Commit: 1309ca51fac2195d9a4c147d9da4e6c60fd769e1
Author: Lukas Tönne
Date:   Tue Feb 17 12:26:45 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB1309ca51fac2195d9a4c147d9da4e6c60fd769e1

Alembic caching support for particle paths.

This hooks into the particle path update functions and reads cache data
if available instead of constructing expensive child paths every time.

Currently the cache grows quite rapidly due to lack of optimized sample
storage: constant values such as numer of segments, times, colors etc
only need to be stored in the first sample. "Velocities" (actually
position deltas) could also be calculated on-the-fly, which is
relatively cheap compared to full child calculation. In any case, disk
space it cheap ...

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

M       release/scripts/startup/bl_ui/properties_particle.py
M       source/blender/blenkernel/intern/particle.c
M       source/blender/makesdna/DNA_particle_types.h
M       source/blender/makesrna/intern/rna_particle.c
M       source/blender/pointcache/PTC_api.cpp
M       source/blender/pointcache/PTC_api.h
M       source/blender/pointcache/alembic/abc_cloth.cpp
M       source/blender/pointcache/alembic/abc_cloth.h
M       source/blender/pointcache/alembic/abc_mesh.cpp
M       source/blender/pointcache/alembic/abc_particles.cpp
M       source/blender/pointcache/alembic/abc_particles.h
M       source/blender/pointcache/alembic/abc_smoke.cpp
M       source/blender/pointcache/alembic/abc_softbody.cpp
M       source/blender/pointcache/alembic/abc_writer.cpp
M       source/blender/pointcache/alembic/abc_writer.h
M       source/blender/pointcache/intern/alembic.h
M       source/blender/pointcache/intern/writer.cpp
M       source/blender/pointcache/intern/writer.h

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

diff --git a/release/scripts/startup/bl_ui/properties_particle.py 
b/release/scripts/startup/bl_ui/properties_particle.py
index 971621c..cd1ab55 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -415,15 +415,19 @@ class PARTICLE_PT_cache(ParticleButtonsPanel, Panel):
         if psys.settings.is_fluid:
             return False
         phystype = psys.settings.physics_type
-        if phystype == 'NO' or phystype == 'KEYED':
-            return False
-        return (psys.settings.type in {'EMITTER', 'REACTOR'} or 
(psys.settings.type == 'HAIR' and psys.use_hair_dynamics)) and engine in 
cls.COMPAT_ENGINES
+        #if phystype == 'NO' or phystype == 'KEYED':
+        #    return False
+        #return (psys.settings.type in {'EMITTER', 'REACTOR'} or 
(psys.settings.type == 'HAIR' and psys.use_hair_dynamics)) and engine in 
cls.COMPAT_ENGINES
+        return engine in cls.COMPAT_ENGINES
 
     def draw(self, context):
+        layout = self.layout
         psys = context.particle_system
 
         point_cache_ui(self, context, psys, psys.point_cache, True, 'HAIR' if 
(psys.settings.type == 'HAIR') else 'PSYS')
 
+        layout.prop(psys, "point_cache_paths")
+
 
 class PARTICLE_PT_velocity(ParticleButtonsPanel, Panel):
     bl_label = "Velocity"
diff --git a/source/blender/blenkernel/intern/particle.c 
b/source/blender/blenkernel/intern/particle.c
index 03a2530..88b3763 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -86,6 +86,8 @@
 #include "BKE_scene.h"
 #include "BKE_deform.h"
 
+#include "PTC_api.h"
+
 #include "RE_render_ext.h"
 
 unsigned int PSYS_FRAND_SEED_OFFSET[PSYS_FRAND_COUNT];
@@ -2323,6 +2325,9 @@ static void exec_child_path_cache(TaskPool *UNUSED(pool), 
void *taskdata, int UN
 
 void psys_cache_child_paths(ParticleSimulationData *sim, float cfra, int 
editupdate)
 {
+       struct PTCReader *cache_reader = PTC_reader_particle_paths(sim->scene, 
sim->ob, sim->psys, PTC_PARTICLE_PATHS_CHILDREN);
+       PTCReadSampleResult cache_result;
+       
        TaskScheduler *task_scheduler;
        TaskPool *task_pool;
        ParticleThreadContext ctx;
@@ -2353,32 +2358,36 @@ void psys_cache_child_paths(ParticleSimulationData 
*sim, float cfra, int editupd
                sim->psys->totchildcache = totchild;
        }
        
-       /* cache parent paths */
-       ctx.parent_pass = 1;
-       psys_tasks_create(&ctx, totparent, &tasks_parent, &numtasks_parent);
-       for (i = 0; i < numtasks_parent; ++i) {
-               ParticleTask *task = &tasks_parent[i];
+       /* try reading from point cache */
+       cache_result = PTC_read_sample(cache_reader, cfra);
+       if (cache_result == PTC_READ_SAMPLE_INVALID) {
+               /* cache parent paths */
+               ctx.parent_pass = 1;
+               psys_tasks_create(&ctx, totparent, &tasks_parent, 
&numtasks_parent);
+               for (i = 0; i < numtasks_parent; ++i) {
+                       ParticleTask *task = &tasks_parent[i];
+                       
+                       psys_task_init_path(task, sim);
+                       BLI_task_pool_push(task_pool, exec_child_path_cache, 
task, false, TASK_PRIORITY_LOW);
+               }
+               BLI_task_pool_work_and_wait(task_pool);
                
-               psys_task_init_path(task, sim);
-               BLI_task_pool_push(task_pool, exec_child_path_cache, task, 
false, TASK_PRIORITY_LOW);
-       }
-       BLI_task_pool_work_and_wait(task_pool);
-       
-       /* cache child paths */
-       ctx.parent_pass = 0;
-       psys_tasks_create(&ctx, totchild, &tasks_child, &numtasks_child);
-       for (i = 0; i < numtasks_child; ++i) {
-               ParticleTask *task = &tasks_child[i];
+               /* cache child paths */
+               ctx.parent_pass = 0;
+               psys_tasks_create(&ctx, totchild, &tasks_child, 
&numtasks_child);
+               for (i = 0; i < numtasks_child; ++i) {
+                       ParticleTask *task = &tasks_child[i];
+                       
+                       psys_task_init_path(task, sim);
+                       BLI_task_pool_push(task_pool, exec_child_path_cache, 
task, false, TASK_PRIORITY_LOW);
+               }
+               BLI_task_pool_work_and_wait(task_pool);
+               
+               BLI_task_pool_free(task_pool);
                
-               psys_task_init_path(task, sim);
-               BLI_task_pool_push(task_pool, exec_child_path_cache, task, 
false, TASK_PRIORITY_LOW);
+               psys_tasks_free(tasks_parent, numtasks_parent);
+               psys_tasks_free(tasks_child, numtasks_child);
        }
-       BLI_task_pool_work_and_wait(task_pool);
-
-       BLI_task_pool_free(task_pool);
-       
-       psys_tasks_free(tasks_parent, numtasks_parent);
-       psys_tasks_free(tasks_child, numtasks_child);
        
        psys_thread_context_free(&ctx);
 }
@@ -2428,6 +2437,9 @@ static void 
cache_key_incremental_rotation(ParticleCacheKey *key0, ParticleCache
  * - Cached path data is also used to determine cut position for the editmode 
tool. */
 void psys_cache_paths(ParticleSimulationData *sim, float cfra)
 {
+       struct PTCReader *cache_reader = PTC_reader_particle_paths(sim->scene, 
sim->ob, sim->psys, PTC_PARTICLE_PATHS_PARENTS);
+       PTCReadSampleResult cache_result;
+       
        PARTICLE_PSMD;
        ParticleEditSettings *pset = &sim->scene->toolsettings->particle;
        ParticleSystem *psys = sim->psys;
@@ -2471,6 +2483,11 @@ void psys_cache_paths(ParticleSimulationData *sim, float 
cfra)
        /* clear out old and create new empty path cache */
        psys_free_path_cache(psys, psys->edit);
        cache = psys->pathcache = 
psys_alloc_path_cache_buffers(&psys->pathcachebufs, totpart, segments + 1);
+       
+       /* try reading from point cache */
+       cache_result = PTC_read_sample(cache_reader, cfra);
+       if (cache_result != PTC_READ_SAMPLE_INVALID)
+               return;
 
        psys->lattice_deform_data = psys_create_lattice_deform_data(sim);
        ma = give_current_material(sim->ob, psys->part->omat);
diff --git a/source/blender/makesdna/DNA_particle_types.h 
b/source/blender/makesdna/DNA_particle_types.h
index ea58bf7..e94eb3d 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -543,6 +543,7 @@ typedef enum eParticleChildFlag {
 //#define PSYS_PROTECT_CACHE   4096 /* deprecated */
 #define PSYS_DISABLED                  8192
 #define PSYS_OB_ANIM_RESTORE   16384 /* runtime flag */
+#define PSYS_CACHE_PATHS       32768
 
 /* pars->flag */
 #define PARS_UNEXIST           1
diff --git a/source/blender/makesrna/intern/rna_particle.c 
b/source/blender/makesrna/intern/rna_particle.c
index d2417f0..d2e484f 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -3461,6 +3461,10 @@ static void rna_def_particle_system(BlenderRNA *brna)
        RNA_def_property_struct_type(prop, "PointCache");
        RNA_def_property_ui_text(prop, "Point Cache", "");
 
+       prop = RNA_def_property(srna, "point_cache_paths", PROP_BOOLEAN, 
PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", PSYS_CACHE_PATHS);
+       RNA_def_property_ui_text(prop, "Cache Paths", "Store final paths in the 
point cache");
+
        /* offset ob */
        prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
        RNA_def_property_pointer_sdna(prop, NULL, "parent");
diff --git a/source/blender/pointcache/PTC_api.cpp 
b/source/blender/pointcache/PTC_api.cpp
index d470cf5..ca4566c 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -164,15 +164,7 @@ PTCWriter *PTC_writer_from_rna(Scene *scene, PointerRNA 
*ptr)
        if (RNA_struct_is_a(ptr->type, &RNA_ParticleSystem)) {
                Object *ob = (Object *)ptr->id.data;
                ParticleSystem *psys = (ParticleSystem *)ptr->data;
-               /* XXX particles are bad ...
-                * this can be either the actual particle cache or the hair 
dynamics cache,
-                * which is actually the cache of the internal cloth modifier
-                */
-               bool use_cloth_cache = psys->part->type == PART_HAIR && 
(psys->flag & PSYS_HAIR_DYNAMICS);
-               if (use_cloth_cache && psys->clmd)
-                       return PTC_writer_cloth(scene, ob, psys->clmd);
-               else
-                       return PTC_writer_particles(scene, ob, psys);
+               return PTC_writer_particles_combined(scene, ob, psys);
        }
        if (RNA_struct_is_a(ptr->type, &RNA_ClothModifier)) {
                Object *ob = (Object *)ptr->id.data;
@@ -375,6 +367,21 @@ int PTC_reader_particles_totpoint(PTCReader *_reader)
        return ((PTC::ParticlesReader *)_reader)->totpoint();
 }
 
+//PTCWriter *PTC_writer_particle_paths(Scene *scene, Object *ob, 
ParticleSystem *psys)
+//{
+//     return (PTCWriter *)abc_writer_particle_paths(scene, ob, psys);
+//}
+
+PTCReader *PTC_reader_particle_paths(Scene *scene, Object *ob, ParticleSystem 
*psys, eParticlePathsMode mode)
+{
+       return (PTCReader *)abc_reader_particle_paths(scene, ob, psys, mode);
+}
+
+PTCWriter *PTC_writer_particles_combined(Scene *scene, Object *ob, 
ParticleSystem *psys)
+{
+       return (PTCWriter *)abc_writer_particle_combined(scene, ob, psys);
+}
+
 
 /* ==== RIGID BODY ==== */
 
diff --git a/source/blender/pointcache/PTC_api.h 
b/source/blender/pointcache/PTC_api.h
index 411757a..469c80a 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -77,6 +77,16 @@ struct PTCWriter *PTC_writer_particles(struct Scene *scene, 
struct Object *ob, s
 struct PTCReader *PTC_reader_particles(struct Scene *scene, struct Object *ob, 
struct ParticleSystem *psys);
 int PTC_reader_particles_totpoint(struct PTCReader *reader);
 
+typedef enum eParticlePathsMode {
+       PTC_PARTICLE_PATHS_PARENTS = 0,
+       PTC_PARTICLE_PATHS_CHILDREN = 1,
+} eParticlePathsMode;
+
+//struct PTCWriter *PTC_writer_particle_paths(struct Scene *scene, struct 
Object *ob, struct ParticleSystem *psys);
+struct PTCReader *PTC_reader_particle_paths(struct Scene *scene, struct Object 
*ob, struct ParticleSystem *psys, eParticlePathsMode mode);
+
+struct PTCWriter *PTC_writer_particles_combined(struct Scene *scene, struct 
Object *ob, struct ParticleSystem *psys);
+
 /* Cloth */
 struct PTCWriter *PTC_writer_cloth(struct Scene *scene, struct Object *ob, 
struct ClothModifierData *clmd);
 struct PTCReader *PTC_reader_cloth(struct Scene *scene, struct Object *ob, 
struct ClothModifierData *clmd);
diff --git a/source/blender/pointcache/alembic/abc_cloth.cpp 
b/source/blender/pointcache/alembic/abc_cloth.cpp
index 4b629aa..e3f3951 100644
--- a/source/blender/pointcache/alembic/abc_cloth.cpp
+++ b/source/blender/pointcache/alembic/abc_cloth.cpp
@@ -43,10 +43,8 @@ AbcClothWriter::AbcClothWriter(Scene *scene, Object *ob, 
ClothModifierData *clmd
 {
        set_error_handler(new ModifierErrorHandler(&clmd->modifier));
        
-       uint32_t fs = m_archive.add_frame_sampling();
-       
        OObject root = m_archive.archive.getTop();
-       m_points = OPoints(root, m_clmd->modifier.na

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