// Copyright Epic Games, Inc. All Rights Reserved. #include "DatasmithDirectLink.h" #include "DatasmithExporterManager.h" #include "IDatasmithSceneElements.h" #include "DirectLink/DatasmithDirectLinkTools.h" #include "DirectLinkEndpoint.h" #include "DirectLinkMisc.h" #include "Containers/Ticker.h" #include "MeshDescription.h" #include "Misc/CommandLine.h" #include "Modules/ModuleInterface.h" #include "Modules/ModuleManager.h" DEFINE_LOG_CATEGORY(LogDatasmithDirectLinkExporterAPI); class FDatasmithDirectLinkImpl { public: FDatasmithDirectLinkImpl() : Endpoint(MakeShared(TEXT("DatasmithExporter"))) { check(DirectLink::ValidateCommunicationStatus() == DirectLink::ECommunicationStatus::NoIssue); Endpoint->SetVerbose(); // #ue_directlink_integration app specific endpoint name, and source name. } bool InitializeForScene(const TSharedRef& Scene) { UE_LOG(LogDatasmithDirectLinkExporterAPI, Log, TEXT("InitializeForScene")); Endpoint->RemoveSource(Source); // Use the scene's label to name the source const TCHAR* SourceName = FCString::Strlen(Scene->GetLabel()) == 0 ? TEXT("unnamed") : Scene->GetLabel(); Source = Endpoint->AddSource(SourceName, DirectLink::EVisibility::Public); bool bSnapshotNow = false; Endpoint->SetSourceRoot(Source, &*Scene, bSnapshotNow); CurrentScene = Scene; return true; } bool UpdateScene(const TSharedRef& Scene) { UE_LOG(LogDatasmithDirectLinkExporterAPI, Log, TEXT("UpdateScene")); if (CurrentScene != Scene) { InitializeForScene(Scene); } Endpoint->SnapshotSource(Source); DumpDatasmithScene(Scene, TEXT("send")); return true; } void CloseCurrentSource() { Endpoint->RemoveSource(Source); CurrentScene.Reset(); } TSharedRef GetEnpoint() const { return Endpoint; } private: TSharedRef Endpoint; DirectLink::FSourceHandle Source; TSharedPtr CurrentScene; }; TUniquePtr DirectLinkImpl; int32 FDatasmithDirectLink::ValidateCommunicationSetup() { return (int32)DirectLink::ValidateCommunicationStatus(); } bool FDatasmithDirectLink::Shutdown() { DirectLinkImpl.Reset(); return true; } FDatasmithDirectLink::FDatasmithDirectLink() { if (!DirectLinkImpl) { DirectLinkImpl = MakeUnique(); } } bool FDatasmithDirectLink::InitializeForScene(const TSharedRef& Scene) { return DirectLinkImpl->InitializeForScene(Scene); } bool FDatasmithDirectLink::UpdateScene(const TSharedRef& Scene) { return DirectLinkImpl->UpdateScene(Scene); } void FDatasmithDirectLink::CloseCurrentSource() { DirectLinkImpl->CloseCurrentSource(); } TSharedRef FDatasmithDirectLink::GetEnpoint() { if (!DirectLinkImpl) { DirectLinkImpl = MakeUnique(); } return DirectLinkImpl->GetEnpoint(); }