mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-06-06 08:42:35 +00:00
feat: script_brushmodel now works correctly
This commit is contained in:
@@ -64,8 +64,8 @@ namespace BSP
|
||||
|
||||
struct BSPBoxBrush
|
||||
{
|
||||
vec3_t localMins;
|
||||
vec3_t localMaxs;
|
||||
size_t vertexIndex;
|
||||
size_t vertexCount;
|
||||
|
||||
int surfaceFlags;
|
||||
int contentFlags;
|
||||
@@ -82,6 +82,7 @@ namespace BSP
|
||||
std::vector<BSPXModel> xmodels;
|
||||
|
||||
std::vector<BSPBoxBrush> scriptBoxBrushes;
|
||||
std::vector<vec3_t> boxBrushVerts;
|
||||
};
|
||||
|
||||
enum BSPLightType
|
||||
|
||||
@@ -653,6 +653,14 @@ namespace
|
||||
if (mesh.primitives.size() == 0)
|
||||
throw new GltfLoadException("Script model created with no mesh data");
|
||||
|
||||
Eigen::Vector4f tempPosition(0, 0, 0, 1.0f);
|
||||
Eigen::Vector4f transformedPosition = nodeMatrix * tempPosition;
|
||||
vec3_t origin;
|
||||
origin.x = transformedPosition.x();
|
||||
origin.y = transformedPosition.y();
|
||||
origin.z = transformedPosition.z();
|
||||
RhcToLhcCoordinates(origin.v);
|
||||
|
||||
BSPModel model;
|
||||
model.isGfxModel = m_is_world_gfx;
|
||||
model.surfaceIndex = 0;
|
||||
@@ -661,11 +669,16 @@ namespace
|
||||
model.brushIndex = m_curr_bsp_world->scriptBoxBrushes.size();
|
||||
m_bsp->models.emplace_back(model);
|
||||
|
||||
size_t materialIndex = m_emptyMaterialIndex;
|
||||
if (node.extras && node.extras->contains("flags"))
|
||||
{
|
||||
bool isNoDrawFlagSet;
|
||||
materialIndex = createMaterialWithFlags(materialIndex, node.extras->at("flags"), isNoDrawFlagSet);
|
||||
}
|
||||
BSPBoxBrush boxBrush;
|
||||
boxBrush.contentFlags = 1;
|
||||
boxBrush.surfaceFlags = 1;
|
||||
vec3_t worldMins;
|
||||
vec3_t worldMaxs;
|
||||
boxBrush.vertexIndex = m_curr_bsp_world->boxBrushVerts.size();
|
||||
boxBrush.contentFlags = m_curr_bsp_world->materials.at(materialIndex).contentFlags;
|
||||
boxBrush.surfaceFlags = m_curr_bsp_world->materials.at(materialIndex).surfaceFlags;
|
||||
for (size_t primIdx = 0; primIdx < mesh.primitives.size(); primIdx++)
|
||||
{
|
||||
const auto& primitive = mesh.primitives.at(primIdx);
|
||||
@@ -699,31 +712,15 @@ namespace
|
||||
vertex.z = transformedPosition.z();
|
||||
RhcToLhcCoordinates(vertex.v);
|
||||
|
||||
if (vertexIndex == 0 && primIdx == 0)
|
||||
{
|
||||
worldMins = vertex;
|
||||
worldMaxs = vertex;
|
||||
}
|
||||
else
|
||||
BSPUtil::updateAABBWithPoint(vertex, worldMins, worldMaxs);
|
||||
// brush verts use local position
|
||||
vertex.x -= origin.x;
|
||||
vertex.y -= origin.y;
|
||||
vertex.z -= origin.z;
|
||||
|
||||
m_curr_bsp_world->boxBrushVerts.emplace_back(vertex);
|
||||
}
|
||||
}
|
||||
|
||||
// convert world position to local position
|
||||
Eigen::Vector4f position(0, 0, 0, 1.0f);
|
||||
Eigen::Vector4f transformedPosition = nodeMatrix * position;
|
||||
vec3_t origin;
|
||||
origin.x = transformedPosition.x();
|
||||
origin.y = transformedPosition.y();
|
||||
origin.z = transformedPosition.z();
|
||||
RhcToLhcCoordinates(origin.v);
|
||||
boxBrush.localMins.x = worldMins.x - origin.x;
|
||||
boxBrush.localMins.y = worldMins.y - origin.y;
|
||||
boxBrush.localMins.z = worldMins.z - origin.z;
|
||||
boxBrush.localMaxs.x = worldMaxs.x - origin.x;
|
||||
boxBrush.localMaxs.y = worldMaxs.y - origin.y;
|
||||
boxBrush.localMaxs.z = worldMaxs.z - origin.z;
|
||||
|
||||
boxBrush.vertexCount = m_curr_bsp_world->boxBrushVerts.size() - boxBrush.vertexIndex;
|
||||
m_curr_bsp_world->scriptBoxBrushes.emplace_back(boxBrush);
|
||||
|
||||
return m_bsp->models.size(); // script model index starts at 1
|
||||
|
||||
@@ -291,9 +291,24 @@ namespace BSP
|
||||
|
||||
if (bspModel.hasBrush)
|
||||
{
|
||||
|
||||
BSPBoxBrush& bspBrush = bsp->colWorld.scriptBoxBrushes.at(bspModel.brushIndex);
|
||||
clipModel->leaf.mins = bspBrush.localMins;
|
||||
clipModel->leaf.maxs = bspBrush.localMaxs;
|
||||
vec3_t mins;
|
||||
vec3_t maxs;
|
||||
for (size_t vertIdx = 0; vertIdx < bspBrush.vertexCount; vertIdx++)
|
||||
{
|
||||
vec3_t* vertex = &clipMap->info.brushVerts[bspBrush.vertexIndex + vertIdx];
|
||||
if (vertIdx == 0)
|
||||
{
|
||||
mins = *vertex;
|
||||
maxs = *vertex;
|
||||
}
|
||||
else
|
||||
BSPUtil::updateAABBWithPoint(*vertex, mins, maxs);
|
||||
}
|
||||
|
||||
clipModel->leaf.mins = mins;
|
||||
clipModel->leaf.maxs = maxs;
|
||||
clipModel->leaf.brushContents = bspBrush.contentFlags;
|
||||
clipModel->leaf.leafBrushNode = static_cast<int>(brushNodeVec.size());
|
||||
assert(clipModel->leaf.leafBrushNode != 0);
|
||||
@@ -308,9 +323,11 @@ namespace BSP
|
||||
|
||||
cbrush_array_t brush;
|
||||
memset(&brush, 0, sizeof(cbrush_array_t)); // if not sides or verts are given, the mins/maxs are used instead
|
||||
brush.numverts = static_cast<unsigned int>(bspBrush.vertexCount);
|
||||
brush.verts = &clipMap->info.brushVerts[bspBrush.vertexIndex];
|
||||
brush.contents = bspBrush.contentFlags;
|
||||
brush.mins = bspBrush.localMins;
|
||||
brush.maxs = bspBrush.localMaxs;
|
||||
brush.mins = mins;
|
||||
brush.maxs = maxs;
|
||||
brush.axial_cflags[0][0] = bspBrush.contentFlags;
|
||||
brush.axial_cflags[0][1] = bspBrush.contentFlags;
|
||||
brush.axial_cflags[0][2] = bspBrush.contentFlags;
|
||||
@@ -326,11 +343,11 @@ namespace BSP
|
||||
brushVec.emplace_back(brush);
|
||||
|
||||
if (bspModel.surfaceCount != 0)
|
||||
BSPUtil::updateAABB(bspBrush.localMins, bspBrush.localMaxs, clipModel->mins, clipModel->maxs);
|
||||
BSPUtil::updateAABB(mins, maxs, clipModel->mins, clipModel->maxs);
|
||||
else
|
||||
{
|
||||
clipModel->mins = bspBrush.localMins;
|
||||
clipModel->maxs = bspBrush.localMaxs;
|
||||
clipModel->mins = mins;
|
||||
clipModel->maxs = maxs;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -757,8 +774,6 @@ namespace BSP
|
||||
clipMap->info.brushsides = nullptr;
|
||||
clipMap->info.numLeafBrushes = 0;
|
||||
clipMap->info.leafbrushes = nullptr;
|
||||
clipMap->info.numBrushVerts = 0;
|
||||
clipMap->info.brushVerts = nullptr;
|
||||
clipMap->info.brushBounds = nullptr;
|
||||
clipMap->info.brushContents = nullptr;
|
||||
|
||||
@@ -767,8 +782,9 @@ namespace BSP
|
||||
memset(&tempNode, 0, sizeof(cLeafBrushNode_s));
|
||||
brushNodeVec.emplace_back(tempNode);
|
||||
|
||||
clipMap->info.numBrushes = 0;
|
||||
clipMap->info.brushes = nullptr;
|
||||
clipMap->info.numBrushVerts = static_cast<uint16_t>(bsp->colWorld.boxBrushVerts.size());
|
||||
clipMap->info.brushVerts = m_memory.Alloc<vec3_t>(bsp->colWorld.boxBrushVerts.size());
|
||||
memcpy(clipMap->info.brushVerts, bsp->colWorld.boxBrushVerts.data(), sizeof(vec3_t) * bsp->colWorld.boxBrushVerts.size());
|
||||
|
||||
// load verts, tris, uinds and partitions
|
||||
if (!loadPartitions(clipMap, bsp))
|
||||
|
||||
@@ -606,8 +606,8 @@ namespace BSP
|
||||
}
|
||||
else
|
||||
{
|
||||
currEntModel->startSurfIndex = 0;
|
||||
currEntModel->surfaceCount = -1; // -1 when it doesn't use map surfaces
|
||||
currEntModel->startSurfIndex = -1; // -1 when it doesn't use map surfaces
|
||||
currEntModel->surfaceCount = 0;
|
||||
currEntModel->bounds[0].x = 0.0f;
|
||||
currEntModel->bounds[0].y = 0.0f;
|
||||
currEntModel->bounds[0].z = 0.0f;
|
||||
|
||||
Reference in New Issue
Block a user