|
Blender
V2.59
|
00001 /* 00002 * $Id: collada_utils.cpp 35243 2011-02-27 20:30:35Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory. 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00030 /* COLLADABU_ASSERT, may be able to remove later */ 00031 #include "COLLADABUPlatform.h" 00032 00033 #include "COLLADAFWGeometry.h" 00034 #include "COLLADAFWMeshPrimitive.h" 00035 #include "COLLADAFWMeshVertexData.h" 00036 00037 #include "DNA_customdata_types.h" 00038 #include "DNA_object_types.h" 00039 00040 #include "BLI_math.h" 00041 00042 #include "BKE_context.h" 00043 #include "BKE_customdata.h" 00044 #include "BKE_depsgraph.h" 00045 #include "BKE_object.h" 00046 00047 #include "WM_api.h" // XXX hrm, see if we can do without this 00048 #include "WM_types.h" 00049 00050 float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index) 00051 { 00052 if (index >= array.getValuesCount()) 00053 return 0.0f; 00054 00055 if (array.getType() == COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT) 00056 return array.getFloatValues()->getData()[index]; 00057 else 00058 return array.getDoubleValues()->getData()[index]; 00059 } 00060 00061 // copied from /editors/object/object_relations.c 00062 int bc_test_parent_loop(Object *par, Object *ob) 00063 { 00064 /* test if 'ob' is a parent somewhere in par's parents */ 00065 00066 if(par == NULL) return 0; 00067 if(ob == par) return 1; 00068 00069 return bc_test_parent_loop(par->parent, ob); 00070 } 00071 00072 // a shortened version of parent_set_exec() 00073 // if is_parent_space is true then ob->obmat will be multiplied by par->obmat before parenting 00074 int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) 00075 { 00076 Object workob; 00077 Main *bmain = CTX_data_main(C); 00078 Scene *sce = CTX_data_scene(C); 00079 00080 if (!par || bc_test_parent_loop(par, ob)) 00081 return false; 00082 00083 ob->parent = par; 00084 ob->partype = PAROBJECT; 00085 00086 ob->parsubstr[0] = 0; 00087 00088 if (is_parent_space) { 00089 float mat[4][4]; 00090 // calc par->obmat 00091 where_is_object(sce, par); 00092 00093 // move child obmat into world space 00094 mul_m4_m4m4(mat, ob->obmat, par->obmat); 00095 copy_m4_m4(ob->obmat, mat); 00096 } 00097 00098 // apply child obmat (i.e. decompose it into rot/loc/size) 00099 object_apply_mat4(ob, ob->obmat, 0, 0); 00100 00101 // compute parentinv 00102 what_does_parent(sce, ob, &workob); 00103 invert_m4_m4(ob->parentinv, workob.obmat); 00104 00105 ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA; 00106 par->recalc |= OB_RECALC_OB; 00107 00108 DAG_scene_sort(bmain, sce); 00109 DAG_ids_flush_update(bmain, 0); 00110 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); 00111 00112 return true; 00113 } 00114