Commit: c69458985cdb0cc1b388b81f61e5091c73461003
Author: Campbell Barton
Date:   Wed Feb 4 07:04:21 2015 +1100
Branches: master
https://developer.blender.org/rBc69458985cdb0cc1b388b81f61e5091c73461003

Hook Modifier: add falloff & radius options

- Add falloff types & curves (matching warp-modifier)
- Add uniform scale option,
  important when adding hooks to non-uniform scaled objects,
  especially for use with lattice objects which can't avoid uneven scaling.

  This uses relative transformation set when the hook is assigned,
  when measuring the distances.

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

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

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 4c96707..92e9e02 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -352,6 +352,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         layout.label(text="Settings are inside the Physics tab")
 
     def HOOK(self, layout, ob, md):
+        use_falloff = (md.falloff_type != 'NONE')
         split = layout.split()
 
         col = split.column()
@@ -366,19 +367,28 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
         layout.separator()
 
-        split = layout.split()
+        row = layout.row(align=True)
+        if use_falloff:
+            row.prop(md, "falloff_radius")
+        row.prop(md, "strength", slider=True)
+        layout.prop(md, "falloff_type")
 
-        col = split.column()
-        col.prop(md, "falloff")
-        col.prop(md, "force", slider=True)
+        col = layout.column()
+        if use_falloff:
+            if md.falloff_type == 'CURVE':
+                col.template_curve_mapping(md, "falloff_curve")
+
+        split = layout.split()
 
         col = split.column()
-        col.operator("object.hook_reset", text="Reset")
-        col.operator("object.hook_recenter", text="Recenter")
+        col.prop(md, "use_falloff_uniform")
 
         if ob.mode == 'EDIT':
-            layout.separator()
-            row = layout.row()
+            row = col.row(align=True)
+            row.operator("object.hook_reset", text="Reset")
+            row.operator("object.hook_recenter", text="Recenter")
+
+            row = layout.row(align=True)
             row.operator("object.hook_select", text="Select")
             row.operator("object.hook_assign", text="Assign")
 
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 9daa693..7bfe6f0 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4840,6 +4840,11 @@ static void direct_link_modifiers(FileData *fd, ListBase 
*lb)
                        if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
                                BLI_endian_switch_int32_array(hmd->indexar, 
hmd->totindex);
                        }
+
+                       hmd->curfalloff = newdataadr(fd, hmd->curfalloff);
+                       if (hmd->curfalloff) {
+                               direct_link_curvemapping(fd, hmd->curfalloff);
+                       }
                }
                else if (md->type == eModifierType_ParticleSystem) {
                        ParticleSystemModifierData *psmd = 
(ParticleSystemModifierData *)md;
diff --git a/source/blender/blenloader/intern/versioning_270.c 
b/source/blender/blenloader/intern/versioning_270.c
index 6f33cab..a6320ed 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -519,6 +519,20 @@ void blo_do_versions_270(FileData *fd, Library 
*UNUSED(lib), Main *main)
                }
        }
 
+       if (!DNA_struct_elem_find(fd->filesdna, "HookModifierData", "char", 
"flag")) {
+               Object *ob;
+
+               for (ob = main->object.first; ob; ob = ob->id.next) {
+                       ModifierData *md;
+                       for (md = ob->modifiers.first; md; md = md->next) {
+                               if (md->type == eModifierType_Hook) {
+                                       HookModifierData *hmd = 
(HookModifierData *)md;
+                                       hmd->falloff_type = 
eHook_Falloff_InvSquare;
+                               }
+                       }
+               }
+       }
+
        if (!MAIN_VERSION_ATLEAST(main, 273, 3)) {
                ParticleSettings *part;
                for (part = main->particle.first; part; part = part->id.next) {
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index 1de2b6b..3eeb30a 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1485,6 +1485,10 @@ static void write_modifiers(WriteData *wd, ListBase 
*modbase)
                if (md->type==eModifierType_Hook) {
                        HookModifierData *hmd = (HookModifierData*) md;
                        
+                       if (hmd->curfalloff) {
+                               write_curvemapping(wd, hmd->curfalloff);
+                       }
+
                        writedata(wd, DATA, sizeof(int)*hmd->totindex, 
hmd->indexar);
                }
                else if (md->type==eModifierType_Cloth) {
diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index 2d8c3b2..47273d3 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -535,16 +535,39 @@ typedef struct ArmatureModifierData {
        char defgrp_name[64];     /* MAX_VGROUP_NAME */
 } ArmatureModifierData;
 
+enum {
+       MOD_HOOK_UNIFORM_SPACE = (1 << 0),
+};
+
+/* same as WarpModifierFalloff */
+typedef enum {
+       eHook_Falloff_None   = 0,
+       eHook_Falloff_Curve  = 1,
+       eHook_Falloff_Sharp  = 2, /* PROP_SHARP */
+       eHook_Falloff_Smooth = 3, /* PROP_SMOOTH */
+       eHook_Falloff_Root   = 4, /* PROP_ROOT */
+       eHook_Falloff_Linear = 5, /* PROP_LIN */
+       eHook_Falloff_Const  = 6, /* PROP_CONST */
+       eHook_Falloff_Sphere = 7, /* PROP_SPHERE */
+       eHook_Falloff_InvSquare = 8, /* PROP_INVSQUARE */
+       /* PROP_RANDOM not used */
+} HookModifierFalloff;
+
 typedef struct HookModifierData {
        ModifierData modifier;
 
        struct Object *object;
        char subtarget[64];     /* optional name of bone target, MAX_ID_NAME-2 
*/
 
+       char flag;
+       char falloff_type;      /* use enums from WarpModifier (exact same 
functionality) */
+       char pad[6];
        float parentinv[4][4];  /* matrix making current transform unmodified */
        float cent[3];          /* visualization of hook */
        float falloff;          /* if not zero, falloff is distance where 
influence zero */
 
+       struct CurveMapping *curfalloff;
+
        int *indexar;           /* if NULL, it's using vertexgroup */
        int totindex;
        float force;
diff --git a/source/blender/makesrna/intern/rna_modifier.c 
b/source/blender/makesrna/intern/rna_modifier.c
index 12b6d74..3124add 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -134,6 +134,22 @@ EnumPropertyItem modifier_triangulate_ngon_method_items[] 
= {
        {0, NULL, 0, NULL, NULL}
 };
 
+#ifndef RNA_RUNTIME
+/* use eWarp_Falloff_*** & eHook_Falloff_***, they're in sync */
+static EnumPropertyItem modifier_warp_falloff_items[] = {
+       {eWarp_Falloff_None,    "NONE", 0, "No Falloff", ""},
+       {eWarp_Falloff_Curve,   "CURVE", 0, "Curve", ""},
+       {eWarp_Falloff_Smooth,  "SMOOTH", ICON_SMOOTHCURVE, "Smooth", ""},
+       {eWarp_Falloff_Sphere,  "SPHERE", ICON_SPHERECURVE, "Sphere", ""},
+       {eWarp_Falloff_Root,    "ROOT", ICON_ROOTCURVE, "Root", ""},
+       {eWarp_Falloff_InvSquare, "INVERSE_SQUARE", ICON_ROOTCURVE, "Inverse 
Square", ""},
+       {eWarp_Falloff_Sharp,   "SHARP", ICON_SHARPCURVE, "Sharp", ""},
+       {eWarp_Falloff_Linear,  "LINEAR", ICON_LINCURVE, "Linear", ""},
+       {eWarp_Falloff_Const,   "CONSTANT", ICON_NOCURVE, "Constant", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+#endif
+
 /* ***** Data Transfer ***** */
 
 EnumPropertyItem DT_method_vertex_items[] = {
@@ -1111,19 +1127,6 @@ static void rna_def_modifier_warp(BlenderRNA *brna)
        StructRNA *srna;
        PropertyRNA *prop;
 
-       static EnumPropertyItem prop_falloff_items[] = {
-               {eWarp_Falloff_None,    "NONE", 0, "No Falloff", ""},
-               {eWarp_Falloff_Curve,   "CURVE", 0, "Curve", ""},
-               {eWarp_Falloff_Smooth,  "SMOOTH", ICON_SMOOTHCURVE, "Smooth", 
""},
-               {eWarp_Falloff_Sphere,  "SPHERE", ICON_SPHERECURVE, "Sphere", 
""},
-               {eWarp_Falloff_Root,    "ROOT", ICON_ROOTCURVE, "Root", ""},
-               {eWarp_Falloff_InvSquare, "INVERSE_SQUARE", ICON_ROOTCURVE, 
"Inverse Square", ""},
-               {eWarp_Falloff_Sharp,   "SHARP", ICON_SHARPCURVE, "Sharp", ""},
-               {eWarp_Falloff_Linear,  "LINEAR", ICON_LINCURVE, "Linear", ""},
-               {eWarp_Falloff_Const,   "CONSTANT", ICON_NOCURVE, "Constant", 
""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
        srna = RNA_def_struct(brna, "WarpModifier", "Modifier");
        RNA_def_struct_ui_text(srna, "Warp Modifier", "Warp modifier");
        RNA_def_struct_sdna(srna, "WarpModifierData");
@@ -1146,7 +1149,7 @@ static void rna_def_modifier_warp(BlenderRNA *brna)
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
        prop = RNA_def_property(srna, "falloff_type", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_items(prop, prop_falloff_items);
+       RNA_def_property_enum_items(prop, modifier_warp_falloff_items);
        RNA_def_property_ui_text(prop, "Falloff Type", "");
        RNA_def_property_translation_context(prop, BLF_I18NCONTEXT_ID_CURVE); 
/* Abusing id_curve :/ */
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
@@ -1678,15 +1681,28 @@ static void rna_def_modifier_hook(BlenderRNA *brna)
        RNA_def_struct_sdna(srna, "HookModifierData");
        RNA_def_struct_ui_icon(srna, ICON_HOOK);
 
-       prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_DISTANCE);
+       prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "force");
+       RNA_def_property_range(prop, 0, 1);
+       RNA_def_property_ui_text(prop, "Strength",  "Relative force of the 
hook");
+       RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+       prop = RNA_def_property(srna, "falloff_type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, modifier_warp_falloff_items);  /* 
share the enum */
+       RNA_def_property_ui_text(prop, "Falloff Type", "");
+       RNA_def_property_translation_context(prop, BLF_I18NCONTEXT_ID_CURVE); 
/* Abusing id_curve :/ */
+       RNA_def_property_update(prop, 0, "rna_Modifier_update");
+
+       prop = RNA_def_property(srna, "falloff_radius", PROP_FLOAT, 
PROP_DISTANCE);
+       RNA_def_property_float_sdna(prop, NULL, "falloff");
        RNA_def_property_range(prop, 0, FLT_MAX);
        RNA_def_property_ui_range(prop, 0, 100, 100, 2);
-       RNA_def_property_ui_text(prop, "Falloff",  "If not zero, the distance 
from the hook where influence ends");
+       RNA_def_property_ui_text(prop, "Radius",  "If not zero, the distance 
from the hook where influence ends");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
-       prop = RNA_def_property(srna, "force", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_range(prop, 0, 1);
-       RNA_def_property_ui_text(prop, "Force",  "Relative force of the hook");
+       prop = RNA_def_property(srna, "falloff_curve", PROP_POINTER, PROP_NONE);
+       RNA_def_property_pointer_sdna(prop, NULL, "curfalloff");
+       RNA_def_property_ui_text(prop, "Falloff Curve", "Custom Lamp Falloff 
Curve");
        RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
        

@@ 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