Sign in to follow this  
KamikazE AT

MAXScript (MAX 9.0): Problems with getNormal function

Recommended Posts

KamikazE AT    122
Hello Everyone! I am trying to export vertex normals of an object into a simple custom ASCII format. Some relevant parts of the code:
> mesh = snapshotAsMesh objects[obj_idx]
> faceCount = getNumFaces mesh
>
> for idx = 1 to faceCount do
> (
>   coord_face = getFace mesh idx
>   for vidx = 1 to 3 do
>   (
>     vector = getNormal mesh coord_face[vidx]
>     format " n % % %" vector[1] vector[2] vector[3] to:file
>   )
> )
When I use my script to export the vertex normals of a cube I get strange results:
> // triangle 1
> v -5.0 -5.0 -5.0 n 0.0 0.0 -2.0
> v -5.0 5.0 -5.0 n 0.0 0.0 -1.0
> v 5.0 5.0 -5.0 n 0.0 0.0 -2.0
> // triangle 2
> v 5.0 5.0 -5.0 n 0.0 0.0 -2.0
> v 5.0 -5.0 -5.0 n 0.0 0.0 -1.0
> v -5.0 -5.0 -5.0 n 0.0 0.0 -2.0
> // triangle 3
> v -5.0 -5.0 5.0 n 0.0 0.0 2.0
> v 5.0 -5.0 5.0 n 0.0 0.0 1.0
> v 5.0 5.0 5.0 n 0.0 0.0 2.0
> <and so on..>
I also tried to export face normals and they were perfectly OK. Am I doing something wrong or is the internal vertex normal cache broken somehow? Anybody ever had similar problems with normals? Thx in advance for any comments! Martin

Share this post


Link to post
Share on other sites
KamikazE AT    122
Ok, I think I figured this one out myself :-)


> mesh = snapshotAsMesh objects[obj_idx]
> faceCount = getNumFaces mesh
>
> for idx = 1 to faceCount do
> (
> coord_face = getFace mesh idx
> for vidx = 1 to 3 do
> (
> normals = meshop.getFaceRNormals mesh idx
> vector = normals[vidx]
> format " n % % %" vector[1] vector[2] vector[3] to:file
> )
> )


Of course the array I implicitly accessed with getNormal contained
only 8 normals. one for each unique vertex in the model. The flat shaded
cube needs 3 different normals for each of the 8 unique vertices.

Exactly these normals can be accessed by the meshop.getFaceRNormals( )
function. YES! :-)

Greetz!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this