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

Function CopySqueezeDataForObject

editor/editor_lighting.cpp:233–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233void CopySqueezeDataForObject(object *obj, int subnum, int facenum, uint16_t *dest_data, int dest_x, int dest_y) {
234 lightmap_object_face *fp = &obj->lm_object.lightmap_faces[subnum][facenum];
235 lightmap_info *lmi_ptr = &LightmapInfo[fp->lmi_handle];
236 uint16_t *src_data = (uint16_t *)lm_data(lmi_ptr->lm_handle);
237 int t, k;
238
239 int w = lmi_ptr->width;
240 int h = lmi_ptr->height;
241
242 // Copy over the actual lightmap data
243 CopySqueezeBodyAndEdges(dest_data, src_data, w, h, dest_x, dest_y);
244
245 // Now alter all face uvs that have this lightmap info
246 float dest_u = (float)(dest_x + 1) / 128.0;
247 float dest_v = (float)(dest_y + 1) / 128.0;
248
249 float u_scalar = (float)w / 128.0;
250 float v_scalar = (float)h / 128.0;
251
252 for (int objnum = obj - Objects; objnum != -1; objnum = Objects[objnum].next) {
253 object *this_obj = &Objects[objnum];
254
255 if (this_obj->lighting_render_type != LRT_LIGHTMAPS)
256 continue;
257 if (!this_obj->lm_object.used)
258 continue;
259
260 for (t = 0; t < this_obj->lm_object.num_models; t++) {
261 if (IsNonRenderableSubmodel(&Poly_models[this_obj->rtype.pobj_info.model_num], t))
262 continue;
263
264 for (k = 0; k < this_obj->lm_object.num_faces[t]; k++) {
265 lightmap_object_face *this_fp = &this_obj->lm_object.lightmap_faces[t][k];
266 int lmi_handle = this_fp->lmi_handle;
267 if (lmi_handle == BAD_LMI_INDEX)
268 continue;
269 if (Lmi_spoken_for[lmi_handle])
270 continue;
271
272 if (lmi_handle == fp->lmi_handle) {
273 lmi_ptr->x1 = dest_x + 1;
274 lmi_ptr->y1 = dest_y + 1;
275
276 // We have to alter our uvs for this face to reflect our change
277 for (int j = 0; j < this_fp->num_verts; j++) {
278 this_fp->u2[j] *= u_scalar;
279 this_fp->u2[j] += dest_u;
280
281 this_fp->v2[j] *= v_scalar;
282 this_fp->v2[j] += dest_v;
283 }
284 }
285 }
286 }
287 }
288
289 ASSERT(fp->lmi_handle != BAD_LMI_INDEX);
290 Lmi_spoken_for[fp->lmi_handle] = 1;

Callers 1

SqueezeLightmapsFunction · 0.85

Calls 4

lm_dataFunction · 0.85
CopySqueezeBodyAndEdgesFunction · 0.85
IsNonRenderableSubmodelFunction · 0.85
lm_FreeLightmapFunction · 0.85

Tested by

no test coverage detected