Files
UnrealEngineUWP/Engine/Source/Runtime/GeometryCache/Private/GeometryCacheTrack.cpp

117 lines
2.9 KiB
C++
Raw Normal View History

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "GeometryCacheModulePrivatePCH.h"
#include "GeometryCacheTrack.h"
GEOMETRYCACHE_API UGeometryCacheTrack::UGeometryCacheTrack(const FObjectInitializer& ObjectInitializer /*= FObjectInitializer::Get()*/) : UObject(ObjectInitializer)
{
NumMaterials = 0;
}
const bool UGeometryCacheTrack::UpdateMeshData(const float Time, const bool bLooping, int32& InOutMeshSampleIndex, FGeometryCacheMeshData*& OutMeshData)
{
return false;
}
const bool UGeometryCacheTrack::UpdateMatrixData(const float Time, const bool bLooping, int32& InOutMatrixSampleIndex, FMatrix& OutWorldMatrix)
{
// Retrieve sample index from Time
const uint32 MatrixSampleIndex = FindSampleIndexFromTime(MatrixSampleTimes, Time, bLooping);
// Update the Matrix and Index if MatrixSampleIndex is different from the stored InOutMatrixSampleIndex
if (MatrixSampleIndex != InOutMatrixSampleIndex)
{
InOutMatrixSampleIndex = MatrixSampleIndex;
OutWorldMatrix = MatrixSamples[MatrixSampleIndex];
return true;
}
return false;
}
UGeometryCacheTrack::~UGeometryCacheTrack()
{
MatrixSamples.Empty();
MatrixSampleTimes.Empty();
}
void UGeometryCacheTrack::Serialize(FArchive& Ar)
{
Ar << MatrixSamples;
Ar << MatrixSampleTimes;
Ar << NumMaterials;
}
void UGeometryCacheTrack::SetMatrixSamples(const TArray<FMatrix>& Matrices, const TArray<float>& SampleTimes)
{
// Copy Matrix samples and sample-times
MatrixSamples.Append(Matrices);
MatrixSampleTimes.Append(SampleTimes);
}
const float UGeometryCacheTrack::GetMaxSampleTime() const
{
// If there are sample-times available return the (maximal) time from the last sample
if ( MatrixSampleTimes.Num() > 0 )
{
return MatrixSampleTimes.Last();
}
// Otherwise no data/times availabel
return 0.0f;
}
const uint32 UGeometryCacheTrack::FindSampleIndexFromTime(const TArray<float>& SampleTimes, const float Time, const bool bLooping)
{
// No index possible
if (SampleTimes.Num() == 0)
{
return 0;
}
// Modulo the incoming Time if the animation is played on a loop
float SampleTime = Time;
if (bLooping)
{
Copying //UE4/Dev-Framework to Dev-Main (//UE4/Dev-Main) @ 2855699 #lockdown Nick.Penwarden ========================== MAJOR FEATURES + CHANGES ========================== Change 2839897 on 2016/01/22 by Ori.Cohen Allow static mesh editor to specify a default collision profile. #rb Lina.Halper #UE-2836 Change 2840489 on 2016/01/22 by Ori.Cohen Fix collision customization so that it respects const editing property #rb Marc.Audy Change 2840528 on 2016/01/22 by Ori.Cohen Fix compile error and actually get value from attribute Change 2840672 on 2016/01/22 by Zak.Middleton #ue4 - Include data from USkinnedMeshComponent in USkeletalMeshComponent::GetResourceSize(). #rb Michael.Noland Change 2841314 on 2016/01/24 by Marc.Audy Fix depressingly frequent misspellings of 'suppress' Change 2841323 on 2016/01/24 by Marc.Audy Reserve worst case memory for TSet Intersect, Union, and Difference to avoid memory allocations during iteration Ensure that TSet Intersect considers the least number of elements possible Early out from TSet Contains if Other is larger than this Clarify comment on TSet Difference #rb Steve.Robb Change 2841380 on 2016/01/24 by Aaron.McLeran UE-25586 Audio assets not correctly reporting resource memory usage Tested on PC/PS4 and with Editor builds. Memory reporting is working for all cases now. Change 2841385 on 2016/01/24 by Aaron.McLeran UE-21210 Adding subtitle priority to USoundWave Change 2841386 on 2016/01/24 by Marc.Audy Return null for GameNetDriver if World is null instead of crashing Change 2841409 on 2016/01/24 by Aaron.McLeran UE-25514 Removing load for default objects for every sound wave Change 2841858 on 2016/01/25 by Ori.Cohen Make sure that PIE face index results are consistent with runtime #rb Benn.Gallagher Change 2841977 on 2016/01/25 by Ori.Cohen Fix object type customization so that it's only enabled when custom is selected. (Accidently broke this in recent change) Change 2841982 on 2016/01/25 by Marc.Audy Minor optimization by avoiding recreating FNames repeatedly in constructor Change 2842169 on 2016/01/25 by Benn.Gallagher Fixes to animBP compiler and instance to store and double buffer internal machine state weights on the instance. So they can be queried cross-machine without issue. #rb Lina.Halper Change 2842390 on 2016/01/25 by Ori.Cohen Fix in world editing of BodyInstance not working. No longer serializing Scale3D as this is allways initialized in InitBody. No longer overwriting MassInKg and renamed to to MassInKgOverride which better reflects what this variable does. #JIRA UE-25518 #rb Lina.Halper Change 2843579 on 2016/01/26 by Marc.Audy Only update replication when it actually changes Don't check calling SetIsReplicated if the class cannot replicate, instead output an error message Fix spelling in comment #rb Ori.Cohen Change 2843627 on 2016/01/26 by Marc.Audy Add \\ as a default console key for Italian keyboard layouts #jira UE-25198 #rb James.Golding Change 2843628 on 2016/01/26 by Marc.Audy Don't reconstruct FName on each call to GetHitResultAtScreenPosition #rb James.Golding Change 2843671 on 2016/01/26 by Martin.Wilson Fix incorrect bone transforms being pushed to the renderer during SetSkeletalMesh. This presented as motion blur artifacts in editor #rb Thomas.Sarkanen Change 2843768 on 2016/01/26 by Marc.Audy Inline Get Component functions in TriggerBase Change 2844003 on 2016/01/26 by Zak.Middleton #ue4 - Fix FMath::Fmod(X, Y) sometimes returning small negative values for positive X and Y due to float imprecision. Added tests to math tests at startup to check this, and also to better handle results close to Y. Wrap the ensure on Y=0 within a conditional so a breakpoint can be used during debugging (to distinguish between zero and very small input). #codereview Laurent.Delayen Change 2844005 on 2016/01/26 by Zak.Middleton #ue4 - Convert uses of fmod() and fmodf() to use FMath::Fmod() instead. Also see CL 2844003 [CL 2855709 by Marc Audy in Main branch]
2016-02-04 10:55:30 -05:00
SampleTime = FMath::Fmod(Time, SampleTimes[SampleTimes.Num() - 1]);
}
// Binary searching for closest (floored) SampleIndex
uint32 MinIndex = 0;
uint32 MaxIndex = SampleTimes.Num() - 1;
if (SampleTime > SampleTimes[MaxIndex])
{
return MaxIndex;
}
else if (SampleTime < SampleTimes[MinIndex])
{
return MinIndex;
}
while (MaxIndex > 0 && MaxIndex >= MinIndex)
{
uint32 Mid = (MinIndex + MaxIndex) / 2;
if (SampleTime > SampleTimes[Mid])
{
MinIndex = Mid + 1;
}
else
{
MaxIndex = Mid - 1;
}
}
return MinIndex;
}
SIZE_T UGeometryCacheTrack::GetResourceSize(EResourceSizeMode::Type Mode)
{
SIZE_T ResourceSize = 0;
// Determine resource size from data that is serialized
ResourceSize += MatrixSamples.Num() * sizeof(FMatrix);
ResourceSize += MatrixSampleTimes.Num() * sizeof(float);
return ResourceSize;
}