Notifications
Clear all

[Closed] Build mesh Handler FAQ

Hi, I’m learning to create custom meshes with Max Script, and though i’m really finding the help reference very helpful, I still got some questions…
Basically, what I’m trying to do is to define a custom mesh object trough a series of parameters,
much like in the example Antistar in help…
And the concept is to define mesh A and mesh B and do subtraction.
But the problem is , that I dont know where to keep temporary meshes (or trimeshes) before i
finally subtract them and put them in mesh constructor.
Now, i figure the conversation should continue in code
This is what i made so far… keep in mind i’m new in coding and pretty much rusty in math ;D

—script by Slobodan Kovacevic alias freesmith 08.03.2010.
plugin simpleObject Archcube
name:“Archcube”
category:“HowTo”
classID:#(596559238, 1453114438)

(

parameters main rollout: params
(
radius1 type:#float ui:radius1 default:3
height type:#float ui:height default:1
width type:#float ui:width default:1
Segments type:#float ui:Segments default:10
)

rollout params “Archcube” width:162 height:130
(
spinner radius1 “Radius 1” pos:[34,9] width:112 height:16 range:[3,50,3] scale:0.01
spinner height “height” pos:[34,34] width:112 height:16 range:[3,50,3] scale:0.01
spinner width “width” pos:[36,58] width:112 height:16 range:[3,50,3] scale:0.01
spinner Segments “Segments” pos:[34,84] width:112 height:16 range:[3,50,10] scale:0.01
label credit “script by freesmith” pos:[55,109] width:90 height:21
)

on buildMesh do

(
vert_array = #()
face_array = #()
vert_count = 0
degree =180/segments
g=degree/2
for a = g to 180-g by degree do
(
v1 = [radius1cos(a-g),0,radius1sin(a-g)]
v2 = [radius1cos(a+g),0,radius1sin(a+g)]
v3 = [radius1cos(a-g),width,radius1sin(a-g)]
v4= [radius1cos(a+g),width,radius1sin(a+g)]
v5 = [0,0,0]
v6 = [0,width,0]
append vert_array v1
append vert_array v2
append vert_array v3
append vert_array v4
append vert_array v5
append vert_array v6

append face_array [vert_count+1,vert_count+4,vert_count+2]
append face_array [vert_count+1,vert_count+3,vert_count+4]
append face_array [vert_count+1,vert_count+2,vert_count+5]
append face_array [vert_count+3,vert_count+6,vert_count+4]
vert_count +=6

)

v7 = [radius1cos(0),0,radius1sin(0)-height]
v8= [radius1cos(0),width,radius1sin(0)-height]
v9= [radius1cos(180),0,radius1sin(180)-height]
v10= [radius1cos(180),width,radius1sin(180)-height]

append vert_array v7—+1
append vert_array v8—+2
append vert_array v9—–+3
append vert_array v10—–+4

append face_array [1,5,vert_count+1]
append face_array [5,vert_count+3,vert_count+1]
append face_array [5,vert_count-4,vert_count+3]
append face_array [1,vert_count+1,vert_count+2]
append face_array [1,vert_count+2,3]
append face_array [3,vert_count+2,6]
append face_array [vert_count+2,vert_count+4,6]
append face_array [6,vert_count+4,vert_count-2]
append face_array [vert_count-2,vert_count+3,vert_count-4]
append face_array [vert_count-2,vert_count+4,vert_count+3]
append face_array [vert_count+1,vert_count+3,vert_count+2]
append face_array [vert_count+3,vert_count+4,vert_count+2]

setMesh mesh verts:vert_array faces:face_array
meshop.autoSmooth mesh #{1…mesh .numfaces} 5
meshop.weldVertsByThreshold mesh #{1…mesh .numverts} 0.01
meshop.autoEdge mesh #{1…mesh .edges.count} 5
————————————————————End Build main object

)–end buildMesh
tool create
(
on mousePoint click do
(
case click of
(
1: coordsys grid (nodeTM.translation = gridPoint)
)
)

on mouseMove click do
(
case click of
(
2: (radius1 = abs(gridDist.y))
3: (height= abs(gridDist.y))
4: (width = abs(gridDist.x))
5: (#stop)
)
)
)–end create

)–end plugin



Now , what I would like to know is how to put the current mesh that script creates , in temporary mesh, then create a new one , might be the same , just smaller , and subtract them and put in final mesh constructor… which would give in the end hollow Archcube

3 Replies

I’m not sure if I fully understand your problem, but you can just boolean substract two tri-meshes, like:

mesh = mesh1.mesh - mesh2.mesh
 

I think you can also use it on self:

mesh = mesh.mesh - mesh2.mesh
 

Afterwards you should delete the temporary meshes, otherwise they stay in memory.

delete mesh2

Hey, thanks for the reply
well, the actual problem is this… when I try this

mesh1 = mesh vertices:vert_array faces:face_array

i have this message…
Type error: Call needs function or class, got: TriMesh <<

so , I really dont know how to define temporary mesh inside the buildmesh handler before I put the final data in mesh constructor…

I have seen some examples on web , where people create instance of an object like box etc, and then extract mesh from it, or apply some meshop operations and then extract mesh to be finally added in mesh constructor …

the line —mesh1 = mesh vertices:vert_array faces:face_array–
works well if not in scripted plugin build mesh handler… but there it makes problems…
Also i’ve seen a suggestion that if you create mesh from some object instance (like box), you should assign it to mesh constructor this way mesh += obj.mesh, because if you try this mesh = obj.mesh , 3ds max crashes… I ‘ve been trying some ways to solve my problem and indeed you get some weird things going on , before max crashes…

Also , if I try this
on buildMesh do
(
mesh1 = createInstance box
mesh1=mesh1.mesh
meshop.deleteFaces mesh1 #{1…mesh1.numfaces} delIsoVerts:true
setmesh mesh1 verts:#([0,0,0],[width,0,0],[width,depth,0],[0,depth,0]) faces:#([3,2,1], [1,4,3])
mesh += mesh1.mesh
)

i get this error message in setmesh line of code…
>> MAXScript Scripted Plugin Handler Exception: – Unknown system exception << :hmm: