Intermidiate – 01 Build Mesh in maxscript

This is a small script that creates a cylindrical mesh without any capping directly from maxscript… this can be a good testbench if you want to try to make your own custom mesh.

It is easy to get confused with the numbering of the polys and the order in which you create them… but it is very important to get that correct since it is the order in which you create the poly that defines which way it is facing… so you probably end up with a flipped face if you do it in the wrong direction..

/*
Created by Anton Berg - OgmaSoul3D 
www.os3d.se

This small script creates a cylinder without any capping...

this is a useful testbench for people trying to program their
own custom objects...
*/

delete $DeleteMe*

heightSegs = 25
totalHeight = 180.0
sides = 36
VertArray =#()
heightPerSeg = (totalHeight / heightSegs)
radius = 20.0
count = 1

for z = 0 to heightSegs do (

	for i = 1 to sides do (
		TheVal = 360/sides
		xpos = cos(theVal * i) * radius --(radius * sin (z*5)) 
		ypos = sin(theVal * i) * radius
		zpos = heightPerSeg * z
		VertArray[count] = [xpos,ypos,zpos]
		count += 1
		)

)

undo off -- Turn OFF Undo for polygon creation
(
	mm = mesh numverts:VertArray.count name:"DeleteMe"
	for v = 1 to VertArray.count do (
		meshop.setvert mm v vertArray[v]
	)

	for hs = 0 to (heightSegs-1) do (
	--format "=== heightseg: %\n" hs 	

	for side = 1 to (sides) do (

			x0 = side
			x1 = side +1
			y0 = hs * (sides )
			y1 = (hs+1)*(sides )

			if side == (sides) then (
		--		format "\n"
				x1 -= (side) 

				--this is neccecary since we want to set the last 
				--poly in every segemt to connect to the first vertex again
			)

			--format " %  -- POLY %  %  %  %   \n" side (x0 + y0) (x1+y0) (x1 + y1) (x0 + y1) 
			meshop.createPolygon mm #( (x0 + y0), (x1+y0), (x1 + y1), (x0 + y1) ) 
		)
	)

	update mm
)--end undo off