P3D File Format - ODOLV7: Difference between revisions

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


===Overall===
''// uint unsigned integer 32bit''
''// word unsigned short integer 16bit''
'''struct''' ODOL
  {
  '''char''' Signature[4]; ''//"ODOL"''
  '''uint''' Version;    ''// 7''
  '''uint''' LodCount;  '' // at least one''
  '''struct''' Lod[LodCount]
  {
    '''uint''' VerticesCount;
    '''uint''' VerticesAttribs[VerticesCount]; ''// if VerticesCount > 255 then array is compresed by LZ algorithm. see LZ in ODOL.
''
    '''uint''' VerticesCount; ''// again same value''
    '''struct''' UVset[VerticesCount]; ''// if VerticesCount > 127 then array is compresed by LZ algorithm. see LZ in ODOL.
''
    '''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 Table1stCount > 511 then array is compresed by LZ algorithm. see LZ in ODOL.''
 
    '''uint''' Table2ndCount; ''// Table2ndCount is same value like VerticesCount''
    '''word''' Table2nd[Table2ndCount];''// if Table2ndCount > 511 then array is compresed by LZ algorithm. see LZ in ODOL.
    //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
'''uint''' ResolutionCount; ''// same as LODCount''
'''float ''' Resolution[ResolutionCount];
.
.
. ''// folows some unknow data.''
}; ''// end of ODOL;''


===Faces===
== Legend ==
  '''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===
see [[Generic FileFormat Data Types]]
    '''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''
      '''struct''' ustruct {...};''// size same as char[56]; // unknown value''
    };


===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===
== CompressedStructures ==


''Lempel-Ziv compression
(potentially) compressed arrays are endemic to most blocks contained in a p3d.


Note1.
<syntaxhighlight lang="cpp">
CompressedStruct
{
ulong Count;
<type> Array[Count];
};
</syntaxhighlight>


Rregardless of method, 4 extra bytes representing the checksum exist at end of the data 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)


Note2.
After decompression, the Count remains the same because it is a count of the arraytype.
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.


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


==== pascal code====


'''function''' LZBlockRead(var F:file; var outdata:array of byte;szout:integer):byte;
Thus for various Array <types>
'''var'''
* ulong Array:   > 255  // 1024 sizeof(ulong)
k, r, pr, pi,po,i,j:integer;
* float thing[2]: > 127 // 1024 / 2*sizeof(float)
flags:word;
* SomeStructure: >      // count * sizeof (SomeStructure) > 1023
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)
Note that potentially compressed arrays in these structures only have an known output length. the decompressor therefore must work on infinite input length.
{
 
        szin = szin > 0? szin: 0x7fffffff;
 
        '''int'''  i, j, k, r = 0, pr, pi = 0,po = 0;
= Odol7Stuct =
        '''unsigned int'''  flags = 0;
 
        '''unsigned char''' buf[0x100F], c;
See [[P3D Model Info]].
        '''for''' (i = 0; i < 0x100F; buf[i] = 0x20, i++);
<syntaxhighlight lang="cpp">
        '''while''' (pi < szin && po < szout)
ODOLV7
        {
{
                '''if''' (((flags >>= 1) & 256) == 0)
StandardP3DHeader Header;
                {
LodStruct Lods[Header.LodCount];
                        '''if'''(pi >= szin)'''break''';
ModelInfo ModelInfo;
                        c = in[pi++];
};
                        flags = c | 0xff00;
</syntaxhighlight>
                }
 
                '''if''' (flags & 1)
 
                {
== StandardP3DHeader ==
                        '''if'''(pi >= szin || po >= szout)'''break''';
 
                        c = in[pi++];
<syntaxhighlight lang="cpp">
                        out[po++] = c;
StandardP3DHeader
                        buf[r++] = c;
{
                        r &= 0xfff;
char Signature[4]; //"ODOL" (vs MLOD eg)
                } '''else'''
ulong Version; // 7
                {
ulong LodCount; // at least one
                        '''if'''(pi + 1 >= szin)'''break''';
}
                        i = in[pi++];
</syntaxhighlight>
                        j = in[pi++];
 
                        i |= (j & 0xf0) << 4;
 
                        j  = (j & 0x0f) + 2;
== LodStruct ==
                        pr = r;
 
                        '''for''' (k = 0; k <= j; k++)
See:
                        {
* {{Link|#VertexTable}}
                                c = buf[(pr - i + k) & 0xfff];
* {{Link|#Textures}}
                                '''if'''(po >= szout)'''break''';
* [[P3D Lod Edges]]
                                out[po++] = c;
* [[P3D Lod Faces]]
                                buf[r++] = c;
* [[P3D Lod Sections]]
                                r &= 0xfff;
* [[P3D Named Selections]]
                        }
* {{Link|#NamedProperty}}
                }
* [[P3D Lod Frames]]
        }
* [[P3D Lod Proxies]]
        '''return''' pi;// next 4 bytes = checksum
 
}
 
<syntaxhighlight lang="cpp">
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];
};
</syntaxhighlight>
 
=== VertexTable ===
 
See [[P3D Point and Face Flags]].
<syntaxhighlight lang="cpp">
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
}
</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]]
 
 
[[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