WHAT?! You are a C++ programmer now, man! =).Quote:
Originally posted by ChuckB
g.reserve(1); //I like using 1 as first location...skip 0 pos.
Yes, that is essentially it =).
Z.
Printable View
WHAT?! You are a C++ programmer now, man! =).Quote:
Originally posted by ChuckB
g.reserve(1); //I like using 1 as first location...skip 0 pos.
Yes, that is essentially it =).
Z.
No. A group can hold more than one vector/face. So each group should hold it's own vector of vertices and vector of faces.
It seems that this is what you're trying, but the syntax is wrong.
struct GROUP {
string sName;
vector<VERTEX> v;
vector<FACE> f;
};
Yeah, I just assumed it was a typo, CB =).
Z.
Hi,
I have had time to work with this idea of loading a 3D model saved in the .OBJ format into vectors. I appreciate all of the input in this thread as it was most helpful. Here is my solution.
An .OBJ file will contain a 3D model consisting of several groups.
A 3D model may be a humanoid and the model consists of several groups such as a head, chest, left arm, etc. Each group is a mesh consisting of triangles. Each triangle of course consists of 3 verticies. Each vertex is a 3D point.
So, this code creates the structures needed to support this.
As the .OBJ file is read, the group name and number of faces (triangles) are provided before the actual data is presented. So,Code:typedef struct VERTEX //3D point
{
float x,y,z;
};
typedef struct TRIANGLE //a face with 3 vertices
{
VERTEX a,b,c;
};
typedef struct GROUP //part of a complete model
{
vector<TRIANGLE> t; //didn't know this was possible at first. :-)
};
Assume the 3D model in the OBJ file has two groups. Group 1 has 3 faces and group 2 has 4 faces...
I would use variables instead of the numbers inside the '( )' below.
So, I can resize the GROUP vector as required to accomodate many groups. I can resize the number of triangles per group as required...Code:
//this can be increased in size as the file is read
vector<GROUP> g(2); //two different groups
//this too can be dynamically resized
g[1].t.reserve(3); //group 1 has three faces or triangles
g[2].t.reserve(4); //group 2 has four faces or triangles
//demonstrates hard coding of one triangle or face
g[1].t[1].a.x = .5; //group 1, triangle 1, vertex 1
g[1].t[1].a.y = 0;
g[1].t[1].a.z = 0;
g[1].t[1].b.x = .5; //group 1, triangle 1, vertex 2
g[1].t[1].b.y = 0;
g[1].t[1].b.z = 0;
g[1].t[1].c.x = .5; //group 1, triangle 1, vertex 3
g[1].t[1].c.y = 0;
g[1].t[1].c.z = 0;
. . . etc.
I write this only to say this concepts works well and is easy to manage. It just took me a while reading this thread and programming to get it to work.
As always, thanks to all.
Regards,
ChuckB