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 "GameFramework/Actor.h"
16
17#include "I3DHConnector.generated.h"
18
19class AI3DHGeometry;
21class FI3DHPageToStaticMeshTask;
22class UBodySetup;
23
25DECLARE_DYNAMIC_MULTICAST_DELEGATE(FConnectedDelegate);
27DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FConnectErrorDelegate, const FString&, ErrorMessage);
29DECLARE_DYNAMIC_MULTICAST_DELEGATE(FDisconnectedDelegate);
30
40DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FClipPlaneCreatedDelegate, int32, ClipPlaneId, AActor*, ClipPlaneActor, bool, OwnEvent);
41
48DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FClipPlaneRemovedDelegate, int32, ClipPlaneId, bool, OwnEvent);
49
64USTRUCT(BlueprintType, Category = "{instant3Dhub}|Connector")
66{
67 GENERATED_BODY()
68
69
77 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "{instant3Dhub}|ConnectOptions")
78 FString SessionId;
79
88 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "{instant3Dhub}|ConnectOptions")
89 FString RestoreSessionId;
90};
91
96UCLASS(ClassGroup = "instant3Dhub", MinimalAPI)
97class AI3DHConnector : public AActor
98{
99 GENERATED_BODY()
100
101public:
102 INSTANT3DHUB_API AI3DHConnector();
103
104
105protected:
106 INSTANT3DHUB_API virtual void BeginPlay() override;
107 INSTANT3DHUB_API virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
108
109 INSTANT3DHUB_API virtual void Tick(float DeltaTime) override;
110
111 // ----------------------------------------------------------
112 // API Accessor
113 // ----------------------------------------------------------
114public:
122 INSTANT3DHUB_API TSharedPtr<FI3DHConnectorAPI> GetAPI() const;
123
124 // ----------------------------------------------------------
125 // ConnectorAPI
126 // ----------------------------------------------------------
127public:
134 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
135 INSTANT3DHUB_API void AddNetworkCredentialCookie(const FString& CookieKey, const FString& CookieValue);
136
142 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
143 INSTANT3DHUB_API void RemoveNetworkCredentialCookie(const FString& CookieKey);
144
151 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
152 INSTANT3DHUB_API void AddNetworkCredentialToken(const FString& TokenKey, const FString& TokenValue);
153
159 UFUNCTION(BlueprintCallable, BlueprintPure = false, Category = "{instant3Dhub}|Connector")
160 INSTANT3DHUB_API void RemoveNetworkCredentialToken(const FString& TokenKey);
161
167 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
168 INSTANT3DHUB_API const TMap<FString, FString>& GetNetworkCredentialCookies() const { return NetworkCredentialCookies; }
169
175 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
176 INSTANT3DHUB_API const TMap<FString, FString>& GetNetworkCredentialTokens() const { return NetworkCredentialTokens; }
177
217 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Connector")
218 INSTANT3DHUB_API void ConnectToHub(const FString& HubURL, const FString& SessionId);
219
230 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Connector")
231 INSTANT3DHUB_API void ConnectToHubWithOptions(const FString& HubURL, const FI3DHConnectOptions& Options);
232
234 void OnBackendConnected_Internal_GameThread(const FString& SessionId);
235 void OnBackendConnectError_Internal_GameThread(const FString& ErrorMessage);
246 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Connector")
247 INSTANT3DHUB_API void Disconnect();
248
255 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
256 INSTANT3DHUB_API bool IsDisconnected() const;
257
264 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
265 INSTANT3DHUB_API bool IsEstablishingConnectionToHub() const;
266
272 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
273 INSTANT3DHUB_API bool IsConnectedToHub() const;
274
280 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
281 INSTANT3DHUB_API FString GetHubURL() const;
282
288 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
289 INSTANT3DHUB_API FString GetSessionId() const;
290
295 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
296 FConnectedDelegate OnConnectedDelegate;
297
302 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
303 FConnectErrorDelegate OnConnectErrorDelegate;
304
309 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Connector")
310 FDisconnectedDelegate OnDisconnectedDelegate;
311
317 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
318 INSTANT3DHUB_API FMatrix GetOriginToWorldTransform() const;
319
325 UFUNCTION(BlueprintCallable, BlueprintPure, Category = "{instant3Dhub}|Connector")
326 INSTANT3DHUB_API FMatrix GetWorldToOriginTransform() const;
327
331 INSTANT3DHUB_API AActor* GetOriginActor()
332 {
333 AActor* RootActor = this;
334 check(RootActor != nullptr);
335 return RootActor;
336 }
337
341 INSTANT3DHUB_API const AActor* GetOriginActor() const
342 {
343 const AActor* RootActor = this;
344 check(RootActor != nullptr);
345 return RootActor;
346 }
347
348 // ----------------------------------------------------------
349 // ClipPlane API
350 // ----------------------------------------------------------
351public:
356 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Clip Plane API")
357 FClipPlaneCreatedDelegate OnClipPlaneCreatedDelegate;
358
363 UPROPERTY(BlueprintAssignable, Transient, Category = "{instant3Dhub}|Clip Plane API")
364 FClipPlaneRemovedDelegate OnClipPlaneRemovedDelegate;
365
370 UPROPERTY(EditAnywhere, meta = (ClampMin = "0.1", ClampMax = "120.0", UIMin = "0.1", UIMax = "120.0"), Category = "{instant3Dhub}|Clip Plane API")
371 float ClipPlaneSyncHz = 1.0;
372
377 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Clip Plane API")
378 TSubclassOf<AActor> ClipPlaneActorClass = nullptr;
379
385 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Clip Plane API")
386 INSTANT3DHUB_API TArray<int32> GetClipPlanes();
387
394 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Clip Plane API")
395 INSTANT3DHUB_API AActor* FindClipPlaneActor(int32 ClipPlaneId);
396
402 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Clip Plane API")
403 INSTANT3DHUB_API AActor* GetMainClipPlaneActor();
404
405 // ----------------------------------------------------------
406 // Drawing API
407 // ----------------------------------------------------------
408public:
414 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Drawing API")
415 TObjectPtr<UMaterialInterface> DrawingBaseMaterial{nullptr};
416
421 UPROPERTY(EditAnywhere, meta = (ClampMin = "0.1", ClampMax = "120.0", UIMin = "0.1", UIMax = "120.0"), Category = "{instant3Dhub}|Drawing API")
422 float DrawingSyncHz = 1.0;
423
432 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
433 INSTANT3DHUB_API UMaterialInterface* GetDrawingMaterial(FLinearColor Color);
434
442 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
443 INSTANT3DHUB_API class AI3DHDrawing* FindDrawingActor(int DrawingHandle);
444
451 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
452 INSTANT3DHUB_API void SetClipDrawingsByClipPlane(const bool bClipDrawingsByClipPlaneEnabled);
453
460 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Drawing API")
461 INSTANT3DHUB_API bool GetClipDrawingsByClipPlane();
462
463 // ----------------------------------------------------------
464 // InstanceGraph API
465 // ----------------------------------------------------------
466public:
467
473 UFUNCTION(BlueprintPure, Category = "{instant3Dhub}|Instance Graph API")
474 INSTANT3DHUB_API int32 GetGlobalRootNodeId();
475
476
477 // ----------------------------------------------------------
478 // Selection API
479 // ----------------------------------------------------------
480public:
487 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Selection API")
488 INSTANT3DHUB_API TArray<int32> GetSelection();
489
490 // ----------------------------------------------------------
491 // TransformAuthority API
492 // ----------------------------------------------------------
493public:
494 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
503 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Get WorldTransform With Authority (Experimental)"))
504 INSTANT3DHUB_API bool GetWorldTransformWithAuthority(const FI3DHTransformAuthorityHandle TransformAuthorityHandle, int NodeId, FMatrix& OutWorldTransform);
505
506 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
514 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Set WorldTransform With Authority (Experimental)"))
515 INSTANT3DHUB_API void SetWorldTransformWithAuthority(const FI3DHTransformAuthorityHandle TransformAuthorityHandle, int NodeId, const FMatrix& WorldTransform);
516
517 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
524 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Release TransformAuthority (Experimental)"))
525 INSTANT3DHUB_API void ReleaseTransformAuthority(const FI3DHTransformAuthorityHandle TransformAuthorityHandle);
526
527 INSTANT3DHUB_EXPERIMENTAL(0.0.23, "TransformAuthorityAPI is a temporary solution suspect to changes or replacement.")
533 UFUNCTION(BlueprintCallable, Category = "{instant3Dhub}|Transform Authority", meta = (DisplayName = "Is TransformAuthority Active (Experimental)"))
534 INSTANT3DHUB_API bool IsTransformAuthorityActive(const FI3DHTransformAuthorityHandle TransformAuthorityHandle) const;
535
536protected:
541 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
542 TObjectPtr<class UMaterialParameterCollection> I3DHParameterCollection = nullptr;
543
545 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
546 TSubclassOf<AI3DHGeometry> GeometryActorClass;
547
549 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
550 bool bSpawnedGeometryCastsShadow = false;
551
553 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
554 int MaxComponentsCreatedPerTick = 2;
555
561 UPROPERTY(EditAnywhere, Category = "{instant3Dhub}|Connector")
562 int32 TargetedTrianglesOnComponentsWithVisibility = 10000000;
563
565 UPROPERTY(EditAnywhere, meta = (ClampMin = "0.1", ClampMax = "120.0", UIMin = "0.1", UIMax = "120.0"), Category = "{instant3Dhub}|Connector")
566 float ViewSyncHz = 5.0;
567
569 UPROPERTY(VisibleAnywhere, Category = "{instant3Dhub}|Connector")
570 TObjectPtr<USceneComponent> RootComponentConnector;
571
573 // ----------------------------------------------------------
574 // Internal
575 // ----------------------------------------------------------
576public:
577 FI3DHConnectorDrawingStorage& GetDrawingStorage();
578 const FI3DHConnectorDrawingStorage& GetDrawingStorage() const;
579
580 FI3DHConnectorRenderStorage& GetRenderStorage();
581 const FI3DHConnectorRenderStorage& GetRenderStorage() const;
582
584 AI3DHGeometry* FindGeometryActor(int32 RootNodeId);
585
586 UMaterialParameterCollectionInstance* GetI3DHParameterCollectionInstance() const;
587
588private:
589 TMap<FString, FString> NetworkCredentialCookies;
590 TMap<FString, FString> NetworkCredentialTokens;
591
592 FString HubURL;
593 FString SessionId;
594
595 bool bReloadKeyPressedLastFrame = false;
596
597 // Timings for measuring time to first pixel.
598 // All values in seconds of platform time.
599 //
600 // Note that the camera position and orientation can influence the timings
601 // via effects on the remote culler. For accurate measurements the camera
602 // should be in a fixed position pointing at the scene.
603 double ConnectTime;
604 double FirstVisibilityTime;
605 double FirstActorTime;
606
607 FTimerHandle ViewSyncTimer;
608
609 UPROPERTY()
610 FI3DHConnectorDrawingStorage DrawingStorage;
611
612 UPROPERTY()
613 FI3DHConnectorRenderStorage RenderStorage;
614
615 // API and Backend
616 // ----------------------------------------------------------
617 TSharedPtr<class FI3DHConnectorAPIImpl> APIImpl;
618
619 TSharedPtr<class FI3DHConnectionPromiseImpl> ConnectionPromise;
620
621 TSharedPtr<class FI3DHConnectorBackend> ConnectorBackend;
622 TSharedPtr<class FI3DHEventBackend> EventBackend;
623 TSharedPtr<class FI3DHRenderBackend> RenderBackend;
624
625private:
633 AI3DHGeometry* SpawnGeometryActor(AActor* AttachActor, int32 RootNodeId, const struct FI3DHInstanceSpawnProperties& SpawnProperties);
634
642 UStaticMeshComponent* SpawnMeshComponentFromTask(FI3DHPageInstanceHandle PageInstanceHandle, AI3DHGeometry* AttachActor, const FI3DHPageToStaticMeshTask& Task);
643
649 void FinishPhysicsAsyncCook(bool bSuccess, UBodySetup* FinishedBodySetup);
650
651public:
655 void SetAppearance_Internal(const FLinearColor& OverrideColor, EAppearanceURIMode OverrideMode, const TArray<int32>& RootNodeIds);
656
662 void SetTransforms_Internal(const TArray<FMatrix>& GlobalTransforms, const TArray<int32>& RootNodeIds);
663
670 void SetEnabled_Internal(bool bNewEnabled, const TArray<int32>& RootNodeIds);
671
678 void SetVariantEnabled_Internal(bool bNewVariantEnabled, const TArray<int32>& RootNodeIds);
679
685 void SetSelected_Internal(bool bNewSelected, const TArray<int32>& RootNodeIds);
686
687private:
692 void UpdateMeshComponentVisibilityAfterActorHiddenInGameStateChange_Internal(AI3DHGeometry* GeometryActor);
693
694 struct HubCameraParameters
695 {
696 int Width;
697 int Height;
698 FMatrix44f ViewMatrix;
699 FMatrix44f ProjectionMatrix;
700 };
706 HubCameraParameters GetHubCameraParamsForPlayer(const APlayerController* PlayerController);
707
708 void ViewSyncTimerCallback();
709
711};
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)
Actor containing mesh components used to represent instant3Dhub geometry.
Definition I3DHGeometry.h:59
Contains optional parameters for connecting to the hub.
Definition I3DHConnector.h:66