Example #1
0
int Load3ds::CompileObjects()
{
#ifdef GRAPHICS_DEBUG
	FILE* file = NULL;
	file = fopen("normals.out", "w+");
	assert( file );
#endif

	int j = 0;
	TVector3<float> position, normal;
	TVector2<float> texCoord;

	// the number of faces * 3: 3 indices per face
	for (int i = 0; i < mModelData->mFaceCount * 3; i+=3)
	{
		mMesh->addTriangleIndices(mModelData->mFaces[ i ], 
			mModelData->mFaces[i + 1], mModelData->mFaces[i + 2]);
	}

	// set up all the information: position, normal and eventually
	// the texture coordinates, and compile them into our TVertex class
	for (int i = 0; i < mModelData->mVertexCount; i++)
	{
		j = i * 3;

		position.setX( mModelData->mVertices[ j ] );
		position.setY( mModelData->mVertices[j + 1] );
		position.setZ( mModelData->mVertices[j + 2] );

		normal.setX( mModelData->mNormals[ j ] );
		normal.setY( mModelData->mNormals[j + 1] );
		normal.setZ( mModelData->mNormals[j + 2] );

#ifdef GRAPHICS_DEBUG
		fprintf(file, "%i: X: %f, Y: %f, Z: %f\n", i, normal.x(), normal.y(), 
			normal.z());
#endif

		if ( mModelData->mContainsTexCoords )
		{
			// stride: one face -> 2 texture coordinates
			j = i * 2;

			texCoord.setX( mModelData->mTexCoords[ j ] );
			texCoord.setY( mModelData->mTexCoords[j + 1] );
		}

		mMesh->addVertex( TVertex(normal, position, texCoord) );
	}

#ifdef GRAPHICS_DEBUG
	fclose( file );
#endif

	return 1;
}