View Full Version : using Mesh3DS
ghettotek
2003.03.06, 10:58 PM
i found what i think to be what the Mesh3DS.framework included with ppinter1's screen saver originated from, but i cant find any documentation on it. it loads the 3DS models fine, but they are all white. i tried my own custom models, and other models and they are all white, so its not a model problem. im hoping that ppinter1 could possibly help me out on this one :D , but thanks to anyone who can.
ppinter1
2003.03.07, 01:02 PM
:blink:
Whoa! I neatly missed this thread till just now... sorry about that.
The all-white meshes usually indicate you have yet to set up your lighting and texture states properly.
In other words, Mesh3DS will load a 3DS mesh but it's up to you to ensure the OpenGL state machine is prepared to display the mesh.
When I get home from work tonight, I'll post a link to a small demo program called Display3DS for Mac OS X that shows how to use the Mesh3DS framework painlessly. I'm 2 hours behind you GhettoTek, so check in around 22:00 EST.
Alternatively, the complete source code to the SpaceTime screen saver, Mesh3DS Framework and Display3DS demo program is available for a sawbuck ($10) via my website (http://p-squared.com) in case you're looking to extend the code for your own needs.
/p2
Mars_999
2003.03.07, 08:49 PM
Wouldn't the white models suggest you haven't setup normals? And texturing?
ghettotek
2003.03.07, 08:56 PM
everything else in the scene is textured fine. only the 3DS models are white.
Mars_999
2003.03.07, 09:56 PM
Originally posted by ghettotek
everything else in the scene is textured fine. only the 3DS models are white.
Ok but that still doesn't mean you have lighting done and you need to define a normal for each triangle on the model.
Here is some code I use to calculate normals
void Model::CalNormal(float *p1, float *p2, float *p3)
{
float a[3] = {0.0f};
float b[3] = {0.0f};
float result[3] = {0.0f};
float length = 0.0f;
a[0] = p1[0] - p2[0];
a[1] = p1[1] - p2[1];
a[2] = p1[2] - p2[2];
b[0] = p1[0] - p3[0];
b[1] = p1[1] - p3[1];
b[2] = p1[2] - p3[2];
result[0] = a[1] * b[2] - b[1] * a[2];
result[1] = b[0] * a[2] - a[0] * b[2];
result[2] = a[0] * b[1] - b[0] * a[1];
length = (float)sqrt(result[0]*result[0] + result[1]*result[1] + result[2]*result[2]);
glNormal3f(result[0]/length, result[1]/length, result[2]/length);
}
ghettotek
2003.03.07, 10:16 PM
ok but shouldnt textures show even if i dont have lighting enabled? they should still show even if i havent defined normals right? ive tried enabling/disabling different client states but nothing seems to work. also, it doesnt seem that Mesh3DS allows direct access to the vertecies of the models, although i could be mistaken.
Mars_999
2003.03.07, 10:32 PM
I have no experience with 3DS, I use .md2 models. If I remember right you need to setup lighting to render the model correctly? If I am wrong please correct me?? Also are you sending the vertex points to the glTexCoord2f()?
Here are some links that might be helpful? This one has some source code
http://www.gametutorials.com/CodeDump/CodeDump_Pg1.htm
Here the link for the tutorial on 3DS file loader
http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg4.htm
Hope this helps?
ppinter1
2003.03.07, 10:43 PM
Okay, download Display3DS (http://p-squared.com/Display3DS.dmg) for a simple example of how to call the Mesh3DS Framework.
I'm outta here till Monday... have a great weekend everyone!
/p2
ghettotek
2003.03.08, 01:34 AM
so the way it looks is i cant use a textured model unless i have lighting enabled when its drawn. what if i need a model to not be lit? is there a way around this or is that just how it is? either way, ill take it. thanks ppinter.
David
2003.03.08, 03:51 AM
lighting is not related to texturing.
Originally posted by Mars_999
...
length = (float)sqrt(result[0]*result[0] + result[1]*result[1] + result[2]*result[2]);
glNormal3f(result[0]/length, result[1]/length, result[2]/length);
...
i don't think you need to normalize your normals. they still point exactly in the same direction afterwards.
OneSadCookie
2003.03.08, 06:45 AM
If you're using lighting, you need to normalize your normals. If you're not using lighting, you probably don't need normals at all :p
ghettotek
2003.03.08, 01:02 PM
ok. if i dont enable lighting before i draw the model [Mesh3DS Display], then the model is all white. so there must be some relation between lighting and the texture on the models (not in OpenGL, but in the Mesh3DS framework). also, if i have GL_COLOR_MATERIAL enabled before i draw the model, its shaded..but its still white.
Mars_999
2003.03.10, 12:10 AM
I have been told you need to calculate the normals for every model, and then set up lighting depending on whether the vertices are pre-lit or not. Hope that helps?
ghettotek
2003.03.10, 01:00 AM
i dont think you get what im saying. i have no way of calculating normals because i cannot access the vertices in the model. all i can access is the model class' public methods. is there a way to automatically calculate normals for vertices drawn?
Mars_999
2003.03.10, 01:16 AM
Originally posted by ghettotek
i dont think you get what im saying. i have no way of calculating normals because i cannot access the vertices in the model. all i can access is the model class' public methods. is there a way to automatically calculate normals for vertices drawn? Not that I know of? But their isn't a function to return the vertices data? that seems like a poor design to me? Sorry I can't help any further!! :(
ppinter1
2003.03.10, 09:42 AM
Where to begin...
The version of Mesh3DS included with my SpaceTime screen saver has only latent support for textures (SpaceTime's sample meshes are not textured).
I have yet to test the code to:
- flip bitmap textures right-side up as the OS X coordinate system is opposite OpenGL's default
- handle mixed case texture filenames generically, both within and without resource bundles
Also, Mesh3DS does automatically compute both vertex and surface normals.
However, because only *materials* are currently supported, you need lighting enabled to see these (normalized) materials properly. It sounds like people are confusing materials with textures w.r.t. lighting.
Finally, key data structures such as vertex and shared surface lists are currently exposed (see the header file), but have only limited utility value once the mesh's displaylist is compiled.
I was thinking of deleting these structures during post-processing as they take up huge amounts of memory and only enable the ability to re-scale the meshes dynamically.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.