Commit: ea601a481428881c6618e4552b65d3e7a3c74b40
Author: Lukas Tönne
Date:   Thu Mar 5 13:43:31 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rBea601a481428881c6618e4552b65d3e7a3c74b40

Use a combined class for hair dynamics for cloth and mesh data.

Particles store a copy of the DM internally as the emitter.

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

M       source/blender/blenkernel/intern/cache_library.c
M       source/blender/pointcache/PTC_api.cpp
M       source/blender/pointcache/PTC_api.h
M       source/blender/pointcache/alembic/abc_cloth.h
M       source/blender/pointcache/alembic/abc_particles.cpp
M       source/blender/pointcache/alembic/abc_particles.h
M       source/blender/pointcache/alembic/alembic.cpp
M       source/blender/pointcache/intern/ptc_types.h

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

diff --git a/source/blender/blenkernel/intern/cache_library.c 
b/source/blender/blenkernel/intern/cache_library.c
index fd843d4..585c0f0 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -719,7 +719,7 @@ void BKE_cache_library_writers(CacheLibrary *cachelib, 
Scene *scene, DerivedMesh
                        case CACHE_TYPE_HAIR: {
                                ParticleSystem *psys = (ParticleSystem 
*)BLI_findlink(&item->ob->particlesystem, item->index);
                                if (psys && psys->part && psys->part->type == 
PART_HAIR && psys->clmd) {
-                                       cachelib_add_writer(writers, item, 
PTC_writer_hair_dynamics(name, item->ob, psys->clmd));
+                                       cachelib_add_writer(writers, item, 
PTC_writer_hair_dynamics(name, item->ob, psys));
                                }
                                break;
                        }
@@ -812,7 +812,7 @@ static struct PTCReader 
*cache_library_reader_hair_dynamics(CacheLibrary *cachel
                char name[2*MAX_NAME];
                BKE_cache_item_name(ob, CACHE_TYPE_HAIR, index, name);
                
-               return PTC_reader_hair_dynamics(name, ob, psys->clmd);
+               return PTC_reader_hair_dynamics(name, ob, psys);
        }
        
        return NULL;
diff --git a/source/blender/pointcache/PTC_api.cpp 
b/source/blender/pointcache/PTC_api.cpp
index 2d38782..5da5268 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -244,16 +244,6 @@ PTCReader *PTC_reader_cloth(const char *name, Object *ob, 
ClothModifierData *clm
        return (PTCReader *)PTC::Factory::alembic->create_reader_cloth(name, 
ob, clmd);
 }
 
-PTCWriter *PTC_writer_hair_dynamics(const char *name, Object *ob, 
ClothModifierData *clmd)
-{
-       return (PTCWriter 
*)PTC::Factory::alembic->create_writer_hair_dynamics(name, ob, clmd);
-}
-
-PTCReader *PTC_reader_hair_dynamics(const char *name, Object *ob, 
ClothModifierData *clmd)
-{
-       return (PTCReader 
*)PTC::Factory::alembic->create_reader_hair_dynamics(name, ob, clmd);
-}
-
 
 /* ==== MESH ==== */
 
@@ -318,6 +308,16 @@ int PTC_reader_particles_totpoint(PTCReader *_reader)
        return ((PTC::ParticlesReader *)_reader)->totpoint();
 }
 
+PTCWriter *PTC_writer_hair_dynamics(const char *name, Object *ob, 
ParticleSystem *psys)
+{
+       return (PTCWriter 
*)PTC::Factory::alembic->create_writer_hair_dynamics(name, ob, psys);
+}
+
+PTCReader *PTC_reader_hair_dynamics(const char *name, Object *ob, 
ParticleSystem *psys)
+{
+       return (PTCReader 
*)PTC::Factory::alembic->create_reader_hair_dynamics(name, ob, psys);
+}
+
 PTCWriter *PTC_writer_particles_pathcache_parents(const char *name, Object 
*ob, ParticleSystem *psys)
 {
        return (PTCWriter 
*)PTC::Factory::alembic->create_writer_particles_pathcache_parents(name, ob, 
psys);
diff --git a/source/blender/pointcache/PTC_api.h 
b/source/blender/pointcache/PTC_api.h
index e57a528..5afa651 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -92,6 +92,9 @@ struct PTCWriter *PTC_writer_particles(const char *name, 
struct Object *ob, stru
 struct PTCReader *PTC_reader_particles(const char *name, struct Object *ob, 
struct ParticleSystem *psys);
 int PTC_reader_particles_totpoint(struct PTCReader *reader);
 
+struct PTCWriter *PTC_writer_hair_dynamics(const char *name, struct Object 
*ob, struct ParticleSystem *psys);
+struct PTCReader *PTC_reader_hair_dynamics(const char *name, struct Object 
*ob, struct ParticleSystem *psys);
+
 struct PTCWriter *PTC_writer_particles_pathcache_parents(const char *name, 
struct Object *ob, struct ParticleSystem *psys);
 struct PTCReader *PTC_reader_particles_pathcache_parents(const char *name, 
struct Object *ob, struct ParticleSystem *psys);
 struct PTCWriter *PTC_writer_particles_pathcache_children(const char *name, 
struct Object *ob, struct ParticleSystem *psys);
@@ -100,8 +103,6 @@ struct PTCReader 
*PTC_reader_particles_pathcache_children(const char *name, stru
 /* Cloth */
 struct PTCWriter *PTC_writer_cloth(const char *name, struct Object *ob, struct 
ClothModifierData *clmd);
 struct PTCReader *PTC_reader_cloth(const char *name, struct Object *ob, struct 
ClothModifierData *clmd);
-struct PTCWriter *PTC_writer_hair_dynamics(const char *name, struct Object 
*ob, struct ClothModifierData *clmd);
-struct PTCReader *PTC_reader_hair_dynamics(const char *name, struct Object 
*ob, struct ClothModifierData *clmd);
 
 struct PTCWriter *PTC_writer_derived_mesh(const char *name, struct Object *ob, 
struct DerivedMesh **dm_ptr);
 struct PTCReader *PTC_reader_derived_mesh(const char *name, struct Object *ob);
diff --git a/source/blender/pointcache/alembic/abc_cloth.h 
b/source/blender/pointcache/alembic/abc_cloth.h
index 9b4d2ed..947f49a 100644
--- a/source/blender/pointcache/alembic/abc_cloth.h
+++ b/source/blender/pointcache/alembic/abc_cloth.h
@@ -63,25 +63,6 @@ private:
        AbcGeom::IP3fGeomParam m_param_goal_positions;
 };
 
-
-/* Hair is just a cloth sim in disguise ... */
-
-class AbcHairDynamicsWriter : public AbcClothWriter {
-public:
-       AbcHairDynamicsWriter(const std::string &name, Object *ob, 
ClothModifierData *clmd) :
-           AbcClothWriter(name, ob, clmd)
-       {}
-};
-
-class AbcHairDynamicsReader : public AbcClothReader {
-public:
-       AbcHairDynamicsReader(const std::string &name, Object *ob, 
ClothModifierData *clmd) :
-           AbcClothReader(name, ob, clmd)
-       {}
-       
-       PTCReadSampleResult read_sample(float frame) { return 
AbcClothReader::read_sample(frame); }
-};
-
 } /* namespace PTC */
 
 #endif  /* PTC_CLOTH_H */
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp 
b/source/blender/pointcache/alembic/abc_particles.cpp
index 6dcbbb5..ac9ea71 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -17,11 +17,13 @@
  */
 
 #include "abc_cloth.h"
+#include "abc_mesh.h"
 #include "abc_particles.h"
 
 extern "C" {
 #include "BLI_math.h"
 
+#include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 #include "DNA_particle_types.h"
 
@@ -131,6 +133,55 @@ PTCReadSampleResult AbcParticlesReader::read_sample(float 
frame)
 }
 
 
+AbcHairDynamicsWriter::AbcHairDynamicsWriter(const std::string &name, Object 
*ob, ParticleSystem *psys) :
+    ParticlesWriter(ob, psys, name),
+    m_dm_writer(name+"__mesh", ob, &psys_get_modifier(ob, psys)->dm),
+    m_cloth_writer(name+"__cloth", ob, psys->clmd)
+{
+}
+
+void AbcHairDynamicsWriter::open_archive(WriterArchive *archive)
+{
+       m_dm_writer.open_archive(archive);
+       m_cloth_writer.open_archive(archive);
+}
+
+void AbcHairDynamicsWriter::write_sample()
+{
+       m_dm_writer.write_sample();
+       m_cloth_writer.write_sample();
+}
+
+AbcHairDynamicsReader::AbcHairDynamicsReader(const std::string &name, Object 
*ob, ParticleSystem *psys) :
+       ParticlesReader(ob, psys, name),
+       m_dm_reader(name+"__mesh", ob),
+       m_cloth_reader(name+"__cloth", ob, psys->clmd)
+{
+}
+
+void AbcHairDynamicsReader::open_archive(ReaderArchive *archive)
+{
+       m_dm_reader.open_archive(archive);
+       m_cloth_reader.open_archive(archive);
+}
+
+PTCReadSampleResult AbcHairDynamicsReader::read_sample(float frame)
+{
+       if (m_dm_reader.read_sample(frame) == PTC_READ_SAMPLE_INVALID)
+               return PTC_READ_SAMPLE_INVALID;
+       
+       ParticleSystemModifierData *psmd = psys_get_modifier(m_ob, m_psys);
+       if (psmd->dm)
+               psmd->dm->release(psmd->dm);
+       psmd->dm = m_dm_reader.acquire_result();
+       
+       if (m_cloth_reader.read_sample(frame) == PTC_READ_SAMPLE_INVALID)
+               return PTC_READ_SAMPLE_INVALID;
+       
+       return PTC_READ_SAMPLE_EXACT;
+}
+
+
 AbcParticlePathcacheWriter::AbcParticlePathcacheWriter(const std::string 
&name, Object *ob, ParticleSystem *psys, ParticleCacheKey ***pathcache, int 
*totpath, const std::string &suffix) :
     ParticlesWriter(ob, psys, name),
     m_pathcache(pathcache),
diff --git a/source/blender/pointcache/alembic/abc_particles.h 
b/source/blender/pointcache/alembic/abc_particles.h
index 5e624e6..968ff7a 100644
--- a/source/blender/pointcache/alembic/abc_particles.h
+++ b/source/blender/pointcache/alembic/abc_particles.h
@@ -39,6 +39,9 @@ struct ParticleCacheKey;
 namespace PTC {
 
 class AbcClothWriter;
+class AbcClothReader;
+class AbcDerivedMeshWriter;
+class AbcDerivedMeshReader;
 
 class AbcParticlesWriter : public ParticlesWriter, public AbcWriter {
 public:
@@ -66,6 +69,36 @@ private:
        AbcGeom::IPoints m_points;
 };
 
+
+/* Hair is just a cloth sim in disguise ... */
+
+class AbcHairDynamicsWriter : public ParticlesWriter, public AbcWriter {
+public:
+       AbcHairDynamicsWriter(const std::string &name, Object *ob, 
ParticleSystem *psys);
+       
+       void open_archive(WriterArchive *archive);
+       
+       void write_sample();
+       
+private:
+       AbcDerivedMeshWriter m_dm_writer;
+       AbcClothWriter m_cloth_writer;
+};
+
+class AbcHairDynamicsReader : public ParticlesReader, public AbcReader {
+public:
+       AbcHairDynamicsReader(const std::string &name, Object *ob, 
ParticleSystem *psys);
+       
+       void open_archive(ReaderArchive *archive);
+       
+       PTCReadSampleResult read_sample(float frame);
+       
+private:
+       AbcDerivedMeshReader m_dm_reader;
+       AbcClothReader m_cloth_reader;
+};
+
+
 class AbcParticlePathcacheWriter : public ParticlesWriter, public AbcWriter {
 protected:
        AbcParticlePathcacheWriter(const std::string &name, Object *ob, 
ParticleSystem *psys, ParticleCacheKey ***pathcache, int *totpath, const 
std::string &suffix);
diff --git a/source/blender/pointcache/alembic/alembic.cpp 
b/source/blender/pointcache/alembic/alembic.cpp
index 38ff9a7..d14a86e 100644
--- a/source/blender/pointcache/alembic/alembic.cpp
+++ b/source/blender/pointcache/alembic/alembic.cpp
@@ -56,6 +56,16 @@ class AbcFactory : public Factory {
                return new AbcParticlesReader(name, ob, psys);
        }
        
+       Writer *create_writer_hair_dynamics(const std::string &name, Object 
*ob, ParticleSystem *psys)
+       {
+               return new AbcHairDynamicsWriter(name, ob, psys);
+       }
+       
+       Reader *create_reader_hair_dynamics(const std::string &name, Object 
*ob, ParticleSystem *psys)
+       {
+               return new AbcHairDynamicsReader(name, ob, psys);
+       }
+       
        Writer *create_writer_particles_pathcache_parents(const std::string 
&name, Object *ob, ParticleSystem *psys)
        {
                return new AbcParticlePathcacheParentsWriter(name, ob, psys);
@@ -88,16 +98,6 @@ class AbcFactory : public Factory {
                return new AbcClothReader(name, ob, clmd);
        }
        
-       Writer *create_writer_hair_dynamics(const std::string &name, Object 
*ob, ClothModifierData *c

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