PDA

View Full Version : In simpleObject connect vertex to another object


ektho
06-07-2011, 01:39 PM
Hi all, a question.. in simpleObject (generated via maxscript) it's possible connect the position of his vertices to another object in the scene?
Thank in advance.

PEN
06-07-2011, 03:59 PM
I think this will be possible, not sure that it is advised how ever.
You are going to have to store a reference of the model you want to follow, calculate the new position of that vertex and then force an update to the mesh.

ektho
06-07-2011, 04:54 PM
Hi Pen , I'm honored that you answer to my question, here down the code:



plugin simpleObject customPlane
name:"Custom Plane"
classID:#(0x21764401, 0x55a56f86)
category:"Scripted Primitives"
(

local vertArray = #()
local faceArray = #()

parameters main rollout:params
(
pLength type:#float ui:planeLength
pWidth type:#float ui:planeWidth
pLengthSegs type:#integer ui:lengthSegs default:3
pWidthSegs type:#integer ui:widthSegs default:3
ObjNode type:#node ui:chooseit
ObjNodePoz type:#float default:0

on ObjNode set transform do
(
if CamAt != undefined then ObjNodePoz = ObjNode.pos.z CamAt.name else ObjNodePoz
)
)
rollout params "Parameters"
(
spinner planeLength "Length: " type:#float range:[0,100000,0]
spinner planeWidth "Width: " type:#float range:[0,100000,0]
spinner lengthSegs "Length Segs: " type:#integer range:[1,500,3]
spinner widthSegs "Width Segs: " type:#integer range:[1,500,3]

fn Box_filt obj = classof obj == Box

pickbutton chooseit "Select Box" width:160 filter:Box_filt autoDisplay:true

on chooseit picked obj do
(
ObjNode = obj
ObjNodePoz = ObjNode.pos.z
)
)
on buildMesh do
(
vertArray = #()
widthStep = pWidth / pWidthSegs
lengthStep = pLength / pLengthSegs
for j = 0 to pLengthSegs do
(
y = (lengthStep * j)
for i = 0 to pWidthSegs do
(
x = (widthStep * i)
append vertArray [x-(pWidth/2), y-(pLength/2), ObjNodePoz]
)
)

faceArray = #()
if pWidth * pLength >= 0 then
(
for j = 0 to (pLengthSegs - 1) do
(
for i = 1 to pWidthSegs do
(
v1 = i + (j * (pWidthSegs + 1))
v2 = v1 + 1
v3 = v2 + pWidthSegs + 1
append faceArray [v1,v2,v3]
swap v1 v3
v2 = v1 - 1
append faceArray [v1,v2,v3]
)
)
)
else
(
for j = 0 to (pLengthSegs - 1) do
(
for i = 1 to pWidthSegs do
(
v1 = i + (j * (pWidthSegs + 1))
v2 = v1 + 1
v3 = v2 + pWidthSegs + 1
append faceArray [v3,v2,v1]
swap v1 v3
v2 = v1 - 1
append faceArray [v3,v2,v1]
)
)
)
setMesh mesh verts:vertArray faces:faceArray
for f = 1 to faceArray.count do
(
setEdgeVis mesh f 3 false
)
)
tool create
(
on mousePoint click do case click of
(
1: nodeTM.translation = gridPoint
2: #stop
)
on mouseMove click do case click of
(
2: ( pWidth = abs gridDist.x; pLength = abs gridDist.y )
)
)
)




Now works only when I select the box...when moved the box the vertices don't changed the position...why?


Sorry for my english...

CGTalk Moderation
06-07-2011, 04:55 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.