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 "I3DHDrawing.h"
12#include "I3DHError.h"
13#include "I3DHSplineData.h"
14#include "I3DHVersion.h"
15
16#include "GameFramework/Actor.h"
17#include "Templates/RefCounting.h"
18#include "Engine/AssetUserData.h"
19
20#include "I3DHDrawingEditor.generated.h"
21
22class AI3DHConnector;
23
29UENUM(BlueprintType)
30enum class EI3DHDrawingEditorMode : uint8
31{
33 None,
39 Draw,
53};
54
57DECLARE_DYNAMIC_DELEGATE_ThreeParams(FI3DHDrawingFinalizedDelegate, const FI3DHDrawingResult&, DrawingResult, const FI3DHDrawingProperties&, DrawingProperties, const TArray<FI3DHSplineData>&, Splines);
59
60class INSTANT3DHUB_EXPERIMENTAL(0.0.27, "The instant3Dhub Drawings feature is available as a preview and is actively under development.") AI3DHDrawingEditor;
61
62
81UCLASS(Experimental, Abstract, NotPlaceable, meta = (DisplayName = "I3DH DrawingEditor (Experimental)"))
82class INSTANT3DHUBDRAWINGS_API AI3DHDrawingEditor
83 : public AActor
85{
87 GENERATED_BODY()
88
89 friend class UI3DHDrawingSplineRendererBase;
90 friend class UI3DHDrawingInstancedStaticMeshRenderer;
91 friend class UI3DHDrawingJointMeshRenderer;
92 friend class UI3DHDrawingSegmentMeshRenderer;
93 friend class UI3DHDrawingControlPointRenderer;
94
95public:
97
103 void InitializePreSpawn(AI3DHConnector* ParentHubConnector);
104
105 //~ Begin AActor Interface
106 virtual void Tick(float DeltaSeconds) override;
107 //~ End AActor Interface
108
109 //~ Begin II3DHEditDrawingInterface
110 virtual void BeginEditDrawing_Implementation(
111 const int32 DrawingHandle,
112 const FI3DHDrawingProperties& DrawingProperties,
113 const UI3DHEditDrawingGeometryProvider* GeometryProvider,
114 const class AI3DHDrawing* DrawingActor) override;
115 //~ End II3DHEditDrawingInterface
116
117public:
124 UFUNCTION(BlueprintCallable, meta = (DefaultToSelf = "HubConnector", DeterminesOutputType = "DrawingClass"), Category = "{instant3DhubDrawings}")
125 static AI3DHDrawingEditor* CreateDrawingEditor(AI3DHConnector* HubConnector, TSubclassOf<AI3DHDrawingEditor> DrawingClass);
126
131 UFUNCTION(BlueprintPure, Category = "{instant3DhubDrawings}")
132 AI3DHConnector* GetHubConnector() const { return HubConnector; }
133
134 // ----------------------------------------------------------
135 // AI3DHDrawingEditor API
136 // ----------------------------------------------------------
137
142 UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Color"), Category = "{instant3DhubDrawings}")
143 void SetDrawingColor(const FLinearColor& Color);
144
149 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
150 FLinearColor GetDrawingColor() const;
151
157 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
158 void SetDrawingScale(const double& Scale);
159
165 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
166 double GetDrawingScale() const;
167
172 const FString& GetEditedDrawingName() const { return EditedDrawingName; }
173
174 INSTANT3DHUB_DEPRECATED(1.1.0, "Will be removed because it is not supported for LineStrip drawings.")
179 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}", meta = (DisplayName = "Set Omit Stroke Start and End Joints (Deprecated)"))
180 void SetOmitStrokeStartAndEndJoints(bool bNewOmitJoints);
181
186 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
187 void SetShowActiveSliceControlPoints(bool bNewShowActiveSliceControlPoints);
188
193 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
194 bool IsEmpty() const;
195
201 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
202 int32 NumSplines() const;
203
205 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
206 void Clear();
207
213 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
214 void Restore();
215
221 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3DhubDrawings}")
222 void MoveCursorTo(const FVector& Location);
223
228 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
229 void AddPointAtCursor();
230
236 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
237 void BeginNewSplineSlice();
238
243 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
244 UPARAM(DisplayName = "bWasLastSplineSlice") bool RemoveLastSplineSlice();
245
250 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
251 void BeginNewSpline();
252
253 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
270 void FinalizeDrawing(TUniqueFunction<void(FI3DHDrawingResult)> OnComplete);
271 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
272
283 void CreateHubDrawingAndDestroy(const FString& Name, TUniqueFunction<void(int32 DrawingHandle, EI3DHErrorCode ErrorCode)> OnComplete);
284
289 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
290 void SetDrawingMode(EI3DHDrawingEditorMode InDrawingMode);
291
296 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
297 EI3DHDrawingEditorMode GetDrawingEditorMode() const { return DrawingMode; }
298
307 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
308 bool AddPoint(const FVector& Location, bool bIsWorldSpace = false);
309
310 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
315 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
316 void InitFromSplines(const TArray<FI3DHSplineData>& InSplines);
317 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
318
323 void InitFromSplines(TArray<FI3DHSplineData>&& InSplines);
324
325 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
331 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
332 const TArray<FI3DHSplineData>& GetSplines() const { return Splines; }
333 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
334
340 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
341 bool SelectNearestPointAtCursor();
342
350 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
351 bool SelectNearestPoint(const FVector& Location, bool bIsWorldSpace = false);
352
358 UFUNCTION(BlueprintPure, Category = "{instant3DhubDrawings}")
359 int32 GetNumFinalizedSplines() const
360 {
361 if (GetDrawingEditorMode() != EI3DHDrawingEditorMode::Finalize) { return 0; }
362 return FinalizedSplineMask.CountSetBits();
363 }
364
370 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
371 TArray<int32> GetFinalizedSplineIndices() const
372 {
373 TArray<int32> Indices;
374 if (GetDrawingEditorMode() != EI3DHDrawingEditorMode::Finalize) { return Indices; }
375
376 const int32 Num = FinalizedSplineMask.CountSetBits();
377 Indices.Reserve(Num);
378 for (TConstSetBitIterator It(FinalizedSplineMask); It; ++It)
379 {
380 Indices.Add(It.GetIndex());
381 }
382 return Indices;
383 }
384
391 UFUNCTION(BlueprintPure, Category = "{instant3DhubDrawings}")
392 bool WasSplineFinalized(int32 SplineIndex) const
393 {
394 if (GetDrawingEditorMode() != EI3DHDrawingEditorMode::Finalize) { return false; }
395 if (!FinalizedSplineMask.IsValidIndex(SplineIndex)) { return false; }
396 return FinalizedSplineMask[SplineIndex];
397 }
404 const TBitArray<>& GetFinalizedSplineMask() const
405 {
406 return FinalizedSplineMask;
407 }
408
409protected:
410 // Called when the game starts or when spawned
411 virtual void BeginPlay() override;
412
413 virtual bool IsReadyForFinishDestroy() override { return Super::IsReadyForFinishDestroy() && (!AsyncTaskFence.IsValid() || AsyncTaskFence.GetRefCount() <= 1); }
414
415private:
417 bool ShouldShowCursor() const { return GetDrawingEditorMode() == EI3DHDrawingEditorMode::Draw; }
418
419 void InsertPointInternal(const FVector& RelativeLocation, const int32 SplineIndex, const int32 PointIndex);
420 void RemovePointsInternal(const int32 SplineIndex, const int32 StartPointIndex, const int32 NumRemovals);
421
422 void CheckIsSplineDataAndStateValid() const;
423
424 void UpdateRenderState();
425 void UpdateHoveredState();
426
427 bool ShouldCreateLineStripDrawings() const { return bCreateLineStripDrawings; }
428 bool ShouldCreateCollidersForTriangleMeshDrawings() const { return bCreateCollidersForTriangleMeshDrawings; }
429
430public:
435 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}", AdvancedDisplay)
436 bool bCreateLineStripDrawings{true};
437
442 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}", AdvancedDisplay, meta = (EditCondition = "!bCreateLineStripDrawings"))
443 bool bCreateCollidersForTriangleMeshDrawings{false};
444
446 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
447 double MinimumPointDistance = 3.0;
448
450 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
451 double HoverPointDistance = 1.0;
452
454 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
455 FString ThumbnailBase64DataURI;
456
457private:
458 UPROPERTY(Transient)
459 TObjectPtr<AI3DHConnector> HubConnector{nullptr};
460
462 UPROPERTY()
463 TObjectPtr<class UStaticMeshComponent> Cursor{nullptr};
464
466 UPROPERTY()
467 TObjectPtr<class UStaticMeshComponent> ActiveSegment{nullptr};
468
470 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
471 FLinearColor DefaultColor{FLinearColor::Yellow};
472
477 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
478 double DefaultScale{1};
479
484 UPROPERTY(Transient)
485 TObjectPtr<class UStaticMesh> SegmentMesh{nullptr};
486
491 UPROPERTY(Transient)
492 TObjectPtr<class UStaticMesh> JointMesh{nullptr};
493
499 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
500 TObjectPtr<class UStaticMesh> ControlPointMesh{nullptr};
501
503 bool bOmitStrokeStartAndEndJoints{false};
504
506 bool bShowActiveSliceControlPoints{false};
507
509 EI3DHDrawingEditorMode DrawingMode{EI3DHDrawingEditorMode::Draw};
510
511 bool bIsCursorLocationDirty{true};
512
514 bool bCanCreateLineStripDrawings{false};
515
516 FString EditedDrawingName;
517
518 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
520 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Transient)
521 TArray<FI3DHSplineData> Splines;
522
527 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Transient)
528 TArray<FI3DHSplineData> InitialSplines;
529 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
530
535 TOptional<FTransform> InitialTransform;
536
538 TBitArray<> FinalizedSplineMask;
539
541 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Instanced, Transient)
542 TObjectPtr<class UI3DHSplineStateObject> StateObject;
543
545 TRefCountPtr<FThreadSafeRefCountedObject> AsyncTaskFence{nullptr};
546};
547
552UCLASS(Transient)
553class UI3DHDrawingEditorTransientSplineData : public UAssetUserData
554{
555 GENERATED_BODY()
556public:
557 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Transient)
558 TArray<FI3DHSplineData> Splines;
559};
560
562UCLASS(Experimental, MinimalAPI, meta = (DisplayName = "I3DH Transient EditableDrawing (Experimental)"))
563class AI3DHTransientEditableDrawing : public AI3DHDrawing
564{
565 GENERATED_BODY()
566
567public:
568 AI3DHTransientEditableDrawing();
569};
EI3DHDrawingEditorMode
DrawingEditor Modes describe how the editor visualizes the drawing and what actions are available.
Definition I3DHDrawingEditor.h:31
@ EditDrawing
EditDrawing Mode:
@ Finalize
Finalize Mode:
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:119
Actor for creating line-based 3D drawings that sync to instant3Dhub when finished.
Definition I3DHDrawingEditor.h:85
This actor is the scene representation of drawings in the session.
Definition I3DHDrawing.h:47
Interface that can be implemented to provide drawing editing functionality.
Definition I3DHDataTypes.h:2045
Provides access to geometry of an instant3Dhub drawing.
Definition I3DHDataTypes.h:1917
#define PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
Macro for temporarily disabling experimental warnings.
Definition I3DHVersion.h:267
#define PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
Macro for re-enabling experimental warnings after PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS.
Definition I3DHVersion.h:284
#define INSTANT3DHUB_EXPERIMENTAL(Version, Message)
Macro for marking up experimental code, functions and types.
Definition I3DHVersion.h:245
instant3Dhub drawing properties.
Definition I3DHDataTypes.h:1776
Encapsulates the result of an instant3Dhub drawing.
Definition I3DHDataTypes.h:1874