2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory.
20
* ***** END GPL LICENSE BLOCK *****
23
/** \file blender/collada/collada_utils.cpp
28
/* COLLADABU_ASSERT, may be able to remove later */
29
#include "COLLADABUPlatform.h"
31
#include "COLLADAFWGeometry.h"
32
#include "COLLADAFWMeshPrimitive.h"
33
#include "COLLADAFWMeshVertexData.h"
35
#include "DNA_customdata_types.h"
36
#include "DNA_object_types.h"
37
#include "DNA_scene_types.h"
41
#include "BKE_context.h"
42
#include "BKE_customdata.h"
43
#include "BKE_depsgraph.h"
44
#include "BKE_object.h"
45
#include "BKE_scene.h"
47
#include "WM_api.h" // XXX hrm, see if we can do without this
50
float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index)
52
if (index >= array.getValuesCount())
55
if (array.getType() == COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT)
56
return array.getFloatValues()->getData()[index];
58
return array.getDoubleValues()->getData()[index];
61
// copied from /editors/object/object_relations.c
62
int bc_test_parent_loop(Object *par, Object *ob)
64
/* test if 'ob' is a parent somewhere in par's parents */
66
if (par == NULL) return 0;
67
if (ob == par) return 1;
69
return bc_test_parent_loop(par->parent, ob);
72
// a shortened version of parent_set_exec()
73
// if is_parent_space is true then ob->obmat will be multiplied by par->obmat before parenting
74
int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
77
Main *bmain = CTX_data_main(C);
78
Scene *sce = CTX_data_scene(C);
80
if (!par || bc_test_parent_loop(par, ob))
84
ob->partype = PAROBJECT;
88
if (is_parent_space) {
91
where_is_object(sce, par);
93
// move child obmat into world space
94
mult_m4_m4m4(mat, par->obmat, ob->obmat);
95
copy_m4_m4(ob->obmat, mat);
98
// apply child obmat (i.e. decompose it into rot/loc/size)
99
object_apply_mat4(ob, ob->obmat, 0, 0);
102
what_does_parent(sce, ob, &workob);
103
invert_m4_m4(ob->parentinv, workob.obmat);
105
ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA;
106
par->recalc |= OB_RECALC_OB;
108
DAG_scene_sort(bmain, sce);
109
DAG_ids_flush_update(bmain, 0);
110
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
115
Object *bc_add_object(Scene *scene, int type, const char *name)
117
Object *ob = add_only_object(type, name);
119
ob->data= add_obdata_from_type(type);
121
ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
123
scene_select_base(scene, scene_add_base(scene, ob));