PDA

View Full Version : Get vertex normal count


Pjanssen
02-05-2008, 06:19 PM
Is there any way to get the vertex normal count from an object in 3dsmax?

So far the only way I've found was through adding an edit_normal modifier. However, this only gave a proper result if the modifier tab was opened and the object selected.
As I want to use this in a loop, this is not at all a convenient method.

Thanks.

JHN
02-05-2008, 09:02 PM
As far as I can see, it would involve some serious looping over the faces to get their smoothing group and verts and compare per smoothing group how much verts it has and eventually count that..


/* from the manual */
fn getFaceSmoothGroupB obj face =
(
local sgroup_val = polyOp.getFaceSmoothGroup obj face
local sg_bitarray=#{}
if sgroup_val < 0 do
(
sg_bitarray[32]=true
sgroup_val -= 2^31
)
for i = 1 to 31 do
(
sg_bitarray[i]= (mod sgroup_val 2 > .5)
sgroup_val /= 2
)
sg_bitarray
)


lPoly = selection[1]
lVertCount = polyOp.getNumVerts lPoly
lVertNormArr = #() -- Vert nr + normals.count
lVertNormTotal = 0 -- Total normals

for i in 1 to lVertCount do
(
lFaces = polyOp.getFacesUsingVert lPoly i
lSmoothArr = #{}
for lFace in lFaces do
(
--format " % -" lFace
lFaceArr = getFaceSmoothGroupB lPoly lFace -- Get SmoothingGroups as bitarray
lSmoothArr = lSmoothArr + lFaceArr - (lSmoothArr * lFaceArr)
--lSmoothArr += lFaceArr -- Add Smoothinggroups to bitarray

if (lSmoothArr as array).count == 0 then
for i in 1 to (lFaces as array).count do lSmoothArr += #{i} --as bitarray

)
format "%\n" lSmoothArr
--format "\n"
lCount = (lSmoothArr as array).count
--format "%\n" lCount
append lVertNormArr lCount
lVertNormTotal += lCount

)
format "Total count: %\n" lVertNormTotal


This is as far as I got... it seems smoothinggroups and normals are 2 different things...
which seems logical... but there seems to be no way to check if a face with no smoothinggroups shares a normal or not...

I think the editnormals mod is your best bet... to bad you can't apply modifiers on a mesh in memory... It will be slow or you would need some dlx or something to work itout for you. IMHO there's no direct access to all the normals of a vert. But maybe a bigger scripter can add something I missed :)

-Johan

Pjanssen
02-05-2008, 09:11 PM
Yeah I thought of the comparing smoothing groups idea as well. This is something I basically did in my soft/hard edges script. But it will, as you say, be very cpu intensive. In fact, too cpu intensive for the thing I want to use it for. (an exporter that performs a number of checks on a bunch of objects)

Actually, I must say that I'd be seriously disappointed in 3dsmax and maxscript if vertex normals would not be exposed in a normal (no pun intended :p ) way...

JHN
02-05-2008, 09:27 PM
I don't know if it's gonna be very slow, my script runs pretty fast, depends on how much verts per object, since I'm getting only the faces per vertex, it's not doing anything redundant as far as I can tell. And it uses bitarrays those are fast too.

It's not for nothing they added a editNormal modifier in max8 (?) it was a much requested feature from game studio's if I recall correctly...

I think you'd better be starting to get really disappointed in maxscript maybe even as dissapointed as me when I discovered there's noway to run the simulate hair button from a script... that was a real downer... all properties exposed except for run... out off all things...

Yeah those are the times I'm jalously looking at maya.. everything exposed (allthough I heard that's not all true either.. but more exposed then maxscript anyway)....

-Johan

Pjanssen
02-05-2008, 09:38 PM
I don't know if it's gonna be very slow, my script runs pretty fast, depends on how much verts per object, since I'm getting only the faces per vertex, it's not doing anything redundant as far as I can tell. And it uses bitarrays those are fast too.
Well it is for game art, but still, the 'worst' case I've seen it used for was a scene with 200K+ tri's... And I know about the performance of maxscript by now, so I'm not too confident in huge loops through topology..
I will give it a try tomorrow nonetheless.


It's not for nothing they added a editNormal modifier in max8 (?) it was a much requested feature from game studio's if I recall correctly...
Was it honestly only in max8??
Man man, it feels like a leftover thing from times long gone by. And it's crap to use, since anything you do in it overrules smoothing group actions later on.
I think it'd be much more useful to have like a display toggle for it, just like in maya...


I think you'd better be starting to get really disappointed in maxscript maybe even as dissapointed as me when I discovered there's noway to run the simulate hair button from a script... that was a real downer... all properties exposed except for run... out off all things...

Yeah those are the times I'm jalously looking at maya.. everything exposed (allthough I heard that's not all true either.. but more exposed then maxscript anyway)....
-Johan
Yeah I must say that I sometimes wonder what those people at Autodesk are doing...no offence to anyone working there who's reading this of course. But damn, there are so many things that should be done so much better...
And of course a lot are fundamental and hard to chance, but man improvements are necessary. Better late than never eh.
Btw, just for the record: I'm neither max nor maya fan. I use both, and think both have their strenghts and weaknesses...

JHN
02-06-2008, 08:49 AM
The key words here are (i think) legacy and shareholders...

Maybe when mayax hits the streets all is fine until then, code on :)

-Johan

CGTalk Moderation
02-06-2008, 08:49 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.