98
109
// apply child obmat (i.e. decompose it into rot/loc/size)
99
object_apply_mat4(ob, ob->obmat, 0, 0);
110
BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
101
112
// compute parentinv
102
what_does_parent(sce, ob, &workob);
113
BKE_object_workob_calc_parent(sce, ob, &workob);
103
114
invert_m4_m4(ob->parentinv, workob.obmat);
105
116
ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA;
106
117
par->recalc |= OB_RECALC_OB;
119
/** done once after import
108
120
DAG_scene_sort(bmain, sce);
109
121
DAG_ids_flush_update(bmain, 0);
110
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
122
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
115
129
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));
131
Object *ob = BKE_object_add_only_object(G.main, type, name);
133
ob->data = BKE_object_obdata_add_from_type(type);
134
ob->lay = scene->lay;
135
ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
137
BKE_scene_base_select(scene, BKE_scene_base_add(scene, ob));
142
Mesh *bc_to_mesh_apply_modifiers(Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type)
145
CustomDataMask mask = CD_MASK_MESH;
146
DerivedMesh *dm = NULL;
147
switch (export_mesh_type) {
148
case BC_MESH_TYPE_VIEW: {
149
dm = mesh_create_derived_view(scene, ob, mask);
152
case BC_MESH_TYPE_RENDER: {
153
dm = mesh_create_derived_render(scene, ob, mask);
158
tmpmesh = BKE_mesh_add(G.main, "ColladaMesh"); // name is not important here
159
DM_to_mesh(dm, tmpmesh, ob);
164
Object *bc_get_assigned_armature(Object *ob)
166
Object *ob_arm = NULL;
168
if (ob->parent && ob->partype == PARSKEL && ob->parent->type == OB_ARMATURE) {
173
for (mod = (ModifierData *)ob->modifiers.first; mod; mod = mod->next) {
174
if (mod->type == eModifierType_Armature) {
175
ob_arm = ((ArmatureModifierData *)mod)->object;
183
// Returns the highest selected ancestor
184
// returns NULL if no ancestor is selected
185
// IMPORTANT: This function expects that
186
// all exported objects have set:
187
// ob->id.flag & LIB_DOIT
188
Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob)
190
Object *ancestor = ob;
191
while (ob->parent && bc_is_marked(ob->parent)) {
199
bool bc_is_base_node(LinkNode *export_set, Object *ob)
201
Object *root = bc_get_highest_selected_ancestor_or_self(export_set, ob);
205
bool bc_is_in_Export_set(LinkNode *export_set, Object *ob)
207
return (BLI_linklist_index(export_set, ob) != -1);
210
bool bc_has_object_type(LinkNode *export_set, short obtype)
214
for (node = export_set; node; node = node->next) {
215
Object *ob = (Object *)node->link;
216
/* XXX - why is this checking for ob->data? - we could be looking for empties */
217
if (ob->type == obtype && ob->data) {
224
int bc_is_marked(Object *ob)
226
return ob && (ob->id.flag & LIB_DOIT);
229
void bc_remove_mark(Object *ob)
231
ob->id.flag &= ~LIB_DOIT;
234
void bc_set_mark(Object *ob)
236
ob->id.flag |= LIB_DOIT;
239
// Use bubble sort algorithm for sorting the export set
240
void bc_bubble_sort_by_Object_name(LinkNode *export_set)
244
for (node = export_set; node->next && !sorted; node = node->next) {
249
for (current = export_set; current->next; current = current->next) {
250
Object *a = (Object *)current->link;
251
Object *b = (Object *)current->next->link;
253
if (strcmp(a->id.name, b->id.name) > 0) {
255
current->next->link = a;
263
/* Check if a bone is the top most exportable bone in the bone hierarchy.
264
* When deform_bones_only == false, then only bones with NO parent
265
* can be root bones. Otherwise the top most deform bones in the hierarchy
268
bool bc_is_root_bone(Bone *aBone, bool deform_bones_only)
270
if (deform_bones_only) {
274
if (!(bone->flag & BONE_NO_DEFORM))
278
return (aBone == root);
281
return !(aBone->parent);
284
int bc_get_active_UVLayer(Object *ob)
286
Mesh *me = (Mesh *)ob->data;
287
return CustomData_get_active_layer_index(&me->fdata, CD_MTFACE);
290
std::string bc_url_encode(std::string data) {
291
/* XXX We probably do not need to do a full encoding.
292
But in case that is necessary,then it can be added here.
294
return bc_replace_string(data,"#", "%23");
297
std::string bc_replace_string(std::string data, const std::string& pattern,
298
const std::string& replacement) {
300
while((pos = data.find(pattern, pos)) != std::string::npos) {
301
data.replace(pos, pattern.length(), replacement);
302
pos += replacement.length();
308
Calculate a rescale factor such that the imported scene's scale
309
is preserved. I.e. 1 meter in the import will also be
310
1 meter in the current scene.
311
XXX : I am not sure if it is correct to map 1 Blender Unit
312
to 1 Meter for unit type NONE. But it looks reasonable to me.
314
void bc_match_scale(std::vector<Object *> *objects_done,
316
UnitConverter &bc_unit) {
320
PointerRNA scene_ptr, unit_settings;
321
PropertyRNA *system_ptr, *scale_ptr;
322
RNA_id_pointer_create(&sce.id, &scene_ptr);
324
unit_settings = RNA_pointer_get(&scene_ptr, "unit_settings");
325
system_ptr = RNA_struct_find_property(&unit_settings, "system");
326
scale_ptr = RNA_struct_find_property(&unit_settings, "scale_length");
328
int type = RNA_property_enum_get(&unit_settings, system_ptr);
334
bl_scale = 1.0; // map 1 Blender unit to 1 Meter
337
case USER_UNIT_METRIC:
338
bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
342
bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
343
// it looks like the conversion to Imperial is done implicitly.
344
// So nothing to do here.
348
float scale_conv = bc_unit.getLinearMeter() / bl_scale;
351
rescale[0] = rescale[1] = rescale[2] = scale_conv;
353
float size_mat4[4][4];
355
float axis_mat4[4][4];
358
size_to_mat4(size_mat4, rescale);
360
for (std::vector<Object *>::iterator it = objects_done->begin();
361
it != objects_done->end();
365
mult_m4_m4m4(ob->obmat, size_mat4, ob->obmat);
366
mult_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat);
367
BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
b'\\ No newline at end of file'