Elaztek Developer Hub
Blamite Game Engine - blam!  00423.10.27.24.0533.blamite
The core library for the Blamite Game Engine.
ogre_scene_editor.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <limits.h>
6 #include <OGRE/OgreSceneManager.h>
7 
10 
15 {
16 private:
23  void ShowSceneNodeControls(Ogre::Node* node, int iterator_index)
24  {
25  if (!node)
26  {
27  return;
28  }
29 
30  std::string entry_name = node->getName() + "##" + node->getName() + std::to_string(iterator_index);
31 
32  if (ImGui::CollapsingHeader(entry_name.c_str()))
33  {
34  Ogre::Vector3 position = node->getPosition();
35  Ogre::Quaternion orientation = node->getOrientation();
36  Ogre::Vector3 scale = node->getScale();
37 
38  std::string position_name = "position##" + node->getName() + std::to_string(iterator_index);
39  std::string orientation_name = "orientation##" + node->getName() + std::to_string(iterator_index);
40  std::string rotation_name = "rotation##" + node->getName() + std::to_string(iterator_index);
41  std::string scale_name = "scale##" + node->getName() + std::to_string(iterator_index);
42 
43  if (ImGui::DragFloat3(position_name.c_str(), (float*)&position))
44  {
45  node->setPosition(position);
46  }
47 
48  BlamVector3 rotation = BlamVector3(orientation.getPitch().valueDegrees(), orientation.getYaw().valueDegrees(),
49  orientation.getRoll().valueDegrees());
50 
51  if (ImGui::DragFloat3(rotation_name.c_str(), (float*)&rotation))
52  {
53  BlamVector4 quaternion = BlamStrings::Utils::Math::GetQuaternionFromRotation(rotation);
54  node->setOrientation(quaternion.w, quaternion.x, quaternion.y, quaternion.z);
55  }
56 
57  if (ImGui::DragFloat4(orientation_name.c_str(), (float*)&orientation, 0.001f))
58  {
59  node->setOrientation(orientation);
60  }
61 
62  if (ImGui::DragFloat3(scale_name.c_str(), (float*)&scale))
63  {
64  node->setScale(scale);
65  }
66 
67  Ogre::SceneNode* sn = (Ogre::SceneNode*)node;
68  for (int i = 0; i < sn->numAttachedObjects(); i++)
69  {
70  Ogre::MovableObject* object = sn->getAttachedObject(i);
71  std::string header_name = "attach" + std::to_string(i) + ": " + object->getName() + "##" + std::to_string(iterator_index) + "_" + std::to_string(i);
72 
73  if (ImGui::CollapsingHeader(header_name.c_str()))
74  {
75  std::string flags_name = "query flags##" + node->getName() + std::to_string(iterator_index) + "_" + std::to_string(i);
76 
77  std::string flags = std::to_string(sn->getAttachedObject(0)->getQueryFlags());
78  ImGui::InputText(flags_name.c_str(), &flags, ImGuiInputTextFlags_ReadOnly);
79  }
80  }
81 
82  if (node->numChildren() > 0)
83  {
84  std::string child_count_message = "children: " + std::to_string(node->numChildren());
85  ImGui::Text(child_count_message.c_str());
86 
87  Ogre::Node::NodeVecIterator it = node->getChildIterator();
88  ImGui::Indent(20.0f);
89  int index = 0;
90  while (it.current() != it.end())
91  {
92  Ogre::Node* node = it.getNext();
93  ShowSceneNodeControls(node, index);
94  index++;
95  }
96  ImGui::Unindent(20.0f);
97  }
98  }
99  }
100 
101 public:
102  void Draw()
103  {
104  if (!show)
105  {
106  return;
107  }
108 
109  if (ImGui::Begin("Ogre Scene Editor", &show))
110  {
112 
114  {
115  Ogre::SceneNode* root = ogre_graphics_system->getSceneManager()->getRootSceneNode();
116  Ogre::SceneNode* root_2d = Blam::Rendering::Get2DSceneManager()->getRootSceneNode();
117 
118  if (ImGui::CollapsingHeader("world"))
119  {
120  ShowSceneNodeControls(root, 0);
121  }
122 
123  if (ImGui::CollapsingHeader("2d ortho"))
124  {
125  ShowSceneNodeControls(root_2d, 0);
126  }
127  }
128  else
129  {
130  ImGui::Text("ogre graphics system was nullptr");
131  }
132  }
133  ImGui::End();
134  }
135 };
ImGuiInputTextFlags_ReadOnly
@ ImGuiInputTextFlags_ReadOnly
Definition: imgui.h:769
BlamImGuiWindow::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: imgui.h:34
ImGui::InputText
IMGUI_API bool InputText(const char *label, char *buf, size_t buf_size, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition: imgui_widgets.cpp:3068
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
BlamImGuiWindow_OgreSceneEditor::Draw
void Draw()
Draws the contents of the group.
Definition: ogre_scene_editor.hpp:102
ogre_graphics_system
Demo::GraphicsSystem * ogre_graphics_system
Definition: ogre.cpp:52
imgui_stdlib.h
rendering.h
BlamImGuiWindow
Class representing an ImGUI window.
Definition: imgui.h:31
Demo::GraphicsSystem::getSceneManager
Ogre::SceneManager * getSceneManager(void) const
Definition: GraphicsSystem.h:147
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
ImGui::CollapsingHeader
IMGUI_API bool CollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0)
Definition: imgui_widgets.cpp:5422
ImGui::Unindent
IMGUI_API void Unindent(float indent_w=0.0f)
Definition: imgui.cpp:7178
ImGui::Text
IMGUI_API void Text(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:238
ImGui::DragFloat3
IMGUI_API bool DragFloat3(const char *label, float v[3], float v_speed=1.0f, float v_min=0.0f, float v_max=0.0f, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2174
Blam::Rendering::GetGraphicsSystem
BLAM Demo::GraphicsSystem * GetGraphicsSystem()
Retrieves the graphics system used by OGRE.
Definition: ogre.cpp:492
Demo::GraphicsSystem
Definition: GraphicsSystem.h:27
Blam::Rendering::Get2DSceneManager
BLAM Ogre::SceneManager * Get2DSceneManager()
Retrieves the scene manager used to handle 2D rendering.
Definition: ogre.cpp:552
imgui.h
ImGui::DragFloat4
IMGUI_API bool DragFloat4(const char *label, float v[4], float v_speed=1.0f, float v_min=0.0f, float v_max=0.0f, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2179
ImGui::Indent
IMGUI_API void Indent(float indent_w=0.0f)
Definition: imgui.cpp:7170
BlamImGuiWindow_OgreSceneEditor
Class for the Ogre Scene Editor utility.
Definition: ogre_scene_editor.hpp:14