[Bf-blender-cvs] [a862ceb] openvdb: Bring in refactor from other (private) branch.
Kévin Dietrich
noreply at git.blender.org
Sat Jan 9 06:16:19 CET 2016
Commit: a862cebfd4df3ca465220567653d31eba19a4435
Author: Kévin Dietrich
Date: Sat Jan 9 06:16:03 2016 +0100
Branches: openvdb
https://developer.blender.org/rBa862cebfd4df3ca465220567653d31eba19a4435
Bring in refactor from other (private) branch.
Now the system behaves a bit more like the pointcache.
It's about time I merge the changes.
===================================================================
M source/blender/blenkernel/BKE_smoke.h
M source/blender/blenkernel/intern/depsgraph.c
M source/blender/blenkernel/intern/smoke.c
M source/blender/blenloader/intern/readfile.c
M source/blender/editors/object/object_modifier.c
M source/blender/editors/space_time/space_time.c
M source/blender/editors/space_view3d/drawobject.c
M source/blender/makesdna/DNA_smoke_types.h
M source/blender/makesrna/intern/CMakeLists.txt
M source/blender/makesrna/intern/rna_smoke.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_smoke.h b/source/blender/blenkernel/BKE_smoke.h
index 0d99451..5de8c27 100644
--- a/source/blender/blenkernel/BKE_smoke.h
+++ b/source/blender/blenkernel/BKE_smoke.h
@@ -61,7 +61,9 @@ void smokeModifier_OpenVDB_export(struct SmokeModifierData *smd, struct Scene *s
bool smokeModifier_OpenVDB_import(struct SmokeModifierData *smd, struct Scene *scene, struct Object *ob, struct OpenVDBCache *cache);
-struct OpenVDBCache *BKE_openvdb_get_current_cache(struct SmokeDomainSettings *sds);
+struct OpenVDBCache *BKE_openvdb_cache_current(struct SmokeDomainSettings *sds);
void BKE_openvdb_cache_filename(char *r_filename, const char *path, const char *fname, const char *relbase, int frame);
+void BKE_openvdb_cache_remove_files(struct OpenVDBCache *cache, const char *relbase);
+bool BKE_openvdb_cache_reset(struct Object *ob);
#endif /* __BKE_SMOKE_H__ */
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
index e313ad7..15fa3a6 100644
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ b/source/blender/blenkernel/intern/depsgraph.c
@@ -80,6 +80,7 @@
#include "BKE_pointcache.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
+#include "BKE_smoke.h"
#include "BKE_tracking.h"
#include "GPU_buffers.h"
@@ -1887,6 +1888,40 @@ static void flush_pointcache_reset(Main *bmain, Scene *scene, DagNode *node,
}
}
+/* node was checked to have lasttime != curtime, and is of type ID_OB */
+static void flush_openvdbcache_reset(Main *bmain, Scene *scene, DagNode *node,
+ int curtime, unsigned int lay, bool reset)
+{
+ DagAdjList *itA;
+ Object *ob;
+
+ node->lasttime = curtime;
+
+ for (itA = node->child; itA; itA = itA->next) {
+ if (itA->node->type != ID_OB) {
+ continue;
+ }
+
+ if (itA->node->lasttime != curtime) {
+ ob = (Object *)(itA->node->ob);
+
+ if (reset || (ob->recalc & OB_RECALC_ALL)) {
+ if (BKE_openvdb_cache_reset(ob)) {
+ /* Don't tag nodes which are on invisible layer. */
+ if (itA->node->lay & lay) {
+ ob->recalc |= OB_RECALC_DATA;
+ lib_id_recalc_data_tag(bmain, &ob->id);
+ }
+ }
+
+ flush_openvdbcache_reset(bmain, scene, itA->node, curtime, lay, true);
+ }
+ else
+ flush_openvdbcache_reset(bmain, scene, itA->node, curtime, lay, false);
+ }
+ }
+}
+
/* flush layer flags to dependencies */
static void dag_scene_flush_layers(Scene *sce, int lay)
{
@@ -2002,12 +2037,24 @@ void DAG_scene_flush_update(Main *bmain, Scene *sce, unsigned int lay, const sho
lib_id_recalc_data_tag(bmain, &ob->id);
}
+ if (BKE_openvdb_cache_reset(ob)) {
+ ob->recalc |= OB_RECALC_DATA;
+ lib_id_recalc_data_tag(bmain, &ob->id);
+ }
+
flush_pointcache_reset(bmain, sce, itA->node, lasttime,
lay, true);
+
+ flush_openvdbcache_reset(bmain, sce, itA->node, lasttime,
+ lay, true);
}
- else
+ else {
flush_pointcache_reset(bmain, sce, itA->node, lasttime,
lay, false);
+
+ flush_openvdbcache_reset(bmain, sce, itA->node, lasttime,
+ lay, false);
+ }
}
}
}
@@ -2540,6 +2587,7 @@ static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id)
if (GS(id->name) == ID_OB) {
ob = (Object *)id;
BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH);
+ BKE_openvdb_cache_reset(obt);
/* So if someone tagged object recalc directly,
* id_tag_update bit-field stays relevant
@@ -2571,6 +2619,7 @@ static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id)
obt->recalc |= OB_RECALC_DATA;
lib_id_recalc_data_tag(bmain, &obt->id);
BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
+ BKE_openvdb_cache_reset(obt);
}
}
}
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 3b24cd7..28d5648 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -370,6 +370,9 @@ static void smokeModifier_freeDomain(SmokeModifierData *smd)
OpenVDBWriter_free(cache->writer);
OpenVDBReader_free(cache->reader);
#endif
+ if (cache->cached_frames != NULL)
+ MEM_freeN(cache->cached_frames);
+
MEM_freeN(cache);
}
@@ -2751,15 +2754,81 @@ static void smokeModifier_process_pointcache(SmokeModifierData *smd, Scene *scen
#endif
}
+/* forward declarations */
+void OpenVDB_export_smoke(SmokeDomainSettings *sds, struct OpenVDBWriter *writer);
+void OpenVDB_write_fluid_settings(SmokeDomainSettings *sds, struct OpenVDBWriter *writer);
+
+static void OpenVDBCache_validate_frames(OpenVDBCache *cache, Object *ob)
+{
+ if ((cache->flags & (OPENVDB_CACHE_OUTDATED|OPENVDB_CACHE_INVALID)) == 0) {
+ return;
+ }
+
+ const int start = cache->startframe, end = cache->endframe;
+
+ if (cache->cached_frames == NULL) {
+ cache->cached_frames = MEM_callocN(sizeof(char) * end - start + 1,
+ "OpenVDBCache_cached_frames");
+ }
+
+ const char *relbase = modifier_path_relbase(ob);
+
+ if ((cache->flags & OPENVDB_CACHE_INVALID) != 0) {
+ BKE_openvdb_cache_remove_files(cache, relbase);
+ cache->flags &= ~OPENVDB_CACHE_INVALID;
+ return;
+ }
+
+ char filename[FILE_MAX];
+ for (int fr = start; fr != end; fr++) {
+ BKE_openvdb_cache_filename(filename, cache->path, cache->name, relbase, fr);
+
+ if (BLI_exists(filename)) {
+ cache->cached_frames[fr - start] = 1;
+ }
+ }
+
+ cache->flags &= ~OPENVDB_CACHE_OUTDATED;
+}
+
+static void bke_openvdb_cache_write_smoke(OpenVDBCache *cache, SmokeDomainSettings *sds, Object *ob, int framenr)
+{
+#ifdef WITH_OPENVDB
+ if (cache->writer == NULL) {
+ cache->writer = OpenVDBWriter_create();
+ }
+
+ if (framenr == cache->startframe) {
+ unit_m4(sds->obmat);
+ }
+
+ const bool save_as_half = ((cache->flags & OPENVDB_CACHE_SAVE_AS_HALF) != 0);
+ OpenVDBWriter_set_flags(cache->writer, cache->compression, save_as_half);
+
+ const char *relbase = modifier_path_relbase(ob);
+ char filename[FILE_MAX];
+ BKE_openvdb_cache_filename(filename, cache->path, cache->name, relbase, framenr);
+
+ OpenVDB_write_fluid_settings(sds, cache->writer);
+ OpenVDB_export_smoke(sds, cache->writer);
+ OpenVDBWriter_write(cache->writer, filename);
+
+ cache->cached_frames[framenr - cache->startframe] = 1;
+#else
+ UNUSED_VARS(cache, sds, ob, framnr);
+#endif
+}
+
static void smokeModifier_process_openvdb(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm)
{
SmokeDomainSettings *sds = smd->domain;
- OpenVDBCache *cache = BKE_openvdb_get_current_cache(sds);
+ OpenVDBCache *cache = BKE_openvdb_cache_current(sds);
int startframe, endframe, framenr;
framenr = scene->r.cfra;
- if (cache) {
+ if (cache != NULL) {
+ OpenVDBCache_validate_frames(cache, ob);
startframe = cache->startframe;
endframe = cache->endframe;
}
@@ -2768,14 +2837,14 @@ static void smokeModifier_process_openvdb(SmokeModifierData *smd, Scene *scene,
endframe = scene->r.efra;
}
- if (!smd->domain->fluid || framenr == startframe) {
+ if (!sds->fluid || framenr == startframe) {
smokeModifier_reset_ex(smd, false);
}
- if (!smd->domain->fluid && (framenr != startframe) && (smd->domain->flags & MOD_SMOKE_FILE_LOAD) == 0)
+ if (!sds->fluid && (framenr != startframe) && (sds->flags & MOD_SMOKE_FILE_LOAD) == 0)
return;
- smd->domain->flags &= ~MOD_SMOKE_FILE_LOAD;
+ sds->flags &= ~MOD_SMOKE_FILE_LOAD;
CLAMP(framenr, startframe, endframe);
/* If already viewing a pre/after frame, no need to reload */
@@ -2800,14 +2869,25 @@ static void smokeModifier_process_openvdb(SmokeModifierData *smd, Scene *scene,
return;
/* don't simulate if viewing start frame, but scene frame is not real start frame */
- if (framenr != scene->r.cfra)
+ if (framenr != scene->r.cfra) {
return;
+ }
+
+ /* if on second frame, write cache for first frame */
+ if ((cache != NULL) && (int)smd->time == startframe) {
+ bke_openvdb_cache_write_smoke(cache, sds, ob, startframe);
+ }
// set new time
smd->time = scene->r.cfra;
/* do simulation */
smokeModifier_step_simulation(smd, scene, ob, dm, framenr, startframe);
+
+ /* try to write cache */
+ if (cache != NULL) {
+ bke_openvdb_cache_write_smoke(cache, sds, ob, framenr);
+ }
}
static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm)
@@ -3183,7 +3263,7 @@ static void OpenVDB_read_fluid_settings(SmokeDomainSettings *sds, struct OpenVDB
OpenVDBReader_get_meta_mat4(reader, "obmat", sds->obmat);
}
-static void OpenVDB_write_fluid_settings(SmokeDomainSettings *sds, struct OpenVDBWriter *writer)
+void OpenVDB_write_fluid_settings(SmokeDomainSettings *sds, struct OpenVDBWriter *writer)
{
OpenVDBWriter_add_meta_int(writer, "active_fields", sds->active_fields);
OpenVDBWriter_add_meta_v3_int(writer, "resolution", sds->res);
@@ -3199,24 +3279,7 @@ static void OpenVDB_write_fluid_settings(SmokeDomainSettings *sds, struct OpenVD
OpenVDBWriter_add_meta_mat4(writer, "obmat", sds->obmat);
}
-void BKE_openvdb_cache_filename(char *r_filename, const char *path, const char *fname, const char *relbase, int frame)
-{
- char cachepath[FILE_MAX];
-
- BLI_strncpy(cachepath, path, FILE_MAX - 10);
- BLI_path_abs(cachepath, relbase);
-
- if (!BLI_exists(cachepath)) {
- BLI_dir_create_recursive(cachepath);
- }
-
- BLI_join_dirfile(r_filename, sizeof(cachepath), cachepath, fname);
- BLI_path_suffix(r_filename, FILE_MAX, "", "_");
- BLI_path_frame(r_filename, frame, 4);
- BLI_ensure_extension(r_filename, FILE_MAX, ".vdb");
-}
-
-static void OpenVDB_export_smoke(SmokeDomainSettings *sds, struct OpenVDBWriter *writer)
+void OpenVDB_export_smoke(SmokeDomainSettings *sds, struct OpenVDBWriter *writer)
{
int fluid_fields = smoke_get_data_flags(sds);
struct OpenVDBFloatGrid *clip_grid = NULL;
@@ -3283,7 +3346,7 @@ static void OpenVDB_export_smoke(SmokeDomainSettings *sds, struct OpenVDBWriter
}
}
-static void OpenVDB_import_smoke(SmokeDomainSettings *sds, struct OpenVDBReader *reader, bool for_display)
+static void OpenVDB_import_smoke(SmokeDomainSettings
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list