Polyphase Game Engine
Loading...
Searching...
No Matches
Node3d.h
Go to the documentation of this file.
1#pragma once
2
3#include "PolyphaseAPI.h"
4#include "Nodes/Node.h"
5#include "EngineTypes.h"
6
7#include "Maths.h"
8
9#include "AssetRef.h"
10
11class SkeletalMesh3D;
12
14{
15public:
16
18
19 Node3D();
20 virtual ~Node3D();
21
22 virtual void Create() override;
23 virtual void Destroy() override;
24 virtual void Tick(float deltaTime) override;
25
26 virtual const char* GetTypeName() const override;
27 virtual void GatherProperties(std::vector<Property>& outProps) override;
28 virtual void GatherReplicatedData(std::vector<NetDatum>& outData);
29
30 virtual bool IsNode3D() const override;
31
32 void AttachToBone(SkeletalMesh3D* parent, const char* boneName, bool keepWorldTransform = false, int32_t childIndex = -1);
33 void AttachToBone(SkeletalMesh3D* parent, int32_t boneIndex, bool keepWorldTransform = false, int32_t childIndex = -1);
34
35 // Attach to a named socket (or, if no socket by that name exists, a bone of
36 // that name) on `parent`. Use this for the initial attach; once attached,
37 // prefer SetAttachSocket() to move between sockets on the SAME parent -- it
38 // avoids the RemoveChild/AddChild round trip that reorders siblings.
39 void AttachToSocket(SkeletalMesh3D* parent, const char* socketName, bool keepWorldTransform = false, int32_t childIndex = -1);
40 void SetAttachSocket(const char* socketName);
41 const std::string& GetAttachSocket() const;
42
43 void MarkTransformDirty();
44 bool IsTransformDirty() const;
45 virtual void UpdateTransform(bool updateChildren);
46
47 virtual bool CheckNetRelevance(Node* playerNode) override;
48
49 virtual void GatherProxyDraws(std::vector<DebugDraw>& inoutDraws);
50
51#if EDITOR
52 virtual void OnDrawGizmos();
53 virtual void OnDrawGizmosSelected();
54 virtual bool DrawCustomProperty(Property& prop) override;
55#endif
56
57 glm::vec3 GetPosition() const;
58 glm::vec3 GetRotationEuler() const;
59 glm::quat GetRotationQuat() const;
60 glm::vec3 GetScale() const;
61
62 glm::vec3& GetPositionRef();
63 glm::vec3& GetRotationEulerRef();
64 glm::quat& GetRotationQuatRef();
65 glm::vec3& GetScaleRef();
66
67 const glm::mat4& GetTransform();
68
69 void SetPosition(glm::vec3 position);
70 void SetRotation(glm::vec3 rotation);
71 void SetRotation(glm::quat quat);
72 void SetScale(glm::vec3 scale);
73 virtual void SetTransform(const glm::mat4& transform);
74
75 glm::vec3 GetWorldPosition();
76 glm::vec3 GetWorldRotationEuler();
77 glm::quat GetWorldRotationQuat();
78 glm::vec3 GetWorldScale();
79
80 void SetWorldPosition(glm::vec3 position);
81 void SetWorldRotation(glm::vec3 rotation);
82 void SetWorldRotation(glm::quat rotation);
83 void SetWorldScale(glm::vec3 scale);
84
85 void AddRotation(glm::quat rotation);
86 void AddRotation(glm::vec3 rotation);
87 void AddWorldRotation(glm::quat rotation);
88 void AddWorldRotation(glm::vec3 rotation);
89 void RotateAround(glm::vec3 pivot, glm::vec3 axis, float degrees);
90
91 void LookAt(glm::vec3 target, glm::vec3 up);
92
93 // World-space bounding box of THIS node's own geometry. Node3D has no
94 // geometry of its own, so the base implementation returns a degenerate
95 // box at the node's world origin. Primitive3D overrides this.
96 virtual AABB GetAABB() const;
97
98 // This node unioned with every Node3D descendant's GetAABB(). Useful for
99 // framing, selection and group operations.
100 AABB GetHierarchyAABB(bool includeSelf = true) const;
101
102 glm::vec3 GetCachedEulerRotation() const;
103
104 glm::vec3 GetForwardVector();
105 glm::vec3 GetRightVector();
106 glm::vec3 GetUpVector();
107
108 glm::mat4 GetParentTransform();
109 int32_t GetParentBoneIndex() const;
110
111 bool GetInheritTransform() const;
112 void SetInheritTransform(bool inheritTransform);
113
114 virtual void Attach(Node* parent, bool keepWorldTransform = false, int32_t index = -1) override;
115
116 static bool OnRep_RootPosition(Datum* datum, uint32_t index, const void* newValue);
117 static bool OnRep_RootRotation(Datum* datum, uint32_t index, const void* newValue);
118 static bool OnRep_RootScale(Datum* datum, uint32_t index, const void* newValue);
119
120protected:
121
122 virtual void SetParent(Node* parent) override;
123
124 glm::vec3 mPosition;
125 glm::vec3 mRotationEuler;
126 glm::vec3 mScale;
127
128 glm::quat mRotationQuat;
129
130 glm::mat4 mTransform;
131
132 // Bone/socket attachment. mAttachSocket is the authoritative, serialized
133 // value -- it names either a socket or a bare bone on the parent skeletal
134 // mesh. The two indices are a lazily-resolved cache, rebuilt on demand in
135 // ResolveAttachSocket() and invalidated whenever the name or parent changes.
136 // Resolving by name (rather than storing an index) means a mesh reimport
137 // that reorders bones can't silently move attached props.
138 std::string mAttachSocket;
140 int32_t mAttachSocketIndex = -1;
141 bool mAttachResolved = false;
142
143 bool mInheritTransform = true;
144
146
147private:
148
149 // Resolves mAttachSocket against the parent skeletal mesh into
150 // mParentBoneIndex / mAttachSocketIndex. Cheap no-op once resolved.
151 void ResolveAttachSocket();
152 void InvalidateAttachSocket();
153};
Export macros for Polyphase Engine symbols.
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
Definition Datum.h:169
Definition Node3d.h:14
std::string mAttachSocket
Definition Node3d.h:138
glm::vec3 mRotationEuler
Definition Node3d.h:125
glm::vec3 mPosition
Definition Node3d.h:124
glm::mat4 mTransform
Definition Node3d.h:130
glm::quat mRotationQuat
Definition Node3d.h:128
bool mTransformDirty
Definition Node3d.h:145
int32_t mParentBoneIndex
Definition Node3d.h:139
glm::vec3 mScale
Definition Node3d.h:126
DECLARE_NODE(Node3D, Node)
Definition Node.h:67
virtual bool CheckNetRelevance(Node *playerNode)
Definition Node.cpp:1414
virtual void Create()
Definition Node.cpp:235
virtual void SetParent(Node *parent)
Definition Node.cpp:2340
virtual void GatherProperties(std::vector< Property > &outProps) override
Definition Node.cpp:618
virtual void GatherReplicatedData(std::vector< NetDatum > &outData)
Definition Node.cpp:662
virtual void Attach(Node *parent, bool keepWorldTransform=false, int32_t index=-1)
Definition Node.cpp:1615
virtual bool IsNode3D() const
Definition Node.cpp:1580
virtual void Tick(float deltaTime)
Definition Node.cpp:573
virtual const char * GetTypeName() const
Definition Node.cpp:1567
virtual void Destroy()
Definition Node.cpp:249
virtual bool DrawCustomProperty(Property &prop)
Definition Object.h:46
Definition Property.h:14
Definition SkeletalMesh3d.h:129
Definition EngineTypes.h:213