Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/space_view3d.c
| Show All 40 Lines | |||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_depsgraph.h" | #include "BKE_depsgraph.h" | ||||
| #include "BKE_icons.h" | #include "BKE_icons.h" | ||||
| #include "BKE_library.h" | #include "BKE_library.h" | ||||
| #include "BKE_localview.h" | |||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_scene.h" | #include "BKE_scene.h" | ||||
| #include "BKE_screen.h" | #include "BKE_screen.h" | ||||
| #include "ED_space_api.h" | #include "ED_space_api.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| ▲ Show 20 Lines • Show All 354 Lines • ▼ Show 20 Lines | if (bgpic->source == V3D_BGPIC_IMAGE) { | ||||
| id_us_min((ID *)bgpic->ima); | id_us_min((ID *)bgpic->ima); | ||||
| } | } | ||||
| else if (bgpic->source == V3D_BGPIC_MOVIE) { | else if (bgpic->source == V3D_BGPIC_MOVIE) { | ||||
| id_us_min((ID *)bgpic->clip); | id_us_min((ID *)bgpic->clip); | ||||
| } | } | ||||
| } | } | ||||
| BLI_freelistN(&vd->bgpicbase); | BLI_freelistN(&vd->bgpicbase); | ||||
| if (vd->localvd) MEM_freeN(vd->localvd); | if (vd->localviewd) | ||||
| MEM_freeN(vd->localviewd); | |||||
| if (vd->properties_storage) MEM_freeN(vd->properties_storage); | if (vd->properties_storage) MEM_freeN(vd->properties_storage); | ||||
| /* matcap material, its preview rect gets freed via icons */ | /* matcap material, its preview rect gets freed via icons */ | ||||
| if (vd->defmaterial) { | if (vd->defmaterial) { | ||||
| if (vd->defmaterial->gpumaterial.first) | if (vd->defmaterial->gpumaterial.first) | ||||
| GPU_material_free(&vd->defmaterial->gpumaterial); | GPU_material_free(&vd->defmaterial->gpumaterial); | ||||
| BKE_previewimg_free(&vd->defmaterial->preview); | BKE_previewimg_free(&vd->defmaterial->preview); | ||||
| Show All 16 Lines | |||||
| static SpaceLink *view3d_duplicate(SpaceLink *sl) | static SpaceLink *view3d_duplicate(SpaceLink *sl) | ||||
| { | { | ||||
| View3D *v3do = (View3D *)sl; | View3D *v3do = (View3D *)sl; | ||||
| View3D *v3dn = MEM_dupallocN(sl); | View3D *v3dn = MEM_dupallocN(sl); | ||||
| BGpic *bgpic; | BGpic *bgpic; | ||||
| /* clear or remove stuff from old */ | /* clear or remove stuff from old */ | ||||
| if (v3dn->localvd) { | if (v3dn->localviewd) { | ||||
| v3dn->localvd = NULL; | v3dn->localviewd = NULL; | ||||
| v3dn->properties_storage = NULL; | v3dn->properties_storage = NULL; | ||||
| v3dn->lay = v3do->localvd->lay & 0xFFFFFF; | |||||
| } | } | ||||
| if (v3dn->drawtype == OB_RENDER) | if (v3dn->drawtype == OB_RENDER) | ||||
| v3dn->drawtype = OB_SOLID; | v3dn->drawtype = OB_SOLID; | ||||
| /* copy or clear inside new stuff */ | /* copy or clear inside new stuff */ | ||||
| v3dn->defmaterial = NULL; | v3dn->defmaterial = NULL; | ||||
| ▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | |||||
| /* type callback, not region itself */ | /* type callback, not region itself */ | ||||
| static void view3d_main_region_free(ARegion *ar) | static void view3d_main_region_free(ARegion *ar) | ||||
| { | { | ||||
| RegionView3D *rv3d = ar->regiondata; | RegionView3D *rv3d = ar->regiondata; | ||||
| if (rv3d) { | if (rv3d) { | ||||
| if (rv3d->localvd) MEM_freeN(rv3d->localvd); | if (rv3d->localviewd) | ||||
| if (rv3d->clipbb) MEM_freeN(rv3d->clipbb); | MEM_freeN(rv3d->localviewd); | ||||
| if (rv3d->clipbb) | |||||
| MEM_freeN(rv3d->clipbb); | |||||
| if (rv3d->render_engine) | if (rv3d->render_engine) | ||||
| RE_engine_free(rv3d->render_engine); | RE_engine_free(rv3d->render_engine); | ||||
| if (rv3d->depths) { | if (rv3d->depths) { | ||||
| if (rv3d->depths->depths) MEM_freeN(rv3d->depths->depths); | if (rv3d->depths->depths) MEM_freeN(rv3d->depths->depths); | ||||
| MEM_freeN(rv3d->depths); | MEM_freeN(rv3d->depths); | ||||
| } | } | ||||
| Show All 14 Lines | |||||
| /* copy regiondata */ | /* copy regiondata */ | ||||
| static void *view3d_main_region_duplicate(void *poin) | static void *view3d_main_region_duplicate(void *poin) | ||||
| { | { | ||||
| if (poin) { | if (poin) { | ||||
| RegionView3D *rv3d = poin, *new; | RegionView3D *rv3d = poin, *new; | ||||
| new = MEM_dupallocN(rv3d); | new = MEM_dupallocN(rv3d); | ||||
| if (rv3d->localvd) | if (rv3d->localviewd) | ||||
| new->localvd = MEM_dupallocN(rv3d->localvd); | new->localviewd = MEM_dupallocN(rv3d->localviewd); | ||||
| if (rv3d->clipbb) | if (rv3d->clipbb) | ||||
| new->clipbb = MEM_dupallocN(rv3d->clipbb); | new->clipbb = MEM_dupallocN(rv3d->clipbb); | ||||
| new->depths = NULL; | new->depths = NULL; | ||||
| new->gpuoffscreen = NULL; | new->gpuoffscreen = NULL; | ||||
| new->render_engine = NULL; | new->render_engine = NULL; | ||||
| new->sms = NULL; | new->sms = NULL; | ||||
| new->smooth_timer = NULL; | new->smooth_timer = NULL; | ||||
| ▲ Show 20 Lines • Show All 525 Lines • ▼ Show 20 Lines | else if (CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const unsigned int lay = v3d ? v3d->lay : scene->lay; | const unsigned int lay = v3d ? v3d->lay : scene->lay; | ||||
| Base *base; | Base *base; | ||||
| const bool selected_objects = CTX_data_equals(member, "selected_objects"); | const bool selected_objects = CTX_data_equals(member, "selected_objects"); | ||||
| for (base = scene->base.first; base; base = base->next) { | for (base = scene->base.first; base; base = base->next) { | ||||
| if ((base->flag & SELECT) && (base->lay & lay)) { | if ((base->flag & SELECT) && (base->lay & lay)) { | ||||
| if (!v3d || BKE_localview_is_object_visible(v3d, base->object)) { | |||||
| if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) { | if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) { | ||||
| if (selected_objects) | if (selected_objects) | ||||
| CTX_data_id_list_add(result, &base->object->id); | CTX_data_id_list_add(result, &base->object->id); | ||||
| else | else | ||||
| CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) { | else if (CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const unsigned int lay = v3d ? v3d->lay : scene->lay; | const unsigned int lay = v3d ? v3d->lay : scene->lay; | ||||
| Base *base; | Base *base; | ||||
| const bool selected_editable_objects = CTX_data_equals(member, "selected_editable_objects"); | const bool selected_editable_objects = CTX_data_equals(member, "selected_editable_objects"); | ||||
| for (base = scene->base.first; base; base = base->next) { | for (base = scene->base.first; base; base = base->next) { | ||||
| if ((base->flag & SELECT) && (base->lay & lay)) { | if ((base->flag & SELECT) && (base->lay & lay)) { | ||||
| if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) { | if ((!v3d || BKE_localview_is_object_visible(v3d, base->object)) && | ||||
| (base->object->restrictflag & OB_RESTRICT_VIEW) == 0) | |||||
| { | |||||
| if (0 == BKE_object_is_libdata(base->object)) { | if (0 == BKE_object_is_libdata(base->object)) { | ||||
| if (selected_editable_objects) | if (selected_editable_objects) | ||||
| CTX_data_id_list_add(result, &base->object->id); | CTX_data_id_list_add(result, &base->object->id); | ||||
| else | else | ||||
| CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "visible_objects") || CTX_data_equals(member, "visible_bases")) { | else if (CTX_data_equals(member, "visible_objects") || CTX_data_equals(member, "visible_bases")) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const unsigned int lay = v3d ? v3d->lay : scene->lay; | const unsigned int lay = v3d ? v3d->lay : scene->lay; | ||||
| Base *base; | Base *base; | ||||
| const bool visible_objects = CTX_data_equals(member, "visible_objects"); | const bool visible_objects = CTX_data_equals(member, "visible_objects"); | ||||
| for (base = scene->base.first; base; base = base->next) { | for (base = scene->base.first; base; base = base->next) { | ||||
| if (base->lay & lay) { | if ((base->lay & lay) && | ||||
| (!v3d || BKE_localview_is_object_visible(v3d, base->object))) | |||||
| { | |||||
| if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) { | if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) { | ||||
| if (visible_objects) | if (visible_objects) | ||||
| CTX_data_id_list_add(result, &base->object->id); | CTX_data_id_list_add(result, &base->object->id); | ||||
| else | else | ||||
| CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "selectable_objects") || CTX_data_equals(member, "selectable_bases")) { | else if (CTX_data_equals(member, "selectable_objects") || CTX_data_equals(member, "selectable_bases")) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const unsigned int lay = v3d ? v3d->lay : scene->lay; | const unsigned int lay = v3d ? v3d->lay : scene->lay; | ||||
| Base *base; | Base *base; | ||||
| const bool selectable_objects = CTX_data_equals(member, "selectable_objects"); | const bool selectable_objects = CTX_data_equals(member, "selectable_objects"); | ||||
| for (base = scene->base.first; base; base = base->next) { | for (base = scene->base.first; base; base = base->next) { | ||||
| if (base->lay & lay) { | if ((base->lay & lay) && | ||||
| (!v3d || BKE_localview_is_object_visible(v3d, base->object))) | |||||
| { | |||||
| if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->object->restrictflag & OB_RESTRICT_SELECT) == 0) { | if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->object->restrictflag & OB_RESTRICT_SELECT) == 0) { | ||||
| if (selectable_objects) | if (selectable_objects) | ||||
| CTX_data_id_list_add(result, &base->object->id); | CTX_data_id_list_add(result, &base->object->id); | ||||
| else | else | ||||
| CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION); | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "active_base")) { | else if (CTX_data_equals(member, "active_base")) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const unsigned int lay = v3d ? v3d->lay : scene->lay; | const unsigned int lay = v3d ? v3d->lay : scene->lay; | ||||
| if (scene->basact && (scene->basact->lay & lay)) { | if (scene->basact && (scene->basact->lay & lay)) { | ||||
| Object *ob = scene->basact->object; | Object *ob = scene->basact->object; | ||||
| if (!v3d || BKE_localview_is_object_visible(v3d, ob)) { | |||||
| /* if hidden but in edit mode, we still display, can happen with animation */ | /* if hidden but in edit mode, we still display, can happen with animation */ | ||||
| if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT)) | if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT)) | ||||
| CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, scene->basact); | CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, scene->basact); | ||||
| } | } | ||||
| } | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| else if (CTX_data_equals(member, "active_object")) { | else if (CTX_data_equals(member, "active_object")) { | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| const unsigned int lay = v3d ? v3d->lay : scene->lay; | const unsigned int lay = v3d ? v3d->lay : scene->lay; | ||||
| if (scene->basact && (scene->basact->lay & lay)) { | if (scene->basact && (scene->basact->lay & lay)) { | ||||
| Object *ob = scene->basact->object; | Object *ob = scene->basact->object; | ||||
| if (!v3d || BKE_localview_is_object_visible(v3d, ob)) { | |||||
| if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT)) | if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT)) | ||||
| CTX_data_id_pointer_set(result, &scene->basact->object->id); | CTX_data_id_pointer_set(result, &scene->basact->object->id); | ||||
| } | } | ||||
| } | |||||
| return 1; | return 1; | ||||
| } | } | ||||
| else { | else { | ||||
| return 0; /* not found */ | return 0; /* not found */ | ||||
| } | } | ||||
| return -1; /* found but not available */ | return -1; /* found but not available */ | ||||
| } | } | ||||
| static void view3d_id_remap(ScrArea *sa, SpaceLink *slink, ID *old_id, ID *new_id) | static void view3d_id_remap(ScrArea *sa, SpaceLink *slink, ID *old_id, ID *new_id) | ||||
| { | { | ||||
| View3D *v3d; | View3D *v3d = (View3D *)slink; | ||||
| ARegion *ar; | bool has_localview = v3d->localviewd != NULL; | ||||
| bool is_local = false; | |||||
| if (!ELEM(GS(old_id->name), ID_OB, ID_MA, ID_IM, ID_MC)) { | if (!ELEM(GS(old_id->name), ID_OB, ID_MA, ID_IM, ID_MC)) { | ||||
| return; | return; | ||||
| } | } | ||||
| for (v3d = (View3D *)slink; v3d; v3d = v3d->localvd, is_local = true) { | |||||
| if ((ID *)v3d->camera == old_id) { | if ((ID *)v3d->camera == old_id) { | ||||
| v3d->camera = (Object *)new_id; | v3d->camera = (Object *)new_id; | ||||
| if (has_localview) { | |||||
| v3d->localviewd->camera = (Object *)new_id; | |||||
| } | |||||
| if (!new_id) { | if (!new_id) { | ||||
| /* 3D view might be inactive, in that case needs to use slink->regionbase */ | /* 3D view might be inactive, in that case needs to use slink->regionbase */ | ||||
| ListBase *regionbase = (slink == sa->spacedata.first) ? &sa->regionbase : &slink->regionbase; | ListBase *regionbase = (slink == sa->spacedata.first) ? &sa->regionbase : &slink->regionbase; | ||||
| for (ar = regionbase->first; ar; ar = ar->next) { | for (ARegion *ar = regionbase->first; ar; ar = ar->next) { | ||||
| if (ar->regiontype == RGN_TYPE_WINDOW) { | if (ar->regiontype == RGN_TYPE_WINDOW) { | ||||
| RegionView3D *rv3d = is_local ? ((RegionView3D *)ar->regiondata)->localvd : ar->regiondata; | RegionView3D *rv3d = (RegionView3D *)ar->regiondata; | ||||
| if (rv3d && (rv3d->persp == RV3D_CAMOB)) { | if (rv3d && (rv3d->persp == RV3D_CAMOB)) { | ||||
| rv3d->persp = RV3D_PERSP; | rv3d->persp = RV3D_PERSP; | ||||
| if (has_localview) { | |||||
| rv3d->localviewd->persp = rv3d->persp; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if ((ID *)v3d->ob_centre == old_id) { | if ((ID *)v3d->ob_centre == old_id) { | ||||
| v3d->ob_centre = (Object *)new_id; | v3d->ob_centre = (Object *)new_id; | ||||
| if (new_id == NULL) { /* Otherwise, bonename may remain valid... We could be smart and check this, too? */ | if (new_id == NULL) { /* Otherwise, bonename may remain valid... We could be smart and check this, too? */ | ||||
| v3d->ob_centre_bone[0] = '\0'; | v3d->ob_centre_bone[0] = '\0'; | ||||
| } | } | ||||
| } | } | ||||
| if ((ID *)v3d->defmaterial == old_id) { | if ((ID *)v3d->defmaterial == old_id) { | ||||
| v3d->defmaterial = (Material *)new_id; | v3d->defmaterial = (Material *)new_id; | ||||
| } | } | ||||
| #if 0 /* XXX Deprecated? */ | #if 0 /* XXX Deprecated? */ | ||||
| if ((ID *)v3d->gpd == old_id) { | if ((ID *)v3d->gpd == old_id) { | ||||
| v3d->gpd = (bGPData *)new_id; | v3d->gpd = (bGPData *)new_id; | ||||
| } | } | ||||
| #endif | #endif | ||||
| if (ELEM(GS(old_id->name), ID_IM, ID_MC)) { | if (ELEM(GS(old_id->name), ID_IM, ID_MC)) { | ||||
| for (BGpic *bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { | for (BGpic *bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) { | ||||
| if ((ID *)bgpic->ima == old_id) { | if ((ID *)bgpic->ima == old_id) { | ||||
| bgpic->ima = (Image *)new_id; | bgpic->ima = (Image *)new_id; | ||||
| id_us_min(old_id); | id_us_min(old_id); | ||||
| id_us_plus(new_id); | id_us_plus(new_id); | ||||
| } | } | ||||
| if ((ID *)bgpic->clip == old_id) { | if ((ID *)bgpic->clip == old_id) { | ||||
| bgpic->clip = (MovieClip *)new_id; | bgpic->clip = (MovieClip *)new_id; | ||||
| id_us_min(old_id); | id_us_min(old_id); | ||||
| id_us_plus(new_id); | id_us_plus(new_id); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (is_local) { | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| /* only called once, from space/spacetypes.c */ | /* only called once, from space/spacetypes.c */ | ||||
| void ED_spacetype_view3d(void) | void ED_spacetype_view3d(void) | ||||
| { | { | ||||
| SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype view3d"); | SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype view3d"); | ||||
| ARegionType *art; | ARegionType *art; | ||||
| ▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines | |||||