Incorporates the geometry from the specified object into the specified room. Deletes the object. Returns true if worked, false if some error
| 3087 | // Incorporates the geometry from the specified object into the specified room. Deletes the object. |
| 3088 | // Returns true if worked, false if some error |
| 3089 | bool MergeObjectIntoRoom(room *rp, int objnum) { |
| 3090 | object *objp = &Objects[objnum]; |
| 3091 | ASSERT(objp->render_type == RT_POLYOBJ); |
| 3092 | |
| 3093 | poly_model *pm = GetPolymodelPointer(objp->rtype.pobj_info.model_num); |
| 3094 | |
| 3095 | if (pm->n_models > 1) { |
| 3096 | #ifndef NEWEDITOR |
| 3097 | OutrageMessageBox("Cannot merge: Only supported for objects with one submodel.\n\nIf you really need this " |
| 3098 | "functions for objects with multiple submodles, talk to MattT."); |
| 3099 | #else |
| 3100 | OutrageMessageBox("Cannot merge: Only supported for objects with one submodel."); |
| 3101 | #endif |
| 3102 | return 0; |
| 3103 | } |
| 3104 | if (!pm->n_ground) { |
| 3105 | OutrageMessageBox("Cannot merge: The object must have a ground plane to merge."); |
| 3106 | return 0; |
| 3107 | } |
| 3108 | if (OBJECT_OUTSIDE(objp)) { |
| 3109 | OutrageMessageBox("Cannot merge: The object is outside."); |
| 3110 | return 0; |
| 3111 | } |
| 3112 | if (objp->roomnum != ROOMNUM(rp)) { |
| 3113 | OutrageMessageBox("Cannot merge: The object is not in the specified room."); |
| 3114 | return 0; |
| 3115 | } |
| 3116 | |
| 3117 | // Get points to model data |
| 3118 | bsp_info *sm = &pm->submodel[0]; |
| 3119 | |
| 3120 | // Add verts to room |
| 3121 | int first_new_vert = RoomAddVertices(rp, sm->nverts); |
| 3122 | |
| 3123 | // Rotate the points and copy them to the room |
| 3124 | matrix rotmat = ~objp->orient; |
| 3125 | for (int i = 0; i < sm->nverts; i++) { |
| 3126 | rp->verts[first_new_vert + i] = objp->pos + sm->verts[i] * rotmat; |
| 3127 | } |
| 3128 | |
| 3129 | // Add faces to the room |
| 3130 | int first_new_face = RoomAddFaces(rp, sm->num_faces); |
| 3131 | |
| 3132 | // Copy the faces |
| 3133 | for (i = 0; i < sm->num_faces; i++) { |
| 3134 | polyface *pfp = &sm->faces[i]; |
| 3135 | face *fp = &rp->faces[first_new_face + i]; |
| 3136 | |
| 3137 | InitRoomFace(fp, pfp->nverts); |
| 3138 | |
| 3139 | for (int v = 0; v < fp->num_verts; v++) { |
| 3140 | fp->face_verts[v] = first_new_vert + pfp->vertnums[v]; |
| 3141 | fp->face_uvls[v].u = pfp->u[v]; |
| 3142 | fp->face_uvls[v].v = pfp->v[v]; |
| 3143 | } |
| 3144 | |
| 3145 | #ifndef NEWEDITOR |
| 3146 | fp->tmap = pm->textures[pfp->texnum]; |
no test coverage detected