Notifications
Clear all
[Closed] Index faces?
May 30, 2011 3:07 pm
I need help, I’m trying to do a simple mesh object, a parametric plane, but i can not make the formula for the index face, down here the script:
plugin simpleObject quad
name:"Plane"
category:"Extra Primitives"
classID:#(0x4927806d, 0x3d9ca278)
(
parameters main rollout:params
(
widthVal type:#float ui:widthVal default:0
lengthVal type:#float ui:lengthVal default:0
widthSeg type:#integer ui:widthSeg default:3
lengthSeg type:#integer ui:lengthSeg default:3
)
rollout params "Parameters"
(
spinner widthVal "Width: " range:[0,10000,5] fieldWidth:50
spinner lengthVal "Length : " range:[0,10000,5] fieldWidth:50
spinner widthSeg "WidthSeg: " range:[1,100,5] fieldWidth:50
spinner lengthSeg "LengthSeg : " range:[1,100,5] fieldWidth:50
)
on buildMesh do
(
vert_array = #()
face_array = #()
for i = 1 to lengthSeg+1 do
(
for ii = 1 to widthSeg+1 do
(
append vert_array [ (widthVal/widthSeg)*(ii-1), (lengthVal/lengthSeg)*(i-1), 0]
)
)
for j = 1 to widthSeg do
(
append face_array [j,j+1,j+widthSeg+2]
)
--face_array = #([1,2,6],[2,3,7],[3,4,8],[1,6,5],[2,7,6],[3,8,7])
setMesh mesh verts:vert_array faces:face_array
)
tool create
(
on mousePoint click do
case click of (1: coordsys grid (nodeTM.translation = gridPoint);2: print LengthSeg)
on mouseMove click do
case click of (2:(widthVal = gridDist.x; lengthVal = gridDist.y); 3: #stop)
)
)
Sorry for my english.
2 Replies
May 30, 2011 3:07 pm
I did the same exact thing for a class last year. Maybe it will help you solve your problem.
plugin simpleObject customPlane
name:"Custom Plane"
classID:#(0x21764401, 0x55a56f86)
category:"Scripted Primitives"
(
local faceArray = #()
local vertArray = #()
rollout params "Parameters"
(
spinner planeLength "Length: " type:#float range:[0,1000,0]
spinner planeWidth "Width: " type:#float range:[0,1000,0]
spinner lengthSegs "Length Segs: " type:#integer range:[1,10,1]
spinner widthSegs "Width Segs: " type:#integer range:[1,10,1]
)
parameters main rollout:params
(
pLength type:#float ui:planeLength
pWidth type:#float ui:planeWidth
pLengthSegs type:#integer ui:lengthSegs default:1
pWidthSegs type:#integer ui:widthSegs default:1
)
on buildMesh do
(
-- Create vertices
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, y, 0]
)
)
-- Put vertex numbers in face array
faceArray = #()
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]
)
)
-- Create the mesh
setMesh mesh verts:vertArray faces:faceArray
)
-- Tells the script what to do with your mouse clicks and drags.
tool create
(
on mousePoint click do case click of
(
1: nodeTM.translation = gridPoint
2: #stop
)
on mouseMove click do case click of
(
2: ( pWidth = gridDist.x; pLength = gridDist.y )
)
)
)
May 30, 2011 3:07 pm
Thanks so much Viro, is what I was looking, you saved my brain!:applause: