I3DHInteractiveSplineDrawing.h Source File

I3DHInteractiveSplineDrawing.h Source File#

instant3Dhub: I3DHInteractiveSplineDrawing.h Source File
instant3Dhub
I3DHInteractiveSplineDrawing.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "CoreMinimal.h"
9
10#include "I3DHAsyncTaskFence.h"
11#include "I3DHError.h"
12#include "I3DHVersion.h"
13
14#include "Components/SplineComponent.h"
15#include "Components/SplineMeshComponent.h"
16#include "GameFramework/Actor.h"
17#include "Templates/RefCounting.h"
18#include "UObject/StrongObjectPtr.h"
19
20#include "I3DHInteractiveSplineDrawing.generated.h"
21
22class AI3DHConnector;
23
24DECLARE_DYNAMIC_DELEGATE_TwoParams(FSplineDrawingCreatedDelegate, const FI3DHDrawingResult&, DrawingResult, const FI3DHDrawingProperties&, DrawingProperties);
25
26class INSTANT3DHUB_EXPERIMENTAL(0.0.27, "The instant3Dhub Drawings feature is available as a preview and is actively under development.") AI3DHInteractiveSplineDrawing;
27
50UCLASS(Experimental, Abstract, NotPlaceable, meta = (DisplayName = "I3DH Interactive SplineDrawing (Experimental)"))
51class INSTANT3DHUBDRAWINGS_API AI3DHInteractiveSplineDrawing : public AActor
52{
53 GENERATED_BODY()
54
55public:
56 // Sets default values for this actor's properties
57 AI3DHInteractiveSplineDrawing();
58
65 UFUNCTION(BlueprintCallable, meta = (DefaultToSelf = "HubConnector", DeterminesOutputType = "DrawingClass"), Category = "{instant3DhubDrawings}")
66 static AI3DHInteractiveSplineDrawing* CreateInteractiveSplineDrawing(AI3DHConnector* HubConnector, TSubclassOf<AI3DHInteractiveSplineDrawing> DrawingClass);
67
72 void InitializePreSpawn(AI3DHConnector* ParentHubConnector);
73
78 UFUNCTION(BlueprintPure, Category = "{instant3DhubDrawings}")
79 AI3DHConnector* GetHubConnector() const { return HubConnector; }
80
85 UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Color"), Category = "{instant3DhubDrawings}")
86 void SetDrawingColor(const FLinearColor& Color);
87
92 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
94
99 UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Color"), Category = "{instant3DhubDrawings}")
100 void SetDrawingScale(const FVector2D& Scale);
101
106 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
107 FVector2D GetDrawingScale() const;
108
113 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
114 void SetCursorHiddenInGame(bool bIsHiddenInGame);
115
120 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
121 bool IsEmpty() const;
122
124 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
125 void Clear();
126
134 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3DhubDrawings}")
135 void MoveCursorTo(const FVector& Location, const FVector& Normal);
136
138 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
140
145 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
147
149 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
151
159
170 void CreateHubDrawingAndDestroy(const FString& Name, TUniqueFunction<void(int32 DrawingHandle, EI3DHErrorCode ErrorCode)> OnComplete);
171
176 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
177 double CursorNormalOffset = 0.01;
178
180 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
182
183protected:
184 // Called when the game starts or when spawned
185 virtual void BeginPlay() override;
186
187 virtual bool IsReadyForFinishDestroy() override { return Super::IsReadyForFinishDestroy() && (!AsyncTaskFence.IsValid() || AsyncTaskFence->GetRefCount() <= 1); }
188
189private:
190 // Updates the active spline to end at the new location. Its last segment is updated to spawn from the second-last
191 // point in the spline to the last.
192 bool UpdateActiveSplineEndSegment(const FVector& NewEndLocation, const FVector& NewEndUpVector);
193
196 void RemoveLastSegmentFromActiveSpline_Internal(bool bAttachNewEndToCursor);
197
198 UPROPERTY()
199 AI3DHConnector* HubConnector;
200
201 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
202 UStaticMeshComponent* Cursor;
203
204 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
205 FLinearColor DefaultColor = FLinearColor::Yellow;
206
207 // Mesh used to render a single segment of the splines.
208 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
209 UStaticMesh* SegmentMesh;
210
211 // Length of the tangents of segments. Length == 0 scales with the length of the segment.
212 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
213 double WorldSpaceTangentLength = 5;
214
215 // We don't use a USTRUCT here so we can keep the struct private.
216 // This means we have to use ObjectPtr for memory management.
217 struct InteractiveSplineData
218 {
219 // Immediately destroy all components. Call this before the struct is destroyed!
220 void DestroyAllComponents()
221 {
222 if (Spline.IsValid() && !Spline->IsBeingDestroyed())
223 {
224 Spline->DestroyComponent();
225 }
226
227 for (const TStrongObjectPtr<USplineMeshComponent>& SplineSegment : Segments)
228 {
229 if (SplineSegment.IsValid() && !SplineSegment->IsBeingDestroyed())
230 {
231 SplineSegment->DestroyComponent();
232 }
233 }
234 }
235
237
239 };
240
241 // Store pointer instead of value so we can hold a pointer to the active spline without having to worry about it
242 // being invalidated by operations to the array.
244
245 // Points to the active spline's data. The active spline is the one whose end follows the cursor.
246 TSharedPtr<InteractiveSplineData> ActiveSplineData = nullptr;
247
248 FVector2D ActiveScale{1, 1};
249
250 bool bIsFinalized{false};
251
252 TRefCountPtr<FI3DHAsyncTaskFence> AsyncTaskFence{nullptr};
253};
EI3DHErrorCode
Enumeration of Error Codes returned from various instant3Dhub API Calls.
Definition I3DHError.h:16
The HubConnector is the central actor for communication with an instant3Dhub instance in your network...
Definition I3DHConnector.h:214
A helper for creating spline-based drawings in the scene that are synced to the session when finished...
Definition I3DHInteractiveSplineDrawing.h:52
void InitializePreSpawn(AI3DHConnector *ParentHubConnector)
Call before (deferred) spawning.
FString ThumbnailBase64DataURI
Data-URI string, e.g.
Definition I3DHInteractiveSplineDrawing.h:181
void FinishActiveSpline()
Detaches the currently edited spline from the cursor.
void FinalizeDrawing(TUniqueFunction< void(FI3DHDrawingResult)> OnComplete)
Finalizes the drawing and builds the drawing geometry.
void Clear()
Clears this drawing to its blank/initial state.
void SetDrawingColor(const FLinearColor &Color)
Sets the color used for drawing and applies it to the active spline.
FLinearColor GetDrawingColor() const
Retrieves the color currently used for drawing.
void SetDrawingScale(const FVector2D &Scale)
Sets the scale used for drawing and applies it to the active spline.
void SetCursorHiddenInGame(bool bIsHiddenInGame)
Hides the cursor in game.
bool IsEmpty() const
Query if this drawing is empty.
double CursorNormalOffset
Offset along the normal when moving the cursor (in world units).
Definition I3DHInteractiveSplineDrawing.h:177
FVector2D GetDrawingScale() const
Retrieves the scale currently used for drawing.
static AI3DHInteractiveSplineDrawing * CreateInteractiveSplineDrawing(AI3DHConnector *HubConnector, TSubclassOf< AI3DHInteractiveSplineDrawing > DrawingClass)
Creates an actor which can be used for drawing and syncing to the Hub when finished.
AI3DHConnector * GetHubConnector() const
Returns the parent hub connector.
Definition I3DHInteractiveSplineDrawing.h:79
void CreateHubDrawingAndDestroy(const FString &Name, TUniqueFunction< void(int32 DrawingHandle, EI3DHErrorCode ErrorCode)> OnComplete)
Finalizes the drawing, synchronizes it with the hub and destroys this actor.
void RemoveLastSegmentFromActiveSpline()
Removes the last segment of the active spline, which was following the cursor.
void MoveCursorTo(const FVector &Location, const FVector &Normal)
Sets the cursor position.
void AddSplinePointAtCursor()
Adds a spline point at the cursor position to the active spline.
#define INSTANT3DHUB_EXPERIMENTAL(Version, Message)
Macro for marking up experimental code, functions and types.
Definition I3DHVersion.h:246
instant3Dhub drawing properties.
Definition I3DHDataTypes.h:1995
Encapsulates the result of an instant3Dhub drawing.
Definition I3DHDataTypes.h:2093