I3DHDrawingEditor.h Source File

instant3Dhub: I3DHDrawingEditor.h Source File
instant3Dhub
I3DHDrawingEditor.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "CoreMinimal.h"
9
10#include "I3DHDataTypes.h"
11#include "I3DHError.h"
12#include "I3DHSplineData.h"
13#include "I3DHVersion.h"
14
15#include "GameFramework/Actor.h"
16#include "Templates/RefCounting.h"
17
18#include "I3DHDrawingEditor.generated.h"
19
20class AI3DHConnector;
21
23UENUM(BlueprintType)
24enum class EI3DHDrawingEditorMode : uint8
25{
27 None,
29 Draw,
38};
39
41DECLARE_DYNAMIC_DELEGATE_ThreeParams(FI3DHDrawingFinalizedDelegate, const FI3DHDrawingResult&, DrawingResult, const FI3DHDrawingProperties&, DrawingProperties, const TArray<FI3DHSplineData>&, Splines);
42
43class INSTANT3DHUB_EXPERIMENTAL(0.0.27, "The instant3Dhub Drawings feature is available as a preview and is actively under development.") AI3DHDrawingEditor;
44
69UCLASS(Experimental, Abstract, NotPlaceable, meta = (DisplayName = "I3DH DrawingEditor (Experimental)"))
70class INSTANT3DHUBDRAWINGS_API AI3DHDrawingEditor : public AActor
71{
72 GENERATED_BODY()
73
74 friend class UI3DHDrawingSplineRendererBase;
75 friend class UI3DHDrawingInstancedStaticMeshRenderer;
76 friend class UI3DHDrawingJointMeshRenderer;
77 friend class UI3DHDrawingSegmentMeshRenderer;
78 friend class UI3DHDrawingControlPointRenderer;
79
80public:
81 // Sets default values for this actor's properties
83
84 // Call before (deferred) spawning.
85 void InitializePreSpawn(AI3DHConnector* ParentHubConnector);
86
87 virtual void Tick(float DeltaSeconds) override;
88
89public:
96 UFUNCTION(BlueprintCallable, meta = (DefaultToSelf = "HubConnector", DeterminesOutputType = "DrawingClass"), Category = "{instant3DhubDrawings}")
97 static AI3DHDrawingEditor* CreateDrawingEditor(AI3DHConnector* HubConnector, TSubclassOf<AI3DHDrawingEditor> DrawingClass);
98
103 UFUNCTION(BlueprintPure, Category = "{instant3DhubDrawings}")
104 AI3DHConnector* GetHubConnector() const { return HubConnector; }
105
106 // ----------------------------------------------------------
107 // AI3DHDrawingEditor API
108 // ----------------------------------------------------------
109
114 UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Color"), Category = "{instant3DhubDrawings}")
115 void SetDrawingColor(const FLinearColor& Color);
116
121 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
122 FLinearColor GetDrawingColor() const;
123
128 UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Color"), Category = "{instant3DhubDrawings}")
129 void SetDrawingScale(const double& Scale);
130
135 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
136 double GetDrawingScale() const;
137
142 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
143 void SetOmitStrokeStartAndEndJoints(bool bNewOmitJoints);
144
149 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
150 void SetShowActiveSliceControlPoints(bool bNewShowActiveSliceControlPoints);
151
156 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
157 bool IsEmpty() const;
158
164 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
165 int32 NumSplines() const;
166
168 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
169 void Clear();
170
176 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3DhubDrawings}")
177 void MoveCursorTo(const FVector& Location);
178
184 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
185 void AddPointAtCursor();
186
194 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
195 void BeginNewSplineSlice();
196
201 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
202 UPARAM(DisplayName = "bWasLastSplineSlice") bool RemoveLastSplineSlice();
203
208 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
209 void BeginNewSpline();
210
218 INSTANT3DHUB_EXPERIMENTAL(0.0.25, "The handling of SplineData is not yet finalized, the callback signature might change.")
219 void FinalizeDrawing(TUniqueFunction<void(FI3DHDrawingResult, TArray<FI3DHSplineData> OutSplines)> OnComplete);
220
231 void CreateHubDrawingAndDestroy(const FString& Name, TUniqueFunction<void(int DrawingHandle, EI3DHErrorCode ErrorCode)> OnComplete);
232
237 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
238 void SetDrawingMode(EI3DHDrawingEditorMode InDrawingMode);
239
244 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
245 EI3DHDrawingEditorMode GetDrawingEditorMode() const { return DrawingMode; }
246
255 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
256 bool AddPoint(const FVector& Location, bool bIsWorldSpace = false);
257
262 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
263 void InitFromSplines(const TArray<FI3DHSplineData>& InSplines);
264
271 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
272 const TArray<FI3DHSplineData>& GetSplines() const { return Splines; }
273
278 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
279 bool SelectNearestPointAtCursor();
280
288 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
289 bool SelectNearestPoint(const FVector& Location, bool bIsWorldSpace = false);
290
291protected:
292 // Called when the game starts or when spawned
293 virtual void BeginPlay() override;
294
295 virtual bool IsReadyForFinishDestroy() override { return Super::IsReadyForFinishDestroy() && (!AsyncTaskFence.IsValid() || AsyncTaskFence.GetRefCount() <= 1); }
296
297private:
299 bool ShouldShowCursor() const { return DrawingMode == EI3DHDrawingEditorMode::Draw; }
300
301 void InsertPointInternal(const FVector& RelativeLocation, const int32 SplineIndex, const int32 PointIndex);
302 void RemovePointsInternal(const int32 SplineIndex, const int32 StartPointIndex, const int32 NumRemovals);
303
304 void CheckIsSplineDataAndStateValid() const;
305
306 void UpdateRenderState();
307 void UpdateHoveredState();
308
309public:
311 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
312 double MinimumPointDistance = 3.0;
313
315 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
316 double HoverPointDistance = 1.0;
317
319 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
320 FString ThumbnailBase64DataURI;
321
322private:
323 UPROPERTY(Transient)
324 TObjectPtr<AI3DHConnector> HubConnector{nullptr};
325
327 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
328 TObjectPtr<class UStaticMeshComponent> Cursor{nullptr};
329
331 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
332 TObjectPtr<class UStaticMeshComponent> ActiveSegment{nullptr};
333
335 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
336 FLinearColor DefaultColor{FLinearColor::Yellow};
337
339 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
340 double DefaultScale{1};
341
346 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
347 TObjectPtr<class UStaticMesh> SegmentMesh{nullptr};
348
350 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
351 TObjectPtr<class UStaticMesh> JointMesh{nullptr};
352
354 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
355 TObjectPtr<class UStaticMesh> ControlPointMesh{nullptr};
356
358 bool bOmitStrokeStartAndEndJoints{false};
360 bool bShowActiveSliceControlPoints{false};
361
363 EI3DHDrawingEditorMode DrawingMode{EI3DHDrawingEditorMode::Draw};
364
365 bool bIsCursorLocationDirty{true};
366
368 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Transient)
369 TArray<FI3DHSplineData> Splines;
370
374 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Instanced, Transient)
375 TObjectPtr<class UI3DHSplineStateObject> StateObject;
376
377 TRefCountPtr<FThreadSafeRefCountedObject> AsyncTaskFence{nullptr};
378};
EI3DHDrawingEditorMode
DrawingEditor Modes determine the functionalities and inner workings of the Drawing Editor.
Definition I3DHDrawingEditor.h:25
@ Draw
In Draw Mode, a Cursor is visible and new points or spline slices can be added to the drawing.
@ EditDrawing
In EditDrawing Mode, the splines are locked but the drawing can be edited as a whole.
@ Finalize
In Finalize Mode, all editing capabilities of the drawing are locked.
DECLARE_DYNAMIC_DELEGATE void FI3DHDrawingFinalizedDelegate(const FI3DHDrawingResult &DrawingResult, const FI3DHDrawingProperties &DrawingProperties, const TArray< FI3DHSplineData > &Splines)
Drawing Finalized Delegate Type.
The HubConnector is the central actor for communication with an instant3Dhub instance in your network...
Definition I3DHConnector.h:98
DrawingEditor Actor for creating spline 3D drawings in the scene that are synced to the session when ...
Definition I3DHDrawingEditor.h:71
#define INSTANT3DHUB_EXPERIMENTAL(Version, Message)
Macro for marking up experimental code, functions and types.
Definition I3DHVersion.h:212
instant3Dhub drawing properties.
Definition I3DHDataTypes.h:1750
Encapsulates the result of an instant3Dhub drawing.
Definition I3DHDataTypes.h:1811