- Рейтинг
- 7
Помогите доработать скриптик для мапинга. Понимаю, что тема изъезжена, но все же.
Есть скрипт, который почти устраивает, но вот хотелось бы реализовать в нем нормальную функцию поэлементного мапинга. По сути - пообъектный мапинг, только работа с элементами.
Попытался реализовать с помощью поэлементного наложения модификаторов, но получается коряво. Наверняка есть простой и более изящный способ. Подскажите, пожалуйста.
Вот сам скриптик:
Есть скрипт, который почти устраивает, но вот хотелось бы реализовать в нем нормальную функцию поэлементного мапинга. По сути - пообъектный мапинг, только работа с элементами.
Попытался реализовать с помощью поэлементного наложения модификаторов, но получается коряво. Наверняка есть простой и более изящный способ. Подскажите, пожалуйста.
Вот сам скриптик:
Код:
--macroScript UVW_mapping category:"AlexY" buttonText:"UVW_mapping"
--(
--function
fn getelements obj=
(
try
(
f=obj.numfaces
eles=#()
done=#()
for i=1 to f do
(
if (finditem done i)==0 then
(
case (classof obj) of
(
editable_mesh:(faces=(meshop.getElementsUsingFace obj #(i)) as array)
editable_poly:(faces=(polyop.getElementsUsingFace obj #(i)) as array)
)
append eles faces
join done faces
)
)
)
catch(eles=undefined)
return eles
)
fn getGeomOnlyObj =
(
local theGeomObj = #()
local theCount = selection.count
if theCount != 0 do for i in selection do if superclassof i == GeometryClass do append theGeomObj i
try select theGeomObj catch()
)
fn deleteModifiers obj =
(
local deleteClasses = #(Uvwmap)
try( for i = obj.modifiers.count to 1 by -1 where findItem deleteClasses (classof obj.modifiers[i]) != 0 do deleteModifier obj obj.modifiers[i])catch()
)
--function
rollout uvw "UVW maping (sel only)"
( -- start rollout standart_uvw "standart UVW map (selection obj)"
group "Fast mapping (Instanced):"
(
button b2 "1k_1k_1k ch1" across:2
button b3 "2k_2k_2k ch2"
button b1 "Create UVW Map by size"
)
button b4 "Delete all UVW map"
group "Other mapping (by obj or elem):"
(
button b5 "Mapping by obj" across:2
checkBox btnCheck "Fit" checked:false align: #center
button b6 "Mapping OBJ by elements" align: #left
)
dropdownlist typeMap "MapType:" items:#("Planar", "Cylindrical", "Spherical", "Shrink Wrap", "Box") selection:5
label lab1 "Aligment:" across:2
radioButtons rdo1 "" columns:3 labels:#("X", "Y", "Z") default:3
spinner theL "Length:" range:[-100000,100000,500] align:#right width:100 type:#worldunits across:2
spinner randX "randX:" range:[-100000,100000,0] align:#right type:#worldunits width:80
spinner theW "Width:" range:[-100000,100000,500] align:#right width:100 type:#worldunits across:2
spinner randY "randY:" range:[-100000,100000,0] align:#right type:#worldunits width:80
spinner theH "Height:" range:[-100000,100000,500] align:#right width:100 type:#worldunits across:2
spinner randZ "randZ:" range:[-100000,100000,0] align:#right type:#worldunits width:80
label pust "" across:2
spinner randRot "randRotate:" range:[0,360,0] align:#right type:#float
spinner theMapChan "Map Channel:" range:[1,100,1] align:#right type:#integer
on typeMap selected i do format "%\n" typeMap.items[i]
on b1 pressed do --start button b1 "Create UVW Map by size"
(
getGeomOnlyObj()
local theUVWmap = (UVWMap())
theUVWmap.maptype = typeMap.selection - 1
theUVWmap.mapChannel = theMapChan.value
try(theUVWmap.length = theL.value)catch()
try(theUVWmap.width = theW.value)catch()
try(theUVWmap.height = theH.value)catch()
SetCommandPanelTaskMode #modify
try(modPanel.addModToSelection theUVWmap)catch()
) --end button b1 "Create UVW Map by size"
on b2 pressed do -- start button b2 "1k_1k_1k ch1"
(
getGeomOnlyObj()
local theUVWmap = (UVWMap())
theUVWmap.maptype = 4
theUVWmap.mapChannel = 1
try theUVWmap.length = 1000 catch()
try(theUVWmap.width = 1000)catch()
try(theUVWmap.height = 1000)catch()
SetCommandPanelTaskMode #modify
try(modPanel.addModToSelection theUVWmap)catch()
) -- end button b2 "1k_1k_1k ch1"
on b3 pressed do -- start button b3 "2k_2k_2k ch2"
(
getGeomOnlyObj()
local theUVWmap = (UVWMap())
theUVWmap.maptype = 4
theUVWmap.mapChannel = 2
try(theUVWmap.length = 2000)catch()
try(theUVWmap.width = 2000)catch()
try(theUVWmap.height = 2000)catch()
SetCommandPanelTaskMode #modify
try(modPanel.addModToSelection theUVWmap)catch()
) -- end button b3 "2k_2k_2k ch2"
on b4 pressed do -- start button b4 "Delete all UVW map"
(
getGeomOnlyObj()
for obj in selection do deleteModifiers obj
) -- end button b4 "Delete all UVW map"
on btnCheck changed theState do -- start checkBox btnCheck "Fit"
(
try theL.enabled = not btnCheck.state catch()
try theW.enabled = not btnCheck.state catch()
try theH.enabled = not btnCheck.state catch()
) --end checkBox btnCheck "Fit"
on b5 pressed do -- start button b5 "Mapping by obj"
(
getGeomOnlyObj()
local theSelOBJ = selection as array
for i in theSelOBJ do
(
select i
local theUVWmap = (UVWMap())
theUVWmap.maptype = typeMap.selection - 1
theUVWmap.mapChannel = theMapChan.value
try theUVWmap.length = theL.value catch()
try theUVWmap.width = theW.value catch()
try theUVWmap.height =theH.value catch()
try theUVWmap.axis = rdo1.state - 1 catch()
if btnCheck.state == false then addModifier i theUVWmap
else
(
try
(
theUVWmap.length = if rdo1.state == 3 then (i.max.y - i.min.y) else if rdo1.state == 2 then (i.max.z - i.min.z) else (i.max.y - i.min.y)
)catch()
try
(
theUVWmap.width = if rdo1.state == 3 then (i.max.y - i.min.y) else if rdo1.state == 2 then (i.max.y - i.min.y) else (i.max.z - i.min.z)
)catch()
try
(
theUVWmap.height = if rdo1.state == 3 then (i.max.z - i.min.z) else if rdo1.state == 2 then (i.max.y - i.min.y) else (i.max.x - i.min.x)
)catch()
addModifier i theUVWmap
)
i.modifiers[1].gizmo.pos.x = random -randX.value randX.value
i.modifiers[1].gizmo.pos.y = random -randY.value randY.value
i.modifiers[1].gizmo.pos.z = random -randZ.value randZ.value
select theSelOBJ
)
)-- end button b5 "Mapping by obj"
on b6 pressed do -- start button b6 "Mapping OBJ by elements"
(
getGeomOnlyObj()
SetCommandPanelTaskMode #modify
if selection.count == 1 then
(
local theOBJ = $
local theElemObj = getelements theOBJ
for i = 1 to (getelements theOBJ).count do
(
local theEditMesh = (Edit_Mesh name:(uniquename "EM_uvw_"))
modPanel.addModToSelection theEditMesh
subObjectLevel = 4
local theUVWmap = (UVWMap())
theUVWmap.maptype = typeMap.selection - 1
theUVWmap.mapChannel = theMapChan.value
theUVWmap.length = theL.value
theUVWmap.width = theW.value
theUVWmap.height =theH.value
theUVWmap.axis = rdo1.state - 1
SetFaceSelection theOBJ theElemObj[i]
modPanel.addModToSelection theUVWmap
theOBJ.modifiers[1].gizmo.pos.x = random -randX.value randX.value
theOBJ.modifiers[1].gizmo.pos.y = random -randY.value randY.value
theOBJ.modifiers[1].gizmo.pos.z = random -randZ.value randZ.value
theOBJ.modifiers[1].gizmo.rotation = if rdo1.state == 3 then ((angleaxis (random -randRot.value randRot.value) [0,0,1]) as quat)
else if rdo1.state == 2
then ((angleaxis (random -randRot.value randRot.value) [0,1,0]) as quat)
else ((angleaxis (random-randRot.value randRot.value) [1,0,0]) as quat)
update theOBJ
)
)else (print "Please select one object")
)-- end button b6 "Mapping OBJ by elements"
) createdialog uvw 210 360
--tested in Max 2013