Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
SceneViewWindow.cpp
Go to the documentation of this file.
1
2
6
8
13
14#include <imgui_internal.h>
15#include <IconsForkAwesome.h>
16
17namespace Divide
18{
19
21 : NodePreviewWindow(parent, descriptor)
22 {
24 }
25
27 {
29
30 bool play = !_parent.simulationPaused();
31 _descriptor.name = (play ? ICON_FK_PLAY_CIRCLE : ICON_FK_PAUSE_CIRCLE) + _originalName;
32 ImGui::Text("Play:");
33 ImGui::SameLine();
34 if (ImGui::ToggleButton("Play", &play))
35 {
37 }
38
39 if (ImGui::IsItemHovered())
40 {
41 ImGui::SetTooltip("Toggle scene playback");
42 }
43
44 ImGui::SameLine();
45 const bool enableStepButtons = !play;
46 if (button(enableStepButtons,
47 ICON_FK_FORWARD,
48 "When playback is paused, advanced the simulation by 1 full frame"))
49 {
51 }
52
53 ImGui::SameLine();
54
55 if (button(enableStepButtons,
56 ICON_FK_FAST_FORWARD,
57 Util::StringFormat("When playback is paused, advanced the simulation by {} full frame", Config::TARGET_FRAME_RATE).c_str()))
58 {
60 }
61
62 bool readOnly = false;
63
66
67 const F32 ItemSpacing = ImGui::GetStyle().ItemSpacing.x;
68 static F32 TButtonWidth = 10.0f;
69 static F32 RButtonWidth = 10.0f;
70 static F32 SButtonWidth = 10.0f;
71 static F32 NButtonWidth = 10.0f;
72
73 ImGuiWindow* window = ImGui::GetCurrentWindow();
74 ImGui::SameLine(window->Size.x * 0.49f);
75 if (play)
76 {
78 readOnly = true;
79 }
80
81 if (button(true, ICON_FK_CAMERA_RETRO, "Copy the player's camera snapshot to the editor camera"))
82 {
84 }
85
86 ImGui::SameLine();
87 if (button(true, ICON_FK_HOME, "Set the editor's camera's position to (0, 0, 0) and view direction to (0, -1, 0)"))
88 {
90 }
91
92 F32 pos = (2*SButtonWidth) + ItemSpacing + 25;
93 ImGui::SameLine( window->Size.x - pos);
94 if (button(!enableGizmo || !IsScaleOperation(settings), ICON_FK_EXPAND, "Scale", true))
95 {
96 switch (settings.previousAxisSelected[2])
97 {
98 case 0u: settings.currentGizmoOperation = ImGuizmo::SCALE; break;
99 case 1u: settings.currentGizmoOperation = ImGuizmo::SCALE_X; break;
100 case 2u: settings.currentGizmoOperation = ImGuizmo::SCALE_Y; break;
101 case 3u: settings.currentGizmoOperation = ImGuizmo::SCALE_Z; break;
102 }
103 settings.currentAxisSelected = settings.previousAxisSelected[2];
105 }
106
107 SButtonWidth = ImGui::GetItemRectSize().x;
108
109 pos += RButtonWidth + ItemSpacing + 1;
110 ImGui::SameLine( window->Size.x - pos);
111 if (button(!enableGizmo || !IsRotationOperation(settings), ICON_FK_REPEAT, "Rotate", true))
112 {
113 switch (settings.previousAxisSelected[1])
114 {
115 case 0u: settings.currentGizmoOperation = ImGuizmo::ROTATE; break;
116 case 1u: settings.currentGizmoOperation = ImGuizmo::ROTATE_X; break;
117 case 2u: settings.currentGizmoOperation = ImGuizmo::ROTATE_Y; break;
118 case 3u: settings.currentGizmoOperation = ImGuizmo::ROTATE_Z; break;
119 }
120 settings.currentAxisSelected = settings.previousAxisSelected[1];
122 }
123
124 RButtonWidth = ImGui::GetItemRectSize().x;
125
126 pos += TButtonWidth + ItemSpacing + 1;
127 ImGui::SameLine( window->Size.x - pos);
128 if (button(!enableGizmo || !IsTranslationOperation(settings), ICON_FK_ARROWS, "Translate", true))
129 {
130 switch (settings.previousAxisSelected[0])
131 {
132 case 0u: settings.currentGizmoOperation = ImGuizmo::TRANSLATE; break;
133 case 1u: settings.currentGizmoOperation = ImGuizmo::TRANSLATE_X; break;
134 case 2u: settings.currentGizmoOperation = ImGuizmo::TRANSLATE_Y; break;
135 case 3u: settings.currentGizmoOperation = ImGuizmo::TRANSLATE_Z; break;
136 }
137 settings.currentAxisSelected = settings.previousAxisSelected[0];
139 }
140
141 TButtonWidth = ImGui::GetItemRectSize().x;
142
143 pos += NButtonWidth + ItemSpacing + 1;
144 ImGui::SameLine( window->Size.x - pos);
145 if (button(enableGizmo, ICON_FK_MOUSE_POINTER, "Select", true))
146 {
148 settings.currentAxisSelected = 0u;
149 }
150
151 NButtonWidth = ImGui::GetItemRectSize().x;
152
153 if (play)
154 {
155 PopReadOnly();
156 readOnly = false;
157 }
158
161
163
164 if (play || !enableGizmo)
165 {
166 PushReadOnly();
167 readOnly = true;
168 }
169 if (ImGui::RadioButton("Local", settings.currentGizmoMode == ImGuizmo::LOCAL))
170 {
171 settings.currentGizmoMode = ImGuizmo::LOCAL;
172 }
173
174 ImGui::SameLine();
175 if (ImGui::RadioButton("World", settings.currentGizmoMode == ImGuizmo::WORLD))
176 {
177 settings.currentGizmoMode = ImGuizmo::WORLD;
178 }
179
180 ImGui::SameLine();
181 ImGui::Text("Gizmo Axis [ ");
182 ImGui::SameLine();
184 if (button(enableGizmo && settings.currentAxisSelected != 1u, Util::FieldLabels[0], "X Axis Only", true))
185 {
186 settings.currentAxisSelected = 1u;
187
188 switch (settings.currentGizmoOperation)
189 {
190 case ImGuizmo::TRANSLATE:
191 case ImGuizmo::TRANSLATE_X:
192 case ImGuizmo::TRANSLATE_Y:
193 case ImGuizmo::TRANSLATE_Z:
194 settings.currentGizmoOperation = ImGuizmo::TRANSLATE_X;
195 settings.previousAxisSelected[0] = 1u;
196 break;
197 case ImGuizmo::ROTATE:
198 case ImGuizmo::ROTATE_X:
199 case ImGuizmo::ROTATE_Y:
200 case ImGuizmo::ROTATE_Z:
201 settings.currentGizmoOperation = ImGuizmo::ROTATE_X;
202 settings.previousAxisSelected[1] = 1u;
203 break;
204 case ImGuizmo::SCALE:
205 case ImGuizmo::SCALE_X:
206 case ImGuizmo::SCALE_Y:
207 case ImGuizmo::SCALE_Z:
208 settings.currentGizmoOperation = ImGuizmo::SCALE_X;
209 settings.previousAxisSelected[2] = 1u;
210 break;
211
212 case ImGuizmo::ROTATE_SCREEN:
213 case ImGuizmo::BOUNDS:
214 break;
215 };
216 }
218 ImGui::SameLine();
220 if (button(enableGizmo && settings.currentAxisSelected != 2u, Util::FieldLabels[1], "Y Axis Only", true))
221 {
222 settings.currentAxisSelected = 2u;
223
224 switch (settings.currentGizmoOperation)
225 {
226 case ImGuizmo::TRANSLATE:
227 case ImGuizmo::TRANSLATE_X:
228 case ImGuizmo::TRANSLATE_Y:
229 case ImGuizmo::TRANSLATE_Z:
230 settings.currentGizmoOperation = ImGuizmo::TRANSLATE_Y;
231 settings.previousAxisSelected[0] = 2u;
232 break;
233 case ImGuizmo::ROTATE:
234 case ImGuizmo::ROTATE_X:
235 case ImGuizmo::ROTATE_Y:
236 case ImGuizmo::ROTATE_Z:
237 settings.currentGizmoOperation = ImGuizmo::ROTATE_Y;
238 settings.previousAxisSelected[1] = 2u;
239 break;
240 case ImGuizmo::SCALE:
241 case ImGuizmo::SCALE_X:
242 case ImGuizmo::SCALE_Y:
243 case ImGuizmo::SCALE_Z:
244 settings.currentGizmoOperation = ImGuizmo::SCALE_Y;
245 settings.previousAxisSelected[2] = 2u;
246 break;
247 case ImGuizmo::ROTATE_SCREEN:
248 case ImGuizmo::BOUNDS:
249 break;
250 };
251 }
253 ImGui::SameLine();
255 if (button(enableGizmo && settings.currentAxisSelected != 3u, Util::FieldLabels[2], "Z Axis Only", true))
256 {
257 settings.currentAxisSelected = 3u;
258
259 switch (settings.currentGizmoOperation)
260 {
261 case ImGuizmo::TRANSLATE:
262 case ImGuizmo::TRANSLATE_X:
263 case ImGuizmo::TRANSLATE_Y:
264 case ImGuizmo::TRANSLATE_Z:
265 settings.currentGizmoOperation = ImGuizmo::TRANSLATE_Z;
266 settings.previousAxisSelected[0] = 3u;
267 break;
268 case ImGuizmo::ROTATE:
269 case ImGuizmo::ROTATE_X:
270 case ImGuizmo::ROTATE_Y:
271 case ImGuizmo::ROTATE_Z:
272 settings.currentGizmoOperation = ImGuizmo::ROTATE_Z;
273 settings.previousAxisSelected[1] = 3u;
274 break;
275 case ImGuizmo::SCALE:
276 case ImGuizmo::SCALE_X:
277 case ImGuizmo::SCALE_Y:
278 case ImGuizmo::SCALE_Z:
279 settings.currentGizmoOperation = ImGuizmo::SCALE_Z;
280 settings.previousAxisSelected[2] = 3u;
281 break;
282 case ImGuizmo::ROTATE_SCREEN:
283 case ImGuizmo::BOUNDS:
284 break;
285 };
286 }
288
289 ImGui::SameLine();
291 if (button(enableGizmo && settings.currentAxisSelected != 0u, "All", "All Axis", true))
292 {
293 settings.currentAxisSelected = 0u;
294
295 switch (settings.currentGizmoOperation)
296 {
297 case ImGuizmo::TRANSLATE:
298 case ImGuizmo::TRANSLATE_X:
299 case ImGuizmo::TRANSLATE_Y:
300 case ImGuizmo::TRANSLATE_Z:
301 settings.currentGizmoOperation = ImGuizmo::TRANSLATE;
302 settings.previousAxisSelected[0] = 0u;
303 break;
304 case ImGuizmo::ROTATE:
305 case ImGuizmo::ROTATE_X:
306 case ImGuizmo::ROTATE_Y:
307 case ImGuizmo::ROTATE_Z:
308 settings.currentGizmoOperation = ImGuizmo::ROTATE;
309 settings.previousAxisSelected[1] = 0u;
310 break;
311 case ImGuizmo::SCALE:
312 case ImGuizmo::SCALE_X:
313 case ImGuizmo::SCALE_Y:
314 case ImGuizmo::SCALE_Z:
315 settings.currentGizmoOperation = ImGuizmo::SCALE;
316 settings.previousAxisSelected[2] = 0u;
317 break;
318 case ImGuizmo::ROTATE_SCREEN:
319 case ImGuizmo::BOUNDS:
320 break;
321 };
322 }
324
325 ImGui::SameLine();
326 ImGui::Text(" ]");
327
328 ImGui::SameLine(0.f, 25.0f);
329 ImGui::Checkbox("Snap", &settings.useSnap);
330
331 const ImGuiInputTextFlags flags = Util::GetDefaultFlagsForSettings(readOnly, false);
332 if (settings.useSnap)
333 {
334 ImGui::SameLine();
335 ImGui::Text("Step:");
336 ImGui::SameLine();
337 ImGui::PushItemWidth(150);
338 {
339 if (IsTranslationOperation(settings))
340 {
341 switch (settings.currentGizmoOperation)
342 {
343 case ImGuizmo::TRANSLATE:
344 for (size_t i = 0; i < 3; ++i)
345 {
346 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
348 settings.snapTranslation[i],
349 0.f,
350 0.001f,
351 1000.f,
352 0.f,
353 0.f,
354 Util::Colours[i],
356 Util::Colours[i],
357 flags);
358 ImGui::SameLine();
359 }
360 ImGui::Dummy(ImVec2(0, 0));
361 break;
362 case ImGuizmo::TRANSLATE_X:
363 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
365 settings.snapTranslation[0],
366 0.f,
367 0.001f,
368 1000.f,
369 0.f,
370 0.f,
371 Util::Colours[0],
373 Util::Colours[0],
374 flags);
375 break;
376 case ImGuizmo::TRANSLATE_Y:
377 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
379 settings.snapTranslation[1],
380 0.f,
381 0.001f,
382 1000.f,
383 0.f,
384 0.f,
385 Util::Colours[1],
387 Util::Colours[1],
388 flags);
389 break;
390 case ImGuizmo::TRANSLATE_Z:
391 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
393 settings.snapTranslation[2],
394 0.f,
395 0.001f,
396 1000.f,
397 0.f,
398 0.f,
399 Util::Colours[2],
401 Util::Colours[2],
402 flags);
403 break;
404 default: DIVIDE_UNEXPECTED_CALL(); break;
405 }
406 }
407 else if (IsRotationOperation(settings))
408 {
409 switch (settings.currentGizmoOperation)
410 {
411 case ImGuizmo::ROTATE:
412 for (size_t i = 0; i < 3; ++i)
413 {
414 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
416 settings.snapTranslation[i],
417 0.f,
418 0.001f,
419 1000.f,
420 0.f,
421 0.f,
422 Util::Colours[i],
424 Util::Colours[i],
425 flags);
426 ImGui::SameLine();
427 }
428 ImGui::Dummy(ImVec2(0, 0));
429 break;
430 case ImGuizmo::ROTATE_X:
431 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
433 settings.snapRotation[0],
434 0.f,
435 0.001f,
436 180.f,
437 0.f,
438 0.f,
439 Util::Colours[0],
441 Util::Colours[0],
442 flags);
443 break;
444 case ImGuizmo::ROTATE_Y:
445 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
447 settings.snapRotation[1],
448 0.f,
449 0.001f,
450 180.f,
451 0.f,
452 0.f,
453 Util::Colours[1],
455 Util::Colours[1],
456 flags);
457 break;
458 case ImGuizmo::ROTATE_Z:
459 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
461 settings.snapRotation[2],
462 0.f,
463 0.001f,
464 180.f,
465 0.f,
466 0.f,
467 Util::Colours[2],
469 Util::Colours[2],
470 flags);
471 break;
472 default: DIVIDE_UNEXPECTED_CALL(); break;
473 }
474 }
475 else if (IsScaleOperation(settings))
476 {
477 switch (settings.currentGizmoOperation)
478 {
479 case ImGuizmo::SCALE:
480 for (size_t i = 0; i < 3; ++i)
481 {
482 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
484 settings.snapScale[i],
485 0.f,
486 0.001f,
487 1000.f,
488 0.f,
489 0.f,
490 Util::Colours[i],
492 Util::Colours[i],
493 flags);
494 ImGui::SameLine();
495 }
496 ImGui::Dummy(ImVec2(0, 0));
497 break;
498 case ImGuizmo::SCALE_X:
499 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
501 settings.snapScale[0],
502 0.f,
503 0.001f,
504 1000.f,
505 0.f,
506 0.f,
507 Util::Colours[0],
509 Util::Colours[0],
510 flags);
511 break;
512 case ImGuizmo::SCALE_Y:
513 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
515 settings.snapScale[1],
516 0.f,
517 0.001f,
518 1000.f,
519 0.f,
520 0.f,
521 Util::Colours[1],
523 Util::Colours[1],
524 flags);
525 break;
526 case ImGuizmo::SCALE_Z:
527 Util::DrawVecComponent<F32, false>(ImGuiDataType_Float,
529 settings.snapScale[2],
530 0.f,
531 0.001f,
532 1000.f,
533 0.f,
534 0.f,
535 Util::Colours[2],
537 Util::Colours[2],
538 flags);
539 break;
540 default: DIVIDE_UNEXPECTED_CALL(); break;
541 }
542 }
543 }
544 ImGui::PopItemWidth();
545 }
546
548 if (play || !enableGizmo)
549 {
550 PopReadOnly();
551 readOnly = false;
552 }
553
554 ImGui::SameLine( window->Size.x * 0.95f);
555
556 bool enableGrid = _parent.infiniteGridEnabledScene();
557 if (ImGui::Checkbox(ICON_FK_PLUS_SQUARE_O" Infinite Grid", &enableGrid))
558 {
559 _parent.infiniteGridEnabledScene(enableGrid);
560 }
561 if (ImGui::IsItemHovered())
562 {
563 ImGui::SetTooltip("Toggle the editor XZ grid on/off.\nGrid sizing is controlled in the \"Editor options\" window (under \"File\" in the menu bar)");
564 }
565 }
566} //namespace Divide
#define DIVIDE_UNEXPECTED_CALL()
#define PROFILE_SCOPE_AUTO(CATEGORY)
Definition: Profiler.h:87
static void editorEnableGizmo(const Editor &editor, const bool state) noexcept
Definition: Editor.h:410
static void copyPlayerCamToEditorCam(Editor &editor) noexcept
Definition: Editor.h:415
static bool editorEnabledGizmo(const Editor &editor) noexcept
Definition: Editor.h:405
static void simulationPaused(Editor &editor, const bool state) noexcept
Definition: Editor.h:435
static void editorStepQueue(Editor &editor, const U32 steps) noexcept
Definition: Editor.h:430
static void setEditorCamLookAt(Editor &editor, const vec3< F32 > &eye, const vec3< F32 > &fwd, const vec3< F32 > &up) noexcept
Definition: Editor.h:420
const Descriptor & descriptor() const noexcept
Definition: DockedWindow.h:69
Descriptor _descriptor
Definition: DockedWindow.h:87
void setTransformSettings(const TransformSettings &settings) const noexcept
Definition: Editor.inl:45
const TransformSettings & getTransformSettings() const noexcept
Definition: Editor.inl:49
bool simulationPaused() const noexcept
Definition: Editor.inl:57
GFXRTPool & renderTargetPool() noexcept
Definition: GFXDevice.inl:133
RenderTarget * getRenderTarget(const RenderTargetID target) const
Definition: GFXRTPool.cpp:50
bool button(bool enabled, const char *label, const char *tooltip, bool small=false)
PlatformContext & context() noexcept
GFXDevice & gfx() noexcept
Handle< Texture > texture() const
RTAttachment * getAttachment(RTAttachmentType type, RTColourAttachmentSlot slot=RTColourAttachmentSlot::SLOT_0) const
SceneViewWindow(Editor &parent, const Descriptor &descriptor)
void drawInternal() override
constexpr U16 TARGET_FRAME_RATE
Application desired framerate for physics and input simulations.
Definition: config.h:97
constexpr Optick::Category::Type GUI
Definition: Profiler.h:64
Str StringFormat(const char *fmt, Args &&...args)
void PopBoldFont()
Definition: Utils.cpp:291
void PopButtonStyle()
Definition: Utils.cpp:350
static const ImVec4 Colours[]
Definition: Utils.h:58
void PushBoldFont()
Definition: Utils.cpp:282
static const ImVec4 ColoursHovered[]
Definition: Utils.h:63
void PushButtonStyle(bool bold, ImVec4 buttonColour, ImVec4 buttonColourHovered, ImVec4 buttonColourActive)
Definition: Utils.cpp:336
ImGuiInputTextFlags GetDefaultFlagsForSettings(bool readOnly, bool hex)
Definition: Utils.cpp:429
constexpr const char * FieldLabels[]
Definition: Utils.h:69
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
FORCE_INLINE bool IsRotationOperation(const TransformSettings &settings)
Definition: Gizmo.h:73
void PushReadOnly(const bool fade)
Definition: Editor.cpp:2961
FORCE_INLINE bool IsTranslationOperation(const TransformSettings &settings)
Definition: Gizmo.h:66
FORCE_INLINE bool IsScaleOperation(const TransformSettings &settings)
Definition: Gizmo.h:80
void PopReadOnly()
Definition: Editor.cpp:2971
Project & parent
Definition: DefaultScene.h:41
static const vec3< F32 > WORLD_Z_NEG_AXIS
Definition: MathVectors.h:1444
static const vec3< F32 > VECTOR3_ZERO
Definition: MathVectors.h:1434
static const vec3< F32 > WORLD_Y_AXIS
Definition: MathVectors.h:1440
bool ToggleButton(const char *str_id, bool *v)
static RenderTargetID BACK_BUFFER
Definition: GFXDevice.h:196
U8 previousAxisSelected[3]
Definition: Gizmo.h:61
ImGuizmo::OPERATION currentGizmoOperation
Definition: Gizmo.h:56
ImGuizmo::MODE currentGizmoMode
Definition: Gizmo.h:57