|
|
|
@ -270,6 +270,16 @@ 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; |
|
|
|
} |
|
|
|
|
|
|
|
int process_faces(const world_t* world) |
|
|
|
{ |
|
|
|
// Write some data to a file
|
|
|
|
@ -282,7 +292,7 @@ int process_faces(const world_t* world) |
|
|
|
outHeader.version = 1; |
|
|
|
fwrite(&outHeader, sizeof(ps1bsp_header_t), 1, fbsp); |
|
|
|
|
|
|
|
// Write vertex data to a file (no vertex splitting yet)
|
|
|
|
// Convert vertex data (no vertex splitting yet)
|
|
|
|
std::vector<ps1bsp_vertex_t> outVertices; |
|
|
|
for (unsigned short i = 0; i < world->numVertices; ++i) |
|
|
|
{ |
|
|
|
@ -306,6 +316,7 @@ int process_faces(const world_t* world) |
|
|
|
outVertices.push_back(outVertex); |
|
|
|
} |
|
|
|
|
|
|
|
// Convert faces defined by edges into faces defined by vertex indices
|
|
|
|
std::vector<ps1bsp_face_t> outFaces; |
|
|
|
std::vector<ps1bsp_facevertex_t> outFaceVertices; |
|
|
|
for (int faceIdx = 0; faceIdx < world->numFaces; ++faceIdx) |
|
|
|
@ -373,17 +384,67 @@ int process_faces(const world_t* world) |
|
|
|
(*iter).r = 0; |
|
|
|
} |
|
|
|
|
|
|
|
// Convert planes
|
|
|
|
std::vector<ps1bsp_plane_t> outPlanes; |
|
|
|
for (int planeIdx = 0; planeIdx < world->numPlanes; ++planeIdx) |
|
|
|
{ |
|
|
|
plane_t* plane = &world->planes[planeIdx]; |
|
|
|
|
|
|
|
ps1bsp_plane_t outPlane; |
|
|
|
outPlane.normal = convertNormal(plane->normal); |
|
|
|
outPlane.dist = (short)(plane->dist * 4); |
|
|
|
|
|
|
|
outPlanes.push_back(outPlane); |
|
|
|
} |
|
|
|
|
|
|
|
// Convert nodes
|
|
|
|
std::vector<ps1bsp_node_t> outNodes; |
|
|
|
for (int nodeIdx = 0; nodeIdx < world->numNodes; ++nodeIdx) |
|
|
|
{ |
|
|
|
node_t* node = &world->nodes[nodeIdx]; |
|
|
|
|
|
|
|
ps1bsp_node_t outNode; |
|
|
|
outNode.planeId = node->plane_id; |
|
|
|
outNode.front = node->front; |
|
|
|
outNode.back = node->back; |
|
|
|
|
|
|
|
outNodes.push_back(outNode); |
|
|
|
} |
|
|
|
|
|
|
|
// Convert leaves
|
|
|
|
std::vector<ps1bsp_leaf_t> outLeaves; |
|
|
|
for (int leafIdx = 0; leafIdx < world->numLeaves; ++leafIdx) |
|
|
|
{ |
|
|
|
dleaf_t* leaf = &world->leaves[leafIdx]; |
|
|
|
|
|
|
|
ps1bsp_leaf_t outLeaf; |
|
|
|
outLeaf.type = leaf->type; |
|
|
|
outLeaf.vislist = leaf->vislist; |
|
|
|
outLeaf.firstLeafFace = leaf->lface_id; |
|
|
|
outLeaf.numLeafFaces = leaf->lface_num; |
|
|
|
|
|
|
|
outLeaves.push_back(outLeaf); |
|
|
|
} |
|
|
|
|
|
|
|
std::vector<unsigned short> outLeafFaces(world->faceList, world->faceList + world->faceListLength); |
|
|
|
|
|
|
|
// Write collected data to file and update header info
|
|
|
|
writeMapData(outVertices, outHeader.vertices, fbsp); |
|
|
|
writeMapData(outFaces, outHeader.faces, fbsp); |
|
|
|
writeMapData(outFaceVertices, outHeader.faceVertices, fbsp); |
|
|
|
writeMapData(outPlanes, outHeader.planes, fbsp); |
|
|
|
writeMapData(outNodes, outHeader.nodes, fbsp); |
|
|
|
writeMapData(outLeaves, outHeader.leaves, fbsp); |
|
|
|
writeMapData(outLeafFaces, outHeader.leafFaces, fbsp); |
|
|
|
|
|
|
|
// Write final header
|
|
|
|
fseek(fbsp, 0, SEEK_SET); |
|
|
|
fwrite(&outHeader, sizeof(ps1bsp_header_t), 1, fbsp); |
|
|
|
fclose(fbsp); |
|
|
|
|
|
|
|
printf("PS1BSP: wrote %d vertices, %d indices, %d faces\n", outVertices.size(), outFaceVertices.size(), outFaces.size()); |
|
|
|
printf("PS1BSP: wrote %d vertices, %d faces, %d face verts, %d planes, %d nodes, %d leaves, %d leaf faces\n", |
|
|
|
outVertices.size(), outFaces.size(), outFaceVertices.size(), |
|
|
|
outPlanes.size(), outNodes.size(), outLeaves.size(), outLeafFaces.size()); |
|
|
|
|
|
|
|
return 1; |
|
|
|
} |
|
|
|
|