Lysa Nodes  0.0
Lysa Nodes — Scene Graph for the Lysa Engine
Node Class Reference

Detailed Description

Base class for all 3D nodes

+ Inheritance diagram for Node:

Public Types

enum  Type {
  ANIMATION_PLAYER, CAMERA, CHARACTER, COLLISION_AREA,
  COLLISION_OBJECT, DIRECTIONAL_LIGHT, ENVIRONMENT, KINEMATIC_BODY,
  LIGHT, MESH_INSTANCE, NODE, OMNI_LIGHT,
  PHYSICS_BODY, RAYCAST, RIGID_BODY, SKYBOX,
  SPOT_LIGHT, STATIC_BODY, VIEWPORT
}
 Node type. More...
 

Public Member Functions

 Node (const Node &node)
 
 Node (const std::string &name=TypeNames[NODE], Type type=NODE)
 
virtual ~Node () = default
 
auto getId () const
 
virtual void onReady ()
 
virtual void onEnterScene ()
 
virtual void onExitScene ()
 
virtual void onProcess (const float alpha)
 
virtual void onPhysicsProcess (const float delta)
 
virtual bool onInput (const InputEvent &inputEvent)
 
const float4x4 & getTransform () const
 
void setTransform (const float4x4 &transform)
 
const float4x4 & getTransformGlobal () const
 
virtual void setPosition (const float3 &position)
 
virtual void setPosition (const float x, const float y, const float z)
 
float3 getPosition () const
 
void translate (const float3 &localOffset)
 
void translate (const float x, const float y, const float z)
 
virtual void setPositionGlobal (const float3 &position)
 
virtual void setPositionGlobal (const float x, const float y, const float z)
 
float3 getPositionGlobal () const
 
void rotate (const quaternion &quaternion)
 
void rotateX (float angle)
 
void rotateY (float angle)
 
void rotateZ (float angle)
 
void rotateGlobalX (float angle)
 
void rotateGlobalY (float angle)
 
void rotateGlobalZ (float angle)
 
quaternion getRotation () const
 
quaternion getRotationGlobal () const
 
float3 getRotationEulerAngles () const
 
float3 getRotationEulerAnglesGlobal () const
 
virtual void scale (float scale)
 
void setScale (const float3 &scale)
 
void setRotation (const quaternion &quat)
 
void setRotationGlobal (const quaternion &quat)
 
void setRotation (const float3 &rot)
 
void setRotationX (float angle)
 
void setRotationY (float angle)
 
void setRotationZ (float angle)
 
float getRotationX () const
 
float getRotationY () const
 
float getRotationZ () const
 
float getRotationGlobalX () const
 
float getRotationGlobalY () const
 
float getRotationGlobalZ () const
 
void setRotationGlobalX (float angle)
 
void setRotationGlobalY (float angle)
 
void setRotationGlobalZ (float angle)
 
float3 getScale () const
 
float3 getScaleGlobal () const
 
template<typename T = Node>
const std::shared_ptr< T > & addChild (const std::shared_ptr< T > &child, bool async=false)
 
template<typename T = Node>
bool removeChild (const std::shared_ptr< T > &child)
 
void removeAllChildren (bool async=false)
 
void lookAt (const float3 &target)
 
template<typename T = Node>
std::list< std::shared_ptr< T > > findAllChildrenByGroup (const std::string &groupName, const bool recursive=true) const
 
const std::list< std::string > & getGroups () const
 
void addToGroup (const std::string &group)
 
void removeFromGroup (const std::string &group)
 
virtual bool isVisible () const
 
virtual void setVisible (bool visible=true)
 
bool isInGroup (const std::string &group) const
 
void setProcessMode (const ProcessMode mode)
 
bool isProcessed () const
 
auto getType () const
 
std::string getPath () const
 
virtual void setProperty (const std::string &property, const std::string &value)
 
void printTree (int tab=0) const
 
std::shared_ptr< Node > duplicate (bool recursiveFilter=false) const
 
float3 toGlobal (const float3 &local) const
 
float3 toLocal (const float3 &global) const
 
float3 getRightVector () const
 
float3 getLeftVector () const
 
float3 getFrontVector () const
 
float3 getBackVector () const
 
float3 getUpVector () const
 
float3 getDownVector () const
 
template<typename T >
bool haveChild (const std::shared_ptr< T > &child, const bool recursive=true) const
 
template<typename T = Node>
std::shared_ptr< T > getChild (const std::string &name) const
 
template<typename T = Node>
std::shared_ptr< T > getChildByPath (const std::string &path) const
 
template<typename T = Node>
std::string getRelativePath (const std::shared_ptr< T > &root) const
 
template<typename T = Node>
std::shared_ptr< T > findFirstChild (const std::string &name) const
 
template<typename T >
std::shared_ptr< T > findFirstChild (const bool recursive=true) const
 
template<typename T >
std::list< std::shared_ptr< T > > findAllChildren (const bool recursive=true) const
 
template<typename T = Node>
std::list< std::shared_ptr< T > > findAllChildren (const std::string &name, const bool recursive=true) const
 
const std::list< std::shared_ptr< Node > > & getChildren ()
 
const std::list< std::shared_ptr< Node > > & getChildren () const
 
void setName (const std::string &nodeName)
 
template<typename T = Node>
std::shared_ptr< T > getSharedPtr ()
 
const std::string & getName () const
 
template<typename T = Scene>
T * getScene () const
 
const auto & getParent () const
 
bool haveParent () const
 
virtual std::shared_ptr< Node > copy () const
 
void setLuaThis () override
 

Static Public Member Functions

static std::string sanitizeName (const std::string &name)
 

Static Public Attributes

static constexpr auto TypeNames
 Display names for each node Type value, indexed by the Type enum. More...
 

Protected Member Functions

virtual void updateGlobalTransform ()
 

Protected Attributes

float4x4 localTransform {}
 
float4x4 globalTransform {}
 
Scene * scene {nullptr}
 

Member Enumeration Documentation

enum Type

Node type.

Enum ValuesDocumentation
ANIMATION_PLAYER 
CAMERA 
CHARACTER 
COLLISION_AREA 
COLLISION_OBJECT 
DIRECTIONAL_LIGHT 
ENVIRONMENT 
KINEMATIC_BODY 
LIGHT 
MESH_INSTANCE 
NODE 
OMNI_LIGHT 
PHYSICS_BODY 
RAYCAST 
RIGID_BODY 
SKYBOX 
SPOT_LIGHT 
STATIC_BODY 
VIEWPORT 

Constructor & Destructor Documentation

Node ( const Node &  node)

Creates a node by copying the transforms, process mode, type and name

Node ( const std::string &  name = TypeNames[NODE],
Type  type = NODE 
)

Creates a new node at (0.0, 0.0, 0.0) without a parent

virtual ~Node ( )
virtualdefault

Member Function Documentation

const std::shared_ptr<T>& addChild ( const std::shared_ptr< T > &  child,
bool  async = false 
)
inline

Adds a child node.
Nodes can have any number of children, but a child can have only one parent.
The node will be added to the scene at the start of the next frame.

Parameters
childthe node to add
asyncif true and the node has children all the nodes will be added in batch mode. Be careful to set the visibility of the nodes to falseor they will appear slowly in the scene.
void addToGroup ( const std::string &  group)
inline

Adds the node to the group. Groups can be helpful to organize a subset of nodes, for example "enemies" or "stairs".

virtual std::shared_ptr<Node> copy ( ) const
virtual

Returns a deep copy of this node and its subtree.

Reimplemented in lysa::nodes::MeshInstance::copy(), lysa::nodes::Viewport::copy(), lysa::nodes::Environment::copy()

std::shared_ptr<Node> duplicate ( bool  recursiveFilter = false) const

Duplicates a node. Warning: not implemented on all node types, check documentation for the node type before using it.

std::list<std::shared_ptr<T> > findAllChildren ( const bool  recursive = true) const
inline

Finds all children by type

std::list<std::shared_ptr<T> > findAllChildren ( const std::string &  name,
const bool  recursive = true 
) const
inline

Finds all children by name

std::list<std::shared_ptr<T> > findAllChildrenByGroup ( const std::string &  groupName,
const bool  recursive = true 
) const
inline

Finds all children by group

std::shared_ptr<T> findFirstChild ( const bool  recursive = true) const
inline

Finds the first child by is type.

std::shared_ptr<T> findFirstChild ( const std::string &  name) const
inline

Finds the first child by is name.

float3 getBackVector ( ) const
inline

Returns the normalized back vector

std::shared_ptr<T> getChild ( const std::string &  name) const
inline

Returns the child node by is name. Not recursive

std::shared_ptr<T> getChildByPath ( const std::string &  path) const
inline

Returns the child node by its relative path (does not start with '/')

const std::list<std::shared_ptr<Node> >& getChildren ( )
inline

Returns the immutable list of children nodes

const std::list<std::shared_ptr<Node> >& getChildren ( ) const
inline

Returns the immutable list of children nodes

float3 getDownVector ( ) const
inline

Returns the normalized down vector

float3 getFrontVector ( ) const
inline

Returns the normalized front vector

const std::list<std::string>& getGroups ( ) const
inline

Returns an immutable list of group names that the node has been added to.

auto getId ( ) const
inline

Returns the unique id of the node

float3 getLeftVector ( ) const
inline

Returns the normalized left vector

const std::string& getName ( ) const
inline

Returns the node's display name.

const auto& getParent ( ) const
inline

Returns the node's parent in the scene tree

std::string getPath ( ) const

Returns the absolute node path

float3 getPosition ( ) const
inline

Returns the local space position (relative to parent)

float3 getPositionGlobal ( ) const
inline

Returns the world space position

std::string getRelativePath ( const std::shared_ptr< T > &  root) const
inline
float3 getRightVector ( ) const
inline

Returns the normalized right vector

quaternion getRotation ( ) const

Returns the rotation of the local transformation

float3 getRotationEulerAngles ( ) const
inline

Returns the rotation of the local transformation, in euler angles in radians

float3 getRotationEulerAnglesGlobal ( ) const
inline

Returns the rotation of the world transformation, in euler angles in radians

quaternion getRotationGlobal ( ) const

Returns the rotation of the world transformation

float getRotationGlobalX ( ) const

Returns the X axis rotation of the global transformation

float getRotationGlobalY ( ) const

Returns the Y axis rotation of the global transformation

float getRotationGlobalZ ( ) const

Returns the Z axis rotation of the global transformation

float getRotationX ( ) const

Returns the X axis rotation of the local transformation

float getRotationY ( ) const

Returns the Y axis rotation of the local transformation

float getRotationZ ( ) const

Returns the Z axis rotation of the local transformation

float3 getScale ( ) const

Returns the scale part of the local transformation.

float3 getScaleGlobal ( ) const

Returns the scale part of the global transformation.

T* getScene ( ) const
inline

Returns the scene this node belongs to, cast to type T, or nullptr if not in a scene.

std::shared_ptr<T> getSharedPtr ( )
inline

Returns a shared_ptr to this node, optionally cast to type T.

const float4x4& getTransform ( ) const
inline

Returns the local space transformation matrix

const float4x4& getTransformGlobal ( ) const
inline

Returns the world space transformation matrix

auto getType ( ) const
inline

Returns the node type

float3 getUpVector ( ) const
inline

Returns the normalized up vector

bool haveChild ( const std::shared_ptr< T > &  child,
const bool  recursive = true 
) const
inline

Returns true if the node has this child

bool haveParent ( ) const
inline

Returns true if this node has a parent in the scene tree.

bool isInGroup ( const std::string &  group) const
inline

Returns true if this node has been added to the given group

bool isProcessed ( ) const

Returns true if the node is processed and receive input callbacks

virtual bool isVisible ( ) const
inlinevirtual

Returns the visibility of the node.

void lookAt ( const float3 &  target)

Rotate the node toward the target

virtual void onEnterScene ( )
inlinevirtual

Called when a node is added to the scene

virtual void onExitScene ( )
inlinevirtual

Called when a node is removed from the scene

virtual bool onInput ( const InputEvent &  inputEvent)
inlinevirtual

Called on a keyboard, mouse, or gamepad event

virtual void onPhysicsProcess ( const float  delta)
inlinevirtual

Called just after the physics system has been updated (can be called multiple times if we have free time between frames)

virtual void onProcess ( const float  alpha)
inlinevirtual

Called each frame after the physics have been updated and just before drawing the frame

virtual void onReady ( )
inlinevirtual

Called when a node is ready to initialize, before being added to the scene

void printTree ( int  tab = 0) const

Recursively prints the node tree in the log system

void removeAllChildren ( bool  async = false)

Removes all children nodes. The nodes, along with their children can be deleted depending on their reference counters. The nodes will be removed from the scene at the start of the next frame.

Parameters
asyncif true and the nodes will be removed in batch mode. Be careful to set the visibility of the nodes to false or they will disappear slowly from the scene.
bool removeChild ( const std::shared_ptr< T > &  child)
inline

Removes a child node. The node, along with its children can be deleted depending on their reference counter.
Use the iterator version in a for-each loop.
The node will be removed from the scene at the start of the next frame.

Parameters
childthe node to remove
asyncif true and the node have children all the nodes will be removed in batch mode. Be careful to set the visibility of the nodes to false or they will disappear slowly from the scene.
void removeFromGroup ( const std::string &  group)
inline

Removes the node from the given group. Does nothing if the node is not in the group

void rotate ( const quaternion &  quaternion)

Rotates the local transformation

void rotateGlobalX ( float  angle)

Rotates the global transformation around the X axis by angle in radians.

void rotateGlobalY ( float  angle)

Rotates the global transformation around the Y axis by angle in radians.

void rotateGlobalZ ( float  angle)

Rotates the global transformation around the Z axis by angle in radians.

void rotateX ( float  angle)

Interpolate the local transformation

Rotates the local transformation around the X axis by angle in radians.

void rotateY ( float  angle)

Rotates the local transformation around the Y axis by angle in radians.

void rotateZ ( float  angle)

Rotates the local transformation around the Z axis by angle in radians.

static std::string sanitizeName ( const std::string &  name)
static

Returns a sanitized copy of name with characters that are invalid in node identifiers replaced or removed.

virtual void scale ( float  scale)
virtual

Scale the local transformation

void setLuaThis ( )
override
void setName ( const std::string &  nodeName)
inline

Sets the node name (purely informative)

virtual void setPosition ( const float  x,
const float  y,
const float  z 
)
inlinevirtual

Sets the local space position (relative to parent)

virtual void setPosition ( const float3 &  position)
virtual

Sets the local space position (relative to parent)

virtual void setPositionGlobal ( const float  x,
const float  y,
const float  z 
)
inlinevirtual

Sets the world space position

virtual void setPositionGlobal ( const float3 &  position)
virtual

Sets the world space position

void setProcessMode ( const ProcessMode  mode)
inline

Changes the node's processing behavior.

virtual void setProperty ( const std::string &  property,
const std::string &  value 
)
virtual

Sets a property by its name and value. Currently, not all properties in all node classes are supported.

Reimplemented in lysa::nodes::MeshInstance::setProperty(), lysa::nodes::Environment::setProperty()

void setRotation ( const float3 &  rot)

Sets the local rotation

void setRotation ( const quaternion &  quat)

Sets the local rotation

void setRotationGlobal ( const quaternion &  quat)

Sets the world rotation

void setRotationGlobalX ( float  angle)

Sets the X axis rotation of the global transformation by angle in radians.

void setRotationGlobalY ( float  angle)

Sets the Y axis rotation of the global transformation by angle in radians.

void setRotationGlobalZ ( float  angle)

Sets the Z axis rotation of the global transformation by angle in radians.

void setRotationX ( float  angle)

Sets the X axis rotation of the local transformation by angle in radians.

void setRotationY ( float  angle)

Sets the Y axis rotation of the local transformation by angle in radians.

void setRotationZ ( float  angle)

Sets the Z axis rotation of the local transformation by angle in radians.

void setScale ( const float3 &  scale)

Sets the local scale

void setTransform ( const float4x4 &  transform)

Sets the local transformation matrix

virtual void setVisible ( bool  visible = true)
virtual

Changes the visibility of the node.
The node stays in the scene tree and the data in VRAM.

Reimplemented in lysa::nodes::MeshInstance::setVisible()

float3 toGlobal ( const float3 &  local) const

Transforms a local vector from this node's local space to world space.

float3 toLocal ( const float3 &  global) const

Transforms a world space vector to this node's local space.

void translate ( const float  x,
const float  y,
const float  z 
)
inline

Changes the node's position by the given offset vector in local space.

void translate ( const float3 &  localOffset)

Changes the node's position by the given offset vector in local space.

virtual void updateGlobalTransform ( )
protectedvirtual

Member Data Documentation

float4x4 globalTransform {}
protected
float4x4 localTransform {}
protected
Scene* scene {nullptr}
protected
constexpr auto TypeNames
staticconstexpr
Initial value:
std::array {
"AnimationPlayer",
"Camera",
"Character",
"CollisionArea",
"CollisionObject",
"DirectionalLight",
"Environment",
"KinematicBody",
"Light",
"MeshInstance",
"Node",
"OmniLight",
"PhysicsBody",
"RayCast",
"RigidBody",
"Skybox",
"SpotLight",
"StaticBody",
"Viewport"
}

Display names for each node Type value, indexed by the Type enum.