You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Some DCC may close a 3d scene without closing the application, in that case they must be able to close the DirectLink source as well. With the simplified DirectLink API (FDatasmithDirectLink) this was only achievable by creating a new scene that would override the existing one, which is not desirable in this case. Our C# exporters can only use the simplified API at the moment and this seems like a common enough use-case to be added to FDatasmithDirectLink. #jira UE-140665 #rb Johan.Duparc #preflight 6290fa2db83292836e093ea2 #preflight 62953a005370042eb043f84a [CL 20433116 by benoit deschenes in ue5-main branch]
120 lines
3.0 KiB
C++
120 lines
3.0 KiB
C++
// 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<DirectLink::FEndpoint, ESPMode::ThreadSafe>(TEXT("DatasmithExporter")))
|
|
{
|
|
check(DirectLink::ValidateCommunicationStatus() == DirectLink::ECommunicationStatus::NoIssue);
|
|
Endpoint->SetVerbose();
|
|
// #ue_directlink_integration app specific endpoint name, and source name.
|
|
}
|
|
|
|
bool InitializeForScene(const TSharedRef<IDatasmithScene>& 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<IDatasmithScene>& 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<DirectLink::FEndpoint, ESPMode::ThreadSafe> GetEnpoint() const
|
|
{
|
|
return Endpoint;
|
|
}
|
|
|
|
private:
|
|
TSharedRef<DirectLink::FEndpoint, ESPMode::ThreadSafe> Endpoint;
|
|
DirectLink::FSourceHandle Source;
|
|
TSharedPtr<IDatasmithScene> CurrentScene;
|
|
};
|
|
|
|
|
|
TUniquePtr<FDatasmithDirectLinkImpl> DirectLinkImpl;
|
|
|
|
int32 FDatasmithDirectLink::ValidateCommunicationSetup()
|
|
{ return (int32)DirectLink::ValidateCommunicationStatus(); }
|
|
|
|
bool FDatasmithDirectLink::Shutdown()
|
|
{
|
|
DirectLinkImpl.Reset();
|
|
return true;
|
|
}
|
|
|
|
FDatasmithDirectLink::FDatasmithDirectLink()
|
|
{
|
|
if (!DirectLinkImpl)
|
|
{
|
|
DirectLinkImpl = MakeUnique<FDatasmithDirectLinkImpl>();
|
|
}
|
|
}
|
|
|
|
|
|
bool FDatasmithDirectLink::InitializeForScene(const TSharedRef<IDatasmithScene>& Scene)
|
|
{ return DirectLinkImpl->InitializeForScene(Scene); }
|
|
|
|
bool FDatasmithDirectLink::UpdateScene(const TSharedRef<IDatasmithScene>& Scene)
|
|
{ return DirectLinkImpl->UpdateScene(Scene); }
|
|
|
|
void FDatasmithDirectLink::CloseCurrentSource()
|
|
{
|
|
DirectLinkImpl->CloseCurrentSource();
|
|
}
|
|
|
|
TSharedRef<DirectLink::FEndpoint, ESPMode::ThreadSafe> FDatasmithDirectLink::GetEnpoint()
|
|
{
|
|
if (!DirectLinkImpl)
|
|
{
|
|
DirectLinkImpl = MakeUnique<FDatasmithDirectLinkImpl>();
|
|
}
|
|
|
|
return DirectLinkImpl->GetEnpoint();
|
|
}
|