Move background images into the camera
authorCampbell Barton <ideasman42@gmail.com>
Thu, 26 Oct 2017 10:40:37 +0000 (21:40 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 26 Oct 2017 11:02:40 +0000 (22:02 +1100)
This moves background images out of the 3D viewport,
to be used only as camera reference images.

For 3D viewport references,
background images can be used, see: D2827

Some work is still needed
(background option isn't working at the moment).

23 files changed:
release/scripts/startup/bl_ui/properties_data_camera.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenkernel/BKE_camera.h
source/blender/blenkernel/intern/camera.c
source/blender/blenkernel/intern/image.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/versioning_legacy.c
source/blender/blenloader/intern/writefile.c
source/blender/draw/intern/draw_manager.c
source/blender/editors/include/ED_screen.h
source/blender/editors/include/ED_view3d.h
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/space_view3d/view3d_draw_legacy.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/space_view3d/view3d_intern.h
source/blender/makesdna/DNA_camera_types.h
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_camera.c
source/blender/makesrna/intern/rna_space.c
source/blender/windowmanager/intern/wm_draw.c
source/blenderplayer/bad_level_call_stubs/stubs.c

index f77c0ff40e895603b7971c42ccf1f8e64b6c4bb5..0d0fc96550d5af7412fb06363e2d67b61e5a07cb 100644 (file)
@@ -255,6 +255,107 @@ class DATA_PT_camera_dof(CameraButtonsPanel, Panel):
                 col.prop(dof_options, "blades")
 
 
+class DATA_PT_camera_background_image(CameraButtonsPanel, Panel):
+    bl_label = "Background Images"
+    bl_options = {'DEFAULT_CLOSED'}
+    COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME', 'BLENDER_CLAY', 'BLENDER_EEVEE'}
+
+    def draw_header(self, context):
+        cam = context.camera
+
+        self.layout.prop(cam, "show_background_images", text="")
+
+    def draw(self, context):
+        layout = self.layout
+
+        cam = context.camera
+        use_multiview = context.scene.render.use_multiview
+
+        col = layout.column()
+        col.operator("view3d.background_image_add", text="Add Image")
+
+        for i, bg in enumerate(cam.background_images):
+            layout.active = cam.show_background_images
+            box = layout.box()
+            row = box.row(align=True)
+            row.prop(bg, "show_expanded", text="", emboss=False)
+            if bg.source == 'IMAGE' and bg.image:
+                row.prop(bg.image, "name", text="", emboss=False)
+            elif bg.source == 'MOVIE_CLIP' and bg.clip:
+                row.prop(bg.clip, "name", text="", emboss=False)
+            else:
+                row.label(text="Not Set")
+
+            if bg.show_background_image:
+                row.prop(bg, "show_background_image", text="", emboss=False, icon='RESTRICT_VIEW_OFF')
+            else:
+                row.prop(bg, "show_background_image", text="", emboss=False, icon='RESTRICT_VIEW_ON')
+
+            row.operator("view3d.background_image_remove", text="", emboss=False, icon='X').index = i
+
+            if bg.show_expanded:
+                row = box.row()
+                row.prop(bg, "source", expand=True)
+
+                has_bg = False
+                if bg.source == 'IMAGE':
+                    row = box.row()
+                    row.template_ID(bg, "image", open="image.open")
+                    if bg.image is not None:
+                        box.template_image(bg, "image", bg.image_user, compact=True)
+                        has_bg = True
+
+                        if use_multiview and bg.view_axis in {'CAMERA', 'ALL'}:
+                            box.prop(bg.image, "use_multiview")
+
+                            column = box.column()
+                            column.active = bg.image.use_multiview
+
+                            column.label(text="Views Format:")
+                            column.row().prop(bg.image, "views_format", expand=True)
+
+                            sub = column.box()
+                            sub.active = bg.image.views_format == 'STEREO_3D'
+                            sub.template_image_stereo_3d(bg.image.stereo_3d_format)
+
+                elif bg.source == 'MOVIE_CLIP':
+                    box.prop(bg, "use_camera_clip")
+
+                    column = box.column()
+                    column.active = not bg.use_camera_clip
+                    column.template_ID(bg, "clip", open="clip.open")
+
+                    if bg.clip:
+                        column.template_movieclip(bg, "clip", compact=True)
+
+                    if bg.use_camera_clip or bg.clip:
+                        has_bg = True
+
+                    column = box.column()
+                    column.active = has_bg
+                    column.prop(bg.clip_user, "proxy_render_size", text="")
+                    column.prop(bg.clip_user, "use_render_undistorted")
+
+                if has_bg:
+                    col = box.column()
+                    col.prop(bg, "alpha", slider=True)
+                    col.row().prop(bg, "draw_depth", expand=True)
+
+                    col.row().prop(bg, "frame_method", expand=True)
+
+                    box = col.box()
+                    row = box.row()
+                    row.prop(bg, "offset")
+
+                    row = box.row()
+                    row.prop(bg, "use_flip_x")
+                    row.prop(bg, "use_flip_y")
+
+                    row = box.row()
+                    row.prop(bg, "rotation")
+                    row.prop(bg, "scale")
+
+
 class DATA_PT_camera_display(CameraButtonsPanel, Panel):
     bl_label = "Display"
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME', 'BLENDER_CLAY', 'BLENDER_EEVEE'}
@@ -344,6 +445,7 @@ classes = (
     DATA_PT_camera_stereoscopy,
     DATA_PT_camera_dof,
     DATA_PT_camera_display,
+    DATA_PT_camera_background_image,
     DATA_PT_camera_safe_areas,
     DATA_PT_custom_props_camera,
 )
index da1db6836c68e3694aa477c403fef86c3f593542..1604c878595492948f38c0862fd98e71c77527be 100644 (file)
@@ -3711,113 +3711,6 @@ class VIEW3D_PT_view3d_curvedisplay(Panel):
         col.prop(context.scene.tool_settings, "normal_size", text="Normal Size")
 
 
-class VIEW3D_PT_background_image(Panel):
-    bl_space_type = 'VIEW_3D'
-    bl_region_type = 'UI'
-    bl_label = "Background Images"
-    bl_options = {'DEFAULT_CLOSED'}
-
-    def draw_header(self, context):
-        view = context.space_data
-
-        self.layout.prop(view, "show_background_images", text="")
-
-    def draw(self, context):
-        layout = self.layout
-
-        view = context.space_data
-        use_multiview = context.scene.render.use_multiview
-
-        col = layout.column()
-        col.operator("view3d.background_image_add", text="Add Image")
-
-        for i, bg in enumerate(view.background_images):
-            layout.active = view.show_background_images
-            box = layout.box()
-            row = box.row(align=True)
-            row.prop(bg, "show_expanded", text="", emboss=False)
-            if bg.source == 'IMAGE' and bg.image:
-                row.prop(bg.image, "name", text="", emboss=False)
-            elif bg.source == 'MOVIE_CLIP' and bg.clip:
-                row.prop(bg.clip, "name", text="", emboss=False)
-            else:
-                row.label(text="Not Set")
-
-            if bg.show_background_image:
-                row.prop(bg, "show_background_image", text="", emboss=False, icon='RESTRICT_VIEW_OFF')
-            else:
-                row.prop(bg, "show_background_image", text="", emboss=False, icon='RESTRICT_VIEW_ON')
-
-            row.operator("view3d.background_image_remove", text="", emboss=False, icon='X').index = i
-
-            box.prop(bg, "view_axis", text="Axis")
-
-            if bg.show_expanded:
-                row = box.row()
-                row.prop(bg, "source", expand=True)
-
-                has_bg = False
-                if bg.source == 'IMAGE':
-                    row = box.row()
-                    row.template_ID(bg, "image", open="image.open")
-                    if bg.image is not None:
-                        box.template_image(bg, "image", bg.image_user, compact=True)
-                        has_bg = True
-
-                        if use_multiview and bg.view_axis in {'CAMERA', 'ALL'}:
-                            box.prop(bg.image, "use_multiview")
-
-                            column = box.column()
-                            column.active = bg.image.use_multiview
-
-                            column.label(text="Views Format:")
-                            column.row().prop(bg.image, "views_format", expand=True)
-
-                            sub = column.box()
-                            sub.active = bg.image.views_format == 'STEREO_3D'
-                            sub.template_image_stereo_3d(bg.image.stereo_3d_format)
-
-                elif bg.source == 'MOVIE_CLIP':
-                    box.prop(bg, "use_camera_clip")
-
-                    column = box.column()
-                    column.active = not bg.use_camera_clip
-                    column.template_ID(bg, "clip", open="clip.open")
-
-                    if bg.clip:
-                        column.template_movieclip(bg, "clip", compact=True)
-
-                    if bg.use_camera_clip or bg.clip:
-                        has_bg = True
-
-                    column = box.column()
-                    column.active = has_bg
-                    column.prop(bg.clip_user, "proxy_render_size", text="")
-                    column.prop(bg.clip_user, "use_render_undistorted")
-
-                if has_bg:
-                    col = box.column()
-                    col.prop(bg, "opacity", slider=True)
-                    col.row().prop(bg, "draw_depth", expand=True)
-
-                    if bg.view_axis in {'CAMERA', 'ALL'}:
-                        col.row().prop(bg, "frame_method", expand=True)
-
-                    box = col.box()
-                    row = box.row()
-                    row.prop(bg, "offset_x", text="X")
-                    row.prop(bg, "offset_y", text="Y")
-
-                    row = box.row()
-                    row.prop(bg, "use_flip_x")
-                    row.prop(bg, "use_flip_y")
-
-                    row = box.row()
-                    if bg.view_axis != 'CAMERA':
-                        row.prop(bg, "rotation")
-                        row.prop(bg, "size")
-
-
 class VIEW3D_PT_transform_orientations(Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'UI'
@@ -4075,7 +3968,6 @@ classes = (
     VIEW3D_PT_view3d_meshdisplay,
     VIEW3D_PT_view3d_meshstatvis,
     VIEW3D_PT_view3d_curvedisplay,
-    VIEW3D_PT_background_image,
     VIEW3D_PT_transform_orientations,
     VIEW3D_PT_etch_a_ton,
     VIEW3D_PT_context_properties,
index 2234cee0e0d87ba8368cf82db9f0934d7b8d43fb..27264100f1bce8ca4795f82143f3c1cce8024928 100644 (file)
@@ -148,6 +148,11 @@ float          BKE_camera_multiview_shift_x(struct RenderData *rd, struct Object
 void           BKE_camera_multiview_params(struct RenderData *rd, struct CameraParams *params, struct Object *camera, const char *viewname);
 bool           BKE_camera_multiview_spherical_stereo(struct RenderData *rd, struct Object *camera);
 
+/* Camera background image API */
+struct CameraBGImage *BKE_camera_background_image_new(struct Camera *cam);
+void BKE_camera_background_image_remove(struct Camera *cam, struct CameraBGImage *bgpic);
+void BKE_camera_background_image_clear(struct Camera *cam);
+
 #ifdef __cplusplus
 }
 #endif
index 97bb679f8b052022a28384796230f65f55eb4df6..ac004e587859d53e6d62005cccfc7f69a5efad89 100644 (file)
@@ -40,6 +40,7 @@
 #include "DNA_ID.h"
 
 #include "BLI_math.h"
+#include "BLI_listbase.h"
 #include "BLI_rect.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
@@ -55,6 +56,8 @@
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 
+#include "MEM_guardedalloc.h"
+
 #include "GPU_compositing.h"
 
 /****************************** Camera Datablock *****************************/
@@ -101,9 +104,19 @@ void *BKE_camera_add(Main *bmain, const char *name)
  *
  * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
  */
-void BKE_camera_copy_data(Main *UNUSED(bmain), Camera *UNUSED(cam_dst), const Camera *UNUSED(cam_src), const int UNUSED(flag))
+void BKE_camera_copy_data(Main *UNUSED(bmain), Camera *cam_dst, const Camera *cam_src, const int flag)
 {
-       /* Nothing to do! */
+       BLI_duplicatelist(&cam_dst->bg_images, &cam_src->bg_images);
+       if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
+               for (CameraBGImage *bgpic = cam_dst->bg_images.first; bgpic; bgpic = bgpic->next) {
+                       if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
+                               id_us_plus((ID *)bgpic->ima);
+                       }
+                       else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
+                               id_us_plus((ID *)bgpic->clip);
+                       }
+               }
+       }
 }
 
 Camera *BKE_camera_copy(Main *bmain, const Camera *cam)
@@ -121,6 +134,16 @@ void BKE_camera_make_local(Main *bmain, Camera *cam, const bool lib_local)
 /** Free (or release) any data used by this camera (does not free the camera itself). */
 void BKE_camera_free(Camera *ca)
 {
+       for (CameraBGImage *bgpic = ca->bg_images.first; bgpic; bgpic = bgpic->next) {
+               if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
+                       id_us_min((ID *)bgpic->ima);
+               }
+               else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
+                       id_us_min((ID *)bgpic->clip);
+               }
+       }
+       BLI_freelistN(&ca->bg_images);
+
        BKE_animdata_free((ID *)ca, false);
 }
 
@@ -961,3 +984,38 @@ void BKE_camera_to_gpu_dof(struct Object *camera, struct GPUFXSettings *r_fx_set
                r_fx_settings->dof->focus_distance = BKE_camera_object_dof_distance(camera);
        }
 }
+
+CameraBGImage *BKE_camera_background_image_new(Camera *cam)
+{
+       CameraBGImage *bgpic = MEM_callocN(sizeof(CameraBGImage), "Background Image");
+
+       bgpic->scale = 1.0f;
+       bgpic->alpha = 0.5f;
+       bgpic->iuser.fie_ima = 2;
+       bgpic->iuser.ok = 1;
+       bgpic->flag |= CAM_BGIMG_FLAG_EXPANDED;
+
+       BLI_addtail(&cam->bg_images, bgpic);
+
+       return bgpic;
+}
+
+void BKE_camera_background_image_remove(Camera *cam, CameraBGImage *bgpic)
+{
+       BLI_remlink(&cam->bg_images, bgpic);
+
+       MEM_freeN(bgpic);
+}
+
+void BKE_camera_background_image_clear(Camera *cam)
+{
+       CameraBGImage *bgpic = cam->bg_images.first;
+
+       while (bgpic) {
+               CameraBGImage *next_bgpic = bgpic->next;
+
+               BKE_camera_background_image_remove(cam, bgpic);
+
+               bgpic = next_bgpic;
+       }
+}
\ No newline at end of file
index 33a690b32c6570dd61ccd494454f5431dc7f0d3a..99f8d6a64c12e7a2b924bb510490f51672ef1f9f 100644 (file)
@@ -2563,20 +2563,19 @@ void BKE_image_walk_all_users(const Main *mainp, void *customdata,
                }
        }
 
+       for (Camera *cam = mainp->camera.first; cam; cam = cam->id.next) {
+               for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
+                       callback(bgpic->ima, &bgpic->iuser, customdata);
+               }
+       }
+
        /* image window, compo node users */
        for (wm = mainp->wm.first; wm; wm = wm->id.next) { /* only 1 wm */
                for (win = wm->windows.first; win; win = win->next) {
                        const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
 
                        for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
-                               if (sa->spacetype == SPACE_VIEW3D) {
-                                       View3D *v3d = sa->spacedata.first;
-                                       BGpic *bgpic;
-                                       for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
-                                               callback(bgpic->ima, &bgpic->iuser, customdata);
-                                       }
-                               }
-                               else if (sa->spacetype == SPACE_IMAGE) {
+                               if (sa->spacetype == SPACE_IMAGE) {
                                        SpaceImage *sima = sa->spacedata.first;
                                        callback(sima->image, &sima->iuser, customdata);
                                }
index ce7914b0f372ea26252fcd82ae573b53343de1a1..2e4ff1c96a60ca22b4ae00a22a1c6d49d478d0eb 100644 (file)
@@ -3505,6 +3505,11 @@ static void lib_link_camera(FileData *fd, Main *main)
 
                        ca->dof_ob = newlibadr(fd, ca->id.lib, ca->dof_ob);
                        
+                       for (CameraBGImage *bgpic = ca->bg_images.first; bgpic; bgpic = bgpic->next) {
+                               bgpic->ima = newlibadr_us(fd, ca->id.lib, bgpic->ima);
+                               bgpic->clip = newlibadr_us(fd, ca->id.lib, bgpic->clip);
+                       }
+
                        ca->id.tag &= ~LIB_TAG_NEED_LINK;
                }
        }
@@ -3514,6 +3519,12 @@ static void direct_link_camera(FileData *fd, Camera *ca)
 {
        ca->adt = newdataadr(fd, ca->adt);
        direct_link_animdata(fd, ca->adt);
+
+       link_list(fd, &ca->bg_images);
+
+       for (CameraBGImage *bgpic = ca->bg_images.first; bgpic; bgpic = bgpic->next) {
+               bgpic->iuser.ok = 1;
+       }
 }
 
 
@@ -6560,22 +6571,10 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                case SPACE_VIEW3D:
                                                {
                                                        View3D *v3d = (View3D*) sl;
-                                                       BGpic *bgpic = NULL;
 
                                                        v3d->camera= newlibadr(fd, sc->id.lib, v3d->camera);
                                                        v3d->ob_centre= newlibadr(fd, sc->id.lib, v3d->ob_centre);
 
-                                                       /* should be do_versions but not easy adding into the listbase */
-                                                       if (v3d->bgpic) {
-                                                               v3d->bgpic = newlibadr(fd, sc->id.lib, v3d->bgpic);
-                                                               BLI_addtail(&v3d->bgpicbase, bgpic);
-                                                               v3d->bgpic = NULL;
-                                                       }
-
-                                                       for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
-                                                               bgpic->ima = newlibadr_us(fd, sc->id.lib, bgpic->ima);
-                                                               bgpic->clip = newlibadr_us(fd, sc->id.lib, bgpic->clip);
-                                                       }
                                                        if (v3d->localvd) {
                                                                v3d->localvd->camera = newlibadr(fd, sc->id.lib, v3d->localvd->camera);
                                                        }
@@ -6905,21 +6904,11 @@ static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map, Main
                        for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
                                if (sl->spacetype == SPACE_VIEW3D) {
                                        View3D *v3d = (View3D *)sl;
-                                       BGpic *bgpic;
                                        ARegion *ar;
                                        
                                        v3d->camera = restore_pointer_by_name(id_map, (ID *)v3d->camera, USER_REAL);
                                        v3d->ob_centre = restore_pointer_by_name(id_map, (ID *)v3d->ob_centre, USER_REAL);
-                                       
-                                       for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
-                                               if ((bgpic->ima = restore_pointer_by_name(id_map, (ID *)bgpic->ima, USER_IGNORE))) {
-                                                       id_us_plus((ID *)bgpic->ima);
-                                               }
-                                               if ((bgpic->clip = restore_pointer_by_name(id_map, (ID *)bgpic->clip, USER_IGNORE))) {
-                                                       id_us_plus((ID *)bgpic->clip);
-                                               }
-                                       }
-                                       
+
                                        /* not very nice, but could help */
                                        if ((v3d->layact & v3d->lay) == 0) v3d->layact = v3d->lay;
 
@@ -7342,22 +7331,8 @@ static bool direct_link_screen(FileData *fd, bScreen *sc)
                        
                        if (sl->spacetype == SPACE_VIEW3D) {
                                View3D *v3d= (View3D*) sl;
-                               BGpic *bgpic;
-                               
                                v3d->flag |= V3D_INVALID_BACKBUF;
                                
-                               link_list(fd, &v3d->bgpicbase);
-                               
-                               /* should be do_versions except this doesnt fit well there */
-                               if (v3d->bgpic) {
-                                       bgpic = newdataadr(fd, v3d->bgpic);
-                                       BLI_addtail(&v3d->bgpicbase, bgpic);
-                                       v3d->bgpic = NULL;
-                               }
-                       
-                               for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next)
-                                       bgpic->iuser.ok = 1;
-                               
                                if (v3d->gpd) {
                                        v3d->gpd = newdataadr(fd, v3d->gpd);
                                        direct_link_gpencil(fd, v3d->gpd);
index 55219cbaad7f5d7232940afe0416725210ddc48c..44b8ec780e8b073f58aeb157e34c9788ea74a6dc 100644 (file)
@@ -2456,13 +2456,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
                                for (sa = sc->areabase.first; sa; sa = sa->next) {
                                        SpaceLink *sl;
                                        for (sl = sa->spacedata.first; sl; sl = sl->next) {
-                                               if (sl->spacetype == SPACE_IMAGE)
+                                               if (sl->spacetype == SPACE_IMAGE) {
                                                        ((SpaceImage *)sl)->iuser.fie_ima = 2;
-                                               else if (sl->spacetype == SPACE_VIEW3D) {
-                                                       View3D *v3d = (View3D *)sl;
-                                                       BGpic *bgpic;
-                                                       for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next)
-                                                               bgpic->iuser.fie_ima = 2;
                                                }
                                        }
                                }
index bfffcbdcae657da6a4910c90ec0021d522fca618..da41433f6bc58b2e7ec3a6efd456673c4fe058a4 100644 (file)
@@ -1992,6 +1992,10 @@ static void write_camera(WriteData *wd, Camera *cam)
                if (cam->adt) {
                        write_animdata(wd, cam->adt);
                }
+
+               for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
+                       writestruct(wd, DATA, CameraBGImage, 1, bgpic);
+               }
        }
 }
 
@@ -2992,12 +2996,8 @@ static void write_screen(WriteData *wd, bScreen *sc)
 
                        if (sl->spacetype == SPACE_VIEW3D) {
                                View3D *v3d = (View3D *)sl;
-                               BGpic *bgpic;
                                writestruct(wd, DATA, View3D, 1, v3d);
 
-                               for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
-                                       writestruct(wd, DATA, BGpic, 1, bgpic);
-                               }
                                if (v3d->localvd) {
                                        writestruct(wd, DATA, View3D, 1, v3d->localvd);
                                }
index 2a3d9fafd2aeb52e39c5620c72f1c53a5a229a9b..b1721247568078d4a81ce039e343406a682249b1 100644 (file)
@@ -3274,6 +3274,25 @@ void DRW_draw_render_loop_ex(
        DRW_state_reset();
        DRW_engines_draw_background();
 
+       /* WIP, single image drawn over the camera view (replace) */
+       bool do_bg_image = false;
+       if (rv3d->persp == RV3D_CAMOB) {
+               Object *cam_ob = v3d->camera;
+               if (cam_ob && cam_ob->type == OB_CAMERA) {
+                       Camera *cam = cam_ob->data;
+                       if (!BLI_listbase_is_empty(&cam->bg_images)) {
+                               do_bg_image = true;
+                       }
+               }
+       }
+
+       extern void view3d_draw_bgpic_test(Scene *scene, ARegion *ar, View3D *v3d,
+                                                                          const bool do_foreground, const bool do_camera_frame);
+       if (do_bg_image) {
+               view3d_draw_bgpic_test(scene, ar, v3d, false, true);
+       }
+
+
        DRW_draw_callbacks_pre_scene();
        if (DST.draw_ctx.evil_C) {
                ED_region_draw_cb_draw(DST.draw_ctx.evil_C, DST.draw_ctx.ar, REGION_DRAW_PRE_VIEW);
@@ -3301,6 +3320,10 @@ void DRW_draw_render_loop_ex(
 
        DRW_stats_reset();
 
+       if (do_bg_image) {
+               view3d_draw_bgpic_test(scene, ar, v3d, true, true);
+       }
+
        if (G.debug_value > 20) {
                DRW_debug_cpu_stats();
                DRW_debug_gpu_stats();
index 5db85d582fcc4e759789739cecf5d0f0e9071303..93786a484f2ad17115c5ea115d4b68ad05e92c84 100644 (file)
@@ -230,6 +230,7 @@ int     ED_operator_posemode_context(struct bContext *C);
 int     ED_operator_posemode(struct bContext *C);
 int     ED_operator_posemode_local(struct bContext *C);
 int     ED_operator_mask(struct bContext *C);
+int     ED_operator_camera(struct bContext *C);
 
 
 /* Cache display helpers */
index b55703bff0e20e42955301c89f72116295d2c465..341cdcdb40ab0a6474a15eb636a8c88fc4c33646 100644 (file)
@@ -40,6 +40,7 @@ struct BPoint;
 struct BaseLegacy;
 struct BezTriple;
 struct BoundBox;
+struct Camera;
 struct Depsgraph;
 struct EditBone;
 struct EvaluationContext;
@@ -430,10 +431,6 @@ bool ED_view3d_camera_lock_autokey(
 
 void ED_view3D_lock_clear(struct View3D *v3d);
 
-struct BGpic *ED_view3D_background_image_new(struct View3D *v3d);
-void ED_view3D_background_image_remove(struct View3D *v3d, struct BGpic *bgpic);
-void ED_view3D_background_image_clear(struct View3D *v3d);
-
 #define VIEW3D_MARGIN 1.4f
 #define VIEW3D_DIST_FALLBACK 1.0f
 
index bc8aa756931bbc90cc8797bc843fe38720515e7e..9f300ff0d3e53c11a59f5e5987b805b8de9f6301 100644 (file)
@@ -583,6 +583,12 @@ int ED_operator_mask(bContext *C)
        return false;
 }
 
+int ED_operator_camera(bContext *C)
+{
+       struct Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
+       return (cam != NULL);
+}
+
 /* *************************** action zone operator ************************** */
 
 /* operator state vars used:  
index 4fab7b33dbe983437cf8693e8cf9497186602a11..dbefcf3d297e2dbc9d464495891121c7f2a6fad5 100644 (file)
@@ -48,6 +48,7 @@
 
 #include "BLT_translation.h"
 
+#include "DNA_camera_types.h"
 #include "DNA_object_types.h"
 #include "DNA_node_types.h"
 #include "DNA_packedFile_types.h"
@@ -1309,21 +1310,23 @@ static int image_open_exec(bContext *C, wmOperator *op)
                ED_space_image_set(sima, scene, obedit, ima);
                iuser = &sima->iuser;
        }
-       else if (sa->spacetype == SPACE_VIEW3D) {
-               View3D *v3d = sa->spacedata.first;
-
-               for (BGpic *bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
-                       if (bgpic->ima == ima) {
-                               iuser = &bgpic->iuser;
-                               break;
-                       }
-               }
-       }
        else {
                Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
                if (tex && tex->type == TEX_IMAGE) {
                        iuser = &tex->iuser;
                }
+
+               if (iuser == NULL) {
+                       Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
+                       if (cam) {
+                               for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
+                                       if (bgpic->ima == ima) {
+                                               iuser = &bgpic->iuser;
+                                               break;
+                                       }
+                               }
+                       }
+               }
        }
 
        /* initialize because of new image */
index 549747f98d789986459d0ace58b72ad24fb341e0..9fe35d571686ff180b1bfae42728e498eb453e7a 100644 (file)
@@ -409,17 +409,6 @@ static SpaceLink *view3d_new(const bContext *C)
 static void view3d_free(SpaceLink *sl)
 {
        View3D *vd = (View3D *) sl;
-       BGpic *bgpic;
-
-       for (bgpic = vd->bgpicbase.first; bgpic; bgpic = bgpic->next) {
-               if (bgpic->source == V3D_BGPIC_IMAGE) {
-                       id_us_min((ID *)bgpic->ima);
-               }
-               else if (bgpic->source == V3D_BGPIC_MOVIE) {
-                       id_us_min((ID *)bgpic->clip);
-               }
-       }
-       BLI_freelistN(&vd->bgpicbase);
 
        if (vd->localvd) MEM_freeN(vd->localvd);
        
@@ -450,7 +439,6 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl)
 {
        View3D *v3do = (View3D *)sl;
        View3D *v3dn = MEM_dupallocN(sl);
-       BGpic *bgpic;
        
        /* clear or remove stuff from old */
 
@@ -467,16 +455,6 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl)
 
        v3dn->defmaterial = NULL;
 
-       BLI_duplicatelist(&v3dn->bgpicbase, &v3do->bgpicbase);
-       for (bgpic = v3dn->bgpicbase.first; bgpic; bgpic = bgpic->next) {
-               if (bgpic->source == V3D_BGPIC_IMAGE) {
-                       id_us_plus((ID *)bgpic->ima);
-               }
-               else if (bgpic->source == V3D_BGPIC_MOVIE) {
-                       id_us_plus((ID *)bgpic->clip);
-               }
-       }
-
        v3dn->properties_storage = NULL;
        if (v3dn->fx_settings.dof)
                v3dn->fx_settings.dof = MEM_dupallocN(v3do->fx_settings.dof);
@@ -1420,21 +1398,6 @@ static void view3d_id_remap(ScrArea *sa, SpaceLink *slink, ID *old_id, ID *new_i
                                        v3d->ob_centre_bone[0] = '\0';
                                }
                        }
-
-                       if (ELEM(GS(old_id->name), ID_IM, ID_MC)) {
-                               for (BGpic *bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
-                                       if ((ID *)bgpic->ima == old_id) {
-                                               bgpic->ima = (Image *)new_id;
-                                               id_us_min(old_id);
-                                               id_us_plus(new_id);
-                                       }
-                                       if ((ID *)bgpic->clip == old_id) {
-                                               bgpic->clip = (MovieClip *)new_id;
-                                               id_us_min(old_id);
-                                               id_us_plus(new_id);
-                                       }
-                               }
-                       }
                }
 
                if (is_local) {
index 3680470c73474e6faeb51d888b59a70700f96930..834c0390e2cfe000dae375da87e77dbefd0ddbf4 100644 (file)
@@ -534,17 +534,18 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                               const bool do_foreground, const bool do_camera_frame)
 {
        RegionView3D *rv3d = ar->regiondata;
-       int fg_flag = do_foreground ? V3D_BGPIC_FOREGROUND : 0;
+       int fg_flag = do_foreground ? CAM_BGIMG_FLAG_FOREGROUND : 0;
+       if (v3d->camera == NULL || v3d->camera->type != OB_CAMERA) {
+               return;
+       }
+       Camera *cam = v3d->camera->data;
 
-       for (BGpic *bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
+       for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
                bgpic->iuser.scene = scene;  /* Needed for render results. */
 
-               if ((bgpic->flag & V3D_BGPIC_FOREGROUND) != fg_flag)
+               if ((bgpic->flag & CAM_BGIMG_FLAG_FOREGROUND) != fg_flag)
                        continue;
 
-               if ((bgpic->view == 0) || /* zero for any */
-                   (bgpic->view & (1 << rv3d->view)) || /* check agaist flags */
-                   (rv3d->persp == RV3D_CAMOB && bgpic->view == (1 << RV3D_VIEW_CAMERA)))
                {
                        float image_aspect[2];
                        float x1, y1, x2, y2, centx, centy;
@@ -554,13 +555,13 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                        Image *ima = NULL;
 
                        /* disable individual images */
-                       if ((bgpic->flag & V3D_BGPIC_DISABLED))
+                       if ((bgpic->flag & CAM_BGIMG_FLAG_DISABLED))
                                continue;
 
                        ImBuf *ibuf = NULL;
                        ImBuf *freeibuf = NULL;
                        ImBuf *releaseibuf = NULL;
-                       if (bgpic->source == V3D_BGPIC_IMAGE) {
+                       if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
                                ima = bgpic->ima;
                                if (ima == NULL)
                                        continue;
@@ -577,11 +578,11 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                                image_aspect[0] = ima->aspx;
                                image_aspect[1] = ima->aspy;
                        }
-                       else if (bgpic->source == V3D_BGPIC_MOVIE) {
+                       else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
                                /* TODO: skip drawing when out of frame range (as image sequences do above) */
                                MovieClip *clip = NULL;
 
-                               if (bgpic->flag & V3D_BGPIC_CAMERACLIP) {
+                               if (bgpic->flag & CAM_BGIMG_FLAG_CAMERACLIP) {
                                        if (scene->camera)
                                                clip = BKE_object_movieclip_get(scene, scene->camera, true);
                                }
@@ -624,8 +625,8 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                        if (ibuf->rect == NULL)
                                IMB_rect_from_float(ibuf);
 
-                       if (rv3d->persp == RV3D_CAMOB) {
-
+                       BLI_assert(rv3d->persp == RV3D_CAMOB);
+                       {
                                if (do_camera_frame) {
                                        rctf vb;
                                        ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &vb, false);
@@ -645,8 +646,8 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                                /* so this has some sane way of working - this matches camera's shift _exactly_ */
                                {
                                        const float max_dim = max_ff(x2 - x1, y2 - y1);
-                                       const float xof_scale = bgpic->xof * max_dim;
-                                       const float yof_scale = bgpic->yof * max_dim;
+                                       const float xof_scale = bgpic->offset[0] * max_dim;
+                                       const float yof_scale = bgpic->offset[1] * max_dim;
 
                                        x1 += xof_scale;
                                        y1 += yof_scale;
@@ -658,7 +659,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                                centy = (y1 + y2) * 0.5f;
 
                                /* aspect correction */
-                               if (bgpic->flag & V3D_BGPIC_CAMERA_ASPECT) {
+                               if (bgpic->flag & CAM_BGIMG_FLAG_CAMERA_ASPECT) {
                                        /* apply aspect from clip */
                                        const float w_src = ibuf->x * image_aspect[0];
                                        const float h_src = ibuf->y * image_aspect[1];
@@ -671,7 +672,7 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                                        const float asp_dst = w_dst / h_dst;
 
                                        if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) {
-                                               if ((asp_src > asp_dst) == ((bgpic->flag & V3D_BGPIC_CAMERA_CROP) != 0)) {
+                                               if ((asp_src > asp_dst) == ((bgpic->flag & CAM_BGIMG_FLAG_CAMERA_CROP) != 0)) {
                                                        /* fit X */
                                                        const float div = asp_src / asp_dst;
                                                        x1 = ((x1 - centx) * div) + centx;
@@ -686,29 +687,6 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                                        }
                                }
                        }
-                       else {
-                               float tvec[3];
-                               float sco[2];
-                               const float mval_f[2] = {1.0f, 0.0f};
-                               const float co_zero[3] = {0};
-
-                               /* calc window coord */
-                               float zfac = ED_view3d_calc_zfac(rv3d, co_zero, NULL);
-                               ED_view3d_win_to_delta(ar, mval_f, tvec, zfac);
-                               float fac = 1.0f / max_ff(fabsf(tvec[0]), max_ff(fabsf(tvec[1]), fabsf(tvec[2]))); /* largest abs axis */
-                               float asp = (float)ibuf->y / (float)ibuf->x;
-
-                               zero_v3(tvec);
-                               ED_view3d_project_float_v2_m4(ar, tvec, sco, rv3d->persmat);
-
-                               x1 =  sco[0] + fac * (bgpic->xof - bgpic->size);
-                               y1 =  sco[1] + asp * fac * (bgpic->yof - bgpic->size);
-                               x2 =  sco[0] + fac * (bgpic->xof + bgpic->size);
-                               y2 =  sco[1] + asp * fac * (bgpic->yof + bgpic->size);
-
-                               centx = (x1 + x2) / 2.0f;
-                               centy = (y1 + y2) / 2.0f;
-                       }
 
                        /* complete clip? */
                        rctf clip_rect;
@@ -762,18 +740,19 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                        ED_region_pixelspace(ar);
 
                        gpuTranslate2f(centx, centy);
+                       gpuScaleUniform(bgpic->scale);
                        gpuRotate2D(RAD2DEGF(-bgpic->rotation));
 
-                       if (bgpic->flag & V3D_BGPIC_FLIP_X) {
+                       if (bgpic->flag & CAM_BGIMG_FLAG_FLIP_X) {
                                zoomx *= -1.0f;
                                x1 = x2;
                        }
-                       if (bgpic->flag & V3D_BGPIC_FLIP_Y) {
+                       if (bgpic->flag & CAM_BGIMG_FLAG_FLIP_Y) {
                                zoomy *= -1.0f;
                                y1 = y2;
                        }
 
-                       float col[4] = {1.0f, 1.0f, 1.0f, 1.0f - bgpic->blend};
+                       float col[4] = {1.0f, 1.0f, 1.0f, bgpic->alpha};
                        IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
                        immDrawPixelsTex(&state, x1 - centx, y1 - centy, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect,
                                         zoomx, zoomy, col);
@@ -794,13 +773,20 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
        }
 }
 
-static void view3d_draw_bgpic_test(Scene *scene, ARegion *ar, View3D *v3d,
-                                   const bool do_foreground, const bool do_camera_frame)
+void view3d_draw_bgpic_test(Scene *scene, ARegion *ar, View3D *v3d,
+                            const bool do_foreground, const bool do_camera_frame)
 {
        RegionView3D *rv3d = ar->regiondata;
 
-       if ((v3d->flag & V3D_DISPBGPICS) == 0)
+       if ((rv3d->persp == RV3D_CAMOB) && v3d->camera && (v3d->camera->type == OB_CAMERA)) {
+               Camera *cam = v3d->camera->data;
+               if ((cam->flag & CAM_SHOW_BG_IMAGE) == 0) {
+                       return;
+               }
+       }
+       else {
                return;
+       }
 
        /* disabled - mango request, since footage /w only render is quite useful
         * and this option is easy to disable all background images at once */
@@ -1884,17 +1870,32 @@ static bool view3d_main_region_draw_engine(
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-       if (v3d->flag & V3D_DISPBGPICS)
+       bool show_image = false;
+       {
+               Camera *cam = ED_view3d_camera_data_get(v3d, rv3d);
+               if (cam->flag & CAM_SHOW_BG_IMAGE) {
+                       show_image = true;
+                       view3d_draw_bgpic_test(scene, ar, v3d, false, true);
+               }
+               else {
+                       imm_draw_box_checker_2d(0, 0, ar->winx, ar->winy);
+               }
+       }
+
+       if (show_image) {
                view3d_draw_bgpic_test(scene, ar, v3d, false, true);
-       else
+       }
+       else {
                imm_draw_box_checker_2d(0, 0, ar->winx, ar->winy);
+       }
 
        /* render result draw */
        type = rv3d->render_engine->type;
        type->render_to_view(rv3d->render_engine, C);
 
-       if (v3d->flag & V3D_DISPBGPICS)
+       if (show_image) {
                view3d_draw_bgpic_test(scene, ar, v3d, true, true);
+       }
 
        if (clip_border) {
                /* restore scissor as it was before */
index 84f31020c32fadcc50f12788e7b5aa681ef8ee23..8172f29e359538c99b15f3fcc40976e0b3f53275 100644 (file)
@@ -34,6 +34,7 @@
 #include <float.h>
 
 #include "DNA_armature_types.h"
+#include "DNA_camera_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
@@ -4515,11 +4516,11 @@ void VIEW3D_OT_navigate(wmOperatorType *ot)
 
 /* ******************** add background image operator **************** */
 
-static BGpic *background_image_add(bContext *C)
+static CameraBGImage *background_image_add(bContext *C)
 {
-       View3D *v3d = CTX_wm_view3d(C);
+       Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
 
-       return ED_view3D_background_image_new(v3d);
+       return BKE_camera_background_image_new(cam);
 }
 
 static int background_image_add_exec(bContext *C, wmOperator *UNUSED(op))
@@ -4531,9 +4532,9 @@ static int background_image_add_exec(bContext *C, wmOperator *UNUSED(op))
 
 static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
-       View3D *v3d = CTX_wm_view3d(C);
+       Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
        Image *ima;
-       BGpic *bgpic;
+       CameraBGImage *bgpic;
        
        ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM);
        /* may be NULL, continue anyway */
@@ -4541,10 +4542,10 @@ static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEven
        bgpic = background_image_add(C);
        bgpic->ima = ima;
 
-       v3d->flag |= V3D_DISPBGPICS;
-       
-       WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
-       
+       cam->flag |= CAM_SHOW_BG_IMAGE;
+
+       WM_event_add_notifier(C, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
+
        return OPERATOR_FINISHED;
 }
 
@@ -4560,7 +4561,7 @@ void VIEW3D_OT_background_image_add(wmOperatorType *ot)
        /* api callbacks */
        ot->invoke = background_image_add_invoke;
        ot->exec   = background_image_add_exec;
-       ot->poll   = ED_operator_view3d_active;
+       ot->poll   = ED_operator_camera;
 
        /* flags */
        ot->flag   = OPTYPE_UNDO;
@@ -4576,21 +4577,22 @@ void VIEW3D_OT_background_image_add(wmOperatorType *ot)
 /* ***** remove image operator ******* */
 static int background_image_remove_exec(bContext *C, wmOperator *op)
 {
-       View3D *v3d = CTX_wm_view3d(C);
+       Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
        const int index = RNA_int_get(op->ptr, "index");
-       BGpic *bgpic_rem = BLI_findlink(&v3d->bgpicbase, index);
+       CameraBGImage *bgpic_rem = BLI_findlink(&cam->bg_images, index);
 
        if (bgpic_rem) {
-               if (bgpic_rem->source == V3D_BGPIC_IMAGE) {
+               if (bgpic_rem->source == CAM_BGIMG_SOURCE_IMAGE) {
                        id_us_min((ID *)bgpic_rem->ima);
                }
-               else if (bgpic_rem->source == V3D_BGPIC_MOVIE) {
+               else if (bgpic_rem->source == CAM_BGIMG_SOURCE_MOVIE) {
                        id_us_min((ID *)bgpic_rem->clip);
                }
 
-               ED_view3D_background_image_remove(v3d, bgpic_rem);
+               BKE_camera_background_image_remove(cam, bgpic_rem);
+
+               WM_event_add_notifier(C, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
 
-               WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
                return OPERATOR_FINISHED;
        }
        else {
@@ -4608,7 +4610,7 @@ void VIEW3D_OT_background_image_remove(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec   = background_image_remove_exec;
-       ot->poll   = ED_operator_view3d_active;
+       ot->poll   = ED_operator_camera;
 
        /* flags */
        ot->flag   = 0;
@@ -5186,43 +5188,6 @@ void ED_view3d_lastview_store(RegionView3D *rv3d)
        }
 }
 
-BGpic *ED_view3D_background_image_new(View3D *v3d)
-{
-       BGpic *bgpic = MEM_callocN(sizeof(BGpic), "Background Image");
-
-       bgpic->rotation = 0.0f;
-       bgpic->size = 5.0f;
-       bgpic->blend = 0.5f;
-       bgpic->iuser.fie_ima = 2;
-       bgpic->iuser.ok = 1;
-       bgpic->view = 0; /* 0 for all */
-       bgpic->flag |= V3D_BGPIC_EXPANDED;
-
-       BLI_addtail(&v3d->bgpicbase, bgpic);
-
-       return bgpic;
-}
-
-void ED_view3D_background_image_remove(View3D *v3d, BGpic *bgpic)
-{
-       BLI_remlink(&v3d->bgpicbase, bgpic);
-
-       MEM_freeN(bgpic);
-}
-
-void ED_view3D_background_image_clear(View3D *v3d)
-{
-       BGpic *bgpic = v3d->bgpicbase.first;
-
-       while (bgpic) {
-               BGpic *next_bgpic = bgpic->next;
-
-               ED_view3D_background_image_remove(v3d, bgpic);
-
-               bgpic = next_bgpic;
-       }
-}
-
 void ED_view3D_lock_clear(View3D *v3d)
 {
        v3d->ob_centre = NULL;
index cdba5ce8b81608016a098f97235388db1c4898d4..6cdc9b02da69bd2dd5633013aa5815f68b5c1197 100644 (file)
@@ -231,6 +231,9 @@ void ED_view3d_draw_select_loop(
 void ED_view3d_draw_depth_loop(
         const struct EvaluationContext *eval_ctx, Scene *scene, ARegion *ar, View3D *v3d);
 
+void view3d_draw_bgpic_test(Scene *scene, ARegion *ar, View3D *v3d,
+                                   const bool do_foreground, const bool do_camera_frame);
+
 void ED_view3d_after_add(ListBase *lb, BaseLegacy *base, const short dflag);
 
 void view3d_update_depths_rect(struct ARegion *ar, struct ViewDepths *d, struct rcti *rect);
index 4aa3edcc78807347c8277586894acd4ca8762865..c90599bb5ccaaaae1a2970b12055ed9fc4636965 100644 (file)
@@ -34,6 +34,8 @@
 
 #include "DNA_defs.h"
 #include "DNA_gpu_types.h"
+#include "DNA_movieclip_types.h"
+#include "DNA_image_types.h"
 #include "DNA_ID.h"
 
 #ifdef __cplusplus
@@ -59,6 +61,20 @@ typedef struct CameraStereoSettings {
        float pole_merge_angle_to;
 } CameraStereoSettings;
 
+/* Background Picture */
+typedef struct CameraBGImage {
+       struct CameraBGImage *next, *prev;
+
+       struct Image *ima;
+       struct ImageUser iuser;
+       struct MovieClip *clip;
+       struct MovieClipUser cuser;
+       float offset[2], scale, rotation;
+       float alpha;
+       short flag;
+       short source;
+} CameraBGImage;
+
 typedef struct Camera {
        ID id;
        struct AnimData *adt;   /* animation data (must be immediately after id for utilities to use it) */ 
@@ -82,6 +98,9 @@ typedef struct Camera {
        struct Object *dof_ob;
        struct GPUDOFSettings gpu_dof;
 
+       /* CameraBGImage reference images */
+       struct ListBase bg_images;
+
        char sensor_fit;
        char pad[7];
 
@@ -131,6 +150,7 @@ enum {
 #endif
        CAM_SHOWSENSOR          = (1 << 8),
        CAM_SHOW_SAFE_CENTER    = (1 << 9),
+       CAM_SHOW_BG_IMAGE       = (1 << 10),
 };
 
 /* yafray: dof sampling switch */
@@ -166,6 +186,32 @@ enum {
        CAM_S3D_POLE_MERGE      = (1 << 1),
 };
 
+/* CameraBGImage->flag */
+/* may want to use 1 for select ? */
+enum {
+       CAM_BGIMG_FLAG_EXPANDED      = (1 << 1),
+       CAM_BGIMG_FLAG_CAMERACLIP    = (1 << 2),
+       CAM_BGIMG_FLAG_DISABLED      = (1 << 3),
+       CAM_BGIMG_FLAG_FOREGROUND    = (1 << 4),
+
+       /* Camera framing options */
+       CAM_BGIMG_FLAG_CAMERA_ASPECT = (1 << 5),  /* don't stretch to fit the camera view  */
+       CAM_BGIMG_FLAG_CAMERA_CROP   = (1 << 6),  /* crop out the image */
+
+       /* Axis flip options */
+       CAM_BGIMG_FLAG_FLIP_X        = (1 << 7),
+       CAM_BGIMG_FLAG_FLIP_Y        = (1 << 8),
+};
+
+#define CAM_BGIMG_FLAG_EXPANDED (CAM_BGIMG_FLAG_EXPANDED | CAM_BGIMG_FLAG_CAMERACLIP)
+
+/* CameraBGImage->source */
+/* may want to use 1 for select ?*/
+enum {
+       CAM_BGIMG_SOURCE_IMAGE          = 0,
+       CAM_BGIMG_SOURCE_MOVIE          = 1,
+};
+
 #ifdef __cplusplus
 }
 #endif
index 2140f7217565edc003e15956842bf0390b7146d7..619f9fd4f6e22e86a2c9b496b9825c8ddb000684 100644 (file)
@@ -72,21 +72,6 @@ typedef struct View3DDebug {
        char background;
        char pad[7];
 } View3DDebug;
-/* Background Picture in 3D-View */
-typedef struct BGpic {
-       struct BGpic *next, *prev;
-
-       struct Image *ima;
-       struct ImageUser iuser;
-       struct MovieClip *clip;
-       struct MovieClipUser cuser;
-       float xof, yof, size, blend, rotation;
-       short view;
-       short flag;
-       short source;
-       char pad[6];
-} BGpic;
 
 /* ********************************* */
 
@@ -185,9 +170,6 @@ typedef struct View3D {
        struct Object *camera, *ob_centre;
        rctf render_border;
 
-       struct ListBase bgpicbase;
-       struct BGpic *bgpic  DNA_DEPRECATED; /* deprecated, use bgpicbase, only kept for do_versions(...) */
-
        struct View3D *localvd; /* allocated backup of its self while in localview */
        
        char ob_centre_bone[64];                /* optional string for armature bone to define center, MAXBONENAME */
@@ -269,7 +251,7 @@ typedef struct View3D {
 
 /* View3D->flag (short) */
 /*#define V3D_DISPIMAGE                1*/ /*UNUSED*/
-#define V3D_DISPBGPICS         2
+/*#define V3D_DISPBGPICS               2*/ /* UNUSED */
 #define V3D_HIDE_HELPLINES     4
 #define V3D_INVALID_BACKBUF    8
 
@@ -390,30 +372,6 @@ enum {
        V3D_MANIPULATOR_DRAW        = (1 << 0),
 };
 
-/* BGPic->flag */
-/* may want to use 1 for select ? */
-enum {
-       V3D_BGPIC_EXPANDED      = (1 << 1),
-       V3D_BGPIC_CAMERACLIP    = (1 << 2),
-       V3D_BGPIC_DISABLED      = (1 << 3),
-       V3D_BGPIC_FOREGROUND    = (1 << 4),
-
-       /* Camera framing options */
-       V3D_BGPIC_CAMERA_ASPECT = (1 << 5),  /* don't stretch to fit the camera view  */
-       V3D_BGPIC_CAMERA_CROP   = (1 << 6),  /* crop out the image */
-
-       /* Axis flip options */
-       V3D_BGPIC_FLIP_X        = (1 << 7),
-       V3D_BGPIC_FLIP_Y        = (1 << 8),
-};
-
-#define V3D_BGPIC_EXPANDED (V3D_BGPIC_EXPANDED | V3D_BGPIC_CAMERACLIP)
-
-/* BGPic->source */
-/* may want to use 1 for select ?*/
-#define V3D_BGPIC_IMAGE                0
-#define V3D_BGPIC_MOVIE                1
-
 #define RV3D_CAMZOOM_MIN -30
 #define RV3D_CAMZOOM_MAX 600
 
index c0d487ddbf628b1d1153b6ab786e60339900fad6..777585d3386ddf3d878470c883a3648d6441bb81 100644 (file)
 
 #include "BLI_math.h"
 
+#include "RNA_access.h"
 #include "RNA_define.h"
 
 #include "rna_internal.h"
 
+#include "WM_api.h"
 #include "WM_types.h"
 
 #ifdef RNA_RUNTIME
@@ -96,8 +98,192 @@ static void rna_Camera_dependency_update(Main *bmain, Scene *UNUSED(scene), Poin
        DEG_id_tag_update(&camera->id, 0);
 }
 
+static CameraBGImage *rna_Camera_background_images_new(Camera *cam)
+{
+       CameraBGImage *bgpic = BKE_camera_background_image_new(cam);
+
+       WM_main_add_notifier(NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
+
+       return bgpic;
+}
+
+static void rna_Camera_background_images_remove(Camera *cam, ReportList *reports, PointerRNA *bgpic_ptr)
+{
+       CameraBGImage *bgpic = bgpic_ptr->data;
+       if (BLI_findindex(&cam->bg_images, bgpic) == -1) {
+               BKE_report(reports, RPT_ERROR, "Background image cannot be removed");
+       }
+
+       BKE_camera_background_image_remove(cam, bgpic);
+       RNA_POINTER_INVALIDATE(bgpic_ptr);
+
+       WM_main_add_notifier(NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
+}
+
+static void rna_Camera_background_images_clear(Camera *cam)
+{
+       BKE_camera_background_image_clear(cam);
+
+       WM_main_add_notifier(NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
+}
+
 #else
 
+static void rna_def_camera_background_image(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+       static const EnumPropertyItem bgpic_source_items[] = {
+               {CAM_BGIMG_SOURCE_IMAGE, "IMAGE", 0, "Image", ""},
+               {CAM_BGIMG_SOURCE_MOVIE, "MOVIE_CLIP", 0, "Movie Clip", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       static const EnumPropertyItem bgpic_camera_frame_items[] = {
+               {0, "STRETCH", 0, "Stretch", ""},
+               {CAM_BGIMG_FLAG_CAMERA_ASPECT, "FIT", 0, "Fit", ""},
+               {CAM_BGIMG_FLAG_CAMERA_ASPECT | CAM_BGIMG_FLAG_CAMERA_CROP, "CROP", 0, "Crop", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       static const EnumPropertyItem bgpic_draw_depth_items[] = {
+               {0, "BACK", 0, "Back", ""},
+               {CAM_BGIMG_FLAG_FOREGROUND, "FRONT", 0, "Front", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       srna = RNA_def_struct(brna, "CameraBackgroundImage", NULL);
+       RNA_def_struct_sdna(srna, "CameraBGImage");
+       RNA_def_struct_ui_text(srna, "Background Image", "Image and settings for display in the 3D View background");
+
+       prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "source");
+       RNA_def_property_enum_items(prop, bgpic_source_items);
+       RNA_def_property_ui_text(prop, "Background Source", "Data source used for background");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
+       RNA_def_property_pointer_sdna(prop, NULL, "ima");
+       RNA_def_property_ui_text(prop, "Image", "Image displayed and edited in this space");
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE);
+       RNA_def_property_pointer_sdna(prop, NULL, "clip");
+       RNA_def_property_ui_text(prop, "MovieClip", "Movie clip displayed and edited in this space");
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_NEVER_NULL);
+       RNA_def_property_pointer_sdna(prop, NULL, "iuser");
+       RNA_def_property_ui_text(prop, "Image User",
+                                "Parameters defining which layer, pass and frame of the image is displayed");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "clip_user", PROP_POINTER, PROP_NONE);
+       RNA_def_property_flag(prop, PROP_NEVER_NULL);
+       RNA_def_property_struct_type(prop, "MovieClipUser");
+       RNA_def_property_pointer_sdna(prop, NULL, "cuser");
+       RNA_def_property_ui_text(prop, "Clip User", "Parameters defining which frame of the movie clip is displayed");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_XYZ);
+       RNA_def_property_float_sdna(prop, NULL, "offset");
+       RNA_def_property_ui_text(prop, "Offset", "");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_FACTOR);
+       RNA_def_property_float_sdna(prop, NULL, "scale");
+       RNA_def_property_ui_text(prop, "Scale", "Scale the background image");
+       RNA_def_property_range(prop, 0.0, FLT_MAX);
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_ANGLE);
+       RNA_def_property_float_sdna(prop, NULL, "rotation");
+       RNA_def_property_ui_text(prop, "Rotation", "Rotation for the background image (ortho view only)");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "use_flip_x", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_FLIP_X);
+       RNA_def_property_ui_text(prop, "Flip Horizontally", "Flip the background image horizontally");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "use_flip_y", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_FLIP_Y);
+       RNA_def_property_ui_text(prop, "Flip Vertically", "Flip the background image vertically");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "alpha");
+       RNA_def_property_ui_text(prop, "Alpha", "Image opacity to blend the image against the background color");
+       RNA_def_property_range(prop, 0.0, 1.0);
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_EXPANDED);
+       RNA_def_property_ui_text(prop, "Show Expanded", "Show the expanded in the user interface");
+       RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
+
+       prop = RNA_def_property(srna, "use_camera_clip", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_CAMERACLIP);
+       RNA_def_property_ui_text(prop, "Camera Clip", "Use movie clip from active scene camera");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "show_background_image", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_DISABLED);
+       RNA_def_property_ui_text(prop, "Show Background Image", "Show this image as background");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       prop = RNA_def_property(srna, "show_on_foreground", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_FOREGROUND);
+       RNA_def_property_ui_text(prop, "Show On Foreground", "Show this image in front of objects in viewport");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       /* expose 1 flag as a enum of 2 items */
+       prop = RNA_def_property(srna, "draw_depth", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
+       RNA_def_property_enum_items(prop, bgpic_draw_depth_items);
+       RNA_def_property_ui_text(prop, "Depth", "Draw under or over everything");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+       /* expose 2 flags as a enum of 3 items */
+       prop = RNA_def_property(srna, "frame_method", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
+       RNA_def_property_enum_items(prop, bgpic_camera_frame_items);
+       RNA_def_property_ui_text(prop, "Frame Method", "How the image fits in the camera frame");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+}
+
+
+static void rna_def_camera_background_images(BlenderRNA *brna, PropertyRNA *cprop)
+{
+       StructRNA *srna;
+       FunctionRNA *func;
+       PropertyRNA *parm;
+
+       RNA_def_property_srna(cprop, "CameraBackgroundImages");
+       srna = RNA_def_struct(brna, "CameraBackgroundImages", NULL);
+       RNA_def_struct_sdna(srna, "Camera");
+       RNA_def_struct_ui_text(srna, "Background Images", "Collection of background images");
+
+       func = RNA_def_function(srna, "new", "rna_Camera_background_images_new");
+       RNA_def_function_ui_description(func, "Add new background image");
+       parm = RNA_def_pointer(func, "image", "CameraBackgroundImage", "", "Image displayed as viewport background");
+       RNA_def_function_return(func, parm);
+
+       func = RNA_def_function(srna, "remove", "rna_Camera_background_images_remove");
+       RNA_def_function_ui_description(func, "Remove background image");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
+       parm = RNA_def_pointer(func, "image", "CameraBackgroundImage", "", "Image displayed as viewport background");
+       RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+       RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+
+       func = RNA_def_function(srna, "clear", "rna_Camera_background_images_clear");
+       RNA_def_function_ui_description(func, "Remove all background images");
+}
+
 static void rna_def_camera_stereo_data(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -372,6 +558,12 @@ void RNA_def_camera(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Show Sensor Size", "Show sensor size (film gate) in Camera view");
        RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
 
+       prop = RNA_def_property(srna, "show_background_images", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOW_BG_IMAGE);
+       RNA_def_property_ui_text(prop, "Display Background Images",
+                                "Display reference images behind objects in the 3D View");
+       RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
+
        prop = RNA_def_property(srna, "lens_unit", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
        RNA_def_property_enum_items(prop, prop_lens_unit_items);
@@ -390,8 +582,17 @@ void RNA_def_camera(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "GPU Depth Of Field", "");
        RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
 
+       prop = RNA_def_property(srna, "background_images", PROP_COLLECTION, PROP_NONE);
+       RNA_def_property_collection_sdna(prop, NULL, "bg_images", NULL);
+       RNA_def_property_struct_type(prop, "CameraBackgroundImage");
+       RNA_def_property_ui_text(prop, "Background Images", "List of background images");
+       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
        rna_def_animdata_common(srna);
 
+       rna_def_camera_background_image(brna);
+       rna_def_camera_background_images(brna, prop);
+
        /* Nested Data  */
        RNA_define_animate_sdna(true);
 
index 3e6328ec1315663f939ff2809cd36afede1f0ecd..679ee1fe69839bd85cc01ec5962dbb32f142e34a 100644 (file)
@@ -1463,59 +1463,6 @@ static void rna_Sequencer_view_type_update(Main *UNUSED(bmain), Scene *UNUSED(sc
        ED_area_tag_refresh(sa);
 }
 
-static float rna_BackgroundImage_opacity_get(PointerRNA *ptr)
-{
-       BGpic *bgpic = (BGpic *)ptr->data;
-       return 1.0f - bgpic->blend;
-}
-
-static void rna_BackgroundImage_opacity_set(PointerRNA *ptr, float value)
-{
-       BGpic *bgpic = (BGpic *)ptr->data;
-       bgpic->blend = 1.0f - value;
-}
-
-/* radius internally (expose as a distance value) */
-static float rna_BackgroundImage_size_get(PointerRNA *ptr)
-{
-       BGpic *bgpic = ptr->data;
-       return bgpic->size * 2.0f;
-}
-
-static void rna_BackgroundImage_size_set(PointerRNA *ptr, float value)
-{
-       BGpic *bgpic = ptr->data;
-       bgpic->size = value * 0.5f;
-}
-
-static BGpic *rna_BackgroundImage_new(View3D *v3d)
-{
-       BGpic *bgpic = ED_view3D_background_image_new(v3d);
-
-       WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, v3d);
-
-       return bgpic;
-}
-
-static void rna_BackgroundImage_remove(View3D *v3d, ReportList *reports, PointerRNA *bgpic_ptr)
-{
-       BGpic *bgpic = bgpic_ptr->data;
-       if (BLI_findindex(&v3d->bgpicbase, bgpic) == -1) {
-               BKE_report(reports, RPT_ERROR, "Background image cannot be removed");
-       }
-
-       ED_view3D_background_image_remove(v3d, bgpic);
-       RNA_POINTER_INVALIDATE(bgpic_ptr);
-
-       WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, v3d);
-}
-
-static void rna_BackgroundImage_clear(View3D *v3d)
-{
-       ED_view3D_background_image_clear(v3d);
-       WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, v3d);
-}
-
 /* Space Node Editor */
 
 static void rna_SpaceNodeEditor_node_tree_set(PointerRNA *ptr, const PointerRNA value)
@@ -2206,194 +2153,6 @@ static void rna_def_space_outliner(BlenderRNA *brna)
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
 }
 
-static void rna_def_background_image(BlenderRNA *brna)
-{
-       StructRNA *srna;
-       PropertyRNA *prop;
-
-       /* note: combinations work but don't flip so arnt that useful */
-       static const EnumPropertyItem bgpic_axis_items[] = {
-               {0, "", 0, N_("X Axis"), ""},
-               {(1 << RV3D_VIEW_LEFT), "LEFT", 0, "Left", "Show background image while looking to the left"},
-               {(1 << RV3D_VIEW_RIGHT), "RIGHT", 0, "Right", "Show background image while looking to the right"},
-               /*{(1<<RV3D_VIEW_LEFT)|(1<<RV3D_VIEW_RIGHT), "LEFT_RIGHT", 0, "Left/Right", ""},*/
-               {0, "", 0, N_("Y Axis"), ""},
-               {(1 << RV3D_VIEW_BACK), "BACK", 0, "Back", "Show background image in back view"},
-               {(1 << RV3D_VIEW_FRONT), "FRONT", 0, "Front", "Show background image in front view"},
-               /*{(1<<RV3D_VIEW_BACK)|(1<<RV3D_VIEW_FRONT), "BACK_FRONT", 0, "Back/Front", ""},*/
-               {0, "", 0, N_("Z Axis"), ""},
-               {(1 << RV3D_VIEW_BOTTOM), "BOTTOM", 0, "Bottom", "Show background image in bottom view"},
-               {(1 << RV3D_VIEW_TOP), "TOP", 0, "Top", "Show background image in top view"},
-               /*{(1<<RV3D_VIEW_BOTTOM)|(1<<RV3D_VIEW_TOP), "BOTTOM_TOP", 0, "Top/Bottom", ""},*/
-               {0, "", 0, N_("Other"), ""},
-               {0, "ALL", 0, "All Views", "Show background image in all views"},
-               {(1 << RV3D_VIEW_CAMERA), "CAMERA", 0, "Camera", "Show background image in camera view"},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       static const EnumPropertyItem bgpic_source_items[] = {
-               {V3D_BGPIC_IMAGE, "IMAGE", 0, "Image", ""},
-               {V3D_BGPIC_MOVIE, "MOVIE_CLIP", 0, "Movie Clip", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       static const EnumPropertyItem bgpic_camera_frame_items[] = {
-               {0, "STRETCH", 0, "Stretch", ""},
-               {V3D_BGPIC_CAMERA_ASPECT, "FIT", 0, "Fit", ""},
-               {V3D_BGPIC_CAMERA_ASPECT | V3D_BGPIC_CAMERA_CROP, "CROP", 0, "Crop", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       static const EnumPropertyItem bgpic_draw_depth_items[] = {
-               {0, "BACK", 0, "Back", ""},
-               {V3D_BGPIC_FOREGROUND, "FRONT", 0, "Front", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       srna = RNA_def_struct(brna, "BackgroundImage", NULL);
-       RNA_def_struct_sdna(srna, "BGpic");
-       RNA_def_struct_ui_text(srna, "Background Image", "Image and settings for display in the 3D View background");
-
-       prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_sdna(prop, NULL, "source");
-       RNA_def_property_enum_items(prop, bgpic_source_items);
-       RNA_def_property_ui_text(prop, "Background Source", "Data source used for background");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
-       RNA_def_property_pointer_sdna(prop, NULL, "ima");
-       RNA_def_property_ui_text(prop, "Image", "Image displayed and edited in this space");
-       RNA_def_property_flag(prop, PROP_EDITABLE);
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE);
-       RNA_def_property_pointer_sdna(prop, NULL, "clip");
-       RNA_def_property_ui_text(prop, "MovieClip", "Movie clip displayed and edited in this space");
-       RNA_def_property_flag(prop, PROP_EDITABLE);
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
-       RNA_def_property_flag(prop, PROP_NEVER_NULL);
-       RNA_def_property_pointer_sdna(prop, NULL, "iuser");
-       RNA_def_property_ui_text(prop, "Image User",
-                                "Parameters defining which layer, pass and frame of the image is displayed");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "clip_user", PROP_POINTER, PROP_NONE);
-       RNA_def_property_flag(prop, PROP_NEVER_NULL);
-       RNA_def_property_struct_type(prop, "MovieClipUser");
-       RNA_def_property_pointer_sdna(prop, NULL, "cuser");
-       RNA_def_property_ui_text(prop, "Clip User", "Parameters defining which frame of the movie clip is displayed");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "offset_x", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_float_sdna(prop, NULL, "xof");
-       RNA_def_property_ui_text(prop, "X Offset", "Offset image horizontally from the world origin");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "offset_y", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_float_sdna(prop, NULL, "yof");
-       RNA_def_property_ui_text(prop, "Y Offset", "Offset image vertically from the world origin");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "size", PROP_FLOAT, PROP_DISTANCE);
-       RNA_def_property_float_sdna(prop, NULL, "size");
-       RNA_def_property_float_funcs(prop, "rna_BackgroundImage_size_get", "rna_BackgroundImage_size_set", NULL);
-       RNA_def_property_ui_text(prop, "Size", "Size of the background image (ortho view only)");
-       RNA_def_property_range(prop, 0.0, FLT_MAX);
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_EULER);
-       RNA_def_property_float_sdna(prop, NULL, "rotation");
-       RNA_def_property_ui_text(prop, "Rotation", "Rotation for the background image (ortho view only)");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "use_flip_x", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FLIP_X);
-       RNA_def_property_ui_text(prop, "Flip Horizontally", "Flip the background image horizontally");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "use_flip_y", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FLIP_Y);
-       RNA_def_property_ui_text(prop, "Flip Vertically", "Flip the background image vertically");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "opacity", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_float_sdna(prop, NULL, "blend");
-       RNA_def_property_float_funcs(prop, "rna_BackgroundImage_opacity_get", "rna_BackgroundImage_opacity_set", NULL);
-       RNA_def_property_ui_text(prop, "Opacity", "Image opacity to blend the image against the background color");
-       RNA_def_property_range(prop, 0.0, 1.0);
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "view_axis", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_sdna(prop, NULL, "view");
-       RNA_def_property_enum_items(prop, bgpic_axis_items);
-       RNA_def_property_ui_text(prop, "Image Axis", "The axis to display the image on");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_EXPANDED);
-       RNA_def_property_ui_text(prop, "Show Expanded", "Show the expanded in the user interface");
-       RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
-
-       prop = RNA_def_property(srna, "use_camera_clip", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_CAMERACLIP);
-       RNA_def_property_ui_text(prop, "Camera Clip", "Use movie clip from active scene camera");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "show_background_image", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", V3D_BGPIC_DISABLED);
-       RNA_def_property_ui_text(prop, "Show Background Image", "Show this image as background");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       prop = RNA_def_property(srna, "show_on_foreground", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FOREGROUND);
-       RNA_def_property_ui_text(prop, "Show On Foreground", "Show this image in front of objects in viewport");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       /* expose 1 flag as a enum of 2 items */
-       prop = RNA_def_property(srna, "draw_depth", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
-       RNA_def_property_enum_items(prop, bgpic_draw_depth_items);
-       RNA_def_property_ui_text(prop, "Depth", "Draw under or over everything");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
-       /* expose 2 flags as a enum of 3 items */
-       prop = RNA_def_property(srna, "frame_method", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
-       RNA_def_property_enum_items(prop, bgpic_camera_frame_items);
-       RNA_def_property_ui_text(prop, "Frame Method", "How the image fits in the camera frame");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-}
-
-static void rna_def_backgroundImages(BlenderRNA *brna, PropertyRNA *cprop)
-{
-       StructRNA *srna;
-       FunctionRNA *func;
-       PropertyRNA *parm;
-
-       RNA_def_property_srna(cprop, "BackgroundImages");
-       srna = RNA_def_struct(brna, "BackgroundImages", NULL);
-       RNA_def_struct_sdna(srna, "View3D");
-       RNA_def_struct_ui_text(srna, "Background Images", "Collection of background images");
-
-       func = RNA_def_function(srna, "new", "rna_BackgroundImage_new");
-       RNA_def_function_ui_description(func, "Add new background image");
-       parm = RNA_def_pointer(func, "image", "BackgroundImage", "", "Image displayed as viewport background");
-       RNA_def_function_return(func, parm);
-
-       func = RNA_def_function(srna, "remove", "rna_BackgroundImage_remove");
-       RNA_def_function_ui_description(func, "Remove background image");
-       RNA_def_function_flag(func, FUNC_USE_REPORTS);
-       parm = RNA_def_pointer(func, "image", "BackgroundImage", "", "Image displayed as viewport background");
-       RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
-       RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
-
-       func = RNA_def_function(srna, "clear", "rna_BackgroundImage_clear");
-       RNA_def_function_ui_description(func, "Remove all background images");
-}
-
-
 static void rna_def_space_view3d(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -2669,19 +2428,6 @@ static void rna_def_space_view3d(BlenderRNA *brna)
        RNA_def_property_ui_icon(prop, ICON_ORTHO, 0);
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
-       prop = RNA_def_property(srna, "background_images", PROP_COLLECTION, PROP_NONE);
-       RNA_def_property_collection_sdna(prop, NULL, "bgpicbase", NULL);
-       RNA_def_property_struct_type(prop, "BackgroundImage");
-       RNA_def_property_ui_text(prop, "Background Images", "List of background images");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-       rna_def_backgroundImages(brna, prop);
-
-       prop = RNA_def_property(srna, "show_background_images", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_DISPBGPICS);
-       RNA_def_property_ui_text(prop, "Display Background Images",
-                                "Display reference images behind objects in the 3D View");
-       RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
        prop = RNA_def_property(srna, "pivot_point", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "around");
        RNA_def_property_enum_items(prop, pivot_items_full);
@@ -4852,7 +4598,6 @@ void RNA_def_space(BlenderRNA *brna)
        rna_def_filemenu_entry(brna);
        rna_def_space_filebrowser(brna);
        rna_def_space_outliner(brna);
-       rna_def_background_image(brna);
        rna_def_space_view3d(brna);
        rna_def_space_buttons(brna);
        rna_def_space_dopesheet(brna);
index f22769dde4048b8c4dd6ce7b6b53c265fdb85967..c6b25ff8079dc2caffbb04c73b593db467cc4e4d 100644 (file)
@@ -34,6 +34,8 @@
 #include <string.h>
 
 #include "DNA_listBase.h"
+#include "DNA_object_types.h"
+#include "DNA_camera_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_userdef_types.h"
@@ -708,9 +710,12 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
                        case SPACE_VIEW3D:
                        {
                                View3D *v3d = sa->spacedata.first;
-                               BGpic *bgpic = v3d->bgpicbase.first;
-                               v3d->multiview_eye = sview;
-                               if (bgpic) bgpic->iuser.multiview_eye = sview;
+                               if (v3d->camera && v3d->camera->type == OB_CAMERA) {
+                                       Camera *cam = v3d->camera->data;
+                                       CameraBGImage *bgpic = cam->bg_images.first;
+                                       v3d->multiview_eye = sview;
+                                       if (bgpic) bgpic->iuser.multiview_eye = sview;
+                               }
                                break;
                        }
                        case SPACE_NODE:
index 30084ba090f2bfbcf2bd5b59b75c5209e72f6bfc..6f874e7728cb98c36e90ba1a24781236f5bab07c 100644 (file)
@@ -542,9 +542,6 @@ void ED_node_tree_pop(struct SpaceNode *snode) RET_NONE
 int ED_view3d_scene_layer_set(int lay, const int *values, int *active) RET_ZERO
 void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip) RET_NONE
 void ED_view3d_from_m4(float mat[4][4], float ofs[3], float quat[4], float *dist) RET_NONE
-struct BGpic *ED_view3D_background_image_new(struct View3D *v3d) RET_NULL
-void ED_view3D_background_image_remove(struct View3D *v3d, struct BGpic *bgpic) RET_NONE
-void ED_view3D_background_image_clear(struct View3D *v3d) RET_NONE
 void ED_view3d_update_viewmat(const struct EvaluationContext *eval_ctx, struct Scene *scene, struct View3D *v3d, struct ARegion *ar, float viewmat[4][4], float winmat[4][4], const struct rcti *rect) RET_NONE
 float ED_view3d_grid_scale(struct Scene *scene, struct View3D *v3d, const char **grid_unit) RET_ZERO
 void ED_view3d_shade_update(struct Main *bmain, struct Scene *scene, struct View3D *v3d, struct ScrArea *sa) RET_NONE