-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathNode.hpp
More file actions
898 lines (704 loc) · 25.6 KB
/
Node.hpp
File metadata and controls
898 lines (704 loc) · 25.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
/* Copyright (c) 2016-2026 Andrew J. MacDonald. All rights reserved. */
#pragma once
#include <Core/containers/Array.hpp>
#include <Core/containers/String.hpp>
#include <Core/memory/RefCountedPtr.hpp>
#include <Core/utilities/Uuid.hpp>
#include <Core/utilities/EnumFlags.hpp>
#include <Core/utilities/StringView.hpp>
#include <Core/utilities/Variant.hpp>
#include <Core/reflection/ObjectBase.hpp>
#include <Core/reflection/Handle.hpp>
#include <scripting/ScriptableDelegate.hpp>
#include <Core/name/Name.hpp>
#include <Core/math/Transform.hpp>
#include <Core/math/Ray.hpp>
#include <Core/math/BoundingBox.hpp>
#include <Core/HashCode.hpp>
#include <Core/Types.hpp>
#include <scene/EntityTag.hpp>
#include <asset/AssetObject.hpp>
namespace Hyperion {
class Scene;
class Node;
class World;
class Entity;
class EditorDelegates;
HYP_ENUM()
enum class NodeFlags : uint32
{
None = 0x0,
IgnoreParentTranslation = 0x1,
IgnoreParentScale = 0x2,
IgnoreParentRotation = 0x4,
IgnoreParentTransform = IgnoreParentTranslation | IgnoreParentScale | IgnoreParentRotation,
ExcludeFromParentBounds = 0x8,
HideInSceneOutline = 0x1000, // Should this node be hidden in the editor's outline window?
Mobility = 0xE000, // ** mask **
MobilityStatic = 0x2000,
MobilityStaticByProxy = 0x4000, // static, but only because its parent is static
MobilityDynamic = Mobility & ~(MobilityStatic | MobilityStaticByProxy),
Default = MobilityStatic
};
HYP_MAKE_ENUM_FLAGS(NodeFlags)
HYP_STRUCT()
struct NodeTag
{
HYP_STRUCT_BODY(NodeTag);
using VariantType = Variant<
int8, int16, int32, int64,
uint8, uint16, uint32, uint64,
float, double,
char,
bool,
Vec2f, Vec3f, Vec4f,
Vec2i, Vec3i, Vec4i,
Vec2u, Vec3u, Vec4u,
String,
Name,
UUID>;
HYP_FIELD(Property = "Name", Serialize = true)
Name name;
HYP_FIELD(Property = "Data", Serialize = true)
VariantType data;
NodeTag() = default;
NodeTag(Name name, const VariantType& data)
: name(name),
data(data)
{
}
NodeTag(Name name, VariantType&& data)
: name(name),
data(std::move(data))
{
}
template <class T>
NodeTag(Name name, T&& value)
: name(name),
data(std::forward<T>(value))
{
}
NodeTag(const NodeTag& other)
: name(other.name),
data(other.data)
{
}
NodeTag& operator=(const NodeTag& other)
{
if (this == &other)
{
return *this;
}
name = other.name;
data = other.data;
return *this;
}
NodeTag(NodeTag&& other) noexcept
: name(std::move(other.name)),
data(std::move(other.data))
{
}
NodeTag& operator=(NodeTag&& other) noexcept
{
if (this == &other)
{
return *this;
}
name = std::move(other.name);
data = std::move(other.data);
return *this;
}
HYP_FORCE_INLINE explicit operator bool() const
{
return data.IsValid();
}
HYP_FORCE_INLINE bool operator!() const
{
return !data.IsValid();
}
HYP_FORCE_INLINE bool IsValid() const
{
return data.IsValid();
}
HYP_FORCE_INLINE bool operator==(const NodeTag& other) const
{
return name == other.name && data == other.data;
}
HYP_FORCE_INLINE bool operator!=(const NodeTag& other) const
{
return name != other.name || data != other.data;
}
HYP_API String ToString() const;
};
struct NodeUnlockTransformScope;
extern void Node_OnPostLoad(Node& node);
HYP_STRUCT()
class NodeTagSet : public HashSet<NodeTag, &NodeTag::name>
{
HYP_STRUCT_BODY(NodeTagSet);
public:
using Base = HashSet<NodeTag, &NodeTag::name>;
using Iterator = typename Base::Iterator;
using ConstIterator = typename Base::ConstIterator;
NodeTagSet() = default;
NodeTagSet(const Base& other)
: Base(other)
{
}
NodeTagSet(Base&& other) noexcept
: Base(std::move(other))
{
}
NodeTagSet(const NodeTagSet& other) = default;
NodeTagSet& operator=(const NodeTagSet& other) = default;
NodeTagSet(NodeTagSet&& other) noexcept = default;
NodeTagSet& operator=(NodeTagSet&& other) noexcept = default;
HYP_FORCE_INLINE bool Has(StringHash name) const
{
return Base::Contains(Name(name));
}
HYP_FORCE_INLINE const NodeTag* Get(StringHash name) const
{
const auto it = Base::Find(Name(name));
if (it != Base::End())
{
return &(*it);
}
return nullptr;
}
HYP_FORCE_INLINE NodeTag* Get(Name name)
{
return const_cast<NodeTag*>(static_cast<const NodeTagSet*>(this)->Get(name));
}
template <class T, class... Args>
NodeTag* Add(Name name, Args&&... args)
{
auto [it, inserted] = Base::Insert(NodeTag { name, NodeTag::VariantType(std::forward<Args>(args)...) });
if (!inserted)
{
// update existing tag
it->data = NodeTag::VariantType(std::forward<Args>(args)...);
}
return &(*it);
}
NodeTag* Add(const NodeTag& tag)
{
NodeTag* pExistingTag = Get(tag.name);
if (pExistingTag != nullptr)
{
// update existing tag
pExistingTag->data = tag.data;
return pExistingTag;
}
auto [it, inserted] = Base::Insert(tag);
return &(*it);
}
NodeTag* Add(NodeTag&& tag)
{
NodeTag* pExistingTag = Get(tag.name);
if (pExistingTag != nullptr)
{
// update existing tag
pExistingTag->data = std::move(tag.data);
return pExistingTag;
}
auto [it, inserted] = Base::Insert(std::move(tag));
return &(*it);
}
bool Remove(StringHash name)
{
return Base::Erase(Name(name));
}
void Clear()
{
Base::Clear();
}
String ToString() const
{
String result = "{ ";
for (const auto& tag : *this)
{
result += tag.ToString() + " ";
}
result += "}";
return result;
}
HYP_DEF_STL_BEGIN_END(Base::Begin(), Base::End())
};
HYP_CLASS(PostLoad = "Node_OnPostLoad")
class HYP_API Node : public AssetObject
{
friend class Scene;
friend class Entity;
HYP_OBJECT_BODY(Node);
public:
class DescendantsIterator
{
public:
DescendantsIterator()
: m_current(nullptr)
{
}
explicit DescendantsIterator(const Node* root)
: m_current(nullptr)
{
if (root != nullptr && root->GetChildren().Any())
{
// Start with first child of root
m_stack.PushBack({ root, 0 });
++(*this);
}
}
DescendantsIterator& operator++()
{
while (m_stack.Any())
{
auto& [node, index] = m_stack.Back();
if (index < node->GetChildren().Size())
{
const Handle<Node>& child = node->GetChildren()[index];
++index;
if (child.IsValid())
{
m_current = child.Get();
if (m_current->GetChildren().Any())
{
m_stack.PushBack({ m_current, 0 });
}
return *this;
}
}
else
{
m_stack.PopBack();
}
}
m_current = nullptr;
return *this;
}
DescendantsIterator operator++(int)
{
DescendantsIterator temp = *this;
++(*this);
return temp;
}
Node* operator*() const
{
return m_current;
}
Node* operator->() const
{
return m_current;
}
bool operator==(const DescendantsIterator& other) const
{
return m_current == other.m_current;
}
bool operator!=(const DescendantsIterator& other) const
{
return m_current != other.m_current;
}
private:
struct StackEntry
{
const Node* node;
size_t index;
};
Node* m_current;
Array<StackEntry> m_stack;
};
class DescendantsView
{
public:
explicit DescendantsView(const Node* node)
: m_node(node)
{
}
DescendantsIterator Begin() const
{
return DescendantsIterator(m_node);
}
DescendantsIterator End() const
{
return DescendantsIterator();
}
DescendantsIterator begin() const
{
return Begin();
}
DescendantsIterator end() const
{
return End();
}
/*! \brief Get the number of descendant nodes.
* \note This method traverses the entire tree to count descendants, so it has O(n) complexity.
* \returns The total count of descendant nodes. */
size_t Size() const
{
size_t count = 0;
for (auto it = Begin(); it != End(); ++it)
{
++count;
}
return count;
}
/*! \brief Get a descendant node by index.
* \param index The index of the descendant to retrieve (0-based).
* \note This method traverses the tree up to the specified index, so it has O(index) complexity.
* For sequential access, prefer using iterators directly.
* \returns A pointer to the node at the specified index, or nullptr if the index is out of bounds. */
Node* operator[](size_t index) const
{
size_t currentIndex = 0;
for (auto it = Begin(); it != End(); ++it)
{
if (currentIndex == index)
{
return *it;
}
++currentIndex;
}
return nullptr;
}
private:
const Node* m_node;
};
using NodeList = Array<Handle<Node>, DynamicAllocator>;
/*! \brief Construct the node, optionally taking in a name string to improve identification.
* \param name The name of the Node.
* \param localTransform An optional parameter representing the local-space transform of this Node.
*/
Node(Name name = Name::Invalid(), const Transform& localTransform = Transform(), Scene* scene = nullptr);
Node(const Node& other) = delete;
Node& operator=(const Node& other) = delete;
Node(Node&& other) noexcept = delete;
Node& operator=(Node&& other) noexcept = delete;
virtual ~Node() override;
HYP_METHOD()
bool HasName() const;
/*! \brief Get the flags of the Node.
* \see NodeFlagBits
* \returns The flags of the Node. */
HYP_METHOD(Property = "NodeFlags", Serialize)
HYP_FORCE_INLINE EnumFlags<NodeFlags> GetNodeFlags() const
{
return m_nodeFlags;
}
/*! \brief Set the flags of the Node.
* \see NodeFlagBits
* \param flags The flags to set on the Node. */
HYP_METHOD(Property = "NodeFlags")
void SetNodeFlags(EnumFlags<NodeFlags> flags);
HYP_METHOD(Property = "Parent", Transient)
HYP_FORCE_INLINE Node* GetParent() const
{
return m_parentNode;
}
HYP_METHOD()
bool IsOrHasParent(const Node* node) const;
HYP_METHOD()
Node* FindParentWithName(UTF8StringView name) const;
HYP_METHOD()
HYP_FORCE_INLINE bool IsRoot() const
{
return m_parentNode == nullptr;
}
/*! \returns A pointer to the Scene this Node and its children are attached to. May be null. */
HYP_METHOD(Property = "Scene", Transient, EditHide)
HYP_FORCE_INLINE Scene* GetScene() const
{
return m_scene;
}
/*! \brief Set the Scene this Node and its children are attached to.
* \internal Not intended to be used in user code. Use Remove() instead. */
HYP_METHOD(Property = "Scene", Transient)
virtual void SetScene(Scene* scene);
/*! \returns A pointer to the World this Node and its children are attached to. May be null. */
HYP_METHOD(Property = "World", Transient, EditHide)
World* GetWorld() const;
/*! \brief \returns The local bounds for this node, not considering child nodes or transform. */
HYP_METHOD(Property = "LocalBounds")
HYP_FORCE_INLINE const BoundingBox& GetLocalBounds() const
{
return m_localBounds;
}
/*! \brief Set the bounds of the Node's content. Does not update the Entity's BoundingBoxComponent.
* \param aabb The bounding box to set
* \note Calls to RefreshEntityTransform() will override this value. */
HYP_METHOD(Property = "LocalBounds")
virtual void SetLocalBounds(const BoundingBox& aabb);
/*! \brief Add the Node as a child of this object, taking ownership over the given Node.
* \param node The Node to be added as achild of this Node
* \returns The added Node */
HYP_METHOD()
Handle<Node> AddChild(const Handle<Node>& node = {});
/*! \brief Remove a child from this Node's child list.
* \param node The child Node to remove from this Node's child list.
* \returns Whether then removal was successful */
bool RemoveChild(const Node* node);
/*! \brief Remove a child at the given index
* \param index The index of the child element to remove
* \returns Whether then removal was successful */
HYP_METHOD()
bool RemoveAt(int index);
/*! \brief Remove this node from the parent Node's list of child Nodes.
* \returns Whether the removal was successful. */
HYP_METHOD()
bool Remove();
HYP_METHOD()
void RemoveAllChildren();
HYP_METHOD()
int NumChildren() const;
/*! \brief Get a child Node from this Node's child list at the given index.
* \param index The index of the child element to return
* \returns The child node at the given index. If the index is out of bounds, nullptr
* will be returned. */
HYP_METHOD()
Handle<Node> GetChild(int index) const;
/*! \brief Search for a (potentially nested) node using the syntax `some/child/node`.
* Each `/` indicates searching a level deeper, so first a child node with the name "some"
* is found, after which a child node with the name "child" is searched for on the previous "some" node,
* and finally a node with the name "node" is searched for from the above "child" node.
* If any level fails to find a node, nullptr is returned.
*
* The string is case-sensitive.
* The '/' can be escaped by using a '\' char. */
HYP_METHOD()
Handle<Node> Select(ANSIStringView selector) const;
/*! \brief Get an iterator for the given child Node from this Node's child list
* \param node The node to find in this Node's child list
* \returns The resulting iterator */
NodeList::Iterator FindChild(const Node* node);
/*! \brief Get an iterator for the given child Node from this Node's child list
* \param node The node to find in this Node's child list
* \returns The resulting iterator */
NodeList::ConstIterator FindChild(const Node* node) const;
/*! \brief Get an iterator for a node by finding it by its name
* \param name The string to compare with the child Node's name
* \returns The resulting iterator */
NodeList::Iterator FindChild(const char* name);
/*! \brief Get an iterator for a node by finding it by its name
* \param name The string to compare with the child Node's name
* \returns The resulting iterator */
NodeList::ConstIterator FindChild(const char* name) const;
/*! \brief Get the child Nodes of this Node.
* \returns Array of child Nodes */
HYP_FORCE_INLINE const NodeList& GetChildren() const
{
return m_childNodes;
}
/*! \brief Get all descendant child Nodes from this Node.
* \returns A view that can be iterated over to traverse all descendant nodes */
DescendantsView GetDescendants() const
{
return DescendantsView(this);
}
/*! \brief Get all descendant child Nodes from this Node as an array.
* \returns A vector of raw pointers to descendant Nodes */
Array<Node*> GetDescendantsArray() const;
/*! \brief Set the local-space translation, scale, rotation of this Node (not influenced by the parent Node) */
HYP_METHOD(Property = "LocalTransform")
void SetLocalTransform(const Transform& transform);
/*! \returns The local-space translation, scale, rotation of this Node. */
HYP_METHOD(Property = "LocalTransform")
HYP_FORCE_INLINE const Transform& GetLocalTransform() const
{
return m_localTransform;
}
/*! \returns The local-space translation of this Node. */
HYP_METHOD(Property = "LocalTranslation", Transient, EditHide)
HYP_FORCE_INLINE const Vec3f& GetLocalTranslation() const
{
return m_localTransform.GetTranslation();
}
/*! \brief Set the local-space translation of this Node (not influenced by the parent Node) */
HYP_METHOD(Property = "LocalTranslation", Transient)
HYP_FORCE_INLINE void SetLocalTranslation(const Vec3f& translation)
{
SetLocalTransform(Transform { translation, m_localTransform.GetScale(), m_localTransform.GetRotation() });
}
/*! \brief Move the Node in local-space by adding the given vector to the current local-space translation.
* \param translation The vector to translate this Node by
*/
HYP_METHOD()
HYP_FORCE_INLINE void Translate(const Vec3f& translation)
{
SetLocalTranslation(m_localTransform.GetTranslation() + translation);
}
/*! \returns The local-space scale of this Node. */
HYP_METHOD(Property = "LocalScale", Transient, EditHide)
HYP_FORCE_INLINE const Vec3f& GetLocalScale() const
{
return m_localTransform.GetScale();
}
/*! \brief Set the local-space scale of this Node (not influenced by the parent Node) */
HYP_METHOD(Property = "LocalScale", Transient)
HYP_FORCE_INLINE void SetLocalScale(const Vec3f& scale)
{
SetLocalTransform(Transform { m_localTransform.GetTranslation(), scale, m_localTransform.GetRotation() });
}
/*! \brief Scale the Node in local-space by multiplying the current local-space scale by the given scale vector.
* \param scale The vector to scale this Node by */
HYP_METHOD()
HYP_FORCE_INLINE void Scale(const Vec3f& scale)
{
SetLocalScale(m_localTransform.GetScale() * scale);
}
/*! \returns The local-space rotation of this Node. */
HYP_METHOD(Property = "LocalRotation", Transient, EditHide)
HYP_FORCE_INLINE const Quaternion& GetLocalRotation() const
{
return m_localTransform.GetRotation();
}
/*! \brief Set the local-space rotation of this Node (not influenced by the parent Node) */
HYP_METHOD(Property = "LocalRotation", Transient)
HYP_FORCE_INLINE void SetLocalRotation(const Quaternion& rotation)
{
SetLocalTransform(Transform { m_localTransform.GetTranslation(), m_localTransform.GetScale(), rotation });
}
/*! \brief Rotate the Node by multiplying the current local-space rotation by the given quaternion.
* \param rotation The quaternion to rotate this Node by */
HYP_METHOD()
HYP_FORCE_INLINE void Rotate(const Quaternion& rotation)
{
SetLocalRotation(m_localTransform.GetRotation() * rotation);
}
/*! \brief \returns The world-space matrix */
HYP_METHOD(Property = "WorldMatrix", Transient, EditHide)
const Mat4f& GetWorldMatrix() const
{
return m_worldMatrix;
}
/*! \returns The world-space translation of this Node. */
HYP_METHOD(Property = "WorldTranslation", Transient, EditHide)
Vec3f GetWorldTranslation() const;
/*! \brief Set the world-space translation of this Node by offsetting the local-space translation */
HYP_METHOD(Property = "WorldTranslation", Transient)
void SetWorldTranslation(const Vec3f& translation);
/*! \returns The local-space scale of this Node. */
HYP_METHOD(Property = "WorldScale", Transient, EditHide)
Vec3f GetWorldScale() const;
/*! \brief Set the local-space scale of this Node by offsetting the local-space scale */
HYP_METHOD(Property = "WorldScale", Transient)
void SetWorldScale(const Vec3f& scale);
/*! \returns The world-space rotation of this Node. */
HYP_METHOD(Property = "WorldRotation", Transient, EditHide)
Quaternion GetWorldRotation() const;
/*! \brief Set the world-space rotation of this Node by offsetting the local-space rotation */
HYP_METHOD(Property = "WorldRotation", Transient)
void SetWorldRotation(const Quaternion& rotation);
/*! \brief Returns whether the Node is locked from being transformed. */
HYP_METHOD()
HYP_FORCE_INLINE bool IsTransformLocked() const
{
return m_transformLocked;
}
/*! \brief Lock the Node from being transformed. */
virtual void LockTransform();
/*! \brief Unlock the Node from being transformed. */
virtual void UnlockTransform();
HYP_FORCE_INLINE bool IsStatic() const
{
return bool(m_nodeFlags & NodeFlags::MobilityStatic);
}
void SetIsStatic(bool isStatic);
HYP_FORCE_INLINE bool IsDynamic() const
{
return !IsStatic();
}
void SetIsDynamic(bool isDynamic);
/*! \brief The local-space axis-aligned bounding box of the node, extended to include the bounds of all child nodes (with their local-space transforms applied). */
HYP_METHOD()
BoundingBox GetLocalBoundsWithChildren() const;
/*! \brief The axis-aligned bounding box of the node in world-space.
* Includes the bounds of all child nodes and is transformed by ancestor transforms to compose the final world-space AABB. */
HYP_METHOD(Property = "WorldBounds", EditEnabled = false, Transient)
BoundingBox GetWorldBounds() const;
/*! \brief Update the world transform of the Node to reflect changes in the local transform and parent transform.
* This will update the TransformComponent of the entity if it exists. */
HYP_METHOD()
void UpdateWorldTransform(bool updateChildTransforms = true);
/*! \brief Calculate the depth of the Node relative to the root Node.
* \returns The depth of the Node relative to the root Node. If the Node has no parent, 0 is returned. */
HYP_METHOD()
uint32 CalculateDepth() const;
/*! \brief Calculate the index of this Node in its parent's child list.
* \returns The index of this Node in its parent's child list. If the Node has no parent, -1 is returned. */
HYP_METHOD()
uint32 FindSelfIndex() const;
bool TestRay(const Ray& ray, RayTestResults& outResults, EnumFlags<RayTestFlags> flags = RayTestFlags::TestBVH) const;
/*! \brief Search child nodes (breadth-first) until a node with the given name is found. */
HYP_METHOD()
Handle<Node> FindChildByName(StringHash name) const;
HYP_FORCE_INLINE const NodeTagSet& GetTags() const
{
return m_tags;
}
/*! \brief Add a tag to this Node. */
void AddTag(NodeTag&& value);
/*! \brief Remove a tag from this Node.
* \param key The key the tag
* \returns Whether the tag with the given key was successfully removed or not */
bool RemoveTag(StringHash key);
/*! \brief Get a tag from this Node.
* \param key The key the tag
* \returns The tag with the given key. If the tag does not exist, an empty NodeTag is returned */
const NodeTag& GetTag(StringHash key) const;
/*! \brief Check if this Node has a tag with the given name.
* \param key The key the tag
* \returns True if the tag exists, false otherwise. */
bool HasTag(StringHash key) const;
HYP_FIELD()
ScriptableDelegate<void, Node*, bool /* direct */> OnChildAdded;
HYP_FIELD()
ScriptableDelegate<void, Node*, bool /* direct */> OnChildRemoved;
protected:
virtual void Init() override;
virtual void OnAttachedToNode(Node* node);
virtual void OnDetachedFromNode(Node* node);
virtual void OnNodeAttached(Node* node);
virtual void OnNodeDetached(Node* node);
virtual void OnTransformUpdated();
virtual void OnMobilityChanged(bool isStatic);
HYP_METHOD(Property = "Children", NoScriptBindings, Serialize)
void SetChildren(const NodeList& children); // use setter so we can manage parent pointers
HYP_FIELD(Property = "NodeFlags", Serialize)
EnumFlags<NodeFlags> m_nodeFlags;
HYP_FIELD(Property = "Parent", Transient)
Node* m_parentNode;
HYP_FIELD(Property = "Children", LoadOrder = -1, EditHide, Serialize)
NodeList m_childNodes;
HYP_FIELD(Property = "LocalTransform", Serialize, Label = "Local-space Transform")
Transform m_localTransform;
HYP_FIELD(Transient, EditHide)
Mat4f m_worldMatrix;
HYP_FIELD(Property = "LocalBounds", Serialize, Label = "Bounding Box", Description = "The bounds for the content of this node. Does not take into account child nodes or transform.")
BoundingBox m_localBounds;
HYP_FIELD(Property = "Scene", Transient, EditHide)
Scene* m_scene;
bool m_transformLocked : 1;
HYP_FIELD(Property = "NodeTags", Serialize)
NodeTagSet m_tags;
};
struct NodeUnlockTransformScope
{
NodeUnlockTransformScope(Node& node)
: node(node),
locked(node.IsTransformLocked())
{
if (locked)
{
node.UnlockTransform();
}
}
~NodeUnlockTransformScope()
{
if (locked)
{
node.LockTransform();
}
}
Node& node;
bool locked;
};
} // namespace Hyperion