Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_relations.c
| Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_collection.h" | #include "BKE_collection.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_constraint.h" | #include "BKE_constraint.h" | ||||
| #include "BKE_curve.h" | #include "BKE_curve.h" | ||||
| #include "BKE_DerivedMesh.h" | #include "BKE_DerivedMesh.h" | ||||
| #include "BKE_displist.h" | #include "BKE_displist.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil.h" | |||||
| #include "BKE_fcurve.h" | #include "BKE_fcurve.h" | ||||
| #include "BKE_idprop.h" | #include "BKE_idprop.h" | ||||
| #include "BKE_lamp.h" | #include "BKE_lamp.h" | ||||
| #include "BKE_lattice.h" | #include "BKE_lattice.h" | ||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_library_override.h" | #include "BKE_library_override.h" | ||||
| #include "BKE_library_query.h" | #include "BKE_library_query.h" | ||||
| ▲ Show 20 Lines • Show All 1,534 Lines • ▼ Show 20 Lines | void OBJECT_OT_make_links_data(wmOperatorType *ot) | ||||
| /* properties */ | /* properties */ | ||||
| ot->prop = RNA_def_enum(ot->srna, "type", make_links_items, 0, "Type", ""); | ot->prop = RNA_def_enum(ot->srna, "type", make_links_items, 0, "Type", ""); | ||||
| } | } | ||||
| /**************************** Make Single User ********************************/ | /**************************** Make Single User ********************************/ | ||||
| static Object *single_object_users_object(Main *bmain, Scene *scene, Object *ob) | static Object *single_object_users_object(Main *bmain, Object *ob) | ||||
| { | { | ||||
| /* base gets copy of object */ | /* base gets copy of object */ | ||||
| Object *obn = ID_NEW_SET(ob, BKE_object_copy(bmain, ob)); | Object *obn = ID_NEW_SET(ob, BKE_object_copy(bmain, ob)); | ||||
| /* remap gpencil parenting */ | |||||
| if (scene->gpd) { | |||||
| bGPdata *gpd = scene->gpd; | |||||
| for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { | |||||
| if (gpl->parent == ob) { | |||||
| gpl->parent = obn; | |||||
| } | |||||
| } | |||||
| } | |||||
| id_us_plus(&obn->id); | id_us_plus(&obn->id); | ||||
| id_us_min(&ob->id); | id_us_min(&ob->id); | ||||
| return obn; | return obn; | ||||
| } | } | ||||
| static void libblock_relink_collection(Collection *collection) | static void libblock_relink_collection(Collection *collection) | ||||
| { | { | ||||
| for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { | for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { | ||||
| BKE_libblock_relink_to_newid(&cob->ob->id); | BKE_libblock_relink_to_newid(&cob->ob->id); | ||||
| } | } | ||||
| for (CollectionChild *child = collection->children.first; child; child = child->next) { | for (CollectionChild *child = collection->children.first; child; child = child->next) { | ||||
| libblock_relink_collection(child->collection); | libblock_relink_collection(child->collection); | ||||
| } | } | ||||
| } | } | ||||
| static void single_object_users_collection(Main *bmain, Scene *scene, Collection *collection, const int flag, const bool copy_collections) | static void single_object_users_collection(Main *bmain, Scene *scene, Collection *collection, const int flag, const bool copy_collections) | ||||
| { | { | ||||
| for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { | for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) { | ||||
| Object *ob = cob->ob; | Object *ob = cob->ob; | ||||
| /* an object may be in more than one collection */ | /* an object may be in more than one collection */ | ||||
| if ((ob->id.newid == NULL) && ((ob->flag & flag) == flag)) { | if ((ob->id.newid == NULL) && ((ob->flag & flag) == flag)) { | ||||
| if (!ID_IS_LINKED(ob) && ob->id.us > 1) { | if (!ID_IS_LINKED(ob) && ob->id.us > 1) { | ||||
| cob->ob = single_object_users_object(bmain, scene, cob->ob); | cob->ob = single_object_users_object(bmain, cob->ob); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| for (CollectionChild *child = collection->children.first; child; child = child->next) { | for (CollectionChild *child = collection->children.first; child; child = child->next) { | ||||
| single_object_users_collection(bmain, scene, child->collection, flag, copy_collections); | single_object_users_collection(bmain, scene, child->collection, flag, copy_collections); | ||||
| } | } | ||||
| } | } | ||||
| Show All 37 Lines | if (copy_collections) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* collection pointers in scene */ | /* collection pointers in scene */ | ||||
| BKE_scene_groups_relink(scene); | BKE_scene_groups_relink(scene); | ||||
| /* active camera */ | |||||
| ID_NEW_REMAP(scene->camera); | ID_NEW_REMAP(scene->camera); | ||||
| if (v3d) ID_NEW_REMAP(v3d->camera); | if (v3d) ID_NEW_REMAP(v3d->camera); | ||||
| /* gp_object */ | |||||
| ID_NEW_REMAP(scene->gp_object); | |||||
| /* object and collection pointers */ | /* object and collection pointers */ | ||||
| libblock_relink_collection(master_collection); | libblock_relink_collection(master_collection); | ||||
| } | } | ||||
| /* not an especially efficient function, only added so the single user | /* not an especially efficient function, only added so the single user | ||||
| * button can be functional.*/ | * button can be functional.*/ | ||||
| void ED_object_single_user(Main *bmain, Scene *scene, Object *ob) | void ED_object_single_user(Main *bmain, Scene *scene, Object *ob) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if (!ID_IS_LINKED(ob)) { | ||||
| BKE_pose_rebuild(ob, ob->data); | BKE_pose_rebuild(ob, ob->data); | ||||
| break; | break; | ||||
| case OB_SPEAKER: | case OB_SPEAKER: | ||||
| ob->data = ID_NEW_SET(ob->data, BKE_speaker_copy(bmain, ob->data)); | ob->data = ID_NEW_SET(ob->data, BKE_speaker_copy(bmain, ob->data)); | ||||
| break; | break; | ||||
| case OB_LIGHTPROBE: | case OB_LIGHTPROBE: | ||||
| ob->data = ID_NEW_SET(ob->data, BKE_lightprobe_copy(bmain, ob->data)); | ob->data = ID_NEW_SET(ob->data, BKE_lightprobe_copy(bmain, ob->data)); | ||||
| break; | break; | ||||
| case OB_GPENCIL: | |||||
| ob->data = ID_NEW_SET(ob->data, BKE_gpencil_copy(bmain, ob->data)); | |||||
| break; | |||||
| default: | default: | ||||
| printf("ERROR %s: can't copy %s\n", __func__, id->name); | printf("ERROR %s: can't copy %s\n", __func__, id->name); | ||||
| BLI_assert(!"This should never happen."); | BLI_assert(!"This should never happen."); | ||||
| /* We need to end the FOREACH_OBJECT_FLAG_BEGIN iterator to prevent memory leak. */ | /* We need to end the FOREACH_OBJECT_FLAG_BEGIN iterator to prevent memory leak. */ | ||||
| BKE_scene_objects_iterator_end(&iter_macro); | BKE_scene_objects_iterator_end(&iter_macro); | ||||
| return; | return; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | /* Relink datablock pointer properties */ | ||||
| if (scene->nodetree) { | if (scene->nodetree) { | ||||
| IDP_RelinkProperty(scene->nodetree->id.properties); | IDP_RelinkProperty(scene->nodetree->id.properties); | ||||
| for (bNode *node = scene->nodetree->nodes.first; node; node = node->next) { | for (bNode *node = scene->nodetree->nodes.first; node; node = node->next) { | ||||
| IDP_RelinkProperty(node->prop); | IDP_RelinkProperty(node->prop); | ||||
| } | } | ||||
| } | } | ||||
| if (scene->gpd) { | |||||
| IDP_RelinkProperty(scene->gpd->id.properties); | |||||
| } | |||||
| if (scene->world) { | if (scene->world) { | ||||
| IDP_RelinkProperty(scene->world->id.properties); | IDP_RelinkProperty(scene->world->id.properties); | ||||
| } | } | ||||
| if (scene->clip) { | if (scene->clip) { | ||||
| IDP_RelinkProperty(scene->clip->id.properties); | IDP_RelinkProperty(scene->clip->id.properties); | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 631 Lines • Show Last 20 Lines | |||||