9#ifndef AVARA3D_SCENE_NODE_H
10#define AVARA3D_SCENE_NODE_H
19#include "a3d/mesh/AABB.h"
20#include "a3d/util/Bitmask.h"
45 class Node :
public std::enable_shared_from_this<Node> {
54 ShowHighlightBox = 1 << 0,
55 ShowHighlightTint = 1 << 1
64 static std::shared_ptr<Node>
MeshNode(
const std::shared_ptr<Mesh>& geometry);
81 explicit Node(
const std::shared_ptr<Mesh>&
mesh);
90 Node& operator=(
const Node&) =
delete;
100 const std::optional<std::string>&
name()
const;
106 const std::shared_ptr<Light>&
light()
const;
112 const std::shared_ptr<Camera>&
camera()
const;
118 const std::shared_ptr<Mesh>&
mesh()
const;
239 void addChildren(
const std::vector<std::shared_ptr<Node>>& nodes);
250 std::vector<std::shared_ptr<Node>>
children(
bool resursive =
false)
const;
259 std::shared_ptr<Node>
childNamed(
const std::string&
name,
bool resursive =
false)
const;
301 enum class DirtyMask : uint32_t {
303 WorldTransform = 1 << 0,
330 void checkNotifyPhysicsBodyOfReachablePhysicsWorld()
const;
331 void checkNotifyPhysicsBodyOfUnreachablePhysicsWorld()
const;
333 bool containsChild(
const std::shared_ptr<Node>& node);
335 AABB aabb(
bool vertfit =
false)
const;
336 math::vec3 extent(
bool vertfit =
false)
const;
341 void _debugPrintRec(
Node& node,
unsigned level);
346 void getAABBRec(
AABB& aabb);
349 void syncPhysicsTransforms();
351 std::vector<std::shared_ptr<Node>>
children(
const Node& root)
const;
352 void childrenRec(
const std::shared_ptr<Node>& node, std::vector<std::shared_ptr<Node>>&
children)
const;
354 DirtyMask dirtyMask()
const;
355 void dirtyMask(DirtyMask mask);
359 std::optional<std::string> _name;
360 std::shared_ptr<Light> _light;
361 std::shared_ptr<Camera> _camera;
362 std::shared_ptr<Mesh> _mesh;
363 std::vector<std::shared_ptr<Node>> _children;
367 mutable std::optional<math::vec3> _eulerAngles;
368 std::unique_ptr<PhysicsBody> _physicsBody;
373 std::weak_ptr<Node> _parent;
374 DirtyMask _dirtyMask;
377 namespace util::bitmask {
380 struct enable_ops<Node::DebugOptions> : std::true_type {};
383 struct enable_ops<Node::DirtyMask> : std::true_type {};
A transformable object in a Scene hierarchy.
const math::vec3 & scale() const
Returns the node scale relative to its parent.
math::vec3 worldRight() const
Returns the node's local +X axis expressed in world coordinates.
const std::shared_ptr< Mesh > & mesh() const
Returns the mesh attached to this node, or nullptr if none is attached.
math::vec3 convertFrom(const math::vec3 &pos, const Node &from)
Converts pos from from local coordinates into this node's local coordinates.
math::vec3 worldUp() const
Returns the node's local +Y axis expressed in world coordinates.
void position(const math::vec3 &position)
Sets the node position in parent coordinates.
math::vec3 worldPosition() const
Returns the node position in world coordinates.
Node(const std::shared_ptr< Mesh > &mesh)
Creates a node containing mesh and an identity transform.
const std::shared_ptr< Camera > & camera() const
Returns the camera attached to this node, or nullptr if none is attached.
void scale(const math::vec3 &scale)
Sets the node scale relative to its parent.
void physicsBody(std::unique_ptr< PhysicsBody > body)
Replaces the physics body owned by this node; nullptr removes it.
DebugOptions debugOptions() const
Returns the enabled node debug visualization options.
math::vec3 worldScale() const
Returns the effective node scale in world coordinates.
void eulerAngles(const math::vec3 &angles)
Sets the node Euler angles as pitch, yaw, and roll in radians.
math::vec3 convertTo(const math::vec3 &pos, const Node &to)
Converts pos from this node's local coordinates into to local coordinates.
math::mat4 convertFrom(const math::mat4 &t, const Node &from)
Converts t from from local coordinates into this node's local coordinates.
static std::shared_ptr< Node > CameraNode(const std::shared_ptr< Camera > &camera)
Creates a new node containing camera.
bool hidden() const
Returns true when this node is hidden from rendering.
void renderOrder(int order)
Sets the node render-order value.
void hidden(bool hidden)
Sets whether this node is hidden from rendering.
math::mat4 worldTransform() const
Returns the transform from this node's local coordinates to world coordinates.
math::vec3 right() const
Returns the node's local +X axis expressed in parent coordinates.
std::shared_ptr< Node > childNamed(const std::string &name, bool resursive=false) const
Finds a child with name.
Node(const std::shared_ptr< Camera > &camera)
Creates a node containing camera and an identity transform.
const std::shared_ptr< Light > & light() const
Returns the light attached to this node, or nullptr if none is attached.
math::mat4 convertTo(const math::mat4 &t, const Node &to)
Converts t from this node's local coordinates into to local coordinates.
Node()
Creates an empty node with an identity transform.
Node(const std::shared_ptr< Light > &light)
Creates a node containing light and an identity transform.
math::vec3 worldEulerAngles() const
Returns the node world Euler angles as pitch, yaw, and roll in radians.
static std::shared_ptr< Node > LightNode(const std::shared_ptr< Light > &light)
Creates a new node containing light.
void removeFromParent()
Detaches this node from its current parent, if it has one.
std::weak_ptr< Node > parent() const
Returns the current parent, or an empty weak pointer for a root or detached node.
void name(const std::string &name)
Sets the node name.
DebugOptions
Debug visualization options associated with a node.
const std::optional< std::string > & name() const
Returns the optional node name.
static std::shared_ptr< Node > NamedNode(const std::string &name)
Creates a new node with name.
static std::shared_ptr< Node > MeshNode(const std::shared_ptr< Mesh > &geometry)
Creates a new node containing geometry.
math::vec3 up() const
Returns the node's local +Y axis expressed in parent coordinates.
const math::vec3 & position() const
Returns the node position in parent coordinates.
int renderOrder() const
Returns the node render-order value.
math::vec3 eulerAngles() const
Returns the node Euler angles in parent coordinates as pitch, yaw, and roll in radians.
const math::quat & orientation() const
Returns the node orientation in parent coordinates as a quaternion.
math::vec4 worldRotation() const
Returns the node world rotation.
void mesh(const std::shared_ptr< Mesh > &mesh)
Replaces the mesh attached to this node.
Node(const std::string &name)
Creates a node with name and an identity transform.
math::vec3 forward() const
Returns the node's local -Z axis expressed in parent coordinates.
void debugOptions(DebugOptions options)
Sets the enabled node debug visualization options.
void camera(const std::shared_ptr< Camera > &camera)
Replaces the camera attached to this node; nullptr removes it.
std::vector< std::shared_ptr< Node > > children(bool resursive=false) const
Returns this node's children.
void transform(const math::mat4 &transform)
Sets the node transform from local coordinates to parent coordinates.
void addChildren(const std::vector< std::shared_ptr< Node > > &nodes)
Adds each node in nodes as a child.
math::vec3 worldForward() const
Returns the node's local -Z axis expressed in world coordinates.
void light(const std::shared_ptr< Light > &light)
Replaces the light attached to this node; nullptr removes it.
math::quat worldOrientation() const
Returns the node orientation in world coordinates.
void orientation(const math::quat &orientation)
Sets the node orientation in parent coordinates.
math::mat4 transform() const
Returns the node transform from local coordinates to parent coordinates.
Scene * scene() const
Returns the Scene containing this node, or nullptr if the node is not attached to a Scene.
math::vec4 rotation() const
Returns the node rotation in parent coordinates.
PhysicsBody * physicsBody() const
Returns the physics body owned by this node, or nullptr if none is attached.
void rotation(const math::vec3 &axis, float angle)
Sets the node rotation from axis and angle in radians.
void addChild(const std::shared_ptr< Node > &node)
Adds node as a child of this node.
Rigid-body simulation state attached to a Node.
Simulates rigid bodies and performs physics collision queries for a Scene.
Owns a scene graph and the worlds used to simulate and render it.
Manages the visual presentation, camera, and visual queries for a Scene.
Axis-aligned bounding box defined by minimum and maximum corners.