Notifications
Clear all
[Closed] UVW_XYZ_Wrp
Feb 12, 2014 12:21 pm
Hello,
this is my try to make first modifier in maxscript.
It take one mesh “Mesh” and hit rays from every point to another mesh “UV”. Then it moves points where it hitted the “UV” mesh but on “XY” mesh. “UV” and “XY” should have the same topology. As “Mesh” and mesh with modifier (references )
It is basic but slow. How can I make it faster? thanks
--------------------------------------------------------------------------------------------------------------------------------------------
plugin simpleMod UVW_XYZ_Wrp
name:"UVW_XYZ_Wrp"
classID:#(0x59c28d28, 0x2315bf74)
version:1
(
fn bary2Pos Vertpos BaryX =
(
p = BaryX[1]*Vertpos[1] + BaryX[2]*Vertpos[2] + BaryX[3]*Vertpos[3]
)
fn Editmesh_filt obj = classof obj == Editable_mesh
parameters main rollout:params
(
FromTop type:#boolean animatable:False default:true
FromFront type:#boolean animatable:False default:False
ObjTRNSFRM type:#matrix3
Obj_UV type:#node ui:Pck01 subAnim:false
Obj_XY type:#node ui:Pck02 subAnim:false
ObjMesh type:#node ui:Pck03 subAnim:false
Offsetray type:#float ui:Offsetray default:2000
)
rollout params "UVProjectWrapp"
(
checkbox Chck01 "FromTop" checked:true
checkbox Chck02 "FromFront" checked:False
Pickbutton Pck01 "UV" filter:Editmesh_filt autoDisplay:true width:80 height:30
Pickbutton Pck02 "XY" filter:Editmesh_filt autoDisplay:true width:80 height:30
Pickbutton Pck03 "Mesh" filter:Editmesh_filt autoDisplay:true width:80 height:30
spinner Offsetray "Offset_Ray" type:#Float range:[100000.0,900000.0,0]
on Chck01 changed theState do
(
Chck01.checked = true
Chck02.checked = False
FromTop = true
FromFront = False
)
on Chck02 changed theState do
(
Chck01.checked = False
Chck02.checked = true
FromTop = False
FromFront = true
)
)
on attachedToNode TheNode do
(
ObjTRNSFRM = TheNode.transform
)
on map i p do
(
if Obj_UV!=undefined and Obj_XY!=undefined and ObjMesh!=undefined then
(
try
(
if FromTop == true then
(
Offset = [0,0,Offsetray]
RayDir = [0,0,-1]
)
else
(
Offset = [0,- Offsetray,0]
RayDir = [0,1,0]
)
RayPOS = getVert ObjMesh i + Offset
HitRay = intersectRayEx Obj_UV (Ray RayPOS RayDir)
HitDist = (RayPOS - (Offset)) - HitRay[1].pos
case of
(
(FromTop == true and HitDist[3] >= 0) : (OverUnder = 1)
(FromTop != true and HitDist[2] <= 0) : (OverUnder = 1)
default : OverUnder = -1
)
HitFace = HitRay[2]
HitBary = HitRay[3]
VertArr = getface Obj_XY HitFace
PosArr = #()
For j = 1 to 3 do
(
NewFace = getVert Obj_XY VertArr[j] + ((getNormal Obj_XY VertArr[j]) * (length HitDist) * OverUnder)
append PosArr NewFace
)
p = (bary2Pos PosArr HitBary) * (inverse ObjTRNSFRM)
)
catch(p)
)
else(p)
)
)
)
Probably I should ask “How to do it right?”.