MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / FixConcaveFaces

Function FixConcaveFaces

editor/Erooms.cpp:1220–1334  ·  view source on GitHub ↗

Fixes all the concave/nonplanar faces of facelist of room rp

Source from the content-addressed store, hash-verified

1218
1219// Fixes all the concave/nonplanar faces of facelist of room rp
1220void FixConcaveFaces(room *rp, int *facelist, int facecount) {
1221 int i, t, k;
1222 face *newfaces;
1223
1224 for (i = 0; i < facecount; i++) {
1225 // If this face is concave, build a triangle strip out of the concave face
1226 if (!FaceIsPlanar(rp, facelist[i])) {
1227 int concave_verts[MAX_VERTS_PER_FACE];
1228
1229 int old_num_faces = rp->num_faces;
1230 int concave_count = rp->faces[facelist[i]].num_verts;
1231 int old_tmap = rp->faces[facelist[i]].tmap;
1232 int num_new_faces = concave_count - 3;
1233 ASSERT(num_new_faces > 0);
1234
1235 mprintf(0, "Creating %d new faces from face %d!\n", num_new_faces, facelist[i]);
1236
1237 // copy the concave vert indices for later use
1238 for (t = 0; t < concave_count; t++)
1239 concave_verts[t] = rp->faces[facelist[i]].face_verts[t];
1240
1241 // Allocate memory for our new faces
1242 int nfaces = rp->num_faces + num_new_faces;
1243
1244 newfaces = (face *)mem_malloc(nfaces * sizeof(face));
1245 ASSERT(newfaces != NULL);
1246
1247 // Copy all the faces into our new array
1248 for (t = 0; t < rp->num_faces; t++) {
1249
1250 if (t != facelist[i]) {
1251 int nverts = rp->faces[t].num_verts;
1252
1253 newfaces[t].face_verts = (int16_t *)mem_malloc(nverts * sizeof(int16_t));
1254 ASSERT(newfaces[t].face_verts != NULL);
1255 newfaces[t].face_uvls = (roomUVL *)mem_malloc(nverts * sizeof(roomUVL));
1256 ASSERT(newfaces[t].face_uvls != NULL);
1257
1258 newfaces[t].normal = rp->faces[t].normal;
1259 newfaces[t].tmap = rp->faces[t].tmap;
1260 newfaces[t].flags = rp->faces[t].flags;
1261 newfaces[t].portal_num = rp->faces[t].portal_num;
1262 newfaces[t].num_verts = rp->faces[t].num_verts;
1263 newfaces[t].special_handle = BAD_SPECIAL_FACE_INDEX;
1264
1265 for (k = 0; k < nverts; k++) {
1266 newfaces[t].face_verts[k] = rp->faces[t].face_verts[k];
1267 newfaces[t].face_uvls[k] = rp->faces[t].face_uvls[k];
1268 }
1269 } else // special case the concave face into a triangle
1270 {
1271 int nverts = 3;
1272
1273 newfaces[t].face_verts = (int16_t *)mem_malloc(nverts * sizeof(int16_t));
1274 ASSERT(newfaces[t].face_verts != NULL);
1275 newfaces[t].face_uvls = (roomUVL *)mem_malloc(nverts * sizeof(roomUVL));
1276 ASSERT(newfaces[t].face_uvls != NULL);
1277

Callers 4

SizeFaceVerticesFunction · 0.85
SizeFaceEdgeFunction · 0.85
MoveRoomFaceFunction · 0.85
RotateRoomsFunction · 0.85

Calls 5

ComputeFaceNormalFunction · 0.85
InitRoomFaceFunction · 0.85
ResetRoomFaceNormalsFunction · 0.85
FaceIsPlanarFunction · 0.70

Tested by

no test coverage detected