Plasma Engine  2.0
Loading...
Searching...
No Matches
GameObjectDocument.h
1#pragma once
2#include <EditorFramework/Assets/AssetDocument.h>
3#include <EditorFramework/DocumentWindow/EngineDocumentWindow.moc.h>
4#include <EditorFramework/EditorFrameworkDLL.h>
5#include <Foundation/SimdMath/SimdTransform.h>
6#include <ToolsFoundation/Document/Document.h>
7#include <ToolsFoundation/Object/DocumentObjectManager.h>
8#include <ToolsFoundation/Object/ObjectMetaData.h>
9#include <ToolsFoundation/Project/ToolsProject.h>
10
14
15struct PL_EDITORFRAMEWORK_DLL TransformationChanges
16{
17 enum Enum
18 {
19 Translation = PL_BIT(0),
20 Rotation = PL_BIT(1),
21 Scale = PL_BIT(2),
22 UniformScale = PL_BIT(3),
23 All = 0xFF
24 };
25};
26
27struct PL_EDITORFRAMEWORK_DLL plGameObjectEvent
28{
29 enum class Type
30 {
31 RenderSelectionOverlayChanged,
32 RenderVisualizersChanged,
33 RenderShapeIconsChanged,
34 AddAmbientLightChanged,
35 SimulationSpeedChanged,
36 PickTransparentChanged,
37
38 ActiveEditToolChanged,
39
40 TriggerShowSelectionInScenegraph,
41 TriggerFocusOnSelection_Hovered,
42 TriggerFocusOnSelection_All,
43
44 TriggerSnapSelectionPivotToGrid,
45 TriggerSnapEachSelectedObjectToGrid,
46
47 GameModeChanged,
48
49 GizmoTransformMayBeInvalid,
50 };
51
52 Type m_Type;
53};
54
56{
57 enum class Type
58 {
59 GameMode_Stopped,
60 GameMode_StartingSimulate,
61 GameMode_StartingPlay,
63 };
64
65 Type m_Type;
66 plGameObjectDocument* m_pDocument = nullptr;
67};
68
69class PL_EDITORFRAMEWORK_DLL plGameObjectMetaData : public plReflectedClass
70{
71 PL_ADD_DYNAMIC_REFLECTION(plGameObjectMetaData, plReflectedClass);
72
73public:
74 enum ModifiedFlags
75 {
76 CachedName = PL_BIT(2),
77 AllFlags = 0xFFFFFFFF
78 };
79
80 plGameObjectMetaData() = default;
81
82 plString m_CachedNodeName;
83 QIcon m_Icon;
84};
85
86struct PL_EDITORFRAMEWORK_DLL plSelectedGameObject
87{
88 const plDocumentObject* m_pObject;
89 plVec3 m_vLocalScaling;
90 float m_fLocalUniformScaling;
91 plTransform m_GlobalTransform;
92};
93
94class PL_EDITORFRAMEWORK_DLL plGameObjectDocument : public plAssetDocument
95{
96 PL_ADD_DYNAMIC_REFLECTION(plGameObjectDocument, plAssetDocument);
97
98public:
99 plGameObjectDocument(plStringView sDocumentPath, plDocumentObjectManager* pObjectManager,
100 plAssetDocEngineConnection engineConnectionType = plAssetDocEngineConnection::FullObjectMirroring);
102
103
104 virtual plEditorInputContext* GetEditorInputContextOverride() override;
105
106protected:
107 void SubscribeGameObjectEventHandlers();
108 void UnsubscribeGameObjectEventHandlers();
109
110 void GameObjectDocumentEventHandler(const plGameObjectDocumentEvent& e);
111
114public:
116 void SetActiveEditTool(const plRTTI* pEditToolType);
117
119 plGameObjectEditTool* GetActiveEditTool() const { return m_pActiveEditTool; }
120
122 bool IsActiveEditTool(const plRTTI* pEditToolType) const;
123
126 void SetEditToolConfigDelegate(plDelegate<void(plGameObjectEditTool*)> configDelegate);
127
128 void SetGizmoWorldSpace(bool bWorldSpace);
129 bool GetGizmoWorldSpace() const;
130
131 void SetGizmoMoveParentOnly(bool bMoveParent);
132 bool GetGizmoMoveParentOnly() const;
133
138 void ComputeTopLevelSelectedGameObjects(plDeque<plSelectedGameObject>& out_selection);
139
140 virtual void HandleEngineMessage(const plEditorEngineDocumentMsg* pMsg) override;
141
142private:
143 void DeallocateEditTools();
144
145 plDelegate<void(plGameObjectEditTool*)> m_EditToolConfigDelegate;
146 plGameObjectEditTool* m_pActiveEditTool = nullptr;
148
149
153
154public:
155 void TriggerShowSelectionInScenegraph() const;
156 void TriggerFocusOnSelection(bool bAllViews) const;
157 void TriggerSnapPivotToGrid() const;
158 void TriggerSnapEachObjectToGrid() const;
160 void SnapCameraToObject();
162 void MoveCameraHere();
163
165 plStatus CreateGameObjectHere();
166
167 void ScheduleSendObjectSelection();
168
170 void SendObjectSelection();
171
175public:
176 bool GetAddAmbientLight() const { return m_bAddAmbientLight; }
177 void SetAddAmbientLight(bool b);
178
179 float GetSimulationSpeed() const { return m_fSimulationSpeed; }
180 void SetSimulationSpeed(float f);
181
182 bool GetRenderSelectionOverlay() const { return m_CurrentMode.m_bRenderSelectionOverlay; }
183 void SetRenderSelectionOverlay(bool b);
184
185 bool GetRenderVisualizers() const { return m_CurrentMode.m_bRenderVisualizers; }
186 void SetRenderVisualizers(bool b);
187
188 bool GetRenderShapeIcons() const { return m_CurrentMode.m_bRenderShapeIcons; }
189 void SetRenderShapeIcons(bool b);
190
191 bool GetPickTransparent() const { return m_bPickTransparent; }
192 void SetPickTransparent(bool b);
193
197
201 void SetGlobalTransform(const plDocumentObject* pObject, const plTransform& t, plUInt8 uiTransformationChanges) const;
202
204 void SetGlobalTransformParentOnly(const plDocumentObject* pObject, const plTransform& t, plUInt8 uiTransformationChanges) const;
205
207 plTransform GetGlobalTransform(const plDocumentObject* pObject) const;
208
210 static plTransform QueryLocalTransform(const plDocumentObject* pObject);
211 static plSimdTransform QueryLocalTransformSimd(const plDocumentObject* pObject);
212
215 plTransform ComputeGlobalTransform(const plDocumentObject* pObject) const;
216
218 virtual plResult ComputeObjectTransformation(const plDocumentObject* pObject, plTransform& out_result) const override;
219
223
225 void DetermineNodeName(const plDocumentObject* pObject, const plUuid& prefabGuid, plStringBuilder& out_sResult, QIcon* out_pIcon = nullptr) const;
226
229 void QueryCachedNodeName(
230 const plDocumentObject* pObject, plStringBuilder& out_sResult, plUuid* out_pPrefabGuid = nullptr, QIcon* out_pIcon = nullptr) const;
231
233 void GenerateFullDisplayName(const plDocumentObject* pRoot, plStringBuilder& out_sFullPath) const;
234
236
237public:
238 mutable plEvent<const plGameObjectEvent&> m_GameObjectEvents;
240
241 static plEvent<const plGameObjectDocumentEvent&> s_GameObjectDocumentEvents;
242
243protected:
244 void InvalidateGlobalTransformValue(const plDocumentObject* pObject) const;
247 virtual void SendGameWorldToEngine();
248
249 virtual void InitializeAfterLoading(bool bFirstTimeCreation) override;
250 virtual void AttachMetaDataBeforeSaving(plAbstractObjectGraph& graph) const override;
251 virtual void RestoreMetaDataAfterLoading(const plAbstractObjectGraph& graph, bool bUndoable) override;
252
253public:
254 void SelectionManagerEventHandler(const plSelectionManagerEvent& e);
255 void ObjectPropertyEventHandler(const plDocumentObjectPropertyEvent& e);
256 void ObjectStructureEventHandler(const plDocumentObjectStructureEvent& e);
257 void ObjectEventHandler(const plDocumentObjectEvent& e);
258
259protected:
260 struct PL_EDITORFRAMEWORK_DLL GameModeData
261 {
262 bool m_bRenderSelectionOverlay;
263 bool m_bRenderVisualizers;
264 bool m_bRenderShapeIcons;
265 };
266 GameModeData m_CurrentMode;
267
268private:
269 bool m_bAddAmbientLight = false;
270 bool m_bGizmoWorldSpace = true; // whether the gizmo is in local/global space mode
271 bool m_bGizmoMoveParentOnly = false;
272 bool m_bPickTransparent = true;
273
274 float m_fSimulationSpeed = 1.0f;
275
277 mutable TransformTable m_GlobalTransforms;
278
279 // when new objects are created the engine sometimes needs to catch up creating sub-objects (e.g. for reference prefabs)
280 // therefore when the selection is changed in the first frame, it might not be fully correct
281 // by sending it a second time, we can fix that easily
282 plInt8 m_iResendSelection = 0;
283
284protected:
285 plEventSubscriptionID m_SelectionManagerEventHandlerID;
286 plEventSubscriptionID m_ObjectPropertyEventHandlerID;
287 plEventSubscriptionID m_ObjectStructureEventHandlerID;
288 plEventSubscriptionID m_ObjectEventHandlerID;
289};
Definition AbstractObjectGraph.h:115
Definition AssetDocument.h:42
Simple class to handle asset file headers (the very first bytes in all transformed asset files)
Definition AssetFileHeader.h:8
Definition Deque.h:270
Definition DocumentObjectBase.h:11
Represents to content of a document. Every document has exactly one root object under which all objec...
Definition DocumentObjectManager.h:116
Base class for all messages that are tied to some document.
Definition EngineProcessMessages.h:151
Definition EditorInputContext.h:22
Definition Event.h:177
Definition GameObjectDocument.h:95
plGameObjectEditTool * GetActiveEditTool() const
Returns the currently active edit tool (nullptr for none).
Definition GameObjectDocument.h:119
Definition EditTool.h:29
Definition GameObjectDocument.h:70
Definition Map.h:408
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
Definition SimdTransform.h:6
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
Definition GameObjectDocument.h:16
Definition AllocatorWrapper.h:25
A generic delegate class which supports static functions and member functions.
Definition Delegate.h:76
Used by plDocumentObjectManager::m_ObjectEvents.
Definition DocumentObjectManager.h:100
Used by plDocumentObjectManager::m_PropertyEvents.
Definition DocumentObjectManager.h:77
Used by plDocumentObjectManager::m_StructureEvents.
Definition DocumentObjectManager.h:45
Definition GameObjectDocument.h:261
Definition GameObjectDocument.h:56
Type
Definition GameObjectDocument.h:58
@ GameMode_StartingExternal
ie. scene is exported for plPlayer
Definition GameObjectDocument.h:28
Type
Definition GameObjectDocument.h:30
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition GameObjectDocument.h:87
Definition SelectionManager.h:10
An plResult with an additional message for the reason of failure.
Definition Status.h:12