[Bf-blender-cvs] [df67565] openvdb: User feedback: merge pointcache and openvdb cache panel together so it's easier to work with, and avoids potential issues between vdb and point caches.

Kévin Dietrich noreply at git.blender.org
Sun Aug 2 19:07:55 CEST 2015


Commit: df67565ae00361dce89c192da7dc4d285388fab8
Author: Kévin Dietrich
Date:   Sun Aug 2 19:08:55 2015 +0200
Branches: openvdb
https://developer.blender.org/rBdf67565ae00361dce89c192da7dc4d285388fab8

User feedback: merge pointcache and openvdb cache panel together so it's
easier to work with, and avoids potential issues between vdb and point
caches.

Also finally separate the pointcache and openvdb cache code for the
smokeModifier_process function.

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

M	release/scripts/startup/bl_ui/properties_physics_smoke.py
M	source/blender/blenkernel/intern/smoke.c
M	source/blender/makesdna/DNA_smoke_types.h
M	source/blender/makesrna/intern/rna_smoke.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_smoke.py b/release/scripts/startup/bl_ui/properties_physics_smoke.py
index e6cb674..8e0ffb1 100644
--- a/release/scripts/startup/bl_ui/properties_physics_smoke.py
+++ b/release/scripts/startup/bl_ui/properties_physics_smoke.py
@@ -291,28 +291,6 @@ class PHYSICS_PT_smoke_groups(PhysicButtonsPanel, Panel):
         col.prop(domain, "collision_group", text="")
 
 
-class PHYSICS_PT_smoke_cache(PhysicButtonsPanel, Panel):
-    bl_label = "Smoke Cache"
-    bl_options = {'DEFAULT_CLOSED'}
-
-    @classmethod
-    def poll(cls, context):
-        md = context.smoke
-        rd = context.scene.render
-        return md and (md.smoke_type == 'DOMAIN') and (not rd.use_game_engine)
-
-    def draw(self, context):
-        layout = self.layout
-
-        md = context.smoke.domain_settings
-        cache = md.point_cache
-
-        layout.label(text="Compression:")
-        layout.prop(md, "point_cache_compress_type", expand=True)
-
-        point_cache_ui(self, context, cache, (cache.is_baked is False), 'SMOKE')
-
-
 class DATA_UL_openvdb_caches(UIList):
     def draw_items(self, context, layout, item, icon, active_data, active_propname, index):
         if self.layout_type in {'DEFAULT', 'COMPACT'}:
@@ -322,8 +300,8 @@ class DATA_UL_openvdb_caches(UIList):
             layout.label(text="", icon_value=icon)
 
 
-class PHYSICS_PT_smoke_openvdb(PhysicButtonsPanel, Panel):
-    bl_label = "OpenVDB export"
+class PHYSICS_PT_smoke_cache(PhysicButtonsPanel, Panel):
+    bl_label = "Smoke Cache"
     bl_options = {'DEFAULT_CLOSED'}
 
     @classmethod
@@ -332,46 +310,50 @@ class PHYSICS_PT_smoke_openvdb(PhysicButtonsPanel, Panel):
         rd = context.scene.render
         return md and (md.smoke_type == 'DOMAIN') and (not rd.use_game_engine)
 
-    def draw_header(self, context):
+    def draw(self, context):
         layout = self.layout
+
         domain = context.smoke.domain_settings
-        layout.prop(domain, "use_openvdb", text="")
+        cache_type = domain.cache_type
 
-    def draw(self, context):
-        layout = self.layout
+        layout.prop(domain, "cache_type")
 
-        if not bpy.app.build_options.openvdb:
-            layout.label("Build without OpenVDB support.")
-            return
+        if cache_type in {'POINTCACHE'}:
+            cache = domain.point_cache
 
-        domain = context.smoke.domain_settings
-        layout.active = domain.use_openvdb
-
-        row = layout.row()
-        row.template_list("DATA_UL_openvdb_caches", "", domain, "cache", domain, "active_openvdb_cache_index", rows=3)
-
-        col = row.column()
-        sub = col.row()
-        subsub = sub.column(align=True)
-        subsub.operator("object.openvdb_cache_add", icon='ZOOMIN', text="")
-        subsub.operator("object.openvdb_cache_remove", icon='ZOOMOUT', text="")
-        sub = col.row()
-        subsub = sub.column(align=True)
-        subsub.operator("object.openvdb_cache_move", icon='MOVE_UP_VEC', text="").direction = 'UP'
-        subsub.operator("object.openvdb_cache_move", icon='MOVE_DOWN_VEC', text="").direction = 'DOWN'
-
-        cache = domain.active_openvdb_cache
-
-        if cache:
-            layout.prop(cache, "filepath")
-            layout.prop(cache, "compression")
-            row = layout.row(align=True)
-            row.prop(cache, "frame_start")
-            row.prop(cache, "frame_end")
-            row = layout.row()
-            row.prop(cache, "save_as_half")
+            layout.label(text="Compression:")
+            layout.prop(domain, "point_cache_compress_type", expand=True)
+
+            point_cache_ui(self, context, cache, (cache.is_baked is False), 'SMOKE')
+        elif cache_type in {'OPENVDB'}:
+            if not bpy.app.build_options.openvdb:
+                layout.label("Build without OpenVDB support.")
+                return
 
-        layout.operator("object.smoke_vdb_export")
+            row = layout.row()
+            row.template_list("DATA_UL_openvdb_caches", "", domain, "cache", domain, "active_openvdb_cache_index", rows=3)
+
+            col = row.column()
+            sub = col.row()
+            subsub = sub.column(align=True)
+            subsub.operator("object.openvdb_cache_add", icon='ZOOMIN', text="")
+            subsub.operator("object.openvdb_cache_remove", icon='ZOOMOUT', text="")
+            sub = col.row()
+            subsub = sub.column(align=True)
+            subsub.operator("object.openvdb_cache_move", icon='MOVE_UP_VEC', text="").direction = 'UP'
+            subsub.operator("object.openvdb_cache_move", icon='MOVE_DOWN_VEC', text="").direction = 'DOWN'
+
+            cache = domain.active_openvdb_cache
+
+            if cache:
+                layout.prop(cache, "filepath")
+                layout.prop(cache, "compression")
+                row = layout.row(align=True)
+                row.prop(cache, "frame_start")
+                row.prop(cache, "frame_end")
+                row = layout.row()
+                row.prop(cache, "save_as_half")
+                layout.operator("object.smoke_vdb_export", text="Bake")
 
 
 class PHYSICS_PT_smoke_field_weights(PhysicButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 55089f0..90c17aa 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -579,7 +579,7 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
 			smd->domain->viewsettings = MOD_SMOKE_VIEW_SHOWBIG;
 			smd->domain->effector_weights = BKE_add_effector_weights(NULL);
 
-			smd->domain->use_openvdb = false;
+			smd->domain->cache_type = SMOKE_CACHE_POINTCACHE;
 		}
 		else if (smd->type & MOD_SMOKE_TYPE_FLOW)
 		{
@@ -2657,6 +2657,168 @@ static DerivedMesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob)
 	return result;
 }
 
+/* simulate the actual smoke (c++ code in intern/smoke) */
+static void smokeModifier_step_simulation(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm, bool for_render, const int framenr, const int startframe)
+{
+	SmokeDomainSettings *sds = smd->domain;
+
+	/* DG: interesting commenting this + deactivating loading of noise files */
+	if (framenr != startframe){
+		if (sds->flags & MOD_SMOKE_DISSOLVE) {
+			/* low res dissolve */
+			smoke_dissolve(sds->fluid, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG);
+			/* high res dissolve */
+			if (sds->wt) {
+				smoke_dissolve_wavelet(sds->wt, sds->diss_speed, sds->flags & MOD_SMOKE_DISSOLVE_LOG);
+			}
+		}
+
+		step(scene, ob, smd, dm, scene->r.frs_sec / scene->r.frs_sec_base, for_render);
+	}
+
+	/* create shadows before writing cache so they get stored */
+	smoke_calc_transparency(sds, scene);
+
+	if (sds->wt) {
+		smoke_turbulence_step(sds->wt, sds->fluid);
+	}
+}
+
+static void smokeModifier_process_pointcache(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm, bool for_render)
+{
+	SmokeDomainSettings *sds = smd->domain;
+	PointCache *cache = NULL;
+	PTCacheID pid;
+	int startframe, endframe, framenr;
+	float timescale;
+
+	framenr = scene->r.cfra;
+
+	//printf("time: %d\n", scene->r.cfra);
+
+	cache = sds->point_cache[0];
+	BKE_ptcache_id_from_smoke(&pid, ob, smd);
+	BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, &timescale);
+
+	if (!smd->domain->fluid || framenr == startframe)
+	{
+		BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
+		smokeModifier_reset_ex(smd, false);
+		BKE_ptcache_validate(cache, framenr);
+		cache->flag &= ~PTCACHE_REDO_NEEDED;
+	}
+
+	if (!smd->domain->fluid && (framenr != startframe) && (smd->domain->flags & MOD_SMOKE_FILE_LOAD) == 0 && (cache->flag & PTCACHE_BAKED) == 0)
+		return;
+
+	smd->domain->flags &= ~MOD_SMOKE_FILE_LOAD;
+	CLAMP(framenr, startframe, endframe);
+
+	/* If already viewing a pre/after frame, no need to reload */
+	if ((smd->time == framenr) && (framenr != scene->r.cfra))
+		return;
+
+	if (smokeModifier_init(smd, ob, scene, dm) == 0)
+	{
+		printf("bad smokeModifier_init\n");
+		return;
+	}
+
+	/* try to read from cache */
+	if ((BKE_ptcache_read(&pid, (float)framenr) == PTCACHE_READ_EXACT)) {
+		BKE_ptcache_validate(cache, framenr);
+		smd->time = framenr;
+		return;
+	}
+
+	/* only calculate something when we advanced a single frame */
+	if (framenr != (int)smd->time + 1)
+		return;
+
+	/* don't simulate if viewing start frame, but scene frame is not real start frame */
+	if (framenr != scene->r.cfra)
+		return;
+
+	tstart();
+
+	/* if on second frame, write cache for first frame */
+	if ((int)smd->time == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0)) {
+		BKE_ptcache_write(&pid, startframe);
+	}
+
+	// set new time
+	smd->time = scene->r.cfra;
+
+	/* do simulation */
+	smokeModifier_step_simulation(smd, scene, ob, dm, for_render, framenr, startframe);
+
+	BKE_ptcache_validate(cache, framenr);
+	if (framenr != startframe)
+		BKE_ptcache_write(&pid, framenr);
+
+	tend();
+	// printf ( "Frame: %d, Time: %f\n\n", (int)smd->time, (float) tval() );
+}
+
+static void smokeModifier_process_openvdb(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm, bool for_render)
+{
+	SmokeDomainSettings *sds = smd->domain;
+	OpenVDBCache *cache = cache = BKE_openvdb_get_current_cache(sds);
+	int startframe, endframe, framenr;
+
+	framenr = scene->r.cfra;
+
+	if (cache) {
+		startframe = cache->startframe;
+		endframe = cache->endframe;
+	}
+	else {
+		startframe = scene->r.sfra;
+		endframe = scene->r.efra;
+	}
+
+	if (!smd->domain->fluid || framenr == startframe) {
+		smokeModifier_reset_ex(smd, false);
+	}
+
+	if (!smd->domain->fluid && (framenr != startframe) && (smd->domain->flags & MOD_SMOKE_FILE_LOAD) == 0)
+		return;
+
+	smd->domain->flags &= ~MOD_SMOKE_FILE_LOAD;
+	CLAMP(framenr, startframe, endframe);
+
+	/* If already viewing a pre/after frame, no need to reload */
+	if ((smd->time == framenr) && (framenr != scene->r.cfra))
+		return;
+
+	if (smokeModifier_init(smd, ob, scene, dm) == 0) {
+		printf("bad smokeModifier_init\n");
+		return;
+	}
+
+	/* try to read from cache */
+	if (cache != NULL) {
+		if (smokeModifier_OpenVDB_import(smd, scene, ob

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list