P3D File Format - ODOLV4x: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
 
(282 intermediate revisions by 12 users not shown)
Line 1: Line 1:
{{unsupported-doc}}
{{TOC|side}}
{{Feature|UnsupportedDoc}}
== 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 [[P3D Model Info|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 ({{arma1}}) ====
 
* Original {{arma1}} binarised p3d
 
==== VBS2 ====
• [[P3D Model Info|ModelInfo]] now has a 24 byte thermal profile appended
 
==== V43 (Arma2a) ====
 
* As per VBS2 plus
* An extra byte at end of Skeleton structure: always 0
* LZSS compression is still used at this level
 
====V47 (Arma2b LZO) ====


== Introduction ==
As per V43 plus:
 
* all compressed blocks are LZO compressed
* CompressedMinMax block is now nMinMax*8 in size
* CompressedNormals block is now nNormals*4 in size
* LodFrame has 4 extra floats
* UVSet structure changed to:
<syntaxhighlight lang="cpp">
LodUV
{
float uvScaling[4];
ulong nVertices;
tbool DefaultFill;
if (DefaultFill)
float UV; // default fill for all nVertices
else
float UV[nVertices]; // potentially compressed
}
</syntaxhighlight>
 
==== V48 (Arma2c) ====
As per V47 plus:
* [[P3D Model Info|ModelInfo]] has a 4 byte appendix
 
Arma2c format is the mainstay of Arma2. Types 43 and 47 are rarely encountered being works-in-progress in the initial release.
 
==== V49 (Arrowhead) ====
As per V48. No known differences apart from version number
 
==== V50 (Arrowhead DLC) ====
 
Introduced in PMC and BAF DLC
* additional count after usedbones
*lodPointFlags swapped around
 
==== V53 (Dayz) ====
*edges set to zero
 
*added Specular and Specular2  to rvmats
 
*added SpecularPower and SpecularPower2 stage info type 15 to rvmats
 
* added htMin,htMaz etc thermal info to rvmat stage infos (same as vbs)
*added disableCover
*added optional; bisurf data


The general file format of a ArmA ODOL v40 p3d model file is similar to the ODOL v7 format.
==== V54 (Dayz) ====
The major differences are that in ArmA models there is now included (but not always) a model.cfg and the resolutions are ordered in the file in reverse numerical order.
bool added to [[P3D Model Info|ModelInfo]]


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)
==== V52 (TOH) ====
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.
intoduced in patch to BAF DLC, used mostly in TOH
*additional float after usedbones in each lod
* ModelInfo.PixelShaders additional 24 bytes
* LODFaceDefaults additional count and float
* LodStageTextures additional bool for type 11's


==== V56 ({{arma3}}) ====
same as V52 Plus:
* thermal profile split into two chunks (same overall size as v52)
* unknown byte indices increased from 12 to 14
* animation class always four floats
* physx data added at end of file


==== V58 ({{arma3}}) ====
* prefix added to header
* default indicators added at end of headerinfo


<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>
==== V59 ({{arma3}}) ====
* no genuine changes simply an alteration of the type value from 32 to 64 bits


==== V60 ({{arma3}}) ====
* alteration to the physx data at end of file


=== Legend ===
==== V64 ({{arma3}}) ====
* Compressed sections no longer follow the 1024 byte rule, they now have a byte field for compressed or not


{| border="0"
==== V67 ({{arma3}}) ====
!width="100"|Type
* LOD sections have an added 4 bytes and optional CollimatorInfo structure
!width="300" align="left"|Description
* LOD struct has additional 4 bytes at the end and optional CollimatorInfo structure
|-
|-
|align="middle"|byte||align="left"| 8 bit (1 byte)
|-
|align="middle"|ushort||align="left"| 16 bit unsigned short (2 bytes)
|-
|align="middle"|int||align="left"| 32 bit signed 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
|-
|-
|}


----
==== V68 ({{arma3}}) ====
* LOD struct has an additional byte at the end
==== V69 ({{arma3}}) ====
edges changed from shorts to longs
face structure changed from shorts to longs
face indices ditto
point_indices changed from shorts to longs
==== V70 ({{arma3}}) ====
float ModelInfo.lodDensityCoef added
==== V71 ({{arma3}}) ====
float  ModelInfo.drawImportance added
==== V72 ({{arma3}}) ====
float ModelInfo.explosionshielding added
==== V72 ({{arma3}}) ====
bool ModelInfo.disableCover added
==== V75 ({{arma3}}) ====
optional encrypted p3d signature


== File Format ==
== File Format ==
<syntaxhighlight lang="cpp">
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];
if (any arma3 type)
{
long Always0;
A3_Physx A3_Physx[...]; // optional if not v60
}
} // EndOfFile
</syntaxhighlight>




The following is a mix of ''pseudo-code'' and structure references that could be used to discribe the file format of ODOL v40.
== Structures ==
It may or may not be accurate but has do date been used to read ODOL v40 is 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.


=== StandardP3DHeader ===


=== Simple ===
common header structure for all P3D file formats


<code><nowiki>
<syntaxhighlight lang="cpp">
  ODOLv40
struct
  {
{
    Header;
char[4] Filetype; // "ODOL"
    Model.cfg; (optional)
ulong Version;
    Resolutions; (reverse numerical order)
  }
</nowiki></code>


=== Detailed ===
if Version>=75 (arma3)
      ulong enc1;
      ulong enc2;
      if enc1 or enc2
        return encrypted
   
if Version>=58 (arma3)
      ulong  appid;
  if Version==58 (arma3)
Asciiz P3dPrefix; // \a3\data_f\proxies\muzzle_flash\muzzle_flash_rifle_mk20
ulong NoOfLods; // alias NoOfResolutions;
}
</syntaxhighlight>


<code><nowiki>
An '''optional''' prefix declaring the actual location of the p3d was introduced for arma3 (2nd version). Idiotically, it means the p3d cannot be moved out of it is current pbo.


  ODOLv40
The prefix is optional in the sense that it may be null. ("\0")
  {
    structP3DHeader Header;
    byte[155] Unknown;
    structSkeleton Skeleton;
    byte unknown1;
    byte unknown2;
    if(unknown2== 0x00)
    {
      byte[31] byteArrayUnknown1;
    }
    else
    {
      byte[32] byteArrayUnknown1;
    }
    int unknown4;
    byte unknown5;
    asciiz ModelString1;
    asciiz ModelString2;
    byte[5] byteArrayUnknown2;
    byte AnimsExist;
    if (AnimsExist == 0x01)
      {
        int NoOfAnimSelections;
        structAnimation[NoOfAnimSelections] Animations;


        //Basically... for each bone there is a list of Animations and this array structure
[[P3D Model Info|ModelInfo]]
        //            is stored on a per resolution basis.
        int NoOfResolutions;
        for(int i=0; i<NoOfResolutions; i++)
        {
          int NoOfBones;
          for(int ii=0; ii<NoOfResolutions; ii++)
          {
            int NoOfAnims;
            if (NoOfAnims > 0)
              {
                for(int iii=0; iii<NoOfAnims; iii++)
                {
                  int Animation;
                }
              }
          }
        }


        //Unknown Anim info...
=== Animations ===
        //Basically... for each Animation if the TransformType !=9 then there
        // is a 6 x float of positional info.
        for(int i=0; i<NoOfResolutions; i++)
        {
          int Anim;
          if (Anim != -1)
            {
              if (Animations[Anim].TransformType != 9)
              {
                  float[6] UnknownAnimInfo;
              }
            }
        }
      }//AnimExist
    byte[Header.NoOfResolutions * 8] Unknown8;
    bool[Header.NoOfResolutions] ResolutionFaceIndicator;


    //Basically...For each Resolution if the LODFaceIndicator is true
<syntaxhighlight lang="cpp">
    //there is a int FaceCount + 13 bytes
Animations
    //I think this 'indicator' may serve other areas but at the very least it indicates
{
    //the following structure
tbool AnimsExist;
    for (int i = 0; i < Header.NoOfResolutions; i++)
if (AnimsExist)
    {
{
        if (LODFaceIndicator[i])
ulong nAnimationClasses; // eg NoOfAnimSelections;
        {
AnimationClass AnimationClasses[nAnimationClasses];
            int HeaderFaceCount;
            byte[13] Unknown9;
        }
    }


    int NoOfModelProxies;
long NoOfResolutions; // is -1 if nAnimationClasses == 0
    if (NoOfModelProxies != 0)
Bones2Anims Bones2Anims[NoOfResolutions];
    {
Anims2Bones Anims2Bones[NoOfResolutions];
      structProxy[NoOfModelProxies] ModelProxies;
// 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
}
}
</syntaxhighlight>


=== AnimationClass ===


    structResolution[Header.NoOfResolutions]; //Note:- Remember, the order in which lod's
<syntaxhighlight lang="cpp">
                                              //       occur is descending numerical order.
AnimationClass
                                              //       eg. Resolution 1.0 will be the last in
{
                                              //          the file.
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


    //EndOfFile
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;
}


</nowiki></code>


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


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


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


=== structP3DHeader ===
==== Anims2Bones ====
<code><nowiki>
  Anims2Bones
  struct structP3DHeader
  {
  {
  asciiz                  Filetype; //eg. ODOL
  AnimBones AnimBones[Animations.nAnimationClasses];
  int                      Version;    //eg. 0x2800 0000 = 40
  int                      NoOfResolutions;
  float[NoOfResolutions]   HeaderResolutions;
  }
  }
</nowiki></code>


=== structBone ===
==== AnimBones ====
<code><nowiki>
 
   structBone
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)
   {
   {
    asciiz Bone;
  /*
    asciiz Parent;
  ** 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>
}


=== structSkeleton ===
=== LODFaceDefaults ===
<code><nowiki>
  tbool            UseDefault[Header.NoOfLods];
   structSkeleton
   FaceData
   {
   {
    asciiz                  SkeletonName;
  ulong  HeaderFaceCount;
     if (SkeletonName != null)
  ulong  aDefaultLong;     //ffffffff or 6f 7a 80 fa eg
    {
  byte    UnknownByte;     //generally zero
      bool                    isInherited;
  byte    aFlag;           // zero or one
      int                    NoOfBones;
  bytes  Zeroes[7];
      structBone[NoOfBonesBones;
  ======if v52 =========
    }
  ulong  AnotherCount;
   }
  float   AnotherFloat;
</nowiki></code>
  =======endif===========
   }[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.
*TrueArma2 == type 47 or greater (lzo compression)
*Type 43 was a preliminary p3d prior to lzo compression. rarely encountered


=== structAnimation ===
   ODOLv4xLod
<code><nowiki>
   structAnimation
   {
   {
     int        AnimTransformType;
     ulong                        nProxies;
     asciiz      AnimSelection;
     LodProxy                      LodProxies[nProxies];              // see [[P3D Lod Proxies]]
     asciiz      AnimSource;
    ulong                        nLodItems;
     if (AnimTransformType == 9)
    ulong                        LodItems[nLodItems];               // potentially compressed, except for v64 and later
       {
     ulong                        nBoneLinks;
        float[6] Transforms;
     LodBoneLink                  LodBoneLinks[nBoneLinks];
      }
  =========if v5x==========
      else
    ulong                        LodPointCount;
      {
       if v52
        float[7] Transforms;
    float                        UnknownV52Float;
      }
    endif
    else
    LodPointFlags                LodPointFlags;                    // Potentially compressed
===========endif==========
    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;
=== V65 ===
    ulong  UnknownLongValue1
    if UnknownLongValue1
    {
        CollimatorInfo  unknown //Vec3,Vec3,ulong,vec3,ulong
    }
===========
=== V68 ===
    byte unknown;
===========
   }
   }
</nowiki></code>
==== VertexTable ====
 
all arrays are subject to compression
 
struct
{
    UvSet                        DefaultUVset;
    ulong                        nUVs;                              //in error, V47 sometimes sets nUV's as 0 but means 1
    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 [[P3D Lod Frames|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 3 x 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
}


=== structProxy ===
==== VertexNeighborInfo ====
<code><nowiki>
CompressedArray
   structProxy
{
   {
   ushort  vertexIndex _posA;
    asciiz      ProxyName;
   AnimationRTWeight _rtwA;
    float[12]   ModelProxyUnknown1;
   ushort  vertexIndex _posB;
    int[4]      ModelProxyUnknown2;
  AnimationRTWeight _rtwB;
  }
}
</nowiki></code>


=== structStage ===
==== LodBoneLink ====
<code><nowiki>
  structStage
  {
    asciiz  StageTexture;
    int      Stage;
    int      UVSource;
    float[3] aside;
    float[3] up;
    float[3] dir;
    float[3] pos;
  }
</nowiki></code>


=== structMaterial ===
LodBoneLink
<code><nowiki>
{
  structMaterial
  ulong NoOfLinks;         //range 0..3
  {
  ulong Value[NoOfLinks]; //the 'Value' seems to reference the 'LodItems' structure, resulting in a circular-reference.
    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>
==== LodMaterials ====
    //Basically... A direct replication of the information in the given .rvmat file
Basically... A direct replication of the information in the given .rvmat file
    for (int i = 0; i < NoOfMaterials; i++)
    {
      asciiz Material;
      byte[4] byteArrayMaterialUnknown1;
      float[4] Emissive;
      float[4] Ambient;
      float[4] Diffuse;
      float[4] forcedDiffuse;
      float[4] Specular;
      float    SpecularPower;
      int      PixelShaderId; //See enumPixelShaderId
      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++)
          {
            byte[4]  byteArrayMaterialUnknown3;
            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>


=== structPolygons ===
The stages in the p3d include a default stage and a TI stage that are not normally listed in the rvmat.
<code><nowiki>
:The first stage (in the p3d) is unconditionally the default stage. It is defaulted to empty (RvMatName=""), unless, specified in the rvmat
  structPolygons
: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.
    byte NoOfVertices; // 3 or 4
Neither of these two special, hidden, stage types use uvsets. The transform matrix for them is defaulted empty (so-called 'TexGen0').
    ushort[NoOfVertices] VerticesIndex; // 0-based index into Vertices Arrays
  }
</nowiki></code>


=== structComponent ===
When specified in the rvmat (class Stage0 and StageTI respectively), no  class uvTransform is declared for them. It is assumed default empty.
<code><nowiki>
  structComponent
  {
    asciiz ComponentName;


    //Selected Faces
In an rvmat, uvTransforms are ordinarily declared within each stage body.
    int NoOfSelectedFaces;
    ushort[NoOfSelectedFaces] SelectedFaceIndexes;


    int intComponentUnknown1;
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)
    bool bComponentUnknown1;
    if (bComponentUnknown1)
    {
      int NoOf;
      int[NoOf] intArrayComponentUnknown1;
    }
    else
    {
      int intComponentUnknown2;
    }


    // Selected Vertices
This P3D style can, if preferred, be used in rvmat syntax as
    int NoOfSelectedVertices;
class TexGenX
    ushort[NoOfSelectedVertices] SelectedVerticesIndexes; // Zero based array of index values into
  {
                                                          // the array of Vertices.
  .......
                                                          // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
};
                                                                      compressed.


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


where X and Z are numbers


=== structProperties ===
<code><nowiki>
  structProperties
  {
    asciiz Property;
    asciiz Value;
  }
</nowiki></code>


=== structUV ===
====LodMaterial====
<code><nowiki>
   LodMaterial
   structUV
   {
   {
    float u;
    asciiz            RvMatName;    // "ca\characters\data\soldier_captive_hhl.rvmat"
    float v;
    ulong            Type;          // 9 == Arma, 10==VBS2,11==Arrowhead
   }
    D3DCOLORVALUE    Emissive;
</nowiki></code>
    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;    //A2 deprecated, always 1 //A1 rarely zero                                 
    ulong            RenderFlags;    //Generally 0
    ulong            nTextures;
    ulong            nTransforms;    // always same as nTextures
    LodStageTexture  StageTextures  [nTextures];
    LodStageTransform StageTransforms[nTransforms];
    if type>=10//vbs2/arma2
    LodStageTexture  DummyStageTexture;// see special, additional byte for THIS stagetexture
    endif 
   
  } 


=== structVerticesPosition ===
: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
<code><nowiki>
:It is the only entry if a SurfaceName exists.
  structVerticesPosition
  {
    float x;
    float z;
    float y;
  }
</nowiki></code>


=== structVerticesNormal ===
=== A3_Physics Type1 (optional) ===
<code><nowiki>
  structVerticesNormal
  {
    float x;
    float z;
    float y;
  }
</nowiki></code>


=== structVerticesMinMax ===
<code><nowiki>
  structVerticesMinMax
   {
   {
    float x1;
    A3_stanza A3_stanzas[...]; // optional
    float z1;
    float aFloat;
    float y1;
    float x2;
    float z2;
    float y2;
   }
   }
</nowiki></code>
*The type1 structure may not be present at all, or, only contain the single ending float


=== structVerticesUnknown1 ===
==== A3 stanza ====
<code><nowiki>
  structVerticesUnknown1
  {
    ushort One;
    ushort Two;
    ushort Three;
    ushort Four;
    ushort Five;
    ushort Six;
  }
</nowiki></code>


=== structResolution (simple) ===
{
<code><nowiki>
  //header//////
   structResolution
  long   Xcount,Ycount,Zcount;
  {
  float  floats[4];
    NoOfVertices;
  long  minCount; //Always2;
    <space>
  long  maxCount; //Always4;
    NoOfTextures;
  //////////////
    Textures;
  float frames[Xcount*Ycount*Zcount][5];
    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) ===
A header with no frames is legal, it is XYZcounts (and floats[4]) are zero.
<code><nowiki>
  structResolution
  {
    int        NoOfVertices;
    byte        byteResUnknown1;
    byte        byteResUnknown2;
    switch (byteResUnknown2)
    {
        case 0x00: { byte[40] byteArrayResUnknown1; break; }
        case 0x20: { byte[45] byteArrayResUnknown1; break; }
        case 0x30: { byte[45] byteArrayResUnknown1; break; }
        case 0xFF: { byte[45] byteArrayResUnknown1; break; }
        case 0x3F: { byte[51] byteArrayResUnknown1; break; }
    }
    int                            NoOfTextures;
    asciiz[NoOfTextures]            Textures;
    int                            NoOfMaterials;
    structMaterial[NoOfMaterials]  Materials;


    byte[8] byteArrayResUnknown2;
A 'stanza' consists of 5 float values. The amount of stanzas (if any) are determined by the 3 counts.
    int NoOfPolygons;
    byte[6] byteArrayResUnknown3;
    structPolygons[NoOfPolygons] Polygons;
   
    //Model 'Section' Info. Unknown structure, however this code snippet iterates over it
    int NoOfSections;
    for (int i = 0; i < NoOfSections; i++)
    {
      byte[26] byteArrayResUnknown4;
      byte byteResUnknown3;
      if (byteResUnknown3 == 0xFF)
      {
        byte[16] byteArrayResUnknown5;
      }
      else
      {
        byte[15] byteArrayResUnknown5;
      }
    }//EndOf Model 'Section' info. structure


    int NoOfComponents;
The range of each count value varies between 2,3 and 4.
    structComponent[NoOfComponents] Components;


    int NoOfProperties;
    structProperties[NoOfProperties] Properties;


    ushort usUnknown1;
=== A3 Physx type60 ===
    ushort usUnknown2;
Introduced for format 60
    if (usUnknown2 == 0)
{
    {
  long      signature; // 0x03020400
      byte[17] byteArrayResUnknown6;
  long      nStanzas;
    }
  stanza60  stanza60s[nStanzas];
    else
  long      signature; // same as above
    {
  long      nStanzas2;
      byte[15] byteArrayResUnknown6;
  stanza60  stanza60s2[nStanzas2];
    }
};
==== stanza60 ====
{
  {// 1st stanza
  long    signature;//0x03020400
  long    size;
  bytes  phsyx_data[size];
  }
  {// 2nd stanza
  long    signature;// as above
  long    size;
  bytes  phsyx_data2[size];
  }
}
* the signatures and sizes are NOT optional. the data is
===== phsyx_data =====
{
  phsyx_header
  {
    {
      byte id[8]; // 'NXS.CVXM'
      long Always13;
      long Always0;
    }
    {
      byte id[8]; // 'ICE.CLHL'
      long Always6;
    }
    {
      byte id[8]; // always 'ICE.CVHL'
      long Always6;
    }
    long nTriplets;
    long count;
    long nFrames;
    long 2xcount;  // always dbl 'count'
  }
  tripletXYZ triplets[nTriplets];
  short 00;
  frames
  {
    float floats[4];
    long  value;
  }frames[nFrames];
  byte index[variable length];
  //25x4 byte ending sequence
  float generally_zero;
  float f;
  long  value;
  float floats[7];
  long  value2;
  float floats[14];
};
*the amount of index bytes can be determined by end of frame data to the start of the fixed 25x4 offset at end of lod


    int NoOfVertices;
=== D3DCOLORVALUE ===
    byte bUV
D3DCOLORVALUE
    if (bUV == 0x00)
{
    {
  float r,g,b,a;
        structUV[NoOfVertices2ndUV] VerticesUVSet1;        //  </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
}
                                                                      compressed.
===== RenderFlags =====
      int NoOfVertices2ndUV;
:*Bit0:AlwaysInShadow (A1 only)
    }
:*Bit1:NoZWrite
    else
:*Bit4:NoColorWrite
    {
:*Bit5:NoAlphaWrite
      byte[12] byteArrayResUnknown7;
:*Bit6:AddBlend
    }
:*Bit7:AlphaTest (clutter)
:*Bit8:AlphaTest64 (clutter)
:*Bit19:Road      (a1only)
:*Bit11:NoTiWrite


    if (NoOfVertices2ndUV == 2)
===== LodStageTexture =====
    {
LodStageTexture
      int NoOfVertices2ndUV;
{
      byte bUV;
  ulong  TextureFilter; // see below
       if (bUV == 0x00)
  asciiz PaaTexture;   // "ca\characters\data\civil_tvreport_body_as.paa
      {
                        // alternatively "#(argb,8,8,3)color(0,0,0,1,CO)" (eg)
        structUV[NoOfVertices2ndUV] VerticesUVSet2;       // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
  ulong  TransformIndex;       // zero based, see below
                                                                      compressed.
if =======Type11 AND V52 OR Type11 AND last(dummy) stage Texture ===================
      }
  byte  V52Type11bool;   // only for arrowhead/pmc . and only for material types 11
      else
endif
      {
};
        byte[8] byteArrayResUnknown8;
      }
    }


    int NoOfVertices;
:The first stageTexture is a dummy entry. For N humanly readable stage classes, there are 1+N LodStageTextures
    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;
:Later p3d formats (VBS2, Operation Arrowhead) append an additional classTI LodStageTexture. if not present or declared in the rvmat file, it is a dummy entry. The rvmat gui editor from BisTools is not able to display this.
    if (NoOfVertices != 0)
    {
      structVerticesMinMax[NoOfVertices] VerticesMinMax;  // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
    }                                                                compressed.


    int NoOfVertices;
:The TransformIndex is generally iterative (linear sequential). 1st entry is 0, 2nd 1, 3rd 2, etc. It refers to the nTH Transform Matrix
    if (NoOfVertices != 0)
    {
      structVerticesUnknown1[NoOfVertices] VerticesUnknown1;  // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
      int NoOfVertices;                                              compressed.
    }


    if (NoOfVertices != 0)
:TextureFilter maybe 1 of the following values.
    {
:*0: Point // sometimes
      byte[32][NoOfVertices] VerticesUnknown2;  // </nowiki><b>''Note:-''</b><nowiki> If expectedSize >= 1024 bytes this array is
:*1: Linear  // rarely
    }                                                                compressed.
:*2: TriLinear // not seen
:*3: Anisotropic (default)


    if (Pointer < Filesize)
===== LodStageTransform =====
    {
  LodStageTransform
      int NoOfProxies;
  {
      if (ProxyCount != 0)
    ulong UVSource;
      {
    float Transform[4][3];//a DirectX texture space transform matrix
          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...
:UVSource corresponds to the 8 possible uvsets available
  // 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.
:*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


   //EndOfResolution
==== NamedProperty ====
   struct
  {
    Asciiz Property;// "noshadow" = "1" eg
    Asciiz Value;
   }
   }
</nowiki></code>


----
*See [[Named Properties]]


== Decompression ==
== Decompression ==


In ODOL v40 format files some of the datastructures present in the file are compressed by using a form of LZ compression.
see [[Compressed LZSS File Format]]
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.
see [[Compressed LZO File Format]]




<b>''Note:- Data structures that are identified as being compressible will only be compressed if the 'expectedSize' is >= 1024 bytes.''</b>
In ODOL v40 and v43 format files, some of the data structures present in the file are compressed by using LZSS compression.
ODOL v47 and v48 use LZO compression. This is represented as


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.


<b>''The code that follows is written in C# and may or may not be optimal or correct.''</b>
<b>''Note:- Data structures that are identified as being compressible will only be compressed if the 'expectedSize' is >= 1024 bytes.''</b>


<b>V64+</b>
v64 implements a new flag for all compressed blobs. They no longer follow the 1024 byte rule. All possibly compressed arrays are now:


ulong elementCount
byte  compressed
    0 - not compressed
    2 - compressed
byte  data[elementCount]


As an example if one was expanding the array of vertices positions...
As an example if one was expanding the array of vertices positions...


* A vertex is described by it's x,y,z coordinates which are floats. A float is a 32bit (4 byte) number.
* A vertex is described by it is x,y,z coordinates which are floats. A float is a 32bit (4 byte) number.
* If we were processing 1968 vertices then our expected output size would be 1968 * (3 * 4) = 23,616 bytes.
* 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.
This 'expectedSize' is the only necessary information one would need to pass to a processing sub-routine or function.


<code><nowiki>
  public bool Expand(int ExpectedSize)
  {
      byte PacketFlagsByte; //packet flags
      byte WIPByte;
      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);


      PacketFlagsByte = br.ReadByte();
      do
      {
          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>
----


== Reference Tables ==
== Reference Tables ==


Note: These are not part of the p3d model file but are reference tables used for processing.
=== Resolutions ===
<code><nowiki>
refResolutions
{
  float  Resolution;
  string ResolutionName;
}
</nowiki></code>
{| border="0"
!width="50" align="left"|Value
!width="150" align="left"|Value
!width="300" align="left"|Description
|-
|-
|align="left"|1.0e3||align="left"|1,000||align="left"|View Gunner
|-
|align="left"|1.1e3||align="left"|1,100||align="left"|View Pilot
|-
|align="left"|1.2e3||align="left"|1,200||align="left"|View Cargo
|-
|align="left"|1.0e4||align="left"|10,000||align="left"|Stencil Shadow
|-
|align="left"|1.001e4||align="left"|10,010||align="left"|Stencil Shadow 2
|-
|align="left"|1.1e4||align="left"|11000||align="left"|Shadow Volume
|-
|align="left"|1.101e4||align="left"|11010||align="left"|Shadow Volume 2
|-
|align="left"|1.0e13||align="left"|10,000,000,000,000||align="left"|Geometry
|-
|align="left"|1.0e15||align="left"|1,000,000,000,000,000||align="left"|Memory
|-
|align="left"|2.0e15||align="left"|2,000,000,000,000,000||align="left"|Land Contact
|-
|align="left"|3.0e15||align="left"|3,000,000,000,000,000||align="left"|Roadway
|-
|align="left"|4.0e15||align="left"|4,000,000,000,000,000||align="left"|Paths
|-
|align="left"|5.0e15||align="left"|5,000,000,000,000,000||align="left"|HitPoints
|-
|align="left"|6.0e15||align="left"|6,000,000,000,000,000||align="left"|View Geometry
|-
|align="left"|7.0e15||align="left"|7,000,000,000,000,000||align="left"|Fire Geometry
|-
|align="left"|8.0e15||align="left"|8,000,000,000,000,000||align="left"|View Cargo Geometry
|-
|align="left"|9.0e15||align="left"|9,000,000,000,000,000||align="left"|View Cargo Fire Geometry
|-
|align="left"|1.0e16||align="left"|10,000,000,000,000,000||align="left"|View Commander
|-
|align="left"|1.1e16||align="left"|11,000,000,000,000,000||align="left"|View Commander Geometry
|-
|align="left"|1.2e16||align="left"|12,000,000,000,000,000||align="left"|View Commander Fire Geometry
|-
|align="left"|1.3e16||align="left"|13,000,000,000,000,000||align="left"|View Pilot Geometry
|-
|align="left"|1.4e16||align="left"|14,000,000,000,000,000||align="left"|View Pilot Fire Geometry
|-
|align="left"|1.5e16||align="left"|15,000,000,000,000,000||align="left"|View Gunner Geometry
|-
|align="left"|1.6e16||align="left"|16,000,000,000,000,000||align="left"|View Gunner Fire Geometry
|-
|align="left"|1.7e16||align="left"|17,000,000,000,000,000||align="left"|Sub Parts
|-
|-
|}


=== Material Stages ===
=== Material Stages ===
Line 821: Line 796:
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 844: Line 819:
|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 852: Line 827:
|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 864: Line 839:
|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 895: Line 870:
|-
|-
|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
|-
|-
|-
|-
Line 903: Line 892:
== Enums ==
== Enums ==


<code><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>
 
<code style="display: block"><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>
Line 936: Line 927:


[[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]]
{{GameCategory|arma1|File Formats}}

Latest revision as of 07:24, 8 November 2024

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

VBS2

ModelInfo now has a 24 byte thermal profile appended

V43 (Arma2a)

  • As per VBS2 plus
  • An extra byte at end of Skeleton structure: always 0
  • LZSS compression is still used at this level

V47 (Arma2b LZO)

As per V43 plus:

  • all compressed blocks are LZO compressed
  • CompressedMinMax block is now nMinMax*8 in size
  • CompressedNormals block is now nNormals*4 in size
  • LodFrame has 4 extra floats
  • UVSet structure changed to:
LodUV
{
	float	uvScaling[4];
	ulong	nVertices;
	tbool	DefaultFill;
	if (DefaultFill)
	float	UV;				// default fill for all nVertices
	else
	float	UV[nVertices];	// potentially compressed
}

V48 (Arma2c)

As per V47 plus:

Arma2c format is the mainstay of Arma2. Types 43 and 47 are rarely encountered being works-in-progress in the initial release.

V49 (Arrowhead)

As per V48. No known differences apart from version number

V50 (Arrowhead DLC)

Introduced in PMC and BAF DLC

  • additional count after usedbones
  • lodPointFlags swapped around

V53 (Dayz)

  • edges set to zero
  • added Specular and Specular2 to rvmats
  • added SpecularPower and SpecularPower2 stage info type 15 to rvmats
  • added htMin,htMaz etc thermal info to rvmat stage infos (same as vbs)
  • added disableCover
  • added optional; bisurf data

V54 (Dayz)

bool added to ModelInfo

V52 (TOH)

intoduced in patch to BAF DLC, used mostly in TOH

  • additional float after usedbones in each lod
  • ModelInfo.PixelShaders additional 24 bytes
  • LODFaceDefaults additional count and float
  • LodStageTextures additional bool for type 11's

V56 (Arma 3)

same as V52 Plus:

  • thermal profile split into two chunks (same overall size as v52)
  • unknown byte indices increased from 12 to 14
  • animation class always four floats
  • physx data added at end of file

V58 (Arma 3)

  • prefix added to header
  • default indicators added at end of headerinfo

V59 (Arma 3)

  • no genuine changes simply an alteration of the type value from 32 to 64 bits

V60 (Arma 3)

  • alteration to the physx data at end of file

V64 (Arma 3)

  • Compressed sections no longer follow the 1024 byte rule, they now have a byte field for compressed or not

V67 (Arma 3)

  • LOD sections have an added 4 bytes and optional CollimatorInfo structure
  • LOD struct has additional 4 bytes at the end and optional CollimatorInfo structure

V68 (Arma 3)

  • LOD struct has an additional byte at the end

V69 (Arma 3)

edges changed from shorts to longs face structure changed from shorts to longs face indices ditto point_indices changed from shorts to longs

V70 (Arma 3)

float ModelInfo.lodDensityCoef added

V71 (Arma 3)

float ModelInfo.drawImportance added

V72 (Arma 3)

float ModelInfo.explosionshielding added

V72 (Arma 3)

bool ModelInfo.disableCover added

V75 (Arma 3)

optional encrypted p3d signature

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];
	if (any arma3 type) 
	{
		long		Always0;
		A3_Physx	A3_Physx[...]; // optional if not v60
	}
} // EndOfFile


Structures

StandardP3DHeader

common header structure for all P3D file formats

struct
{
	char[4]	Filetype;		// "ODOL"
	ulong	Version;

	if Version>=75 (arma3)
      ulong enc1;
      ulong enc2;
      if enc1 or enc2
        return encrypted
    
	if Version>=58 (arma3)
      ulong  appid;
	  if Version==58 (arma3)
		Asciiz	P3dPrefix;	// \a3\data_f\proxies\muzzle_flash\muzzle_flash_rifle_mk20
	
	ulong	NoOfLods;		// alias NoOfResolutions;
}

An optional prefix declaring the actual location of the p3d was introduced for arma3 (2nd version). Idiotically, it means the p3d cannot be moved out of it is current pbo.

The prefix is optional in the sense that it may be null. ("\0")

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];
  ======if v52 =========
  ulong   AnotherCount;
  float   AnotherFloat;
  =======endif===========
 }[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.
  • TrueArma2 == type 47 or greater (lzo compression)
  • Type 43 was a preliminary p3d prior to lzo compression. rarely encountered
 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];
 =========if v5x==========
   ulong                         LodPointCount;
     if v52
   float                         UnknownV52Float;
    endif
   else
   LodPointFlags                 LodPointFlags;                     // Potentially compressed
===========endif==========
   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;
=== V65 ===
    ulong   UnknownLongValue1
    if UnknownLongValue1
    {
        CollimatorInfo   unknown //Vec3,Vec3,ulong,vec3,ulong
    }
===========
=== V68 ===
   byte unknown;
===========
 }

VertexTable

all arrays are subject to compression

struct
{
   UvSet                         DefaultUVset;
   ulong                         nUVs;                              //in error, V47 sometimes sets nUV's as 0 but means 1
   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 3 x 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, 10==VBS2,11==Arrowhead
   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;    //A2 deprecated, always 1 //A1 rarely zero                                   
   ulong             RenderFlags;     //Generally 0
   ulong             nTextures;
   ulong             nTransforms;     // always same as nTextures
   LodStageTexture   StageTextures  [nTextures];
   LodStageTransform StageTransforms[nTransforms];
   if type>=10//vbs2/arma2
    LodStageTexture   DummyStageTexture;// see special, additional byte for THIS stagetexture
   endif   
   
 }  
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.

A3_Physics Type1 (optional)

 {
   A3_stanza A3_stanzas[...]; // optional
   float  aFloat;
 }
  • The type1 structure may not be present at all, or, only contain the single ending float

A3 stanza

{
  //header//////
  long   Xcount,Ycount,Zcount;
  float  floats[4];
  long   minCount; //Always2;
  long   maxCount; //Always4;
  //////////////
  float  frames[Xcount*Ycount*Zcount][5];
 }

A header with no frames is legal, it is XYZcounts (and floats[4]) are zero.

A 'stanza' consists of 5 float values. The amount of stanzas (if any) are determined by the 3 counts.

The range of each count value varies between 2,3 and 4.


A3 Physx type60

Introduced for format 60

{
 long      signature; // 0x03020400
 long      nStanzas;
 stanza60  stanza60s[nStanzas];
 long      signature; // same as above
 long      nStanzas2;
 stanza60  stanza60s2[nStanzas2];
};

stanza60

{
  {// 1st stanza
  long    signature;//0x03020400
  long    size;
  bytes   phsyx_data[size];
  }
  {// 2nd stanza
  long    signature;// as above
  long    size;
  bytes   phsyx_data2[size];
  }
}
  • the signatures and sizes are NOT optional. the data is
phsyx_data
{
  phsyx_header
  {
    {
      byte id[8]; // 'NXS.CVXM'
      long Always13;
      long Always0;
    }
    {
      byte id[8]; // 'ICE.CLHL'
      long Always6;
    }
    {
      byte id[8]; // always 'ICE.CVHL'
      long Always6;
    }
    long nTriplets;
    long count;
    long nFrames;
    long 2xcount;  // always dbl 'count'
  }
  tripletXYZ triplets[nTriplets];
  short 00;
  frames
  {
    float floats[4];
    long  value;
  }frames[nFrames];
  byte  index[variable length];
  //25x4 byte ending sequence
  float generally_zero;
  float f;
  long  value;
  float floats[7];
  long  value2;
  float floats[14];
};
  • the amount of index bytes can be determined by end of frame data to the start of the fixed 25x4 offset at end of lod

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
if =======Type11 AND V52 OR Type11 AND last(dummy) stage Texture ===================
 byte   V52Type11bool;   // only for arrowhead/pmc . and only for material types 11
endif
};
The first stageTexture is a dummy entry. For N humanly readable stage classes, there are 1+N LodStageTextures
Later p3d formats (VBS2, Operation Arrowhead) append an additional classTI LodStageTexture. if not present or declared in the rvmat file, it is a dummy entry. The rvmat gui editor from BisTools is not able to display this.
The TransformIndex is generally iterative (linear sequential). 1st entry is 0, 2nd 1, 3rd 2, etc. It refers to the nTH Transform Matrix
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 and v43 format files, some of the data structures present in the file are compressed by using LZSS compression. ODOL v47 and v48 use LZO compression. This is represented as

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.

Note:- Data structures that are identified as being compressible will only be compressed if the 'expectedSize' is >= 1024 bytes.

V64+ v64 implements a new flag for all compressed blobs. They no longer follow the 1024 byte rule. All possibly compressed arrays are now:

ulong elementCount byte compressed

   0 - not compressed
   2 - compressed

byte data[elementCount]

As an example if one was expanding the array of vertices positions...

  • A vertex is described by it is x,y,z coordinates which are floats. A float is a 32bit (4 byte) number.
  • 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.


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)