Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions eqglib/eqg_terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ bool Terrain::InitFromWLDData(const STerrainWLDData& wldData)

area.tag = wldArea.tag;
area.userData = wldArea.userData;
area.areaNum = areaNum;
area.regionNumbers.resize(wldArea.numRegions);
memcpy(area.regionNumbers.data(), wldArea.regions, sizeof(uint32_t) * wldArea.numRegions);

Expand Down Expand Up @@ -460,6 +461,7 @@ bool Terrain::InitFromWLDData(const STerrainWLDData& wldData)
if (!m_wldAreas.empty())
{
m_wldAreaEnvironments.resize(m_numWLDRegions);
m_wldAreaEnvironmentsPerArea.resize(m_wldAreas.size());

for (const SArea& area : m_wldAreas)
{
Expand Down Expand Up @@ -510,6 +512,7 @@ bool Terrain::InitFromWLDData(const STerrainWLDData& wldData)
}
}

m_wldAreaEnvironmentsPerArea[area.areaNum] = env;
for (uint32_t regionNum : area.regionNumbers)
{
m_wldAreaEnvironments[regionNum] = env;
Expand Down
2 changes: 2 additions & 0 deletions eqglib/eqg_terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct SArea
{
std::string tag;
std::string userData;
uint32_t areaNum;
std::vector<uint32_t> regionNumbers;
std::vector<glm::vec3> centers;
};
Expand Down Expand Up @@ -148,6 +149,7 @@ class Terrain
std::vector<SArea> m_wldAreas;
std::vector<uint32_t> m_wldAreaIndices;
std::vector<AreaEnvironment> m_wldAreaEnvironments;
std::vector<AreaEnvironment> m_wldAreaEnvironmentsPerArea;
std::shared_ptr<SWorldTreeWLDData> m_wldBspTree;

// EQG areas
Expand Down
74 changes: 37 additions & 37 deletions meshgen/AreaVolumeRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ void AreaVolumeRenderSystem::RebuildBuffers()
{
// Combine volumes in this color group
std::vector<glm::vec3> vertices;
std::vector<std::vector<uint16_t>> faces;
std::vector<std::array<uint16_t, 3>> faces;
std::vector<std::array<uint16_t, 2>> edges;
std::vector<uint32_t> debugFaceColors; // Per-face colors for debug mode

for (entt::entity entity : group)
Expand All @@ -200,13 +201,19 @@ void AreaVolumeRenderSystem::RebuildBuffers()

for (const auto& face : volumeComp.faces)
{
std::vector<uint16_t> adjustedFace;
adjustedFace.reserve(face.size());
for (uint16_t idx : face)
{
adjustedFace.push_back(baseIndex + idx);
}
faces.push_back(std::move(adjustedFace));
std::array<uint16_t, 3> adjustedFace{};
adjustedFace[0] = face[0] + baseIndex;
adjustedFace[1] = face[1] + baseIndex;
adjustedFace[2] = face[2] + baseIndex;
faces.push_back(adjustedFace);
}

for (const auto& edge : volumeComp.outerEdges)
{
std::array<uint16_t, 2> adjustedEdge{};
adjustedEdge[0] = edge[0] + baseIndex;
adjustedEdge[1] = edge[1] + baseIndex;
edges.push_back(adjustedEdge);
}
}

Expand Down Expand Up @@ -251,14 +258,10 @@ void AreaVolumeRenderSystem::RebuildBuffers()
allVertices.push_back(v);
}

// Fan triangulate this face
for (uint16_t i = 1; i + 1 < static_cast<uint16_t>(face.size()); ++i)
{
// Front
allIndices.push_back(faceBaseVertex + 0);
allIndices.push_back(faceBaseVertex + i);
allIndices.push_back(faceBaseVertex + i + 1);
}
// Faces are triangulated
allIndices.push_back(faceBaseVertex + 0);
allIndices.push_back(faceBaseVertex + 1);
allIndices.push_back(faceBaseVertex + 2);
}
}
else
Expand All @@ -279,30 +282,27 @@ void AreaVolumeRenderSystem::RebuildBuffers()

for (const auto& face : faces)
{
for (size_t i = 0; i + 2 < face.size(); ++i)
{
// Front
allIndices.push_back(vertexOffset + face[0]);
allIndices.push_back(vertexOffset + face[i + 1]);
allIndices.push_back(vertexOffset + face[i + 2]);
// Back
//allIndices.push_back(vertexOffset + face[0]);
//allIndices.push_back(vertexOffset + face[i + 2]);
//allIndices.push_back(vertexOffset + face[i + 1]);
}
// Front
allIndices.push_back(vertexOffset + face[0]);
allIndices.push_back(vertexOffset + face[1]);
allIndices.push_back(vertexOffset + face[2]);
// Back
// allIndices.push_back(vertexOffset + face[0]);
// allIndices.push_back(vertexOffset + face[2]);
// allIndices.push_back(vertexOffset + face[1]);
}

for (size_t i = 0; i < face.size(); ++i)
{
uint16_t v0 = face[i];
uint16_t v1 = face[(i + 1) % face.size()];
if (v0 > v1)
std::swap(v0, v1);
for (const auto& edge : edges)
{
uint16_t a = edge[0];
uint16_t b = edge[1];
if (a > b)
std::swap(a, b);

const glm::vec3& vert0 = vertices[v0];
const glm::vec3& vert1 = vertices[v1];
const glm::vec3& vert0 = vertices[a];
const glm::vec3& vert1 = vertices[b];

allLineInstances.emplace_back(vert0, m_lineWidth, outlineCol, vert1, m_lineWidth, outlineCol);
}
allLineInstances.emplace_back(vert0, m_lineWidth, outlineCol, vert1, m_lineWidth, outlineCol);
}
}

Expand Down
3 changes: 2 additions & 1 deletion meshgen/EQComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ struct WldAreaComponent
struct AreaVolumeComponent
{
std::vector<glm::vec3> vertices;
std::vector<std::vector<uint16_t>> faces; // Polygon faces (not triangulated)
std::vector<std::array<uint16_t, 3>> faces; // explicitly triangulated faces
std::vector<std::array<uint16_t, 2>> outerEdges;
};

// Render configuration for AreaVolumeComponent.
Expand Down
Loading