|
|
This thread is locked; no one can reply to it.
|
1
2
|
| Quick Question about 3D model format |
|
Dario ff
Member #10,065
August 2008
|
Trying to load up a an specific 3D binary model, and I'm having some trouble with face-reading. Only documentation I got is that the faces are supposed to be read as strips, and that I should read the last reference point of the last face every time I read a new reference point and create a new face. But I thought faces are supposed to be created with only 3 indices? How could I possibly create one from 2 reference points? The face indices are just unsigned short ints in big endian. TL;DR;, how do you read faces indices as strips and create the appropiate faces in a format like (index 1, index 2, index 3)? TranslatorHack 2010, a human translation chain in a.cc. |
|
Arthur Kalliokoski
Member #5,540
February 2005
|
I think they mean you only read in one new vertex and use the previous two vertices as the other two points for a face, hence the term strip. I really admire the U.S. Constitution. It's so much better than what we have now. |
|
verthex
Member #11,340
September 2009
|
Dario ff said: TL;DR;, how do you read faces indices as strips and create the appropiate faces in a format like (index 1, index 2, index 3)? I always thought the indices were completely arbitrary and its up to the programmer to decide what they are. But you have to be consistent once you choose your coordinate frame.
|
|
gnolam
Member #2,030
March 2002
|
Dario ff said: But I thought faces are supposed to be created with only 3 indices? How could I possibly create one from 2 reference points?
As you said: they're strips - a list of connected triangles/quads, so you keep track of the last couple of vertices. For a triangle strip for instance, a new triangle is created from each vertex after the first two. -- |
|
Dario ff
Member #10,065
August 2008
|
Ok so according to your answers, the following code should work I think... 1 unsigned short int face_1=0;
2 unsigned short int face_2=0;
3 unsigned short int face_3=0;
4
5 for (int i=0; i<face_count; i++) {
6 face_3 = face_2;
7 face_2 = face_1;
8
9 fread(&face_1, sizeof(unsigned short int), 1, fp);
10 face_1 = _byteswap_ushort(face_1);
11
12
13 if (i==2) base_indices.push_back(Ogre::Vector3(face_1, face_2, face_3));
14 else if (i > 2) {
15 Ogre::Vector3 overt(face_1, face_2, face_3);
16 base_indices.push_back(overt);
17 }
18 }
But it looks like this: Perhaps...
EDIT: It's supposed to be some kind of tree. TranslatorHack 2010, a human translation chain in a.cc. |
|
verthex
Member #11,340
September 2009
|
What is it supposed to look like a squid?
|
|
gnolam
Member #2,030
March 2002
|
If you're creating triangles out of triangle strips yourself, note that odd and even triangles have different vertex orderings (to keep a CW/CCW order). -- |
|
Arthur Kalliokoski
Member #5,540
February 2005
|
These short ints are indices to x, y, z floating point numbers? Could you post the vertex list? I really admire the U.S. Constitution. It's so much better than what we have now. |
|
Dario ff
Member #10,065
August 2008
|
Arthur Kalliokoski said: Could you post the vertex list? Vertex list, Faces list(in the order of the binary file) Here's how the vertices(or is it vertexes? EDIT: The "65535" face index is probably a 0 that I just endian swapped. TranslatorHack 2010, a human translation chain in a.cc. |
|
Arthur Kalliokoski
Member #5,540
February 2005
|
I'm playing with it, I think the 65535 is just a marker to start a new strip. I really admire the U.S. Constitution. It's so much better than what we have now. |
|
Dario ff
Member #10,065
August 2008
|
I think you might be on to something. But perhaps I just need to add a new face at the end of each strip? 1 unsigned short int face_1=0;
2 unsigned short int face_2=0;
3 unsigned short int face_3=0;
4
5 int new_strip=3;
6
7 for (int i=0; i<face_count; i++) {
8 unsigned short int t=0;
9 fread(&t, sizeof(unsigned short int), 1, fp);
10 t = _byteswap_ushort(t);
11 if (t == 65535) {
12 new_strip = 3;
13 }
14 else {
15 new_strip -= 1;
16
17 face_3 = face_2;
18 face_2 = face_1;
19 face_1 = t;
20
21 if (new_strip==0) {
22 Ogre::Vector3 overt(face_3, face_2, face_1);
23 base_indices.push_back(overt);
24 new_strip = 1;
25 }
26 }
27 }
TranslatorHack 2010, a human translation chain in a.cc. |
|
Arthur Kalliokoski
Member #5,540
February 2005
|
I got this far with it, but Blender barfs on it. I was assuming vertex winding wouldn't matter (I don't remember where the setting is). You've already got something showing so I'll stop now. I really admire the U.S. Constitution. It's so much better than what we have now. |
|
Trent Gamblin
Member #261
April 2000
|
Just looking at the model, it might be what gnolam said, the triangles alternate ccw and cw so every second one is getting culled. If eating hotdogs is wrong, I don't wanna be right. |
|
Arthur Kalliokoski
Member #5,540
February 2005
|
If it's OpenGL you could do I really admire the U.S. Constitution. It's so much better than what we have now. |
|
Dario ff
Member #10,065
August 2008
|
Indeed it seems to be... when I enable the 2-sided faces on Ogre it looks like this: How do I fix the winding problem? Swap the indices order at every odd/even index? Forcing culling off is not really the right way to do it. TranslatorHack 2010, a human translation chain in a.cc. |
|
Paul whoknows
Member #5,081
September 2004
|
Are you using Ogre? still working with Allegro5? ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
|
gnolam
Member #2,030
March 2002
|
Dario ff said: How do I fix the winding problem? Swap the indices order at every odd/even index? Yes. [EDIT] -- |
|
Arthur Kalliokoski
Member #5,540
February 2005
|
This page has a bit to say about it just past halfway down. You might have to rewrite the data in a different order to ship with the game or whatever. I really admire the U.S. Constitution. It's so much better than what we have now. |
|
Trent Gamblin
Member #261
April 2000
|
|
Dario ff
Member #10,065
August 2008
|
Yeah I fixed it with just switching faces around every odd sub-index(as in, index from the last strip). Thanks a lot. {"name":"605564","src":"http:\/\/static.allegro.cc\/image\/cache\/b\/8\/b80c5ee4220d1d8e154c41f553a87b4c.png","w":713,"h":663,"tn":"http:\/\/static.allegro.cc\/image\/cache\/b\/8\/b80c5ee4220d1d8e154c41f553a87b4c"} Another model. TranslatorHack 2010, a human translation chain in a.cc. |
|
Steve Terry
Member #1,989
March 2002
|
See attachment ___________________________________ |
|
Dario ff
Member #10,065
August 2008
|
8mb of Goatsee? EDIT: Mr. Potato head in A4. TranslatorHack 2010, a human translation chain in a.cc. |
|
Arthur Kalliokoski
Member #5,540
February 2005
|
Steve Terry said: See attachment I tried some of the examples with my OBJ loader, the space shuttle example didn't have a mtl file, the triceratops had more than 4 vertices for a face, and when the f5e_05 example had 3 texture vertices I gave up. [EDIT] If I clean them up by running them through Blender they work. {"name":"605568","src":"http:\/\/static.allegro.cc\/image\/cache\/9\/7\/9789eafdcc5469610f0a17f72ee90ba1.png","w":1000,"h":800,"tn":"http:\/\/static.allegro.cc\/image\/cache\/9\/7\/9789eafdcc5469610f0a17f72ee90ba1"} I really admire the U.S. Constitution. It's so much better than what we have now. |
|
Steve Terry
Member #1,989
March 2002
|
Don't know what you are talking about, all loaded by my utility just fine. ___________________________________ |
|
gnolam
Member #2,030
March 2002
|
Arthur Kalliokoski said: I tried some of the examples with my OBJ loader, the space shuttle example didn't have a mtl file, the triceratops had more than 4 vertices for a face, and when the f5e_05 example had 3 texture vertices I gave up.
All of which are perfectly legal for an OBJ. (Well, I'm only pretty sure about the first (it's been a while since I did anything with my OBJ loader). The latter two are definitely legal, though - faces can have any number of vertices, and 3D textures are supported.) -- |
|
|
1
2
|