P3D File Format - ODOLV4x: Difference between revisions

From Bohemia Interactive Community
m (Text replacement - "\[\[Category:BIS( |_)File( |_)Formats\]\]" to "Category:Real Virtuality File Formats")
 
(203 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{unsupported-doc}}
{{TOC|side}}
{{Feature|UnsupportedDoc}}
<!--


Wiki Editors: DO NOT DOCUMENT ANYTHING AFTER ARMA 1
-->
== Introduction ==
== Introduction ==
===Acknowledgements===
This body of work is due to Synide's sweat and tears. To whom, all honour and glory.
Ably assisted by T_D, with Mikero trying to keep up with them both.


All accurate data is supplied by the first two individuals. All mistakes, omissions, typos and general misinformation is due to Mikero alone );
=== Acknowledgements ===
===General===
The general file format of a ArmA ODOL v40 p3d model file is similar to the ODOL v7 format.
The major differences are that in ArmA models are


*an optional model.cfg
This body of work is due to Synide's sweat and tears. To whom, all honour and glory.
*resolutions are in reverse numerical order.
Ably assisted by T_D and Mikero that further detailed the data and gave this article a more general and correct structure.


The order of resolutions denoted in the header portion of the file is <b>not</b> necessarily the numerical order of the resolutions. (often the 11,000 resolution is the last in the header array)
=== General ===
The header resolutions need to be sorted in descending order. The resultant sorted array of resolutions is the order in which they appear in the file.


The general format of an ArmA ODOLV4x p3d model is similar to the ODOLV7 format. The '''major''' differences are that ArmA models have


*an optional model.cfg, and
*Lods occur in the file from highest to lowest LodType value.


<b>''NOTE:- As at Aug, 13th 2007, this file format is not conclusive and final. It may or may not fit the actual model file format of an Armed Assault ODOL v40 p3d model.''</b>
==== Legend ====
see [[Generic FileFormat Data Types]]


==== Relative Coordinates ====
All coordinates are '''relative''' to [[P3D Model Info|ModelInfo]].CentreOfGravity


=== Legend ===
==== File Paths ====


{| border="0"
'''All''' file references are absolute to the Linux \ (root).
!width="100"|Type
!width="300" align="left"|Description
|-
|-
|align="middle"|byte||align="left"| 8 bit (1 byte)
|-
|align="middle"|tbool||align="left"| byte: 0 = false.
|-
|align="middle"|ushort||align="left"| 16 bit unsigned short (2 bytes)
|-
|align="middle"|int||align="left"| 32 bit signed integer (4 bytes)
|-
|align="middle"|ulong||align="left"| 32 bit unsigned integer (4 bytes)
|-
|align="middle"|float||align="left"| 32 bit signed single precision floating point value (4 bytes)
|-
|align="middle"|asciiz||align="left"| Null terminated (0x00) variable length ascii string
|-
|-
|}


----
As a convenience A drive letter is used (such as P:\) for sanity when modelling. The engine knows nothing about C:\my documents or even P:


== File Format ==
The leading \ is optional.


\my_project\data\some.paa AND
my_project\data\some.paa


The following is a mix of ''pseudo-code'' and structure references that could be used to describe the file format of ODOL v40.
point to the same file.
It may or may not be accurate but has do date been used to read ODOL v40 in some cases without manual intervention. As at the writing of this article in most cases though, manual intervention is required to complete navigation throughout the given p3d file as there is some unkonwn data that prevents continuous processing.


=== Versions ===


=== Simple ===
This Document covers ODOL versions:


<code><nowiki>
==== V40 ({{arma1}}) ====
  ODOLv40
  {
    Header;
    Model.cfg; (optional)
    Resolutions; (reverse numerical order)
  }
</nowiki></code>


=== Detailed ===
* Original {{arma1}} binarised p3d


<code><nowiki>


ODOLv40
== File Format ==
{
  StandardP3DHeader Header;
  float  HeaderResolutions[[NoOfLods];
  ModelInfo[...];
  Skeleton[...];
  UnknownStruct1[...];
  Animations[...];
    byte[Header.NoOfResolutions * 8] Unknown8;
    bool[Header.NoOfResolutions] LODFaceIndicator;


    //Basically...For each Resolution if the LODFaceIndicator is false
<syntaxhighlight lang="cpp">
    //there is a int FaceCount + 13 bytes
ODOLv4x
    //I think this 'indicator' may serve other areas but at the very least it indicates
{
     //the following structure
StandardP3DHeader Header;
    for (int i = 0; i < Header.NoOfResolutions; i++)
     struct ModelInfo;
    {
Animations Animations;
        if (!LODFaceIndicator[i])
ulong StartAddressOfLods[Header.NoOfLods]; // offset relative to start of file.
        {
ulong EndAddressOfLods  [Header.NoOfLods];
            int HeaderFaceCount;
LODFaceDefaults LODFaceDefaults;
            byte[13] Unknown9;
ODOLv40Lod ODOLv40Lods[Header.NoOfLods];
        }
} // EndOfFile
    }
</syntaxhighlight>


    int NoOfModelProxies;
    if (NoOfModelProxies != 0)
    {
      structProxy[NoOfModelProxies] ModelProxies;
    }
    structResolution[Header.NoOfResolutions];  //Note:- Remember, the order in which lod's
                                              //      occur is descending numerical order.
                                              //      eg. Resolution 1.0 will be the last in
                                              //          the file.
    //EndOfFile
  }
</nowiki></code>
----
===ModelInfo===
  ModelInfo
  {
  ulong Unknown;
  float Sphere;
  byte  Unknown[36];
  float ViewDensity;
  byte  Unknown[24];
  float ModelVertexOffset[3];    //xyz
  float Unknown[3];              //xyz
  float ModelCentreOfGravity[3]; //xyz
  float ModelMassVectors[3][3];
  byte  AutoCenter,
        lockAutoCenter,
        canOcclude,
        canBeOccluded,
        allowAnimation;
  byte  Unknown[6];
  }
===UnknownStruct1===
UnknownStruct1
{
  byte unknown1;
  byte unknown2;
  if(unknown2 != 0)
  {
  byte  ExtraByte;
  }
  byte unknown3[3];
  float ModelMass.
        ModelMassReciprocal,
        ModelMassModifier;
  byte Unknown16[16];
  ulong unknown4;
  byte unknown5;
  asciiz ModelString1;
  asciiz ModelString2;
  byte[5] byteArrayUnknown2;
}
===Animations===
Animations
{
  byte AnimsExist;
  if (AnimsExist == 0x01)
  {
    ulong          NoOfAnimSelections;
    structAnimation[NoOfAnimSelections] Animations;
    //Basically... for each bone there is a list of Animations and this array structure
    //            is stored on a per resolution basis.
    ulong NoOfResolutions;
    {
      ulong NoOfBones;
      {
        ulong NoOfAnims;
        ulong Animation[NoOfAnims];
      }[NoOfBones];
    }[NoOfResolutions];
        //This time it is the other way around: every Animation gets it Bone and additionally
        //the position of the axis if needed for animtype
        for(int i=0; i<NoOfResolutions; i++)
        {
          for(int j=0; j<NoOfAnimSelections; j++)
          {
            ulong Bone;
            if (Bone != -1)
            {
              if (Animations[j].TransformType != 8 && Animations[j].TransformType != 9)
              {
                  float[3] axisPos; //describes the position of the axis used for this anim
                  float[3] axisDir;
              }
            }
        }
  }//AnimExist


== Structures ==
== Structures ==


=== StandardP3DHeader ===
=== StandardP3DHeader ===
<code><nowiki>
StandardP3DHeader
{
  char[4]  Filetype; // "ODOL"
  ulong    Version;  // 40
  ulong    NoOfLods; // alias NoOfResolutions;
}
</nowiki></code>


common header structure for all P3D file formats
Common header structure for all P3D file formats.


=== structBone ===
<syntaxhighlight lang="cpp">
<code><nowiki>
struct
  structBone
{
  {
char[4] Filetype; // "ODOL"
    asciiz Bone;
ulong Version;
    asciiz Parent;
ulong NoOfLods; // alias NoOfResolutions;
  }
}
</nowiki></code>
</syntaxhighlight>


=== structSkeleton ===
[[P3D Model Info|ModelInfo]]
<code><nowiki>
  structSkeleton
  {
    asciiz                  SkeletonName;
    if (SkeletonName != null)
    {
      byte                    isInherited; // 0x00=false, 0x01=true
      int                    NoOfBones;
      structBone[NoOfBones]   Bones;
    }
  }
</nowiki></code>


=== structAnimation ===
=== Animations ===
<code><nowiki>
  structAnimation
  {
    int        AnimTransformType;
    asciiz      AnimSelection;
    asciiz      AnimSource;
    switch(AnimTransformType)
      case 9: //"hide"
      {
        float minValue;
        float maxValue;
        float minPhase;
        float maxPhase;
        int sourceAdress;
        float hideValue;
      }
      case 8: //"direct"
      {
        float minValue;
        float maxValue;
        float minPhase;
        float maxPhase;
        int sourceAdress;
        float axisPos[3];
        float axisDir[3];
        float angle; //in radians whereas the model.cfg entry is in degrees
        float axisOffset;
      }
      default
      {
        float minValue;
        float maxValue;
        float minPhase;
        float maxPhase;
        int sourceAdress;
        float angle0/offset0; //depends on animType
        float angle1/offset1; //depends on animType
      }
  }
</nowiki></code>


=== structProxy ===
<syntaxhighlight lang="cpp">
<code><nowiki>
Animations
  structProxy
{
  {
tbool AnimsExist;
    asciiz      ProxyName;
if (AnimsExist)
    float[12]  ModelProxyUnknown1;
{
    int[4]     ModelProxyUnknown2;
ulong nAnimationClasses; // eg NoOfAnimSelections;
  }
AnimationClass AnimationClasses[nAnimationClasses];
</nowiki></code>


=== structStage ===
long NoOfResolutions; // is -1 if nAnimationClasses == 0
<code><nowiki>
Bones2Anims Bones2Anims[NoOfResolutions];
  structStage
Anims2Bones Anims2Bones[NoOfResolutions];
  {
// For every bone there is a list of Animations for each resolution
    asciiz  StageTexture;
// And, a reversed table of every Animation gets a Bone.
    int      Stage;
// The reversed table optionally appends axis info dependent on the AnimTransformType
    int      UVSource;
}
    float[3] aside;
}
    float[3] up;
</syntaxhighlight>
    float[3] dir;
    float[3] pos;
  }
</nowiki></code>


=== structMaterial ===
=== AnimationClass ===
<code><nowiki>
  structMaterial
  {
    asciiz        Material;
    float[4]      Emissive;
    float[4]      Ambient;
    float[4]      Diffuse;
    float[4]      forcedDiffuse;
    float[4]      Specular;
    float          SpecularPower;
    int            PixelShaderId;
    int            VertexShaderId;
    structStage[]  Stages;
  }
</nowiki></code>


<code><nowiki>
<syntaxhighlight lang="cpp">
    //Basically... A direct replication of the information in the given .rvmat file
AnimationClass
    for (int i = 0; i < NoOfMaterials; i++)
{
    {
ulong AnimTransformType;
      asciiz Material;
asciiz AnimClassName; // "RightDoor"
      byte[4] byteArrayMaterialUnknown1;
asciiz AnimSource; // "rotor"
      float[4] Emissive;
float MinMaxValue[2];
      float[4] Ambient;
float MinMaxPhase[2];
      float[4] Diffuse;
ulong junk; // used to be sourceAddress, no longer, always 953267991
      float[4] forcedDiffuse;
IF ARMA3
      float[4] Specular;
ulong Always0; // no idea what this is used for
      float    SpecularPower;
ulong sourceAddress; // this is the actual source address, 0 = clamp, 1 = mirror, 2 = loop
      int      PixelShaderId; //See enumPixelShaderId
endif
      int      VertexShaderId; //See enumVertexShaderId
      //Based on the enumPixelShaderId that matches this PixelShaderId process a variable 'NoOfStages'
      //by default one should probably process 2 stages as this seems the most common amount
      if (NoOfStages > 0)
        {
          byte[34]  byteArrayMaterialUnknown2;
          for (int i = 0; i < NoOfStages; i++)
          {
            int  Filter;
            asciiz    StageTexture;
            int      StageNumber;
          }
          for (int i = 0; i < NoOfStages; i++)
          {
            int      UVSource;
            float[3] aside;
            float[3] up;
            float[3] dir;
            float[3] pos;
          }
          byte[52] byteArrayMaterialUnknown4; //Possibly default values for a stage as same struct size
        }
        else
        {
          byte[86] byteArrayMaterialUnknown5;
        }
     
    }//EndOfMaterials
</nowiki></code>


switch(AnimTransformType)
case 0://rotaton
case 1://rotationX
case 2://rotationY
case 3://rotationZ
float angle0;
float angle1;
break;
case 4://translation
case 5://translationX
case 6://translationY
case 7://translationZ
float offset0;
float offset1;
break;
case 8: //"direct"
float axisPos[3];
float axisDir[3];
float angle; //in radians whereas the model.cfg entry is in degrees
float axisOffset;
break;
case 9: //"hide"
float hideValue;
break;
}




=== structComponent ===
// corresponds to model.cfg
<code><nowiki>
class CfgModels
  structComponent
{
  {
// ...
    asciiz ComponentName;


    //Selected Faces
class whateverModel : Default
    int NoOfSelectedFaces;
{
    ushort[NoOfSelectedFaces] SelectedFaceIndexes;
// ...
class Animations
{
class RightDoor // AnimClassName
{
type = "translation"; // AnimTransformType
source = "rotor"; // AnimSource
// etc
};
};
};
</syntaxhighlight>


    int intComponentUnknown1;
==== Bones2Anims ====
    bool bComponentUnknown1;
Bones2Anims
    if (bComponentUnknown1)
{
    {
  ulong       NoOfBones;
       int NoOf;
  Bone2AnimClassList  Bone2AnimClassLists[NoOfBones];
      int[NoOf] intArrayComponentUnknown1;
}
    }
==== Bone2AnimClassList ====
    else
Bone2AnimClassList
    {
{
      int intComponentUnknown2;
  ulong NoOfAnimClasses;
    }
  ulong AnimationClassIndex[NoOfAnimClasses]; // a (sometimes repeating) list of zero based indexes into above animation classes
}


    // Selected Vertices
==== Anims2Bones ====
    int NoOfSelectedVertices;
Anims2Bones
    ushort[NoOfSelectedVertices] SelectedVerticesIndexes// Zero based array of index values into
{
                                                          // the array of Vertices.
  AnimBones AnimBones[Animations.nAnimationClasses];
                                                          // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
  }
                                                                      compressed.


    // Selected Vertices Properties
==== AnimBones ====
    int NoOfSelectedVertices;
    byte[NoOfSelectedVertices] SelectedVerticesProperties; // Zero based array of index values into
                                                          // the array of Vertices.
                                                          // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
                                                                      compressed.
  }
</nowiki></code>


every lod contains an identical list of animation entries that declare the position and axis of the each animation classes


=== structProperties ===
AnimBones
<code><nowiki>
{
   structProperties
  long SkeletonBoneNameIndex; // zero based index to the SkeletonBoneName name & parentname
  // equivalent to selection = "LeftDoor"; eg in the model.cfg
  /*
  ** SkeletonBoneNameIndex== -1 when no skeleton bone is for this Anim and (obviously?) no axis information follows.
  */
   if (SkeletonBoneNameIndex!= -1) && (AnimationClass.AnimTransformType != 8 || 9)
   {
   {
     asciiz Property;
  /*
     asciiz Value;
  ** AnimationClass.AnimTransformType 8 (direct) and 9 (hide) never require axis information.
  ** This because the "direct" (type 8) already has axis info in it is AnimationClass structure,
  ** and "hidden" (type 9) clearly doesn't need it.
  */
     XYZTriplet axisPos; //describes the position of the axis used for this anim
     XYZTriplet axisDir;
   }
   }
</nowiki></code>
}


=== structUV ===
=== LODFaceDefaults ===
<code><nowiki>
  structUV
  {
    float u;
    float v;
  }
</nowiki></code>


=== structVerticesPosition ===
  tbool            UseDefault[Header.NoOfLods];
<code><nowiki>
   FaceData
   structVerticesPosition
   {
   {
    float x;
  ulong  HeaderFaceCount;
     float z;
  ulong  aDefaultLong;     //ffffffff or 6f 7a 80 fa eg
    float y;
  byte    UnknownByte;     //generally zero
   }
  byte    aFlag;           // zero or one
</nowiki></code>
  bytes  Zeroes[7];
   }[Number of false UseDefault's];


=== structVerticesNormal ===
A face data struct only exists for those lods who's UseDefault is zero
<code><nowiki>
  structVerticesNormal
  {
    float x;
    float z;
    float y;
  }
</nowiki></code>


=== structVerticesMinMax ===
=== ODOLv4xLod ===
<code><nowiki>
*Lod layout corresponds to Arma1 (type40). The differences in a2 are in the nitty gritty of the structures themselves. Arrowhead(v50) has some changes.
  structVerticesMinMax
  {
    float x1;
    float z1;
    float y1;
    float x2;
    float z2;
    float y2;
  }
</nowiki></code>


=== structVerticesUnknown1 ===
   ODOLv4xLod
<code><nowiki>
   structVerticesUnknown1
   {
   {
    ushort One;
    ulong                        nProxies;
    ushort Two;
    LodProxy                      LodProxies[nProxies];              // see [[P3D Lod Proxies]]
    ushort Three;
    ulong                        nLodItems;
    ushort Four;
    ulong                        LodItems[nLodItems];              // potentially compressed, except for v64 and later
    ushort Five;
    ulong                        nBoneLinks;
    ushort Six;
    LodBoneLink                  LodBoneLinks[nBoneLinks];
    float                        UnknownFloat1;
    float                        UnknownFloat2;
    XYZTriplet                    MinPos;
    XYZTriplet                    MaxPos;
    XYZTriplet                    AutoCenterPos;
    float                        Sphere;                            // same as geo or mem values in modelinfo, if this lod is geo or memlod of course
    ulong                        NoOfTextures;
    asciiz                        LodPaaTextureNames[NoOfTextures];  //"ca\characters\hhl\hhl_01_co.paa"
    ulong                        NoOfMaterials;
    LodMaterial                  LodMaterials[NoOfMaterials];
    LodEdges                      LodEdges;                          // compressed see [[P3D Lod Edges]]
    ulong                        NoOfFaces;
    ulong                        OffsetToSectionsStruct;            // see below
    ushort                       AlwaysZero;
    LodFace                      LodFace[NoOfFaces];                // see [[P3D Lod Faces]]
    ulong                        nSections;
    LodSection                    LodSections[nSections];            // see [[P3D Lod Sections]]
    ulong                        nNamedSelections;
    LodNamedSelection            LodNamedSelections[nNamedSelections]; //See [[P3D Named Selections]] potentially compressed
    ulong                        nTokens;
    NamedProperty                NamedProperties[nTokens];          //See [[Named Properties]]
    ulong                        nFrames;
    LodFrame                      LodFrames[nFrames];                //see [[P3D Lod Frames]]
    ulong                        IconColor;
    ulong                        SelectedColor;
    ulong                        special; // IsAlpha|IsTransparent|IsAnimated|OnSurface
    byte                          vertexBoneRefIsSimple;
    ulong                        sizeOfVertexTable;                 //(including these 4 bytes)
    if (v5x)
    LodPointFlags                LodPointFlags;                     // Potentially compressed
    endif
    VertexTable                  VertexTable;
   }
   }
</nowiki></code>


=== structResolution (simple) ===
==== VertexTable ====
<code><nowiki>
all arrays are subject to compression
  structResolution
  {
    NoOfVertices;
    <space>
    NoOfTextures;
    Textures;
    NoOfMaterials;
    Materials;
    <space>
    NoOfPolygons;
    <space>
    Polygons;
    <space>
    NoOfComponents;
    Components;
    NoOfProperties;
    Properties;
    <space>
    NoOfVertices;
    VerticesUVSet1;
    NoOfVertices;
    VerticesUVSet2;
    NoOfVertices;
    VerticesPositions;
    NoOfVertices;
    VerticesNormals;
    NoOfVertices;
    VerticesMinMax; //Looks like Min/Max info.
    NoOfVertices;
    VerticesUnknown1; //Looks like per vertex properties
    NoOfVertices;
    VerticesUnknown2; //hmmmm...
    if(pointer<filesize)
    {
        NoOfProxies;
        Proxies;
        <space>
    }
    NoOf;
    IntermittentUnknownData; // As at article date 12-Aug-2007. This data is not in every lod
                              // it is intermittent. Currently, structure is unknown.
                              // Can be bypassed by manual intervention to start of next resolution.
                              // Most likely is Texture-2-Face/Vertex mappings.
                              //This is a 'show-stopper' for continuous processing.
  }
</nowiki></code>


=== structResolution (detailed) ===
struct
<code><nowiki>
{
  structResolution
    UvSet                        DefaultUVset;
  {
    ulong                        nUVs;
     StarterStructOne[...];
     UvSet                        UVSets[nUVs-1];
     StarterStructTwo[...];
     ulong                        NoOfPoints;
     PointProperties[...];
    XYZTriplet                    LodPoints[NoOfPoints];
     TextureNames[...];
     ulong                        nNormals;
     Materials[...];
    (A2)LodNormals                LodNormals[nNormals];
     byte[8] byteArrayResUnknown2;
     ulong                        nMinMax;
     PolygonStruct[...];
    (A2)LodMinMax                MinMax[nMinMax];                   //optional
     ulong                        nProperties;
    VertProperty                  VertProperties[nProperties];       //optional related to skeleton
     ulong                        Count;
     VertexNeighborInfo            neighborBoneRef[Count];         //optional
}


    //Model 'Section' Info. Unknown structure, however this code snippet iterates over it
* All non zero counts counts are the same.
    int NoOfSections;
* Points,PointFlags, Normals and UV1 arrays are an integral group, they are either all there, or not specified (RacetK.p3d, a [[P3D Lod Frames|FrameTime]] lod has no counts at all)
    for (int i = 0; i < NoOfSections; i++)
* UV2,MinMax, VertProperties and Unknown are optional in the sense that their counts can individually be zero, else they are the same as the others
    {
* In Odol7 PointFlags are part of this stucture, in Arma, they are a separated table.
      byte[26] byteArrayResUnknown4;
      byte byteResUnknown3;
      if (byteResUnknown3 == 0xFF)
      {
        byte[16] byteArrayResUnknown5;
      }
      else
      {
        byte[15] byteArrayResUnknown5;
      }
    }//EndOf Model 'Section' info. structure


    int NoOfComponents;
==== CompressedFill Arrays ====
    structComponent[NoOfComponents] Components;


    int NoOfProperties;
LodPointFlags, LodUV's and LodNormals arrays are not only subject to the standard 1024 rule compression, but also have a fill byte.
    structProperties[NoOfProperties] Properties;


    ushort usUnknown1;
struct
    ushort usUnknown2;
{
    if (usUnknown2 == 0)
  ulong                        Count;
    {
  tbool                        DefaultFill;
      byte[17] byteArrayResUnknown6;
  if (DefaultFill)
    }
  type                        Array;         // default fill for all Counts
    else
  else
    {
  type                        Array[Count];   // potentially compressed
      byte[15] byteArrayResUnknown6;
}
    }


    int NoOfVertices;
The structure either contains a single set of type variables, or, an array of type variables. If a full array is declared (DefaultFill =false) then that array is subject to the 1024 rule as per normal.
    byte bUV
==== UVset ====
    if (bUV == 0x00)
if TrueARMA2
    {
     float                        UVScale[4];
        structUV[NoOfVertices2ndUV] VerticesUVSet1;        //  </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
endif
                                                                      compressed.
     (A2)LodUV                    LodUV;
      int NoOfVertices2ndUV;
    }
    else
     {
      byte[12] byteArrayResUnknown7;
     }


    if (NoOfVertices2ndUV == 2)
==== LodUV ====
    {
CompressedFill type = UVPair // eg float U,V;
      int NoOfVertices2ndUV;
==== A2LodUV ====
      byte bUV;
  CompressedFill type = float // eg float UV;
      if (bUV == 0x00)
==== LodNormals ====
      {
  CompressedFill type = XYZTriplet
        structUV[NoOfVertices2ndUV] VerticesUVSet2;        // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
==== A2LodNormals ====
                                                                      compressed.
  CompressedFill type = CompressedXYZTriplet
      }
      else
      {
        byte[8] byteArrayResUnknown8;
      }
    }


    int NoOfVertices;
===== CompressedXYZTriplet =====
    structVerticesPosition[NoOfVertices] VerticesPositions;        // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
                                                                      compressed.
    int NoOfVertices;
    byte bNormal;
    if (bNormal == 0x00)
    {
      structVerticesNormal[NoOfVertices] VerticesNormals;  // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
    }                                                                compressed.
    else
    {
        byte[12] byteArrayResUnknown9;
    }


    int NoOfVertices;
contains 3x 10 bit fields in a 32bit 'integer'
    if (NoOfVertices != 0)
    {
      structVerticesMinMax[NoOfVertices] VerticesMinMax;  // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
    }                                                                compressed.


    int NoOfVertices;
code for converting back to a standard XYZTriplet is:
    if (NoOfVertices != 0)
    {
      structVerticesUnknown1[NoOfVertices] VerticesUnknown1;  // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
      int NoOfVertices;                                              compressed.
    }


     if (NoOfVertices != 0)
void DecodeXYZ(ulong CompressedXYZ, XYZTriplet *triplet)
     {
{
       byte[32][NoOfVertices] VerticesUnknown2;   // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
     double scaleFactor = -1.0 /511;
     }                                                                 compressed.
     trp->X=trp->Y=trp->Z=0.0;
    int x=  CompressedXYZ       & 0x3FF;
    int y = (CompressedXYZ>> 10) & 0x3FF;
    int z = (CompressedXYZ>> 20) & 0x3FF;
    if (x > 511) x -= 1024;
    if (y > 511) y -= 1024;
    if (z > 511) z -= 1024;
    if (x) trp->X = (float)(x * scaleFactor);
    if (y) trp->Y = (float)(y * scaleFactor);
     if (x) trp->Z = (float)(z * scaleFactor);
}


    if (Pointer < Filesize)
==== LodPointFlags ====
    {
CompressedFill type = ulong bits
      int NoOfProxies;
      if (ProxyCount != 0)
      {
          structProxy[NoOfProxies] Proxies;
      }
      if (Pointer < Filesize)
      {
        int NoOf;
        int[NoOf] intArrayResUnknown1;
        int NoOf;
        if (NoOf > 0)
        {
          for (int i = 0; i < NoOf; i++)
          {
              int NoOf2;
              int[NoOf2] intArrayResUnknown2;
          }
        }
        else
        {
            int intResUnknown1;
        }
      }
    }


  // Show stopper...
This table is the equivalent of Oxygen's points->properties dialog box. It specifically stores the user values and other flags for that point.
  // At this point there is a unknown, intermittent, variable length structure.
  // Requires manual intervention to move to next resolution.
  // possibly Face-2-Texture mappings.


  byte[VariableLength] IntermittentUnknownData; //Only present intermitently.
In ODOl7 it was part of the vertex table. In ArmA, it is separate.


See [[P3D Point and Face Flags]]


   //EndOfResolution
==== LodMinMax ====
  }
CompressedArray
</nowiki></code>
{
   XYZTriplet    MinMax[Count][2]; // 2 == min vs max
}


----
==== A2LodMinMax ====
====StarterStructOne====
  CompressedArray
  StarterOne
  {
  {
   ulong Count;
   float        MinMax[Count][2]; // 2 == min vs max
  ulong Items[Count];
  }
  };
 
====StarterStructTwo====
==== VertProperty ====
  StarterTwo
  CompressedArray
  {
  {
   ulong Count;
   ulong index;// seen range 0..4
   {
   ulong a,b; // definite not floats. might be flags, or indices
  ulong NoOf3;
  ulong Items[NoOf3];
  }[Count];
  }
  }
===PointProperties===
 
  PointProperties
==== VertexNeighborInfo ====
  CompressedArray
  {
  {
   ushort NoOfPts;
   ushort vertexIndex _posA;
   ushort Unknown;
   AnimationRTWeight _rtwA;
   byte PointPropsInd;
   ushort  vertexIndex _posB;
  if (PointPropsInd==1) // all default
   AnimationRTWeight _rtwB;
  {
  ulong DefaultValue;
  }
  byte Unknown[8];
   float Unknown[10];
  }
  }
===TextureNames===
 
  TextureNames
==== LodBoneLink ====
 
  LodBoneLink
  {
  {
  ulong     NoOfTextures;
  ulong NoOfLinks;         //range 0..3
  asciiz   Textures[NoOfTextures];
   ulong Value[NoOfLinks]; //the 'Value' seems to reference the 'LodItems' structure, resulting in a circular-reference.
  }
  }
===Materials===
 
  Materials
==== LodMaterials ====
Basically... A direct replication of the information in the given .rvmat file
 
The stages in the p3d include a default stage and a TI stage that are not normally listed in the rvmat.
:The first stage (in the p3d) is unconditionally the default stage. It is defaulted to empty (RvMatName=""), unless, specified in the rvmat
:The last stage is the TI stage, and is also defaulted empty, unless specified in the rvmat.
::TI Stages were introduced for operation arrowhead. Lod Material Types 9 and 10 (Arma1 and Arma2) do not have a TI stage at all.
Neither of these two special, hidden, stage types use uvsets. The transform matrix for them is defaulted empty (so-called 'TexGen0').
 
When specified in the rvmat (class Stage0 and StageTI respectively), no  class uvTransform is declared for them. It is assumed default empty.
 
In an rvmat, uvTransforms are ordinarily declared within each stage body.
 
In a P3D, identical UVTransforms are declared once, and multiple 'stages' refer to them. There is, always, a default UVSet0 Transform as the 1st entry. (IE some stages dont require uvsets)
 
This P3D style can, if preferred, be used in rvmat syntax as
  class TexGenX
  {
  {
   ulong NoOfMaterials;
   .......
  structMaterial[NoOfMaterials];
  };
  }


===PolygonStruct===
  class StageZ
  PolygonStruct
  {
  {
  ulong  NoOfPolygons;
  .........
  byte   Unknown[6];                   // 28 00 00 00 00 00 eg
   Texgen=X;
  PoyygonVertices
};
  {
    byte  NoOfVertices;                // 3 or 4
    ushort VerticesIndex[NoOfVertices]; // 0-based index into Vertices Arrays
  }[NoOfPolygons];
}


== Decompression ==
where X and Z are numbers


In ODOL v40 format files some of the datastructures present in the file are compressed by using a form of LZ compression.
Unlike pbo compression, in ArmA model files, one only knows the number of items to decompress, the expected output size (in bytes) and the expected checksum.
With this information and the size of a given data item one has the necessary information to expand the data to it's original format and size.


====LodMaterial====
  LodMaterial
  {
    asciiz            RvMatName;    // "ca\characters\data\soldier_captive_hhl.rvmat"
    ulong            Type;          // 9 == ArmA
    D3DCOLORVALUE    Emissive;
    D3DCOLORVALUE    Ambient;
    D3DCOLORVALUE    Diffuse;
    D3DCOLORVALUE    forcedDiffuse;
    D3DCOLORVALUE    Specular;
    D3DCOLORVALUE    Specular2;      //Usually same as Specular
    float            SpecularPower;  //
    ulong            PixelShaderId;  //See enumPixelShaderId
    ulong            VertexShaderId;  //See enumVertexShaderId
    LongBool          mainLight;    // 1 or zero
    ulong            ul_FogMode;    /// 0..4
    Asciiz            BiSurfaceName;  // "ca\data\Penetration\plastic.bisurf"
    LongBool          Arma1Mostly1;    //rarely zero
    ulong            RenderFlags;    //Generally 0
    ulong            nTextures;
    ulong            nTransforms;    // always same as nTextures
    LodStageTexture  StageTextures  [nTextures];
    LodStageTransform StageTransforms[nTransforms];
  } 


<b>''Note:- Data structures that are identified as being compressible will only be compressed if the 'expectedSize' is >= 1024 bytes.''</b>
:Each lodmaterial entry contains a default StageTexture and StageTransform as the first entry. It is not shown in the rvmat file and has no PaaTexture
:It is the only entry if a SurfaceName exists.


=== D3DCOLORVALUE ===
D3DCOLORVALUE
{
  float r,g,b,a;
}
===== RenderFlags =====
:*Bit0:AlwaysInShadow (A1 only)
:*Bit1:NoZWrite
:*Bit4:NoColorWrite
:*Bit5:NoAlphaWrite
:*Bit6:AddBlend
:*Bit7:AlphaTest (clutter)
:*Bit8:AlphaTest64 (clutter)
:*Bit19:Road      (a1only)
:*Bit11:NoTiWrite


<b>''The code that follows is written in C# and may or may not be optimal or correct.''</b>
===== LodStageTexture =====
LodStageTexture
{
  ulong  TextureFilter; // see below
  asciiz PaaTexture;    // "ca\characters\data\civil_tvreport_body_as.paa
                        // alternatively "#(argb,8,8,3)color(0,0,0,1,CO)" (eg)
  ulong  TransformIndex;      // zero based, see below
};


:The first stageTexture is a dummy entry. For N humanly readable stage classes, there are 1+N LodStageTextures


:TextureFilter maybe 1 of the following values.
:*0: Point // sometimes
:*1: Linear  // rarely
:*2: TriLinear // not seen
:*3: Anisotropic (default)


As an example if one was expanding the array of vertices positions...
===== LodStageTransform =====
  LodStageTransform
  {
    ulong UVSource;
    float Transform[4][3];//a DirectX texture space transform matrix
  };


* A vertex is described by it's x,y,z coordinates which are floats. A float is a 32bit (4 byte) number.
:UVSource corresponds to the 8 possible uvsets available
* If we were processing 1968 vertices then our expected output size would be 1968 * (3 * 4) = 23,616 bytes.


This 'expectedSize' is the only necessary information one would need to pass to a processing sub-routine or function.
:*0 "None"
:*1 "Tex" default
:*2: "Tex2"
:*........
:*8:"Tex8"


:*Tex1..8 cannot be taken literally as uvsource 1..8. They can mean anything, according to the template and are scarcely encountered


<code><nowiki>
==== NamedProperty ====
   public bool Expand(int ExpectedSize)
   struct
   {
   {
      byte PacketFlagsByte; //packet flags
    Asciiz Property;// "noshadow" = "1" eg
      byte WIPByte;
    Asciiz Value;
      BitVector32 BV;
  }
      msLZ = new MemoryStream(ExpectedSize);
      BinaryWriter bwLZ = new BinaryWriter(msLZ);
      byte[] Buffer = new byte[ExpectedSize + 15];
      bool[] BitFlags = new bool[8];
      int i = 0, PointerRef = 0, ndx = 0, CalculatedCRC = 0, ReadCRC = 0, rPos, rLen, CurrentPointerRef = 0, Count = 0;
      int Bit0 = BitVector32.CreateMask();
      int Bit1 = BitVector32.CreateMask(Bit0);
      int Bit2 = BitVector32.CreateMask(Bit1);
      int Bit3 = BitVector32.CreateMask(Bit2);
      int Bit4 = BitVector32.CreateMask(Bit3);
      int Bit5 = BitVector32.CreateMask(Bit4);
      int Bit6 = BitVector32.CreateMask(Bit5);
      int Bit7 = BitVector32.CreateMask(Bit6);


*See [[Named Properties]]


      PacketFlagsByte = br.ReadByte();
== Decompression ==
      do
 
      {
see [[Compressed LZSS File Format]]
          BV = new BitVector32(PacketFlagsByte);
          BitFlags[0] = BV[Bit0];
          BitFlags[1] = BV[Bit1];
          BitFlags[2] = BV[Bit2];
          BitFlags[3] = BV[Bit3];
          BitFlags[4] = BV[Bit4];
          BitFlags[5] = BV[Bit5];
          BitFlags[6] = BV[Bit6];
          BitFlags[7] = BV[Bit7];
          i = 0;
          do
          {
              if ((int)bwLZ.BaseStream.Position >= ExpectedSize) { break; }
              if (BitFlags[i++]) //Direct Output
              {
                  WIPByte = br.ReadByte();
                  bwLZ.Write(WIPByte);
                  Buffer[PointerRef++] = WIPByte;
                  CalculatedCRC += WIPByte;
              }
              else //Get from previous 4k
              {
                  rPos = (int)(br.ReadByte());
                  rLen = (int)(br.ReadByte());
                  rPos |= (rLen & 0xF0) << 4;
                  rLen = (rLen & 0x0F) + 2;
                  CurrentPointerRef = PointerRef;
                  if ((CurrentPointerRef - (rPos + rLen)) > 0)
                  {
                      //Case of wholly within the buffer, partially within the end of the buffer or wholly outside the end of the buffer
                      for (Count = 0; Count <= rLen; Count++)
                      {
                          ndx = (CurrentPointerRef - rPos) + Count;
                              if (ndx < 0)
                              {
                                  //Beyond the start of the buffer
                                  WIPByte = 0x20;
                              }
                              else
                              {
                                  //Within the buffer
                                  WIPByte = Buffer[ndx];
                              }
                          //}
                          bwLZ.Write(WIPByte);
                          Buffer[PointerRef++] = WIPByte;
                          CalculatedCRC += WIPByte;
                      }
                  }
                  else
                  {
                      //Case of wholly or partially beyond the start of the buffer.
                      for (Count = 0; Count <= rLen; Count++)
                      {
                          ndx = (CurrentPointerRef - rPos) + Count;
                          if (ndx < 0)
                          {
                              //Beyond the start of the buffer
                              WIPByte = 0x20;
                          }
                          else
                          {
                              //Within the buffer
                              WIPByte = Buffer[ndx];
                          }
                          bwLZ.Write(WIPByte);
                          Buffer[PointerRef++] = WIPByte;
                          CalculatedCRC += WIPByte;
                      }
                  }
              }
          }
          while ((i < 8) & (bwLZ.BaseStream.Position < ExpectedSize));
          if (bwLZ.BaseStream.Position < ExpectedSize) { PacketFlagsByte = br.ReadByte(); }
      }
      while (bwLZ.BaseStream.Position < ExpectedSize);
      ReadCRC = br.ReadInt32();
      return (ReadCRC == CalculatedCRC);
  }
</nowiki></code>


----
see [[Compressed LZO File Format]]


== Reference Tables ==


Note: These are not part of the p3d model file but are reference tables used for processing.
In ODOL v40 format files, some of the data structures present in the file are compressed by using LZSS compression.


=== Resolutions ===
Unlike pbo compression, in ArmA model files, one only knows the number of items to decompress, the expected output size (in bytes) and the expected checksum.
With this information and the size of a given data item one has the necessary information to expand the data to it is original format and size.


<code><nowiki>
{{Feature|informative|Data structures that are identified as being compressible will only be compressed if the 'expectedSize' is &ge; 1024 bytes.}}
refResolutions
{
  float  Resolution;
  string ResolutionName;
}
</nowiki></code>


{| border="0"
!width="100" align="left"|Hex-Value
!width="50" align="left"|Value
!width="150" align="left"|Value
!width="300" align="left"|Description
|-
|-
|align="left"|0x447a0000||align="left"|1.0e3||align="left"|1,000||align="left"|View Gunner
|-
|align="left"|0x44898000||align="left"|1.1e3||align="left"|1,100||align="left"|View Pilot
|-
|align="left"|0x44960000||align="left"|1.2e3||align="left"|1,200||align="left"|View Cargo
|-
|align="left"|0x461c4000||align="left"|1.0e4||align="left"|10,000||align="left"|Stencil Shadow
|-
|align="left"|0x461c6800||align="left"|1.001e4||align="left"|10,010||align="left"|Stencil Shadow 2
|-
|align="left"|0x462be000||align="left"|1.1e4||align="left"|11000||align="left"|Shadow Volume
|-
|align="left"|0x462c0800||align="left"|1.101e4||align="left"|11010||align="left"|Shadow Volume 2
|-
|align="left"|0x551184e7||align="left"|1.0e13||align="left"|10,000,000,000,000||align="left"|Geometry
|-
|align="left"|0x58635fa9||align="left"|1.0e15||align="left"|1,000,000,000,000,000||align="left"|Memory
|-
|align="left"|0x58e35fa9||align="left"|2.0e15||align="left"|2,000,000,000,000,000||align="left"|Land Contact
|-
|align="left"|0x592a87bf||align="left"|3.0e15||align="left"|3,000,000,000,000,000||align="left"|Roadway
|-
|align="left"|0x59635fa9||align="left"|4.0e15||align="left"|4,000,000,000,000,000||align="left"|Paths
|-
|align="left"|0x598e1bca||align="left"|5.0e15||align="left"|5,000,000,000,000,000||align="left"|HitPoints
|-
|align="left"|0x59aa87bf||align="left"|6.0e15||align="left"|6,000,000,000,000,000||align="left"|View Geometry
|-
|align="left"|0x59c6f3b4||align="left"|7.0e15||align="left"|7,000,000,000,000,000||align="left"|Fire Geometry
|-
|align="left"|0x59e35fa9||align="left"|8.0e15||align="left"|8,000,000,000,000,000||align="left"|View Cargo Geometry
|-
|align="left"|0x59ffcb9e||align="left"|9.0e15||align="left"|9,000,000,000,000,000||align="left"|View Cargo Fire Geometry
|-
|align="left"|0x5a0e1bca||align="left"|1.0e16||align="left"|10,000,000,000,000,000||align="left"|View Commander
|-
|align="left"|0x5a1c51c4||align="left"|1.1e16||align="left"|11,000,000,000,000,000||align="left"|View Commander Geometry
|-
|align="left"|0x5a2a87bf||align="left"|1.2e16||align="left"|12,000,000,000,000,000||align="left"|View Commander Fire Geometry
|-
|align="left"|0x5a38bdb9||align="left"|1.3e16||align="left"|13,000,000,000,000,000||align="left"|View Pilot Geometry
|-
|align="left"|0x5a46f3b4||align="left"|1.4e16||align="left"|14,000,000,000,000,000||align="left"|View Pilot Fire Geometry
|-
|align="left"|0x5a5529af||align="left"|1.5e16||align="left"|15,000,000,000,000,000||align="left"|View Gunner Geometry
|-
|align="left"|0x5a635fa9||align="left"|1.6e16||align="left"|16,000,000,000,000,000||align="left"|View Gunner Fire Geometry
|-
|align="left"|0x5a7195a4||align="left"|1.7e16||align="left"|17,000,000,000,000,000||align="left"|Sub Parts
|-
|-
|}


Note: Hex-Values are provided for convenience, as you can use those in different programming languages 'switch'-statement as opposed to floating point values.
== Reference Tables ==


=== Material Stages ===
=== Material Stages ===
Line 919: Line 526:
A reference table is used when processing materials where depending on the shader specified the given number of stages should be processed.
A reference table is used when processing materials where depending on the shader specified the given number of stages should be processed.


<code><nowiki>
<code style="display: block"><nowiki>
  refShaderStages
  refShaderStages
  {
  {
Line 942: Line 549:
|align="left"|0x03, 3||align="left"|NormalMapThrough||align="left"|normal map shader - through lighting||align="left"|3
|align="left"|0x03, 3||align="left"|NormalMapThrough||align="left"|normal map shader - through lighting||align="left"|3
|-
|-
|align="left"|0x04, 4||align="left"|?||align="left"|?||align="left"|?
|align="left"|0x04, 4||align="left"|NormalMapSpecularDIMap||align="left"|VBS2 only||align="left"|2
|-
|-
|align="left"|0x05, 5||align="left"|NormalMapDiffuse||align="left"|?||align="left"|2
|align="left"|0x05, 5||align="left"|NormalMapDiffuse||align="left"|?||align="left"|2
Line 950: Line 557:
|align="left"|0x07, 7||align="left"|?||align="left"|?||align="left"|?
|align="left"|0x07, 7||align="left"|?||align="left"|?||align="left"|?
|-
|-
|align="left"|0x08, 8||align="left"|Water||align="left"|sea water||align="left"|2
|align="left"|0x08, 8||align="left"|Water||align="left"|A1 only sea water||align="left"|2
|-
|-
|align="left"|0x09, 9||align="left"|?||align="left"|?||align="left"|?
|align="left"|0x09, 9||align="left"|?||align="left"|vbs2||align="left"|?
|-
|-
|align="left"|0x0A, 10||align="left"|White||align="left"|?||align="left"|0
|align="left"|0x0A, 10||align="left"|White||align="left"|A1 only||align="left"|0
|-
|-
|align="left"|0x0B, 11||align="left"|?||align="left"|?||align="left"|?
|align="left"|0x0B, 11||align="left"|?||align="left"|vbs2||align="left"|?
|-
|-
|align="left"|0x0C, 12||align="left"|AlphaShadow||align="left"|shadow alpha write||align="left"|0
|align="left"|0x0C, 12||align="left"|AlphaShadow||align="left"|shadow alpha write||align="left"|0
Line 962: Line 569:
|align="left"|0x0D, 13||align="left"|AlphaNoShadow||align="left"|shadow alpha (no shadow) write||align="left"|0
|align="left"|0x0D, 13||align="left"|AlphaNoShadow||align="left"|shadow alpha (no shadow) write||align="left"|0
|-
|-
|align="left"|0x0E, 14||align="left"|?||align="left"|?||align="left"|?
|align="left"|0x0E, 14||align="left"|?||align="left"|vbs2||align="left"|?
|-
|-
|align="left"|0x0F, 15||align="left"|DetailMacroAS||align="left"|?||align="left"|3
|align="left"|0x0F, 15||align="left"|DetailMacroAS||align="left"|?||align="left"|3
|-
|-
|align="left"|0x10, 16||align="left"|?||align="left"|?||align="left"|?
|align="left"|0x10, 16||align="left"|?||align="left"|vbs2||align="left"|?
|-
|-
|align="left"|0x11, 17||align="left"|?||align="left"|?||align="left"|?
|align="left"|0x11, 17||align="left"|?||align="left"|vbs2||align="left"|?
|-
|-
|align="left"|0x12, 18||align="left"|NormalMapSpecularMap||align="left"|?||align="left"|2
|align="left"|0x12, 18||align="left"|NormalMapSpecularMap||align="left"|?||align="left"|2
Line 994: Line 601:
|align="left"|0x3C, 60||align="left"|NormalMapThroughSimple||align="left"|?||align="left"|0
|align="left"|0x3C, 60||align="left"|NormalMapThroughSimple||align="left"|?||align="left"|0
|-
|-
|align="left"|0xxx, 102||align="left"|Super||align="left"|Arrowhead||align="left"|0
|-
|align="left"|0xxx, 103||align="left"|Multi||align="left"|Arrowhead||align="left"|0
|-
|align="left"|0xxx, 107||align="left"|Tree||align="left"|Arrowhead||align="left"|0
|-
|align="left"|0xxx, 110||align="left"|Skin||align="left"|Arrowhead||align="left"|0
|-
|align="left"|0x6F, 111||align="left"|CalmWater||align="left"|Arrowhead||align="left"|7
|-
|-
|align="left"|0xxx, 114||align="left"|TreeAdv||align="left"|Arrowhead||align="left"|0
|-
|align="left"|0xxx, 116||align="left"|TreeAdvTrunk||align="left"|Arrowhead||align="left"|0
|}
|}


----


== Enums ==
== Enums ==


<code><nowiki>
<code style="display: block"><nowiki>
int enum PixelShaderId
{
  Normal = 0x00,
  NormalMap = 0x02,
  NormalMapDiffuse = 0x05,
  NormalMapMacroASSpecularMap = 0x14,
  NormalMapSpecularDIMap = 0x16,
  NormalMapMacroASSpecularDIMap = 0x18,
  AlphaShadow = 0x0C,
  AlphaNoShadow = 0x0D,
  Glass = 0x38,
  Detail = 0x06,
  NormalMapSpecularMap = 0x12
}
</nowiki></code>
 
<code><nowiki>
  int enum VertexShaderId
  int enum VertexShaderId
  {
  {
  Basic = 0x00,
case 0: return "Basic";
  NormalMap = 0x01,
case 1: return "NormalMap";
  NormalMapAS = 0x0F
case 2: return "NormalMapDiffuse";
case 3: return "Grass";
case 8: return "Water";
case 11: return  "NormalMapThrough";
case 15: return "NormalMapAS";
case 14: return "BasicAS";
case 17: return "Glass";
case 18: return "NormalMapSpecularThrough";
case 19: return "NormalMapThroughNoFade";
case 20: return "NormalMapSpecularThroughNoFade";
case 23: return "Super";
case 24: return "Multi";
case 25: return "Tree";
case 30: return "CalmWater";
case 26: return "TreeNoFade";
case 29: return "Skin";
case 31: return "TreeAdv";
case 32: return "TreeAdvTrunk";
  }
  }
</nowiki></code>
</nowiki></code>
----


== Links ==
== Links ==


[[User:Sy|Article Author - Sy (Synide)]] -- [[User:Sy|Sy]] 17:16, 11 August 2007 (CEST)
[[User:Sy|Article Author - Sy (Synide)]] -- [[User:Sy|Sy]] 17:16, 11 August 2007 (CEST)


[[P3D File Format - ODOLV40|Original ODOLv40 Article detailed by Bxbx (Biki'd by Mikero)]]
[[P3D File Format - ODOLV40|Original ODOLv40 Article detailed by Bxbx (Biki'd by Mikero)]]
[[Category:BIS_File_Formats]]
[[Category:Real Virtuality File Formats]]
[[Category:ArmA: File Formats]]
{{GameCategory|arma1|File Formats}}

Latest revision as of 13:27, 8 May 2025

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.

Introduction

Acknowledgements

This body of work is due to Synide's sweat and tears. To whom, all honour and glory. Ably assisted by T_D and Mikero that further detailed the data and gave this article a more general and correct structure.

General

The general format of an ArmA ODOLV4x p3d model is similar to the ODOLV7 format. The major differences are that ArmA models have

  • an optional model.cfg, and
  • Lods occur in the file from highest to lowest LodType value.

Legend

see Generic FileFormat Data Types

Relative Coordinates

All coordinates are relative to ModelInfo.CentreOfGravity

File Paths

All file references are absolute to the Linux \ (root).

As a convenience A drive letter is used (such as P:\) for sanity when modelling. The engine knows nothing about C:\my documents or even P:

The leading \ is optional.

\my_project\data\some.paa AND my_project\data\some.paa

point to the same file.

Versions

This Document covers ODOL versions:

V40 (Armed Assault)

  • Original Armed Assault binarised p3d


File Format

ODOLv4x
{
	StandardP3DHeader Header;
    struct ModelInfo;
	Animations		Animations;
	ulong			StartAddressOfLods[Header.NoOfLods]; // offset relative to start of file.
	ulong			EndAddressOfLods  [Header.NoOfLods];
	LODFaceDefaults	LODFaceDefaults;
	ODOLv40Lod		ODOLv40Lods[Header.NoOfLods];
} // EndOfFile


Structures

StandardP3DHeader

Common header structure for all P3D file formats.

struct
{
	char[4]	Filetype;		// "ODOL"
	ulong	Version;
	ulong	NoOfLods;		// alias NoOfResolutions;
}

ModelInfo

Animations

Animations
{
	tbool	AnimsExist;
	if (AnimsExist)
	{
		ulong			nAnimationClasses; // eg NoOfAnimSelections;
		AnimationClass	AnimationClasses[nAnimationClasses];

		long		NoOfResolutions; // is -1 if nAnimationClasses == 0
		Bones2Anims	Bones2Anims[NoOfResolutions];
		Anims2Bones	Anims2Bones[NoOfResolutions];
		// For every bone there is a list of Animations for each resolution
		// And, a reversed table of every Animation gets a Bone.
		// The reversed table optionally appends axis info dependent on the AnimTransformType
	}
}

AnimationClass

	AnimationClass
	{
		ulong	AnimTransformType;
		asciiz	AnimClassName;	// "RightDoor"
		asciiz	AnimSource;		// "rotor"
		float	MinMaxValue[2];
		float	MinMaxPhase[2];
		ulong	junk; // used to be sourceAddress, no longer, always 953267991
		IF ARMA3
			ulong	Always0;		// no idea what this is used for
			ulong	sourceAddress;	// this is the actual source address, 0 = clamp, 1 = mirror, 2 = loop
		endif

		switch(AnimTransformType)
		case 0://rotaton
		case 1://rotationX
		case 2://rotationY
		case 3://rotationZ
			float angle0;
			float angle1;
			break;
		case 4://translation
		case 5://translationX
		case 6://translationY
		case 7://translationZ
			float offset0;
			float offset1;
			break;
		case 8: //"direct"
			float axisPos[3];
			float axisDir[3];
			float angle; //in radians whereas the model.cfg entry is in degrees
			float axisOffset;
			break;
		case 9: //"hide"
			float hideValue;
			break;
	 }


// corresponds to model.cfg
class CfgModels
{
	// ...

	class whateverModel : Default
	{
	 // ...
	 class Animations
	 {
		class RightDoor // AnimClassName
		{
			type = "translation";	// AnimTransformType
			source = "rotor";		// AnimSource
			// etc
		};
	};
};

Bones2Anims

Bones2Anims
{
 ulong        NoOfBones;
 Bone2AnimClassList   Bone2AnimClassLists[NoOfBones];
}

Bone2AnimClassList

Bone2AnimClassList
{
 ulong NoOfAnimClasses;
 ulong AnimationClassIndex[NoOfAnimClasses]; // a (sometimes repeating) list of zero based indexes into above animation classes
}

Anims2Bones

Anims2Bones
{
 AnimBones AnimBones[Animations.nAnimationClasses];
}

AnimBones

every lod contains an identical list of animation entries that declare the position and axis of the each animation classes

AnimBones
{
 long SkeletonBoneNameIndex; // zero based index to the SkeletonBoneName name & parentname
 // equivalent to selection = "LeftDoor"; eg in the model.cfg
 /*
 ** SkeletonBoneNameIndex== -1 when no skeleton bone is for this Anim and (obviously?) no axis information follows.
 */
 if (SkeletonBoneNameIndex!= -1) && (AnimationClass.AnimTransformType != 8 || 9)
 {
 /*
 ** AnimationClass.AnimTransformType 8 (direct) and 9 (hide) never require axis information. 
 ** This because the "direct" (type 8) already has axis info in it is AnimationClass structure, 
 ** and "hidden" (type 9) clearly doesn't need it.
 */
    XYZTriplet axisPos; //describes the position of the axis used for this anim
    XYZTriplet axisDir;
 }
}

LODFaceDefaults

 tbool             UseDefault[Header.NoOfLods];
 FaceData
 {
  ulong   HeaderFaceCount;
  ulong   aDefaultLong;     //ffffffff or 6f 7a 80 fa eg
  byte    UnknownByte;      //generally zero
  byte    aFlag;            // zero or one
  bytes   Zeroes[7];
 }[Number of false UseDefault's];

A face data struct only exists for those lods who's UseDefault is zero

ODOLv4xLod

  • Lod layout corresponds to Arma1 (type40). The differences in a2 are in the nitty gritty of the structures themselves. Arrowhead(v50) has some changes.
 ODOLv4xLod
 {
   ulong                         nProxies;
   LodProxy                      LodProxies[nProxies];              // see P3D Lod Proxies
   ulong                         nLodItems;
   ulong                         LodItems[nLodItems];               // potentially compressed, except for v64 and later
   ulong                         nBoneLinks;
   LodBoneLink                   LodBoneLinks[nBoneLinks];
   float                         UnknownFloat1;
   float                         UnknownFloat2;
   XYZTriplet                    MinPos;
   XYZTriplet                    MaxPos;
   XYZTriplet                    AutoCenterPos;
   float                         Sphere;                            // same as geo or mem values in modelinfo, if this lod is geo or memlod of course
   ulong                         NoOfTextures;
   asciiz                        LodPaaTextureNames[NoOfTextures];  //"ca\characters\hhl\hhl_01_co.paa"
   ulong                         NoOfMaterials;
   LodMaterial                   LodMaterials[NoOfMaterials];
   LodEdges                      LodEdges;                          // compressed see P3D Lod Edges
   ulong                         NoOfFaces;
   ulong                         OffsetToSectionsStruct;            // see below
   ushort                        AlwaysZero;
   LodFace                       LodFace[NoOfFaces];                // see P3D Lod Faces
   ulong                         nSections;
   LodSection                    LodSections[nSections];            // see P3D Lod Sections
   ulong                         nNamedSelections;
   LodNamedSelection             LodNamedSelections[nNamedSelections]; //See P3D Named Selections potentially compressed
   ulong                         nTokens;
   NamedProperty                 NamedProperties[nTokens];          //See Named Properties
   ulong                         nFrames;
   LodFrame                      LodFrames[nFrames];                //see P3D Lod Frames
   ulong                         IconColor;
   ulong                         SelectedColor;
   ulong                         special; // IsAlpha|IsTransparent|IsAnimated|OnSurface
   byte                          vertexBoneRefIsSimple;
   ulong                         sizeOfVertexTable;                 //(including these 4 bytes)
   if (v5x)
   LodPointFlags                 LodPointFlags;                     // Potentially compressed
   endif
   VertexTable                   VertexTable;
 }

VertexTable

all arrays are subject to compression

struct
{
   UvSet                         DefaultUVset;
   ulong                         nUVs;
   UvSet                         UVSets[nUVs-1];
   ulong                         NoOfPoints;
   XYZTriplet                    LodPoints[NoOfPoints];
   ulong                         nNormals;
   (A2)LodNormals                LodNormals[nNormals];
   ulong                         nMinMax;
   (A2)LodMinMax                 MinMax[nMinMax];                   //optional
   ulong                         nProperties;
   VertProperty                  VertProperties[nProperties];       //optional related to skeleton
   ulong                         Count;
   VertexNeighborInfo            neighborBoneRef[Count];          //optional
}
  • All non zero counts counts are the same.
  • Points,PointFlags, Normals and UV1 arrays are an integral group, they are either all there, or not specified (RacetK.p3d, a FrameTime lod has no counts at all)
  • UV2,MinMax, VertProperties and Unknown are optional in the sense that their counts can individually be zero, else they are the same as the others
  • In Odol7 PointFlags are part of this stucture, in Arma, they are a separated table.

CompressedFill Arrays

LodPointFlags, LodUV's and LodNormals arrays are not only subject to the standard 1024 rule compression, but also have a fill byte.

struct
{
 ulong                         Count;
 tbool                         DefaultFill;
 if (DefaultFill)
  type                         Array;          // default fill for all Counts
 else
  type                         Array[Count];   // potentially compressed
}

The structure either contains a single set of type variables, or, an array of type variables. If a full array is declared (DefaultFill =false) then that array is subject to the 1024 rule as per normal.

UVset

if TrueARMA2
   float                         UVScale[4];
endif
   (A2)LodUV                     LodUV;

LodUV

CompressedFill type = UVPair // eg float U,V;

A2LodUV

CompressedFill type = float // eg float UV;

LodNormals

 CompressedFill type = XYZTriplet

A2LodNormals

 CompressedFill type = CompressedXYZTriplet
CompressedXYZTriplet

contains 3x 10 bit fields in a 32bit 'integer'

code for converting back to a standard XYZTriplet is:

void DecodeXYZ(ulong CompressedXYZ, XYZTriplet *triplet)
{
   double scaleFactor = -1.0 /511;
   trp->X=trp->Y=trp->Z=0.0;
   int x=   CompressedXYZ       & 0x3FF;
   int y = (CompressedXYZ>> 10) & 0x3FF;
   int z = (CompressedXYZ>> 20) & 0x3FF;
   if (x > 511) x -= 1024;
   if (y > 511) y -= 1024;
   if (z > 511) z -= 1024;
   if (x) trp->X = (float)(x * scaleFactor);
   if (y) trp->Y = (float)(y * scaleFactor);
   if (x) trp->Z = (float)(z * scaleFactor);
}

LodPointFlags

CompressedFill type = ulong bits

This table is the equivalent of Oxygen's points->properties dialog box. It specifically stores the user values and other flags for that point.

In ODOl7 it was part of the vertex table. In ArmA, it is separate.

See P3D Point and Face Flags

LodMinMax

CompressedArray
{
 XYZTriplet     MinMax[Count][2]; // 2 == min vs max
}

A2LodMinMax

CompressedArray
{
 float         MinMax[Count][2]; // 2 == min vs max
}

VertProperty

CompressedArray
{
 ulong  index;// seen range 0..4
 ulong  a,b; // definite not floats. might be flags, or indices
}

VertexNeighborInfo

CompressedArray
{
 ushort  vertexIndex _posA;
 AnimationRTWeight _rtwA;
 ushort  vertexIndex _posB;
 AnimationRTWeight _rtwB;
}

LodBoneLink

LodBoneLink
{
  ulong NoOfLinks;         //range 0..3
  ulong Value[NoOfLinks];  //the 'Value' seems to reference the 'LodItems' structure, resulting in a circular-reference.
}

LodMaterials

Basically... A direct replication of the information in the given .rvmat file

The stages in the p3d include a default stage and a TI stage that are not normally listed in the rvmat.

The first stage (in the p3d) is unconditionally the default stage. It is defaulted to empty (RvMatName=""), unless, specified in the rvmat
The last stage is the TI stage, and is also defaulted empty, unless specified in the rvmat.
TI Stages were introduced for operation arrowhead. Lod Material Types 9 and 10 (Arma1 and Arma2) do not have a TI stage at all.

Neither of these two special, hidden, stage types use uvsets. The transform matrix for them is defaulted empty (so-called 'TexGen0').

When specified in the rvmat (class Stage0 and StageTI respectively), no class uvTransform is declared for them. It is assumed default empty.

In an rvmat, uvTransforms are ordinarily declared within each stage body.

In a P3D, identical UVTransforms are declared once, and multiple 'stages' refer to them. There is, always, a default UVSet0 Transform as the 1st entry. (IE some stages dont require uvsets)

This P3D style can, if preferred, be used in rvmat syntax as

class TexGenX
{
  .......
};
class StageZ
{
  .........
  Texgen=X;
};

where X and Z are numbers


LodMaterial

 LodMaterial
 {
   asciiz            RvMatName;     // "ca\characters\data\soldier_captive_hhl.rvmat"
   ulong             Type;          // 9 == ArmA
   D3DCOLORVALUE     Emissive;
   D3DCOLORVALUE     Ambient;
   D3DCOLORVALUE     Diffuse;
   D3DCOLORVALUE     forcedDiffuse;
   D3DCOLORVALUE     Specular;
   D3DCOLORVALUE     Specular2;       //Usually same as Specular
   float             SpecularPower;   // 
   ulong            PixelShaderId;   //See enumPixelShaderId
   ulong            VertexShaderId;  //See enumVertexShaderId
   LongBool          mainLight;     // 1 or zero
   ulong             ul_FogMode;    /// 0..4
   Asciiz            BiSurfaceName;   // "ca\data\Penetration\plastic.bisurf"
   LongBool          Arma1Mostly1;    //rarely zero
   ulong             RenderFlags;     //Generally 0
   ulong             nTextures;
   ulong             nTransforms;     // always same as nTextures
   LodStageTexture   StageTextures  [nTextures];
   LodStageTransform StageTransforms[nTransforms];
 }  
Each lodmaterial entry contains a default StageTexture and StageTransform as the first entry. It is not shown in the rvmat file and has no PaaTexture
It is the only entry if a SurfaceName exists.

D3DCOLORVALUE

D3DCOLORVALUE
{
  float r,g,b,a;
}
RenderFlags
  • Bit0:AlwaysInShadow (A1 only)
  • Bit1:NoZWrite
  • Bit4:NoColorWrite
  • Bit5:NoAlphaWrite
  • Bit6:AddBlend
  • Bit7:AlphaTest (clutter)
  • Bit8:AlphaTest64 (clutter)
  • Bit19:Road (a1only)
  • Bit11:NoTiWrite
LodStageTexture
LodStageTexture
{
 ulong  TextureFilter; // see below
 asciiz PaaTexture;    // "ca\characters\data\civil_tvreport_body_as.paa
                       // alternatively "#(argb,8,8,3)color(0,0,0,1,CO)" (eg)
 ulong  TransformIndex;       // zero based, see below
};
The first stageTexture is a dummy entry. For N humanly readable stage classes, there are 1+N LodStageTextures
TextureFilter maybe 1 of the following values.
  • 0: Point // sometimes
  • 1: Linear // rarely
  • 2: TriLinear // not seen
  • 3: Anisotropic (default)
LodStageTransform
  LodStageTransform
  {
   ulong UVSource;
   float Transform[4][3];//a DirectX texture space transform matrix
  };
UVSource corresponds to the 8 possible uvsets available
  • 0 "None"
  • 1 "Tex" default
  • 2: "Tex2"
  • ........
  • 8:"Tex8"
  • Tex1..8 cannot be taken literally as uvsource 1..8. They can mean anything, according to the template and are scarcely encountered

NamedProperty

 struct
 {
    Asciiz Property;// "noshadow" = "1" eg
    Asciiz Value;
 }

Decompression

see Compressed LZSS File Format

see Compressed LZO File Format


In ODOL v40 format files, some of the data structures present in the file are compressed by using LZSS compression.

Unlike pbo compression, in ArmA model files, one only knows the number of items to decompress, the expected output size (in bytes) and the expected checksum. With this information and the size of a given data item one has the necessary information to expand the data to it is original format and size.

Data structures that are identified as being compressible will only be compressed if the 'expectedSize' is ≥ 1024 bytes.


Reference Tables

Material Stages

The number of material stages is dependant on the type of Shader that is used to process the material by the ArmA game engine. A reference table is used when processing materials where depending on the shader specified the given number of stages should be processed.

refShaderStages { int PixelShaderId; int NoOfStages; };

ID (Hex/Decimal) Name Description NoOfStages
0x00, 0 Normal diffuse color modulate, alpha replicate 0
0x01, 1 NormalDXTA diffuse color modulate, alpha replicate, DXT alpha correction 0
0x02, 2 NormalMap normal map shader 3
0x03, 3 NormalMapThrough normal map shader - through lighting 3
0x04, 4 NormalMapSpecularDIMap VBS2 only 2
0x05, 5 NormalMapDiffuse ? 2
0x06, 6 Detail ? 1
0x07, 7 ? ? ?
0x08, 8 Water A1 only sea water 2
0x09, 9 ? vbs2 ?
0x0A, 10 White A1 only 0
0x0B, 11 ? vbs2 ?
0x0C, 12 AlphaShadow shadow alpha write 0
0x0D, 13 AlphaNoShadow shadow alpha (no shadow) write 0
0x0E, 14 ? vbs2 ?
0x0F, 15 DetailMacroAS ? 3
0x10, 16 ? vbs2 ?
0x11, 17 ? vbs2 ?
0x12, 18 NormalMapSpecularMap ? 2
0x13, 19 NormalMapDetailSpecularMap Similar to NormalMapDiffuse 3
0x14, 20 NormalMapMacroASSpecularMap ? 4
0x15, 21 NormalMapDetailMacroASSpecularMap ? 5
0x16, 22 NormalMapSpecularDIMap Same as NormalMapSpecularMap, but uses _SMDI texture 2
0x17, 23 NormalMapDetailSpecularDIMap ? 3
0x18, 24 NormalMapMacroASSpecularDIMap ? 4
0x19, 25 NormalMapDetailMacroASSpecularDIMap ? 5
0x38, 56 Glass ? 2
0x3A, 58 NormalMapSpecularThrough ? 3
0x3B, 59 Grass Special shader to allow volumetric shadows to be cast on grass clutter 0
0x3C, 60 NormalMapThroughSimple ? 0
0xxx, 102 Super Arrowhead 0
0xxx, 103 Multi Arrowhead 0
0xxx, 107 Tree Arrowhead 0
0xxx, 110 Skin Arrowhead 0
0x6F, 111 CalmWater Arrowhead 7
0xxx, 114 TreeAdv Arrowhead 0
0xxx, 116 TreeAdvTrunk Arrowhead 0


Enums

int enum VertexShaderId { case 0: return "Basic"; case 1: return "NormalMap"; case 2: return "NormalMapDiffuse"; case 3: return "Grass"; case 8: return "Water"; case 11: return "NormalMapThrough"; case 15: return "NormalMapAS"; case 14: return "BasicAS"; case 17: return "Glass"; case 18: return "NormalMapSpecularThrough"; case 19: return "NormalMapThroughNoFade"; case 20: return "NormalMapSpecularThroughNoFade"; case 23: return "Super"; case 24: return "Multi"; case 25: return "Tree"; case 30: return "CalmWater"; case 26: return "TreeNoFade"; case 29: return "Skin"; case 31: return "TreeAdv"; case 32: return "TreeAdvTrunk"; }

Links

Article Author - Sy (Synide) -- Sy 17:16, 11 August 2007 (CEST)


Original ODOLv40 Article detailed by Bxbx (Biki'd by Mikero)