~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/collada/collada_utils.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory.
 
19
 *
 
20
 * ***** END GPL LICENSE BLOCK *****
 
21
 */
 
22
 
 
23
/** \file blender/collada/collada_utils.cpp
 
24
 *  \ingroup collada
 
25
 */
 
26
 
 
27
 
 
28
/* COLLADABU_ASSERT, may be able to remove later */
 
29
#include "COLLADABUPlatform.h"
 
30
 
 
31
#include "COLLADAFWGeometry.h"
 
32
#include "COLLADAFWMeshPrimitive.h"
 
33
#include "COLLADAFWMeshVertexData.h"
 
34
 
 
35
#include "DNA_customdata_types.h"
 
36
#include "DNA_object_types.h"
 
37
#include "DNA_scene_types.h"
 
38
 
 
39
#include "BLI_math.h"
 
40
 
 
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"
 
46
 
 
47
#include "WM_api.h" // XXX hrm, see if we can do without this
 
48
#include "WM_types.h"
 
49
 
 
50
float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index)
 
51
{
 
52
        if (index >= array.getValuesCount())
 
53
                return 0.0f;
 
54
 
 
55
        if (array.getType() == COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT)
 
56
                return array.getFloatValues()->getData()[index];
 
57
        else 
 
58
                return array.getDoubleValues()->getData()[index];
 
59
}
 
60
 
 
61
// copied from /editors/object/object_relations.c
 
62
int bc_test_parent_loop(Object *par, Object *ob)
 
63
{
 
64
        /* test if 'ob' is a parent somewhere in par's parents */
 
65
        
 
66
        if (par == NULL) return 0;
 
67
        if (ob == par) return 1;
 
68
        
 
69
        return bc_test_parent_loop(par->parent, ob);
 
70
}
 
71
 
 
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)
 
75
{
 
76
        Object workob;
 
77
        Main *bmain = CTX_data_main(C);
 
78
        Scene *sce = CTX_data_scene(C);
 
79
        
 
80
        if (!par || bc_test_parent_loop(par, ob))
 
81
                return false;
 
82
 
 
83
        ob->parent = par;
 
84
        ob->partype = PAROBJECT;
 
85
 
 
86
        ob->parsubstr[0] = 0;
 
87
 
 
88
        if (is_parent_space) {
 
89
                float mat[4][4];
 
90
                // calc par->obmat
 
91
                where_is_object(sce, par);
 
92
 
 
93
                // move child obmat into world space
 
94
                mult_m4_m4m4(mat, par->obmat, ob->obmat);
 
95
                copy_m4_m4(ob->obmat, mat);
 
96
        }
 
97
        
 
98
        // apply child obmat (i.e. decompose it into rot/loc/size)
 
99
        object_apply_mat4(ob, ob->obmat, 0, 0);
 
100
 
 
101
        // compute parentinv
 
102
        what_does_parent(sce, ob, &workob);
 
103
        invert_m4_m4(ob->parentinv, workob.obmat);
 
104
 
 
105
        ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA;
 
106
        par->recalc |= OB_RECALC_OB;
 
107
 
 
108
        DAG_scene_sort(bmain, sce);
 
109
        DAG_ids_flush_update(bmain, 0);
 
110
        WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
 
111
 
 
112
        return true;
 
113
}
 
114
 
 
115
Object *bc_add_object(Scene *scene, int type, const char *name)
 
116
{
 
117
        Object *ob = add_only_object(type, name);
 
118
 
 
119
        ob->data= add_obdata_from_type(type);
 
120
        ob->lay= scene->lay;
 
121
        ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
 
122
 
 
123
        scene_select_base(scene, scene_add_base(scene, ob));
 
124
 
 
125
        return ob;
 
126
}
 
127