[Bf-blender-cvs] [2611937] alembic_pointcache: Generic validation function to help ensure that we don't add meaningless items to a cache library.
Lukas Tönne
noreply at git.blender.org
Mon Mar 2 12:11:27 CET 2015
Commit: 26119375cc3291822460d7ff21e3e7038ab6af48
Author: Lukas Tönne
Date: Mon Mar 2 12:10:51 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB26119375cc3291822460d7ff21e3e7038ab6af48
Generic validation function to help ensure that we don't add meaningless
items to a cache library.
===================================================================
M source/blender/blenkernel/BKE_cache_library.h
M source/blender/blenkernel/intern/cache_library.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 98006d0..4231595 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -87,6 +87,7 @@ struct CacheItem *BKE_cache_library_add_item(struct CacheLibrary *cachelib, stru
void BKE_cache_library_remove_item(struct CacheLibrary *cachelib, struct CacheItem *item);
void BKE_cache_library_clear(struct CacheLibrary *cachelib);
+bool BKE_cache_library_validate_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
void BKE_cache_library_group_update(struct Main *bmain, struct CacheLibrary *cachelib);
bool BKE_cache_read_derived_mesh(struct Main *bmain, struct Scene *scene, float frame, struct Object *ob, struct DerivedMesh **r_dm);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 6cc5dc3..6850b91 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -45,6 +45,7 @@
#include "BKE_cache_library.h"
#include "BKE_global.h"
+#include "BKE_group.h"
#include "BKE_library.h"
#include "BKE_main.h"
@@ -84,7 +85,7 @@ void BKE_cache_library_free(CacheLibrary *cachelib)
BLI_ghash_free(cachelib->items_hash, NULL, NULL);
}
-void BKE_cache_library_unlink(CacheLibrary *cachelib)
+void BKE_cache_library_unlink(CacheLibrary *UNUSED(cachelib))
{
}
@@ -425,6 +426,9 @@ CacheItem *BKE_cache_library_add_item(CacheLibrary *cachelib, struct Object *ob,
{
CacheItem *item;
+ /* assert validity */
+ BLI_assert(BKE_cache_library_validate_item(cachelib, ob, type, index));
+
cache_library_ensure_items_hash(cachelib);
item = BKE_cache_library_find_item(cachelib, ob, type, index);
@@ -468,6 +472,38 @@ void BKE_cache_library_clear(CacheLibrary *cachelib)
BLI_listbase_clear(&cachelib->items);
}
+bool BKE_cache_library_validate_item(CacheLibrary *cachelib, Object *ob, int type, int index)
+{
+ if (!cachelib || !cachelib->group)
+ return false;
+
+ if (!BKE_group_object_exists(cachelib->group, ob))
+ return false;
+
+ if (ELEM(type, CACHE_TYPE_DERIVED_MESH)) {
+ if (ob->type != OB_MESH)
+ return false;
+ }
+ else if (ELEM(type, CACHE_TYPE_PARTICLES, CACHE_TYPE_HAIR, CACHE_TYPE_HAIR_PATHS)) {
+ ParticleSystem *psys = BLI_findlink(&ob->particlesystem, index);
+
+ if (!psys)
+ return false;
+
+ if (ELEM(type, CACHE_TYPE_PARTICLES)) {
+ if (psys->part->type != PART_EMITTER)
+ return false;
+ }
+
+ if (ELEM(type, CACHE_TYPE_HAIR, CACHE_TYPE_HAIR_PATHS)) {
+ if (psys->part->type != PART_HAIR)
+ return false;
+ }
+ }
+
+ return true;
+}
+
void BKE_cache_library_group_update(Main *bmain, CacheLibrary *cachelib)
{
if (cachelib) {
More information about the Bf-blender-cvs
mailing list