3 from math import atan, pi, degrees
9 import platform as pltfrm
11 if pltfrm.architecture()[0] == '64bit':
16 def write_pov(filename, scene=None, info_callback = None):
17 file = open(filename, 'w')
21 scene = bpy.data.scenes[0]
23 render = scene.render_data
26 # --- taken from fbx exporter
27 ## This was used to make V, but faster not to do all that
28 ##valid = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_,.()[]{}'
30 ##for c in valid: v.remove(ord(c))
31 v = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,42,43,46,47,58,59,60,61,62,63,64,92,94,96,124,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254]
32 invalid = ''.join([chr(i) for i in v])
34 for ch in invalid: name = name.replace(ch, '_')
38 # --- done with clean name.
40 def uniqueName(name, nameSeq):
42 if name not in nameSeq:
47 while name in nameSeq:
48 name = '%s_%.3d' % (name_orig, i)
54 def writeMatrix(matrix):
55 file.write('\tmatrix <%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f>\n' %\
56 (matrix[0][0], matrix[0][1], matrix[0][2], matrix[1][0], matrix[1][1], matrix[1][2], matrix[2][0], matrix[2][1], matrix[2][2], matrix[3][0], matrix[3][1], matrix[3][2]) )
58 def writeObjectMaterial(material):
59 if material and material.transparency_method=='RAYTRACE':
60 file.write('\tinterior { ior %.6f }\n' % material.raytrace_transparency.ior)
71 DEF_MAT_NAME = 'Default'
72 def writeMaterial(material):
73 # Assumes only called once on each material
76 name_orig = material.name
78 name_orig = DEF_MAT_NAME
80 name = materialNames[name_orig] = uniqueName(cleanName(name_orig), materialNames)
82 file.write('#declare %s = finish {\n' % name)
85 file.write('\tdiffuse %.3g\n' % material.diffuse_reflection)
86 file.write('\tspecular %.3g\n' % material.specular_reflection)
88 file.write('\tambient %.3g\n' % material.ambient)
89 #file.write('\tambient rgb <%.3g, %.3g, %.3g>\n' % tuple([c*material.ambient for c in world.ambient_color])) # povray blends the global value
91 # map hardness between 0.0 and 1.0
92 roughness = ((1.0 - ((material.specular_hardness-1.0)/510.0)))
93 # scale from 0.0 to 0.1
95 # add a small value because 0.0 is invalid
96 roughness += (1/511.0)
98 file.write('\troughness %.3g\n' % roughness)
102 if material.raytrace_mirror.enabled:
103 raytrace_mirror= material.raytrace_mirror
104 if raytrace_mirror.reflect:
105 file.write('\treflection {\n')
106 file.write('\t\trgb <%.3g, %.3g, %.3g>' % tuple(material.mirror_color))
107 file.write('\t\tfresnel 1 falloff %.3g exponent %.3g metallic %.3g} ' % (raytrace_mirror.fresnel, raytrace_mirror.fresnel_fac, raytrace_mirror.reflect))
110 file.write('\tdiffuse 0.8\n')
111 file.write('\tspecular 0.2\n')
115 # This is written into the object
117 if material and material.transparency_method=='RAYTRACE':
118 'interior { ior %.3g} ' % material.raytrace_transparency.ior
121 #file.write('\t\t\tcrand 1.0\n') # Sand granyness
122 #file.write('\t\t\tmetallic %.6f\n' % material.spec)
123 #file.write('\t\t\tphong %.6f\n' % material.spec)
124 #file.write('\t\t\tphong_size %.6f\n' % material.spec)
125 #file.write('\t\t\tbrilliance %.6f ' % (material.specular_hardness/256.0) # Like hardness
130 camera = scene.camera
131 matrix = camera.matrix
134 Qsize=float(render.resolution_x)/float(render.resolution_y)
136 file.write('camera {\n')
137 file.write('\tlocation <0, 0, 0>\n')
138 file.write('\tlook_at <0, 0, -1>\n')
139 file.write('\tright <%s, 0, 0>\n' % -Qsize)
140 file.write('\tup <0, 1, 0>\n')
141 file.write('\tangle %f \n' % (360.0*atan(16.0/camera.data.lens)/pi))
143 file.write('\trotate <%.6f, %.6f, %.6f>\n' % tuple([degrees(e) for e in matrix.rotationPart().toEuler()]))
144 file.write('\ttranslate <%.6f, %.6f, %.6f>\n' % (matrix[3][0], matrix[3][1], matrix[3][2]))
149 def exportLamps(lamps):
156 color = tuple([c * lamp.energy for c in lamp.color]) # Colour is modified by energy
158 file.write('light_source {\n')
159 file.write('\t< 0,0,0 >\n')
160 file.write('\tcolor rgb<%.3g, %.3g, %.3g>\n' % color)
162 if lamp.type == 'POINT': # Point Lamp
164 elif lamp.type == 'SPOT': # Spot
165 file.write('\tspotlight\n')
167 # Falloff is the main radius from the centre line
168 file.write('\tfalloff %.2f\n' % (lamp.spot_size/2.0) ) # 1 TO 179 FOR BOTH
169 file.write('\tradius %.6f\n' % ((lamp.spot_size/2.0) * (1-lamp.spot_blend)) )
171 # Blender does not have a tightness equivilent, 0 is most like blender default.
172 file.write('\ttightness 0\n') # 0:10f
174 file.write('\tpoint_at <0, 0, -1>\n')
175 elif lamp.type == 'SUN':
176 file.write('\tparallel\n')
177 file.write('\tpoint_at <0, 0, -1>\n') # *must* be after 'parallel'
179 elif lamp.type == 'AREA':
182 samples_x = lamp.shadow_ray_samples_x
183 if lamp.shape == 'SQUARE':
185 samples_y = samples_x
188 samples_y = lamp.shadow_ray_samples_y
192 file.write('\tarea_light <%d,0,0>,<0,0,%d> %d, %d\n' % (size_x, size_y, samples_x, samples_y))
193 if lamp.shadow_ray_sampling_method == 'CONSTANT_JITTERED':
195 file.write('\tjitter\n')
197 file.write('\tadaptive 1\n')
198 file.write('\tjitter\n')
200 if lamp.shadow_method == 'NOSHADOW':
201 file.write('\tshadowless\n')
203 file.write('\tfade_distance %.6f\n' % lamp.distance)
204 file.write('\tfade_power %d\n' % 1) # Could use blenders lamp quad?
209 def exportMeta(metas):
211 # TODO - blenders 'motherball' naming is not supported.
216 file.write('blob {\n')
217 file.write('\t\tthreshold %.4g\n' % meta.threshold)
220 material= meta.materials[0] # lame! - blender cant do enything else.
224 for elem in meta.elements:
226 if elem.type not in ('BALL', 'ELLIPSOID'):
227 continue # Not supported
231 stiffness= elem.stiffness
233 stiffness = -stiffness
235 if elem.type == 'BALL':
237 file.write('\tsphere { <%.6g, %.6g, %.6g>, %.4g, %.4g ' % (loc.x, loc.y, loc.z, elem.radius, stiffness))
239 # After this wecould do something simple like...
241 # except we'll write the color
243 elif elem.type == 'ELLIPSOID':
244 # location is modified by scale
245 file.write('\tsphere { <%.6g, %.6g, %.6g>, %.4g, %.4g ' % (loc.x/elem.size_x, loc.y/elem.size_y, loc.z/elem.size_z, elem.radius, stiffness))
246 file.write( 'scale <%.6g, %.6g, %.6g> ' % (elem.size_x, elem.size_y, elem.size_z))
249 diffuse_color = material.diffuse_color
251 if material.transparency and material.transparency_method=='RAYTRACE': trans = 1-material.raytrace_transparency.filter
255 'pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>} finish {%s} }\n' % \
256 (diffuse_color[0], diffuse_color[1], diffuse_color[2], 1-material.alpha, trans, materialNames[material.name])
260 file.write('pigment {rgb<1 1 1>} finish {%s} }\n' % DEF_MAT_NAME) # Write the finish last.
262 writeObjectMaterial(material)
264 writeMatrix(ob.matrix)
271 def exportMeshs(sel):
278 if ob.type in ('LAMP', 'CAMERA', 'EMPTY'):
282 me_materials= me.materials
284 me = ob.create_render_mesh(scene)
290 info_callback('Object %2.d of %2.d (%s)' % (ob_num, len(sel), ob.name))
297 try: uv_layer = me.active_uv_texture.data
298 except:uv_layer = None
300 try: vcol_layer = me.active_vertex_color.data
301 except:vcol_layer = None
307 return fv[0], fv[1], fv[2]
308 return fv[0], fv[1], fv[2], fv[3]
310 faces_verts = [regular_face(f) for f in me.faces]
311 faces_normals = [tuple(f.normal) for f in me.faces]
312 verts_normals = [tuple(v.normal) for v in me.verts]
314 # quads incur an extra face
315 quadCount = len([f for f in faces_verts if len(f)==4])
317 file.write('mesh2 {\n')
318 file.write('\tvertex_vectors {\n')
319 file.write('\t\t%s' % (len(me.verts))) # vert count
321 file.write(',\n\t\t<%.6f, %.6f, %.6f>' % tuple(v.co)) # vert count
325 # Build unique Normal list
327 for fi, f in enumerate(me.faces):
329 # [-1] is a dummy index, use a list so we can modify in place
330 if f.smooth: # Use vertex normals
332 key = verts_normals[v]
333 uniqueNormals[key] = [-1]
334 else: # Use face normal
335 key = faces_normals[fi]
336 uniqueNormals[key] = [-1]
338 file.write('\tnormal_vectors {\n')
339 file.write('\t\t%d' % len(uniqueNormals)) # vert count
341 for no, index in uniqueNormals.items():
342 file.write(',\n\t\t<%.6f, %.6f, %.6f>' % no) # vert count
349 vertCols = {} # Use for material colours also.
352 # Generate unique UV's
355 for fi, uv in enumerate(uv_layer):
357 if len(faces_verts[fi])==4:
358 uvs = uv.uv1, uv.uv2, uv.uv3, uv.uv4
360 uvs = uv.uv1, uv.uv2, uv.uv3
363 uniqueUVs[tuple(uv)] = [-1]
365 file.write('\tuv_vectors {\n')
367 file.write('\t\t%s' % (len(uniqueUVs))) # vert count
369 for uv, index in uniqueUVs.items():
370 file.write(',\n\t\t<%.6f, %.6f>' % uv)
375 # Just add 1 dummy vector, no real UV's
376 file.write('\t\t1') # vert count
377 file.write(',\n\t\t<0.0, 0.0>')
384 for fi, f in enumerate(me.faces):
385 material_index = f.material_index
386 material = me_materials[material_index]
388 if material and material.vertex_color_paint:
392 if len(faces_verts[fi])==4:
393 cols = col.color1, col.color2, col.color3, col.color4
395 cols = col.color1, col.color2, col.color3
398 key = col[0], col[1], col[2], material_index # Material index!
403 diffuse_color = tuple(material.diffuse_color)
404 key = diffuse_color[0], diffuse_color[1], diffuse_color[2], material_index
409 # No vertex colours, so write material colours as vertex colours
410 for i, material in enumerate(me_materials):
413 diffuse_color = tuple(material.diffuse_color)
414 key = diffuse_color[0], diffuse_color[1], diffuse_color[2], i # i == f.mat
419 file.write('\ttexture_list {\n')
420 file.write('\t\t%s' % (len(vertCols))) # vert count
422 for col, index in vertCols.items():
425 material = me_materials[col[3]]
426 material_finish = materialNames[material.name]
428 if material.transparency and material.transparency_method=='RAYTRACE': trans = 1-material.raytrace_transparency.filter
432 material_finish = DEF_MAT_NAME # not working properly,
436 file.write( ',\n\t\ttexture { pigment {rgbft<%.3g, %.3g, %.3g, %.3g, %.3g>} finish {%s}}' %
437 (col[0], col[1], col[2], 1-material.alpha, trans, material_finish) )
442 file.write( '\n }\n' )
445 file.write('\tface_indices {\n')
446 file.write('\t\t%d' % (len(me.faces) + quadCount)) # faces count
447 for fi, f in enumerate(me.faces):
449 material_index= f.material_index
450 if len(fv) == 4: indicies = (0,1,2), (0,2,3)
451 else: indicies = ((0,1,2),)
457 cols = col.color1, col.color2, col.color3, col.color4
459 cols = col.color1, col.color2, col.color3
462 if not me_materials or me_materials[material_index] == None: # No materials
463 for i1, i2, i3 in indicies:
464 file.write(',\n\t\t<%d,%d,%d>' % (fv[i1], fv[i2], fv[i3])) # vert count
466 material = me_materials[material_index]
467 for i1, i2, i3 in indicies:
468 if me.vertex_colors and material.vertex_color_paint:
469 # Colour per vertex - vertex colour
475 ci1 = vertCols[col1[0], col1[1], col1[2], material_index][0]
476 ci2 = vertCols[col2[0], col2[1], col2[2], material_index][0]
477 ci3 = vertCols[col3[0], col3[1], col3[2], material_index][0]
479 # Colour per material - flat material colour
480 diffuse_color= material.diffuse_color
481 ci1 = ci2 = ci3 = vertCols[diffuse_color[0], diffuse_color[1], diffuse_color[2], f.material_index][0]
483 file.write(',\n\t\t<%d,%d,%d>, %d,%d,%d' % (fv[i1], fv[i2], fv[i3], ci1, ci2, ci3)) # vert count
489 # normal_indices indicies
490 file.write('\tnormal_indices {\n')
491 file.write('\t\t%d' % (len(me.faces) + quadCount)) # faces count
492 for fi, fv in enumerate(faces_verts):
494 if len(fv) == 4: indicies = (0,1,2), (0,2,3)
495 else: indicies = ((0,1,2),)
497 for i1, i2, i3 in indicies:
499 file.write(',\n\t\t<%d,%d,%d>' %\
500 (uniqueNormals[verts_normals[fv[i1]]][0],\
501 uniqueNormals[verts_normals[fv[i2]]][0],\
502 uniqueNormals[verts_normals[fv[i3]]][0])) # vert count
504 idx = uniqueNormals[faces_normals[fi]][0]
505 file.write(',\n\t\t<%d,%d,%d>' % (idx, idx, idx)) # vert count
510 file.write('\tuv_indices {\n')
511 file.write('\t\t%d' % (len(me.faces) + quadCount)) # faces count
512 for fi, fv in enumerate(faces_verts):
514 if len(fv) == 4: indicies = (0,1,2), (0,2,3)
515 else: indicies = ((0,1,2),)
518 if len(faces_verts[fi])==4:
519 uvs = tuple(uv.uv1), tuple(uv.uv2), tuple(uv.uv3), tuple(uv.uv4)
521 uvs = tuple(uv.uv1), tuple(uv.uv2), tuple(uv.uv3)
523 for i1, i2, i3 in indicies:
524 file.write(',\n\t\t<%d,%d,%d>' %\
525 (uniqueUVs[uvs[i1]][0],\
526 uniqueUVs[uvs[i2]][0],\
527 uniqueUVs[uvs[i2]][0])) # vert count
531 material = me.materials[0] # dodgy
532 writeObjectMaterial(material)
537 bpy.data.remove_mesh(me)
539 def exportWorld(world):
546 file.write('fog {\n')
547 file.write('\tdistance %.6f\n' % mist.depth)
548 file.write('\tcolor rgbt<%.3g, %.3g, %.3g, %.3g>\n' % (tuple(world.horizon_color) + (1-mist.intensity,)))
549 #file.write('\tfog_offset %.6f\n' % mist.start)
550 #file.write('\tfog_alt 5\n')
551 #file.write('\tturbulence 0.2\n')
552 #file.write('\tturb_depth 0.3\n')
553 file.write('\tfog_type 1\n')
556 def exportGlobalSettings(scene):
558 file.write('global_settings {\n')
560 if scene.pov_radio_enable:
561 file.write('\tradiosity {\n')
562 file.write("\t\tadc_bailout %.4g\n" % scene.pov_radio_adc_bailout)
563 file.write("\t\talways_sample %d\n" % scene.pov_radio_always_sample)
564 file.write("\t\tbrightness %.4g\n" % scene.pov_radio_brightness)
565 file.write("\t\tcount %d\n" % scene.pov_radio_count)
566 file.write("\t\terror_bound %.4g\n" % scene.pov_radio_error_bound)
567 file.write("\t\tgray_threshold %.4g\n" % scene.pov_radio_gray_threshold)
568 file.write("\t\tlow_error_factor %.4g\n" % scene.pov_radio_low_error_factor)
569 file.write("\t\tmedia %d\n" % scene.pov_radio_media)
570 file.write("\t\tminimum_reuse %.4g\n" % scene.pov_radio_minimum_reuse)
571 file.write("\t\tnearest_count %d\n" % scene.pov_radio_nearest_count)
572 file.write("\t\tnormal %d\n" % scene.pov_radio_normal)
573 file.write("\t\trecursion_limit %d\n" % scene.pov_radio_recursion_limit)
577 file.write("\tambient_light rgb<%.3g, %.3g, %.3g>\n" % tuple(world.ambient_color))
582 # Convert all materials to strings we can access directly per vertex.
583 writeMaterial(None) # default material
585 for material in bpy.data.materials:
586 writeMaterial(material)
591 exportLamps([l for l in sel if l.type == 'LAMP'])
592 exportMeta([l for l in sel if l.type == 'META'])
594 exportWorld(scene.world)
595 exportGlobalSettings(scene)
600 def write_pov_ini(filename_ini, filename_pov, filename_image):
601 scene = bpy.data.scenes[0]
602 render = scene.render_data
604 x= int(render.resolution_x*render.resolution_percentage*0.01)
605 y= int(render.resolution_y*render.resolution_percentage*0.01)
607 file = open(filename_ini, 'w')
609 file.write('Input_File_Name="%s"\n' % filename_pov)
610 file.write('Output_File_Name="%s"\n' % filename_image)
612 file.write('Width=%d\n' % x)
613 file.write('Height=%d\n' % y)
615 # Needed for border render.
617 file.write('Start_Column=%d\n' % part.x)
618 file.write('End_Column=%d\n' % (part.x+part.w))
620 file.write('Start_Row=%d\n' % (part.y))
621 file.write('End_Row=%d\n' % (part.y+part.h))
624 file.write('Display=0\n')
625 file.write('Pause_When_Done=0\n')
626 file.write('Output_File_Type=C\n') # TGA, best progressive loading
627 file.write('Output_Alpha=1\n')
629 if render.antialiasing:
630 aa_mapping = {'OVERSAMPLE_5':2, 'OVERSAMPLE_8':3, 'OVERSAMPLE_11':4, 'OVERSAMPLE_16':5} # method 1 assumed
631 file.write('Antialias=1\n')
632 file.write('Antialias_Depth=%d\n' % aa_mapping[render.antialiasing_samples])
634 file.write('Antialias=0\n')
638 # Radiosity panel, use in the scene for now.
639 FloatProperty= bpy.types.Scene.FloatProperty
640 IntProperty= bpy.types.Scene.IntProperty
641 BoolProperty= bpy.types.Scene.BoolProperty
643 # Not a real pov option, just to know if we should write
644 BoolProperty( attr="pov_radio_enable",
645 name="Enable Radiosity",
646 description="Enable povrays radiosity calculation.",
648 BoolProperty( attr="pov_radio_display_advanced",
649 name="Advanced Options",
650 description="Show advanced options.",
654 FloatProperty( attr="pov_radio_adc_bailout",
656 description="The adc_bailout for radiosity rays. Use adc_bailout = 0.01 / brightest_ambient_object for good results.",
657 min=0.0, max=1000.0, soft_min=0.0, soft_max=1.0, default= 0.01)
659 BoolProperty( attr="pov_radio_always_sample",
660 name="Always Sample",
661 description="Only use the data from the pretrace step and not gather any new samples during the final radiosity pass..",
664 FloatProperty( attr="pov_radio_brightness",
666 description="Ammount objects are brightened before being returned upwards to the rest of the system.",
667 min=0.0, max=1000.0, soft_min=0.0, soft_max=10.0, default= 1.0)
669 IntProperty( attr="pov_radio_count",
671 description="number of rays that are sent out whenever a new radiosity value has to be calculated.",
672 min=1, max=1600, default= 35)
674 FloatProperty( attr="pov_radio_error_bound",
676 description="one of the two main speed/quality tuning values, lower values are more accurate.",
677 min=0.0, max=1000.0, soft_min=0.1, soft_max=10.0, default= 1.8)
679 FloatProperty( attr="pov_radio_gray_threshold",
680 name="Gray Threshold",
681 description="one of the two main speed/quality tuning values, lower values are more accurate.",
682 min=0.0, max=1.0, soft_min=0, soft_max=1, default= 0.0)
684 FloatProperty( attr="pov_radio_low_error_factor",
685 name="Low Error Factor",
686 description="If you calculate just enough samples, but no more, you will get an image which has slightly blotchy lighting.",
687 min=0.0, max=1.0, soft_min=0.0, soft_max=1.0, default= 0.5)
689 # max_sample - not available yet
690 BoolProperty( attr="pov_radio_media",
692 description="Radiosity estimation can be affected by media.",
695 FloatProperty( attr="pov_radio_minimum_reuse",
696 name="Minimum Reuse",
697 description="Fraction of the screen width which sets the minimum radius of reuse for each sample point (At values higher than 2% expect errors).",
698 min=0.0, max=1.0, soft_min=0.1, soft_max=0.1, default= 0.015)
700 IntProperty( attr="pov_radio_nearest_count",
701 name="Nearest Count",
702 description="Number of old ambient values blended together to create a new interpolated value.",
703 min=1, max=20, default= 5)
705 BoolProperty( attr="pov_radio_normal",
707 description="Radiosity estimation can be affected by normals.",
710 IntProperty( attr="pov_radio_recursion_limit",
711 name="Recursion Limit",
712 description="how many recursion levels are used to calculate the diffuse inter-reflection.",
713 min=1, max=20, default= 3)
716 class PovrayRender(bpy.types.RenderEngine):
717 __idname__ = 'POVRAY_RENDER'
721 def _export(self, scene):
724 self.temp_file_in = tempfile.mktemp(suffix='.pov')
725 self.temp_file_out = tempfile.mktemp(suffix='.tga')
726 self.temp_file_ini = tempfile.mktemp(suffix='.ini')
728 self.temp_file_in = '/test.pov'
729 self.temp_file_out = '/test.tga'
730 self.temp_file_ini = '/test.ini'
733 def info_callback(txt):
734 self.update_stats("", "POVRAY: " + txt)
736 write_pov(self.temp_file_in, scene, info_callback)
740 try: os.remove(self.temp_file_out) # so as not to load the old file
743 write_pov_ini(self.temp_file_ini, self.temp_file_in, self.temp_file_out)
745 print ("***-STARTING-***")
747 pov_binary = "povray"
749 if sys.platform=='win32':
751 pov_binary = "pvengine64"
753 pov_binary = "pvengine"
756 self.process = subprocess.Popen([pov_binary, self.temp_file_ini]) # stdout=subprocess.PIPE, stderr=subprocess.PIPE
758 # This works too but means we have to wait until its done
759 os.system('%s %s' % (pov_binary, self.temp_file_ini))
761 print ("***-DONE-***")
764 for f in (self.temp_file_in, self.temp_file_ini, self.temp_file_out):
768 self.update_stats("", "")
770 def render(self, scene):
772 self.update_stats("", "POVRAY: Exporting data from Blender")
774 self.update_stats("", "POVRAY: Parsing File")
777 r = scene.render_data
780 x= int(r.resolution_x*r.resolution_percentage*0.01)
781 y= int(r.resolution_y*r.resolution_percentage*0.01)
785 # Wait for the file to be created
786 while not os.path.exists(self.temp_file_out):
787 if self.test_break():
788 try: self.process.terminate()
792 if self.process.poll() != None:
793 self.update_stats("", "POVRAY: Failed")
796 time.sleep(self.DELAY)
798 if os.path.exists(self.temp_file_out):
800 self.update_stats("", "POVRAY: Rendering")
805 result = self.begin_result(0, 0, x, y)
806 lay = result.layers[0]
807 # possible the image wont load early on.
808 try: lay.load_from_file(self.temp_file_out)
810 self.end_result(result)
812 # Update while povray renders
815 # test if povray exists
816 if self.process.poll() != None:
821 if self.test_break():
822 try: self.process.terminate()
827 # Would be nice to redirect the output
828 # stdout_value, stderr_value = self.process.communicate() # locks
831 # check if the file updated
832 new_size = os.path.getsize(self.temp_file_out)
834 if new_size != prev_size:
838 time.sleep(self.DELAY)
842 bpy.types.register(PovrayRender)
844 # Use some of the existing buttons.
846 buttons_scene.SCENE_PT_render.COMPAT_ENGINES.add('POVRAY_RENDER')
847 buttons_scene.SCENE_PT_dimensions.COMPAT_ENGINES.add('POVRAY_RENDER')
848 buttons_scene.SCENE_PT_antialiasing.COMPAT_ENGINES.add('POVRAY_RENDER')
849 buttons_scene.SCENE_PT_output.COMPAT_ENGINES.add('POVRAY_RENDER')
852 # Use only a subset of the world panels
854 buttons_world.WORLD_PT_preview.COMPAT_ENGINES.add('POVRAY_RENDER')
855 buttons_world.WORLD_PT_context_world.COMPAT_ENGINES.add('POVRAY_RENDER')
856 buttons_world.WORLD_PT_world.COMPAT_ENGINES.add('POVRAY_RENDER')
857 buttons_world.WORLD_PT_mist.COMPAT_ENGINES.add('POVRAY_RENDER')
860 # Example of wrapping every class 'as is'
861 import buttons_material
862 for member in dir(buttons_material):
863 subclass = getattr(buttons_material, member)
864 try: subclass.COMPAT_ENGINES.add('POVRAY_RENDER')
868 class RenderButtonsPanel(bpy.types.Panel):
869 __space_type__ = 'PROPERTIES'
870 __region_type__ = 'WINDOW'
871 __context__ = "scene"
872 # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
874 def poll(self, context):
875 rd = context.scene.render_data
876 return (rd.use_game_engine==False) and (rd.engine in self.COMPAT_ENGINES)
878 class SCENE_PT_povray_radiosity(RenderButtonsPanel):
879 __label__ = "Radiosity"
880 COMPAT_ENGINES = set(['POVRAY_RENDER'])
882 def draw_header(self, context):
884 scene = context.scene
885 layout.itemR(scene, "pov_radio_enable", text="")
887 def draw(self, context):
889 scene = context.scene
890 rd = scene.render_data
892 layout.active = scene.pov_radio_enable
894 split = layout.split()
898 col.itemR(scene, "pov_radio_count", text="Rays")
899 col.itemR(scene, "pov_radio_recursion_limit", text="Recursions")
901 col.itemR(scene, "pov_radio_error_bound", text="Error")
903 layout.itemR(scene, "pov_radio_display_advanced")
905 if scene.pov_radio_display_advanced:
906 split = layout.split()
909 col.itemR(scene, "pov_radio_adc_bailout", slider=True)
910 col.itemR(scene, "pov_radio_gray_threshold", slider=True)
911 col.itemR(scene, "pov_radio_low_error_factor", slider=True)
916 col.itemR(scene, "pov_radio_brightness")
917 col.itemR(scene, "pov_radio_minimum_reuse", text="Min Reuse")
918 col.itemR(scene, "pov_radio_nearest_count")
921 split = layout.split()
924 col.itemL(text="Estimation Influence:")
925 col.itemR(scene, "pov_radio_media")
926 col.itemR(scene, "pov_radio_normal")
929 col.itemR(scene, "pov_radio_always_sample")
932 bpy.types.register(SCENE_PT_povray_radiosity)