I3DHConnector.h Source File

instant3Dhub: I3DHConnector.h Source File
instant3Dhub
I3DHConnector.h
Go to the documentation of this file.
1
6#pragma once
7
8#include "CoreMinimal.h"
9
10#include "I3DHConnectorAPI.h"
12#include "I3DHDataTypes.h"
13#include "I3DHVersion.h"
14
15#include "Engine/Texture2D.h"
16#include "GameFramework/Actor.h"
17
18#include "I3DHConnector.generated.h"
19
20class AI3DHGeometry;
22class FI3DHPageToStaticMeshTask;
23class UBodySetup;
24
26DECLARE_DYNAMIC_MULTICAST_DELEGATE(FConnectedDelegate);
28DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FConnectErrorDelegate, const FString&, ErrorMessage);
30DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FErrorDelegate, const FString&, ErrorMessage);
32DECLARE_DYNAMIC_MULTICAST_DELEGATE(FDisconnectedDelegate);
33
43DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FClipPlaneCreatedDelegate, int32, ClipPlaneId, AActor*, ClipPlaneActor, bool, OwnEvent);
44
51DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FClipPlaneRemovedDelegate, int32, ClipPlaneId, bool, OwnEvent);
52
87USTRUCT(BlueprintType, Category = "{instant3Dhub}|Connector")
89{
90 GENERATED_BODY()
91
92
100 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "{instant3Dhub}|ConnectOptions")
101 FString SessionId;
102
111 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "{instant3Dhub}|ConnectOptions")
112 FString RestoreSessionId;
113};
114
119UCLASS(ClassGroup = "instant3Dhub", MinimalAPI)
120class AI3DHConnector : public AActor
121{
122 GENERATED_BODY()
123
124public:
125 INSTANT3DHUB_API AI3DHConnector();
126
127protected:
128 INSTANT3DHUB_API virtual void BeginPlay() override;
129 INSTANT3DHUB_API virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
130
131 INSTANT3DHUB_API virtual void Tick(float DeltaTime) override;
132
133#if WITH_EDITOR
134 INSTANT3DHUB_API virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
135#endif
136
137 // ----------------------------------------------------------
138 // API Accessor
139 // ----------------------------------------------------------
140public:
148 INSTANT3DHUB_API TSharedPtr<FI3DHConnectorAPI> GetAPI() const;
149
150 // ----------------------------------------------------------
151 // ConnectorAPI
152 // ----------------------------------------------------------
153public:
160 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
161 INSTANT3DHUB_API void AddNetworkCredentialCookie(const FString& CookieKey, const FString& CookieValue);
162
168 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
169 INSTANT3DHUB_API void RemoveNetworkCredentialCookie(const FString& CookieKey);
170
177 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
178 INSTANT3DHUB_API void AddNetworkCredentialToken(const FString& TokenKey, const FString& TokenValue);
179
185 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
186 INSTANT3DHUB_API void RemoveNetworkCredentialToken(const FString& TokenKey);
187
193 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
194 INSTANT3DHUB_API const TMap<FString, FString>& GetNetworkCredentialCookies() const { return NetworkCredentialCookies; }
195
201 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
202 INSTANT3DHUB_API const TMap<FString, FString>& GetNetworkCredentialTokens() const { return NetworkCredentialTokens; }
203
243 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Connector")
244 INSTANT3DHUB_API void ConnectToHub(const FString& HubURL, const FString& SessionId);
245
256 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Connector")
257 INSTANT3DHUB_API void ConnectToHubWithOptions(const FString& HubURL, const FI3DHConnectOptions& Options);
258
271 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Connector")
272 INSTANT3DHUB_API void Disconnect();
273
280 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
281 INSTANT3DHUB_API bool IsDisconnected() const;
282
289 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
290 INSTANT3DHUB_API bool IsEstablishingConnectionToHub() const;
291
297 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
298 INSTANT3DHUB_API bool IsConnectedToHub() const;
299
305 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
306 INSTANT3DHUB_API FString GetHubURL() const;
307
313 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
314 INSTANT3DHUB_API FString GetSessionId() const;
315
323 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
324 FConnectedDelegate OnConnectedDelegate;
325
332 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
333 FConnectErrorDelegate OnConnectErrorDelegate;
334
343 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
344 FErrorDelegate OnErrorDelegate;
345
352 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
353 FDisconnectedDelegate OnDisconnectedDelegate;
354
360 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
361 INSTANT3DHUB_API FMatrix GetOriginToWorldTransform() const;
362
368 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
369 INSTANT3DHUB_API FMatrix GetWorldToOriginTransform() const;
370
374 INSTANT3DHUB_API AActor* GetOriginActor()
375 {
376 AActor* RootActor = this;
377 check(RootActor != nullptr);
378 return RootActor;
379 }
380
384 INSTANT3DHUB_API const AActor* GetOriginActor() const
385 {
386 const AActor* RootActor = this;
387 check(RootActor != nullptr);
388 return RootActor;
389 }
390
392 // ----------------------------------------------------------
393 // Internal Connection Helper Functions
394 // ----------------------------------------------------------
395public:
396 void OnBackendConnected_Internal_GameThread(const FString& SessionId);
397 void OnBackendError_Internal_GameThread(const FString& ErrorMessage);
398
399private:
400 void ReportError_Internal_GameThread(const FString& ErrorMessage);
401 void ReportConnectError_Internal_GameThread(const FString& ErrorMessage);
402 bool Disconnect_Internal_GameThread();
405 // ----------------------------------------------------------
406 // Debugging Tools
407 // ----------------------------------------------------------
408
409public:
423 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Debugging")
424 INSTANT3DHUB_API bool RequestRemoteCullerDebugStream();
425
438 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Debugging")
439 INSTANT3DHUB_API UTexture2D* GetRemoteCullerDebugStreamTexture();
440
452 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Debugging")
453 INSTANT3DHUB_API const TArray<FI3DHDebugMetric>& GetDebugMetrics();
454
466 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Debugging")
467 INSTANT3DHUB_API FString GetDebugSessionInfo();
468
469 // ----------------------------------------------------------
470 // Progress
471 // ----------------------------------------------------------
472
473public:
485 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Progress")
486 INSTANT3DHUB_API FI3DHClientProgress GetClientProgress();
487
488 // ----------------------------------------------------------
489 // ClipPlane API
490 // ----------------------------------------------------------
491public:
496 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Clip Plane API")
497 FClipPlaneCreatedDelegate OnClipPlaneCreatedDelegate;
498
503 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Clip Plane API")
504 FClipPlaneRemovedDelegate OnClipPlaneRemovedDelegate;
505
511 UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0.1", ClampMax = "120.0", UIMin = "0.1", UIMax = "120.0"), Category = "{instant3Dhub}|Clip Plane API")
512 float ClipPlaneSyncHz = 1.0;
513
518 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Clip Plane API")
519 TSubclassOf<AActor> ClipPlaneActorClass = nullptr;
520
526 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Clip Plane API")
527 INSTANT3DHUB_API TArray<int32> GetClipPlanes();
528
535 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Clip Plane API")
536 INSTANT3DHUB_API AActor* FindClipPlaneActor(int32 ClipPlaneId);
537
543 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Clip Plane API")
544 INSTANT3DHUB_API AActor* GetMainClipPlaneActor();
545
546 // ----------------------------------------------------------
547 // Drawing API
548 // ----------------------------------------------------------
549public:
557 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Drawing API", AdvancedDisplay)
558 TObjectPtr<UMaterialInterface> DrawingBaseMaterial{nullptr};
559
567 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Drawing API", AdvancedDisplay)
568 TObjectPtr<class UStaticMesh> DrawingSegmentMesh{nullptr};
569
576 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Drawing API", AdvancedDisplay)
577 TObjectPtr<class UStaticMesh> DrawingJointMesh{nullptr};
578
586 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API", meta = (DisplayName = "Create Drawing Material"))
587 INSTANT3DHUB_API UMaterialInterface* GetDrawingMaterial(FLinearColor Color);
588
596 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
597 INSTANT3DHUB_API class AI3DHDrawing* FindDrawingActor(int32 DrawingHandle);
598
605 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
606 INSTANT3DHUB_API void SetClipDrawingsByClipPlane(const bool bClipDrawingsByClipPlaneEnabled);
607
614 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
615 INSTANT3DHUB_API bool GetClipDrawingsByClipPlane();
616
617 // ----------------------------------------------------------
618 // EditDrawing API
619 // ----------------------------------------------------------
620public:
634 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|EditDrawing API")
635 virtual void EditDrawing(int32 DrawingHandle, const TScriptInterface<class II3DHEditDrawingInterface>& EditDrawingInterface, bool bIsEditingCopy = false);
636
637 // ----------------------------------------------------------
638 // InstanceGraph API
639 // ----------------------------------------------------------
640public:
646 UFUNCTION(BlueprintPure, Category = "{instant3Dhub}|Instance Graph API")
647 INSTANT3DHUB_API int32 GetGlobalRootNodeId();
648
649 // ----------------------------------------------------------
650 // Selection API
651 // ----------------------------------------------------------
652public:
659 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Selection API")
660 INSTANT3DHUB_API TArray<int32> GetSelection();
661
662 // ----------------------------------------------------------
663 // TransformAuthority API
664 // ----------------------------------------------------------
665public:
666 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
675 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Get WorldTransform With Authority (Experimental)"))
676 INSTANT3DHUB_API bool GetWorldTransformWithAuthority(const FI3DHTransformAuthorityHandle TransformAuthorityHandle, int32 NodeId, FMatrix& OutWorldTransform);
677
678 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
686 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Set WorldTransform With Authority (Experimental)"))
687 INSTANT3DHUB_API void SetWorldTransformWithAuthority(const FI3DHTransformAuthorityHandle TransformAuthorityHandle, int32 NodeId, const FMatrix& WorldTransform);
688
689 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
696 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Release TransformAuthority (Experimental)"))
697 INSTANT3DHUB_API void ReleaseTransformAuthority(const FI3DHTransformAuthorityHandle TransformAuthorityHandle);
698
699 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
705 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Is TransformAuthority Active (Experimental)"))
706 INSTANT3DHUB_API bool IsTransformAuthorityActive(const FI3DHTransformAuthorityHandle TransformAuthorityHandle) const;
707
708 // ----------------------------------------------------------
709 // Runtime adjustable performance parameters
710 // ----------------------------------------------------------
711public:
713 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3Dhub}|Connector", meta = (ClampMin = 1, UIMin = 1))
714 int32 MaxConversionTasksCreatedPerTick = 8;
715
717 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3Dhub}|Connector", meta = (ClampMin = 1, UIMin = 1))
718 int32 MaxComponentsCreatedPerTick = 2;
719
725 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "{instant3Dhub}|Connector", meta = (ClampMin = 0, UIMin = 0, Delta = 1000000))
726 int32 TargetedTrianglesOnComponentsWithVisibility = 10000000;
727
732 UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0.1", ClampMax = "100.0", UIMin = "0.1", UIMax = "100.0"), Category = "{instant3Dhub}|Connector")
733 float CreateComponentsBudgetMs = 5.0f;
734
739 UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0.1", ClampMax = "120.0", UIMin = "0.1", UIMax = "120.0"), Category = "{instant3Dhub}|Connector")
740 float ViewSyncHz = 5.0;
741
742protected:
747 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
748 TObjectPtr<class UMaterialParameterCollection> I3DHParameterCollection = nullptr;
749
750 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
752 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
753 TSubclassOf<AI3DHGeometry> GeometryActorClass;
754 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
755
757 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
758 bool bSpawnedGeometryCastsShadow = false;
759
760protected:
762 UPROPERTY(VisibleAnywhere, Category = "{instant3Dhub}|Connector")
763 TObjectPtr<USceneComponent> RootComponentConnector;
764
766 // ----------------------------------------------------------
767 // Internal
768 // ----------------------------------------------------------
769public:
770 FI3DHConnectorDrawingStorage& GetDrawingStorage();
771 const FI3DHConnectorDrawingStorage& GetDrawingStorage() const;
772
773 FI3DHConnectorRenderStorage& GetRenderStorage();
774 const FI3DHConnectorRenderStorage& GetRenderStorage() const;
775
776 const FI3DHConnectorRenderStats& GetRenderStats() const;
777
778 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
780 AI3DHGeometry* FindGeometryActor(int32 RootNodeId);
781 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
782
783 UMaterialParameterCollectionInstance* GetI3DHParameterCollectionInstance() const;
784
785private:
786 TMap<FString, FString> NetworkCredentialCookies;
787 TMap<FString, FString> NetworkCredentialTokens;
788
789 FString HubURL;
790 FString SessionId;
791
792 bool bReloadKeyPressedLastFrame = false;
793 bool bDebugStreamKeyPressedLastFrame = false;
794
795 // Timings for measuring time to first pixel.
796 // All values in seconds of platform time.
797 //
798 // Note that the camera position and orientation can influence the timings
799 // via effects on the remote culler. For accurate measurements the camera
800 // should be in a fixed position pointing at the scene.
801 double ConnectTime;
802 double FirstVisibilityTime;
803 double FirstActorTime;
804
805 // Time estimates for CreateMeshComponents budgeting.
806 // The estimates are updated using exponential moving averages.
807 // For the physics build we assume (based on our tests) that
808 // the constant overhead is negligible and the time is
809 // fully dependent on the per-triangle cost.
810 // Initial values are based on measurements on my computer.
811 double EstimatedSpawnGeometryActorTime = 0.180e-3; // seconds
812 double EstimatedSpawnMeshComponentStaticTime = 0.600e-3; // seconds
813 double EstimatedPhysicsBuildTimePerTriangle = 0.240e-6; // seconds per triangle
814
815 FTimerHandle ViewSyncTimer;
816
817 UPROPERTY()
818 FI3DHConnectorDrawingStorage DrawingStorage;
819
820 UPROPERTY()
821 FI3DHConnectorRenderStorage RenderStorage;
822
823 TArray<FI3DHDebugMetric> DebugMetrics;
824 // Timing metrics in milliseconds.
825 int32 MetricTimingVisibilityMs = 0;
826 int32 MetricTimingGeometryMs = 0;
827
828 // API and Backend
829 // ----------------------------------------------------------
830 TSharedPtr<class FI3DHConnectorAPIImpl> APIImpl;
831
832 TSharedPtr<class FI3DHConnectionPromiseImpl> ConnectionPromise;
833
834 TSharedPtr<class FI3DHConnectorBackend> ConnectorBackend;
835 TSharedPtr<class FI3DHEventBackend> EventBackend;
836 TSharedPtr<class FI3DHRenderBackend> RenderBackend;
837
838private:
839 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
847 AI3DHGeometry* SpawnGeometryActor(AActor* AttachActor, int32 RootNodeId, const struct FI3DHInstanceSpawnProperties& SpawnProperties);
848 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
849
850 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
858 UStaticMeshComponent* SpawnMeshComponentFromTask(FI3DHPageInstanceHandle PageInstanceHandle, AI3DHGeometry* AttachActor, const FI3DHPageToStaticMeshTask& Task, double& PhysicsBuildTime);
859 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
860
866 void FinishPhysicsAsyncCook(bool bSuccess, UBodySetup* FinishedBodySetup);
867
868public:
872 void SetAppearance_Internal(const FLinearColor& OverrideColor, EAppearanceURIMode OverrideMode, const TArray<int32>& RootNodeIds);
873
879 void SetTransforms_Internal(const TArray<FMatrix>& GlobalTransforms, const TArray<int32>& RootNodeIds);
880
887 void SetEnabled_Internal(bool bNewEnabled, const TArray<int32>& RootNodeIds);
888
895 void SetVariantEnabled_Internal(bool bNewVariantEnabled, const TArray<int32>& RootNodeIds);
896
902 void SetSelected_Internal(bool bNewSelected, const TArray<int32>& RootNodeIds);
903
908 void RemoveGeometryActors_Internal(const TArray<int32>& RootNodeIds);
909
910private:
911 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
916 void UpdateMeshComponentVisibilityAfterActorHiddenInGameStateChange_Internal(AI3DHGeometry* GeometryActor);
917 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
918
919 struct HubCameraParameters
920 {
921 int32 Width;
922 int32 Height;
923 FMatrix44f ViewMatrix;
924 FMatrix44f ProjectionMatrix;
925 };
931 HubCameraParameters GetHubCameraParamsForPlayer(const APlayerController* PlayerController);
932
933 void ViewSyncTimerCallback();
934
935private:
936 TSharedPtr<class FI3DHEventStreamConnector> EventStreamConnector;
937
938private:
939 void AddCredentialHeaders(const FString& URL, TMap<FString, FString>& Headers);
940 void ToggleDebugStreamOverlayModeInternal();
941 void ToggleDebugStreamOverlayEnabledInteral();
942
943 TSharedPtr<class FI3DHDebugStreamConnector> DebugStreamConnector;
944
945 UPROPERTY(Transient)
946 TObjectPtr<class AI3DHDebugStreamOverlay> DebugStreamOverlay;
947
948private:
949 static bool TestIsValidDrawingMaterial(const UMaterialInterface* DrawingMaterial);
950
952};
DECLARE_DYNAMIC_MULTICAST_DELEGATE void FErrorDelegate(const FString &ErrorMessage)
Error Delegate Type.
DECLARE_DYNAMIC_MULTICAST_DELEGATE void FClipPlaneCreatedDelegate(int32 ClipPlaneId, AActor *ClipPlaneActor, bool OwnEvent)
Delegate type invoked when a clip plane is created.
DECLARE_DYNAMIC_MULTICAST_DELEGATE void FDisconnectedDelegate()
Disconnected Delegate Type.
DECLARE_DYNAMIC_MULTICAST_DELEGATE void FClipPlaneRemovedDelegate(int32 ClipPlaneId, bool OwnEvent)
Delegate type invoked when a clip plane is removed.
DECLARE_DYNAMIC_MULTICAST_DELEGATE void FConnectErrorDelegate(const FString &ErrorMessage)
Connect Error Delegate Type.
DECLARE_DYNAMIC_MULTICAST_DELEGATE void FConnectedDelegate()
Connected Delegate Type.
@ Transform
Transform (represented as FMatrix in Unreal)
@ EditDrawing
EditDrawing Mode:
Actor containing mesh components used to represent instant3Dhub geometry.
Definition I3DHGeometry.h:80
Contains optional parameters for connecting to the hub.
Definition I3DHConnector.h:89