[Bf-blender-cvs] [0ff8990] gooseberry: Cache reading functions for constructing a nested dupligroup list based on Alembic cache data.
Lukas Tönne
noreply at git.blender.org
Mon Mar 23 13:03:18 CET 2015
Commit: 0ff8990e135dccfaf03f26dc1822f0853984ad30
Author: Lukas Tönne
Date: Thu Mar 12 12:21:12 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB0ff8990e135dccfaf03f26dc1822f0853984ad30
Cache reading functions for constructing a nested dupligroup list based
on Alembic cache data.
===================================================================
M source/blender/blenkernel/BKE_anim.h
M source/blender/blenkernel/intern/cache_library.c
M source/blender/blenkernel/intern/object_dupli.c
M source/blender/blenloader/intern/readfile.c
M source/blender/makesdna/DNA_object_types.h
M source/blender/pointcache/PTC_api.cpp
M source/blender/pointcache/PTC_api.h
M source/blender/pointcache/alembic/abc_group.cpp
M source/blender/pointcache/alembic/abc_group.h
M source/blender/pointcache/alembic/alembic.cpp
M source/blender/pointcache/intern/ptc_types.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index a91f4ae..65a0ea8 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -44,6 +44,9 @@ struct bPoseChannel;
struct ReportList;
struct GHash;
struct DupliCache;
+struct DupliObject;
+struct DupliObjectData;
+struct DerivedMesh;
/* ---------------------------------------------------- */
/* Animation Visualization */
@@ -76,7 +79,8 @@ int count_duplilist(struct Object *ob);
void BKE_object_dupli_cache_update(struct Scene *scene, struct Object *ob, struct EvaluationContext *eval_ctx);
void BKE_object_dupli_cache_clear(struct Object *ob);
-void BKE_dupli_cache_add_mesh(struct DupliCache *dupcache, float obmat[4][4], struct DerivedMesh *dm);
+struct DupliObjectData *BKE_dupli_cache_add_mesh(struct DupliCache *dupcache, struct DerivedMesh *dm);
+void BKE_dupli_cache_add_instance(struct DupliCache *dupcache, float obmat[4][4], struct DupliObjectData *data);
typedef struct DupliExtraData {
float obmat[4][4];
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 72e97a0..88654d5 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -1215,8 +1215,17 @@ bool BKE_cache_read_dupligroup(Main *bmain, Scene *scene, float frame, eCacheLib
FOREACH_CACHELIB_READ(bmain, cachelib, eval_mode) {
if (cachelib->group == dupgroup) {
- // TODO
- // BKE_dupli_cache_add_mesh();
+ char filename[FILE_MAX];
+ struct PTCReaderArchive *archive;
+ eCacheReadSampleResult result;
+
+ BKE_cache_archive_path(cachelib->filepath, (ID *)cachelib, cachelib->id.lib, filename, sizeof(filename));
+ archive = PTC_open_reader_archive(scene, filename);
+
+ result = BKE_cache_read_result(PTC_read_dupligroup(archive, frame, dupgroup, dupcache));
+
+ PTC_close_reader_archive(archive);
+
return true;
}
}
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 5f19e5e..2af8235 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1241,29 +1241,28 @@ int count_duplilist(Object *ob)
}
/* ------------------------------------------------------------------------- */
+
+
+
typedef struct DupliCache {
-#if 0
- /* XXX ghash implementation later, for now listbase is easier */
struct GHash *ghash;
-#else
+
ListBase duplilist;
-#endif
} DupliCache;
-static void dupli_object_free(DupliObject *dob)
+static void dupli_object_data_free(DupliObjectData *data)
{
- if (dob->cache_dm)
- dob->cache_dm->release(dob->cache_dm);
+ if (data->cache_dm)
+ data->cache_dm->release(data->cache_dm);
- MEM_freeN(dob);
+ MEM_freeN(data);
}
-#if 0
-static void dupli_cache_clear(DupliCache *dupcache)
+static void dupli_object_free(DupliObject *dob)
{
- BLI_ghash_clear(dupcache->ghash, NULL, (GHashValFreeFP)dupli_object_free);
+ MEM_freeN(dob);
}
-#else
+
static void dupli_cache_clear(DupliCache *dupcache)
{
DupliObject *dob, *dob_next;
@@ -1273,10 +1272,41 @@ static void dupli_cache_clear(DupliCache *dupcache)
dupli_object_free(dob);
}
BLI_listbase_clear(&dupcache->duplilist);
+
+ BLI_ghash_clear(dupcache->ghash, NULL, (GHashValFreeFP)dupli_object_data_free);
+}
+
+static void dupli_cache_free(DupliCache *dupcache)
+{
+ dupli_cache_clear(dupcache);
+
+ BLI_ghash_free(dupcache->ghash, NULL, (GHashValFreeFP)dupli_object_data_free);
+ MEM_freeN(dupcache);
}
-#endif
-static DupliObject *dupli_cache_push(DupliCache *dupcache)
+static DupliCache *dupli_cache_new(void)
+{
+ DupliCache *dupcache = MEM_callocN(sizeof(DupliCache), "dupli object cache");
+
+ dupcache->ghash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "dupli object data hash");
+
+ return dupcache;
+}
+
+static DupliObjectData *dupli_cache_add_object_data(DupliCache *dupcache)
+{
+ DupliObjectData *data = MEM_callocN(sizeof(DupliObjectData), "dupli object data");
+
+ BLI_ghash_insert(dupcache->ghash, data, data);
+ return data;
+}
+
+static bool dupli_cache_contains_object_data(DupliCache *dupcache, DupliObjectData *data)
+{
+ return BLI_ghash_lookup(dupcache->ghash, data) != NULL;
+}
+
+static DupliObject *dupli_cache_add_object(DupliCache *dupcache)
{
DupliObject *dob = MEM_callocN(sizeof(DupliObject), "dupli object");
@@ -1296,7 +1326,7 @@ void BKE_object_dupli_cache_update(Scene *scene, Object *ob, EvaluationContext *
dupli_cache_clear(ob->dup_cache);
}
else {
- ob->dup_cache = MEM_callocN(sizeof(DupliCache), "dupli object cache");
+ ob->dup_cache = dupli_cache_new();
}
#if 0
@@ -1327,8 +1357,7 @@ void BKE_object_dupli_cache_update(Scene *scene, Object *ob, EvaluationContext *
}
else {
if (ob->dup_cache) {
- dupli_cache_clear(ob->dup_cache);
- MEM_freeN(ob->dup_cache);
+ dupli_cache_free(ob->dup_cache);
ob->dup_cache = NULL;
}
}
@@ -1341,14 +1370,26 @@ void BKE_object_dupli_cache_clear(Object *ob)
}
}
-void BKE_dupli_cache_add_mesh(DupliCache *dupcache, float obmat[4][4], DerivedMesh *dm)
+DupliObjectData *BKE_dupli_cache_add_mesh(DupliCache *dupcache, DerivedMesh *dm)
{
- DupliObject *dob = dupli_cache_push(dupcache);
+ DupliObjectData *data = dupli_cache_add_object_data(dupcache);
+
+ data->cache_dm = dm;
+
+ return data;
+}
+
+void BKE_dupli_cache_add_instance(DupliCache *dupcache, float obmat[4][4], DupliObjectData *data)
+{
+ DupliObject *dob = dupli_cache_add_object(dupcache);
+
+ /* data must have been created correctly */
+ BLI_assert(dupli_cache_contains_object_data(dupcache, data));
dob->ob = NULL;
copy_m4_m4(dob->mat, obmat);
- dob->cache_dm = dm;
+ dob->data = data;
}
/* ------------------------------------------------------------------------- */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index d591d01..6115d3f 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5055,6 +5055,8 @@ static void direct_link_object(FileData *fd, Object *ob)
/* do it here, below old data gets converted */
direct_link_modifiers(fd, &ob->modifiers);
+ ob->dup_cache = NULL;
+
link_list(fd, &ob->effect);
paf= ob->effect.first;
while (paf) {
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index d52f1c5..fe38d09 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -341,9 +341,14 @@ typedef struct DupliObject {
/* particle this dupli was generated from */
struct ParticleSystem *particle_system;
- struct DerivedMesh *cache_dm;
+ struct DupliObjectData *data;
} DupliObject;
+/* data that can be shared by multiple DupliObject instances */
+typedef struct DupliObjectData {
+ struct DerivedMesh *cache_dm;
+} DupliObjectData;
+
/* **************** OBJECT ********************* */
/* used many places... should be specialized */
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index e8123ce..cbb94c7 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -201,6 +201,12 @@ char *PTC_get_archive_info(PTCReaderArchive *_archive)
}
+PTCReadSampleResult PTC_read_dupligroup(PTCReaderArchive *archive, float frame, Group *dupgroup, DupliCache *dupcache)
+{
+ return PTC::Factory::alembic->read_dupligroup((PTC::ReaderArchive *)archive, frame, dupgroup, dupcache);
+}
+
+
/* get writer/reader from RNA type */
PTCWriter *PTC_writer_from_rna(Scene *scene, PointerRNA *ptr)
{
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 25da29e..cb7e048 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -32,15 +32,14 @@ struct ListBase;
struct PointerRNA;
struct ReportList;
+struct DupliCache;
struct ClothModifierData;
struct DerivedMesh;
-struct DynamicPaintSurface;
+struct Group;
struct ModifierData;
struct Object;
struct ParticleSystem;
struct CacheModifierData;
-struct RigidBodyWorld;
-struct SmokeDomainSettings;
struct SoftBody;
struct PTCWriterArchive;
@@ -86,6 +85,8 @@ PTCReadSampleResult PTC_test_sample(struct PTCReader *reader, float frame);
char *PTC_get_archive_info(struct PTCReaderArchive *archive);
+PTCReadSampleResult PTC_read_dupligroup(struct PTCReaderArchive *archive, float frame, struct Group *dupgroup, struct DupliCache *dupcache);
+
/* get writer/reader from RNA type */
struct PTCWriter *PTC_writer_from_rna(struct Scene *scene, struct PointerRNA *ptr);
struct PTCReader *PTC_reader_from_rna(struct Scene *scene, struct PointerRNA *ptr);
diff --git a/source/blender/pointcache/alembic/abc_group.cpp b/source/blender/pointcache/alembic/abc_group.cpp
index 15331c8..12b3fa8 100644
--- a/source/blender/pointcache/alembic/abc_group.cpp
+++ b/source/blender/pointcache/alembic/abc_group.cpp
@@ -16,16 +16,22 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <map>
#include <sstream>
#include <string>
+#include <Alembic/Abc/IObject.h>
+
+#include "abc_mesh.h"
#include "abc_group.h"
extern "C" {
#include "BLI_math.h"
#include "DNA_group_types.h"
+#include "DNA_object_types.h"
+#include "BKE_anim.h"
#include "BKE_group.h"
}
@@ -93,4 +99,120 @@ PTCReadSampleResult AbcGroupReader::read_sample(float frame)
return PTC_READ_SAMPLE_EXACT;
}
+/* ========================================================================= */
+
+typedef float Matrix[4][4];
+
+typedef float (*MatrixPtr)[4];
+
+static Matrix I = {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}};
+
+struct DupliGroupContext {
+ typedef std::map<ObjectReaderPtr, DupliObjectData*> DupliMap;
+ typedef std::pair<ObjectReaderPtr, DupliObjectData*> DupliPair;
+
+ struct Transform {
+ Transform() {}
+ Transform(float (*value)[4]) { copy_m4_m4(matrix, value); }
+ Transform(const Transform &tfm) { memcpy(matrix, tfm.matrix, sizeof(Matr
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list