Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JokerMartini/4be7febf2c159cdf2888 to your computer and use it in GitHub Desktop.
Save JokerMartini/4be7febf2c159cdf2888 to your computer and use it in GitHub Desktop.
Maxscript: This snippet demonstrates how to create a simple geometry plugin for 3ds Max using a combination of custom geometry and a primitive.
plugin simpleObject IntegratedMesh
name:"IntegratedMesh"
category:"Standard Primitives"
classID:#(0x512e8ff9, 0x51aefc78)
(
parameters main rollout:rltParams
(
enableTube type:#boolean default:false ui:uiEnableTube
tubeRadius type:#worldUnits default:6 ui:uiTubeRadius
frameWidth type:#worldUnits default:30 ui:uiFrameWidth
frameSegs type:#integer default:4 ui:uiFrameSegs
numDupes type:#integer default:5 ui:uiNumDupes
DupeDist type:#float default:10 ui:uiDupeDist
)
rollout rltParams "Parameters"
(
checkbox uiEnableTube "Enable Tube" offset:[6,4]
spinner uiTubeRadius "Tube Radius:" range:[.1,1e9,0] type:#worldUnits
spinner uiFrameWidth "Frame Width:" range:[0,1e9,0] type:#worldunits offset:[0,6]
spinner uiFrameSegs "Segments:" range:[2,1e9,1] type:#integer
spinner uiNumDupes "Duplicates:" range:[0,100,5] type:#integer offset:[0,3]
spinner uiDupeDist "Distance:" range:[0,100000,10] type:#worldunits offset:[0,3]
)
fn genFramePlatform start:[0,0,0] =
(
local FrameVerts = #()
/* Create first strip of verts */
for r = 0 to frameSegs-1 do
(
rowSet = (frameWidth/(frameSegs-1))*r
for s = 0 to frameSegs-1 do
(
offset = (frameWidth/(frameSegs-1))*s
vertPos = start + [offset,rowSet,0]
append FrameVerts vertPos
)
)
return FrameVerts
)
fn genMesh =
(
/*Set Vertices*/
local verticesArr = #()
/* Platform of Verts */
frameVerts = genFramePlatform start:[0,0,0]
join verticesArr frameVerts
/*Set Faces*/
local facesArr = #()
local count = frameSegs
local endCounter = count
local loops = frameSegs * frameSegs - frameSegs --total number of verts minus last set
for l = 1 to loops do
(
if l < endCounter then --less then
(
append facesArr [l+1, l, l+count]
append facesArr [l+count , l+count+1 , l+1 ]
)else(
--only needed if planning on connecting start/end edges like a tube
endCounter += count --reset strip of verts
)
)
/*Set Mesh*/
platformMesh = setMesh mesh verts:verticesArr faces:facesArr
/*Dupe Meshes*/
local meshes = #()
for i = 1 to numDupes do
(
local newMesh = copy mesh
meshop.moveVert newMesh #{1..(newMesh.numverts)} [0,0,i*DupeDist]
append meshes newMesh
)
for m in meshes do
(
meshop.attach mesh m
free m
)
free meshes
/* Tube */
if enableTube do
(
local tub = createinstance Tube pos:[0,0,0] sides:8 heightsegs:20 capsegs:1 height:30 radius1:tubeRadius radius2:(tubeRadius/2) smooth:on
meshop.attach mesh tub.mesh
free tub
)
update mesh
)
on buildMesh do (genMesh())
tool create
(
on mousePoint click do ()
on mouseMove click do ()
)
)
delete objects
clearlistener()
m = IntegratedMesh()
m.vertexticks = true
select m
__________________
Bobo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment