Advertisement

3DS and normals

Started by September 10, 2005 08:44 AM
13 comments, last by BlackRyder 19 years, 5 months ago
i think i know what i am doing wrong.
vertex should have as much normals as the faces he is part of.
so everytime you draw a face you will have to put the normals that are related to that face.

example to calculat the normals if for face 1: i do

v_normal = face1Normal.
start testing neighbours

and for face 2 i do:
v_normal = face2Normal
start testing neioubours

and so on....

but what is the definition of neighbours faces?
any face that share the vertex in question.
Advertisement
if someone here is intrested the result code of our conversation is:

void Object::computeBlendedNormals(void){	unsigned int faceNum;			//Holds the current face num	Vector3D normal;				//Holds the current vertex blended normal.	Vector3D faceNormal;			//Holds the current face normal	unsigned int i;					//Loop index	Face face;						//Holds the current face.		for(faceNum=0;faceNum<face_list.size();faceNum++)	{		face = face_list[faceNum];		faceNormal = computeFaceNormal(face);				//compute for every vertex in the face its blended normal		for(i=0;i<3;i++)		{            normal = computeVertexBlendedNormal(face,faceNormal);			face.setNormal(i,normal);		}		face_list[faceNum]=face;	}}Vector3D Object::computeVertexBlendedNormal(unsigned int vertexNum,Vector3D &vNormal){	Face face;					//Holds the current tested faces    unsigned int faceNum;		//Holds the current face number that we test.	Vector3D faceNormal;		//Holds the current face normal	Vector3D blendNormal;		//Holds the result blended normal	for(faceNum=0;faceNum<face_list.size();faceNum++)	{		face = face_list.at(faceNum);		//if this is a neighbor face		if((face[0]==vertexNum)||(face[1]==vertexNum)||(face[2]==vertexNum))		{			faceNormal = computeFaceNormal(face);			if(vNormal.dotProduct(faceNormal)>=0.71)			{				blendNormal = vNormal+faceNormal;			}		}	}	blendNormal = blendNormal - vNormal;	//we added twice the normal of the vertex	blendNormal.normalize();	return blendNormal;}


if you found any bug in my code please report to me by email
or by typing it here

Regards
BlackRyder
The 3DS format does some interesting things, when exporting to it, it will frequently take 2 faces that share a vertex and make 2 instances of that vertex. This means if you normalize the combined normals, you wont get 1 nice smooth vertex normals, but 2 (or more) vertices in the same location with different normals.

I would advise not to use this format if you want smoothed/blended normals for shared verts (i'm currently in the transition of chaning formats myself).
as i figured it out it doesnt save 2 instances of the same vertex...
and i also got some great results from the 2 methods that i wrote...

This topic is closed to new replies.

Advertisement