BlankMat 0.1.0
Free open-source 3D texture creation application
Loading...
Searching...
No Matches
Node Class Reference

Node used to group together other nodes and meshes in a scene. More...

Inheritance diagram for Node:
Collaboration diagram for Node:

Public Member Functions

void Read (const std::string &scope, std::ifstream &file, bool clear) override
 Reads child nodes for this node from the file.
 
void Write (std::ofstream &file) override
 Writes this node to the file.
 
void Clear () override
 Recursively deletes this node's children.
 
unsigned int WriteCount ()
 Returns the number of elements that can be written.
 
unsigned int ChildCount ()
 Returns the number of child nodes.
 
unsigned int MeshCount ()
 Returns the number of child meshes.
 
void Draw (Shader *shader, State *state, Material *defaultMat, const glm::mat4 &viewProj, bool drawMats=false) override
 Recursively draws the node and its children and child meshes.
 
void DrawShadows (Shader *shader, State *state)
 Recursively draws the node's and children's shadows.
 
void RecalcMatrices () override
 Recalculates all matrices of the node.
 
bool HasMesh (Mesh *mesh)
 Returns whether the node has the given mesh.
 
bool HasNode (const std::string &child)
 Returns whether the node has the given child.
 
bool IsRootNode ()
 Returns whether this node is the root node.
 
int GetNodeIndex (const std::string &child)
 Returns the index of the given node or -1 if not found.
 
int GetMeshIndex (Mesh *mesh)
 Returns the index of the given mesh or -1 if not found.
 
NodeGetChild (unsigned int index)
 Returns the child node with the given index, or none if out of bounds.
 
MeshGetMesh (unsigned int index)
 Returns the mesh with the given index, or none if out of bounds.
 
void UpdateEnabledStatus () override
 Updates the enabled status of the object and its children.
 
NodeFindNode (const std::string &name)
 Recursively searches for the node with the given name.
 
MeshFindMesh (const std::string &name)
 Recursively searches for the mesh with the given name.
 
void LoadMeshes (MeshContainer *meshes)
 Recursively loads the unloaded child meshes of this and child nodes.
 
void AddMeshName (const std::string &name)
 Adds the name of the mesh to the node, so that the mesh can later be obtained from a mesh container.
 
void AddMesh (Mesh *mesh)
 Adds a mesh for the node.
 
void AddChild (Node *child)
 Adds a child to the node.
 
bool MoveMesh (Mesh *mesh, Node *other)
 Moves the given mesh from this node to the given node.
 
bool MoveChild (const std::string &child, Node *other)
 Moves the given child node from this node to the given node.
 
bool TryDelete (Node *node)
 Attempts to delete the given node. Does nothing if the node is root or is null.
 
bool DeleteNode (const std::string &name)
 Removes the node with the given name along with its children.
 
bool DeleteMesh (const std::string &name)
 Removes the given mesh from the node that holds it.
 
bool DeleteChild (Node *node)
 Deletes the given child node if it is a direct child of this node.
 
 Node (Node *parent)
 Creates a default node under the given parent.
 
 Node (Node *parent, const std::string &name, const std::string &scope, const glm::vec3 &pos=glm::vec3(0.0f), const glm::vec3 &rot=glm::vec3(0.0f), const glm::vec3 &scale=glm::vec3(1.0f))
 Creates a scene node with the given parent and name.
 
- Public Member Functions inherited from IEntity
virtual const glm::vec3 GetPos ()
 
virtual const glm::vec3 GetRot ()
 
virtual const glm::vec3 GetScale ()
 
virtual MaterialGetMaterial ()
 
const glm::vec3 GetUp ()
 
const glm::vec3 GetRight ()
 
const glm::vec3 GetFront ()
 
void Translate (const glm::vec3 &delta)
 
void Rotate (const glm::vec3 &delta)
 
void Scale (const glm::vec3 &delta)
 
const glm::vec3 GetWorldPos ()
 
virtual void SetPos (const glm::vec3 &pos)
 
virtual void SetRot (const glm::vec3 &rot)
 
virtual void SetScale (const glm::vec3 &scale)
 
void CalcBasis ()
 
void LoadMaterial (MaterialContainer *materials)
 
virtual void SetMaterial (Material *material)
 
bool IsEnabled ()
 
bool IsEnabledInHierarchy ()
 
void Enable (bool shouldEnable=true)
 
void EnableParent (bool shouldEnable)
 
bool ToggleEnabled ()
 
virtual void SetParentModelMatrix (const glm::mat4 &parentModelMatrix)
 
const glm::mat4 & GetModelMatrix ()
 
const glm::mat4 & GetParentModelMatrix ()
 
const glm::mat4 & GetSelfModelMatrix ()
 
const glm::mat3 & GetNormalModelMatrix ()
 
 IEntity (const std::string &name="", const std::string &scope="", Material *material=nullptr, bool drawOver=false, const glm::vec3 &pos=glm::vec3(0.0f), const glm::vec3 &rot=glm::vec3(0.0f), const glm::vec3 &scale=glm::vec3(1.0f))
 
 IEntity (const std::string &name, const std::string &scope, const std::string &material, bool drawOver=false, const glm::vec3 &pos=glm::vec3(0.0f), const glm::vec3 &rot=glm::vec3(0.0f), const glm::vec3 &scale=glm::vec3(1.0f))
 
virtual void Cleanup ()
 
- Public Member Functions inherited from ISelectable
virtual SelectableType GetSelectableType ()
 Returns the type of the selectable.
 
 ISelectable (SelectableType type=SelectableType::NONE)
 Sets the type of the selectable.
 
- Public Member Functions inherited from INameable
virtual void Rename (const std::string &newName, bool includeScope=true)
 Renames the object, setting the scope to be the scoped part of the name.
 
virtual void SetName (const std::string &name)
 Sets the name of the object. Note: Does not set the scope variable. If renaming based on raw input, use Rename() instead to set the scope.
 
virtual void SetScope (const std::string &scope)
 Sets the scope of the object.
 
std::string GetUnscopedName ()
 Returns the unscoped name of the object.
 
std::string GetScope ()
 Returns the scope of the object.
 
std::string GetScopedName ()
 Returns the scoped name of the object.
 
void InitName (const std::string &name, const std::string &scope="")
 Initializes the nameable object with the given name and scope.
 
 INameable ()
 Creates a default nameable object without name or scope.
 

Protected Member Functions

void GenBuffers () override
 Generates buffers. Nodes have no buffers.
 
NodeReadRecurse (const std::string &scope, std::ifstream &file, Node *parent)
 Recursively reads all nodes from the given file.
 
void WriteRecurse (std::ofstream &file, Node *node, unsigned int depth=0)
 Recursively writes all nodes into the given file.
 

Protected Attributes

NodemParent
 Parent node of this node. Nullptr if this is the root node.
 
std::vector< Node * > mChildren
 List of child nodes.
 
std::vector< Mesh * > mMeshes
 List of contained meshes.
 
std::unordered_set< std::string > mUnloadedMeshes
 List of mesh names to load eventually.
 
- Protected Attributes inherited from IEntity
unsigned int mVAO = 0
 
unsigned int mVBO = 0
 
unsigned int mEBO = 0
 
bool mDrawOver = false
 
glm::vec3 mFront = glm::vec3(0.0f)
 
glm::vec3 mRight = glm::vec3(0.0f)
 
glm::vec3 mUp = glm::vec3(0.0f)
 
glm::vec3 mPos = glm::vec3(0.0f)
 
glm::vec3 mRot = glm::vec3(0.0f)
 
glm::vec3 mScale = glm::vec3(1.0f)
 
bool mIsEnabled = true
 
bool mIsEnabledSelf = true
 
bool mIsEnabledParent = true
 
MaterialmMaterial = nullptr
 
std::string mMaterialName = ""
 
bool mRecalcMatrices = true
 
glm::mat4 mParentModelMatrix = glm::mat4(1.0f)
 
glm::mat4 mSelfModelMatrix = glm::mat4(1.0f)
 
glm::mat4 mModelMatrix = glm::mat4(1.0f)
 
glm::mat3 mNormalModelMatrix = glm::mat3(1.0f)
 
- Protected Attributes inherited from ISelectable
SelectableType mSelectableType = SelectableType::NONE
 Type of the selectable.
 
- Protected Attributes inherited from INameable
std::string mName = ""
 Name of the object.
 
std::string mScope = ""
 Scope of the object.
 

Additional Inherited Members

- Static Public Member Functions inherited from IEntity
static const std::string GetNameNullSafe (IEntity *entity)
 

Detailed Description

Node used to group together other nodes and meshes in a scene.

Constructor & Destructor Documentation

◆ Node() [1/2]

Node::Node ( Node parent)

Creates a default node under the given parent.

Parameters
parentParent node or nulltpr

◆ Node() [2/2]

Node::Node ( Node parent,
const std::string &  name,
const std::string &  scope,
const glm::vec3 &  pos = glm::vec3(0.0f),
const glm::vec3 &  rot = glm::vec3(0.0f),
const glm::vec3 &  scale = glm::vec3(1.0f) 
)

Creates a scene node with the given parent and name.

Parameters
parentParent node or nullptr
nameName of this node
scopeScope of this node
posPosition of the node
rotRotation of the node
scaleScale of the node

Member Function Documentation

◆ AddChild()

void Node::AddChild ( Node child)

Adds a child to the node.

Parameters
childChild node to add

◆ AddMesh()

void Node::AddMesh ( Mesh mesh)

Adds a mesh for the node.

Parameters
meshMesh to add

◆ AddMeshName()

void Node::AddMeshName ( const std::string &  name)

Adds the name of the mesh to the node, so that the mesh can later be obtained from a mesh container.

Parameters
nameName of the mesh

◆ ChildCount()

unsigned int Node::ChildCount ( )

Returns the number of child nodes.

Returns
Number of child nodes

◆ Clear()

void Node::Clear ( )
overridevirtual

Recursively deletes this node's children.

Implements IWritable.

◆ DeleteChild()

bool Node::DeleteChild ( Node node)

Deletes the given child node if it is a direct child of this node.

Parameters
nodeNode to delete
Returns
Whether deletion was successful

◆ DeleteMesh()

bool Node::DeleteMesh ( const std::string &  name)

Removes the given mesh from the node that holds it.

Parameters
nameName of the mesh
Returns
Whether the mesh was found and removed

◆ DeleteNode()

bool Node::DeleteNode ( const std::string &  name)

Removes the node with the given name along with its children.

Parameters
nameName of child node to delete
Returns
Whether the deletion happened or not

◆ Draw()

void Node::Draw ( Shader shader,
State state,
Material defaultMat,
const glm::mat4 &  viewProj,
bool  drawMats = false 
)
overridevirtual

Recursively draws the node and its children and child meshes.

Parameters
shaderShader to draw to
stateGlobal state of the application
defaultMatDefault material of the scene
viewProjProjection * View Matrix of the camera
modelCombined model matrix of all parents

Implements IEntity.

◆ DrawShadows()

void Node::DrawShadows ( Shader shader,
State state 
)
virtual

Recursively draws the node's and children's shadows.

Parameters
shaderShadow shader
stateGlobal state of the application
modelModel matrix

Implements IEntity.

◆ FindMesh()

Mesh * Node::FindMesh ( const std::string &  name)

Recursively searches for the mesh with the given name.

Parameters
nameName of the mesh
Returns
Mesh with the given name or nullptr if not found

◆ FindNode()

Node * Node::FindNode ( const std::string &  name)

Recursively searches for the node with the given name.

Parameters
nameNode to search for
Returns
Node with the given name or nullptr if not found

◆ GenBuffers()

void Node::GenBuffers ( )
inlineoverrideprotectedvirtual

Generates buffers. Nodes have no buffers.

Implements IEntity.

◆ GetChild()

Node * Node::GetChild ( unsigned int  index)

Returns the child node with the given index, or none if out of bounds.

Parameters
indexIndex of the child node to find
Returns
Node with given index or null

◆ GetMesh()

Mesh * Node::GetMesh ( unsigned int  index)

Returns the mesh with the given index, or none if out of bounds.

Parameters
indexIndex of the mesh to find
Returns
Mesh with given index or null

◆ GetMeshIndex()

int Node::GetMeshIndex ( Mesh mesh)

Returns the index of the given mesh or -1 if not found.

Parameters
meshMesh to search for
Returns
Index of the given mesh or -1

◆ GetNodeIndex()

int Node::GetNodeIndex ( const std::string &  child)

Returns the index of the given node or -1 if not found.

Parameters
childChild node to search for
Returns
Index of the node with the given name

◆ HasMesh()

bool Node::HasMesh ( Mesh mesh)

Returns whether the node has the given mesh.

Parameters
meshMesh to search for
Returns
Whether the mesh was found or not

◆ HasNode()

bool Node::HasNode ( const std::string &  child)

Returns whether the node has the given child.

Parameters
childChild node to search for
Returns
Whether the node was found or not

◆ IsRootNode()

bool Node::IsRootNode ( )

Returns whether this node is the root node.

Returns
Whether this node is the root node

◆ LoadMeshes()

void Node::LoadMeshes ( MeshContainer meshes)

Recursively loads the unloaded child meshes of this and child nodes.

Parameters
meshesScene mesh list

◆ MeshCount()

unsigned int Node::MeshCount ( )

Returns the number of child meshes.

Returns
Number of child meshes

◆ MoveChild()

bool Node::MoveChild ( const std::string &  child,
Node other 
)

Moves the given child node from this node to the given node.

Parameters
childName of the child node to move
otherNode to move child node to
Returns
Whether the moving was successful

◆ MoveMesh()

bool Node::MoveMesh ( Mesh mesh,
Node other 
)

Moves the given mesh from this node to the given node.

Parameters
meshMesh to move
otherNode to move mesh to
Returns
Whether the moving was successful

◆ Read()

void Node::Read ( const std::string &  scope,
std::ifstream &  file,
bool  clear 
)
overridevirtual

Reads child nodes for this node from the file.

Parameters
scopeScope to read in
fileFile to read from
clearWhether to overwrite the contents of the item

Implements IWritable.

◆ ReadRecurse()

Node * Node::ReadRecurse ( const std::string &  scope,
std::ifstream &  file,
Node parent 
)
protected

Recursively reads all nodes from the given file.

Parameters
scopeScope to read in
fileFile to read
parentParent node
Returns
Node that was stored in the file

◆ RecalcMatrices()

void Node::RecalcMatrices ( )
overridevirtual

Recalculates all matrices of the node.

Reimplemented from IEntity.

◆ TryDelete()

bool Node::TryDelete ( Node node)

Attempts to delete the given node. Does nothing if the node is root or is null.

Parameters
nodeNode to delete
Returns
Whether the item was deleted or not

◆ UpdateEnabledStatus()

void Node::UpdateEnabledStatus ( )
overridevirtual

Updates the enabled status of the object and its children.

Reimplemented from IEntity.

◆ Write()

void Node::Write ( std::ofstream &  file)
overridevirtual

Writes this node to the file.

Parameters
fileFile to output to

Implements IWritable.

◆ WriteCount()

unsigned int Node::WriteCount ( )
virtual

Returns the number of elements that can be written.

Returns
Number of writable elements

Implements IWritable.

◆ WriteRecurse()

void Node::WriteRecurse ( std::ofstream &  file,
Node node,
unsigned int  depth = 0 
)
protected

Recursively writes all nodes into the given file.

Parameters
fileFile to write to
nodeNode to write
depthDepth of the node to write

Member Data Documentation

◆ mChildren

std::vector<Node*> Node::mChildren
protected

List of child nodes.

◆ mMeshes

std::vector<Mesh*> Node::mMeshes
protected

List of contained meshes.

◆ mParent

Node* Node::mParent
protected

Parent node of this node. Nullptr if this is the root node.

◆ mUnloadedMeshes

std::unordered_set<std::string> Node::mUnloadedMeshes
protected

List of mesh names to load eventually.