Polyphase Game Engine
Loading...
Searching...
No Matches
Spline3d.h
Go to the documentation of this file.
1#pragma once
2
3#include "Nodes/3D/Node3d.h"
4#include <vector>
5
6// POLYPHASE_API: exported for native addons (e.g. the Houdini HDA addon
7// bakes HDA curve output into Spline3D nodes and feeds Spline3D points back
8// into HDA inputs).
10{
11public:
13
14 virtual void Create() override;
15 virtual void OnSpawnedInEditor() override;
16 virtual void Start() override;
17 virtual void Stop() override;
18 virtual void Tick(float deltaTime) override;
19 virtual void Copy(Node* srcNode, bool recurse) override;
20 virtual void SaveStream(Stream& stream, Platform platform) override;
21 virtual void LoadStream(Stream& stream, Platform platform, uint32_t version) override;
22 virtual void GatherProperties(std::vector<Property>& props) override;
23 virtual void GatherProxyDraws(std::vector<DebugDraw>& inoutDraws) override;
24
25 // Authoritative point access: a spline's points ARE its "pointN" child
26 // nodes (created by GeneratePoint / the editor, gathered in index order).
27 // Prefer these over the mPoints-based API below, which is a separate
28 // legacy vector that the child-node representation never populates.
29 uint32_t GetNumSplinePoints() const;
30 glm::vec3 GetSplinePointPosition(uint32_t index) const; // relative to the spline
31 glm::vec3 GetSplinePointWorldPosition(uint32_t index) const;
32 void SetSplinePointPosition(uint32_t index, const glm::vec3& localPosition);
33 Node3D* AddSplinePoint(const glm::vec3& localPosition); // appends a new pointN child
34 void ClearSplinePoints();
35
36 // Brute-force arc-length queries over the authoritative pointN
37 // representation (world space). Not cached -- same convention as
38 // SplineLengthNode / SplineNearestPercentNode in NodeGraph/Nodes/SplineNodes.cpp,
39 // which re-sample every call rather than track a dirty flag against point
40 // nodes that can also move via the ordinary transform gizmo.
41 float GetSplineLength() const;
42 float GetClosestDistanceAlong(const glm::vec3& worldPos) const;
43
44 void AddPoint(const glm::vec3& p);
45 void ClearPoints();
46 uint32_t GetPointCount() const;
47 glm::vec3 GetPoint(uint32_t index) const;
48 void SetPoint(uint32_t index, const glm::vec3& p);
49
50 glm::vec3 GetPositionAt(float t) const; // t in [0,1]
51 glm::vec3 GetTangentAt(float t) const; // normalized tangent
52
53 void SetCloseLoop(bool close) { mCloseLoop = close; }
54 bool IsCloseLoop() const { return mCloseLoop; }
55 void SetSmoothCurve(bool smooth) { mSmoothCurve = smooth; }
56 bool IsSmoothCurve() const { return mSmoothCurve; }
57
58 static bool HandlePropChange(Datum* datum, uint32_t index, const void* newValue);
59
60 static glm::vec3 CatmullRom(const glm::vec3& p0, const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& p3, float t);
61 static glm::vec3 CatmullRomTangent(const glm::vec3& p0, const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& p3, float t);
62
63 void Play();
64 void StopPlayback();
65 void SetPaused(bool paused);
66 bool IsPaused() const;
67 void SetFollowLinkEnabled(uint32_t index, bool enabled);
68 bool IsFollowLinkEnabled(uint32_t index) const;
69 bool IsNearLinkFrom(uint32_t index, float epsilon = 0.05f) const;
70 bool IsNearLinkTo(uint32_t index, float epsilon = 0.05f) const;
71 bool IsLinkDirectionForward(uint32_t index, float threshold = 0.0f) const;
72 bool TriggerLink(uint32_t index);
73 void CancelActiveLink();
74
75 static void SetSplineLinesVisible(bool visible);
76 static bool IsSplineLinesVisible();
77
78#if EDITOR
79 virtual bool DrawCustomProperty(Property& prop) override;
80#endif
81
82protected:
83 struct SplineLink;
84 void GeneratePoint();
85 SplineLink* GetLinkByIndex(uint32_t index);
86 const SplineLink* GetLinkByIndex(uint32_t index) const;
87 void EnsureLinkSlots(uint32_t count);
88
89protected:
90 std::vector<glm::vec3> mPoints;
98
100 {
103 bool mFollow = true;
104 bool mTriggered = false;
105 float mSpeed = 1.0f;
106 };
107
108 std::vector<SplineLink> mLinks;
109 bool mLinkActive = false;
110 bool mDisableBounce = false;
111 float mLinkSpeedModifier = 1.0f;
112 int32_t mGeneratedLinkCount = 10;
113
114 float mActiveLinkSpeedModifier = 1.0f;
115 bool mLinkSmoothStep = false;
116 bool mLinkSmoothRotate = false;
117 float mLinkTravel = 0.0f;
118 float mLinkLen = 0.0f;
119 glm::vec3 mLinkStart = glm::vec3(0.0f);
120 glm::vec3 mLinkEnd = glm::vec3(0.0f);
122 float mLinkTargetStartDist = 0.0f;
123 float mLinkTargetPrevDist = 0.0f;
124 float mLinkTargetTotalLen = 0.0f;
125
126 glm::mat4 mOrigCamTransform = glm::mat4(1.0f);
127 glm::mat4 mOrigStaticTransform = glm::mat4(1.0f);
128 glm::mat4 mOrigSkeletalTransform = glm::mat4(1.0f);
129 glm::mat4 mOrigParticleTransform = glm::mat4(1.0f);
130 glm::mat4 mOrigPointLightTransform = glm::mat4(1.0f);
131 glm::mat4 mOrigAudioTransform = glm::mat4(1.0f);
132 glm::mat4 mOrigNodeTransform = glm::mat4(1.0f);
133
134 float mSpeed = 2.0f;
135 bool mPlaying = false;
136 bool mLoop = true;
137 bool mCloseLoop = false;
138 bool mPingPong = false;
139 bool mPingPongForward = true;
140 bool mSmoothCurve = true;
141 bool mSmoothRotate = false;
142 bool mPause = false;
143 bool mFaceTangent = false;
144 bool mReverseFaceTangent = false;
145 float mTravel = 0.0f;
146
147 bool mHasTrackedPos = false;
148 glm::vec3 mPrevTrackedPos = glm::vec3(0.0f);
149 glm::vec3 mTrackedMoveDir = glm::vec3(0.0f);
150
152 {
153 std::string name;
154 float speed = 1.0f;
155 bool smoothIn = false;
156 bool smoothOut = false;
157 bool smoothCurve = false;
158 };
159
160 std::vector<PointSpeedEntry> mPointSpeedEntries;
162 float mPointSpeedValue = 1.0f;
163 bool mPointSmoothInValue = false;
164 bool mPointSmoothOutValue = false;
165 bool mPointSmoothCurveValue = false;
166};
Platform
Definition EngineTypes.h:32
void SetPaused(bool paused)
Definition Engine.cpp:1784
bool IsPaused()
Definition Engine.cpp:1789
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
Definition Datum.h:169
Definition Node3d.h:14
virtual void Create() override
Definition Node3d.cpp:96
virtual void Tick(float deltaTime) override
Definition Node3d.cpp:114
virtual void GatherProperties(std::vector< Property > &outProps) override
Definition Node3d.cpp:124
virtual void GatherProxyDraws(std::vector< DebugDraw > &inoutDraws)
Definition Node3d.cpp:298
Definition Node.h:67
virtual void Stop()
Definition Node.cpp:519
static bool HandlePropChange(Datum *datum, uint32_t index, const void *newValue)
Definition Node.cpp:89
virtual void Copy(Node *srcNode, bool recurse)
Definition Node.cpp:338
virtual void Start()
Definition Node.cpp:474
virtual void SaveStream(Stream &stream, Platform platform)
Definition Node.cpp:328
virtual void OnSpawnedInEditor()
Definition Node.cpp:608
virtual void LoadStream(Stream &stream, Platform platform, uint32_t version)
Definition Node.cpp:333
virtual bool DrawCustomProperty(Property &prop)
Definition Object.h:46
Definition Property.h:14
Definition Spline3d.h:10
std::vector< SplineLink > mLinks
Definition Spline3d.h:108
std::vector< glm::vec3 > mPoints
Definition Spline3d.h:90
NodePtrWeak mAttachmentNode3D
Definition Spline3d.h:97
void SetCloseLoop(bool close)
Definition Spline3d.h:53
NodePtrWeak mPointSpeedTarget
Definition Spline3d.h:161
bool IsSmoothCurve() const
Definition Spline3d.h:56
NodePtrWeak mAttachmentParticle3D
Definition Spline3d.h:94
bool IsCloseLoop() const
Definition Spline3d.h:54
NodePtrWeak mAttachmentPointLight
Definition Spline3d.h:95
NodePtrWeak mLinkTargetSpline
Definition Spline3d.h:121
NodePtrWeak mAttachmentSkeletalMesh
Definition Spline3d.h:93
NodePtrWeak mAttachmentStaticMesh
Definition Spline3d.h:92
void SetSmoothCurve(bool smooth)
Definition Spline3d.h:55
NodePtrWeak mAttachmentCamera
Definition Spline3d.h:91
std::vector< PointSpeedEntry > mPointSpeedEntries
Definition Spline3d.h:160
DECLARE_NODE(Spline3D, Node3D)
NodePtrWeak mAttachmentAudio3D
Definition Spline3d.h:96
Definition Stream.h:21
Definition Spline3d.h:152
std::string name
Definition Spline3d.h:153