#!BPY """Registration info for Blender menus: Name: 'V-Ray/Blender 2.49.12' Blender: 240 Group: 'Render' Tooltip: 'Export to V-Ray scene format (.vrscene)' """ """ V-Ray/Blender 2.49.12 http://vray.cgdo.ru Started: 7 Feb 2008 Last Modified: 19 May 2010 Author: Andrey M. Izrantsev (aka bdancer) E-Mail: izrantsev@gmail.com This plugin is protected by the GNU General Public License v.2 This program is free software: you can redioutibute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is dioutibuted 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, see . All Rights Reserved. V-Ray(R) is a registered trademark of Chaos Group """ try: import math import os import sys as pysys import shutil import tempfile import socket except: print "Error loading Python modules!\nInstall Python 2.6 to use V-Ray/Blender." import bpy import Blender from Blender import * from Blender.Scene import Render from Blender.Window import DrawProgressBar, Theme from Blender.Mathutils import * from Blender.sys import * vray_module= None try: from Blender.VRay import * vray_module= 1 except: pass vrayblender_version= "2.49.12" vrayblender_version_ext= vrayblender_version + ".70" ostype= pysys.platform scene= bpy.data.scenes.active frame= 0 hostname= socket.gethostname() ## GUI Events evtNone= 0 evtRedraw= 1 evtRender= 2 evtExportG= 3 evtExportN= 4 evtExportL= 5 evtExportC= 6 evtExportM= 7 evtRun= 50 evtExit= 100 evtFlipResol= 101 evtCalcArea= 102 ## ## V-RAY DEFAULTS ## vray_defaults = { "vray_debug": 1, "vray_metric_scale": 1.0, "vray_photometric_scale" : 0.002, "vray_imageSamplerType": 1, "vray_FixedRate": 1, "vray_imageSamplerType": 1, "vray_dmc_minSubdivs": 1, "vray_dmc_maxSubdivs": 4, "vray_dmc_threshold": 0.01, "vray_subdivision_minRate": -1, "vray_subdivision_maxRate": 2, "vray_subdivision_threshold": 0.15, "vray_subdivision_edges": 0, "vray_subdivision_normals": 0, "vray_subdivision_normals_threshold": 0.1, "vray_aa_filter_type": 0, "vray_aa_filter_size": 1.5, "vray_cm_type": 0, "vray_dark_mult": 1.0, "vray_bright_mult": 1.0, "vray_gamma": 1.0, "vray_inputgamma": 1.0, "vray_subpixel_mapping": 0, "vray_clamp_output": 1, "vray_clamp_level": 1.0, "vray_adaptation_only": 0, "vray_linearWorkflow": 0, "vray_affect_background": 1, "vray_pm_bounces": 10, "vray_pm_search_distance": 20.0, "vray_pm_auto_search_distance": 0, "vray_pm_max_photons": 30, "vray_pm_prefilter": 0, "vray_pm_prefilter_samples": 10, "vray_pm_multiplier": 1.0, "vray_pm_convex_hull_estimate": 0, "vray_pm_store_direct_light": 1, "vray_pm_retrace_corners": 0.0, "vray_pm_retrace_bounces": 10, "vray_pm_max_density": 0.0, "vray_gi_on": 0, "vray_primary_engine": 0, "vray_primary_multiplier": 1.0, "vray_secondary_engine": 3, "vray_secondary_multiplier": 1.0, "vray_reflect_caustics": 0, "vray_refract_caustics": 1, "vray_saturation": 1.0, "vray_contrast": 1.0, "vray_contrast_base": 0.5, "vray_time_dependent": 0, "vray_adaptive_amount": 0.85, "vray_adaptive_threshold": 0.01, "vray_adaptive_min_samples": 8, "vray_subdivs_mult": 1.0, "vray_caustics_on": 0, "vray_caustics_max_photons": 30, "vray_caustics_search_distance": 0.05, "vray_caustics_max_density": 0.0, "vray_caustics_multiplier": 1.0, "vray_caustics_mode": 0, "vray_caustics_file": "", "vray_caustics_auto_save": 0, "vray_caustics_auto_save_file": "", "vray_caustics_show_calc_phase": 0, "vray_maxLevels": 60, "vray_minLeafSize": 0.0, "vray_faceLevelCoef": 1.0, "vray_dynMemLimit": 500, "vray_xc": 32, "vray_yc": 32, "vray_geom_backfaceCull": 0, "vray_geom_displacement": 1, "vray_geom_doHidden": 0, "vray_light_doLights": 1, "vray_light_doDefaultLights": 0, "vray_light_doHiddenLights": 0, "vray_light_doShadows": 1, "vray_mtl_reflectionRefraction": 1, "vray_mtl_glossy": 1, "vray_mtl_limitDepth": 0, "vray_mtl_maxDepth": 5, "vray_mtl_overall": 0, "vray_mtl_overall_mat": 0, "vray_mtl_overall_type": 0, "vray_mtl_doMaps": 0, "vray_mtl_filterMaps": 0, "vray_mtl_transpMaxLevels": 50, "vray_mtl_transpCutoff": 0.001, "vray_gi_dontRenderImage": 0, "vray_ray_bias": 0.0, "vray_displace_override_on": 0, "vray_displace_edgeLength": 4.0, "vray_displace_maxSubdivs": 256, "vray_displace_amount": 0.001, "vray_displace_viewDependent": 1, "vray_displace_tightBounds": 1, "vray_displace_relative": 0, "vray_renderid": 0, "vray_normals": 0, "vray_zdepth": 0, "vray_zdepth_depth_black": 0.0, "vray_zdepth_depth_white": 10.0, "vray_zdepth_depth_clamp": 1, "vray_velocity": 0, "vray_velocity_clamp_velocity": 0, # bool = true "vray_velocity_max_velocity": 1.0, # float = 1 "vray_velocity_max_velocity_last_frame": 0, # float = 0 "vray_velocity_ignore_z": 0, # bool = true "vray_mainpasses": 0, "vray_mainpasses_cm": 0, "vray_color": 0, "vray_color_alias": 1000, "vray_color_color_mapping": 0, "vray_extratex": 0, "vray_extratex_consider_for_aa": 1, # bool = true "vray_extratex_matte": 1, # bool = true "vray_extratex_ao_radius" : 0.1, "vray_multimatte": 0, "vray_multimatte_red_id": 0, "vray_multimatte_green_id": 0, "vray_multimatte_blue_id": 0, "vray_multimatte_use_mtl_id": 0, "vray_sunsky_turbidity": 3.0, "vray_sunsky_ozone": 0.35, "vray_sunsky_intensity": 1.0, "vray_sunsky_size_multiplier": 1.0, "vray_sunsky_shadow_subdivs": 3, "vray_sunsky_shadow_bias": 0.0, "vray_sunsky_photon_emit_radius": 50.0, "vray_sunsky_invisible": 0, "vray_sunsky_sky_intensity": 1.0, "vray_im_min_rate": -3, "vray_im_max_rate": 0, "vray_im_subdivs": 50, "vray_im_interp_samples": 20, "vray_im_interp_frames": 2, "vray_im_calc_interp_samples": 10, "vray_im_color_threshold": 0.3, "vray_im_normal_threshold": 0.1, "vray_im_distance_threshold": 0.1, "vray_im_detail_enhancement": 0, "vray_im_detail_radius": 0.06, "vray_im_detail_subdivs_mult": 0.3, "vray_im_detail_scale": 0, "vray_im_interpolationType": 1, "vray_im_lookupType": 2, "vray_im_show_calc_phase": 0, "vray_im_show_direct_light": 1, "vray_im_show_samples": 0, "vray_im_multipass": 0, "vray_im_check_sample_visibility": 0, "vray_im_randomize_samples": 1, "vray_im_mode": 0, "vray_im_dont_delete": 0, "vray_im_file": "", "vray_im_auto_save": 0, "vray_im_auto_save_file": "", "vray_lc_subdivs": 1000, "vray_lc_sample_size": 0.02, "vray_lc_num_passes": 4, "vray_lc_num_passes_auto": 0, "vray_lc_depth": 100, "vray_lc_filter_type": 0, "vray_lc_filter_samples": 10, "vray_lc_filter_size": 0.02, "vray_lc_prefilter": 0, "vray_lc_prefilter_samples": 40, "vray_lc_show_calc_phase": 0, "vray_lc_store_direct_light": 1, "vray_lc_use_for_glossy_rays": 0, "vray_lc_scale": 0, "vray_lc_adaptive_sampling": 0, "vray_lc_mode": 0, "vray_lc_dont_delete": 0, "vray_lc_file": "", "vray_lc_auto_save": 0, "vray_lc_auto_save_file": "", "vray_dmcgi_subdivs": 8, "vray_dmcgi_depth": 3, "vray_pm_bounces": 10, "vray_pm_search_distance": 20.0, "vray_pm_auto_search_distance": 0, "vray_pm_max_photons": 30, "vray_pm_prefilter": 0, "vray_pm_prefilter_samples": 10, "vray_pm_multiplier": 1.0, "vray_pm_convex_hull_estimate": 0, "vray_pm_store_direct_light": 1, "vray_pm_retrace_corners": 0.0, "vray_pm_retrace_bounces": 10, "vray_pm_max_density": 0.0, "vray_env_bg": 0, "vray_env_bg_sky":0, "vray_env_bg_mult": 1.0, "vray_env_bg_type": 1, "vray_env_bg_uvtype": 0, "vray_env_gi": 0, "vray_env_gi_sky": 0, "vray_env_gi_mult": 1.0, "vray_env_gi_type": 7, "vray_env_gi_uvtype": 0, "vray_env_reflect": 0, "vray_env_reflect_sky": 0, "vray_env_reflect_mult": 1.0, "vray_env_reflect_type": 7, "vray_env_reflect_uvtype": 0, "vray_env_refract": 0, "vray_env_refract_sky": 0, "vray_env_refract_mult": 1.0, "vray_env_refract_type": 7, "vray_env_refract_uvtype": 0, "vray_env_bg_color": [1.0, 1.0, 1.0], "vray_env_gi_color": [1.0, 1.0, 1.0], "vray_env_reflect_color": [0.0, 0.0, 0.0], "vray_env_refract_color": [0.0, 0.0, 0.0], "vray_env_bg_tex_id": 0, "vray_env_gi_tex_id": 0, "vray_env_reflect_tex_id": 0, "vray_env_refract_tex_id": 0, "vray_env_volume": 0, "vray_env_volume_color": [1.0, 1.0, 1.0], "vray_env_volume_mult": 0.1, "vray_dohair": 1, "vray_do_AO_effect": 0, "vray_AO_effect_color": [0.15,0.15,0.15], "vray_AO_effect_alpha": 0.6, "vray_render_crop": 0, "vray_autosave_render": 0, "vray_img_separateAlpha": 0, "vray_threads": 0, "vray_threads_export": 1, "vray_threads_auto": 1, "vray_wine": 0, "vray_log_window": 0, "vray_run": 1, "vray_binary": "", "vray_gui_screen": 0, "vray_novfb": 1, "vray_stamp": 0, "vray_realtime": 0, "vray_interactive": 0, "vray_verboseLevel": 3, "vray_unique_name": 1, "vray_export_path_over": 0, "vray_export_path": "", "vray_export_path_dr": "SET ME PLEASE :)", "vray_export_lock": 0, "vray_export_manual": 0, "vray_export_active": 0, "vray_export_bake": 0, "vray_export_animation": 0, "vray_export_dupli": 0, "vray_export_emitter": 0, "vray_export_instances": 1, "vray_export_cameraloop": 0, "vray_camera_start": 0, "vray_camera_end": 0, "vray_dr": 0, "vray_dr_hosts": "", "vray_dr_port": 20204, "vray_dr_network": 0 } vray_object_defaults = { "vray_mesh_valid": 0, "vray_volume_fog": 0, # 0 - none, 1 - VolumeFog, 2 - ScatterFog "vray_node_name": "", "vray_geometry_name": "", "vray_material_name": "", "vray_material_2sided": 0, "vray_volume_name": "", "vray_scatter_name": "", "vray_visible": 1, "vray_displace": 0, "vray_displace_tex": "", "vray_displace_use_dispfac": 1, "vray_displace_dispfac": 0.0, "vray_displace_amount": 0.01, "vray_displace_amount_delim" : 1.0, "vray_displace_shift": 0.0, "vray_displace_use_globals": 0, "vray_displace_edgeLength": 4.0, "vray_displace_maxSubdivs": 256, "vray_displace_view_dep": 1, "vray_displace_keep_continuity": 0, "vray_displace_water_level": 0.0, "vray_camera_phys_use_dof": 0, "vray_camera_phys_use_moblur": 0, "vray_camera_phys_subdivs": 6, "vray_camera_phys_bokeh": 0, "vray_camera_center_bias": 0.0, "vray_camera_anisotropy": 0.0, "vray_camera_blades_enable": 0, "vray_camera_blades_num": 5, "vray_camera_blades_rotation": 0, "vray_camera_physical": 0, "vray_camera_physical_type": 0, "vray_camera_film_width": 36.0, "vray_camera_focal_length": 40.0, "vray_camera_zoom_factor": 1.0, "vray_camera_distortion": 0.0, "vray_camera_f_number": 8.0, "vray_camera_lens_shift": 0.0, "vray_camera_shutter_speed": 300.0, "vray_camera_shutter_angle": 180.0, "vray_camera_shutter_offset": 0.0, "vray_camera_latency": 0.0, "vray_camera_ISO": 200.0, "vray_camera_specify_focus": 1, "vray_camera_focus_distance": 200.0, "vray_camera_targeted": 0, "vray_camera_target_distance": 200.0, "vray_camera_dof_display_threshold": 0.001, "vray_camera_exposure": 1, "vray_camera_white_balance": [1.0, 1.0, 1.0], "vray_camera_vignetting": 1.0, "vray_camera_blades_enable": 0, "vray_camera_blades_num": 5, "vray_camera_blades_rotation": 0.0, "vray_camera_center_bias": 0.0, "vray_camera_anisotropy": 0.0, "vray_camera_use_dof": 0, "vray_camera_use_moblur": 0, "vray_camera_subdivs": 6, "vray_camera_usehide": 0, "vray_camera_autohide": 0, "vray_camera_autohide_all": 0, "vray_camera_autohide_cam": 0, "vray_camera_autohide_gi": 0, "vray_camera_autohide_refl": 0, "vray_camera_autohide_refr": 0, "vray_camera_autohide_shad": 0, "vray_camera_hidelist_all": "", "vray_camera_hidelist_cam": "", "vray_camera_hidelist_gi": "", "vray_camera_hidelist_refl": "", "vray_camera_hidelist_refr": "", "vray_camera_hidelist_shad": "", "vray_camera_type": 0, "vray_camera_height": 0.4, "vray_camera_auto_fit": 1, "vray_camera_dist": 2.0, "vray_camera_curve": 1.0, "vray_light_affectDiffuse": 1, "vray_light_affectSpecular": 1, "vray_light_affectReflections": 1, "vray_light_beamRadius": 1.0, "vray_light_radius": 0.03, "vray_light_use_dome_tex": 0, "vray_light_dome_spherifical": 0, "vray_light_shadows": 1, "vray_light_shadowColor": [0.0, 0.0, 0.0], "vray_light_shadowBias": 0.0, "vray_light_shadowRadius": 0.0, "vray_light_subdivs": 8, "vray_light_caustics_subdivs": 1000, "vray_light_store": 0, "vray_light_invisible": 0, "vray_light_units": 0, "vray_light_intensity": 30.0, "vray_light_portal": 0, "vray_light_IES": "", "vray_light_isIES": 0, "vray_light_IES_soft_shadows": 0, "vray_light_sun": 0, "vray_IBL_mapping_type": 0, "vray_light_sphere_type": 0, "vray_object_id": 0, "vray_object_generate_gi": 1.0, "vray_object_receive_gi": 1.0, "vray_object_generate_caustics": 1.0, "vray_object_receive_caustics": 1.0, "vray_object_matte_surface": 0, # bool "vray_object_alpha_contribution": 1.0, "vray_object_shadows": 0, # bool "vray_object_affect_alpha": 0, # bool "vray_object_shadow_tint_color": [0.0, 0.0, 0.0], "vray_object_shadow_brightness": 1.0, "vray_object_reflection_amount": 1.0, "vray_object_refraction_amount": 1.0, "vray_object_gi_amount": 1.0, "vray_object_no_gi_on_other_mattes": 1, # bool "vray_object_gi_surface_id": 0, # bool "vray_object_base_material": "", "vray_object_override_mtl": 0, "vray_object_override_gi": [0.6, 0.6, 0.6], "vray_object_dynamic": 0, "vray_object_dynamic_uv": 0, "vray_object_dynamic_mtlID": 0, "vray_object_dynamic_material": 0, "vray_object_add_AO": 1, "vray_object_AO_radius": 0.02, "vray_object_visible_all": 1, "vray_object_visible_cam": 1, "vray_object_visible_refr": 1, "vray_object_visible_refl": 1, "vray_object_visible_gi": 1, "vray_object_visible_shad": 1, "vray_object_proxy_file": "", "vray_object_proxy_anim_speed": 1.0, "vray_object_proxy_anim_type": 0, "vray_object_proxy_anim_offset": 0.0, "vray_object_proxy_mindex": 1, "vray_object_proxy_m1": "", "vray_object_proxy_m2": "", "vray_object_proxy_m3": "", "vray_object_proxy_m4": "", "vray_object_proxy_m5": "", "vray_object_proxy_m6": "", "vray_object_proxy_m6": "", "vray_object_proxy_m7": "", "vray_object_proxy_m8": "", "vray_object_proxy_m9": "", "vray_object_proxy_m10": "", "vray_object_hair_thin": 0.002, "vray_object_hair0": "", "vray_object_hair1": "", "vray_object_hair2": "", "vray_object_hair3": "", "vray_object_hair4": "", "vray_object_hair5": "", "vray_mesh_uv1": "", "vray_mesh_uv2": "", "vray_mesh_uv3": "", "vray_mesh_uv4": "", "vray_mesh_uv5": "", "vray_mesh_uv6": "", "vray_mesh_uv7": "", "vray_mesh_uv8": "", 'vray_calcarea_type': 0, 'vray_calcarea_id': 0, 'vray_calcarea_val': 0.0, } blendmode= { "0" : "1", # Mix -> None "1" : "6", # Multiply "2" : "4", # Add "3" : "5", # Subtract "4" : "0", # Divide -> None "5" : "9", # Darken "6" : "7", # Difference "7" : "8", # Lighten "8" : "3", # Screen -> Out "9" : "0", # Overlay "10" : "2", # Hue -> In "11" : "10", # Saturate "12" : "11", # Value -> Desaturate "13" : "12" # Color -> Illuminate } animtypes= { "0": "Static", "1": "Dynamic", } OBJ_TYPES= ('Mesh', 'Curve', 'MBall', 'Surf', 'Text', 'Empty') TEX_TYPES= [Texture.Types.IMAGE] def filename(path): (dir, name)= os.path.split(path) return name def s(name, value, ob=None): if(ob): if type(ob) is Types.MaterialType: ob.properties[name]= value elif ob.type == 'Lamp': ob.data.properties[name]= value else: ob.properties[name]= value else: scene.properties[name]= value def g(name, ob=None): if(ob): try: if type(ob) is Types.MaterialType: value= ob.properties[name] elif ob.type == 'Lamp': value= ob.data.properties[name] else: value= ob.properties[name] except: value= vray_object_defaults[name] s(name, value, ob) return value else: try: value= scene.properties[name] except: value= vray_defaults[name] s(name, value) return value def l(name, ob=None): if(ob): return lambda e,v: s(name, v, ob) else: return lambda e,v: s(name, v) def debug(s): if g("vray_debug"): print "V-Ray/Blender: %s"%(s) def stripName(text): for char in ' /\\=[]{}().,<>\'":;~!@#$%^&*|?': text= text.replace(char, "_") text= text.replace("+", "p") text= text.replace("-", "m") return text def getName(obj): return stripName(obj.name) def getColor(param, obj=None): if(obj): c = g(param, obj) else: c = g(param) return c[0],c[1],c[2] def copyfile(fp, dst): fp= cleanpath(expandpath(fp)) shutil.copy(fp, dst) def clean_dr_path(s): return s.replace("\\","/") def getPath(file): if g('vray_dr'): filename= basename(file) file_fullpath= cleanpath(expandpath(file)) dest_path= os.path.normpath(filenames['texpath']) if os.path.isfile(file_fullpath): debug("Copying \"%s\" to \"%s\""%(file_fullpath,dest_path)) copyfile(file_fullpath,dest_path) path= os.path.join(dest_path, filename) if(ostype == 'win32'): if(g('vray_dr_network') == 0): dr_path= "//%s/%s"%(hostname,clean_dr_path(path[3:])) else: dr_path= ".." + clean_dr_path(path[2:]) return dr_path else: return ".." + path if g('vray_export_path_over'): path= cleanpath(expandpath(file)) else: path= relpath(file) if(path[:2] == "//"): path= os.path.join("..",path[2:]) return path def getFilename(param, obj= None): # For GUI if(obj): path= g(param, obj) else: path= g(param) try: name= basename(path) except: return None return name def buildTexMenu(textures): tex_menu= "Texture: %t" tex_id= 0 for mtex in textures: if mtex: tex_menu+= "| %s %%x%d"%(mtex.tex.name, tex_id) tex_id+= 1 return tex_menu def output_image_type(): global scene ImgType= { "4": "jpg", "14": "tga", "17": "png", "20": "bmp", "22": "tiff", "23": "exr", "28": "vrimg", "30": "jpg" } try: imgType= ImgType[str(scene.getRenderingContext().imageType)] except: imgType= "png" return imgType def isProxy(ob): return (g("vray_object_proxy_file",ob) != "") def transformMatrix(matrix): return "Transform(Matrix(Vector(%f, %f, %f),Vector(%f, %f, %f),Vector(%f, %f, %f)),Vector(%f, %f, %f))"\ %(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]) def a(t): global frame if type(t) == type(1): if g("vray_export_animation") or g("vray_export_cameraloop"): return "interpolate((%i,%i))"%(frame,t) return "%i"%(t) elif type(t) == type(1.0): if g("vray_export_animation") or g("vray_export_cameraloop"): return "interpolate((%i,%.6f))"%(frame,t) return "%.6f"%(t) else: if g("vray_export_animation") or g("vray_export_cameraloop"): return "interpolate((%i,%s))"%(frame,t) return "%s"%(t) none_matrix= Matrix( [1.0,0.0,0.0], [0.0,1.0,0.0], [0.0,0.0,1.0], [0.0,0.0,0.0] ) ## ## GEOMETRY ## def generate_hair(ob, hairs, gfile= None, hair_name= None): coords= [] faces= [] delta= g("vray_object_hair_thin",ob) c0, c1, c2, c3 = 0, 1, 2, 3 print "V-Ray/Blender: Writing hair: %s"%(ob.name) for hair in hairs: for h in xrange(len(hair)-1): if h == 0: coords.extend([[ hair[h][0], hair[h][1], hair[h][2] ]]) coords.extend([[ hair[h][0]+delta, hair[h][1]+delta, hair[h][2] ]]) coords.extend([[ hair[h+1][0], hair[h+1][1], hair[h+1][2] ]]) coords.extend([[ hair[h+1][0]+delta, hair[h+1][1]+delta, hair[h+1][2] ]]) faces.extend([[c0, c2, c3, c1]]) c0= c2 c1= c3 c2+= 2 c3+= 2 c0+= 2 c1+= 2 c2+= 2 c3+= 2 vertex_out= "" for co in coords: vertex_out+= "Vector(%.6f,%.6f,%.6f),"%(tuple(co)) faces_out= "" for fa in faces: for v in [0,1,2,2,3,0]: faces_out+="%i,"%(fa[v]) if(vray_module): gfile= open(filenames["geometry"], 'a') gfile.write("\nGeomStaticMesh %s {"%(hair_name)) gfile.write("\n\tvertices= %s;"%(a("ListVector(%s)"%(vertex_out[:-1])))) gfile.write("\n\tfaces= %s;"%(a("ListInt(%s)"%(faces_out[:-1])))) gfile.write("\n}\n") if(vray_module): gfile.close() # me= bpy.data.meshes.new('TEMP_HAIR') # me.verts.extend(coords) # me.faces.extend(faces) # ob= bpy.data.scenes.active.objects.new(me, 'TEMP_HAIR_OBJ') # return ob, me def exportGeomDisplacedMesh(obj): obj_name= stripName(obj.data.name) out_name= "GeomDisp_%s"%(obj_name) s("vray_geometry_name", out_name, obj) amount= g("vray_displace_amount",obj) * g("vray_displace_amount_delim",obj) if(g("vray_displace_use_dispfac",obj)): amount= g("vray_displace_dispfac",obj) * g("vray_displace_amount_delim",obj) out = "\nGeomDisplacedMesh %s {"%(out_name) out+= "\n\tmesh= %s;"%("Geom_%s"%(obj_name)) out+= "\n\tdisplacement_tex_color= %s;"%(g("vray_displace_tex",obj)) out+= "\n\tdisplacement_amount= %.5f;"%(amount) out+= "\n\tdisplacement_shift= %.6f;"%(g("vray_displace_shift",obj)) out+= "\n\tuse_globals= %d;"%(g("vray_displace_use_globals",obj)) out+= "\n\tview_dep= %d;"%(g("vray_displace_view_dep",obj)) out+= "\n\tedge_length= %.6f;"%(g("vray_displace_edgeLength",obj)) out+= "\n\tmax_subdivs= %d;"%(g("vray_displace_maxSubdivs",obj)) out+= "\n\tkeep_continuity= %d;"%(g("vray_displace_keep_continuity",obj)) out+= "\n\twater_level= %.6f;"%(g("vray_displace_water_level",obj)) out+= "\n}\n" return out def exportGeomMeshFile(obj): global exported_proxy out= "" filename= basename(g("vray_object_proxy_file",obj)) out_name= "Geom_%s"%(stripName(filename)) if(filename not in exported_proxy): exported_proxy.append(filename) out+= "\nGeomMeshFile %s {"%(out_name) out+= "\n\tfile= \"%s\";"%(getPath(g("vray_object_proxy_file",obj))) out+= "\n\tanim_speed= %i;"%(g("vray_object_proxy_anim_speed",obj)) out+= "\n\tanim_type= %i;"%(g("vray_object_proxy_anim_type",obj)) out+= "\n\tanim_offset= %i;"%(g("vray_object_proxy_anim_offset",obj)) out+= "\n}\n" return out_name, out def exportMesh(obj, mesh, mesh_name, ofile): global progress def vertices(me): vertex_out= "" for vertex in me.verts: vertex_out+= "Vector(%.6f,%.6f,%.6f),"%(tuple(vertex.co)) return vertex_out[0:-1] def normals(me): normals_out = "" for face in me.faces: normal = face.no if(len(face.verts) == 3): for vertex in face.verts: if(face.smooth): normal= vertex.no normals_out += "Vector(%.6f,%.6f,%.6f),"%(tuple(normal)) else: for v in [0,1,2,2,3,0]: vertex= face.verts[v] if(face.smooth): normal= vertex.no normals_out += "Vector(%.6f,%.6f,%.6f),"%(tuple(normal)) return normals_out[0:-1] def mapchannelsList(obj, me): out= "" uvArray= {} out+= "\n\tmap_channels= List(" uvLayers= me.getUVLayerNames() activeUVLayer= me.activeUVLayer for uvLayer in uvLayers: mapchannelVertexList = "" mapchannelFaceList = "" me.activeUVLayer= uvLayer uv_id= uvLayers.index(uvLayer)+1 s("vray_mesh_uv%i"%(uv_id), uvLayer, obj) out+= "\n\t\t// %s"%(uvLayer) out+= "\n\t\tList(%d,"%(uv_id) u = 0 for face in me.faces: for uv in face.uv: uv_coord = "%.6f,%.6f,0"%(uv[0],uv[1]) mapchannelVertexList += "Vector(%s),"%(uv_coord) uvArray[uv_coord] = u u += 1 for face in me.faces: if(len(face.uv) == 3): for uv in face.uv: mapchannelFaceList += "%i,"%(uvArray["%.6f,%.6f,0"%(uv[0], uv[1])]) else: quvArray = {} v = 0 for uv in face.uv: uv_coord = "%.6f,%.6f,0"%(uv[0], uv[1]) quvArray[v] = uv_coord v += 1 for l in [0,1,2,2,3,0]: mapchannelFaceList += "%i,"%(uvArray[quvArray[l]]) out += "ListVector(%s),"%(mapchannelVertexList[0:-1]) out += "ListInt(%s)"%(mapchannelFaceList[0:-1]) if(uvLayer == uvLayers[len(uvLayers)-1]): out += ")" else: out += ")," me.activeUVLayer= activeUVLayer out += "\n\t);" return out context= scene.getRenderingContext() out_name= "Geom_%s"%(stripName(mesh_name)) faces= "" faceNormals= "" face_mtlIDs= "" n= 0 for face in mesh.faces: face_mtlIDs+= "%s,"%(face.mat) if(len(face.verts) == 3): for vertex in face.verts: faceNormals+= "%i,"%(n) faces+= "%i,"%(vertex.index) n+= 1 else: face_mtlIDs+= "%s,"%(face.mat) for v in [0,1,2,2,3,0]: faceNormals+= "%i,"%(n) faces+= "%i,"%(face.verts[v].index) n+= 1 f= 0 fc= 0 fcount= len(mesh.faces) ev_str= "" edge_visibility= "" if fcount < 5: for face in mesh.faces: if(len(face.verts) == 3): ev_str+= "111" else: ev_str+= "011011" edge_visibility+= "%i,"%(int(ev_str, 2)) else: f= 0 for face in mesh.faces: if(len(face.verts) == 3): ev_str+= "111" f+= 1 else: ev_str+= "011011" f+= 2 if(f == 10): edge_visibility+= "%i,"%(int(ev_str, 2)) ev_str= "" f= 0 left_faces= fcount % 10 if left_faces: ev_str= "" for lf in xrange(fcount-left_faces, fcount): if(len(mesh.faces[lf].verts) == 3): ev_str+= "111" else: ev_str+= "011011" edge_visibility+= "%i,"%(int(ev_str, 2)) map_channels= "" if mesh.faceUV: map_channels= mapchannelsList(obj, mesh) ofile.write("\nGeomStaticMesh %s {"%(out_name)) ofile.write("\n\tvertices= %s;"%(a("ListVector(%s)"%(vertices(mesh))))) ofile.write("\n\tnormals= %s;"%(a("ListVector(%s)"%(normals(mesh))))) ofile.write("\n\tfaces= %s;"%(a("ListInt(%s)"%(faces[:-1])))) ofile.write("\n\tfaceNormals= %s;"%(a("ListInt(%s)"%(faceNormals[:-1])))) if(edge_visibility != ""): ofile.write("\n\tedge_visibility= %s;"%(a("ListInt(%s)"%(edge_visibility[:-1])))) ofile.write("\n\tface_mtlIDs= %s;"%(a("ListInt(%s)"%(face_mtlIDs[:-1])))) if mesh.faceUV: ofile.write(map_channels) ofile.write("\n}\n") return out_name def writeGeometry(): global filenames global progress global progress_step global frame global exported_meshes exported_meshes= [] OBJECTS= scene.objects progress= 0.0 progress_step= 1.0/len(OBJECTS) start_time= time() print "V-Ray/Blender: Writing meshes..." DrawProgressBar(0.0, "") ofile= open(filenames["geometry"], 'w') ofile.write("// V-Ray/Blender: Geometry\n") if(vray_module): ofile.close() def mesh(ob, base_name= None): def me(ob, me_name, me_mesh= None): if not ob.type == 'Empty': if me_mesh: me= me_mesh else: try: me= Mesh.New() me.getFromObject(ob, 0, 1) except: return if(len(me.faces)): exported_meshes.append(me_name) s("vray_mesh_valid", 1, ob) if ob.lib: debug("Library: %s => Object: %s => Mesh: %s"%(lib_name, ob.name, ob.data.name)) else: debug("Object: %s => Mesh: %s"%(ob.name, ob.data.name)) if(vray_module): VRayExportMesh(filenames["geometry"], ob, "Geom_%s"%(me_name)) else: exportMesh(ob, me, me_name, ofile) else: s("vray_mesh_valid", 0, ob) print "Object: %s => Incorrect mesh!"%(ob.name) if ob.type in OBJ_TYPES: if not ob.restrictRender: def is_instance(me_name): if(g("vray_export_instances")): if(me_name in exported_meshes): return 1 return 0 if not g("vray_export_animation"): DrawProgressBar(progress, "Geometry: %s "%(ob.name)) if ob.type == 'Empty': me_name= ob.name s("vray_mesh_valid", 1, ob) else: if(g("vray_export_instances")): me_name= ob.data.name else: me_name= ob.name if ob.lib: lib_name= filename(ob.lib) me_name= "%s_%s"%(me_name, lib_name) elif base_name: me_name= "%s_%s"%(base_name, me_name) s("vray_geometry_name", stripName("Geom_%s"%(me_name)), ob) if(is_instance(me_name)): if ob.lib: debug("Library: %s => Object: %s => Mesh: %s (instance)"%(lib_name, ob.name, ob.data.name)) else: debug("Object: %s => Mesh: %s (instance)"%(ob.name, ob.data.name)) s("vray_mesh_valid", 1, ob) return render= 1 psystems= ob.getParticleSystems() if(len(psystems)): ps_number= 0 for ps in psystems: pcount= ps.amount if not ps.renderEmitter: render= 0 # System type: Hair if(ps.type == 2): if g("vray_dohair"): # Particles: Path if(ps.drawAs == 6): locations= ps.getLoc(1, 0) if locations: hair_name= g("vray_object_hair%i"%(ps_number), ob) if hair_name == "": hair_name= stripName("Geom_Hair_%i_%s"%(ps_number, me_name)) s("vray_object_hair%i"%(ps_number), hair_name, ob) generate_hair(ob, locations, ofile, hair_name) # (hair_obj, hair_mesh)= generate_hair(locations) # me(hair_obj, hair_name, hair_mesh) # bpy.data.scenes.active.objects.unlink(hair_obj) ps_number+= 1 else: for i in xrange(5): s("vray_object_hair%i"%(i), "", ob) if not render: return if(ob.enableDupFaces|ob.enableDupVerts|ob.enableDupGroup): if ob.DupObjects: for dup_ob, dup_matrix in ob.DupObjects: if ob.enableDupGroup: mesh(dup_ob, ob.name) else: mesh(dup_ob) if g("vray_export_dupli"): me(ob, me_name) else: me(ob, me_name) def meshes(obs): global frame global progress global progress_step for ob in obs: if(g("vray_export_active")): if(ob.Layers & scene.Layers): if not vray_module: if g("vray_export_animation"): DrawProgressBar(progress, "(%d) Writing geometry..."%(frame)) else: DrawProgressBar(progress, "Mesh: %s "%(ob.name)) mesh(ob) else: if not vray_module: if g("vray_export_animation"): DrawProgressBar(progress, "(%d) Writing geometry..."%(frame)) else: DrawProgressBar(progress, "Mesh: %s "%(ob.name)) mesh(ob) if not g("vray_export_animation"): progress+= progress_step if(g("vray_export_animation")): meshes_static= [] meshes_dynamic= [] for ob in OBJECTS: if g("vray_object_dynamic",ob): meshes_dynamic.append(ob) else: meshes_static.append(ob) context= scene.getRenderingContext() progress= 0.0 progress_step= float(1.0/(context.eFrame-context.sFrame+1)) frame= context.sFrame Blender.Set("curframe", frame) meshes(meshes_static) if(len(meshes_dynamic)): for f in xrange(context.sFrame, context.eFrame+1): frame= f exported_meshes= [] Blender.Set("curframe", frame) meshes(meshes_dynamic) progress+= progress_step else: meshes(OBJECTS) if not vray_module: ofile.write("// vim: set syntax=on syntax=c:\n") ofile.close() DrawProgressBar(1.0, "") print "V-Ray/Blender: Writing meshes... done [%.3f s.]"%(time()-start_time) ## ## MATERIALS ## def exportVolumeScatterFog(name, obj=None): out_name= "VolumeScatterFog_%s"%(name) out = "\nVolumeScatterFog %s {"%(name) if(obj): if type(obj) is Types.MaterialType: out+= "\n\tcolor= Color(%.6f, %.6f, %.6f);"%(obj.R,obj.G,obj.B) else: out+= "\n\tenvironment_fog=1;" out+= "\n\tcolor= Color(%.6f, %.6f, %.6f);"%(getColor("vray_env_volume_color")) out+= "\n\tcolor_mult= %.3f;"%(0.1) out+= "\n\tior= %.3f;"%(1.0) out+= "\n\tbias= %.3f;"%(0.0) out+= "\n\tsubdivs= %d;"%(8) out+= "\n\tthickness= %.3f;"%(100.0) out+= "\n\tlight_mult= %.3f;"%(1.0) out+= "\n\tscatter_coeff= %.3f;"%(0.0) out+= "\n\tscatter_direction= %.3f;"%(1.0) out+= "\n\tscatter_levels= %d;"%(1) out+= "\n}\n" return out_name, out def exportUVWGenEnvironment(uv_type, params=None): uvtype= { "0" : "spherical", "1" : "screen", "2" : "mirror_ball", "3" : "cubic", "4" : "angular" } out_name= "UVWGenEnvironment_%s"%(uvtype[str(uv_type)]) out = "\nUVWGenEnvironment %s {"%(out_name) if(params): out+= "\n\tuvw_transform= %s;"%(transformMatrix(RotationMatrix(params[0], 4, 'z'))) out+= "\n\tmapping_type= \"%s\";"%(uvtype[str(uv_type)]) out+= "\n\twrap_u=1;" out+= "\n\twrap_v=1;" out+= "\n\tcrop_u=0;" out+= "\n\tcrop_v=0;" out+= "\n}\n" return out_name, out def exportUVWGenChannel(obj, mtex): (xrepeat, yrepeat)= mtex.tex.repeat bitmap_name= mtex.tex.image.name uvLayer= mtex.uvlayer uvLayer_idx= 1 if(not uvLayer == ""): if 0: for uv_item in tex_uv: if(uv_item[0] == uvLayer): uvLayer_idx= uv_item[1] else: for l in xrange(1,9): if(uvLayer == g("vray_mesh_uv%i"%(l), obj)): uvLayer_idx= l break out_name= "UVWGenChannel_%s"%(stripName(bitmap_name)) out = "\nUVWGenChannel %s {"%(out_name) out+= "\n\tuvw_channel= %d;"%(uvLayer_idx) out+= "\n\tuvw_transform= Transform(" out+= "\n\t\tMatrix(" out+= "\n\t\t\tVector(1.0,0.0,0.0)*%s,"%(xrepeat) out+= "\n\t\t\tVector(0.0,1.0,0.0)*%s,"%(yrepeat) out+= "\n\t\t\tVector(0.0,0.0,1.0)" out+= "\n\t\t)," out+= "\n\t\tVector(0.0,0.0,0.0)" # xoffset, yoffset, 0.0 out+= "\n\t);" out+= "\n}\n" return out_name, out def exportUVWGenObject(obj, mtex): (xrepeat, yrepeat)= mtex.tex.repeat out_name= "UVWGenObject_%s"%(stripName(obj.name)) out = "\nUVWGenObject %s {"%(out_name) out+= "\n\tuvw_transform= Transform(" out+= "\n\t\tMatrix(" out+= "\n\t\t\tVector(1.0,0.0,0.0)*%s,"%(xrepeat) out+= "\n\t\t\tVector(0.0,1.0,0.0)*%s,"%(yrepeat) out+= "\n\t\t\tVector(0.0,0.0,1.0)" out+= "\n\t\t)," out+= "\n\t\tVector(0.0,0.0,0.0)" # xoffset, yoffset, 0.0 out+= "\n\t);" out+= "\n}\n" return out_name, out def exportBitmapBuffer(obj, tex): global exported_bitmaps if(type(tex) is Types.MTexType): tex= tex.tex out= "" bitmap_name= tex.image.name out_name= "BitmapBuffer_%s"%(stripName(bitmap_name)) if(bitmap_name not in exported_bitmaps): exported_bitmaps.append(bitmap_name) out+= "\nBitmapBuffer %s {"%(out_name) fname= tex.image.filename if tex.lib and fname[:2] == "//": fpath= fname[2:] lib_dir= dirname(cleanpath(expandpath(tex.lib))) full_path= cleanpath(join(lib_dir,fpath)) scene_dir= dirname(filenames["scene"]) rel_lib_path= os.path.relpath(full_path,scene_dir) out+= "\n\tfile= %s;"%(a("\"%s\""%(rel_lib_path))) else: out+= "\n\tfile= %s;"%(a("\"%s\""%(getPath(fname)))) filter_type= 0 if(tex.imageFlags & Texture.ImageFlags['INTERPOL']): if(tex.imageFlags & Texture.ImageFlags['MIPMAP']): filter_type= 1 else: filter_type= 2 out+= "\n\tfilter_type= %d;"%(filter_type) out+= "\n\tfilter_blur= %.3f;"%(tex.filterSize) out+= "\n\tgamma= %.6f;"%(g("vray_inputgamma")) out+= "\n}\n" return out_name, out def exportTexBitmap(mtex, obj=None, env=None, env_type=None): if(type(mtex) is Types.TextureType): tex= mtex else: tex= mtex.tex out= "" uv_out= "" bitmap_out= "" tex_name= tex.name out_name= "TexBitmap_%s"%(stripName(tex_name)) if(env): (uv_name, uv_out)= exportUVWGenEnvironment(env_type) else: (uv_name, uv_out)= exportUVWGenChannel(obj, mtex) out= uv_out + out (bitmap_name, bitmap_out)= exportBitmapBuffer(obj, tex) out= bitmap_out + out out+= "\nTexBitmap %s {"%(out_name) out+= "\n\tbitmap= %s;"%(bitmap_name) out+= "\n\tuvwgen= %s;"%(uv_name) out+= "\n\tnouvw_color= AColor(0,0,0,0);" if not env: if(mtex.tex.extend == Texture.ExtendModes['CLIP']): out+= "\n\ttile= %d;"%(0) out+= "\n}\n" return out_name, out def exportTexInvert(tex): out_name= "TexInvert_%s"%(tex) out= "\nTexInvert %s {"%(out_name) out+= "\n\ttexture= %s;"%(tex) out+= "\n}\n" return out_name, out def exportTexFresnel(vraymat): mat= vraymat["blendermat"] mir= 1.0 - mat.rayMirr out_name= "TexFresnel_%s"%(vraymat["name"]) out = "\nTexFresnel %s {"%(out_name) out+= "\n\tblack_color= Color(0.0, 0.0, 0.0);" # if(vraymat["reflection_tex"]): # out+= "\n\twhite_color= %s;"%(vraymat["reflection_tex"]) # else: # out+= "\n\twhite_color= %s;"%(a("AColor(%.6f, %.6f, %.6f, 1.0)"%(mat.rayMirr, mat.rayMirr, mat.rayMirr))) if(vraymat["reflection_tex"]): out+= "\n\tblack_color= %s;"%(vraymat["reflection_tex"]) else: out+= "\n\tblack_color= %s;"%(a("AColor(%.6f, %.6f, %.6f, 1.0)"%(mir, mir, mir))) out+= "\n\tfresnel_ior= %.3f;"%(mat.getFresnelMirr()) out+= "\n}\n" return out_name, out def exportTexGradRamp(name, uvwgen, colors, positions, mat=None): global exported_textures out= "" out_name= "TexGradRamp_%s"%(name) if(out_name not in exported_textures): exported_textures.append(name) colors_str= "" positions_str= "" for color in colors: colors_str+= "Color(%.3f, %.3f, %.3f),"%(color[0], color[1], color[2]) for position in positions: positions_str+= "%.6f,"%(position) out+= "\nTexGradRamp %s {"%(out_name) out+= "\n\tuvwgen= %s;"%(uvwgen) #out+= "\n\ttile_u= %;"%()) # integer = 0, If true there is horizontal tiling #out+= "\n\ttile_v= %;"%()) # integer = 0, If true there is vertical tiling out+= "\n\tcolors= %s;"%(a("ListColor(%s)"%(colors_str[0:-1]))) out+= "\n\tpositions= %s;"%(a("ListFloat(%s)"%(positions_str[0:-1]))) # Gradient type: 0:four corner, 1:box, 2:diagonal, 3:lighting, 4:linear, # 5:mapped, 6:normal, 7:pong, 8:radial, 9:spiral, 10:sweep, 11:tartan out+= "\n\tgradient_type= %d;"%(4) # Interpolation: 0:none, 1:linear, 2:expUp, 3:expDown, 4:smooth, 5:bump, 6:spike out+= "\n\tinterpolation= %d;"%(1) out+= "\n}\n" return out_name, out def exportTexSky(): global exported_textures out= "" out_name= "VRaySky" if(out_name not in exported_textures): exported_textures.append(out_name) out+= "\nTexSky %s {"%(out_name) out+= "\n\tsun= VRaySun;" out+= "\n}\n" return out_name, out def exportTexAColorOp(tex, val, tex_name= None): if tex_name: out_name= "TexAColorOp_%s"%(tex_name) else: out_name= "TexAColorOp_%s"%(tex) out = "\nTexAColorOp %s {"%(out_name) out+= "\n\tcolor_a= %s;"%(a(tex)) out+= "\n\tmult_a= %s;"%(val) out+= "\n}\n" return out_name, out def exportTexCompMax(name, sourceA, sourceB): out_name= "TexCompMax_%s"%(name) out = "\nTexCompMax %s {"%(out_name) out+= "\n\tsourceA= %s;"%(sourceA) out+= "\n\tsourceB= %s;"%(sourceB) out+= "\n\toperator= %d;"%(3) out+= "\n}\n" return out_name, out def exportTexDirt(name, params= None): global exported_textures out= "" out_name= "TexDirt_%s"%(name) defaults= { 'white_color': "AColor(1.0, 1.0, 1.0, 1.0)", 'black_color': "AColor(0.0, 0.0, 0.0, 1.0)", 'radius': 0.1, 'subdivs': 16, 'ignore_for_gi': 1 } if out_name not in exported_textures: exported_textures.append(out_name) out+= "\nTexDirt %s {"%(out_name) for key in defaults: try: if params: out+= "\n\t%s= %s;"%(key, params[key]) except: out+= "\n\t%s= %s;"%(key, defaults[key]) out+= "\n}\n" return out_name, out def exportTexEdges(name, mat=None): global exported_textures out= "" out_name= "TexEdges_%s"%(name) if(out_name not in exported_textures): exported_textures.append(out_name) out+= "\nTexEdges %s {"%(out_name) if(mat): out+= "\n\tedges_tex= AColor(%.6f, %.6f, %.6f 1.0);"%(mat.R,mat.G,mat.B) out+= "\n\tbg_tex= AColor(%.6f, %.6f, %.6f 1.0);"%(mat.specR,mat.specG,mat.specB) else: out+= "\n\tedges_tex= AColor(0.1, 0.1, 0.1, 1.0);" out+= "\n\tbg_tex= AColor(0.8, 0.8, 0.8, 1.0);" out+= "\n\tshow_hidden_edges= 0;" out+= "\n\twidth_type= %d;"%(1) # 0 : World units, 1 : Pixels out+= "\n\tworld_width= %.3f;"%(1.0) out+= "\n\tpixel_width= %.3f;"%(0.5) out+= "\n}\n" return out_name, out def exportBRDFSSS2(vraymat): mat= vraymat["blendermat"] out_name= "BRDFSSS2_%s"%(getName(mat)) out = "\nBRDFSSS2 %s {"%(out_name) out+= "\n\tprepass_rate= %i;"%(-1) out+= "\n\tscale= %.3f;"%(mat.sssScale) out+= "\n\tior= %.3f;"%(mat.sssIOR) if(vraymat["color_tex"]): out+= "\n\tdiffuse_reflectance= %s;"%(vraymat["color_tex"]) else: out+= "\n\tdiffuse_reflectance= %s;"%(a("AColor(%.6f, %.6f, %.6f, 1)"%(mat.sssR,mat.sssG,mat.sssB))) out+= "\n\tscatter_radius= %s;"%(a("AColor(%.6f, %.6f, %.6f, 1)"%(mat.sssRadiusRed,mat.sssRadiusGreen,mat.sssRadiusBlue))) out+= "\n\tscatter_radius_mult= %.3f;"%(1.0) out+= "\n\tsubdivs= %d;"%(mat.sampGlossMir) out+= "\n\tphase_function= %.3f;"%(0.0) out+= "\n\tsingle_scatter= %i;"%(1) out+= "\n\tfront_scatter= %i;"%(1) # bool out+= "\n\tback_scatter= %i;"%(1) # bool out+= "\n\tscatter_gi= %i;"%(0) # bool out+= "\n\tprepass_lod_threshold= %.3f;"%(4.0) out+= "\n\tprepass_blur= %.3f;"%(1.2) out+= "\n}\n" return out_name, out def exportBRDFLight(vraymat): mat= vraymat["blendermat"] out_name= "BRDFLight_%s"%(getName(mat)) out= "\nBRDFLight %s {"%(out_name) out+= "\n\temitOnBackSide= %s;"%(a(1)) color= "Color(%.6f, %.6f, %.6f)"%(mat.R*100*mat.emit,mat.G*100*mat.emit,mat.B*100*mat.emit) if(vraymat["color_tex"]): (color, tex_out)= exportTexAColorOp(vraymat["color_tex"], 100*mat.emit) out= tex_out + out if(vraymat["alpha_tex"]): out+= "\n\ttransparency= %s;"%(a(vraymat["alpha_tex"])) (alpha_tex, tex_out)= exportTexInvert(vraymat["alpha_tex"]) out= tex_out + out (color, tex_out)= exportTexCompMax("%s_mult"%(out_name), alpha_tex, color) out= tex_out + out else: out+= "\n\ttransparency= %s;"%(a(vraymat["alpha"])) out+= "\n\tcolor= %s;"%(a("%s"%(color))) out+= "\n}\n" return out_name, out def exportBRDFDiffuse(vraymat): mat= vraymat["blendermat"] out_name= "BRDFDiffuse_%s"%(vraymat["name"]) out = "\nBRDFDiffuse %s {"%(out_name) out+= "\n\tcolor= %s;"%(a(vraymat["color"])) if(vraymat["color_tex"]): out+= "\n\tcolor_tex= %s;"%(vraymat["color_tex"]) out+= "\n\tcolor_tex_mult= %.3f;"%(vraymat["color_tex_mult"]) out+= "\n\ttransparency= %s;"%(a(vraymat["alpha"])) if(vraymat["alpha_tex"]): out+= "\n\ttransparency_tex= %s;"%(a(vraymat["alpha_tex"])) out+= "\n\ttransparency_tex_mult= 1.0;" out+= "\n}\n" return out_name, out def exportBRDFBump(vraymat, base_brdf): out_name= "BRDFBump_%s"%(vraymat["name"]) out = "\nBRDFBump %s {"%(out_name) out+= "\n\tbase_brdf= %s;"%(base_brdf) out+= "\n\tbump_tex_color= %s;"%(vraymat["bump_tex"]) out+= "\n\tbump_tex_mult= %.6f;"%(vraymat["bump_amount"]) out+= "\n\tbump_shadows= 1;" out+= "\n\tmap_type= %i;"%(vraymat["bump_normal"]) out+= "\n}\n" return out_name, out def exportBRDFMirror(vraymat): mat= vraymat["blendermat"] out_name= "BRDFMirror_%s"%(vraymat["name"]) out = "\nBRDFMirror %s {"%(out_name) out+= "\n\tcolor= %s;"%(a("Color(%.3f, %.3f, %.3f)"%(mat.specR,mat.specG,mat.specB))) if(vraymat["reflection_tex"]): out+= "\n\ttransparency= Color(1.0,1.0,1.0);" out+= "\n\ttransparency_tex= %s;"%(a(vraymat["reflection_tex"])) if not mat.getFresnelMirr() > 0.0: out+= "\n\ttransparency_tex_mult= %.3f;"%(mat.rayMirr) else: out+= "\n\ttransparency= %s;"%(a(vraymat["reflection_transparensy"])) out+= "\n\tback_side= %d;"%(1 if mat.mode & Material.Modes['TRANSPSHADOW'] else 0) out+= "\n\ttrace_reflections= %d;"%(1 if mat.mode & Material.Modes['RAYMIRROR'] else 0) out+= "\n\ttrace_depth= %i;"%(mat.rayMirrDepth) try: out+= "\n\tcutoff= %.6f;"%(mat.threshMir) except: pass out+= "\n}\n" return out_name, out def exportBRDFGlossy(vraymat): mat= vraymat["blendermat"] out= "" out_name= "BRDFGlossy_%s"%(vraymat["name"]) if(mat.specShader == 1): out+= "\nBRDFPhong %s {"%(out_name) elif(mat.specShader == 4): out+= "\nBRDFWard %s {"%(out_name) else: out+= "\nBRDFBlinn %s {"%(out_name) out+= "\n\tcolor= %s;"%(a("Color(%.3f, %.3f, %.3f)"%(mat.specR,mat.specG,mat.specB))) out+= "\n\tsubdivs= %i;"%(mat.sampGlossMir) if(vraymat["reflection_tex"]): out+= "\n\ttransparency= Color(1.0,1.0,1.0);" out+= "\n\ttransparency_tex= %s;"%(a(vraymat["reflection_tex"])) if not mat.getFresnelMirr() > 0.0: out+= "\n\ttransparency_tex_mult= %s;"%(a(mat.rayMirr)) else: out+= "\n\ttransparency= %s;"%(a(vraymat["reflection_transparensy"])) out+= "\n\treflectionGlossiness= %s;"%(a(mat.glossMir)) out+= "\n\thilightGlossiness= %s;"%(a(mat.glossMir)) if(vraymat["reflectionGlossiness_tex"]): out+= "\n\treflectionGlossiness_tex= %s;"%(a("%s::out_intensity"%(vraymat["reflectionGlossiness_tex"]))) out+= "\n\thilightGlossiness_tex= %s;"%(a("%s::out_intensity"%(vraymat["reflectionGlossiness_tex"]))) out+= "\n\tback_side= %d;"%(1 if mat.mode & Material.Modes['TRANSPSHADOW'] else 0) out+= "\n\ttrace_reflections= %d;"%(1 if mat.mode & Material.Modes['RAYMIRROR'] else 0) out+= "\n\ttrace_depth= %i;"%(mat.rayMirrDepth) try: if(mat.specShader != 1): out+= "\n\tanisotropy= %s;"%(a(mat.anisotropy)) out+= "\n\tcutoff= %.6f;"%(mat.threshMir) except: pass out+= "\n}\n" return out_name, out def exportBRDFGlass(vraymat): mat= vraymat["blendermat"] out_name= "BRDFGlass_%s"%(vraymat["name"]) out = "\nBRDFGlass %s {"%(out_name) out+= "\n\tcolor= %s;"%(a(vraymat["color"])) if(vraymat["color_tex"]): out+= "\n\tcolor_tex= %s;"%(vraymat["color_tex"]) out+= "\n\tior= %.6f;"%(mat.IOR) out+= "\n\taffect_shadows= %d;"%(1 if mat.mode & Material.Modes['SHADOW'] else 0) out+= "\n\ttrace_refractions= 1;" out+= "\n\ttransparency= Color(0, 0, 0);" out+= "\n\ttrace_depth= %i;"%(mat.transDepth) try: out+= "\n\tcutoff= %.6f;"%(mat.threshTra) except: pass out+= "\n}\n" return out_name, out def exportBRDFGlassGlossy(vraymat): mat= vraymat["blendermat"] out_name= "BRDFGlassGlossy_%s"%(vraymat["name"]) out = "\nBRDFGlassGlossy %s {"%(out_name) out+= "\n\tcolor= %s;"%(vraymat["color"]) if(vraymat["color_tex"]): out+= "\n\tcolor_tex= %s;"%(vraymat["color_tex"]) out+= "\n\tglossiness= %.3f;"%(mat.glossTra) out+= "\n\tsubdivs= %i;"%(mat.sampGlossTra) out+= "\n\tior= %.6f;"%(mat.IOR) out+= "\n\taffect_shadows= %d;"%(1 if mat.mode & Material.Modes['SHADOW'] else 0) out+= "\n\ttrace_refractions= 1;" out+= "\n\ttrace_depth= %i;"%(mat.transDepth) try: out+= "\n\tcutoff= %.6f;"%(mat.threshTra) except: pass out+= "\n}\n" return out_name, out def material_name(mat): ma_name= mat.name if mat.lib: lib_name= filename(mat.lib) ma_name= "%s_%s"%(lib_name, ma_name) debug("Library: %s => Material: %s"%(lib_name,mat.name)) else: debug("Material: %s"%(mat.name)) return "Material_%s"%(stripName(ma_name)) def exportMaterial(mat, ob): global exported_bitmaps global exported_textures global exported_materials out= "" mat_name= material_name(mat) if mat_name not in exported_materials: exported_materials.append(mat_name) s("vray_volume_fog", 0, mat) s("vray_volume_name", "", mat) s("vray_displace", 0, mat) s("vray_displace_tex", "", mat) s("vray_displace_dispfac", 0, mat) out_tex= "" out_brdf= "" out_texlayered= "" out_texlayered_modes= "" vray_dispfac= 0.0 brdfs= [] vraytex= {} vraytex["color_tex"]= [] vraytex["bump_tex"]= [] vraytex["reflection_tex"]= [] vraytex["reflectionGlossiness_tex"]= [] vraytex["alpha_tex"]= [] vraytex["emit_tex"]= [] vraytex["displace_tex"]= [] vraymat= {} vraymat["blendermat"]= mat vraymat["name"]= mat_name vraymat["color"]= "Color(%.6f, %.6f, %.6f)"%(mat.R,mat.G,mat.B) vraymat["color_tex"]= None vraymat["color_tex_mult"]= 1.0 vraymat["bump_tex"]= None vraymat["bump_amount"]= 0.0 vraymat["bump_normal"]= 0 vraymat["reflection"]= "Color(%.6f, %.6f, %.6f)"%(mat.rayMirr,mat.rayMirr,mat.rayMirr) vraymat["reflection_transparensy"]= "Color(%.6f, %.6f, %.6f)"%(1-mat.rayMirr,1-mat.rayMirr,1-mat.rayMirr) vraymat["reflection_tex"]= None vraymat["reflectionGlossiness_tex"]= None vraymat["reflectionGlossiness_tex_mult"]= 1.0 vraymat["refractionGlossiness_tex"]= None vraymat["refractionGlossiness_tex_mult"]= 1.0 vraymat["alpha"]= "Color(%.6f, %.6f, %.6f)"%(1-mat.alpha,1-mat.alpha,1-mat.alpha) vraymat["alpha_tex"]= None vraymat["displace_tex"]= None texlayered_modes= [] texlayered_names= [] # Collecting textures for texture in mat.textures: if texture and texture.tex: if texture.tex.type in TEX_TYPES: if(texture.mapto & Texture.MapTo['COL']): vraytex["color_tex"].append(texture) if(texture.mapto & Texture.MapTo['NOR']): vraytex["bump_tex"].append(texture) vraymat["bump_amount"]= texture.norfac/100 vraymat["bump_normal"]= texture.tex.normalMap # bool if(texture.mapto & Texture.MapTo['RAYMIR']): vraytex["reflection_tex"].append(texture) vraymat["reflection_tex_mul"]= texture.colfac if(texture.mapto & Texture.MapTo['SPEC']): vraytex["reflectionGlossiness_tex"].append(texture) vraymat["reflectionGlossiness_tex_mult"]= texture.varfac if(texture.mapto & Texture.MapTo['ALPHA']): vraytex["alpha_tex"].append(texture) if(texture.mapto & Texture.MapTo['DISP']): vraytex["displace_tex"].append(texture) vray_dispfac= texture.dispfac for textype in vraytex: if(len(vraytex[textype])): if(len(vraytex[textype]) == 1): texture= vraytex[textype][0] (vraymat[textype], tex_out)= exportTexBitmap(texture, ob) out_tex+= tex_out debug(" Slot: %s"%(textype)) debug(" Texture: %s"%(texture.tex.name)) if textype == "color_tex": if(texture.stencil): tex_name= "TexBlend_%s"%(vraymat[textype]) out_tex+= "\nTexBlend %s {"%(tex_name) out_tex+= "\n\tcolor_a= %s;"%("AColor(%.3f,%.3f,%.3f,1.0)"%(mat.R,mat.G,mat.B)) out_tex+= "\n\tcolor_b= %s;"%(vraymat[textype]) out_tex+= "\n\tblend_amount= %s::out_alpha;"%(vraymat[textype]) out_tex+= "\n\tcomposite= %d;"%(0) out_tex+= "\n}\n" vraymat[textype]= tex_name if(texture.colfac < 1.0): tex_name= "TexCombineColor_%s"%(vraymat[textype]) out_tex+= "\nTexCombineColor %s {"%(tex_name) out_tex+= "\n\tcolor= %s;"%("AColor(%.3f,%.3f,%.3f,1.0)"%(mat.R,mat.G,mat.B)) out_tex+= "\n\ttexture= %s;"%(vraymat[textype]) out_tex+= "\n\ttexture_multiplier= %s;"%(a(texture.colfac)) out_tex+= "\n}\n" vraymat[textype]= tex_name else: stencil= 0 for texture in vraytex[textype]: (tex_name, tex_out)= exportTexBitmap(texture, ob) out_tex+= tex_out texlayered_names.append(tex_name) # For stencil texlayered_modes.append(blendmode[str(texture.blendmode)]) out_texlayered += "%s,"%(tex_name) debug(" Slot: %s"%(textype)) debug(" Texture: %s [mode: %s (%s)]"%(texture.tex.name, texture.blendmode, blendmode[str(texture.blendmode)])) if(texture.stencil): stencil= vraytex[textype].index(texture) for i in xrange(1, len(texlayered_modes)): out_texlayered_modes+= "%s,"%(texlayered_modes[i]) if(stencil): tex_name= "%s_Stencil_%s_"%(mat_name, textype) out_tex+= "\nTexBlend %s {"%(tex_name) out_tex+= "\n\tcolor_a= %s;"%(texlayered_names[stencil-1]) out_tex+= "\n\tcolor_b= %s;"%(texlayered_names[stencil+1]) out_tex+= "\n\tblend_amount= %s::out_intensity;"%(texlayered_names[stencil]) out_tex+= "\n\tcomposite= %d;"%(0) out_tex+= "\n}\n" else: tex_name= "%s_TexLayered_%s"%(mat_name, textype) out_tex+= "\nTexLayered %s {"%(tex_name) out_tex+= "\n\ttextures= List(%s);"%(out_texlayered[0:-1]) out_tex+= "\n\tblend_modes= List(0, %s);"%(out_texlayered_modes[0:-1]) out_tex+= "\n}\n" vraymat[textype]= tex_name if(vraymat["displace_tex"]): s("vray_displace", 1, mat) s("vray_displace_tex", vraymat["displace_tex"], mat) s("vray_displace_dispfac", vray_dispfac, mat) if(mat.mode & Material.Modes['HALO']): (volume_name, volume_out)= exportVolumeScatterFog(stripName(mat_name), mat) s("vray_volume_fog", 2, mat) s("vray_volume_name", volume_name, mat) out_tex+= volume_out else: if(mat.mode & Material.Modes['RAYTRANSP']): if(mat.mirR < 0.999 or mat.mirG < 0.999 or mat.mirB < 0.999): volume_name= "VolumeFog_%s"%(stripName(mat_name)) out_tex+= "\nVolumeFog %s {"%(volume_name) out_tex+= "\n\tcolor= %s;"%(a("Color(%.6f, %.6f, %.6f)"%(mat.mirR,mat.mirG,mat.mirB))) out_tex+= "\n\tcolor_mult= %.6f;"%(mat.getTranslucency() * 100) out_tex+= "\n\tior= %.6f;"%(mat.IOR) out_tex+= "\n}\n" s("vray_volume_fog", 1, mat) s("vray_volume_name", volume_name, mat) else: if g("vray_object_add_AO", ob) and g("vray_do_AO_effect"): (tex_dirt_name, tex_out)= exportTexDirt(mat_name, { 'white_color': "AColor(%.3f,%.3f,%.3f,%.3f)"%(1.0,1.0,1.0, 1.0), 'black_color': "AColor(%s,%.3f)"%("%.3f,%.3f,%.3f"%(getColor("vray_AO_effect_color")), g("vray_AO_effect_alpha")), 'radius': g("vray_object_AO_radius", ob), 'subdivs': 6, 'ignore_for_gi': 0 }) out_tex+= tex_out if vraymat["color_tex"]: (vraymat["color_tex"], tex_out)= exportTexCompMax("%s_AO"%(mat_name), vraymat["color_tex"], tex_dirt_name) out_tex+= tex_out else: (vraymat["color_tex"], tex_out)= exportTexCompMax("%s_AO"%(mat_name), "AColor(%.3f,%.3f,%.3f,%.3f)"%(mat.R,mat.G,mat.B, 1.0), tex_dirt_name) out_tex+= tex_out if(vraymat["reflection_tex"]): (vraymat["reflection_tex"], tex_out)= exportTexInvert(vraymat["reflection_tex"]) out_tex+= tex_out if(mat.getFresnelMirr() > 0.0): (vraymat["reflection_tex"], tex_out)= exportTexFresnel(vraymat) out_tex+= tex_out if(mat.emit > 0.0): (brdf_name, brdf_out)= exportBRDFLight(vraymat) out_brdf+= brdf_out brdfs.append(brdf_name) else: if(mat.rayMirr > 0.0 or vraymat["reflection_tex"]): if(mat.glossMir < 1.0 or vraymat["reflectionGlossiness_tex"]): (brdf_name, brdf_out)= exportBRDFGlossy(vraymat) else: (brdf_name, brdf_out)= exportBRDFMirror(vraymat) out_brdf+= brdf_out brdfs.append(brdf_name) if(mat.enableSSS): (brdf_name, brdf_out)= exportBRDFSSS2(vraymat) elif(mat.mode & Material.Modes['RAYTRANSP']): if(mat.glossTra < 1.0): (brdf_name, brdf_out)= exportBRDFGlassGlossy(vraymat) else: (brdf_name, brdf_out)= exportBRDFGlass(vraymat) else: (brdf_name, brdf_out)= exportBRDFDiffuse(vraymat) out_brdf+= brdf_out brdfs.append(brdf_name) if(len(brdfs) == 1): base_brdf= brdfs[0] else: base_brdf= "BRDFLayered_%s"%(mat_name) out_brdf+= "\nBRDFLayered %s {"%(base_brdf) out_brdf+= "\n\tbrdfs= List(" brdfs_out= "" for brdf in brdfs: brdfs_out+= "\n\t\t%s,"%(brdf) out_brdf+= brdfs_out[0:-1] out_brdf+= "\n\t);" if(vraymat["alpha_tex"]): out_brdf+= "\n\ttransparency_tex= %s;"%(vraymat["alpha_tex"]) out_brdf+= "\n\ttransparency_tex_mult= 1.0;" out_brdf+= "\n}\n" if(vraymat["bump_tex"]): (base_brdf, brdf_out)= exportBRDFBump(vraymat,base_brdf) out_brdf+= brdf_out if(mat.name[0:6] == "2SIDED"): out+= "\nMtlSingleBRDF MtlSingleBRDF_%s {"%(mat_name) out+= "\n\tbrdf= %s;"%(base_brdf) out+= "\n\tdouble_sided= 0;" out+= "\n}\n" out+= "\nMtl2Sided %s {"%(mat_name) out+= "\n\tfront= MtlSingleBRDF_%s;"%(mat_name) out+= "\n\tback= MtlSingleBRDF_%s;"%(mat_name) out+= "\n\ttranslucency= Color(%.6f, %.6f, %.6f);"%(mat.amb,mat.amb,mat.amb) out+= "\n\tforce_1sided= 1;" out+= "\n}\n" else: out+= "\nMtlSingleBRDF %s {"%(mat_name) out+= "\n\tbrdf= %s;"%(base_brdf) out+= "\n\tdouble_sided= 1;" out+= "\n}\n" out= out_tex + out_brdf + out out= "\n//\n// Material: %s\n//"%(mat.name) + out if(g("vray_volume_fog",mat)): s("vray_volume_fog", g("vray_volume_fog",mat), ob) s("vray_volume_name", g("vray_volume_name",mat), ob) if(g("vray_displace",mat)): s("vray_displace", 1, ob) s("vray_displace_dispfac", g("vray_displace_dispfac",mat), ob) s("vray_displace_tex", g("vray_displace_tex",mat), ob) return mat_name, out def material(obj): global exported_materials global exported_mtlmulti out= "" out_mtls_list = "" out_ids_list = "" if obj.type == 'Empty': if isProxy(obj): mtl_name= "MtlMulti_%s"%(stripName(obj.name)) s("vray_object_base_material", mtl_name, obj) if mtl_name not in exported_mtlmulti: exported_mtlmulti.append(mtl_name) for i in xrange(1,g("vray_object_proxy_mindex",obj)+1): (ma_name, ma_out)= exportMaterial(Material.Get(g("vray_object_proxy_m%d"%(i),obj)),obj) out+= ma_out out_mtls_list+= "%s,"%(ma_name) out_ids_list += "%i,"%(i) out+= "\nMtlMulti %s {"%(mtl_name) out+= "\n\tmtls_list= List(%s);"%(out_mtls_list[0:-1]) out+= "\n\tids_list= ListInt(%s);"%(out_ids_list[0:-1]) out+= "\n}\n" else: obj_name= getName(obj.data) mtl_name= "MtlMulti_%s"%(obj_name) mats= obj.data.materials if(len(mats)): if(len(mats) == 1): (mtl_name, mat_out)= exportMaterial(mats[0], obj) s("vray_object_base_material", mtl_name, obj) out+= mat_out else: s("vray_object_base_material", mtl_name, obj) if mtl_name not in exported_mtlmulti: exported_mtlmulti.append(mtl_name) m= 0 for mat in mats: (mat_name, mat_out)= exportMaterial(mat, obj) out+= mat_out out_mtls_list+= "%s,"%(mat_name) out_ids_list += "%i,"%(m) m+= 1 out+= "\n//\n// Materials on mesh: %s\n//"%(obj.data.name) out+= "\nMtlMulti %s {"%(mtl_name) out+= "\n\tmtls_list= List(%s);"%(out_mtls_list[0:-1]) out+= "\n\tids_list= ListInt(%s);"%(out_ids_list[0:-1]) out+= "\n}\n" return out def writeMaterials(): global frame global progress global progress_step global exported_bitmaps global exported_textures global exported_materials global exported_mtlmulti global tex_uv global tex_uv_idx exported_bitmaps= [] exported_textures= [] exported_materials= [] exported_mtlmulti= [] print "V-Ray/Blender: Writing materials..." mfile= open(filenames["materials"], 'w') mfile.write("// V-Ray/Blender: Materials\n") mfile.write("\n//\n// Material: TEMP\n//") mfile.write("\nBRDFDiffuse BRDFDiffuse_Temp {") mfile.write("\n\tcolor=Color(0.5, 0.5, 0.5);") mfile.write("\n}\n") mfile.write("\nMtlSingleBRDF Material_Temp {") mfile.write("\n\tbrdf= BRDFDiffuse_Temp;") mfile.write("\n}\n") if g("vray_mtl_overall"): tmp_name= "OVERRIDE" over_name= "Material_%s"%(tmp_name) out= "\n\n//\n// %s\n//"%(over_name) if(g("vray_mtl_overall_type") == 1): (tex_name, tex_out)= exportTexEdges(tmp_name) out+= tex_out out+= "\nBRDFDiffuse BRDFDiffuse_%s {"%(tmp_name) out+= "\n\tcolor_tex= %s;"%(tex_name) out+= "\n}\n" out+= "\nMtlSingleBRDF %s {"%(over_name) out+= "\n\tbrdf= BRDFDiffuse_%s;"%(tmp_name) out+= "\n}\n" elif(g("vray_mtl_overall_type") == 2): (tex_name, tex_out)= exportTexDirt(tmp_name) out+= tex_out out+= "\nBRDFDiffuse BRDFDiffuse_%s {"%(tmp_name) out+= "\n\tcolor_tex= %s;"%(tex_name) out+= "\n}\n" out+= "\nMtlSingleBRDF %s {"%(over_name) out+= "\n\tbrdf= BRDFDiffuse_%s;"%(tmp_name) out+= "\n}\n" elif(g("vray_mtl_overall_type") == 3): (tex_name, tex_out)= exportTexDirt(tmp_name) out+= tex_out (tex_name, tex_out)= exportTexAColorOp(tex_name, 5) out+= tex_out out+= "\nBRDFLight BRDFLight_%s {"%(tmp_name) out+= "\n\tcolor= %s;"%(tex_name) out+= "\n}\n" out+= "\nMtlSingleBRDF %s {"%(over_name) out+= "\n\tbrdf= BRDFLight_%s;"%(tmp_name) out+= "\n}\n" else: out+= "\nBRDFDiffuse BRDFDiffuse_%s {"%(tmp_name) out+= "\n\tcolor= Color(%.6f,%.6f,%.6f);"%(0.8,0.8,0.8) out+= "\n}\n" out+= "\nMtlSingleBRDF %s {"%(over_name) out+= "\n\tbrdf= BRDFDiffuse_%s;"%(tmp_name) out+= "\n}\n" mfile.write(out) else: tex_uv= [] tex_uv_idx= 1 for ma in bpy.data.materials: for tex in ma.textures: if tex and tex.tex: if tex.tex.type in TEX_TYPES: uvLayer= tex.uvlayer if(not uvLayer == ""): new_uv= True for uv_item in tex_uv: if(uv_item[0] == uvLayer): new_uv= False if(new_uv): tex_uv.append((uvLayer, tex_uv_idx)) tex_uv_idx+= 1 debug(tex_uv) sce= bpy.data.scenes.active obs= sce.objects def mat(): def mat(ob): s("vray_displace", 0, ob) s("vray_displace_dispfac", 0.0, ob) s("vray_displace_tex", "", ob) if ob.type in OBJ_TYPES and not ob.restrictRender: mfile.write(material(ob)) if ob.enableDupGroup: for dup_ob, dup_matrix in ob.DupObjects: mat(dup_ob) for ob in obs: if(g("vray_export_active")): if(ob.Layers & sce.Layers): mat(ob) else: mat(ob) if g("vray_export_animation"): context= sce.getRenderingContext() progress= 0.0 progress_step= float(1.0/(context.eFrame-context.sFrame+1)) for f in xrange(context.sFrame, context.eFrame+1): frame= f exported_bitmaps= [] exported_textures= [] exported_materials= [] exported_mtlmulti= [] DrawProgressBar(progress, "(%d) Writing materials..."%(frame)) Blender.Set("curframe", frame) mat() progress+= progress_step else: progress= 0.0 progress_step= float(1.0/len(obs)) mat() if not vray_module: mfile.write("// vim: set syntax=on syntax=c:\n") mfile.close() print "V-Ray/Blender: Writing materials... done" if vray_module and 0: # Some nodes VRayExportMaterials(filenames["materials"]) ## ## NODES ## def writeNodes(): global frame global progress global progress_step global exported_proxy global exported_nodes exported_proxy= [] exported_nodes= [] obs= sce.objects start_time= time() print "V-Ray/Blender: Writing nodes..." DrawProgressBar(0.0, "") ofile= open(filenames["nodes"], 'w') ofile.write("// V-Ray/Blender: Nodes\n") def hide_list(cam): hidelist= { 'all': [], 'cam': [], 'gi': [], 'refl': [], 'refr': [], 'shad': [] } for h_type in ('all', 'cam', 'gi', 'refl', 'refr', 'shad'): if g("vray_camera_autohide_%s"%(h_type),cam): try: grp= Group.Get("hf_%s"%(cam.name)) for ob in grp.objects: if ob.type in OBJ_TYPES: hidelist[h_type].append(ob.name) except: pass else: hide_str= g("vray_camera_hidelist_%s"%(h_type),cam) hidelist[h_type]= hide_str.split(';') hidelist_dupli= [] for hide_item in hidelist[h_type]: try: grp= Group.Get(hide_item) for ob in grp.objects: if ob.type in OBJ_TYPES: hidelist_dupli.append(ob.name) except: continue hidelist[h_type].extend(hidelist_dupli) debug("Hide list: %s"%(hidelist)) return hidelist def wrapper(obj, node_name): base_material= g("vray_object_base_material", obj) if base_material == "": base_material= "Material_Temp" node_name= "MtlWrapper_%s"%(node_name) s("vray_material_name", node_name, obj) out = "\nMtlWrapper %s {"%(node_name) out+= "\n\tbase_material= %s;"%(base_material) out+= "\n\tgenerate_gi= %.3f;"%(g("vray_object_generate_gi", obj)) out+= "\n\treceive_gi= %.3f;"%(g("vray_object_receive_gi", obj)) out+= "\n\tgenerate_caustics= %.3f;"%(g("vray_object_generate_caustics", obj)) out+= "\n\treceive_caustics= %.3f;"%(g("vray_object_receive_caustics", obj)) out+= "\n\tmatte_surface= %i;"%(g("vray_object_matte_surface", obj)) out+= "\n\talpha_contribution= %.3f;"%(g("vray_object_alpha_contribution", obj)) out+= "\n\tshadows= %i;"%(g("vray_object_shadows", obj)) out+= "\n\taffect_alpha= %i;"%(g("vray_object_affect_alpha", obj)) out+= "\n\tshadow_brightness= %.3f;"%(g("vray_object_shadow_brightness", obj)) out+= "\n\treflection_amount= %.3f;"%(g("vray_object_reflection_amount", obj)) out+= "\n\trefraction_amount= %.3f;"%(g("vray_object_refraction_amount", obj)) out+= "\n\tgi_amount= %.3f;"%(g("vray_object_gi_amount", obj)) out+= "\n\tno_gi_on_other_mattes= %i;"%(g("vray_object_no_gi_on_other_mattes", obj)) out+= "\n\tgi_surface_id= %i;"%(g("vray_object_gi_surface_id", obj)) out+= "\n}\n" ofile.write(out) def write_particles(obj): psystems= obj.getParticleSystems() if(len(psystems)): ps_number= 0 for ps in psystems: pcount= ps.amount if ps.renderEmitter: write_node(obj) # System type: Hair if(ps.type == 2): if g("vray_dohair"): # Particles: Path if(ps.drawAs == 6): hair_name= g("vray_object_hair%i"%(ps_number),obj) write_node(obj, matrix= none_matrix, node_name="Node_%s"%(hair_name), hair=1, hair_name= hair_name) ''' Place object on hair segment ''' #locations= ps.getLoc(1, 0) #if locations: # writeHair(obj, locations) # hair_number= 0 # for loc in locations: # hair_segment_nubmer= 0 # for l in loc: # m= TranslationMatrix(Vector([l[0],l[1],l[2]])) # write_node(pobj, m, "Hair_%s_%i_%i"%(pobj_name, hair_number, hair_segment_nubmer)) # hair_segment_nubmer+= 1 # hair_number+= 1 if(ps.drawAs == 7): # Particles: Object pobj= ps.duplicateObject pobj_name= getName(pobj) # Make base particle object invisible #s("vray_visible", 0, pobj) locations= ps.getLoc(1, 0) if(ps.type == 2): # System type: Hair for i in xrange(pcount): loc= None try: loc= locations[i][0] except: pass if(loc): m= TranslationMatrix(Vector([loc[0],loc[1],loc[2]])) write_node(pobj, m, "Particle_%s_%i"%(pobj_name, i)) else: rot= ps.getRot(1, 0) sca= ps.getSize(1, 0) for i in xrange(pcount): l,r,s = None,None,None try: l,r,s = locations[i],rot[i],sca[i] except: pass if(l and r and s): m= pobj.matrixWorld * Quaternion(r).toMatrix().resize4x4() * ScaleMatrix(s, 4) * TranslationMatrix(Vector([l[0],l[1],l[2]])) write_node(pobj, m, "Particle_%s_%i"%(pobj_name, i), visible= 1) else: write_node(pobj, none_matrix, "Particle_%s_%i"%(pobj_name, i), visible= 0) ps_number+= 1 def write_node(ob, matrix= None, node_name= None, visible= None, hair= False, hair_name= None, render_stats= None): out= "" if not node_name: node_name= g("vray_node_name",ob) if g("vray_displace",ob): if g("vray_geom_displacement"): out+= exportGeomDisplacedMesh(ob) if visible == None: visible= g("vray_visible",ob) if g("vray_mtl_overall"): material= "Material_OVERRIDE" else: wrapper(ob, node_name) material= "MtlWrapper_%s"%(node_name) if g("vray_object_override_mtl",ob): over_name= "GI_OVERRIDE" over_brdf_name= "BRDFDiffuse_%s_%s"%(over_name,node_name) over_mat_name= "%s_%s"%(over_name,node_name) mtl_name= "%s_%s"%(over_name,material) out+= "\nBRDFDiffuse %s {"%(over_brdf_name) out+= "\n\tcolor= %s;"%(a("Color(%.6f, %.6f, %.6f)"%(tuple(getColor("vray_object_override_gi",ob))))) out+= "\n}\n" out+= "\nMtlSingleBRDF %s {"%(over_mat_name) out+= "\n\tbrdf= %s;"%(over_brdf_name) out+= "\n\tdouble_sided= 1;" out+= "\n}\n" out+= "\nMtlOverride %s {"%(mtl_name) out+= "\n\tbase_mtl= %s;"%(material) out+= "\n\tgi_mtl= %s;"%(over_mat_name) #out+= "\n\treflect_mtl= %s;"%() #out+= "\n\trefract_mtl= %s;"%() #out+= "\n\tshadow_mtl= %s;"%() out+= "\n}\n" material= mtl_name if render_stats: render_stats_defaults= { 'base_mtl': material, 'camera_visibility': 1, 'reflections_visibility': 1, 'refractions_visibility': 1, 'gi_visibility': 1, 'shadows_visibility': 1, 'visibility': 1 } material= "MtlRenderStats_%s"%(node_name) out+= "\nMtlRenderStats %s {"%(material) for key in render_stats_defaults: try: param= render_stats[key] except: param= render_stats_defaults[key] if key == 'base_mtl': out+= "\n\t%s= %s;"%(key, param) else: out+= "\n\t%s= %s;"%(key, a(param)) out+= "\n}\n" out+= "\nNode %s {"%(node_name) out+= "\n\tvisible= %s;"%(a(visible)) if visible: out+= "\n\tobjectID= %d;"%(ob.passIndex) if hair: out+= "\n\tgeometry= %s;"%(hair_name) elif isProxy(ob): proxy_filename= basename(g("vray_object_proxy_file",ob)) out+= "\n\tgeometry= %s;"%("Geom_%s"%(stripName(proxy_filename))) else: out+= "\n\tgeometry= %s;"%(g("vray_geometry_name",ob)) out+= "\n\tmaterial= %s;"%(material) if matrix: out+= "\n\ttransform= %s;"%(a(transformMatrix(matrix))) else: out+= "\n\ttransform= %s;"%(a(transformMatrix(ob.matrix))) if(g("vray_volume_fog",ob)): out+= "\n\tvolume= %s;"%(g("vray_volume_name",ob)) out+= "\n}\n" ofile.write(out) def node(ob, base_name= None, matrix= None, visible= None, hidelist= None, render_stats= None): out= "" if ob.type in OBJ_TYPES: if not ob.restrictRender: if not render_stats: render_stats= { 'camera_visibility': g("vray_object_visible_cam",ob), 'gi_visibility': g("vray_object_visible_gi",ob), 'reflections_visibility': g("vray_object_visible_refl",ob), 'refractions_visibility': g("vray_object_visible_refr",ob), 'shadows_visibility': g("vray_object_visible_shad",ob), 'visibility': 1 } if visible == None: if hidelist and g("vray_camera_usehide",camera): if ob.name in hidelist['all']: render_stats['visibility']= 0 if ob.name in hidelist['cam']: render_stats['camera_visibility']= 0 if ob.name in hidelist['gi']: render_stats['gi_visibility']= 0 if ob.name in hidelist['refl']: render_stats['reflections_visibility']= 0 if ob.name in hidelist['refr']: render_stats['refractions_visibility']= 0 if ob.name in hidelist['shad']: render_stats['shadows_visibility']= 0 else: render_stats['visibility']= g("vray_visible",ob) else: render_stats['visibility']= visible valid_mesh= 0 if(ob.type == 'Empty'): valid_mesh= 1 else: me= Mesh.New() me.getFromObject(ob, 1, 0) if(len(me.faces)): valid_mesh= 1 if(valid_mesh): ob_name= ob.name lib_name= None mesh_name= "" if ob.type == 'Empty': if isProxy(ob): (mesh_name, mesh_out)= exportGeomMeshFile(ob) ofile.write(mesh_out) elif ob.enableDupGroup and ob.DupObjects: mesh_name= stripName(ob.name) else: return "" else: if(g("vray_export_instances")): mesh_name= ob.data.name else: mesh_name= ob.name if ob.lib: lib_name= filename(ob.lib) ob_name= "%s_%s"%(ob_name,lib_name) mesh_name= "Geom_%s_%s"%(mesh_name,lib_name) else: mesh_name= "Geom_%s"%(mesh_name) ob_name= stripName(ob_name) s("vray_geometry_name", stripName(mesh_name), ob) node_name= "" if base_name: node_name= "Node_%s_%s"%(stripName(base_name), ob_name) else: node_name= "Node_%s"%(ob_name) debug("Object: %s"%(node_name)) s("vray_node_name", stripName(node_name), ob) if(ob.enableDupFaces|ob.enableDupVerts|ob.enableDupGroup): if ob.DupObjects: if g("vray_export_dupli"): write_node(ob, matrix, render_stats=render_stats) dup_index= 0 for dup_ob, dup_matrix in ob.DupObjects: dup_name= "%s_%s"%(ob.name,dup_index) if ob.enableDupGroup: dup_name= ob.name node(dup_ob, dup_name, dup_matrix, render_stats=render_stats) dup_index+= 1 elif len(ob.getParticleSystems()): write_particles(ob) else: write_node(ob, matrix, render_stats=render_stats) def nodes(hidelist= None): global progress for ob in obs: if(g("vray_export_active")): if(ob.Layers & sce.Layers): if g("vray_export_animation"): DrawProgressBar(progress, "(%d) Writing objects..."%(frame)) else: DrawProgressBar(progress, "Object: %s "%(ob.name)) node(ob, hidelist=hidelist) else: if g("vray_export_animation"): DrawProgressBar(progress, "(%d) Writing objects..."%(frame)) else: DrawProgressBar(progress, "Object: %s "%(ob.name)) node(ob, hidelist=hidelist) if not g("vray_export_animation"): progress+= progress_step if g("vray_export_animation"): progress= 0.0 progress_step= float(1.0/(context.eFrame-context.sFrame+1)) for f in xrange(context.sFrame, context.eFrame+1): frame= f exported_proxy= [] exported_nodes= [] Blender.Set("curframe", frame) nodes(hide_list(camera)) progress+= progress_step elif g("vray_export_cameraloop"): cameras= [ob for ob in sce.objects if (ob.type == 'Camera' and not ob.restrictRender and ob.Layers & sce.Layers)] frame= 0 for ca in cameras: frame+= 1 print "V-Ray/Blender: Writing nodes for camera: %s"%(ca.name) progress= 0.0 progress_step= float(1.0/len(obs)) nodes(hide_list(ca)) else: progress= 0.0 progress_step= float(1.0/len(obs)) nodes(hide_list(camera)) ofile.write("\n// vim: set syntax=on syntax=c:\n") ofile.close() DrawProgressBar(1.0, "") print "V-Ray/Blender: Writing nodes... done [%.3f s.]"%(time()-start_time) ### ### LIGHTS ### def lightOmni(obj): out = "\nLightOmni LightOmni_%s {"%(getName(obj)) out+= "\n\tenabled= 1;" out+= "\n\ttransform= %s;"%(a(transformMatrix(obj.matrix))) out+= "\n\tintensity= %s;"%(a(obj.data.energy * g("vray_light_intensity",obj))) out+= "\n\tcolor= %s;"%(a("Color(%.6f, %.6f, %.6f)"%(obj.data.R,obj.data.G,obj.data.B))) out+= "\n\tshadows= %i;"%(g("vray_light_shadows",obj)) out+= "\n\tshadowBias= %.3f;"%(g("vray_light_shadowBias",obj)) out+= "\n\tcausticSubdivs= %i;"%(g("vray_light_caustics_subdivs",obj)) out+= "\n\taffectDiffuse= %i;"%(g("vray_light_affectDiffuse",obj)) out+= "\n\taffectSpecular= %i;"%(g("vray_light_affectSpecular",obj)) out+= "\n\tunits= %i;"%(g("vray_light_units",obj)) out+= "\n\tshadowRadius= %.3f;"%(g("vray_light_shadowRadius",obj)) out+= "\n\tshadowSubdivs= %i;"%(g("vray_light_subdivs",obj)) out+= "\n}\n" return out def LightDome(obj): out= "" obj_name= getName(obj) tex_name= None for texture in obj.data.textures: if(texture): if(texture.tex.type == Texture.Types.IMAGE): (tex_name, out)= exportTexBitmap(texture, obj, 1, g("vray_IBL_mapping_type",obj)) out+= "\nLightDome LightDome_%s {"%(obj_name) out+= "\n\tenabled= 1;" out+= "\n\ttransform=%s;"%(a(transformMatrix(obj.matrix))) out+= "\n\tintensity= %s;"%(a(obj.data.energy * g("vray_light_intensity",obj))) out+= "\n\tcolor= %s;"%(a("Color(%.6f, %.6f, %.6f)"%(obj.data.R,obj.data.G,obj.data.B))) if(tex_name): out+= "\n\tuse_dome_tex= %d;"%(g("vray_light_use_dome_tex",obj)) out+= "\n\tdome_tex= %s;"%(tex_name) out+= "\n\tdome_spherical=%d;"%(g("vray_light_dome_spherifical",obj)) out+= "\n\tsubdivs=%i;"%(g("vray_light_subdivs",obj)) out+= "\n\tcausticSubdivs=%i;"%(g("vray_light_caustics_subdivs",obj)) out+= "\n\tstoreWithIrradianceMap=%i;"%(g("vray_light_store",obj)) out+= "\n\tinvisible=%i;"%(g("vray_light_invisible",obj)) out+= "\n\tunits=%i;"%(g("vray_light_units",obj)) out+= "\n\tshadows=%i;"%(g("vray_light_shadows",obj)) out+= "\n\tshadowBias=%.3f;"%(g("vray_light_shadowBias",obj)) out+= "\n\taffectDiffuse= %i;"%(g("vray_light_affectDiffuse",obj)) out+= "\n\taffectSpecular= %i;"%(g("vray_light_affectSpecular",obj)) out+= "\n\taffectReflections= %i;"%(g("vray_light_affectReflections",obj)) out+= "\n}\n" return out def LightRectangle(obj): out= "" out_textures= "" tex_name= None for texture in obj.data.textures: if(texture): if(texture.tex.type == Texture.Types.IMAGE): (tex_name, out)= exportTexBitmap(texture, obj, 0, 0) out+= "\nLightRectangle LightRectangle_%s {"%(getName(obj)) out+= "\n\ttransform= %s;"%(a(transformMatrix(obj.matrix))) out+= "\n\tu_size= %s;"%(a(obj.data.areaSizeX/2)) out+= "\n\tv_size= %s;"%(a(obj.data.areaSizeY/2)) out+= "\n\tlightPortal=%s;"%(g("vray_light_portal",obj)) out+= "\n\tintensity= %s;"%(a(obj.data.energy * g("vray_light_intensity",obj))) out+= "\n\tcolor= %s;"%(a("Color(%.6f, %.6f, %.6f)"%(obj.data.R,obj.data.G,obj.data.B))) if(tex_name): out+= "\n\trect_tex= %s;"%(tex_name) out+= "\n\tuse_rect_tex= 1;" out+= "\n\tstoreWithIrradianceMap= %i;"%(g("vray_light_store",obj)) out+= "\n\tnoDecay=0;" out+= "\n\tinvisible= %i;"%(g("vray_light_invisible",obj)) out+= "\n\tunits= %i;"%(g("vray_light_units",obj)) out+= "\n\tsubdivs= %i;"%(g("vray_light_subdivs",obj)) out+= "\n\tcausticSubdivs= %i;"%(g("vray_light_caustics_subdivs",obj)) out+= "\n\taffectDiffuse= %i;"%(g("vray_light_affectDiffuse",obj)) out+= "\n\taffectSpecular= %i;"%(g("vray_light_affectSpecular",obj)) out+= "\n\taffectReflections= %i;"%(g("vray_light_affectReflections",obj)) out+= "\n\tshadows= %i;"%(g("vray_light_shadows",obj)) out+= "\n\tshadowBias= %.3f;"%(g("vray_light_shadowBias",obj)) out+= "\n}\n" return out_textures + out def LightSphere(obj): out = "\nLightSphere LightSphere_%s {"%(getName(obj)) out+= "\n\tenabled= 1;" out+= "\n\ttransform=%s;"%(a(transformMatrix(obj.matrix))) out+= "\n\tcolor= %s;"%(a("Color(%.6f, %.6f, %.6f)"%(obj.data.R,obj.data.G,obj.data.B))) out+= "\n\tintensity= %s;"%(a(obj.data.energy * g("vray_light_intensity",obj))) out+= "\n\tunits= %i;"%(g("vray_light_units",obj)) out+= "\n\tinvisible= %i;"%(g("vray_light_invisible",obj)) out+= "\n\tsubdivs= %i;"%(g("vray_light_subdivs",obj)) out+= "\n\tcausticSubdivs= %i;"%(g("vray_light_caustics_subdivs",obj)) out+= "\n\tshadows= %i;"%(g("vray_light_shadows",obj)) out+= "\n\tradius= %.6f;"%(g("vray_light_radius",obj)) out+= "\n\taffectDiffuse= %i;"%(g("vray_light_affectDiffuse",obj)) out+= "\n\taffectSpecular= %i;"%(g("vray_light_affectSpecular",obj)) out+= "\n\taffectReflections= %i;"%(g("vray_light_affectReflections",obj)) out+= "\n\tshadowBias= %.3f;"%(g("vray_light_shadowBias",obj)) out+= "\n}\n" return out def LightSpot(obj): out = "\nLightSpot LightSpot_%s {"%(getName(obj)) out+= "\n\tenabled= 1;" out+= "\n\ttransform=%s;"%(a(transformMatrix(obj.matrix))) out+= "\n\tcolor= %s;"%(a("Color(%.6f, %.6f, %.6f)"%(obj.data.R,obj.data.G,obj.data.B))) out+= "\n\tconeAngle= %s;"%(a(math.radians(obj.data.spotSize))) out+= "\n\tpenumbraAngle= %s;"%(a(math.radians(-(obj.data.spotSize*obj.data.spotBlend)))) out+= "\n\tintensity= %s;"%(a(obj.data.energy * g("vray_light_intensity",obj))) out+= "\n\tunits= %i;"%(g("vray_light_units",obj)) out+= "\n\tshadows= %i;"%(g("vray_light_shadows",obj)) out+= "\n\tshadowBias= %.3f;"%(g("vray_light_shadowBias",obj)) out+= "\n\tshadowRadius= %.3f;"%(g("vray_light_shadowRadius",obj)) out+= "\n\tshadowSubdivs= %i;"%(g("vray_light_subdivs",obj)) out+= "\n\taffectDiffuse= %i;"%(g("vray_light_affectDiffuse",obj)) out+= "\n\taffectSpecular= %i;"%(g("vray_light_affectSpecular",obj)) out+= "\n\taffectReflections= %i;"%(g("vray_light_affectReflections",obj)) out+= "\n\tcausticSubdivs= %i;"%(g("vray_light_caustics_subdivs",obj)) out+= "\n\tcutoffThreshold= %.6f;"%(0.001) out+= "\n}\n" return out def LightIES(obj): out = "\nLightIES LightIES_%s {"%(getName(obj)) out+= "\n\tenabled= 1;" out+= "\n\ttransform=%s;"%(a(transformMatrix(obj.matrix))) out+= "\n\tpower= %s;"%(a(obj.data.energy * g("vray_light_intensity",obj))) out+= "\n\tcolor= %s;"%(a("Color(%.6f, %.6f, %.6f)"%(obj.data.R,obj.data.G,obj.data.B))) out+= "\n\tcutoffThreshold=0.001;" out+= "\n\tshadowSubdivs= %i;"%(g("vray_light_subdivs",obj)) out+= "\n\tcausticSubdivs= %i;"%(g("vray_light_caustics_subdivs",obj)) out+= "\n\ties_file=\"%s\";"%(getPath(g("vray_light_IES",obj))) out+= "\n\tfilter_color=Color(1, 1, 1);" out+= "\n\tsoft_shadows= %i;"%(g("vray_light_IES_soft_shadows",obj)) out+= "\n\tshadows= %i;"%(g("vray_light_shadows",obj)) out+= "\n\tshadowBias= %.3f;"%(g("vray_light_shadowBias",obj)) out+= "\n\taffectDiffuse= %i;"%(g("vray_light_affectDiffuse",obj)) out+= "\n\taffectSpecular= %i;"%(g("vray_light_affectSpecular",obj)) out+= "\n\taffectReflections= %i;"%(g("vray_light_affectReflections",obj)) out+= "\n}\n" return out def LightSun(obj): out = "\nSunLight VRaySun {" out+= "\n\tenabled= 1;" out+= "\n\ttransform=%s;"%(a(transformMatrix(obj.matrix))) out+= "\n\tshadowBias= %.6f;"%(g("vray_sunsky_shadow_bias")) out+= "\n\tturbidity= %.3f;"%(g("vray_sunsky_turbidity")) out+= "\n\tozone= %.3f;"%(g("vray_sunsky_ozone")) out+= "\n\tintensity_multiplier= %s;"%(a(obj.data.energy * g("vray_sunsky_intensity"))) out+= "\n\tsize_multiplier= %.3f;"%(g("vray_sunsky_size_multiplier")) out+= "\n\tinvisible= %i;"%(g("vray_sunsky_invisible")) out+= "\n\tshadow_subdivs= %i;"%(g("vray_sunsky_shadow_subdivs")) out+= "\n\tphoton_radius= %.3f;"%(g("vray_sunsky_photon_emit_radius")) out+= "\n\tphotonSubdivs= 500;" out+= "\n\tcausticSubdivs= %i;"%(g("vray_light_caustics_subdivs",obj)) out+= "\n\tup_vector= Vector(0,0,1);" out+= "\n}\n" return out def LightDirect(obj): out = "\nLightDirect LightDirect_%s {"%(getName(obj)) out+= "\n\tenabled= 1;" out+= "\n\ttransform=%s;"%(a(transformMatrix(obj.matrix))) out+= "\n\tcolor= %s;"%(a("Color(%.6f, %.6f, %.6f)"%(obj.data.R,obj.data.G,obj.data.B))) out+= "\n\tshadows= %i;"%(g("vray_light_shadows",obj)) out+= "\n\tshadowRadius= %.3f;"%(g("vray_light_shadowRadius",obj)) out+= "\n\tshadowSubdivs= %i;"%(g("vray_light_subdivs",obj)) out+= "\n\tphotonSubdivs=500;" out+= "\n\tcausticSubdivs= %i;"%(g("vray_light_caustics_subdivs",obj)) out+= "\n\tcutoffThreshold= 0.001;" out+= "\n\tunits= %i;"%(g("vray_light_units",obj)) out+= "\n\tintensity= %s;"%(a(obj.data.energy * g("vray_light_intensity",obj))) out+= "\n\tbeamRadius= %.6f;"%(g("vray_light_beamRadius",obj)) out+= "\n\tshadowBias= %.3f;"%(g("vray_light_shadowBias",obj)) out+= "\n\taffectDiffuse= %i;"%(g("vray_light_affectDiffuse",obj)) out+= "\n\taffectSpecular= %i;"%(g("vray_light_affectSpecular",obj)) out+= "\n\taffectReflections= %i;"%(g("vray_light_affectReflections",obj)) out+= "\n}\n" return out def exportLight(ob): out = "" lamp_type= ob.data.type if(lamp_type == 0): if(g("vray_light_sphere_type",ob)): out+= LightSphere(ob) else: out+= lightOmni(ob) elif(lamp_type == 1): if(g("vray_light_sun",ob)): out+= LightSun(ob) else: out+= LightDirect(ob) elif(lamp_type == 2): if(g("vray_light_isIES",ob)): out+= LightIES(ob) else: out+= LightSpot(ob) elif(lamp_type == 3): out+= LightDome(ob) elif(lamp_type == 4): out+= LightRectangle(ob) else: debug("Lamp \"%s\" - lamp type is not supported!"%(ob.name)) return out def writeLights(): global frame global progress global progress_step global filenames print "V-Ray/Blender: Writing lights..." lfile= open(filenames["lights"], 'w') lfile.write("// V-Ray/Blender: Lights\n") scene_lights= [ob for ob in bpy.data.scenes.active.objects if ob.type == 'Lamp' and not ob.restrictRender] progress= 0.0 progress_step= float(1.0/(len(scene_lights)+1)) DrawProgressBar(0.0, "") def lights(): global progress global progress_step for ob in scene_lights: if ob.Layers & scene.Layers: if g("vray_export_animation"): DrawProgressBar(progress, "(%d) Writing lights..."%(frame)) else: DrawProgressBar(progress, "Light: %s "%(ob.name)) lfile.write(exportLight(ob)) else: if(g("vray_light_doHiddenLights")): if g("vray_export_animation"): DrawProgressBar(progress, "(%d) Writing lights..."%(frame)) else: DrawProgressBar(progress, "Light: %s "%(ob.name)) lfile.write(exportLight(ob)) if not g("vray_export_animation"): progress+= progress_step if(g("vray_export_animation")): context= scene.getRenderingContext() progress= 0.0 progress_step= float(1.0/(context.eFrame-context.sFrame+1)) for f in xrange(context.sFrame, context.eFrame+1): frame= f Blender.Set("curframe", frame) lights() progress+= progress_step else: lights() lfile.write("// vim: set syntax=on syntax=c:\n") lfile.close() DrawProgressBar(1.0, "") print "V-Ray/Blender: Writing lights... done" ### ### ENVIRONMENT ### def exportEnvironment(): global exported_textures global exported_bitmaps out = "\nSettingsEnvironment {" env_out= "" for e in ['bg', 'gi', 'reflect', 'refract']: col= None hor= Blender.World.Get()[0].getHor() zen= Blender.World.Get()[0].getZen() amb= Blender.World.Get()[0].getAmb() if(g("vray_env_%s_type"%(e)) == 0): # Color col= getColor("vray_env_%s_color"%(e)) elif(g("vray_env_%s_type"%(e)) == 1): # Hor color col= hor elif(g("vray_env_%s_type"%(e)) == 2): # Zen color col= zen elif(g("vray_env_%s_type"%(e)) == 3): # Amb color col= amb if(col): col_mult= g("vray_env_%s_mult"%(e)) color= "Color(%.6f, %.6f, %.6f)"%(tuple(col)) if col_mult > 0 and col_mult != 1.0: (tex_name, tex_out)= exportTexAColorOp(color, col_mult, "%s_color_mult"%(e)) out= tex_out + out out+= "\n\t%s_tex= %s;"%(e, tex_name) else: out+= "\n\t%s_color= %s;"%(e, a(color)) if(g("vray_env_%s_type"%(e)) == 4): # VRaySky (tex_name, tex_out)= exportTexSky() out= tex_out + out out+= "\n\t%s_tex= %s;"%(e, tex_name) elif(g("vray_env_%s_type"%(e)) in [5,6]): texture_name= "env_%s"%(e) tex_name= None if(g("vray_env_%s_type"%(e)) == 5): try: (tex_name, tex_out)= exportTexBitmap(Blender.World.Get()[0].textures[g("vray_env_%s_tex_id"%(e))], None, 1, g("vray_env_%s_uvtype"%(e))) out= tex_out + out except: debug("\"env_%s\" texture is not set!"%(e)) if(g("vray_env_%s_type"%(e)) == 6): (uv_name, uv_out)= exportUVWGenEnvironment(1, [-90]) # 1= screen (tex_name, tex_out)= exportTexGradRamp(texture_name, uv_name, [hor,zen], [0.0,1.0]) out= uv_out + tex_out + out if(tex_name): out += "\n\t%s_tex= %s;"%(e, tex_name) out += "\n\t%s_tex_mult= %.6f;"%(e, g("vray_env_%s_mult"%(e))) if(g("vray_env_volume")): (vol_name, vol_out)= exportVolumeScatterFog("env") out= vol_out + out out += "\n\tenvironment_volume= %s;"%(vol_name) out+= "\n}\n" return out ### ### CAMERA ### def writeCamera(): global frame global scene global filenames global progress global exported_textures global exported_bitmaps def exportCamera(camera, fr= None): global frame out= "" cnt= scene.getRenderingContext() imagePercent= float(cnt.renderwinSize)/100 imageX= cnt.imageSizeX() imageY= cnt.imageSizeY() aspect= float(imageX)/float(imageY) fov= camera.data.angle if(aspect < 1.0): fov= fov*aspect if g("vray_export_bake"): if len(Blender.Object.GetSelected()) == 1: out += "UVWGenChannel UVWGenChannel_BakeView {" out += "\n\tuvw_transform=Transform(" out += "\n\t\tMatrix(" out += "\n\t\tVector(1.0,0.0,0.0)," out += "\n\t\tVector(0.0,1.0,0.0)," out += "\n\t\tVector(0.0,0.0,1.0)" out += "\n\t\t)," out += "\n\t\tVector(0.0,0.0,0.0)" out += "\n\t);" out += "\n\tuvw_channel=1;" out += "\n}\n" out += "\nBakeView {" out += "\n\tbake_node= %s;"%(g("vray_node_name",Blender.Object.GetSelected()[0])) out += "\n\tbake_uvwgen=UVWGenChannel_BakeView;" out += "\n\tdilation= %i;"%(cnt.bakeMargin*2) out += "\n}\n" else: print "V-Ray/Blender: Error! No object selected for baking!" return "" else: out += "\nRenderView RenderView {" out += "\n\ttransform= %s;"%(a(transformMatrix(camera.matrix))) if not g("vray_camera_physical",camera): out += "\n\tfov= %s;"%(a(math.radians(fov))) if(g("vray_camera_type",camera) != 4): out += "\n\tclipping= 1;" out += "\n\tclipping_near= %s;"%(a(camera.data.clipStart)) out += "\n\tclipping_far= %s;"%(a(camera.data.clipEnd)) if(g("vray_camera_type",camera) == 6): out += "\n\torthographic= 1;" out += "\n\torthographicWidth= %s;"%(a(camera.data.scale)) out += "\n}\n" if(g("vray_camera_physical",camera)): focal_length= g("vray_camera_focal_length",camera) film_width= 2*focal_length*math.tan((math.pi*fov)/360.0) out += "\nCameraPhysical physicalCamera {" out += "\n\ttype= %i;"%(g("vray_camera_physical_type",camera)) out += "\n\tfilm_width= %s;"%(a(film_width)) out += "\n\tfocal_length= %.6f;"%(focal_length) out += "\n\tzoom_factor= %.3f;"%(g("vray_camera_zoom_factor",camera)) out += "\n\tdistortion=0.0;" out += "\n\tf_number= %.1f;"%(g("vray_camera_f_number",camera)) out += "\n\tlens_shift= %.6f;"%(g("vray_camera_lens_shift",camera)) out += "\n\tshutter_speed= %.1f;"%(g("vray_camera_shutter_speed",camera)) out += "\n\tshutter_angle= %.1f;"%(g("vray_camera_shutter_angle",camera)) out += "\n\tshutter_offset= %.1f;"%(g("vray_camera_shutter_offset",camera)) out += "\n\tlatency=0.0;" out += "\n\tISO= %.1f;"%(g("vray_camera_ISO",camera)) out += "\n\texposure=1;" out += "\n\twhite_balance= Color(%.6f, %.6f, %.6f);"%(getColor("vray_camera_white_balance", camera)) out += "\n\tvignetting= %i;"%(g("vray_camera_vignetting",camera)) out += "\n\tuse_dof= %i;"%(g("vray_camera_phys_use_dof",camera)) if(g("vray_camera_phys_use_dof",camera)): out += "\n\tspecify_focus= %d;"%(g("vray_camera_specify_focus",camera)) focus_distance= camera.data.dofDist if(focus_distance == 0.0): focus_distance= 1.0 out += "\n\tfocus_distance= %s;"%(a(focus_distance)) out += "\n\tblades_enable= %i;"%(g("vray_camera_blades_enable",camera)) out += "\n\tblades_num= %i;"%(g("vray_camera_blades_num",camera)) out += "\n\tblades_rotation= %.3f;"%(g("vray_camera_blades_rotation",camera)) out += "\n\tcenter_bias= %.3f;"%(g("vray_camera_center_bias",camera)) out += "\n\tanisotropy= %.3f;"%(g("vray_camera_anisotropy",camera)) out += "\n\tuse_moblur= %i;"%(g("vray_camera_phys_use_moblur",camera)) out += "\n\tsubdivs= %i;"%(g("vray_camera_phys_subdivs",camera)) out += "\n}\n" else: out += "\nSettingsCamera {" out += "\n\ttype= %i;"%(g("vray_camera_type",camera)) out += "\n\tfov= %s;"%(a(math.radians(fov))) if(g("vray_camera_type",camera) == 3): out += "\n\theight= %.3f;"%(g("vray_camera_height",camera)) if(g("vray_camera_type",camera) == 5): out += "\n\tauto_fit= %i;"%(g("vray_camera_auto_fit",camera)) out += "\n\tdist= %.3f;"%(g("vray_camera_dist",camera)) out += "\n\tcurve= %.3f;"%(g("vray_camera_curve",camera)) out += "\n}\n" if(g("vray_camera_phys_use_dof",camera)): out += "\nSettingsCameraDof {" out += "\n\ton=%i;"%(g("vray_camera_phys_use_dof",camera)) out += "\n\tfocal_dist= %s;"%(a(camera.data.dofDist)) out += "\n\taperture=5.0;" out += "\n\tsubdivs=%i;"%(g("vray_camera_phys_subdivs",camera)) if(g("vray_camera_phys_use_dof",camera) and g("vray_camera_phys_bokeh",camera)): out += "\n\tcenter_bias=%.3f;"%(g("vray_camera_center_bias",camera)) out += "\n\tanisotropy=%.3f;"%(g("vray_camera_anisotropy",camera)) out += "\n\tsides_on=%i;"%(g("vray_camera_blades_enable",camera)) out += "\n\tsides_num=%i;"%(g("vray_camera_blades_num",camera)) out += "\n\trotation=%.3f;"%(g("vray_camera_blades_rotation",camera)) out += "\n}\n" return out print "V-Ray/Blender: Writing camera..." DrawProgressBar(0.0, "") ofile= open(filenames["camera"], 'w') ofile.write("// V-Ray/Blender: Camera\n") if g("vray_export_animation"): context= scene.getRenderingContext() progress= 0.0 progress_step= float(1.0/(context.eFrame-context.sFrame+1)) for f in xrange(context.sFrame, context.eFrame+1): frame= f Blender.Set("curframe", frame) DrawProgressBar(progress, "(%i) Writing camera..."%(f)) ofile.write(exportCamera(camera)) exported_textures= [] exported_bitmaps= [] ofile.write(exportEnvironment()) progress+= progress_step elif g("vray_export_cameraloop"): frame= 1 ofile.write(exportEnvironment()) cameras= [ob for ob in sce.objects if (ob.type == 'Camera' and not ob.restrictRender and ob.Layers & sce.Layers)] s("vray_camera_start", 1) frame= 0 for ca in cameras: frame+= 1 ofile.write(exportCamera(ca,frame)) s("vray_camera_end",frame) else: ofile.write(exportCamera(camera)) ofile.write(exportEnvironment()) ofile.close() DrawProgressBar(1.0, "") print "V-Ray/Blender: Writing camera... done" ## ## SETTINGS ## def exportSettings(): global exported_bitmaps global exported_textures exported_bitmaps= [] exported_textures= [] out= "" imagePercent= float(scene.getRenderingContext().renderwinSize)/100 imageX= scene.getRenderingContext().imageSizeX() imageY= scene.getRenderingContext().imageSizeY() def settingsGIIrrmap(): out = "\nSettingsIrradianceMap {" out += "\n\tmin_rate= %i;"%(g("vray_im_min_rate")) out += "\n\tmax_rate= %i;"%(g("vray_im_max_rate")) out += "\n\tsubdivs= %i;"%(g("vray_im_subdivs")) out += "\n\tinterp_samples= %i;"%(g("vray_im_interp_samples")) out += "\n\tinterp_frames= %i;"%(g("vray_im_interp_frames")) out += "\n\tcalc_interp_samples= %i;"%(g("vray_im_calc_interp_samples")) out += "\n\tcolor_threshold= %.6f;"%(g("vray_im_color_threshold")) out += "\n\tnormal_threshold= %.6f;"%(g("vray_im_normal_threshold")) out += "\n\tdistance_threshold= %.6f;"%(g("vray_im_distance_threshold")) out += "\n\tdetail_enhancement= %i;"%(g("vray_im_detail_enhancement")) if g("vray_im_detail_enhancement"): out += "\n\tdetail_radius= %.6f;"%(g("vray_im_detail_radius")) out += "\n\tdetail_subdivs_mult= %.6f;"%(g("vray_im_detail_subdivs_mult")) out += "\n\tdetail_scale= %i;"%(g("vray_im_detail_scale")) out += "\n\tinterpolation_mode= %i;"%(g("vray_im_interpolationType")) out += "\n\tlookup_mode= %i;"%(g("vray_im_lookupType")) out += "\n\tshow_calc_phase= %i;"%(g("vray_im_show_calc_phase")) out += "\n\tshow_direct_light= %i;"%(g("vray_im_show_direct_light")) out += "\n\tshow_samples= %i;"%(g("vray_im_show_samples")) out += "\n\tmultipass= %i;"%(g("vray_im_multipass")) out += "\n\tcheck_sample_visibility= %i;"%(g("vray_im_check_sample_visibility")) out += "\n\trandomize_samples= %i;"%(g("vray_im_randomize_samples")) out += "\n\tmode= %d;"%(g("vray_im_mode")) out += "\n\tauto_save= %d;"%(g("vray_im_auto_save")) out += "\n\tauto_save_file= \"%s\";"%(os.path.join(filenames["lmapspath"], g("vray_im_auto_save_file"))) out += "\n\tfile= \"%s\";"%(g("vray_im_file")) out += "\n}\n" return out def settingsGIBruteForce(): out = "\nSettingsDMCGI {" out += "\n\tsubdivs= %i;"%(g("vray_dmcgi_subdivs")) out += "\n\tdepth= %i;"%(g("vray_dmcgi_depth")) out += "\n}\n" return out def settingsGILightCache(): out = "\nSettingsLightCache {" out += "\n\tsubdivs= %.0f;"%(g("vray_lc_subdivs") * g("vray_subdivs_mult")) out += "\n\tsample_size= %.6f;"%(g("vray_lc_sample_size")) out += "\n\tnum_passes= %i;"%(g("vray_lc_num_passes")) out += "\n\tdepth= %i;"%(g("vray_lc_depth")) out += "\n\tfilter_type= %i;"%(g("vray_lc_filter_type")) if (g("vray_lc_filter_type") != 0): out += "\n\tfilter_samples= %i;"%(g("vray_lc_filter_samples")) out += "\n\tfilter_size= %.6f;"%(g("vray_lc_filter_size")) out += "\n\tprefilter= %i;"%(g("vray_lc_prefilter")) if g("vray_lc_prefilter"): out += "\n\tprefilter_samples= %i;"%(g("vray_lc_prefilter_samples")) out += "\n\tshow_calc_phase= %i;"%(g("vray_lc_show_calc_phase")) out += "\n\tstore_direct_light= %i;"%(g("vray_lc_store_direct_light")) out += "\n\tuse_for_glossy_rays= %i;"%(g("vray_lc_use_for_glossy_rays")) out += "\n\tworld_scale= %i;"%(g("vray_lc_scale")) out += "\n\tadaptive_sampling= %i;"%(g("vray_lc_adaptive_sampling")) out += "\n\tmode= %d;"%(g("vray_lc_mode")) out += "\n\tauto_save= %d;"%(g("vray_lc_auto_save")) out += "\n\tauto_save_file= \"%s\";"%(os.path.join(filenames["lmapspath"], g("vray_lc_auto_save_file"))) out += "\n\tfile= \"%s\";"%(g("vray_lc_file")) out += "\n}\n" return out def settingsGIPhotonMap(): out = "\nSettingsPhotonMap {" out += "\n\tbounces= %i;"%(g("vray_pm_bounces")) out += "\n\tsearch_distance= %.3f;"%(g("vray_pm_search_distance")) out += "\n\tauto_search_distance= %i;"%(g("vray_pm_auto_search_distance")) out += "\n\tmax_photons= %i;"%(g("vray_pm_max_photons")) out += "\n\tprefilter= %i;"%(g("vray_pm_prefilter")) out += "\n\tprefilter_samples= %i;"%(g("vray_pm_prefilter_samples")) out += "\n\tmultiplier= %.3f;"%(g("vray_pm_multiplier")) out += "\n\tconvex_hull_estimate= %i;"%(g("vray_pm_convex_hull_estimate")) out += "\n\tstore_direct_light= %i;"%(g("vray_pm_store_direct_light")) out += "\n\tretrace_corners= %.3f;"%(g("vray_pm_retrace_corners")) out += "\n\tretrace_bounces= %i;"%(g("vray_pm_retrace_bounces")) out += "\n\tmax_density= %.3f;"%(g("vray_pm_max_density")) out += "\n}\n" return out width= int(float(imageX)*float(imagePercent)) height= int(float(imageY)*float(imagePercent)) out+= "\nSettingsOutput {" out+= "\n\timg_width= %d;"%(width) if g("vray_export_bake"): out+= "\n\timg_height= %d;"%(width) else: out+= "\n\timg_height= %d;"%(height) out+= "\n\timg_separateAlpha= %d;"%(g("vray_img_separateAlpha")) if context.borderRender and not g("vray_render_crop"): (xmin,ymin,xmax,ymax)= context.border width_x= xmax-xmin width_y= ymax-ymin rgn_left= xmin*imageX*imagePercent rgn_top= imageY*imagePercent*(1.0-ymax) rgn_width= width_x*imageX*imagePercent rgn_heigth= width_y*imageY*imagePercent out+= "\n\tr_left= %d;"%(rgn_left) out+= "\n\tr_width= %d;"%(rgn_width) out+= "\n\tr_top= %d;"%(rgn_top) out+= "\n\tr_height= %d;"%(rgn_heigth+1) if g("vray_autosave_render") or g("vray_export_animation") or g("vray_export_cameraloop"): if g("vray_export_cameraloop"): out+= "\n\timg_file= \"render_view.%s\";"%(output_image_type()) else: out+= "\n\timg_file= \"render_%s.%s\";"%(getName(camera), output_image_type()) out+= "\n\timg_dir= \"%s\";"%(filenames["output"]) out+= "\n\timg_file_needFrameNumber= 1;" out+= "\n\tanim_start= %d;"%(context.sFrame) out+= "\n\tanim_end= %d;"%(context.eFrame) out+= "\n\tframe_start= %d;"%(context.sFrame) out+= "\n\tframes_per_second= %d;"%(1.0) out+= "\n\tframes= %d-%d;"%(context.sFrame, context.eFrame) out+= "\n\tframe_stamp_enabled= %d;"%(g("vray_stamp")) out+= "\n\tframe_stamp_text= \"%s\";"%("V-Ray/Blender %s | V-Ray Standalone %%vraycore | %%rendertime"%(vrayblender_version)) out+= "\n}\n" out+= "\nSettingsUnitsInfo {" out+= "\n\tmeters_scale=%f;"%(g("vray_metric_scale")) out+= "\n\tphotometric_scale=%.6f;"%(g("vray_photometric_scale")) out+= "\n}\n" out += "\nSettingsImageSampler {" out += "\n\ttype= %i;"%(g("vray_imageSamplerType")) if g("vray_imageSamplerType") == 0: out += "\n\tfixed_subdivs= %i;"%(g("vray_FixedRate")) if g("vray_imageSamplerType") == 1: out += "\n\tdmc_minSubdivs= %i;"%(g("vray_dmc_minSubdivs")) out += "\n\tdmc_maxSubdivs= %i;"%(g("vray_dmc_maxSubdivs")) out += "\n\tdmc_threshold= %.6f;"%(g("vray_dmc_threshold")) if g("vray_imageSamplerType") == 2: out += "\n\tsubdivision_minRate= %i;"%(g("vray_subdivision_minRate")) out += "\n\tsubdivision_maxRate= %i;"%(g("vray_subdivision_maxRate")) out += "\n\tsubdivision_threshold= %.3f;"%(g("vray_subdivision_threshold")) #out += "\n\tsubdivision_jitter= 1;" out += "\n\tsubdivision_edges= %i;"%(g("vray_subdivision_edges")) out += "\n\tsubdivision_normals= %i;"%(g("vray_subdivision_normals")) out += "\n\tsubdivision_normals_threshold= %.6f;"%(g("vray_subdivision_normals_threshold")) out += "\n}\n" filtertype = { "1" : "\nFilterArea {", "2" : "\nFilterBox {", "3" : "\nFilterTriangle {", "4" : "\nFilterLanczos {", "5" : "\nFilterSinc {", "6" : "\nFilterGaussian {" } if (g("vray_aa_filter_type") != 0): out += filtertype[str(g("vray_aa_filter_type"))] out += "\n\tsize=%.3f;"%(g("vray_aa_filter_size")) out += "\n}\n" out += "\nSettingsColorMapping {" out += "\n\ttype= %s;"%(g("vray_cm_type")) out += "\n\taffect_background= %d;"%(g("vray_affect_background")) if (g("vray_cm_type") == 6): out += "\n\tbright_mult= %.1f;"%(g("vray_dark_mult")) out += "\n\tdark_mult= %.1f;"%(g("vray_bright_mult")) else: out += "\n\tbright_mult= %.1f;"%(g("vray_bright_mult")) out += "\n\tdark_mult= %.1f;"%(g("vray_dark_mult")) out += "\n\tgamma= %.6f;"%(g("vray_gamma")) out += "\n\tsubpixel_mapping= %i;"%(g("vray_subpixel_mapping")) out += "\n\tclamp_output= %i;"%(g("vray_clamp_output")) out += "\n\tclamp_level= %.6f;"%(g("vray_clamp_level")) out += "\n\tadaptation_only= %i;"%(g("vray_adaptation_only")) out += "\n\tlinearWorkflow= %i;"%(g("vray_linearWorkflow")) out += "\n}\n" if(g("vray_gi_on")): out += "\nSettingsGI {" out += "\n\ton= 1;" out += "\n\tprimary_engine= %s;"%(g("vray_primary_engine")) out += "\n\tprimary_multiplier= %s;"%(g("vray_primary_multiplier")) out += "\n\tsecondary_engine= %s;"%(g("vray_secondary_engine")) out += "\n\tsecondary_multiplier= %s;"%(g("vray_secondary_multiplier")) out += "\n\treflect_caustics= %s;"%(g("vray_reflect_caustics")) out += "\n\trefract_caustics= %s;"%(g("vray_refract_caustics")) out += "\n\tsaturation= %.6f;"%(g("vray_saturation")) out += "\n\tcontrast= %.6f;"%(g("vray_contrast")) out += "\n\tcontrast_base= %.6f;"%(g("vray_contrast_base")) out += "\n}\n" if(g("vray_primary_engine") == 0): out += settingsGIIrrmap() if g("vray_primary_engine") == 1 and g("vray_secondary_engine") == 1: out += settingsGIPhotonMap() else: if(g("vray_primary_engine") == 1): out += settingsGIPhotonMap() if(g("vray_secondary_engine") == 1): out += settingsGIPhotonMap() if g("vray_primary_engine") == 2 and g("vray_secondary_engine") == 2: out += settingsGIBruteForce() else: if(g("vray_primary_engine") == 2): out += settingsGIBruteForce() if(g("vray_secondary_engine") == 2): out += settingsGIBruteForce() if g("vray_primary_engine") == 3 and g("vray_secondary_engine") == 3: out += settingsGILightCache() else: if(g("vray_primary_engine") == 3): out += settingsGILightCache() if(g("vray_secondary_engine") == 3): out += settingsGILightCache() out += "\nSettingsDMCSampler {" out += "\n\ttime_dependent= %s;"%(g("vray_time_dependent")) out += "\n\tadaptive_amount= %.6f;"%(g("vray_adaptive_amount")) out += "\n\tadaptive_threshold= %.6f;"%(g("vray_adaptive_threshold")) out += "\n\tadaptive_min_samples= %s;"%(g("vray_adaptive_min_samples")) out += "\n\tsubdivs_mult= %.6f;"%(g("vray_subdivs_mult")) out += "\n}\n" if g("vray_caustics_on"): out+= "\nSettingsCaustics {" out+= "\n\ton= 1;" out+= "\n\tdont_delete= 0;" out+= "\n\tmax_photons= %i;"%(g("vray_caustics_max_photons")) out+= "\n\tsearch_distance= %.6f;"%(g("vray_caustics_search_distance")) out+= "\n\tmax_density= %.3f;"%(g("vray_caustics_max_density")) out+= "\n\tmultiplier= %.6f;"%(g("vray_caustics_multiplier")) out+= "\n\tmode= %i;"%(g("vray_caustics_mode")) if g("vray_caustics_mode"): if g("vray_caustics_file") != "": out+= "\n\tfile= \"%s\";"%(g("vray_caustics_file")) else: out+= "\n\tauto_save= %d;"%(g("vray_caustics_auto_save")) if g("vray_caustics_auto_save"): out+= "\n\tauto_save_file= \"%s\";"%(os.path.join(filenames["lmapspath"], g("vray_caustics_auto_save_file"))) out+= "\n\tshow_calc_phase= %d;"%(g("vray_caustics_show_calc_phase")) out+= "\n}\n" out += "\nSettingsRaycaster {" out += "\n\tmaxLevels= %s;"%(g("vray_maxLevels")) out += "\n\tminLeafSize= %s;"%(g("vray_minLeafSize")) out += "\n\tfaceLevelCoef= %s;"%(g("vray_faceLevelCoef")) out += "\n\tdynMemLimit= %s;"%(g("vray_dynMemLimit")) out += "\n\toptLevel=0;" out += "\n}\n" out += "\nSettingsRegionsGenerator {" out += "\n\txc= %s;"%(g("vray_xc")) out += "\n\tyc= %s;"%(g("vray_xc")) out += "\n\txymeans= 0;" out += "\n\tseqtype= 4;" out += "\n\treverse= 0;" out += "\n}\n" out += "\nSettingsOptions {" out += "\n\tgeom_backfaceCull= %i;"%(g("vray_geom_backfaceCull")) out += "\n\tgeom_displacement= %i;"%(g("vray_geom_displacement")) out += "\n\tgeom_doHidden= %i;"%(g("vray_geom_doHidden")) out += "\n\tlight_doLights= %i;"%(g("vray_light_doLights")) out += "\n\tlight_doDefaultLights= %i;"%(g("vray_light_doDefaultLights")) out += "\n\tlight_doHiddenLights= %i;"%(g("vray_light_doHiddenLights")) out += "\n\tlight_doShadows= %i;"%(g("vray_light_doShadows")) out += "\n\tmtl_reflectionRefraction= %i;"%(g("vray_mtl_reflectionRefraction")) out += "\n\tmtl_glossy= %i;"%(g("vray_mtl_glossy")) out += "\n\tmtl_limitDepth= %i;"%(g("vray_mtl_limitDepth")) out += "\n\tmtl_maxDepth= %i;"%(g("vray_mtl_maxDepth")) #out += "\n\tmtl_override_on= %d;"%() #out += "\n\tmtl_doMaps= %d;"%() #out += "\n\tmtl_filterMaps= %d;"%() out += "\n\tmtl_transpMaxLevels= %i;"%(g("vray_mtl_transpMaxLevels")) out += "\n\tmtl_transpCutoff= %.6f;"%(g("vray_mtl_transpCutoff")) #out += "\n\tray_bias= %.6f;"%(g("vray_ray_bias")) out += "\n\tgi_dontRenderImage= %d;"%(g("vray_gi_dontRenderImage")) out += "\n\tmisc_lowThreadPriority= %d;"%(1) out += "\n}\n" out += "\nSettingsDefaultDisplacement {" out += "\n\toverride_on= %i;"%(g("vray_displace_override_on")) out += "\n\tedgeLength= %.6f;"%(g("vray_displace_edgeLength")) out += "\n\tmaxSubdivs= %d;"%(g("vray_displace_maxSubdivs")) out += "\n\tamount= %.6f;"%(g("vray_displace_amount")) out += "\n\tviewDependent= %d;"%(g("vray_displace_viewDependent")) out += "\n\ttightBounds= %d;"%(g("vray_displace_tightBounds")) out += "\n\trelative= %d;"%(g("vray_displace_relative")) out += "\n}\n" out += "\nSettingsJPEG {" out += "\n\tquality= %i;"%(context.quality()) out += "\n}\n" out += "\nSettingsEXR {" # Compression for OpenEXR output (0 - default, 1 - no compression, 2 - RLE, 3 - ZIPS, 4 - ZIP, 5 - PIZ, 6 - pxr24) out += "\n\tcompression= 0;" out += "\n\tbits_per_channel= 32;" out += "\n}\n" if(g("vray_realtime")): out += "\nRTEngine {" out += "\n\tseparate_window= 0;" out += "\n\ttrace_depth= 5;" out += "\n\tuse_gi= 1;" out += "\n\tgi_depth= 3;" out += "\n\tgi_reflective_caustics= 0;" out += "\n\tgi_refractive_caustics= 1;" out += "\n\tuse_opencl= 1;" out += "\n}\n" if(g("vray_zdepth")): out += "\nRenderChannelZDepth {" out += "\n\tname= \"ZDepth\";" out += "\n\tdepth_black= %.6f;"%(g("vray_zdepth_depth_black")) out += "\n\tdepth_white= %.6f;"%(g("vray_zdepth_depth_white")) out += "\n\tdepth_clamp= %d;"%(g("vray_zdepth_depth_clamp")) out += "\n}\n" if not g("vray_export_bake"): if g("vray_velocity"): out += "\nRenderChannelVelocity {" out += "\n\tclamp_velocity= %d;"%(g("vray_velocity_clamp_velocity")) out += "\n\tmax_velocity= %.6f;"%(g("vray_velocity_max_velocity")) out += "\n\tmax_velocity_last_frame= %.6f;"%(g("vray_velocity_max_velocity_last_frame")) out += "\n\tignore_z= %d;"%(g("vray_velocity_ignore_z")) out += "\n}\n" if(g("vray_renderid")): out += "\nRenderChannelRenderID {" out += "\n\tname= \"RenderID\";" out += "\n}\n" if(g("vray_normals")): out += "\nRenderChannelNormals {" out += "\n\tname= \"Normals\";" out += "\n}\n" if g("vray_mainpasses"): out += "\nRenderChannelColor VRay_RGB {" out += "\n\tname= \"VRay_RGB\";" out += "\n\talias= 1;" out += "\n}\n" out += "\nRenderChannelColor VRay_Diffuse {" out += "\n\tname= \"VRay_Diffuse\";" out += "\n\talias= 101;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Reflect {" out += "\n\tname= \"VRay_Reflect\";" out += "\n\talias= 102;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Refract {" out += "\n\tname= \"VRay_Refract\";" out += "\n\talias= 103;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Self_Illumination {" out += "\n\tname= \"VRay_Self_Illumination\";" out += "\n\talias= 104;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Shadow {" out += "\n\tname= \"VRay_Shadow\";" out += "\n\talias= 105;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Specular {" out += "\n\tname= \"VRay_Specular\";" out += "\n\talias= 106;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Lightning {" out += "\n\tname= \"VRay_Lightning\";" out += "\n\talias= 107;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_GI {" out += "\n\tname= \"VRay_GI\";" out += "\n\talias= 108;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Caustics {" out += "\n\tname= \"VRay_Caustics\";" out += "\n\talias= 109;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Raw_GI {" out += "\n\tname= \"VRay_Raw_GI\";" out += "\n\talias= 110;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Raw_Lightning {" out += "\n\tname= \"VRay_Raw_Lightning\";" out += "\n\talias= 111;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Raw_Shadow {" out += "\n\tname= \"VRay_Raw_Shadow\";" out += "\n\talias= 112;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Velocity {" out += "\n\tname= \"VRay_Velocity\";" out += "\n\talias= 113;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" # out += "\nRenderChannelColor VRay_Render_ID {" # out += "\n\tname= \"VRay_Render_ID\";" # out += "\n\talias= 114;" # out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) # out += "\n}\n" # out += "\nRenderChannelColor VRay_Material_ID {" # out += "\n\tname= \"VRay_Material_ID\";" # out += "\n\talias= 115;" # out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) # out += "\n}\n" # out += "\nRenderChannelColor VRay_Node_ID {" # out += "\n\tname= \"VRay_Node_ID\";" # out += "\n\talias= 116;" # out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) # out += "\n}\n" # out += "\nRenderChannelColor VRay_Zdepth {" # out += "\n\tname= \"VRay_Zdepth\";" # out += "\n\talias= 117;" # out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) # out += "\n}\n" out += "\nRenderChannelColor VRay_Reflection_Filter {" out += "\n\tname= \"VRay_Reflection_Filter\";" out += "\n\talias= 118;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Raw_Reflection {" out += "\n\tname= \"VRay_Raw_Reflection\";" out += "\n\talias= 119;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Refraction_Filter {" out += "\n\tname= \"VRay_Refraction_Filter\";" out += "\n\talias= 120;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Raw_Refraction {" out += "\n\tname= \"VRay_Raw_Refraction\";" out += "\n\talias= 121;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Real_Color{" out += "\n\tname= \"VRay_Real_Color\";" out += "\n\talias= 122;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" # out += "\nRenderChannelColor VRay_Normal {" # out += "\n\tname= \"VRay_Normal\";" # out += "\n\talias= 123;" # out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) # out += "\n}\n" out += "\nRenderChannelColor VRay_Background {" out += "\n\tname= \"VRay_Background\";" out += "\n\talias= 124;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Alpha {" out += "\n\tname= \"VRay_Alpha\";" out += "\n\talias= 125;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Color {" out += "\n\tname= \"VRay_Color\";" out += "\n\talias= 126;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Wire_Color {" out += "\n\tname= \"VRay_Wire_Color\";" out += "\n\talias= 127;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Matte_Shadow {" out += "\n\tname= \"VRay_Matte_Shadow\";" # essentially this is = (rawShadow)/(rawLight+rawShadow) out += "\n\talias= 128;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Total_Lightning{" out += "\n\tname= \"VRay_Total_Lightning\";" out += "\n\talias= 129;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Raw_Total_Lightning {" out += "\n\tname= \"VRay_Raw_Total_Lightning\";" out += "\n\talias= 130;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Bump_Normal {" out += "\n\tname= \"VRay_Bump_Normal\";" out += "\n\talias= 131;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_Samplerate {" out += "\n\tname= \"VRay_Samplerate\";" out += "\n\talias= 132;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" out += "\nRenderChannelColor VRay_SSS {" out += "\n\tname= \"VRay_SSS\";" out += "\n\talias= 133;" out += "\n\tcolor_mapping= %d;"%(g("vray_mainpasses_cm")) out += "\n}\n" if(g("vray_multimatte")): out += "\nRenderChannelMultiMatte {" out += "\n\tname= \"MultiMatte\";" out += "\n\tred_id= %d;"%(g("vray_multimatte_red_id")) out += "\n\tgreen_id= %d;"%(g("vray_multimatte_green_id")) out += "\n\tblue_id= %d;"%(g("vray_multimatte_blue_id")) out += "\n\tuse_mtl_id= %d;"%(g("vray_multimatte_use_mtl_id")) out += "\n}\n" if(g("vray_extratex")): (tex_name, out_tex)= exportTexDirt('ExtraTex_AO', { 'radius': g("vray_extratex_ao_radius"), 'subdivs': 16, 'white_color': "AColor(%.3f,%.3f,%.3f,%.3f)"%(1.0,1.0,1.0, 1.0), 'black_color': "AColor(%.3f,%.3f,%.3f,%.3f)"%(0.0,0.0,0.0, 1.0) }) out+= out_tex channel_name= "AO" out+= "\nRenderChannelExtraTex %s {"%(channel_name) out+= "\n\tname= \"%s\";"%(channel_name) out+= "\n\tconsider_for_aa= %d;"%(g("vray_extratex_consider_for_aa")) out+= "\n\taffect_matte_objects= %d;"%(g("vray_extratex_matte")) out+= "\n\ttexmap= %s;"%(tex_name) out+= "\n\tfiltering= %d;"%(1) out+= "\n}\n" out += "\n" return out ## ## CREATE FILES & LAUNCH RENDER ## def updateRegistry(): globals = {} globals["vray_dr_hosts"]= g("vray_dr_hosts") globals["vray_dr_port"]= g("vray_dr_port") globals["vray_binary"]= g("vray_binary") globals["vray_wine"]= g("vray_wine") Blender.Registry.SetKey('VRay', globals, True) vray_globals= Blender.Registry.GetKey('VRay', True) if vray_globals: try: s("vray_dr_hosts", vray_globals["vray_dr_hosts"]) s("vray_dr_port", vray_globals["vray_dr_port"]) s("vray_binary", vray_globals["vray_binary"]) s("vray_wine", vray_globals["vray_wine"]) except: updateRegistry() def getFilenames(): global filenames sce= bpy.data.scenes.active cnt= sce.getRenderingContext() def_path= tempfile.gettempdir() img_dir= cleanpath(expandpath(cnt.getRenderPath())) (filepath,filename) = os.path.split(Blender.Get("filename")) if(filename): if g("vray_export_path_over") and not g("vray_unique_name"): filename= "scene" else: filename= filename[0:-6] else: filename= "default" filepath= tempfile.gettempdir() print "V-Ray/Blender: Using $TEMP directory: %s"%(filepath) basepath= "" texpath= "" if g("vray_dr"): if g("vray_export_path_dr") != vray_defaults["vray_export_path_dr"]: (basepath, tmp)= os.path.split(g("vray_export_path_dr")) else: if(ostype == "win32"): basepath= "C:\\render\\" else: basepath= "/render/" print "V-Ray/Blender: DR export path is not set - using default: %s"%(basepath) if not exists(basepath): os.mkdir(basepath) texpath= os.path.join(basepath,"textures/") if not exists(texpath): os.mkdir(texpath) else: if g("vray_export_path_over"): if g("vray_export_path") == "": print "V-Ray/Blender: Export path is not set - using default: %s"%(def_path) basepath= def_path else: (basepath, tmp)= os.path.split(g("vray_export_path")) else: basepath= cleanpath(os.path.join(filepath, "vray")) if not exists(basepath): print "V-Ray/Blender: Exporting path doesn't exist, trying to create..." print "V-Ray/Blender: Creating directory %s"%(basepath) try: os.mkdir(basepath) except: print "V-Ray/Blender: Creating directory \"%s\" failed!"%(basepath) basepath= tempfile.gettempdir() print "V-Ray/Blender: Using default export path: %s"%(basepath) lmapspath= cleanpath(os.path.join(basepath, "lightmaps")) if not exists(lmapspath): os.mkdir(lmapspath) basename= cleanpath(os.path.join(basepath, filename)) if g("vray_autosave_render"): if not exists(img_dir): print "V-Ray/Blender: Render autosave path doesn\'t exist, trying to create..." print "V-Ray/Blender: Creating directory %s"%(img_dir) try: os.mkdir(img_dir) except: print "V-Ray/Blender: Creating directory %s failed!"%(img_dir) img_dir= tempfile.gettempdir() print "V-Ray/Blender: Using default render output path: %s"%(img_dir) filenames= {} filenames["name"]= filename filenames["path"]= basepath filenames["texpath"]= texpath filenames["lmapspath"]= lmapspath filenames["output"]= img_dir filenames["scene"]= basename + ".vrscene" filenames["geometry"]= basename + "_geometry.vrscene" filenames["materials"]= basename + "_materials.vrscene" filenames["lights"]= basename + "_lights.vrscene" filenames["nodes"]= basename + "_nodes.vrscene" filenames["camera"]= basename + "_camera.vrscene" def writeSettings(): debug("Writing scene file...") sfile= open(filenames["scene"], 'w') sfile.write("// V-Ray/Blender: Scene file\n") sfile.write("// Version: %s\n"%(vrayblender_version)) if(g('vray_dr')): for f in ['geometry', 'materials', 'lights', 'nodes', 'camera']: if(ostype == 'win32'): path= filenames[f] if(g('vray_dr_network') == 0): sfile.write("#include \"//%s/%s\"\n"%(hostname,clean_dr_path(path[3:]))) else: sfile.write("#include \"..%s\"\n"%(clean_dr_path(path[2:]))) else: sfile.write("#include \"..%s\"\n"%(filenames[f])) else: for f in ['geometry', 'materials', 'lights', 'nodes', 'camera']: sfile.write("#include \"%s\"\n"%(filenames[f])) sfile.write(exportSettings()) sfile.write("// vim: set syntax=on syntax=c:\n") sfile.close() debug("Writing scene file... done.") def writeScene(): global scene global context global camera global sce # tmp scene= bpy.data.scenes.active camera= scene.objects.camera context= scene.getRenderingContext() sce= scene # temp debug("Exporting scene...") if g("vray_export_lock"): writeGeometry() writeMaterials() writeNodes() writeLights() writeSettings() writeCamera() debug("Exporting scene... done.") def run(params): if(g("vray_binary") == ""): print "V-Ray/Blender: V-Ray binary is not set!" else: vray_bin= g("vray_binary") if(not ostype == "win32"): vray_bin= vray_bin.replace(' ', '\\ ') if(ostype == "linux2"): if(g("vray_log_window")): cmd = "(xterm -T V-Ray -geometry 90x10 -e \"%s %s\")&"%(vray_bin, params) else: cmd = "(%s %s)&"%(vray_bin, params) elif(ostype == "win32"): cmd = "start \"dummy\" /b /belownormal \"%s\" %s"%(g("vray_binary"), params) else: cmd = "%s %s"%(vray_bin, params) if(g("vray_run")): os.system(cmd) else: print "V-Ray/Blender: Command: %s"%(cmd) print "V-Ray/Blender: Enable \"Autorun\" option to start V-Ray automatically after export..." def render(): params = "-scenefile=\"%s\""%(filenames["scene"]) if(not ostype == "win32"): params = params.replace(' ', '\\ ') if not g("vray_threads_auto"): params+= " -numThreads=%d"%(g("vray_threads")) params+= " -verboseLevel=%i"%(g("vray_verboseLevel")) #params+= " -showProgress=%i"%(2) if(context.borderRender): if(g("vray_render_crop")): imagePercent= float(context.renderwinSize)/100 imageX= context.imageSizeX() imageY= context.imageSizeY() (xmin,ymin,xmax,ymax)= context.border width_x= xmax-xmin width_y= ymax-ymin rgn_left= xmin*imageX*imagePercent rgn_top= imageY*imagePercent*(1.0-ymax) rgn_width= width_x*imageX*imagePercent rgn_heigth= width_y*imageY*imagePercent if(ostype == "win32"): params+= " -crop=%i;%i;%i;%i"%(rgn_left,rgn_top,rgn_left+rgn_width,rgn_top+rgn_heigth) else: params+= " -crop=%i\;%i\;%i\;%i"%(rgn_left,rgn_top,rgn_left+rgn_width,rgn_top+rgn_heigth) # Region is defined in 'SettingsOutput' #else: # params+= " -region=%i\;%i\;%i\;%i"%(rgn_left,rgn_top,rgn_left+rgn_width,rgn_top+rgn_heigth) if not g("vray_novfb"): params+= " -display=0" else: params+= " -display=1" if g("vray_dr"): params+= " -distributed=1 -portNumber=%i -renderhost=\"%s\""%(g("vray_dr_port"), g("vray_dr_hosts")) if g("vray_export_animation"): params+= " -frames=%d-%d"%(context.sFrame, context.eFrame) elif g("vray_export_cameraloop"): params+= " -frames=%d-%d"%(g("vray_camera_start"), g("vray_camera_end")) else: params+= " -frames=%d"%(context.currentFrame()) if g("vray_autosave_render"): params+= " -imgFile=\"%s\""%(os.path.join(filenames["output"], "render_%s.%s"%(getName(camera), output_image_type()))) run(params) ## ## GUI ## def genMaterialMenu(): menu= None materials= Material.Get() if(len(materials)): menu= "Material %t" for i in reversed(range(len(materials))): menu+= "| %s %%x%i"%(materials[i].name, i) return menu def drawText(x, y, string, size=None): BGL.glColor3f(0.9,0.9,0.9) BGL.glRasterPos2i(x,y) if(size): Draw.Text(string,size) else: Draw.Text(string, "normal") def drawFrame(fx, fy): frame_min_y = 42 frame_max_x = 646 frame_max_y = 400 frame_y = 398 BGL.glColor3f(0.5,0.5,0.5) BGL.glRectf(fx, frame_max_y+5, fx+91, frame_max_y+7) # _ Top BGL.glRectf(5, frame_min_y, frame_max_x, frame_min_y+1) # _ Bottom ### Buttons def drawButtons(): # Background (width, height)= Window.GetAreaSize() BGL.glColor3f(0.25,0.25,0.25) BGL.glRectf(0,0,width,height) drawText(10, 435, "V-Ray/Blender %s"%(vrayblender_version), "small") drawText(550, 435, "http://vray.cgdo.ru", "small") Draw.BeginAlign() Draw.Button("Render", evtRedraw, 10, 410, 90, 16, "Render options [1 - key]", lambda e,v: s("vray_gui_screen", 0)) Draw.Button("Sampler", evtRedraw, 100, 410, 90, 16, "AA & DMC Sampler [2 - key]", lambda e,v: s("vray_gui_screen", 1)) Draw.Button("GI", evtRedraw, 190, 410, 90, 16, "Global Illumination [3 - key]", lambda e,v: s("vray_gui_screen", 2)) Draw.Button("CM / Env", evtRedraw, 280, 410, 90, 16, "Color Mapping [4 - key]", lambda e,v: s("vray_gui_screen", 3)) Draw.Button("Disp / Caust", evtRedraw, 370, 410, 90, 16, "Displace & Caustics globals [5 - key]", lambda e,v: s("vray_gui_screen", 4)) Draw.Button("System", evtRedraw, 460, 410, 90, 16, "System settings", lambda e,v: s("vray_gui_screen", 5)) Draw.Button("Object", evtRedraw, 550, 410, 90, 16, "Selected object settings [6 - key]", lambda e,v: s("vray_gui_screen", 6)) Draw.EndAlign() # Underline if g("vray_gui_screen") == 0: drawFrame(10, 405) if g("vray_gui_screen") == 1: drawFrame(100, 405) if g("vray_gui_screen") == 2: drawFrame(190, 405) if g("vray_gui_screen") == 3: drawFrame(280, 405) if g("vray_gui_screen") == 4: drawFrame(370, 405) if g("vray_gui_screen") == 5: drawFrame(460, 405) if g("vray_gui_screen") == 6: drawFrame(550, 405) if len(scene.objects): Draw.Button("RENDER", evtRender, 10, 8, 85, 30, "Render scene") if not g("vray_export_lock"): Draw.Button("EXPORT MESHES", evtExportG, 100, 8, 120, 30, "Export geometry") if g("vray_export_manual"): x1= 225 x2= x1+80 x3= x2+85 if g("vray_export_lock"): x1= 100 x2= x1+80 x3= x2+85 Draw.BeginAlign() Draw.Button("Materials", evtExportM, x1, 23, 80, 15, "Export materials") Draw.Button("Nodes", evtExportN, x2, 23, 80, 15, "Export nodes") Draw.Button("Lights", evtExportL, x1, 8, 80, 15, "Export lights") Draw.Button("Camera", evtExportC, x2, 8, 80, 15, "Export camera") Draw.EndAlign() Draw.Button("RUN", evtRun, x3, 8, 60, 30, "Export settings and run V-Ray") # Quick controls Draw.Button("Flip W/H", evtFlipResol, 420, 17, 65, 20, "Flip image") Draw.Toggle("GI", evtRedraw, 490, 22, 57, 15, g("vray_gi_on"), "Enable GI", l("vray_gi_on")) Draw.Toggle("Don't render", evtRedraw, 550, 22, 90, 15, g("vray_gi_dontRenderImage"), "Don't render final image (only GI)", l("vray_gi_dontRenderImage")) if(g("vray_threads_auto")): drawText(525, 8, "Threads:") Draw.Toggle("Auto", evtRedraw, 580, 4, 60, 15, g("vray_threads_auto"), "", l("vray_threads_auto")) else: Draw.BeginAlign() Draw.Number("Threads:", evtNone, 490, 4, 90, 15, g("vray_threads"), 0, 1000, "", l("vray_threads")) Draw.Toggle("Auto", evtRedraw, 580, 4, 60, 15, g("vray_threads_auto"), "", l("vray_threads_auto")) Draw.EndAlign() ### V-Ray: Common settings def panelRender(): drawButtons() drawText(10, 380, "Geometry:") Draw.Toggle("Displacement", evtNone, 20, 351, 100, 16, g("vray_geom_displacement"), "", l("vray_geom_displacement")) Draw.Toggle("Backface cull ", evtNone, 125, 351, 100, 16, g("vray_geom_backfaceCull"), "", l("vray_geom_backfaceCull")) Draw.Number("Ray bias:", evtNone, 20, 326, 205, 18, g("vray_ray_bias"), 0, 1.0, "", l("vray_ray_bias")) drawText(10, 305, "Lighting:") Draw.Toggle("Lights", evtNone, 20, 276, 100, 16, g("vray_light_doLights"), "", l("vray_light_doLights")) Draw.Toggle("Shadows", evtNone, 20, 251, 100, 16, g("vray_light_doShadows"), "", l("vray_light_doShadows")) Draw.Toggle("Hidden lights", evtNone, 125, 276, 100, 16, g("vray_light_doHiddenLights"), "", l("vray_light_doHiddenLights")) drawText(10, 230, "Materials:") Draw.Toggle("Reflect/refract", evtNone, 20, 201, 100, 16, g("vray_mtl_reflectionRefraction"), "", l("vray_mtl_reflectionRefraction")) Draw.Toggle("Glossy", evtNone, 125, 201, 100, 16, g("vray_mtl_glossy"), "", l("vray_mtl_glossy")) if(g("vray_mtl_limitDepth")): Draw.Toggle("Limit raydepth", evtRedraw, 20, 176, 120, 16, g("vray_mtl_limitDepth"), "", l("vray_mtl_limitDepth")) Draw.Number("Depth:", evtNone, 145, 175, 80, 18, g("vray_mtl_maxDepth"), 1, 100, "", l("vray_mtl_maxDepth")) else: Draw.Toggle("Limit raydepth", evtRedraw, 20, 176, 205, 16, g("vray_mtl_limitDepth"), "", l("vray_mtl_limitDepth")) Draw.Number("Tra. levels:", evtNone, 20, 150, 105, 18, g("vray_mtl_transpMaxLevels"), 0, 1000, "Max. transparency levels", l("vray_mtl_transpMaxLevels")) Draw.Number("Cutoff:", evtNone, 130, 150, 95, 18, g("vray_mtl_transpCutoff"), 0, 1.0, "Transparency cutoff", l("vray_mtl_transpCutoff")) if(g("vray_mtl_overall")): mtl_over= "Type %t| Dirt %x2| Wire %x1| Color %x0" Draw.Toggle("Material override",evtRedraw, 20, 125, 110, 18, g("vray_mtl_overall"), "", l("vray_mtl_overall")) Draw.Menu(mtl_over, evtRedraw, 135, 125, 90, 18, g("vray_mtl_overall_type"), "", l("vray_mtl_overall_type")) else: Draw.Toggle("Material override",evtRedraw, 20, 125, 205, 18, g("vray_mtl_overall"), "", l("vray_mtl_overall")) drawText(10, 105, "Options:") Draw.Toggle("Save render", evtRedraw, 20, 80, 90, 16, g("vray_autosave_render"), "Autosave render image to \"Output\" path", l("vray_autosave_render")) if(g("vray_autosave_render")): Draw.Toggle("Save alpha", evtNone, 115, 80, 90, 16, g("vray_img_separateAlpha"), "Save alpha channel to separate file", l("vray_img_separateAlpha")) Draw.Toggle("Don't render", evtRedraw, 20, 55, 90, 16, g("vray_gi_dontRenderImage"), "Don't render final image (only GI)", l("vray_gi_dontRenderImage")) drawText(250, 380, "Passes:") Draw.Toggle("Main passes", evtRedraw, 260, 351, 80, 16, g("vray_mainpasses"), "", l("vray_mainpasses")) if g("vray_mainpasses"): Draw.Toggle("Color mapping", evtNone, 350, 351, 90, 16, g("vray_mainpasses_cm"), "Apply color mapping to the channel", l("vray_mainpasses_cm")) Draw.Toggle("Render ID", evtNone, 260, 326, 80, 16, g("vray_renderid"), "", l("vray_renderid")) Draw.Toggle("Velocity", evtRedraw, 260, 301, 80, 16, g("vray_velocity"), "", l("vray_velocity")) if(g("vray_velocity")): Draw.Toggle("Clamp", evtNone, 350, 301, 50, 16, g("vray_velocity_clamp_velocity"), "", l("vray_velocity_clamp_velocity")) Draw.Toggle("Ignore Z", evtNone, 405, 301, 60, 16, g("vray_velocity_ignore_z"), "", l("vray_velocity_ignore_z")) Draw.Number("Max:", evtNone, 470, 300, 75, 18, g("vray_velocity_max_velocity"), 0.0, 1000.0, "", l("vray_velocity_max_velocity")) Draw.Number("Max last:", evtNone, 550, 300, 85, 18, g("vray_velocity_max_velocity_last_frame"), 0.0, 1000.0, "", l("vray_velocity_max_velocity_last_frame")) Draw.Toggle("Z-Depth", evtRedraw, 260, 276, 80, 16, g("vray_zdepth"), "", l("vray_zdepth")) if(g("vray_zdepth")): Draw.Number("Near:", evtNone, 350, 275, 90, 18, g("vray_zdepth_depth_black"), 0, 1000, "", l("vray_zdepth_depth_black")) Draw.Number("Far:", evtNone, 445, 275, 90, 18, g("vray_zdepth_depth_white"), 0, 1000, "", l("vray_zdepth_depth_white")) Draw.Toggle("Clamp", evtNone, 540, 276, 50, 16, g("vray_zdepth_depth_clamp"), "", l("vray_zdepth_depth_clamp")) Draw.Toggle("Normals", evtNone, 260, 251, 80, 16, g("vray_normals"), "", l("vray_normals")) Draw.Toggle("AO", evtRedraw, 260, 226, 80, 16, g("vray_extratex"), "", l("vray_extratex")) if(g("vray_extratex")): Draw.Toggle("AA", evtNone, 350, 226, 40, 16, g("vray_extratex_consider_for_aa"), "", l("vray_extratex_consider_for_aa")) Draw.Toggle("Affect matte objects", evtNone, 395, 226, 130, 16, g("vray_extratex_matte"), "", l("vray_extratex_matte")) Draw.Number("R:", evtNone, 530, 225, 80, 18, g("vray_extratex_ao_radius"), 0.0, 1.0, "", l("vray_extratex_ao_radius")) Draw.Toggle("MultiMatte", evtRedraw, 260, 201, 80, 16, g("vray_multimatte"), "", l("vray_multimatte")) if(g("vray_multimatte")): Draw.Number("R:", evtNone, 350, 200, 50, 18, g("vray_multimatte_red_id"), 0, 100, "The object ID that will be written as the red channel (0 to disable the red channel)", l("vray_multimatte_red_id")) Draw.Number("G:", evtNone, 405, 200, 50, 18, g("vray_multimatte_green_id"), 0, 100, "The object ID that will be written as the green channel (0 to disable the green channel)", l("vray_multimatte_green_id")) Draw.Number("B:", evtNone, 460, 200, 50, 18, g("vray_multimatte_blue_id"), 0, 100, "The object ID that will be written as the blue channel (0 to disable the blue channel)", l("vray_multimatte_blue_id")) Draw.Toggle("Use material ID", evtNone, 515, 201, 100, 16, g("vray_multimatte_use_mtl_id"), "Use the material IDs instead of the object IDs", l("vray_multimatte_use_mtl_id")) drawText(250, 180, "Pipeline:") Draw.Toggle("Active layers", evtNone, 260, 150, 105, 16, g("vray_export_active"), "Render only renderable objects from active layers", l("vray_export_active")) Draw.Toggle("Auto meshes", evtRedraw, 260, 125, 105, 16, g("vray_export_lock"), "Automatically export meshes before render", l("vray_export_lock")) Draw.Toggle("Manual export", evtRedraw, 260, 100, 105, 16, g("vray_export_manual"), "Manual export control", l("vray_export_manual")) Draw.Toggle("Animation", evtRedraw, 375, 150, 105, 16, g("vray_export_animation"), "Render animation", l("vray_export_animation")) Draw.Toggle("Camera loop", evtNone, 375, 125, 105, 16, g("vray_export_cameraloop"), "Render all active cameras", l("vray_export_cameraloop")) Draw.Toggle("Bake selected", evtNone, 375, 100, 105, 16, g("vray_export_bake"), "Bake texture for selected object", l("vray_export_bake")) Draw.Toggle("Instances", evtNone, 375, 75, 105, 16, g("vray_export_instances"), "Use instances, turn off to export each object as unique", l("vray_export_instances")) Draw.Toggle("Show dupli base", evtNone, 490, 150, 105, 16, g("vray_export_dupli"), "Show Dupli base object", l("vray_export_dupli")) Draw.Toggle("Render hair", evtNone, 490, 125, 105, 16, g("vray_dohair"), "Render hair on objects", l("vray_dohair")) Draw.BeginAlign() Draw.Toggle("Add AO effect", evtRedraw, 490, 100, 105, 16, g("vray_do_AO_effect"), "Add AO effect. Idea of Ni Zu ", l("vray_do_AO_effect")) if g("vray_do_AO_effect"): Draw.ColorPicker( evtRedraw, 490, 75, 45, 18, getColor("vray_AO_effect_color"), "AO color", l("vray_AO_effect_color")) Draw.Number("", evtNone, 536, 75, 59, 18, g("vray_AO_effect_alpha"), 0.0, 1.0, "", l("vray_AO_effect_alpha")) Draw.EndAlign() ### V-Ray: Image sampler & Antialiasing def panelSampler(): drawButtons() drawText(10, 380, "Image sampler:") Draw.Menu("Type %t| Adaptive subdivision %x2| DMC %x1| Fixed %x0", evtRedraw, 110, 375, 140, 18, g("vray_imageSamplerType"), "", l("vray_imageSamplerType")) if g("vray_imageSamplerType") == 0: Draw.Number("Rate:", evtNone, 110, 350, 140, 18, g("vray_FixedRate"), 1, 100, "Fixed rate", l("vray_FixedRate")) if g("vray_imageSamplerType") == 1: Draw.Number("Min:", evtNone, 110, 350, 140, 18, g("vray_dmc_minSubdivs"), 1, 100, "DMC minimus subdivisions", l("vray_dmc_minSubdivs")) Draw.Number("Max:", evtNone, 255, 350, 140, 18, g("vray_dmc_maxSubdivs"), g("vray_dmc_minSubdivs")+1, 100, "DMC maximum subdivisions", l("vray_dmc_maxSubdivs")) Draw.Number("Thresh:", evtNone, 110, 325, 140, 18, g("vray_dmc_threshold"), 0, 1.0, "", l("vray_dmc_threshold")) if g("vray_imageSamplerType") == 2: Draw.Number("Min:", evtNone, 110, 350, 140, 18, g("vray_subdivision_minRate"), -10, 100, "Min rate", l("vray_subdivision_minRate")) Draw.Number("Max:", evtNone, 255, 350, 140, 18, g("vray_subdivision_maxRate"), g("vray_subdivision_minRate")+1, 100, "Max rate", l("vray_subdivision_maxRate")) Draw.Number("Thresh:", evtNone, 400, 350, 140, 18, g("vray_subdivision_threshold"), 0, 1.0, "Max rate", l("vray_subdivision_threshold")) Draw.Toggle("Edges", evtNone, 110, 325, 65, 18, g("vray_subdivision_edges"), "", l("vray_subdivision_edges")) Draw.Toggle("Normals", evtRedraw, 180, 325, 70, 18, g("vray_subdivision_normals"), "", l("vray_subdivision_normals")) if g("vray_subdivision_normals"): Draw.Number("Nrm. tresh:", evtNone, 255, 325, 140, 18, g("vray_subdivision_normals_threshold"), 0, 1.0, "", l("vray_subdivision_normals_threshold")) BGL.glRasterPos2i(10,280) Draw.Text("Antialiasing filter:") menu_filter = "Type %t| Gaussian %x6| Sinc %x5| Lanczos %x4| Triangle %x3| Box %x2| Area %x1| None %x0" Draw.Menu(menu_filter, evtRedraw, 110, 275, 140, 18, g("vray_aa_filter_type"), "", l("vray_aa_filter_type")) if g("vray_aa_filter_type") != 0: Draw.Number("Size:", evtNone, 110, 250, 140, 18, g("vray_aa_filter_size"), 0.01, 20.0, "Filter width", l("vray_aa_filter_size")) BGL.glRasterPos2i(10,205) Draw.Text("DMC Sampler:") Draw.Number("Adaptive amount:", evtNone, 110, 200, 200, 18, g("vray_adaptive_amount"), 0.0, 1.0, "", l("vray_adaptive_amount")) Draw.Number("Noise threshold:", evtNone, 110, 175, 200, 18, g("vray_adaptive_threshold"), 0.001, 1.0, "", l("vray_adaptive_threshold")) Draw.Number("Min. samples:", evtNone, 110, 150, 200, 18, g("vray_adaptive_min_samples"), 0, 100, "", l("vray_adaptive_min_samples")) Draw.Number("Subdivs mult:", evtNone, 110, 125, 200, 18, g("vray_subdivs_mult"), 0.0, 100.0, "", l("vray_subdivs_mult")) Draw.Toggle("Time dependent", evtNone, 110, 100, 110, 18, g("vray_time_dependent"), "", l("vray_time_dependent")) def drawPhotonMap(x): c1 = x+10 c2 = x+160 BGL.glRasterPos2i(x,280) Draw.Text("Photon map:") Draw.Number("Bounces:", evtNone, c1, 250, 140, 18, g("vray_pm_bounces"), 1, 1000, "", l("vray_pm_bounces")) Draw.Toggle("Auto dist", evtRedraw, c1, 226, 55, 16, g("vray_pm_auto_search_distance"), "", l("vray_pm_auto_search_distance")) if g("vray_pm_auto_search_distance") == 0: Draw.Number("Dist:", evtNone, c1+60, 225, 80, 18, g("vray_pm_search_distance"), 0, 1000.0, "", l("vray_pm_search_distance")) Draw.Number("Max. photons:", evtNone, c1, 200, 140, 18, g("vray_pm_max_photons"), 1, 1000, "", l("vray_pm_max_photons")) Draw.Number("Multiplier:", evtNone, c1, 175, 140, 18, g("vray_pm_multiplier"), 0, 100.0, "", l("vray_pm_multiplier")) Draw.Number("Max density:", evtNone, c1, 150, 140, 18, g("vray_pm_max_density"), 0, 10.0, "", l("vray_pm_max_density")) Draw.Toggle("Convert to IM", evtRedraw, c2, 251, 140, 16, g("vray_pm_prefilter"), "", l("vray_pm_prefilter")) if g("vray_pm_prefilter"): Draw.Number("Interp samples:", evtNone, c2, 225, 140, 18, g("vray_pm_prefilter_samples"), 0, 1000, "", l("vray_pm_prefilter_samples")) Draw.Toggle("Convex hull area", evtNone, c2, 200, 140, 16, g("vray_pm_convex_hull_estimate"), "", l("vray_pm_convex_hull_estimate")) Draw.Toggle("Store direct light", evtNone, c2, 175, 140, 16, g("vray_pm_store_direct_light"), "", l("vray_pm_store_direct_light")) Draw.Number("Rtr thresh:", evtNone, c2, 150, 140, 18, g("vray_pm_retrace_corners"), 0, 1.0, "", l("vray_pm_retrace_corners")) Draw.Number("Rtr bounces:", evtNone, c2, 125, 140, 18, g("vray_pm_retrace_bounces"), 0, 1000, "", l("vray_pm_retrace_bounces")) def drawLightCache(x): c1 = x+10 c3 = x+245 menu_lc_mode = "Mode %t| Single frame %x0| Fly-Through %x1| From file %x2| Path-Tracing %x3" Draw.Menu(menu_lc_mode, evtRedraw, 525, 300, 105, 18, g("vray_lc_mode"), "", l("vray_lc_mode")) drawText(x,280,"Light Cache:") Draw.Toggle("Auto save", evtRedraw, c1+205, 277, 80, 14, g("vray_lc_auto_save"), "Autosave Light Cache", l("vray_lc_auto_save")) Draw.Number("Subdivs:", evtNone, c1, 250, 180, 18, g("vray_lc_subdivs"), 1, 65535, "", l("vray_lc_subdivs")) Draw.Number("Sample size:", evtNone, c1, 225, 150, 18, g("vray_lc_sample_size"), 0, 1.0, "", l("vray_lc_sample_size")) Draw.Toggle("W", evtNone, c1+155, 226, 25, 16, g("vray_lc_scale"), "World mode", l("vray_lc_scale")) Draw.Number("Passes:", evtNone, c1, 200, 90, 18, g("vray_lc_num_passes"), 1, 128, "Light Cache passes. Better if = cores/CPU number", l("vray_lc_num_passes")) Draw.Number("Depth:", evtNone, c1+95, 200, 85, 18, g("vray_lc_depth"), 1, 1000, "", l("vray_lc_depth")) if(g("vray_lc_prefilter")): Draw.Toggle("Pre-filter", evtRedraw, c1, 176, 110, 16, g("vray_lc_prefilter"), "", l("vray_lc_prefilter")) Draw.Number("", evtNone, c1+115, 175, 65, 18, g("vray_lc_prefilter_samples"), 1, 1000, "", l("vray_lc_prefilter_samples")) else: Draw.Toggle("Pre-filter", evtRedraw, c1, 176, 180, 16, g("vray_lc_prefilter"), "", l("vray_lc_prefilter")) drawText(c1,155,"Filter:") menu_lc_filter = "Type %t| Fixed %x2| Nearest %x1| None %x0" if(g("vray_lc_filter_type")): Draw.Menu(menu_lc_filter, evtRedraw, c1+40, 150, 75, 18, g("vray_lc_filter_type"), "", l("vray_lc_filter_type")) else: Draw.Menu(menu_lc_filter, evtRedraw, c1+40, 150, 140, 18, g("vray_lc_filter_type"), "", l("vray_lc_filter_type")) if(g("vray_lc_filter_type") == 1): Draw.Number("", evtNone, c1+120, 150, 60, 18, g("vray_lc_filter_samples"), 1, 1000, "", l("vray_lc_filter_samples")) if(g("vray_lc_filter_type") == 2): Draw.Number("", evtNone, c1+120, 150, 60, 18, g("vray_lc_filter_size"), 0, 1.0, "", l("vray_lc_filter_size")) Draw.Toggle("Store", evtNone, c3, 250, 50, 16, g("vray_lc_store_direct_light"), "", l("vray_lc_store_direct_light")) Draw.Toggle("Show", evtNone, c3, 225, 50, 16, g("vray_lc_show_calc_phase"), "", l("vray_lc_show_calc_phase")) Draw.Toggle("Glossy", evtNone, c3, 200, 50, 16, g("vray_lc_use_for_glossy_rays"), "", l("vray_lc_use_for_glossy_rays")) Draw.Toggle("Adapt", evtNone, c3, 175, 50, 16, g("vray_lc_adaptive_sampling"), "", l("vray_lc_adaptive_sampling")) if(g("vray_lc_auto_save")): Draw.String("File: ", evtNone, c1, 52, 140, 18, g("vray_lc_auto_save_file"), 100, "", l("vray_lc_auto_save_file")) if(g("vray_lc_mode") == 2): Draw.Button("File: %s"%(getFilename("vray_lc_file")), evtRedraw, c1+150, 52, 140, 18, "Set LC file", lambda e,v:Window.FileSelector(lambda v: s("vray_lc_file",v), "Select LC file")) def drawBruteForce(x, sb): c1 = x+10 BGL.glRasterPos2i(x,280) Draw.Text("Brute force:") Draw.Number("Subdivs:", evtNone, c1, 250, 140, 18, g("vray_dmcgi_subdivs"), 1, 256, "", l("vray_dmcgi_subdivs")) if (sb == 1): Draw.Number("Depth:", evtNone, c1, 225, 140, 18, g("vray_dmcgi_depth"), 1, 256, "", l("vray_dmcgi_depth")) ### V-Ray: Global Illumination def panelGI(): drawButtons() BGL.glColor3f(0.9,0.9,0.9) BGL.glRasterPos2i(10,380) Draw.Text("Global illumination:") Draw.Toggle("On", evtRedraw, 20, 351, 81, 16, g("vray_gi_on"), "", l("vray_gi_on")) if g("vray_gi_on") == 1: Draw.Toggle("Refl", evtRedraw, 120, 351, 60, 16, g("vray_reflect_caustics"), "Reflect caustics", l("vray_reflect_caustics")) Draw.Toggle("Refr", evtRedraw, 185, 351, 60, 16, g("vray_refract_caustics"), "Refract caustics", l("vray_refract_caustics")) Draw.Number("Sat:", evtNone, 260, 350, 120, 18, g("vray_saturation"), 0, 1.0, "", l("vray_saturation")) Draw.Number("Contrast:", evtNone, 385, 350, 120, 18, g("vray_contrast"), 0, 10.0, "", l("vray_contrast")) Draw.Number("Base:", evtNone, 510, 350, 120, 18, g("vray_contrast_base"), 0, 10.0, "", l("vray_contrast_base")) BGL.glColor3f(0.9,0.9,0.9) BGL.glRasterPos2i(10,330) Draw.Text("Primary bounces:") menu_gi_pe = "Engine %t| Light Cache %x3| Brute force %x2| Photon map %x1| Irradiance map %x0" Draw.Number("", evtNone, 20, 300, 55, 18, g("vray_primary_multiplier"), 0, 100.0, "Primary bounces multiplier", l("vray_primary_multiplier")) Draw.Menu(menu_gi_pe, evtRedraw, 80, 300, 115, 18, g("vray_primary_engine"), "Primary bounces engine", l("vray_primary_engine")) BGL.glColor3f(0.9,0.9,0.9) BGL.glRasterPos2i(335,330) Draw.Text("Secondary bounces:") menu_gi_se = "Engine %t| Light Cache %x3| Brute force %x2| Photon map %x1| None %x0" Draw.Number("", evtNone, 345, 300, 55, 18, g("vray_secondary_multiplier"), 0, 1.0, "Secondary bounces multiplier", l("vray_secondary_multiplier")) Draw.Menu(menu_gi_se, evtRedraw, 405, 300, 115, 18, g("vray_secondary_engine"), "Secondary bounces engine", l("vray_secondary_engine")) # Irradiance map if g("vray_primary_engine") == 0: BGL.glRasterPos2i(10,280) Draw.Text("Irradiance map:") menu_im_mode = "Mode %t| Single frame %x0| Incremental %x1| From file %x2| Bucket %x5| Animation (prepass) %x6| Animation (render) %x7|" Draw.Menu(menu_im_mode, evtRedraw, 200, 300, 110, 18, g("vray_im_mode"), "", l("vray_im_mode")) Draw.Toggle("Auto save", evtRedraw, 230, 277, 80, 14, g("vray_im_auto_save"), "Autosave Irradiance Map", l("vray_im_auto_save")) Draw.Number("Min. rate:", evtRedraw, 20, 250, 140, 18, g("vray_im_min_rate"), -10, 10, "", l("vray_im_min_rate")) Draw.Number("Max. rate:", evtNone, 20, 225, 140, 18, g("vray_im_max_rate"), g("vray_im_min_rate"), 10.0, "", l("vray_im_max_rate")) Draw.Number("HSph. subdivs:", evtNone, 20, 200, 140, 18, g("vray_im_subdivs"), 1, 300.0, "", l("vray_im_subdivs")) Draw.Number("Interp. frames:", evtNone, 20, 175, 140, 18, g("vray_im_interp_frames"), 1, 300, "", l("vray_im_interp_frames")) Draw.Number("Interp. samples:", evtNone, 20, 150, 140, 18, g("vray_im_interp_samples"), 1, 300, "", l("vray_im_interp_samples")) Draw.Number("Clr tresh:", evtNone, 170, 250, 140, 18, g("vray_im_color_threshold"), 0, 1.0, "", l("vray_im_color_threshold")) Draw.Number("Nrm tresh:", evtNone, 170, 225, 140, 18, g("vray_im_normal_threshold"), 0, 1.0, "", l("vray_im_normal_threshold")) Draw.Number("Dst tresh:", evtNone, 170, 200, 140, 18, g("vray_im_distance_threshold"), 0, 1.0, "", l("vray_im_distance_threshold")) Draw.Toggle("Show", evtRedraw, 170, 151, 40, 16, g("vray_im_show_calc_phase"), "", l("vray_im_show_calc_phase")) if g("vray_im_show_calc_phase"): Draw.Toggle("Direct", evtNone, 215, 151, 45, 16, g("vray_im_show_direct_light"), "", l("vray_im_show_direct_light")) Draw.Toggle("Samples", evtNone, 265, 151, 45, 16, g("vray_im_show_samples"), "", l("vray_im_show_samples")) menu_im_interpolationType = "Type %t| Least squares with Voronoi weights %x3| Delone triangulation %x2| Least squares fit %x1| Weighted average %x0" Draw.Menu(menu_im_interpolationType, evtNone, 20, 125, 140, 18, g("vray_im_interpolationType"), "", l("vray_im_interpolationType")) menu_im_lookupType = "Type %t| Density-based %x3| Overlapping %x2| Nearest %x1| Quad-balanced %x0" Draw.Menu(menu_im_lookupType, evtNone, 170, 125, 140, 18, g("vray_im_lookupType"), "", l("vray_im_lookupType")) Draw.Number("Calc. pass samples:", evtNone, 125, 100, 185, 18, g("vray_im_calc_interp_samples"), 1, 200, "", l("vray_im_calc_interp_samples")) Draw.Toggle("M", evtNone, 20, 101, 25, 16, g("vray_im_multipass"), "Multipass", l("vray_im_multipass")) Draw.Toggle("R", evtNone, 55, 101, 25, 16, g("vray_im_randomize_samples"), "Randomize samples", l("vray_im_randomize_samples")) Draw.Toggle("C", evtNone, 90, 101, 25, 16, g("vray_im_check_sample_visibility"), "Check sample visibility", l("vray_im_check_sample_visibility")) if g("vray_im_detail_enhancement"): Draw.Toggle("DE", evtRedraw, 20, 76, 30, 16, g("vray_im_detail_enhancement"), "Detail enhancement", l("vray_im_detail_enhancement")) Draw.Number("Radius:", evtNone, 55, 75, 110, 18, g("vray_im_detail_radius"), 0, 1000.0, "Radius", l("vray_im_detail_radius")) Draw.Number("Subdivs:", evtNone, 170, 75, 110, 18, g("vray_im_detail_subdivs_mult"), 0, 1.0, "Subdivs multiplier", l("vray_im_detail_subdivs_mult")) Draw.Toggle("W", evtNone, 285, 76, 25, 16, g("vray_im_detail_scale"), "World scale", l("vray_im_detail_scale")) else: Draw.Toggle("Detail enhancement", evtRedraw, 20, 76, 290, 16, g("vray_im_detail_enhancement"), "Detail enhancement", l("vray_im_detail_enhancement")) if(g("vray_im_auto_save")): Draw.String("File: ", evtNone, 20, 52, 140, 18, g("vray_im_auto_save_file"), 100, "", l("vray_im_auto_save_file")) if(g("vray_im_mode") == 2): Draw.Button("File: %s"%(getFilename("vray_im_file")), evtRedraw, 170, 52, 140, 18, "Set IM file", lambda e,v:Window.FileSelector(lambda v: s("vray_im_file",v), "Select IM file")) if g("vray_primary_engine") == 1 and g("vray_secondary_engine") == 1: drawPhotonMap(160) else: if g("vray_primary_engine") == 1: drawPhotonMap(10) if g("vray_secondary_engine") == 1: drawPhotonMap(335) if g("vray_primary_engine") == 2 and g("vray_secondary_engine") == 2: drawBruteForce(220,1) else: if g("vray_primary_engine") == 2: drawBruteForce(10,0) if g("vray_secondary_engine") == 2: drawBruteForce(335,1) if g("vray_primary_engine") == 3 and g("vray_secondary_engine") == 3: drawLightCache(160) else: if g("vray_primary_engine") == 3: drawLightCache(10) if g("vray_secondary_engine") == 3: drawLightCache(335) ### V-Ray: Displacement / Caustics def panelDispCaust(): drawButtons() drawText(10, 380, "Displacement:") Draw.Number("Edge length:", evtNone, 110, 375, 140, 18, g("vray_displace_edgeLength"), 0, 100.0, "", l("vray_displace_edgeLength")) Draw.Number("Max. subdivs:", evtNone, 110, 350, 140, 18, g("vray_displace_maxSubdivs"), 1, 1000, "", l("vray_displace_maxSubdivs")) Draw.Number("Amount mult.:", evtNone, 110, 325, 140, 18, g("vray_displace_amount"), 0, 100.0, "", l("vray_displace_amount")) Draw.Toggle("View dependent", evtNone, 275, 375, 120, 18, g("vray_displace_viewDependent"), "", l("vray_displace_viewDependent")) Draw.Toggle("Tight bounds", evtNone, 275, 350, 120, 18, g("vray_displace_tightBounds"), "", l("vray_displace_tightBounds")) Draw.Toggle("Relative", evtNone, 275, 325, 120, 18, g("vray_displace_relative"), "", l("vray_displace_relative")) drawText(10, 280, "Caustics") Draw.Toggle("On", evtRedraw, 70, 276, 40, 16, g("vray_caustics_on"), "", l("vray_caustics_on")) if g("vray_caustics_on"): drawText(20, 255, "Mode:") Draw.Menu("Mode %t| From file %x1| Normal %x0", evtRedraw, 110, 250, 140, 18, g("vray_caustics_mode"), "", l("vray_caustics_mode")) drawText(20, 230, "Parameters:") if g("vray_caustics_mode"): Draw.Button("File: %s"%(getFilename("vray_caustics_file")), evtRedraw, 110, 225, 140, 18, "Set caustics file", lambda e,v:Window.FileSelector(lambda v: s("vray_caustics_file",v), "Select caustics file")) else: Draw.Toggle("Auto save", evtRedraw, 260, 251, 80, 16, g("vray_caustics_auto_save"), "", l("vray_caustics_auto_save")) if g("vray_caustics_auto_save"): Draw.String("File: ", evtNone, 350, 250, 140, 18, g("vray_caustics_auto_save_file"), 100, "", l("vray_caustics_auto_save_file")) Draw.Toggle("Show", evtNone, 260, 226, 80, 16, g("vray_caustics_show_calc_phase"), "", l("vray_caustics_show_calc_phase")) Draw.Number("Multiplier:", evtNone, 110, 225, 140, 18, g("vray_caustics_multiplier"), 0, 100.0, "", l("vray_caustics_multiplier")) Draw.Number("Search dist:", evtNone, 110, 200, 140, 18, g("vray_caustics_search_distance"), 0, 10.0, "", l("vray_caustics_search_distance")) Draw.Number("Max photons:", evtNone, 110, 175, 140, 18, g("vray_caustics_max_photons"), 0, 10000, "", l("vray_caustics_max_photons")) Draw.Number("Max density:", evtNone, 110, 150, 140, 18, g("vray_caustics_max_density"), 0, 1000.0, "", l("vray_caustics_max_density")) ### V-Ray: Color mapping def panelCM(): drawButtons() drawText(10, 380, "Color mapping:") menu_cm = "Type %t| Reinhard %x6| Intensity gamma %x5| Gamma correction %x4| Intensity exponential %x3| HSV exponential %x2| Exponential %x1| Linear %x0" Draw.Menu(menu_cm, evtRedraw, 110, 375, 140, 18, g("vray_cm_type"), "", l("vray_cm_type")) if g("vray_cm_type") == 0 or g("vray_cm_type") == 1 or g("vray_cm_type") == 2 or g("vray_cm_type") == 3: Draw.Number("Bright mult:", evtNone, 110, 350, 140, 18, g("vray_bright_mult"), 0, 100.0, "", l("vray_bright_mult")) Draw.Number("Dark mult:", evtNone, 110, 325, 140, 18, g("vray_dark_mult"), 0, 100.0, "", l("vray_dark_mult")) if g("vray_cm_type") == 4 or g("vray_cm_type") == 5: Draw.Number("Multiplier:", evtNone, 110, 350, 140, 18, g("vray_bright_mult"), 0, 100.0, "", l("vray_bright_mult")) Draw.Number("Inverse gamma:", evtNone, 110, 325, 140, 18, g("vray_dark_mult"), 0, 100.0, "", l("vray_dark_mult")) if g("vray_cm_type") == 6: Draw.Number("Multiplier:", evtNone, 110, 350, 140, 18, g("vray_bright_mult"), 0, 100.0, "", l("vray_bright_mult")) Draw.Number("Burn:", evtNone, 110, 325, 140, 18, g("vray_dark_mult"), 0, 100.0, "", l("vray_dark_mult")) Draw.Number("Gamma:", evtNone, 110, 300, 140, 18, g("vray_gamma"), 0, 10.0, "", l("vray_gamma")) Draw.Number("Input gamma:", evtNone, 110, 275, 140, 18, g("vray_inputgamma"), 0, 10.0, "", l("vray_inputgamma")) Draw.Toggle("Affect BG", evtNone, 255, 375, 80, 18, g("vray_affect_background"), "", l("vray_affect_background")) Draw.Toggle("Subpixel", evtNone, 255, 350, 80, 18, g("vray_subpixel_mapping"), "", l("vray_subpixel_mapping")) Draw.Toggle("Clamp", evtRedraw, 255, 325, 80, 18, g("vray_clamp_output"), "", l("vray_clamp_output")) if g("vray_clamp_output"): Draw.Number("Level:", evtNone, 340, 325, 120, 18, g("vray_clamp_level"), 0, 10.0, "", l("vray_clamp_level")) Draw.Toggle("Adapt only", evtNone, 255, 300, 80, 18, g("vray_adaptation_only"), "", l("vray_adaptation_only")) Draw.Toggle("LWF", evtNone, 255, 275, 80, 18, g("vray_linearWorkflow"), "Linear workflow", l("vray_linearWorkflow")) drawText(10, 205, "Environment:") uvwenv_menu = "Type: %t| Angular %x4| Cubic %x3| Mirror ball %x2| Screen %x1| Spherical %x0" env_menu = "Type: %t| None %x7| Gradient %x6| Texture %x5| VRaySky %x4| Amb color %x3| Zen color %x2| Hor color %x1| Color %x0" tex_menu= buildTexMenu(Blender.World.Get()[0].textures) drawText(20, 180, "Background:") Draw.Menu(env_menu, evtRedraw, 115, 175, 95, 18, g("vray_env_bg_type"), "", l("vray_env_bg_type")) if(g("vray_env_bg_type") == 0): Draw.ColorPicker( evtRedraw, 300, 175, 45, 18, getColor("vray_env_bg_color"), "BG color", l("vray_env_bg_color")) if(g("vray_env_bg_type") == 5): Draw.Menu(tex_menu, evtNone, 300, 175, 100, 18, g("vray_env_bg_tex_id"), "", l("vray_env_bg_tex_id")) Draw.Menu(uvwenv_menu, evtNone, 405, 175, 100, 18, g("vray_env_bg_uvtype"), "", l("vray_env_bg_uvtype")) if not g("vray_env_bg_type") in (4,7): Draw.Number("Mult: ", evtNone, 215, 175, 80, 18, g("vray_env_bg_mult"), 0.0, 1000.0, "", l("vray_env_bg_mult")) drawText(20, 155, "GI override:") Draw.Menu(env_menu, evtRedraw, 115, 150, 95, 18, g("vray_env_gi_type"), "", l("vray_env_gi_type")) if(g("vray_env_gi_type") == 0): Draw.ColorPicker( evtRedraw, 300, 150, 45, 18, getColor("vray_env_gi_color"), "GI override color", l("vray_env_gi_color")) if(g("vray_env_gi_type") == 5): Draw.Menu(tex_menu, evtNone, 300, 150, 100, 18, g("vray_env_gi_tex_id"), "", l("vray_env_gi_tex_id")) Draw.Menu(uvwenv_menu, evtNone, 405, 150, 100, 18, g("vray_env_gi_uvtype"), "", l("vray_env_gi_uvtype")) if not g("vray_env_gi_type") in (4,7): Draw.Number("Mult: ", evtNone, 215, 150, 80, 18, g("vray_env_gi_mult"), 0.0, 1000.0, "", l("vray_env_gi_mult")) drawText(20, 130, "Reflect override:") Draw.Menu(env_menu, evtRedraw, 115, 125, 95, 18, g("vray_env_reflect_type"), "", l("vray_env_reflect_type")) if(g("vray_env_reflect_type") == 0): Draw.ColorPicker( evtRedraw, 300, 125, 45, 18, getColor("vray_env_reflect_color"), "Reflection override color", l("vray_env_reflect_color")) if(g("vray_env_reflect_type") == 5): Draw.Menu(tex_menu, evtNone, 300, 125, 100, 18, g("vray_env_reflect_tex_id"), "", l("vray_env_reflect_tex_id")) Draw.Menu(uvwenv_menu, evtNone, 405, 125, 100, 18, g("vray_env_reflect_uvtype"), "", l("vray_env_reflect_uvtype")) if not g("vray_env_reflect_type") in (4,7): Draw.Number("Mult: ", evtNone, 215, 125, 80, 18, g("vray_env_reflect_mult"), 0.0, 1000.0, "", l("vray_env_reflect_mult")) drawText(20, 105, "Refract override:") Draw.Menu(env_menu, evtRedraw, 115, 100, 95, 18, g("vray_env_refract_type"), "", l("vray_env_refract_type")) if(g("vray_env_refract_type") == 0): Draw.ColorPicker( evtRedraw, 300, 100, 45, 18, getColor("vray_env_refract_color"), "Refraction override color", l("vray_env_refract_color")) if(g("vray_env_refract_type") == 5): Draw.Menu(tex_menu, evtNone, 300, 100, 100, 18, g("vray_env_refract_tex_id"), "", l("vray_env_refract_tex_id")) Draw.Menu(uvwenv_menu, evtNone, 405, 100, 100, 18, g("vray_env_refract_uvtype"), "", l("vray_env_refract_uvtype")) if not g("vray_env_refract_type") in (4,7): Draw.Number("Mult: ", evtNone, 215, 100, 80, 18, g("vray_env_refract_mult"), 0.0, 1000.0, "", l("vray_env_refract_mult")) # drawText(20, 80, "Fog:") # if(g("vray_env_volume")): # Draw.Toggle("On", evtRedraw, 115, 75, 45, 18, g("vray_env_volume"), "Environment fog", l("vray_env_volume")) # Draw.ColorPicker( evtRedraw, 165, 75, 45, 18, getColor("vray_env_volume_color"), "Refraction override color", l("vray_env_volume_color")) # Draw.Number("Mult: ", evtNone, 215, 75, 80, 18, g("vray_env_volume_mult"), 0.0, 1000.0, "", l("vray_env_volume_mult")) # else: # Draw.Toggle("On", evtRedraw, 115, 75, 95, 18, g("vray_env_volume"), "Environment fog", l("vray_env_volume")) ### V-Ray: System def panelSystem(): drawButtons() BGL.glColor3f(0.9,0.9,0.9) BGL.glRasterPos2i(10,380) Draw.Text("Raycaster:") Draw.Number("Max. levels:", evtNone, 110, 375, 200, 18, g("vray_maxLevels"), 0, 100, "", l("vray_maxLevels")) Draw.Number("Min. leaf size:", evtNone, 110, 350, 200, 18, g("vray_minLeafSize"), 0.0, 10.0, "", l("vray_minLeafSize")) Draw.Number("Face/level coef.:", evtNone, 110, 325, 200, 18, g("vray_faceLevelCoef"), 0.0, 10.0, "", l("vray_faceLevelCoef")) Draw.Number("Dynamic memory limit:", evtNone, 110, 300, 200, 18, g("vray_dynMemLimit"), 0, 10000, "", l("vray_dynMemLimit")) Draw.Number("Bucket size:", evtNone, 340, 300, 200, 18, g("vray_xc"), 0, 1024, "", l("vray_xc")) drawText(405, 380, "Blender Unit = 1.0 Meter") Draw.Number("", evtNone, 340, 375, 60, 18, g("vray_metric_scale"), 0.0, 100.0, "", l("vray_metric_scale")) Draw.Number("Photometric scale:", evtNone, 340, 350, 200, 18, g("vray_photometric_scale"), 0.0, 1.0, "", l("vray_photometric_scale")) drawText(10, 255, "Renderer:") Draw.Button("SAVE", evtNone, 585, 250, 50, 18, "Save settings globally", lambda e,v:updateRegistry()) if(ostype == "win32"): vray_binary= "vray.exe" else: vray_binary= "vray" Draw.Button("...", evtRedraw, 110, 250, 20, 18, "Select V-Ray binary", lambda e,v:Window.FileSelector(lambda val: s("vray_binary", val), "Select V-Ray binary", vray_binary)) drawText(135, 255, "V-Ray binary: %s"%(g("vray_binary"))) Draw.Toggle("Autorun", evtNone, 110, 225, 80, 18, g("vray_run"), "", l("vray_run")) Draw.Toggle("Debug", evtNone, 200, 225, 80, 18, g("vray_debug"), "", l("vray_debug")) Draw.Number("Verbose:", evtNone, 290, 225, 100, 18, g("vray_verboseLevel"), 0, 4, "", l("vray_verboseLevel")) if(ostype == "linux2"): Draw.Toggle("Log window", evtNone, 400, 225, 80, 18, g("vray_log_window"), "", l("vray_log_window")) Draw.Toggle("Show VFB", evtNone, 110, 200, 80, 18, g("vray_novfb"), "Show VFB window", l("vray_novfb")) Draw.Toggle("Show stamp", evtNone, 200, 200, 80, 18, g("vray_stamp"), "Show VFB window", l("vray_stamp")) Draw.Menu("Type: %t| Region %x0| Crop %x1",\ evtNone, 290, 200, 100, 18, g("vray_render_crop"), "Border render type", l("vray_render_crop")) Draw.Toggle("Realtime", evtNone, 400, 200, 80, 18, g("vray_realtime"), "Activate V-Ray RT", l("vray_realtime")) drawText(10, 166, "Distributed:") Draw.Toggle("On", evtRedraw, 110, 160, 30, 18, g("vray_dr"), "Distributed render. Press \"Save\" to save state.", l("vray_dr")) if g("vray_dr"): Draw.String("Hosts: ", evtNone, 145, 160, 330, 18, g("vray_dr_hosts"), 399, "host{;host} - Hosts can be specified either as computer names or by IPs.", l("vray_dr_hosts")) Draw.Number("", evtNone, 480, 160, 70, 18, g("vray_dr_port"), 1, 65535, "Port", l("vray_dr_port")) Draw.Menu("Network: %t|Unix-Unix %x2|Win-Unix %x1|Win-Win %x0",\ evtNone, 555, 160, 80, 18, g("vray_dr_network"), "Network master-nodes configuration", l("vray_dr_network")) drawText(10, 125, "Exporting paths:") drawText(110, 125, "General:") Draw.Toggle("Override", evtRedraw, 165, 121, 70, 16, g("vray_export_path_over"),"", l("vray_export_path_over")) if g("vray_export_path_over"): Draw.Toggle("Same name", evtNone, 245, 121, 80, 16, g("vray_unique_name"), "Use unique filename for exported scene", l("vray_unique_name")) Draw.Button("...", evtRedraw, 335, 120, 20, 18, "Select exporting directory", lambda e,v:Window.FileSelector(lambda val: s("vray_export_path", val), "Select directory", "")) drawText(365, 125, "Path: %s"%(g("vray_export_path"))) if g("vray_dr"): drawText(110, 96, "DR:") Draw.Button("...", evtRedraw, 165, 90, 20, 18, "Select exporting directory for DR", lambda e,v:Window.FileSelector(lambda val: s("vray_export_path_dr", val), "Select exporting directory for DR", "")) drawText(195, 96, "Path: %s"%(g("vray_export_path_dr"))) drawText(10, 56, "Script version: %s"%(vrayblender_version_ext)) ### V-Ray: Lights, physical Sun/Sky, physical camera def drawDOF(x,y,obj): Draw.Toggle("DOF", evtRedraw, x, y+1, 40, 16, g("vray_camera_phys_use_dof",obj), "", l("vray_camera_phys_use_dof",obj)) Draw.Toggle("Motion blur", evtRedraw, x+45, y+1, 95, 16, g("vray_camera_phys_use_moblur",obj), "", l("vray_camera_phys_use_moblur",obj)) if(g("vray_camera_phys_use_dof",obj) or g("vray_camera_phys_use_moblur",obj)): Draw.Number("Subdivs:", evtNone, x, y-25, 140, 18, g("vray_camera_phys_subdivs",obj), 0, 1024, "", l("vray_camera_phys_subdivs",obj)) if g("vray_camera_phys_use_dof",obj): Draw.Toggle("Bokeh effects", evtRedraw, x, y-50+1, 110, 16, g("vray_camera_phys_bokeh",obj), "", l("vray_camera_phys_bokeh",obj)) if g("vray_camera_phys_bokeh",obj): Draw.Number("Center bias:", evtNone, x+10, y-75, 130, 18, g("vray_camera_center_bias",obj), -10.0, 10.0, "", l("vray_camera_center_bias",obj)) Draw.Number("Anisotropy:", evtNone, x+10, y-100, 130, 18, g("vray_camera_anisotropy",obj), -10.0, 10.0, "", l("vray_cameraa_nisotropy",obj)) Draw.Toggle("Blades", evtRedraw, x+10, y-125+1, 110, 16, g("vray_camera_blades_enable",obj), "", l("vray_camera_blades_enable",obj)) if g("vray_camera_blades_enable",obj): Draw.Number("Number:", evtNone, x+20, y-150, 120, 18, g("vray_camera_blades_num",obj), 0, 20, "", l("vray_camera_blades_num",obj)) Draw.Number("Rotation:", evtNone, x+20, y-175, 120, 18, g("vray_camera_blades_rotation",obj), 0, 20, "", l("vray_camera_blades_rotation",obj)) def drawCommonLight(x,y,obj): Draw.Number("Subdivs:", evtNone, x, y, 120, 18, g("vray_light_subdivs",obj), 1, 200, "", l("vray_light_subdivs",obj)) Draw.Number("Caustics:", evtNone, x, y-25, 120, 18, g("vray_light_caustics_subdivs",obj), 0, 1000000, "Caustics subdivs", l("vray_light_caustics_subdivs",obj)) Draw.Toggle("Invisible", evtNone, x, y-50, 58, 18, g("vray_light_invisible",obj), "", l("vray_light_invisible",obj)) Draw.Toggle("Store", evtNone, x+62, y-50, 58, 18, g("vray_light_store",obj), "", l("vray_light_store",obj)) if not g("vray_light_portal",obj): drawText(x,y-75+5, "Units:") Draw.Menu("Units: %t| Watt/m %x4| Watts %x3| Lumen/m %x2| Lumen %x1| Default %x0",\ evtNone, x+40, y-75, 80, 18, g("vray_light_units",obj), "", l("vray_light_units",obj)) Draw.Number("Intensity:", evtNone, x, y-100, 120, 18, g("vray_light_intensity",obj), 0, 100000.0, "", l("vray_light_intensity",obj)) else: y= y+50 drawText(x,y-125+5, "Affect:") Draw.Toggle("D", evtNone, x+50, y-125, 20, 18, g("vray_light_affectDiffuse",obj), "Affect diffuse", l("vray_light_affectDiffuse",obj)) Draw.Toggle("S", evtNone, x+75, y-125, 20, 18, g("vray_light_affectSpecular",obj), "Affect specular", l("vray_light_affectSpecular",obj)) Draw.Toggle("R", evtNone, x+100, y-125, 20, 18, g("vray_light_affectReflections",obj), "Affect reflection", l("vray_light_affectReflections",obj)) Draw.Toggle("Shadows", evtRedraw, x, y-151, 120, 16, g("vray_light_shadows",obj), "", l("vray_light_shadows",obj)) if(g("vray_light_shadows",obj)): Draw.Number("Bias:", evtNone, x, y-175, 120, 18, g("vray_light_shadowBias",obj), 0.0, 1.0, "", l("vray_light_shadowBias",obj)) if obj.data.getType() != 4: # Rectangle Draw.Number("Radius:",evtNone, x, y-200, 120, 18, g("vray_light_shadowRadius",obj), 0.0, 10.0, "", l("vray_light_shadowRadius",obj)) def drawAnimParams(obj, x, y): drawText(x, y, "Animation properties:") drawText(x+20, y-25, "Type:") menu= "Type: %t| Dynamic %x1| Static %x0" Draw.Menu(menu, evtNone, x+60, y-30, 130, 18, g("vray_object_dynamic",obj), "", l("vray_object_dynamic",obj)) def panelObject(): drawButtons() selected = Blender.Object.GetSelected() if (len(selected) == 1): obj= selected[0] obj_name= obj.name if (obj.getType() == "Lamp"): light_caption = "Light: %s"%(obj_name) drawText(10, 380, light_caption) light_caption_offset = 10+Draw.GetStringWidth(light_caption, "normal")+5 if obj.data.getType() == 1: # Direct/Sun drawText(20, 355, "Type:") type_menu= "Type: %t| Sun %x1| Direct %x0" Draw.Menu(type_menu, evtRedraw, 60, 350, 110, 18, g("vray_light_sun",obj), "", l("vray_light_sun",obj)) drawText(20, 330, "Properties:") if(g("vray_light_sun",obj)): # Sun/Sky if(g("vray_light_sun",obj)): drawText(40,305, "Sun:") Draw.Number("Turbidity:", evtNone, 60, 275, 150, 18, g("vray_sunsky_turbidity"), 2, 20.0, "", l("vray_sunsky_turbidity")) Draw.Number("Ozone:", evtNone, 60, 250, 150, 18, g("vray_sunsky_ozone"), 0, 1.0, "", l("vray_sunsky_ozone")) Draw.Number("Intensity:", evtNone, 60, 225, 150, 18, g("vray_sunsky_intensity"), 0, 10.0, "", l("vray_sunsky_intensity")) Draw.Number("Size:", evtNone, 60, 200, 150, 18, g("vray_sunsky_size_multiplier"), 0, 10.0, "", l("vray_sunsky_size_multiplier")) Draw.Number("Subdivs:", evtNone, 60, 175, 150, 18, g("vray_sunsky_shadow_subdivs"), 1, 64, "", l("vray_sunsky_shadow_subdivs")) Draw.Number("Caustics:", evtNone, 60, 150, 150, 18, g("vray_light_caustics_subdivs",obj), 0, 1000000, "", l("vray_light_caustics_subdivs",obj)) Draw.Number("Shadow bias:", evtNone, 60, 125, 150, 18, g("vray_sunsky_shadow_bias"), 0, 1.0, "", l("vray_sunsky_shadow_bias")) Draw.Number("Photon radius:", evtNone, 60, 100, 150, 18, g("vray_sunsky_photon_emit_radius"), 0, 1000.0, "", l("vray_sunsky_photon_emit_radius")) Draw.Toggle("Invisible", evtNone, 60, 75, 150, 18, g("vray_sunsky_invisible"), "", l("vray_sunsky_invisible")) drawText(220,305, "Sky:") Draw.Number("Intensity:", evtNone, 240, 275, 120, 18, g("vray_sunsky_sky_intensity"), 0, 10.0, "", l("vray_sunsky_sky_intensity")) else: # Direct Draw.Number("Beam R:", evtNone, 40, 300, 120, 18, g("vray_light_beamRadius",obj), 0.0, 100.0, "", l("vray_light_beamRadius",obj)) drawCommonLight(40,275,obj) if obj.data.getType() == 3: # Dome drawCommonLight(20,350,obj) Draw.Toggle("Full dome", evtNone, 20, 151, 120, 16, g("vray_light_dome_spherifical",obj), "", l("vray_light_dome_spherifical",obj)) Draw.Toggle("Use texture", evtRedraw, 20, 126, 120, 16, g("vray_light_use_dome_tex",obj), "", l("vray_light_use_dome_tex",obj)) if(g("vray_light_use_dome_tex",obj)): BGL.glRasterPos2i(20,105) Draw.Text("Type:") Draw.Menu("Type: %t| Angular %x4| Cubic %x3| Mirror ball %x2| Screen %x1| Spherical %x0",\ evtNone, 60, 100, 80, 18, g("vray_IBL_mapping_type",obj), "", l("vray_IBL_mapping_type",obj)) if obj.data.getType() == 0: # Lamp drawText(20, 355, "Type:") type_menu= "Type: %t| Sphere %x1| Omni %x0" Draw.Menu(type_menu, evtRedraw, 60, 350, 110, 18, g("vray_light_sphere_type",obj), "", l("vray_light_sphere_type",obj)) drawText(20, 330, "Properties:") if(g("vray_light_sphere_type",obj)): Draw.Number("R:", evtNone, 40, 300, 120, 18, g("vray_light_radius",obj), 0.0, 10.0, "Radius", l("vray_light_radius",obj)) drawCommonLight(40,275,obj) else: drawCommonLight(40,300,obj) if obj.data.getType() == 2: # Spot drawText(20, 355, "Mode:") mode_menu= "Mode: %t| IES %x1| Spot %x0" Draw.Menu(mode_menu, evtRedraw, 60, 350, 110, 18, g("vray_light_isIES",obj), "", l("vray_light_isIES",obj)) drawText(20, 330, "Properties:") drawCommonLight(40,305,obj) if(g("vray_light_isIES",obj)): drawText(200, 330, "IES:") Draw.Toggle("Soft shadows", evtNone, 220, 300, 100, 18, g("vray_light_IES_soft_shadows",obj), "", l("vray_light_IES_soft_shadows",obj)) Draw.Button("File: %s"%(getFilename("vray_light_IES",obj)), evtNone, 220, 275, 100, 18, "Select IES file [%s]"%(g("vray_light_IES",obj)), lambda e,v:Window.FileSelector(lambda v: s("vray_light_IES",v,obj), "Select IES file")) if obj.data.getType() == 4: # Rectangle drawText(20, 355, "Mode:") mode_menu= "Mode: %t| Simple portal %x2| Skylight portal %x1| Normal %x0" Draw.Menu(mode_menu, evtRedraw, 60, 350, 110, 18, g("vray_light_portal",obj), "", l("vray_light_portal",obj)) drawText(20, 330, "Properties:") drawCommonLight(30,300,obj) elif (obj.getType() == "Camera"): camera_caption = "Camera: %s"%(obj_name) drawText(10,380,camera_caption) drawText(20, 355, "Mode:") mode_menu= "Mode: %t| Physical %x1| Normal %x0" Draw.Menu(mode_menu, evtRedraw, 60, 350, 110, 18, g("vray_camera_physical",obj), "", l("vray_camera_physical",obj)) drawText(20, 330, "Properties:") if g("vray_camera_physical",obj): drawDOF(180,300,obj) drawText(30, 305, "Type:") menu = "Type %t| Video %x2| Movie %x1| Still %x0" Draw.Menu(menu, evtNone, 70, 300, 100, 18, g("vray_camera_physical_type",obj), "", l("vray_camera_physical_type",obj)) Draw.Number("F-number:", evtNone, 30, 275, 140, 18, g("vray_camera_f_number",obj), 0, 100.0, "", l("vray_camera_f_number",obj)) Draw.Number("Shutter speed:", evtNone, 30, 250, 140, 18, g("vray_camera_shutter_speed",obj), 0, 1000.0, "", l("vray_camera_shutter_speed",obj)) Draw.Number("ISO:", evtNone, 30, 225, 140, 18, g("vray_camera_ISO",obj), 0, 10000.0, "", l("vray_camera_ISO",obj)) Draw.Number("Focal length:", evtNone, 30, 200, 140, 18, g("vray_camera_focal_length",obj), 0, 200.0, "", l("vray_camera_focal_length",obj)) Draw.Number("Zoom factor:", evtNone, 30, 175, 140, 18, g("vray_camera_zoom_factor",obj), 0, 1.0, "", l("vray_camera_zoom_factor",obj)) def guess_lens_shift(e,v): shift= 0.0 const= None if len(obj.constraints) > 0: for co in obj.constraints: if co.type == Constraint.Type.TRACKTO: const= co break if(const): co_ob= const.__getitem__(Constraint.Settings.TARGET) if(co_ob): z_shift= obj.LocZ - co_ob.LocZ x= obj.LocX - co_ob.LocX y= obj.LocY - co_ob.LocY l= math.sqrt( x * x + y * y ) shift= -1 * z_shift / l else: rx= obj.rot[0] lsx= rx - math.pi/2 if(math.fabs(lsx) > 0.0001): shift= math.tan(lsx) s("vray_camera_lens_shift", shift, obj) Draw.BeginAlign() Draw.Number("Lens shift:", evtNone, 30, 150, 120, 18, g("vray_camera_lens_shift",obj), -1.0, 1.0, "", l("vray_camera_lens_shift",obj)) Draw.Button("G", evtRedraw, 151, 150, 19, 18, "Guess lens shift", guess_lens_shift) Draw.EndAlign() Draw.Number("Vignetting", evtNone, 30, 125, 140, 16, g("vray_camera_vignetting",obj), 0, 10.0, "", l("vray_camera_vignetting",obj)) drawText(30, 105, "White balance:") Draw.ColorPicker(evtRedraw, 125, 100, 45, 18, getColor("vray_camera_white_balance", obj), "White balance", l("vray_camera_white_balance",obj)) else: drawText(30, 305, "Type:") menu_camera_type = "Type %t| Orthographic %x6| Fish eye %x5| Box %x4| Cylindrical (ortho) %x3| Cylindrical (point) %x2| Spherical %x1| Standard %x0" Draw.Menu(menu_camera_type, evtRedraw, 70, 300, 140, 18, g("vray_camera_type",obj), "", l("vray_camera_type",obj)) if g("vray_camera_type",obj) == 3: Draw.Number("Height:", evtNone, 30, 275, 140, 18, g("vray_camera_height",obj), 0, 1000.0, "", l("vray_camera_height",obj)) drawDOF(30,250,obj) elif g("vray_camera_type",obj) == 5: Draw.Toggle("Auto-fit", evtRedraw, 30, 276, 60, 16, g("vray_camera_auto_fit",obj), "", l("vray_camera_auto_fit",obj)) if g("vray_camera_auto_fit",obj) == 0: Draw.Number("Dist:", evtNone, 95, 275, 75, 18, g("vray_camera_dist",obj), 0, 1000.0, "", l("vray_camera_dist",obj)) Draw.Number("Curve:", evtNone, 30, 250, 140, 18, g("vray_camera_curve",obj), 0, 10.0, "", l("vray_camera_curve",obj)) drawDOF(30,225,obj) else: drawDOF(30,275,obj) drawText(350, 330, "Hide:") Draw.Toggle("Enable", evtNone, 390, 325, 60, 16, g("vray_camera_usehide",obj), "Enable hide", l("vray_camera_usehide",obj)) drawText(360, 305, "Full:") if g("vray_camera_autohide_all",obj): Draw.Toggle("Auto", evtRedraw, 400, 301, 45, 16, g("vray_camera_autohide_all",obj), "Enable autohide", l("vray_camera_autohide_all",obj)) else: Draw.BeginAlign() Draw.Toggle("A", evtRedraw, 400, 300, 20, 18, g("vray_camera_autohide_all",obj), "Enable autohide", l("vray_camera_autohide_all",obj)) Draw.String("", evtNone, 420, 300, 210, 18, g("vray_camera_hidelist_all", obj), 200, "Object or group names to hide. Format: name{;name}", l("vray_camera_hidelist_all",obj)) Draw.EndAlign() drawText(360, 280, "Cam:") if g("vray_camera_autohide_cam",obj): Draw.Toggle("Auto", evtRedraw, 400, 276, 45, 16, g("vray_camera_autohide_cam",obj), "Enable autohide", l("vray_camera_autohide_cam",obj)) else: Draw.BeginAlign() Draw.Toggle("A", evtRedraw, 400, 275, 20, 18, g("vray_camera_autohide_cam",obj), "Enable autohide", l("vray_camera_autohide_cam",obj)) Draw.String("", evtNone, 420, 275, 210, 18, g("vray_camera_hidelist_cam", obj), 200, "Object or group names to hide from camera. Format: name{;name}", l("vray_camera_hidelist_cam",obj)) Draw.EndAlign() drawText(360, 255, "GI:") if g("vray_camera_autohide_gi",obj): Draw.Toggle("Auto", evtRedraw, 400, 251, 45, 16, g("vray_camera_autohide_gi",obj), "Enable autohide", l("vray_camera_autohide_gi",obj)) else: Draw.BeginAlign() Draw.Toggle("A", evtRedraw, 400, 250, 20, 18, g("vray_camera_autohide_gi",obj), "Enable autohide", l("vray_camera_autohide_gi",obj)) Draw.String("", evtNone, 420, 250, 210, 18, g("vray_camera_hidelist_gi", obj), 200, "Object or group names to hide from GI. Format: name{;name}", l("vray_camera_hidelist_gi",obj)) Draw.EndAlign() drawText(360, 230, "Refl:") if g("vray_camera_autohide_refl",obj): Draw.Toggle("Auto", evtRedraw, 400, 226, 45, 16, g("vray_camera_autohide_refl",obj), "Enable autohide", l("vray_camera_autohide_refl",obj)) else: Draw.BeginAlign() Draw.Toggle("A", evtRedraw, 400, 225, 20, 18, g("vray_camera_autohide_refl",obj), "Enable autohide", l("vray_camera_autohide_refl",obj)) Draw.String("", evtNone, 420, 225, 210, 18, g("vray_camera_hidelist_refl",obj), 200, "Object or group names to hide from reflection. Format: name{;name}", l("vray_camera_hidelist_refl",obj)) Draw.EndAlign() drawText(360, 205, "Refr:") if g("vray_camera_autohide_refr",obj): Draw.Toggle("Auto", evtRedraw, 400, 201, 45, 16, g("vray_camera_autohide_refr",obj), "Enable autohide", l("vray_camera_autohide_refr",obj)) else: Draw.BeginAlign() Draw.Toggle("A", evtRedraw, 400, 200, 20, 18, g("vray_camera_autohide_refr",obj), "Enable autohide", l("vray_camera_autohide_refr",obj)) Draw.String("", evtNone, 420, 200, 210, 18, g("vray_camera_hidelist_refr",obj), 200, "Object or group names to hide from refraction. Format: name{;name}", l("vray_camera_hidelist_refr",obj)) Draw.EndAlign() drawText(360, 180, "Shad:") if g("vray_camera_autohide_shad",obj): Draw.Toggle("Auto", evtRedraw, 400, 176, 45, 16, g("vray_camera_autohide_shad",obj), "Enable autohide", l("vray_camera_autohide_shad",obj)) else: Draw.BeginAlign() Draw.Toggle("A", evtRedraw, 400, 175, 20, 18, g("vray_camera_autohide_shad",obj), "Enable autohide", l("vray_camera_autohide_shad",obj)) Draw.String("", evtNone, 420, 175, 210, 18, g("vray_camera_hidelist_shad",obj), 200, "Object or group names to hide from shadows. Format: name{;name}", l("vray_camera_hidelist_shad",obj)) Draw.EndAlign() elif (obj.getType() == "Mesh"): drawText(10, 380, "Object: %s"%(obj_name)) drawText(20, 355, "Additional surface properties:") Draw.Number("GI surface ID: ", evtNone, 40, 325, 160, 18, g("vray_object_gi_surface_id",obj), 0, 1000, "", l("vray_object_gi_surface_id",obj)) Draw.Number("Generate GI: ", evtNone, 40, 300, 160, 18, g("vray_object_generate_gi",obj), 0, 100.0, "", l("vray_object_generate_gi",obj)) Draw.Number("Receive GI: ", evtNone, 40, 275, 160, 18, g("vray_object_receive_gi",obj), 0, 100.0, "", l("vray_object_receive_gi",obj)) Draw.Number("Generate caustics: ", evtNone, 40, 250, 160, 18, g("vray_object_generate_caustics",obj), 0, 100.0, "", l("vray_object_generate_caustics",obj)) Draw.Number("Receive caustics: ", evtNone, 40, 225, 160, 18, g("vray_object_receive_caustics",obj), 0, 100.0, "", l("vray_object_receive_caustics",obj)) Draw.Toggle("Override", evtRedraw, 40, 201, 60, 16, g("vray_object_override_mtl",obj), "", l("vray_object_override_mtl",obj)) if g("vray_object_override_mtl",obj): Draw.ColorPicker(evtRedraw, 105, 200, 45, 18, getColor("vray_object_override_gi", obj), "Object color for GI", l("vray_object_override_gi",obj)) matte_caption = "Matte properties:" drawText(220, 355, matte_caption) matte_caption_offset = 220+Draw.GetStringWidth(matte_caption)+5 Draw.Number("Alpha contribution: ", evtNone, 240, 325, 180, 18, g("vray_object_alpha_contribution",obj), -1.0, 1.0, "", l("vray_object_alpha_contribution",obj)) Draw.Toggle("Matte surface", evtRedraw, matte_caption_offset, 351, 90, 16, g("vray_object_matte_surface",obj), "", l("vray_object_matte_surface",obj)) if g("vray_object_matte_surface",obj): Draw.Number("Reflection amount: ", evtNone, 240, 300, 180, 18, g("vray_object_reflection_amount",obj), 0, 1.0, "", l("vray_object_reflection_amount",obj)) Draw.Number("Refraction amount: ", evtNone, 240, 275, 180, 18, g("vray_object_refraction_amount",obj), 0, 1.0, "", l("vray_object_refraction_amount",obj)) Draw.Number("GI amount: ", evtNone, 240, 250, 180, 18, g("vray_object_gi_amount",obj), 0, 1.0, "", l("vray_object_gi_amount",obj)) Draw.Toggle("Alpha", evtNone, 240, 226, 45, 16, g("vray_object_affect_alpha",obj), "", l("vray_object_affect_alpha",obj)) Draw.Toggle("Shadows", evtNone, 290, 226, 90, 16, g("vray_object_shadows",obj), "", l("vray_object_shadows",obj)) drawAnimParams(obj, 440, 355) drawText(440, 305, 'Render options:') Draw.Number("Hair thin: ", evtNone, 460, 275, 180, 18, g("vray_object_hair_thin",obj), 0.0, 1.0, "", l("vray_object_hair_thin",obj)) Draw.BeginAlign() if g("vray_object_add_AO",obj): Draw.Toggle("Add AO", evtRedraw, 460, 250, 60, 18, g("vray_object_add_AO",obj), "AO effect. Idea of Ni Zu ", l("vray_object_add_AO",obj)) Draw.Number("R: ", evtNone, 521, 250, 120, 18, g("vray_object_AO_radius",obj), 0.0, 1.0, "AO effect radius. Idea of Ni Zu ", l("vray_object_AO_radius",obj)) else: Draw.Toggle("Add AO effect", evtRedraw, 460, 251, 180, 16, g("vray_object_add_AO",obj), "AO effect. Idea of Ni Zu ", l("vray_object_add_AO",obj)) Draw.EndAlign() if g("vray_object_visible_all",obj): Draw.Toggle("Visible to all", evtRedraw, 460, 226, 180, 16, g("vray_object_visible_all",obj), "Visible to...", l("vray_object_visible_all",obj)) else: Draw.Toggle("To:", evtRedraw, 460, 226, 30, 16, g("vray_object_visible_all",obj), "Visible to everything", l("vray_object_visible_all",obj)) Draw.BeginAlign() Draw.Toggle("Cam", evtNone, 495, 226, 30, 16, g("vray_object_visible_cam",obj), "Visible to camera", l("vray_object_visible_cam",obj)) Draw.Toggle("GI", evtNone, 525, 226, 25, 16, g("vray_object_visible_gi",obj), "Visible to GI", l("vray_object_visible_gi",obj)) Draw.Toggle("RL", evtNone, 550, 226, 30, 16, g("vray_object_visible_refl",obj), "Visible to reflection", l("vray_object_visible_refl",obj)) Draw.Toggle("RR", evtNone, 580, 226, 30, 16, g("vray_object_visible_refr",obj), "Visible to refraction", l("vray_object_visible_refr",obj)) Draw.Toggle("Shad", evtNone, 610, 226, 30, 16, g("vray_object_visible_shad",obj), "Visible to shadows", l("vray_object_visible_shad",obj)) Draw.EndAlign() disp_caption = "Displacement:" disp_caption_offset = 20+Draw.GetStringWidth(disp_caption)+5 drawText(20, 155, disp_caption) Draw.Toggle("Use globals", evtRedraw, disp_caption_offset, 151, 100, 16, g("vray_displace_use_globals",obj), "If true, the global displacement quality settings will be used.", l("vray_displace_use_globals",obj)) Draw.Toggle("\"Disp\"", evtRedraw, 40, 125, 45, 18, g("vray_displace_use_dispfac",obj), "Use \"Disp\" value from \"Map To\"", l("vray_displace_use_dispfac",obj)) if not g("vray_displace_use_dispfac",obj): Draw.Number("Amount:", evtNone, 90, 125, 120, 18, g("vray_displace_amount",obj), -10.0, 10.0, "Determines the displacement amount for white areas in the displacement map", l("vray_displace_amount",obj)) drawText(215, 131, "x") Draw.Number("", evtNone, 225, 125, 60, 18, g("vray_displace_amount_delim",obj), -10.0, 10.0, "Amount delimiter", l("vray_displace_amount_delim",obj)) else: drawText(90, 131, "x") Draw.Number("", evtNone, 100, 125, 60, 18, g("vray_displace_amount_delim",obj), -10.0, 10.0, "Amount delimiter", l("vray_displace_amount_delim",obj)) Draw.Number("Shift:", evtNone, 40, 100, 170, 18, g("vray_displace_shift",obj), -10.0, 10.0, "This constant value is added to the displacement map.", l("vray_displace_shift",obj)) Draw.Number("Water level:", evtNone, 40, 75, 170, 18, g("vray_displace_water_level",obj), -10.0, 10.0, "Geometry below this displacement level will be clipped away.", l("vray_displace_water_level",obj)) if not g("vray_displace_use_globals",obj): Draw.Number("Edge length:", evtNone, 220, 100, 160, 18, g("vray_displace_edgeLength",obj), 0.0, 100.0, "Determines the approximate edge length for the sub-triangles.", l("vray_displace_edgeLength",obj)) Draw.Number("Max. subdivs:", evtNone, 220, 75, 160, 18, g("vray_displace_maxSubdivs",obj), 1, 1000, "Determines the maximum subdivisions for a triangle of the original mesh.", l("vray_displace_maxSubdivs",obj)) Draw.Toggle("View dependent", evtNone, 385, 100, 120, 18, g("vray_displace_view_dep",obj), "Determines if view-dependent tesselation is used.", l("vray_displace_view_dep",obj)) Draw.Toggle("Keep continuity", evtNone, 385, 75, 120, 18, g("vray_displace_keep_continuity",obj), "If true, V-Ray will attempt to keep the continuity of the displaced surface.", l("vray_displace_keep_continuity",obj)) Draw.Menu("Type %t| All %x0| Sel %x1| ID %x2|", evtRedraw, 485, 200, 50, 18, g('vray_calcarea_type',obj), "", l('vray_calcarea_type',obj)) def calc_area(e,v): if len(Blender.Object.GetSelected()) == 1: square= 0.0 in_emode = Window.EditMode() if in_emode: Window.EditMode(0) ob= Blender.Object.GetSelected()[0] me= Mesh.New() me.getFromObject(ob, 1, 1) for fa in me.faces: if g('vray_calcarea_type',ob) == 1: if fa.sel: square+= fa.area elif g('vray_calcarea_type',ob) == 2: if fa.mat + 1 == g('vray_calcarea_id',ob): square+= fa.area else: square+= fa.area if in_emode: Window.EditMode(1) s('vray_calcarea_val', square, ob) Draw.Button("Calc", evtRedraw, 440, 200, 40, 18, "Calculate surface area", calc_area) if g('vray_calcarea_type',obj) == 2: Draw.Number("", evtNone, 540, 200, 40, 18, g('vray_calcarea_id',obj), 1, 100, "", l('vray_calcarea_id',obj)) if g('vray_calcarea_type',obj) == 2: drawText(585, 205, "S: %.1f"%(g('vray_calcarea_val',obj))) else: drawText(545, 205, "S: %.1f"%(g('vray_calcarea_val',obj))) elif (obj.getType() == "Empty"): drawText(10, 380, "Proxy: %s"%(obj_name)) Draw.Button("File: %s"%(getFilename("vray_object_proxy_file",obj)), evtRedraw, 20, 350, 200, 18, "Select VRayProxy file", lambda e,v:Window.FileSelector(lambda v: s("vray_object_proxy_file",v,obj), "Select .vrmesh file")) mat_capt= "Materials: " drawText(20, 330, mat_capt) Draw.Number("", evtRedraw, 20+Draw.GetStringWidth(mat_capt, "normal")+5, 326, 50, 16, g("vray_object_proxy_mindex",obj), 1, 10, "", l("vray_object_proxy_mindex",obj)) materials= Material.Get() if(len(materials)): material_menu= genMaterialMenu() mat_idx = [] y = 300 for i in range(1, g("vray_object_proxy_mindex",obj)+1): drawText(40, y+5, "ID %i: "%(i)) param= "vray_object_proxy_m%d"%(i) mat_name= g(param, obj) try: mat_idx.append(materials.index(Material.Get(mat_name))) except: mat_idx.append(0) s(param, materials[0].name, obj) y = y - 25 Draw.Menu(material_menu, evtNone, 80, 300, 140, 18, mat_idx[0] , "", lambda e, v: s("vray_object_proxy_m1", materials[v].name, obj)) if g("vray_object_proxy_mindex",obj) > 1: Draw.Menu(material_menu, evtNone, 80, 275, 140, 18, mat_idx[1] , "", lambda e, v: s("vray_object_proxy_m2", materials[v].name, obj)) if g("vray_object_proxy_mindex",obj) > 2: Draw.Menu(material_menu, evtNone, 80, 250, 140, 18, mat_idx[2] , "", lambda e, v: s("vray_object_proxy_m3", materials[v].name, obj)) if g("vray_object_proxy_mindex",obj) > 3: Draw.Menu(material_menu, evtNone, 80, 225, 140, 18, mat_idx[3] , "", lambda e, v: s("vray_object_proxy_m4", materials[v].name, obj)) if g("vray_object_proxy_mindex",obj) > 4: Draw.Menu(material_menu, evtNone, 80, 200, 140, 18, mat_idx[4] , "", lambda e, v: s("vray_object_proxy_m5", materials[v].name, obj)) if g("vray_object_proxy_mindex",obj) > 5: Draw.Menu(material_menu, evtNone, 80, 175, 140, 18, mat_idx[5] , "", lambda e, v: s("vray_object_proxy_m6", materials[v].name, obj)) if g("vray_object_proxy_mindex",obj) > 6: Draw.Menu(material_menu, evtNone, 80, 150, 140, 18, mat_idx[6] , "", lambda e, v: s("vray_object_proxy_m7", materials[v].name, obj)) if g("vray_object_proxy_mindex",obj) > 7: Draw.Menu(material_menu, evtNone, 80, 125, 140, 18, mat_idx[7] , "", lambda e, v: s("vray_object_proxy_m8", materials[v].name, obj)) if g("vray_object_proxy_mindex",obj) > 8: Draw.Menu(material_menu, evtNone, 80, 100, 140, 18, mat_idx[8] , "", lambda e, v: s("vray_object_proxy_m9", materials[v].name, obj)) if g("vray_object_proxy_mindex",obj) > 9: Draw.Menu(material_menu, evtNone, 80, 75, 140, 18, mat_idx[9] , "", lambda e, v: s("vray_object_proxy_m10", materials[v].name, obj)) else: drawText(40, 300, "No materials in the scene.") drawText(250, 330, "Animation: ") Draw.Number("Type: ", evtNone, 270, 300, 160, 18, g("vray_object_proxy_anim_type",obj), 0.0, 100.0, "", l("vray_object_proxy_anim_type",obj)) Draw.Number("Speed: ", evtNone, 270, 275, 160, 18, g("vray_object_proxy_anim_speed",obj), 0.0, 100.0, "", l("vray_object_proxy_anim_speed",obj)) Draw.Number("Offset: ", evtNone, 270, 250, 160, 18, g("vray_object_proxy_anim_offset",obj), 0.0, 100.0, "", l("vray_object_proxy_anim_offset",obj)) drawAnimParams(obj, 440, 355) elif(len(selected) > 1): drawText(10, 380, "Selected objects: %d"%(len(selected))) def setDynamic(e,v): for ob in Blender.Object.GetSelected(): s("vray_object_dynamic", v, ob) menu= "Type: %t| Dynamic %x1| Static %x0" Draw.Menu(menu, evtNone, 20, 350, 130, 18, 0, "", setDynamic) def setObjectAORadius(e,v): for ob in Blender.Object.GetSelected(): if ob.type in OBJ_TYPES: s("vray_object_AO_radius", v, ob) Draw.Number("AO radius: ", evtNone, 20, 325, 130, 18, g("vray_object_AO_radius",selected[0]), 0.0, 1.0, "AO effect radius. Idea of Ni Zu ", setObjectAORadius) else: drawText(10, 380, "Select objects: Lamp, Camera, Mesh or Empty.") ### GUI Drawing def drawGUI(): if(g("vray_gui_screen") == 0): panelRender() elif(g("vray_gui_screen") == 1): panelSampler() elif(g("vray_gui_screen") == 2): panelGI() elif(g("vray_gui_screen") == 3): panelCM() elif(g("vray_gui_screen") == 4): panelDispCaust() elif(g("vray_gui_screen") == 5): panelSystem() elif(g("vray_gui_screen") == 6): panelObject() else: s("vray_gui_screen", 0) panelRender() ### Button events def buttonEvt(evt): if not evt == evtNone: if evt == evtRedraw: Draw.Redraw() else: getFilenames() if(evt == evtExportG): writeGeometry() elif(evt == evtExportN): writeNodes() elif(evt == evtExportM): writeMaterials() elif(evt == evtExportL): writeLights() elif(evt == evtExportC): writeCamera() elif(evt == evtRun): writeSettings() render() if(evt == evtFlipResol): w= scene.getRenderingContext().sizeX scene.getRenderingContext().sizeX= scene.getRenderingContext().sizeY scene.getRenderingContext().sizeY= w Window.RedrawAll() elif(evt == evtRender): debug("Version %s"%(vrayblender_version)) if g("vray_export_bake"): if len(Blender.Object.GetSelected()) == 1: writeScene() render() elif(scene.objects.camera): writeScene() render() else: print "V-Ray/Blender: Error! No camera in the scene!" debug("Done.\n") ### Keyboard and mouse events def keyEvt(evt, val): # if g("vray_hotkeys"): # if evt == Draw.ONEKEY: # s("vray_gui_screen", 0) # if evt == Draw.TWOKEY: # s("vray_gui_screen", 1) # if evt == Draw.THREEKEY: # s("vray_gui_screen", 2) # if evt == Draw.FOURKEY: # s("vray_gui_screen", 3) # if evt == Draw.FIVEKEY: # s("vray_gui_screen", 4) # if evt == Draw.SIXKEY: # s("vray_gui_screen", 6) # if evt == Draw.SEVENKEY: # s("vray_gui_screen", 5) # Draw.Redraw() if evt == Draw.QKEY: Draw.Exit() return Draw.Register(drawGUI, keyEvt, buttonEvt)