-
Notifications
You must be signed in to change notification settings - Fork 3
/
CCollisionTree.bt
194 lines (181 loc) · 5.32 KB
/
CCollisionTree.bt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#ifndef _CAABOXCOLLISIONTREE
#define _CAABOXCOLLISIONTREE
#include "CAABox.bt"
#include "COBBox.bt"
#include "CTransform4f.bt"
typedef enum {
kCOL_AABox = 0,
kCOL_OBBox = 1,
} CollisionPrimitiveType;
struct CAABoxTreeNode {
CAABox bounds;
uint start;
uint end;
uchar unk3;
uchar unk4;
uchar unk5;
uchar unk6;
};
struct COBBoxTreeNode {
COBBox bounds;
uint start;
uint end;
uchar unk3;
uchar unk4;
uchar unk5;
uchar unk6;
};
struct CCollisionMaterial {
uint orientation;
uint materialType;
uint worldType;
uint behaviorList;
uint filterList;
};
struct CIndexedTriangle {
uint idx1;
uint idx2;
uint idx3;
if (form.readerVersion > 2 && form.writerVersion > 2) //Fix reading test collisions from DKCTF
{
ushort material;
ushort unk2;
}
};
struct CollisionMaterialVector {
uint count;
CCollisionMaterial collisionMaterials[count];
};
struct VertexVector {
uint count;
CVector3f vertices[count];
};
struct IndexedTriangleVector {
uint count;
CIndexedTriangle tris[count]<optimize=false>;
};
struct TreeNodeVector(CollisionPrimitiveType type) {
uint count;
switch (type) {
case kCOL_AABox:
CAABoxTreeNode nodes[count];
break;
case kCOL_OBBox:
COBBoxTreeNode nodes[count];
break;
}
};
struct ModConData {
char id[16];
CTransform4f xf;
ushort unk;
};
local int idx <hidden=true> =0;
typedef struct CCollisionTree(uint64 size, CollisionPrimitiveType type) {
local CollisionPrimitiveType tmpType <hidden = true> = type;
local uint64 start<format = hex, hidden = true> = FTell();
while (FTell() != start + size) {
struct Chunk {
ChunkDescriptor desc;
union {
switch (desc.id) {
case "INFO":
CAABox bounds;
break;
case "MTRL":
CollisionMaterialVector materials;
break;
case "TRIS":
IndexedTriangleVector triangles;
break;
case "VERT":
VertexVector vertices;
break;
case "TREE":
TreeNodeVector treeNodes(tmpType);
break;
}
char raw[desc.size];
} data;
} chunks;
}
if (idx == 0) {
local int i = 0;
//Hack, do this so DCLN doesn't break the printouts, seems to work on MP1R DCLN but haven't tested CLSN
local int vertChunk = 0;
local int triangleChunk = 2;
local int materialChunk = 1;
if (form.id == "DCLN")
{
vertChunk = 1;
if (form.readerVersion > 2 && form.writerVersion > 2) //Read legacy CLSNs
{
materialChunk = 2;
triangleChunk = 3;
}
else
{
triangleChunk = 2;
materialChunk = 0;
}
}
else if (form.id == "CLSN" && (form.readerVersion == 2 && form.writerVersion == 2))
{
materialChunk = 0;
triangleChunk = 1;
}
for (i = 0; i < chunks[vertChunk].data.vertices.count; ++i) {
Printf("v %f %f %f\n", chunks[vertChunk].data.vertices.vertices[i].x,
chunks[vertChunk].data.vertices.vertices[i].y,
chunks[vertChunk].data.vertices.vertices[i].z);
}
local int t;
local int y;
local int prevMat = -1;
for (i = 0; i < chunks[triangleChunk].data.triangles.count; ++i) {
if (materialChunk != 0)
{
if (chunks[triangleChunk].data.triangles.tris[i].material != prevMat && (form.readerVersion > 2 && form.writerVersion > 2)) {
Printf("o mat_%i_%08X\n", chunks[triangleChunk].data.triangles.tris[i].material,
chunks[materialChunk]
.data.materials
.collisionMaterials[chunks[triangleChunk].data.triangles.tris[i].material]
.filterList);
prevMat = chunks[triangleChunk].data.triangles.tris[i].material;
}
}
Printf("f %i %i %i\n", chunks[triangleChunk].data.triangles.tris[i].idx1 + 1,
chunks[triangleChunk].data.triangles.tris[i].idx2 + 1,
chunks[triangleChunk].data.triangles.tris[i].idx3 + 1);
}
}
/*
for (i = 0; i < chunks[2].data.triangles.count; ++i) {
Printf("%i->%i: orientation=%08X, materialType=%08X, worldType=%08X, "
"behaviorList=%08X, filterList=%08X\n",
i, chunks[2].data.triangles.tris[i].material,
chunks[1]
.data.materials
.collisionMaterials[chunks[2].data.triangles.tris[i].material]
.orientation,
chunks[1]
.data.materials
.collisionMaterials[chunks[2].data.triangles.tris[i].material]
.materialType,
chunks[1]
.data.materials
.collisionMaterials[chunks[2].data.triangles.tris[i].material]
.worldType,
chunks[1]
.data.materials
.collisionMaterials[chunks[2].data.triangles.tris[i].material]
.behaviorList,
chunks[1]
.data.materials
.collisionMaterials[chunks[2].data.triangles.tris[i].material]
.filterList);
}
*/
++idx;
} CCollisionTree;
#endif // _CAABOXCOLLISIONTREE