diff options
Diffstat (limited to 'source/blender/collada')
38 files changed, 305 insertions, 716 deletions
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index 97d3b6b29b8..9c65aa4d2c5 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -38,6 +38,7 @@ bool AnimationExporter::exportAnimations(Scene *sce) { bool has_animations = hasAnimations(sce); if (has_animations) { + this->eval_ctx = eval_ctx; this->scene = sce; openLibrary(); @@ -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) { float fmat[4][4]; - bc_update_scene(scene, *ctime); + bc_update_scene(eval_ctx, scene, *ctime); BKE_object_matrix_local_get(ob, fmat); if (this->export_settings->limit_precision) bc_sanitize_mat(fmat, 6); @@ -246,7 +247,7 @@ void AnimationExporter::export_sampled_transrotloc_animation(Object *ob, std::ve float fsize[3]; float feul[3]; - bc_update_scene(scene, *ctime); + bc_update_scene(eval_ctx, scene, *ctime); BKE_object_matrix_local_get(ob, fmat); mat4_decompose(floc, fquat, fsize, fmat); quat_to_eul(feul, fquat); @@ -402,7 +403,7 @@ void AnimationExporter::export_morph_animation(Object *ob) void AnimationExporter::make_anim_frames_from_targets(Object *ob, std::vector<float> &frames ) { - ListBase *conlist = get_active_constraints(ob); + ListBase *conlist = get_active_constraints(this->eval_ctx, ob); if (conlist == NULL) return; bConstraint *con; for (con = (bConstraint *)conlist->first; con; con = con->next) { @@ -721,7 +722,7 @@ void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, B if (flag & ARM_RESTPOS) { arm->flag &= ~ARM_RESTPOS; - BKE_pose_where_is(scene, ob_arm); + BKE_pose_where_is(eval_ctx, scene, ob_arm); } if (fra.size()) { @@ -730,7 +731,7 @@ void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, B if (flag & ARM_RESTPOS) arm->flag = flag; - BKE_pose_where_is(scene, ob_arm); + BKE_pose_where_is(eval_ctx, scene, ob_arm); } void AnimationExporter::dae_baked_animation(std::vector<float> &fra, Object *ob_arm, Bone *bone) @@ -1005,7 +1006,7 @@ std::string AnimationExporter::create_source_from_fcurve(COLLADASW::InputSemanti void AnimationExporter::evaluate_anim_with_constraints(Object *ob, float ctime) { BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL); - ListBase *conlist = get_active_constraints(ob); + ListBase *conlist = get_active_constraints(this->eval_ctx, ob); bConstraint *con; for (con = (bConstraint *)conlist->first; con; con = con->next) { ListBase targets = { NULL, NULL }; @@ -1021,7 +1022,7 @@ void AnimationExporter::evaluate_anim_with_constraints(Object *ob, float ctime) if (obtar) { BKE_animsys_evaluate_animdata(scene, &obtar->id, obtar->adt, ctime, ADT_RECALC_ANIM); - BKE_object_where_is_calc_time(scene, obtar, ctime); + BKE_object_where_is_calc_time(this->eval_ctx, scene, obtar, ctime); } } @@ -1029,7 +1030,7 @@ void AnimationExporter::evaluate_anim_with_constraints(Object *ob, float ctime) cti->flush_constraint_targets(con, &targets, 1); } } - BKE_object_where_is_calc_time(scene, ob, ctime); + BKE_object_where_is_calc_time(this->eval_ctx, scene, ob, ctime); } /* @@ -1315,15 +1316,16 @@ std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Obj float frame = *it; float ctime = BKE_scene_frame_get_from_ctime(scene, frame); - bc_update_scene(scene, ctime); + bc_update_scene(eval_ctx, scene, ctime); if (is_bone_animation) { + if (pchan->flag & POSE_CHAIN) { enable_fcurves(ob->adt->action, NULL); BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL); - BKE_pose_where_is(scene, ob); + BKE_pose_where_is(eval_ctx, scene, ob); } else { - BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1); + BKE_pose_where_is_bone(eval_ctx, scene, ob, pchan, ctime, 1); } // compute bone local mat @@ -1841,7 +1843,7 @@ void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bo // exit rest position if (flag & ARM_RESTPOS) { arm->flag &= ~ARM_RESTPOS; - BKE_pose_where_is(scene, ob_arm); + BKE_pose_where_is(eval_ctx, scene, ob_arm); } //v array will hold all values which will be exported. if (fra.size()) { @@ -1871,7 +1873,7 @@ void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bo // restore restpos if (flag & ARM_RESTPOS) arm->flag = flag; - BKE_pose_where_is(scene, ob_arm); + BKE_pose_where_is(eval_ctx, scene, ob_arm); } void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pchan) @@ -1896,7 +1898,7 @@ void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, i BKE_animsys_evaluate_animdata(scene, &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM); - BKE_pose_where_is_bone(scene, ob_arm, pchan, ctime, 1); + BKE_pose_where_is_bone(eval_ctx, scene, ob_arm, pchan, ctime, 1); // compute bone local mat if (bone->parent) { diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index a739b2b6cbe..d2216c04ee5 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -79,17 +79,19 @@ extern "C" #include <vector> #include <algorithm> // std::find - +struct EvaluationContext; class AnimationExporter: COLLADASW::LibraryAnimations { private: Scene *scene; + EvaluationContext *eval_ctx; COLLADASW::StreamWriter *sw; public: - AnimationExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): + AnimationExporter(EvaluationContext *eval_ctx, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): + eval_ctx(eval_ctx), COLLADASW::LibraryAnimations(sw), export_settings(export_settings) { @@ -97,7 +99,6 @@ public: } bool exportAnimations(Scene *sce); - // called for each exported object void operator() (Object *ob); diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index ed3d953166f..4ef256fbcf1 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -1913,7 +1913,7 @@ Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root, COLLADAFW::No job->lay = BKE_scene_base_find(scene, job)->lay = 2; mul_v3_fl(job->size, 0.5f); - DAG_id_tag_update(&job->id, OB_RECALC_OB); + DEG_id_tag_update(&job->id, OB_RECALC_OB); verify_adt_action((ID *)&job->id, 1); @@ -1934,14 +1934,14 @@ Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root, COLLADAFW::No if (par_job) { job->parent = par_job; - DAG_id_tag_update(&par_job->id, OB_RECALC_OB); + DEG_id_tag_update(&par_job->id, OB_RECALC_OB); job->parsubstr[0] = 0; } BKE_object_where_is_calc(scene, job); // after parenting and layer change - DAG_relations_tag_update(CTX_data_main(C)); + DEG_relations_tag_update(CTX_data_main(C)); joint_objects[node->getUniqueId()] = job; } diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp index d2495a8cb9f..844be2dd60b 100644 --- a/source/blender/collada/ArmatureExporter.cpp +++ b/source/blender/collada/ArmatureExporter.cpp @@ -62,8 +62,8 @@ ArmatureExporter::ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSett } // write bone nodes -void ArmatureExporter::add_armature_bones(Object *ob_arm, Scene *sce, - SceneExporter *se, +void ArmatureExporter::add_armature_bones(const EvaluationContext *eval_ctx, Object *ob_arm, + Scene *sce, SceneExporter *se, std::list<Object *>& child_objects) { // write bone nodes @@ -77,7 +77,7 @@ void ArmatureExporter::add_armature_bones(Object *ob_arm, Scene *sce, for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) { // start from root bones if (!bone->parent) - add_bone_node(bone, ob_arm, sce, se, child_objects); + add_bone_node(eval_ctx, bone, ob_arm, sce, se, child_objects); } if (!is_edited) { @@ -116,10 +116,7 @@ bool ArmatureExporter::add_instance_controller(Object *ob) write_bone_URLs(ins, ob_arm, bone); } - InstanceWriter::add_material_bindings(ins.getBindMaterial(), - ob, - this->export_settings->active_uv_only, - this->export_settings->export_texture_type); + InstanceWriter::add_material_bindings(ins.getBindMaterial(), ob, this->export_settings->active_uv_only); ins.add(); return true; @@ -160,7 +157,7 @@ void ArmatureExporter::find_objects_using_armature(Object *ob_arm, std::vector<O #endif // parent_mat is armature-space -void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce, +void ArmatureExporter::add_bone_node(const EvaluationContext *eval_ctx, Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se, std::list<Object *>& child_objects) { @@ -234,7 +231,7 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce, mul_m4_m4m4((*i)->parentinv, temp, (*i)->parentinv); } - se->writeNodes(*i, sce); + se->writeNodes(eval_ctx, *i, sce); copy_m4_m4((*i)->parentinv, backup_parinv); child_objects.erase(i++); @@ -243,13 +240,13 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce, } for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - add_bone_node(child, ob_arm, sce, se, child_objects); + add_bone_node(eval_ctx, child, ob_arm, sce, se, child_objects); } node.end(); } else { for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - add_bone_node(child, ob_arm, sce, se, child_objects); + add_bone_node(eval_ctx, child, ob_arm, sce, se, child_objects); } } } diff --git a/source/blender/collada/ArmatureExporter.h b/source/blender/collada/ArmatureExporter.h index d271b505aa9..a3ed97c3a43 100644 --- a/source/blender/collada/ArmatureExporter.h +++ b/source/blender/collada/ArmatureExporter.h @@ -60,7 +60,7 @@ public: ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); // write bone nodes - void add_armature_bones(Object *ob_arm, Scene *sce, SceneExporter *se, + void add_armature_bones(const struct EvaluationContext *eval_ctx, Object *ob_arm, Scene *sce, SceneExporter *se, std::list<Object *>& child_objects); bool add_instance_controller(Object *ob); @@ -85,7 +85,7 @@ private: // Scene, SceneExporter and the list of child_objects // are required for writing bone parented objects - void add_bone_node(Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se, + void add_bone_node(const struct EvaluationContext *eval_ctx, Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se, std::list<Object *>& child_objects); void add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node& node); diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp index 0ea8324ed7c..8832e0fd577 100644 --- a/source/blender/collada/ArmatureImporter.cpp +++ b/source/blender/collada/ArmatureImporter.cpp @@ -34,7 +34,6 @@ extern "C" { #include "BKE_action.h" -#include "BKE_depsgraph.h" #include "BKE_object.h" #include "BKE_armature.h" #include "BLI_string.h" @@ -42,6 +41,8 @@ extern "C" { #include "ED_armature.h" } +#include "DEG_depsgraph.h" + #include "collada_utils.h" #include "ArmatureImporter.h" @@ -54,9 +55,10 @@ 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, Scene *sce, ViewLayer *view_layer, const ImportSettings *import_settings) : TransformReader(conv), scene(sce), + view_layer(view_layer), unit_converter(conv), import_settings(import_settings), empty(NULL), @@ -410,7 +412,7 @@ Object *ArmatureImporter::get_empty_for_leaves() { if (empty) return empty; - empty = bc_add_object(scene, OB_EMPTY, NULL); + empty = bc_add_object(scene, view_layer, OB_EMPTY, NULL); empty->empty_drawtype = OB_EMPTY_SPHERE; return empty; @@ -496,7 +498,7 @@ void ArmatureImporter::create_armature_bones(std::vector<Object *> &ob_arms) ob_arms.push_back(ob_arm); } - DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA); + DEG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA); } } @@ -585,7 +587,7 @@ Object *ArmatureImporter::create_armature_bones(SkinInfo& skin) ob_arm = skin.set_armature(shared); } else { - ob_arm = skin.create_armature(scene); //once for every armature + ob_arm = skin.create_armature(scene, view_layer); //once for every armature } // enter armature edit mode @@ -629,7 +631,7 @@ Object *ArmatureImporter::create_armature_bones(SkinInfo& skin) ED_armature_from_edit(armature); ED_armature_edit_free(armature); - DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA); + DEG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA); return ob_arm; } diff --git a/source/blender/collada/ArmatureImporter.h b/source/blender/collada/ArmatureImporter.h index 17173f157e5..f260bb2307c 100644 --- a/source/blender/collada/ArmatureImporter.h +++ b/source/blender/collada/ArmatureImporter.h @@ -63,6 +63,7 @@ class ArmatureImporter : private TransformReader { private: Scene *scene; + ViewLayer *view_layer; UnitConverter *unit_converter; const ImportSettings *import_settings; @@ -137,7 +138,7 @@ private: TagsMap uid_tags_map; public: - ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce, const ImportSettings *import_settings); + ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce, ViewLayer *view_layer, const ImportSettings *import_settings); ~ArmatureImporter(); void add_root_joint(COLLADAFW::Node *node, Object *parent); diff --git a/source/blender/collada/CMakeLists.txt b/source/blender/collada/CMakeLists.txt index 293049a1a05..8642bbee698 100644 --- a/source/blender/collada/CMakeLists.txt +++ b/source/blender/collada/CMakeLists.txt @@ -30,6 +30,7 @@ set(INC ../blenkernel ../blenlib ../blentranslation + ../depsgraph ../editors/include ../makesdna ../makesrna diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp index 4afe71f47ba..ae99e6bafde 100644 --- a/source/blender/collada/ControllerExporter.cpp +++ b/source/blender/collada/ControllerExporter.cpp @@ -98,17 +98,15 @@ bool ControllerExporter::add_instance_controller(Object *ob) write_bone_URLs(ins, ob_arm, bone); } - InstanceWriter::add_material_bindings(ins.getBindMaterial(), - ob, - this->export_settings->active_uv_only, - this->export_settings->export_texture_type); + InstanceWriter::add_material_bindings(ins.getBindMaterial(), ob, this->export_settings->active_uv_only); ins.add(); return true; } -void ControllerExporter::export_controllers(Scene *sce) +void ControllerExporter::export_controllers(const struct EvaluationContext *eval_ctx, Scene *sce) { + this->eval_ctx = eval_ctx; scene = sce; openLibrary(); @@ -200,7 +198,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm) bool use_instantiation = this->export_settings->use_object_instantiation; Mesh *me; - me = bc_get_mesh_copy(scene, + me = bc_get_mesh_copy(eval_ctx, scene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, @@ -302,7 +300,7 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key) bool use_instantiation = this->export_settings->use_object_instantiation; Mesh *me; - me = bc_get_mesh_copy(scene, + me = bc_get_mesh_copy(eval_ctx, scene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, @@ -497,7 +495,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas // put armature in rest position if (!(arm->flag & ARM_RESTPOS)) { arm->flag |= ARM_RESTPOS; - BKE_pose_where_is(scene, ob_arm); + BKE_pose_where_is(eval_ctx, scene, ob_arm); } for (bDeformGroup *def = (bDeformGroup *)defbase->first; def; def = def->next) { @@ -545,7 +543,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas // back from rest positon if (!(flag & ARM_RESTPOS)) { arm->flag = flag; - BKE_pose_where_is(scene, ob_arm); + BKE_pose_where_is(eval_ctx, scene, ob_arm); } source.finish(); diff --git a/source/blender/collada/ControllerExporter.h b/source/blender/collada/ControllerExporter.h index 80b858ca6dd..a1d46c5aafb 100644 --- a/source/blender/collada/ControllerExporter.h +++ b/source/blender/collada/ControllerExporter.h @@ -54,6 +54,7 @@ #include "BKE_key.h" +struct EvaluationContext; class SceneExporter; class ControllerExporter : public COLLADASW::LibraryControllers, protected TransformWriter, protected InstanceWriter @@ -65,11 +66,12 @@ public: bool add_instance_controller(Object *ob); - void export_controllers(Scene *sce); + void export_controllers(const struct EvaluationContext *eval_ctx, Scene *sce); void operator()(Object *ob); private: + const struct EvaluationContext *eval_ctx; Scene *scene; UnitConverter converter; const ExportSettings *export_settings; diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index d4eb6b477db..04af73f2406 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -138,8 +138,7 @@ extern bool bc_has_object_type(LinkNode *export_set, short obtype); char *bc_CustomData_get_layer_name(const struct CustomData *data, int type, int n) { int layer_index = CustomData_get_layer_index(data, type); - if (layer_index < 0) - return NULL; + if (layer_index < 0) return NULL; return data->layers[layer_index + n].name; } @@ -148,13 +147,14 @@ char *bc_CustomData_get_active_layer_name(const CustomData *data, int type) { /* get the layer index of the active layer of type */ int layer_index = CustomData_get_active_layer_index(data, type); - if (layer_index < 1) - return NULL; + if (layer_index < 0) return NULL; - return bc_CustomData_get_layer_name(data, type, layer_index-1); + return data->layers[layer_index].name; } -DocumentExporter::DocumentExporter(const ExportSettings *export_settings) : export_settings(export_settings) { +DocumentExporter::DocumentExporter(EvaluationContext *eval_ctx, const ExportSettings *export_settings) : + eval_ctx(eval_ctx), + export_settings(export_settings) { } static COLLADABU::NativeString make_temp_filepath(const char *name, const char *extension) @@ -181,7 +181,8 @@ static COLLADABU::NativeString make_temp_filepath(const char *name, const char * // COLLADA allows this through multiple <channel>s in <animation>. // For this to work, we need to know objects that use a certain action. -int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scene *sce) + +int DocumentExporter::exportCurrentScene(Scene *sce) { PointerRNA sceneptr, unit_settings; PropertyRNA *system; /* unused , *scale; */ @@ -287,7 +288,7 @@ int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scen // <library_geometries> if (bc_has_object_type(export_set, OB_MESH)) { GeometryExporter ge(writer, this->export_settings); - ge.exportGeom(sce); + ge.exportGeom(eval_ctx, sce); } // <library_controllers> @@ -295,7 +296,7 @@ int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scen ControllerExporter controller_exporter(writer, this->export_settings); if (bc_has_object_type(export_set, OB_ARMATURE) || this->export_settings->include_shapekeys) { - controller_exporter.export_controllers(sce); + controller_exporter.export_controllers(eval_ctx, sce); } // <library_visual_scenes> @@ -304,10 +305,10 @@ int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scen if (this->export_settings->include_animations) { // <library_animations> - AnimationExporter ae(writer, this->export_settings); + AnimationExporter ae(eval_ctx, writer, this->export_settings); ae.exportAnimations(sce); } - se.exportScene(sce); + se.exportScene(eval_ctx, sce); // <scene> std::string scene_name(translate_id(id_name(sce))); diff --git a/source/blender/collada/DocumentExporter.h b/source/blender/collada/DocumentExporter.h index 60e5deb0e31..68e1523fbee 100644 --- a/source/blender/collada/DocumentExporter.h +++ b/source/blender/collada/DocumentExporter.h @@ -31,7 +31,7 @@ extern "C" { #include "DNA_customdata_types.h" -#include "BKE_depsgraph.h" + } struct Scene; @@ -39,11 +39,13 @@ struct Scene; class DocumentExporter { public: - DocumentExporter(const ExportSettings *export_settings); - int exportCurrentScene(const EvaluationContext *eval_ctx, Scene *sce); + DocumentExporter(EvaluationContext *eval_ctx, const ExportSettings *export_settings); + int exportCurrentScene(Scene *sce); + void exportScenes(const char *filename); private: const ExportSettings *export_settings; + EvaluationContext *eval_ctx; }; #endif diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index f7fdfb06a40..dfd662aa66c 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -57,12 +57,13 @@ extern "C" { #include "BLI_fileops.h" #include "BKE_camera.h" +#include "BKE_collection.h" #include "BKE_main.h" +#include "BKE_layer.h" #include "BKE_lamp.h" #include "BKE_library.h" #include "BKE_texture.h" #include "BKE_fcurve.h" -#include "BKE_depsgraph.h" #include "BKE_scene.h" #include "BKE_global.h" #include "BKE_material.h" @@ -82,6 +83,9 @@ extern "C" { } +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" + #include "ExtraHandler.h" #include "ErrorHandler.h" #include "DocumentImporter.h" @@ -104,8 +108,9 @@ DocumentImporter::DocumentImporter(bContext *C, const ImportSettings *import_set import_settings(import_settings), mImportStage(General), mContext(C), - armature_importer(&unit_converter, &mesh_importer, CTX_data_scene(C), import_settings), - mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C)), + view_layer(CTX_data_view_layer(mContext)), + armature_importer(&unit_converter, &mesh_importer, CTX_data_scene(C), view_layer, import_settings), + mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C), view_layer), anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C)) { } @@ -130,7 +135,7 @@ bool DocumentImporter::import() loader.registerExtraDataCallbackHandler(ehandler); // deselect all to select new objects - BKE_scene_base_deselect_all(CTX_data_scene(mContext)); + BKE_view_layer_base_deselect_all(view_layer); std::string mFilename = std::string(this->import_settings->filepath); const std::string encodedFilename = bc_url_encode(mFilename); @@ -230,7 +235,7 @@ void DocumentImporter::finish() } // update scene - DAG_relations_tag_update(bmain); + DEG_relations_tag_update(bmain); WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL); } @@ -241,7 +246,7 @@ void DocumentImporter::finish() armature_importer.set_tags_map(this->uid_tags_map); armature_importer.make_armatures(mContext, *objects_to_scale); armature_importer.make_shape_keys(); - DAG_relations_tag_update(bmain); + DEG_relations_tag_update(bmain); #if 0 armature_importer.fix_animation(); @@ -263,19 +268,11 @@ void DocumentImporter::finish() std::vector<Object *>::iterator it; for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) { Object *ob = *it; - - Base *base = BKE_scene_base_find(sce, ob); - if (base) { - BLI_remlink(&sce->base, base); - BKE_libblock_free_us(G.main, base->object); - if (sce->basact == base) - sce->basact = NULL; - MEM_freeN(base); - } + BKE_collections_object_remove(G.main, &sce->id, ob, true); } libnode_ob.clear(); - DAG_relations_tag_update(bmain); + DEG_relations_tag_update(bmain); } bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units); @@ -384,7 +381,7 @@ Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera return NULL; } - Object *ob = bc_add_object(sce, OB_CAMERA, NULL); + Object *ob = bc_add_object(sce, view_layer, OB_CAMERA, NULL); Camera *cam = uid_camera_map[cam_uid]; Camera *old_cam = (Camera *)ob->data; ob->data = cam; @@ -400,7 +397,7 @@ Object *DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce return NULL; } - Object *ob = bc_add_object(sce, OB_LAMP, NULL); + Object *ob = bc_add_object(sce, view_layer, OB_LAMP, NULL); Lamp *la = uid_lamp_map[lamp_uid]; Lamp *old_lamp = (Lamp *)ob->data; ob->data = la; @@ -413,8 +410,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); Object *obn = BKE_object_copy(G.main, source_ob); - DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); - BKE_scene_base_add(sce, obn); + DEG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); + BKE_collection_object_add_from(sce, source_ob, obn); if (instance_node) { anim_importer.read_node_transform(instance_node, obn); @@ -516,7 +513,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA if (parent_node == NULL && !is_library_node) { // A Joint on root level is a skeleton without root node. // Here we add the armature "on the fly": - par = bc_add_object(sce, OB_ARMATURE, std::string("Armature").c_str()); + par = bc_add_object(sce, view_layer, OB_ARMATURE, std::string("Armature").c_str()); objects_done->push_back(par); root_objects->push_back(par); object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), par)); @@ -630,10 +627,10 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA 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. if (is_armature(node)) { - ob = bc_add_object(sce, OB_ARMATURE, name.c_str()); + ob = bc_add_object(sce, view_layer, OB_ARMATURE, name.c_str()); } else { - ob = bc_add_object(sce, OB_EMPTY, NULL); + ob = bc_add_object(sce, view_layer, OB_EMPTY, NULL); } objects_done->push_back(ob); if (parent_node == NULL) { diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h index 62f76dbc022..fd61f3a68da 100644 --- a/source/blender/collada/DocumentImporter.h +++ b/source/blender/collada/DocumentImporter.h @@ -144,6 +144,7 @@ private: ImportStage mImportStage; bContext *mContext; + ViewLayer *view_layer; UnitConverter unit_converter; ArmatureImporter armature_importer; diff --git a/source/blender/collada/EffectExporter.cpp b/source/blender/collada/EffectExporter.cpp index 2bf0859b0f0..5e7f92047d3 100644 --- a/source/blender/collada/EffectExporter.cpp +++ b/source/blender/collada/EffectExporter.cpp @@ -27,6 +27,7 @@ #include <map> +#include <set> #include "COLLADASWEffectProfile.h" #include "COLLADAFWColorOrTexture.h" @@ -43,21 +44,31 @@ extern "C" { #include "DNA_texture_types.h" #include "DNA_world_types.h" + #include "BKE_collection.h" #include "BKE_customdata.h" #include "BKE_mesh.h" #include "BKE_material.h" } -EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryEffects(sw), export_settings(export_settings) { +// OB_MESH is assumed +static std::string getActiveUVLayerName(Object *ob) +{ + Mesh *me = (Mesh *)ob->data; + + int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); + if (num_layers) + return std::string(bc_CustomData_get_active_layer_name(&me->fdata, CD_MTFACE)); + + return ""; } +EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryEffects(sw), export_settings(export_settings) { +} bool EffectsExporter::hasEffects(Scene *sce) { - Base *base = (Base *)sce->base.first; - - while (base) { - Object *ob = base->object; + FOREACH_SCENE_OBJECT(sce, ob) + { int a; for (a = 0; a < ob->totcol; a++) { Material *ma = give_current_material(ob, a + 1); @@ -67,56 +78,20 @@ bool EffectsExporter::hasEffects(Scene *sce) return true; } - base = base->next; } + FOREACH_SCENE_OBJECT_END return false; } void EffectsExporter::exportEffects(Scene *sce) { - this->scene = sce; - - if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) { - if (hasEffects(sce)) { - MaterialFunctor mf; - openLibrary(); - mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set); - closeLibrary(); - } - } - else { - std::set<Object *> uv_textured_obs = bc_getUVTexturedObjects(sce, !this->export_settings->active_uv_only); - std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only); - if (uv_images.size() > 0) { - openLibrary(); - std::set<Image *>::iterator uv_images_iter; - for (uv_images_iter = uv_images.begin(); - uv_images_iter != uv_images.end(); - uv_images_iter++) { - - Image *ima = *uv_images_iter; - std::string key(id_name(ima)); - key = translate_id(key); - COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D, - key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX, - key + COLLADASW::Sampler::SURFACE_SID_SUFFIX); - sampler.setImageId(key); - - openEffect(key + "-effect"); - COLLADASW::EffectProfile ep(mSW); - ep.setProfileType(COLLADASW::EffectProfile::COMMON); - ep.setShaderType(COLLADASW::EffectProfile::PHONG); - ep.setDiffuse(createTexture(ima, key, &sampler), false, "diffuse"); - COLLADASW::ColorOrTexture cot = getcol(0, 0, 0, 1.0f); - ep.setSpecular(cot, false, "specular"); - ep.openProfile(); - ep.addProfileElements(); - ep.addExtraTechniques(mSW); - ep.closeProfile(); - closeEffect(); - } - closeLibrary(); - } + if (hasEffects(sce)) { + this->scene = sce; + openLibrary(); + MaterialFunctor mf; + mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set); + + closeLibrary(); } } @@ -200,7 +175,8 @@ void EffectsExporter::operator()(Material *ma, Object *ob) { // create a list of indices to textures of type TEX_IMAGE std::vector<int> tex_indices; - createTextureIndices(ma, tex_indices); + if (this->export_settings->include_material_textures) + createTextureIndices(ma, tex_indices); openEffect(translate_id(id_name(ma)) + "-effect"); @@ -336,7 +312,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob) // used as fallback when MTex->uvname is "" (this is pretty common) // it is indeed the correct value to use in that case - std::string active_uv(bc_get_active_uvlayer_name(ob)); + std::string active_uv(getActiveUVLayerName(ob)); // write textures // XXX very slow diff --git a/source/blender/collada/EffectExporter.h b/source/blender/collada/EffectExporter.h index 7d45a085777..d20cbfdfe0b 100644 --- a/source/blender/collada/EffectExporter.h +++ b/source/blender/collada/EffectExporter.h @@ -48,6 +48,7 @@ class EffectsExporter: COLLADASW::LibraryEffects public: EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); void exportEffects(Scene *sce); + void operator()(Material *ma, Object *ob); COLLADASW::ColorOrTexture createTexture(Image *ima, diff --git a/source/blender/collada/ExportSettings.h b/source/blender/collada/ExportSettings.h index fa6751bef60..b6a7c1f1b4e 100644 --- a/source/blender/collada/ExportSettings.h +++ b/source/blender/collada/ExportSettings.h @@ -43,10 +43,6 @@ typedef enum BC_export_transformation_type { BC_TRANSFORMATION_TYPE_TRANSROTLOC } BC_export_transformation_type; -typedef enum BC_export_texture_type { - BC_TEXTURE_TYPE_MAT, - BC_TEXTURE_TYPE_UV -} BC_export_texture_type; typedef struct ExportSettings { bool apply_modifiers; @@ -61,7 +57,7 @@ typedef struct ExportSettings { int sampling_rate; bool active_uv_only; - BC_export_texture_type export_texture_type; + bool include_material_textures; bool use_texture_copies; bool triangulate; diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp index 73b00fd07ec..8dbee607b01 100644 --- a/source/blender/collada/GeometryExporter.cpp +++ b/source/blender/collada/GeometryExporter.cpp @@ -52,16 +52,16 @@ extern "C" { #include "collada_internal.h" #include "collada_utils.h" - // TODO: optimize UV sets by making indexed list with duplicates removed GeometryExporter::GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryGeometries(sw), export_settings(export_settings) { } -void GeometryExporter::exportGeom(Scene *sce) +void GeometryExporter::exportGeom(const struct EvaluationContext *eval_ctx, Scene *sce) { openLibrary(); + mEvalCtx = eval_ctx; mScene = sce; GeometryFunctor gf; gf.forEachMeshObjectInExportSet<GeometryExporter>(sce, *this, this->export_settings->export_set); @@ -77,7 +77,7 @@ void GeometryExporter::operator()(Object *ob) #endif bool use_instantiation = this->export_settings->use_object_instantiation; - Mesh *me = bc_get_mesh_copy( mScene, + Mesh *me = bc_get_mesh_copy(mEvalCtx, mScene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, @@ -135,22 +135,13 @@ void GeometryExporter::operator()(Object *ob) // Only create Polylists if number of faces > 0 if (me->totface > 0) { // XXX slow - std::set<Image *> uv_images = bc_getUVImages(ob, !this->export_settings->active_uv_only); - if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT || uv_images.size() == 0) { - if (ob->totcol) { - for (int a = 0; a < ob->totcol; a++) { - createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); - } - } - else { - int i = 0; - createPolylist(i, has_uvs, has_color, ob, me, geom_id, norind); + if (ob->totcol) { + for (int a = 0; a < ob->totcol; a++) { + createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); } } else { - bool all_uv_layers = !this->export_settings->active_uv_only; - std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers); - createPolylists(uv_images, has_uvs, has_color, ob, me, geom_id, norind); + createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind); } } @@ -230,15 +221,13 @@ void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb) //createLooseEdgeList(ob, me, geom_id, norind); // XXX slow - if (ob->totcol && this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) { + if (ob->totcol) { for (int a = 0; a < ob->totcol; a++) { createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); } } else { - bool all_uv_layers = !this->export_settings->active_uv_only; - std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers); - createPolylists(uv_images, has_uvs, has_color, ob, me, geom_id, norind); + createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind); } closeMesh(); @@ -307,44 +296,7 @@ std::string GeometryExporter::makeVertexColorSourceId(std::string& geom_id, char return result; } -static void prepareToAppendValues(bool is_triangulated, COLLADASW::PrimitivesBase *facelist, std::vector<unsigned long> &vcount_list) -{ - // performs the actual writing - if (is_triangulated) { - ((COLLADASW::Triangles *)facelist)->prepareToAppendValues(); - } - else { - // sets <vcount> - facelist->setVCountList(vcount_list); - ((COLLADASW::Polylist *)facelist)-> prepareToAppendValues(); - } -} - -static void finishList(bool is_triangulated, COLLADASW::PrimitivesBase *facelist) -{ - if (is_triangulated) { - ((COLLADASW::Triangles *)facelist)->finish(); - } - else { - ((COLLADASW::Polylist *)facelist)->finish(); - } -} - -COLLADASW::PrimitivesBase *getFacelist(bool is_triangulated, COLLADASW::StreamWriter *mSW) -{ - COLLADASW::PrimitivesBase *facelist; - - if (is_triangulated) - { - facelist = new COLLADASW::Triangles(mSW); - } - else { - facelist = new COLLADASW::Polylist(mSW); - } - return facelist; -} - -// Export meshes with Materials +// powerful because it handles both cases when there is material and when there's not void GeometryExporter::createPolylist(short material_index, bool has_uvs, bool has_color, @@ -362,7 +314,7 @@ void GeometryExporter::createPolylist(short material_index, int i; int faces_in_polylist = 0; std::vector<unsigned long> vcount_list; - bool is_triangulated = true; + // count faces with this material for (i = 0; i < totpolys; i++) { MPoly *p = &mpolys[i]; @@ -370,9 +322,6 @@ void GeometryExporter::createPolylist(short material_index, if (p->mat_nr == material_index) { faces_in_polylist++; vcount_list.push_back(p->totloop); - if (p->totloop != 3) { - is_triangulated = false; - } } } @@ -383,21 +332,20 @@ void GeometryExporter::createPolylist(short material_index, } Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL; - COLLADASW::PrimitivesBase *facelist = getFacelist(is_triangulated, mSW); - + COLLADASW::Polylist polylist(mSW); // sets count attribute in <polylist> - facelist->setCount(faces_in_polylist); + polylist.setCount(faces_in_polylist); // sets material name if (ma) { std::string material_id = get_material_id(ma); std::ostringstream ostr; ostr << translate_id(material_id); - facelist->setMaterial(ostr.str()); + polylist.setMaterial(ostr.str()); } - - COLLADASW::InputList &til = facelist->getInputList(); + + COLLADASW::InputList &til = polylist.getInputList(); // creates <input> in <polylist> for vertices COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); @@ -413,21 +361,13 @@ void GeometryExporter::createPolylist(short material_index, int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE)-1; for (i = 0; i < num_layers; i++) { if (!this->export_settings->active_uv_only || i == active_uv_index) { - - std::string uv_name(bc_get_uvlayer_name(me, i)); - std::string effective_id = geom_id; // (uv_name == "") ? geom_id : uv_name; - std::string layer_id = makeTexcoordSourceId( - effective_id, - i, this->export_settings->active_uv_only); - - /* Note: the third parameter denotes the offset of TEXCOORD in polylist elements - For now this is always 2 (This may change sometime/maybe) - */ + + // char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i); COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD, - makeUrl(layer_id), - 2, // this is only until we have optimized UV sets - (this->export_settings->active_uv_only) ? 0 : i // only_active_uv exported -> we have only one set - ); + makeUrl(makeTexcoordSourceId(geom_id, i, this->export_settings->active_uv_only)), + 2, // this is only until we have optimized UV sets + (this->export_settings->active_uv_only) ? 0 : i // only_active_uv exported -> we have only one set + ); til.push_back(input3); } } @@ -448,10 +388,12 @@ void GeometryExporter::createPolylist(short material_index, } } + // sets <vcount> + polylist.setVCountList(vcount_list); // performs the actual writing - prepareToAppendValues(is_triangulated, facelist, vcount_list); - + polylist.prepareToAppendValues(); + // <p> int texindex = 0; for (i = 0; i < totpolys; i++) { @@ -463,201 +405,20 @@ void GeometryExporter::createPolylist(short material_index, BCPolygonNormalsIndices normal_indices = norind[i]; for (int j = 0; j < loop_count; j++) { - facelist->appendValues(l[j].v); - facelist->appendValues(normal_indices[j]); - if (has_uvs) - facelist->appendValues(texindex + j); - - if (has_color) - facelist->appendValues(texindex + j); - } - } - - texindex += loop_count; - } - - finishList(is_triangulated, facelist); - delete facelist; -} - -void GeometryExporter::createPolylists(std::set<Image *> uv_images, - bool has_uvs, - bool has_color, - Object *ob, - Mesh *me, - std::string& geom_id, - std::vector<BCPolygonNormalsIndices>& norind) -{ - std::set<Image *>::iterator uv_images_iter; - for (uv_images_iter = uv_images.begin(); - uv_images_iter != uv_images.end(); - uv_images_iter++) { - - Image *ima = *uv_images_iter; - std::string imageid(id_name(ima)); - createPolylist(imageid, has_uvs, - has_color, - ob, - me, - geom_id, - norind); - } - - /* We msut add an additional collector for the case when - * some parts of the object are not textured at all. - * The next call creates a polylist for all untextured polygons - */ - - createPolylist("", has_uvs, - has_color, - ob, - me, - geom_id, - norind); - -} - -/* =========================================================================== - * Export Meshes with UV Textures (export as materials, see also in - * effectExporter and MaterialExporter) - * - * If imageid is the empty string, then collect only untextured polygons - * =========================================================================== */ -void GeometryExporter::createPolylist(std::string imageid, - bool has_uvs, - bool has_color, - Object *ob, - Mesh *me, - std::string& geom_id, - std::vector<BCPolygonNormalsIndices>& norind) -{ - - MPoly *mpolys = me->mpoly; - MLoop *mloops = me->mloop; - MTexPoly *mtpolys = me->mtpoly; - - int totpolys = me->totpoly; - - // <vcount> - int i; - int faces_in_polylist = 0; - std::vector<unsigned long> vcount_list; - bool is_triangulated = true; - // count faces with this material - for (i = 0; i < totpolys; i++) { - MTexPoly *tp = &mtpolys[i]; - MPoly *p = &mpolys[i]; - - std::string tpageid = (mtpolys && tp->tpage) ? id_name(tp->tpage) : ""; - if (tpageid == imageid) { - faces_in_polylist++; - vcount_list.push_back(p->totloop); - if (p->totloop != 3) { - is_triangulated = false; - } - } - } - - // no faces using this imageid - if (faces_in_polylist == 0) { - if (imageid != "") - fprintf(stderr, "%s: Image %s is not used.\n", id_name(ob).c_str(), imageid.c_str()); - return; - } - - COLLADASW::PrimitivesBase *facelist = getFacelist(is_triangulated, mSW); - - // sets count attribute in <polylist> - facelist->setCount(faces_in_polylist); - - if (imageid != "") { - // sets material name - std::string material_id = get_material_id_from_id(imageid); - std::ostringstream ostr; - ostr << translate_id(material_id); - facelist->setMaterial(ostr.str()); - } - COLLADASW::InputList &til = facelist->getInputList(); - - // creates <input> in <polylist> for vertices - COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0); - - // creates <input> in <polylist> for normals - COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1); - - til.push_back(input1); - til.push_back(input2); - - // if mesh has uv coords writes <input> for TEXCOORD - int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); - int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1; - for (i = 0; i < num_layers; i++) { - if (!this->export_settings->active_uv_only || i == active_uv_index) { - - std::string uv_name(bc_get_uvlayer_name(me, i)); - std::string effective_id = geom_id; // (uv_name == "") ? geom_id : uv_name; - std::string layer_id = makeTexcoordSourceId( - effective_id, - i, this->export_settings->active_uv_only); - - /* Note: the third parameter denotes the offset of TEXCOORD in polylist elements - For now this is always 2 (This may change sometime/maybe) - */ - COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD, - makeUrl(layer_id), - 2, // this is only until we have optimized UV sets - (this->export_settings->active_uv_only) ? 0 : i // only_active_uv exported -> we have only one set - ); - til.push_back(input3); - } - } - - int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL); - if (totlayer_mcol > 0) { - int map_index = 0; - - for (int a = 0; a < totlayer_mcol; a++) { - char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPCOL, a); - COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR, - makeUrl(makeVertexColorSourceId(geom_id, layer_name)), - (has_uvs) ? 3 : 2, // all color layers have same index order - map_index // set number equals color map index - ); - til.push_back(input4); - map_index++; - } - } - - // performs the actual writing - prepareToAppendValues(is_triangulated, facelist, vcount_list); - - // <p> - int texindex = 0; - for (i = 0; i < totpolys; i++) { - MTexPoly *tp = &mtpolys[i]; - MPoly *p = &mpolys[i]; - int loop_count = p->totloop; - std::string tpageid = (mtpolys && tp->tpage) ? id_name(tp->tpage) : ""; - if (tpageid == imageid) { - MLoop *l = &mloops[p->loopstart]; - BCPolygonNormalsIndices normal_indices = norind[i]; - - for (int j = 0; j < loop_count; j++) { - facelist->appendValues(l[j].v); - facelist->appendValues(normal_indices[j]); + polylist.appendValues(l[j].v); + polylist.appendValues(normal_indices[j]); if (has_uvs) - facelist->appendValues(texindex + j); + polylist.appendValues(texindex + j); if (has_color) - facelist->appendValues(texindex + j); + polylist.appendValues(texindex + j); } } texindex += loop_count; } - - finishList(is_triangulated, facelist); - delete facelist; + + polylist.finish(); } // creates <source> for positions @@ -778,13 +539,7 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me) MLoopUV *mloops = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, a); COLLADASW::FloatSourceF source(mSW); - std::string active_uv_name(bc_get_active_uvlayer_name(me)); - std::string effective_id = geom_id; // (active_uv_name == "") ? geom_id : active_uv_name; - std::string layer_id = makeTexcoordSourceId( - effective_id, - a, - this->export_settings->active_uv_only ); - + std::string layer_id = makeTexcoordSourceId(geom_id, a, this->export_settings->active_uv_only); source.setId(layer_id); source.setArrayId(layer_id + ARRAY_ID_SUFFIX); diff --git a/source/blender/collada/GeometryExporter.h b/source/blender/collada/GeometryExporter.h index 890304f4568..7527195fdd8 100644 --- a/source/blender/collada/GeometryExporter.h +++ b/source/blender/collada/GeometryExporter.h @@ -46,6 +46,8 @@ #include "BKE_key.h" +struct EvaluationContext; + extern Object *bc_get_highest_selected_ancestor_or_self(Object *ob); class Normal @@ -72,12 +74,13 @@ class GeometryExporter : COLLADASW::LibraryGeometries Normal n; + const struct EvaluationContext *mEvalCtx; Scene *mScene; public: GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); - void exportGeom(Scene *sce); + void exportGeom(const struct EvaluationContext *eval_ctx, Scene *sce); void operator()(Object *ob); @@ -85,33 +88,15 @@ public: Mesh *me, std::string& geom_id); - // Create polylists for meshes with Materials + // powerful because it handles both cases when there is material and when there's not void createPolylist(short material_index, - bool has_uvs, - bool has_color, - Object *ob, - Mesh *me, - std::string& geom_id, - std::vector<BCPolygonNormalsIndices>& norind); - - // Create polylists for meshes with UV Textures - void createPolylists(std::set<Image *> uv_images, - bool has_uvs, - bool has_color, - Object *ob, - Mesh *me, - std::string& geom_id, - std::vector<BCPolygonNormalsIndices>& norind); - - // Create polylists for meshes with UV Textures - void createPolylist(std::string imageid, - bool has_uvs, - bool has_color, - Object *ob, - Mesh *me, - std::string& geom_id, - std::vector<BCPolygonNormalsIndices>& norind); - + bool has_uvs, + bool has_color, + Object *ob, + Mesh *me, + std::string& geom_id, + std::vector<BCPolygonNormalsIndices>& norind); + // creates <source> for positions void createVertsSource(std::string geom_id, Mesh *me); diff --git a/source/blender/collada/ImageExporter.cpp b/source/blender/collada/ImageExporter.cpp index 93be7de6236..a2ab3ce520b 100644 --- a/source/blender/collada/ImageExporter.cpp +++ b/source/blender/collada/ImageExporter.cpp @@ -55,9 +55,9 @@ ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw, const ExportSettings void ImagesExporter::export_UV_Image(Image *image, bool use_copies) { - std::string id(id_name(image)); - std::string translated_id(translate_id(id)); - bool not_yet_exported = find(mImages.begin(), mImages.end(), translated_id) == mImages.end(); + std::string name(id_name(image)); + std::string translated_name(translate_id(name)); + bool not_yet_exported = find(mImages.begin(), mImages.end(), translated_name) == mImages.end(); if (not_yet_exported) { @@ -88,7 +88,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) // make absolute destination path - BLI_strncpy(export_file, id.c_str(), sizeof(export_file)); + BLI_strncpy(export_file, name.c_str(), sizeof(export_file)); BKE_image_path_ensure_ext_from_imformat(export_file, &imageFormat); BLI_join_dirfile(export_path, sizeof(export_path), export_dir, export_file); @@ -143,60 +143,15 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) } } - /* set name also to mNameNC. This helps other viewers import files exported from Blender better */ - COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(export_path)), translated_id, translated_id); + COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(export_path)), translated_name, translated_name); /* set name also to mNameNC. This helps other viewers import files exported from Blender better */ img.add(mSW); fprintf(stdout, "Collada export: Added image: %s\n", export_file); - mImages.push_back(translated_id); + mImages.push_back(translated_name); BKE_image_release_ibuf(image, imbuf, NULL); } } -void ImagesExporter::export_UV_Images() -{ - std::set<Image *> uv_textures; - LinkNode *node; - bool use_texture_copies = this->export_settings->use_texture_copies; - bool active_uv_only = this->export_settings->active_uv_only; - - for (node = this->export_settings->export_set; node; node = node->next) { - Object *ob = (Object *)node->link; - if (ob->type == OB_MESH) { - Mesh *me = (Mesh *) ob->data; - BKE_mesh_tessface_ensure(me); - int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY); - for (int i = 0; i < me->pdata.totlayer; i++) { - if (me->pdata.layers[i].type == CD_MTEXPOLY) { - if (!active_uv_only || active_uv_layer == i) - { - MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data; - for (int j = 0; j < me->totpoly; j++, txface++) { - - Image *ima = txface->tpage; - if (ima == NULL) - continue; - - bool not_in_list = uv_textures.find(ima) == uv_textures.end(); - if (not_in_list) { - uv_textures.insert(ima); - export_UV_Image(ima, use_texture_copies); - } - } - } - } - } - } - } -} - -/* ============================================================ - * Check if there are any images to be exported - * Returns true as soon as an object is detected that - * either has an UV Texture assigned, or has a material - * assigned that uses an Image Texture. - * ============================================================ - */ bool ImagesExporter::hasImages(Scene *sce) { LinkNode *node; @@ -216,20 +171,6 @@ bool ImagesExporter::hasImages(Scene *sce) } } - if (ob->type == OB_MESH) { - Mesh *me = (Mesh *) ob->data; - BKE_mesh_tessface_ensure(me); - bool has_uvs = (bool)CustomData_has_layer(&me->fdata, CD_MTFACE); - if (has_uvs) { - int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE); - for (int a = 0; a < num_layers; a++) { - MTFace *tface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, a); - Image *img = tface->tpage; - if (img) return true; - } - } - } - } return false; } @@ -239,12 +180,9 @@ void ImagesExporter::exportImages(Scene *sce) openLibrary(); MaterialFunctor mf; - if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) { + if (this->export_settings->include_material_textures) { mf.forEachMaterialInExportSet<ImagesExporter>(sce, *this, this->export_settings->export_set); } - else { - export_UV_Images(); - } closeLibrary(); } diff --git a/source/blender/collada/ImageExporter.h b/source/blender/collada/ImageExporter.h index 0eaebdd5cdd..f3dd2b336e4 100644 --- a/source/blender/collada/ImageExporter.h +++ b/source/blender/collada/ImageExporter.h @@ -51,7 +51,6 @@ public: private: std::vector<std::string> mImages; // contains list of written images, to avoid duplicates - void export_UV_Images(); void export_UV_Image(Image *image, bool use_texture_copies); bool hasImages(Scene *sce); const ExportSettings *export_settings; diff --git a/source/blender/collada/InstanceWriter.cpp b/source/blender/collada/InstanceWriter.cpp index de1a4075462..71371d280df 100644 --- a/source/blender/collada/InstanceWriter.cpp +++ b/source/blender/collada/InstanceWriter.cpp @@ -32,76 +32,43 @@ #include "COLLADASWInstanceMaterial.h" extern "C" { -#include "BKE_customdata.h" -#include "BKE_material.h" -#include "DNA_mesh_types.h" + #include "BKE_customdata.h" + #include "BKE_material.h" + #include "DNA_mesh_types.h" } #include "InstanceWriter.h" #include "collada_internal.h" #include "collada_utils.h" -void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only, BC_export_texture_type export_texture_type) +void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only) { - bool all_uv_layers = !active_uv_only; - COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList(); + for (int a = 0; a < ob->totcol; a++) { + Material *ma = give_current_material(ob, a + 1); + + COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList(); - if (export_texture_type == BC_TEXTURE_TYPE_UV) - { - std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers); - std::set<Image *>::iterator uv_images_iter; - for (uv_images_iter = uv_images.begin(); - uv_images_iter != uv_images.end(); - uv_images_iter++) { - Image *ima = *uv_images_iter; - std::string matid(id_name(ima)); - matid = get_material_id_from_id(matid); + if (ma) { + std::string matid(get_material_id(ma)); + matid = translate_id(matid); std::ostringstream ostr; ostr << matid; COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid)); - + // create <bind_vertex_input> for each uv map Mesh *me = (Mesh *)ob->data; int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE); - + int map_index = 0; - int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1; + int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) -1; for (int b = 0; b < totlayer; b++) { if (!active_uv_only || b == active_uv_index) { char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b); im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++)); } } - + iml.push_back(im); } } - - else { - for (int a = 0; a < ob->totcol; a++) { - Material *ma = give_current_material(ob, a + 1); - if (ma) { - std::string matid(get_material_id(ma)); - matid = translate_id(matid); - std::ostringstream ostr; - ostr << matid; - COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid)); - - // create <bind_vertex_input> for each uv map - Mesh *me = (Mesh *)ob->data; - int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE); - - int map_index = 0; - int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1; - for (int b = 0; b < totlayer; b++) { - if (!active_uv_only || b == active_uv_index) { - char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b); - im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++)); - } - } - - iml.push_back(im); - } - } - } } diff --git a/source/blender/collada/InstanceWriter.h b/source/blender/collada/InstanceWriter.h index a46027325a2..49ddf091b1c 100644 --- a/source/blender/collada/InstanceWriter.h +++ b/source/blender/collada/InstanceWriter.h @@ -31,12 +31,11 @@ #include "COLLADASWBindMaterial.h" #include "DNA_object_types.h" -#include "collada.h" class InstanceWriter { protected: - void add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only, BC_export_texture_type export_texture_type); + void add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only); }; #endif diff --git a/source/blender/collada/MaterialExporter.cpp b/source/blender/collada/MaterialExporter.cpp index 6e6cc24be20..4aece997f72 100644 --- a/source/blender/collada/MaterialExporter.cpp +++ b/source/blender/collada/MaterialExporter.cpp @@ -38,39 +38,14 @@ MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw, const ExportSe void MaterialsExporter::exportMaterials(Scene *sce) { - if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) - { - if (hasMaterials(sce)) { - openLibrary(); + if (hasMaterials(sce)) { + openLibrary(); - MaterialFunctor mf; - mf.forEachMaterialInExportSet<MaterialsExporter>(sce, *this, this->export_settings->export_set); + MaterialFunctor mf; + mf.forEachMaterialInExportSet<MaterialsExporter>(sce, *this, this->export_settings->export_set); - closeLibrary(); - } + closeLibrary(); } - - else { - std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only); - if (uv_images.size() > 0) { - openLibrary(); - std::set<Image *>::iterator uv_images_iter; - for (uv_images_iter = uv_images.begin(); - uv_images_iter != uv_images.end(); - uv_images_iter++) { - - Image *ima = *uv_images_iter; - std::string matid(id_name(ima)); - - openMaterial(get_material_id_from_id(matid), translate_id(matid)); - std::string efid = translate_id(matid) + "-effect"; - addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, efid)); - closeMaterial(); - } - closeLibrary(); - } - } - } bool MaterialsExporter::hasMaterials(Scene *sce) diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index 6ca53c64299..f8cd487c355 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -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, Scene *sce, ViewLayer *view_layer): + unitconverter(unitconv), + scene(sce), + view_layer(view_layer), + armature_importer(arm) { } bool MeshImporter::set_poly_indices(MPoly *mpoly, MLoop *mloop, int loop_index, unsigned int *indices, int loop_count) @@ -472,11 +476,9 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me) COLLADAFW::MeshVertexData::InputInfos *info = collada_mesh->getUVCoords().getInputInfosArray()[i]; COLLADAFW::String &uvname = info->mName; // Allocate space for UV_data - CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, uvname.c_str()); CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, me->totloop, uvname.c_str()); } // activate the first uv map - me->mtpoly = (MTexPoly *)CustomData_get_layer_n(&me->pdata, CD_MTEXPOLY, 0); me->mloopuv = (MLoopUV *) CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, 0); } @@ -1051,11 +1053,11 @@ void MeshImporter::optimize_material_assignements() * which materials shall be moved to the created geometries. Also see * optimize_material_assignements() above. */ -MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial, - std::map<COLLADAFW::UniqueId, Material *>& uid_material_map, - Object *ob, const COLLADAFW::UniqueId *geom_uid, - char *layername, MTFace *texture_face, - std::map<Material *, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index) +void MeshImporter::assign_material_to_geom( + COLLADAFW::MaterialBinding cmaterial, + std::map<COLLADAFW::UniqueId, Material *>& uid_material_map, + Object *ob, const COLLADAFW::UniqueId *geom_uid, + std::map<Material *, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index) { MTex *color_texture = NULL; Mesh *me = (Mesh *)ob->data; @@ -1065,7 +1067,7 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri if (uid_material_map.find(ma_uid) == uid_material_map.end()) { fprintf(stderr, "Cannot find material by UID.\n"); - return NULL; + return; } // first time we get geom_uid, ma_uid pair. Save for later check. @@ -1089,15 +1091,6 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri color_texture); } - // set texture face - if (color_texture && - strlen((color_texture)->uvname) && - !STREQ(layername, color_texture->uvname)) { - texture_face = (MTFace *)CustomData_get_layer_named(&me->fdata, CD_MTFACE, - color_texture->uvname); - strcpy(layername, color_texture->uvname); - } - MaterialIdPrimitiveArrayMap& mat_prim_map = geom_uid_mat_mapping_map[*geom_uid]; COLLADAFW::MaterialId mat_id = cmaterial.getMaterialId(); @@ -1114,15 +1107,9 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri for (i = 0; i < prim.totpoly; i++, mpoly++) { mpoly->mat_nr = mat_index; - // bind texture images to faces - if (texture_face && color_texture) { - texture_face->tpage = (Image *)color_texture->tex->ima; - texture_face++; - } } } } - return texture_face; } Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom, @@ -1158,7 +1145,7 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta const char *name = (id.length()) ? id.c_str() : NULL; // add object - Object *ob = bc_add_object(scene, OB_MESH, name); + Object *ob = bc_add_object(scene, view_layer, OB_MESH, name); bc_set_mark(ob); // used later for material assignement optimization @@ -1176,10 +1163,6 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta id_us_plus(&old_mesh->id); /* Because BKE_mesh_assign_object would have already decreased it... */ BKE_libblock_free_us(G.main, old_mesh); - char layername[100]; - layername[0] = '\0'; - MTFace *texture_face = NULL; - COLLADAFW::MaterialBindingArray& mat_array = geom->getMaterialBindings(); @@ -1187,9 +1170,9 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta for (unsigned int i = 0; i < mat_array.getCount(); i++) { if (mat_array[i].getReferencedMaterial().isValid()) { - texture_face = assign_material_to_geom(mat_array[i], uid_material_map, ob, geom_uid, - layername, texture_face, - material_texture_mapping_map, i); + assign_material_to_geom( + mat_array[i], uid_material_map, ob, geom_uid, + material_texture_mapping_map, i); } else { fprintf(stderr, "invalid referenced material for %s\n", mat_array[i].getName().c_str()); diff --git a/source/blender/collada/MeshImporter.h b/source/blender/collada/MeshImporter.h index d6426fbaf56..f57f57e07a7 100644 --- a/source/blender/collada/MeshImporter.h +++ b/source/blender/collada/MeshImporter.h @@ -92,6 +92,8 @@ private: UnitConverter *unitconverter; Scene *scene; + ViewLayer *view_layer; + ArmatureImporter *armature_importer; std::map<std::string, std::string> mesh_geom_map; // needed for correct shape key naming @@ -159,7 +161,7 @@ private: public: - MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce); + MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce, ViewLayer *view_layer); virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid); @@ -171,11 +173,11 @@ public: void optimize_material_assignements(); - MTFace *assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial, - std::map<COLLADAFW::UniqueId, Material*>& uid_material_map, - Object *ob, const COLLADAFW::UniqueId *geom_uid, - char *layername, MTFace *texture_face, - std::map<Material*, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index); + void assign_material_to_geom( + COLLADAFW::MaterialBinding cmaterial, + std::map<COLLADAFW::UniqueId, Material*>& uid_material_map, + Object *ob, const COLLADAFW::UniqueId *geom_uid, + std::map<Material*, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index); Object *create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom, diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp index 5a0badf8d3a..3a6386a8721 100644 --- a/source/blender/collada/SceneExporter.cpp +++ b/source/blender/collada/SceneExporter.cpp @@ -26,6 +26,7 @@ extern "C" { #include "BLI_utildefines.h" + #include "BKE_group.h" #include "BKE_object.h" #include "BLI_listbase.h" } @@ -38,17 +39,17 @@ SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, { } -void SceneExporter::exportScene(Scene *sce) +void SceneExporter::exportScene(const EvaluationContext *eval_ctx, Scene *sce) { // <library_visual_scenes> <visual_scene> std::string id_naming = id_name(sce); openVisualScene(translate_id(id_naming), id_naming); - exportHierarchy(sce); + exportHierarchy(eval_ctx, sce); closeVisualScene(); closeLibrary(); } -void SceneExporter::exportHierarchy(Scene *sce) +void SceneExporter::exportHierarchy(const EvaluationContext *eval_ctx, Scene *sce) { LinkNode *node; std::vector<Object *> base_objects; @@ -80,13 +81,13 @@ void SceneExporter::exportHierarchy(Scene *sce) Object *ob = base_objects[index]; if (bc_is_marked(ob)) { bc_remove_mark(ob); - writeNodes(ob, sce); + writeNodes(eval_ctx, ob, sce); } } } -void SceneExporter::writeNodes(Object *ob, Scene *sce) +void SceneExporter::writeNodes(const EvaluationContext *eval_ctx, Object *ob, Scene *sce) { // Add associated armature first if available bool armature_exported = false; @@ -95,7 +96,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce) armature_exported = bc_is_in_Export_set(this->export_settings->export_set, ob_arm); if (armature_exported && bc_is_marked(ob_arm)) { bc_remove_mark(ob_arm); - writeNodes(ob_arm, sce); + writeNodes(eval_ctx, ob_arm, sce); armature_exported = true; } } @@ -146,10 +147,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce) COLLADASW::InstanceGeometry instGeom(mSW); instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, this->export_settings->use_object_instantiation))); instGeom.setName(translate_id(id_name(ob))); - InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), - ob, - this->export_settings->active_uv_only, - this->export_settings->export_texture_type); + InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), ob, this->export_settings->active_uv_only); instGeom.add(); } @@ -157,7 +155,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce) // <instance_controller> else if (ob->type == OB_ARMATURE) { - arm_exporter->add_armature_bones(ob, sce, this, child_objects); + arm_exporter->add_armature_bones(eval_ctx, ob, sce, this, child_objects); } // <instance_camera> @@ -175,12 +173,13 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce) // empty object else if (ob->type == OB_EMPTY) { // TODO: handle groups (OB_DUPLIGROUP if ((ob->transflag & OB_DUPLIGROUP) == OB_DUPLIGROUP && ob->dup_group) { - GroupObject *go = NULL; - Group *gr = ob->dup_group; - /* printf("group detected '%s'\n", gr->id.name + 2); */ - for (go = (GroupObject *)(gr->gobject.first); go; go = go->next) { - printf("\t%s\n", go->ob->id.name); + Group *group = ob->dup_group; + /* printf("group detected '%s'\n", group->id.name + 2); */ + FOREACH_GROUP_OBJECT(group, object) + { + printf("\t%s\n", object->id.name); } + FOREACH_GROUP_OBJECT_END } } @@ -235,7 +234,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce) for (std::list<Object *>::iterator i = child_objects.begin(); i != child_objects.end(); ++i) { if (bc_is_marked(*i)) { bc_remove_mark(*i); - writeNodes(*i, sce); + writeNodes(eval_ctx, *i, sce); } } diff --git a/source/blender/collada/SceneExporter.h b/source/blender/collada/SceneExporter.h index b896b9abd8d..3e3c15b836f 100644 --- a/source/blender/collada/SceneExporter.h +++ b/source/blender/collada/SceneExporter.h @@ -96,12 +96,12 @@ class SceneExporter: COLLADASW::LibraryVisualScenes, protected TransformWriter, { public: SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings); - void exportScene(Scene *sce); + void exportScene(const EvaluationContext *eval_ctx, Scene *sce); private: friend class ArmatureExporter; - void exportHierarchy(Scene *sce); - void writeNodes(Object *ob, Scene *sce); + void exportHierarchy(const struct EvaluationContext *eval_ctx, Scene *sce); + void writeNodes(const struct EvaluationContext *eval_ctx, Object *ob, Scene *sce); ArmatureExporter *arm_exporter; const ExportSettings *export_settings; diff --git a/source/blender/collada/SkinInfo.cpp b/source/blender/collada/SkinInfo.cpp index c48c060dc95..24b47f8db3c 100644 --- a/source/blender/collada/SkinInfo.cpp +++ b/source/blender/collada/SkinInfo.cpp @@ -159,9 +159,9 @@ void SkinInfo::set_controller(const COLLADAFW::SkinController *co) } // called from write_controller -Object *SkinInfo::create_armature(Scene *scene) +Object *SkinInfo::create_armature(Scene *scene, ViewLayer *view_layer) { - ob_arm = bc_add_object(scene, OB_ARMATURE, NULL); + ob_arm = bc_add_object(scene, view_layer, OB_ARMATURE, NULL); return ob_arm; } @@ -227,7 +227,7 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - ModifierData *md = ED_object_modifier_add(NULL, bmain, scene, ob, NULL, eModifierType_Armature); + ModifierData *md = ED_object_modifier_add(NULL, bmain, scene, ob, OB_MODE_OBJECT, NULL, eModifierType_Armature); ArmatureModifierData *amd = (ArmatureModifierData *)md; amd->object = ob_arm; @@ -241,9 +241,9 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique BKE_object_workob_calc_parent(scene, ob, &workob); invert_m4_m4(ob->parentinv, workob.obmat); - DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA); + DEG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA); - DAG_relations_tag_update(bmain); + DEG_relations_tag_update(bmain); WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); #endif copy_m4_m4(ob->obmat, bind_shape_matrix); diff --git a/source/blender/collada/SkinInfo.h b/source/blender/collada/SkinInfo.h index e074f59cffc..a399bff9e3c 100644 --- a/source/blender/collada/SkinInfo.h +++ b/source/blender/collada/SkinInfo.h @@ -99,7 +99,7 @@ public: void set_controller(const COLLADAFW::SkinController* co); // called from write_controller - Object *create_armature(Scene *scene); + Object *create_armature(Scene *scene, ViewLayer *view_layer); Object* set_armature(Object *ob_arm); diff --git a/source/blender/collada/TransformWriter.cpp b/source/blender/collada/TransformWriter.cpp index b7eeff3b074..84817d76073 100644 --- a/source/blender/collada/TransformWriter.cpp +++ b/source/blender/collada/TransformWriter.cpp @@ -61,7 +61,8 @@ void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[4][4], } } -void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob, BC_export_transformation_type transformation_type) +void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob, + BC_export_transformation_type transformation_type) { #if 0 float rot[3], loc[3], scale[3]; diff --git a/source/blender/collada/TransformWriter.h b/source/blender/collada/TransformWriter.h index 5bb13d4aac9..580430911f7 100644 --- a/source/blender/collada/TransformWriter.h +++ b/source/blender/collada/TransformWriter.h @@ -41,7 +41,8 @@ class TransformWriter protected: void add_node_transform(COLLADASW::Node& node, float mat[4][4], float parent_mat[4][4]); - void add_node_transform_ob(COLLADASW::Node& node, Object *ob, BC_export_transformation_type transformation_type); + void add_node_transform_ob(COLLADASW::Node& node, Object *ob, + BC_export_transformation_type transformation_type); void add_node_transform_identity(COLLADASW::Node& node); diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp index 3794b6aefac..64e3a4c36ce 100644 --- a/source/blender/collada/collada.cpp +++ b/source/blender/collada/collada.cpp @@ -32,11 +32,13 @@ #include "DocumentImporter.h" #include "ExportSettings.h" #include "ImportSettings.h" +#include "collada.h" extern "C" { #include "BKE_scene.h" #include "BKE_context.h" +#include "DEG_depsgraph.h" /* make dummy file */ #include "BLI_fileops.h" @@ -52,13 +54,15 @@ int collada_export(EvaluationContext *eval_ctx, Scene *sce, ExportSettings *export_settings) { + ViewLayer *view_layer = eval_ctx->view_layer; int includeFilter = OB_REL_NONE; if (export_settings->include_armatures) includeFilter |= OB_REL_MOD_ARMATURE; if (export_settings->include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE; eObjectSet objectSet = (export_settings->selected) ? OB_SET_SELECTED : OB_SET_ALL; - export_settings->export_set = BKE_object_relational_superset(sce, objectSet, (eObRelationTypes)includeFilter); + export_settings->export_set = BKE_object_relational_superset(view_layer, objectSet, (eObRelationTypes)includeFilter); + int export_count = BLI_linklist_count(export_settings->export_set); if (export_count == 0) { @@ -74,8 +78,8 @@ int collada_export(EvaluationContext *eval_ctx, bc_bubble_sort_by_Object_name(export_settings->export_set); } - DocumentExporter exporter(export_settings); - int status = exporter.exportCurrentScene(eval_ctx, sce); + DocumentExporter exporter(eval_ctx, export_settings); + int status = exporter.exportCurrentScene(sce); BLI_linklist_free(export_settings->export_set, NULL); diff --git a/source/blender/collada/collada.h b/source/blender/collada/collada.h index 312f11d4ba9..f95fca03b65 100644 --- a/source/blender/collada/collada.h +++ b/source/blender/collada/collada.h @@ -36,15 +36,14 @@ extern "C" { #endif -#include "BKE_depsgraph.h" #include "BLI_linklist.h" #include "BLI_path_util.h" #include "RNA_types.h" - -struct EvaluationContext; struct bContext; struct Scene; +struct ViewLayer; +struct EvaluationContext; /* * both return 1 on success, 0 on error @@ -52,6 +51,7 @@ struct Scene; int collada_import(struct bContext *C, ImportSettings *import_settings); + int collada_export(struct EvaluationContext *eval_ctx, struct Scene *sce, ExportSettings *export_settings); diff --git a/source/blender/collada/collada_internal.cpp b/source/blender/collada/collada_internal.cpp index 8974acb3460..6ebde6bd773 100644 --- a/source/blender/collada/collada_internal.cpp +++ b/source/blender/collada/collada_internal.cpp @@ -344,13 +344,7 @@ std::string get_camera_id(Object *ob) std::string get_material_id(Material *mat) { - std::string id = id_name(mat); - return get_material_id_from_id(id); -} - -std::string get_material_id_from_id(std::string id) -{ - return translate_id(id) + "-material"; + return translate_id(id_name(mat)) + "-material"; } std::string get_morph_id(Object *ob) diff --git a/source/blender/collada/collada_internal.h b/source/blender/collada/collada_internal.h index 5f3fa34edc1..1c7aa160f57 100644 --- a/source/blender/collada/collada_internal.h +++ b/source/blender/collada/collada_internal.h @@ -103,7 +103,6 @@ extern std::string get_joint_sid(Bone *bone, Object *ob_arm); extern std::string get_camera_id(Object *ob); extern std::string get_material_id(Material *mat); -extern std::string get_material_id_from_id(std::string id); extern std::string get_morph_id(Object *ob); diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index fcd92e220c0..cc18cea662a 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -47,9 +47,9 @@ extern "C" { #include "BKE_context.h" #include "BKE_customdata.h" -#include "BKE_depsgraph.h" #include "BKE_object.h" #include "BKE_global.h" +#include "BKE_layer.h" #include "BKE_mesh.h" #include "BKE_scene.h" #include "BKE_DerivedMesh.h" @@ -64,6 +64,8 @@ extern "C" { #include "bmesh_tools.h" } +#include "DEG_depsgraph.h" + #include "collada_utils.h" #include "ExportSettings.h" @@ -95,6 +97,9 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) { Object workob; Scene *sce = CTX_data_scene(C); + EvaluationContext eval_ctx; + + CTX_data_eval_ctx(C, &eval_ctx); if (!par || bc_test_parent_loop(par, ob)) return false; @@ -107,7 +112,7 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) if (is_parent_space) { float mat[4][4]; // calc par->obmat - BKE_object_where_is_calc(sce, par); + BKE_object_where_is_calc(&eval_ctx, sce, par); // move child obmat into world space mul_m4_m4m4(mat, par->obmat, ob->obmat); @@ -118,21 +123,26 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) BKE_object_apply_mat4(ob, ob->obmat, 0, 0); // compute parentinv - BKE_object_workob_calc_parent(sce, ob, &workob); + BKE_object_workob_calc_parent(&eval_ctx, sce, ob, &workob); invert_m4_m4(ob->parentinv, workob.obmat); - DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA); - DAG_id_tag_update(&par->id, OB_RECALC_OB); + DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA); + DEG_id_tag_update(&par->id, OB_RECALC_OB); /** done once after import */ #if 0 - DAG_relations_tag_update(bmain); + DEG_relations_tag_update(bmain); WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL); #endif return true; } +Scene *bc_get_scene(bContext *C) +{ + return CTX_data_scene(C); +} + Main *bc_get_main() { return G.main; @@ -144,28 +154,32 @@ EvaluationContext *bc_get_evaluation_context() return bmain->eval_ctx; } -void bc_update_scene(Scene *scene, float ctime) + +void bc_update_scene(EvaluationContext *eval_ctx, Scene *scene, float ctime) { BKE_scene_frame_set(scene, ctime); Main *bmain = bc_get_main(); - EvaluationContext *ev_context = bc_get_evaluation_context(); - BKE_scene_update_for_newframe(ev_context, bmain, scene, scene->lay); + BKE_scene_graph_update_for_newframe(eval_ctx, eval_ctx->depsgraph, bmain, scene, eval_ctx->view_layer); } -Object *bc_add_object(Scene *scene, int type, const char *name) +Object *bc_add_object(Scene *scene, ViewLayer *view_layer, int type, const char *name) { Object *ob = BKE_object_add_only_object(G.main, type, name); ob->data = BKE_object_obdata_add_from_type(G.main, type, name); ob->lay = scene->lay; - DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); + DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); - BKE_scene_base_select(scene, BKE_scene_base_add(scene, ob)); + LayerCollection *layer_collection = BKE_layer_collection_get_active_ensure(scene, view_layer); + BKE_collection_object_add(&scene->id, layer_collection->scene_collection, ob); + + Base *base = BKE_view_layer_base_find(view_layer, ob); + BKE_view_layer_base_select(view_layer, base); 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(const struct EvaluationContext *eval_ctx, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate) { Mesh *tmpmesh; CustomDataMask mask = CD_MASK_MESH; @@ -175,12 +189,12 @@ Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh switch (export_mesh_type) { case BC_MESH_TYPE_VIEW: { - dm = mesh_create_derived_view(scene, ob, mask); + dm = mesh_create_derived_view(eval_ctx, scene, ob, mask); break; } case BC_MESH_TYPE_RENDER: { - dm = mesh_create_derived_render(scene, ob, mask); + dm = mesh_create_derived_render(eval_ctx, scene, ob, mask); break; } } @@ -907,16 +921,6 @@ void bc_copy_farray_m4(float *r, float a[4][4]) } /* -* Returns name of Active UV Layer or empty String if no active UV Layer defined. -* Assuming the Object is of type MESH -*/ -std::string bc_get_active_uvlayer_name(Object *ob) -{ - Mesh *me = (Mesh *)ob->data; - return bc_get_active_uvlayer_name(me); -} - -/* * Returns name of Active UV Layer or empty String if no active UV Layer defined */ std::string bc_get_active_uvlayer_name(Mesh *me) @@ -932,6 +936,16 @@ std::string bc_get_active_uvlayer_name(Mesh *me) } /* +* Returns name of Active UV Layer or empty String if no active UV Layer defined. +* Assuming the Object is of type MESH +*/ +std::string bc_get_active_uvlayer_name(Object *ob) +{ + Mesh *me = (Mesh *)ob->data; + return bc_get_active_uvlayer_name(me); +} + +/* * Returns UV Layer name or empty string if layer index is out of range */ std::string bc_get_uvlayer_name(Mesh *me, int layer) @@ -946,6 +960,7 @@ std::string bc_get_uvlayer_name(Mesh *me, int layer) return ""; } +#if 0 /********************************************************************** * * Return the list of Mesh objects with assigned UVtextures and Images @@ -1066,4 +1081,5 @@ std::set<Image *> bc_getUVImages(Object *ob, bool all_uv_layers) } } return UVImages; -}
\ No newline at end of file +} +#endif diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h index 0069b4d4871..52767557397 100644 --- a/source/blender/collada/collada_utils.h +++ b/source/blender/collada/collada_utils.h @@ -34,7 +34,6 @@ #include <vector> #include <map> -#include <set> #include <algorithm> extern "C" { @@ -61,17 +60,20 @@ extern "C" { #include "ExportSettings.h" #include "collada_internal.h" +struct EvaluationContext; + typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex *> > TexIndexTextureArrayMap; +extern Scene *bc_get_scene(bContext *C); extern Main *bc_get_main(); extern EvaluationContext *bc_get_evaluation_context(); -extern void bc_update_scene(Scene *scene, float ctime); +extern void bc_update_scene(EvaluationContext *eval_ctx, Scene *scene, float ctime); 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_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 Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate); +extern Object *bc_add_object(Scene *scene, ViewLayer *view_layer, int type, const char *name); +extern Mesh *bc_get_mesh_copy(const struct EvaluationContext *eval_ctx, 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_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob); @@ -123,14 +125,6 @@ extern bool bc_get_property_matrix(Bone *bone, std::string key, float mat[4][4]) extern void bc_create_restpose_mat(const ExportSettings *export_settings, Bone *bone, float to_mat[4][4], float world[4][4], bool use_local_space); -extern std::string bc_get_active_uvlayer_name(Object *ob); -extern std::string bc_get_active_uvlayer_name(Mesh *me); -extern std::string bc_get_uvlayer_name(Mesh *me, int layer); - -extern std::set<Image *> bc_getUVImages(Scene *sce, bool all_uv_layers); -extern std::set<Image *> bc_getUVImages(Object *ob, bool all_uv_layers); -extern std::set<Object *> bc_getUVTexturedObjects(Scene *sce, bool all_uv_layers); - class BCPolygonNormalsIndices { std::vector<unsigned int> normal_indices; |