Commit: e2d60d180ed8a318b48833a07e1d17a788fa9a38
Author: Campbell Barton
Date:   Tue Apr 28 23:34:40 2015 +1000
Branches: master
https://developer.blender.org/rBe2d60d180ed8a318b48833a07e1d17a788fa9a38

Project Paint: Add symmetry support

- Access from symmetry panel (as with sculpt)
- Supports multiple axis at once.
- Supports all brush types including clone.

===================================================================

M       release/scripts/startup/bl_ui/space_view3d_toolbar.py
M       source/blender/editors/include/ED_view3d.h
M       source/blender/editors/sculpt_paint/paint_image_proj.c
M       source/blender/editors/space_view3d/view3d_project.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py 
b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index d5f64a7..51dd8b0 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -1698,6 +1698,25 @@ class VIEW3D_PT_tools_imagepaint_external(Panel, 
View3DPaintPanel):
         col.operator("paint.project_image", text="Apply Camera Image")
 
 
+class VIEW3D_PT_tools_imagepaint_symmetry(Panel, View3DPaintPanel):
+    bl_category = "Tools"
+    bl_context = "imagepaint"
+    bl_label = "Symmetry"
+    bl_options = {'DEFAULT_CLOSED'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        toolsettings = context.tool_settings
+        ipaint = toolsettings.image_paint
+
+        col = layout.column(align=True)
+        row = col.row(align=True)
+        row.prop(ipaint, "use_symmetry_x", text="X", toggle=True)
+        row.prop(ipaint, "use_symmetry_y", text="Y", toggle=True)
+        row.prop(ipaint, "use_symmetry_z", text="Z", toggle=True)
+
+
 class VIEW3D_PT_tools_projectpaint(View3DPaintPanel, Panel):
     bl_category = "Options"
     bl_context = "imagepaint"
diff --git a/source/blender/editors/include/ED_view3d.h 
b/source/blender/editors/include/ED_view3d.h
index ab270f6..be4204e 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -219,6 +219,7 @@ void ED_view3d_win_to_vector(const struct ARegion *ar, 
const float mval[2], floa
 bool ED_view3d_win_to_segment(const struct ARegion *ar, struct View3D *v3d, 
const float mval[2],
                               float r_ray_start[3], float r_ray_end[3], const 
bool do_clip);
 void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, struct 
Object *ob, float pmat[4][4]);
+void ED_view3d_ob_project_mat_get_from_obmat(const struct RegionView3D *rv3d, 
float obmat[4][4], float pmat[4][4]);
 void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, 
const float y, const float z);
 
 /* end */
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c 
b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 3ceaaff..698b62b 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -43,6 +43,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
 #include "BLI_math.h"
+#include "BLI_math_bits.h"
 #include "BLI_math_color_blend.h"
 #include "BLI_memarena.h"
 #include "BLI_threads.h"
@@ -196,6 +197,29 @@ typedef struct ProjPaintImage {
        bool touch;
 } ProjPaintImage;
 
+/**
+ * Handle for stroke (operator customdata)
+ */
+typedef struct ProjStrokeHandle {
+       /* Support for painting from multiple views at once,
+        * currently used to impliment summetry painting,
+        * we can assume at least the first is set while painting. */
+       struct ProjPaintState *ps_views[8];
+       int ps_views_tot;
+       int symmetry_flags;
+
+       int orig_brush_size;
+
+       bool need_redraw;
+
+       /* trick to bypass regular paint and allow clone picking */
+       bool is_clone_cursor_pick;
+
+       /* In ProjPaintState, only here for convenience */
+       Scene *scene;
+       Brush *brush;
+} ProjStrokeHandle;
+
 /* Main projection painting struct passed to all projection painting functions 
*/
 typedef struct ProjPaintState {
        View3D *v3d;
@@ -211,24 +235,14 @@ typedef struct ProjPaintState {
 
        Brush *brush;
        short tool, blend, mode;
-       int orig_brush_size;
+
        float brush_size;
        Object *ob;
+       /* for symmetry, we need to store modified object matrix */
+       float obmat[4][4];
+       float obmat_imat[4][4];
        /* end similarities with ImagePaintState */
 
-       DerivedMesh    *dm;
-       int dm_totface;
-       int dm_totedge;
-       int dm_totvert;
-       int dm_release;
-
-       MVert          *dm_mvert;
-       MEdge          *dm_medge;
-       MFace          *dm_mface;
-       MTFace         **dm_mtface;
-       MTFace         **dm_mtface_clone;    /* other UV map, use for cloning 
between layers */
-       MTFace         *dm_mtface_stencil;
-
        Image *stencil_ima;
        Image *canvas_ima;
        Image *clone_ima;
@@ -239,24 +253,16 @@ typedef struct ProjPaintState {
        LinkNode **bucketRect;              /* screen sized 2D array, each 
pixel has a linked list of ProjPixel's */
        LinkNode **bucketFaces;             /* bucketRect aligned array 
linkList of faces overlapping each bucket */
        unsigned char *bucketFlags;         /* store if the bucks have been 
initialized  */
-#ifndef PROJ_DEBUG_NOSEAMBLEED
-       char *faceSeamFlags;                /* store info about faces, if they 
are initialized etc*/
-       char *faceWindingFlags;             /* save the winding of the face in 
uv space, helps as an extra validation step for seam detection */
-       float (*faceSeamUVs)[4][2];         /* expanded UVs for faces to use as 
seams */
-       LinkNode **vertFaces;               /* Only needed for when 
seam_bleed_px is enabled, use to find UV seams */
-#endif
+
        char *vertFlags;                    /* store options per vert, now only 
store if the vert is pointing away from the view */
        int buckets_x;                      /* The size of the bucket grid, the 
grid span's screenMin/screenMax so you can paint outsize the screen or with 2 
brushes at once */
        int buckets_y;
 
-       ProjPaintImage *projImages;
-
        int pixel_sizeof;           /* result of project_paint_pixel_sizeof(), 
constant per stroke */
 
        int image_tot;              /* size of projectImages array */
 
        float (*screenCoords)[4];   /* verts projected into floating point 
screen space */
-       float *cavities;            /* cavity amount for vertices */
        float screenMin[2];         /* 2D bounds for mesh verts on the screen's 
plane (screenspace) */
        float screenMax[2];
        float screen_width;         /* Calculated from screenMin & screenMax */
@@ -308,13 +314,51 @@ typedef struct ProjPaintState {
        int bucketMax[2];
        int context_bucket_x, context_bucket_y; /* must lock threads while 
accessing these */
 
-       /* redraw */
-       bool need_redraw;
-
        struct CurveMapping *cavity_curve;
        BlurKernel *blurkernel;
 
+
+
+       /* -------------------------------------------------------------------- 
*/
+       /* Vars shared between multiple views (keep last) */
+       /**
+        * This data is owned by ``ProjStrokeHandle.ps_views[0]``,
+        * all other views re-use the data.
+        */
+
+#define PROJ_PAINT_STATE_SHARED_MEMCPY(ps_dst, ps_src) \
+       MEMCPY_STRUCT_OFS(ps_dst, ps_src, is_shared_user)
+
+#define PROJ_PAINT_STATE_SHARED_CLEAR(ps) \
+       MEMSET_STRUCT_OFS(ps, 0, is_shared_user)
+
+       bool is_shared_user;
+
+       ProjPaintImage *projImages;
+       float *cavities;            /* cavity amount for vertices */
+
+#ifndef PROJ_DEBUG_NOSEAMBLEED
+       char *faceSeamFlags;                /* store info about faces, if they 
are initialized etc*/
+       char *faceWindingFlags;             /* save the winding of the face in 
uv space, helps as an extra validation step for seam detection */
+       float (*faceSeamUVs)[4][2];         /* expanded UVs for faces to use as 
seams */
+       LinkNode **vertFaces;               /* Only needed for when 
seam_bleed_px is enabled, use to find UV seams */
+#endif
+
        SpinLock *tile_lock;
+
+       DerivedMesh    *dm;
+       int dm_totface;
+       int dm_totedge;
+       int dm_totvert;
+       int dm_release;
+
+       MVert          *dm_mvert;
+       MEdge          *dm_medge;
+       MFace          *dm_mface;
+       MTFace         *dm_mtface_stencil;
+
+       MTFace         **dm_mtface;
+       MTFace         **dm_mtface_clone;    /* other UV map, use for cloning 
between layers */
 } ProjPaintState;
 
 typedef union pixelPointer {
@@ -3110,7 +3154,8 @@ static void proj_paint_state_non_cddm_init(ProjPaintState 
*ps)
        }
 }
 
-static void proj_paint_state_viewport_init(ProjPaintState *ps)
+static void proj_paint_state_viewport_init(
+        ProjPaintState *ps, const char symmetry_flag)
 {
        float mat[3][3];
        float viewmat[4][4];
@@ -3120,7 +3165,19 @@ static void 
proj_paint_state_viewport_init(ProjPaintState *ps)
        ps->viewDir[1] = 0.0f;
        ps->viewDir[2] = 1.0f;
 
-       invert_m4_m4(ps->ob->imat, ps->ob->obmat);
+       copy_m4_m4(ps->obmat, ps->ob->obmat);
+
+       if (symmetry_flag) {
+               int i;
+               for (i = 0; i < 3; i++) {
+                       if ((symmetry_flag >> i) & 1) {
+                               negate_v3(ps->obmat[i]);
+                               ps->is_flip_object = !ps->is_flip_object;
+                       }
+               }
+       }
+
+       invert_m4_m4(ps->obmat_imat, ps->obmat);
 
        if (ELEM(ps->source, PROJ_SRC_VIEW, PROJ_SRC_VIEW_FILL)) {
                /* normal drawing */
@@ -3130,7 +3187,7 @@ static void proj_paint_state_viewport_init(ProjPaintState 
*ps)
                copy_m4_m4(viewmat, ps->rv3d->viewmat);
                copy_m4_m4(viewinv, ps->rv3d->viewinv);
 
-               ED_view3d_ob_project_mat_get(ps->rv3d, ps->ob, ps->projectMat);
+               ED_view3d_ob_project_mat_get_from_obmat(ps->rv3d, ps->obmat, 
ps->projectMat);
 
                ps->is_ortho = ED_view3d_clip_range_get(ps->v3d, ps->rv3d, 
&ps->clipsta, &ps->clipend, true);
        }
@@ -3183,16 +3240,15 @@ static void 
proj_paint_state_viewport_init(ProjPaintState *ps)
                }
 
                /* same as #ED_view3d_ob_project_mat_get */
-               mul_m4_m4m4(vmat, viewmat, ps->ob->obmat);
+               mul_m4_m4m4(vmat, viewmat, ps->obmat);
                mul_m4_m4m4(ps->projectMat, winmat, vmat);
        }
 
 
        /* viewDir - object relative */
-       invert_m4_m4(ps->ob->imat, ps->ob->obmat);
        copy_m3_m4(mat, viewinv);
        mul_m3_v3(mat, ps->viewDir);
-       copy_m3_m4(mat, ps->ob->imat);
+       copy_m3_m4(mat, ps->obmat_imat);
        mul_m3_v3(mat, ps->viewDir);
        normalize_v3(ps->viewDir);
 
@@ -3202,9 +3258,9 @@ static void proj_paint_state_viewport_init(ProjPaintState 
*ps)
 
        /* viewPos - object relative */
        copy_v3_v3(ps->viewPos, viewinv[3]);
-       copy_m3_m4(mat, ps->ob->imat);
+       copy_m3_m4(mat, ps->obmat_imat);
        mul_m3_v3(mat, ps->viewPos);
-       add_v3_v3(ps->viewPos, ps->ob->imat[3]);
+       add_v3_v3(ps->viewPos, ps->obmat_imat[3]);
 }
 
 static void proj_paint_state_screen_coords_init(ProjPaintState *ps, const int 
diameter)
@@ -3351,12 +3407,14 @@ static void proj_paint_state_thread_init(ProjPaintState 
*ps, const bool reset_th
        if (reset_threads)
                ps->thread_tot = 1;
 
-       if (ps->thread_tot > 1) {
-               ps->tile_lock = MEM_mallocN(sizeof(SpinLock), 
"projpaint_tile_lock");
-               BLI_spin_init(ps->tile_lock);
-       }
+       if (ps->is_shared_user == false) {
+               if (ps->thread_tot > 1) {
+                       ps->tile_lock = MEM_mallocN(sizeof(SpinLock), 
"projpaint_tile_lock");
+                       BLI_spin_init(ps->tile_lock);
+               }
 
-       image_undo_init_locks();
+

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to