Archived

This topic is now archived and is closed to further replies.

lightwave file format

This topic is 5813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone have experience with the lwo file format? I can find and use the vetices data in the file but I can''t seem to find u and v co-ords for images/textures. Can anyone explain. I''m using LW 5.6

Share this post


Link to post
Share on other sites
Thanks for the reply. I was looking at these docs a couple of days ago, and the best I seem to find here is:

Location and Size
TSIZ, TCTR, TFAL, TVEL { vector[VEC12] }
These sub-chunks each consist of a vector for the current texture''s size, center, falloff, or velocity. If missing, the center, falloff and velocity are assumed to be zero. The size should always be specified for any texture.

It seems like the center of the texture might be what I looking for, but I don''t know how this relates to u and v, which is what I''m familiar with. Any suggestions.

Do other 3D apps use the u and v or is the above standard fare?

Share this post


Link to post
Share on other sites
So let me clarify, LW 6.0 and after stores u and v for each vertex whereas pre 6.0 uses some algorithm based on the center or velocity/falloff and size of a texture?

It seems like it might be difficult to calculate the u and v based on the available data in the .lwo

Does Milkshape store u and v per vertex?

Share this post


Link to post
Share on other sites
heres my code for loading lightwave objects into my model structure
    
const int TAG_VMAP = 1447903568;
const int TAG_PTAG = 1347699015;
const int TAG_VMAD = 1447903556;
const int TAG_CLIP = 1129072976;
const int TAG_BLOK = 1112297291;
const int TAG_IMAG = 1229799751;
const int TAG_SURF = 1398100550;
const int TAG_FLAG = 1179402567;
const int TAG_TAGS = 1413564243;
const int TAG_LAYR = 1279351122;
const int TAG_PNTS = 1347310675;
const int TAG_BBOX = 1111641944;
const int TAG_TXUV = 1415075158;

int fvalue;
float * fpointer;
fpointer=(float *)&fvalue;
//int TriTexOffsetIndices[NUMTRIANGLES][3];

MyString text;
fseek(F1,0,SEEK_SET);
if (getrw(F1)==1179603533)//FORM

{
MyString Tags[50];
int ChunkSize=getrw(F1);
int FormType=getrw(F1);
int NumSurf;
long TagLength;
if (getrw(F1)!=TAG_TAGS)
{
Error=1;
return(0);
}
TagLength = getrw(F1);
NumSurf=0;
while (ftell(F1) < TagLength + 20)
getString(F1,&Tags[NumSurf++]);

if (getrw(F1)!=TAG_LAYR)
{
Error=1;
return(0);
}
fseek(F1,getrw(F1),SEEK_CUR);
if (getrw(F1)!=TAG_PNTS)
{
Error=1;
return(0);
}
Model->NumVert = getrw(F1)/12;
Model->NumFrame = 1;
Model->AllocateMemory();
Model->FrameNumbers[0][0]=0;

for(x=0;x<Model->NumVert;x++)
{
fvalue = getrw(F1);
Model->Vert[x].FrameV[0].x=*fpointer;
fvalue = getrw(F1);
Model->Vert[x].FrameV[0].z=*fpointer;
fvalue = getrw(F1);
Model->Vert[x].FrameV[0].y=*fpointer;
}
if (getrw(F1)!=TAG_BBOX)
{
Error=1; //Word BBOX

return(0);
}
fseek(F1,getrw(F1),SEEK_CUR);
long VMAPPos[5];
long VMADPos[5];
int VMAPCnt;
int VMADCnt;
VMAPCnt=0;
while (getrw(F1)==TAG_VMAP)
{
VMAPPos[VMAPCnt++] = ftell(F1);
fseek(F1,getrw(F1),SEEK_CUR);
}
fseek(F1,-4,SEEK_CUR);

getrw(F1); //WORD POLS

int PolSize = getrw(F1);
int TriProp;
getrw(F1); //WORD FACE

Model->NumTri = (PolSize-4)/8;
Model->AllocateMemory();
for (x=0;x<Model->NumTri;x++)
{
TriProp = (getc(F1) << 8) + getc(F1);
Model->Tri[x].Tri[0] = (getc(F1) << 8) + getc(F1);
Model->Tri[x].Tri[1] = (getc(F1) << 8) + getc(F1);
Model->Tri[x].Tri[2] = (getc(F1) << 8) + getc(F1);
}
long PolyTag;
if (getrw(F1)!=TAG_PTAG)
{
Error=1;
return(0);
}
PolyTag = ftell(F1) + 4;
fseek(F1,getrw(F1),SEEK_CUR);

// long ptagend = getrw(F1)+ftell(F1);

// getrw(F1); //WORD SURF


VMADCnt=0;
while (getrw(F1)==TAG_VMAD)
{
VMADPos[VMADCnt++] = ftell(F1);
fseek(F1,getrw(F1),SEEK_CUR);
}
fseek(F1,-4,SEEK_CUR);


int TextureNum;
int TextureIndex[5];
while (getrw(F1)==TAG_CLIP)
{
getrw(F1); //Length of Clip chunk

TextureNum = getrw(F1);
getrw(F1); //STIL

getc(F1);
getc(F1);

getString(F1,&Model->TexturePath[TextureNum-1]);
TextureIndex[TextureNum-1] = TexH.GenerateTexture(Model->TexturePath[TextureNum-1],"",0);
}
fseek(F1,-4,SEEK_CUR);

while (getrw(F1)==TAG_FLAG)
{
fseek(F1,(getc(F1) << 8) + getc(F1),SEEK_CUR);
}
fseek(F1,-4,SEEK_CUR);

long NextSurf;
MyString SurfName;
MyString SourceName;
int SurfTex;
int SurfID;
int lVert;
int y,z;
float uval,vval;
int VMAPSize;
int VMADSize;
int TriNum;
int PntNum;
int n;
int lTri;
int TagIndex;
MyString VMAPTex;
while (getrw(F1)==TAG_SURF)
{
NextSurf = getrw(F1) + ftell(F1);
getString(F1,&SurfName);
getString(F1,&SourceName);
while ((getrw(F1)!=TAG_BLOK) && (ftell(F1)<NextSurf))
{
fseek(F1,(getc(F1) << 8) + getc(F1),SEEK_CUR);
}
if (ftell(F1)<NextSurf)
{
getc(F1); //Move past Blok Length bytes

getc(F1);
while (getrw(F1)!=TAG_IMAG)
{
fseek(F1,(getc(F1) << 8) + getc(F1),SEEK_CUR);
}
getc(F1);
getc(F1);
SurfID = (getc(F1) << 8) + getc(F1);
SurfTex = TextureIndex[SurfID-1];
for (x=0;x<NumSurf;x++)
if (SurfName==Tags[x])
break;
TagIndex = x;
fseek(F1,PolyTag,SEEK_SET);
getrw(F1);
for (x=0;x<Model->NumTri;x++)
{
lTri = (getc(F1) << 8) + getc(F1);
if (TagIndex==((getc(F1) << 8) + getc(F1)))
{
Model->Tri[lTri].TriTexturePointer = SurfTex;
}
}
// for (n=0;n<VMAPCnt;n++)

{
fseek(F1,VMAPPos[SurfID-1],SEEK_SET);
VMAPSize = getrw(F1); //VMAP SIZE

getrw(F1); //Word TXUV

int TextureLen = (getc(F1) << 8) + getc(F1); //Equals 2

getString(F1,&VMAPTex);
VMAPSize-=(ftell(F1) - VMAPPos[SurfID-1]+4);
VMAPSize/=10;
for (x=0;x<VMAPSize;x++)
{
lVert = (getc(F1) << 8) + getc(F1);
fvalue = getrw(F1);
uval=*fpointer;
fvalue = getrw(F1);
vval=*fpointer;
for (y=0;y<Model->NumTri;y++)
if (Model->Tri[y].TriTexturePointer==SurfTex)
for (z=0;z<3;z++)
if (Model->Tri[y].Tri[z]==lVert)
{
Model->Tri[y].TriTexVerts[z][0] = uval;
Model->Tri[y].TriTexVerts[z][1] = vval;
}

}
}
}
fseek(F1,NextSurf,SEEK_SET);
}

for (n=0;n<VMADCnt;n++)
{
fseek(F1,VMADPos[n],SEEK_SET);
VMADSize = getrw(F1); //VMAP SIZE

getrw(F1); //Word TXUV

int TextureLen = (getc(F1) << 8) + getc(F1); //Equals 2

getString(F1,&Model->TexturePath[0]);
VMADSize-=(ftell(F1) - VMADPos[n]+4);
VMADSize/=12;
for (x=0;x<VMADSize;x++)
{
PntNum = (getc(F1) << 8) + getc(F1);
TriNum = (getc(F1) << 8) + getc(F1);
for (y=0;y<3;y++)
{
if (Model->Tri[TriNum].Tri[y]==PntNum)
{
fvalue = getrw(F1);
Model->Tri[TriNum].TriTexVerts[y][0] = *fpointer;
fvalue = getrw(F1);
Model->Tri[TriNum].TriTexVerts[y][1] = *fpointer;
break;
}
}
if (y==3)
{
getrw(F1);
getrw(F1);
}
}
}

}
fclose(F1);
return(1);



//Two functions i created

int getrw(FILE * F1)
{
unsigned int w;
w = (getc(F1) << 24) + (getc(F1) << 16) + (getc(F1) << 8) + getc(F1);
return(w);
}

void getString(FILE * F1, MyString * name)
{
int x;
int cnt;
unsigned char lname[80];
cnt=0;
while (x=getc(F1))
{
lname[cnt]=x;
cnt++;
}
lname[cnt]=0;
*name=lname;
if (((float)cnt/2) == (int)(cnt/2))
getc(F1);
}




I spent 10 hours programming this, so I'll expect a check for 165$ in the mail in a couple days.



Edited by - Xanthen on January 12, 2002 2:46:43 PM

Share this post


Link to post
Share on other sites