Calculates radiosity and sets lightmaps for indoor faces only
| 1150 | |
| 1151 | // Calculates radiosity and sets lightmaps for indoor faces only |
| 1152 | void DoRadiosityForCurrentRoom(room *rp) { |
| 1153 | int t; |
| 1154 | int facecount = 0; |
| 1155 | int surface_index = 0; |
| 1156 | int max_index; |
| 1157 | |
| 1158 | if (!CheckForBadFaces(rp - Rooms)) { |
| 1159 | OutrageMessageBox("You have bad faces in your level. Please do a Verify Level."); |
| 1160 | return; |
| 1161 | } |
| 1162 | |
| 1163 | mprintf(0, "Setting up...\n"); |
| 1164 | |
| 1165 | ASSERT(rp != NULL); |
| 1166 | ASSERT(rp->used); |
| 1167 | |
| 1168 | if (rp->flags & RF_EXTERNAL) { |
| 1169 | OutrageMessageBox("You cannot run single room radiosity on external rooms!"); |
| 1170 | return; |
| 1171 | } |
| 1172 | |
| 1173 | if (rp->flags & RF_NO_LIGHT) { |
| 1174 | OutrageMessageBox("You cannot run single room radiosity on a room marked not to light!"); |
| 1175 | return; |
| 1176 | } |
| 1177 | |
| 1178 | // Build bsp tree |
| 1179 | BuildSingleBSPTree(rp - Rooms); |
| 1180 | |
| 1181 | ClearRoomLightmaps(rp - Rooms); |
| 1182 | for (t = 0; t <= Highest_object_index; t++) { |
| 1183 | if (Objects[t].type != OBJ_NONE && (Objects[t].roomnum == rp - Rooms)) |
| 1184 | ClearObjectLightmaps(&Objects[t]); |
| 1185 | } |
| 1186 | |
| 1187 | // Build lightmap uvs |
| 1188 | for (t = 0; t < rp->num_faces; t++) { |
| 1189 | vector verts[MAX_VERTS_PER_FACE * 5]; |
| 1190 | int room_list[2], face_list[2]; |
| 1191 | for (int k = 0; k < rp->faces[t].num_verts; k++) |
| 1192 | verts[k] = rp->verts[rp->faces[t].face_verts[k]]; |
| 1193 | |
| 1194 | room_list[0] = rp - Rooms; |
| 1195 | face_list[0] = t; |
| 1196 | |
| 1197 | BuildLightmapUVs(room_list, face_list, 1, verts, rp->faces[t].num_verts, 0); |
| 1198 | } |
| 1199 | |
| 1200 | // First count how many faces we'll need |
| 1201 | facecount += rp->num_faces; |
| 1202 | |
| 1203 | // Do objects |
| 1204 | facecount += GetTotalObjectFacesForSingleRoom(rp - Rooms); |
| 1205 | |
| 1206 | // Allocate enough memory to hold all surfaces |
| 1207 | |
| 1208 | Light_surfaces = (rad_surface *)mem_malloc(facecount * sizeof(rad_surface)); |
| 1209 | ASSERT(Light_surfaces != NULL); |
no test coverage detected