I3DHInteractiveSplineDrawing.h Source File

instant3Dhub: I3DHInteractiveSplineDrawing.h Source File
instant3Dhub
I3DHInteractiveSplineDrawing.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "CoreMinimal.h"
9
10#include "I3DHError.h"
11#include "I3DHVersion.h"
12
13#include "Components/SplineComponent.h"
14#include "Components/SplineMeshComponent.h"
15#include "GameFramework/Actor.h"
16#include "Templates/RefCounting.h"
17#include "UObject/StrongObjectPtr.h"
18
19#include "I3DHInteractiveSplineDrawing.generated.h"
20
21class AI3DHConnector;
22
23DECLARE_DYNAMIC_DELEGATE_TwoParams(FSplineDrawingCreatedDelegate, const FI3DHDrawingResult&, DrawingResult, const FI3DHDrawingProperties&, DrawingProperties);
24
25class INSTANT3DHUB_EXPERIMENTAL(0.0.27, "The instant3Dhub Drawings feature is available as a preview and is actively under development.") AI3DHInteractiveSplineDrawing;
26
49UCLASS(Experimental, Abstract, NotPlaceable, meta = (DisplayName = "I3DH Interactive SplineDrawing (Experimental)"))
50class INSTANT3DHUBDRAWINGS_API AI3DHInteractiveSplineDrawing : public AActor
51{
52 GENERATED_BODY()
53
54public:
55 // Sets default values for this actor's properties
57
64 UFUNCTION(BlueprintCallable, meta = (DefaultToSelf = "HubConnector", DeterminesOutputType = "DrawingClass"), Category = "{instant3DhubDrawings}")
65 static AI3DHInteractiveSplineDrawing* CreateInteractiveSplineDrawing(AI3DHConnector* HubConnector, TSubclassOf<AI3DHInteractiveSplineDrawing> DrawingClass);
66
71 void InitializePreSpawn(AI3DHConnector* ParentHubConnector);
72
77 UFUNCTION(BlueprintPure, Category = "{instant3DhubDrawings}")
78 AI3DHConnector* GetHubConnector() const { return HubConnector; }
79
84 UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Color"), Category = "{instant3DhubDrawings}")
85 void SetDrawingColor(const FLinearColor& Color);
86
91 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
92 FLinearColor GetDrawingColor() const;
93
98 UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Color"), Category = "{instant3DhubDrawings}")
99 void SetDrawingScale(const FVector2D& Scale);
100
105 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
106 FVector2D GetDrawingScale() const;
107
112 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
113 void SetCursorHiddenInGame(bool bIsHiddenInGame);
114
119 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
120 bool IsEmpty() const;
121
123 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
124 void Clear();
125
133 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3DhubDrawings}")
134 void MoveCursorTo(const FVector& Location, const FVector& Normal);
135
137 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
138 void AddSplinePointAtCursor();
139
144 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
145 void RemoveLastSegmentFromActiveSpline();
146
148 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
149 void FinishActiveSpline();
150
157 void FinalizeDrawing(TUniqueFunction<void(FI3DHDrawingResult)> OnComplete);
158
169 void CreateHubDrawingAndDestroy(const FString& Name, TUniqueFunction<void(int DrawingHandle, EI3DHErrorCode ErrorCode)> OnComplete);
170
175 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
176 double CursorNormalOffset = 0.01;
177
179 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
180 FString ThumbnailBase64DataURI;
181
182protected:
183 // Called when the game starts or when spawned
184 virtual void BeginPlay() override;
185
186 virtual bool IsReadyForFinishDestroy() override { return Super::IsReadyForFinishDestroy() && (!AsyncTaskFence.IsValid() || AsyncTaskFence.GetRefCount() <= 1); }
187
188private:
189 // Updates the active spline to end at the new location. Its last segment is updated to spawn from the second-last
190 // point in the spline to the last.
191 bool UpdateActiveSplineEndSegment(const FVector& NewEndLocation, const FVector& NewEndUpVector);
192
195 void RemoveLastSegmentFromActiveSpline_Internal(bool bAttachNewEndToCursor);
196
197 UPROPERTY()
198 AI3DHConnector* HubConnector;
199
200 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
201 UStaticMeshComponent* Cursor;
202
203 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
204 FLinearColor DefaultColor = FLinearColor::Yellow;
205
206 // Mesh used to render a single segment of the splines.
207 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
208 UStaticMesh* SegmentMesh;
209
210 // Length of the tangents of segments. Length == 0 scales with the length of the segment.
211 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
212 double WorldSpaceTangentLength = 5;
213
214 // We don't use a USTRUCT here so we can keep the struct private.
215 // This means we have to use ObjectPtr for memory management.
216 struct InteractiveSplineData
217 {
218 // Immediately destroy all components. Call this before the struct is destroyed!
219 void DestroyAllComponents()
220 {
221 if (Spline.IsValid() && !Spline->IsBeingDestroyed())
222 {
223 Spline->DestroyComponent();
224 }
225
226 for (const TStrongObjectPtr<USplineMeshComponent>& SplineSegment : Segments)
227 {
228 if (SplineSegment.IsValid() && !SplineSegment->IsBeingDestroyed())
229 {
230 SplineSegment->DestroyComponent();
231 }
232 }
233 }
234
235 TStrongObjectPtr<USplineComponent> Spline;
236
237 TArray<TStrongObjectPtr<USplineMeshComponent>> Segments;
238 };
239
240 // Store pointer instead of value so we can hold a pointer to the active spline without having to worry about it
241 // being invalidated by operations to the array.
242 TArray<TSharedPtr<InteractiveSplineData>> SplineDataStore;
243
244 // Points to the active spline's data. The active spline is the one whose end follows the cursor.
245 TSharedPtr<InteractiveSplineData> ActiveSplineData = nullptr;
246
247 FVector2D ActiveScale{ 1, 1 };
248
249 bool bIsFinalized{ false };
250
251 TRefCountPtr<FThreadSafeRefCountedObject> AsyncTaskFence{nullptr};
252};
The HubConnector is the central actor for communication with an instant3Dhub instance in your network...
Definition I3DHConnector.h:98
A helper for creating spline-based drawings in the scene that are synced to the session when finished...
Definition I3DHInteractiveSplineDrawing.h:51
#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