Commit: 6554207841a452cc58857232837740746a1e8b80
Author: Campbell Barton
Date:   Tue Jan 9 14:59:45 2018 +1100
Branches: master
https://developer.blender.org/rB6554207841a452cc58857232837740746a1e8b80

Add deform axis for Simple Deform modifier

D2989 by @dmarra w/ own edits

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

M       release/scripts/startup/bl_ui/properties_data_modifier.py
M       source/blender/blenloader/intern/versioning_270.c
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/makesrna/intern/rna_modifier.c
M       source/blender/modifiers/intern/MOD_simpledeform.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 7388dea2158..9cd3b743557 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -848,10 +848,18 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.label(text="Axis, Origin:")
         col.prop(md, "origin", text="")
 
+        col.prop(md, "deform_axis")
+
         if md.deform_method in {'TAPER', 'STRETCH', 'TWIST'}:
-            col.label(text="Lock:")
-            col.prop(md, "lock_x")
-            col.prop(md, "lock_y")
+            row = col.row(align=True)
+            row.label(text="Lock:")
+            deform_axis = md.deform_axis
+            if deform_axis != 'X':
+                row.prop(md, "lock_x")
+            if deform_axis != 'Y':
+                row.prop(md, "lock_y")
+            if deform_axis != 'Z':
+                row.prop(md, "lock_z")
 
         col = split.column()
         col.label(text="Deform:")
diff --git a/source/blender/blenloader/intern/versioning_270.c 
b/source/blender/blenloader/intern/versioning_270.c
index fa7bf0c7dee..20475582bc9 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -1735,6 +1735,29 @@ void blo_do_versions_270(FileData *fd, Library 
*UNUSED(lib), Main *main)
                }
        }
 
+       if (!MAIN_VERSION_ATLEAST(main, 279, 1)) {
+               /* Simple deform modifier no longer assumes Z axis (X for bend 
type).
+                * Must set previous defaults. */
+               if (!DNA_struct_elem_find(fd->filesdna, 
"SimpleDeformModifierData", "char", "deform_axis")) {
+                       for (Object *ob = main->object.first; ob; ob = 
ob->id.next) {
+                               for (ModifierData *md = ob->modifiers.first; 
md; md = md->next) {
+                                       if (md->type == 
eModifierType_SimpleDeform) {
+                                               SimpleDeformModifierData *smd = 
(SimpleDeformModifierData *)md;
+                                               switch (smd->mode) {
+                                                       case 
MOD_SIMPLEDEFORM_MODE_BEND:
+                                                               
smd->deform_axis = 0;
+                                                               break;
+                                                       default:
+                                                               
smd->deform_axis = 2;
+                                                               break;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
+
        {
                /* Fix for invalid state of screen due to bug in older 
versions. */
                for (bScreen *sc = main->screen.first; sc; sc = sc->id.next) {
diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index fc0bf59518c..f7136e6e438 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -868,8 +868,8 @@ typedef struct SimpleDeformModifierData {
 
        char mode;              /* deform function */
        char axis;              /* lock axis (for taper and strech) */
+       char deform_axis;       /* axis to perform the deform on (default is X, 
but can be overridden by origin */
        char flag;
-       char pad;
 
 } SimpleDeformModifierData;
 
@@ -889,6 +889,7 @@ enum {
 enum {
        MOD_SIMPLEDEFORM_LOCK_AXIS_X = (1 << 0),
        MOD_SIMPLEDEFORM_LOCK_AXIS_Y = (1 << 1),
+       MOD_SIMPLEDEFORM_LOCK_AXIS_Z = (1 << 2),
 };
 
 typedef struct ShapeKeyModifierData {
diff --git a/source/blender/makesrna/intern/rna_modifier.c 
b/source/blender/makesrna/intern/rna_modifier.c
index a99c9f9d89e..bc36af8d751 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -3239,6 +3239,11 @@ static void rna_def_modifier_simpledeform(BlenderRNA 
*brna)
        RNA_def_property_string_funcs(prop, NULL, NULL, 
"rna_SimpleDeformModifier_vgroup_name_set");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+       prop = RNA_def_property(srna, "deform_axis", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, rna_enum_axis_xyz_items);
+       RNA_def_property_ui_text(prop, "Axis", "Deform around local axis");
+       RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
        prop = RNA_def_property(srna, "origin", PROP_POINTER, PROP_NONE);
        RNA_def_property_ui_text(prop, "Origin", "Offset the origin and 
orientation of the deformation");
        RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
@@ -3268,12 +3273,17 @@ static void rna_def_modifier_simpledeform(BlenderRNA 
*brna)
 
        prop = RNA_def_property(srna, "lock_x", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "axis", 
MOD_SIMPLEDEFORM_LOCK_AXIS_X);
-       RNA_def_property_ui_text(prop, "Lock X Axis", "Do not allow deformation 
along the X axis");
+       RNA_def_property_ui_text(prop, "X", "Do not allow deformation along the 
X axis");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
        prop = RNA_def_property(srna, "lock_y", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "axis", 
MOD_SIMPLEDEFORM_LOCK_AXIS_Y);
-       RNA_def_property_ui_text(prop, "Lock Y Axis", "Do not allow deformation 
along the Y axis");
+       RNA_def_property_ui_text(prop, "Y", "Do not allow deformation along the 
Y axis");
+       RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+       prop = RNA_def_property(srna, "lock_z", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "axis", 
MOD_SIMPLEDEFORM_LOCK_AXIS_Z);
+       RNA_def_property_ui_text(prop, "Z", "Do not allow deformation along the 
Z axis");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
        prop = RNA_def_property(srna, "invert_vertex_group", PROP_BOOLEAN, 
PROP_NONE);
diff --git a/source/blender/modifiers/intern/MOD_simpledeform.c 
b/source/blender/modifiers/intern/MOD_simpledeform.c
index 379eaea5b0c..00c1fc90d27 100644
--- a/source/blender/modifiers/intern/MOD_simpledeform.c
+++ b/source/blender/modifiers/intern/MOD_simpledeform.c
@@ -32,7 +32,6 @@
  *  \ingroup modifiers
  */
 
-
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 
@@ -51,9 +50,33 @@
 
 #define BEND_EPS 0.000001f
 
+/* Re-maps the indicies for X Y Z by shifting them up and wrapping, such that
+ * X = Y, Y = Z, Z = X (for X axis), and X = Z, Y = X, Z = Y (for Y axis). This
+ * exists because the deformations (excluding bend) are based on the Z axis.
+ * Having this helps avoid long, drawn out switches. */
+static const uint axis_map_table[3][3] = {
+       {1, 2, 0},
+       {2, 0, 1},
+       {0, 1, 2},
+};
+
+BLI_INLINE void copy_v3_v3_map(float a[3], const float b[3], const uint map[3])
+{
+       a[0] = b[map[0]];
+       a[1] = b[map[1]];
+       a[2] = b[map[2]];
+}
+
+BLI_INLINE void copy_v3_v3_unmap(float a[3], const float b[3], const uint 
map[3])
+{
+       a[map[0]] = b[0];
+       a[map[1]] = b[1];
+       a[map[2]] = b[2];
+}
+
 /* Clamps/Limits the given coordinate to:  limits[0] <= co[axis] <= limits[1]
  * The amount of clamp is saved on dcut */
-static void axis_limit(int axis, const float limits[2], float co[3], float 
dcut[3])
+static void axis_limit(const int axis, const float limits[2], float co[3], 
float dcut[3])
 {
        float val = co[axis];
        if (limits[0] > val) val = limits[0];
@@ -63,7 +86,7 @@ static void axis_limit(int axis, const float limits[2], float 
co[3], float dcut[
        co[axis] = val;
 }
 
-static void simpleDeform_taper(const float factor, const float dcut[3], float 
r_co[3])
+static void simpleDeform_taper(const float factor, const int UNUSED(axis), 
const float dcut[3], float r_co[3])
 {
        float x = r_co[0], y = r_co[1], z = r_co[2];
        float scale = z * factor;
@@ -72,14 +95,10 @@ static void simpleDeform_taper(const float factor, const 
float dcut[3], float r_
        r_co[1] = y + y * scale;
        r_co[2] = z;
 
-       {
-               r_co[0] += dcut[0];
-               r_co[1] += dcut[1];
-               r_co[2] += dcut[2];
-       }
+       add_v3_v3(r_co, dcut);
 }
 
-static void simpleDeform_stretch(const float factor, const float dcut[3], 
float r_co[3])
+static void simpleDeform_stretch(const float factor, const int UNUSED(axis), 
const float dcut[3], float r_co[3])
 {
        float x = r_co[0], y = r_co[1], z = r_co[2];
        float scale;
@@ -90,14 +109,10 @@ static void simpleDeform_stretch(const float factor, const 
float dcut[3], float
        r_co[1] = y * scale;
        r_co[2] = z * (1.0f + factor);
 
-       {
-               r_co[0] += dcut[0];
-               r_co[1] += dcut[1];
-               r_co[2] += dcut[2];
-       }
+       add_v3_v3(r_co, dcut);
 }
 
-static void simpleDeform_twist(const float factor, const float *dcut, float 
r_co[3])
+static void simpleDeform_twist(const float factor, const int UNUSED(axis), 
const float *dcut, float r_co[3])
 {
        float x = r_co[0], y = r_co[1], z = r_co[2];
        float theta, sint, cost;
@@ -110,32 +125,58 @@ static void simpleDeform_twist(const float factor, const 
float *dcut, float r_co
        r_co[1] = x * sint + y * cost;
        r_co[2] = z;
 
-       {
-               r_co[0] += dcut[0];
-               r_co[1] += dcut[1];
-               r_co[2] += dcut[2];
-       }
+       add_v3_v3(r_co, dcut);
 }
 
-static void simpleDeform_bend(const float factor, const float dcut[3], float 
r_co[3])
+static void simpleDeform_bend(const float factor, const int axis, const float 
dcut[3], float r_co[3])
 {
        float x = r_co[0], y = r_co[1], z = r_co[2];
        float theta, sint, cost;
 
        BLI_assert(!(fabsf(factor) < BEND_EPS));
 
-       theta = x * factor;
+       switch (axis) {
+               case 0:
+                       ATTR_FALLTHROUGH;
+               case 1:
+                       theta = z * factor;
+                       break;
+               default:
+                       theta = x * factor;
+       }
        sint = sinf(theta);
        cost = cosf(theta);
 
-       r_co[0] = -(y - 1.0f / factor) * sint;
-       r_co[1] =  (y - 1.0f / factor) * cost + 1.0f / factor;
-       r_co[2] = z;
-
-       {
-               r_co[0] += cost * dcut[0];
-               r_co[1] += sint * dcut[0];
-               r_co[2] += dcut[2];
+       switch (axis) {
+               case 0:
+                       r_co[0] =  x;
+                       r_co[1] =  (y - 1.0f / factor) * cost + 1.0f / factor;
+                       r_co[2] = -(y - 1.0f / factor) * sint;
+                       {
+                               r_co[0] += dcut[0];
+                               r_co[1] += sint * dcut[2];
+                               r_co[2] += cost * dcut[2];
+                       }
+                       break;
+               case 1:
+                       r_co[0] =  (x - 1.0f / factor) * cost + 1.0f / factor;
+                       r_co[1] =  y;
+                       r_co[2] = -(x - 1.0f / factor) * sint;
+                       {
+                               r_co[0] += sint * dcut[2];
+                               r_co[1] += dcut[1];
+                               r_co[2] += cost * dcut[2];
+                       }
+                       break;
+               default:
+                       r_co[0] = -(y - 1.0f / factor) * sint;
+                       r_co[1] =  (y - 1.0f / factor) * cost + 1.0f / factor;
+                       r_co[2] = z;
+                       {
+                               r_co[0] += cost * dcut[0];
+                               r_co[1] += sint * dcut[0];
+                               r_co[2] += dcut[2];
+                       }
        }
 
 }
@@ -145,16 +186,36 @@ static void simpleDeform_bend(const float factor, const 
float dcut[3], float r_c
 static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct 
Object *ob, struct DerivedMesh *d

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to