Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/object.c
| Show First 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_idprop.h" | #include "BKE_idprop.h" | ||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_action.h" | #include "BKE_action.h" | ||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| #include "BKE_DerivedMesh.h" | #include "BKE_DerivedMesh.h" | ||||
| #include "BKE_animsys.h" | #include "BKE_animsys.h" | ||||
| #include "BKE_anim.h" | #include "BKE_anim.h" | ||||
| #include "BKE_collection.h" | |||||
| #include "BKE_constraint.h" | #include "BKE_constraint.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_displist.h" | #include "BKE_displist.h" | ||||
| #include "BKE_effect.h" | #include "BKE_effect.h" | ||||
| #include "BKE_fcurve.h" | #include "BKE_fcurve.h" | ||||
| #include "BKE_group.h" | |||||
| #include "BKE_icons.h" | #include "BKE_icons.h" | ||||
| #include "BKE_key.h" | #include "BKE_key.h" | ||||
| #include "BKE_lamp.h" | #include "BKE_lamp.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_library_query.h" | #include "BKE_library_query.h" | ||||
| #include "BKE_library_remap.h" | #include "BKE_library_remap.h" | ||||
| ▲ Show 20 Lines • Show All 619 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| if (!name) | if (!name) | ||||
| name = get_obdata_defname(type); | name = get_obdata_defname(type); | ||||
| ob = BKE_libblock_alloc(bmain, ID_OB, name, 0); | ob = BKE_libblock_alloc(bmain, ID_OB, name, 0); | ||||
| /* We increase object user count when linking to SceneCollections. */ | /* We increase object user count when linking to Collections. */ | ||||
| id_us_min(&ob->id); | id_us_min(&ob->id); | ||||
| /* default object vars */ | /* default object vars */ | ||||
| ob->type = type; | ob->type = type; | ||||
| BKE_object_init(ob); | BKE_object_init(ob); | ||||
| return ob; | return ob; | ||||
| Show All 10 Lines | static Object *object_add_common(Main *bmain, ViewLayer *view_layer, int type, const char *name) | ||||
| DEG_id_tag_update_ex(bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); | DEG_id_tag_update_ex(bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); | ||||
| return ob; | return ob; | ||||
| } | } | ||||
| /** | /** | ||||
| * General add: to scene, with layer from area and default name | * General add: to scene, with layer from area and default name | ||||
| * | * | ||||
| * Object is added to the active SceneCollection. | * Object is added to the active Collection. | ||||
| * If there is no linked collection to the active ViewLayer we create a new one. | * If there is no linked collection to the active ViewLayer we create a new one. | ||||
| */ | */ | ||||
| /* creates minimum required data, but without vertices etc. */ | /* creates minimum required data, but without vertices etc. */ | ||||
| Object *BKE_object_add( | Object *BKE_object_add( | ||||
| Main *bmain, Scene *scene, ViewLayer *view_layer, | Main *bmain, Scene *UNUSED(scene), ViewLayer *view_layer, | ||||
| int type, const char *name) | int type, const char *name) | ||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| Base *base; | Base *base; | ||||
| LayerCollection *layer_collection; | LayerCollection *layer_collection; | ||||
| ob = object_add_common(bmain, view_layer, type, name); | ob = object_add_common(bmain, view_layer, type, name); | ||||
| layer_collection = BKE_layer_collection_get_active_ensure(scene, view_layer); | layer_collection = BKE_layer_collection_get_active(view_layer); | ||||
| BKE_collection_object_add(&scene->id, layer_collection->scene_collection, ob); | BKE_collection_object_add(bmain, layer_collection->collection, ob); | ||||
| base = BKE_view_layer_base_find(view_layer, ob); | base = BKE_view_layer_base_find(view_layer, ob); | ||||
| BKE_view_layer_base_select(view_layer, base); | BKE_view_layer_base_select(view_layer, base); | ||||
| return ob; | return ob; | ||||
| } | } | ||||
| /** | /** | ||||
| * Add a new object, using another one as a reference | * Add a new object, using another one as a reference | ||||
| * | * | ||||
| * /param ob_src object to use to determine the collections of the new object. | * /param ob_src object to use to determine the collections of the new object. | ||||
| */ | */ | ||||
| Object *BKE_object_add_from( | Object *BKE_object_add_from( | ||||
| Main *bmain, Scene *scene, ViewLayer *view_layer, | Main *bmain, Scene *scene, ViewLayer *view_layer, | ||||
| int type, const char *name, Object *ob_src) | int type, const char *name, Object *ob_src) | ||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| Base *base; | Base *base; | ||||
| ob = object_add_common(bmain, view_layer, type, name); | ob = object_add_common(bmain, view_layer, type, name); | ||||
| BKE_collection_object_add_from(scene, ob_src, ob); | BKE_collection_object_add_from(bmain, scene, ob_src, ob); | ||||
| base = BKE_view_layer_base_find(view_layer, ob); | base = BKE_view_layer_base_find(view_layer, ob); | ||||
| BKE_view_layer_base_select(view_layer, base); | BKE_view_layer_base_select(view_layer, base); | ||||
| return ob; | return ob; | ||||
| } | } | ||||
| SoftBody *copy_softbody(const SoftBody *sb, const int flag) | SoftBody *copy_softbody(const SoftBody *sb, const int flag) | ||||
| ▲ Show 20 Lines • Show All 358 Lines • ▼ Show 20 Lines | if (ob_src->totcol) { | ||||
| ob_dst->mat = MEM_dupallocN(ob_src->mat); | ob_dst->mat = MEM_dupallocN(ob_src->mat); | ||||
| ob_dst->matbits = MEM_dupallocN(ob_src->matbits); | ob_dst->matbits = MEM_dupallocN(ob_src->matbits); | ||||
| ob_dst->totcol = ob_src->totcol; | ob_dst->totcol = ob_src->totcol; | ||||
| } | } | ||||
| if (ob_src->iuser) ob_dst->iuser = MEM_dupallocN(ob_src->iuser); | if (ob_src->iuser) ob_dst->iuser = MEM_dupallocN(ob_src->iuser); | ||||
| if (ob_src->bb) ob_dst->bb = MEM_dupallocN(ob_src->bb); | if (ob_src->bb) ob_dst->bb = MEM_dupallocN(ob_src->bb); | ||||
| ob_dst->flag &= ~OB_FROMGROUP; | |||||
| BLI_listbase_clear(&ob_dst->modifiers); | BLI_listbase_clear(&ob_dst->modifiers); | ||||
| for (md = ob_src->modifiers.first; md; md = md->next) { | for (md = ob_src->modifiers.first; md; md = md->next) { | ||||
| ModifierData *nmd = modifier_new(md->type); | ModifierData *nmd = modifier_new(md->type); | ||||
| BLI_strncpy(nmd->name, md->name, sizeof(nmd->name)); | BLI_strncpy(nmd->name, md->name, sizeof(nmd->name)); | ||||
| modifier_copyData_ex(md, nmd, flag_subdata); | modifier_copyData_ex(md, nmd, flag_subdata); | ||||
| BLI_addtail(&ob_dst->modifiers, nmd); | BLI_addtail(&ob_dst->modifiers, nmd); | ||||
| ▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | for (fcu = ob->adt->drivers.first; fcu; fcu = fcu->next) { | ||||
| DRIVER_TARGETS_LOOPER_END | DRIVER_TARGETS_LOOPER_END | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* proxy rule: lib_object->proxy_from == the one we borrow from, set temporally while object_update */ | /* proxy rule: lib_object->proxy_from == the one we borrow from, set temporally while object_update */ | ||||
| /* local_object->proxy == pointer to library object, saved in files and read */ | /* local_object->proxy == pointer to library object, saved in files and read */ | ||||
| /* local_object->proxy_group == pointer to group dupli-object, saved in files and read */ | /* local_object->proxy_group == pointer to collection dupli-object, saved in files and read */ | ||||
| void BKE_object_make_proxy(Object *ob, Object *target, Object *gob) | void BKE_object_make_proxy(Object *ob, Object *target, Object *cob) | ||||
| { | { | ||||
| /* paranoia checks */ | /* paranoia checks */ | ||||
| if (ID_IS_LINKED(ob) || !ID_IS_LINKED(target)) { | if (ID_IS_LINKED(ob) || !ID_IS_LINKED(target)) { | ||||
| printf("cannot make proxy\n"); | printf("cannot make proxy\n"); | ||||
| return; | return; | ||||
| } | } | ||||
| ob->proxy = target; | ob->proxy = target; | ||||
| ob->proxy_group = gob; | ob->proxy_group = cob; | ||||
| id_lib_extern(&target->id); | id_lib_extern(&target->id); | ||||
| DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); | DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); | ||||
| DEG_id_tag_update(&target->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); | DEG_id_tag_update(&target->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); | ||||
| /* copy transform | /* copy transform | ||||
| * - gob means this proxy comes from a group, just apply the matrix | * - cob means this proxy comes from a collection, just apply the matrix | ||||
| * so the object wont move from its dupli-transform. | * so the object wont move from its dupli-transform. | ||||
| * | * | ||||
| * - no gob means this is being made from a linked object, | * - no cob means this is being made from a linked object, | ||||
| * this is closer to making a copy of the object - in-place. */ | * this is closer to making a copy of the object - in-place. */ | ||||
| if (gob) { | if (cob) { | ||||
| ob->rotmode = target->rotmode; | ob->rotmode = target->rotmode; | ||||
| mul_m4_m4m4(ob->obmat, gob->obmat, target->obmat); | mul_m4_m4m4(ob->obmat, cob->obmat, target->obmat); | ||||
| if (gob->dup_group) { /* should always be true */ | if (cob->dup_group) { /* should always be true */ | ||||
| float tvec[3]; | float tvec[3]; | ||||
| mul_v3_mat3_m4v3(tvec, ob->obmat, gob->dup_group->dupli_ofs); | mul_v3_mat3_m4v3(tvec, ob->obmat, cob->dup_group->dupli_ofs); | ||||
| sub_v3_v3(ob->obmat[3], tvec); | sub_v3_v3(ob->obmat[3], tvec); | ||||
| } | } | ||||
| BKE_object_apply_mat4(ob, ob->obmat, false, true); | BKE_object_apply_mat4(ob, ob->obmat, false, true); | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_object_transform_copy(ob, target); | BKE_object_transform_copy(ob, target); | ||||
| ob->parent = target->parent; /* libdata */ | ob->parent = target->parent; /* libdata */ | ||||
| copy_m4_m4(ob->parentinv, target->parentinv); | copy_m4_m4(ob->parentinv, target->parentinv); | ||||
| ▲ Show 20 Lines • Show All 1,235 Lines • ▼ Show 20 Lines | bool BKE_object_parent_loop_check(const Object *par, const Object *ob) | ||||
| return BKE_object_parent_loop_check(par->parent, ob); | return BKE_object_parent_loop_check(par->parent, ob); | ||||
| } | } | ||||
| static void object_handle_update_proxy(Depsgraph *depsgraph, | static void object_handle_update_proxy(Depsgraph *depsgraph, | ||||
| Scene *scene, | Scene *scene, | ||||
| Object *object, | Object *object, | ||||
| const bool do_proxy_update) | const bool do_proxy_update) | ||||
| { | { | ||||
| /* The case when this is a group proxy, object_update is called in group.c */ | /* The case when this is a collection proxy, object_update is called in collection.c */ | ||||
| if (object->proxy == NULL) { | if (object->proxy == NULL) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* set pointer in library proxy target, for copying, but restore it */ | /* set pointer in library proxy target, for copying, but restore it */ | ||||
| object->proxy->proxy_from = object; | object->proxy->proxy_from = object; | ||||
| // printf("set proxy pointer for later group stuff %s\n", ob->id.name); | // printf("set proxy pointer for later collection stuff %s\n", ob->id.name); | ||||
| /* the no-group proxy case, we call update */ | /* the no-group proxy case, we call update */ | ||||
| if (object->proxy_group == NULL) { | if (object->proxy_group == NULL) { | ||||
| if (do_proxy_update) { | if (do_proxy_update) { | ||||
| // printf("call update, lib ob %s proxy %s\n", ob->proxy->id.name, ob->id.name); | // printf("call update, lib ob %s proxy %s\n", ob->proxy->id.name, ob->id.name); | ||||
| BKE_object_handle_update(depsgraph, scene, object->proxy); | BKE_object_handle_update(depsgraph, scene, object->proxy); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 763 Lines • ▼ Show 20 Lines | LinkNode *BKE_object_relational_superset(struct ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter) | ||||
| } | } | ||||
| return links; | return links; | ||||
| } | } | ||||
| /** | /** | ||||
| * return all groups this object is apart of, caller must free. | * return all groups this object is apart of, caller must free. | ||||
| */ | */ | ||||
| struct LinkNode *BKE_object_groups(Object *ob) | struct LinkNode *BKE_object_groups(Main *bmain, Object *ob) | ||||
| { | { | ||||
| LinkNode *group_linknode = NULL; | LinkNode *collection_linknode = NULL; | ||||
| Group *group = NULL; | Collection *collection = NULL; | ||||
| while ((group = BKE_group_object_find(group, ob))) { | while ((collection = BKE_collection_object_find(bmain, collection, ob))) { | ||||
| BLI_linklist_prepend(&group_linknode, group); | BLI_linklist_prepend(&collection_linknode, collection); | ||||
| } | } | ||||
| return group_linknode; | return collection_linknode; | ||||
| } | } | ||||
| void BKE_object_groups_clear(Object *ob) | void BKE_object_groups_clear(Main *bmain, Object *ob) | ||||
| { | { | ||||
| Group *group = NULL; | Collection *collection = NULL; | ||||
| while ((group = BKE_group_object_find(group, ob))) { | while ((collection = BKE_collection_object_find(bmain, collection, ob))) { | ||||
| BKE_group_object_unlink(group, ob); | BKE_collection_object_remove(bmain, collection, ob, false); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Return a KDTree from the deformed object (in worldspace) | * Return a KDTree from the deformed object (in worldspace) | ||||
| * | * | ||||
| * \note Only mesh objects currently support deforming, others are TODO. | * \note Only mesh objects currently support deforming, others are TODO. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines | |||||