Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed, 00019 * Nathan Letwory 00020 * 00021 * ***** END GPL LICENSE BLOCK ***** 00022 */ 00023 00029 #include "BKE_object.h" 00030 00031 #include "TransformWriter.h" 00032 00033 #include "BLI_math.h" 00034 00035 void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[][4], float parent_mat[][4]) 00036 { 00037 float loc[3], rot[3], scale[3]; 00038 float local[4][4]; 00039 00040 if (parent_mat) { 00041 float invpar[4][4]; 00042 invert_m4_m4(invpar, parent_mat); 00043 mult_m4_m4m4(local, invpar, mat); 00044 } 00045 else { 00046 copy_m4_m4(local, mat); 00047 } 00048 00049 double dmat[4][4]; 00050 UnitConverter* converter = new UnitConverter(); 00051 converter->mat4_to_dae_double(dmat,local); 00052 00053 TransformBase::decompose(local, loc, rot, NULL, scale); 00054 if ( node.getType() == COLLADASW::Node::JOINT) 00055 node.addMatrix("transform",dmat); 00056 else 00057 add_transform(node, loc, rot, scale); 00058 } 00059 00060 void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob) 00061 { 00062 float rot[3], loc[3], scale[3]; 00063 00064 if (ob->parent) { 00065 float C[4][4], tmat[4][4], imat[4][4], mat[4][4]; 00066 00067 // factor out scale from obmat 00068 00069 copy_v3_v3(scale, ob->size); 00070 00071 ob->size[0] = ob->size[1] = ob->size[2] = 1.0f; 00072 object_to_mat4(ob, C); 00073 copy_v3_v3(ob->size, scale); 00074 00075 mul_serie_m4(tmat, ob->parent->obmat, ob->parentinv, C, NULL, NULL, NULL, NULL, NULL); 00076 00077 // calculate local mat 00078 00079 invert_m4_m4(imat, ob->parent->obmat); 00080 mult_m4_m4m4(mat, imat, tmat); 00081 00082 // done 00083 00084 mat4_to_eul(rot, mat); 00085 copy_v3_v3(loc, mat[3]); 00086 } 00087 else { 00088 copy_v3_v3(loc, ob->loc); 00089 copy_v3_v3(rot, ob->rot); 00090 copy_v3_v3(scale, ob->size); 00091 } 00092 00093 add_transform(node, loc, rot, scale); 00094 } 00095 00096 void TransformWriter::add_node_transform_identity(COLLADASW::Node& node) 00097 { 00098 float loc[] = {0.0f, 0.0f, 0.0f}, scale[] = {1.0f, 1.0f, 1.0f}, rot[] = {0.0f, 0.0f, 0.0f}; 00099 add_transform(node, loc, rot, scale); 00100 } 00101 00102 void TransformWriter::add_transform(COLLADASW::Node& node, float loc[3], float rot[3], float scale[3]) 00103 { 00104 node.addTranslate("location", loc[0], loc[1], loc[2]); 00105 /*node.addRotateZ("rotationZ", COLLADABU::Math::Utils::radToDegF(rot[2])); 00106 node.addRotateY("rotationY", COLLADABU::Math::Utils::radToDegF(rot[1])); 00107 node.addRotateX("rotationX", COLLADABU::Math::Utils::radToDegF(rot[0]));*/ 00108 node.addRotateZ("rotationZ", RAD2DEGF(rot[2])); 00109 node.addRotateY("rotationY", RAD2DEGF(rot[1])); 00110 node.addRotateX("rotationX", RAD2DEGF(rot[0])); 00111 00112 node.addScale("scale", scale[0], scale[1], scale[2]); 00113 }