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

Function BuildObjectLightmapUVs

editor/editor_object_lighting.cpp:491–722  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

489}
490
491void BuildObjectLightmapUVs(object *obj, int *sublist, int *facelist, int count, vector *lightmap_poly, int nv,
492 int lm_type) {
493 matrix face_matrix, trans_matrix;
494 vector fvec;
495 vector avg_vert;
496 vector verts[MAX_VERTS_PER_FACE * 5];
497 vector facevert;
498 vector rot_vert;
499 int i, t;
500 int lmi_handle;
501 vector world_verts[32];
502
503 poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num];
504
505 for (i = 0; i < pm->submodel[sublist[0]].faces[facelist[0]].nverts; i++)
506 GetObjectPointInWorld(&world_verts[i], obj, sublist[0], pm->submodel[sublist[0]].faces[facelist[0]].vertnums[i]);
507
508 // find the center point of this face
509 vm_MakeZero(&avg_vert);
510 for (i = 0; i < nv; i++)
511 avg_vert += lightmap_poly[i];
512
513 avg_vert /= nv;
514
515 // Make the orientation matrix
516 // Reverse the normal because we're looking "at" the face, not from it
517
518 vm_GetNormal(&fvec, &world_verts[0], &world_verts[1], &world_verts[2]);
519 fvec = -fvec;
520
521 if ((vm_NormalizeVector(&fvec)) != 0)
522 vm_VectorToMatrix(&face_matrix, &fvec, NULL, NULL);
523 else
524 vm_MakeIdentity(&face_matrix);
525 // Make the transformation matrix
526
527 angvec avec;
528 vm_ExtractAnglesFromMatrix(&avec, &face_matrix);
529 vm_AnglesToMatrix(&trans_matrix, avec.p, avec.h, avec.b);
530
531 // Rotate all the points
532 for (i = 0; i < nv; i++) {
533 vector vert = lightmap_poly[i];
534
535 vert -= avg_vert;
536 vm_MatrixMulVector(&rot_vert, &vert, &trans_matrix);
537
538 verts[i] = rot_vert;
539 }
540
541 // Find left most point
542 int leftmost_point = -1;
543 float leftmost_x = 900000.00f; // a big number
544
545 for (i = 0; i < nv; i++) {
546 if (verts[i].x < leftmost_x) {
547 leftmost_point = i;
548 leftmost_x = verts[i].x;

Callers 2

TestObjectLightAdjacencyFunction · 0.85
CombineObjectLightmapUVsFunction · 0.85

Calls 11

GetObjectPointInWorldFunction · 0.85
vm_MakeZeroFunction · 0.85
vm_NormalizeVectorFunction · 0.85
AllocLightmapInfoFunction · 0.85
vm_GetNormalFunction · 0.50
vm_VectorToMatrixFunction · 0.50
vm_MakeIdentityFunction · 0.50
vm_AnglesToMatrixFunction · 0.50
vm_MatrixMulVectorFunction · 0.50
vm_TransposeMatrixFunction · 0.50

Tested by 1

TestObjectLightAdjacencyFunction · 0.68