Lysa  0.0
Lysa 3D 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)
 
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 (InputEvent &inputEvent)
 
void setTransformLocal (const float4x4 &transform)
 
const float4x4 & getTransformGlobal () const
 
const float4x4 & getTransform () 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 (float x, float y, float z)
 
virtual void setPositionGlobal (const float3 &position)
 
virtual void setPositionGlobal (const float x, const float y, const float z)
 
float3 getPositionGlobal () const
 
void rotateX (float angle)
 
void rotateY (float angle)
 
void rotateZ (float angle)
 
quaternion getRotation () const
 
quaternion getRotationGlobal () const
 
float3 getRotationEulerAngles () const
 
float3 getRotationEulerAnglesGlobal () const
 
virtual void scale (float scale)
 
void setRotation (const quaternion &quat)
 
void setRotationGlobal (const quaternion &quat)
 
void setRotationX (float angle)
 
void setRotationY (float angle)
 
void setRotationZ (float angle)
 
float getRotationX () const
 
float getRotationY () const
 
float getRotationZ () const
 
float3 getScale () const
 
float3 getScaleGlobal () const
 
auto * getParent () const
 
bool addChild (std::shared_ptr< Node > child, bool async=false)
 
bool removeChild (const std::shared_ptr< Node > &child, bool async=false)
 
void removeAllChildren (bool async=false)
 
bool haveChild (const std::shared_ptr< Node > &child, bool recursive) const
 
void lookAt (const float3 &target)
 
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::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
 
template<typename T = Node>
std::list< std::shared_ptr< T > > findAllChildrenByGroup (const std::string &groupName, const bool recursive=true) const
 
const std::list< std::shared_ptr< Node > > & getChildren () const
 
const std::list< std::string > & getGroups () const
 
void addToGroup (const std::string &group)
 
void removeFromGroup (const std::string &group)
 
bool isVisible () const
 
virtual void setVisible (bool visible=true)
 
auto isInGroup (const std::string &group) const
 
void setProcessMode (const ProcessMode mode)
 
bool isProcessed () const
 
auto getType () const
 
auto getViewport () const
 
const std::string & getName () 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
 
void setName (const std::string &nodeName)
 
template<typename T >
std::shared_ptr< TweencreatePropertyTween (typename PropertyTween< T >::Setter set, const T initial, const T final, float duration, const TransitionType ttype=TransitionType::LINEAR, const Tween::Callback &callback=nullptr)
 
void killTween (const std::shared_ptr< Tween > &tween)
 
auto getSharedPtr ()
 
 ~Node () override = default
 
- Public Member Functions inherited from Object
void connect (const Signal::signal &name, const Signal::Handler &handler)
 
void connect (const Signal::signal &name, const std::function< void ()> &handler)
 
void emit (const Signal::signal &name, void *params=nullptr)
 
virtual std::string toString () const
 
 Object () = default
 
virtual ~Object () = default
 
- Public Member Functions inherited from Updatable
auto isUpdated () const
 
void decrementUpdates ()
 
void setUpdated ()
 
void setMaxUpdates (const uint32 maxUpdates)
 

Static Public Attributes

static constexpr auto TypeNames
 

Protected Member Functions

virtual std::shared_ptr< Node > duplicateInstance () const
 
virtual void updateGlobalTransform ()
 
virtual void ready ()
 
virtual void physicsProcess (float delta)
 
virtual void process (float alpha)
 
virtual void enterScene ()
 
virtual void exitScene ()
 
virtual void attachToViewport (Viewport *viewport)
 
virtual void detachFromViewport ()
 
virtual void pause ()
 
virtual void resume ()
 

Protected Attributes

float4x4 localTransform {}
 
float4x4 globalTransform {}
 

Additional Inherited Members

- Public Attributes inherited from Updatable
uint32 pendingUpdates {0}
 
uint32 maxUpdates {0}
 

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

~Node ( )
overridedefault

Member Function Documentation

bool addChild ( std::shared_ptr< Node >  child,
bool  async = false 
)

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 have 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".

std::shared_ptr<Tween> createPropertyTween ( typename PropertyTween< T >::Setter  set,
const T  initial,
const T  final,
float  duration,
const TransitionType  ttype = TransitionType::LINEAR,
const Tween::Callback callback = nullptr 
)
inline

Creates a Tween to tweens a property of the node between an initial value and final value in a span of time equal to duration, in seconds.

virtual void detachFromViewport ( )
protectedvirtual
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.

virtual void exitScene ( )
protectedvirtual
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 ( ) 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 a 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 name

auto* getParent ( ) const
inline

Returns the node's parent in the scene tree

std::string getPath ( ) const

Returns the node path

float3 getPosition ( ) const
inline

Returns the local space position (relative to parent)

float3 getPositionGlobal ( ) const
inline

Returns the world space position

float3 getRightVector ( ) const
inline

Returns the normalized right vector

quaternion getRotation ( ) const

Returns the rotation of the local transformation

float3 getRotationEulerAngles ( ) const

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

float3 getRotationEulerAnglesGlobal ( ) const

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

quaternion getRotationGlobal ( ) const

Returns the rotation of the world 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.

auto getSharedPtr ( )
inline
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

auto getViewport ( ) const
inline

Returns the attached rendering window or nullptr if the node is not attached to a window.

bool haveChild ( const std::shared_ptr< Node > &  child,
bool  recursive 
) const

Returns true if the node have this child

auto 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

bool isVisible ( ) const
inline

Returns the visibility of the node.

void killTween ( const std::shared_ptr< Tween > &  tween)

Removes the tween from the processing list

void lookAt ( const float3 &  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 ( 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

virtual void pause ( )
protectedvirtual
virtual void physicsProcess ( float  delta)
protectedvirtual
void printTree ( int  tab = 0) const

Recursively prints the node tree in the log system

virtual void process ( float  alpha)
protectedvirtual
virtual void ready ( )
protectedvirtual
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< Node > &  child,
bool  async = false 
)

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

virtual void resume ( )
protectedvirtual
void rotateX ( float  angle)

Rotates the local transformation

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.

virtual void scale ( float  scale)
virtual

Rotates the local transformation

Scale the local transformation

Reimplemented in lysa::CollisionObject::scale()

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
void setRotation ( const quaternion &  quat)

Sets the local transformation

void setRotationGlobal ( const quaternion &  quat)

Sets the world transformation

void setRotationX ( float  angle)

Sets the local transformation

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 setTransformLocal ( const float4x4 &  transform)

Returns the local space 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::Character::setVisible(), lysa::CollisionObject::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 float3 &  localOffset)

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

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

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

virtual void updateGlobalTransform ( )
protectedvirtual

Friends And Related Function Documentation

friend class Loader
friend
Viewport
friend
friend class Window
friend

Member Data Documentation

float4x4 globalTransform {}
protected
float4x4 localTransform {}
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"
}