Advertisement

3 normals per polygon

Started by March 14, 2003 12:16 PM
4 comments, last by Heineken 21 years, 11 months ago
hey, i wanted to create an object with cel shading like nehe''s tutorial 37. i''m using a quake2 model and calculate my own normals. it was all going ok untill i realized i needed 3 normals per polygon. how do i calculate those normals? or how do i get them from the md2 file? there''s this struct: struct tMd2AliasTriangle { byte vertex[3]; byte lightNormalIndex; }; but i don''t know what to do with the lightNormalIndex... ok, danny heineken
Eh? I haven''t looked at the actual lesson code but by just looking at what you''ve posted, lightNormalIndex looks to be a index to an array which holds the face normal. Pretty much the same thing for vertex except it holds all 3 indices for the triangle.
Advertisement
I think people normally just calculate the normals from the model based on the vertex data. I dont think the lightnormalindex value is normally used.
i''ve found that a good way to calculate vertex normals is to calculate the normal for every triangle in which each vertex is a member and average them together to get the normal value you use for those vertices.

example.

take any vertex
find all the triangles it is used in(by using the indices list)
calculate the normals for each of those triangles
average the normals together
normalize your result
save that as your normal for the vertex
loop to next vertex

i find it hard to believe, tho that the md2 file format does not include normal vectors. that''s kind of a crucial component to a 3D model and it''s not so cheap to nicely calculate them each time you load the file. but then i''ve never used those model formats so i don''t really know. i guess if quake2 didn''t have dynamic lighting it would make sense. i don''t remember if it does....

-me
yeah!
that''s gotta work,
why didn''t i think of that...
i think the normals are also in the file, but i can''t find them now and i don''t really care
thanks!
danny heineken
quote:
Original post by Palidine
i find it hard to believe, tho that the md2 file format does not include normal vectors. that's kind of a crucial component to a 3D model and it's not so cheap to nicely calculate them each time you load the file.


Well i had to redo the normals every frame in that way becuse of my skeletal animations. (i have worked around that now)
It really didn't effect my fps to much.

But normals take alot of file space, about 150K per 1000 polygons so calcylating those at loading time is a good idea


and you should probobly remember that q2 md2's have around 200 frames of animation.

[edited by - lc_overlord on March 15, 2003 10:25:53 AM]

This topic is closed to new replies.

Advertisement