2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-11-23 05:12:05 +00:00

chore: do not use class wrapper for bsp utils methods

This commit is contained in:
Jan Laupetin
2025-11-04 21:30:05 +00:00
parent 0a9dae11af
commit 4b1e81056c
6 changed files with 42 additions and 40 deletions

View File

@@ -98,7 +98,7 @@ namespace
blenderCoords.x = static_cast<float>(transformedPos.x); blenderCoords.x = static_cast<float>(transformedPos.x);
blenderCoords.y = static_cast<float>(transformedPos.y); blenderCoords.y = static_cast<float>(transformedPos.y);
blenderCoords.z = static_cast<float>(transformedPos.z); blenderCoords.z = static_cast<float>(transformedPos.z);
vertex.pos = BSPUtil::convertToBO2Coords(blenderCoords); vertex.pos = ConvertToBO2Coords(blenderCoords);
if (surface.material.materialType == BSPMaterialType::MATERIAL_TYPE_TEXTURE if (surface.material.materialType == BSPMaterialType::MATERIAL_TYPE_TEXTURE
|| surface.material.materialType == BSPMaterialType::MATERIAL_TYPE_EMPTY) || surface.material.materialType == BSPMaterialType::MATERIAL_TYPE_EMPTY)
@@ -203,7 +203,7 @@ namespace BSP
{ {
std::unique_ptr<BSPData> createBSPData(const std::string& mapName, ISearchPath& searchPath) std::unique_ptr<BSPData> createBSPData(const std::string& mapName, ISearchPath& searchPath)
{ {
const auto gfxFbxPath = BSPUtil::getFileNameForBSPAsset("map_gfx.fbx"); const auto gfxFbxPath = GetFileNameForBSPAsset("map_gfx.fbx");
const auto gfxFile = searchPath.Open(gfxFbxPath); const auto gfxFile = searchPath.Open(gfxFbxPath);
if (!gfxFile.IsOpen()) if (!gfxFile.IsOpen())
{ {
@@ -232,7 +232,7 @@ namespace BSP
} }
ufbx_scene* colScene; ufbx_scene* colScene;
const auto colFbxPath = BSPUtil::getFileNameForBSPAsset("map_col.fbx"); const auto colFbxPath = GetFileNameForBSPAsset("map_col.fbx");
const auto colFile = searchPath.Open(colFbxPath); const auto colFile = searchPath.Open(colFbxPath);
if (!colFile.IsOpen()) if (!colFile.IsOpen())
{ {

View File

@@ -9,12 +9,12 @@ using namespace T6;
namespace BSP namespace BSP
{ {
std::string BSPUtil::getFileNameForBSPAsset(const std::string& assetName) std::string GetFileNameForBSPAsset(const std::string& assetName)
{ {
return std::format("BSP/{}", assetName); return std::format("BSP/{}", assetName);
} }
vec3_t BSPUtil::convertToBO2Coords(const vec3_t& coordinate) vec3_t ConvertToBO2Coords(const vec3_t& coordinate)
{ {
vec3_t result; vec3_t result;
result.x = coordinate.x; result.x = coordinate.x;
@@ -23,7 +23,7 @@ namespace BSP
return result; return result;
} }
vec3_t BSPUtil::convertFromBO2Coords(const vec3_t& coordinate) vec3_t ConvertFromBO2Coords(const vec3_t& coordinate)
{ {
vec3_t result; vec3_t result;
result.x = coordinate.x; result.x = coordinate.x;
@@ -32,7 +32,7 @@ namespace BSP
return result; return result;
} }
void BSPUtil::updateAABB(const vec3_t& newAABBMins, const vec3_t& newAABBMaxs, vec3_t& AABBMins, vec3_t& AABBMaxs) void UpdateAABB(const vec3_t& newAABBMins, const vec3_t& newAABBMaxs, vec3_t& AABBMins, vec3_t& AABBMaxs)
{ {
AABBMins.x = std::min(AABBMins.x, newAABBMins.x); AABBMins.x = std::min(AABBMins.x, newAABBMins.x);
AABBMaxs.x = std::max(AABBMaxs.x, newAABBMaxs.x); AABBMaxs.x = std::max(AABBMaxs.x, newAABBMaxs.x);
@@ -44,7 +44,7 @@ namespace BSP
AABBMaxs.z = std::max(AABBMaxs.z, newAABBMaxs.z); AABBMaxs.z = std::max(AABBMaxs.z, newAABBMaxs.z);
} }
void BSPUtil::updateAABBWithPoint(const vec3_t& point, vec3_t& AABBMins, vec3_t& AABBMaxs) void UpdateAABBWithPoint(const vec3_t& point, vec3_t& AABBMins, vec3_t& AABBMaxs)
{ {
AABBMins.x = std::min(AABBMins.x, point.x); AABBMins.x = std::min(AABBMins.x, point.x);
AABBMaxs.x = std::max(AABBMaxs.x, point.x); AABBMaxs.x = std::max(AABBMaxs.x, point.x);
@@ -56,7 +56,7 @@ namespace BSP
AABBMaxs.z = std::max(AABBMaxs.z, point.z); AABBMaxs.z = std::max(AABBMaxs.z, point.z);
} }
vec3_t BSPUtil::calcMiddleOfAABB(const vec3_t& mins, const vec3_t& maxs) vec3_t CalcMiddleOfAABB(const vec3_t& mins, const vec3_t& maxs)
{ {
vec3_t result; vec3_t result;
result.x = (mins.x + maxs.x) * 0.5f; result.x = (mins.x + maxs.x) * 0.5f;
@@ -66,7 +66,7 @@ namespace BSP
return result; return result;
} }
vec3_t BSPUtil::calcHalfSizeOfAABB(const vec3_t& mins, const vec3_t& maxs) vec3_t CalcHalfSizeOfAABB(const vec3_t& mins, const vec3_t& maxs)
{ {
vec3_t result; vec3_t result;
result.x = (maxs.x - mins.x) * 0.5f; result.x = (maxs.x - mins.x) * 0.5f;
@@ -76,7 +76,7 @@ namespace BSP
return result; return result;
} }
float BSPUtil::distBetweenPoints(const vec3_t& p1, const vec3_t& p2) float DistBetweenPoints(const vec3_t& p1, const vec3_t& p2)
{ {
const auto x = p2.x - p1.x; const auto x = p2.x - p1.x;
const auto y = p2.y - p1.y; const auto y = p2.y - p1.y;
@@ -86,7 +86,7 @@ namespace BSP
} }
// angles are in euler degrees // angles are in euler degrees
void BSPUtil::convertAnglesToAxis(const vec3_t* angles, vec3_t* axis) void ConvertAnglesToAxis(const vec3_t* angles, vec3_t* axis)
{ {
constexpr auto conversionValue = std::numbers::pi_v<float> / 180.0f; constexpr auto conversionValue = std::numbers::pi_v<float> / 180.0f;
const auto xRadians = angles->x * conversionValue; const auto xRadians = angles->x * conversionValue;
@@ -111,7 +111,7 @@ namespace BSP
axis[2].z = cosZ * cosX; axis[2].z = cosZ * cosX;
} }
void BSPUtil::matrixTranspose3x3(const vec3_t* in, vec3_t* out) void MatrixTranspose3x3(const vec3_t* in, vec3_t* out)
{ {
out[0].x = in[0].x; out[0].x = in[0].x;
out[0].y = in[1].x; out[0].y = in[1].x;

View File

@@ -4,18 +4,20 @@
namespace BSP namespace BSP
{ {
class BSPUtil std::string GetFileNameForBSPAsset(const std::string& assetName);
{
public: T6::vec3_t ConvertToBO2Coords(const T6::vec3_t& OGL_coordinate);
static std::string getFileNameForBSPAsset(const std::string& assetName); T6::vec3_t ConvertFromBO2Coords(const T6::vec3_t& bo2_coordinate);
static T6::vec3_t convertToBO2Coords(const T6::vec3_t& OGL_coordinate);
static T6::vec3_t convertFromBO2Coords(const T6::vec3_t& bo2_coordinate); void UpdateAABB(const T6::vec3_t& newAABBMins, const T6::vec3_t& newAABBMaxs, T6::vec3_t& AABBMins, T6::vec3_t& AABBMaxs);
static void updateAABB(const T6::vec3_t& newAABBMins, const T6::vec3_t& newAABBMaxs, T6::vec3_t& AABBMins, T6::vec3_t& AABBMaxs); void UpdateAABBWithPoint(const T6::vec3_t& point, T6::vec3_t& AABBMins, T6::vec3_t& AABBMaxs);
static void updateAABBWithPoint(const T6::vec3_t& point, T6::vec3_t& AABBMins, T6::vec3_t& AABBMaxs);
static T6::vec3_t calcMiddleOfAABB(const T6::vec3_t& mins, const T6::vec3_t& maxs); T6::vec3_t CalcMiddleOfAABB(const T6::vec3_t& mins, const T6::vec3_t& maxs);
static T6::vec3_t calcHalfSizeOfAABB(const T6::vec3_t& mins, const T6::vec3_t& maxs); T6::vec3_t CalcHalfSizeOfAABB(const T6::vec3_t& mins, const T6::vec3_t& maxs);
static float distBetweenPoints(const T6::vec3_t& p1, const T6::vec3_t& p2);
static void convertAnglesToAxis(const T6::vec3_t* angles, T6::vec3_t* axis); float DistBetweenPoints(const T6::vec3_t& p1, const T6::vec3_t& p2);
static void matrixTranspose3x3(const T6::vec3_t* in, T6::vec3_t* out);
}; void ConvertAnglesToAxis(const T6::vec3_t* angles, T6::vec3_t* axis);
void MatrixTranspose3x3(const T6::vec3_t* in, T6::vec3_t* out);
} // namespace BSP } // namespace BSP

View File

@@ -146,7 +146,7 @@ namespace BSP
clipMap.cmodels[0].maxs.x = gfxModel->bounds[1].x; clipMap.cmodels[0].maxs.x = gfxModel->bounds[1].x;
clipMap.cmodels[0].maxs.y = gfxModel->bounds[1].y; clipMap.cmodels[0].maxs.y = gfxModel->bounds[1].y;
clipMap.cmodels[0].maxs.z = gfxModel->bounds[1].z; clipMap.cmodels[0].maxs.z = gfxModel->bounds[1].z;
clipMap.cmodels[0].radius = BSPUtil::distBetweenPoints(clipMap.cmodels[0].mins, clipMap.cmodels[0].maxs) / 2; clipMap.cmodels[0].radius = DistBetweenPoints(clipMap.cmodels[0].mins, clipMap.cmodels[0].maxs) / 2;
// The world sub model has no leafs associated with it // The world sub model has no leafs associated with it
clipMap.cmodels[0].leaf.firstCollAabbIndex = 0; clipMap.cmodels[0].leaf.firstCollAabbIndex = 0;
@@ -262,14 +262,14 @@ namespace BSP
parentMaxs = vert; parentMaxs = vert;
} }
BSPUtil::updateAABBWithPoint(vert, parentMins, parentMaxs); UpdateAABBWithPoint(vert, parentMins, parentMaxs);
} }
} }
size_t childObjectStartIndex = AABBTreeVec.size(); size_t childObjectStartIndex = AABBTreeVec.size();
CollisionAabbTree parentAABB; CollisionAabbTree parentAABB;
parentAABB.origin = BSPUtil::calcMiddleOfAABB(parentMins, parentMaxs); parentAABB.origin = CalcMiddleOfAABB(parentMins, parentMaxs);
parentAABB.halfSize = BSPUtil::calcHalfSizeOfAABB(parentMins, parentMaxs); parentAABB.halfSize = CalcHalfSizeOfAABB(parentMins, parentMaxs);
parentAABB.materialIndex = 0; // always use the first material parentAABB.materialIndex = 0; // always use the first material
parentAABB.childCount = static_cast<uint16_t>(childObjectCount); parentAABB.childCount = static_cast<uint16_t>(childObjectCount);
parentAABB.u.firstChildIndex = static_cast<int>(childObjectStartIndex); parentAABB.u.firstChildIndex = static_cast<int>(childObjectStartIndex);
@@ -294,15 +294,15 @@ namespace BSP
childMaxs = vert; childMaxs = vert;
} }
BSPUtil::updateAABBWithPoint(vert, childMins, childMaxs); UpdateAABBWithPoint(vert, childMins, childMaxs);
} }
CollisionAabbTree childAABBTree{}; CollisionAabbTree childAABBTree{};
childAABBTree.materialIndex = 0; // always use the first material childAABBTree.materialIndex = 0; // always use the first material
childAABBTree.childCount = 0; childAABBTree.childCount = 0;
childAABBTree.u.partitionIndex = partitionIndex; childAABBTree.u.partitionIndex = partitionIndex;
childAABBTree.origin = BSPUtil::calcMiddleOfAABB(childMins, childMaxs); childAABBTree.origin = CalcMiddleOfAABB(childMins, childMaxs);
childAABBTree.halfSize = BSPUtil::calcHalfSizeOfAABB(childMins, childMaxs); childAABBTree.halfSize = CalcHalfSizeOfAABB(childMins, childMaxs);
AABBTreeVec.emplace_back(childAABBTree); AABBTreeVec.emplace_back(childAABBTree);
} }
@@ -428,7 +428,7 @@ namespace BSP
worldMins = vertex; worldMins = vertex;
worldMaxs = vertex; worldMaxs = vertex;
} }
BSPUtil::updateAABBWithPoint(vertex, worldMins, worldMaxs); UpdateAABBWithPoint(vertex, worldMins, worldMaxs);
} }
const auto tree = std::make_unique<BSPTree>(worldMins.x, worldMins.y, worldMins.z, worldMaxs.x, worldMaxs.y, worldMaxs.z, 0); const auto tree = std::make_unique<BSPTree>(worldMins.x, worldMins.y, worldMins.z, worldMaxs.x, worldMaxs.y, worldMaxs.z, 0);
assert(!tree->isLeaf); assert(!tree->isLeaf);
@@ -448,7 +448,7 @@ namespace BSP
partitionMins = vert; partitionMins = vert;
partitionMaxs = vert; partitionMaxs = vert;
} }
BSPUtil::updateAABBWithPoint(vert, partitionMins, partitionMaxs); UpdateAABBWithPoint(vert, partitionMins, partitionMaxs);
} }
auto currObject = auto currObject =
std::make_shared<BSPObject>(partitionMins.x, partitionMins.y, partitionMins.z, partitionMaxs.x, partitionMaxs.y, partitionMaxs.z, partitionIdx); std::make_shared<BSPObject>(partitionMins.x, partitionMins.y, partitionMins.z, partitionMaxs.x, partitionMaxs.y, partitionMaxs.z, partitionIdx);

View File

@@ -110,7 +110,7 @@ namespace BSP
for (size_t indexIdx = 0; indexIdx < static_cast<size_t>(gfxSurface->tris.triCount * 3); indexIdx++) for (size_t indexIdx = 0; indexIdx < static_cast<size_t>(gfxSurface->tris.triCount * 3); indexIdx++)
{ {
uint16_t vertIndex = gfxWorld.draw.indices[gfxSurface->tris.baseIndex + indexIdx]; uint16_t vertIndex = gfxWorld.draw.indices[gfxSurface->tris.baseIndex + indexIdx];
BSPUtil::updateAABBWithPoint(firstVert[vertIndex].xyz, gfxSurface->bounds[0], gfxSurface->bounds[1]); UpdateAABBWithPoint(firstVert[vertIndex].xyz, gfxSurface->bounds[0], gfxSurface->bounds[1]);
} }
// unused values // unused values
@@ -500,7 +500,7 @@ namespace BSP
for (int surfIdx = 0; surfIdx < gfxWorld.surfaceCount; surfIdx++) for (int surfIdx = 0; surfIdx < gfxWorld.surfaceCount; surfIdx++)
{ {
BSPUtil::updateAABB(gfxWorld.dpvs.surfaces[surfIdx].bounds[0], gfxWorld.dpvs.surfaces[surfIdx].bounds[1], gfxWorld.mins, gfxWorld.maxs); UpdateAABB(gfxWorld.dpvs.surfaces[surfIdx].bounds[0], gfxWorld.dpvs.surfaces[surfIdx].bounds[1], gfxWorld.mins, gfxWorld.maxs);
} }
} }

View File

@@ -77,7 +77,7 @@ namespace BSP
try try
{ {
json entJs; json entJs;
const auto entityFilePath = BSPUtil::getFileNameForBSPAsset("entities.json"); const auto entityFilePath = GetFileNameForBSPAsset("entities.json");
const auto entFile = m_search_path.Open(entityFilePath); const auto entFile = m_search_path.Open(entityFilePath);
if (!entFile.IsOpen()) if (!entFile.IsOpen())
{ {
@@ -93,7 +93,7 @@ namespace BSP
return nullptr; return nullptr;
json spawnJs; json spawnJs;
const auto spawnFilePath = BSPUtil::getFileNameForBSPAsset("spawns.json"); const auto spawnFilePath = GetFileNameForBSPAsset("spawns.json");
const auto spawnFile = m_search_path.Open(spawnFilePath); const auto spawnFile = m_search_path.Open(spawnFilePath);
if (!spawnFile.IsOpen()) if (!spawnFile.IsOpen())
{ {