[Bf-extensions-cvs] [96fbb13] master: WIP: Very basic smoke export

Maurice Raybaud noreply at git.blender.org
Wed Feb 18 19:01:19 CET 2015


Commit: 96fbb13f49f8d4675337532e99edb384fce202cb
Author: Maurice Raybaud
Date:   Sat Feb 7 01:45:21 2015 +0100
Branches: master
https://developer.blender.org/rBA96fbb13f49f8d4675337532e99edb384fce202cb

WIP: Very basic smoke export

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

M	render_povray/df3.py
M	render_povray/render.py

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

diff --git a/render_povray/df3.py b/render_povray/df3.py
index 60b6e72..3005450 100644
--- a/render_povray/df3.py
+++ b/render_povray/df3.py
@@ -351,30 +351,30 @@ class df3:
         return tmp
 
 # -=-=-=- End df3 Class -=-=-=-
+##########DEFAULT EXAMPLES
+# if __name__ == '__main__':
+    # localX = 80
+    # localY = 90
+    # localZ = 100
+    ## Generate an output
+    # temp = df3(localX, localY, localZ)
+
+    # for i in range(localX):
+        # for j in range(localY):
+            # for k in range(localZ):
+                # if (i >= (localX/2)):
+                    # temp.set(i, j, k, 1.0)
+
+    # temp.exportDF3('temp.df3', 16)
+###############################################################################
+    ## Import
+    # temp2 = df3().importDF3('temp.df3')
+    # temp2.mult(1/temp2.max())
 
-if __name__ == '__main__':
-    localX = 80
-    localY = 90
-    localZ = 100
-    # Generate an output
-    temp = df3(localX, localY, localZ)
-
-    for i in range(localX):
-        for j in range(localY):
-            for k in range(localZ):
-                if (i >= (localX/2)):
-                    temp.set(i, j, k, 1.0)
-
-    temp.exportDF3('temp.df3', 16)
-
-    # Import
-    temp2 = df3().importDF3('temp.df3')
-    temp2.mult(1/temp2.max())
-
-    # Compare
-    print(temp2.size())
+    ## Compare
+    # print(temp2.size())
 
-    if (temp.compare(temp2) == 0): print("DF3's Do Not Match")
+    # if (temp.compare(temp2) == 0): print("DF3's Do Not Match")
 
 ###############################################################################
 # ChangeLog
diff --git a/render_povray/render.py b/render_povray/render.py
index 2af180b..043dbfd 100644
--- a/render_povray/render.py
+++ b/render_povray/render.py
@@ -29,6 +29,7 @@ import random
 import platform#
 import subprocess#
 from bpy.types import(Operator)#all added for render preview
+from . import df3 # for smoke rendering
 ##############################SF###########################
 ##############find image texture
 def imageFormat(imgF):
@@ -184,6 +185,13 @@ def renderable_objects():
 tabLevel = 0
 unpacked_images=[]
 
+workDir=os.path.dirname(__file__)      
+previewDir=os.path.join(workDir, "preview")
+## Make sure Preview directory exists and is empty
+if not os.path.isdir(previewDir):
+    os.mkdir(previewDir)
+smokePath = os.path.join(previewDir, "smoke.df3")
+    
 def exportPattern(texture):
     tex=texture
     pat = tex.pov
@@ -679,9 +687,9 @@ def write_pov(filename, scene=None, info_callback=None):
     else:
         print("Official POV-Ray 3.7 feature set chosen in preferences")
     if 'uber' in pov_binary: 
-        print("probably rendering with Uber POV binary")
+        print("The name of the binary suggests you are probably rendering with Uber POV engine")
     else:
-        print("probably rendering with standard POV binary")
+        print("The name of the binary suggests you are probably rendering with standard POV engine")
     def setTab(tabtype, spaces):
         TabStr = ""
         if tabtype == 'NONE':
@@ -1343,7 +1351,172 @@ def write_pov(filename, scene=None, info_callback=None):
                 # Data not yet processed, create a new entry in data_ref.
                 data_ref[dataname] = [(name, MatrixAsPovString(matrix))]
                 return dataname
-
+           
+             
+        def exportSmoke(smoke_obj_name):
+            #if LuxManager.CurrentScene.name == 'preview':
+                #return 1, 1, 1, 1.0
+            #else:
+            flowtype = -1
+            smoke_obj = bpy.data.objects[smoke_obj_name]
+            domain = None
+
+            # Search smoke domain target for smoke modifiers
+            for mod in smoke_obj.modifiers:
+                if mod.name == 'Smoke':
+                    if mod.smoke_type == 'FLOW':
+                        if mod.flow_settings.smoke_flow_type == 'BOTH':
+                            flowtype = 2
+                        else:
+                            if mod.flow_settings.smoke_flow_type == 'SMOKE':
+                                flowtype = 0
+                            else:
+                                if mod.flow_settings.smoke_flow_type == 'FIRE':
+                                    flowtype = 1
+
+                    if mod.smoke_type == 'DOMAIN':
+                        domain = smoke_obj
+                        smoke_modifier = mod
+
+            eps = 0.000001
+            if domain is not None:
+                #if bpy.app.version[0] >= 2 and bpy.app.version[1] >= 71:
+                # Blender version 2.71 supports direct access to smoke data structure
+                set = mod.domain_settings
+                channeldata = []
+                for v in set.density_grid:
+                    channeldata.append(v.real)
+                    print(v.real)
+                ## Usage en voxel texture:
+                # channeldata = []
+                # if channel == 'density':
+                    # for v in set.density_grid:
+                        # channeldata.append(v.real)
+
+                # if channel == 'fire':
+                    # for v in set.flame_grid:
+                        # channeldata.append(v.real)
+
+                resolution = set.resolution_max
+                big_res = []
+                big_res.append(set.domain_resolution[0])
+                big_res.append(set.domain_resolution[1])
+                big_res.append(set.domain_resolution[2])
+
+                if set.use_high_resolution:
+                    big_res[0] = big_res[0] * (set.amplify + 1)
+                    big_res[1] = big_res[1] * (set.amplify + 1)
+                    big_res[2] = big_res[2] * (set.amplify + 1)
+                # else:
+                    # p = []
+                    ##gather smoke domain settings
+                    # BBox = domain.bound_box
+                    # p.append([BBox[0][0], BBox[0][1], BBox[0][2]])
+                    # p.append([BBox[6][0], BBox[6][1], BBox[6][2]])
+                    # set = mod.domain_settings
+                    # resolution = set.resolution_max
+                    # smokecache = set.point_cache
+                    # ret = read_cache(smokecache, set.use_high_resolution, set.amplify + 1, flowtype)
+                    # res_x = ret[0]
+                    # res_y = ret[1]
+                    # res_z = ret[2]
+                    # density = ret[3]
+                    # fire = ret[4]
+
+                    # if res_x * res_y * res_z > 0:
+                        ##new cache format
+                        # big_res = []
+                        # big_res.append(res_x)
+                        # big_res.append(res_y)
+                        # big_res.append(res_z)
+                    # else:
+                        # max = domain.dimensions[0]
+                        # if (max - domain.dimensions[1]) < -eps:
+                            # max = domain.dimensions[1]
+
+                        # if (max - domain.dimensions[2]) < -eps:
+                            # max = domain.dimensions[2]
+
+                        # big_res = [int(round(resolution * domain.dimensions[0] / max, 0)),
+                                   # int(round(resolution * domain.dimensions[1] / max, 0)),
+                                   # int(round(resolution * domain.dimensions[2] / max, 0))]
+
+                    # if set.use_high_resolution:
+                        # big_res = [big_res[0] * (set.amplify + 1), big_res[1] * (set.amplify + 1),
+                                   # big_res[2] * (set.amplify + 1)]
+
+                    # if channel == 'density':
+                        # channeldata = density
+
+                    # if channel == 'fire':
+                        # channeldata = fire
+
+                        # sc_fr = '%s/%s/%s/%05d' % (efutil.export_path, efutil.scene_filename(), bpy.context.scene.name, bpy.context.scene.frame_current)
+                        #		        if not os.path.exists( sc_fr ):
+                        #			        os.makedirs(sc_fr)
+                        #
+                        #       		smoke_filename = '%s.smoke' % bpy.path.clean_name(domain.name)
+                        #	        	smoke_path = '/'.join([sc_fr, smoke_filename])
+                        #
+                        #		        with open(smoke_path, 'wb') as smoke_file:
+                        #			        # Binary densitygrid file format
+                        #			        #
+                        #			        # File header
+                        #	        		smoke_file.write(b'SMOKE')        #magic number
+                        #		        	smoke_file.write(struct.pack('<I', big_res[0]))
+                        #			        smoke_file.write(struct.pack('<I', big_res[1]))
+                        #       			smoke_file.write(struct.pack('<I', big_res[2]))
+                        # Density data
+                        #       			smoke_file.write(struct.pack('<%df'%len(channeldata), *channeldata))
+                        #
+                        #	        	LuxLog('Binary SMOKE file written: %s' % (smoke_path))
+
+        #return big_res[0], big_res[1], big_res[2], channeldata
+       
+                mydf3 = df3.df3(big_res[0],big_res[1],big_res[2])
+                for x in range(mydf3.sizeX()):
+                    for y in range(mydf3.sizeY()):
+                        for z in range(mydf3.sizeZ()):
+                            mydf3.set(x, y, z, channeldata[((z*mydf3.sizeY()+y)*mydf3.sizeX()+x)]) 
+
+                mydf3.exportDF3(smokePath)
+                print('Binary smoke.df3 file written in preview directory')
+                if comments:
+                    file.write("\n//--Smoke--\n\n")
+
+                # media container shape = blender domain
+                file.write("box{<0,0,0>, <%.4g, %.4g, %.4g>\n"% \
+                            (smoke_obj.dimensions[0], smoke_obj.dimensions[1], smoke_obj.dimensions[2]))
+                file.write("    translate <%.4g, %.4g, %.4g>\n"% \
+                            (smoke_obj.location[0], smoke_obj.location[1], smoke_obj.location[2]))
+                file.write("    pigment{ rgbt 1 }\n")
+                file.write("    hollow\n")
+            

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list