From 799fd6f3733f97a175ce6b2e2c2c6ecaa090a6ec Mon Sep 17 00:00:00 2001 From: Arystanbek Dyussenov Date: Wed, 13 Jan 2010 12:44:57 +0000 Subject: COLLADA branch: fix #20653 - tag's target attribute was missing ".ANGLE". Also replaced "."s in ids with "_" and corrected bone sids. --- source/blender/collada/DocumentExporter.cpp | 31 ++++++++++------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index ef36a2eea9a..f0dd24a735f 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -859,11 +859,9 @@ private: return ob_arm; } - std::string get_joint_sid(Bone *bone) + std::string get_joint_sid(Bone *bone, Object *ob_arm) { - char name[100]; - BLI_strncpy(name, bone->name, sizeof(name)); - return translate_id(name); + return get_joint_id(bone, ob_arm); } // parent_mat is armature-space @@ -871,7 +869,7 @@ private: { std::string node_id = get_joint_id(bone, ob_arm); std::string node_name = std::string(bone->name); - std::string node_sid = get_joint_sid(bone); + std::string node_sid = get_joint_sid(bone, ob_arm); COLLADASW::Node node(mSW); @@ -1017,7 +1015,7 @@ private: for (def = (bDeformGroup*)defbase->first; def; def = def->next) { Bone *bone = get_bone_from_defgroup(ob_arm, def); if (bone) - source.appendValues(get_joint_sid(bone)); + source.appendValues(get_joint_sid(bone, ob_arm)); } source.finish(); @@ -1377,7 +1375,6 @@ public: } }; - class EffectsExporter: COLLADASW::LibraryEffects { public: @@ -1786,19 +1783,16 @@ protected: const char *axis_names[] = {"X", "Y", "Z"}; const char *axis_name = NULL; char anim_id[200]; - char anim_name[200]; if (fcu->array_index < 3) axis_name = axis_names[fcu->array_index]; - BLI_snprintf(anim_id, sizeof(anim_id), "%s.%s.%s", (char*)translate_id(ob_name).c_str(), + BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(), fcu->rna_path, axis_names[fcu->array_index]); - BLI_snprintf(anim_name, sizeof(anim_name), "%s.%s.%s", - (char*)ob_name.c_str(), fcu->rna_path, axis_names[fcu->array_index]); // check rna_path is one of: rotation, scale, location - openAnimation(anim_id, anim_name); + openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING); // create input source std::string input_id = create_source_from_fcurve(Sampler::INPUT, fcu, anim_id, axis_name); @@ -1957,7 +1951,6 @@ protected: const char *axis_names[] = {"X", "Y", "Z"}; const char *axis_name = NULL; char anim_id[200]; - char anim_name[200]; bool is_rot = tm_type == 0; if (!fra.size()) @@ -1972,14 +1965,10 @@ protected: std::string transform_sid = get_transform_sid(NULL, tm_type, axis_name); - BLI_snprintf(anim_id, sizeof(anim_id), "%s.%s.%s", (char*)translate_id(ob_name).c_str(), + BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(), (char*)translate_id(bone_name).c_str(), (char*)transform_sid.c_str()); - BLI_snprintf(anim_name, sizeof(anim_name), "%s.%s.%s", - (char*)ob_name.c_str(), (char*)bone_name.c_str(), (char*)transform_sid.c_str()); - - // TODO check rna_path is one of: rotation, scale, location - openAnimation(anim_id, anim_name); + openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING); // create input source std::string input_id = create_source_from_vector(Sampler::INPUT, fra, is_rot, anim_id, axis_name); @@ -2244,13 +2233,13 @@ protected: char *name = extract_transform_name(rna_path); if (strstr(name, "rotation")) - return std::string("rotation") + axis_name; + return std::string("rotation") + std::string(axis_name) + ".ANGLE"; else if (!strcmp(name, "location") || !strcmp(name, "scale")) return std::string(name); } else { if (tm_type == 0) - return std::string("rotation") + axis_name; + return std::string("rotation") + std::string(axis_name) + ".ANGLE"; else return tm_type == 1 ? "scale" : "location"; } -- cgit v1.2.3 From ea1b97a184d54e9c6fa52a89d57d671395eb6483 Mon Sep 17 00:00:00 2001 From: Arystanbek Dyussenov Date: Sat, 23 Jan 2010 12:45:54 +0000 Subject: COLLADA branch: partial fix of bug #20634 * scale and rotation of objects with negative scale is exported correctly. This is accomplished by: ** if ob has no parent, use ob->rot, ob->scale values directly ** if ob has a parent, a local matrix is computed without scale and rotation is derived from it, scale value is copied directly from ob->size Noted a few other bugs: * importer suffers from negative scale problem too * bones with negative scale are exported incorrectly too * object animation values are copied from FCurves which is not ok for child objects where values should be in parent-space --- source/blender/collada/DocumentExporter.cpp | 76 ++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp index f0dd24a735f..8a815418369 100644 --- a/source/blender/collada/DocumentExporter.cpp +++ b/source/blender/collada/DocumentExporter.cpp @@ -669,7 +669,7 @@ class TransformWriter : protected TransformBase protected: void add_node_transform(COLLADASW::Node& node, float mat[][4], float parent_mat[][4]) { - float loc[3], rot[3], size[3]; + float loc[3], rot[3], scale[3]; float local[4][4]; if (parent_mat) { @@ -681,27 +681,61 @@ protected: copy_m4_m4(local, mat); } - TransformBase::decompose(local, loc, rot, NULL, size); + TransformBase::decompose(local, loc, rot, NULL, scale); - /* - // this code used to create a single representing object rotation - float quat[4]; - float axis[3]; - float angle; - double angle_deg; - eul_to_quat( quat,rot); - normalize_qt(quat); - quat_to_axis_angle( axis, &angle,quat); - angle_deg = angle * 180.0f / M_PI; - node.addRotate(axis[0], axis[1], axis[2], angle_deg); - */ - node.addTranslate("location", loc[0], loc[1], loc[2]); + add_transform(node, loc, rot, scale); + } + + void add_node_transform_ob(COLLADASW::Node& node, Object *ob) + { + float rot[3], loc[3], scale[3]; + + if (ob->parent) { + float C[4][4], D[4][4], tmat[4][4], imat[4][4], mat[4][4]; + + // factor out scale from obmat + + copy_v3_v3(scale, ob->size); + + ob->size[0] = ob->size[1] = ob->size[2] = 1.0f; + object_to_mat4(ob, C); + copy_v3_v3(ob->size, scale); + + mul_serie_m4(tmat, ob->parent->obmat, ob->parentinv, C, NULL, NULL, NULL, NULL, NULL); + + // calculate local mat + + invert_m4_m4(imat, ob->parent->obmat); + mul_m4_m4m4(mat, tmat, imat); + + // done + + mat4_to_eul(rot, mat); + copy_v3_v3(loc, mat[3]); + } + else { + copy_v3_v3(loc, ob->loc); + copy_v3_v3(rot, ob->rot); + copy_v3_v3(scale, ob->size); + } + + add_transform(node, loc, rot, scale); + } + + void add_node_transform_identity(COLLADASW::Node& node) + { + float loc[] = {0.0f, 0.0f, 0.0f}, scale[] = {1.0f, 1.0f, 1.0f}, rot[] = {0.0f, 0.0f, 0.0f}; + add_transform(node, loc, rot, scale); + } +private: + void add_transform(COLLADASW::Node& node, float loc[3], float rot[3], float scale[3]) + { + node.addTranslate("location", loc[0], loc[1], loc[2]); node.addRotateZ("rotationZ", COLLADABU::Math::Utils::radToDegF(rot[2])); node.addRotateY("rotationY", COLLADABU::Math::Utils::radToDegF(rot[1])); node.addRotateX("rotationX", COLLADABU::Math::Utils::radToDegF(rot[0])); - - node.addScale("scale", size[0], size[1], size[2]); + node.addScale("scale", scale[0], scale[1], scale[2]); } }; @@ -1238,15 +1272,11 @@ public: bool is_skinned_mesh = arm_exporter->is_skinned_mesh(ob); - float mat[4][4]; - if (ob->type == OB_MESH && is_skinned_mesh) // for skinned mesh we write obmat in - unit_m4(mat); + TransformWriter::add_node_transform_identity(node); else - copy_m4_m4(mat, ob->obmat); - - TransformWriter::add_node_transform(node, mat, ob->parent ? ob->parent->obmat : NULL); + TransformWriter::add_node_transform_ob(node, ob); // if (ob->type == OB_MESH) { -- cgit v1.2.3 From 669533437778339e293c8b2bfefa32166a6cc708 Mon Sep 17 00:00:00 2001 From: Arystanbek Dyussenov Date: Sat, 23 Jan 2010 17:33:40 +0000 Subject: COLLADA branch: patch for importer from Sergey I. Sharybin to build against OpenCollada at revision 721. Thanks Sergey! People who want to build this branch will need update their OpenCollada. On Linux OpenCollada builds without patching. As usual I updated the build doc: http://wiki.blender.org/index.php/User:Kazanbas/Building_Collada_Branch#Building_the_COLLADA_GSoC_branch A small change will be necessary in cmake and scons options on Mac and Windows: OpenCollada's libBuffer was renamed to libbuffer. --- CMakeLists.txt | 2 +- config/linux2-config.py | 2 +- source/blender/collada/DocumentImporter.cpp | 29 +++++++++++++---------------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5bce899c5f..077b5125de9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -217,7 +217,7 @@ IF(UNIX AND NOT APPLE) IF (WITH_OPENCOLLADA) SET(OPENCOLLADA /usr/local/opencollada CACHE FILEPATH "OpenCollada Directory") SET(OPENCOLLADA_LIBPATH ${OPENCOLLADA}/lib) - SET(OPENCOLLADA_LIB OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa Buffer) + SET(OPENCOLLADA_LIB OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre ftoa buffer) SET(OPENCOLLADA_INC ${OPENCOLLADA}) SET(PCRE /usr CACHE FILEPATH "PCRE Directory") SET(PCRE_LIBPATH ${PCRE}/lib) diff --git a/config/linux2-config.py b/config/linux2-config.py index fe07d6dd307..cf79a6a870f 100644 --- a/config/linux2-config.py +++ b/config/linux2-config.py @@ -156,7 +156,7 @@ BF_COLLADA = '#source/blender/collada' BF_COLLADA_INC = '${BF_COLLADA}' BF_COLLADA_LIB = 'bf_collada' BF_OPENCOLLADA = '/usr' -BF_OPENCOLLADA_LIB = 'OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre Buffer ftoa' +BF_OPENCOLLADA_LIB = 'OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver pcre buffer ftoa' BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib' BF_PCRE = '' BF_PCRE_LIB = 'pcre' diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 26e95c378a6..ad8edccbf89 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -1564,15 +1564,13 @@ public: return NULL; } - MTex *assign_textures_to_uvlayer(COLLADAFW::InstanceGeometry::TextureCoordinateBinding &ctexture, + MTex *assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture, Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map, MTex *color_texture) { - - COLLADAFW::TextureMapId texture_index = ctexture.textureMapId; - - char *uvname = CustomData_get_layer_name(&me->fdata, CD_MTFACE, ctexture.setIndex); - + COLLADAFW::TextureMapId texture_index = ctexture.getTextureMapId(); + char *uvname = CustomData_get_layer_name(&me->fdata, CD_MTFACE, ctexture.getSetIndex()); + if (texindex_texarray_map.find(texture_index) == texindex_texarray_map.end()) { fprintf(stderr, "Cannot find texture array by texture index.\n"); @@ -1595,7 +1593,7 @@ public: return color_texture; } - MTFace *assign_material_to_geom(COLLADAFW::InstanceGeometry::MaterialBinding cmaterial, + MTFace *assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial, std::map& uid_material_map, Object *ob, const COLLADAFW::UniqueId *geom_uid, MTex **color_texture, char *layername, MTFace *texture_face, @@ -1614,7 +1612,7 @@ public: Material *ma = uid_material_map[ma_uid]; assign_material(ob, ma, ob->totcol + 1); - COLLADAFW::InstanceGeometry::TextureCoordinateBindingArray& tex_array = + COLLADAFW::TextureCoordinateBindingArray& tex_array = cmaterial.getTextureCoordinateBindingArray(); TexIndexTextureArrayMap texindex_texarray_map = material_texture_mapping_map[ma]; unsigned int i; @@ -1714,7 +1712,7 @@ public: MTFace *texture_face = NULL; MTex *color_texture = NULL; - COLLADAFW::InstanceGeometry::MaterialBindingArray& mat_array = + COLLADAFW::MaterialBindingArray& mat_array = geom->getMaterialBindings(); // loop through geom's materials @@ -3130,7 +3128,7 @@ public: ob = create_lamp_object(lamp[0], ob, sce); } else if (controller.getCount() != 0) { - COLLADAFW::InstanceController *geom = (COLLADAFW::InstanceController*)controller[0]; + COLLADAFW::InstanceGeometry *geom = (COLLADAFW::InstanceGeometry*)controller[0]; ob = mesh_importer.create_mesh_object(node, geom, true, uid_material_map, material_texture_mapping_map); } // XXX instance_node is not supported yet @@ -3284,7 +3282,6 @@ public: int i = 0; COLLADAFW::Color col; - COLLADAFW::Texture ctex; MTex *mtex = NULL; TexIndexTextureArrayMap texindex_texarray_map; @@ -3298,7 +3295,7 @@ public: } // texture else if (ef->getDiffuse().isTexture()) { - ctex = ef->getDiffuse().getTexture(); + COLLADAFW::Texture ctex = ef->getDiffuse().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { mtex->mapto = MAP_COL; @@ -3316,7 +3313,7 @@ public: } // texture else if (ef->getAmbient().isTexture()) { - ctex = ef->getAmbient().getTexture(); + COLLADAFW::Texture ctex = ef->getAmbient().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { mtex->mapto = MAP_AMB; @@ -3333,7 +3330,7 @@ public: } // texture else if (ef->getSpecular().isTexture()) { - ctex = ef->getSpecular().getTexture(); + COLLADAFW::Texture ctex = ef->getSpecular().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { mtex->mapto = MAP_SPEC; @@ -3350,7 +3347,7 @@ public: } // texture else if (ef->getReflective().isTexture()) { - ctex = ef->getReflective().getTexture(); + COLLADAFW::Texture ctex = ef->getReflective().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { mtex->mapto = MAP_REF; @@ -3365,7 +3362,7 @@ public: } // texture else if (ef->getEmission().isTexture()) { - ctex = ef->getEmission().getTexture(); + COLLADAFW::Texture ctex = ef->getEmission().getTexture(); mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); if (mtex != NULL) { mtex->mapto = MAP_EMIT; -- cgit v1.2.3 From 8597925736b32f3151e22fc993ac212dc8208b8e Mon Sep 17 00:00:00 2001 From: Arystanbek Dyussenov Date: Sat, 30 Jan 2010 18:03:18 +0000 Subject: COLLADA branch: updated vc9 project files and w32 scons config. --- config/win32-vc-config.py | 2 +- projectfiles_vc9/blender/blender.vcproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/win32-vc-config.py b/config/win32-vc-config.py index a93145d2134..0fe3fd657d2 100644 --- a/config/win32-vc-config.py +++ b/config/win32-vc-config.py @@ -145,7 +145,7 @@ BF_COLLADA_LIB = 'bf_collada' BF_OPENCOLLADA = LIBDIR + '/opencollada' BF_OPENCOLLADA_INC = '${BF_OPENCOLLADA}/include' -BF_OPENCOLLADA_LIB = 'OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver xml2 pcre' +BF_OPENCOLLADA_LIB = 'OpenCOLLADAStreamWriter OpenCOLLADASaxFrameworkLoader OpenCOLLADAFramework OpenCOLLADABaseUtils GeneratedSaxParser UTF MathMLSolver xml2 pcre buffer ftoa' BF_OPENCOLLADA_LIBPATH = '${BF_OPENCOLLADA}/lib' #Ray trace optimization diff --git a/projectfiles_vc9/blender/blender.vcproj b/projectfiles_vc9/blender/blender.vcproj index 0d7f3c66ff0..5fda32fdefc 100644 --- a/projectfiles_vc9/blender/blender.vcproj +++ b/projectfiles_vc9/blender/blender.vcproj @@ -74,7 +74,7 @@