diff --git a/Source/Private/MobuLiveLinkDevice.cpp b/Source/Private/MobuLiveLinkDevice.cpp index dc4c0db6..77ead0fa 100644 --- a/Source/Private/MobuLiveLinkDevice.cpp +++ b/Source/Private/MobuLiveLinkDevice.cpp @@ -51,9 +51,8 @@ FBRegisterDevice ( MOBULIVELINK__NAME, ************************************************/ bool FMobuLiveLink::FBCreate() { - // Set sampling rate to 60 Hz - CurrentSampleRate = FFrameRate(60, 1); - bShouldUpdateInRenderCallback = false; + // Set sampling rate to Before Render + CurrentSampleRate = SampleOptions.Last().Value; UpdateSampleRate(); StartLiveLink(); @@ -62,7 +61,7 @@ bool FMobuLiveLink::FBCreate() SetDirty(false); TSharedPtr EditorCamera = MakeShared(LiveLinkProvider); - StreamObjects.Emplace((kReference)nullptr, EditorCamera); + StreamObjects.Emplace(-1, EditorCamera); LastEvaluationTime = FPlatformTime::Seconds(); @@ -228,7 +227,7 @@ void FMobuLiveLink::UpdateStream() { UpdateStreamObjects(); } - for (TPair>& MapPair : StreamObjects) + for (TPair>& MapPair : StreamObjects) { const TSharedPtr& StreamObject = MapPair.Value; StreamObject->UpdateSubjectFrame(); @@ -314,7 +313,7 @@ bool FMobuLiveLink::FbxStore(FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat pFbxObject->FieldWriteI(MOBULIVELINK_NUMBER_OF_OBJECT_COLUMNS); // NumberOfObjects * NumberOfObjectColumns * ObjectColumn - for (TPair>& MapPair : StreamObjects) + for (TPair>& MapPair : StreamObjects) { const FString StreamObjectRootName = MapPair.Value->GetRootName(); @@ -368,7 +367,7 @@ bool FMobuLiveLink::FbxRetrieve(FBFbxObject* pFbxObject, kFbxObjectStore pStoreW { FBModel* FoundFBModel = (FBModel*)FoundModels[0]; TSharedPtr FoundStreamObject = StreamObjectManagement::FBModelToStreamObject(FoundFBModel, LiveLinkProvider); - StreamObjects.Emplace((kReference)FoundFBModel, FoundStreamObject); + StreamObjects.Emplace(GetNextUID(), FoundStreamObject); FName SubjectName(pFbxObject->FieldReadC()); int32 StreamingMode = pFbxObject->FieldReadI(); @@ -450,7 +449,7 @@ void FMobuLiveLink::EventSceneChange(HISender Sender, HKEvent Event) void FMobuLiveLink::UpdateStreamObjects() { - for (TPair>& MapPair : StreamObjects) + for (TPair>& MapPair : StreamObjects) { const TSharedPtr& StreamObject = MapPair.Value; if (StreamObject->IsValid()) @@ -471,4 +470,9 @@ void FMobuLiveLink::TickCoreTicker() double CurrentTime = FPlatformTime::Seconds(); FTicker::GetCoreTicker().Tick(CurrentTime - LastEvaluationTime); LastEvaluationTime = CurrentTime; +} + +int32 FMobuLiveLink::GetNextUID() +{ + return NextUID++; } \ No newline at end of file diff --git a/Source/Private/MobuLiveLinkLayout.cpp b/Source/Private/MobuLiveLinkLayout.cpp index c5538d34..f4fad4d1 100644 --- a/Source/Private/MobuLiveLinkLayout.cpp +++ b/Source/Private/MobuLiveLinkLayout.cpp @@ -157,9 +157,9 @@ void FMobuLiveLinkLayout::UIReset() FBTrace("UI Reset!\n"); StreamSpread.Clear(); CreateSpreadColumns(); - for (const TPair& MapPair : LiveLinkDevice->StreamObjects) + for (const TPair& MapPair : LiveLinkDevice->StreamObjects) { - AddSpreadRowFromStreamObject(MapPair.Value); + AddSpreadRowFromStreamObject(MapPair.Key, MapPair.Value); } LiveLinkDevice->SetRefreshUI(false); } @@ -176,28 +176,34 @@ void FMobuLiveLinkLayout::EventUIIdle(HISender Sender, HKEvent Event) } } -void FMobuLiveLinkLayout::AddSpreadRowFromStreamObject(StreamObjectPtr Object) +void FMobuLiveLinkLayout::AddSpreadRowFromStreamObject(int32 NewRowKey, StreamObjectPtr Object) { // Check whether the Object should be shown if (!Object->ShouldShowInUI()) return; - const kReference ObjectReference = Object->GetReference(); const FString RootName = Object->GetRootName(); - StreamSpread.RowAdd(FStringToChar(RootName), ObjectReference); + StreamSpread.RowAdd(FStringToChar(RootName), NewRowKey); - StreamSpread.SetCell(ObjectReference, 0, FStringToChar(Object->GetSubjectName().ToString())); - StreamSpread.SetCell(ObjectReference, 1, FStringToChar(Object->GetStreamOptions())); - StreamSpread.SetCell(ObjectReference, 1, Object->GetStreamingMode()); + StreamSpread.SetCell(NewRowKey, 0, FStringToChar(Object->GetSubjectName().ToString())); + StreamSpread.SetCell(NewRowKey, 1, FStringToChar(Object->GetStreamOptions())); + StreamSpread.SetCell(NewRowKey, 1, Object->GetStreamingMode()); bool bIsActive = Object->GetActiveStatus(); - StreamSpread.SetCell(ObjectReference, 2, bIsActive); - StreamSpread.SetCell(ObjectReference, 2, BoolToActiveText(bIsActive)); + StreamSpread.SetCell(NewRowKey, 2, bIsActive); + StreamSpread.SetCell(NewRowKey, 2, BoolToActiveText(bIsActive)); } bool IsModelInDeviceStream(const FMobuLiveLink* MobuDevice, const FBModel* Model) { - return MobuDevice->StreamObjects.Contains((kReference)Model); + for (const TPair>& StreamPair : MobuDevice->StreamObjects) + { + if (StreamPair.Value->GetModelPointer() == Model) + { + return true; + } + } + return false; } void FMobuLiveLinkLayout::EventAddToStream(HISender Sender, HKEvent Event) @@ -224,8 +230,9 @@ void FMobuLiveLinkLayout::EventAddToStream(HISender Sender, HKEvent Event) else if (!IsModelInDeviceStream(LiveLinkDevice, Model)) { StreamObjectPtr StoreObject = StreamObjectManagement::FBModelToStreamObject(Model, LiveLinkDevice->LiveLinkProvider); - LiveLinkDevice->StreamObjects.Emplace((kReference)Model, StoreObject); - AddSpreadRowFromStreamObject(StoreObject); + int32 NewUID = LiveLinkDevice->GetNextUID(); + LiveLinkDevice->StreamObjects.Emplace(NewUID, StoreObject); + AddSpreadRowFromStreamObject(NewUID, StoreObject); FBTrace("Added New Object to StreamObject\n"); ParentsToIgnore.Emplace(Model); @@ -238,11 +245,11 @@ void FMobuLiveLinkLayout::EventAddToStream(HISender Sender, HKEvent Event) void FMobuLiveLinkLayout::EventRemoveFromStream(HISender Sender, HKEvent Event) { int SelectedCount = 0; - TArray DeletionObjects; + TArray DeletionObjects; DeletionObjects.Reserve(LiveLinkDevice->StreamObjects.Num()); - for (const TPair& MapPair : LiveLinkDevice->StreamObjects) + for (const TPair& MapPair : LiveLinkDevice->StreamObjects) { - kReference RowKey = MapPair.Value->GetReference(); + int32 RowKey = MapPair.Key; bool bRowSelected = StreamSpread.GetRow(RowKey).RowSelected; if (bRowSelected) { @@ -250,7 +257,7 @@ void FMobuLiveLinkLayout::EventRemoveFromStream(HISender Sender, HKEvent Event) SelectedCount++; } } - for (const kReference& DeletionKey : DeletionObjects) + for (int32 DeletionKey : DeletionObjects) { LiveLinkDevice->StreamObjects.Remove(DeletionKey); } diff --git a/Source/Private/StreamObjectManagement.cpp b/Source/Private/StreamObjectManagement.cpp index 53a64208..4568851c 100644 --- a/Source/Private/StreamObjectManagement.cpp +++ b/Source/Private/StreamObjectManagement.cpp @@ -27,7 +27,7 @@ TSharedPtr StreamObjectManagement::FBModelToStreamObject(FBModel* TSharedPtr StreamObjectManagement::StoreCamera(const FBModel* Model, TSharedPtr LiveLinkProvider) { - FBTrace("%s is a Camera!\n", *Model->LongName); + FBTrace("%s is a Camera!\n", (const char*)Model->LongName); TSharedPtr CameraStore = MakeShared(Model, LiveLinkProvider); return CameraStore; @@ -35,7 +35,7 @@ TSharedPtr StreamObjectManagement::StoreCamera(const FBModel* Mod TSharedPtr StreamObjectManagement::StoreLight(const FBModel* Model, TSharedPtr LiveLinkProvider) { - FBTrace("%s is a Light!\n", *Model->LongName); + FBTrace("%s is a Light!\n", (const char*)Model->LongName); TSharedPtr LightStore = MakeShared(Model, LiveLinkProvider); return LightStore; @@ -43,7 +43,7 @@ TSharedPtr StreamObjectManagement::StoreLight(const FBModel* Mode TSharedPtr StreamObjectManagement::StoreSkeleton(const FBModel* Model, TSharedPtr LiveLinkProvider) { - FBTrace("%s is a Skeleton!\n", *Model->LongName); + FBTrace("%s is a Skeleton!\n", (const char*)Model->LongName); TSharedPtr SkeletonStore = MakeShared(Model, LiveLinkProvider); return SkeletonStore; @@ -51,7 +51,7 @@ TSharedPtr StreamObjectManagement::StoreSkeleton(const FBModel* M TSharedPtr StreamObjectManagement::StoreGeneric(const FBModel* Model, TSharedPtr LiveLinkProvider) { - FBTrace("%s is an Unknown Type! - %s\n", *Model->LongName, *((FBModel*)Model)->ClassName()); + FBTrace("%s is an Unknown Type! - %s\n", (const char*)Model->LongName, ((FBModel*)Model)->ClassName()); TSharedPtr GenericStore = MakeShared(Model, LiveLinkProvider); return GenericStore; diff --git a/Source/Public/IStreamObject.h b/Source/Public/IStreamObject.h index 4e71781f..d5bef7f2 100644 --- a/Source/Public/IStreamObject.h +++ b/Source/Public/IStreamObject.h @@ -28,7 +28,7 @@ class IStreamObject virtual void UpdateActiveStatus(bool bIsNowActive) = 0; - virtual const kReference GetReference() const = 0; + virtual const FBModel* GetModelPointer() const = 0; virtual const FString GetRootName() const = 0; diff --git a/Source/Public/MobuLiveLinkDevice.h b/Source/Public/MobuLiveLinkDevice.h index b959f800..0a415968 100644 --- a/Source/Public/MobuLiveLinkDevice.h +++ b/Source/Public/MobuLiveLinkDevice.h @@ -53,7 +53,7 @@ class FMobuLiveLink : public FBDevice public: const FString mProviderName = TEXT("Mobu Live Link"); - TMap> StreamObjects; + TMap> StreamObjects; TSharedPtr LiveLinkProvider; @@ -77,7 +77,11 @@ class FMobuLiveLink : public FBDevice FFrameRate CurrentSampleRate; void UpdateSampleRate(); + + int32 GetNextUID(); private: + int32 NextUID = 1; + void UpdateStream(); //!< Get latest data and send to unreal int32 GetCurrentSampleRateIndex(); diff --git a/Source/Public/MobuLiveLinkLayout.h b/Source/Public/MobuLiveLinkLayout.h index 87536c9d..48a9a45a 100644 --- a/Source/Public/MobuLiveLinkLayout.h +++ b/Source/Public/MobuLiveLinkLayout.h @@ -40,7 +40,7 @@ class FMobuLiveLinkLayout : public FBDeviceLayout typedef TSharedPtr StreamObjectPtr; - void AddSpreadRowFromStreamObject(StreamObjectPtr Object); + void AddSpreadRowFromStreamObject(int32 NewRowKey, StreamObjectPtr Object); FBSystem System; FMobuLiveLink* LiveLinkDevice; diff --git a/Source/StreamObjects/Private/EditorActiveCameraStreamObject.cpp b/Source/StreamObjects/Private/EditorActiveCameraStreamObject.cpp index 6655ce4f..aff888af 100644 --- a/Source/StreamObjects/Private/EditorActiveCameraStreamObject.cpp +++ b/Source/StreamObjects/Private/EditorActiveCameraStreamObject.cpp @@ -63,9 +63,9 @@ void FEditorActiveCameraStreamObject::UpdateActiveStatus(bool bIsNowActive) // Active Status is not changeable on the Editor camera }; -const kReference FEditorActiveCameraStreamObject::GetReference() const +const FBModel* FEditorActiveCameraStreamObject::GetModelPointer() const { - return (kReference)nullptr; + return nullptr; }; const FString FEditorActiveCameraStreamObject::GetRootName() const diff --git a/Source/StreamObjects/Private/ModelStreamObject.cpp b/Source/StreamObjects/Private/ModelStreamObject.cpp index 8e1f6981..ab3f8967 100644 --- a/Source/StreamObjects/Private/ModelStreamObject.cpp +++ b/Source/StreamObjects/Private/ModelStreamObject.cpp @@ -72,9 +72,9 @@ void FModelStreamObject::UpdateActiveStatus(bool bIsNowActive) Refresh(); }; -const kReference FModelStreamObject::GetReference() const +const FBModel* FModelStreamObject::GetModelPointer() const { - return (kReference)RootModel; + return RootModel; }; const FString FModelStreamObject::GetRootName() const diff --git a/Source/StreamObjects/Public/EditorActiveCameraStreamObject.h b/Source/StreamObjects/Public/EditorActiveCameraStreamObject.h index 3c923225..aa814bae 100644 --- a/Source/StreamObjects/Public/EditorActiveCameraStreamObject.h +++ b/Source/StreamObjects/Public/EditorActiveCameraStreamObject.h @@ -26,7 +26,7 @@ class FEditorActiveCameraStreamObject : public IStreamObject bool GetActiveStatus() const final; void UpdateActiveStatus(bool bIsNowActive) final; - const kReference GetReference() const final; + const FBModel* GetModelPointer() const final; const FString GetRootName() const final; diff --git a/Source/StreamObjects/Public/ModelStreamObject.h b/Source/StreamObjects/Public/ModelStreamObject.h index 2fd8b529..0d500a40 100644 --- a/Source/StreamObjects/Public/ModelStreamObject.h +++ b/Source/StreamObjects/Public/ModelStreamObject.h @@ -38,7 +38,7 @@ class FModelStreamObject : public IStreamObject virtual bool GetActiveStatus() const override; virtual void UpdateActiveStatus(bool bIsNowActive) override; - virtual const kReference GetReference() const override; + virtual const FBModel* GetModelPointer() const override; virtual const FString GetRootName() const override;