Patch/Bugfix so wind noise got controlable seed and therefore redoable cloth sims...
authorDaniel Genrich <daniel.genrich@gmx.net>
Sat, 6 Jun 2009 21:49:00 +0000 (21:49 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Sat, 6 Jun 2009 21:49:00 +0000 (21:49 +0000)
source/blender/blenkernel/BKE_blender.h
source/blender/blenkernel/intern/effect.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_object_force.h
source/blender/python/api2_2x/Object.c
source/blender/src/buttons_object.c

index cc2f9bd8334179b9f561adac32216d62590493e6..5513f98b2990d615a1527d0a439de2c81adb6433 100644 (file)
@@ -41,7 +41,7 @@ struct ListBase;
 struct MemFile;
 
 #define BLENDER_VERSION                        249
 struct MemFile;
 
 #define BLENDER_VERSION                        249
-#define BLENDER_SUBVERSION             0
+#define BLENDER_SUBVERSION             1
 
 #define BLENDER_MINVERSION             245
 #define BLENDER_MINSUBVERSION  15
 
 #define BLENDER_MINVERSION             245
 #define BLENDER_MINSUBVERSION  15
index cca5d68167e74084b2fe0aed94a02a938cb2a822..5bc3e2952722554b1236e3b04b0787b3a84905ea 100644 (file)
@@ -80,7 +80,6 @@
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
 
 #include "BKE_screen.h"
 #include "BKE_utildefines.h"
 
-#include "PIL_time.h"
 #include "RE_render_ext.h"
 
 /* fluid sim particle import */
 #include "RE_render_ext.h"
 
 /* fluid sim particle import */
@@ -161,8 +160,7 @@ static void add_to_effectorcache(ListBase *lb, Object *ob, Object *obsrc)
                
                if(pd->forcefield == PFIELD_WIND)
                {
                
                if(pd->forcefield == PFIELD_WIND)
                {
-                       pd->rng = rng_new(1);
-                       rng_srandom(pd->rng, (unsigned int)(ceil(PIL_check_seconds_timer()))); // use better seed
+                       pd->rng = rng_new(pd->seed);
                }
        
                ec= MEM_callocN(sizeof(pEffectorCache), "effector cache");
                }
        
                ec= MEM_callocN(sizeof(pEffectorCache), "effector cache");
@@ -286,14 +284,14 @@ static float eff_calc_visibility(Object *ob, float *co, float *dir)
 // noise function for wind e.g.
 static float wind_func(struct RNG *rng, float strength)
 {
 // noise function for wind e.g.
 static float wind_func(struct RNG *rng, float strength)
 {
-       int random = (rng_getInt(rng)+1) % 65535; // max 2357
+       int random = (rng_getInt(rng)+1) % 128; // max 2357
        float force = rng_getFloat(rng) + 1.0f;
        float ret;
        float sign = 0;
        
        float force = rng_getFloat(rng) + 1.0f;
        float ret;
        float sign = 0;
        
-       sign = (random > 32000.0) ? 1.0: -1.0; // dividing by 2 is not giving equal sign distribution
+       sign = ((float)random > 64.0) ? 1.0: -1.0; // dividing by 2 is not giving equal sign distribution
        
        
-       ret = sign*((float)random / force)*strength/65535.0f;
+       ret = sign*((float)random / force)*strength/128.0f;
        
        return ret;
 }
        
        return ret;
 }
index f0ec75dedd9d9883e9405ef25c3b182dc7888f5b..38b8bfaaa882c0b78dd8e16eeb21598feb47dd7e 100644 (file)
 #include "mydevice.h"
 #include "blendef.h"
 
 #include "mydevice.h"
 #include "blendef.h"
 
+#include "PIL_time.h"
+
 #include <errno.h>
 
 /*
 #include <errno.h>
 
 /*
@@ -8144,6 +8146,16 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                
        }
        
                
        }
        
+       // correct introduce of seed for wind force
+       if (main->versionfile < 249 && main->subversionfile < 1) {
+               Object *ob;
+               for(ob = main->object.first; ob; ob= ob->id.next) {
+                       if(ob->pd)
+                               ob->pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer()))+1) % 128;
+               }
+       
+       }
+       
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in src/usiblender.c! */
index dc449a64c6d5e3d63d392c81b2e3cf5e03d897c4..718d1a1783466a92c6f0f263d16548fdd9de2fbf 100644 (file)
@@ -69,7 +69,7 @@ typedef struct PartDeflect {
        struct Tex *tex;        /* Texture of the texture effector */
        struct RNG *rng; /* random noise generator for e.g. wind */
        float f_noise; /* noise of force (currently used for wind) */
        struct Tex *tex;        /* Texture of the texture effector */
        struct RNG *rng; /* random noise generator for e.g. wind */
        float f_noise; /* noise of force (currently used for wind) */
-       int pad;
+       int seed; /* wind noise random seed */
 } PartDeflect;
 
 typedef struct PointCache {
 } PartDeflect;
 
 typedef struct PointCache {
index c3f7a21a7bf8228ce2c53c5513db4da342a068f0..b50b0082bf4a3d3fd6782ea13081160cb9a2ca28 100644 (file)
@@ -3757,7 +3757,8 @@ static int setupPI( Object* ob )
        ob->pd->pdef_perm    =0;        
        ob->pd->f_strength   =0;        
        ob->pd->f_power      =0;        
        ob->pd->pdef_perm    =0;        
        ob->pd->f_strength   =0;        
        ob->pd->f_power      =0;        
-       ob->pd->maxdist      =0;               
+       ob->pd->maxdist      =0;
+       ob->pd->seed             =0;
        return 1;
 }
 
        return 1;
 }
 
index a90dd0447e900b579cb2997d04aff76ac2857f9c..8bf628368881c40b76a49c79d8ebfa36578507dc 100644 (file)
 
 #include "butspace.h" // own module
 
 
 #include "butspace.h" // own module
 
+#include "PIL_time.h"
+
 static float prspeed=0.0;
 float prlen=0.0;
 
 static float prspeed=0.0;
 float prlen=0.0;
 
@@ -3337,6 +3339,7 @@ static void object_panel_collision(Object *ob)
                ob->pd->pdef_sbdamp = 0.1f;
                ob->pd->pdef_sbift  = 0.2f;
                ob->pd->pdef_sboft  = 0.02f;
                ob->pd->pdef_sbdamp = 0.1f;
                ob->pd->pdef_sbift  = 0.2f;
                ob->pd->pdef_sboft  = 0.02f;
+               ob->pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer()))+1) % 128;
        }
        
        /* only meshes collide now */
        }
        
        /* only meshes collide now */
@@ -3431,6 +3434,7 @@ static void object_panel_fields(Object *ob)
                ob->pd->pdef_sbift  = 0.2f;
                ob->pd->pdef_sboft  = 0.02f;
                ob->pd->tex_nabla = 0.025f;
                ob->pd->pdef_sbift  = 0.2f;
                ob->pd->pdef_sboft  = 0.02f;
                ob->pd->tex_nabla = 0.025f;
+               ob->pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer()))+1) % 128;
        }
        
        if(ob->pd) {
        }
        
        if(ob->pd) {
@@ -3530,7 +3534,10 @@ static void object_panel_fields(Object *ob)
                                else if(pd->forcefield == PFIELD_HARMONIC) 
                                        uiDefButF(block, NUM, B_FIELD_CHANGE, "Damp: ", 10,120,140,20, &pd->f_damp, 0, 10, 10, 0, "Damping of the harmonic force");     
                                else if(pd->forcefield == PFIELD_WIND) 
                                else if(pd->forcefield == PFIELD_HARMONIC) 
                                        uiDefButF(block, NUM, B_FIELD_CHANGE, "Damp: ", 10,120,140,20, &pd->f_damp, 0, 10, 10, 0, "Damping of the harmonic force");     
                                else if(pd->forcefield == PFIELD_WIND) 
-                                       uiDefButF(block, NUM, B_FIELD_CHANGE, "Noise: ",10,120,140,20, &pd->f_noise, 0, 10, 100, 0, "Noise of the wind force"); 
+                               {
+                                       uiDefButF(block, NUM, B_FIELD_CHANGE, "Noise: ",10,120,140,20, &pd->f_noise, 0, 10, 100, 0, "Noise of the wind force");
+                                       uiDefButI(block, NUM, B_FIELD_CHANGE, "Seed: ",10,100,140,20, &pd->seed, 1, 128, 1, 0, "Seed of the wind noise");
+                               }
                        }
                        uiBlockEndAlign(block);
                        
                        }
                        uiBlockEndAlign(block);
                        
@@ -3839,6 +3846,7 @@ static void object_softbodies_collision(Object *ob)
                ob->pd->pdef_sbdamp = 0.1f;
                ob->pd->pdef_sbift  = 0.2f;
                ob->pd->pdef_sboft  = 0.02f;
                ob->pd->pdef_sbdamp = 0.1f;
                ob->pd->pdef_sbift  = 0.2f;
                ob->pd->pdef_sboft  = 0.02f;
+               ob->pd->seed = ((unsigned int)(ceil(PIL_check_seconds_timer()))+1) % 128;
        }
        block= uiNewBlock(&curarea->uiblocks, "object_softbodies_collision", UI_EMBOSS, UI_HELV, curarea->win);
        uiNewPanelTabbed("Soft Body", "Physics"); 
        }
        block= uiNewBlock(&curarea->uiblocks, "object_softbodies_collision", UI_EMBOSS, UI_HELV, curarea->win);
        uiNewPanelTabbed("Soft Body", "Physics");