forked from bartvdbraak/blender
Cleanup: remove last G.main's from Collada code.
This commit is contained in:
parent
66407e15cb
commit
fd19069999
@ -34,9 +34,10 @@ void forEachObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AnimationExporter::exportAnimations(Scene *sce)
|
bool AnimationExporter::exportAnimations(Main *bmain, Scene *sce)
|
||||||
{
|
{
|
||||||
bool has_animations = hasAnimations(sce);
|
bool has_animations = hasAnimations(sce);
|
||||||
|
m_bmain = bmain;
|
||||||
if (has_animations) {
|
if (has_animations) {
|
||||||
this->scene = sce;
|
this->scene = sce;
|
||||||
|
|
||||||
@ -214,7 +215,7 @@ void AnimationExporter::export_sampled_matrix_animation(Object *ob, std::vector<
|
|||||||
for (std::vector<float>::iterator ctime = ctimes.begin(); ctime != ctimes.end(); ++ctime) {
|
for (std::vector<float>::iterator ctime = ctimes.begin(); ctime != ctimes.end(); ++ctime) {
|
||||||
float fmat[4][4];
|
float fmat[4][4];
|
||||||
|
|
||||||
bc_update_scene(scene, *ctime);
|
bc_update_scene(m_bmain, scene, *ctime);
|
||||||
BKE_object_matrix_local_get(ob, fmat);
|
BKE_object_matrix_local_get(ob, fmat);
|
||||||
if (this->export_settings->limit_precision)
|
if (this->export_settings->limit_precision)
|
||||||
bc_sanitize_mat(fmat, 6);
|
bc_sanitize_mat(fmat, 6);
|
||||||
@ -246,7 +247,7 @@ void AnimationExporter::export_sampled_transrotloc_animation(Object *ob, std::ve
|
|||||||
float fsize[3];
|
float fsize[3];
|
||||||
float feul[3];
|
float feul[3];
|
||||||
|
|
||||||
bc_update_scene(scene, *ctime);
|
bc_update_scene(m_bmain, scene, *ctime);
|
||||||
BKE_object_matrix_local_get(ob, fmat);
|
BKE_object_matrix_local_get(ob, fmat);
|
||||||
mat4_decompose(floc, fquat, fsize, fmat);
|
mat4_decompose(floc, fquat, fsize, fmat);
|
||||||
quat_to_eul(feul, fquat);
|
quat_to_eul(feul, fquat);
|
||||||
@ -1315,7 +1316,7 @@ std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Obj
|
|||||||
float frame = *it;
|
float frame = *it;
|
||||||
|
|
||||||
float ctime = BKE_scene_frame_get_from_ctime(scene, frame);
|
float ctime = BKE_scene_frame_get_from_ctime(scene, frame);
|
||||||
bc_update_scene(scene, ctime);
|
bc_update_scene(m_bmain, scene, ctime);
|
||||||
if (is_bone_animation) {
|
if (is_bone_animation) {
|
||||||
if (pchan->flag & POSE_CHAIN) {
|
if (pchan->flag & POSE_CHAIN) {
|
||||||
enable_fcurves(ob->adt->action, NULL);
|
enable_fcurves(ob->adt->action, NULL);
|
||||||
|
@ -84,6 +84,7 @@ extern "C"
|
|||||||
class AnimationExporter: COLLADASW::LibraryAnimations
|
class AnimationExporter: COLLADASW::LibraryAnimations
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
Main *m_bmain;
|
||||||
Scene *scene;
|
Scene *scene;
|
||||||
COLLADASW::StreamWriter *sw;
|
COLLADASW::StreamWriter *sw;
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ public:
|
|||||||
this->sw = sw;
|
this->sw = sw;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool exportAnimations(Scene *sce);
|
bool exportAnimations(Main *bmain, Scene *sce);
|
||||||
|
|
||||||
// called for each exported object
|
// called for each exported object
|
||||||
void operator() (Object *ob);
|
void operator() (Object *ob);
|
||||||
|
@ -54,8 +54,9 @@ static const char *bc_get_joint_name(T *node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ArmatureImporter::ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce, const ImportSettings *import_settings) :
|
ArmatureImporter::ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Main *bmain, Scene *sce, const ImportSettings *import_settings) :
|
||||||
TransformReader(conv),
|
TransformReader(conv),
|
||||||
|
m_bmain(bmain),
|
||||||
scene(sce),
|
scene(sce),
|
||||||
unit_converter(conv),
|
unit_converter(conv),
|
||||||
import_settings(import_settings),
|
import_settings(import_settings),
|
||||||
@ -409,7 +410,7 @@ Object *ArmatureImporter::get_empty_for_leaves()
|
|||||||
{
|
{
|
||||||
if (empty) return empty;
|
if (empty) return empty;
|
||||||
|
|
||||||
empty = bc_add_object(scene, OB_EMPTY, NULL);
|
empty = bc_add_object(m_bmain, scene, OB_EMPTY, NULL);
|
||||||
empty->empty_drawtype = OB_EMPTY_SPHERE;
|
empty->empty_drawtype = OB_EMPTY_SPHERE;
|
||||||
|
|
||||||
return empty;
|
return empty;
|
||||||
@ -584,7 +585,7 @@ Object *ArmatureImporter::create_armature_bones(Main *bmain, SkinInfo& skin)
|
|||||||
ob_arm = skin.set_armature(shared);
|
ob_arm = skin.set_armature(shared);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ob_arm = skin.create_armature(scene); //once for every armature
|
ob_arm = skin.create_armature(m_bmain, scene); //once for every armature
|
||||||
}
|
}
|
||||||
|
|
||||||
// enter armature edit mode
|
// enter armature edit mode
|
||||||
|
@ -62,6 +62,7 @@ extern "C" {
|
|||||||
class ArmatureImporter : private TransformReader
|
class ArmatureImporter : private TransformReader
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
Main *m_bmain;
|
||||||
Scene *scene;
|
Scene *scene;
|
||||||
UnitConverter *unit_converter;
|
UnitConverter *unit_converter;
|
||||||
const ImportSettings *import_settings;
|
const ImportSettings *import_settings;
|
||||||
@ -137,7 +138,7 @@ private:
|
|||||||
TagsMap uid_tags_map;
|
TagsMap uid_tags_map;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce, const ImportSettings *import_settings);
|
ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Main *bmain, Scene *sce, const ImportSettings *import_settings);
|
||||||
~ArmatureImporter();
|
~ArmatureImporter();
|
||||||
|
|
||||||
void add_root_joint(COLLADAFW::Node *node, Object *parent);
|
void add_root_joint(COLLADAFW::Node *node, Object *parent);
|
||||||
|
@ -107,8 +107,9 @@ bool ControllerExporter::add_instance_controller(Object *ob)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControllerExporter::export_controllers(Scene *sce)
|
void ControllerExporter::export_controllers(Main *bmain, Scene *sce)
|
||||||
{
|
{
|
||||||
|
m_bmain = bmain;
|
||||||
scene = sce;
|
scene = sce;
|
||||||
|
|
||||||
openLibrary();
|
openLibrary();
|
||||||
@ -200,7 +201,9 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
|
|||||||
bool use_instantiation = this->export_settings->use_object_instantiation;
|
bool use_instantiation = this->export_settings->use_object_instantiation;
|
||||||
Mesh *me;
|
Mesh *me;
|
||||||
|
|
||||||
me = bc_get_mesh_copy(scene,
|
me = bc_get_mesh_copy(
|
||||||
|
m_bmain,
|
||||||
|
scene,
|
||||||
ob,
|
ob,
|
||||||
this->export_settings->export_mesh_type,
|
this->export_settings->export_mesh_type,
|
||||||
this->export_settings->apply_modifiers,
|
this->export_settings->apply_modifiers,
|
||||||
@ -291,7 +294,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
|
|||||||
add_joints_element(&ob->defbase, joints_source_id, inv_bind_mat_source_id);
|
add_joints_element(&ob->defbase, joints_source_id, inv_bind_mat_source_id);
|
||||||
add_vertex_weights_element(weights_source_id, joints_source_id, vcounts, joints);
|
add_vertex_weights_element(weights_source_id, joints_source_id, vcounts, joints);
|
||||||
|
|
||||||
BKE_libblock_free_us(G.main, me);
|
BKE_libblock_free_us(m_bmain, me);
|
||||||
|
|
||||||
closeSkin();
|
closeSkin();
|
||||||
closeController();
|
closeController();
|
||||||
@ -302,7 +305,9 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key)
|
|||||||
bool use_instantiation = this->export_settings->use_object_instantiation;
|
bool use_instantiation = this->export_settings->use_object_instantiation;
|
||||||
Mesh *me;
|
Mesh *me;
|
||||||
|
|
||||||
me = bc_get_mesh_copy(scene,
|
me = bc_get_mesh_copy(
|
||||||
|
m_bmain,
|
||||||
|
scene,
|
||||||
ob,
|
ob,
|
||||||
this->export_settings->export_mesh_type,
|
this->export_settings->export_mesh_type,
|
||||||
this->export_settings->apply_modifiers,
|
this->export_settings->apply_modifiers,
|
||||||
@ -327,7 +332,7 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key)
|
|||||||
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, morph_weights_id)));
|
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, morph_weights_id)));
|
||||||
targets.add();
|
targets.add();
|
||||||
|
|
||||||
BKE_libblock_free_us(G.main, me);
|
BKE_libblock_free_us(m_bmain, me);
|
||||||
|
|
||||||
|
|
||||||
//support for animations
|
//support for animations
|
||||||
|
@ -65,11 +65,12 @@ public:
|
|||||||
|
|
||||||
bool add_instance_controller(Object *ob);
|
bool add_instance_controller(Object *ob);
|
||||||
|
|
||||||
void export_controllers(Scene *sce);
|
void export_controllers(Main *bmain, Scene *sce);
|
||||||
|
|
||||||
void operator()(Object *ob);
|
void operator()(Object *ob);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Main *m_bmain;
|
||||||
Scene *scene;
|
Scene *scene;
|
||||||
UnitConverter converter;
|
UnitConverter converter;
|
||||||
const ExportSettings *export_settings;
|
const ExportSettings *export_settings;
|
||||||
|
@ -183,6 +183,7 @@ static COLLADABU::NativeString make_temp_filepath(const char *name, const char *
|
|||||||
|
|
||||||
int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *eval_ctx, Scene *sce)
|
int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *eval_ctx, Scene *sce)
|
||||||
{
|
{
|
||||||
|
Main *bmain = CTX_data_main(C);
|
||||||
PointerRNA sceneptr, unit_settings;
|
PointerRNA sceneptr, unit_settings;
|
||||||
PropertyRNA *system; /* unused , *scale; */
|
PropertyRNA *system; /* unused , *scale; */
|
||||||
|
|
||||||
@ -287,7 +288,7 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e
|
|||||||
// <library_geometries>
|
// <library_geometries>
|
||||||
if (bc_has_object_type(export_set, OB_MESH)) {
|
if (bc_has_object_type(export_set, OB_MESH)) {
|
||||||
GeometryExporter ge(writer, this->export_settings);
|
GeometryExporter ge(writer, this->export_settings);
|
||||||
ge.exportGeom(sce);
|
ge.exportGeom(bmain, sce);
|
||||||
}
|
}
|
||||||
|
|
||||||
// <library_controllers>
|
// <library_controllers>
|
||||||
@ -295,7 +296,7 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e
|
|||||||
ControllerExporter controller_exporter(writer, this->export_settings);
|
ControllerExporter controller_exporter(writer, this->export_settings);
|
||||||
if (bc_has_object_type(export_set, OB_ARMATURE) || this->export_settings->include_shapekeys)
|
if (bc_has_object_type(export_set, OB_ARMATURE) || this->export_settings->include_shapekeys)
|
||||||
{
|
{
|
||||||
controller_exporter.export_controllers(sce);
|
controller_exporter.export_controllers(bmain, sce);
|
||||||
}
|
}
|
||||||
|
|
||||||
// <library_visual_scenes>
|
// <library_visual_scenes>
|
||||||
@ -305,7 +306,7 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e
|
|||||||
if (this->export_settings->include_animations) {
|
if (this->export_settings->include_animations) {
|
||||||
// <library_animations>
|
// <library_animations>
|
||||||
AnimationExporter ae(writer, this->export_settings);
|
AnimationExporter ae(writer, this->export_settings);
|
||||||
ae.exportAnimations(sce);
|
ae.exportAnimations(bmain, sce);
|
||||||
}
|
}
|
||||||
se.exportScene(C, sce);
|
se.exportScene(C, sce);
|
||||||
|
|
||||||
|
@ -104,8 +104,8 @@ DocumentImporter::DocumentImporter(bContext *C, const ImportSettings *import_set
|
|||||||
import_settings(import_settings),
|
import_settings(import_settings),
|
||||||
mImportStage(General),
|
mImportStage(General),
|
||||||
mContext(C),
|
mContext(C),
|
||||||
armature_importer(&unit_converter, &mesh_importer, CTX_data_scene(C), import_settings),
|
armature_importer(&unit_converter, &mesh_importer, CTX_data_main(C), CTX_data_scene(C), import_settings),
|
||||||
mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C)),
|
mesh_importer(&unit_converter, &armature_importer, CTX_data_main(C), CTX_data_scene(C)),
|
||||||
anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C))
|
anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -266,7 +266,7 @@ void DocumentImporter::finish()
|
|||||||
Base *base = BKE_scene_base_find(sce, ob);
|
Base *base = BKE_scene_base_find(sce, ob);
|
||||||
if (base) {
|
if (base) {
|
||||||
BLI_remlink(&sce->base, base);
|
BLI_remlink(&sce->base, base);
|
||||||
BKE_libblock_free_us(G.main, base->object);
|
BKE_libblock_free_us(bmain, base->object);
|
||||||
if (sce->basact == base)
|
if (sce->basact == base)
|
||||||
sce->basact = NULL;
|
sce->basact = NULL;
|
||||||
MEM_freeN(base);
|
MEM_freeN(base);
|
||||||
@ -383,11 +383,12 @@ Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *ob = bc_add_object(sce, OB_CAMERA, NULL);
|
Main *bmain = CTX_data_main(mContext);
|
||||||
|
Object *ob = bc_add_object(bmain, sce, OB_CAMERA, NULL);
|
||||||
Camera *cam = uid_camera_map[cam_uid];
|
Camera *cam = uid_camera_map[cam_uid];
|
||||||
Camera *old_cam = (Camera *)ob->data;
|
Camera *old_cam = (Camera *)ob->data;
|
||||||
ob->data = cam;
|
ob->data = cam;
|
||||||
BKE_libblock_free_us(G.main, old_cam);
|
BKE_libblock_free_us(bmain, old_cam);
|
||||||
return ob;
|
return ob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,11 +400,12 @@ Object *DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *ob = bc_add_object(sce, OB_LAMP, NULL);
|
Main *bmain = CTX_data_main(mContext);
|
||||||
|
Object *ob = bc_add_object(bmain, sce, OB_LAMP, NULL);
|
||||||
Lamp *la = uid_lamp_map[lamp_uid];
|
Lamp *la = uid_lamp_map[lamp_uid];
|
||||||
Lamp *old_lamp = (Lamp *)ob->data;
|
Lamp *old_lamp = (Lamp *)ob->data;
|
||||||
ob->data = la;
|
ob->data = la;
|
||||||
BKE_libblock_free_us(G.main, old_lamp);
|
BKE_libblock_free_us(bmain, old_lamp);
|
||||||
return ob;
|
return ob;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,7 +413,8 @@ Object *DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Nod
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "create <instance_node> under node id=%s from node id=%s\n", instance_node ? instance_node->getOriginalId().c_str() : NULL, source_node ? source_node->getOriginalId().c_str() : NULL);
|
fprintf(stderr, "create <instance_node> under node id=%s from node id=%s\n", instance_node ? instance_node->getOriginalId().c_str() : NULL, source_node ? source_node->getOriginalId().c_str() : NULL);
|
||||||
|
|
||||||
Object *obn = BKE_object_copy(G.main, source_ob);
|
Main *bmain = CTX_data_main(mContext);
|
||||||
|
Object *obn = BKE_object_copy(bmain, source_ob);
|
||||||
DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
|
DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
|
||||||
BKE_scene_base_add(sce, obn);
|
BKE_scene_base_add(sce, obn);
|
||||||
|
|
||||||
@ -494,6 +497,7 @@ void DocumentImporter::report_unknown_reference(const COLLADAFW::Node &node, con
|
|||||||
|
|
||||||
std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLADAFW::Node *parent_node, Scene *sce, Object *par, bool is_library_node)
|
std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLADAFW::Node *parent_node, Scene *sce, Object *par, bool is_library_node)
|
||||||
{
|
{
|
||||||
|
Main *bmain = CTX_data_main(mContext);
|
||||||
Object *ob = NULL;
|
Object *ob = NULL;
|
||||||
bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
|
bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
|
||||||
bool read_transform = true;
|
bool read_transform = true;
|
||||||
@ -515,7 +519,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
|
|||||||
if (parent_node == NULL && !is_library_node) {
|
if (parent_node == NULL && !is_library_node) {
|
||||||
// A Joint on root level is a skeleton without root node.
|
// A Joint on root level is a skeleton without root node.
|
||||||
// Here we add the armature "on the fly":
|
// Here we add the armature "on the fly":
|
||||||
par = bc_add_object(sce, OB_ARMATURE, std::string("Armature").c_str());
|
par = bc_add_object(bmain, sce, OB_ARMATURE, std::string("Armature").c_str());
|
||||||
objects_done->push_back(par);
|
objects_done->push_back(par);
|
||||||
root_objects->push_back(par);
|
root_objects->push_back(par);
|
||||||
object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), par));
|
object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), par));
|
||||||
@ -629,10 +633,10 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
|
|||||||
if ( (geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) {
|
if ( (geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) {
|
||||||
//Check if Object is armature, by checking if immediate child is a JOINT node.
|
//Check if Object is armature, by checking if immediate child is a JOINT node.
|
||||||
if (is_armature(node)) {
|
if (is_armature(node)) {
|
||||||
ob = bc_add_object(sce, OB_ARMATURE, name.c_str());
|
ob = bc_add_object(bmain, sce, OB_ARMATURE, name.c_str());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ob = bc_add_object(sce, OB_EMPTY, NULL);
|
ob = bc_add_object(bmain, sce, OB_EMPTY, NULL);
|
||||||
}
|
}
|
||||||
objects_done->push_back(ob);
|
objects_done->push_back(ob);
|
||||||
if (parent_node == NULL) {
|
if (parent_node == NULL) {
|
||||||
@ -649,7 +653,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
|
|||||||
for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); ++it) {
|
for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); ++it) {
|
||||||
ob = *it;
|
ob = *it;
|
||||||
std::string nodename = node->getName().size() ? node->getName() : node->getOriginalId();
|
std::string nodename = node->getName().size() ? node->getName() : node->getOriginalId();
|
||||||
BKE_libblock_rename(G.main, &ob->id, (char *)nodename.c_str());
|
BKE_libblock_rename(bmain, &ob->id, (char *)nodename.c_str());
|
||||||
object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), ob));
|
object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), ob));
|
||||||
node_map[node->getUniqueId()] = node;
|
node_map[node->getUniqueId()] = node;
|
||||||
|
|
||||||
@ -759,8 +763,9 @@ bool DocumentImporter::writeMaterial(const COLLADAFW::Material *cmat)
|
|||||||
if (mImportStage != General)
|
if (mImportStage != General)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
Main *bmain = CTX_data_main(mContext);
|
||||||
const std::string& str_mat_id = cmat->getName().size() ? cmat->getName() : cmat->getOriginalId();
|
const std::string& str_mat_id = cmat->getName().size() ? cmat->getName() : cmat->getOriginalId();
|
||||||
Material *ma = BKE_material_add(G.main, (char *)str_mat_id.c_str());
|
Material *ma = BKE_material_add(bmain, (char *)str_mat_id.c_str());
|
||||||
|
|
||||||
this->uid_effect_map[cmat->getInstantiatedEffect()] = ma;
|
this->uid_effect_map[cmat->getInstantiatedEffect()] = ma;
|
||||||
this->uid_material_map[cmat->getUniqueId()] = ma;
|
this->uid_material_map[cmat->getUniqueId()] = ma;
|
||||||
@ -782,9 +787,10 @@ MTex *DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::T
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Main *bmain = CTX_data_main(mContext);
|
||||||
ma->mtex[i] = BKE_texture_mtex_add();
|
ma->mtex[i] = BKE_texture_mtex_add();
|
||||||
ma->mtex[i]->texco = TEXCO_UV;
|
ma->mtex[i]->texco = TEXCO_UV;
|
||||||
ma->mtex[i]->tex = BKE_texture_add(G.main, "Texture");
|
ma->mtex[i]->tex = BKE_texture_add(bmain, "Texture");
|
||||||
ma->mtex[i]->tex->type = TEX_IMAGE;
|
ma->mtex[i]->tex->type = TEX_IMAGE;
|
||||||
ma->mtex[i]->tex->ima = uid_image_map[ima_uid];
|
ma->mtex[i]->tex->ima = uid_image_map[ima_uid];
|
||||||
|
|
||||||
@ -989,14 +995,15 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera)
|
|||||||
if (mImportStage != General)
|
if (mImportStage != General)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
Main *bmain = CTX_data_main(mContext);
|
||||||
Camera *cam = NULL;
|
Camera *cam = NULL;
|
||||||
std::string cam_id, cam_name;
|
std::string cam_id, cam_name;
|
||||||
|
|
||||||
ExtraTags *et=getExtraTags(camera->getUniqueId());
|
ExtraTags *et=getExtraTags(camera->getUniqueId());
|
||||||
cam_id = camera->getOriginalId();
|
cam_id = camera->getOriginalId();
|
||||||
cam_name = camera->getName();
|
cam_name = camera->getName();
|
||||||
if (cam_name.size()) cam = (Camera *)BKE_camera_add(G.main, (char *)cam_name.c_str());
|
if (cam_name.size()) cam = (Camera *)BKE_camera_add(bmain, (char *)cam_name.c_str());
|
||||||
else cam = (Camera *)BKE_camera_add(G.main, (char *)cam_id.c_str());
|
else cam = (Camera *)BKE_camera_add(bmain, (char *)cam_id.c_str());
|
||||||
|
|
||||||
if (!cam) {
|
if (!cam) {
|
||||||
fprintf(stderr, "Cannot create camera.\n");
|
fprintf(stderr, "Cannot create camera.\n");
|
||||||
@ -1151,6 +1158,7 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light)
|
|||||||
if (mImportStage != General)
|
if (mImportStage != General)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
Main *bmain = CTX_data_main(mContext);
|
||||||
Lamp *lamp = NULL;
|
Lamp *lamp = NULL;
|
||||||
std::string la_id, la_name;
|
std::string la_id, la_name;
|
||||||
|
|
||||||
@ -1163,8 +1171,8 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light)
|
|||||||
|
|
||||||
la_id = light->getOriginalId();
|
la_id = light->getOriginalId();
|
||||||
la_name = light->getName();
|
la_name = light->getName();
|
||||||
if (la_name.size()) lamp = (Lamp *)BKE_lamp_add(G.main, (char *)la_name.c_str());
|
if (la_name.size()) lamp = (Lamp *)BKE_lamp_add(bmain, (char *)la_name.c_str());
|
||||||
else lamp = (Lamp *)BKE_lamp_add(G.main, (char *)la_id.c_str());
|
else lamp = (Lamp *)BKE_lamp_add(bmain, (char *)la_id.c_str());
|
||||||
|
|
||||||
if (!lamp) {
|
if (!lamp) {
|
||||||
fprintf(stderr, "Cannot create lamp.\n");
|
fprintf(stderr, "Cannot create lamp.\n");
|
||||||
|
@ -58,10 +58,11 @@ GeometryExporter::GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSett
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryExporter::exportGeom(Scene *sce)
|
void GeometryExporter::exportGeom(Main *bmain, Scene *sce)
|
||||||
{
|
{
|
||||||
openLibrary();
|
openLibrary();
|
||||||
|
|
||||||
|
m_bmain = bmain;
|
||||||
mScene = sce;
|
mScene = sce;
|
||||||
GeometryFunctor gf;
|
GeometryFunctor gf;
|
||||||
gf.forEachMeshObjectInExportSet<GeometryExporter>(sce, *this, this->export_settings->export_set);
|
gf.forEachMeshObjectInExportSet<GeometryExporter>(sce, *this, this->export_settings->export_set);
|
||||||
@ -77,7 +78,9 @@ void GeometryExporter::operator()(Object *ob)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool use_instantiation = this->export_settings->use_object_instantiation;
|
bool use_instantiation = this->export_settings->use_object_instantiation;
|
||||||
Mesh *me = bc_get_mesh_copy( mScene,
|
Mesh *me = bc_get_mesh_copy(
|
||||||
|
m_bmain,
|
||||||
|
mScene,
|
||||||
ob,
|
ob,
|
||||||
this->export_settings->export_mesh_type,
|
this->export_settings->export_mesh_type,
|
||||||
this->export_settings->apply_modifiers,
|
this->export_settings->apply_modifiers,
|
||||||
@ -175,7 +178,7 @@ void GeometryExporter::operator()(Object *ob)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BKE_libblock_free_us(G.main, me);
|
BKE_libblock_free_us(m_bmain, me);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,12 +72,13 @@ class GeometryExporter : COLLADASW::LibraryGeometries
|
|||||||
|
|
||||||
Normal n;
|
Normal n;
|
||||||
|
|
||||||
|
Main *m_bmain;
|
||||||
Scene *mScene;
|
Scene *mScene;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
|
GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
|
||||||
|
|
||||||
void exportGeom(Scene *sce);
|
void exportGeom(Main *bmain, Scene *sce);
|
||||||
|
|
||||||
void operator()(Object *ob);
|
void operator()(Object *ob);
|
||||||
|
|
||||||
|
@ -207,7 +207,11 @@ void VCOLDataWrapper::get_vcol(int v_index, MLoopCol *mloopcol)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce) : unitconverter(unitconv), scene(sce), armature_importer(arm) {
|
MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Main *bmain, Scene *sce) :
|
||||||
|
unitconverter(unitconv),
|
||||||
|
m_bmain(bmain),
|
||||||
|
scene(sce),
|
||||||
|
armature_importer(arm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MeshImporter::set_poly_indices(MPoly *mpoly, MLoop *mloop, int loop_index, unsigned int *indices, int loop_count)
|
bool MeshImporter::set_poly_indices(MPoly *mpoly, MLoop *mloop, int loop_index, unsigned int *indices, int loop_count)
|
||||||
@ -1077,7 +1081,7 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri
|
|||||||
// Attention! This temporaly assigns material to object on purpose!
|
// Attention! This temporaly assigns material to object on purpose!
|
||||||
// See note above.
|
// See note above.
|
||||||
ob->actcol=0;
|
ob->actcol=0;
|
||||||
assign_material(G.main, ob, ma, mat_index + 1, BKE_MAT_ASSIGN_OBJECT);
|
assign_material(m_bmain, ob, ma, mat_index + 1, BKE_MAT_ASSIGN_OBJECT);
|
||||||
|
|
||||||
COLLADAFW::TextureCoordinateBindingArray& tex_array =
|
COLLADAFW::TextureCoordinateBindingArray& tex_array =
|
||||||
cmaterial.getTextureCoordinateBindingArray();
|
cmaterial.getTextureCoordinateBindingArray();
|
||||||
@ -1160,7 +1164,7 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
|
|||||||
const char *name = (id.length()) ? id.c_str() : NULL;
|
const char *name = (id.length()) ? id.c_str() : NULL;
|
||||||
|
|
||||||
// add object
|
// add object
|
||||||
Object *ob = bc_add_object(scene, OB_MESH, name);
|
Object *ob = bc_add_object(m_bmain, scene, OB_MESH, name);
|
||||||
bc_set_mark(ob); // used later for material assignement optimization
|
bc_set_mark(ob); // used later for material assignement optimization
|
||||||
|
|
||||||
|
|
||||||
@ -1172,11 +1176,11 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
|
|||||||
Mesh *old_mesh = (Mesh *)ob->data;
|
Mesh *old_mesh = (Mesh *)ob->data;
|
||||||
Mesh *new_mesh = uid_mesh_map[*geom_uid];
|
Mesh *new_mesh = uid_mesh_map[*geom_uid];
|
||||||
|
|
||||||
BKE_mesh_assign_object(G.main, ob, new_mesh);
|
BKE_mesh_assign_object(m_bmain, ob, new_mesh);
|
||||||
BKE_mesh_calc_normals(new_mesh);
|
BKE_mesh_calc_normals(new_mesh);
|
||||||
|
|
||||||
id_us_plus(&old_mesh->id); /* Because BKE_mesh_assign_object would have already decreased it... */
|
id_us_plus(&old_mesh->id); /* Because BKE_mesh_assign_object would have already decreased it... */
|
||||||
BKE_libblock_free_us(G.main, old_mesh);
|
BKE_libblock_free_us(m_bmain, old_mesh);
|
||||||
|
|
||||||
char layername[100];
|
char layername[100];
|
||||||
layername[0] = '\0';
|
layername[0] = '\0';
|
||||||
@ -1219,7 +1223,7 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry *geom)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const std::string& str_geom_id = mesh->getName().size() ? mesh->getName() : mesh->getOriginalId();
|
const std::string& str_geom_id = mesh->getName().size() ? mesh->getName() : mesh->getOriginalId();
|
||||||
Mesh *me = BKE_mesh_add(G.main, (char *)str_geom_id.c_str());
|
Mesh *me = BKE_mesh_add(m_bmain, (char *)str_geom_id.c_str());
|
||||||
id_us_min(&me->id); // is already 1 here, but will be set later in BKE_mesh_assign_object
|
id_us_min(&me->id); // is already 1 here, but will be set later in BKE_mesh_assign_object
|
||||||
|
|
||||||
// store the Mesh pointer to link it later with an Object
|
// store the Mesh pointer to link it later with an Object
|
||||||
|
@ -91,6 +91,7 @@ private:
|
|||||||
|
|
||||||
UnitConverter *unitconverter;
|
UnitConverter *unitconverter;
|
||||||
|
|
||||||
|
Main *m_bmain;
|
||||||
Scene *scene;
|
Scene *scene;
|
||||||
ArmatureImporter *armature_importer;
|
ArmatureImporter *armature_importer;
|
||||||
|
|
||||||
@ -159,7 +160,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce);
|
MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Main *bmain, Scene *sce);
|
||||||
|
|
||||||
virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid);
|
virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid);
|
||||||
|
|
||||||
|
@ -159,9 +159,9 @@ void SkinInfo::set_controller(const COLLADAFW::SkinController *co)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// called from write_controller
|
// called from write_controller
|
||||||
Object *SkinInfo::create_armature(Scene *scene)
|
Object *SkinInfo::create_armature(Main *bmain, Scene *scene)
|
||||||
{
|
{
|
||||||
ob_arm = bc_add_object(scene, OB_ARMATURE, NULL);
|
ob_arm = bc_add_object(bmain, scene, OB_ARMATURE, NULL);
|
||||||
return ob_arm;
|
return ob_arm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ public:
|
|||||||
void set_controller(const COLLADAFW::SkinController* co);
|
void set_controller(const COLLADAFW::SkinController* co);
|
||||||
|
|
||||||
// called from write_controller
|
// called from write_controller
|
||||||
Object *create_armature(Scene *scene);
|
Object *create_armature(Main *bmain, Scene *scene);
|
||||||
|
|
||||||
Object* set_armature(Object *ob_arm);
|
Object* set_armature(Object *ob_arm);
|
||||||
|
|
||||||
|
@ -133,30 +133,23 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Main *bc_get_main()
|
EvaluationContext *bc_get_evaluation_context(Main *bmain)
|
||||||
{
|
{
|
||||||
return G.main;
|
|
||||||
}
|
|
||||||
|
|
||||||
EvaluationContext *bc_get_evaluation_context()
|
|
||||||
{
|
|
||||||
Main *bmain = G.main;
|
|
||||||
return bmain->eval_ctx;
|
return bmain->eval_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bc_update_scene(Scene *scene, float ctime)
|
void bc_update_scene(Main *bmain, Scene *scene, float ctime)
|
||||||
{
|
{
|
||||||
BKE_scene_frame_set(scene, ctime);
|
BKE_scene_frame_set(scene, ctime);
|
||||||
Main *bmain = bc_get_main();
|
EvaluationContext *ev_context = bc_get_evaluation_context(bmain);
|
||||||
EvaluationContext *ev_context = bc_get_evaluation_context();
|
|
||||||
BKE_scene_update_for_newframe(ev_context, bmain, scene, scene->lay);
|
BKE_scene_update_for_newframe(ev_context, bmain, scene, scene->lay);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *bc_add_object(Scene *scene, int type, const char *name)
|
Object *bc_add_object(Main *bmain, Scene *scene, int type, const char *name)
|
||||||
{
|
{
|
||||||
Object *ob = BKE_object_add_only_object(G.main, type, name);
|
Object *ob = BKE_object_add_only_object(bmain, type, name);
|
||||||
|
|
||||||
ob->data = BKE_object_obdata_add_from_type(G.main, type, name);
|
ob->data = BKE_object_obdata_add_from_type(bmain, type, name);
|
||||||
ob->lay = scene->lay;
|
ob->lay = scene->lay;
|
||||||
DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
|
DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
|
||||||
|
|
||||||
@ -165,7 +158,8 @@ Object *bc_add_object(Scene *scene, int type, const char *name)
|
|||||||
return ob;
|
return ob;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate)
|
Mesh *bc_get_mesh_copy(
|
||||||
|
Main *bmain, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate)
|
||||||
{
|
{
|
||||||
Mesh *tmpmesh;
|
Mesh *tmpmesh;
|
||||||
CustomDataMask mask = CD_MASK_MESH;
|
CustomDataMask mask = CD_MASK_MESH;
|
||||||
@ -189,7 +183,7 @@ Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh
|
|||||||
dm = mesh_create_derived((Mesh *)ob->data, NULL);
|
dm = mesh_create_derived((Mesh *)ob->data, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpmesh = BKE_mesh_add(G.main, "ColladaMesh"); // name is not important here
|
tmpmesh = BKE_mesh_add(bmain, "ColladaMesh"); // name is not important here
|
||||||
DM_to_mesh(dm, tmpmesh, ob, CD_MASK_MESH, true);
|
DM_to_mesh(dm, tmpmesh, ob, CD_MASK_MESH, true);
|
||||||
tmpmesh->flag = mesh->flag;
|
tmpmesh->flag = mesh->flag;
|
||||||
|
|
||||||
|
@ -63,15 +63,15 @@ extern "C" {
|
|||||||
|
|
||||||
typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex *> > TexIndexTextureArrayMap;
|
typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex *> > TexIndexTextureArrayMap;
|
||||||
|
|
||||||
extern Main *bc_get_main();
|
extern EvaluationContext *bc_get_evaluation_context(Main *bmain);
|
||||||
extern EvaluationContext *bc_get_evaluation_context();
|
extern void bc_update_scene(Main *bmain, Scene *scene, float ctime);
|
||||||
extern void bc_update_scene(Scene *scene, float ctime);
|
|
||||||
|
|
||||||
extern float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index);
|
extern float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index);
|
||||||
extern int bc_test_parent_loop(Object *par, Object *ob);
|
extern int bc_test_parent_loop(Object *par, Object *ob);
|
||||||
extern int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space = true);
|
extern int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space = true);
|
||||||
extern Object *bc_add_object(Scene *scene, int type, const char *name);
|
extern Object *bc_add_object(Main *bmain, Scene *scene, int type, const char *name);
|
||||||
extern Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate);
|
extern Mesh *bc_get_mesh_copy(
|
||||||
|
Main *bmain, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate);
|
||||||
|
|
||||||
extern Object *bc_get_assigned_armature(Object *ob);
|
extern Object *bc_get_assigned_armature(Object *ob);
|
||||||
extern Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob);
|
extern Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob);
|
||||||
|
Loading…
Reference in New Issue
Block a user