|
|
@ -105,7 +105,6 @@ int process_faces(const world_t* world, const TextureList& textures) |
|
|
// Sum all vertices to calculate an average center point
|
|
|
// Sum all vertices to calculate an average center point
|
|
|
vertexSum = vertexSum + vertexPoint; |
|
|
vertexSum = vertexSum + vertexPoint; |
|
|
|
|
|
|
|
|
// TODO: compute texture color * light at this vertex
|
|
|
|
|
|
ps1bsp_facevertex_t faceVertex = { 0 }; |
|
|
ps1bsp_facevertex_t faceVertex = { 0 }; |
|
|
faceVertex.index = (unsigned short)tesselator.addVertex(vertexPoint); |
|
|
faceVertex.index = (unsigned short)tesselator.addVertex(vertexPoint); |
|
|
outFaceVertices.push_back(faceVertex); |
|
|
outFaceVertices.push_back(faceVertex); |
|
|
@ -260,9 +259,9 @@ int process_faces(const world_t* world, const TextureList& textures) |
|
|
// Ensure we don't overflow 16-bit short values. Most Quake maps will stay within these bounds so it *should* be fine (for now).
|
|
|
// Ensure we don't overflow 16-bit short values. Most Quake maps will stay within these bounds so it *should* be fine (for now).
|
|
|
if (inVertex.x > -8192 && inVertex.x < 8192 && inVertex.y > -8192 && inVertex.y < 8192 && inVertex.z > -8192 && inVertex.z < 8192) |
|
|
if (inVertex.x > -8192 && inVertex.x < 8192 && inVertex.y > -8192 && inVertex.y < 8192 && inVertex.z > -8192 && inVertex.z < 8192) |
|
|
{ |
|
|
{ |
|
|
outVertex.x = (short)(inVertex.x * 4); |
|
|
|
|
|
outVertex.y = (short)(inVertex.y * 4); |
|
|
|
|
|
outVertex.z = (short)(inVertex.z * 4); |
|
|
|
|
|
|
|
|
outVertex.x = (short)(inVertex.x * WORLDSCALE); |
|
|
|
|
|
outVertex.y = (short)(inVertex.y * WORLDSCALE); |
|
|
|
|
|
outVertex.z = (short)(inVertex.z * WORLDSCALE); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
@ -289,7 +288,7 @@ int process_faces(const world_t* world, const TextureList& textures) |
|
|
|
|
|
|
|
|
ps1bsp_plane_t outPlane = { 0 }; |
|
|
ps1bsp_plane_t outPlane = { 0 }; |
|
|
outPlane.normal = plane->normal.convertNormal(); |
|
|
outPlane.normal = plane->normal.convertNormal(); |
|
|
outPlane.dist = (short)(plane->dist * 4); |
|
|
|
|
|
|
|
|
outPlane.dist = (short)(plane->dist * WORLDSCALE); |
|
|
outPlane.type = (short)plane->type; |
|
|
outPlane.type = (short)plane->type; |
|
|
|
|
|
|
|
|
outPlanes.push_back(outPlane); |
|
|
outPlanes.push_back(outPlane); |
|
|
@ -329,6 +328,21 @@ int process_faces(const world_t* world, const TextureList& textures) |
|
|
outLeaves.push_back(outLeaf); |
|
|
outLeaves.push_back(outLeaf); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Convert models
|
|
|
|
|
|
std::vector<ps1bsp_model_t> outModels; |
|
|
|
|
|
for (int modelIdx = 0; modelIdx < world->numModels; ++modelIdx) |
|
|
|
|
|
{ |
|
|
|
|
|
model_t* model = &world->models[modelIdx]; |
|
|
|
|
|
|
|
|
|
|
|
ps1bsp_model_t outModel = { 0 }; |
|
|
|
|
|
outModel.boundingSphere = model->bound.toBoundingSphere(); |
|
|
|
|
|
outModel.origin = model->origin.convertWorldPosition(); |
|
|
|
|
|
outModel.nodeId = (u_short)model->node_id0; |
|
|
|
|
|
outModel.clipNodeId = (u_short)model->node_id1; |
|
|
|
|
|
|
|
|
|
|
|
outModels.push_back(outModel); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
std::vector<unsigned short> outLeafFaces(world->faceList, world->faceList + world->faceListLength); |
|
|
std::vector<unsigned short> outLeafFaces(world->faceList, world->faceList + world->faceListLength); |
|
|
std::vector<unsigned char> outVisData(world->visList, world->visList + world->visListLength); |
|
|
std::vector<unsigned char> outVisData(world->visList, world->visList + world->visListLength); |
|
|
|
|
|
|
|
|
@ -344,15 +358,17 @@ int process_faces(const world_t* world, const TextureList& textures) |
|
|
writeMapData(outLeaves, outHeader.leaves, fbsp); |
|
|
writeMapData(outLeaves, outHeader.leaves, fbsp); |
|
|
writeMapData(outLeafFaces, outHeader.leafFaces, fbsp); |
|
|
writeMapData(outLeafFaces, outHeader.leafFaces, fbsp); |
|
|
writeMapData(outVisData, outHeader.visData, fbsp); |
|
|
writeMapData(outVisData, outHeader.visData, fbsp); |
|
|
|
|
|
writeMapData(outModels, outHeader.models, fbsp); |
|
|
|
|
|
|
|
|
// Write final header
|
|
|
// Write final header
|
|
|
fseek(fbsp, 0, SEEK_SET); |
|
|
fseek(fbsp, 0, SEEK_SET); |
|
|
fwrite(&outHeader, sizeof(ps1bsp_header_t), 1, fbsp); |
|
|
fwrite(&outHeader, sizeof(ps1bsp_header_t), 1, fbsp); |
|
|
fclose(fbsp); |
|
|
fclose(fbsp); |
|
|
|
|
|
|
|
|
printf("PS1BSP: wrote %d vertices, %d faces, %d polygons, %d planes, %d nodes, %d leaves, %d leaf faces\n", |
|
|
|
|
|
|
|
|
printf("PS1BSP: wrote %d vertices, %d faces, %d polygons, %d planes, %d nodes, %d leaves, %d leaf faces, %d models\n", |
|
|
outVertices.size(), outFaces.size(), outPolygons.size(), |
|
|
outVertices.size(), outFaces.size(), outPolygons.size(), |
|
|
outPlanes.size(), outNodes.size(), outLeaves.size(), outLeafFaces.size()); |
|
|
|
|
|
|
|
|
outPlanes.size(), outNodes.size(), outLeaves.size(), outLeafFaces.size(), |
|
|
|
|
|
outModels.size()); |
|
|
|
|
|
|
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
@ -532,6 +548,15 @@ int load_bsp(const char* bspname, world_t* world) |
|
|
fseek(f, header->leaves.offset, SEEK_SET); |
|
|
fseek(f, header->leaves.offset, SEEK_SET); |
|
|
fread(world->leaves, sizeof(dleaf_t), world->numLeaves, f); |
|
|
fread(world->leaves, sizeof(dleaf_t), world->numLeaves, f); |
|
|
|
|
|
|
|
|
|
|
|
// Load models
|
|
|
|
|
|
world->numModels = header->models.size / sizeof(model_t); |
|
|
|
|
|
world->models = (model_t*)malloc(header->models.size); |
|
|
|
|
|
if (world->models == NULL) |
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
fseek(f, header->models.offset, SEEK_SET); |
|
|
|
|
|
fread(world->models, sizeof(model_t), world->numModels, f); |
|
|
|
|
|
|
|
|
// Load lightmaps
|
|
|
// Load lightmaps
|
|
|
world->lightmapLength = header->lightmaps.size / sizeof(unsigned char); |
|
|
world->lightmapLength = header->lightmaps.size / sizeof(unsigned char); |
|
|
world->lightmap = (unsigned char*)malloc(header->lightmaps.size); |
|
|
world->lightmap = (unsigned char*)malloc(header->lightmaps.size); |
|
|
|