Newer
Older
except RuntimeError:
print("***POV ERROR WHILE READING OUTPUT FILE***")
# Not needed right now, might only be useful if we find a way to use temp raw output of
# pov 3.7 (in which case it might go under _test_wait()).
Campbell Barton
committed
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
'''
def update_image():
# possible the image wont load early on.
try:
lay.load_from_file(self._temp_file_out)
# XXX, tests for border render.
#lay.load_from_file(self._temp_file_out, xmin, ymin)
#lay.load_from_file(self._temp_file_out, xmin, ymin)
except RuntimeError:
pass
# Update while POV-Ray renders
while True:
# print("***POV RENDER LOOP***")
# test if POV-Ray exists
if self._process.poll() is not None:
print("***POV PROCESS FINISHED***")
update_image()
break
# user exit
if self.test_break():
try:
self._process.terminate()
print("***POV PROCESS INTERRUPTED***")
except OSError:
pass
break
# Would be nice to redirect the output
# stdout_value, stderr_value = self._process.communicate() # locks
# check if the file updated
new_size = os.path.getsize(self._temp_file_out)
if new_size != prev_size:
update_image()
prev_size = new_size
time.sleep(self.DELAY)
'''
self.end_result(result)
Doug Hammond
committed
else:
print("***POV FILE NOT FOUND***")
print("***POV FILE FINISHED***")
#print(filename_log) #bring the pov log to blender console with proper path?
with open(self._temp_file_log) as f: # The with keyword automatically closes the file when you are done
self.update_stats("", "")
Bastien Montagne
committed
if scene.pov.tempfiles_enable or scene.pov.deletefiles_enable:
##################################################################################
#################################Operators########################################
##################################################################################
class RenderPovTexturePreview(Operator):
bl_idname = "tex.preview_update"
bl_label = "Update preview"
def execute(self, context):
tex=bpy.context.object.active_material.active_texture #context.texture
texPrevName=string_strip_hyphen(bpy.path.clean_name(tex.name))+"_prev"
Maurice Raybaud
committed
## Make sure Preview directory exists and is empty
if not os.path.isdir(preview_dir):
os.mkdir(preview_dir)
iniPrevFile=os.path.join(preview_dir, "Preview.ini")
inputPrevFile=os.path.join(preview_dir, "Preview.pov")
outputPrevFile=os.path.join(preview_dir, texPrevName)
##################### ini ##########################################
fileIni=open("%s"%iniPrevFile,"w")
fileIni.write('Version=3.7\n')
fileIni.write('Input_File_Name="%s"\n'%inputPrevFile)
fileIni.write('Output_File_Name="%s.png"\n'%outputPrevFile)
fileIni.write('Library_Path="%s"\n' % preview_dir)
fileIni.write('Width=256\n')
fileIni.write('Height=256\n')
fileIni.write('Pause_When_Done=0\n')
fileIni.write('Output_File_Type=N\n')
fileIni.write('Output_Alpha=1\n')
fileIni.write('Antialias=on\n')
fileIni.write('Sampling_Method=2\n')
fileIni.write('Antialias_Depth=3\n')
fileIni.write('-d\n')
fileIni.close()
##################### pov ##########################################
filePov=open("%s"%inputPrevFile,"w")
PATname = "PAT_"+string_strip_hyphen(bpy.path.clean_name(tex.name))
filePov.write("#declare %s = \n"%PATname)
filePov.write(shading.exportPattern(tex, string_strip_hyphen))
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
filePov.write("#declare Plane =\n")
filePov.write("mesh {\n")
filePov.write(" triangle {<-2.021,-1.744,2.021>,<-2.021,-1.744,-2.021>,<2.021,-1.744,2.021>}\n")
filePov.write(" triangle {<-2.021,-1.744,-2.021>,<2.021,-1.744,-2.021>,<2.021,-1.744,2.021>}\n")
filePov.write(" texture{%s}\n"%PATname)
filePov.write("}\n")
filePov.write("object {Plane}\n")
filePov.write("light_source {\n")
filePov.write(" <0,4.38,-1.92e-07>\n")
filePov.write(" color rgb<4, 4, 4>\n")
filePov.write(" parallel\n")
filePov.write(" point_at <0, 0, -1>\n")
filePov.write("}\n")
filePov.write("camera {\n")
filePov.write(" location <0, 0, 0>\n")
filePov.write(" look_at <0, 0, -1>\n")
filePov.write(" right <-1.0, 0, 0>\n")
filePov.write(" up <0, 1, 0>\n")
filePov.write(" angle 96.805211\n")
filePov.write(" rotate <-90.000003, -0.000000, 0.000000>\n")
filePov.write(" translate <0.000000, 0.000000, 0.000000>\n")
filePov.write("}\n")
filePov.close()
##################### end write ##########################################
pov_binary = PovrayRender._locate_binary()
if sys.platform[:3] == "win":
p1=subprocess.Popen(["%s"%pov_binary,"/EXIT","%s"%iniPrevFile],
stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
p1=subprocess.Popen(["%s"%pov_binary,"-d","%s"%iniPrevFile],
stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
p1.wait()
tex.use_nodes = True
tree = tex.node_tree
links = tree.links
for n in tree.nodes:
tree.nodes.remove(n)
pathPrev="%s.png"%outputPrevFile
im.image = bpy.data.images.load(pathPrev)
name=pathPrev
name=name.split("/")
name=name[len(name)-1]
im.location = 200,200
previewer = tree.nodes.new('TextureNodeOutput')
previewer.label = "Preview"
previewer.location = 400,400
links.new(im.outputs[0],previewer.inputs[0])
#tex.type="IMAGE" # makes clip extend possible
#tex.extension="CLIP"