Skip to content

Commit

Permalink
Cameras now come in with the correct Unreal Orientation
Browse files Browse the repository at this point in the history
Fixed a bug where modifying the scene (renames, moves, etc.) would cause objects to add duplicate BoneNames and BoneParents to their Subject
Added support for Mirroring the active Camera in the Animation Preview via EditorActiveCamera
  • Loading branch information
EpicAeryll committed Jan 22, 2018
1 parent 36282bf commit ef097df
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 19 deletions.
6 changes: 4 additions & 2 deletions Source/Private/MobuLiveLinkDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ bool MobuLiveLink::FBCreate()

SetDirty(false);

TSharedPtr<StreamObjectBase> EditorCamera((StreamObjectBase*)(new EditorActiveCameraStreamObject(LiveLinkProvider)));
StreamObjects.Emplace((kReference)nullptr, EditorCamera);

return true;
}

Expand Down Expand Up @@ -278,8 +281,7 @@ void MobuLiveLink::UpdateStreamObjects()
{
for (auto MapPair : StreamObjects)
{
bool bInScene = FBSystem().Scene->Components.Find((FBComponent*)MapPair.Value->RootModel) >= 0;
if (bInScene)
if (MapPair.Value->IsValid())
{
MapPair.Value->UpdateFromModel();
}
Expand Down
17 changes: 10 additions & 7 deletions Source/Private/MobuLiveLinkLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,17 @@ void MobuLiveLinkLayout::EventUIIdle(HISender Sender, HKEvent Event)

void MobuLiveLinkLayout::AddSpreadRowFromStreamObject(StreamObjectPtr Object)
{
StreamSpread.RowAdd(Object->RootModel->LongName, (kReference)Object->RootModel);
const FBModel* RootModel = Object->GetRootModel();
if (RootModel == nullptr) return;

StreamSpread.SetCell((kReference)Object->RootModel, 0, FStringToChar(Object->GetSubjectName().ToString()));
StreamSpread.SetCell((kReference)Object->RootModel, 1, FStringToChar(Object->GetStreamOptions()));
StreamSpread.SetCell((kReference)Object->RootModel, 1, Object->GetStreamingMode());
StreamSpread.RowAdd(RootModel->LongName, (kReference)RootModel);

StreamSpread.SetCell((kReference)RootModel, 0, FStringToChar(Object->GetSubjectName().ToString()));
StreamSpread.SetCell((kReference)RootModel, 1, FStringToChar(Object->GetStreamOptions()));
StreamSpread.SetCell((kReference)RootModel, 1, Object->GetStreamingMode());
bool bIsActive = Object->GetActiveStatus();
StreamSpread.SetCell((kReference)Object->RootModel, 2, bIsActive);
StreamSpread.SetCell((kReference)Object->RootModel, 2, BoolToActiveText(bIsActive));
StreamSpread.SetCell((kReference)RootModel, 2, bIsActive);
StreamSpread.SetCell((kReference)RootModel, 2, BoolToActiveText(bIsActive));
}


Expand Down Expand Up @@ -224,7 +227,7 @@ void MobuLiveLinkLayout::EventRemoveFromStream(HISender Sender, HKEvent Event)
DeletionObjects.Reserve(LiveLinkDevice->StreamObjects.Num());
for (const auto& MapPair : LiveLinkDevice->StreamObjects)
{
kReference RowKey = (kReference)MapPair.Value->RootModel;
kReference RowKey = (kReference)MapPair.Value->GetRootModel();
bool bRowSelected = StreamSpread.GetRow(RowKey).RowSelected;
if (bRowSelected)
{
Expand Down
25 changes: 23 additions & 2 deletions Source/Public/StreamStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
class StreamObjectBase
{
public:
const FBModel* RootModel;

virtual ~StreamObjectBase();

// Optional Interface for modifying class parameters
Expand All @@ -33,6 +31,10 @@ class StreamObjectBase

virtual void UpdateActiveStatus(bool bIsNowActive);

virtual const FBModel* GetRootModel();

virtual bool IsValid();

// Required Interface for object streaming

virtual void UpdateFromModel() = 0;
Expand All @@ -45,9 +47,12 @@ class StreamObjectBase

static FTransform MobuTransformToUnreal(FBMatrix& MobuTransfrom);
static FTransform UnrealTransformFromModel(FBModel* MobuModel, bool bIsGlobal = true);
static FTransform UnrealTransformFromCamera(FBCamera* CameraModel);

protected:

const FBModel* RootModel;

const TSharedPtr<ILiveLinkProvider> Provider;
const TArray<FString> ConnectionOptions;

Expand All @@ -57,8 +62,11 @@ class StreamObjectBase
int StreamingMode;
bool bIsActive;


StreamObjectBase(const FBModel* ModelPointer, const TSharedPtr<ILiveLinkProvider> StreamProvider, std::initializer_list<FString> Options);

// model-less constructor
StreamObjectBase(const FName InSubjectName, const TSharedPtr<ILiveLinkProvider> StreamProvider);
};

// Generic object that only supports a single transform (Nulls, Cubes, etc.)
Expand Down Expand Up @@ -100,6 +108,19 @@ class SkeletonHeirarchyStreamObject : public StreamObjectBase
public:
SkeletonHeirarchyStreamObject(const FBModel* ModelPointer, const TSharedPtr<ILiveLinkProvider> StreamProvider);

void UpdateFromModel() override;
void GetStreamData() override;
};


// Streams the Active Editor Camera wrapper
class EditorActiveCameraStreamObject : public StreamObjectBase
{
public:
EditorActiveCameraStreamObject(const TSharedPtr<ILiveLinkProvider> StreamProvider);

bool IsValid() override;

void UpdateFromModel() override;
void GetStreamData() override;
};
8 changes: 5 additions & 3 deletions Source/StreamObjects/CameraStreamObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ CameraStreamObject::CameraStreamObject(const FBModel* ModelPointer, const TShare

void CameraStreamObject::UpdateFromModel()
{
BoneNames.Emplace(FName("Bone01"));
BoneParents.Emplace(0);
BoneNames.SetNum(1);
BoneNames[0] = FName("Bone01");
BoneParents.SetNum(1);
BoneParents[0] = -1;

Provider->UpdateSubject(SubjectName, BoneNames, BoneParents);
}
Expand All @@ -22,7 +24,7 @@ void CameraStreamObject::GetStreamData()

FBCamera* CameraModel = (FBCamera*)RootModel;
// Single Bone
BoneTransforms.Emplace(UnrealTransformFromModel(CameraModel));
BoneTransforms.Emplace(UnrealTransformFromCamera(CameraModel));

TArray<FLiveLinkCurveElement> CurveData;
// If Streaming as Camera then get the Camera Properties
Expand Down
70 changes: 70 additions & 0 deletions Source/StreamObjects/EditorActiveCameraStreamObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "StreamStore.h"

EditorActiveCameraStreamObject::EditorActiveCameraStreamObject(const TSharedPtr<ILiveLinkProvider> StreamProvider)
: StreamObjectBase(FName(TEXT("EditorActiveCamera")), StreamProvider)
{
UpdateFromModel();
}

bool EditorActiveCameraStreamObject::IsValid()
{
return true;
}

void EditorActiveCameraStreamObject::UpdateFromModel()
{
BoneNames.SetNum(1);
BoneNames[0] = FName("root");

BoneParents.SetNum(1);
BoneParents[0] = -1;

Provider->UpdateSubject(SubjectName, BoneNames, BoneParents);
}

void EditorActiveCameraStreamObject::GetStreamData()
{
if (!bIsActive) return;

FBSystem System;
FBCamera* CameraModel = System.Scene->Renderer->CurrentCamera;

TArray<FTransform> BoneTransforms;

// Single Bone
BoneTransforms.Emplace(UnrealTransformFromCamera(CameraModel));

TArray<FLiveLinkCurveElement> CurveData;

CurveData.SetNum(9);

CurveData[0].CurveName = FName(TEXT("FieldOfViewX"));
CurveData[0].CurveValue = CameraModel->FieldOfViewX;

CurveData[1].CurveName = FName(TEXT("FieldOfViewY"));
CurveData[1].CurveValue = CameraModel->FieldOfViewY;

CurveData[2].CurveName = FName(TEXT("FieldOfView"));
CurveData[2].CurveValue = CameraModel->FieldOfView;

CurveData[3].CurveName = FName(TEXT("FocalLength"));
CurveData[3].CurveValue = CameraModel->FocalLength;

CurveData[4].CurveName = FName(TEXT("FocusSpecificDistance"));
CurveData[4].CurveValue = CameraModel->FocusSpecificDistance;

CurveData[5].CurveName = FName(TEXT("NearPlaneDistance"));
CurveData[5].CurveValue = CameraModel->NearPlaneDistance;

CurveData[6].CurveName = FName(TEXT("FarPlaneDistance"));
CurveData[6].CurveValue = CameraModel->FarPlaneDistance;

CurveData[7].CurveName = FName(TEXT("FilmSizeWidth"));
CurveData[7].CurveValue = CameraModel->FilmSizeWidth;

CurveData[8].CurveName = FName(TEXT("FilmSizeHeight"));
CurveData[8].CurveValue = CameraModel->FilmSizeHeight;

FBTime LocalTime = FBSystem().LocalTime;
Provider->UpdateSubjectFrame(SubjectName, BoneTransforms, CurveData, LocalTime.GetSecondDouble(), LocalTime.GetFrame());
}
6 changes: 4 additions & 2 deletions Source/StreamObjects/GenericStreamObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ GenericStreamObject::GenericStreamObject(const FBModel* ModelPointer, const TSha

void GenericStreamObject::UpdateFromModel()
{
BoneNames.Emplace(FName("Bone01"));
BoneParents.Emplace(0);
BoneNames.SetNum(1);
BoneNames[0] = FName("Bone01");
BoneParents.SetNum(1);
BoneParents[0] = -1;

Provider->UpdateSubject(SubjectName, BoneNames, BoneParents);
};
Expand Down
6 changes: 4 additions & 2 deletions Source/StreamObjects/LightStreamObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ LightStreamObject::LightStreamObject(const FBModel* ModelPointer, const TSharedP

void LightStreamObject::UpdateFromModel()
{
BoneNames.Emplace(FName("Bone01"));
BoneParents.Emplace(0);
BoneNames.SetNum(1);
BoneNames[0] = FName("Bone01");
BoneParents.SetNum(1);
BoneParents[0] = -1;

Provider->UpdateSubject(SubjectName, BoneNames, BoneParents);
};
Expand Down
49 changes: 48 additions & 1 deletion Source/StreamObjects/StreamObjectBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ StreamObjectBase::StreamObjectBase(const FBModel* ModelPointer, const TSharedPtr
SubjectName = FName(*ModelLongName);
};

// Model-less constructor
StreamObjectBase::StreamObjectBase(const FName InSubjectName, const TSharedPtr<ILiveLinkProvider> StreamProvider)
: RootModel(nullptr), SubjectName(InSubjectName), Provider(StreamProvider), bIsActive(true), StreamingMode(0)
{
};

StreamObjectBase::~StreamObjectBase()
{
Provider->ClearSubject(SubjectName);
Expand Down Expand Up @@ -59,10 +65,22 @@ void StreamObjectBase::UpdateActiveStatus(bool bIsNowActive)
UpdateFromModel();
};

const FBModel* StreamObjectBase::GetRootModel()
{
return RootModel;
};

bool StreamObjectBase::IsValid()
{
// By Default an object is valid if the root model is in the scene
return FBSystem().Scene->Components.Find((FBComponent*)GetRootModel()) >= 0;
};


// Equality comparison

bool StreamObjectBase::operator==(const StreamObjectBase &other) const {
bool StreamObjectBase::operator==(const StreamObjectBase &other) const
{
return (this->RootModel == other.RootModel);
};

Expand Down Expand Up @@ -120,6 +138,35 @@ FTransform StreamObjectBase::UnrealTransformFromModel(FBModel* MobuModel, bool b
return MobuTransformToUnreal(MobuTransform);
};

FTransform StreamObjectBase::UnrealTransformFromCamera(FBCamera* CameraModel)
{
// MotionBuilder suggests that GetMatrix is deprecated for Cameras and to
// reconstruct from the Camera Matrices explicitly

FBMatrix ModelView;
FBMatrix MatOffset;

CameraModel->GetCameraMatrix(ModelView, FBCameraMatrixType::kFBModelView, nullptr);
FBMatrix InvModelView = ModelView.Inverse();

// Y-Up Correction
FBRVector RotOffset(90, 0, 0);
FBRotationToMatrix(MatOffset, RotOffset);
FBMatrixMult(ModelView, MatOffset, ModelView);

// Camera is now in Unreal Space
FTransform CameraTransform = MobuTransformToUnreal(ModelView);

// Mobu Cameras look down a different axis so flip them here
// TODO: Consolidate with MobuTransformToUnreal so we're not repeating work
FQuat CameraRotation = CameraTransform.GetRotation();
FQuat LensRotation;
LensRotation.MakeFromEuler(FVector(-90, -90, 0));
CameraTransform.SetRotation(CameraRotation * LensRotation);

return CameraTransform;
}




0 comments on commit ef097df

Please sign in to comment.