I3DHDrawingEditor.h Source File

I3DHDrawingEditor.h Source File#

instant3Dhub: I3DHDrawingEditor.h Source File
instant3Dhub
I3DHDrawingEditor.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 "I3DHDataTypes.h"
12#include "I3DHDrawing.h"
13#include "I3DHError.h"
14#include "I3DHSplineData.h"
15#include "I3DHVersion.h"
16
17#include "Engine/AssetUserData.h"
18#include "GameFramework/Actor.h"
19#include "Templates/RefCounting.h"
20
21#include "I3DHDrawingEditor.generated.h"
22
23class AI3DHConnector;
24
30UENUM(BlueprintType)
55
56I3DH_PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
58DECLARE_DYNAMIC_DELEGATE_ThreeParams(FI3DHDrawingFinalizedDelegate, const FI3DHDrawingResult&, DrawingResult, const FI3DHDrawingProperties&, DrawingProperties, const TArray<FI3DHSplineData>&, Splines);
59I3DH_PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
60
61class INSTANT3DHUB_EXPERIMENTAL(0.0.27, "The instant3Dhub Drawings feature is available as a preview and is actively under development.") AI3DHDrawingEditor;
62
80I3DH_PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
81UCLASS(Experimental, Abstract, NotPlaceable, meta = (DisplayName = "I3DH DrawingEditor (Experimental)"))
82class INSTANT3DHUBDRAWINGS_API AI3DHDrawingEditor
83 : public AActor
85{
86 I3DH_PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
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:
96 AI3DHDrawingEditor();
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
115 ) override;
116 //~ End II3DHEditDrawingInterface
117
118public:
125 UFUNCTION(BlueprintCallable, meta = (DefaultToSelf = "HubConnector", DeterminesOutputType = "DrawingClass"), Category = "{instant3DhubDrawings}")
126 static AI3DHDrawingEditor* CreateDrawingEditor(AI3DHConnector* HubConnector, TSubclassOf<AI3DHDrawingEditor> DrawingClass);
127
132 UFUNCTION(BlueprintPure, Category = "{instant3DhubDrawings}")
133 AI3DHConnector* GetHubConnector() const { return HubConnector; }
134
135 // ----------------------------------------------------------
136 // AI3DHDrawingEditor API
137 // ----------------------------------------------------------
138
143 UFUNCTION(BlueprintCallable, meta = (AutoCreateRefTerm = "Color"), Category = "{instant3DhubDrawings}")
144 void SetDrawingColor(const FLinearColor& Color);
145
150 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
152
158 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
159 void SetDrawingScale(const double& Scale);
160
166 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
167 double GetDrawingScale() const;
168
173 const FString& GetEditedDrawingName() const { return EditedDrawingName; }
174
175 INSTANT3DHUB_DEPRECATED(1.1.0, "Will be removed because it is not supported for LineStrip drawings.")
180 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}", meta = (DisplayName = "Set Omit Stroke Start and End Joints (Deprecated)"))
181 void SetOmitStrokeStartAndEndJoints(bool bNewOmitJoints);
182
187 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
188 void SetShowActiveSliceControlPoints(bool bNewShowActiveSliceControlPoints);
189
194 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
195 bool IsEmpty() const;
196
202 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
203 int32 NumSplines() const;
204
206 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
207 void Clear();
208
214 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
215 void Restore();
216
222 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3DhubDrawings}")
223 void MoveCursorTo(const FVector& Location);
224
229 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
231
237 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
239
244 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
245 UPARAM(DisplayName = "bWasLastSplineSlice") bool RemoveLastSplineSlice();
246
251 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
253
254 I3DH_PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
272 I3DH_PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
273
284 void CreateHubDrawingAndDestroy(const FString& Name, TUniqueFunction<void(int32 DrawingHandle, EI3DHErrorCode ErrorCode)> OnComplete);
285
290 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
292
297 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3DhubDrawings}")
298 EI3DHDrawingEditorMode GetDrawingEditorMode() const { return DrawingMode; }
299
308 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
309 bool AddPoint(const FVector& Location, bool bIsWorldSpace = false);
310
311 I3DH_PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
316 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
317 void InitFromSplines(const TArray<FI3DHSplineData>& InSplines);
318 I3DH_PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
319
325
326 I3DH_PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
332 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
333 const TArray<FI3DHSplineData>& GetSplines() const { return Splines; }
334 I3DH_PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
335
341 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
343
351 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
352 bool SelectNearestPoint(const FVector& Location, bool bIsWorldSpace = false);
353
359 UFUNCTION(BlueprintPure, Category = "{instant3DhubDrawings}")
361 {
363 return FinalizedSplineMask.CountSetBits();
364 }
365
371 UFUNCTION(BlueprintCallable, Category = "{instant3DhubDrawings}")
373 {
374 TArray<int32> Indices;
375 if (GetDrawingEditorMode() != EI3DHDrawingEditorMode::Finalize) { return Indices; }
376
377 const int32 Num = FinalizedSplineMask.CountSetBits();
378 Indices.Reserve(Num);
379 for (TConstSetBitIterator It(FinalizedSplineMask); It; ++It)
380 {
381 Indices.Add(It.GetIndex());
382 }
383 return Indices;
384 }
385
392 UFUNCTION(BlueprintPure, Category = "{instant3DhubDrawings}")
393 bool WasSplineFinalized(int32 SplineIndex) const
394 {
396 if (!FinalizedSplineMask.IsValidIndex(SplineIndex)) { return false; }
397 return FinalizedSplineMask[SplineIndex];
398 }
399
406 {
407 return FinalizedSplineMask;
408 }
409
410protected:
411 // Called when the game starts or when spawned
412 virtual void BeginPlay() override;
413
414 virtual bool IsReadyForFinishDestroy() override { return Super::IsReadyForFinishDestroy() && (!AsyncTaskFence.IsValid() || AsyncTaskFence->GetRefCount() <= 1); }
415
416private:
418 bool ShouldShowCursor() const { return GetDrawingEditorMode() == EI3DHDrawingEditorMode::Draw; }
419
420 void InsertPointInternal(const FVector& RelativeLocation, const int32 SplineIndex, const int32 PointIndex);
421 void RemovePointsInternal(const int32 SplineIndex, const int32 StartPointIndex, const int32 NumRemovals);
422
423 void CheckIsSplineDataAndStateValid() const;
424
425 void UpdateRenderState();
426 void UpdateHoveredState();
427
428 bool ShouldCreateLineStripDrawings() const { return bCreateLineStripDrawings; }
429 bool ShouldCreateCollidersForTriangleMeshDrawings() const { return bCreateCollidersForTriangleMeshDrawings; }
430
431public:
436 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}", AdvancedDisplay)
438
443 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}", AdvancedDisplay, meta = (EditCondition = "!bCreateLineStripDrawings"))
445
447 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
449
451 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
452 double HoverPointDistance = 1.0;
453
455 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3DhubDrawings}")
457
458private:
459 UPROPERTY(Transient)
460 TObjectPtr<AI3DHConnector> HubConnector{nullptr};
461
463 UPROPERTY()
464 TObjectPtr<class UStaticMeshComponent> Cursor{nullptr};
465
467 UPROPERTY()
468 TObjectPtr<class UStaticMeshComponent> ActiveSegment{nullptr};
469
471 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
472 FLinearColor DefaultColor{FLinearColor::Yellow};
473
478 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
479 double DefaultScale{1};
480
485 UPROPERTY(Transient)
486 TObjectPtr<class UStaticMesh> SegmentMesh{nullptr};
487
492 UPROPERTY(Transient)
493 TObjectPtr<class UStaticMesh> JointMesh{nullptr};
494
500 UPROPERTY(EditDefaultsOnly, Category = "{instant3DhubDrawings}")
501 TObjectPtr<class UStaticMesh> ControlPointMesh{nullptr};
502
504 bool bOmitStrokeStartAndEndJoints{false};
505
507 bool bShowActiveSliceControlPoints{false};
508
511
512 bool bIsCursorLocationDirty{true};
513
515 bool bCanCreateLineStripDrawings{false};
516
517 FString EditedDrawingName;
518
519 I3DH_PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
521 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Transient)
523
528 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Transient)
529 TArray<FI3DHSplineData> InitialSplines;
530 I3DH_PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
531
536 TOptional<FTransform> InitialTransform;
537
539 TBitArray<> FinalizedSplineMask;
540
542 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Instanced, Transient)
544
546 TRefCountPtr<FI3DHAsyncTaskFence> AsyncTaskFence{nullptr};
547};
548
553UCLASS(Transient)
554class UI3DHDrawingEditorTransientSplineData : public UAssetUserData
555{
556 GENERATED_BODY()
557public:
558 UPROPERTY(Category = "{instant3DhubDrawings}", VisibleAnywhere, Transient)
559 TArray<FI3DHSplineData> Splines;
560};
561
563UCLASS(Experimental, MinimalAPI, meta = (DisplayName = "I3DH Transient EditableDrawing (Experimental)"))
564class AI3DHTransientEditableDrawing : public AI3DHDrawing
565{
566 GENERATED_BODY()
567
568public:
569 AI3DHTransientEditableDrawing();
570};
@ None
Zero value.
Definition I3DHDataTypes.h:30
EI3DHDrawingEditorMode
DrawingEditor Modes describe how the editor visualizes the drawing and what actions are available.
Definition I3DHDrawingEditor.h:32
@ Draw
Draw Mode:
Definition I3DHDrawingEditor.h:40
@ EditDrawing
EditDrawing Mode:
Definition I3DHDrawingEditor.h:46
@ Finalize
Finalize Mode:
Definition I3DHDrawingEditor.h:53
DECLARE_DYNAMIC_DELEGATE void FI3DHDrawingFinalizedDelegate(const FI3DHDrawingResult &DrawingResult, const FI3DHDrawingProperties &DrawingProperties, const TArray< FI3DHSplineData > &Splines)
Drawing Finalized Delegate Type.
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
Actor for creating line-based 3D drawings that sync to instant3Dhub when finished.
Definition I3DHDrawingEditor.h:85
bool AddPoint(const FVector &Location, bool bIsWorldSpace=false)
Adds a Spline point at the given location to the active Spline (actor local space unless bIsWorldSpac...
void AddPointAtCursor()
Adds a Spline point at the cursor position to the active Spline.
double MinimumPointDistance
Minimum world-space distance (Unreal units) between consecutive points added to the active Spline.
Definition I3DHDrawingEditor.h:448
double HoverPointDistance
World-space distance (Unreal units) used to hover/select ControlPoints.
Definition I3DHDrawingEditor.h:452
TArray< int32 > GetFinalizedSplineIndices() const
Returns the indices (into AI3DHDrawingEditor::GetSplines) of all splines that produced exportable geo...
Definition I3DHDrawingEditor.h:372
FString ThumbnailBase64DataURI
Data-URI string, e.g.
Definition I3DHDrawingEditor.h:456
bool bCreateCollidersForTriangleMeshDrawings
Whether to create complex colliders for triangle mesh drawings.
Definition I3DHDrawingEditor.h:444
void BeginNewSplineSlice()
Begins a new Slice; the next points belong to this Slice.
void SetDrawingMode(EI3DHDrawingEditorMode InDrawingMode)
Sets the DrawingEditor Mode.
void Restore()
Restores the drawing to its initial state.
bool bCreateLineStripDrawings
If enabled, export LINE_STRIP drawings.
Definition I3DHDrawingEditor.h:437
bool SelectNearestPoint(const FVector &Location, bool bIsWorldSpace=false)
Selects the nearest endpoint (start or end) within AI3DHDrawingEditor::HoverPointDistance of the give...
AI3DHConnector * GetHubConnector() const
Returns the parent hub connector.
Definition I3DHDrawingEditor.h:133
FLinearColor GetDrawingColor() const
Retrieves the color currently used for drawing.
const FString & GetEditedDrawingName() const
Returns the name of drawing if this editor is editing an existing drawing.
Definition I3DHDrawingEditor.h:173
void InitFromSplines(const TArray< FI3DHSplineData > &InSplines)
Clears all Splines and initializes the editor from the provided Splines.
void FinalizeDrawing(TUniqueFunction< void(FI3DHDrawingResult)> OnComplete)
Finalizes the drawing.
int32 GetNumFinalizedSplines() const
Returns the number of splines that produced exportable geometry during finalize.
Definition I3DHDrawingEditor.h:360
int32 NumSplines() const
Returns the number of Splines the drawing consists of.
const TArray< FI3DHSplineData > & GetSplines() const
Returns all Spline data currently in the editor.
Definition I3DHDrawingEditor.h:333
void SetDrawingScale(const double &Scale)
Sets the scale used for drawing and applies it to the active Spline.
bool RemoveLastSplineSlice()
Removes the last Slice from the active Spline.
bool WasSplineFinalized(int32 SplineIndex) const
Tests whether the given editor spline index produced exportable geometry during the last finalize.
Definition I3DHDrawingEditor.h:393
void SetDrawingColor(const FLinearColor &Color)
Sets the color used for drawing and applies it to the active Spline.
double GetDrawingScale() const
Retrieves the scale currently used for drawing.
void BeginNewSpline()
Begins a new Spline that is discontinuous from the previous Spline.
void CreateHubDrawingAndDestroy(const FString &Name, TUniqueFunction< void(int32 DrawingHandle, EI3DHErrorCode ErrorCode)> OnComplete)
Finalizes the drawing, synchronizes it with instant3Dhub and destroys this actor.
const TBitArray & GetFinalizedSplineMask() const
Returns the bitmask of finalized splines.
Definition I3DHDrawingEditor.h:405
void SetShowActiveSliceControlPoints(bool bNewShowActiveSliceControlPoints)
Controls whether all ControlPoints belonging to the active Slice should be visualized.
static AI3DHDrawingEditor * CreateDrawingEditor(AI3DHConnector *HubConnector, TSubclassOf< AI3DHDrawingEditor > DrawingClass)
Creates an actor which can be used for drawing and syncing to instant3Dhub when finished.
EI3DHDrawingEditorMode GetDrawingEditorMode() const
Returns the current DrawingEditor Mode.
Definition I3DHDrawingEditor.h:298
void SetOmitStrokeStartAndEndJoints(bool bNewOmitJoints)
Controls whether the first and last sample point of Splines are rendered with a joint.
bool IsEmpty() const
Returns true if the drawing has no content.
void MoveCursorTo(const FVector &Location)
Sets the cursor location.
void Clear()
Removes all Splines and points from this drawing, leaving it empty.
bool SelectNearestPointAtCursor()
Selects the nearest endpoint (start or end) within AI3DHDrawingEditor::HoverPointDistance of the curr...
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:2261
Provides access to geometry of an instant3Dhub drawing.
Definition I3DHDataTypes.h:2134
#define INSTANT3DHUB_DEPRECATED(Version, Message)
Macro for marking up deprecated code, functions and types.
Definition I3DHVersion.h:203
#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
Raw data of a single spline created by the AI3DHDrawingEditor.
Definition I3DHSplineData.h:21