Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_node.hpp
Go to the documentation of this file.
1#pragma once
2#include "foray_registry.hpp"
3
4namespace foray::scene {
5
7 class Node : public Registry
8 {
9 public:
10 Node(Scene* scene, Node* parent = nullptr);
11
15
17
18 template <typename TComponent>
19 inline int32_t FindChildrenWithComponent(std::vector<Node*>& outnodes);
20
21 template <typename TComponent>
22 inline int32_t FindComponentsRecursive(std::vector<TComponent*>& outnodes);
23
24 inline virtual ~Node() {}
25
26 protected:
27 Node* mParent = nullptr;
28 std::vector<Node*> mChildren = {};
29 std::string mName = "";
30 };
31
32
33 template <typename TComponent>
34 inline int32_t Node::FindChildrenWithComponent(std::vector<Node*>& outnodes)
35 {
36 int32_t found = 0;
37 for(Node* child : mChildren)
38 {
39 if(child->HasComponent<TComponent>())
40 {
41 found++;
42 outnodes.push_back(child);
43 }
44 found += child->FindChildrenWithComponent<TComponent>(outnodes);
45 }
46 return found;
47 }
48
49 template <typename TComponent>
50 inline int32_t Node::FindComponentsRecursive(std::vector<TComponent*>& outnodes)
51 {
52 int32_t found = 0;
54 for(Node* child : mChildren)
55 {
56 found += child->FindComponentsRecursive<TComponent>(outnodes);
57 }
58 return found;
59 }
60
61} // namespace foray::scene
A scene node. Extends the registry with hierarchical information.
Definition foray_node.hpp:8
std::string mName
Definition foray_node.hpp:29
virtual ~Node()
Definition foray_node.hpp:24
FORAY_PROPERTY_V(Parent)
int32_t FindChildrenWithComponent(std::vector< Node * > &outnodes)
Definition foray_node.hpp:34
Node * mParent
Definition foray_node.hpp:27
int32_t FindComponentsRecursive(std::vector< TComponent * > &outnodes)
Definition foray_node.hpp:50
std::vector< Node * > mChildren
Definition foray_node.hpp:28
FORAY_PROPERTY_R(Children)
ncomp::Transform * GetTransform()
Node(Scene *scene, Node *parent=nullptr)
Manages a type identified list of components.
Definition foray_registry.hpp:12
int32_t GetComponents(std::vector< TComponent * > &out)
Appends all components which can be cast to TComponent type to the out vector.
Definition foray_registry.hpp:145
Provides registries and methods as the anchor of a component based scene.
Definition foray_scene.hpp:17
Defines a nodes transform relative to its parent (or world origin, if no parent is set)
Definition foray_transform.hpp:9
Definition foray_animation.hpp:8