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(FDisconnectedDelegate);
31
41DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FClipPlaneCreatedDelegate, int32, ClipPlaneId, AActor*, ClipPlaneActor, bool, OwnEvent);
42
49DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FClipPlaneRemovedDelegate, int32, ClipPlaneId, bool, OwnEvent);
50
85USTRUCT(BlueprintType, Category = "{instant3Dhub}|Connector")
87{
88 GENERATED_BODY()
89
90
98 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "{instant3Dhub}|ConnectOptions")
99 FString SessionId;
100
109 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "{instant3Dhub}|ConnectOptions")
110 FString RestoreSessionId;
111};
112
117UCLASS(ClassGroup = "instant3Dhub", MinimalAPI)
118class AI3DHConnector : public AActor
119{
120 GENERATED_BODY()
121
122public:
123 INSTANT3DHUB_API AI3DHConnector();
124
125
126protected:
127 INSTANT3DHUB_API virtual void BeginPlay() override;
128 INSTANT3DHUB_API virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
129
130 INSTANT3DHUB_API virtual void Tick(float DeltaTime) override;
131
132#if WITH_EDITOR
133 INSTANT3DHUB_API virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
134#endif
135
136 // ----------------------------------------------------------
137 // API Accessor
138 // ----------------------------------------------------------
139public:
147 INSTANT3DHUB_API TSharedPtr<FI3DHConnectorAPI> GetAPI() const;
148
149 // ----------------------------------------------------------
150 // ConnectorAPI
151 // ----------------------------------------------------------
152public:
159 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
160 INSTANT3DHUB_API void AddNetworkCredentialCookie(const FString& CookieKey, const FString& CookieValue);
161
167 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
168 INSTANT3DHUB_API void RemoveNetworkCredentialCookie(const FString& CookieKey);
169
176 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
177 INSTANT3DHUB_API void AddNetworkCredentialToken(const FString& TokenKey, const FString& TokenValue);
178
184 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
185 INSTANT3DHUB_API void RemoveNetworkCredentialToken(const FString& TokenKey);
186
192 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
193 INSTANT3DHUB_API const TMap<FString, FString>& GetNetworkCredentialCookies() const { return NetworkCredentialCookies; }
194
200 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
201 INSTANT3DHUB_API const TMap<FString, FString>& GetNetworkCredentialTokens() const { return NetworkCredentialTokens; }
202
238 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Connector")
239 INSTANT3DHUB_API void ConnectToHub(const FString& HubURL, const FString& SessionId);
240
251 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Connector")
252 INSTANT3DHUB_API void ConnectToHubWithOptions(const FString& HubURL, const FI3DHConnectOptions& Options);
253
255 void OnBackendConnected_Internal_GameThread(const FString& SessionId);
256 void OnBackendConnectError_Internal_GameThread(const FString& ErrorMessage);
257 void ReportConnectError_Internal_GameThread(const FString& ErrorMessage);
268 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Connector")
269 INSTANT3DHUB_API void Disconnect();
270
277 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
278 INSTANT3DHUB_API bool IsDisconnected() const;
279
286 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
287 INSTANT3DHUB_API bool IsEstablishingConnectionToHub() const;
288
294 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
295 INSTANT3DHUB_API bool IsConnectedToHub() const;
296
302 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
303 INSTANT3DHUB_API FString GetHubURL() const;
304
310 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
311 INSTANT3DHUB_API FString GetSessionId() const;
312
317 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
318 FConnectedDelegate OnConnectedDelegate;
319
324 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
325 FConnectErrorDelegate OnConnectErrorDelegate;
326
331 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
332 FDisconnectedDelegate OnDisconnectedDelegate;
333
339 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
340 INSTANT3DHUB_API FMatrix GetOriginToWorldTransform() const;
341
347 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
348 INSTANT3DHUB_API FMatrix GetWorldToOriginTransform() const;
349
353 INSTANT3DHUB_API AActor* GetOriginActor()
354 {
355 AActor* RootActor = this;
356 check(RootActor != nullptr);
357 return RootActor;
358 }
359
363 INSTANT3DHUB_API const AActor* GetOriginActor() const
364 {
365 const AActor* RootActor = this;
366 check(RootActor != nullptr);
367 return RootActor;
368 }
369
370 // ----------------------------------------------------------
371 // Debugging Tools
372 // ----------------------------------------------------------
373
374public:
388 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Debugging")
389 INSTANT3DHUB_API bool RequestRemoteCullerDebugStream();
390
403 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Debugging")
404 INSTANT3DHUB_API UTexture2D* GetRemoteCullerDebugStreamTexture();
405
417 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Debugging")
418 INSTANT3DHUB_API const TArray<FI3DHDebugMetric>& GetDebugMetrics();
419
420 // ----------------------------------------------------------
421 // Progress
422 // ----------------------------------------------------------
423
424public:
436 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Progress")
437 INSTANT3DHUB_API FI3DHClientProgress GetClientProgress();
438
439 // ----------------------------------------------------------
440 // ClipPlane API
441 // ----------------------------------------------------------
442public:
447 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Clip Plane API")
448 FClipPlaneCreatedDelegate OnClipPlaneCreatedDelegate;
449
454 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Clip Plane API")
455 FClipPlaneRemovedDelegate OnClipPlaneRemovedDelegate;
456
461 UPROPERTY(EditAnywhere, meta = (ClampMin = "0.1", ClampMax = "120.0", UIMin = "0.1", UIMax = "120.0"), Category = "{instant3Dhub}|Clip Plane API")
462 float ClipPlaneSyncHz = 1.0;
463
468 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Clip Plane API")
469 TSubclassOf<AActor> ClipPlaneActorClass = nullptr;
470
476 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Clip Plane API")
477 INSTANT3DHUB_API TArray<int32> GetClipPlanes();
478
485 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Clip Plane API")
486 INSTANT3DHUB_API AActor* FindClipPlaneActor(int32 ClipPlaneId);
487
493 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Clip Plane API")
494 INSTANT3DHUB_API AActor* GetMainClipPlaneActor();
495
496 // ----------------------------------------------------------
497 // Drawing API
498 // ----------------------------------------------------------
499public:
507 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Drawing API", AdvancedDisplay)
508 TObjectPtr<UMaterialInterface> DrawingBaseMaterial{nullptr};
509
517 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Drawing API", AdvancedDisplay)
518 TObjectPtr<class UStaticMesh> DrawingSegmentMesh{nullptr};
519
526 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Drawing API", AdvancedDisplay)
527 TObjectPtr<class UStaticMesh> DrawingJointMesh{nullptr};
528
536 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API", meta = (DisplayName = "Create Drawing Material"))
537 INSTANT3DHUB_API UMaterialInterface* GetDrawingMaterial(FLinearColor Color);
538
546 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
547 INSTANT3DHUB_API class AI3DHDrawing* FindDrawingActor(int32 DrawingHandle);
548
555 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
556 INSTANT3DHUB_API void SetClipDrawingsByClipPlane(const bool bClipDrawingsByClipPlaneEnabled);
557
564 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
565 INSTANT3DHUB_API bool GetClipDrawingsByClipPlane();
566
567 // ----------------------------------------------------------
568 // EditDrawing API
569 // ----------------------------------------------------------
570public:
584 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|EditDrawing API")
585 virtual void EditDrawing(int32 DrawingHandle, const TScriptInterface<class II3DHEditDrawingInterface>& EditDrawingInterface, bool bIsEditingCopy = false);
586
587 // ----------------------------------------------------------
588 // InstanceGraph API
589 // ----------------------------------------------------------
590public:
591
597 UFUNCTION(BlueprintPure, Category = "{instant3Dhub}|Instance Graph API")
598 INSTANT3DHUB_API int32 GetGlobalRootNodeId();
599
600
601 // ----------------------------------------------------------
602 // Selection API
603 // ----------------------------------------------------------
604public:
611 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Selection API")
612 INSTANT3DHUB_API TArray<int32> GetSelection();
613
614 // ----------------------------------------------------------
615 // TransformAuthority API
616 // ----------------------------------------------------------
617public:
618 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
627 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Get WorldTransform With Authority (Experimental)"))
628 INSTANT3DHUB_API bool GetWorldTransformWithAuthority(const FI3DHTransformAuthorityHandle TransformAuthorityHandle, int32 NodeId, FMatrix& OutWorldTransform);
629
630 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
638 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Set WorldTransform With Authority (Experimental)"))
639 INSTANT3DHUB_API void SetWorldTransformWithAuthority(const FI3DHTransformAuthorityHandle TransformAuthorityHandle, int32 NodeId, const FMatrix& WorldTransform);
640
641 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
648 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Release TransformAuthority (Experimental)"))
649 INSTANT3DHUB_API void ReleaseTransformAuthority(const FI3DHTransformAuthorityHandle TransformAuthorityHandle);
650
651 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
657 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Is TransformAuthority Active (Experimental)"))
658 INSTANT3DHUB_API bool IsTransformAuthorityActive(const FI3DHTransformAuthorityHandle TransformAuthorityHandle) const;
659
660protected:
665 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
666 TObjectPtr<class UMaterialParameterCollection> I3DHParameterCollection = nullptr;
667
668 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
670 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
671 TSubclassOf<AI3DHGeometry> GeometryActorClass;
672 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
673
675 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
676 bool bSpawnedGeometryCastsShadow = false;
677
679 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
680 int32 MaxComponentsCreatedPerTick = 2;
681
687 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
688 int32 TargetedTrianglesOnComponentsWithVisibility = 10000000;
689
691 UPROPERTY(EditAnywhere, meta = (ClampMin = "0.1", ClampMax = "120.0", UIMin = "0.1", UIMax = "120.0"), Category = "{instant3Dhub}|Connector")
692 float ViewSyncHz = 5.0;
693
695 UPROPERTY(VisibleAnywhere, Category = "{instant3Dhub}|Connector")
696 TObjectPtr<USceneComponent> RootComponentConnector;
697
699 // ----------------------------------------------------------
700 // Internal
701 // ----------------------------------------------------------
702public:
703 FI3DHConnectorDrawingStorage& GetDrawingStorage();
704 const FI3DHConnectorDrawingStorage& GetDrawingStorage() const;
705
706 FI3DHConnectorRenderStorage& GetRenderStorage();
707 const FI3DHConnectorRenderStorage& GetRenderStorage() const;
708
709 const FI3DHConnectorRenderStats& GetRenderStats() const;
710
711 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
713 AI3DHGeometry* FindGeometryActor(int32 RootNodeId);
714 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
715
716 UMaterialParameterCollectionInstance* GetI3DHParameterCollectionInstance() const;
717
718private:
719 TMap<FString, FString> NetworkCredentialCookies;
720 TMap<FString, FString> NetworkCredentialTokens;
721
722 FString HubURL;
723 FString SessionId;
724
725 bool bReloadKeyPressedLastFrame = false;
726 bool bDebugStreamKeyPressedLastFrame = false;
727
728 // Timings for measuring time to first pixel.
729 // All values in seconds of platform time.
730 //
731 // Note that the camera position and orientation can influence the timings
732 // via effects on the remote culler. For accurate measurements the camera
733 // should be in a fixed position pointing at the scene.
734 double ConnectTime;
735 double FirstVisibilityTime;
736 double FirstActorTime;
737
738 FTimerHandle ViewSyncTimer;
739
740 UPROPERTY()
741 FI3DHConnectorDrawingStorage DrawingStorage;
742
743 UPROPERTY()
744 FI3DHConnectorRenderStorage RenderStorage;
745
746 TArray<FI3DHDebugMetric> DebugMetrics;
747 int32 MetricTimingVisibility = 0;
748 int32 MetricTimingGeometry = 0;
749
750 // API and Backend
751 // ----------------------------------------------------------
752 TSharedPtr<class FI3DHConnectorAPIImpl> APIImpl;
753
754 TSharedPtr<class FI3DHConnectionPromiseImpl> ConnectionPromise;
755
756 TSharedPtr<class FI3DHConnectorBackend> ConnectorBackend;
757 TSharedPtr<class FI3DHEventBackend> EventBackend;
758 TSharedPtr<class FI3DHRenderBackend> RenderBackend;
759
760private:
761 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
769 AI3DHGeometry* SpawnGeometryActor(AActor* AttachActor, int32 RootNodeId, const struct FI3DHInstanceSpawnProperties& SpawnProperties);
770 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
771
772 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
780 UStaticMeshComponent* SpawnMeshComponentFromTask(FI3DHPageInstanceHandle PageInstanceHandle, AI3DHGeometry* AttachActor, const FI3DHPageToStaticMeshTask& Task);
781 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
782
788 void FinishPhysicsAsyncCook(bool bSuccess, UBodySetup* FinishedBodySetup);
789
790public:
794 void SetAppearance_Internal(const FLinearColor& OverrideColor, EAppearanceURIMode OverrideMode, const TArray<int32>& RootNodeIds);
795
801 void SetTransforms_Internal(const TArray<FMatrix>& GlobalTransforms, const TArray<int32>& RootNodeIds);
802
809 void SetEnabled_Internal(bool bNewEnabled, const TArray<int32>& RootNodeIds);
810
817 void SetVariantEnabled_Internal(bool bNewVariantEnabled, const TArray<int32>& RootNodeIds);
818
824 void SetSelected_Internal(bool bNewSelected, const TArray<int32>& RootNodeIds);
825
826private:
827 PRAGMA_DISABLE_EXPERIMENTAL_WARNINGS
832 void UpdateMeshComponentVisibilityAfterActorHiddenInGameStateChange_Internal(AI3DHGeometry* GeometryActor);
833 PRAGMA_ENABLE_EXPERIMENTAL_WARNINGS
834
835 struct HubCameraParameters
836 {
837 int32 Width;
838 int32 Height;
839 FMatrix44f ViewMatrix;
840 FMatrix44f ProjectionMatrix;
841 };
847 HubCameraParameters GetHubCameraParamsForPlayer(const APlayerController* PlayerController);
848
849 void ViewSyncTimerCallback();
850
851private:
852 void AddCredentialHeaders(const FString& URL, TMap<FString, FString>& Headers);
853 void ToggleDebugStreamOverlayModeInternal();
854 void ToggleDebugStreamOverlayEnabledInteral();
855
856 TUniquePtr<class FI3DHDebugStreamConnector> DebugStreamConnector;
857
858 UPROPERTY(Transient)
859 TObjectPtr<class AI3DHDebugStreamOverlay> DebugStreamOverlay;
860
861private:
862 static bool TestIsValidDrawingMaterial(const UMaterialInterface* DrawingMaterial);
863
865};
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:59
Contains optional parameters for connecting to the hub.
Definition I3DHConnector.h:87