Skip to main content
GameDev.net gamedev.net
🔒 Locked

Does MD2 contain normals? Where are they?

Started by zacaj Oct 18, 2008 at 5:40 PM 6 replies 1.9k views
Original Post
zacaj
zacaj
Ive been looking at various 3d model formats, and MD2 was the only one ive seen that doesnt use bones, so I thought Id try to load that. Ive got 2 books that teach you about loading it and ive found a good internet page, but none of them talk about applying lighting, or even loading the vertex normals from the MD2. Does MD2 contain vertex normals, and if so, where are they in the file?
swiftcoder
swiftcoder
Take a look at this tutorial. As you can see, each vertex has an index into a table of pre-calculated normals. The easiest way to get the normal table is to borrow the header containing the table from one of these tutorials ;)
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
zacaj
zacaj
So MD2 doesnt have normals in it? I know how I can compute normals, but Id assumed they were included in it...
DarkZoulz
DarkZoulz
As swiftcoder stated, there actually are normals in there. But they are saved as a index into a lookup table instead of the actual normal vector.

I believe they used this approach to save disk space.
zacaj
zacaj
So MD2 only has normal indices, and then theres a pre-computer model inspecific table of normals they reference to? Thats the only way I could understand the source code, but that doesnt make much sense...
fitfool
fitfool
static const float MD2_NORMAL_TABLE[162][3] = {	{-0.525731f, 0.000000f, 0.850651f},	{-0.442863f, 0.238856f, 0.864188f},	{-0.295242f, 0.000000f, 0.955423f},	{-0.309017f, 0.500000f, 0.809017f},	{-0.162460f, 0.262866f, 0.951056f},	{0.000000f, 0.000000f, 1.000000f},	{0.000000f, 0.850651f, 0.525731f},	{-0.147621f, 0.716567f, 0.681718f},	{0.147621f, 0.716567f, 0.681718f},	{0.000000f, 0.525731f, 0.850651f},	{0.309017f, 0.500000f, 0.809017f},	{0.525731f, 0.000000f, 0.850651f},	{0.295242f, 0.000000f, 0.955423f},	{0.442863f, 0.238856f, 0.864188f},	{0.162460f, 0.262866f, 0.951056f},	{-0.681718f, 0.147621f, 0.716567f},	{-0.809017f, 0.309017f, 0.500000f},	{-0.587785f, 0.425325f, 0.688191f},	{-0.850651f, 0.525731f, 0.000000f},	{-0.864188f, 0.442863f, 0.238856f},	{-0.716567f, 0.681718f, 0.147621f},	{-0.688191f, 0.587785f, 0.425325f},	{-0.500000f, 0.809017f, 0.309017f},	{-0.238856f, 0.864188f, 0.442863f},	{-0.425325f, 0.688191f, 0.587785f},	{-0.716567f, 0.681718f, -0.147621f},	{-0.500000f, 0.809017f, -0.309017f},	{-0.525731f, 0.850651f, 0.000000f},	{0.000000f, 0.850651f, -0.525731f},	{-0.238856f, 0.864188f, -0.442863f},	{0.000000f, 0.955423f, -0.295242f},	{-0.262866f, 0.951056f, -0.162460f},	{0.000000f, 1.000000f, 0.000000f},	{0.000000f, 0.955423f, 0.295242f},	{-0.262866f, 0.951056f, 0.162460f},	{0.238856f, 0.864188f, 0.442863f},	{0.262866f, 0.951056f, 0.162460f},	{0.500000f, 0.809017f, 0.309017f},	{0.238856f, 0.864188f, -0.442863f},	{0.262866f, 0.951056f, -0.162460f},	{0.500000f, 0.809017f, -0.309017f},	{0.850651f, 0.525731f, 0.000000f},	{0.716567f, 0.681718f, 0.147621f},	{0.716567f, 0.681718f, -0.147621f},	{0.525731f, 0.850651f, 0.000000f},	{0.425325f, 0.688191f, 0.587785f},	{0.864188f, 0.442863f, 0.238856f},	{0.688191f, 0.587785f, 0.425325f},	{0.809017f, 0.309017f, 0.500000f},	{0.681718f, 0.147621f, 0.716567f},	{0.587785f, 0.425325f, 0.688191f},	{0.955423f, 0.295242f, 0.000000f},	{1.000000f, 0.000000f, 0.000000f},	{0.951056f, 0.162460f, 0.262866f},	{0.850651f, -0.525731f, 0.000000f},	{0.955423f, -0.295242f, 0.000000f},	{0.864188f, -0.442863f, 0.238856f},	{0.951056f, -0.162460f, 0.262866f},	{0.809017f, -0.309017f, 0.500000f},	{0.681718f, -0.147621f, 0.716567f},	{0.850651f, 0.000000f, 0.525731f},	{0.864188f, 0.442863f, -0.238856f},	{0.809017f, 0.309017f, -0.500000f},	{0.951056f, 0.162460f, -0.262866f},	{0.525731f, 0.000000f, -0.850651f},	{0.681718f, 0.147621f, -0.716567f},	{0.681718f, -0.147621f, -0.716567f},	{0.850651f, 0.000000f, -0.525731f},	{0.809017f, -0.309017f, -0.500000f},	{0.864188f, -0.442863f, -0.238856f},	{0.951056f, -0.162460f, -0.262866f},	{0.147621f, 0.716567f, -0.681718f},	{0.309017f, 0.500000f, -0.809017f},	{0.425325f, 0.688191f, -0.587785f},	{0.442863f, 0.238856f, -0.864188f},	{0.587785f, 0.425325f, -0.688191f},	{0.688191f, 0.587785f, -0.425325f},	{-0.147621f, 0.716567f, -0.681718f},	{-0.309017f, 0.500000f, -0.809017f},	{0.000000f, 0.525731f, -0.850651f},	{-0.525731f, 0.000000f, -0.850651f},	{-0.442863f, 0.238856f, -0.864188f},	{-0.295242f, 0.000000f, -0.955423f},	{-0.162460f, 0.262866f, -0.951056f},	{0.000000f, 0.000000f, -1.000000f},	{0.295242f, 0.000000f, -0.955423f},	{0.162460f, 0.262866f, -0.951056f},	{-0.442863f, -0.238856f, -0.864188f},	{-0.309017f, -0.500000f, -0.809017f},	{-0.162460f, -0.262866f, -0.951056f},	{0.000000f, -0.850651f, -0.525731f},	{-0.147621f, -0.716567f, -0.681718f},	{0.147621f, -0.716567f, -0.681718f},	{0.000000f, -0.525731f, -0.850651f},	{0.309017f, -0.500000f, -0.809017f},	{0.442863f, -0.238856f, -0.864188f},	{0.162460f, -0.262866f, -0.951056f},	{0.238856f, -0.864188f, -0.442863f},	{0.500000f, -0.809017f, -0.309017f},	{0.425325f, -0.688191f, -0.587785f},	{0.716567f, -0.681718f, -0.147621f},	{0.688191f, -0.587785f, -0.425325f},	{0.587785f, -0.425325f, -0.688191f},	{0.000000f, -0.955423f, -0.295242f},	{0.000000f, -1.000000f, 0.000000f},	{0.262866f, -0.951056f, -0.162460f},	{0.000000f, -0.850651f, 0.525731f},	{0.000000f, -0.955423f, 0.295242f},	{0.238856f, -0.864188f, 0.442863f},	{0.262866f, -0.951056f, 0.162460f},	{0.500000f, -0.809017f, 0.309017f},	{0.716567f, -0.681718f, 0.147621f},	{0.525731f, -0.850651f, 0.000000f},	{-0.238856f, -0.864188f, -0.442863f},	{-0.500000f, -0.809017f, -0.309017f},	{-0.262866f, -0.951056f, -0.162460f},	{-0.850651f, -0.525731f, 0.000000f},	{-0.716567f, -0.681718f, -0.147621f},	{-0.716567f, -0.681718f, 0.147621f},	{-0.525731f, -0.850651f, 0.000000f},	{-0.500000f, -0.809017f, 0.309017f},	{-0.238856f, -0.864188f, 0.442863f},	{-0.262866f, -0.951056f, 0.162460f},	{-0.864188f, -0.442863f, 0.238856f},	{-0.809017f, -0.309017f, 0.500000f},	{-0.688191f, -0.587785f, 0.425325f},	{-0.681718f, -0.147621f, 0.716567f},	{-0.442863f, -0.238856f, 0.864188f},	{-0.587785f, -0.425325f, 0.688191f},	{-0.309017f, -0.500000f, 0.809017f},	{-0.147621f, -0.716567f, 0.681718f},	{-0.425325f, -0.688191f, 0.587785f},	{-0.162460f, -0.262866f, 0.951056f},	{0.442863f, -0.238856f, 0.864188f},	{0.162460f, -0.262866f, 0.951056f},	{0.309017f, -0.500000f, 0.809017f},	{0.147621f, -0.716567f, 0.681718f},	{0.000000f, -0.525731f, 0.850651f},	{0.425325f, -0.688191f, 0.587785f},	{0.587785f, -0.425325f, 0.688191f},	{0.688191f, -0.587785f, 0.425325f},	{-0.955423f, 0.295242f, 0.000000f},	{-0.951056f, 0.162460f, 0.262866f},	{-1.000000f, 0.000000f, 0.000000f},	{-0.850651f, 0.000000f, 0.525731f},	{-0.955423f, -0.295242f, 0.000000f},	{-0.951056f, -0.162460f, 0.262866f},	{-0.864188f, 0.442863f, -0.238856f},	{-0.951056f, 0.162460f, -0.262866f},	{-0.809017f, 0.309017f, -0.500000f},	{-0.864188f, -0.442863f, -0.238856f},	{-0.951056f, -0.162460f, -0.262866f},	{-0.809017f, -0.309017f, -0.500000f},	{-0.681718f, 0.147621f, -0.716567f},	{-0.681718f, -0.147621f, -0.716567f},	{-0.850651f, 0.000000f, -0.525731f},	{-0.688191f, 0.587785f, -0.425325f},	{-0.587785f, 0.425325f, -0.688191f},	{-0.425325f, 0.688191f, -0.587785f},	{-0.425325f, -0.688191f, -0.587785f},	{-0.587785f, -0.425325f, -0.688191f},	{-0.688191f, -0.587785f, -0.425325f},};
swiftcoder
swiftcoder
Quote:
Original post by zacaj
So MD2 only has normal indices, and then theres a pre-computer model inspecific table of normals they reference to? Thats the only way I could understand the source code, but that doesnt make much sense...
It lets them save a lot of space, at the expense of less accurate normals. For better lighting, you can always recalculate the normals manually from the model geometry.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.