-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zephyr: Scene: optimize matrix transform updates
- Loading branch information
Showing
9 changed files
with
143 additions
and
25 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
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
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
namespace zephyr { | ||
|
||
class SceneNode; | ||
|
||
class SceneGraph { | ||
public: | ||
SceneGraph(); | ||
|
||
[[nodiscard]] const SceneNode* GetRoot() const { | ||
return m_root_node.get(); | ||
} | ||
|
||
[[nodiscard]] SceneNode* GetRoot() { | ||
return m_root_node.get(); | ||
} | ||
|
||
void UpdateTransforms(); | ||
|
||
private: | ||
friend SceneNode; | ||
friend class Transform3D; | ||
|
||
void SignalNodeMounted(SceneNode* node); | ||
void SignalNodeRemoved(SceneNode* node); | ||
void SignalNodeTransformChanged(SceneNode* node); | ||
|
||
std::shared_ptr<SceneNode> m_root_node{}; | ||
std::vector<SceneNode*> m_nodes_with_dirty_transform{}; | ||
}; | ||
|
||
} // namespace zephyr |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
#include <zephyr/scene/scene_graph.hpp> | ||
#include <zephyr/scene/node.hpp> | ||
|
||
namespace zephyr { | ||
|
||
SceneGraph::SceneGraph() { | ||
m_root_node = SceneNode::New("SceneRoot", this); | ||
SignalNodeMounted(m_root_node.get()); | ||
} | ||
|
||
void SceneGraph::UpdateTransforms() { | ||
for(const auto node : m_nodes_with_dirty_transform) { | ||
node->GetTransform().UpdateLocal(); | ||
node->GetTransform().UpdateWorld(); | ||
} | ||
m_nodes_with_dirty_transform.clear(); | ||
} | ||
|
||
void SceneGraph::SignalNodeMounted(SceneNode* node) { | ||
SignalNodeTransformChanged(node); | ||
} | ||
|
||
void SceneGraph::SignalNodeRemoved(SceneNode* node) { | ||
} | ||
|
||
void SceneGraph::SignalNodeTransformChanged(SceneNode* node) { | ||
// TODO(fleroviux): avoid updating nodes more than once. | ||
// If a node is marked for update once and then later again, ideally skip the first update. | ||
node->Traverse([this](SceneNode* child_node) { | ||
m_nodes_with_dirty_transform.push_back(child_node); | ||
return true; | ||
}); | ||
} | ||
|
||
} // namespace zephyr |
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