Revision: 21195
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21195
Author:   jhk
Date:     2009-06-27 17:28:58 +0200 (Sat, 27 Jun 2009)

Log Message:
-----------
Pointcache refresh part 2

* Based on what happens during simulation the cache is marked (also in cache 
panel, this could possibly be extended to 3d view as well) as:
        - exact (not marked)
        - outdated (simulation is not done completely with current settings)
        - non-exact (frames were skipped during simulation)

* The parameter "cache step" effects the number of frames between saved cache 
frames.
        - This can save a lot of memory (or disk space) if absolutely frame 
accurate simulation is not required.
        - Speeds up the "quick caching" very much.
        - Frames between cached frames are interpolated from the cached frames.
        - Current default value of 10 frames works nicely with up/down-arrows 
(skip 10 frames forwards/backwards on timeline), but can be changed if wanted.

* The caching can work in normal or "quick" mode:
        [Normal cache]
        - Basic: Calculate what even happens (settings change, big frame steps 
etc.) and cache results, if possible try to use "cache step" when saving cache 
frames.
        - Becomes non-exact: After larger than 1 frame steps.
        - Becomes outdated: After any change effecting the simulation other 
than frame steps.
        - Pros/cons: Freedom of doing anything and playing with particles, but 
exact results have to calculated from the beginning.

        [Quick cache]
        - Basic: Calculate simulation up to current frame automatically on 
changes with cache step sized jumps in simulation. With multiple "quick cached" 
simulations the smallest cache step is used.
        - Becomes non-exact: Always from frame 1 (unless cache step = 1).
        - Becomes outdated: Never.
        - Pros/cons: Not very accurate, but super fast!
        - Todo: Transform of any animated (non-autokeyed) object is locked! 
Probably needs some tinkering with anim sys overrides.

* The simulation can be run forwards or backwards even if it's cache is 
outdated or non-exact, the following rules apply in these situations:
        - step forwards (to unknown) -> simulate from last exact frame, store 
result
        - step backwards (to known) -> result is interpolated from existing 
frames, store result, clear cache forwards if current frame is after last exact 
frame

* "Calculate to current frame" runs the simulation from start to current frame 
with a frame steps of 1.
        - Baking does the same, but runs the simulation all the way to the end 
of simulation.
        - Rendering does this automatically if the simulation is outdated of 
non-exact, so all rendered simulations will always be updated and exact.
        
* Every cache panel also holds buttons to "Bake all dynamics", "Free all 
dynamics" and "Update all dynamics to current frame".

* Cloth simulation supports the new cache too.

Modified Paths:
--------------
    branches/blender2.5/blender/release/ui/buttons_particle.py
    branches/blender2.5/blender/release/ui/buttons_physic_cloth.py
    branches/blender2.5/blender/source/blender/blenkernel/BKE_cloth.h
    branches/blender2.5/blender/source/blender/blenkernel/BKE_particle.h
    branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/cloth.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/implicit.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/particle.c
    
branches/blender2.5/blender/source/blender/blenkernel/intern/particle_system.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/pointcache.c
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c
    branches/blender2.5/blender/source/blender/editors/physics/ed_pointcache.c
    
branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_object_force.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_cloth.c
    
branches/blender2.5/blender/source/blender/makesrna/intern/rna_object_force.c
    branches/blender2.5/blender/source/blender/render/intern/source/pipeline.c
    
branches/blender2.5/blender/source/blender/windowmanager/intern/wm_event_system.c

Modified: branches/blender2.5/blender/release/ui/buttons_particle.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_particle.py  2009-06-27 
15:21:37 UTC (rev 21194)
+++ branches/blender2.5/blender/release/ui/buttons_particle.py  2009-06-27 
15:28:58 UTC (rev 21195)
@@ -130,11 +130,7 @@
                cache = psys.point_cache
                
                row = layout.row()
-               row.itemR(cache, "name", text="")
-               if cache.outdated:
-                       row.itemL(text="Cache is outdated.")
-               else:
-                       row.itemL(text="")
+               row.itemR(cache, "name")
                
                row = layout.row()
                
@@ -142,19 +138,30 @@
                        row.itemO("PTCACHE_OT_free_bake_particle_system", 
text="Free Bake")
                else:
                        row.item_booleanO("PTCACHE_OT_cache_particle_system", 
"bake", True, text="Bake")
-                       
+               
+               subrow = row.row()
+               subrow.enabled = (cache.frames_skipped or cache.outdated) and 
particle_panel_enabled(psys)
+               subrow.itemO("PTCACHE_OT_cache_particle_system", 
text="Calculate to Current Frame")
+               
                row = layout.row()
                row.enabled = particle_panel_enabled(psys)
                row.itemO("PTCACHE_OT_bake_from_particles_cache", text="Current 
Cache to Bake")
-               if cache.autocache == 0:
-                       row.itemO("PTCACHE_OT_cache_particle_system", 
text="Cache to Current Frame")
+               row.itemR(cache, "step");
        
                row = layout.row()
                row.enabled = particle_panel_enabled(psys)
-               #row.itemR(cache, "autocache")
+               row.itemR(cache, "quick_cache")
                row.itemR(cache, "disk_cache")
-               row.itemL(text=cache.info)
                
+               layout.itemL(text=cache.info)
+               
+               layout.itemS()
+               
+               row = layout.row()
+               row.item_booleanO("PTCACHE_OT_bake_all", "bake", True, 
text="Bake All Dynamics")
+               row.itemO("PTCACHE_OT_free_bake_all", text="Free All Bakes")
+               layout.itemO("PTCACHE_OT_bake_all", text="Update All Dynamics 
to current frame")
+               
                # for particles these are figured out automatically
                #row.itemR(cache, "start_frame")
                #row.itemR(cache, "end_frame")

Modified: branches/blender2.5/blender/release/ui/buttons_physic_cloth.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_physic_cloth.py      
2009-06-27 15:21:37 UTC (rev 21194)
+++ branches/blender2.5/blender/release/ui/buttons_physic_cloth.py      
2009-06-27 15:28:58 UTC (rev 21195)
@@ -43,7 +43,54 @@
                        col.itemR(cloth, "goal_spring", text="Stiffness")
                        col.itemR(cloth, "goal_friction", text="Friction")
                """
+
+class PHYSICS_PT_cloth_cache(PhysicButtonsPanel):
+       __idname__= "PHYSICS_PT_cloth_cache"
+       __label__ = "Cache"
+       __default_closed__ = True
+
+       def draw(self, context):
+               layout = self.layout
+
+               cache = context.cloth.point_cache
+               
+               row = layout.row()
+               row.itemR(cache, "name")
+               
+               row = layout.row()
+               row.itemR(cache, "start_frame")
+               row.itemR(cache, "end_frame")
+               
+               row = layout.row()
+               
+               if cache.baked == True:
+                       row.itemO("PTCACHE_OT_free_bake_cloth", text="Free 
Bake")
+               else:
+                       row.item_booleanO("PTCACHE_OT_cache_cloth", "bake", 
True, text="Bake")
+               
+               subrow = row.row()
+               subrow.enabled = cache.frames_skipped or cache.outdated
+               subrow.itemO("PTCACHE_OT_cache_cloth", text="Calculate to 
Current Frame")
+                       
+               row = layout.row()
+               #row.enabled = particle_panel_enabled(psys)
+               row.itemO("PTCACHE_OT_bake_from_cloth_cache", text="Current 
Cache to Bake")
+               row.itemR(cache, "step");
        
+               row = layout.row()
+               #row.enabled = particle_panel_enabled(psys)
+               row.itemR(cache, "quick_cache")
+               row.itemR(cache, "disk_cache")
+               
+               layout.itemL(text=cache.info)
+               
+               layout.itemS()
+               
+               row = layout.row()
+               row.itemO("PTCACHE_OT_bake_all", "bake", True, text="Bake All 
Dynamics")
+               row.itemO("PTCACHE_OT_free_bake_all", text="Free All Bakes")
+               layout.itemO("PTCACHE_OT_bake_all", text="Update All Dynamics 
to current frame")
+               
 class Physic_PT_cloth_collision(PhysicButtonsPanel):
        __idname__ = "Physic_PT_clothcollision"
        __label__ = "Cloth Collision"
@@ -102,5 +149,6 @@
                sub.itemR(cloth, "bending_stiffness_max", text="Max")
                
 bpy.types.register(Physic_PT_cloth)
+bpy.types.register(PHYSICS_PT_cloth_cache)
 bpy.types.register(Physic_PT_cloth_collision)
 bpy.types.register(Physic_PT_cloth_stiffness)

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_cloth.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_cloth.h   
2009-06-27 15:21:37 UTC (rev 21194)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_cloth.h   
2009-06-27 15:28:58 UTC (rev 21195)
@@ -46,6 +46,7 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
+#include "DNA_scene_types.h"
 
 #include "BKE_collision.h"
 
@@ -245,8 +246,8 @@
 void bvhselftree_update_from_cloth ( ClothModifierData *clmd, int moving );
 
 // needed for editmesh.c
-void cloth_write_cache ( Object *ob, ClothModifierData *clmd, float framenr );
-int cloth_read_cache ( Object *ob, ClothModifierData *clmd, float framenr );
+void cloth_write_cache( Object *ob, ClothModifierData *clmd, int framenr );
+int cloth_read_cache( Scene *scene, Object *ob, ClothModifierData *clmd, float 
framenr, int *old_framenr );
 
 // needed for button_object.c
 void cloth_clear_cache ( Object *ob, ClothModifierData *clmd, float framenr );

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_particle.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_particle.h        
2009-06-27 15:21:37 UTC (rev 21194)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_particle.h        
2009-06-27 15:28:58 UTC (rev 21195)
@@ -252,7 +252,6 @@
 
 struct ParticleSettings *psys_new_settings(char *name, struct Main *main);
 struct ParticleSettings *psys_copy_settings(struct ParticleSettings *part);
-int psys_count_autocache(struct Scene *scene, struct ParticleSettings *part);
 void psys_flush_particle_settings(struct Scene *scene, struct ParticleSettings 
*part, int recalc);
 void make_local_particlesettings(struct ParticleSettings *part);
 

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h      
2009-06-27 15:21:37 UTC (rev 21194)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h      
2009-06-27 15:28:58 UTC (rev 21195)
@@ -93,7 +93,7 @@
        int cfra;
        int totelem;
 
-       float *(*elem_ptr)(int index, void *calldata);
+       void (*set_elem)(int index, void *calldata, float *data);
        void *calldata;
 } PTCacheWriter;
 
@@ -103,12 +103,10 @@
        float cfra;
        int totelem;
 
-       void (*set_elem)(int index, void *calldata, float *data);
-       void (*interpolate_elem)(int index, void *calldata, float frs_sec, 
float cfra, int cfra1, int cfra2, float *data1, float *data2);
+       void (*set_elem)(int elem_index, void *calldata, float *data);
+       void (*interpolate_elem)(int index, void *calldata, float frs_sec, 
float cfra, float cfra1, float cfra2, float *data1, float *data2);
        void *calldata;
 
-       int allow_interpolate;
-       int allow_old;
        int *old_frame;
 } PTCacheReader;
 
@@ -116,6 +114,7 @@
        struct Scene *scene;
        int bake;
        int render;
+       int quick_step;
        struct PTCacheID *pid;
        int (*break_test)(void *data);
        void *break_data;
@@ -146,6 +145,8 @@
 int          BKE_ptcache_file_read_floats(PTCacheFile *pf, float *f, int tot);
 int          BKE_ptcache_file_write_floats(PTCacheFile *pf, float *f, int tot);
 
+void BKE_ptcache_update_info(PTCacheID *pid);
+
 /* General cache reading/writing */
 int                     BKE_ptcache_read_cache(PTCacheReader *reader);
 int                     BKE_ptcache_write_cache(PTCacheWriter *writer);
@@ -160,7 +161,7 @@
 struct PointCache *BKE_ptcache_copy(struct PointCache *cache);
 
 /* Baking */
-void BKE_ptcache_autocache_all(struct Scene *scene);
+void BKE_ptcache_quick_cache_all(struct Scene *scene);
 void BKE_ptcache_make_cache(struct PTCacheBaker* baker);
 void BKE_ptcache_toggle_disk_cache(struct PTCacheID *pid);
 

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/cloth.c        
2009-06-27 15:21:37 UTC (rev 21194)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/cloth.c        
2009-06-27 15:28:58 UTC (rev 21195)
@@ -33,6 +33,7 @@
 #include "DNA_mesh_types.h"
 #include "DNA_object_force.h"
 #include "DNA_scene_types.h"
+#include "DNA_particle_types.h"
 
 #include "BKE_deform.h"
 #include "BKE_DerivedMesh.h"
@@ -42,6 +43,7 @@
 #include "BKE_object.h"
 #include "BKE_modifier.h"
 #include "BKE_utildefines.h"
+#include "BKE_particle.h"
 
 #include "BKE_pointcache.h"
 
@@ -339,78 +341,99 @@
 }
 
 int modifiers_indexInObject(Object *ob, ModifierData *md_seek);
+static void cloth_write_state(int index, Cloth *cloth, float *data)
+{
+       ClothVertex *vert = cloth->verts + index;
 
-int cloth_read_cache(Object *ob, ClothModifierData *clmd, float framenr)
+       memcpy(data, vert->x, 3 * sizeof(float));
+       memcpy(data + 3, vert->xconst, 3 * sizeof(float));
+       memcpy(data + 6, vert->v, 3 * sizeof(float));
+}
+static void cloth_read_state(int index, Cloth *cloth, float *data)
 {
-       PTCacheID pid;
-       PTCacheFile *pf;
-       Cloth *cloth = clmd->clothObject;
-       unsigned int a, ret = 1;
+       ClothVertex *vert = cloth->verts + index;
        
-       if(!cloth)
-               return 0;
-       
-       BKE_ptcache_id_from_cloth(&pid, ob, clmd);
-       pf = BKE_ptcache_file_open(&pid, PTCACHE_FILE_READ, framenr);
-       if(pf) {
-               for(a = 0; a < cloth->numverts; a++) {
-                       if(!BKE_ptcache_file_read_floats(pf, cloth->verts[a].x, 
3)) {
-                               ret = 0;
-                               break;
-                       }
-                       if(!BKE_ptcache_file_read_floats(pf, 
cloth->verts[a].xconst, 3)) {
-                               ret = 0;
-                               break;
-                       }
-                       if(!BKE_ptcache_file_read_floats(pf, cloth->verts[a].v, 
3)) {
-                               ret = 0;
-                               break;
-                       }
-               }
-               
-               BKE_ptcache_file_close(pf);
+       memcpy(vert->x, data, 3 * sizeof(float));
+       memcpy(vert->xconst, data + 3, 3 * sizeof(float));
+       memcpy(vert->v, data + 6, 3 * sizeof(float));
+}
+static void cloth_cache_interpolate(int index, Cloth *cloth, float frs_sec, 
float cfra, float cfra1, float cfra2, float *data1, float *data2)
+{
+       ClothVertex *vert = cloth->verts + index;
+       ParticleKey keys[4];
+       float dfra;
+
+       if(cfra1 == cfra2) {
+               cloth_read_state(index, cloth, data1);
+               return;
        }
-       else
-               ret = 0;
-       
-       return ret;
+
+       memcpy(keys[1].co, data1, 3 * sizeof(float));

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