Newer
Older
Bastien Montagne
committed
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# #**** END GPL LICENSE BLOCK #****
import subprocess
import os
import sys
import time
from math import atan, pi, degrees, sqrt, cos, sin
import re
import platform#
import subprocess#
import tempfile #generate temporary files with random names
from bpy.types import(Operator)
from imghdr import what #imghdr is a python lib to identify image file types
from . import shading # for BI POV haders emulation
from . import primitives # for import and export of POV specific primitives
from . import nodes # for POV specific nodes
##############################SF###########################
##############find image texture
ext = {
'JPG': "jpeg",
'JPEG': "jpeg",
'GIF': "gif",
'TGA': "tga",
'IFF': "iff",
'PPM': "ppm",
'PNG': "png",
'SYS': "sys",
'TIFF': "tiff",
'TIF': "tiff",
'EXR': "exr",
'HDR': "hdr",
}.get(os.path.splitext(imgF)[-1].upper(), "")
print(" WARNING: texture image has no extension") #too verbose
ext = what(imgF) #imghdr is a python lib to identify image file types
image_map = ""
if ts.mapping == 'FLAT':
image_map = "map_type 0 "
elif ts.mapping == 'SPHERE':
elif ts.mapping == 'TUBE':
image_map = "map_type 2 "
## map_type 3 and 4 in development (?)
## for POV-Ray, currently they just seem to default back to Flat (type 0)
#elif ts.mapping=="?":
#elif ts.mapping=="?":
if ts.texture.use_interpolation:
image_map += " interpolate 2 "
if ts.texture.extension == 'CLIP':
image_map += " once "
#image_map += "}"
#if ts.mapping=='CUBE':
# image_map+= "warp { cubic } rotate <-90,0,180>"
# no direct cube type mapping. Though this should work in POV 3.7
# it doesn't give that good results(best suited to environment maps?)
# print(" No texture image found ")
def imgMapTransforms(ts):
# XXX TODO: unchecked textures give error of variable referenced before assignment XXX
# POV-Ray "scale" is not a number of repetitions factor, but ,its
# inverse, a standard scale factor.
# 0.5 Offset is needed relatively to scale because center of the
# scale is 0.5,0.5 in blender and 0,0 in POV
# Strange that the translation factor for scale is not the same as for
# translate.
# TODO: verify both matches with blender internal.
image_map_transforms = ""
image_map_transforms = ("scale <%.4g,%.4g,%.4g> translate <%.4g,%.4g,%.4g>" % \
( 1.0 / ts.scale.x,
1.0 / ts.scale.y,
1.0 / ts.scale.z,
0.5-(0.5/ts.scale.x) - (ts.offset.x),
0.5-(0.5/ts.scale.y) - (ts.offset.y),
# image_map_transforms = (" translate <-0.5,-0.5,0.0> scale <%.4g,%.4g,%.4g> translate <%.4g,%.4g,%.4g>" % \
# ( 1.0 / ts.scale.x,
# 1.0 / ts.scale.y,
# 1.0 / ts.scale.z,
# (0.5 / ts.scale.x) + ts.offset.x,
# (0.5 / ts.scale.y) + ts.offset.y,
# ts.offset.z))
# image_map_transforms = ("translate <-0.5,-0.5,0> scale <-1,-1,1> * <%.4g,%.4g,%.4g> translate <0.5,0.5,0> + <%.4g,%.4g,%.4g>" % \
# 1.0 / ts.scale.y,
# 1.0 / ts.scale.z,
# ts.offset.x,
# ts.offset.y,
# ts.offset.z))
return image_map_transforms
# texture_coords refers to the mapping of world textures:
if wts.texture_coords == 'VIEW' or wts.texture_coords == 'GLOBAL':
elif wts.texture_coords == 'ANGMAP':
image_mapBG = " map_type 1 "
elif wts.texture_coords == 'TUBE':
image_mapBG = " map_type 2 "
if wts.texture.use_interpolation:
image_mapBG += " interpolate 2 "
if wts.texture.extension == 'CLIP':
image_mapBG += " once "
#image_mapBG += "}"
#if wts.mapping == 'CUBE':
# image_mapBG += "warp { cubic } rotate <-90,0,180>"
# no direct cube type mapping. Though this should work in POV 3.7
# it doesn't give that good results(best suited to environment maps?)
#if image_mapBG == "":
# print(" No background texture image found ")
Maurice Raybaud
committed
return bpy.path.abspath(image.filepath, library=image.library).replace("\\","/")
# .replace("\\","/") to get only forward slashes as it's what POV prefers,
Maurice Raybaud
committed
# even on windows
# end find image texture
# -----------------------------------------------------------------------------
def string_strip_hyphen(name):
return name.replace("-", "")
def safety(name, Level):
# safety string name material
#
# Level=1 is for texture with No specular nor Mirror reflection
# Level=2 is for texture with translation of spec and mir levels
# for when no map influences them
# Level=3 is for texture with Maximum Spec and Mirror
Maurice Raybaud
committed
prefix = ""
return prefix + name + "0" # used for 0 of specular map
return prefix + name + "1" # used for 1 of specular map
Maurice Raybaud
committed
##############end safety string name material
##############################EndSF###########################
def is_renderable(scene, ob):
return (ob.is_visible(scene) and not ob.hide_render and ob not in csg_list)
def renderable_objects(scene):
return [ob for ob in bpy.data.objects if is_renderable(scene, ob)]
def no_renderable_objects(scene):
return [ob for ob in csg_list]
Maurice Raybaud
committed
tabLevel = 0
unpacked_images=[]
user_dir = bpy.utils.resource_path('USER')
preview_dir = os.path.join(user_dir, "preview")
## Make sure Preview directory exists and is empty
smokePath = os.path.join(preview_dir, "smoke.df3")
def write_global_setting(scene,file):
file.write("global_settings {\n")
file.write(" assumed_gamma %.6f\n"%scene.pov.assumed_gamma)
if scene.pov.global_settings_advanced:
if scene.pov.radio_enable == False:
file.write(" adc_bailout %.6f\n"%scene.pov.adc_bailout)
file.write(" ambient_light <%.6f,%.6f,%.6f>\n"%scene.pov.ambient_light[:])
file.write(" irid_wavelength <%.6f,%.6f,%.6f>\n"%scene.pov.irid_wavelength[:])
file.write(" charset %s\n"%scene.pov.charset)
file.write(" max_trace_level %s\n"%scene.pov.max_trace_level)
file.write(" max_intersections %s\n"%scene.pov.max_intersections)
file.write(" number_of_waves %s\n"%scene.pov.number_of_waves)
file.write(" noise_generator %s\n"%scene.pov.noise_generator)
# below properties not added to __init__ yet to avoid conflicts with material sss scale
# unless it would override then should be interfaced also in scene units property tab
# if scene.pov.sslt_enable:
# file.write(" mm_per_unit %s\n"%scene.pov.mm_per_unit)
# file.write(" subsurface {\n")
# file.write(" samples %s, %s\n"%(scene.pov.sslt_samples_max,scene.pov.sslt_samples_min))
# if scene.pov.sslt_radiosity:
# file.write(" radiosity on\n")
# file.write("}\n")
if scene.pov.radio_enable:
file.write(" radiosity {\n")
file.write(" pretrace_start %.6f\n"%scene.pov.radio_pretrace_start)
file.write(" pretrace_end %.6f\n"%scene.pov.radio_pretrace_end)
file.write(" count %s\n"%scene.pov.radio_count)
file.write(" nearest_count %s\n"%scene.pov.radio_nearest_count)
file.write(" error_bound %.6f\n"%scene.pov.radio_error_bound)
file.write(" recursion_limit %s\n"%scene.pov.radio_recursion_limit)
file.write(" low_error_factor %.6f\n"%scene.pov.radio_low_error_factor)
file.write(" gray_threshold %.6f\n"%scene.pov.radio_gray_threshold)
file.write(" maximum_reuse %.6f\n"%scene.pov.radio_maximum_reuse)
file.write(" minimum_reuse %.6f\n"%scene.pov.radio_minimum_reuse)
file.write(" brightness %.6f\n"%scene.pov.radio_brightness)
file.write(" adc_bailout %.6f\n"%scene.pov.radio_adc_bailout)
if scene.pov.radio_normal:
if scene.pov.radio_always_sample:
if scene.pov.radio_media:
if scene.pov.radio_subsurface:
file.write(" subsurface on\n")
file.write(" }\n")
if scene.pov.photon_enable:
file.write(" photons {\n")
if scene.pov.photon_enable_count:
file.write(" count %s\n"%scene.pov.photon_count)
else:
file.write(" spacing %.6g\n"%scene.pov.photon_spacing)
if scene.pov.photon_gather:
file.write(" gather %s, %s\n"%(scene.pov.photon_gather_min,scene.pov.photon_gather_max))
if scene.pov.photon_autostop:
file.write(" autostop %.4g\n"%scene.pov.photon_autostop_value)
if scene.pov.photon_jitter_enable:
file.write(" jitter %.4g\n"%scene.pov.photon_jitter)
file.write(" max_trace_level %s\n"%scene.pov.photon_max_trace_level)
if scene.pov.photon_adc:
file.write(" adc_bailout %.6f\n"%scene.pov.photon_adc_bailout)
if scene.pov.photon_media_enable:
file.write(" media %s, %s\n"%(scene.pov.photon_media_steps,scene.pov.photon_media_factor))
if scene.pov.photon_map_file_save_load in {'save'}:
filePhName = 'Photon_map_file.ph'
if scene.pov.photon_map_file != '':
filePhName = scene.pov.photon_map_file+'.ph'
filePhDir = tempfile.gettempdir()
path = bpy.path.abspath(scene.pov.photon_map_dir)
if os.path.exists(path):
filePhDir = path
fullFileName = os.path.join(filePhDir,filePhName)
file.write(' save_file "%s"\n'%fullFileName)
scene.pov.photon_map_file = fullFileName
if scene.pov.photon_map_file_save_load in {'load'}:
fullFileName = bpy.path.abspath(scene.pov.photon_map_file)
if os.path.exists(fullFileName):
file.write(' load_file "%s"\n'%fullFileName)
file.write("}\n")
file.write("}\n")
def write_object_modifiers(scene,ob,File):
'''XXX WIP
onceCSG = 0
for mod in ob.modifiers:
if onceCSG == 0:
if mod :
if mod.type == 'BOOLEAN':
if ob.pov.boolean_mod == "POV":
File.write("\tinside_vector <%.6g, %.6g, %.6g>\n" %
(ob.pov.inside_vector[0],
ob.pov.inside_vector[1],
ob.pov.inside_vector[2]))
onceCSG = 1
'''
File.write("\thollow\n")
if ob.pov.double_illuminate:
File.write("\tdouble_illuminate\n")
File.write("\tsturm\n")
File.write("\tno_shadow\n")
File.write("\tno_image\n")
if ob.pov.no_reflection:
File.write("\tno_reflection\n")
if ob.pov.no_radiosity:
File.write("\tno_radiosity\n")
File.write("\tinverse\n")
File.write("\thierarchy\n")
# XXX, Commented definitions
'''
if scene.pov.photon_enable:
File.write("photons {\n")
if ob.pov.target:
File.write("target %.4g\n"%ob.pov.target_value)
if ob.pov.refraction:
File.write("refraction on\n")
if ob.pov.reflection:
File.write("reflection on\n")
if ob.pov.pass_through:
File.write("pass_through\n")
File.write("}\n")
if ob.pov.object_ior > 1:
File.write("interior {\n")
File.write("ior %.4g\n"%ob.pov.object_ior)
if scene.pov.photon_enable and ob.pov.target and ob.pov.refraction and ob.pov.dispersion:
File.write("ior %.4g\n"%ob.pov.dispersion_value)
File.write("ior %s\n"%ob.pov.dispersion_samples)
if scene.pov.photon_enable == False:
File.write("caustics %.4g\n"%ob.pov.fake_caustics_power)
'''
Campbell Barton
committed
import mathutils
# Only for testing
if not scene:
scene = bpy.data.scenes[0]
render = scene.render
world = scene.world
global_matrix = mathutils.Matrix.Rotation(-pi / 2.0, 4, 'X')
comments = scene.pov.comments_enable and not scene.pov.tempfiles_enable
linebreaksinlists = scene.pov.list_lf_enable and not scene.pov.tempfiles_enable
feature_set = bpy.context.user_preferences.addons[__package__].preferences.branch_feature_set_povray
using_uberpov = (feature_set=='uberpov')
pov_binary = PovrayRender._locate_binary()
if using_uberpov:
print("Unofficial UberPOV feature set chosen in preferences")
else:
print("Official POV-Ray 3.7 feature set chosen in preferences")
print("The name of the binary suggests you are probably rendering with Uber POV engine")
print("The name of the binary suggests you are probably rendering with standard POV engine")
Constantin Rahn
committed
def setTab(tabtype, spaces):
TabStr = ""
Campbell Barton
committed
if tabtype == 'NONE':
TabStr = ""
Campbell Barton
committed
elif tabtype == 'TAB':
TabStr = "\t"
Campbell Barton
committed
elif tabtype == 'SPACE':
TabStr = spaces * " "
Constantin Rahn
committed
return TabStr
Bastien Montagne
committed
tab = setTab(scene.pov.indentation_character, scene.pov.indentation_spaces)
if not scene.pov.tempfiles_enable:
def tabWrite(str_o):
global tabLevel
brackets = str_o.count("{") - str_o.count("}") + str_o.count("[") - str_o.count("]")
if brackets < 0:
tabLevel = tabLevel + brackets
if tabLevel < 0:
print("Indentation Warning: tabLevel = %s" % tabLevel)
tabLevel = 0
if tabLevel >= 1:
file.write("%s" % tab * tabLevel)
file.write(str_o)
if brackets > 0:
tabLevel = tabLevel + brackets
Constantin Rahn
committed
def uniqueName(name, nameSeq):
if name not in nameSeq:
return name
name_orig = name
i = 1
while name in nameSeq:
name = "%s_%.3d" % (name_orig, i)
tabWrite("matrix <%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f>\n" %
(matrix[0][0], matrix[1][0], matrix[2][0],
matrix[0][1], matrix[1][1], matrix[2][1],
matrix[0][2], matrix[1][2], matrix[2][2],
matrix[0][3], matrix[1][3], matrix[2][3]))
Bastien Montagne
committed
def MatrixAsPovString(matrix):
sMatrix = ("matrix <%.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f, %.6f>\n" %
(matrix[0][0], matrix[1][0], matrix[2][0],
matrix[0][1], matrix[1][1], matrix[2][1],
matrix[0][2], matrix[1][2], matrix[2][2],
matrix[0][3], matrix[1][3], matrix[2][3]))
Bastien Montagne
committed
return sMatrix
def writeObjectMaterial(material, ob):
Doug Hammond
committed
# DH - modified some variables to be function local, avoiding RNA write
# this should be checked to see if it is functionally correct
Bastien Montagne
committed
# Commented out: always write IOR to be able to use it for SSS, Fresnel reflections...
#if material and material.transparency_method == 'RAYTRACE':
if material:
# But there can be only one!
if material.subsurface_scattering.use: # SSS IOR get highest priority
tabWrite("interior {\n")
tabWrite("ior %.6f\n" % material.subsurface_scattering.ior)
Bastien Montagne
committed
# Then the raytrace IOR taken from raytrace transparency properties and used for
# reflections if IOR Mirror option is checked.
elif material.pov.mirror_use_IOR:
tabWrite("interior {\n")
tabWrite("ior %.6f\n" % material.raytrace_transparency.ior)
tabWrite("interior {\n")
tabWrite("ior %.6f\n" % material.raytrace_transparency.ior)
Doug Hammond
committed
pov_fake_caustics = False
pov_photons_refraction = False
pov_photons_reflection = False
Bastien Montagne
committed
if material.pov.photons_reflection:
Maurice Raybaud
committed
if not material.pov.refraction_caustics:
Doug Hammond
committed
pov_fake_caustics = False
pov_photons_refraction = False
Bastien Montagne
committed
elif material.pov.refraction_type == "1":
Doug Hammond
committed
pov_fake_caustics = True
pov_photons_refraction = False
Bastien Montagne
committed
elif material.pov.refraction_type == "2":
Doug Hammond
committed
pov_fake_caustics = False
pov_photons_refraction = True
Bastien Montagne
committed
# If only Raytrace transparency is set, its IOR will be used for refraction, but user
# can set up 'un-physical' fresnel reflections in raytrace mirror parameters.
# Last, if none of the above is specified, user can set up 'un-physical' fresnel
# reflections in raytrace mirror parameters. And pov IOR defaults to 1.
if material.pov.caustics_enable:
Doug Hammond
committed
if pov_fake_caustics:
Bastien Montagne
committed
tabWrite("caustics %.3g\n" % material.pov.fake_caustics_power)
Maurice Raybaud
committed
if pov_photons_refraction:
Bastien Montagne
committed
# Default of 1 means no dispersion
tabWrite("dispersion %.6f\n" % material.pov.photons_dispersion)
Maurice Raybaud
committed
tabWrite("dispersion_samples %.d\n" % material.pov.photons_dispersion_samples)
if material.use_transparency and material.transparency_method == 'RAYTRACE':
# fade_distance
Bastien Montagne
committed
# In Blender this value has always been reversed compared to what tooltip says.
# 100.001 rather than 100 so that it does not get to 0
# which deactivates the feature in POV
Bastien Montagne
committed
tabWrite("fade_distance %.3g\n" % \
(100.001 - material.raytrace_transparency.depth_max))
# fade_power
tabWrite("fade_power %.3g\n" % material.raytrace_transparency.falloff)
# fade_color
Bastien Montagne
committed
tabWrite("fade_color <%.3g, %.3g, %.3g>\n" % material.pov.interior_fade_color[:])
# (variable) dispersion_samples (constant count for now)
tabWrite("}\n")
if material.pov.photons_reflection or material.pov.refraction_type=="2":
tabWrite("photons{")
Maurice Raybaud
committed
tabWrite("target %.3g\n" % ob.pov.spacing_multiplier)
if not ob.pov.collect_photons:
tabWrite("collect off\n")
if pov_photons_refraction:
tabWrite("refraction on\n")
if pov_photons_reflection:
tabWrite("reflection on\n")
tabWrite("}\n")
DEF_MAT_NAME = "" #or "Default"?
Doug Hammond
committed
# DH disabled for now, this isn't the correct context
active_object = None # bpy.context.active_object # does not always work MR
matrix = global_matrix * camera.matrix_world
focal_point = camera.data.dof_distance
Qsize = render.resolution_x / render.resolution_y
tabWrite("#declare camLocation = <%.6f, %.6f, %.6f>;\n" %
matrix.translation[:])
tabWrite("#declare camLookAt = <%.6f, %.6f, %.6f>;\n" %
Bastien Montagne
committed
tuple([degrees(e) for e in matrix.to_3x3().to_euler()]))
tabWrite("camera {\n")
Bastien Montagne
committed
if scene.pov.baking_enable and active_object and active_object.type == 'MESH':
tabWrite("mesh_camera{ 1 3\n") # distribution 3 is what we want here
tabWrite("mesh{%s}\n" % active_object.name)
tabWrite("}\n")
tabWrite("location <0,0,.01>")
tabWrite("direction <0,0,-1>")
tabWrite("location <0, 0, 0>\n")
tabWrite("look_at <0, 0, -1>\n")
tabWrite("right <%s, 0, 0>\n" % - Qsize)
tabWrite("up <0, 1, 0>\n")
tabWrite("angle %f\n" % (360.0 * atan(16.0 / camera.data.lens) / pi))
Bastien Montagne
committed
tabWrite("rotate <%.6f, %.6f, %.6f>\n" % \
tuple([degrees(e) for e in matrix.to_3x3().to_euler()]))
tabWrite("translate <%.6f, %.6f, %.6f>\n" % matrix.translation[:])
if camera.data.pov.dof_enable and (focal_point != 0 or camera.data.dof_object):
Bastien Montagne
committed
tabWrite("aperture %.3g\n" % camera.data.pov.dof_aperture)
tabWrite("blur_samples %d %d\n" % \
(camera.data.pov.dof_samples_min, camera.data.pov.dof_samples_max))
tabWrite("variance 1/%d\n" % camera.data.pov.dof_variance)
tabWrite("confidence %.3g\n" % camera.data.pov.dof_confidence)
if camera.data.dof_object:
focalOb = scene.objects[camera.data.dof_object.name]
matrixBlur = global_matrix * focalOb.matrix_world
tabWrite("focal_point <%.4f,%.4f,%.4f>\n"% matrixBlur.translation[:])
else:
tabWrite("focal_point <0, 0, %f>\n" % focal_point)
if camera.data.pov.normal_enable:
tabWrite("normal {%s %.4f turbulence %.4f scale %.4f}\n"%
(camera.data.pov.normal_patterns,
camera.data.pov.cam_normal,
camera.data.pov.turbulence,
camera.data.pov.scale))
tabWrite("}\n")
# Incremented after each lamp export to declare its target
# currently used for Fresnel diffuse shader as their slope vector:
global lampCount
lampCount = 0
# Get all lamps
for ob in lamps:
lamp = ob.data
matrix = global_matrix * ob.matrix_world
# Color is modified by energy #muiltiplie by 2 for a better match --Maurice
color = tuple([c * (lamp.energy) for c in lamp.color])
tabWrite("light_source {\n")
tabWrite("< 0,0,0 >\n")
Maurice Raybaud
committed
tabWrite("color srgb<%.3g, %.3g, %.3g>\n" % color)
tabWrite("spotlight\n")
tabWrite("falloff %.2f\n" % (degrees(lamp.spot_size) / 2.0)) # 1 TO 179 FOR BOTH
Bastien Montagne
committed
tabWrite("radius %.6f\n" % \
((degrees(lamp.spot_size) / 2.0) * (1.0 - lamp.spot_blend)))
# Blender does not have a tightness equivilent, 0 is most like blender default.
tabWrite("tightness 0\n") # 0:10f
tabWrite("point_at <0, 0, -1>\n")
Maurice Raybaud
committed
if lamp.use_halo:
tabWrite("looks_like{\n")
tabWrite("sphere{<0,0,0>,%.6f\n" %lamp.distance)
tabWrite("hollow\n")
tabWrite("material{\n")
tabWrite("texture{\n")
tabWrite("pigment{rgbf<1,1,1,%.4f>}\n" % (lamp.halo_intensity*5.0))
tabWrite("}\n")
tabWrite("interior{\n")
tabWrite("media{\n")
tabWrite("emission 1\n")
tabWrite("scattering {1, 0.5}\n")
tabWrite("density{\n")
tabWrite("spherical\n")
tabWrite("color_map{\n")
tabWrite("[0.0 rgb <0,0,0>]\n")
tabWrite("[0.5 rgb <1,1,1>]\n")
tabWrite("[1.0 rgb <1,1,1>]\n")
tabWrite("}\n")
tabWrite("}\n")
tabWrite("}\n")
tabWrite("}\n")
tabWrite("}\n")
tabWrite("}\n")
tabWrite("}\n")
tabWrite("parallel\n")
tabWrite("point_at <0, 0, -1>\n") # *must* be after 'parallel'
tabWrite("fade_distance %.6f\n" % (lamp.distance / 2.0))
Bastien Montagne
committed
# Area lights have no falloff type, so always use blenders lamp quad equivalent
# for those?
tabWrite("fade_power %d\n" % 2)
size_x = lamp.size
samples_x = lamp.shadow_ray_samples_x
if lamp.shape == 'SQUARE':
size_y = size_x
samples_y = samples_x
else:
size_y = lamp.size_y
samples_y = lamp.shadow_ray_samples_y
Maurice Raybaud
committed
tabWrite("area_light <%.6f,0,0>,<0,%.6f,0> %d, %d\n" % \
(size_x, size_y, samples_x, samples_y))
tabWrite("area_illumination\n")
Maurice Raybaud
committed
if lamp.shadow_ray_sample_method == 'CONSTANT_JITTERED':
if lamp.use_jitter:
tabWrite("jitter\n")
tabWrite("adaptive 1\n")
tabWrite("jitter\n")
Bastien Montagne
committed
# HEMI never has any shadow_method attribute
if(not scene.render.use_shadows or lamp.type == 'HEMI' or
(lamp.type != 'HEMI' and lamp.shadow_method == 'NOSHADOW')):
tabWrite("shadowless\n")
Bastien Montagne
committed
# Sun shouldn't be attenuated. Hemi and area lights have no falloff attribute so they
# are put to type 2 attenuation a little higher above.
if lamp.type not in {'SUN', 'AREA', 'HEMI'}:
tabWrite("fade_distance %.6f\n" % (sqrt(lamp.distance/2.0)))
tabWrite("fade_power %d\n" % 2) # Use blenders lamp quad equivalent
tabWrite("fade_distance %.6f\n" % (lamp.distance / 2.0))
tabWrite("fade_power %d\n" % 1) # Use blenders lamp linear
Bastien Montagne
committed
elif lamp.falloff_type == 'CONSTANT':
tabWrite("fade_distance %.6f\n" % (lamp.distance / 2.0))
tabWrite("fade_power %d\n" % 3)
# Use blenders lamp constant equivalent no attenuation.
Bastien Montagne
committed
# Using Custom curve for fade power 3 for now.
elif lamp.falloff_type == 'CUSTOM_CURVE':
tabWrite("fade_power %d\n" % 4)
tabWrite("}\n")
lampCount += 1
# v(A,B) rotates vector A about origin by vector B.
Bastien Montagne
committed
file.write("#declare lampTarget%s= vrotate(<%.4g,%.4g,%.4g>,<%.4g,%.4g,%.4g>);\n" % \
(lampCount, -(ob.location.x), -(ob.location.y), -(ob.location.z),
ob.rotation_euler.x, ob.rotation_euler.y, ob.rotation_euler.z))
Bastien Montagne
committed
####################################################################################################
def exportRainbows(rainbows):
for ob in rainbows:
povdataname = ob.data.name #enough?
angle = degrees(ob.data.spot_size/2.5) #radians in blender (2
width = ob.data.spot_blend *10
#eps=0.0000001
#angle = br/(cr+eps) * 10 #eps is small epsilon variable to avoid dividing by zero
#width = ob.dimensions[2] #now let's say width of rainbow is the actual proxy height
# formerly:
#cz-bz # let's say width of the rainbow is height of the cone (interfacing choice
# v(A,B) rotates vector A about origin by vector B.
# and avoid a 0 length vector by adding 1
# file.write("#declare %s_Target= vrotate(<%.6g,%.6g,%.6g>,<%.4g,%.4g,%.4g>);\n" % \
# (povdataname, -(ob.location.x+0.1), -(ob.location.y+0.1), -(ob.location.z+0.1),
# ob.rotation_euler.x, ob.rotation_euler.y, ob.rotation_euler.z))
direction = (ob.location.x,ob.location.y,ob.location.z) # not taking matrix into account
rmatrix = global_matrix * ob.matrix_world
#ob.rotation_euler.to_matrix().to_4x4() * mathutils.Vector((0,0,1))
# XXX Is result of the below offset by 90 degrees?
up =ob.matrix_world.to_3x3()[1].xyz #* global_matrix
#tabWrite("#declare %s = rainbow {\n"%povdataname)
# clumsy for now but remove the rainbow from instancing
# system because not an object. use lamps later instead of meshes
#del data_ref[dataname]
tabWrite("rainbow {\n")
tabWrite("angle %.4f\n"%angle)
tabWrite("width %.4f\n"%width)
tabWrite("distance %.4f\n"%distance)
tabWrite("arc_angle %.4f\n"%ob.pov.arc_angle)
tabWrite("falloff_angle %.4f\n"%ob.pov.falloff_angle)
tabWrite("direction <%.4f,%.4f,%.4f>\n"%rmatrix.translation[:])
tabWrite("up <%.4f,%.4f,%.4f>\n"%(up[0],up[1],up[2]))
tabWrite("color_map {\n")
Maurice Raybaud
committed
tabWrite("[0.000 color srgbt<1.0, 0.5, 1.0, 1.0>]\n")
tabWrite("[0.130 color srgbt<0.5, 0.5, 1.0, 0.9>]\n")
tabWrite("[0.298 color srgbt<0.2, 0.2, 1.0, 0.7>]\n")
tabWrite("[0.412 color srgbt<0.2, 1.0, 1.0, 0.4>]\n")
tabWrite("[0.526 color srgbt<0.2, 1.0, 0.2, 0.4>]\n")
tabWrite("[0.640 color srgbt<1.0, 1.0, 0.2, 0.4>]\n")
tabWrite("[0.754 color srgbt<1.0, 0.5, 0.2, 0.6>]\n")
tabWrite("[0.900 color srgbt<1.0, 0.2, 0.2, 0.7>]\n")
tabWrite("[1.000 color srgbt<1.0, 0.2, 0.2, 1.0>]\n")
povMatName = "Default_texture"
#tabWrite("texture {%s}\n"%povMatName)
write_object_modifiers(scene,ob,file)
#tabWrite("rotate x*90\n")
#matrix = global_matrix * ob.matrix_world
#writeMatrix(matrix)
tabWrite("}\n")
#continue #Don't render proxy mesh, skip to next object
################################XXX LOFT, ETC.
def exportCurves(scene, ob):
name_orig = "OB" + ob.name
dataname_orig = "DATA" + ob.data.name
name = string_strip_hyphen(bpy.path.clean_name(name_orig))
dataname = string_strip_hyphen(bpy.path.clean_name(dataname_orig))
global_matrix = mathutils.Matrix.Rotation(-pi / 2.0, 4, 'X')
matrix=global_matrix*ob.matrix_world
bezier_sweep = False
if ob.pov.curveshape == 'sphere_sweep':
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
#inlined spheresweep macro, which itself calls Shapes.inc:
file.write(' #include "shapes.inc"\n')
file.write(' #macro Shape_Bezierpoints_Sphere_Sweep(_merge_shape, _resolution, _points_array, _radius_array)\n')
file.write(' //input adjusting and inspection\n')
file.write(' #if(_resolution <= 1)\n')
file.write(' #local res = 1;\n')
file.write(' #else\n')
file.write(' #local res = int(_resolution);\n')
file.write(' #end\n')
file.write(' #if(dimensions(_points_array) != 1 | dimensions(_radius_array) != 1)\n')
file.write(' #error ""\n')
file.write(' #elseif(div(dimension_size(_points_array,1),4) - dimension_size(_points_array,1)/4 != 0)\n')
file.write(' #error ""\n')
file.write(' #elseif(dimension_size(_points_array,1) != dimension_size(_radius_array,1))\n')
file.write(' #error ""\n')
file.write(' #else\n')
file.write(' #local n_of_seg = div(dimension_size(_points_array,1), 4);\n')
file.write(' #local ctrl_pts_array = array[n_of_seg]\n')
file.write(' #local ctrl_rs_array = array[n_of_seg]\n')
file.write(' #for(i, 0, n_of_seg-1)\n')
file.write(' #local ctrl_pts_array[i] = array[4] {_points_array[4*i], _points_array[4*i+1], _points_array[4*i+2], _points_array[4*i+3]}\n')
file.write(' #local ctrl_rs_array[i] = array[4] {abs(_radius_array[4*i]), abs(_radius_array[4*i+1]), abs(_radius_array[4*i+2]), abs(_radius_array[4*i+3])}\n')
file.write(' #end\n')
file.write(' #end\n')
file.write(' //drawing\n')
file.write(' #local mockup1 =\n')
file.write(' #if(_merge_shape) merge{ #else union{ #end\n')
file.write(' #for(i, 0, n_of_seg-1)\n')
file.write(' #local has_head = true;\n')
file.write(' #if(i = 0)\n')
file.write(' #if(vlength(ctrl_pts_array[i][0]-ctrl_pts_array[n_of_seg-1][3]) = 0 & ctrl_rs_array[i][0]-ctrl_rs_array[n_of_seg-1][3] <= 0)\n')
file.write(' #local has_head = false;\n')
file.write(' #end\n')
file.write(' #else\n')
file.write(' #if(vlength(ctrl_pts_array[i][0]-ctrl_pts_array[i-1][3]) = 0 & ctrl_rs_array[i][0]-ctrl_rs_array[i-1][3] <= 0)\n')
file.write(' #local has_head = false;\n')
file.write(' #end\n')
file.write(' #end\n')
file.write(' #if(has_head = true)\n')
file.write(' sphere{\n')
file.write(' ctrl_pts_array[i][0], ctrl_rs_array[i][0]\n')
file.write(' }\n')
file.write(' #end\n')
file.write(' #local para_t = (1/2)/res;\n')
file.write(' #local this_point = ctrl_pts_array[i][0]*pow(1-para_t,3) + ctrl_pts_array[i][1]*3*pow(1-para_t,2)*para_t + ctrl_pts_array[i][2]*3*(1-para_t)*pow(para_t,2) + ctrl_pts_array[i][3]*pow(para_t,3);\n')
file.write(' #local this_radius = ctrl_rs_array[i][0]*pow(1-para_t,3) + ctrl_rs_array[i][1]*3*pow(1-para_t,2)*para_t + ctrl_rs_array[i][2]*3*(1-para_t)*pow(para_t,2) + ctrl_rs_array[i][3]*pow(para_t,3);\n')
file.write(' #if(vlength(this_point-ctrl_pts_array[i][0]) > abs(this_radius-ctrl_rs_array[i][0]))\n')
file.write(' object{\n')
file.write(' Connect_Spheres(ctrl_pts_array[i][0], ctrl_rs_array[i][0], this_point, this_radius)\n')
file.write(' }\n')
file.write(' #end\n')
file.write(' sphere{\n')
file.write(' this_point, this_radius\n')
file.write(' }\n')
file.write(' #for(j, 1, res-1)\n')
file.write(' #local last_point = this_point;\n')
file.write(' #local last_radius = this_radius;\n')
file.write(' #local para_t = (1/2+j)/res;\n')
file.write(' #local this_point = ctrl_pts_array[i][0]*pow(1-para_t,3) + ctrl_pts_array[i][1]*3*pow(1-para_t,2)*para_t + ctrl_pts_array[i][2]*3*(1-para_t)*pow(para_t,2) + ctrl_pts_array[i][3]*pow(para_t,3);\n')
file.write(' #local this_radius = ctrl_rs_array[i][0]*pow(1-para_t,3) + ctrl_rs_array[i][1]*3*pow(1-para_t,2)*para_t + ctrl_rs_array[i][2]*3*(1-para_t)*pow(para_t,2) + ctrl_rs_array[i][3]*pow(para_t,3);\n')
file.write(' #if(vlength(this_point-last_point) > abs(this_radius-last_radius))\n')
file.write(' object{\n')
file.write(' Connect_Spheres(last_point, last_radius, this_point, this_radius)\n')
file.write(' }\n')
file.write(' #end\n')
file.write(' sphere{\n')
file.write(' this_point, this_radius\n')
file.write(' }\n')
file.write(' #end\n')
file.write(' #local last_point = this_point;\n')
file.write(' #local last_radius = this_radius;\n')
file.write(' #local this_point = ctrl_pts_array[i][3];\n')
file.write(' #local this_radius = ctrl_rs_array[i][3];\n')
file.write(' #if(vlength(this_point-last_point) > abs(this_radius-last_radius))\n')
file.write(' object{\n')
file.write(' Connect_Spheres(last_point, last_radius, this_point, this_radius)\n')
file.write(' }\n')
file.write(' #end\n')
file.write(' sphere{\n')
file.write(' this_point, this_radius\n')
file.write(' }\n')
file.write(' #end\n')
file.write(' }\n')
file.write(' mockup1\n')
file.write(' #end\n')
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
for spl in ob.data.splines:
if spl.type == "BEZIER":
bezier_sweep = True
if ob.pov.curveshape in {'loft','birail'}:
n=0
for spline in ob.data.splines:
n+=1
tabWrite('#declare %s%s=spline {\n'%(dataname,n))
tabWrite('cubic_spline\n')
lp = len(spline.points)
delta = 1/(lp)
d=-delta
point = spline.points[lp-1]
x,y,z,w = point.co[:]
tabWrite('%.6f, <%.6f,%.6f,%.6f>\n'%(d,x,y,z))
d+=delta
for point in spline.points:
x,y,z,w = point.co[:]
tabWrite('%.6f, <%.6f,%.6f,%.6f>\n'%(d,x,y,z))
d+=delta
for i in range(2):
point = spline.points[i]
x,y,z,w = point.co[:]
tabWrite('%.6f, <%.6f,%.6f,%.6f>\n'%(d,x,y,z))
d+=delta
tabWrite('}\n')
if ob.pov.curveshape in {'loft'}:
n = len(ob.data.splines)
tabWrite('#declare %s = array[%s]{\n'%(dataname,(n+3)))
tabWrite('spline{%s%s},\n'%(dataname,n))
for i in range(n):
tabWrite('spline{%s%s},\n'%(dataname,(i+1)))
tabWrite('spline{%s1},\n'%(dataname))
tabWrite('spline{%s2}\n'%(dataname))
tabWrite('}\n')
# Use some of the Meshmaker.inc macro, here inlined
file.write('#macro CheckFileName(FileName)\n')
file.write(' #local Len=strlen(FileName);\n')
file.write(' #if(Len>0)\n')
file.write(' #if(file_exists(FileName))\n')
file.write(' #if(Len>=4)\n')
file.write(' #local Ext=strlwr(substr(FileName,Len-3,4))\n')
file.write(' #if (strcmp(Ext,".obj")=0 | strcmp(Ext,".pcm")=0 | strcmp(Ext,".arr")=0)\n')
file.write(' #local Return=99;\n')
file.write(' #else\n')
file.write(' #local Return=0;\n')
file.write(' #end\n')
file.write(' #else\n')
file.write(' #local Return=0;\n')
file.write(' #end\n')
file.write(' #else\n')
file.write(' #if(Len>=4)\n')
file.write(' #local Ext=strlwr(substr(FileName,Len-3,4))\n')
file.write(' #if (strcmp(Ext,".obj")=0 | strcmp(Ext,".pcm")=0 | strcmp(Ext,".arr")=0)\n')
file.write(' #if (strcmp(Ext,".obj")=0)\n')
file.write(' #local Return=2;\n')
file.write(' #end\n')
file.write(' #if (strcmp(Ext,".pcm")=0)\n')
file.write(' #local Return=3;\n')
file.write(' #end\n')
file.write(' #if (strcmp(Ext,".arr")=0)\n')
file.write(' #local Return=4;\n')
file.write(' #end\n')
file.write(' #else\n')
file.write(' #local Return=1;\n')
file.write(' #end\n')
file.write(' #else\n')
file.write(' #local Return=1;\n')
file.write(' #end\n')
file.write(' #end\n')
file.write(' #else\n')
file.write(' #local Return=1;\n')
file.write(' #end\n')
file.write(' (Return)\n')
file.write('#end\n')
file.write('#macro BuildSpline(Arr, SplType)\n')
file.write(' #local Ds=dimension_size(Arr,1);\n')
file.write(' #local Asc=asc(strupr(SplType));\n')
file.write(' #if(Asc!=67 & Asc!=76 & Asc!=81) \n')
file.write(' #local Asc=76;\n')
file.write(' #debug "\nWrong spline type defined (C/c/L/l/N/n/Q/q), using default linear_spline\\n"\n')
file.write(' #end\n')
file.write(' spline {\n')
file.write(' #switch (Asc)\n')
file.write(' #case (67) //C cubic_spline\n')
file.write(' cubic_spline\n')
file.write(' #break\n')
file.write(' #case (76) //L linear_spline\n')
file.write(' linear_spline\n')
file.write(' #break\n')
file.write(' #case (78) //N linear_spline\n')
file.write(' natural_spline\n')
file.write(' #break\n')
file.write(' #case (81) //Q Quadratic_spline\n')
file.write(' quadratic_spline\n')
file.write(' #break\n')
file.write(' #end\n')
file.write(' #local Add=1/((Ds-2)-1);\n')
file.write(' #local J=0-Add;\n')
file.write(' #local I=0;\n')
file.write(' #while (I<Ds)\n')
file.write(' J\n')
file.write(' Arr[I]\n')
file.write(' #local I=I+1;\n')
file.write(' #local J=J+Add;\n')
file.write(' #end\n')
file.write(' }\n')
file.write('#end\n')
file.write('#macro BuildWriteMesh2(VecArr, NormArr, UVArr, U, V, FileName)\n')
#suppressed some file checking from original macro because no more separate files
file.write(' #local Write=0;\n')
file.write(' #debug concat("\\n\\n Building mesh2: \\n - vertex_vectors\\n")\n')
file.write(' #local NumVertices=dimension_size(VecArr,1);\n')
file.write(' #switch (Write)\n')
file.write(' #case(1)\n')
file.write(' #write(\n')
file.write(' MeshFile,\n')
file.write(' " vertex_vectors {\\n",\n')
file.write(' " ", str(NumVertices,0,0),"\\n "\n')
file.write(' )\n')
file.write(' #break\n')
file.write(' #case(2)\n')
file.write(' #write(\n')
file.write(' MeshFile,\n')
file.write(' "# Vertices: ",str(NumVertices,0,0),"\\n"\n')
file.write(' )\n')
file.write(' #break\n')
file.write(' #case(3)\n')
file.write(' #write(\n')
file.write(' MeshFile,\n')
file.write(' str(2*NumVertices,0,0),",\\n"\n')
file.write(' )\n')
file.write(' #break\n')
file.write(' #case(4)\n')
file.write(' #write(\n')
file.write(' MeshFile,\n')
file.write(' "#declare VertexVectors= array[",str(NumVertices,0,0),"] {\\n "\n')
file.write(' )\n')
file.write(' #break\n')
file.write(' #end\n')
file.write(' mesh2 {\n')
file.write(' vertex_vectors {\n')
file.write(' NumVertices\n')