-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AngelScript: added OGRE
Node
+SceneNode
bindings.
AngelScript API changes: + `ImGuiCond` enum + `ImGui::SetNextItemOpen()` func + `Ogre::Node` object + `Ogre::SceneNode` object Code changes: * CReadonlyScriptDictView moved to ScriptUtils.h * created CReadonlyScriptArrayView in ScriptUtils.h ogre_demo.as changes: * codechange: added class OgreInspector, draw funcs made methods. * ability to traverse scene node graph (using scenemanager.getRootSceneNode() and scenenode.getChildren())
- Loading branch information
Showing
4 changed files
with
374 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,125 @@ | ||
void main() | ||
{ | ||
game.log("EXPERIMENTAL! This script tests the new direct bindings of OGRE rendering framework"); | ||
game.log("CAUTION: Proof of concept, very experimental!"); | ||
game.log("This script tests the new direct bindings of OGRE rendering framework"); | ||
} | ||
|
||
OgreInspector inspector; | ||
|
||
void frameStep(float dt) | ||
{ | ||
// Begin drawing window | ||
ImGui::Begin("OGRE inspector", /*open:*/true, ImGuiWindowFlags_AlwaysAutoResize); | ||
ImGui::TextDisabled("See official OGRE API reference"); | ||
ImGui::TextDisabled("https://ogrecave.github.io/ogre/api/latest/"); | ||
ImGui::Separator(); | ||
ImGui::Begin("OGRE demo script", /*open:*/true, ImGuiWindowFlags_AlwaysAutoResize); | ||
|
||
inspector.draw(); | ||
|
||
Ogre::Root@ root = Ogre::Root::getSingleton(); | ||
if (@root != null) | ||
// End window | ||
ImGui::End(); | ||
} | ||
|
||
class OgreInspector | ||
{ | ||
void draw() | ||
{ | ||
drawTreeNodeOgreRoot(root); | ||
ImGui::TextDisabled("Scene inspector"); | ||
ImGui::SameLine(); | ||
ImGui::TextDisabled("(?)"); | ||
if (ImGui::IsItemHovered()) | ||
{ | ||
ImGui::BeginTooltip(); | ||
this.drawInspectorTooltipBody(); | ||
ImGui::EndTooltip(); | ||
} | ||
ImGui::Separator(); | ||
|
||
Ogre::Root@ root = Ogre::Root::getSingleton(); | ||
if (@root != null) | ||
{ | ||
drawTreeNodeOgreRoot(root); | ||
} | ||
else | ||
{ | ||
ImGui::TextDisabled("Cannot retrieve OGRE `Root` object"); | ||
} | ||
} | ||
else | ||
|
||
void drawInspectorTooltipBody() | ||
{ | ||
ImGui::TextDisabled("Cannot retrieve OGRE `Root` object"); | ||
ImGui::Text("Traverses the OGRE scene hierarchy, as stored in memory"); | ||
ImGui::Text("Note that all element names are just simple strings,"); | ||
ImGui::Text("even if they have '/' in them, like 'Ogre/SceneRoot'."); | ||
ImGui::Separator(); | ||
ImGui::TextDisabled("See official OGRE API reference"); | ||
ImGui::TextDisabled("https://ogrecave.github.io/ogre/api/latest/"); | ||
} | ||
|
||
// End window | ||
ImGui::End(); | ||
} | ||
void drawTreeNodeOgreRoot(Ogre::Root@ root) | ||
{ | ||
if (ImGui::TreeNode("(The OGRE Root)")) | ||
{ | ||
// Scenemanagers | ||
Ogre::SceneManagerInstanceDict@ sceneManagers = root.getSceneManagers(); | ||
ImGui::TextDisabled("Ogre::SceneManager [" + sceneManagers.getSize() + "]"); | ||
array<string> sceneMgrNames = sceneManagers.getKeys(); | ||
for (uint i = 0; i < sceneManagers.getSize(); i++) | ||
{ | ||
drawTreeNodeOgreSceneManager(sceneManagers[sceneMgrNames[i]]); | ||
} | ||
|
||
ImGui::TreePop(); | ||
} | ||
} | ||
|
||
void drawTreeNodeOgreRoot(Ogre::Root@ root) | ||
{ | ||
if (ImGui::TreeNode("Ogre::Root")) | ||
void drawTreeNodeOgreSceneManager(Ogre::SceneManager@ sceneMgr) | ||
{ | ||
// Scenemanagers | ||
Ogre::SceneManagerInstanceDict@ sceneManagers = root.getSceneManagers(); | ||
ImGui::TextDisabled("Ogre::SceneManager [" + sceneManagers.getSize() + "]"); | ||
array<string> sceneMgrNames = sceneManagers.getKeys(); | ||
for (uint i = 0; i < sceneManagers.getSize(); i++) | ||
if (ImGui::TreeNode('"'+sceneMgr.getName()+'"')) | ||
{ | ||
drawTreeNodeOgreSceneManager(sceneManagers[sceneMgrNames[i]]); | ||
} | ||
// Scene nodes | ||
Ogre::SceneNode@ rootNode = sceneMgr.getRootSceneNode(); | ||
if (@rootNode != null) | ||
{ | ||
ImGui::TextDisabled("Ogre::SceneNode [1]"); | ||
this.drawTreeNodeOgreSceneNodeRecursive(rootNode); | ||
} | ||
else | ||
{ | ||
ImGui::TextDisabled("Ogre::SceneNode [0]"); | ||
} | ||
|
||
ImGui::TreePop(); | ||
ImGui::TreePop(); | ||
} | ||
} | ||
} | ||
|
||
void drawTreeNodeOgreSceneManager(Ogre::SceneManager@ sceneMgr) | ||
{ | ||
if (ImGui::TreeNode(sceneMgr.getName())) | ||
{ | ||
ImGui::TreePop(); | ||
void drawTreeNodeOgreSceneNodeRecursive(const Ogre::SceneNode@ snode) | ||
{ | ||
// When drawing first time, fold nodes with many children (root node can have hundreds...) | ||
const Ogre::ChildNodeArray@ children = snode.getChildren(); | ||
ImGui::SetNextItemOpen(children.length() < 10, ImGuiCond_Once); | ||
|
||
// The `__getUniqueId()` is a Rigs of Rods extension (that's why double leading underscores), | ||
// because names are optional and usually not set, and imgui tree nodes require unique IDs. | ||
if (ImGui::TreeNode(snode.__getUniqueId())) | ||
{ | ||
// Tree node open, draw children recursively | ||
ImGui::TextDisabled("Ogre::Node ["+children.length()+"]"); | ||
for (uint i = 0; i < children.length(); i++) | ||
{ | ||
const Ogre::SceneNode@ child = cast<Ogre::SceneNode>(children[i]); | ||
if (@child != null) | ||
{ | ||
drawTreeNodeOgreSceneNodeRecursive(child); | ||
} | ||
} | ||
|
||
ImGui::TreePop(); | ||
} | ||
else | ||
{ | ||
// Tree node closed, draw child count | ||
ImGui::SameLine(); | ||
ImGui::Text("("+children.length()+" children)"); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.