SceneNode.ixx File
Scene graph node representing a transform and optional renderable. More...
Included Headers
#include <cassert>
#include <memory>
#include <vector>
#include <helios.math.TransformType>
#include <helios.math.types>
#include <helios.core.spatial.Transform>
#include <helios.math.transform>
#include <helios.util.Guid>
#include <helios.rendering.Renderable>
#include <helios.scene.SceneNode:SceneFwd>
Namespaces Index
| namespace | helios |
| namespace | scene |
Classes Index
| struct | SceneGraphKey |
|
SceneGraphKey as passkey idiom for accessing `setWorldTransform()`. All friend classes are able to construct the SceneGraphKey for accessing pass key guarded methods like `setWorldTransform`. More... | |
| class | SceneNode |
Description
Scene graph node representing a transform and optional renderable.
File Listing
The file content with the documentation metadata removed is:
23using namespace helios::core::spatial;
25export namespace helios::scene {
36 struct SceneGraphKey {
38 friend class helios::scene::Scene;
59 * `worldTransform`. A Scene might also propagate changes top-bottom - see `Scene::updateNodes()`.
69 const util::Guid guid_;
78 bool needsUpdate_ = true;
89 std::shared_ptr<helios::rendering::Renderable> renderable_ = nullptr;
152 parent_ = parentNode;
156 virtual ~SceneNode() = default;
182 guid_(util::Guid::generate())
193 guid_(util::Guid::generate()),
194 localTransform_(transform)
205 std::shared_ptr<helios::rendering::Renderable> renderable,
206 const Transform& transform
208 guid_(util::Guid::generate()),
209 renderable_(std::move(renderable)),
210 localTransform_(transform)
220 std::shared_ptr<helios::rendering::Renderable> renderable
222 guid_(util::Guid::generate()),
223 renderable_(std::move(renderable))
231 [[nodiscard]] const helios::util::Guid& guid() const noexcept {
245 auto& ref = *children_.emplace_back(std::move(sceneNode));
256 return children_;
264 [[nodiscard]] helios::rendering::Renderable* renderable() noexcept {
265 return renderable_.get();
273 [[nodiscard]] bool hasRenderable() const noexcept {
274 return renderable() != nullptr;
282 [[nodiscard]] const helios::rendering::Renderable* renderable() const noexcept {
283 return renderable_.get();
291 [[nodiscard]] std::shared_ptr<helios::rendering::Renderable> shareRenderable() noexcept {
292 return renderable_;
304 SceneNode& setScale(const helios::math::vec3f& scale) noexcept {
305 localTransform_.setScale(scale);
306 needsUpdate_ = true;
319 SceneNode& setRotation(const helios::math::mat4f& rotation) noexcept {
320 localTransform_.setRotation(rotation);
321 needsUpdate_ = true;
335 SceneNode& setTranslation(const helios::math::vec3f& translation) noexcept {
336 localTransform_.setTranslation(translation);
337 needsUpdate_ = true;
346 [[nodiscard]] const Transform& localTransform() const noexcept {
347 return localTransform_;
355 [[nodiscard]] Transform& localTransform() noexcept {
356 return localTransform_;
366 return parent_;
382 [[nodiscard]] bool applyWorldTransform(
383 const helios::math::mat4f& parentWorldTransform, helios::scene::SceneGraphKey sceneGraphKey
386 const auto newWt = inheritWorldTransform(parentWorldTransform);
388 if (!needsUpdate() && worldTransform_.same(newWt)) {
392 worldTransform_ = newWt;
393 needsUpdate_ = false;
396 onWorldTransformUpdate();
405 void setIsRoot(helios::scene::SceneGraphKey sceneGraphKey) noexcept {
406 isRoot_ = true;
415 return isRoot_;
427 const helios::math::mat4f& worldTransform() noexcept {
428 if (needsUpdate()) {
429 update();
432 return worldTransform_;
443 [[nodiscard]] const helios::math::mat4f& cachedWorldTransform() const noexcept {
444 return worldTransform_;
455 [[nodiscard]] bool needsUpdate() const noexcept {
456 return needsUpdate_ || localTransform_.needsUpdate();
465 [[nodiscard]] helios::math::aabbf aabb() noexcept {
466 if (needsUpdate()) {
467 update();
470 return aabb_;
481 needsUpdate_ = false;
483 if (parent_ == nullptr) {
484 worldTransform_ = localTransform_.transform();
486 worldTransform_ = inheritWorldTransform(parent_->worldTransform());
489 onWorldTransformUpdate();
499 virtual void onWorldTransformUpdate() noexcept {
500 if (renderable_) {
501 const auto& localAABB = renderable_->localAABB();
502 aabb_ = localAABB.applyTransform(worldTransform_);
520 helios::math::mat4f inheritWorldTransform(const helios::math::mat4f& parentWorldTransform) noexcept {
521 using namespace helios::math;
523 if (inheritance_ == helios::math::TransformType::All) {
524 return parentWorldTransform * localTransform_.transform();
527 auto id = parentWorldTransform.decompose(inheritance_);
529 return id * localTransform_.transform();
544 void setInheritance(const helios::math::TransformType inherit) noexcept {
545 inheritance_ = inherit;
546 needsUpdate_ = true;
556 [[nodiscard]] helios::math::TransformType inheritance() const noexcept {
557 return inheritance_;
566 return isActive_;
577 isActive_ = active;
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.