P3D File Format - ODOLV7: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
Line 2: Line 2:


===Overall===
===Overall===
  ''// uint unsigned integer 32bit''
  byte:    8 bits unsigned
  ''// word unsigned short integer 16bit''
  char:    8 bit ascii character
  // Note that potentically compressed arrays in these structures only have an known output length.
  char[]:  fixed length string
  // the decompressor therefore must work on infinite input length.
asciiz:  null terminated char string
  // see example decompression at end of document
  asciiz[]: fixed length null terminated
ulong:    unsigned integer 32bit. 4 bytes
ushort:  unsigned short integer 16bit 2 bytes
  float:    4 bytes


  '''struct''' ODOL
  Note that potentically compressed arrays in these structures only have an known output length.
  {
the decompressor therefore must work on infinite input length.
   '''char''' Signature[4]; ''//"ODOL"''
see example decompression at end of document
   '''uint''' Version;     ''// 7''
 
   '''uint''' LodCount;   '' // at least one''
===OdolStuct===
   '''struct''' Lod[LodCount]
struct ODOL
{
   char     Signature[4];     ''//"ODOL"''
   ulong    Version;          ''// 7''
  ulong    LodCount;         ''// at least one''
   LodStruct Lod[LodCount];
  ulong    ResolutionCount;  ''// same as LodCount''
  float    Resolution[ResolutionCount];
  byte      unknownBytes[24];
  float    offset[3];        ''// model offset (unknown functionality)
  ulong    mapIconColor;     ''// RGBA 32 color
  ulong    mapSelectedColor;  ''// RGBA 32 color
  ulong    unknownValue;
   float    bboxMinPosition[3]; ''// minimum coordinates of bounding box
  float    bboxMaxPosition[3]; ''// maximum coordinates of bounding box
  float    wrpModelOffset[3];  ''// offset value to apply when object is placed on a WRP
  float    offset2[3];        ''// another offset value (unknown functionality)
};
 
 
===LodStruct===
  LodStruct
   {
   {
    CompressedStruct
    {
     '''uint''' VerticesCount;
     '''uint''' VerticesCount;
     '''uint''' VerticesAttribs[VerticesCount]; ''// if > 255 then array is compresed
     '''uint''' VerticesAttribs[VerticesCount]; ''// if > 255 then array is compresed
    }
  ''  
  ''  
     '''uint''' VerticesCount; ''// again same value''
     '''uint''' VerticesCount; ''// again same value''
Line 60: Line 87:
     '''struct''' Proxi[ProxiCount];
     '''struct''' Proxi[ProxiCount];
   }; // end of lod
   }; // end of lod
'''uint''' ResolutionCount; ''// same as LODCount''
'''float ''' Resolution[ResolutionCount];
 
'''char''' unknownBytes[24];
 
'''float''' offset[3]; ''// model offset (unknown functionality)
 
'''uint''' mapIconColor; ''// RGBA 32 color
'''uint''' mapSelectedColor; ''// RGBA 32 color
 
'''uint''' unknownValue;
 
'''float''' bboxMinPosition[3]; ''// minimum coordinates of bounding box
'''float''' bboxMaxPosition[3]; ''// maximum coordinates of bounding box
 
'''float''' wrpModelOffset[3]; ''// offset value to apply when object is placed on a WRP
 
'''float''' offset2[3]; ''// another offset value (unknown functionality)
}; ''// end of ODOL;''


===Faces===
===Faces===

Revision as of 02:27, 6 January 2009

Template:unsupported-doc

Overall

byte:     8 bits unsigned
char:     8 bit ascii character
char[]:   fixed length string
asciiz:   null terminated char string
asciiz[]: fixed length null terminated
ulong:    unsigned integer 32bit. 4 bytes
ushort:   unsigned short integer 16bit 2 bytes
float:    4 bytes
Note that potentically compressed arrays in these structures only have an known output length.
the decompressor therefore must work on infinite input length.
see example decompression at end of document

OdolStuct

struct ODOL
{
  char      Signature[4];      //"ODOL"
  ulong     Version;           // 7
  ulong     LodCount;          // at least one
  LodStruct Lod[LodCount];
  ulong     ResolutionCount;   // same as LodCount
  float     Resolution[ResolutionCount];
  byte      unknownBytes[24];
  float     offset[3];         // model offset (unknown functionality)
  ulong     mapIconColor;      // RGBA 32 color
  ulong     mapSelectedColor;  // RGBA 32 color
  ulong     unknownValue;
  float     bboxMinPosition[3]; // minimum coordinates of bounding box
  float     bboxMaxPosition[3]; // maximum coordinates of bounding box
  float     wrpModelOffset[3];  // offset value to apply when object is placed on a WRP
  float     offset2[3];         // another offset value (unknown functionality)
}; 


LodStruct

  LodStruct
  {
    CompressedStruct
    {
    uint VerticesCount;
    uint VerticesAttribs[VerticesCount]; // if > 255 then array is compresed
    }
 
    uint VerticesCount; // again same value
    struct UVset[VerticesCount]; // if > 127 then array is compresed 
 
    uint VerticesCount; // again same value
    struct VerticesPosition[VerticesCount];
 
    uint VerticesCount; // again same value
    struct VerticesNormal[VerticesCount];
 
    float fvalue[12];  // unknown values // containts some max/min vertices positions and so far
 
    uint TexturesCount;
    char Textures[...]; // zero ended 'C' strings 'd','a','t','a','\','1','.','p','a','a','\0','d','a','t','a','\','2','.','p','a','a','\0'...
    //read until count of founded char('\0') equil TexturesCount;
 
    uint Table1stCount;
    word Table1st[Table1stCount];// if > 511 array compresed   
    uint Table2ndCount; // Table2ndCount is same value like VerticesCount
    word Table2nd[Table2ndCount];// > 511 then array is compresed
    //tables can by used to join vertices, each face has got 3 or 4 vertices that are seperated for each face in odol format
    //every vertex is owned only by 1 face
    //mlodvertexindex = Table1st[ Table2nd[ odolvertexindex ] ];
 
    uint FacesCount;
    uint uvalue;  // unknown value
    struct Face[FacesCount];
 
    uint uvalue2; // unknown value
    char uchar[18*uvalue2]; // unknown value
 
    uint NamedSelectionCount 
    struct NamedSelection[NamedSelectionCount]
 
    uint NamedPropetiesCount;
    struct NamedPropeties[NamedPropetiesCount]
 
    uint uvalue7;// unknown value ???
    struct ustruct[uvalue7]; // unknown value
 
    uint ProxiCount;
    struct Proxi[ProxiCount];
  }; // end of lod

Faces

  struct Face
    {
      uint Attribs;
      word TextureIndex; //if ((int)TextureIndex==-1) no texture;
      char CountOfVertices;  // 3 or 4
      word VerticesIndex[CountOfVertices]; //! size of array is not constant.
    };

NamedSelection

  struct NamedSelection
    {
      char name[...]; // zero ended string
 
      uint VerticesSelectedCount;
      word VerticesSelected[VerticesSelectedCount];// if VerticesSelectedCount > 511 then array is compresed by LZ algorithm. see LZ in ODOL.
 
      uint uvalue3; // unknown value
      word uarray[uvalue3];// unknown value
 
      uint uvalue4; // unknown value
      uint uarray[uvalue4];// unknown value // if VerticesSelectedCount > 255 then array is compresed by LZ algorithm. see LZ in ODOL.
 
      char uchar; // unknown value 
  
      uint uvalue5; // unknown value
      uint uarray[uvalue5];// unknown value
 
      uint FacesSelectedCount;
      word FacessSelected[FacesSelectedCount]// if FacesSelectedCount > 511 then array is compresed by LZ algorithm. see LZ in ODOL.
 
      uint uvalue6; // unknown value
      char uarray[uvalue6];// unknown value
    };

VerticesPosition

   struct VerticesPosition
    {
      float x,y,z;
    };

VerticesNormal

   struct VerticesNormal
    {
      float x,y,z;
    };

UVset

   struct UVset
    {
      float U,V;
    };

Proxi

  struct Proxi
    {
      char Name[...] // zero ended  string
      float rotationMatrix[9];
      float translation[3];
    };

ustruct

  struct ustruct // unknown value
    {
      uint uvalue8;// unknown value
      uint uvalue9;// unknown value
      char uarray[12*uvalue9];// unknown value :-( i know nothing about it
    };

NamedPropeties

  struct NamedPropeties
    {
      char Name[...];
      char Value[...]; // 'n','o','s','h','a','d','o','w','\0','1','\0'...
    };

LZ in ODOL

Lempel-Ziv compression

Note1.

Regardless of method, 4 extra bytes representing the checksum exist at end of the data count.

Note2. The compression code is identical to that employed by pbo packed structures. However, unlike pbo's, the size of the compressed data is unknown, only it's ultimate length. The code below fudges it.


pascal code

function LZBlockRead(var F:file; var outdata:array of byte;szout:integer):byte;
var
k, r, pr, pi,po,i,j:integer;
flags:word;
buf:array[0..$100e] of byte;
c:byte;
crc:integer;
begin
po:=0;
pi:=0;
flags:=0;
r:=0;
for k := 0 to $100F-1 do buf[k] := $20;
       while (po < szout) do
        begin
           flags:= flags shr 1;
           if ((flags and $100)= 0) then
               begin
                 BlockRead(F,c,1);   // direct reading from file
                 inc(pi);
                 flags := c or $ff00;
               end;
           if (flags and 1)=1 then
                begin
                  if (po >= szout)then break;
                  BlockRead(F,c,1);   // direct reading from file
                  inc(pi);
                  outdata[po] := c;
                  inc(po);
                  buf[r] := c;
                  inc(r);
                  r :=r and $fff;
                end
           else
                begin
                  i:=0;
                  BlockRead(F,i,1);  // direct reading from file
                  inc(pi);
                  j:=0;
                  BlockRead(F,j,1); // direct reading from file
                  inc(pi);
                  i :=i or ((j and $f0) shl 4);
                  j := (j and $0f) + 2;
                  pr := r;
                  for k := 0 to j do
                    begin
                      c := buf[(pr - i + k) and $fff];
                      if (po >= szout) then break;
                      outdata[po]:= c;
                      inc(po);
                      buf[r]:= c;
                      inc(r);
                      r :=r and $fff;
                    end;
             end;
       end;
     BlockRead(F,crc,4);   // 4 byte checksum.
     result:= pi;
end;

C code

int Decode(unsigned char *in,unsigned char *out,int szin,int szout)
{
       szin = szin > 0? szin: 0x7fffffff;
       int  i, j, k, r = 0, pr, pi = 0,po = 0;
       unsigned int  flags = 0;
       unsigned char buf[0x100F], c;
       for (i = 0; i < 0x100F; buf[i] = 0x20, i++);
       while (pi < szin && po < szout)
       {
               if (((flags >>= 1) & 256) == 0)
               {
                       if(pi >= szin)break;
                       c = in[pi++];
                       flags = c | 0xff00;
               }
               if (flags & 1)
               {
                       if(pi >= szin || po >= szout)break;
                       c = in[pi++];
                       out[po++] = c;
                       buf[r++] = c;
                       r &= 0xfff;
               } else
               {
                       if(pi + 1 >= szin)break;
                       i = in[pi++];
                       j = in[pi++];
                       i |= (j & 0xf0) << 4;
                       j  = (j & 0x0f) + 2;
                       pr = r;
                        for (k = 0; k <= j; k++)
                       {
                               c = buf[(pr - i + k) & 0xfff];
                               if(po >= szout)break;
                               out[po++] = c;
                               buf[r++] = c;
                               r &= 0xfff;
                       }
               }
       }
       return pi;// next 4 bytes = checksum
}

Related Page(s)

Model File Formats