--金属Metal
--玻璃Glass
--镜子Mirror
--家具Paint
--布料Cloth
global _bool_A=false
global _bool_B=false
global _bool_C=false
global _bool_D=false
global _bool_E=false
global _bool_F=false
rollout SongYangTool "虚拟现实工具 v1.8 享视文化传播" width:300 height:150
(
button btn1 "执行代码" pos:[205,110] width:80 height:20
button btn2 "整理模型" pos:[10,120] width:60 height:20
button btn3 "快速选择" pos:[90,120] width:60 height:20
editText edt1 "物体前缀:" pos:[13,10] width:200 height:20 text:""
editText edt2 "保存路径:" pos:[13,35] width:250 height:20 text:""
checkbox chk_jianmian "复制材质" pos:[12,65] width:80 height:15 checked:false
checkbox chk_fenUV "分UV" pos:[98,65] width:80 height:15 checked:false
checkbox chk_hongpei "烘焙" pos:[12,90] width:80 height:15 checked:false
checkbox chk_hongpeiA "烘焙/16" pos:[180,65] width:80 height:15 checked:false
checkbox chk_caizhiqiu "创建材质球" pos:[98,90] width:92 height:15 checked:false
checkbox chk_Ao "Ao" pos:[180,90] width:92 height:15 checked:false
label lbl1 "V1.7 2013.08.07 " pos:[205,135] width:108 height:22
on SongYangTool open do
(
)
on SongYangTool close do
(
)
on SongYangTool okToClose do
(
)
on SongYangTool resized size do
(
)
on SongYangTool moved pos do
(
)
on btn1 pressed do(
_text=edt1.text
_object=execute ("$"+_text+"*")
_count=execute ("$"+_text+"*"+".count")
if _count >0 then(
--批量赋予材质球
if _bool_A then(
for b in _object do(
_name="_"+b.name
if (getnodebyname _name)!=undefined then(
_nameA=getnodebyname _name
_nameA.material=b.material
hide b
)
)
)else(
)
--批量给物体分UV
if _bool_B then(
for b in _object do(
select b
modPanel.addModToSelection (Unwrap_UVW ()) ui:on
$.modifiers[#unwrap_uvw].unwrap.setMapChannel 2
subobjectLevel = 3
actionMan.executeAction 0 "40021"
actionMan.executeAction 2077580866 "40046"
modPanel.addModToSelection (UV_Packer ()) ui:on
$.modifiers[#UV_Packer].channel = 2
$.modifiers[#UV_Packer].PADDING = 3
$.modifiers[#UV_Packer].show_preview = off
$.modifiers[#UV_Packer].pack()
modPanel.addModToSelection (XForm ()) ui:on
macros.run "Modifier Stack" "Convert_to_Poly"
)
)
--批量烘焙物体
if _bool_C then(
_url=edt2.text
_urlImage=getDir #image
_size=?
_indexA=_object.count
_indexB=0;
print _urlImage
for b in _object do(
select b
_indexB=_indexB+1
_Scale=filterString b.name "_"
case _Scale[3] of(
"S":_size=256
"M":_size=512
"L":_size=1024
"XL":_size=2048
default:_size=512
)
if _url=="" then(
BakeDiffuseAndLighting b _size _urlImage
)else(
BakeDiffuseAndLighting b _size _url
)
print (_indexB as String +"/"+_indexA as String )
)
)
if _bool_E then(
_url=edt2.text
_urlImage=getDir #image
_size=?
print _urlImage
for b in _object do(
select b
_Scale=filterString b.name "_"
case _Scale[3] of(
"S":_size=256/16
"M":_size=512/16
"L":_size=1024/16
"XL":_size=2048/16
default:_size=512/16
)
if _url=="" then(
BakeDiffuseAndLighting b _size _urlImage
)else(
BakeDiffuseAndLighting b _size _url
)
)
)
if _bool_F then(
_url=edt2.text
_urlImage=getDir #image
_size=?
print _urlImage
for b in _object do(
select b
_Scale=filterString b.name "_"
case _Scale[3] of(
"S":_size=256
"M":_size=512
"L":_size=1024
"XL":_size=2048
default:_size=512
)
if _url=="" then(
BakeAO b _size _urlImage
)else(
BakeAO b _size _url
)
)
)
--批量给物体创建材质球
if _bool_D then(
_num=0
_index=_count
_a=1
for i=1 to _index do(
_a=_a+1
select _object[i]
_material=case (classof $.material) of
(
Standardmaterial:
_map=$.material.diffuseMap
Arch___Design__mi:
_map=$.material.mapM0
Multimaterial:
_map=undefined
default:
_map=undefined
)
_object[i].material = standard diffuseMap:() showInViewport:true
_object[i].material.name=_object[i].name
--_object[i].material.diffuseMap=_map
if (mod _a 23)==1 do(
--_a=_a-23
)
)
)
)else(
messageBox "宋洋提醒:您尚未选定任何物体,请先输入物体前缀在进行操作!"
)
)
on chk_jianmian changed state do
_bool_A=chk_jianmian.checked
on chk_fenUV changed state do
_bool_B=chk_fenUV.checked
on chk_hongpei changed state do
_bool_C=chk_hongpei.checked
on chk_caizhiqiu changed state do
_bool_D=chk_caizhiqiu.checked
on chk_hongpeiA changed state do
_bool_E=chk_hongpeiA.checked
on chk_Ao changed state do
_bool_F=chk_Ao.checked
on btn2 pressed do(
_text=edt1.text
_object=execute ("$"+_text+"*")
_count=execute ("$"+_text+"*"+".count")
for i=1 to _count do(
select _object[i]
OBJ _object[i]
)
delete _object
_newobject=execute ("$/*")
for obj in _newobject do(
print obj.name
_n=filterString obj.name "/"
obj.name=_n[1]
print _n
)
)
on btn3 pressed do(
_text=edt1.text
_object=execute ("$"+_text+"*")
select _object
)
)
function OBJ song=(
_name=song.name
print _name
copy(song) name:("/"+_name)
_obj=getnodebyname ("/"+_name)
Box lengthsegs:1 widthsegs:1 heightsegs:1 length:10 width:10 height:10 mapcoords:on pos:[0,0,0] isSelected:on name:"SongYang"
macros.run "Modifier Stack" "Convert_to_Poly"
$SongYang.EditablePoly.attach _obj $
subobjectLevel = 5
$.EditablePoly.SetSelection #Face #{1..6}
actionMan.executeAction 0 "40020" -- Edit: Delete Objects
$.EditablePoly.delete #Face
subobjectLevel = 0
$SongYang.name = ("/"+_name)
)
function BakeDiffuseAndLighting obj size _url=(
obj.iNodeBakeProperties.removeAllBakeElements()
be1 = completeMap()
be1.outputSzX= be1.outputSzY = size --set the size of the baked map
be1.fileType = (_url+"\\"+obj.name+"_complete.exr")
be1.fileName = filenameFromPath be1.fileType
be1.filterOn = true --enable filtering
be1.shadowsOn = true --disable shadows
--be1.lightingOn = true --disable lighting
be1.enabled = true --enable baking
be3 = Ambient_Occlusion()
be3.outputSzX= be3.outputSzY = size*2 --set the size of the baked map
be3.fileType = (_url+"\\"+obj.name+"_ao.exr")
be3.fileName = filenameFromPath be3.fileType
be3.filterOn = true --enable filtering
--be3.shadowsOn = true --disable shadows
--be1.lightingOn = true --disable lighting
be3.enabled = true --enable baking
be3.samples=32
be2 = LightingMap() -- instance of the bake element class
be2.outputSzX =be2.outputSzY = size --set the size of the baked map
--specifythe full file path, name and type:
be2.fileType = (_url+"\\"+obj.name+"_lighting.exr")
be2.fileName = filenameFromPath be2.fileType
be2.filterOn = true --enable filtering
be2.shadowsOn =true --enable shadows
be2.enabled = true --enable baking
--Preparing theobjectfor baking:
obj.INodeBakeProperties.addBakeElement be1 --add first element
obj.INodeBakeProperties.addBakeElement be2 --add second element
obj.INodeBakeProperties.addBakeElement be3
obj.INodeBakeProperties.bakeEnabled = true --enabling baking
obj.INodeBakeProperties.bakeChannel = 2 --channel to bake
obj.INodeBakeProperties.nDilations = 1 --expand the texturea bit
--obj.INodeBakeProperties.MappingCoordinates.channel=2
--select obj --we are baking the selection, so we select the object
--Call the rendererto bake both elements:
render rendertype:#bakeSelected vfb:off progressBar:true outputSize:[size,size]
theComp = CompositeTextureMap() --create a composite map
theComp.add() --add a second layer
theComp.blendMode = #(0,5) --set second layer to Multiply
--Create two maps, one with the diffuse, one with the lighting map
theMap1 =bitmaptexture filename:be1.fileType
theMap2=bitmaptexture filename:be2.fileType
theMap3=bitmaptexture filename:be3.fileType
theComp.mapList = #(theMap1,theMap2,theMap3) --composite the two maps
theComp.opacity = #(100,70) --set the lighting map to 70% opacity
--Create a standard self-illum material using the Composite map
bakedMat = standard diffusemap:theComp selfIllumAmount:100
--print be1.fileType
--print be2.fileType
)
function BakeAO obj size _url=(
be3 = Ambient_Occlusion()
be3.outputSzX= be3.outputSzY = size*2 --set the size of the baked map
be3.fileType = (_url+"\\"+obj.name+"_ao.exr")
be3.fileName = filenameFromPath be3.fileType
be3.filterOn = true --enable filtering
be3.samples=32
--be1.lightingOn = true --disable lighting
be3.enabled = true --enable baking
obj.INodeBakeProperties.addBakeElement be3
obj.INodeBakeProperties.bakeEnabled = true --enabling baking
obj.INodeBakeProperties.bakeChannel = 2 --channel to bake
obj.INodeBakeProperties.nDilations = 1 --expand the texturea bit
--obj.INodeBakeProperties.MappingCoordinates.channel=2
--select obj --we are baking the selection, so we select the object
--Call the rendererto bake both elements:
render rendertype:#bakeSelected vfb:off progressBar:true outputSize:[size,size]
theComp = CompositeTextureMap() --create a composite map
theComp.add() --add a second layer
theComp.blendMode = #(0,5) --set second layer to Multiply
--Create two maps, one with the diffuse, one with the lighting map
--theMap1 =bitmaptexture filename:be1.fileType
--theMap2=bitmaptexture filename:be2.fileType
theMap3=bitmaptexture filename:be3.fileType
theComp.mapList = #(theMap3) --composite the two maps
theComp.opacity = #(100,70) --set the lighting map to 70% opacity
--Create a standard self-illum material using the Composite map
bakedMat = standard diffusemap:theComp selfIllumAmount:100
)
CreateDialog SongYangTool