Debian Codegraph @

editor/edoors.cpp

raw
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // Edoors.cpp
20
21 #ifndef NEWEDITOR
22 #include "d3edit.h"
23 #else
24 #include "globals.h"
25 #define texdlg_texture GetCurrentTexture()
26 #endif
27
28 #include "polymodel.h"
29 #include "erooms.h"
30 #include "room.h"
31 #include "door.h"
32 #include "hroom.h"
33
34 #include "pserror.h"
35
36 void PlaceDoor(room *baseroomp, int baseface, int placed_door) {
37 poly_model *po = GetPolymodelPointer(GetDoorImage(placed_door));
38 int i, t;
39 int num_faces = 0, num_verts = 0;
40 int got_shell = 0, got_front = 0;
41 bsp_info *front_sm, *shell_sm;
42 room *rp;
43 int front_face_index;
44 int front_remap_points[30];
45
46 for (i = 0; i < po->n_models; i++) {
47 bsp_info *sm = &po->submodel[i];
48 if (sm->flags & SOF_SHELL) {
49 got_shell = 1;
50 num_verts += sm->nverts;
51 num_faces += sm->num_faces;
52 shell_sm = &po->submodel[i];
53 }
54 if (sm->flags & SOF_FRONTFACE) {
55 got_front = 1;
56 num_verts += sm->nverts;
57 num_faces++;
58 front_sm = &po->submodel[i];
59 }
60 }
61
62 if (!got_shell || !got_front) {
63 Int3(); // This door is improperly specified in 3dsmax
64 return;
65 }
66
67 rp = CreateNewRoom(num_verts, num_faces, 1);
68
69 ASSERT(rp != NULL);
70
71 // Create the actual room walls
72 int index = 0;
73 for (i = 0; i < shell_sm->nverts; i++, index++) {
74 rp->verts[index] = shell_sm->verts[i];
75 }
76 for (i = 0; i < front_sm->nverts; i++, index++) {
77 rp->verts[index] = front_sm->verts[i];
78 }
79
80 index = 0;
81
82 for (i = 0; i < shell_sm->num_faces; i++, index++) {
83 InitRoomFace(&rp->faces[index], shell_sm->faces[i].nverts);
84
85 ASSERT(rp->faces[index].face_verts);
86 ASSERT(rp->faces[index].face_uvls);
87
88 rp->faces[index].tmap = D3EditState.texdlg_texture;
89
90 for (t = 0; t < rp->faces[index].num_verts; t++)
91 rp->faces[index].face_verts[t] = shell_sm->faces[i].vertnums[t];
92 }
93
94 ASSERT(front_sm->num_faces == 1);
95
96 front_face_index = index;
97 InitRoomFace(&rp->faces[index], front_sm->faces[0].nverts);
98 rp->faces[index].tmap = D3EditState.texdlg_texture;
99
100 // Now find the points on the front face that are the same as the shell
101 for (i = 0; i < front_sm->nverts; i++)
102 front_remap_points[i] = -1;
103
104 vector diff_vec = front_sm->offset - shell_sm->offset;
105
106 for (i = 0; i < shell_sm->nverts; i++)
107 for (t = 0; t < front_sm->nverts; t++) {
108 vector testvec = front_sm->verts[t] + diff_vec;
109
110 if ((PointsAreSame(&shell_sm->verts[i], &testvec)))
111 front_remap_points[t] = i;
112 }
113
114 for (i = 0; i < front_sm->nverts; i++)
115 ASSERT(front_remap_points[i] != -1);
116
117 for (t = 0; t < rp->faces[index].num_verts; t++)
118 rp->faces[index].face_verts[t] = front_remap_points[front_sm->faces[0].vertnums[t]];
119
120 // Reset some values
121
122 if (!ResetRoomFaceNormals(rp))
123 Int3(); // Get Matt
124
125 AssignDefaultUVsToRoom(rp);
126
127 // Now use to the attach room code to actually place this door's room
128 PlaceRoom(baseroomp, baseface, rp - Rooms, front_face_index, placed_door);
129 }