Sign in to follow this  

3DS model reader

This topic is 3297 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have written a 3DS model reader. While it works fine and draws my models I am having problems calculating normals for each vertex. I understand that I need a normal for each vertex that is an average of all the facet normals around it. The problem is that 3DS Max 2009 exports 32 vertices for a 1x1x1 cube with only 1 segment each side. It seems that it is exporting 3 vertices for each facet, e.g. rather than having vertex 0 in facet 0, 4 and 5, it will export the same vertex 3 times for the 3 different facets. The reason that this is a problem is that I can't keep track of the number of connections at each vertex without checking every single vertex every to see if they are the same.
//Done for each facet
connections[facet[i][0]]++;
connections[facet[i][1]]++;
connections[facet[i][2]]++;

*normals[facet[i][0]] += *meshFacet[i]->normal;
*normals[facet[i][1]] += *meshFacet[i]->normal;
*normals[facet[i][2]] += *meshFacet[i]->normal;

for (int i=0; i<vertexCount; i++) {
	*normals[i] /= connections[i];
}	

Is what I have at the moment but each vertex has only 1 connection rather than 3 or 4 like it should have. Is this some setting in Max for the exporter or am I going to have to change the code? Thanks.

Share this post


Link to post
Share on other sites
You could either write your own exporter in Max using MaxScript (google around), find the hidden checkbox (if it exists....i dunno), scrub the data at load time (not recommended), or write your own tool to scrub the 3DS file to convert it to a more natural format for your game.

-me

Share this post


Link to post
Share on other sites
Couln't the reason be that this is how it ensures that normals are not averaged? I mean, if vertices were shared among faces, so would also be normals and the normals would be averaged by programs loading it (this is a guess, at least this is how I were told to do in order to create 'hard edges').

Share this post


Link to post
Share on other sites
It could be a positive difference with the previous versions, just like cignox1 said.
I built a 3DS loader too and the only big problem I have is that shared vertices will end up with averaged normals and that looks really bad on my scene:



So maybe they took a look at this issue and decided to duplicate the vertices for future normal computation.

Share this post


Link to post
Share on other sites
As far as I'm aware, the Smoothing Groups in max dictate the use of shared vertices on export. Make a cube, put every face into one smoothing group, and it should export with only 8 vertices, which will of course allow for averaged normals in your implementation.

So yes, 32 vertices is correct for a cube with no smoothing turned on. If you want different behaviour, fire up the Max SDK Docs and write an exporter. There's a 3DS exporter example in there somewhere.

Share this post


Link to post
Share on other sites
Do I need to have average normals for each vertex or could I just use the facet normal?

Also I think the reason it was exporting 32 vertices was that there was also 32 texture coordinates.

Share this post


Link to post
Share on other sites

This topic is 3297 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this