Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_relations.c
| Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| return ED_operator_editmesh(C) || ED_operator_editsurfcurve(C) || ED_operator_editlattice(C); | return ED_operator_editmesh(C) || ED_operator_editsurfcurve(C) || ED_operator_editlattice(C); | ||||
| } | } | ||||
| static int vertex_parent_set_exec(bContext *C, wmOperator *op) | static int vertex_parent_set_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| EvaluationContext eval_ctx; | EvaluationContext eval_ctx; | ||||
| BMVert *eve; | BMVert *eve; | ||||
| BMIter iter; | BMIter iter; | ||||
| Curve *cu; | Curve *cu; | ||||
| Nurb *nu; | Nurb *nu; | ||||
| BezTriple *bezt; | BezTriple *bezt; | ||||
| BPoint *bp; | BPoint *bp; | ||||
| ▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static int make_proxy_exec(bContext *C, wmOperator *op) | static int make_proxy_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Object *ob, *gob = ED_object_active_context(C); | Object *ob, *gob = ED_object_active_context(C); | ||||
| GroupObject *go; | GroupObject *go; | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *scene_layer = CTX_data_scene_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| if (gob->dup_group != NULL) { | if (gob->dup_group != NULL) { | ||||
| go = BLI_findlink(&gob->dup_group->gobject, RNA_enum_get(op->ptr, "object")); | go = BLI_findlink(&gob->dup_group->gobject, RNA_enum_get(op->ptr, "object")); | ||||
| ob = go->ob; | ob = go->ob; | ||||
| } | } | ||||
| else { | else { | ||||
| ob = gob; | ob = gob; | ||||
| gob = NULL; | gob = NULL; | ||||
| } | } | ||||
| if (ob) { | if (ob) { | ||||
| Object *newob; | Object *newob; | ||||
| char name[MAX_ID_NAME + 4]; | char name[MAX_ID_NAME + 4]; | ||||
| BLI_snprintf(name, sizeof(name), "%s_proxy", ((ID *)(gob ? gob : ob))->name + 2); | BLI_snprintf(name, sizeof(name), "%s_proxy", ((ID *)(gob ? gob : ob))->name + 2); | ||||
| /* Add new object for the proxy */ | /* Add new object for the proxy */ | ||||
| newob = BKE_object_add_from(bmain, scene, scene_layer, OB_EMPTY, name, gob ? gob : ob); | newob = BKE_object_add_from(bmain, scene, view_layer, OB_EMPTY, name, gob ? gob : ob); | ||||
| /* set layers OK */ | /* set layers OK */ | ||||
| BKE_object_make_proxy(newob, ob, gob); | BKE_object_make_proxy(newob, ob, gob); | ||||
| /* Set back pointer immediately so dependency graph knows that this is | /* Set back pointer immediately so dependency graph knows that this is | ||||
| * is a proxy and will act accordingly. Otherwise correctness of graph | * is a proxy and will act accordingly. Otherwise correctness of graph | ||||
| * will depend on order of bases. | * will depend on order of bases. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 1,320 Lines • ▼ Show 20 Lines | static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const int flag, const bool copy_groups) | ||||
| GroupObject *go; | GroupObject *go; | ||||
| clear_sca_new_poins(); /* BGE logic */ | clear_sca_new_poins(); /* BGE logic */ | ||||
| /* duplicate all the objects of the scene */ | /* duplicate all the objects of the scene */ | ||||
| SceneCollection *msc = BKE_collection_master(scene); | SceneCollection *msc = BKE_collection_master(scene); | ||||
| single_object_users_scene_collection(bmain, scene, msc, flag, copy_groups); | single_object_users_scene_collection(bmain, scene, msc, flag, copy_groups); | ||||
| /* loop over SceneLayers and assign the pointers accordingly */ | /* loop over ViewLayers and assign the pointers accordingly */ | ||||
| for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) { | for (ViewLayer *sl = scene->view_layers.first; sl; sl = sl->next) { | ||||
| for (Base *base = sl->object_bases.first; base; base = base->next) { | for (Base *base = sl->object_bases.first; base; base = base->next) { | ||||
| ID_NEW_REMAP(base->object); | ID_NEW_REMAP(base->object); | ||||
| } | } | ||||
| } | } | ||||
| /* duplicate groups that consist entirely of duplicated objects */ | /* duplicate groups that consist entirely of duplicated objects */ | ||||
| for (group = bmain->group.first; group; group = group->id.next) { | for (group = bmain->group.first; group; group = group->id.next) { | ||||
| if (copy_groups && group->gobject.first) { | if (copy_groups && group->gobject.first) { | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | if (id && !ID_IS_LINKED(id)) { | ||||
| else if (id->us > 1) { | else if (id->us > 1) { | ||||
| matar[a] = ID_NEW_SET(id, BKE_material_copy(bmain, matar[a])); | matar[a] = ID_NEW_SET(id, BKE_material_copy(bmain, matar[a])); | ||||
| id_us_min(id); | id_us_min(id); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void single_obdata_users(Main *bmain, Scene *scene, SceneLayer *sl, const int flag) | static void single_obdata_users(Main *bmain, Scene *scene, ViewLayer *sl, const int flag) | ||||
| { | { | ||||
| Lamp *la; | Lamp *la; | ||||
| Curve *cu; | Curve *cu; | ||||
| /* Camera *cam; */ | /* Camera *cam; */ | ||||
| Mesh *me; | Mesh *me; | ||||
| Lattice *lat; | Lattice *lat; | ||||
| ID *id; | ID *id; | ||||
| int a; | int a; | ||||
| ▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | static void single_obdata_users(Main *bmain, Scene *scene, ViewLayer *sl, const int flag) | ||||
| me = bmain->mesh.first; | me = bmain->mesh.first; | ||||
| while (me) { | while (me) { | ||||
| ID_NEW_REMAP(me->texcomesh); | ID_NEW_REMAP(me->texcomesh); | ||||
| me = me->id.next; | me = me->id.next; | ||||
| } | } | ||||
| } | } | ||||
| static void single_object_action_users(Scene *scene, SceneLayer *sl, const int flag) | static void single_object_action_users(Scene *scene, ViewLayer *sl, const int flag) | ||||
| { | { | ||||
| FOREACH_OBJECT_FLAG(scene, sl, flag, ob) | FOREACH_OBJECT_FLAG(scene, sl, flag, ob) | ||||
| if (!ID_IS_LINKED(ob)) { | if (!ID_IS_LINKED(ob)) { | ||||
| DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | ||||
| BKE_animdata_copy_id_action(&ob->id, false); | BKE_animdata_copy_id_action(&ob->id, false); | ||||
| } | } | ||||
| FOREACH_OBJECT_FLAG_END | FOREACH_OBJECT_FLAG_END | ||||
| } | } | ||||
| static void single_mat_users(Main *bmain, Scene *scene, SceneLayer *sl, const int flag, const bool do_textures) | static void single_mat_users(Main *bmain, Scene *scene, ViewLayer *sl, const int flag, const bool do_textures) | ||||
| { | { | ||||
| Material *ma, *man; | Material *ma, *man; | ||||
| Tex *tex; | Tex *tex; | ||||
| int a, b; | int a, b; | ||||
| FOREACH_OBJECT_FLAG(scene, sl, flag, ob) | FOREACH_OBJECT_FLAG(scene, sl, flag, ob) | ||||
| if (!ID_IS_LINKED(ob)) { | if (!ID_IS_LINKED(ob)) { | ||||
| for (a = 1; a <= ob->totcol; a++) { | for (a = 1; a <= ob->totcol; a++) { | ||||
| ▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | static void tag_localizable_objects(bContext *C, const int mode) | ||||
| /* TODO(sergey): Drivers targets? */ | /* TODO(sergey): Drivers targets? */ | ||||
| } | } | ||||
| /** | /** | ||||
| * Instance indirectly referenced zero user objects, | * Instance indirectly referenced zero user objects, | ||||
| * otherwise they're lost on reload, see T40595. | * otherwise they're lost on reload, see T40595. | ||||
| */ | */ | ||||
| static bool make_local_all__instance_indirect_unused(Main *bmain, Scene *scene, SceneLayer *sl, SceneCollection *sc) | static bool make_local_all__instance_indirect_unused(Main *bmain, Scene *scene, ViewLayer *sl, SceneCollection *sc) | ||||
| { | { | ||||
| Object *ob; | Object *ob; | ||||
| bool changed = false; | bool changed = false; | ||||
| for (ob = bmain->object.first; ob; ob = ob->id.next) { | for (ob = bmain->object.first; ob; ob = ob->id.next) { | ||||
| if (ID_IS_LINKED(ob) && (ob->id.us == 0)) { | if (ID_IS_LINKED(ob) && (ob->id.us == 0)) { | ||||
| Base *base; | Base *base; | ||||
| id_us_plus(&ob->id); | id_us_plus(&ob->id); | ||||
| BKE_collection_object_add(scene, sc, ob); | BKE_collection_object_add(scene, sc, ob); | ||||
| base = BKE_scene_layer_base_find(sl, ob); | base = BKE_view_layer_base_find(sl, ob); | ||||
| base->flag |= BASE_SELECTED; | base->flag |= BASE_SELECTED; | ||||
| BKE_scene_object_base_flag_sync_from_base(base); | BKE_scene_object_base_flag_sync_from_base(base); | ||||
| 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); | ||||
| changed = true; | changed = true; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | static int make_local_exec(bContext *C, wmOperator *op) | ||||
| ParticleSystem *psys; | ParticleSystem *psys; | ||||
| Material *ma, ***matarar; | Material *ma, ***matarar; | ||||
| Lamp *la; | Lamp *la; | ||||
| const int mode = RNA_enum_get(op->ptr, "type"); | const int mode = RNA_enum_get(op->ptr, "type"); | ||||
| int a; | int a; | ||||
| /* Note: we (ab)use LIB_TAG_PRE_EXISTING to cherry pick which ID to make local... */ | /* Note: we (ab)use LIB_TAG_PRE_EXISTING to cherry pick which ID to make local... */ | ||||
| if (mode == MAKE_LOCAL_ALL) { | if (mode == MAKE_LOCAL_ALL) { | ||||
| SceneLayer *scene_layer = CTX_data_scene_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| SceneCollection *scene_collection = CTX_data_scene_collection(C); | SceneCollection *scene_collection = CTX_data_scene_collection(C); | ||||
| BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false); | BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false); | ||||
| /* De-select so the user can differentiate newly instanced from existing objects. */ | /* De-select so the user can differentiate newly instanced from existing objects. */ | ||||
| BKE_scene_layer_base_deselect_all(scene_layer); | BKE_view_layer_base_deselect_all(view_layer); | ||||
| if (make_local_all__instance_indirect_unused(bmain, scene, scene_layer, scene_collection)) { | if (make_local_all__instance_indirect_unused(bmain, scene, view_layer, scene_collection)) { | ||||
| BKE_report(op->reports, RPT_INFO, "Orphan library objects added to the current scene to avoid loss"); | BKE_report(op->reports, RPT_INFO, "Orphan library objects added to the current scene to avoid loss"); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true); | BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true); | ||||
| tag_localizable_objects(C, mode); | tag_localizable_objects(C, mode); | ||||
| CTX_DATA_BEGIN (C, Object *, ob, selected_objects) | CTX_DATA_BEGIN (C, Object *, ob, selected_objects) | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | enum { | ||||
| MAKE_SINGLE_USER_ALL = 1, | MAKE_SINGLE_USER_ALL = 1, | ||||
| MAKE_SINGLE_USER_SELECTED = 2, | MAKE_SINGLE_USER_SELECTED = 2, | ||||
| }; | }; | ||||
| static int make_single_user_exec(bContext *C, wmOperator *op) | static int make_single_user_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); /* ok if this is NULL */ | View3D *v3d = CTX_wm_view3d(C); /* ok if this is NULL */ | ||||
| const int flag = (RNA_enum_get(op->ptr, "type") == MAKE_SINGLE_USER_SELECTED) ? SELECT : 0; | const int flag = (RNA_enum_get(op->ptr, "type") == MAKE_SINGLE_USER_SELECTED) ? SELECT : 0; | ||||
| const bool copy_groups = false; | const bool copy_groups = false; | ||||
| bool update_deps = false; | bool update_deps = false; | ||||
| if (RNA_boolean_get(op->ptr, "object")) { | if (RNA_boolean_get(op->ptr, "object")) { | ||||
| if (flag == SELECT) { | if (flag == SELECT) { | ||||
| BKE_scene_layer_selected_objects_tag(sl, OB_DONE); | BKE_view_layer_selected_objects_tag(sl, OB_DONE); | ||||
| single_object_users(bmain, scene, v3d, OB_DONE, copy_groups); | single_object_users(bmain, scene, v3d, OB_DONE, copy_groups); | ||||
| } | } | ||||
| else { | else { | ||||
| single_object_users(bmain, scene, v3d, 0, copy_groups); | single_object_users(bmain, scene, v3d, 0, copy_groups); | ||||
| } | } | ||||
| /* needed since object relationships may have changed */ | /* needed since object relationships may have changed */ | ||||
| update_deps = true; | update_deps = true; | ||||
| ▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines | |||||