MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / OptimizeTriangleOrdering

Function OptimizeTriangleOrdering

Engine/source/gfx/util/triListOpt.cpp:31–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29{
30
31void OptimizeTriangleOrdering(const dsize_t numVerts, const dsize_t numIndices, const U32 *indices, IndexType *outIndices)
32{
33 PROFILE_SCOPE(TriListOpt_OptimizeTriangleOrdering);
34
35 if(numVerts == 0 || numIndices == 0)
36 {
37 dCopyArray(outIndices, indices, numIndices);
38 return;
39 }
40
41 const U32 NumPrimitives = numIndices / 3;
42 AssertFatal(NumPrimitives == U32(mFloor(numIndices / 3.0f)), "Number of indicies not divisible by 3, not a good triangle list.");
43
44 //
45 // Step 1: Run through the data, and initialize
46 //
47 FrameTemp<VertData> vertexData(numVerts);
48 FrameTemp<TriData> triangleData(NumPrimitives);
49
50 U32 curIdx = 0;
51 for(S32 tri = 0; tri < NumPrimitives; tri++)
52 {
53 TriData &curTri = triangleData[tri];
54
55 for(S32 c = 0; c < 3; c++)
56 {
57 const U32 &curVIdx = indices[curIdx];
58 AssertFatal(curVIdx < numVerts, "Out of range index.");
59
60 // Add this vert to the list of verts that define the triangle
61 curTri.vertIdx[c] = curVIdx;
62
63 VertData &curVert = vertexData[curVIdx];
64
65 // Increment the number of triangles that reference this vertex
66 curVert.numUnaddedReferences++;
67
68 curIdx++;
69 }
70 }
71
72 // Allocate per-vertex triangle lists, and calculate the starting score of
73 // each of the verts
74 for(S32 v = 0; v < numVerts; v++)
75 {
76 VertData &curVert = vertexData[v];
77 curVert.triIndex = new S32[curVert.numUnaddedReferences];
78 curVert.score = FindVertexScore::score(curVert);
79 }
80
81 // These variables will be used later, but need to be declared now
82 S32 nextNextBestTriIdx = -1, nextBestTriIdx = -1;
83 F32 nextNextBestTriScore = -1.0f, nextBestTriScore = -1.0f;
84
85#define _VALIDATE_TRI_IDX(idx) if(idx > -1) { AssertFatal(idx < NumPrimitives, "Out of range triangle index."); AssertFatal(!triangleData[idx].isInList, "Triangle already in list, bad."); }
86#define _CHECK_NEXT_NEXT_BEST(score, idx) { if(score > nextNextBestTriScore) { nextNextBestTriIdx = idx; nextNextBestTriScore = score; } }
87#define _CHECK_NEXT_BEST(score, idx) { if(score > nextBestTriScore) { _CHECK_NEXT_NEXT_BEST(nextBestTriScore, nextBestTriIdx); nextBestTriIdx = idx; nextBestTriScore = score; } _VALIDATE_TRI_IDX(nextBestTriIdx); }
88

Callers 1

disassembleMethod · 0.85

Calls 8

dCopyArrayFunction · 0.85
mFloorFunction · 0.85
scoreFunction · 0.85
useVertexMethod · 0.80
enforceSizeMethod · 0.80
U32Enum · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected