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

Function BuildLightmapUVs

editor/editor_lighting.cpp:2385–2610  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2383}*/
2384
2385void BuildLightmapUVs(int *room_list, int *face_list, int count, vector *lightmap_poly, int nv, int external) {
2386 matrix face_matrix, trans_matrix;
2387 vector fvec;
2388 vector avg_vert;
2389 vector verts[MAX_VERTS_PER_FACE * 5];
2390 vector facevert;
2391 vector rot_vert;
2392 int i, t;
2393 int lmi_handle;
2394
2395 // find the center point of this face
2396 vm_MakeZero(&avg_vert);
2397 for (i = 0; i < nv; i++)
2398 avg_vert += lightmap_poly[i];
2399
2400 avg_vert /= nv;
2401
2402 // Make the orientation matrix
2403 // Reverse the normal because we're looking "at" the face, not from it
2404 fvec = -Rooms[room_list[0]].faces[face_list[0]].normal;
2405
2406 vm_VectorToMatrix(&face_matrix, &fvec, NULL, NULL);
2407 // Make the transformation matrix
2408
2409 angvec avec;
2410 vm_ExtractAnglesFromMatrix(&avec, &face_matrix);
2411 vm_AnglesToMatrix(&trans_matrix, avec.p, avec.h, avec.b);
2412
2413 // Rotate all the points
2414 for (i = 0; i < nv; i++) {
2415 vector vert = lightmap_poly[i];
2416
2417 vert -= avg_vert;
2418 vm_MatrixMulVector(&rot_vert, &vert, &trans_matrix);
2419
2420 verts[i] = rot_vert;
2421 }
2422
2423 // Find left most point
2424 int leftmost_point = -1;
2425 float leftmost_x = 900000.00f; // a big number
2426
2427 for (i = 0; i < nv; i++) {
2428 if (verts[i].x < leftmost_x) {
2429 leftmost_point = i;
2430 leftmost_x = verts[i].x;
2431 }
2432 }
2433
2434 ASSERT(leftmost_point != -1);
2435
2436 // Find top most point
2437 int topmost_point = -1;
2438 float topmost_y = -900000.0f; // a big number
2439
2440 for (i = 0; i < nv; i++) {
2441 if (verts[i].y > topmost_y) {
2442 topmost_point = i;

Callers 3

TestLightAdjacencyFunction · 0.85

Calls 7

vm_MakeZeroFunction · 0.85
AllocLightmapInfoFunction · 0.85
vm_VectorToMatrixFunction · 0.50
vm_AnglesToMatrixFunction · 0.50
vm_MatrixMulVectorFunction · 0.50
vm_TransposeMatrixFunction · 0.50

Tested by 1

TestLightAdjacencyFunction · 0.68