forked from emilk/sproxel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tools.h
288 lines (232 loc) · 7.44 KB
/
Tools.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
#ifndef __TOOLS_H__
#define __TOOLS_H__
#include "Global.h"
#include "UndoManager.h"
#include <ImathVec.h>
#include <ImathColor.h>
////////////////////////////////////////////////////////////////////////////////
// Abstract base class for Sproxel tools and their execution states
////////////////////////////////////////////////////////////////////////////////
class ToolState
{
public:
ToolState(UndoManager* um) : m_clicksRemain(0),
p_undoManager(um),
m_ray(Imath::Line3d()),
m_color(Imath::Color4f(0.0f, 0.0f, 0.0f, 0.0f)),
m_index(0),
p_gvg(NULL),
m_supportsDrag(false) {}
virtual ~ToolState() {}
virtual void execute() = 0;
virtual SproxelTool type() = 0;
virtual std::vector<Imath::V3i> voxelsAffected() = 0;
virtual void executeErase() {}
const Imath::Line3d& ray() const { return m_ray; }
void set(VoxelGridGroupPtr gvg, const Imath::Box3i &edit_bounds,
const Imath::Line3d& ray, const Imath::Color4f& color, int index)
{
p_gvg = gvg;
m_editBounds=edit_bounds;
m_ray = ray;
m_color = color;
m_index = index;
}
int clicksRemaining() { return m_clicksRemain; }
void decrementClicks()
{
m_clicksRemain--;
if (m_clicksRemain == 0)
m_clicksRemain = m_totalClicks;
}
virtual void setDragSupport(bool support) { m_supportsDrag = support; }
virtual bool supportsDrag() { return m_supportsDrag; }
protected:
int m_totalClicks;
int m_clicksRemain;
UndoManager* p_undoManager;
Imath::Line3d m_ray;
Imath::Box3i m_editBounds;
Imath::Color4f m_color;
int m_index;
VoxelGridGroupPtr p_gvg;
bool m_supportsDrag;
std::vector<Imath::V3i> rayIntersection(const Imath::Line3d &worldRay)
{
Imath::Line3d localRay = worldRay * p_gvg->transform().inverse();
return walk_ray(localRay, m_editBounds);
}
};
////////////////////////////////////////////////////////////////////////////////
// Splat tool
////////////////////////////////////////////////////////////////////////////////
class SplatToolState : public ToolState
{
public:
SplatToolState(UndoManager* um) : ToolState(um)
{
m_totalClicks = m_clicksRemain = 1;
}
~SplatToolState() {}
void execute();
SproxelTool type() { return TOOL_SPLAT; }
std::vector<Imath::V3i> voxelsAffected();
};
////////////////////////////////////////////////////////////////////////////////
// Flood tool
////////////////////////////////////////////////////////////////////////////////
class FloodToolState : public ToolState
{
public:
FloodToolState(UndoManager* um) : ToolState(um)
{
m_totalClicks = m_clicksRemain = 1;
}
~FloodToolState() {}
void execute();
SproxelTool type() { return TOOL_FLOOD; }
std::vector<Imath::V3i> voxelsAffected();
private:
void setNeighborsRecurse(const Imath::V3i& alreadySet,
const Imath::Color4f& repColor,
const Imath::Color4f& newColor,
int newIndex);
};
////////////////////////////////////////////////////////////////////////////////
// Eraser tool
////////////////////////////////////////////////////////////////////////////////
class EraserToolState : public ToolState
{
public:
EraserToolState(UndoManager* um) : ToolState(um)
{
m_totalClicks = m_clicksRemain = 1;
}
~EraserToolState() {}
void execute();
SproxelTool type() { return TOOL_ERASER; }
std::vector<Imath::V3i> voxelsAffected();
};
////////////////////////////////////////////////////////////////////////////////
// Replace tool
////////////////////////////////////////////////////////////////////////////////
class ReplaceToolState : public ToolState
{
public:
ReplaceToolState(UndoManager* um) : ToolState(um)
{
m_totalClicks = m_clicksRemain = 1;
}
~ReplaceToolState() {}
void execute();
SproxelTool type() { return TOOL_REPLACE; }
std::vector<Imath::V3i> voxelsAffected();
};
////////////////////////////////////////////////////////////////////////////////
// Ray tool
////////////////////////////////////////////////////////////////////////////////
class RayToolState : public ToolState
{
public:
RayToolState(UndoManager* um) : ToolState(um)
{
m_totalClicks = m_clicksRemain = 1;
}
~RayToolState() {}
void execute();
SproxelTool type() { return TOOL_RAY; }
std::vector<Imath::V3i> voxelsAffected();
};
////////////////////////////////////////////////////////////////////////////////
// Slab tool
////////////////////////////////////////////////////////////////////////////////
class SlabToolState : public ToolState
{
public:
SlabToolState(UndoManager* um) : ToolState(um)
{
m_workingAxis = Y_AXIS;
m_totalClicks = m_clicksRemain = 1;
}
~SlabToolState() {}
virtual void setAxis(SproxelAxis axis)
{
m_workingAxis = axis;
}
void execute();
SproxelTool type() { return TOOL_SLAB; }
std::vector<Imath::V3i> voxelsAffected();
private:
SproxelAxis m_workingAxis;
};
////////////////////////////////////////////////////////////////////////////////
// Line tool
////////////////////////////////////////////////////////////////////////////////
class LineToolState : public ToolState
{
public:
LineToolState(UndoManager* um) : ToolState(um), m_startPoint(-1, -1, -1)
{
m_totalClicks = m_clicksRemain = 2;
}
~LineToolState() {}
void execute();
SproxelTool type() { return TOOL_LINE; }
std::vector<Imath::V3i> voxelsAffected();
private:
Imath::V3i m_startPoint;
};
////////////////////////////////////////////////////////////////////////////////
// Box tool
////////////////////////////////////////////////////////////////////////////////
class BoxToolState : public ToolState
{
public:
BoxToolState(UndoManager* um) : ToolState(um), m_startPoint(-1, -1, -1)
{
m_totalClicks = m_clicksRemain = 2;
}
~BoxToolState() {}
void execute();
SproxelTool type() { return TOOL_BOX; }
std::vector<Imath::V3i> voxelsAffected();
private:
Imath::V3i m_startPoint;
};
////////////////////////////////////////////////////////////////////////////////
// Extrude tool
////////////////////////////////////////////////////////////////////////////////
class ExtrudeToolState : public ToolState
{
public:
ExtrudeToolState(UndoManager* um) : ToolState(um)
{
m_totalClicks = m_clicksRemain = 1;
}
~ExtrudeToolState() {}
void execute();
void executeErase();
SproxelTool type() { return TOOL_EXTRUDE; }
std::vector<Imath::V3i> voxelsAffected();
private:
Imath::V3i m_dir;
void doExtrude(bool is_erase);
void fillExtrudeMap(GameVoxelGrid<char> &map, const Imath::V3i &mapOfs,
const Imath::V3i &pos, int axis);
};
////////////////////////////////////////////////////////////////////////////////
// Dropper tool
////////////////////////////////////////////////////////////////////////////////
class DropperToolState : public ToolState
{
public:
DropperToolState(UndoManager* um) : ToolState(um)
{
m_totalClicks = m_clicksRemain = 1;
}
~DropperToolState() {}
void execute();
SproxelTool type() { return TOOL_DROPPER; }
std::vector<Imath::V3i> voxelsAffected();
};
#endif