forked from scp-fs2open/PCS2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SOBJ_editor.h
319 lines (265 loc) · 9 KB
/
SOBJ_editor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#pragma once
#include <unordered_set>
#include <wx/event.h>
#include"model_editor_ctrl.h"
#include"array_ctrl.h"
#include"primitive_ctrl.h"
#include"pcs_file.h"
//editor for a subobject
class sobj_ctrl :
public editor<pcs_sobj>
{
pcs_sobj data;
protected:
//controls
string_ctrl*name;
primitive_radio_button_ctrl<int>*movement_axis;
multi_string_ctrl*properties;
vector_ctrl*offset;
default_value_vector_ctrl*bbox_min;
default_value_vector_ctrl*bbox_max;
default_value_float_ctrl*max_rad;
public:
sobj_ctrl(wxWindow*parent, wxString Title, int orient = wxVERTICAL)
:editor<pcs_sobj>(parent, orient, Title)
{
std::vector<primitive_list_item<int> > list;
//add controls
add_control(name=new string_ctrl(this,_("Name")),0,wxEXPAND );
list.resize(4);
list[0].title = "None";
list[0].data = ANONE;
list[1].title = "X Axis";
list[1].data = MV_X;
list[2].title = "Y Axis";
list[2].data = MV_Y;
list[3].title = "Z Axis";
list[3].data = MV_Z;
add_control(movement_axis=new primitive_radio_button_ctrl<int>(this, list,_("Rotation Axis")),0,wxEXPAND );
add_control(offset=new vector_ctrl(this,_("Offset")),0,wxEXPAND );
add_control(bbox_min=new default_value_vector_ctrl(this,_("Bounding Box Min")),0,wxEXPAND );
add_control(bbox_max=new default_value_vector_ctrl(this,_("Bounding Box Max")),0,wxEXPAND );
add_control(max_rad = new default_value_float_ctrl(this,_("Max Radius")), 0, wxEXPAND);
std::vector<std::string> op;
op.push_back("$special=subsystem\n");
op.push_back("$special=no_rotate\n");
op.push_back("$name=x\n");
op.push_back("$lod0_name=x\n");
op.push_back("");
op.push_back("$fov=180\n");
op.push_back("");
op.push_back("$rotate=x\n");
op.push_back("$dumb_rotate:x\n");
op.push_back("$pbank=0\n");
op.push_back("");
op.push_back("$detail_box:1\n");
op.push_back("$box_min: x,x,x\n");
op.push_back("$box_max: x,x,x\n");
op.push_back("");
op.push_back("$triggered:\n");
op.push_back("");
op.push_back("$stepped\n");
op.push_back("$steps=4\n");
op.push_back("$t_paused=2\n");
op.push_back("$t_transit=6\n");
op.push_back("$fraction_accel=x\n");
op.push_back("");
op.push_back("$gun_rotation:\n");
op.push_back("");
op.push_back("$uvec:0,1,0\n");
op.push_back("$fvec:0,0,1\n");
op.push_back("");
op.push_back("$no_collisions\n");
op.push_back("$nocollide_this_only\n");
op.push_back("$collide_invisible\n");
add_control(properties=new suggest_ctrl<std::string, multi_string_ctrl>(this,_("Properties"),op, SUGGEST_APPEND),1,wxEXPAND );
};
virtual ~sobj_ctrl(void){};
//set the control's value
void set_value(const pcs_sobj&t){
data=t;
name->set_value(t.name);
movement_axis->set_value(t.movement_axis);
if (t.movement_type == MNONE) {
movement_axis->set_value(ANONE);
}
offset->set_value(t.offset);
bbox_min->set_value_with_default(
data.bounding_box_min_point_overridden ?
data.bounding_box_min_point_override :
data.bounding_box_min_point, data.bounding_box_min_point);
bbox_max->set_value_with_default(
data.bounding_box_max_point_overridden ?
data.bounding_box_max_point_override :
data.bounding_box_max_point, data.bounding_box_max_point);
max_rad->set_value_with_default(
data.radius_overridden ?
data.radius_override :
data.radius, data.radius);
properties->set_value(t.properties);
}
//return's the control's value
pcs_sobj get_value(){
data.name = name->get_value();
data.movement_axis = movement_axis->get_value();
data.movement_type = data.movement_axis == ANONE ? MNONE : ROTATE;
data.offset = offset->get_value();
data.bounding_box_min_point_override = bbox_min->get_value();
data.bounding_box_max_point_override = bbox_max->get_value();
data.bounding_box_min_point = bbox_min->get_default_value();
data.bounding_box_max_point = bbox_max->get_default_value();
data.bounding_box_min_point_overridden = bbox_min->is_overridden();
data.bounding_box_max_point_overridden = bbox_max->is_overridden();
data.radius_override = max_rad->get_value();
data.radius = max_rad->get_default_value();
data.radius_overridden = max_rad->is_overridden();
data.properties = properties->get_value();
return data;
}
void set_pos(vector3d p){
offset->set_value(data.offset = p);
}
virtual void transform(const matrix& transform, const vector3d& translation, int sobj_num) {
pcs_sobj sobj = get_value();
sobj.Transform(get_main_window()->get_model(), sobj_num, transform, translation, false, false);
}
};
class SOBJ_ctrl
:public editor_ctrl<pcs_sobj>
{
sobj_ctrl*sobj;
wxCheckBox*bsp_render_box;
string_disp*sobj_info;
int sobj_num;
wxBitmapButton*cpy_btn;
wxBitmapButton*del_btn;
public:
static color selected_item;
SOBJ_ctrl(wxWindow*parent,int Sobj_num)
:editor_ctrl<pcs_sobj>(parent, _("Subobject")),sobj_num(Sobj_num)
{
//add controls
wxBoxSizer*b=new wxBoxSizer(wxHORIZONTAL);
b->Add(cpy_btn = new wxBitmapButton(this, SOBJ_BUTTON_CPY, wxBitmap(copy_btn),wxDefaultPosition,wxDefaultSize, wxBORDER_NONE));
b->Add(del_btn = new wxBitmapButton(this, SOBJ_BUTTON_DEL, wxBitmap(delete_btn),wxDefaultPosition,wxDefaultSize, wxBORDER_NONE));
add_sizer(b);
cpy_btn->SetToolTip(_("Copy"));
del_btn->SetToolTip(_("Delete"));
add_control(sobj=new sobj_ctrl(this, _("")),0,wxEXPAND );
add_control(bsp_render_box=new wxCheckBox(this, BSP_DRAW, _("Draw BSP Debug Info")));
bsp_render_box->Disable();
add_control(sobj_info = new string_disp(this,_("Subobject Info")),0,wxEXPAND );
}
//do nothing, needed so the base destructor will get called
virtual~SOBJ_ctrl(){}
//set's the control's value
void set_value(const pcs_sobj&t){
data=t;
sobj->set_value(t);
}
//return's the control's value
pcs_sobj get_value(){
data = sobj->get_value();
return data;
}
//populates the control with data from the model
void set_data(PCS_Model &model){
if(sobj_num >=0 && sobj_num<model.GetSOBJCount()){
set_value(model.SOBJ(sobj_num));
if(model.get_bsp_cache_status())
bsp_render_box->Enable();
else
bsp_render_box->Disable();
bsp_render_box->SetValue(model.draw_bsp);
update_info(model);
}
}
void update_info(PCS_Model& model) {
vector3d& min_box = data.bounding_box_min_point_overridden ? data.bounding_box_min_point_override : data.bounding_box_min_point;
vector3d& max_box = data.bounding_box_max_point_overridden ? data.bounding_box_max_point_override : data.bounding_box_max_point;
vector3d size = max_box - min_box;
wxString info(wxString::Format(_("Poly Count: %i\nChild Poly Count: %i\nTotal: %i\n"),
data.polygons.size(),
model.get_child_subobj_poly_count(sobj_num),
data.polygons.size() + model.get_child_subobj_poly_count(sobj_num)));
info += wxString::Format(_("Vertices: %i\n"), count_vertices());
info += wxString::Format(_("Normals: %i\n"), count_normals());
info += wxString::Format(_("H: %0.2f, W: %0.2f, D: %0.2f\nParent submodel: "),
fabs(size.y), fabs(size.x), fabs(size.z));
if (data.parent_sobj > -1) {
info += wxString(model.SOBJ(data.parent_sobj).name.c_str(), wxConvUTF8);
} else {
info += _("*NONE*");
}
sobj_info->set_value(std::string(info.mb_str()));
}
//applies the data in the control to the model
void apply_data(PCS_Model &model){
if(sobj_num >=0 && sobj_num<model.GetSOBJCount()) {
model.SOBJ(sobj_num)=get_value();
update_info(model);
}
}
void set_item(const std::vector<int>&coord){
if(coord[0] >-1)
sobj_num = coord[0];
}
std::vector<int> get_item(){
std::vector<int> ret;
ret.resize(1);
ret[0] = sobj_num;
return ret;
};
omnipoints get_omnipoints(){
omnipoints o;
o.point.resize(1);
o.point[0].resize(1);
o.point[0][0].pos = get_value().offset;
return o;
}
void set_omnipoints(const omnipoints&points){
if(points.point.size() == 1 && points.point[0].size() == 1){
sobj->set_pos(points.point[0][0].pos);
wxCommandEvent event(SUBOBJECT_UPDATE, GetId());
GetEventHandler()->ProcessEvent(event);
}
}
void get_omnipoint_coords(int&list, int&item){
list = 0;
item = 0;
}
void set_omnipoint_coords(int&list, int&item){
}
DECLARE_EVENT_TABLE();
void on_BSP_render_change(wxCommandEvent& event){
wxCommandEvent e(BSP_RENDER_CHANGE, GetId());
e.SetInt((event.IsChecked())?1:0);
GetEventHandler()->ProcessEvent(e);
}
wxSizer* get_transform_options(wxWindow* parent) {
return NULL;
}
virtual void transform(const matrix& transform, const vector3d& translation) {
sobj->transform(transform, translation, sobj_num);
set_data(get_main_window()->get_model());
}
private:
size_t count_vertices() {
std::unordered_set<vector3d> points;
for (size_t i = 0; i < data.polygons.size(); i++) {
for (size_t j = 0; j < data.polygons[i].verts.size(); j++) {
points.insert(data.polygons[i].verts[j].point);
}
}
return points.size();
}
size_t count_normals() {
std::unordered_set<vector3d> vertices;
for (size_t i = 0; i < data.polygons.size(); i++) {
for (size_t j = 0; j < data.polygons[i].verts.size(); j++) {
vertices.insert(data.polygons[i].verts[j].norm);
}
}
return vertices.size();
}
};