PDA

View Full Version : from lws to cpp



teoteo
01-29-2006, 03:46 AM
Hi,
i recently went to lightwave. I am searching for a way to convert a 3D animation made through the Ligthwave into .cpp arrays for using them with Opengl. I dont want to use plugin as i program in linux.

Cheers,Theo.

Lightwolf
01-29-2006, 04:20 AM
Hi,
i recently went to lightwave. I am searching for a way to convert a 3D animation made through the Ligthwave into .cpp arrays for using them with Opengl. I dont want to use plugin as i program in linux.

I'm afraid you will need to write your own parser to import LW objects and scenes.
http://www.newtek.com/lightwave/developers.php

Cheers,
Mike

RedBull
01-31-2006, 02:51 AM
Yeah i'm not sure on the scene files, but you can convert .lwo files to .cpp OGL code without a problem...

I just tried it on a simple box, and it works no okay.

struct sample_MATERIAL{
GLfloat ambient[3];
GLfloat diffuse[3];
GLfloat specular[3];
GLfloat emission[3];
GLfloat alpha;
GLfloat phExp;
int texture;
};

static sample_MATERIAL materials [2] = {
{{0.0f,0.0f,0.0f}, {0.635294f,0.690196f,0.933333f}, {0.0f,0.0f,0.0f}, {0.0f,0.0f,0.0f}, 1.0f,8.0f,-1}, //Default
{{0.0f,0.0f,0.0f}, {0.196078f,0.0901961f,0.784314f}, {0.0f,0.0f,0.0f}, {0.0f,0.0f,0.0f}, 1.0f,8.0f,-1} //Surface
};

// 8 Verticies
// 0 Texture Coordinates
// 6 Normals
// 12 Triangles

static BYTE face_indicies[12][9] = {
// Object #0
{3,1,0 ,0,0,0 ,0,0,0}, {3,2,1 ,0,0,0 ,0,0,0}, {1,4,0 ,1,1,1 ,0,0,0},
{1,5,4 ,1,1,1 ,0,0,0}, {2,5,1 ,2,2,2 ,0,0,0}, {2,6,5 ,2,2,2 ,0,0,0},
{7,2,3 ,3,3,3 ,0,0,0}, {7,6,2 ,3,3,3 ,0,0,0}, {4,3,0 ,4,4,4 ,0,0,0},
{4,7,3 ,4,4,4 ,0,0,0}, {5,7,4 ,5,5,5 ,0,0,0}, {5,6,7 ,5,5,5 ,0,0,0}
};
static GLfloat vertices [8][3] = {
{-0.5f,-0.362069f,-0.231034f},{0.5f,-0.362069f,-0.231034f},{0.5f,0.362069f,-0.231034f},
{-0.5f,0.362069f,-0.231034f},{-0.5f,-0.362069f,0.231034f},{0.5f,-0.362069f,0.231034f},
{0.5f,0.362069f,0.231034f},{-0.5f,0.362069f,0.231034f}
};
static GLfloat normals [6][3] = {
{0.0f,0.0f,-1.0f},{0.0f,-1.0f,0.0f},{1.0f,0.0f,0.0f},
{0.0f,1.0f,0.0f},{-1.0f,0.0f,0.0f},{0.0f,0.0f,1.0f}
};
GLfloat textures[1][2]={{0.0f,0.0f}};
/*Material indicies*/
/*{material index,face count}*/
static int material_ref [4][2] = {
{0,2},
{1,2},
{0,6},
{1,2}
};
void MyMaterial(GLenum mode,GLfloat *f,GLfloat alpha)
{
GLfloat d[4];
d[0]=f[0];
d[1]=f[1];
d[2]=f[2];
d[3]=alpha;
glMaterialfv (GL_FRONT_AND_BACK,mode,d);
}
/*
* SelectMaterial uses OpenGL commands to define facet colors.
*
* Returns:
* Nothing
*/

void SelectMaterial(int i)
{
//
// Define the reflective properties of the 3D Object faces.
//
glEnd();
GLfloat alpha=materials[i].alpha;
MyMaterial (GL_AMBIENT, materials[i].ambient,alpha);
MyMaterial (GL_DIFFUSE, materials[i].diffuse,alpha);
MyMaterial (GL_SPECULAR, materials[i].specular,alpha);
MyMaterial (GL_EMISSION, materials[i].emission,alpha);
glMaterialf (GL_FRONT_AND_BACK,GL_SHININESS,materials[i].phExp);
glBegin(GL_TRIANGLES);

};

GLint Gen3DObjectList()
{
int i;
int j;

GLint lid=glGenLists(1);
int mcount=0;
int mindex=0;
glNewList(lid, GL_COMPILE);

glBegin (GL_TRIANGLES);
for(i=0;i<sizeof(face_indicies)/sizeof(face_indicies[0]);i++)
{
if(!mcount)
{
SelectMaterial(material_ref[mindex][0]);
mcount=material_ref[mindex][1];
mindex++;
}
mcount--;
for(j=0;j<3;j++)
{
int vi=face_indicies[i][j];
int ni=face_indicies[i][j+3];//Normal index
int ti=face_indicies[i][j+6];//Texture index
glNormal3f (normals[ni][0],normals[ni][1],normals[ni][2]);
glTexCoord2f(textures[ti][0],textures[ti][1]);
glVertex3f (vertices[vi][0],vertices[vi][1],vertices[vi][2]);
}
}
glEnd ();

glEndList();
return lid;
};