Advertisement

MAXScript (MAX 9.0): Problems with getNormal function

Started by March 20, 2007 05:56 PM
0 comments, last by KamikazE AT 17 years, 10 months ago
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
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!

This topic is closed to new replies.

Advertisement