Skip to content

Commit b0db42a

Browse files
committed
Update Havok 010 template
1 parent 81c082d commit b0db42a

1 file changed

Lines changed: 267 additions & 42 deletions

File tree

External/010templates/bree/fb2/HavokPhysicsData.bt

Lines changed: 267 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111
// History:
1212
//------------------------------------------------
1313

14+
uint align(uint bytes)
15+
{
16+
local uint alignment = FTell();
17+
local uint i = 0;
18+
while (alignment % bytes != 0)
19+
{
20+
FSkip(1);
21+
i = i + 1;
22+
alignment = FTell();
23+
}
24+
return i;
25+
}
26+
1427
struct Vec3 {
1528
float x;
1629
float y;
@@ -24,6 +37,12 @@ struct Vec4 {
2437
float w;
2538
};
2639

40+
struct QSTransform {
41+
Vec3 left;
42+
Vec3 up;
43+
Vec3 forward;
44+
};
45+
2746
struct AxisAlignedBox {
2847
Vec3 min;
2948
Vec3 max;
@@ -70,6 +89,149 @@ struct hkDescriptorInfo
7089
int Key;
7190
};
7291

92+
enum <ubyte> ShapeDispatchTypeEnum
93+
{
94+
CONVEX_IMPLICIT = 0,
95+
CONVEX = 1,
96+
HEIGHT_FIELD = 2,
97+
COMPOSITE = 3,
98+
USER = 4,
99+
NUM_DISPATCH_TYPES = 5
100+
};
101+
102+
enum <ubyte> ShapeInfoCodecTypeEnum
103+
{
104+
NULL_CODEC = 0,
105+
UFM358 = 1,
106+
MAX_NUM_CODECS = 16
107+
};
108+
109+
enum <ubyte> CollectionType
110+
{
111+
COLLECTION_LIST = 0,
112+
COLLECTION_EXTENDED_MESH = 1,
113+
COLLECTION_TRISAMPLED_HEIGHTFIELD = 2,
114+
COLLECTION_USER = 3,
115+
COLLECTION_SIMPLE_MESH = 4,
116+
COLLECTION_MESH_SHAPE = 5,
117+
COLLECTION_COMPRESSED_MESH = 6,
118+
COLLECTION_MAX = 7
119+
};
120+
121+
122+
struct hkBaseObject
123+
{
124+
uint base; // might be 8 (maybe on 64bits?)
125+
};
126+
127+
struct hkReferenceObject
128+
{
129+
hkBaseObject super;
130+
uint memSizeAndRefCount;
131+
};
132+
133+
struct hkcdShape
134+
{
135+
hkReferenceObject super;
136+
byte type;
137+
ShapeDispatchTypeEnum dispatchType;
138+
ubyte bitsPerKey;
139+
ShapeInfoCodecTypeEnum shapeInfoCodecType;
140+
};
141+
142+
struct hkpShapeBase
143+
{
144+
hkcdShape super;
145+
};
146+
147+
struct hkpShape
148+
{
149+
hkpShapeBase super;
150+
uint userData; // might be 8 (maybe on 64bits?)
151+
};
152+
153+
struct hkpShapeCollection
154+
{
155+
hkpShape super;
156+
uint pad0; // might be 8 (maybe on 64bits?)
157+
byte disableWelding;
158+
CollectionType collectionType;
159+
ushort pad1; // might be 4 (maybe on 64bits?)
160+
};
161+
162+
struct hkpSphereRepShape
163+
{
164+
hkpShape super;
165+
};
166+
167+
struct hkpConvexShape
168+
{
169+
hkpSphereRepShape super;
170+
float radius;
171+
// skip 4 on 64 bits
172+
};
173+
174+
struct hkpBoxShape
175+
{
176+
hkpConvexShape super;
177+
align(16);
178+
Vec4 halfExtents;
179+
};
180+
181+
struct hkpShapeContainer
182+
{
183+
uint base; // might be 8 (maybe on 64bits?)
184+
};
185+
186+
struct hkpSingleShapeContainer
187+
{
188+
hkpShapeContainer super;
189+
hkpShape childShape;
190+
};
191+
192+
struct hkpConvexTransformShapeBase
193+
{
194+
hkpConvexShape super;
195+
//hkpSingleShapeContainer childShape; // this should be a pointer
196+
uint childShapeSizeForSpu; // might be 8 (maybe on 64bits?)
197+
};
198+
199+
struct hkpConvexTransformShape
200+
{
201+
hkpConvexTransformShapeBase super;
202+
align(16);
203+
QSTransform transform;
204+
Vec4 extraScale;
205+
};
206+
207+
struct hkpConvexTranslateShape
208+
{
209+
hkpConvexTransformShapeBase super;
210+
align(16);
211+
Vec4 translation;
212+
};
213+
214+
struct hkpCylinderShape
215+
{
216+
hkpConvexShape super;
217+
float cylRadius;
218+
float cylBaseRadiusFactorForHeightFieldCollisions;
219+
align(16);
220+
Vec4 vertexA;
221+
Vec4 vertexB;
222+
Vec4 perpendicular1;
223+
Vec4 perpendiculat2;
224+
};
225+
226+
struct hkpConvexVerticesShape
227+
{
228+
hkpConvexShape super;
229+
align(16);
230+
Vec4 aabbHalfExtents;
231+
Vec4 aabbHalfCenter;
232+
uint relocPointer; //? TODO: finish
233+
};
234+
73235
struct hkExtendedMeshHeader
74236
{
75237
byte UnknownNull[21];
@@ -84,10 +246,10 @@ struct hkExtendedMeshHeader
84246
int U6;
85247
int U7;
86248
short U8;
87-
byte U9[16];
88-
byte U10[16];
89-
int Null1;
90-
int U11;
249+
Vec4 aabbHalfExtents;
250+
Vec4 aabbCenter;
251+
int materialClass;
252+
int numBitsForSubpartIndex;
91253
byte Null2[11];
92254
int U12;
93255
ubyte Null3;
@@ -130,26 +292,12 @@ struct HavokPhysicsData {
130292
int64 MaterialIndicesOffset;
131293
int MaterialFlagsAndIndicesCount;
132294
int64 MaterialFlagsAndIndicesOffset;
133-
float Scale;
295+
int Scale;
134296
ubyte MaterialCountUsed;
135297
ubyte HighestMaterialIndex;
136298
ushort Padding;
137299
} data;
138300

139-
140-
uint align(uint bytes)
141-
{
142-
local uint alignment = FTell();
143-
local uint i = 0;
144-
while (alignment % bytes != 0)
145-
{
146-
FSkip(1);
147-
i = i + 1;
148-
alignment = FTell();
149-
}
150-
return i;
151-
}
152-
153301
uint RoundUp(uint bytes, uint a)
154302
{
155303
FSkip(bytes);
@@ -201,35 +349,35 @@ if (data.MaterialFlagsAndIndicesCount > 0)
201349

202350
FSeek(s_HavokOffset);
203351

204-
while(FTell() != FileSize())
205-
{
206352
struct {
353+
s_HavokOffset = FTell();
207354
hkPackfileHeader header;
208-
hkPackfileSectionHeader sectionHeader[header.NumSections];
209355

210-
// TODO: un-hardcode classnames from index 0.
356+
//hkPackfileSectionHeader sectionHeader[header.NumSections];
357+
hkPackfileSectionHeader classNamesSectionHeader;
358+
hkPackfileSectionHeader typesSectionHeader;
359+
hkPackfileSectionHeader dataSectionHeader;
360+
211361
// __classnames__
212362
struct {
213-
local uint ClassNamesStart = s_HavokOffset + sectionHeader[0].AbsoluteDataStart;
214-
local uint ClassNamesEnd = ClassNamesStart + sectionHeader[0].EndOffset - 1;
363+
local uint ClassNamesStart = s_HavokOffset + classNamesSectionHeader.AbsoluteDataStart;
364+
local uint ClassNamesEnd = ClassNamesStart + classNamesSectionHeader.EndOffset - 1;
215365
FSeek(ClassNamesStart);
216366
while (FTell() < ClassNamesEnd)
217367
{
218368
hkDescriptor descriptor;
219369
}
220-
221-
ubyte Pad;
222370
} __classnames__;
223371

224372
// ignore __types__ as EndOffset is 0.
225373

226374
// __data__
227375

228376
struct {
229-
local uint DataStart = s_HavokOffset + sectionHeader[2].AbsoluteDataStart;
230-
local uint DataEnd = DataStart + sectionHeader[2].EndOffset - 1;
231-
local uint DataFixupStart = DataStart + sectionHeader[2].VirtualFixupsOffset;
232-
local uint DataFixupEnd = DataStart + sectionHeader[2].ExportsOffset;
377+
local uint DataStart = s_HavokOffset + dataSectionHeader.AbsoluteDataStart;
378+
local uint DataEnd = DataStart + dataSectionHeader.EndOffset - 1;
379+
local uint DataFixupStart = DataStart + dataSectionHeader.VirtualFixupsOffset;
380+
local uint DataFixupEnd = DataStart + dataSectionHeader.ExportsOffset;
233381
local uint infoCount = 0;
234382
FSeek(DataStart);
235383
hkxRoot root;
@@ -281,21 +429,98 @@ struct {
281429

282430
for (int i=0; i < infoCount; i++)
283431
{
284-
FSeek(DataStart + descriptorInfo[i].Offset);
285-
if (descriptorInfo[i].Key == 169) //hkpExtendedMeshShape
286-
{
287-
hkExtendedMeshHeader meshHeader <bgcolor=0xFF0000>;
288-
hkExtendedMeshEntry meshTransform[meshHeader.IndexCount] <bgcolor=0xFF0000>;
289-
}
290-
else
432+
if (descriptorInfo[i].Key != -1)
291433
{
292-
hkxRoot root <bgcolor=0xFF0000>;
434+
FSeek(s_HavokOffset + classNamesSectionHeader.AbsoluteDataStart + descriptorInfo[i].Key);
435+
struct String {
436+
string _;
437+
};
438+
String keyName;
439+
FSeek(DataStart + descriptorInfo[i].Offset);
440+
if (keyName._ == "hkpExtendedMeshShape")
441+
{
442+
struct hkkk {
443+
// hkReferenceObject
444+
int memSizeAndRefCount;
445+
// hkcdShape
446+
byte type;
447+
byte dispatchType;
448+
byte bitsPerKey;
449+
byte shapeInfoCodecType;
450+
// hkpShapeBase
451+
// hkpShape
452+
uint64 userData;
453+
// hkpShapeCollection
454+
byte disableWelding;
455+
uint64 collectionType;
456+
457+
// hkpExtendedMeshShapeTrianglesSubpart
458+
uint numTriangleShapes;
459+
uint vertexBase;
460+
int numVertices;
461+
uint indexBase;
462+
ushort vertexStriding;
463+
int triangleOffset;
464+
ushort indexStriding;
465+
byte stridingType;
466+
byte flipAlternateTriangles;
467+
Vec4 extrusion;
468+
Vec4 left;
469+
Vec4 up;
470+
Vec4 forward;
471+
Vec4 trans;
472+
473+
// hkpExtendedMeshShape
474+
hfloat aabbHalfExtents_min_x;
475+
hfloat aabbHalfExtents_min_y;
476+
hfloat aabbHalfExtents_min_z;
477+
hfloat aabbHalfExtents_max_x;
478+
hfloat aabbHalfExtents_max_y;
479+
hfloat aabbHalfExtents_max_z;
480+
} ;
481+
482+
hkExtendedMeshHeader meshHeader <bgcolor=0xFF0000>;
483+
hkExtendedMeshEntry meshTransform[meshHeader.IndexCount] <bgcolor=0xFF0000>;
484+
}
485+
else if (keyName._ == "hkpBoxShape")
486+
{
487+
hkpBoxShape boxShape;
488+
}
489+
else if (keyName._ == "hkpConvexTransformShape")
490+
{
491+
hkpConvexTransformShape convexTransformShape;
492+
}
493+
else if (keyName._ == "hkpConvexTranslateShape")
494+
{
495+
hkpConvexTranslateShape convexTranslateShape;
496+
}
497+
else if (keyName._ == "hkpCylinderShape")
498+
{
499+
hkpCylinderShape cylinderShape;
500+
}
501+
else if (keyName._ == "hkpConvexVerticesShape")
502+
{
503+
hkpConvexVerticesShape convexVerticesShape;
504+
}
505+
else if (keyName._ == "hkpCompressedMeshShape")
506+
{
507+
hkpShapeCollection _compressedMeshShape; // TODO: finish
508+
}
509+
else if (keyName._ == "HavokPhysicsContainer")
510+
{
511+
hkxRoot root <bgcolor=0xFF0000>;
512+
}
513+
else
514+
{
515+
hkxRoot root <bgcolor=0xFF0000>;
516+
}
293517
}
294518
}
295519
FSeek(pos);
296520
} __data__;
297521

298-
} hk;
299522
align(16);
300-
s_HavokOffset = FTell();
301-
}
523+
} hk[2] <optimize=false>;
524+
525+
uint fixupSize32;
526+
uint fixupSize64;

0 commit comments

Comments
 (0)