diff options
Diffstat (limited to 'source/blender/collada')
39 files changed, 351 insertions, 1214 deletions
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index bf371332fd0..95298986f5a 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -214,7 +214,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(depsgraph, scene, *ctime); BKE_object_matrix_local_get(ob, fmat); if (this->export_settings->limit_precision) bc_sanitize_mat(fmat, 6); @@ -246,7 +246,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(depsgraph, scene, *ctime); BKE_object_matrix_local_get(ob, fmat); mat4_decompose(floc, fquat, fsize, fmat); quat_to_eul(feul, fquat); @@ -721,7 +721,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(depsgraph, scene, ob_arm); } if (fra.size()) { @@ -730,7 +730,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(depsgraph, scene, ob_arm); } void AnimationExporter::dae_baked_animation(std::vector<float> &fra, Object *ob_arm, Bone *bone) @@ -1004,7 +1004,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); + BKE_animsys_evaluate_animdata(depsgraph, scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL); ListBase *conlist = get_active_constraints(ob); bConstraint *con; for (con = (bConstraint *)conlist->first; con; con = con->next) { @@ -1020,8 +1020,8 @@ void AnimationExporter::evaluate_anim_with_constraints(Object *ob, float ctime) obtar = ct->tar; 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_animsys_evaluate_animdata(depsgraph, scene, &obtar->id, obtar->adt, ctime, ADT_RECALC_ANIM); + BKE_object_where_is_calc_time(this->depsgraph, scene, obtar, ctime); } } @@ -1029,7 +1029,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->depsgraph, scene, ob, ctime); } /* @@ -1315,15 +1315,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(depsgraph, 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_animsys_evaluate_animdata(depsgraph, scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL); + BKE_pose_where_is(depsgraph, scene, ob); } else { - BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1); + BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1); } // compute bone local mat @@ -1841,7 +1842,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(depsgraph, scene, ob_arm); } //v array will hold all values which will be exported. if (fra.size()) { @@ -1871,7 +1872,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(depsgraph, scene, ob_arm); } void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pchan) @@ -1895,8 +1896,8 @@ void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, i float ctime = BKE_scene_frame_get_from_ctime(scene, *it); - 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_animsys_evaluate_animdata(depsgraph, scene, &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM); + BKE_pose_where_is_bone(depsgraph, 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 36968d3edef..a50bcaf0ef4 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -79,25 +79,26 @@ extern "C" #include <vector> #include <algorithm> // std::find - +struct Depsgraph; class AnimationExporter: COLLADASW::LibraryAnimations { private: Scene *scene; + Depsgraph *depsgraph; COLLADASW::StreamWriter *sw; public: - AnimationExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): + AnimationExporter(Depsgraph *depsgraph, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): COLLADASW::LibraryAnimations(sw), + depsgraph(depsgraph), export_settings(export_settings) { this->sw = sw; } 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 3dda67abbba..e57f8c2f652 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -1938,7 +1938,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); @@ -1959,14 +1959,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 52f7c5627b9..85b9d3297ca 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(bContext *C, Object *ob_arm, Scene *sce, - SceneExporter *se, +void ArmatureExporter::add_armature_bones(bContext *C, Depsgraph *depsgraph, Object *ob_arm, + Scene *sce, SceneExporter *se, std::list<Object *>& child_objects) { Main *bmain = CTX_data_main(C); @@ -78,7 +78,7 @@ void ArmatureExporter::add_armature_bones(bContext *C, Object *ob_arm, Scene *sc for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) { // start from root bones if (!bone->parent) - add_bone_node(C, bone, ob_arm, sce, se, child_objects); + add_bone_node(C, depsgraph, bone, ob_arm, sce, se, child_objects); } if (!is_edited) { @@ -117,10 +117,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; @@ -161,7 +158,7 @@ void ArmatureExporter::find_objects_using_armature(Object *ob_arm, std::vector<O #endif // parent_mat is armature-space -void ArmatureExporter::add_bone_node(bContext *C, Bone *bone, Object *ob_arm, Scene *sce, +void ArmatureExporter::add_bone_node(bContext *C, Depsgraph *depsgraph, Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se, std::list<Object *>& child_objects) { @@ -235,7 +232,7 @@ void ArmatureExporter::add_bone_node(bContext *C, Bone *bone, Object *ob_arm, Sc mul_m4_m4m4((*i)->parentinv, temp, (*i)->parentinv); } - se->writeNodes(C, *i, sce); + se->writeNodes(C, depsgraph, *i, sce); copy_m4_m4((*i)->parentinv, backup_parinv); child_objects.erase(i++); @@ -244,13 +241,13 @@ void ArmatureExporter::add_bone_node(bContext *C, Bone *bone, Object *ob_arm, Sc } for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - add_bone_node(C, child, ob_arm, sce, se, child_objects); + add_bone_node(C, depsgraph, child, ob_arm, sce, se, child_objects); } node.end(); } else { for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - add_bone_node(C, child, ob_arm, sce, se, child_objects); + add_bone_node(C, depsgraph, child, ob_arm, sce, se, child_objects); } } } diff --git a/source/blender/collada/ArmatureExporter.h b/source/blender/collada/ArmatureExporter.h index 3199703cb20..7efa8b70e43 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(bContext *C, Object *ob_arm, Scene *sce, SceneExporter *se, + void add_armature_bones(bContext *C, struct Depsgraph *depsgraph, 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(bContext *C, Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se, + void add_bone_node(bContext *C, struct Depsgraph *depsgraph, 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 344a73cfa6f..0e71149fba6 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), @@ -409,7 +411,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; @@ -495,7 +497,7 @@ void ArmatureImporter::create_armature_bones(Main *bmain, std::vector<Object *> 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); } } @@ -584,7 +586,7 @@ Object *ArmatureImporter::create_armature_bones(Main *bmain, 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 @@ -628,7 +630,7 @@ Object *ArmatureImporter::create_armature_bones(Main *bmain, SkinInfo& skin) ED_armature_from_edit(bmain, 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 b637ec89f8b..58121a090fa 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 c89e0f1ec62..122094e33a6 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(struct Depsgraph *depsgraph, Scene *sce) { + this->depsgraph = depsgraph; 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(depsgraph, 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(depsgraph, 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(depsgraph, 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(depsgraph, scene, ob_arm); } source.finish(); diff --git a/source/blender/collada/ControllerExporter.h b/source/blender/collada/ControllerExporter.h index 80b858ca6dd..e13d7c7ebea 100644 --- a/source/blender/collada/ControllerExporter.h +++ b/source/blender/collada/ControllerExporter.h @@ -54,6 +54,7 @@ #include "BKE_key.h" +struct Depsgraph; 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(struct Depsgraph *depsgraph, Scene *sce); void operator()(Object *ob); private: + struct Depsgraph *depsgraph; Scene *scene; UnitConverter converter; const ExportSettings *export_settings; diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index f1838b9dbb6..9e78c164dad 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -71,7 +71,6 @@ extern "C" #include "DNA_mesh_types.h" #include "DNA_image_types.h" #include "DNA_material_types.h" -#include "DNA_texture_types.h" #include "DNA_anim_types.h" #include "DNA_action_types.h" #include "DNA_curve_types.h" @@ -138,8 +137,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 +146,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(Depsgraph *depsgraph, const ExportSettings *export_settings) : + depsgraph(depsgraph), + export_settings(export_settings) { } static COLLADABU::NativeString make_temp_filepath(const char *name, const char *extension) @@ -181,7 +180,7 @@ 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(bContext *C, const EvaluationContext *eval_ctx, Scene *sce) +int DocumentExporter::exportCurrentScene(bContext *C, Scene *sce) { PointerRNA sceneptr, unit_settings; PropertyRNA *system; /* unused , *scale; */ @@ -287,7 +286,7 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e // <library_geometries> if (bc_has_object_type(export_set, OB_MESH)) { GeometryExporter ge(writer, this->export_settings); - ge.exportGeom(sce); + ge.exportGeom(depsgraph, sce); } // <library_controllers> @@ -295,7 +294,7 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e 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(depsgraph, sce); } // <library_visual_scenes> @@ -304,10 +303,10 @@ int DocumentExporter::exportCurrentScene(bContext *C, const EvaluationContext *e if (this->export_settings->include_animations) { // <library_animations> - AnimationExporter ae(writer, this->export_settings); + AnimationExporter ae(depsgraph, writer, this->export_settings); ae.exportAnimations(sce); } - se.exportScene(C, sce); + se.exportScene(C, depsgraph, 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 817df3735da..8a48ca29090 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,10 +39,12 @@ struct Scene; class DocumentExporter { public: - DocumentExporter(const ExportSettings *export_settings); - int exportCurrentScene(bContext *C, const EvaluationContext *eval_ctx, Scene *sce); + DocumentExporter(Depsgraph *depsgraph, const ExportSettings *export_settings); + int exportCurrentScene(bContext *C, Scene *sce); + void exportScenes(const char *filename); private: + Depsgraph *depsgraph; const ExportSettings *export_settings; }; diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 5cbffbe4526..d80f7c20139 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -57,12 +57,12 @@ 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 +82,9 @@ extern "C" { } +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_build.h" + #include "ExtraHandler.h" #include "ErrorHandler.h" #include "DocumentImporter.h" @@ -104,8 +107,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 +134,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 +234,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 +245,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(mContext); - DAG_relations_tag_update(bmain); + DEG_relations_tag_update(bmain); #if 0 armature_importer.fix_animation(); @@ -259,22 +263,14 @@ void DocumentImporter::finish() fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size()); // free all library_nodes - std::vector<Object *>::iterator lit; - for (lit = libnode_ob.begin(); lit != libnode_ob.end(); lit++) { - Object *ob = *lit; - - 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); - } + std::vector<Object *>::iterator it; + for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) { + Object *ob = *it; + BKE_scene_collections_object_remove(G.main, sce, 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); @@ -383,7 +379,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; @@ -399,7 +395,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; @@ -412,8 +408,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(G.main, sce, source_ob, obn); if (instance_node) { anim_importer.read_node_transform(instance_node, obn); @@ -515,7 +511,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)); @@ -547,8 +543,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA // maybe join multiple <instance_...> meshes into 1, and link object with it? not sure... // <instance_geometry> while (geom_done < geom.getCount()) { - ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map, - material_texture_mapping_map); + ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map); if (ob == NULL) { report_unknown_reference(*node, "instance_mesh"); } @@ -588,7 +583,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA } while (controller_done < controller.getCount()) { COLLADAFW::InstanceGeometry *geometry = (COLLADAFW::InstanceGeometry *)controller[controller_done]; - ob = mesh_importer.create_mesh_object(node, geometry, true, uid_material_map, material_texture_mapping_map); + ob = mesh_importer.create_mesh_object(node, geometry, true, uid_material_map); if (ob == NULL) { report_unknown_reference(*node, "instance_controller"); } @@ -629,10 +624,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) { @@ -768,102 +763,74 @@ bool DocumentImporter::writeMaterial(const COLLADAFW::Material *cmat) return true; } -// create mtex, create texture, set texture image -MTex *DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::Texture &ctex, Material *ma, - int i, TexIndexTextureArrayMap &texindex_texarray_map) -{ - COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray(); - COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()]; - - const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage(); - - if (uid_image_map.find(ima_uid) == uid_image_map.end()) { - fprintf(stderr, "Couldn't find an image by UID.\n"); - return NULL; - } - - ma->mtex[i] = BKE_texture_mtex_add(); - ma->mtex[i]->texco = TEXCO_UV; - ma->mtex[i]->tex = BKE_texture_add(G.main, "Texture"); - ma->mtex[i]->tex->type = TEX_IMAGE; - ma->mtex[i]->tex->ima = uid_image_map[ima_uid]; - - texindex_texarray_map[ctex.getTextureMapId()].push_back(ma->mtex[i]); - - return ma->mtex[i]; -} - void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Material *ma) { COLLADAFW::EffectCommon::ShaderType shader = ef->getShaderType(); + // TODO: add back texture and extended material parameter support + // blinn if (shader == COLLADAFW::EffectCommon::SHADER_BLINN) { +#if 0 ma->spec_shader = MA_SPEC_BLINN; ma->spec = ef->getShininess().getFloatValue(); +#endif } // phong else if (shader == COLLADAFW::EffectCommon::SHADER_PHONG) { +#if 0 ma->spec_shader = MA_SPEC_PHONG; ma->har = ef->getShininess().getFloatValue(); +#endif } // lambert else if (shader == COLLADAFW::EffectCommon::SHADER_LAMBERT) { +#if 0 ma->diff_shader = MA_DIFF_LAMBERT; +#endif } // default - lambert else { +#if 0 ma->diff_shader = MA_DIFF_LAMBERT; fprintf(stderr, "Current shader type is not supported, default to lambert.\n"); +#endif } // reflectivity - ma->ray_mirror = ef->getReflectivity().getFloatValue(); + ma->metallic = ef->getReflectivity().getFloatValue(); // index of refraction +#if 0 ma->ang = ef->getIndexOfRefraction().getFloatValue(); +#endif - int i = 0; COLLADAFW::Color col; - MTex *mtex = NULL; - TexIndexTextureArrayMap texindex_texarray_map; // DIFFUSE // color if (ef->getDiffuse().isColor()) { - /* too high intensity can create artefacts (fireflies) - So here we take care that intensity is set to 0.8 wherever possible - */ col = ef->getDiffuse().getColor(); - ma->ref = max_ffff(col.getRed(), col.getGreen(), col.getBlue(), 0.8); - ma->r = col.getRed() / ma->ref; - ma->g = col.getGreen() / ma->ref; - ma->b = col.getBlue() / ma->ref; + ma->r = col.getRed(); + ma->g = col.getGreen(); + ma->b = col.getBlue(); } // texture else if (ef->getDiffuse().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getDiffuse().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_COL; - ma->texact = (int)i; - i++; - } +#endif } // AMBIENT // color if (ef->getAmbient().isColor()) { +#if 0 col = ef->getAmbient().getColor(); - ma->ambr = col.getRed(); - ma->ambg = col.getGreen(); - ma->ambb = col.getBlue(); +#endif } // texture else if (ef->getAmbient().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getAmbient().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_AMB; - i++; - } +#endif } // SPECULAR // color @@ -875,29 +842,22 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia } // texture else if (ef->getSpecular().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getSpecular().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_SPEC; - i++; - } +#endif } // REFLECTIVE // color if (ef->getReflective().isColor()) { +#if 0 col = ef->getReflective().getColor(); - ma->mirr = col.getRed(); - ma->mirg = col.getGreen(); - ma->mirb = col.getBlue(); +#endif } // texture else if (ef->getReflective().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getReflective().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_REF; - i++; - } +#endif } // EMISSION @@ -908,40 +868,31 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia } // texture else if (ef->getEmission().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getEmission().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_EMIT; - i++; - } +#endif } // TRANSPARENT // color if (ef->getOpacity().isColor()) { +#if 0 col = ef->getTransparent().getColor(); float alpha = ef->getTransparency().getFloatValue(); if (col.isValid()) { alpha *= col.getAlpha(); // Assuming A_ONE opaque mode } if (col.isValid() || alpha < 1.0) { - ma->alpha = alpha; - ma->mode |= MA_ZTRANSP | MA_TRANSP; + ... } +#endif } // texture else if (ef->getOpacity().isTexture()) { +#if 0 COLLADAFW::Texture ctex = ef->getOpacity().getTexture(); - mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); - if (mtex != NULL) { - mtex->mapto = MAP_ALPHA; - i++; - ma->spectra = ma->alpha = 0; - ma->mode |= MA_ZTRANSP | MA_TRANSP; - } +#endif } - - material_texture_mapping_map[ma] = texindex_texarray_map; } /** When this method is called, the writer must write the effect. @@ -1188,7 +1139,6 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light) et->setData("spotsize", &(lamp->spotsize)); lamp->spotsize = DEG2RADF(lamp->spotsize); et->setData("spotblend", &(lamp->spotblend)); - et->setData("halo_intensity", &(lamp->haint)); et->setData("att1", &(lamp->att1)); et->setData("att2", &(lamp->att2)); et->setData("falloff_type", &(lamp->falloff_type)); @@ -1196,38 +1146,12 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light) et->setData("clipend", &(lamp->clipend)); et->setData("bias", &(lamp->bias)); et->setData("soft", &(lamp->soft)); - et->setData("compressthresh", &(lamp->compressthresh)); et->setData("bufsize", &(lamp->bufsize)); - et->setData("samp", &(lamp->samp)); et->setData("buffers", &(lamp->buffers)); - et->setData("filtertype", &(lamp->filtertype)); - et->setData("bufflag", &(lamp->bufflag)); - et->setData("buftype", &(lamp->buftype)); - et->setData("ray_samp", &(lamp->ray_samp)); - et->setData("ray_sampy", &(lamp->ray_sampy)); - et->setData("ray_sampz", &(lamp->ray_sampz)); - et->setData("ray_samp_type", &(lamp->ray_samp_type)); et->setData("area_shape", &(lamp->area_shape)); et->setData("area_size", &(lamp->area_size)); et->setData("area_sizey", &(lamp->area_sizey)); et->setData("area_sizez", &(lamp->area_sizez)); - et->setData("adapt_thresh", &(lamp->adapt_thresh)); - et->setData("ray_samp_method", &(lamp->ray_samp_method)); - et->setData("shadhalostep", &(lamp->shadhalostep)); - et->setData("sun_effect_type", &(lamp->shadhalostep)); - et->setData("skyblendtype", &(lamp->skyblendtype)); - et->setData("horizon_brightness", &(lamp->horizon_brightness)); - et->setData("spread", &(lamp->spread)); - et->setData("sun_brightness", &(lamp->sun_brightness)); - et->setData("sun_size", &(lamp->sun_size)); - et->setData("backscattered_light", &(lamp->backscattered_light)); - et->setData("sun_intensity", &(lamp->sun_intensity)); - et->setData("atm_turbidity", &(lamp->atm_turbidity)); - et->setData("atm_extinction_factor", &(lamp->atm_extinction_factor)); - et->setData("atm_distance_factor", &(lamp->atm_distance_factor)); - et->setData("skyblendfac", &(lamp->skyblendfac)); - et->setData("sky_exposure", &(lamp->sky_exposure)); - et->setData("sky_colorspace", &(lamp->sky_colorspace)); } else { float constatt = light->getConstantAttenuation().getValue(); @@ -1291,7 +1215,6 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light) { /* our sun is very strong, so pick a smaller energy level */ lamp->type = LA_SUN; - lamp->mode |= LA_NO_SPEC; } break; case COLLADAFW::Light::POINT_LIGHT: diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h index c5bc6907867..b31a086d710 100644 --- a/source/blender/collada/DocumentImporter.h +++ b/source/blender/collada/DocumentImporter.h @@ -77,7 +77,6 @@ public: Object* create_instance_node(Object*, COLLADAFW::Node*, COLLADAFW::Node*, Scene*, bool); void create_constraints(ExtraTags *et, Object *ob); std::vector<Object *> *write_node(COLLADAFW::Node*, COLLADAFW::Node*, Scene*, Object*, bool); - MTex* create_texture(COLLADAFW::EffectCommon*, COLLADAFW::Texture&, Material*, int, TexIndexTextureArrayMap&); void write_profile_COMMON(COLLADAFW::EffectCommon*, Material*); void translate_anim_recursive(COLLADAFW::Node*, COLLADAFW::Node*, Object*); @@ -144,6 +143,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 d33ce725e58..271dab5deea 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" @@ -40,24 +41,33 @@ extern "C" { #include "DNA_mesh_types.h" - #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_BEGIN(sce, ob) + { int a; for (a = 0; a < ob->totcol; a++) { Material *ma = give_current_material(ob, a + 1); @@ -67,69 +77,21 @@ 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); -void EffectsExporter::writeBlinn(COLLADASW::EffectProfile &ep, Material *ma) -{ - COLLADASW::ColorOrTexture cot; - ep.setShaderType(COLLADASW::EffectProfile::BLINN); - // shininess - ep.setShininess(ma->har, false, "shininess"); - // specular - cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f); - ep.setSpecular(cot, false, "specular"); + closeLibrary(); + } } void EffectsExporter::writeLambert(COLLADASW::EffectProfile &ep, Material *ma) @@ -138,110 +100,21 @@ void EffectsExporter::writeLambert(COLLADASW::EffectProfile &ep, Material *ma) ep.setShaderType(COLLADASW::EffectProfile::LAMBERT); } -void EffectsExporter::writePhong(COLLADASW::EffectProfile &ep, Material *ma) -{ - COLLADASW::ColorOrTexture cot; - ep.setShaderType(COLLADASW::EffectProfile::PHONG); - // shininess - ep.setShininess(ma->har, false, "shininess"); - // specular - cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f); - ep.setSpecular(cot, false, "specular"); -} - -void EffectsExporter::writeTextures( - COLLADASW::EffectProfile &ep, - std::string &key, - COLLADASW::Sampler *sampler, - MTex *t, Image *ima, - std::string &uvname ) -{ - // Image not set for texture - if (!ima) return; - - // color - if (t->mapto & MAP_COL) { - ep.setDiffuse(createTexture(ima, uvname, sampler), false, "diffuse"); - } - // ambient - if (t->mapto & MAP_AMB) { - ep.setAmbient(createTexture(ima, uvname, sampler), false, "ambient"); - } - // specular - if (t->mapto & (MAP_SPEC | MAP_COLSPEC)) { - ep.setSpecular(createTexture(ima, uvname, sampler), false, "specular"); - } - // emission - if (t->mapto & MAP_EMIT) { - ep.setEmission(createTexture(ima, uvname, sampler), false, "emission"); - } - // reflective - if (t->mapto & MAP_REF) { - ep.setReflective(createTexture(ima, uvname, sampler)); - } - // alpha - if (t->mapto & MAP_ALPHA) { - ep.setTransparent(createTexture(ima, uvname, sampler)); - } - // extension: - // Normal map --> Must be stored with <extra> tag as different technique, - // since COLLADA doesn't support normal maps, even in current COLLADA 1.5. - if (t->mapto & MAP_NORM) { - COLLADASW::Texture texture(key); - texture.setTexcoord(uvname); - texture.setSampler(*sampler); - // technique FCOLLADA, with the <bump> tag, is most likely the best understood, - // most widespread de-facto standard. - texture.setProfileName("FCOLLADA"); - texture.setChildElementName("bump"); - ep.addExtraTechniqueColorOrTexture(COLLADASW::ColorOrTexture(texture)); - } -} - 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); + // TODO: add back texture and extended material parameter support openEffect(translate_id(id_name(ma)) + "-effect"); COLLADASW::EffectProfile ep(mSW); ep.setProfileType(COLLADASW::EffectProfile::COMMON); ep.openProfile(); - // set shader type - one of three blinn, phong or lambert - if (ma->spec > 0.0f) { - if (ma->spec_shader == MA_SPEC_BLINN) { - writeBlinn(ep, ma); - } - else { - // \todo figure out handling of all spec+diff shader combos blender has, for now write phong - // for now set phong in case spec shader is not blinn - writePhong(ep, ma); - } - } - else { - if (ma->diff_shader == MA_DIFF_LAMBERT) { - writeLambert(ep, ma); - } - else { - // \todo figure out handling of all spec+diff shader combos blender has, for now write phong - writePhong(ep, ma); - } - } - - // index of refraction - if (ma->mode & MA_RAYTRANSP) { - ep.setIndexOfRefraction(ma->ang, false, "index_of_refraction"); - } - else { - ep.setIndexOfRefraction(1.0f, false, "index_of_refraction"); - } + writeLambert(ep, ma); COLLADASW::ColorOrTexture cot; // transparency - if (ma->mode & MA_TRANSP) { + if (ma->alpha != 1.0f) { // Tod: because we are in A_ONE mode transparency is calculated like this: cot = getcol(1.0f, 1.0f, 1.0f, ma->alpha); ep.setTransparent(cot); @@ -249,34 +122,14 @@ void EffectsExporter::operator()(Material *ma, Object *ob) } // emission +#if 0 cot = getcol(ma->emit, ma->emit, ma->emit, 1.0f); - ep.setEmission(cot, false, "emission"); +#endif - // diffuse multiplied by diffuse intensity - cot = getcol(ma->r * ma->ref, ma->g * ma->ref, ma->b * ma->ref, 1.0f); + // diffuse + cot = getcol(ma->r, ma->g, ma->b, 1.0f); ep.setDiffuse(cot, false, "diffuse"); - // ambient - /* ma->ambX is calculated only on render, so lets do it here manually and not rely on ma->ambX. */ - if (this->scene->world) - cot = getcol(this->scene->world->ambr * ma->amb, this->scene->world->ambg * ma->amb, this->scene->world->ambb * ma->amb, 1.0f); - else - cot = getcol(ma->amb, ma->amb, ma->amb, 1.0f); - - ep.setAmbient(cot, false, "ambient"); - - // reflective, reflectivity - if (ma->mode & MA_RAYMIRROR) { - cot = getcol(ma->mirr, ma->mirg, ma->mirb, 1.0f); - ep.setReflective(cot); - ep.setReflectivity(ma->ray_mirror); - } - // else { - // cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f); - // ep.setReflective(cot); - // ep.setReflectivity(ma->spec); - // } - // specular if (ep.getShaderType() != COLLADASW::EffectProfile::LAMBERT) { cot = getcol(ma->specr * ma->spec, ma->specg * ma->spec, ma->specb * ma->spec, 1.0f); @@ -285,6 +138,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob) // XXX make this more readable if possible +#if 0 // create <sampler> and <surface> for each image COLLADASW::Sampler samplers[MAX_MTEX]; //COLLADASW::Surface surfaces[MAX_MTEX]; @@ -335,13 +189,15 @@ void EffectsExporter::operator()(Material *ma, Object *ob) b++; } } +#endif // 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 +#if 0 for (a = 0; a < tex_indices.size(); a++) { MTex *t = ma->mtex[tex_indices[a]]; Image *ima = t->tex->ima; @@ -357,6 +213,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob) COLLADASW::Sampler *sampler = (COLLADASW::Sampler *)samp_surf[i]; writeTextures(ep, key, sampler, t, ima, uvname); } +#endif // performs the actual writing ep.addProfileElements(); @@ -397,20 +254,3 @@ COLLADASW::ColorOrTexture EffectsExporter::getcol(float r, float g, float b, flo COLLADASW::ColorOrTexture cot(color); return cot; } - -//returns the array of mtex indices which have image -//need this for exporting textures -void EffectsExporter::createTextureIndices(Material *ma, std::vector<int> &indices) -{ - indices.clear(); - - for (int a = 0; a < MAX_MTEX; a++) { - if (ma->mtex[a] && - ma->mtex[a]->tex && - ma->mtex[a]->tex->type == TEX_IMAGE && - ma->mtex[a]->texco == TEXCO_UV) - { - indices.push_back(a); - } - } -} diff --git a/source/blender/collada/EffectExporter.h b/source/blender/collada/EffectExporter.h index 278e1ebcfce..a1395bfde9f 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, @@ -57,12 +58,7 @@ public: COLLADASW::ColorOrTexture getcol(float r, float g, float b, float a); private: - /** Fills the array of mtex indices which have image. Used for exporting images. */ - void createTextureIndices(Material *ma, std::vector<int> &indices); - - void writeBlinn(COLLADASW::EffectProfile &ep, Material *ma); void writeLambert(COLLADASW::EffectProfile &ep, Material *ma); - void writePhong(COLLADASW::EffectProfile &ep, Material *ma); void writeTextures(COLLADASW::EffectProfile &ep, std::string &key, COLLADASW::Sampler *sampler, 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 4b693332715..65e844cbe50 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(struct Depsgraph *depsgraph, Scene *sce) { openLibrary(); + mDepsgraph = depsgraph; 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(mDepsgraph, 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_image_set = bc_getUVImages(ob, all_uv_layers); - createPolylists(uv_image_set, 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); @@ -414,20 +362,12 @@ void GeometryExporter::createPolylist(short material_index, 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,9 +388,11 @@ 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; @@ -463,202 +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 @@ -779,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 8c536721e4b..b0cd650adcd 100644 --- a/source/blender/collada/GeometryExporter.h +++ b/source/blender/collada/GeometryExporter.h @@ -46,6 +46,8 @@ #include "BKE_key.h" +struct Depsgraph; + extern Object *bc_get_highest_selected_ancestor_or_self(Object *ob); class Normal @@ -72,12 +74,13 @@ class GeometryExporter : COLLADASW::LibraryGeometries Normal n; + struct Depsgraph *mDepsgraph; Scene *mScene; public: GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings); - void exportGeom(Scene *sce); + void exportGeom(struct Depsgraph *depsgraph, Scene *sce); void operator()(Object *ob); @@ -85,32 +88,14 @@ 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 87f1197e3af..bb3cebf4cf0 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; @@ -209,27 +164,8 @@ bool ImagesExporter::hasImages(Scene *sce) // no material, but check all of the slots if (!ma) continue; - int b; - for (b = 0; b < MAX_MTEX; b++) { - MTex *mtex = ma->mtex[b]; - if (mtex && mtex->tex && mtex->tex->ima) return true; - } - + // TODO: find image textures in shader nodes } - 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 +175,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(); } @@ -253,13 +186,6 @@ void ImagesExporter::exportImages(Scene *sce) void ImagesExporter::operator()(Material *ma, Object *ob) { - int a; - bool use_texture_copies = this->export_settings->use_texture_copies; - for (a = 0; a < MAX_MTEX; a++) { - MTex *mtex = ma->mtex[a]; - if (mtex && mtex->tex && mtex->tex->ima) { - Image *image = mtex->tex->ima; - export_UV_Image(image, use_texture_copies); - } - } + // bool use_texture_copies = this->export_settings->use_texture_copies; + // TODO call export_UV_Image for every image in shader nodes } diff --git a/source/blender/collada/ImageExporter.h b/source/blender/collada/ImageExporter.h index 524260891ae..1867c44ac9c 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 4d846693e50..68842596550 100644 --- a/source/blender/collada/InstanceWriter.cpp +++ b/source/blender/collada/InstanceWriter.cpp @@ -41,22 +41,16 @@ extern "C" { #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); - 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); + COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList(); + + 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)); @@ -66,7 +60,7 @@ void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_materia 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); @@ -77,32 +71,4 @@ void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_materia 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/LightExporter.cpp b/source/blender/collada/LightExporter.cpp index 02c5438ec47..11377e06ce8 100644 --- a/source/blender/collada/LightExporter.cpp +++ b/source/blender/collada/LightExporter.cpp @@ -149,7 +149,6 @@ bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Lamp *la) cla.addExtraTechniqueParameter("blender", "dist", la->dist, "blender_dist"); cla.addExtraTechniqueParameter("blender", "spotsize", RAD2DEGF(la->spotsize)); cla.addExtraTechniqueParameter("blender", "spotblend", la->spotblend); - cla.addExtraTechniqueParameter("blender", "halo_intensity", la->haint, "blnder_halo_intensity"); cla.addExtraTechniqueParameter("blender", "att1", la->att1); cla.addExtraTechniqueParameter("blender", "att2", la->att2); // \todo figure out how we can have falloff curve supported here @@ -158,38 +157,13 @@ bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Lamp *la) cla.addExtraTechniqueParameter("blender", "clipend", la->clipend); cla.addExtraTechniqueParameter("blender", "bias", la->bias); cla.addExtraTechniqueParameter("blender", "soft", la->soft); - cla.addExtraTechniqueParameter("blender", "compressthresh", la->compressthresh); cla.addExtraTechniqueParameter("blender", "bufsize", la->bufsize); cla.addExtraTechniqueParameter("blender", "samp", la->samp); cla.addExtraTechniqueParameter("blender", "buffers", la->buffers); - cla.addExtraTechniqueParameter("blender", "filtertype", la->filtertype); - cla.addExtraTechniqueParameter("blender", "bufflag", la->bufflag); - cla.addExtraTechniqueParameter("blender", "buftype", la->buftype); - cla.addExtraTechniqueParameter("blender", "ray_samp", la->ray_samp); - cla.addExtraTechniqueParameter("blender", "ray_sampy", la->ray_sampy); - cla.addExtraTechniqueParameter("blender", "ray_sampz", la->ray_sampz); - cla.addExtraTechniqueParameter("blender", "ray_samp_type", la->ray_samp_type); cla.addExtraTechniqueParameter("blender", "area_shape", la->area_shape); cla.addExtraTechniqueParameter("blender", "area_size", la->area_size); cla.addExtraTechniqueParameter("blender", "area_sizey", la->area_sizey); cla.addExtraTechniqueParameter("blender", "area_sizez", la->area_sizez); - cla.addExtraTechniqueParameter("blender", "adapt_thresh", la->adapt_thresh); - cla.addExtraTechniqueParameter("blender", "ray_samp_method", la->ray_samp_method); - cla.addExtraTechniqueParameter("blender", "shadhalostep", la->shadhalostep); - cla.addExtraTechniqueParameter("blender", "sun_effect_type", la->shadhalostep); - cla.addExtraTechniqueParameter("blender", "skyblendtype", la->skyblendtype); - cla.addExtraTechniqueParameter("blender", "horizon_brightness", la->horizon_brightness); - cla.addExtraTechniqueParameter("blender", "spread", la->spread); - cla.addExtraTechniqueParameter("blender", "sun_brightness", la->sun_brightness); - cla.addExtraTechniqueParameter("blender", "sun_size", la->sun_size); - cla.addExtraTechniqueParameter("blender", "backscattered_light", la->backscattered_light); - cla.addExtraTechniqueParameter("blender", "sun_intensity", la->sun_intensity); - cla.addExtraTechniqueParameter("blender", "atm_turbidity", la->atm_turbidity); - cla.addExtraTechniqueParameter("blender", "atm_extinction_factor", la->atm_extinction_factor); - cla.addExtraTechniqueParameter("blender", "atm_distance_factor", la->atm_distance_factor); - cla.addExtraTechniqueParameter("blender", "skyblendfac", la->skyblendfac); - cla.addExtraTechniqueParameter("blender", "sky_exposure", la->sky_exposure); - cla.addExtraTechniqueParameter("blender", "sky_colorspace", la->sky_colorspace); return true; } diff --git a/source/blender/collada/MaterialExporter.cpp b/source/blender/collada/MaterialExporter.cpp index 0c0395f2a21..4aece997f72 100644 --- a/source/blender/collada/MaterialExporter.cpp +++ b/source/blender/collada/MaterialExporter.cpp @@ -38,40 +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 604db646419..e95f8ed0888 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); } @@ -877,48 +879,6 @@ std::string *MeshImporter::get_geometry_name(const std::string &mesh_name) return NULL; } -MTex *MeshImporter::assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture, - Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map, - MTex *color_texture) -{ - const COLLADAFW::TextureMapId texture_index = ctexture.getTextureMapId(); - size_t setindex = ctexture.getSetIndex(); - std::string uvname = ctexture.getSemantic(); - - if (setindex == -1) return NULL; - - const CustomData *data = &me->fdata; - int layer_index = CustomData_get_layer_index(data, CD_MTFACE); - - if (layer_index == -1) return NULL; - - CustomDataLayer *cdl = &data->layers[layer_index + setindex]; - - /* set uvname to bind_vertex_input semantic */ - BLI_strncpy(cdl->name, uvname.c_str(), sizeof(cdl->name)); - - if (texindex_texarray_map.find(texture_index) == texindex_texarray_map.end()) { - - fprintf(stderr, "Cannot find texture array by texture index.\n"); - return color_texture; - } - - std::vector<MTex *> textures = texindex_texarray_map[texture_index]; - - std::vector<MTex *>::iterator it; - - for (it = textures.begin(); it != textures.end(); it++) { - - MTex *texture = *it; - - if (texture) { - BLI_strncpy(texture->uvname, uvname.c_str(), sizeof(texture->uvname)); - if (texture->mapto == MAP_COL) color_texture = texture; - } - } - return color_texture; -} - /** * this function checks if both objects have the same * materials assigned to Object (in the same order) @@ -1052,21 +1012,19 @@ 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, + short mat_index) { - MTex *color_texture = NULL; - Mesh *me = (Mesh *)ob->data; const COLLADAFW::UniqueId& ma_uid = cmaterial.getReferencedMaterial(); // do we know this material? 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. @@ -1079,27 +1037,6 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri ob->actcol=0; assign_material(G.main, ob, ma, mat_index + 1, BKE_MAT_ASSIGN_OBJECT); - COLLADAFW::TextureCoordinateBindingArray& tex_array = - cmaterial.getTextureCoordinateBindingArray(); - TexIndexTextureArrayMap texindex_texarray_map = material_texture_mapping_map[ma]; - unsigned int i; - // loop through <bind_vertex_inputs> - for (i = 0; i < tex_array.getCount(); i++) { - - color_texture = assign_textures_to_uvlayer(tex_array[i], me, texindex_texarray_map, - 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,23 +1051,16 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri Primitive& prim = *it; MPoly *mpoly = prim.mpoly; - for (i = 0; i < prim.totpoly; i++, mpoly++) { + for (int 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, bool isController, - std::map<COLLADAFW::UniqueId, Material *>& uid_material_map, - std::map<Material *, TexIndexTextureArrayMap>& material_texture_mapping_map) + std::map<COLLADAFW::UniqueId, Material *>& uid_material_map) { const COLLADAFW::UniqueId *geom_uid = &geom->getInstanciatedObjectId(); @@ -1160,7 +1090,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 @@ -1178,10 +1108,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(); @@ -1189,9 +1115,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, + 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 f0da3cc21cf..c98126916d7 100644 --- a/source/blender/collada/MeshImporter.h +++ b/source/blender/collada/MeshImporter.h @@ -51,7 +51,6 @@ extern "C" { #include "DNA_meshdata_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" -#include "DNA_texture_types.h" } @@ -92,6 +91,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,29 +160,24 @@ 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); virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId& geom_uid); - MTex *assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture, - Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map, - MTex *color_texture); - 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, + short mat_index); Object *create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom, bool isController, - std::map<COLLADAFW::UniqueId, Material*>& uid_material_map, - std::map<Material*, TexIndexTextureArrayMap>& material_texture_mapping_map); + std::map<COLLADAFW::UniqueId, Material*>& uid_material_map); // create a mesh storing a pointer in a map so it can be retrieved later by geometry UID bool write_geometry(const COLLADAFW::Geometry* geom); diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp index 4e08548449f..d909203488e 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_collection.h" #include "BKE_object.h" #include "BLI_listbase.h" } @@ -38,17 +39,17 @@ SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, { } -void SceneExporter::exportScene(bContext *C, Scene *sce) +void SceneExporter::exportScene(bContext *C, Depsgraph *depsgraph, Scene *sce) { // <library_visual_scenes> <visual_scene> std::string id_naming = id_name(sce); openVisualScene(translate_id(id_naming), id_naming); - exportHierarchy(C, sce); + exportHierarchy(C, depsgraph, sce); closeVisualScene(); closeLibrary(); } -void SceneExporter::exportHierarchy(bContext *C, Scene *sce) +void SceneExporter::exportHierarchy(bContext *C, Depsgraph *depsgraph, Scene *sce) { LinkNode *node; std::vector<Object *> base_objects; @@ -80,13 +81,13 @@ void SceneExporter::exportHierarchy(bContext *C, Scene *sce) Object *ob = base_objects[index]; if (bc_is_marked(ob)) { bc_remove_mark(ob); - writeNodes(C, ob, sce); + writeNodes(C, depsgraph, ob, sce); } } } -void SceneExporter::writeNodes(bContext *C, Object *ob, Scene *sce) +void SceneExporter::writeNodes(bContext *C, Depsgraph *depsgraph, Object *ob, Scene *sce) { // Add associated armature first if available bool armature_exported = false; @@ -95,7 +96,7 @@ void SceneExporter::writeNodes(bContext *C, 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(C, ob_arm, sce); + writeNodes(C, depsgraph, ob_arm, sce); armature_exported = true; } } @@ -146,10 +147,7 @@ void SceneExporter::writeNodes(bContext *C, 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(bContext *C, Object *ob, Scene *sce) // <instance_controller> else if (ob->type == OB_ARMATURE) { - arm_exporter->add_armature_bones(C, ob, sce, this, child_objects); + arm_exporter->add_armature_bones(C, depsgraph, ob, sce, this, child_objects); } // <instance_camera> @@ -173,14 +171,15 @@ void SceneExporter::writeNodes(bContext *C, 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); + else if (ob->type == OB_EMPTY) { // TODO: handle groups (OB_DUPLICOLLECTION + if ((ob->transflag & OB_DUPLICOLLECTION) == OB_DUPLICOLLECTION && ob->dup_group) { + Collection *collection = ob->dup_group; + /* printf("group detected '%s'\n", group->id.name + 2); */ + FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(collection, object) + { + printf("\t%s\n", object->id.name); } + FOREACH_COLLECTION_OBJECT_RECURSIVE_END; } } @@ -235,7 +234,7 @@ void SceneExporter::writeNodes(bContext *C, 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(C, *i, sce); + writeNodes(C, depsgraph, *i, sce); } } diff --git a/source/blender/collada/SceneExporter.h b/source/blender/collada/SceneExporter.h index 6cf561749de..91f98063020 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(bContext *C, Scene *sce); + void exportScene(bContext *C, Depsgraph *depsgraph, Scene *sce); private: friend class ArmatureExporter; - void exportHierarchy(bContext *C, Scene *sce); - void writeNodes(bContext *C, Object *ob, Scene *sce); + void exportHierarchy(bContext *C, struct Depsgraph *depsgraph, Scene *sce); + void writeNodes(bContext *C, struct Depsgraph *depsgraph, 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 72d5c656920..7ec3f04aabf 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; } @@ -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 de88bf32fcf..fdfee0a943a 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 89653c139f3..9f75a604f96 100644 --- a/source/blender/collada/TransformWriter.cpp +++ b/source/blender/collada/TransformWriter.cpp @@ -26,8 +26,10 @@ */ -#include "BKE_object.h" #include "BLI_math.h" +#include "BLI_sys_types.h" + +#include "BKE_object.h" #include "TransformWriter.h" @@ -61,7 +63,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 ecaa7fba08c..bf310cb24d8 100644 --- a/source/blender/collada/collada.cpp +++ b/source/blender/collada/collada.cpp @@ -32,11 +32,14 @@ #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" +#include "DEG_depsgraph_query.h" /* make dummy file */ #include "BLI_fileops.h" @@ -49,17 +52,19 @@ int collada_import(bContext *C, ImportSettings *import_settings) } int collada_export(bContext *C, - EvaluationContext *eval_ctx, + Depsgraph *depsgraph, Scene *sce, ExportSettings *export_settings) { + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); 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) { @@ -75,8 +80,8 @@ int collada_export(bContext *C, bc_bubble_sort_by_Object_name(export_settings->export_set); } - DocumentExporter exporter(export_settings); - int status = exporter.exportCurrentScene(C, eval_ctx, sce); + DocumentExporter exporter(depsgraph, export_settings); + int status = exporter.exportCurrentScene(C, sce); BLI_linklist_free(export_settings->export_set, NULL); diff --git a/source/blender/collada/collada.h b/source/blender/collada/collada.h index 907c94855f7..a47463b5a7a 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 Depsgraph; struct Scene; +struct ViewLayer; /* * both return 1 on success, 0 on error @@ -53,7 +52,7 @@ int collada_import(struct bContext *C, ImportSettings *import_settings); int collada_export(struct bContext *C, - struct EvaluationContext *eval_ctx, + struct Depsgraph *depsgraph, struct Scene *sce, ExportSettings *export_settings); diff --git a/source/blender/collada/collada_internal.cpp b/source/blender/collada/collada_internal.cpp index f2cc56777d8..cf4dcb5eb42 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 ff998a94685..1eac5b68778 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); 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 153bc8b28bd..945dda68745 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,9 @@ extern "C" { #include "bmesh_tools.h" } +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" + #include "collada_utils.h" #include "ExportSettings.h" @@ -94,6 +97,7 @@ int bc_test_parent_loop(Object *par, Object *ob) int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) { Object workob; + Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *sce = CTX_data_scene(C); if (!par || bc_test_parent_loop(par, ob)) @@ -107,7 +111,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(depsgraph, sce, par); // move child obmat into world space mul_m4_m4m4(mat, par->obmat, ob->obmat); @@ -118,54 +122,57 @@ 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(depsgraph, 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; } -Main *bc_get_main() +Scene *bc_get_scene(bContext *C) { - return G.main; + return CTX_data_scene(C); } -EvaluationContext *bc_get_evaluation_context() +Main *bc_get_main() { - Main *bmain = G.main; - return bmain->eval_ctx; + return G.main; } -void bc_update_scene(Scene *scene, float ctime) + +void bc_update_scene(Depsgraph *depsgraph, 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(depsgraph, bmain); } -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); + + LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer); + BKE_collection_object_add(G.main, layer_collection->collection, ob); - BKE_scene_base_select(scene, BKE_scene_base_add(scene, 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(struct Depsgraph *depsgraph, 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 +182,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(depsgraph, scene, ob, mask); break; } case BC_MESH_TYPE_RENDER: { - dm = mesh_create_derived_render(scene, ob, mask); + dm = mesh_create_derived_render(depsgraph, scene, ob, mask); break; } } @@ -907,16 +914,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 +929,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) @@ -945,125 +952,3 @@ std::string bc_get_uvlayer_name(Mesh *me, int layer) } return ""; } - -/********************************************************************** -* -* Return the list of Mesh objects with assigned UVtextures and Images -* Note: We need to create artificaial materials for each of them -* -***********************************************************************/ -std::set<Object *> bc_getUVTexturedObjects(Scene *sce, bool all_uv_layers) -{ - std::set <Object *> UVObjects; - Base *base = (Base *)sce->base.first; - - while (base) { - Object *ob = base->object; - bool has_uvimage = false; - if (ob->type == OB_MESH) { - Mesh *me = (Mesh *)ob->data; - int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY); - - for (int i = 0; i < me->pdata.totlayer && !has_uvimage; i++) { - if (all_uv_layers || active_uv_layer == i) - { - if (me->pdata.layers[i].type == CD_MTEXPOLY) { - MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data; - MPoly *mpoly = me->mpoly; - for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) { - - Image *ima = txface->tpage; - if (ima != NULL) { - has_uvimage = true; - break; - } - } - } - } - } - - if (has_uvimage) { - UVObjects.insert(ob); - } - } - base = base->next; - } - return UVObjects; -} - -/********************************************************************** -* -* Return the list of UV Texture images from all exported Mesh Items -* Note: We need to create one artificial material for each Image. -* -***********************************************************************/ -std::set<Image *> bc_getUVImages(Scene *sce, bool all_uv_layers) -{ - std::set <Image *> UVImages; - Base *base = (Base *)sce->base.first; - - while (base) { - Object *ob = base->object; - bool has_uvimage = false; - if (ob->type == OB_MESH) { - Mesh *me = (Mesh *)ob->data; - int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY); - - for (int i = 0; i < me->pdata.totlayer && !has_uvimage; i++) { - if (all_uv_layers || active_uv_layer == i) - { - if (me->pdata.layers[i].type == CD_MTEXPOLY) { - MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data; - MPoly *mpoly = me->mpoly; - for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) { - - Image *ima = txface->tpage; - if (ima != NULL) { - if (UVImages.find(ima) == UVImages.end()) - UVImages.insert(ima); - } - } - } - } - } - } - base = base->next; - } - return UVImages; -} - -/********************************************************************** -* -* Return the list of UV Texture images for the given Object -* Note: We need to create one artificial material for each Image. -* -***********************************************************************/ -std::set<Image *> bc_getUVImages(Object *ob, bool all_uv_layers) -{ - std::set <Image *> UVImages; - - bool has_uvimage = false; - if (ob->type == OB_MESH) { - Mesh *me = (Mesh *)ob->data; - int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY); - - for (int i = 0; i < me->pdata.totlayer && !has_uvimage; i++) { - if (all_uv_layers || active_uv_layer == i) - { - if (me->pdata.layers[i].type == CD_MTEXPOLY) { - MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data; - MPoly *mpoly = me->mpoly; - for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) { - - Image *ima = txface->tpage; - if (ima != NULL) { - if (UVImages.find(ima) == UVImages.end()) - UVImages.insert(ima); - } - } - } - } - } - } - return UVImages; -} diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h index cbce74485b7..20c569834d8 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 Depsgraph; + 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 Depsgraph *bc_get_depsgraph(); +extern void bc_update_scene(Depsgraph *depsgraph, 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(struct Depsgraph *depsgraph, 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; |