Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / .OBJ Loader doesn't work correctly?

Author
Message
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 11th Feb 2012 07:18
Hey everyone!

I've been working on an OBJ loader using the Matrix1Utils library, and I thought I had it figured out... but for some reason it's not loading the model correctly, instead it seems like it's only drawing a few triangles out of the whole thing.

Here's the code, and the media will be included in a download. BTW, don't mind the extra DLL in there and such... I also used that media for another game in another language (and the DLLs were memory management functions I wrote).


Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 11th Feb 2012 17:14 Edited at: 11th Feb 2012 18:06
Quote: "MAKE OBJECT NEW objectNum, f_cnt * 3, f_cnt * 3, FVF_XYZ || FVF_NORMAL || FVF_TEX2"


Shouldn't one f_cnt*3 be vertex count and the other index_count?

EDIT:
There's something you did wrong ->you set the faces and at the same time you set the vertices and somewhere in that process you messed up. Here is corrected version where vertices are set first and then faces.



Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 11th Feb 2012 21:21
Thanks! Though the reason I tried what I did in the first place is because I'm not sure the normals and texture coordinates perfectly match up to the vertices in the file. Also, if you take it out of wireframe mode you may notice that it's all one big green glob when it should actually be a finely textured object(the texture is repeated on the object).
DarkDISCUSSION
15
Years of Service
User Offline
Joined: 6th Jul 2011
Location: Ft Madison, IA
Posted: 11th Feb 2012 22:02
Did you ever fix it?

Monsters are Ready to spill their Dark Sercrets......
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 11th Feb 2012 22:05
Quote: "you may notice that it's all one big green glob when it should actually be a finely textured object"

you used FVF_TEX2 fvf format so only the 2nd layer is shown(which doesn't contain uv coords). Use FVF_TEX1 and it will work

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 11th Feb 2012 23:49
Oh! I thought with FVF_TEXn the n represented the number of dimensions of the texture! Thanks
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 16th Feb 2012 03:51 Edited at: 16th Feb 2012 04:01
Hey all!

I noticed there was an issue with the texture not showing up correctly. That was because the UVs weren't matching the polygons correctly. Then I used a value of 0 for the Index, and Number_of_triangles * 3 for the vertex value and it worked. My question is does the index automatically get populated with each set of 3 vertices automatically then? In answer to your question DarkDISCUSSIONS, it did get fixed but I am just trying to learn more about how it works under the hood.

Sorry for the constant questions, I'm just curious.
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 16th Feb 2012 11:03
Quote: " My question is does the index automatically get populated with each set of 3 vertices automatically then?"

no, everything needs to be populated manualy

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 16th Feb 2012 18:02
Quote: "no, everything needs to be populated manualy"

Hmmm... How does it work with just vertices then? I'd figure it would create all the vertices, automatically create the corresponding indices with each vertex, and create the object that way. Either way, though, it works nicely. Thank you guys for all your help!
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 16th Feb 2012 22:50
Quote: "How does it work with just vertices then?"

I don't exactly understand what do you mean by this.
You need to fill vertex buffer with vertices and then index buffer with indices and thats it.

Quote: "automatically create the corresponding indices with each vertex"

What exactly do you mean by this. The same way you filled vertices you need to fill indices.

But of course, objects can be made just out of vertices (with no indices), but rendering of those objects is slower and i don't know if you can make such an object with Matri1Utils dll

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 17th Feb 2012 05:13
This code works when you specify index count as 0, but have the vertex count be a multiple of 3 (because there's 3 verts for each face):

Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 17th Feb 2012 05:30
then you messed up something with the indices. You can leave it to use only vertices if it works ok, but as i said earlier, the rendering of such objects is a little slower than rendering of objects with indices. The difference is more obvious on the objects with lots of vertices and polygons. If you're gone use only low poly objects you can leave it as it is.

Login to post a reply

Server time is: 2026-07-09 23:12:14
Your offset time is: 2026-07-09 23:12:14