PHYS

From wowdev
Jump to navigation Jump to search
This section only applies to versions ≥ Mists.

.phys files are chunked. The files are used by Blizzard's Domino physics engine which got added to WoW in the fourth expansion (MoP). In build Mists (5.0.1.15464), there is one .phys file "item/objectcomponents/waist/buckle_panstart_a_01.phys". .phys files are an extension to M2s. The M2 requests a .phys file to be loaded by having GlobalModelFlags & 0x20 set.

The main PHYS chunk is followed by an unordered sequence of unique chunks of the other types.

// vec*: * floats
// mat*x*: * times * floats.
  • 1 phys
  • n body
    • n shapes
      • 1 box
      • 1 capsule
      • 1 sphere
      • 1 polytope (version 3+)
      • 1 (tree mesh [*])
      • 1 (height field [*])
  • n joints
    • 1 weld
    • 1 spherical
    • 1 shoulder
    • 1 distance (version 2+)
    • 1 revolute (version 2+)
    • 1 prismatic (version 2+)
    • 1 (mouse [*])
    • 1 (center [*])
    • 1 (empty [*])

[*] supported by domino, but not available in wow

One body is connected to one bone. Bodies are connected via joints. A joint is of type weld, spherical or shoulder. A body is constructed out of shapes. A shape is a box, capsule or sphere.

PHYS

 short version;
 // since Mists (5.0.1.15???): 0
 // since Legion (7.0.1.20773): 1
 // since Legion (7.0.1.20979): 2
 // since Legion (7.0.1.21063): 2* -- not a different version in file or client parsing, but changed semantics and chunk names
 // since Legion (7.0.3.21287): 3
 // since Legion (7.0.3.21846): 4
 // since Legion (7.3.0.24500): 5 -- this version does not change anything in parsing. it likely handles some existing field differently
 // since ≥ 7.3, ≤ 9.0, but seen in 34003: 6 

Loading is partially backwards compatible and fills up with default values if loading older versions. Since version 2* it no longer reuses chunk identifiers but has separate identifiers for versions (BDY2, SHP2, WLJ2). It still is able to parse old ones, and fills up with defaults.

PHYT (version 1+)

This section only applies to versions ≥ Legion (7.0.1.20773).
uint32_t phyt; // default: 0

BODY, BDY2

struct
{
/*0x00*/  unsigned short type; // maps to dmBodyDef type enum. 0 -> 1, 1 -> 0 = dm_dynamicBody, * -> 2. Only one should be of type 0 (root). possibly only 0 and 1.
/*0x02*/  char PADDING_a[2];
/*0x04*/  vec3 position;
/*0x10*/  unsigned short modelBoneIndex;
/*0x12*/  char PADDING_b[2];
/*0x14*/  int shapes_base; // starting at shapes[shapes_base]
/*0x18*/  int shapes_count; // shapes_count shapes are in this body.
#if version >= 2 // BDY2
/*0x1c*/  float _x1c; // default 1.0
#endif
} bodies[];

BDY3, BDY4

struct
{
/*0x00*/  unsigned short type; // maps to dmBodyDef type enum. 0 -> 1, 1 -> 0 = dm_dynamicBody, * -> 2. Only one should be of type 0 (root). possibly only 0 and 1.
/*0x02*/  unsigned short boneIndex;
/*0x04*/  vec3 position;
/*0x10*/  unsigned short shapeIndex;
/*0x12*/  char PADDING_b[2];
/*0x14*/  int shapesCount; // shapes_count shapes are in this body.
/*0x18*/  float unk0;
#if version >= 3 // BDY3
/*0x1c*/  float _x1c; // default 1.0
/*0x20*/  float drag; // default 0, maybe incorrect
/*0x24*/  float unk1; // default 0, seems to be some sort of weight. 
                      // If version >= 3 and unk1 == 0 the body will be non kinematic even if the flag is set, it needs to get its transform from the parent bone.
                      // See offhand_1h_artifactskulloferedar_d_06 where all the bodies have the kinematic flag
/*0x28*/  float _x28; // default 0.89999998
#if version >= 4 // BDY4
/*0x2c*/  char _x2c[0x04]; // default 0x00000000
/*0x30*/
#endif
#endif
} bodies[];
  • density
  • friction
  • restitution
  • rollingResistance
  • explosionFactor
  • explosionLiftFactor
  • windFactor
  • dragFactor
  • liftFactor
  • filter
  • isSensor

SHAP, SHP2

struct
{
/*0x00*/  short shapeType;
  enum
  {
    box = 0,      // BOXS
    capsule = 1,  // CAPS
    sphere = 2,   // SPHS
#if version >= 3
    polytope = 3, // PLYT
#endif
  };
/*0x02*/  short shapeIndex; // into the corresponding chunk
/*0x04*/  char unk[4];
/*0x08*/  float friction;
/*0x0c*/  float restitution;
/*0x10*/  float density;
#if version >= 2 // SHP2
/*0x14*/  uint32_t _x14; // default 0
/*0x18*/  float _x18; // default 1.0
/*0x1c*/  uint16_t _x1c; // default 0
/*0x1e*/  uint16_t _x1e; // no default, padding?
#endif
} shapes[];

Shapes

BOXS

struct
{
/*0x00*/  mat3x4 a;
/*0x30*/  vec3 c;
} boxShapes[];

CAPS

struct
{
  vec3 localPosition1;
  vec3 localPosition2;
  float radius;
} capsuleShapes[];

SPHS

struct
{
  vec3 localPosition;
  float radius;
} sphereShapes[];

PLYT (version 3+)

This section only applies to versions ≥ Legion (7.0.3.21287).

This chunk does it's own array handling since the second part of the chunk is raw data. Instead of splitting in a header and a data chunk, it is combining both parts. The header has fixed size entries, the data block has entries of size based on the corresponding header entry. The header also has fields that are only set on runtime which should be 0 in file and will be a pointer to the corresponding data upon loading.

struct {
/*0x00*/  uint32_t count;
    
  struct {
  /*0x00*/  uint32_t vertexCount;               // Mostly 8
  /*0x04*/  char unk_04[0x4];
  /*0x08*/  uint64_t RUNTIME_08_ptr_data_0;  // = &data[i].unk_0
  /*0x10*/  uint32_t count_10;               // Mostly 6
  /*0x14*/  char unk_14[0x4];
  /*0x18*/  uint64_t RUNTIME_18_ptr_data_1;  // = &data[i].unk_1
  /*0x20*/  uint64_t RUNTIME_20_ptr_data_2;  // = &data[i].unk_2
  /*0x28*/  uint32_t nodeCount;               // Mostly 24
  /*0x2c*/  char unk_2C[0x4];
  /*0x30*/  uint64_t RUNTIME_30_ptr_data_3;  // = &data[i].unk_3
  /*0x38*/  float unk_38[6];                 // not sure if floats: has e-08 values
  } header[count];
  
  struct {                                   // NOTE: This is NOT a fixed size. Every entries' size depends on the header entry's value!
    vec3 vertices[header[i].vertexCount];    // The vertices that compose the convex hull mesh, this data is enough to generate the collision mesh
    struct {
      char unk_00[0x10];                     // probably a vec4, but really e-07 values en masse
    } unk_1[header[i].count_10];
    char unk_2[header[i].count_10];
    struct {
      char unk;                              // 1 or -1
      char vertexIndex;                      // index in vertex list
      char unkIndex0;                        // index into the nodes
      char unkIndex1;                        // index into the nodes
    } nodes[header[i].nodeCount];            // a tree structure that connects the vertices together
  } data[count];
} polytopeShapes;

Joints

JOIN

struct JOINEntry
{
  unsigned int bodyAIdx;
  unsigned int bodyBIdx;
  char unk[4];
  enum
  {
    sphericalJoint = 0,
    shoulderJoint = 1,
    weldJoint = 2,
#if version >= 2
    revoluteJoint = 3,
    prismaticJoint = 4,
    distanceJoint = 5,
#endif
  };
  short jointType;
  short jointId; // reference into the corresponding chunk entries.
} joints[];

WELJ, WLJ2, WLJ3

struct
{
/*0x00*/  mat3x4 frameA;
/*0x30*/  mat3x4 frameB;
/*0x60*/  float angularFrequencyHz;
/*0x64*/  float angularDampingRatio;
#if version >= 2 // WLJ2
/*0x68*/  float linearFrequencyHz; // default 0
/*0x6c*/  float linearDampingRatio; // default 0
#if version >= 3 // WLJ3
/*0x70*/  float unk70;
/*0x74*/
#endif
#endif
} weldJoints[];

SPHJ

struct SPHJEntry
{
  vec3 anchorA;
  vec3 anchorB;
  float frictionTorque;
} sphericalJointEntries[];

SHOJ, SHJ2

Note that even though this chunk is handled differently since version 2, it does not have a version 2* chunk name. At some unknown later point, a SHJ2 version was added though. This is actually version 3!

struct SHOJEntry
{
/*0x00*/  mat3x4 frameA;
/*0x30*/  mat3x4 frameB;
/*0x60*/  float lowerTwistAngle;
/*0x64*/  float upperTwistAngle;
/*0x68*/  float coneAngle;
#if version >= 2
/*0x6C*/  float maxMotorTorque;
/*0x70*/  uint32_t motorMode; // NO BACKWARDS COMPATIBILITY as of Legion (7.0.1.20979) and Legion (7.3.0.24931)! client always assumes new size!
/*0x74*/
#if version >= ?? // SHJ2
/*0x74*/  float motorFrequencyHz;
/*0x78*/  float motorDampingRatio;
/*0x7C*/
#endif
#endif
} shoulderJoints[];
  • motorMode
  • enableTwistLimit
  • motorDampingRatio
  • motorFrequencyHz

PRSJ (version 2+), PRS2

This section only applies to versions ≥ Legion (7.0.1.20979).
struct
{
/*0x00*/  mat3x4 frameA;
/*0x30*/  mat3x4 frameB;
/*0x60*/  float lowerLimit;
/*0x64*/  float upperLimit;
/*0x68*/  float _68;
/*0x6C*/  float maxMotorForce;
/*0x70*/  float _70;
/*0x74*/  uint32_t motorMode;
#if version >= ?? // PRS2
/*0x78*/  float motorFrequencyHz;
/*0x7C*/  float motorDampingRatio;
/*0x80*/
#endif
} prismaticJoints[];
  • enableLimit

REVJ (version 2+), REV2

This section only applies to versions ≥ Legion (7.0.1.20979).
struct
{
/*0x00*/  mat3x4 frameA;
/*0x30*/  mat3x4 frameB;
/*0x60*/  float lowerAngle;
/*0x64*/  float upperAngle;
/*0x68*/  float maxMotorTorque;
/*0x6C*/  uint32 motorMode; // 1: motorPositionMode → frequency > 0, 2: motorVelocityMode
#if version >= ?? // REV2
/*0x70*/  float motorFrequencyHz;
/*0x74*/  float motorDampingRatio;
/*0x78*/
#endif
} revoluteJoints[];

DSTJ (version 2+)

This section only applies to versions ≥ Legion (7.0.1.20979).
struct
{
/*0x00*/  vec3 localAnchorA;
/*0x0C*/  vec3 localAnchorB;
/*0x18*/  float some_distance_factor;
/*0x1C*/
} distanceJoints[];
  • mindistance = maxdistance = some_distance_factor * something
  • hertz
  • dampingratio

PHYV (version 1+)

This section only applies to versions ≥ Legion (7.0.1.20773).

When this chunk is present there seem to be no other following chunks, probably defines a single collider? example: 7vs_detail_nightmareplant01_phys.phys

struct
{
/*0x00*/  float _unk[0x6];
/*0x18*/
} phyv[];

When given, every entry allocates a struct with values

 v1->field_0 = 1.25;
 v1->field_4 = 0.25;
 v1->field_8 = 8.0;
 v1->field_C = 0.1;
 v1->field_10 = 20.0;
 v1->field_14 = 4.0;
 v1->field_18 = 9.424778;
 v1->field_1C = 6.2831855;
 v1->field_20 = 1.5707;
 v1->field_24 = 0.5;

which is then overwriting the fist six floats with the phyv content. Some kind of tuning?