|
|
|
@ -15,26 +15,6 @@ template<class TData> size_t writeMapData(const std::vector<TData>& data, ps1bsp |
|
|
|
return fwrite(data.data(), sizeof(TData), data.size(), f); |
|
|
|
} |
|
|
|
|
|
|
|
static SVECTOR convertNormal(vec3_t normal) |
|
|
|
{ |
|
|
|
SVECTOR outNormal; |
|
|
|
outNormal.vx = (short)(normal.x * 4096); |
|
|
|
outNormal.vy = (short)(normal.y * 4096); |
|
|
|
outNormal.vz = (short)(normal.z * 4096); |
|
|
|
outNormal.pad = 0; |
|
|
|
return outNormal; |
|
|
|
} |
|
|
|
|
|
|
|
static SVECTOR convertWorldPosition(vec3_t point) |
|
|
|
{ |
|
|
|
SVECTOR outPoint; |
|
|
|
outPoint.vx = (short)(point.x * 4); |
|
|
|
outPoint.vy = (short)(point.y * 4); |
|
|
|
outPoint.vz = (short)(point.z * 4); |
|
|
|
outPoint.pad = 1; |
|
|
|
return outPoint; |
|
|
|
} |
|
|
|
|
|
|
|
static float computeFaceArea(const world_t* world, const face_t* face) |
|
|
|
{ |
|
|
|
const plane_t* plane = &world->planes[face->plane_id]; |
|
|
|
@ -57,7 +37,7 @@ static float computeFaceArea(const world_t* world, const face_t* face) |
|
|
|
|
|
|
|
double x = tangent.dotProduct(vec); |
|
|
|
double y = bitangent.dotProduct(vec); |
|
|
|
bounds.includePoint(Vec3(x, y, 0)); |
|
|
|
bounds.includePoint(Vec3(x, y, 0.0)); |
|
|
|
} |
|
|
|
|
|
|
|
Vec3 extents = bounds.max - bounds.min; |
|
|
|
@ -131,7 +111,7 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex |
|
|
|
// export_lightmap(world, face, bounds, faceIdx);
|
|
|
|
|
|
|
|
outFace.numFaceVertices = (unsigned char)(outFaceVertices.size() - outFace.firstFaceVertex); |
|
|
|
outFace.center = convertWorldPosition(vertexSum / face->ledge_num); |
|
|
|
outFace.center = (vertexSum / face->ledge_num).convertWorldPosition(); |
|
|
|
float area = computeFaceArea(world, face); // TODO: divide by number of polygons
|
|
|
|
outFace.center.pad = (short)(sqrt(area)); |
|
|
|
outFaces.push_back(outFace); |
|
|
|
@ -159,6 +139,13 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// Invisible collision volumes don't have to be tessellated
|
|
|
|
if (!strcmp(miptex->name, "clip") || !strcmp(miptex->name, "trigger")) |
|
|
|
{ |
|
|
|
outFace->numPolygons = 0; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// Draw water as fullbright transparent surfaces
|
|
|
|
if (miptex->name[0] == '*') |
|
|
|
{ |
|
|
|
@ -233,7 +220,7 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex |
|
|
|
plane_t* plane = &world->planes[planeIdx]; |
|
|
|
|
|
|
|
ps1bsp_plane_t outPlane = { 0 }; |
|
|
|
outPlane.normal = convertNormal(plane->normal); |
|
|
|
outPlane.normal = plane->normal.convertNormal(); |
|
|
|
outPlane.dist = (short)(plane->dist * 4); |
|
|
|
outPlane.type = (short)plane->type; |
|
|
|
|
|
|
|
@ -246,13 +233,12 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex |
|
|
|
{ |
|
|
|
node_t* node = &world->nodes[nodeIdx]; |
|
|
|
|
|
|
|
ps1bsp_node_t outNode; |
|
|
|
ps1bsp_node_t outNode = { 0 }; |
|
|
|
outNode.planeId = node->plane_id; |
|
|
|
outNode.children[0] = node->front; |
|
|
|
outNode.children[1] = node->back; |
|
|
|
|
|
|
|
outNode.firstFace = node->face_id; |
|
|
|
outNode.numFaces = node->face_num; |
|
|
|
outNode.boundingSphere = node->box.toBoundingSphere(); |
|
|
|
|
|
|
|
outNodes.push_back(outNode); |
|
|
|
} |
|
|
|
@ -263,7 +249,7 @@ int process_faces(const world_t* world, const std::vector<ps1bsp_texture_t>& tex |
|
|
|
{ |
|
|
|
dleaf_t* leaf = &world->leaves[leafIdx]; |
|
|
|
|
|
|
|
ps1bsp_leaf_t outLeaf; |
|
|
|
ps1bsp_leaf_t outLeaf = { 0 }; |
|
|
|
outLeaf.type = leaf->type; |
|
|
|
outLeaf.vislist = leaf->vislist; |
|
|
|
outLeaf.firstLeafFace = leaf->lface_id; |
|
|
|
|