P3D File Format - ODOLV7: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{HashLink" to "{{Link")
 
(80 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{unsupported-doc}}
{{Feature|UnsupportedDoc}}
{{TOC|side}}
= General =


===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.
== Legend ==
the decompressor therefore must work on infinite input length.
see example decompression at end of document


===Odol7Stuct===
see [[Generic FileFormat Data Types]]
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
{
  '''    '''  VerticesStruct[...];
  '''float'''  fvalue[12];              ''// unknown: contains some max/min vertices positions''
  '''ulong'''  TexturesCount;
  '''Asciiz''' Textures[TexturesCount]; ''// "data/1.paa\0data/2.paa\0"...
  '''      ''' TableStruct[...];
  '''ulong'''  FacesCount;
  '''ulong'''  uvalue;                  ''// unknown''
  '''struct''' Face[FacesCount];
 
  '''ulong'''  uvalue2;                ''// unknown''
  '''byte'''  uchar[18*uvalue2];      ''// unknown valuea''
 
  '''    '''  NamedStruct[...];
 
  '''ulong''' uvalue7;                ''// unknown value ???
  '''struct''' ustruct[uvalue7];      ''// unknown value''
 
  '''ulong''' ProxiCount;
  '''struct''' Proxi[ProxiCount];
}; // end of lod


===VerticesStruct===
== CompressedStructures ==
  VerticesStruct
  {
    CompressedStruct Attribs
    {
    '''ulong''' Count;
    '''ulong''' Attribs[Count];    ''// if > 255 then array is compressed
    }
    CompressedStruct UVset
    {
    '''ulong''' Count;              ''// again same value''
    '''float''' UVset[Count];      ''// if > 127 then array is compressed
    }
    CompressedStruct Position
    {
    '''ulong''' Count;              ''// again same value''
    '''float''' Position[Count][3]; ''// XZY.  If > etc
    }
    CompressedStruct Normals
    {
    '''ulong''' Count;              ''// again same value''
    '''float''' Normals[Count][3];  ''// XZY. If > etc
    }
  }


===TableStruct===
(potentially) compressed arrays are endemic to most blocks contained in a p3d.
struct TableStruct
{
  CompressedStruct Table1
  {
  '''ulong'''  Count;
  '''ushort''' Table1[Count];''// if > 511 array compressed '' 
  }
  CompressedStruct Table2
  {
  '''ulong'''  Count;        ''// this Count is same value as any Vertices.Count''
  '''ushort''' Table2[Count];''// > 511 then array is compressed
  }
}


Tables are used to join vertices. Each face has got 3 or 4 vertices that are unique for each face Eg. Every vertex is owned only by 1 face.
<syntaxhighlight lang="cpp">
'''MLOD'''vertexindex = Table1[ Table2['''ODOL'''vertexindex] ];''
CompressedStruct
{
ulong Count;
<type> Array[Count];
};
</syntaxhighlight>


===NamedStruct===
if Count * sizeof(<type>) exceeds 1023 bytes the array is compressed. The '''resulting''' array will be expanded using lzh compression exactly as found in pbo's (for instance)
NamedStruct
{
  CompressedStruct Selection
  {
  '''ulong'''  Count;
  '''struct''' NamedSelection[Count];
  }
  CompressedStruct Properties
  {
  '''ulong''' Count;
  '''struct''' NamedPropeties[Count]
  }
}


After decompression, the Count remains the same because it is a count of the arraytype.


For uncompressed arrays (byte count < 1024) the Count and data are treated 'as is'.


====NamedSelection====
'''struct''' NamedSelection
{
  '''asciiz''' name;
  CompressedStruct Vertices
  {
  '''ulong'''  Count;                  ''// if > 511 then array is compressed
  '''ushort''' Vertices[Count];
  }
  CompressedStruct UnknownUshort
  {
  '''ulong'''  Count;                ''// if > 511 then array is compressed
  '''ushort'''  Unknown[Count];
  }
  CompressedStruct UnknownUlong
  {
  '''ulong''' Count;                    ''// if > 255 then array is compressed
  '''ulong''' Unknown[Count];
  }
  '''byte''' Unknown;
  CompressedStruct UnknownUlong2
  {
  '''ulong''' Count;                    ''// if etc
  '''ulong''' Unknown[Count];
  }
  CompressedStruct Faces
  {
  '''ulong''' Count;                    ''// if etc
  '''ushort''' Faces[Count];
  }
  CompressedStruct UnknownByte
  {
  '''ulong''' Count;                    ''// if etc
  '''byte''' Unknown[Count];
  }
};
===Faces===
  '''struct''' Face
    {
      '''ulong'''  Attribs;
      '''ushort''' TextureIndex; ''//if ((int)TextureIndex==-1) no texture;''
      '''byte'''  Count;  // 3 or 4
      '''ushort''' VerticesIndex[Count];'' //! size of array is not constant.''
    };
====CompressedStruct====


a compressed struct is such that if the Count * sizeof data type is > 1023 then lzh compression is used
Thus for various Array <types>
* ulong Array:    > 255  // 1024 /  sizeof(ulong)
* float thing[2]: > 127  // 1024 / 2*sizeof(float)
* SomeStructure:  >      // count * sizeof (SomeStructure) > 1023


Thus,
*ulong arrays = > 255
*float[2] = > 127
*etc


===Proxi===
Note that potentially compressed arrays in these structures only have an known output length. the decompressor therefore must work on infinite input length.
  '''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===
= Odol7Stuct =


''Lempel-Ziv compression
See [[P3D Model Info]].
<syntaxhighlight lang="cpp">
ODOLV7
{
StandardP3DHeader Header;
LodStruct Lods[Header.LodCount];
ModelInfo ModelInfo;
};
</syntaxhighlight>


Note1.


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


Note2.
<syntaxhighlight lang="cpp">
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.
StandardP3DHeader
{
char Signature[4]; //"ODOL" (vs MLOD eg)
ulong Version; // 7
ulong LodCount; // at least one
}
</syntaxhighlight>




==== pascal code====
== LodStruct ==


'''function''' LZBlockRead(var F:file; var outdata:array of byte;szout:integer):byte;
See:
'''var'''
* {{Link|#VertexTable}}
k, r, pr, pi,po,i,j:integer;
* {{Link|#Textures}}
flags:word;
* [[P3D Lod Edges]]
buf:'''array'''[0..$100e] '''of''' byte;
* [[P3D Lod Faces]]
c:byte;
* [[P3D Lod Sections]]
crc:integer;
* [[P3D Named Selections]]
'''begin'''
* {{Link|#NamedProperty}}
po:=0;
* [[P3D Lod Frames]]
pi:=0;
* [[P3D Lod Proxies]]
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)
<syntaxhighlight lang="cpp">
{
LodStruct
        szin = szin > 0? szin: 0x7fffffff;
{
        '''int'''  i, j, k, r = 0, pr, pi = 0,po = 0;
VertexTable VertexTable;
        '''unsigned int'''  flags = 0;
float UnknownFloat1;
        '''unsigned char''' buf[0x100F], c;
float UnknownFloat2;
        '''for''' (i = 0; i < 0x100F; buf[i] = 0x20, i++);
XYZTriplet MinPos;
        '''while''' (pi < szin && po < szout)
XYZTriplet MaxPos;
        {
XYZTriplet AutoCenterPos;
                '''if''' (((flags >>= 1) & 256) == 0)
float UnknownFloat3;
                {
Textures Textures;
                        '''if'''(pi >= szin)'''break''';
LodEdges LodEdges;
                        c = in[pi++];
ulong NoOfFaces;
                        flags = c | 0xff00;
ulong OffsetToLodSections;
                }
LodFace LodFaces[NoOfFaces]; // ie polygons
                '''if''' (flags & 1)
ulong nSections;
                {
LODSection LODSections[nSections];
                        '''if'''(pi >= szin || po >= szout)'''break''';
ulong nNamedSelections;
                        c = in[pi++];
NamedSelection NamedSelections[nNamedSelections];
                        out[po++] = c;
ulong nTokens;
                        buf[r++] = c;
NamedProperty NamedProperties[nTokens];
                        r &= 0xfff;
ulong nFrames;
                } '''else'''
Frame Frames[nFrames];
                {
ulong IconColor;
                        '''if'''(pi + 1 >= szin)'''break''';
ulong SelectedColor;
                        i = in[pi++];
ulong Unknown;
                        j = in[pi++];
ulong nProxies;
                        i |= (j & 0xf0) << 4;
LodProxy LodProxies[nProxies];
                        j  = (j & 0x0f) + 2;
};
                        pr = r;
</syntaxhighlight>
                        '''for''' (k = 0; k <= j; k++)
 
                        {
=== VertexTable ===
                                c = buf[(pr - i + k) & 0xfff];
 
                                '''if'''(po >= szout)'''break''';
See [[P3D Point and Face Flags]].
                                out[po++] = c;
<syntaxhighlight lang="cpp">
                                buf[r++] = c;
struct
                                r &= 0xfff;
{
                        }
ulong Count;
                }
ulong PointFlags[Count]; // compressed
        }
ulong Count;
        '''return''' pi;// next 4 bytes = checksum
UVPair UV1[Count]; // compressed
}
ulong Count;
XYZTriplet Points[Count]; // UNcompressed
ulong Count;
XYZTriplet Normals[Count]; // UNcompressed
}
</syntaxhighlight>
 
*Count is the same value for all four tables.
 
=== Textures ===
 
<syntaxhighlight lang="cpp">
struct
{
ulong Count;
asciiz Textures[...]; // "data/1.paa\0data/2.paa\0"...
}
</syntaxhighlight>
 
Count corresponds to the number of concatenated strings. It is required, since, architecturally at least, one of more of the asciiz strings could be null.
 
=== NamedProperty ===
 
<syntaxhighlight lang="cpp">
struct
{
Asciiz Property; // e.g "noshadow" = "1"
Asciiz Value;
}
</syntaxhighlight>
 
 
= Related Page(s) =
 
== LZ in ODOL ==
 
see [[Compressed LZSS File Format]]
 
[[BIS File Formats#3D Model File Formats|Model File Formats]]


=Related Page(s)=


[[BIS_File_Formats#3D_Model_File_Formats|Model File Formats]]
[[Category:BIS_File_Formats]]
[[Category:BIS_File_Formats]]

Latest revision as of 17:43, 4 January 2023

bi symbol white.png
Disclaimer: This page describes internal undocumented structures of Bohemia Interactive software.

This page contains unofficial information.

Some usage of this information may constitute a violation of the rights of Bohemia Interactive and is in no way endorsed or recommended by Bohemia Interactive.
Bohemia Interactive is not willing to tolerate use of such tools if it contravenes any general licenses granted to end users of this community wiki or BI products.

General

Legend

see Generic FileFormat Data Types


CompressedStructures

(potentially) compressed arrays are endemic to most blocks contained in a p3d.

CompressedStruct
{
	ulong	Count;
	<type>	Array[Count];
};

if Count * sizeof(<type>) exceeds 1023 bytes the array is compressed. The resulting array will be expanded using lzh compression exactly as found in pbo's (for instance)

After decompression, the Count remains the same because it is a count of the arraytype.

For uncompressed arrays (byte count < 1024) the Count and data are treated 'as is'.


Thus for various Array <types>

  • ulong Array: > 255 // 1024 / sizeof(ulong)
  • float thing[2]: > 127 // 1024 / 2*sizeof(float)
  • SomeStructure: > // count * sizeof (SomeStructure) > 1023


Note that potentially compressed arrays in these structures only have an known output length. the decompressor therefore must work on infinite input length.


Odol7Stuct

See P3D Model Info.

ODOLV7
{
	StandardP3DHeader	Header;
	LodStruct			Lods[Header.LodCount];
	ModelInfo			ModelInfo;
};


StandardP3DHeader

StandardP3DHeader
{
	char	Signature[4];	//"ODOL" (vs MLOD eg)
	ulong	Version;		// 7
	ulong	LodCount;		// at least one
}


LodStruct

See:


LodStruct
{
	VertexTable		VertexTable;
	float			UnknownFloat1;
	float			UnknownFloat2;
	XYZTriplet		MinPos;
	XYZTriplet		MaxPos;
	XYZTriplet		AutoCenterPos;
	float			UnknownFloat3;
	Textures		Textures;
	LodEdges		LodEdges;
	ulong			NoOfFaces;
	ulong			OffsetToLodSections;
	LodFace			LodFaces[NoOfFaces]; // ie polygons
	ulong			nSections;
	LODSection		LODSections[nSections];
	ulong			nNamedSelections;
	NamedSelection	NamedSelections[nNamedSelections];
	ulong			nTokens;
	NamedProperty	NamedProperties[nTokens];
	ulong			nFrames;
	Frame			Frames[nFrames];
	ulong			IconColor;
	ulong			SelectedColor;
	ulong			Unknown;
	ulong			nProxies;
	LodProxy		LodProxies[nProxies];
};

VertexTable

See P3D Point and Face Flags.

	struct
	{ 
	ulong		Count;
	ulong		PointFlags[Count];	// compressed
	ulong		Count;
	UVPair		UV1[Count];			// compressed 
	ulong		Count;
	XYZTriplet	Points[Count];		// UNcompressed
	ulong		Count;
	XYZTriplet	Normals[Count];		// UNcompressed
	}
  • Count is the same value for all four tables.

Textures

struct
{
ulong	Count;
asciiz	Textures[...]; // "data/1.paa\0data/2.paa\0"...
}

Count corresponds to the number of concatenated strings. It is required, since, architecturally at least, one of more of the asciiz strings could be null.

NamedProperty

struct
{
	Asciiz Property; // e.g "noshadow" = "1"
	Asciiz Value;
}


Related Page(s)

LZ in ODOL

see Compressed LZSS File Format

Model File Formats