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, Nathan Letwory. 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 */ 00022 00028 /* COLLADABU_ASSERT, may be able to remove later */ 00029 #include "COLLADABUPlatform.h" 00030 00031 #include "COLLADAFWGeometry.h" 00032 #include "COLLADAFWMeshPrimitive.h" 00033 #include "COLLADAFWMeshVertexData.h" 00034 00035 #include "DNA_customdata_types.h" 00036 #include "DNA_object_types.h" 00037 00038 #include "BLI_math.h" 00039 00040 #include "BKE_context.h" 00041 #include "BKE_customdata.h" 00042 #include "BKE_depsgraph.h" 00043 #include "BKE_object.h" 00044 00045 #include "WM_api.h" // XXX hrm, see if we can do without this 00046 #include "WM_types.h" 00047 00048 float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index) 00049 { 00050 if (index >= array.getValuesCount()) 00051 return 0.0f; 00052 00053 if (array.getType() == COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT) 00054 return array.getFloatValues()->getData()[index]; 00055 else 00056 return array.getDoubleValues()->getData()[index]; 00057 } 00058 00059 // copied from /editors/object/object_relations.c 00060 int bc_test_parent_loop(Object *par, Object *ob) 00061 { 00062 /* test if 'ob' is a parent somewhere in par's parents */ 00063 00064 if(par == NULL) return 0; 00065 if(ob == par) return 1; 00066 00067 return bc_test_parent_loop(par->parent, ob); 00068 } 00069 00070 // a shortened version of parent_set_exec() 00071 // if is_parent_space is true then ob->obmat will be multiplied by par->obmat before parenting 00072 int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) 00073 { 00074 Object workob; 00075 Main *bmain = CTX_data_main(C); 00076 Scene *sce = CTX_data_scene(C); 00077 00078 if (!par || bc_test_parent_loop(par, ob)) 00079 return false; 00080 00081 ob->parent = par; 00082 ob->partype = PAROBJECT; 00083 00084 ob->parsubstr[0] = 0; 00085 00086 if (is_parent_space) { 00087 float mat[4][4]; 00088 // calc par->obmat 00089 where_is_object(sce, par); 00090 00091 // move child obmat into world space 00092 mult_m4_m4m4(mat, par->obmat, ob->obmat); 00093 copy_m4_m4(ob->obmat, mat); 00094 } 00095 00096 // apply child obmat (i.e. decompose it into rot/loc/size) 00097 object_apply_mat4(ob, ob->obmat, 0, 0); 00098 00099 // compute parentinv 00100 what_does_parent(sce, ob, &workob); 00101 invert_m4_m4(ob->parentinv, workob.obmat); 00102 00103 ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA; 00104 par->recalc |= OB_RECALC_OB; 00105 00106 DAG_scene_sort(bmain, sce); 00107 DAG_ids_flush_update(bmain, 0); 00108 WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); 00109 00110 return true; 00111 } 00112