* Rest length parameter for harmonic force springs. Implementation is a slightly...
authorJanne Karhu <jhkarh@gmail.com>
Mon, 21 Dec 2009 11:19:07 +0000 (11:19 +0000)
committerJanne Karhu <jhkarh@gmail.com>
Mon, 21 Dec 2009 11:19:07 +0000 (11:19 +0000)
* Also added a "multiple springs" option to use every effector point as a harmonic spring instead of just one.

release/scripts/ui/properties_physics_common.py
source/blender/blenkernel/intern/effect.c
source/blender/makesdna/DNA_object_force.h
source/blender/makesrna/intern/rna_object_force.c

index 26411b227a8c12d254b804b94d78d3965ce0605b..24c822f9ca9d4fa5c0f4458044a2969760bb9701 100644 (file)
@@ -150,6 +150,7 @@ def basic_force_field_settings_ui(self, context, field):
         col.prop(field, "flow")
     elif field.type == 'HARMONIC':
         col.prop(field, "harmonic_damping", text="Damping")
+        col.prop(field, "rest_length")
     elif field.type == 'VORTEX' and field.shape != 'POINT':
         col.prop(field, "inflow")
     elif field.type == 'DRAG':
@@ -163,6 +164,8 @@ def basic_force_field_settings_ui(self, context, field):
     col.prop(field, "seed")
     if field.type == 'TURBULENCE':
         col.prop(field, "global_coordinates", text="Global")
+    elif field.type == 'HARMONIC':
+        col.prop(field, "multiple_springs")
 
     split = layout.split()
 
index 6d63553396d90b91a920c0b25d9cc96fc8b24d79..83f63c9ffb2c2ea883d847b597b624aa914bd863 100644 (file)
@@ -128,7 +128,6 @@ PartDeflect *object_add_collision_fields(int type)
        pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer()))+1) % 128;
        pd->f_strength = 1.0f;
        pd->f_damp = 1.0f;
-       pd->f_size = 1.0f;
 
        /* set sensible defaults based on type */
        switch(type) {
@@ -139,6 +138,9 @@ PartDeflect *object_add_collision_fields(int type)
                        pd->shape = PFIELD_SHAPE_PLANE;
                        pd->f_flow = 1.0f; /* realistic wind behavior */
                        break;
+               case PFIELD_TEXTURE:
+                       pd->f_size = 1.0f;
+                       break;
        }
        pd->flag = PFIELD_DO_LOCATION|PFIELD_DO_ROTATION;
 
@@ -693,6 +695,10 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
                sub_v3_v3v3(efd->vec_to_point, point->loc, efd->loc);
                efd->distance = len_v3(efd->vec_to_point);
 
+               /* rest length for harmonic effector, will have to see later if this could be extended to other effectors */
+               if(eff->pd->forcefield == PFIELD_HARMONIC && eff->pd->f_size)
+                       mul_v3_fl(efd->vec_to_point, (efd->distance-eff->pd->f_size)/efd->distance);
+
                if(eff->flag & PE_USE_NORMAL_DATA) {
                        VECCOPY(efd->vec_to_point2, efd->vec_to_point);
                        VECCOPY(efd->nor2, efd->nor);
@@ -735,7 +741,7 @@ static void get_effector_tot(EffectorCache *eff, EffectorData *efd, EffectedPoin
                        */
                        efd->charge = eff->pd->f_strength;
                }
-               else if(eff->pd->forcefield == PFIELD_HARMONIC) {
+               else if(eff->pd->forcefield == PFIELD_HARMONIC && (eff->pd->flag & PFIELD_MULTIPLE_SPRINGS)==0) {
                        /* every particle is mapped to only one harmonic effector particle */
                        *p= point->index % eff->psys->totpart;
                        *tot= *p + 1;
index adccf8893d4aa4097cfba6c2184b590e6d5d699b..99b8f400a5ec178298950e3fe2d428718505f162 100644 (file)
@@ -71,7 +71,7 @@ typedef struct PartDeflect {
        float f_flow;           /* How much force is converted into "air flow", i.e.    */
                                                /* force used as the velocity of surrounding medium.    */
 
-       float f_size;
+       float f_size;           /* Noise size for noise effector, restlength for harmonic effector */
 
        /* fall-off */
        float f_power;          /* The power law - real gravitation is 2 (square)       */
@@ -320,6 +320,7 @@ typedef struct SoftBody {
 #define PFIELD_TEX_OBJECT              64
 #define PFIELD_GLOBAL_CO               64                      /* used for turbulence */
 #define PFIELD_TEX_2D                  128
+#define PFIELD_MULTIPLE_SPRINGS        128                     /* used for harmonic force */
 #define PFIELD_USEMIN                  256
 #define PFIELD_USEMAXR                 512
 #define PFIELD_USEMINR                 1024
index 9a57a24e1a7d481012ccd25d9bb684033da8e27a..67c7a9aa078cff5310b72ffb78cee50be5894fd2 100644 (file)
@@ -1109,6 +1109,12 @@ static void rna_def_field(BlenderRNA *brna)
        RNA_def_property_range(prop, 0.0f, 10.0f);
        RNA_def_property_ui_text(prop, "Size", "Size of the noise");
        RNA_def_property_update(prop, 0, "rna_FieldSettings_update");
+
+       prop= RNA_def_property(srna, "rest_length", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "f_size");
+       RNA_def_property_range(prop, 0.0f, 1000.0f);
+       RNA_def_property_ui_text(prop, "Rest Length", "Rest length of the harmonic force");
+       RNA_def_property_update(prop, 0, "rna_FieldSettings_update");
        
        prop= RNA_def_property(srna, "falloff_power", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "f_power");
@@ -1221,6 +1227,11 @@ static void rna_def_field(BlenderRNA *brna)
        RNA_def_property_boolean_sdna(prop, NULL, "flag", PFIELD_VISIBILITY);
        RNA_def_property_ui_text(prop, "Absorption", "Force gets absorbed by collision objects");
        RNA_def_property_update(prop, 0, "rna_FieldSettings_update");
+
+       prop= RNA_def_property(srna, "multiple_springs", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", PFIELD_MULTIPLE_SPRINGS);
+       RNA_def_property_ui_text(prop, "Multiple Springs", "Every point is effected by multiple springs");
+       RNA_def_property_update(prop, 0, "rna_FieldSettings_update");
        
        /* Pointer */