mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-11-23 13:12:06 +00:00
Extended BSP creation to support X, Y and Z splitting and simplified clipmap BSP generation.
This commit is contained in:
@@ -86,8 +86,6 @@ namespace BSP
|
|||||||
splitTree();
|
splitTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
// For simplicity, only split across the X and Z axis.
|
|
||||||
// It is unlikely that there are many layers to a map, and is instead mostly flat
|
|
||||||
void BSPTree::splitTree()
|
void BSPTree::splitTree()
|
||||||
{
|
{
|
||||||
std::unique_ptr<BSPTree> front;
|
std::unique_ptr<BSPTree> front;
|
||||||
@@ -105,6 +103,17 @@ namespace BSP
|
|||||||
node = std::make_unique<BSPNode>(std::move(front), std::move(back), AXIS_X, halfLength);
|
node = std::make_unique<BSPNode>(std::move(front), std::move(back), AXIS_X, halfLength);
|
||||||
leaf = nullptr;
|
leaf = nullptr;
|
||||||
}
|
}
|
||||||
|
else if (max.y - min.y > MAX_NODE_SIZE)
|
||||||
|
{
|
||||||
|
// split along the x axis
|
||||||
|
halfLength = (min.y + max.y) * 0.5f;
|
||||||
|
front = std::make_unique<BSPTree>(min.x, halfLength, min.z, max.x, max.y, max.z, level + 1);
|
||||||
|
back = std::make_unique<BSPTree>(min.x, min.y, min.z, max.x, halfLength, max.z, level + 1);
|
||||||
|
|
||||||
|
isLeaf = false;
|
||||||
|
node = std::make_unique<BSPNode>(std::move(front), std::move(back), AXIS_Y, halfLength);
|
||||||
|
leaf = nullptr;
|
||||||
|
}
|
||||||
else if (max.z - min.z > MAX_NODE_SIZE)
|
else if (max.z - min.z > MAX_NODE_SIZE)
|
||||||
{
|
{
|
||||||
// split along the z axis
|
// split along the z axis
|
||||||
|
|||||||
@@ -332,27 +332,20 @@ namespace BSP
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
cplane_s plane;
|
cplane_s plane;
|
||||||
|
plane.dist = tree->node->distance;
|
||||||
if (tree->node->axis == AXIS_X)
|
if (tree->node->axis == AXIS_X)
|
||||||
{
|
{
|
||||||
plane.normal = normalX;
|
plane.normal = normalX;
|
||||||
plane.dist = tree->node->distance;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// converting Z coords to BO2 negates the z coords and sets it to the y coord.
|
|
||||||
assert(tree->node->axis == AXIS_Z);
|
|
||||||
plane.normal = normalY;
|
|
||||||
plane.dist = -tree->node->distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plane.normal.x == 1.0f)
|
|
||||||
plane.type = 0;
|
plane.type = 0;
|
||||||
else if (plane.normal.y == 1.0f)
|
}
|
||||||
plane.type = 1;
|
else if (tree->node->axis == AXIS_Y)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
assert(plane.normal.z == 1.0f);
|
plane.normal = normalY;
|
||||||
|
plane.type = 1;
|
||||||
|
}
|
||||||
|
else // tree->node->axis == AXIS_Z
|
||||||
|
{
|
||||||
|
plane.normal = normalZ;
|
||||||
plane.type = 2;
|
plane.type = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,23 +362,14 @@ namespace BSP
|
|||||||
|
|
||||||
planeVec.emplace_back(plane);
|
planeVec.emplace_back(plane);
|
||||||
|
|
||||||
// The recursion of adding the children means the node needs to be added before the chilren are loaded
|
// The recursion of adding the children through loadBSPNode means the parent node needs to be added before the chilren are loaded
|
||||||
size_t nodeIndex = nodeVec.size();
|
size_t nodeIndex = nodeVec.size();
|
||||||
nodeVec.emplace_back();
|
nodeVec.emplace_back();
|
||||||
|
|
||||||
cNode_t node;
|
cNode_t node;
|
||||||
node.plane = nullptr; // initalised after the BSP tree has been loaded
|
node.plane = nullptr; // initalised after the BSP tree has been loaded
|
||||||
if (plane.type == 1)
|
|
||||||
{
|
|
||||||
// Due to the plane normal going from Z to Y, objects behind the plane are now in front and objects in front are now behind
|
|
||||||
node.children[1] = loadBSPNode(clipMap, tree->node->front.get());
|
|
||||||
node.children[0] = loadBSPNode(clipMap, tree->node->back.get());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
node.children[0] = loadBSPNode(clipMap, tree->node->front.get());
|
node.children[0] = loadBSPNode(clipMap, tree->node->front.get());
|
||||||
node.children[1] = loadBSPNode(clipMap, tree->node->back.get());
|
node.children[1] = loadBSPNode(clipMap, tree->node->back.get());
|
||||||
}
|
|
||||||
|
|
||||||
nodeVec.at(nodeIndex) = node;
|
nodeVec.at(nodeIndex) = node;
|
||||||
|
|
||||||
@@ -395,15 +379,11 @@ namespace BSP
|
|||||||
|
|
||||||
void ClipMapLinker::loadBSPTree(clipMap_t* clipMap, BSPData* bsp)
|
void ClipMapLinker::loadBSPTree(clipMap_t* clipMap, BSPData* bsp)
|
||||||
{
|
{
|
||||||
// HACK:
|
|
||||||
// the BSP tree creation does not work when BO2's coordinate system is used for mins and maxs.
|
|
||||||
// Workaround is to convert every BO2 coordinate before it is added into the BSP tree.
|
|
||||||
|
|
||||||
vec3_t worldMins;
|
vec3_t worldMins;
|
||||||
vec3_t worldMaxs;
|
vec3_t worldMaxs;
|
||||||
for (unsigned int vertIdx = 0; vertIdx < clipMap->vertCount; vertIdx++)
|
for (unsigned int vertIdx = 0; vertIdx < clipMap->vertCount; vertIdx++)
|
||||||
{
|
{
|
||||||
vec3_t vertex = BSPUtil::convertFromBO2Coords(clipMap->verts[vertIdx]);
|
vec3_t vertex = clipMap->verts[vertIdx];
|
||||||
// initalise AABB with the first vertex
|
// initalise AABB with the first vertex
|
||||||
if (vertIdx == 0)
|
if (vertIdx == 0)
|
||||||
{
|
{
|
||||||
@@ -423,7 +403,7 @@ namespace BSP
|
|||||||
for (int uindIdx = 0; uindIdx < partition->nuinds; uindIdx++)
|
for (int uindIdx = 0; uindIdx < partition->nuinds; uindIdx++)
|
||||||
{
|
{
|
||||||
uint16_t uind = clipMap->info.uinds[partition->fuind + uindIdx];
|
uint16_t uind = clipMap->info.uinds[partition->fuind + uindIdx];
|
||||||
vec3_t vert = BSPUtil::convertFromBO2Coords(clipMap->verts[uind]);
|
vec3_t vert = clipMap->verts[uind];
|
||||||
// initalise the AABB with the first vertex
|
// initalise the AABB with the first vertex
|
||||||
if (uindIdx == 0)
|
if (uindIdx == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user