Auto Vertex Normal average script

Hey folks,

I’m about to embark on my first Max script:

at the moment we have a character system where customisable parts are part of the same mesh but are separate elements. so the arms detach from the torso for example.

to hide the seem where this is happening I’ve been using the edit normals modifier to make the verts on the join point in the saamedirection (average selected).

What I’m about to script is a tool that will loop through the verts in a mesh and average the ones at the join.

I’ve seen some similar scripts but none of them seem to do this functionality.

So I thought I’d ask:

A) if people think this would be possible (it does look like you could do it from the max script help.)

B) Does any one have any advice or experience they’d like to share in how you’d go about doing this. (especially methods and functions as I’m new to max script)

Thanks for your time dudes.

Sounds like this should be very much doable, but with some headaches. Getting proper object space vertex normals from MaxScript is surprisingly non-trivial (without querying them via the Edit Normals modifier which slows things down a lot).

Have fun matching the “which vertices are the same” without things getting really slow on higher density meshes. Cache the vertex positions and don’t do a getVert for each vertex in every iteration. Optimize by only testing the elements where their bounding boxes overlap or with some more complex methods. Expect to have more than two vertices being the same at some locations. Smoothing groups (thus a vertex having more than one normal) will give you headache.

Sounds like a fairly complex thing if you’re new to MaxScript, but a wonderful learning experience (as if finding out why some things are hard to do in MaxScript… :slight_smile:

That being said, this sounds like a fun weekend thing to write. :slight_smile:

SamiV.

Cheers Sami, I’ll give it a shot based off your advice, you’ve pretty much confirmed any fears that I had about what would and wouldn’t be difficult.

Certainly is a tricky task for my first foray in Max script but I love jumping in the deep end, it’s kinda how I role.

fortunately we’re dealing with mobile level assets so our ver counts are pretty low always below 5K.

If any one else wants to add to this awesome advice please feel free the more Expertise I can get on this the better me thinks.

thanks again guys

Hi!
you could reduce the problem using this kind of passes (don’t know if appliable to your models):

-check for the border (detached edge loop in editPoly) for every submesh and store them as vertex indices
-find the right corrispondence between coupled borders in object sub-meshes
-for every coupled borders, find a common vertex
-find the average normal from the two vertices

in this way the real problems become:
1)find the coupling between the vertex borders
2)for every border couple find the coupled vertices

the 1) problem could be resolved (with some luck :slight_smile: ) checking the average position of all the border vertices and test the distances

the 2) problem could be easly resolved checking the distances between a vertex of a border with all the other vertices in the second border (when you find a couple, delete them from the arrays)

this is what I think in a 1 minute :slight_smile: if I find a better approach I’ll let you know.

Cheers Alessandro,

Looking into the edit normals modifier it has a threasold hold setting which I think might save me some time.

all I need to do from what I can see is grab all the vertex normals in an array some how then apply the average with the lowest threshold possible this would work for what we want.

I’ve only just started looking into the syntax for all this but its not immediately obvious how to index all the normals so I can use the average command on the entire Array.

Any Ideas what that would look like?

for the commands open the listener and see the ouput:

$.modifiers[#Edit_Normals].EditNormalsMod.Select #{1..24}
$.modifiers[#Edit_Normals].EditNormalsMod.Average useThresh:on threshold:14.4096

I’m not sure about your solution…try to create a box, convert to editPoly, add the EditNormal modifiers, select all the normal and do the average…I think it would not work for your needs…or maybe I’ve not understood you :slight_smile:

Cheers Alessandro,

I saw this, this is what made me ask how to get the vert norms from the slected object automatically.

$.modifiers[#Edit_Normals].EditNormalsMod.Select #{1…24}

the 1…24 in the brackets about only get put in there like that when you manually select the normals, I need to find the command to select them with max script instead.

Doing that way does seem to work for what I want so that should cover it for now, I will as I get better at max script update this to work as I originally intended by detecting the the open edges as you and Sami have both suggested.

I did this in the end and it seems to work

numNormals = $.modifiers[#Edit_Normals].EditNormalsMod.GetNumNormals ()

			$.modifiers[#Edit_Normals].EditNormalsMod.SetSelection #{1..numNormals}

			$.modifiers[#Edit_Normals].EditNormalsMod.Average useThresh:on threshold:0.1