- Joined
- Jun 15, 2009
- Messages
- 107
- Reaction score
- 37
So i was staring and trying for a while now and this is what i could come up with. Seems like it parses and loads pretty much all o3d files, but i still don't understand how it's animated.
Credits to Fatduck and Pipelli.
EDIT: update on material field (lightning)
EDIT: update2: figured float7, its an animation state struct. They are explicit, easy to apply. For example:
local animations seems to belong to the current lod.
Also, looks like its enough to load only 1 group of the lodGroups, the patchers Degree of object expression seems to choose one from these groups. (Or loads the first group if the rest doesnt exist). The highest res seems to be the first group, and the lowest is the last. (I guess that explains why setting Degree of object expression to low makes the game loading slower -.-)
Credits to Fatduck and Pipelli.
Code:
struct vector
{
float x,y,z;
};
struct quaternion
{
float a,b,c,d;
};
struct tAnimationState
{
quaternion rotateData; //rotation applied first
vector translateData; //translation applied second
};
template<bool hasbones>
struct loddata
{
int xcount;
int vtcount;
int fccount;
int fcsize;
vector xdata[ xcount ];
struct tvertex
{
vector pos; //translate this with translation matrix
if( hasbones )
{
float weight1;
float weight2;
short bone1;
short bone2;
}
vector normal;
float u,v;
}vertexes[ vtcount ];
struct tface
{
short a, b, c; //indexes to vertex array
}faces [ fccount ];
short unk1[ vtcount ];
int nUnk2;
int unk2[ nUnk2 ];
int unk3;
int matcount;
struct tMaterial
{
float lightAmbient[4]; //alpha is 0! has to be set to 1 explicitly
float lightDiffuse[4];
float lightSpecular[4];
int unk5[ 5 ];
int namelen;
char textureName [ namelen ];
};
tMaterial materials [ max(1, matcount) ]; //at least one
int matidcount;
struct tMatid //accociates materials to the faces
{
int startindex; //index to face array. (it's a raw index, so if you loaded structs, divide by 3!, this indexes the floats)
int count; //number of sequential faces to apply the material to (don't divide by 3, if you loaded structs. oh joy, this indexes the faces)
int matid; //index to materials
int unk1 [ 31 ];
} matids[ matidcount ];
};
//-------------------------------------------------------------------------------------------
// Beginning of file
//-------------------------------------------------------------------------------------------
byte strlen1;
char filename[strlen1]; //xor 0xCD
int version; //0x14, 0x15 or 0x16
unsigned int unk20; //checksum maybe?
vector element1Startpoint;
vector element1Endpoint;
if(version == 0x16)
{
vector element2Startpoint;
vector element2Endpoint;
}
int unk2_1;
int unk2_2;
char unk2[ 16 ]; //filename?
float xmin; //bounding box
float ymin;
float zmin;
float xmax;
float ymax;
float zmax;
float 0.5; //allways 0.5
int nAnimationStates; //number of animation states
int nUnk3;
vector data[ nUnk3 ];
//--Not visible lods, defineing the walkable areas-----------------------------------------------
int lod1count;
if(lod1count > 0)
{
struct tLod1
{
float transformationMatrix[ 16 ]; //only used if not null
loddata<false> data;
}lod1s[ lod1count ]; //usually have no texture specified, sometimes texture name is garbage
} //but even if its valid, it shouldn't be displayed. Its a bounding box thingie, sepcifieing the
//areas of the model wich cannot be walked through
int unk6;
//--Bone section-------------------------------------------------------------------------------
int nBones;
struct tbonedata1
{
float trans1[ 16 ];
float trans2[ 16 ];
}bonedata1[ nBones ];
struct tbonedata2
{
int namelen;
char bonename[ namelen ]; //bone name. usually "Bone1", "Bone2", etc
float trans1[ 16 ];
float trans2[ 16 ];
int some_index; //starts with -1, less than nBones
}bonedata2[ nBones ];
if(nBones > 0) //this is important
{
int nUnk3; //something animation maybe?
for(int j = 0; j < nUnk3; )
{
int unk5; //0 or 1 allways
if( unk5 != 0 )
{
tAnimationState globalAnimStates[ nAnimationStates ];
j += nAnimationStates; //increase counter here only
}else
{
//this branch (unk5 == 0) does NOT increase the counter
struct tbonedata16
{
float trans[ 16 ];
}bonedata16;
}
}
int unk6; //0 or 1 allways
if(unk6 == 0)
{
struct tbonedata17
{
float trans[ 16 ];
int unk7;
}bonedata17;
}
}
//--lods section-------------------------------------------------------------------------------
//struct for visible lods
struct tLod2
{
int flags; //some flags: hasbones = 1, allways_transparent = 0x80000000
int uknCount3; //indexes to external bone file?
int unk7[ uknCount3 ];
int lodIndex; //lodIndex = n for the nth lod
int lodlink; //index of lod wich modelview matrix should be loaded before animate/view the current lod (not to confuse with the translation matrix)
if(lodlink != -1)
{
if((lodlink == 0) && ((flags & 1) != 0)) //now im not sure about this
{
tAnimationState localAnimationStates1[ nAnimationStates ];
}
int m2;
}
float translationMatrix[ 16 ]; //only used if not null
float unk5[ 16 ]; //bounding box?
loddata< ((flags & 1) != 0) && (lodlink != 0) > data; //hasbones = (((flags & 1) != 0) && (lodlink != 0))
if((nAnimationStates > 0) && ((flags & 1) == 0))
{
int t6;
if(t6 != 0)
{
tAnimationStates localAnimationStates2[ BoneDataSize ];
}
}
};
int sumlod2count;
for(int i = 0; i < sumlod2count; )
{
struct lodGroup //each group contains the same model, but different primitive count
{
int lodcount;
tLod2 lod2s[ lodcount ];
} lg;
i += lg.lodcount;
}
//-------------------------------------------------------------------------------------------
// End of file
//-------------------------------------------------------------------------------------------
EDIT: update on material field (lightning)
EDIT: update2: figured float7, its an animation state struct. They are explicit, easy to apply. For example:
Code:
glTranslatef(
tAnimationState.rotatePositionX,
tAnimationState.rotatePositionY,
tAnimationState.rotatePositionZ);
glRotatef(
acos(tAnimationState.degrees) * 180 / pi,
tAnimationState.rotateX,
tAnimationState.rotateY,
tAnimationState.rotateZ);
glTranslatef(
-tAnimationState.rotatePositionX,
-tAnimationState.rotatePositionY,
-tAnimationState.rotatePositionZ);
local animations seems to belong to the current lod.
Also, looks like its enough to load only 1 group of the lodGroups, the patchers Degree of object expression seems to choose one from these groups. (Or loads the first group if the rest doesnt exist). The highest res seems to be the first group, and the lowest is the last. (I guess that explains why setting Degree of object expression to low makes the game loading slower -.-)
Last edited:

