|
|
|
|
@@ -291,7 +291,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
model.boundingSphere.radius = *(float*)(buf);
|
|
|
|
|
model.boundingSphere.radius = Max(*(float*)(buf), 0.1f);
|
|
|
|
|
model.boundingSphere.center.x = *(float*)(buf+4);
|
|
|
|
|
model.boundingSphere.center.y = *(float*)(buf+8);
|
|
|
|
|
model.boundingSphere.center.z = *(float*)(buf+12);
|
|
|
|
|
@@ -304,10 +304,13 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
|
|
|
|
|
model.numSpheres = *(int16*)(buf+40);
|
|
|
|
|
buf += 44;
|
|
|
|
|
if(model.numSpheres > 0){
|
|
|
|
|
model.spheres = (CColSphere*)RwMalloc(model.numSpheres*sizeof(CColSphere));
|
|
|
|
|
model.spheres = new CColSphere[model.numSpheres];
|
|
|
|
|
REGISTER_MEMPTR(&model.spheres);
|
|
|
|
|
for(i = 0; i < model.numSpheres; i++){
|
|
|
|
|
model.spheres[i].Set(*(float*)buf, *(CVector*)(buf+4), buf[16], buf[17]);
|
|
|
|
|
float radius = *(float*)buf;
|
|
|
|
|
if(radius > model.boundingSphere.radius)
|
|
|
|
|
model.boundingSphere.radius = radius + 0.01f;
|
|
|
|
|
model.spheres[i].Set(radius, *(CVector*)(buf+4), buf[16], buf[17]);
|
|
|
|
|
buf += 20;
|
|
|
|
|
}
|
|
|
|
|
}else
|
|
|
|
|
@@ -316,7 +319,8 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
|
|
|
|
|
model.numLines = *(int16*)buf;
|
|
|
|
|
buf += 4;
|
|
|
|
|
if(model.numLines > 0){
|
|
|
|
|
//model.lines = (CColLine*)RwMalloc(model.numLines*sizeof(CColLine));
|
|
|
|
|
//model.lines = new CColLine[model.numLines];;
|
|
|
|
|
REGISTER_MEMPTR(&model.lines);
|
|
|
|
|
for(i = 0; i < model.numLines; i++){
|
|
|
|
|
//model.lines[i].Set(*(CVector*)buf, *(CVector*)(buf+12));
|
|
|
|
|
buf += 24;
|
|
|
|
|
@@ -329,7 +333,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
|
|
|
|
|
model.numBoxes = *(int16*)buf;
|
|
|
|
|
buf += 4;
|
|
|
|
|
if(model.numBoxes > 0){
|
|
|
|
|
model.boxes = (CColBox*)RwMalloc(model.numBoxes*sizeof(CColBox));
|
|
|
|
|
model.boxes = new CColBox[model.numBoxes];
|
|
|
|
|
REGISTER_MEMPTR(&model.boxes);
|
|
|
|
|
for(i = 0; i < model.numBoxes; i++){
|
|
|
|
|
model.boxes[i].Set(*(CVector*)buf, *(CVector*)(buf+12), buf[24], buf[25]);
|
|
|
|
|
@@ -341,7 +345,7 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
|
|
|
|
|
int32 numVertices = *(int16*)buf;
|
|
|
|
|
buf += 4;
|
|
|
|
|
if(numVertices > 0){
|
|
|
|
|
model.vertices = (CompressedVector*)RwMalloc(numVertices*sizeof(CompressedVector));
|
|
|
|
|
model.vertices = new CompressedVector[numVertices];
|
|
|
|
|
REGISTER_MEMPTR(&model.vertices);
|
|
|
|
|
for(i = 0; i < numVertices; i++){
|
|
|
|
|
model.vertices[i].Set(*(float*)buf, *(float*)(buf+4), *(float*)(buf+8));
|
|
|
|
|
@@ -359,14 +363,64 @@ CFileLoader::LoadCollisionModel(uint8 *buf, CColModel &model, char *modelname)
|
|
|
|
|
model.numTriangles = *(int16*)buf;
|
|
|
|
|
buf += 4;
|
|
|
|
|
if(model.numTriangles > 0){
|
|
|
|
|
model.triangles = (CColTriangle*)RwMalloc(model.numTriangles*sizeof(CColTriangle));
|
|
|
|
|
model.triangles = new CColTriangle[model.numTriangles];
|
|
|
|
|
REGISTER_MEMPTR(&model.triangles);
|
|
|
|
|
for(i = 0; i < model.numTriangles; i++){
|
|
|
|
|
model.triangles[i].Set(*(int32*)buf, *(int32*)(buf+4), *(int32*)(buf+8), buf[12]);
|
|
|
|
|
buf += 16;
|
|
|
|
|
|
|
|
|
|
// skip small triangles
|
|
|
|
|
CVector vA = model.vertices[model.triangles[i].a].Get();
|
|
|
|
|
CVector vB = model.vertices[model.triangles[i].b].Get();
|
|
|
|
|
CVector vC = model.vertices[model.triangles[i].c].Get();
|
|
|
|
|
float area = CrossProduct(vA - vB, vA - vC).Magnitude();
|
|
|
|
|
if(area < 0.001f || vA == vB || vA == vC || vB == vC){
|
|
|
|
|
i--;
|
|
|
|
|
model.numTriangles--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else
|
|
|
|
|
model.triangles = nil;
|
|
|
|
|
|
|
|
|
|
SplitColTrianglesIntoSections(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
CFileLoader::SplitColTrianglesIntoSections(CColModel &model)
|
|
|
|
|
{
|
|
|
|
|
if(model.triangles == nil || model.numTriangles == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
model.numTriBBoxes = 1;
|
|
|
|
|
model.triBBoxes = new CColTriBBox[1];
|
|
|
|
|
model.triBBoxes[0].first = 0;
|
|
|
|
|
model.triBBoxes[0].last = model.numTriangles-1;
|
|
|
|
|
CVector v = model.vertices[model.triangles[0].a].Get();
|
|
|
|
|
model.triBBoxes[0].Set(v, v);
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < model.numTriangles; i++){
|
|
|
|
|
CVector vA = model.vertices[model.triangles[i].a].Get();
|
|
|
|
|
CVector vB = model.vertices[model.triangles[i].b].Get();
|
|
|
|
|
CVector vC = model.vertices[model.triangles[i].c].Get();
|
|
|
|
|
model.triBBoxes[0].min.x = Min(vA.x, model.triBBoxes[0].min.x);
|
|
|
|
|
model.triBBoxes[0].min.y = Min(vA.y, model.triBBoxes[0].min.y);
|
|
|
|
|
model.triBBoxes[0].min.z = Min(vA.z, model.triBBoxes[0].min.z);
|
|
|
|
|
model.triBBoxes[0].min.x = Min(vB.x, model.triBBoxes[0].min.x);
|
|
|
|
|
model.triBBoxes[0].min.y = Min(vB.y, model.triBBoxes[0].min.y);
|
|
|
|
|
model.triBBoxes[0].min.z = Min(vB.z, model.triBBoxes[0].min.z);
|
|
|
|
|
model.triBBoxes[0].min.x = Min(vC.x, model.triBBoxes[0].min.x);
|
|
|
|
|
model.triBBoxes[0].min.y = Min(vC.y, model.triBBoxes[0].min.y);
|
|
|
|
|
model.triBBoxes[0].min.z = Min(vC.z, model.triBBoxes[0].min.z);
|
|
|
|
|
model.triBBoxes[0].max.x = Max(vA.x, model.triBBoxes[0].max.x);
|
|
|
|
|
model.triBBoxes[0].max.y = Max(vA.y, model.triBBoxes[0].max.y);
|
|
|
|
|
model.triBBoxes[0].max.z = Max(vA.z, model.triBBoxes[0].max.z);
|
|
|
|
|
model.triBBoxes[0].max.x = Max(vB.x, model.triBBoxes[0].max.x);
|
|
|
|
|
model.triBBoxes[0].max.y = Max(vB.y, model.triBBoxes[0].max.y);
|
|
|
|
|
model.triBBoxes[0].max.z = Max(vB.z, model.triBBoxes[0].max.z);
|
|
|
|
|
model.triBBoxes[0].max.x = Max(vC.x, model.triBBoxes[0].max.x);
|
|
|
|
|
model.triBBoxes[0].max.y = Max(vC.y, model.triBBoxes[0].max.y);
|
|
|
|
|
model.triBBoxes[0].max.z = Max(vC.z, model.triBBoxes[0].max.z);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|