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
|
struct BSPBoxBrush
|
||||||
{
|
{
|
||||||
vec3_t localMins;
|
size_t vertexIndex;
|
||||||
vec3_t localMaxs;
|
size_t vertexCount;
|
||||||
|
|
||||||
int surfaceFlags;
|
int surfaceFlags;
|
||||||
int contentFlags;
|
int contentFlags;
|
||||||
@@ -82,6 +82,7 @@ namespace BSP
|
|||||||
std::vector<BSPXModel> xmodels;
|
std::vector<BSPXModel> xmodels;
|
||||||
|
|
||||||
std::vector<BSPBoxBrush> scriptBoxBrushes;
|
std::vector<BSPBoxBrush> scriptBoxBrushes;
|
||||||
|
std::vector<vec3_t> boxBrushVerts;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BSPLightType
|
enum BSPLightType
|
||||||
|
|||||||
@@ -653,6 +653,14 @@ namespace
|
|||||||
if (mesh.primitives.size() == 0)
|
if (mesh.primitives.size() == 0)
|
||||||
throw new GltfLoadException("Script model created with no mesh data");
|
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;
|
BSPModel model;
|
||||||
model.isGfxModel = m_is_world_gfx;
|
model.isGfxModel = m_is_world_gfx;
|
||||||
model.surfaceIndex = 0;
|
model.surfaceIndex = 0;
|
||||||
@@ -661,11 +669,16 @@ namespace
|
|||||||
model.brushIndex = m_curr_bsp_world->scriptBoxBrushes.size();
|
model.brushIndex = m_curr_bsp_world->scriptBoxBrushes.size();
|
||||||
m_bsp->models.emplace_back(model);
|
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;
|
BSPBoxBrush boxBrush;
|
||||||
boxBrush.contentFlags = 1;
|
boxBrush.vertexIndex = m_curr_bsp_world->boxBrushVerts.size();
|
||||||
boxBrush.surfaceFlags = 1;
|
boxBrush.contentFlags = m_curr_bsp_world->materials.at(materialIndex).contentFlags;
|
||||||
vec3_t worldMins;
|
boxBrush.surfaceFlags = m_curr_bsp_world->materials.at(materialIndex).surfaceFlags;
|
||||||
vec3_t worldMaxs;
|
|
||||||
for (size_t primIdx = 0; primIdx < mesh.primitives.size(); primIdx++)
|
for (size_t primIdx = 0; primIdx < mesh.primitives.size(); primIdx++)
|
||||||
{
|
{
|
||||||
const auto& primitive = mesh.primitives.at(primIdx);
|
const auto& primitive = mesh.primitives.at(primIdx);
|
||||||
@@ -699,31 +712,15 @@ namespace
|
|||||||
vertex.z = transformedPosition.z();
|
vertex.z = transformedPosition.z();
|
||||||
RhcToLhcCoordinates(vertex.v);
|
RhcToLhcCoordinates(vertex.v);
|
||||||
|
|
||||||
if (vertexIndex == 0 && primIdx == 0)
|
// brush verts use local position
|
||||||
{
|
vertex.x -= origin.x;
|
||||||
worldMins = vertex;
|
vertex.y -= origin.y;
|
||||||
worldMaxs = vertex;
|
vertex.z -= origin.z;
|
||||||
}
|
|
||||||
else
|
|
||||||
BSPUtil::updateAABBWithPoint(vertex, worldMins, worldMaxs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
|
m_curr_bsp_world->boxBrushVerts.emplace_back(vertex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boxBrush.vertexCount = m_curr_bsp_world->boxBrushVerts.size() - boxBrush.vertexIndex;
|
||||||
m_curr_bsp_world->scriptBoxBrushes.emplace_back(boxBrush);
|
m_curr_bsp_world->scriptBoxBrushes.emplace_back(boxBrush);
|
||||||
|
|
||||||
return m_bsp->models.size(); // script model index starts at 1
|
return m_bsp->models.size(); // script model index starts at 1
|
||||||
|
|||||||
@@ -291,9 +291,24 @@ namespace BSP
|
|||||||
|
|
||||||
if (bspModel.hasBrush)
|
if (bspModel.hasBrush)
|
||||||
{
|
{
|
||||||
|
|
||||||
BSPBoxBrush& bspBrush = bsp->colWorld.scriptBoxBrushes.at(bspModel.brushIndex);
|
BSPBoxBrush& bspBrush = bsp->colWorld.scriptBoxBrushes.at(bspModel.brushIndex);
|
||||||
clipModel->leaf.mins = bspBrush.localMins;
|
vec3_t mins;
|
||||||
clipModel->leaf.maxs = bspBrush.localMaxs;
|
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.brushContents = bspBrush.contentFlags;
|
||||||
clipModel->leaf.leafBrushNode = static_cast<int>(brushNodeVec.size());
|
clipModel->leaf.leafBrushNode = static_cast<int>(brushNodeVec.size());
|
||||||
assert(clipModel->leaf.leafBrushNode != 0);
|
assert(clipModel->leaf.leafBrushNode != 0);
|
||||||
@@ -308,9 +323,11 @@ namespace BSP
|
|||||||
|
|
||||||
cbrush_array_t brush;
|
cbrush_array_t brush;
|
||||||
memset(&brush, 0, sizeof(cbrush_array_t)); // if not sides or verts are given, the mins/maxs are used instead
|
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.contents = bspBrush.contentFlags;
|
||||||
brush.mins = bspBrush.localMins;
|
brush.mins = mins;
|
||||||
brush.maxs = bspBrush.localMaxs;
|
brush.maxs = maxs;
|
||||||
brush.axial_cflags[0][0] = bspBrush.contentFlags;
|
brush.axial_cflags[0][0] = bspBrush.contentFlags;
|
||||||
brush.axial_cflags[0][1] = bspBrush.contentFlags;
|
brush.axial_cflags[0][1] = bspBrush.contentFlags;
|
||||||
brush.axial_cflags[0][2] = bspBrush.contentFlags;
|
brush.axial_cflags[0][2] = bspBrush.contentFlags;
|
||||||
@@ -326,11 +343,11 @@ namespace BSP
|
|||||||
brushVec.emplace_back(brush);
|
brushVec.emplace_back(brush);
|
||||||
|
|
||||||
if (bspModel.surfaceCount != 0)
|
if (bspModel.surfaceCount != 0)
|
||||||
BSPUtil::updateAABB(bspBrush.localMins, bspBrush.localMaxs, clipModel->mins, clipModel->maxs);
|
BSPUtil::updateAABB(mins, maxs, clipModel->mins, clipModel->maxs);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
clipModel->mins = bspBrush.localMins;
|
clipModel->mins = mins;
|
||||||
clipModel->maxs = bspBrush.localMaxs;
|
clipModel->maxs = maxs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -757,8 +774,6 @@ namespace BSP
|
|||||||
clipMap->info.brushsides = nullptr;
|
clipMap->info.brushsides = nullptr;
|
||||||
clipMap->info.numLeafBrushes = 0;
|
clipMap->info.numLeafBrushes = 0;
|
||||||
clipMap->info.leafbrushes = nullptr;
|
clipMap->info.leafbrushes = nullptr;
|
||||||
clipMap->info.numBrushVerts = 0;
|
|
||||||
clipMap->info.brushVerts = nullptr;
|
|
||||||
clipMap->info.brushBounds = nullptr;
|
clipMap->info.brushBounds = nullptr;
|
||||||
clipMap->info.brushContents = nullptr;
|
clipMap->info.brushContents = nullptr;
|
||||||
|
|
||||||
@@ -767,8 +782,9 @@ namespace BSP
|
|||||||
memset(&tempNode, 0, sizeof(cLeafBrushNode_s));
|
memset(&tempNode, 0, sizeof(cLeafBrushNode_s));
|
||||||
brushNodeVec.emplace_back(tempNode);
|
brushNodeVec.emplace_back(tempNode);
|
||||||
|
|
||||||
clipMap->info.numBrushes = 0;
|
clipMap->info.numBrushVerts = static_cast<uint16_t>(bsp->colWorld.boxBrushVerts.size());
|
||||||
clipMap->info.brushes = nullptr;
|
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
|
// load verts, tris, uinds and partitions
|
||||||
if (!loadPartitions(clipMap, bsp))
|
if (!loadPartitions(clipMap, bsp))
|
||||||
|
|||||||
@@ -606,8 +606,8 @@ namespace BSP
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
currEntModel->startSurfIndex = 0;
|
currEntModel->startSurfIndex = -1; // -1 when it doesn't use map surfaces
|
||||||
currEntModel->surfaceCount = -1; // -1 when it doesn't use map surfaces
|
currEntModel->surfaceCount = 0;
|
||||||
currEntModel->bounds[0].x = 0.0f;
|
currEntModel->bounds[0].x = 0.0f;
|
||||||
currEntModel->bounds[0].y = 0.0f;
|
currEntModel->bounds[0].y = 0.0f;
|
||||||
currEntModel->bounds[0].z = 0.0f;
|
currEntModel->bounds[0].z = 0.0f;
|
||||||
|
|||||||
Reference in New Issue
Block a user