PDA

View Full Version : Scripted Primitive Problem


arcburn
04-06-2006, 12:26 AM
I am trying to work from the scripted primitive example in the MaxScript Reference and extend it further.

I scripted a box that draws upon another box.

The problem is the second box starts at the gridpoint that begins the primitive "nodeTM.translation = gridPoint"

How can I make the second box begin at the height of the first box?

plugin simpleObject squareTube
name:"SquareTube"
classID:#(63445,55332)
category:"Scripted Primitives"
(
local box1, box2
parameters main rollout:params
(
length type:#worldUnits ui:length default:1E-3
width type:#worldUnits ui:width default:1E-3
height type:#worldUnits ui:height default:1E-3
Ilength type:#worldunits ui:Ilength default:1E-3
Iwidth type:#worldunits ui:Iwidth default:1E-3
Iheight type:#worldUnits ui:height default:1E-3
)
rollout params "SquareTube"
(
spinner height "Height" type:#worldUnits range:[1E-3,1E9,1E-3]
spinner width "Width" type:#worldUnits range:[1E-3,1E9,1E-3]
spinner length "Length" type:#worldUnits range:[-1E9,1E9,1E-3]
spinner Iheight "Height" type:#worldUnits range:[1E-3,1E9,1E-3]
spinner Ilength "InnerBox" type:#worldUnits range:[-1E9,1E9,1E-3]
spinner Iwidth "InnerBox" type:#worldUnits range:[-1E9,1E9,1E-3]
)
on buildMesh do
(
if box1 == undefined then
(
box1 = createInstance box; box2 = createInstance box
)
box1.height = height;
box1.width = width;
box1.length = length;
box2.height = Iheight;
box2.width = Iwidth;
box2.length = Ilength;
mesh = box2.mesh + box1.mesh
)
tool create
(
on mousePoint click do
case click of
(
1: nodeTM.translation = gridPoint
5: #stop
)
on mouseMove click do
case click of
(
2: (Iwidth = abs gridDist.x; Ilength = abs gridDist.y)
3: (width = abs gridDist.x; length = abs gridDist.y)
4: Iheight = gridDist.z;
5: height = gridDist.z;
)
)
)

Bobo
04-06-2006, 05:51 AM
Here is a possible solution:


plugin simpleObject squareTube
name:"SquareTube"
classID:#(63445,55332)
category:"Scripted Primitives"
(
local box1, box2
parameters main rollout:params
(
length type:#worldUnits ui:length default:1E-3
width type:#worldUnits ui:width default:1E-3
height type:#worldUnits ui:height default:1E-3
Ilength type:#worldunits ui:Ilength default:1E-3
Iwidth type:#worldunits ui:Iwidth default:1E-3
Iheight type:#worldUnits ui:Iheight default:1E-3
)
rollout params "SquareTube"
(
spinner height "Height" type:#worldUnits range:[1E-3,1E9,1E-3]
spinner width "Width" type:#worldUnits range:[1E-3,1E9,1E-3]
spinner length "Length" type:#worldUnits range:[-1E9,1E9,1E-3]
spinner Iheight "Top Box Height" type:#worldUnits range:[1E-3,1E9,1E-3]
spinner Ilength "Top Box Length" type:#worldUnits range:[-1E9,1E9,1E-3]
spinner Iwidth "Top Box Width" type:#worldUnits range:[-1E9,1E9,1E-3]
)
on buildMesh do
(
if box1 == undefined then
(
box1 = createInstance box
box2 = createInstance box
)
box1.height = height
box1.width = width
box1.length = length

box2.height = Iheight
box2.width = Iwidth
box2.length = Ilength

mesh2 = box2.mesh
for v = 1 to mesh2.numverts do setVert mesh2 v ((getVert mesh2 v)+[0,0,height])
mesh = box1.mesh + mesh2
)
tool create
(
on mousePoint click do
case click of
(
1: nodeTM.translation = gridPoint
5: #stop
)
on mouseMove click do
case click of
(
2: (width = abs gridDist.x; length = abs gridDist.y)
3: height = gridDist.z;
4: (Iwidth = abs gridDist.x; Ilength = abs gridDist.y)
5: Iheight = gridDist.z;
)
)
)

I changed the creation order a bit, so you first create the bottom box completely, then the top box.

Also fixed some bugs (Iheight was not linked to the proper spinner) and changed the spinner labels.

arcburn
04-06-2006, 08:36 AM
That works perfectly!! :thumbsup: Thanks Bobo!! :applause:

CGTalk Moderation
04-06-2006, 08:36 AM
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.