Notifications
Clear all

[Closed] Problem exporting vertex normals

Hi!

I recently wrote a model exporter for 3DS where the output format look like this:

HEADER

f [1, 3, 4]
f [5, 4, 2]

v [1.3, 4.5, 9.2] n [0, 0, -1]
v [9.1, 1.2, 3.3] n [0, -1, 0]

Where the n [x, y, z] would represent the normal of each vertex, which I can get by the method getNorm at each vertex index. But as I can understand from 3DS each vertex does not only have one normal per vertex.

Since the vertices is combined by the face table, the normals will be shared by the vertices and resulting in a incorrect lightning.

8 Replies
 PEN

I did this by setting smoothing groups instead of loading vertex normals. This way I’m only writting out an integer value for each face.

Could you please explain what a smoothing group is and how it work?

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

In short, 3D Studio (both the DOS version where the 3DS format came from and Max) do not use explicit vertex normals by default (Max can use explicit normals, but this was added later).

The idea is this: Face normals are there always, as the normalized cross product of two edges. So we have face normals for free. Smoothing groups are flags (stored as bits in a 32 bit long integer) which define whether the edge between two faces is smoothed of not. Max does a pass to generate vertex normals by comparing the smoothing group flags of the faces. Where two faces do not share a smoothing group, the face normal will be used for the corresponding vertex, resulting in flat shading and sharp edge shading. Where two faces share one or more smoothing groups, the vertex will interpolate a normal based on the face normals and the influence (area) of each face. This way, the faces store the info about how implicit vertex normals should be calculated from implicit face normals, and all it takes is one 32 bit integer per face and no multiple normals per vertex to store. (back in 1990, memory and disk space weren’t cheap ;))

I just tried to calculate the normals within my importer with the cross product, in order to achieve the normals i did like this: CrossProduct(v2 – v1, v3 – v1); but still some, but only a few normals has a incorrect direction.

I obviously picked the wrong vertex order, it should be CrossProduct(v2 – v1, v3 – v2);

Damn, it worked atleast once!?

 PEN

Why not just store the smoothing group and use it to set the smoothing? What are you gaining by storing the vert normals and then calculating the smoothing group your self?

I think I need a concrete example of the use of smoothing groups, that would solve my headache