Newer
Older
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.8\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))
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)
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
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"
Maurice Raybaud
committed
class RunPovTextRender(Operator):
"""Export files depending on text editor options and render image."""
Maurice Raybaud
committed
bl_idname = "text.run"
bl_label = "Run"
bl_context = "text"
bl_description = "Run a render with this text only"
Maurice Raybaud
committed
def execute(self, context):
scene = context.scene
scene.pov.text_block = context.space_data.text.name
bpy.ops.render.render()
Maurice Raybaud
committed
# empty text name property engain
Maurice Raybaud
committed
scene.pov.text_block = ""
return {'FINISHED'}
classes = (PovrayRender, RenderPovTexturePreview, RunPovTextRender)
# from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):