View Full Version : check the thickness of the mesh

02-14-2012, 08:46 PM

I would like to write a maxscript that calculates the thickness of the mesh and where it would be too thin it gives the face a color.
My idea for doing this would be to use the RayMeshGridIntersect and check the distance of every face with the intersectray.
I wonder how long it will take to do 100000 faces.

If somebody has other ideas on how to do this, just let me know.

Tomorrow i will make an example and post here.

02-15-2012, 09:20 AM

I made an example script with the intersectray from the maxscript help file for checking the thickness of a model. I do hope it is readable.

If someone has ideas to improve or optimize the script, just let know.

global vertex_color_array = #()
global face_index_VC = #()
global MaxDistance = 25 --mm
global dist_color = (240 / MaxDistance)
global theRef
global theTarget

fn initialisatie theRef =

global rm = RayMeshGridIntersect() --create an instance of the Reference Target
rm.free() --leeg het voxel grid en bouw daarna een grid op
global fastgridsize = (((theRef.numfaces / 250.0) + 2) as integer)
rm.initialize (if (fastgridsize<=500) then fastgridsize else 500)
rm.addNode theTarget --add the sphere to the grid
rm.buildGrid() --build the grid data (collecting faces into the grid voxels)
fn init_rmGRID_minus =
format "total vertexis are : %\n" theRef.numverts
for v = 1 to theRef.numverts do --go through all verts of the Geosphere
thePos = getVert theRef v --+ 0.0001--get the position of the vertex
thePosX = thePos[1]
thePosY = thePos[2]
thePosZ = thePos[3] - 0.00001
theNormal = -(getNormal theRef v) --get the normal of the vertex, reverse direction
thePos[3] = thePosZ

theHitsCount = rm.intersectRay thePos theNormal true
if theHitsCount != 0 then --if have hit anything...

theIndex = rm.getClosestHit()
theFace = rm.getHitFace theIndex
dist = rm.getHitDist theIndex
if dist > 0.0001 and dist < MaxDistance then
color_vertex = 255 - (dist * dist_color)
append vertex_color_array (color 255 color_vertex color_vertex)
append face_index_VC theFace
append vertex_color_array (color 255 255 255)
append face_index_VC theFace
--print "niks geraakt"

fn Vertex_Color_Assign =
count = face_index_VC.count
svc = meshop.setVertColor
for i = 1 to count do
x = getface theTarget face_index_VC[i] --get facenumber van het object
va = #{x[1],x[2],x[3]}
svc theTarget 0 va vertex_color_array[i]--3 punt vertex met kleur toekenning

fn Update_colormap =
update theTarget

delete objects
-------create test model
test = box length:50 width:100 height:50 lengthsegs:10 widthsegs:20 heightsegs:10
taps = taper amount:1.5 curve:0.18 primaryaxis:0
addmodifier test taps
theRef = snapshot test
theTarget = theRef
initialisatie theRef
t1 = timestamp()
init_rmGRID_minus ()
t2 = timestamp()
t3 = timestamp()
delete test

format "check distances : % sec\n" ((t2-t1) / 1000)
format "assign color : % sec\n" ((t3-t2) / 1000)

CGTalk Moderation
02-15-2012, 09:20 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.