Hey guys,
First off, I'm a newbie. sorry.
I'm trying to learn maxscript and to create standard parametric geometries for archviz. Currently I'm working on a curtain wall plugin similar to the one that comes with Max but with more functionality for what I need. I have a pretty good handle on creating the geometry itself but I'm stuck on how to assign materials and material ids to specific faces and establish uv coordinates.
I created the following script for testing. I would like to assign a different material for each polygon. Can anybody help?
(
parameters main rollout: params(
WidthA type:#float ui:WidthA default:10
LengthA type:#float ui:LengthA default:10
)
rollout params "Test Plane"(
spinner WidthA"Width "range:[0,10000,10] tooltip:"Width"
spinner LengthA"Length "range:[0,10000,10] tooltip:"Length"
)
on buildMesh do (
vert_array = #()
face_array = #()
append vert_array[0,0,0]
append vert_array[(LengthA/2),0,0]
append vert_array[LengthA,0,0]
append vert_array[0,WidthA,0]
append vert_array[(LengthA/2),WidthA,0]
append vert_array[LengthA,WidthA,0]
append face_array[4,1,2]
append face_array[2,5,4]
append face_array[5,2,3]
append face_array[3,6,5]
setmesh mesh vertices:vert_array faces:face_array
for face = 1 to mesh.numfaces do setEdgeVis mesh face 3 false
)
tool create
(
on mousePoint click do (
case click of (
1: coordsys grid (nodeTM.translation = gridPoint)
)
)
on mouseMove click do (
case click of (
2: (LengthA = abs(gridDist.x); WidthA = abs(gridDist.y))
3: (#stop)
)
)
)
)
Thanks in advance,
Gary
Comments (8)
Comment policy
quick tip
If you need more advanced solution use this tool by Garp
http://www.scriptspot.com/3ds-max/scripts/primitive-maker
Also you can look theses video tutorials by Bobo
http://www.youtube.com/watch?v=61UXxvhZolI
http://www.youtube.com/watch?v=oEhjjIGvYEk
http://www.youtube.com/watch?v=8HxWZ4TWk_Y
http://www.youtube.com/watch?v=WL37bakWwAI
http://www.youtube.com/watch?v=W1b9Zs2eYXs
http://www.youtube.com/watch?v=ZoJiPm-3tWg
http://www.youtube.com/watch?v=_GspSEHCn8U
Duh
Oh wow! That is so much simpler. I was thinking i would have to cycle through the mesh after it was made. This is exactly what i needed. Thank you!
I'm glad that this code help.
By the way, next time when you post some code use tags "< code> your code here < /code>"
Cheers!
thanks
And this is your plugin (place it if you want in script>startup directory)
You don't need my function for plugin
Attachments
Set Unique Mesh Polygon Material ID
Hope this help
fn setPolygonMtlID obj =
(
local obj = selection[1]
local uniqueFaces = #()
for f in 1 to obj.numfaces do appendifunique uniqueFaces ((meshop.getPolysUsingFace obj #{f}) as array)[1]
meshPolygonsArr = for i in uniqueFaces collect ((meshop.getPolysUsingFace obj #{i}) as array)
for mid in 1 to meshPolygonsArr.count do
(
for f in meshPolygonsArr[mid] do setFaceMatID obj f mid
)
free meshPolygonsArr ; free uniqueFaces ; update obj
)
for obj in selection where iskindof obj.baseobject Editable_Mesh do
(
setPolygonMtlID obj.baseobject
)
Hey, thanks for the help and the quick reply! :)
I tried it in my script but it didn't seem to do anything. I'm not entirely sure exactly what your code does so I probably didn't apply it correctly.
Attached is the script if you'ld like to have a look.
Thank you. :)
Attachments
Explanation
Run the code below and you'll find out how my function works