2#include "Engine/Ecs/RegistryManager.h"
4#include <glm/gtc/quaternion.hpp>
27 class SceneNode :
public std::enable_shared_from_this<SceneNode> {
131 void addChild(
const std::shared_ptr<SceneNode> &newChild);
138 void addChildren(std::vector<std::shared_ptr<SceneNode>> newChildren);
159 const std::shared_ptr<SceneNode>& newParent,
248 [[nodiscard]]
const std::shared_ptr<SceneNode>&
getRoot()
const {
return root_; }
265 const std::shared_ptr<SceneNode> & parent,
266 bool disableCaching =
false);
283 static std::shared_ptr<SceneNode>
createNode(
const std::shared_ptr<SceneNode>& parent,
bool disableCaching =
false);
295 const std::shared_ptr<SceneNode>& parent,
297 bool disableCaching =
false);
307 shared->registerWithEcs();
static entt::registry & get()
Gets the registry for all components.
Factory class for creating SceneNodes with proper parent-child relationships. This ensures that nodes...
static std::vector< std::shared_ptr< SceneNode > > createNodes(const std::shared_ptr< SceneNode > &parent, size_t count, bool disableCaching=false)
Creates multiple nodes under the same parent.
static std::shared_ptr< SceneNode > createNode(const std::shared_ptr< SceneNode > &parent, bool disableCaching=false)
Creates a new SceneNode with the specified parent.
static std::shared_ptr< RootNode > createRoot()
Creates a new root node for a scene graph. This is the only way to create a parentless node,...
RootNode(entt::registry ®istry)
Creates the root node in the given ECS registry. The root never moves, so its world matrix is always ...
SceneGraph(const std::shared_ptr< SceneNode > &root)
Constructs a new Scene Graph object, initializing the root node.
std::shared_ptr< SceneNode > root_
void reserveRootChildren(size_t additionalChildren)
Reserves space for additional root children to avoid reallocations during bulk spawning.
std::shared_ptr< SceneNode > createNode(const Ecs::Transform &transform, const std::shared_ptr< SceneNode > &parent, bool disableCaching=false)
Creates a node which tells you where an object is in the scene.
const std::shared_ptr< SceneNode > & getRoot() const
Gets the root node of the scene graph.
bool isRoot() const
Checks if this node is the root node.
void setWorldModelMatrix(const glm::mat4 &newModelMatrix)
Overwrites all components of this transform.
void setWorldScale(const glm::vec3 &newScale)
sets the scale for this node
void setWorldPosition(const glm::vec3 &newLocation)
Sets the world position of the scene node. This will calculate the corresponding local position based...
void rotateWorld(const glm::quat &deltaRotation)
Applies an incremental rotation to the current world rotation using quaternion multiplication.
const glm::mat4 & getWorldMatrix() const
get the world matrix as a raw glm matrix
void setLocalModelMatrix(const glm::mat4 &newModelMatrix)
Overwrites all components of the transform.
void addChildren(std::vector< std::shared_ptr< SceneNode > > newChildren)
adds new children to this node
void clearChildren()
Removes all children from this node.
void detachFromParent()
Detaches this node from its parent, transferring ownership away from the scene graph.
void updateWorldMatrix() const
void reparentTo(const std::shared_ptr< SceneNode > &newParent, AttachmentTransformRule rule=AttachmentTransformRule::KeepWorld)
Safely reparents this node while preserving either world or local transform.
~SceneNode()
Destroys this scene node and releases its ECS registration state.
entt::registry * registry
SceneNode(entt::registry ®istry, bool disableCaching=false)
Constructs a new Scene Node object.
entt::entity getEntity() const
Gets the entity associated with this scene node.
const Ecs::Transform & getLocalTransform() const
Gets the local transform of the scene node. The local transform is relative to the parent node.
std::vector< std::shared_ptr< SceneNode > > children_
void markDirtyRecursive() const
Marks this node and its children as dirty.
void setWorldRotation(const glm::quat &newRotation)
Sets a new world rotation with a quaternion on this node.
void setWorldRotation(const glm::vec3 &newRotation)
Sets the world rotation of this node with euler angles.
Ecs::Transform & getLocalTransform()
Gets the local transform of the scene node. The local transform is relative to the parent node.
bool isWorldMatrixDirty() const
Checks if the world matrix has to be recalculated.
void rotateWorld(const glm::vec3 &deltaRotation)
Applies an incremental rotation to the current world rotation using quaternion multiplication....
void removeChild(const std::shared_ptr< SceneNode > &child)
Removes a single child from this node.
void registerWithEcs()
Registers this scene node and its transform data in the ECS registry.
void addChild(const std::shared_ptr< SceneNode > &newChild)
Adds a child node to this node.
bool isDirectChildOf(const std::shared_ptr< SceneNode > &potentialParent) const
Checks whether this node is directly attached to the given parent.
std::weak_ptr< SceneNode > parent_
std::vector< std::weak_ptr< SceneNode > > getChildren() const
Get a list of all children of this node.
EnTT component data used by engine systems.
AttachmentTransformRule
Controls which transform space is preserved when attaching or reparenting nodes.
@ KeepLocal
Preserve the node's local transform relative to the new parent.
@ KeepWorld
Preserve the node's world transform while recomputing its local transform.