Drawing Lightwave Objects

Wheatie
Unregistered
 
Post: #1
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
Quote this message in a reply
Nimrod
Unregistered
 
Post: #2
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.
Quote this message in a reply
Wheatie
Unregistered
 
Post: #3
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
Quote this message in a reply
Wheatie
Unregistered
 
Post: #4
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
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #5
I have the LWO spec. What that help or do you have that already?

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
Wheatie
Unregistered
 
Post: #6
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  3ds–OBJ/Lightwave Barclay 2 2,782 Apr 23, 2006 01:26 PM
Last Post: bodini
  openGL 2d drawing problems, objects appear to overlap matthew 12 5,649 Oct 5, 2003 07:53 PM
Last Post: matthew
  drawing objects in openGL, plane question. xDexx 7 5,525 Apr 28, 2003 01:06 PM
Last Post: OneSadCookie
  Lightwave character animation Wheatie 5 3,672 Mar 25, 2003 10:02 PM
Last Post: Wheatie
  how can i use a lightwave object in openGL? zeoworld 4 4,447 Feb 1, 2003 03:16 PM
Last Post: henryj