Skip to content

Commit

Permalink
QD3D: Support 32-bit triangle point indices
Browse files Browse the repository at this point in the history
  • Loading branch information
jorio committed Oct 19, 2023
1 parent 1881d3a commit ef94150
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/QD3D/3DMFParser.cpp
Expand Up @@ -328,9 +328,7 @@ void Q3MetaFileParser::Parse_tmsh(uint32_t chunkSize)
}
else
{
static_assert(sizeof(TQ3TriMeshTriangleData::pointIndices[0]) == 2);
Assert(false, "Meshes exceeding 65535 vertices are not supported");
//ReadTriangleVertexIndices<uint32_t>(f, numTriangles, currentMesh);
ReadTriangleVertexIndices<uint32_t>(f, numTriangles, currentMesh);
}

// Ensure all vertex indices are in the expected range
Expand Down
30 changes: 15 additions & 15 deletions src/QD3D/QD3D.cpp
Expand Up @@ -232,9 +232,9 @@ void Q3TriMeshData_SubdivideTriangles(TQ3TriMeshData* mesh)
{
struct Edge
{
int a;
int b;
int midpoint;
uint32_t a;
uint32_t b;
uint32_t midpoint;
};

std::map<uint32_t, Edge> edges;
Expand All @@ -254,8 +254,8 @@ void Q3TriMeshData_SubdivideTriangles(TQ3TriMeshData* mesh)

for (int e = 0; e < 3; e++)
{
int edgeP0 = triangle.pointIndices[e];
int edgeP1 = triangle.pointIndices[(e+1) % 3];
uint32_t edgeP0 = triangle.pointIndices[e];
uint32_t edgeP1 = triangle.pointIndices[(e+1) % 3];
if (edgeP0 > edgeP1)
{
int swap = edgeP0;
Expand All @@ -271,7 +271,7 @@ void Q3TriMeshData_SubdivideTriangles(TQ3TriMeshData* mesh)
}
else
{
edges[edgeHash] = { edgeP0, edgeP1, -1 };
edges[edgeHash] = { edgeP0, edgeP1, (uint32_t) -1 };
triangleEdges[t*3 + e] = &edges[edgeHash];
numDistinctEdges++;
}
Expand Down Expand Up @@ -305,9 +305,9 @@ void Q3TriMeshData_SubdivideTriangles(TQ3TriMeshData* mesh)
edge.midpoint = numPointsWritten;
numPointsWritten++;

int M = edge.midpoint;
int A = edge.a;
int B = edge.b;
uint32_t M = edge.midpoint;
uint32_t A = edge.a;
uint32_t B = edge.b;

mesh->points[M].x = (mesh->points[A].x + mesh->points[B].x) / 2.0f;
mesh->points[M].y = (mesh->points[A].y + mesh->points[B].y) / 2.0f;
Expand Down Expand Up @@ -353,12 +353,12 @@ void Q3TriMeshData_SubdivideTriangles(TQ3TriMeshData* mesh)
A ^ C
*/

uint16_t A = triangle.pointIndices[0];
uint16_t B = triangle.pointIndices[1];
uint16_t C = triangle.pointIndices[2];
uint16_t A2B = triangleEdges[t*3 + 0]->midpoint;
uint16_t B2C = triangleEdges[t*3 + 1]->midpoint;
uint16_t C2A = triangleEdges[t*3 + 2]->midpoint;
uint32_t A = triangle.pointIndices[0];
uint32_t B = triangle.pointIndices[1];
uint32_t C = triangle.pointIndices[2];
uint32_t A2B = triangleEdges[t*3 + 0]->midpoint;
uint32_t B2C = triangleEdges[t*3 + 1]->midpoint;
uint32_t C2A = triangleEdges[t*3 + 2]->midpoint;

mesh->triangles[numTrianglesWritten++] = {{A2B, B, B2C} };
mesh->triangles[numTrianglesWritten++] = {{B2C, C, C2A} };
Expand Down
3 changes: 1 addition & 2 deletions src/QD3D/QD3D.h
Expand Up @@ -266,10 +266,9 @@ typedef struct TQ3PlaneEquation
float constant;
} TQ3PlaneEquation;

// WARNING: this structure differs from QD3D (indices were originally 32-bit)
typedef struct TQ3TriMeshTriangleData
{
uint16_t pointIndices[3];
uint32_t pointIndices[3];
} TQ3TriMeshTriangleData;

// This structure differs from QD3D.
Expand Down

0 comments on commit ef94150

Please sign in to comment.