/*
This Script is free of charge. I just hope it will help your pipleline in the way it helps us. You can modify it, but please let me know and share your code. So we can improve it further
This Script cannot be resold in anyway.
General notes:
Use the same BRDF model on all the shaders you're working on. Recommended: WARD
Camera based maps won't work (example - fallof)
This script will bake complex VRayBlend shaders down to Single VRayMtl, but reflections, glossiness etc will be averaged and result may be different than original.
CHANGELOG:
VRaymtl Baking script v0.05:
Fixed: Custom path now is correctly assigned. Before it rendered to wrong directory.
Fixed: Cancelling fixed. Now you can execute script 2 times in a row.
VRaymtl Baking script v0.04:
Added: After each segment of baking Cancel popup appears and user has 3 seconds to cancel execution.
Fixed: Checking for existing channel.
VRaymtl Baking script v0.03:
Added: Option to convert exr to jpg after rendering.
Added: Option to select baking preset. After rendering is finished, script reloads previous settings.
VRaymtl Baking script v0.02:
Added: "Select object for baking" popup if nothing is selected.
Added: "Mapping channel doesn't exist" popup if UV doesn't exist.
Changed: Better looking UI
Added: option to changed UV channel
Added: option to change padding size
Added: Script now saves current settings and loads preset from G:\GFX\VRay_preset\backing_basic_preset.rps after render is finished it loads back the previous settings.
Bug: Bump normal now correctly set to 100
Bug: Script now doesn't assign maps that weren't baked
Added: Ability to switch off all buttons with right click
Added: Opacity Map baking
Added: Button for switching of creating VRayMtl
--------- Original version created by Tomasz Wyszolmirski (studio Dabarti). Email: tomek@dabarti.com dabarti.com twitter:@wyszolmirski ------------
*/
macroScript VRayMapsBaking category:"Dabarti" toolTip:"V-ray maps baking tool." ButtonText:"V-ray maps baking tool." (
--MODIFY here with default paths to baking preset and 64 bit DJV converter
global
baking_preset = "Path to baking preset"
converter_path = "djv_convert.exe"
cancelled = false
fn Convert_Bake_IOR_material material = (
if (material!=undefined) do (
for i=1 to (getNumSubMtls material) do (
Convert_Bake_IOR_material (getSubMtl material i)
)
if ((classof material)==VRayMtl) do (
if (material.reflection_fresnel == false) then (
ior = VRayColor()
ior.blue = ior.red = ior.green = 0
material.texmap_diffuse = ior
) else (
if (material.reflection_lockIOR == true) then
( ior = VRayColor()
ior.blue = ior.red = ior.green = 1/material.refraction_ior
material.texmap_diffuse = ior
) else (
ior = VRayColor()
ior.blue = ior.red = ior.green = 1/material.reflection_ior
material.texmap_diffuse = ior
)
/*if (material.reflection_fresnel == false) then (
material.diffuse = color 0 0 0
) else (
if (material.reflection_lockIOR == true) then
( ior = (1.0 / material.refraction_ior)*255
ior = ior as float
material.diffuse = color ior ior ior
) else (
ior = (1.0 / material.reflection_ior)*255
ior = ior as float
material.diffuse = color ior ior ior
)*/
)
if material.texmap_reflectionIOR != undefined do (
material.texmap_diffuse = material.texmap_reflectionIOR
material.texmap_diffuse_multiplier = material.texmap_reflectionIOR_multiplier
)
material.reflection = color 0 0 0
material.refraction = color 0 0 0
material.texmap_diffuse_on = true
material.texmap_bump_on = false
material.option_traceReflection = false
material.option_traceRefraction = false
material.texmap_reflection_on = false
material.texmap_reflectionGlossiness_on = false
material.texmap_refractionGlossiness_on = false
material.texmap_refractionIOR_on = false
material.texmap_displacement_on = false
material.texmap_translucent_on = false
material.texmap_environment_on = false
material.texmap_hilightGlossiness_on = false
material.texmap_reflectionIOR_on = false
material.texmap_opacity_on = false
material.texmap_roughness_on = false
material.texmap_anisotropy_on = false
)
)
)
fn Convert_Bake_IOR_node node =(
if isValidNode node then (
Convert_Bake_IOR_material node.material
) else (
for i=1 to node.children.count do (
Convert_Bake_IOR_node node.children[i]
)
)
)
fn Convert_Bake_reflect_material material = (
if (material!=undefined) do (
for i=1 to (getNumSubMtls material) do (
Convert_Bake_reflect_material (getSubMtl material i)
)
if ((classof material)==VRayMtl) do (
material.diffuse = material.reflection
material.texmap_diffuse = material.texmap_reflection
material.texmap_diffuse_on = true
material.texmap_diffuse_multiplier = material.texmap_reflection_multiplier
material.texmap_bump_on = false
material.option_traceReflection = false
material.option_traceRefraction = false
material.texmap_reflection_on = false
material.texmap_reflectionGlossiness_on = false
material.texmap_refractionGlossiness_on = false
material.texmap_refractionIOR_on = false
material.texmap_displacement_on = false
material.texmap_translucent_on = false
material.texmap_environment_on = false
material.texmap_hilightGlossiness_on = false
material.texmap_reflectionIOR_on = false
material.texmap_opacity_on = false
material.texmap_roughness_on = false
material.texmap_anisotropy_on = false
)
)
)
fn Convert_Bake_reflect_node node =(
if isValidNode node then (
Convert_Bake_reflect_material node.material
) else (
for i=1 to node.children.count do (
Convert_Bake_reflect_node node.children[i]
)
)
)
fn Convert_Bake_refract_material material = (
if (material!=undefined) do (
for i=1 to (getNumSubMtls material) do (
Convert_Bake_refract_material (getSubMtl material i)
)
if ((classof material)==VRayMtl) do (
material.diffuse = material.refraction
material.texmap_diffuse = material.texmap_refraction
material.texmap_diffuse_on = material.texmap_refraction_on
material.texmap_diffuse_multiplier = material.texmap_refraction_multiplier
material.texmap_bump_on = false
material.option_traceReflection = false
material.option_traceRefraction = false
material.texmap_reflection_on = false
material.texmap_reflectionGlossiness_on = false
material.texmap_refractionGlossiness_on = false
material.texmap_refractionIOR_on = false
material.texmap_displacement_on = false
material.texmap_translucent_on = false
material.texmap_environment_on = false
material.texmap_hilightGlossiness_on = false
material.texmap_reflectionIOR_on = false
material.texmap_opacity_on = false
material.texmap_roughness_on = false
material.texmap_anisotropy_on = false
)
)
)
fn Convert_Bake_refract_node node =(
if isValidNode node then (
Convert_Bake_refract_material node.material
) else (
for i=1 to node.children.count do (
Convert_Bake_refract_node node.children[i]
)
)
)
fn Convert_Bake_diffuse_material material = (
if (material!=undefined) do (
for i=1 to (getNumSubMtls material) do (
Convert_Bake_diffuse_material (getSubMtl material i)
)
if ((classof material)==VRayMtl) do (
material.texmap_bump_on = false
material.option_traceReflection = false
material.option_traceRefraction = false
material.texmap_reflection_on = false
material.texmap_reflectionGlossiness_on = false
material.texmap_refractionGlossiness_on = false
material.texmap_refractionIOR_on = false
material.texmap_displacement_on = false
material.texmap_translucent_on = false
material.texmap_environment_on = false
material.texmap_hilightGlossiness_on = false
material.texmap_reflectionIOR_on = false
material.texmap_opacity_on = false
material.texmap_roughness_on = false
material.texmap_anisotropy_on = false
)
)
)
fn Convert_Bake_diffuse_node node =(
if isValidNode node then (
Convert_Bake_diffuse_material node.material
) else (
for i=1 to node.children.count do (
Convert_Bake_diffuse_node node.children[i]
)
)
)
fn Convert_Bake_opacity_material material = (
if (material!=undefined) do (
for i=1 to (getNumSubMtls material) do (
Convert_Bake_opacity_material (getSubMtl material i)
)
if ((classof material)==VRayMtl) do (
material.diffuse = color 255 255 255
material.texmap_diffuse = material.texmap_opacity
material.texmap_diffuse_on = true
material.texmap_diffuse_multiplier = material.texmap_opacity_multiplier
material.texmap_bump_on = false
material.option_traceReflection = false
material.option_traceRefraction = false
material.texmap_reflection_on = false
material.texmap_reflectionGlossiness_on = false
material.texmap_refractionGlossiness_on = false
material.texmap_refractionIOR_on = false
material.texmap_displacement_on = false
material.texmap_translucent_on = false
material.texmap_environment_on = false
material.texmap_hilightGlossiness_on = false
material.texmap_reflectionIOR_on = false
material.texmap_opacity_on = false
material.texmap_roughness_on = false
material.texmap_anisotropy_on = false
)
)
)
fn Convert_Bake_opacity_node node =(
if isValidNode node then (
Convert_Bake_opacity_material node.material
) else (
for i=1 to node.children.count do (
Convert_Bake_opacity_node node.children[i]
)
)
)
rollout Cancel_Rollout "Cancel?" width: 200 height: 50 (
timer clock "testClock" interval:1000
label test "3"
button btn_cancel_please "YES" pos:[10,20] width:180 height:20
on clock tick do
(
time_left = (test.text as integer) - 1
test.text = (time_left as string)
if time_left == 0 do DestroyDialog Cancel_Rollout
)
on btn_cancel_please pressed do (
cancelled = true
DestroyDialog Cancel_Rollout
)
)
rollout Bake_VRay_Textures_Rollout "V-ray maps baking tool." width: 400 height: 500 (
label lbl1 "DABARTI'S VRAY MAPS BAKING TOOL" pos:[24,8] width:200 height:16
groupBox grp2 "TEXTURE BAKING OPTIONS" pos:[4,25] width:390 height:210
label label_message "Baked textures location.:" pos:[24,48] width:200 height:16
edittext bake_path width:320 text:maxFilePath pos:[20,68] height:20
button btn_path "..." pos:[345,68] width:30 height:20
label label_fileformat "File Format:" pos:[24,108] width:200 height:16
dropdownlist drop_fileformat items:#("exr", "jpg", "tga", "png") selection:1 pos:[84,105] width:50 height:16
label label_textureresolution "Texture resolution:" width:200 height:13 pos:[154,108] width:50 height:16
dropdownlist drop_textures items:#("256x256", "512x512", "1024x1024", "2048x2048", "4096x4096", "8192x8192", "16384x16384") selection:4 pos:[254,105] width:120 height:16
label label_mapchannel "UVW Channel:" width:200 height:13 pos:[24,138] width:50 height:16
edittext text_bake_channel pos:[94,135] width:50 height:16 text:"10"
label label_padding_size "Padding size in pixels:" width:130 height:13 pos:[224,138] width:50 height:16
edittext text_padding pos:[334,135] width:40 height:16 text:"4"
checkbutton check_Bake_normal_bump "NORMAL BUMP" checked:true pos:[20,165] width:120 height:20
checkbutton check_Bake_refl_gloss "REFLECTION GLOSS" checked:true pos:[140,165] width:120 height:20
checkbutton check_Bake_refr_gloss "REFRACTION GLOSS" checked:true pos:[260,165] width:120 height:20
checkbutton check_Bake_self_ill "SELF ILLUMINATION" checked:true pos:[20,185] width:120 height:20
checkbutton check_Bake_Diffuse "DIFFUSE" checked:true pos:[140,185] width:120 height:20
checkbutton check_Bake_IOR "FRESNEL IOR" checked:true pos:[260,185] width:120 height:20
checkbutton check_Bake_Refl "REFLECTION" checked:true pos:[20,205] width:120 height:20
checkbutton check_Bake_Refr "REFRACTION" checked:true pos:[140,205] width:120 height:20
checkbutton check_Bake_opac "OPACITY" checked:true pos:[260,205] width:120 height:20
label label_baking_prset "Baking Preset:" pos:[24,242] width:200 height:16
edittext preset_path width:320 text:baking_preset pos:[20,258] height:20
button btn_preset_path "..." pos:[345,258] width:30 height:20
label label_convert_exr "Converter Path:" pos:[24,282] width:200 height:16
edittext djv_path width:320 text:converter_path pos:[20,298] height:20
button btn_djv_path "..." pos:[345,298] width:30 height:20
checkbutton check_convertexrtojpg "Convert to JPG" checked:false pos:[20,325] width:120 height:20
checkbutton check_load_preset "Load Preset" checked:false pos:[140,325] width:120 height:20
checkbutton check_novraymtl "CREATE VRMTL" checked:true pos:[260,325] width:120 height:20
button btn_bake "BAKE!!!" pos:[260,445] width:120 height:20
on drop_textures selected status do (
text_padding.text=case drop_textures.selection of (
1: "2"
2: "2"
3: "2"
4: "4"
5: "8"
6: "16"
7: "32"
)
)
on btn_path pressed do (
local baking_path = getSavePath caption:"Select Folder" initialDir:maxFilePath
if (baking_path!=undefined) do (
bake_path.text=baking_path + "\\"
)
)
on btn_preset_path pressed do (
local preset_path_new = getOpenFileName caption:"Select Preset file:" filename:baking_preset
if (preset_path_new!=undefined) do (
preset_path.text = preset_path_new
baking_preset = preset_path.text
)
)
on btn_djv_path pressed do (
local djv_path_new = getOpenFileName caption:"Select path to djv_converter.exe:" filename:converter_path
if (djv_path_new!=undefined) do (
djv_path.text = djv_path_new
converter_path = djv_path.text
)
)
-- Right click functionality to switch off all
on check_Bake_normal_bump rightclick do ( check_Bake_refl_gloss.checked = check_Bake_refr_gloss.checked = check_Bake_self_ill.checked = check_Bake_normal_bump.checked = check_Bake_Diffuse.checked = check_Bake_IOR.checked = check_Bake_Refl.checked = check_Bake_Refr.checked = check_Bake_opac.checked = false)
on check_Bake_refl_gloss rightclick do ( check_Bake_refl_gloss.checked = check_Bake_refr_gloss.checked = check_Bake_self_ill.checked = check_Bake_normal_bump.checked = check_Bake_Diffuse.checked = check_Bake_IOR.checked = check_Bake_Refl.checked = check_Bake_Refr.checked = check_Bake_opac.checked = false)
on check_Bake_refr_gloss rightclick do ( check_Bake_refl_gloss.checked = check_Bake_refr_gloss.checked = check_Bake_self_ill.checked = check_Bake_normal_bump.checked = check_Bake_Diffuse.checked = check_Bake_IOR.checked = check_Bake_Refl.checked = check_Bake_Refr.checked = check_Bake_opac.checked = false)
on check_Bake_self_ill rightclick do ( check_Bake_refl_gloss.checked = check_Bake_refr_gloss.checked = check_Bake_self_ill.checked = check_Bake_normal_bump.checked = check_Bake_Diffuse.checked = check_Bake_IOR.checked = check_Bake_Refl.checked = check_Bake_Refr.checked = check_Bake_opac.checked = false)
on check_Bake_Diffuse rightclick do ( check_Bake_refl_gloss.checked = check_Bake_refr_gloss.checked = check_Bake_self_ill.checked = check_Bake_normal_bump.checked = check_Bake_Diffuse.checked = check_Bake_IOR.checked = check_Bake_Refl.checked = check_Bake_Refr.checked = check_Bake_opac.checked = false)
on check_Bake_IOR rightclick do ( check_Bake_refl_gloss.checked = check_Bake_refr_gloss.checked = check_Bake_self_ill.checked = check_Bake_normal_bump.checked = check_Bake_Diffuse.checked = check_Bake_IOR.checked = check_Bake_Refl.checked = check_Bake_Refr.checked = check_Bake_opac.checked = false)
on check_Bake_Refl rightclick do ( check_Bake_refl_gloss.checked = check_Bake_refr_gloss.checked = check_Bake_self_ill.checked = check_Bake_normal_bump.checked = check_Bake_Diffuse.checked = check_Bake_IOR.checked = check_Bake_Refl.checked = check_Bake_Refr.checked = check_Bake_opac.checked = false)
on check_Bake_Refr rightclick do ( check_Bake_refl_gloss.checked = check_Bake_refr_gloss.checked = check_Bake_self_ill.checked = check_Bake_normal_bump.checked = check_Bake_Diffuse.checked = check_Bake_IOR.checked = check_Bake_Refl.checked = check_Bake_Refr.checked = check_Bake_opac.checked = false)
on btn_bake pressed do (
file_format=case drop_fileformat.selection of (
1: "exr"
2: "jpg"
3: "tga"
4: "png"
)
file_resolution=case drop_textures.selection of (
1: 256
2: 512
3: 1024
4: 2048
5: 4096
6: 8192
7: 16384
)
if selection[1] == undefined then ( messagebox "Select object for baking." ) else (
obj = selection[1]
if (classof obj == Editable_Mesh) then (
if ( (meshop.getMapSupport obj (text_bake_channel.text as integer)) == false ) do (
messagebox "Mapping channel doesn't exist."
cancelled = true
)
) else (
if ( (polyop.getMapSupport obj (text_bake_channel.text as integer)) == false ) do (
messagebox "Mapping channel doesn't exist."
cancelled = true
)
)
if (NOT cancelled) do (
if (check_load_preset.checked == true) do (
renderpresets.SaveAll 0 (maxfilepath+"render_preset_backup")
renderpresets.LoadAll 0 (baking_preset)
)
if ((check_Bake_normal_bump.checked == true) or (check_Bake_refl_gloss.checked == true) or (check_Bake_refr_gloss.checked == true) or (check_Bake_self_ill.checked == true)) do (
obj.iNodeBakeProperties.removeAllBakeElements()
/*be_diff_texture = VRayDiffuseFilterMap()
be_diff_texture.outputSzX = be_diff_texture.outputSzY = file_resolution
be_diff_texture.fileType = (bake_path.text + obj.name + "_Diffuse." + file_format)
be_diff_texture.fileName = filenameFromPath be_diff_texture.fileType
be_diff_texture.enabled = true*/
--obj.INodeBakeProperties.addBakeElement be_SelfIll_texture
if (check_Bake_normal_bump.checked == true) do (
be_NorBum_texture = VRayBumpNormalsMap()
be_NorBum_texture.outputSzX = be_NorBum_texture.outputSzY = file_resolution
be_NorBum_texture.fileType = (bake_path.text + obj.name + "_Normal_Bump." + file_format)
be_NorBum_texture.fileName = filenameFromPath be_NorBum_texture.fileType
be_NorBum_texture.enabled = true
obj.INodeBakeProperties.addBakeElement be_NorBum_texture
)
if (check_Bake_refl_gloss.checked == true) do (
be_ReflGloss_texture = VRayMtlReflectGlossinessBake()
be_ReflGloss_texture.outputSzX = be_ReflGloss_texture.outputSzY = file_resolution
be_ReflGloss_texture.fileType = (bake_path.text + obj.name + "_Refl_Gloss." + file_format)
be_ReflGloss_texture.fileName = filenameFromPath be_ReflGloss_texture.fileType
be_ReflGloss_texture.enabled = true
obj.INodeBakeProperties.addBakeElement be_ReflGloss_texture
)
if (check_Bake_refr_gloss.checked == true) do (
be_RefrGloss_texture = VRayMtlRefractGlossinessBake()
be_RefrGloss_texture.outputSzX = be_RefrGloss_texture.outputSzY = file_resolution
be_RefrGloss_texture.fileType = (bake_path.text + obj.name + "_Refr_Gloss." + file_format)
be_RefrGloss_texture.fileName = filenameFromPath be_RefrGloss_texture.fileType
be_RefrGloss_texture.enabled = true
obj.INodeBakeProperties.addBakeElement be_RefrGloss_texture
)
if (check_Bake_self_ill.checked == true) do (
be_SelfIll_texture = VRaySelfIlluminationMap()
be_SelfIll_texture.outputSzX = be_SelfIll_texture.outputSzY = file_resolution
be_SelfIll_texture.fileType = (bake_path.text + obj.name + "_Self_Illum." + file_format)
be_SelfIll_texture.fileName = filenameFromPath be_SelfIll_texture.fileType
be_SelfIll_texture.enabled = true
)
obj.INodeBakeProperties.bakeEnabled = true
obj.INodeBakeProperties.bakeChannel = text_bake_channel.text as integer
obj.INodeBakeProperties.nDilations = text_padding.text as integer
render rendertype:#bakeSelected vfb:off progressBar:false outputSize:[file_resolution,file_resolution]
)
if (NOT cancelled) do CreateDialog Cancel_Rollout modal:true
if (check_Bake_Diffuse.checked == true) and (NOT cancelled) do (
obj2 = copy obj
obj2.material = copy obj.material
Convert_Bake_diffuse_node obj2
select obj2
obj2.iNodeBakeProperties.removeAllBakeElements()
be_diff_texture = VRayDiffuseFilterMap()
be_diff_texture.outputSzX = be_diff_texture.outputSzY = file_resolution
be_diff_texture.fileType = (bake_path.text + obj.name + "_Diffuse." + file_format)
be_diff_texture.fileName = filenameFromPath be_diff_texture.fileType
be_diff_texture.enabled = true
obj2.INodeBakeProperties.addBakeElement be_diff_texture
obj2.INodeBakeProperties.bakeEnabled = true
obj2.INodeBakeProperties.bakeChannel = text_bake_channel.text as integer
obj2.INodeBakeProperties.nDilations = text_padding.text as integer
render rendertype:#bakeSelected vfb:off progressBar:false outputSize:[file_resolution,file_resolution]
delete obj2
select obj
)
if (NOT cancelled) do CreateDialog Cancel_Rollout modal:true
if (check_Bake_IOR.checked == true) and (NOT cancelled) do (
obj2 = copy obj
obj2.material = copy obj.material
Convert_Bake_IOR_node obj2
select obj2
obj2.iNodeBakeProperties.removeAllBakeElements()
be_IOR_texture = VRayDiffuseFilterMap()
be_IOR_texture.outputSzX = be_IOR_texture.outputSzY = file_resolution
be_IOR_texture.fileType = (bake_path.text + obj.name + "_reflectIOR." + file_format)
be_IOR_texture.fileName = filenameFromPath be_IOR_texture.fileType
be_IOR_texture.enabled = true
obj2.INodeBakeProperties.addBakeElement be_IOR_texture
obj2.INodeBakeProperties.bakeEnabled = true
obj2.INodeBakeProperties.bakeChannel = text_bake_channel.text as integer
obj2.INodeBakeProperties.nDilations = text_padding.text as integer
render rendertype:#bakeSelected vfb:off progressBar:false outputSize:[file_resolution,file_resolution]
delete obj2
select obj
)
if (NOT cancelled) do CreateDialog Cancel_Rollout modal:true
if (check_Bake_Refl.checked == true) and (NOT cancelled) do (
obj2 = copy obj
obj2.material = copy obj.material
Convert_Bake_reflect_node obj2
select obj2
obj2.iNodeBakeProperties.removeAllBakeElements()
be_reflect_texture = VRayDiffuseFilterMap()
be_reflect_texture.outputSzX = be_reflect_texture.outputSzY = file_resolution
be_reflect_texture.fileType = (bake_path.text + obj.name + "_reflect." + file_format)
be_reflect_texture.fileName = filenameFromPath be_reflect_texture.fileType
be_reflect_texture.enabled = true
obj2.INodeBakeProperties.addBakeElement be_reflect_texture
obj2.INodeBakeProperties.bakeEnabled = true
obj2.INodeBakeProperties.bakeChannel = text_bake_channel.text as integer
obj2.INodeBakeProperties.nDilations = text_padding.text as integer
render rendertype:#bakeSelected vfb:off progressBar:false outputSize:[file_resolution,file_resolution]
delete obj2
select obj
)
if (NOT cancelled) do CreateDialog Cancel_Rollout modal:true
if (check_Bake_Refr.checked == true) and (NOT cancelled) do (
obj2 = copy obj
obj2.material = copy obj.material
Convert_Bake_refract_node obj2
select obj2
obj2.iNodeBakeProperties.removeAllBakeElements()
be_refract_texture = VRayDiffuseFilterMap()
be_refract_texture.outputSzX = be_refract_texture.outputSzY = file_resolution
be_refract_texture.fileType = (bake_path.text + obj.name + "_refract." + file_format)
be_refract_texture.fileName = filenameFromPath be_refract_texture.fileType
be_refract_texture.enabled = true
obj2.INodeBakeProperties.addBakeElement be_refract_texture
obj2.INodeBakeProperties.bakeEnabled = true
obj2.INodeBakeProperties.bakeChannel = text_bake_channel.text as integer
obj2.INodeBakeProperties.nDilations = text_padding.text as integer
render rendertype:#bakeSelected vfb:off progressBar:false outputSize:[file_resolution,file_resolution]
delete obj2
select obj
)
if (NOT cancelled) do CreateDialog Cancel_Rollout modal:true
if ((check_Bake_opac.checked) == true) and (NOT cancelled) do (
obj2 = copy obj
obj2.material = copy obj.material
Convert_Bake_opacity_node obj2
select obj2
obj2.iNodeBakeProperties.removeAllBakeElements()
be_opacity_texture = VRayDiffuseFilterMap()
be_opacity_texture.outputSzX = be_opacity_texture.outputSzY = file_resolution
be_opacity_texture.fileType = (bake_path.text + obj.name + "_opacity." + file_format)
be_opacity_texture.fileName = filenameFromPath be_opacity_texture.fileType
be_opacity_texture.enabled = true
obj2.INodeBakeProperties.addBakeElement be_opacity_texture
obj2.INodeBakeProperties.bakeEnabled = true
obj2.INodeBakeProperties.bakeChannel = text_bake_channel.text as integer
obj2.INodeBakeProperties.nDilations = text_padding.text as integer
render rendertype:#bakeSelected vfb:off progressBar:false outputSize:[file_resolution,file_resolution]
delete obj2
select obj
)
if (NOT cancelled) do CreateDialog Cancel_Rollout modal:true
if (check_convertexrtojpg.checked == true) and (NOT cancelled) do (
if check_Bake_Diffuse.checked == true do (
doscommand(converter_path+" "+(bake_path.text + obj.name + "_Diffuse." + file_format)+" "+(bake_path.text + obj.name + "_Diffuse.jpg -pixel rgb u16") )
)
if check_Bake_Refl.checked == true do (
doscommand(converter_path+" "+(bake_path.text + obj.name + "_reflect." + file_format)+" "+(bake_path.text + obj.name + "_reflect.jpg -pixel rgb u16") )
)
if check_Bake_Refr.checked == true do (
doscommand(converter_path+" "+(bake_path.text + obj.name + "_refract." + file_format)+" "+(bake_path.text + obj.name + "_refract.jpg -pixel rgb u16") )
)
if (check_Bake_refl_gloss.checked == true) do (
doscommand(converter_path+" "+(bake_path.text + obj.name + "_Refl_Gloss." + file_format)+" "+(bake_path.text + obj.name + "_Refl_Gloss.jpg -pixel rgb u16") )
)
if (check_Bake_refr_gloss.checked == true) do (
doscommand(converter_path+" "+(bake_path.text + obj.name + "_Refr_Gloss." + file_format)+" "+(bake_path.text + obj.name + "_Refr_Gloss.jpg -pixel rgb u16") )
)
if check_Bake_IOR.checked == true do (
doscommand(converter_path+" "+(bake_path.text + obj.name + "_reflectIOR." + file_format)+" "+(bake_path.text + obj.name + "_reflectIOR.jpg -pixel rgb u16") )
)
if (check_Bake_normal_bump.checked == true) do (
doscommand(converter_path+" "+(bake_path.text + obj.name + "_Normal_Bump." + file_format)+" "+(bake_path.text + obj.name + "_Normal_Bump.jpg -pixel rgb u16") )
)
if (check_Bake_opac.checked == true) do (
doscommand(converter_path+" "+(bake_path.text + obj.name + "_opacity." + file_format)+" "+(bake_path.text + obj.name + "_opacity.jpg -pixel rgb u16") )
)
file_format = "jpg"
)
if (NOT cancelled) do CreateDialog Cancel_Rollout modal:true
if (check_novraymtl.checked == true) and (NOT cancelled) do (
obj2 = copy obj
obj2.name = obj.name + "_baked"
obj.material.name = obj.material.name + "_old"
new_baked_material = VRayMtl()
new_baked_material.name = obj.name
new_baked_material.reflection_lockIOR = false
new_baked_material.brdf_type = 2
if check_Bake_Diffuse.checked == true do (
new_baked_material.texmap_diffuse = bitmaptexture()
new_baked_material.texmap_diffuse.fileName = (bake_path.text + obj.name + "_Diffuse." + file_format)
)
if check_Bake_Refl.checked == true do (
new_baked_material.texmap_reflection = bitmaptexture()
new_baked_material.texmap_reflection.fileName = (bake_path.text + obj.name + "_reflect." + file_format)
)
if check_Bake_Refr.checked == true do (
new_baked_material.texmap_refraction = bitmaptexture()
new_baked_material.texmap_refraction.fileName = (bake_path.text + obj.name + "_refract." + file_format)
)
if (check_Bake_refl_gloss.checked == true) do (
new_baked_material.texmap_reflectionGlossiness = bitmaptexture()
new_baked_material.texmap_reflectionGlossiness.fileName = (bake_path.text + obj.name + "_Refl_Gloss." + file_format)
)
if (check_Bake_refr_gloss.checked == true) do (
new_baked_material.texmap_refractionGlossiness = bitmaptexture()
new_baked_material.texmap_refractionGlossiness.fileName = (bake_path.text + obj.name + "_Refr_Gloss." + file_format)
)
if check_Bake_IOR.checked == true do (
new_baked_material.texmap_reflectionIOR = bitmaptexture()
new_baked_material.texmap_reflectionIOR.fileName = (bake_path.text + obj.name + "_reflectIOR." + file_format)
)
if check_Bake_opac.checked == true do (
new_baked_material.texmap_opacity = bitmaptexture()
new_baked_material.texmap_opacity.fileName = (bake_path.text + obj.name + "_opacity." + file_format)
)
if (check_Bake_self_ill.checked == true) do (
new_baked_material.texmap_self_illumination = bitmaptexture()
new_baked_material.texmap_self_illumination.fileName = (bake_path.text + obj.name + "_Self_Illum." + file_format)
)
if (check_Bake_normal_bump.checked == true) do (
new_baked_material.texmap_bump = VRayNormalMap()
new_baked_material.texmap_bump.normal_map = bitmaptexture()
new_baked_material.texmap_bump.normal_map.fileName = (bake_path.text + obj.name + "_Normal_Bump." + file_format)
new_baked_material.texmap_bump_multiplier = 100
)
obj2.material = new_baked_material
)
if (check_load_preset.checked == true) do (
renderpresets.LoadAll 0 (maxfilepath+"render_preset_backup")
doscommand("del "+(maxfilepath+"render_preset_backup.rps"))
)
)
cancelled = false
)
)
)
CreateDialog Bake_VRay_Textures_Rollout
)