Skip to content

Commit

Permalink
Added the ability to get all Animatable and Streamable properties for…
Browse files Browse the repository at this point in the history
… a given model. Vastly simplifies streaming logic
  • Loading branch information
EpicAeryll committed Jan 23, 2018
1 parent ef097df commit 2104ee5
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 81 deletions.
1 change: 1 addition & 0 deletions Source/Public/StreamStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class StreamObjectBase
static FTransform MobuTransformToUnreal(FBMatrix& MobuTransfrom);
static FTransform UnrealTransformFromModel(FBModel* MobuModel, bool bIsGlobal = true);
static FTransform UnrealTransformFromCamera(FBCamera* CameraModel);
static TArray<FLiveLinkCurveElement> GetAllAnimatableCurves(FBModel* MobuModel);

protected:

Expand Down
30 changes: 2 additions & 28 deletions Source/StreamObjects/CameraStreamObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,11 @@ void CameraStreamObject::GetStreamData()
BoneTransforms.Emplace(UnrealTransformFromCamera(CameraModel));

TArray<FLiveLinkCurveElement> CurveData;

// If Streaming as Camera then get the Camera Properties
if (StreamingMode == 0)
{
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;
CurveData = GetAllAnimatableCurves(CameraModel);
}

FBTime LocalTime = FBSystem().LocalTime;
Expand Down
31 changes: 1 addition & 30 deletions Source/StreamObjects/EditorActiveCameraStreamObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,7 @@ void EditorActiveCameraStreamObject::GetStreamData()
// 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;
TArray<FLiveLinkCurveElement> CurveData = GetAllAnimatableCurves(CameraModel);

FBTime LocalTime = FBSystem().LocalTime;
Provider->UpdateSubjectFrame(SubjectName, BoneTransforms, CurveData, LocalTime.GetSecondDouble(), LocalTime.GetFrame());
Expand Down
3 changes: 2 additions & 1 deletion Source/StreamObjects/LightStreamObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ void LightStreamObject::GetStreamData()
// If Streaming as Light then get the Light Properties
if (StreamingMode == 0)
{
// TODO: Get Light Properties here
// TODO: Add any additional Light logic here. For now stream everything we can
CurveData = GetAllAnimatableCurves(LightModel);
}

FBTime LocalTime = FBSystem().LocalTime;
Expand Down
48 changes: 26 additions & 22 deletions Source/StreamObjects/SkeletonHeirarchyStreamObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,40 @@ void SkeletonHeirarchyStreamObject::UpdateFromModel()
BoneParents.Emplace(-1);
BoneModels.Emplace(RootModel);

TArray<TPair<int, FBModel*>> SearchList;
TArray<TPair<int, FBModel*>> SearchListNext;

SearchList.Emplace(0, (FBModel*)RootModel);

// If Streaming as Hierarchy
if (StreamingMode == 0)
{
while (SearchList.Num() > 0)
TArray<TPair<int, FBModel*>> SearchList;
TArray<TPair<int, FBModel*>> SearchListNext;

SearchList.Emplace(0, (FBModel*)RootModel);

if (StreamingMode == 0)
{
for (const auto& SearchPair : SearchList)
while (SearchList.Num() > 0)
{
int ParentIdx = SearchPair.Key;
FBModel* SearchModel = SearchPair.Value;
int ChildCount = SearchModel->Children.GetCount(); // Yuck

for (int ChildIdx = 0; ChildIdx < ChildCount; ++ChildIdx)
for (const auto& SearchPair : SearchList)
{
FBModel* ChildModel = SearchModel->Children[ChildIdx];
int ParentIdx = SearchPair.Key;
FBModel* SearchModel = SearchPair.Value;
int ChildCount = SearchModel->Children.GetCount(); // Yuck

for (int ChildIdx = 0; ChildIdx < ChildCount; ++ChildIdx)
{
FBModel* ChildModel = SearchModel->Children[ChildIdx];

if (ChildModel->GetTypeId() != FBModelSkeleton::TypeInfo) continue; // Only want joints
if (ChildModel->GetTypeId() != FBModelSkeleton::TypeInfo) continue; // Only want joints

BoneNames.Emplace(ChildModel->Name);
BoneParents.Emplace(ParentIdx);
BoneModels.Emplace(ChildModel);
BoneNames.Emplace(ChildModel->Name);
BoneParents.Emplace(ParentIdx);
BoneModels.Emplace(ChildModel);

SearchListNext.Emplace(BoneModels.Num() - 1, ChildModel);
SearchListNext.Emplace(BoneModels.Num() - 1, ChildModel);
}
}
SearchList = SearchListNext;
SearchListNext.Empty();
}
SearchList = SearchListNext;
SearchListNext.Empty();
}
}
Provider->UpdateSubject(SubjectName, BoneNames, BoneParents);
Expand Down Expand Up @@ -74,8 +78,8 @@ void SkeletonHeirarchyStreamObject::GetStreamData()
}


// Generic Models have no special properties
TArray<FLiveLinkCurveElement> CurveData;
// Stream all properties on the root bone
TArray<FLiveLinkCurveElement> CurveData = GetAllAnimatableCurves((FBModel*)BoneModels[0]);

FBTime LocalTime = FBSystem().LocalTime;
Provider->UpdateSubjectFrame(SubjectName, BoneTransforms, CurveData, LocalTime.GetSecondDouble(), LocalTime.GetFrame());
Expand Down
74 changes: 74 additions & 0 deletions Source/StreamObjects/StreamObjectBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,80 @@ FTransform StreamObjectBase::UnrealTransformFromCamera(FBCamera* CameraModel)
return CameraTransform;
}

// Get all properties on a given model that are both Animatable and are of a Type we can stream
TArray<FLiveLinkCurveElement> StreamObjectBase::GetAllAnimatableCurves(FBModel* MobuModel)
{
int PropertyCount = MobuModel->PropertyList.GetCount();

TArray<FLiveLinkCurveElement> LiveLinkCurves;
// Reserve enough memory for worst case
LiveLinkCurves.Reserve(PropertyCount);

float PropertyValue;
FName PropertyName;
for (int i = 0; i < PropertyCount; ++i)
{
FBProperty* Property = MobuModel->PropertyList[i];
if (Property->IsAnimatable())
{
switch (Property->GetPropertyType())
{
case kFBPT_bool:
{
bool bValue;
Property->GetData(&bValue, sizeof(bValue), nullptr);
PropertyValue = bValue ? 1.0f : 0.0f;
break;
}
case kFBPT_double:
{
double Value;
Property->GetData(&Value, sizeof(Value), nullptr);
PropertyValue = (float)Value;
break;
}
case kFBPT_float:
{
// PropertyValue is a float so retrieve it directly
Property->GetData(&PropertyValue, sizeof(PropertyValue), nullptr);
break;
}
case kFBPT_enum: // Enums are assumed to be ints. THIS MAY NOT BE A VALID ASSUMPTION
case kFBPT_int:
{
int Value;
Property->GetData(&Value, sizeof(Value), nullptr);
PropertyValue = (float)Value;
break;
}
case kFBPT_int64:
{
int64 Value;
Property->GetData(&Value, sizeof(Value), nullptr);
PropertyValue = (float)Value;
break;
}
case kFBPT_uint64:
{
uint64 Value;
Property->GetData(&Value, sizeof(Value), nullptr);
PropertyValue = (float)Value;
break;
}
default:
continue;
}

FLiveLinkCurveElement NewCurveElement;
NewCurveElement.CurveName = FName(Property->GetName());;
NewCurveElement.CurveValue = PropertyValue;

LiveLinkCurves.Emplace(NewCurveElement);
}
}
return LiveLinkCurves;
}




0 comments on commit 2104ee5

Please sign in to comment.