macroScript vrayStudioSetup category:"S_VRay Tools" buttonText:"VRayStudio" tooltip:"VRay Studio Setup"
(
rollout srsetup "Studio and Rendering Setup" width:300 height:420
(
	label lbl1 "Units (Millimeters)" pos:[15,15] width:95 height:15
	label lbl2 "Renderer (V-Ray)" pos:[15,35] width:95 height:15
	button btn_units "Set" pos:[200,15] width:85 height:15
	button btn_setvray "Assign" pos:[200,35] width:85 height:15
	GroupBox grp1 "Scene Setup" pos:[5,75] width:290 height:162
	label lbl3 "Base" pos:[15,95] width:45 height:15
	button btn_base "Create" pos:[225,95] width:60 height:15
	label lbl4 "Left VRayLight" pos:[15,115] width:85 height:15
	button btn_leftlg "Create" pos:[225,115] width:60 height:15
	label lbl5 "Right VRayLight" pos:[15,135] width:85 height:15
	button btn_rightlg "Create" pos:[225,135] width:60 height:15
	colorPicker cp2 "" pos:[155,115] width:50 height:15 color:(color 198 235 255)
	colorPicker cp3 "" pos:[155,135] width:50 height:15 color:(color 255 247 213)
	colorPicker cp4 "" pos:[155,155] width:50 height:15 color:(color 255 255 255)
	label lbl6 "GI Environment (skylight)" pos:[15,155] width:135 height:15
	colorPicker cp1 "" pos:[155,95] width:50 height:15 color:(color 211 211 211)
	label lbl7 "Sample Geometry (3 GeoSpheres)" pos:[15,175] width:190 height:15
	button btn_spheres "Create" pos:[225,175] width:60 height:15
	label lbl8 "Sample Geometry (Torus Knot)" pos:[15,195] width:190 height:15
	button btn_torus "Create" pos:[225,195] width:60 height:15
	label lbl9 "VRayPhysicalCamera (Active Viewport)" pos:[15,215] width:199 height:15
	button btn_camera "Create" pos:[225,215] width:60 height:15
	label lbl10 "Gamma 2.2" pos:[15,55] width:95 height:15
	button btn_gamma "Set" pos:[200,55] width:85 height:15
	GroupBox grp2 "Output Size" pos:[5,245] width:120 height:84
	checkbutton ckb_1024 "1024x768" pos:[15,265] width:100 height:15
	checkbutton ckb_800 "800x600" pos:[15,285] width:100 height:15
	checkbutton ckb_640 "640x480" pos:[15,305] width:100 height:15
	checkbox chk_framestamp "Frame Stamp" pos:[15,335] width:130 height:15 checked:false
	radiobuttons rdo1 "Rendering Presets" pos:[160,245] width:90 height:62 labels:#("Low (Test)", "Medium (Test)", "High") default:1 columns:1
	button btn_render "Render!" pos:[160,320] width:125 height:40
	
	local sorigwidth = renderWidth
	local sorigheight = renderHeight
	
	fn setRenderResolution width height =
	(
		if (renderSceneDialog.isOpen()) then 
		(
			renderSceneDialog.close()
			renderHeight = height
			renderWidth = width
			renderSceneDialog.open()	
		)			
		else 
		(
			renderHeight = height
			renderWidth = width
		)
	)
				
	fn applyRenderSettings settings =
 	(
	   for i = 1 to settings.count do
	   (
	       rString = "renderers.current." + settings[i]
		   execute rString
		)
	)
	fn CollectSettings x =
	(
		renderLow = #(
		"gi_on = true"
		,"gi_refractCaustics = true"
		,"gi_reflectCaustics = false"
		,"gi_primary_type = 0"
		,"gi_primary_multiplier = 1.0"
		,"gi_secondary_type = 2"
		,"gi_secondary_multiplier = 0.8"
		,"gi_irradmap_minRate = -3"
		,"gi_irradmap_maxRate = -2"
		,"gi_irradmap_subdivs = 25"
		,"gi_irradmap_interpSamples = 20"
		,"gi_irradmap_colorThreshold = 0.4"
		,"gi_irradmap_normalThreshold = 0.3"
		,"gi_irradmap_distThreshold = 0.1"
		,"gi_irradmap_showCalcPhase = true"
		,"adv_irradmap_calcInterpSamples = 15"
		,"dmcgi_subdivs = 8"
		,"dmcgi_depth = 3"
		,"dmc_importanceSampling = 1.0"
		,"dmc_earlyTermination_amount = 0.95"
		,"dmc_earlyTermination_threshold = 0.01"
		,"dmc_earlyTermination_minSamples = 6"
		,"dmc_subdivs_mult = 1"
		,"imageSampler_type = 1"
		,"twoLevel_baseSubdivs = 1"
		,"twoLevel_fineSubdivs = 4"
		,"twoLevel_useDMCSamplerThresh = true"
		,"filter_on = true"
		,"filter_kernel = Mitchell_Netravali()"
		,"options_defaultLights = 0"
		,"environment_gi_on = true"
		,"environment_gi_color = [255,255,255]"
		,"environment_gi_color_multiplier = 0.1"
		,"environment_rr_on = true"
		,"environment_rr_color = [0,0,0]"
		,"environment_rr_color_multiplier = 1.0"
		,"colorMapping_type = 1"
		,"colorMapping_affectBackground = true"
		,"colorMapping_clampOutput = true"
		,"colorMapping_subpixel = true"
		,"system_region_x = 64"
        ,"system_region_y =64"
		)
		renderMed = #(
		"gi_on = true"
		,"gi_refractCaustics = true"
		,"gi_reflectCaustics = false"
		,"gi_primary_type = 0"
		,"gi_primary_multiplier = 1.0"
		,"gi_secondary_type = 2"
		,"gi_secondary_multiplier = 0.8"
		,"gi_irradmap_minRate = -3"
		,"gi_irradmap_maxRate = -1"
		,"gi_irradmap_subdivs = 50"
		,"gi_irradmap_interpSamples = 20"
		,"gi_irradmap_colorThreshold = 0.4"
		,"gi_irradmap_normalThreshold = 0.2"
		,"gi_irradmap_distThreshold = 0.1"
		,"adv_irradmap_calcInterpSamples = 15"
		,"gi_irradmap_showCalcPhase = true"
		,"dmcgi_subdivs = 10"
		,"dmcgi_depth = 5"
		,"dmc_importanceSampling = 1.0"
		,"dmc_earlyTermination_amount = 0.85"
		,"dmc_earlyTermination_threshold = 0.01"
		,"dmc_earlyTermination_minSamples = 12"
		,"dmc_subdivs_mult = 1"
		,"imageSampler_type = 1"
		,"twoLevel_baseSubdivs = 1"
		,"twoLevel_fineSubdivs = 4"
		,"twoLevel_useDMCSamplerThresh = true"
		,"filter_on = true"
		,"filter_kernel = Mitchell_Netravali()"
		,"options_defaultLights = 0"
		,"environment_gi_on = true"
		,"environment_gi_color = [255,255,255]"
		,"environment_gi_color_multiplier = 0.1"
		,"environment_rr_on = true"
		,"environment_rr_color = [0,0,0]"
		,"environment_rr_color_multiplier = 1.0"
		,"colorMapping_type = 1"
		,"colorMapping_affectBackground = true"
		,"colorMapping_clampOutput = true"
		,"colorMapping_subpixel = true"
		,"system_region_x = 64"
        ,"system_region_y =64"
		)
		renderHi = #(
		"gi_on = true"
		,"gi_refractCaustics = true"
		,"gi_reflectCaustics = false"
		,"gi_primary_type = 0"
		,"gi_primary_multiplier = 1.0"
		,"gi_secondary_type = 2"
		,"gi_secondary_multiplier = 0.8"
		,"gi_irradmap_minRate = -3"
		,"gi_irradmap_maxRate = 0"
		,"gi_irradmap_subdivs = 70"
		,"gi_irradmap_interpSamples = 20"
		,"gi_irradmap_colorThreshold = 0.3"
		,"gi_irradmap_normalThreshold = 0.1"
		,"gi_irradmap_distThreshold = 0.1"
		,"adv_irradmap_calcInterpSamples = 10"
		,"gi_irradmap_showCalcPhase = true"
		,"dmcgi_subdivs = 30"
		,"dmcgi_depth = 20"
		,"dmc_importanceSampling = 1.0"
		,"dmc_earlyTermination_amount = 0.5"
		,"dmc_earlyTermination_threshold = 0.005"
		,"dmc_earlyTermination_minSamples = 14"
		,"dmc_subdivs_mult = 1.5"
		,"imageSampler_type = 1"
		,"twoLevel_baseSubdivs = 1"
		,"twoLevel_fineSubdivs = 30"
		,"twoLevel_useDMCSamplerThresh = true"
		,"filter_on = true"
		,"filter_kernel = Mitchell_Netravali()"
		,"options_defaultLights = 0"
		,"environment_gi_on = true"
		,"environment_gi_color = [255,255,255]"
		,"environment_gi_color_multiplier = 0.1"
		,"environment_rr_on = true"
		,"environment_rr_color = [0,0,0]"
		,"environment_rr_color_multiplier = 1.0"
		,"colorMapping_type = 1"
		,"colorMapping_affectBackground = true"
		,"colorMapping_clampOutput = true"
		,"colorMapping_subpixel = true"
		,"system_region_x = 64"
        ,"system_region_y =64"
		)
        
		case rdo1.state of
		(
		   1: applyRenderSettings renderLow
		   2: applyRenderSettings renderMed
		   3: applyRenderSettings renderHi
		 )  
     )

	on btn_units pressed do
	(
		units.DisplayType = #metric
		units.MetricType = #millimeters
	    units.SystemType = #millimeters
	)
	on btn_setvray pressed do
	(
		renderers.current=vray()
		renderers.current.output_on = on
		renderers.current.output_getsetsfrommax = true
	)
	on btn_base pressed do
	(
	ground = convertToPoly(Plane name:"Ground" length:1500 width:1000 lengthsegs:4 widthsegs:4 pos:[0,198,0])
	select ground
	max modify mode
	subObjectLevel = 1
	polyop.setVertSelection ground #(21,22,23,24,25)
	ground.moveToPlane [0,0,1] 527.134 #Vertex
	subObjectLevel = 0
	ground.wireColor = black
	ground.surfSubdivide = true
	ground.iterations = 1
	ground.useRenderIterations = true
	ground.useRenderSmoothness = true
	ground.renderIterations = 3
	ground.renderSmoothness = 1
	meditMaterials[1] = VrayMtl()
	meditMaterials[1].name = "Ground_mat"
	meditMaterials[1].Diffuse = cp1.color
	meditMaterials[1].Reflection = color 0 0 0
	meditMaterials[1].reflection_glossiness = 1.0
	meditMaterials[1].reflection_subdivs = 8
	meditMaterials[1].reflection_maxDepth = 5
	meditMaterials[1].brdf_type = 1
	ground.material = meditMaterials[1]
	clearSelection()
	)
	on btn_leftlg pressed do
	(
	leftLight = VRayLight()
	leftLight.name = "VrayLight_Left"
	leftLight.type = 0
	leftLight.size0 = 400
	leftLight.size1 = 350
	leftLight.color = cp2.color
	leftLight.multiplier = 40
	leftLight.invisible = on
	leftLight.subdivs = 24
	leftLight.shadowBias = 0.2
	leftLight.storeWithIrradMap = on
	leftLight.position = [-726.58,-215.395,627.33]
	rotate leftLight (angleaxis -50 [0,1,0])
	rotate leftLight (angleaxis 21 [0,0,1])
	)
	on btn_rightlg pressed do
	(
	rightLight = VRayLight()
	rightLight.name = "VRayLight_Right"
	rightLight.type = 0
	rightLight.size0 = 500
	rightLight.size1 = 360
	rightLight.color = cp3.color
	rightLight.multiplier = 60
	rightLight.invisible = on
	rightLight.subdivs = 24
	rightLight.shadowBias = 0.2
	rightLight.storeWithIrradMap = on
	rightLight.position = [752.309,53.182,477.891]
	rotate rightLight (angleaxis 65 [0,1,0])	
	)
	on btn_spheres pressed do
	(
	GSph01 = GeoSphere radius:35 segs:12 baseType:2 pos:[0.942,59.121,35.02] name:"GSph01"
	GSph02 = GeoSphere radius:35 segs:12 baseType:2 pos:[-38.312,-8.083,35.02] name:"GSph02"
	GSph03 = GeoSphere radius:35 segs:12 baseType:2 pos:[40.343,-8.083,35.02] name:"GSph03"
	GSph01.backfacecull = on
	GSph02.backfacecull = on
	GSph03.backfacecull = on
	meditMaterials[2] = VrayMtl()
	meditMaterials[2].name = "White_mat"
	meditMaterials[2].Diffuse = color 250 250 250
	meditMaterials[2].Reflection = color 0 0 0
	meditMaterials[2].reflection_glossiness = 1.0
	meditMaterials[2].reflection_subdivs = 8
	meditMaterials[2].reflection_maxDepth = 5
	meditMaterials[2].brdf_type = 1
	GSph01.material = meditMaterials[2]
	meditMaterials[3] = VrayMtl()
	meditMaterials[3].name = "Blue_mat"
	meditMaterials[3].Diffuse = color 9 1 120
	meditMaterials[3].Reflection = color 133 133 133
	meditMaterials[3].reflection_glossiness = 1.0
	meditMaterials[3].reflection_fresnel = on
	meditMaterials[3].reflection_lockIOR = off
	meditMaterials[3].reflection_IOR = 2
	meditMaterials[3].reflection_subdivs = 8
	meditMaterials[3].reflection_maxDepth = 7
	meditMaterials[3].brdf_type = 1
	GSph02.material = meditMaterials[3]
	meditMaterials[4] = VrayMtl()
	meditMaterials[4].name = "Chrome_mat"
	meditMaterials[4].Diffuse = color 0 0 0
	meditMaterials[4].Reflection = color 225 225 225
	meditMaterials[4].reflection_glossiness = 1.0
	meditMaterials[4].reflection_fresnel = on
	meditMaterials[4].reflection_lockIOR = off
	meditMaterials[4].reflection_IOR = 16
	meditMaterials[4].reflection_subdivs = 8
	meditMaterials[4].reflection_maxDepth = 7
	meditMaterials[4].brdf_type = 1
	GSph03.material = meditMaterials[4]	
	)
	on btn_torus pressed do
	(
	Torus01 = Torus_Knot base_curve:0 radius:27.441 segments:240 p:1.5 q:3.0 radius2:3.167 sides:38 eccentricity:1.0 twist:0.0 lumps:6.0 lump_height:4.0 lump_offset:15.0 smooth:2 pos:[0.0,0.0,33.914]
	meditMaterials[5] = VrayMtl()
	meditMaterials[5].name = "Torus_mat"
	meditMaterials[5].Diffuse = color 204 3 3
	meditMaterials[5].Reflection = color 133 133 133
	meditMaterials[5].reflection_glossiness = 1.0
	meditMaterials[5].reflection_subdivs = 8
	meditMaterials[5].reflection_fresnel = on
	meditMaterials[5].reflection_lockIOR = off
	meditMaterials[5].reflection_IOR = 2
	meditMaterials[5].reflection_maxDepth = 7
	meditMaterials[5].brdf_type = 1
	Torus01.material = meditMaterials[5]
	)
	on btn_camera pressed do
	(
	cam01 = vrayphysicalcamera name:"Camera_Common01" nearclip:1 farclip:1000 nearrange:0 farrange:1000 transform:(matrix3 [0,1,0] [0,0,1] [1,0,0] [0,-347.291,213.576]) isSelected:off target:(Targetobject transform:(matrix3 [1,0,0] [0,1,0] [0,0,1] [0,15.219,29.225]))
	cam01.focal_length = 51.0
	cam01.targetDistance = 407.083
	cam01.f_number = 3.0
	cam01.vignetting = off
	cam01.whiteBalance_preset = 1
	cam01.shutter_speed = 250.0
	cam01.ISO = 200.0
	viewport.setCamera cam01
	viewport.setShowEdgeFaces true
	displaySafeFrames = true
	)
	on btn_gamma pressed do
	(
		IDisplayGamma.colorCorrectionMode = #gamma 
	    IDisplayGamma.gamma = 2.2
		fileInGamma = 2.2
		fileOutGamma = 1.0
		renderers.current.colorMapping_gamma = 2.2
	)
	on ckb_1024 changed state do
	(
		    	if state == on then 
		
				(
					ckb_800.state = off
					ckb_640.state = off
					setRenderResolution 1024 768			
				)
				if state == off then
				(
					setRenderResolution sorigwidth sorigheight 
				)
			)
	on ckb_800 changed state do
	(
		    	if state == on then 
		
				(
					ckb_1024.state = off
					ckb_640.state = off
					setRenderResolution 800 600			
				)
				if state == off then
				(
					setRenderResolution sorigwidth sorigheight 
				)
			)
	on ckb_640 changed state do
	(
		    	if state == on then 
		
				(
					ckb_1024.state = off
					ckb_800.state = off
					setRenderResolution 640 480			
				)
				if state == off then
				(
					setRenderResolution sorigwidth sorigheight 
				)
			)
	on chk_framestamp changed state do
	(
	renderers.current.system_frameStamp_on = state
	)
	on btn_render pressed do
	(
	 CollectSettings 0
	 max quick render
	)
)
rollout aboutme "About" width:300 height:77
(
	label lbl1 "VRayStudioSetup v0.5" pos:[94,5] width:120 height:16
	label lbl3 "Created by Regimantas Valiukas" pos:[70,20] width:160 height:16
	label lbl10 "© 2009" pos:[127,35] width:39 height:15
	HyperLink homepage "www.siger.lt" pos:[118,45] width:65 height:15 address:"http://www.siger.lt" color:(color 255 153 51) hovercolor:(color 255 153 51) visitedcolor:(color 255 153 51)
)
r_studio = newrolloutfloater "VRayStudioSetup 0.5" 315 490
addRollout srsetup r_studio rolledUp:false
addRollout aboutme r_studio rolledUp:false
)