Computes the the mines UVs Faces can now share one lightmap, so this routine goes through and tries to combine as many faces as it can into one lightmap
| 946 | // Faces can now share one lightmap, so this routine goes through and tries to |
| 947 | // combine as many faces as it can into one lightmap |
| 948 | void CombineObjectLightmapUVs(object *obj, int lmi_type) { |
| 949 | int i, t, k; |
| 950 | int not_combined = 0; |
| 951 | |
| 952 | poly_model *pm = &Poly_models[obj->rtype.pobj_info.model_num]; |
| 953 | ASSERT(obj->lm_object.used); |
| 954 | |
| 955 | for (i = 0; i < pm->n_models; i++) { |
| 956 | bsp_info *sm = &pm->submodel[i]; |
| 957 | |
| 958 | if (IsNonRenderableSubmodel(pm, i)) |
| 959 | continue; |
| 960 | |
| 961 | ObjectsAlreadyCombined[i] = (uint8_t *)mem_malloc(sm->num_faces); |
| 962 | ASSERT(ObjectsAlreadyCombined[i]); |
| 963 | for (k = 0; k < sm->num_faces; k++) |
| 964 | ObjectsAlreadyCombined[i][k] = 0; |
| 965 | } |
| 966 | |
| 967 | for (i = 0; i < pm->n_models; i++) { |
| 968 | bsp_info *sm = &pm->submodel[i]; |
| 969 | |
| 970 | if (IsNonRenderableSubmodel(pm, i)) |
| 971 | continue; |
| 972 | |
| 973 | for (t = 0; t < sm->num_faces; t++) { |
| 974 | if (*(ObjectsAlreadyCombined[i] + t) == 0) |
| 975 | TestObjectLightAdjacency(obj, i, t, lmi_type); |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | // Now build lightmaps for any faces that couldn't be combined |
| 980 | for (i = 0; i < pm->n_models; i++) { |
| 981 | bsp_info *sm = &pm->submodel[i]; |
| 982 | |
| 983 | if (IsNonRenderableSubmodel(pm, i)) |
| 984 | continue; |
| 985 | |
| 986 | for (t = 0; t < sm->num_faces; t++) { |
| 987 | if (!ObjectsAlreadyCombined[i][t]) { |
| 988 | vector verts[MAX_VERTS_PER_FACE * 5]; |
| 989 | int submodel_list[2], face_list[2]; |
| 990 | for (k = 0; k < sm->faces[t].nverts; k++) { |
| 991 | GetObjectPointInWorld(&verts[k], obj, i, sm->faces[t].vertnums[k]); |
| 992 | } |
| 993 | |
| 994 | submodel_list[0] = i; |
| 995 | face_list[0] = t; |
| 996 | BuildObjectLightmapUVs(obj, submodel_list, face_list, 1, verts, sm->faces[t].nverts, lmi_type); |
| 997 | not_combined++; |
| 998 | } |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | mprintf(0, "%d %s faces couldn't be combined!\n", not_combined, pm->name); |
| 1003 | |
| 1004 | // Free memory |
| 1005 | for (i = 0; i < pm->n_models; i++) { |
no test coverage detected