iDevGames Forums
Drawing Lightwave Objects - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Drawing Lightwave Objects (/thread-7661.html)



Drawing Lightwave Objects - Wheatie - Jul 15, 2002 05:31 PM

I've seen plenty of code out there for loading lightwave .lwo's and got the 'lwobject' demo from the lightwave sdk working, but nowhere can I find actual code to draw the object in OpenGL. I gave it my best shot and came pretty close (I think) but had no luck. Anyone know of some sample code? Much appreciated.

Wheatie
Wheatie000@aol.com


Drawing Lightwave Objects - Nimrod - Jul 16, 2002 07:59 AM

I've never dealt with Lightwave models and unless there's something I don't know, how to draw them depends entirely on how you parse them and how you store them in memory.

If you can show some source code of the storage, e.g:
Code:
struct Tri
{
    int v[3];
};

// and so on for other stuff to do with mesh storage

just showing how you store the mesh data, then I can show you (hopefully) how to draw it with OpenGL.


Drawing Lightwave Objects - Wheatie - Jul 17, 2002 01:21 PM

Basically, what I did was take the lwobject application from the lightwave sdk, compiled it as a command-line tool, and then tried to add GLUT code to display the loaded model without any special features, like texturing. The structs for the object are:

typedef struct st_lwObject {
...
lwLayer * layer; /* linked list of layers */
...
}lwObject;

typedef struct st_lwLayer {
...
lwPointList point;
lwPolygonList polygon;
...
}lwLayer;

typedef struct st_lwPointList {
...
lwPoint *pt; /* array of points /*
...
}lwPointList;

typedef struct st_lwPolygonList {
...
lwPolygon *pol; /* array of polygons */
...
}lwPointList;

typedef struct st_lwPoint {
...
float pos[3];
...
}lwPoint;

typedef struct st_lwPolygon {
...
int nverts;
lwPolVert *v; /* array of vertex records */
...
}lwPolygon;

typedef struct st_lwPolVert {
...
int index; /* index into the point array */
...
}lwPolVert;

Sorry about the long code...Anyway, what I did to render the object was a for loop to go through all of the polygons, and then for each vertex, finding the index to that point in the lwPointList...Here is my display() function:

void display()
{
int i, k, n;
lwPoint *pt;
lwPolygon *pol;

glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View

glColor3f(0.5f,0.5f,1.0f);
for (i = 0; i < obj->layer->polygon.count; i++)
{
pol = &(obj->layer->polygon).pol[i];

for (k = 0; k < pol->nverts; k++)
{
/* point index, position */
n = pol->v[k].index;
pt[k] = obj->layer->point.pt[n];
}

glBegin(GL_QUADS); // Start Drawing A Quad
glVertex3f(pt[0].pos[0], pt[0].pos[1], pt[0].pos[2]);
glVertex3f(pt[1].pos[0], pt[1].pos[1], pt[1].pos[2]);
glVertex3f(pt[2].pos[0], pt[2].pos[1], pt[2].pos[2]);
glVertex3f(pt[3].pos[0], pt[3].pos[1], pt[3].pos[2]);
//glVertex3f(pt->pos[0], pt->pos[1], pt->pos[2]);
glEnd();
}

glutSwapBuffers();
}

Sorry for the long post.

Wheatie


Drawing Lightwave Objects - Wheatie - Jul 19, 2002 10:13 PM

After playing around with it some more, I finally got it drawing the way it should be. It had to with the model being freed before I got around to actually drawing it...Oops...Anyway, now I just have to figure out how to implement the other features of the lightwave objects, such as texturing, UV coordinates, etc. So it would be much appreciated if any of you had tips or examples of that instead. Thanks in advance.

Wheatie


Drawing Lightwave Objects - Carlos Camacho - Jul 20, 2002 01:16 AM

I have the LWO spec. What that help or do you have that already?


Drawing Lightwave Objects - Wheatie - Jul 20, 2002 02:30 PM

I have the lightwave sdk and working code for loading and drawing only the polygons of the model. I'm interested in finding code that can extract the texture information so that I could (theoretically) use the models in a game. Thanks anyway, though.

Wheatie
Wheatie000@aol.com