diff options
Diffstat (limited to 'source/blender/collada')
-rw-r--r-- | source/blender/collada/AnimationExporter.cpp | 6 | ||||
-rw-r--r-- | source/blender/collada/AnimationExporter.h | 4 | ||||
-rw-r--r-- | source/blender/collada/ArmatureImporter.cpp | 8 | ||||
-rw-r--r-- | source/blender/collada/ControllerExporter.cpp | 3 | ||||
-rw-r--r-- | source/blender/collada/DocumentImporter.cpp | 4 | ||||
-rw-r--r-- | source/blender/collada/DocumentImporter.h | 1 | ||||
-rw-r--r-- | source/blender/collada/GeometryExporter.cpp | 53 | ||||
-rw-r--r-- | source/blender/collada/GeometryExporter.h | 19 | ||||
-rw-r--r-- | source/blender/collada/ImageExporter.cpp | 2 | ||||
-rw-r--r-- | source/blender/collada/SceneExporter.cpp | 4 | ||||
-rw-r--r-- | source/blender/collada/collada.cpp | 2 | ||||
-rw-r--r-- | source/blender/collada/collada_utils.cpp | 7 |
12 files changed, 72 insertions, 41 deletions
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index de4e29a7d48..7bea0b70c95 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -185,7 +185,7 @@ void AnimationExporter::make_anim_frames_from_targets(Object *ob, std::vector<fl for (con = (bConstraint *)conlist->first; con; con = con->next) { ListBase targets = {NULL, NULL}; - bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); + const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); if (!validateConstraints(con)) continue; @@ -1526,7 +1526,7 @@ void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, i bool AnimationExporter::validateConstraints(bConstraint *con) { bool valid = true; - bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); + const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); /* these we can skip completely (invalid constraints...) */ if (cti == NULL) valid = false; if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) valid = false; @@ -1545,7 +1545,7 @@ void AnimationExporter::calc_ob_mat_at_time(Object *ob, float ctime , float mat[ for (con = (bConstraint *)conlist->first; con; con = con->next) { ListBase targets = {NULL, NULL}; - bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); + const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); if (cti && cti->get_constraint_targets) { bConstraintTarget *ct; diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index 6f675ed6a39..4736361ad13 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -103,7 +103,7 @@ protected: const ExportSettings *export_settings; void dae_animation(Object *ob, FCurve *fcu, char *transformName, bool is_param, Material *ma = NULL); - + void export_object_constraint_animation(Object *ob); void export_morph_animation(Object *ob); @@ -154,7 +154,7 @@ protected: std::string create_xyz_source(float *v, int tot, const std::string& anim_id); std::string create_4x4_source(std::vector<float> &frames, Object * ob_arm, Bone *bone, const std::string& anim_id); - + std::string create_interpolation_source(FCurve *fcu, const std::string& anim_id, const char *axis_name, bool *has_tangents); std::string fake_interpolation_source(int tot, const std::string& anim_id, const char *axis_name); diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp index c2ee6170470..bccaf4eddf6 100644 --- a/source/blender/collada/ArmatureImporter.cpp +++ b/source/blender/collada/ArmatureImporter.cpp @@ -588,9 +588,11 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin) /* and step back to edit mode to fix the leaf nodes */ ED_armature_to_edit(armature); - connect_bone_chains(armature, (Bone *)armature->bonebase.first, UNLIMITED_CHAIN_MAX); - fix_leaf_bones(armature, (Bone *)armature->bonebase.first); - + if (armature->bonebase.first) { + /* Do this only if Armature has bones */ + connect_bone_chains(armature, (Bone *)armature->bonebase.first, UNLIMITED_CHAIN_MAX); + fix_leaf_bones(armature, (Bone *)armature->bonebase.first); + } // exit armature edit mode ED_armature_from_edit(armature); ED_armature_edit_free(armature); diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp index 16c3f68bca4..06e151c363b 100644 --- a/source/blender/collada/ControllerExporter.cpp +++ b/source/blender/collada/ControllerExporter.cpp @@ -284,7 +284,8 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm) } if (oob_counter > 0) { - fprintf(stderr, "Ignored %d Vertex weights which use index to non existing VGroup %ld.\n", oob_counter, joint_index_by_def_index.size()); + fprintf(stderr, "Ignored %d Vertex weights which use index to non existing VGroup %lu.\n", + oob_counter, joint_index_by_def_index.size()); } } diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 462b7b6f200..0aff5147060 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -771,9 +771,9 @@ MTex *DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::T return NULL; } - ma->mtex[i] = add_mtex(); + ma->mtex[i] = BKE_texture_mtex_add(); ma->mtex[i]->texco = TEXCO_UV; - ma->mtex[i]->tex = add_texture(G.main, "Texture"); + 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]; diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h index 5a7df9a41cf..62f76dbc022 100644 --- a/source/blender/collada/DocumentImporter.h +++ b/source/blender/collada/DocumentImporter.h @@ -51,7 +51,6 @@ -struct Main; struct bContext; /** Importer class. */ diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp index 28cee05ec4b..7c7c57f3305 100644 --- a/source/blender/collada/GeometryExporter.cpp +++ b/source/blender/collada/GeometryExporter.cpp @@ -532,8 +532,8 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me) // each <source> will get id like meshName + "map-channel-1" int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV); for (int a = 0; a < num_layers; a++) { - - if (!this->export_settings->active_uv_only || a == active_uv_index) { + int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_MLOOPUV, a); + if (!this->export_settings->active_uv_only || layer_index == active_uv_index) { MLoopUV *mloops = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, a); COLLADASW::FloatSourceF source(mSW); @@ -563,6 +563,11 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me) } } +bool operator<(const Normal &a, const Normal &b) +{ + /* only needed to sort normal vectors and find() them later in a map.*/ + return a.x < b.x || (a.x == b.x && (a.y < b.y || (a.y == b.y && a.z < b.z))); +} //creates <source> for normals void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *me, std::vector<Normal>& nor) @@ -596,15 +601,25 @@ void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *me, std::v void GeometryExporter::create_normals(std::vector<Normal> &normals, std::vector<BCPolygonNormalsIndices> &polygons_normals, Mesh *me) { - std::map<unsigned int, unsigned int> shared_normal_indices; + std::map<Normal, unsigned int> shared_normal_indices; int last_normal_index = -1; MVert *verts = me->mvert; MLoop *mloops = me->mloop; + float(*lnors)[3] = NULL; + bool use_custom_normals = false; + + BKE_mesh_calc_normals_split(me); + if (CustomData_has_layer(&me->ldata, CD_NORMAL)) { + lnors = (float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL); + use_custom_normals = true; + } + for (int poly_index = 0; poly_index < me->totpoly; poly_index++) { MPoly *mpoly = &me->mpoly[poly_index]; + bool use_vertex_normals = use_custom_normals || mpoly->flag & ME_SMOOTH; - if (!(mpoly->flag & ME_SMOOTH)) { + if (!use_vertex_normals) { // For flat faces use face normal as vertex normal: float vector[3]; @@ -615,25 +630,29 @@ void GeometryExporter::create_normals(std::vector<Normal> &normals, std::vector< last_normal_index++; } - - MLoop *mloop = mloops + mpoly->loopstart; BCPolygonNormalsIndices poly_indices; for (int loop_index = 0; loop_index < mpoly->totloop; loop_index++) { - unsigned int vertex_index = mloop[loop_index].v; - if (mpoly->flag & ME_SMOOTH) { - if (shared_normal_indices.find(vertex_index) != shared_normal_indices.end()) - poly_indices.add_index (shared_normal_indices[vertex_index]); - else { + unsigned int loop_idx = mpoly->loopstart + loop_index; + if (use_vertex_normals) { + float normalized[3]; - float vector[3]; - normal_short_to_float_v3(vector, verts[vertex_index].no); + if (use_custom_normals) { + normalize_v3_v3(normalized, lnors[loop_idx]); + } + else { + normal_short_to_float_v3(normalized, verts[mloops[loop_index].v].no); + normalize_v3(normalized); + } + Normal n = { normalized[0], normalized[1], normalized[2] }; - Normal n = { vector[0], vector[1], vector[2] }; - normals.push_back(n); + if (shared_normal_indices.find(n) != shared_normal_indices.end()) { + poly_indices.add_index(shared_normal_indices[n]); + } + else { last_normal_index++; - poly_indices.add_index(last_normal_index); - shared_normal_indices[vertex_index] = last_normal_index; + shared_normal_indices[n] = last_normal_index; + normals.push_back(n); } } else { diff --git a/source/blender/collada/GeometryExporter.h b/source/blender/collada/GeometryExporter.h index 4d54e79d796..69d1067e6f4 100644 --- a/source/blender/collada/GeometryExporter.h +++ b/source/blender/collada/GeometryExporter.h @@ -48,6 +48,20 @@ extern Object *bc_get_highest_selected_ancestor_or_self(Object *ob); +class Normal +{ + public: + float x; + float y; + float z; + + friend bool operator< (const Normal &, const Normal &); + +}; + +bool operator< (const Normal &, const Normal &); + + // TODO: optimize UV sets by making indexed list with duplicates removed class GeometryExporter : COLLADASW::LibraryGeometries { @@ -56,10 +70,7 @@ class GeometryExporter : COLLADASW::LibraryGeometries unsigned int v1, v2, v3, v4; }; - struct Normal - { - float x, y, z; - }; + Normal n; Scene *mScene; diff --git a/source/blender/collada/ImageExporter.cpp b/source/blender/collada/ImageExporter.cpp index a5c1493208b..aac41e2e93c 100644 --- a/source/blender/collada/ImageExporter.cpp +++ b/source/blender/collada/ImageExporter.cpp @@ -74,7 +74,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies) short image_source = image->source; bool is_generated = image_source == IMA_SRC_GENERATED; - bool is_packed = image->packedfile != NULL; + bool is_packed = BKE_image_has_packedfile(image); char export_path[FILE_MAX]; char source_path[FILE_MAX]; diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp index b50b8b0a302..ac8ac2b9867 100644 --- a/source/blender/collada/SceneExporter.cpp +++ b/source/blender/collada/SceneExporter.cpp @@ -150,7 +150,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce) if (!instance_controller_created) { 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); instGeom.add(); @@ -210,7 +210,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce) //not ideal: add the target object name as another parameter. //No real mapping in the .dae //Need support for multiple target objects also. - bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); + const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); ListBase targets = {NULL, NULL}; if (cti && cti->get_constraint_targets) { diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp index f1d5f1a208a..4ca21869ec2 100644 --- a/source/blender/collada/collada.cpp +++ b/source/blender/collada/collada.cpp @@ -116,7 +116,7 @@ int collada_export(Scene *sce, eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL; export_settings.export_set = BKE_object_relational_superset(sce, objectSet, (eObRelationTypes)includeFilter); - int export_count = BLI_linklist_length(export_settings.export_set); + int export_count = BLI_linklist_count(export_settings.export_set); if (export_count==0) { diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index f15efa89ea6..d669487db28 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -131,7 +131,7 @@ Object *bc_add_object(Scene *scene, 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); + 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); @@ -144,6 +144,7 @@ Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh { Mesh *tmpmesh; CustomDataMask mask = CD_MASK_MESH; + Mesh *mesh = (Mesh *)ob->data; DerivedMesh *dm = NULL; if (apply_modifiers) { switch (export_mesh_type) { @@ -165,14 +166,12 @@ Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh tmpmesh = BKE_mesh_add(G.main, "ColladaMesh"); // name is not important here DM_to_mesh(dm, tmpmesh, ob, CD_MASK_MESH, true); + tmpmesh->flag = mesh->flag; if (triangulate) { bc_triangulate_mesh(tmpmesh); } - - // XXX Not sure if we need that for ngon_export as well. BKE_mesh_tessface_ensure(tmpmesh); - return tmpmesh; } |