From 82209cdc86f5f248102df89b3dfeca86149768f7 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Tue, 5 Oct 2010 00:05:14 +0000 Subject: Reorganisation of COLLADA import code. Classes have been split into their own files. No functional changes. Where necessary extern "C" {} blocks have been added. --- source/blender/collada/collada_utils.cpp | 106 +++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 source/blender/collada/collada_utils.cpp (limited to 'source/blender/collada/collada_utils.cpp') diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp new file mode 100644 index 00000000000..ec0bc91ee0b --- /dev/null +++ b/source/blender/collada/collada_utils.cpp @@ -0,0 +1,106 @@ +/** + * $Id: DocumentImporter.cpp 32235 2010-10-01 19:46:42Z jesterking $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "COLLADAFWGeometry.h" +#include "COLLADAFWMeshPrimitive.h" +#include "COLLADAFWMeshVertexData.h" + +#include "DNA_customdata_types.h" +#include "DNA_object_types.h" + +#include "BLI_math.h" + +#include "BKE_context.h" +#include "BKE_customdata.h" +#include "BKE_depsgraph.h" +#include "BKE_object.h" + +#include "WM_api.h" // XXX hrm, see if we can do without this +#include "WM_types.h" + +float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index) +{ + if (index >= array.getValuesCount()) + return 0.0f; + + if (array.getType() == COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT) + return array.getFloatValues()->getData()[index]; + else + return array.getDoubleValues()->getData()[index]; +} + +// copied from /editors/object/object_relations.c +int bc_test_parent_loop(Object *par, Object *ob) +{ + /* test if 'ob' is a parent somewhere in par's parents */ + + if(par == NULL) return 0; + if(ob == par) return 1; + + return bc_test_parent_loop(par->parent, ob); +} + +// a shortened version of parent_set_exec() +// if is_parent_space is true then ob->obmat will be multiplied by par->obmat before parenting +int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space) +{ + Object workob; + Main *bmain = CTX_data_main(C); + Scene *sce = CTX_data_scene(C); + + if (!par || bc_test_parent_loop(par, ob)) + return false; + + ob->parent = par; + ob->partype = PAROBJECT; + + ob->parsubstr[0] = 0; + + if (is_parent_space) { + float mat[4][4]; + // calc par->obmat + where_is_object(sce, par); + + // move child obmat into world space + mul_m4_m4m4(mat, ob->obmat, par->obmat); + copy_m4_m4(ob->obmat, mat); + } + + // apply child obmat (i.e. decompose it into rot/loc/size) + object_apply_mat4(ob, ob->obmat); + + // compute parentinv + what_does_parent(sce, ob, &workob); + invert_m4_m4(ob->parentinv, workob.obmat); + + ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA; + par->recalc |= OB_RECALC_OB; + + DAG_scene_sort(bmain, sce); + DAG_ids_flush_update(bmain, 0); + WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL); + + return true; +} + -- cgit v1.2.3