Files
UnrealEngineUWP/Engine/Source/Editor/Sequencer/Private/SequencerMeshTrail.cpp

160 lines
5.3 KiB
C++
Raw Normal View History

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "SequencerMeshTrail.h"
#include "SequencerKeyActor.h"
ViewportInteraction refactoring; miscellaneous VREditor improvements - This merge contains various changes to ViewportInteraction and VR Editor to make things more extensible - Some changes are from Yannick's recent shelved refactoring work, that I've modified and improved upon - EditorWorldManager is gone and replaced by EditorWorldExtensionManager - EditorWorldExtensions are sort of like a more modern version of 'FEdMode', but still a work in progress - Cleaned up access to VREditorMode from other modules, forcing systems to go through EditorWorldExtensions - Overhauled how transforming objects works with world interaction - Viewport interactors can now be used to move objects other than actors around (by implementing an UViewportTransformer, and a FViewportTransformable) - Undo/Redo now works better with inertial transformation! The transaction only ends when objects finally come to rest. - Some initial support for 'grabber sphere' interactor methods has been implemented (not used yet) - Viewport interaction input events now receive the viewport being interacted through - Viewport interaction hover events no longer get a viewport client (because they must be designed to work any number of viewports.) NOTE: This introduces UBT warnings about cyclic module dependencies. We'll have to address this in a different changelist. Other changes: - The active Viewport Interaction 'gizmo mode' is now tied directly to the editor's normal gizmo mode. They share the same state. - New console variable 'VI.UseTransientActors' can be turned off to force editor actors to be created non-transient to make it easier to debug - New console variable 'VI.DragTranslationVelocityStopEpsilon' sets the speed at which transformables will stop have inertia applied to them - Fixed cyclic dependencies with ViewportInteraction and VREditor modules not being tagged properly for UBT - Fixed some issues with transform gizmos not getting release events - Various methods that should have been const were made const - Eliminated duplicate implementation of SpawnTransientSceneActor and DestroyTransientActor; made it static - UnrealEd no longer directly depends on VREditor and ViewportInteraction modules - Engine: AActor::SetIsTemporarilyHiddenInEditor no longer does any work if the object's hidden state didn't change - Slate: Input preprocessor (if bound) now also gets a chance at mouse button down and up events #codereview yannick.lange,lauren.ridge #rb various [CL 3245240 by Mike Fricker in Dev-VREditor branch]
2017-01-03 14:38:17 -05:00
#include "EditorWorldExtension.h"
#include "ViewportWorldInteraction.h"
#include "Materials/MaterialInstance.h"
#include "Materials/MaterialInstanceDynamic.h"
#include "Components/BillboardComponent.h"
#include "Components/StaticMeshComponent.h"
#include "MovieScene3DTransformSection.h"
#include "TimerManager.h"
#include "Editor.h"
ASequencerMeshTrail::ASequencerMeshTrail()
: Super()
{
TrailTime = 0.0f;
MaxTrailTime = 1.0f;
UBillboardComponent* PrimitiveRootComponent = CreateDefaultSubobject<UBillboardComponent>(TEXT("RootComponent"));
PrimitiveRootComponent->bSelectable = false;
PrimitiveRootComponent->SetVisibility(false, false);
SetRootComponent(PrimitiveRootComponent);
if (!IsTemplate() && GEditor)
{
GEditor->GetTimerManager()->SetTimer(TrailUpdate, FTimerDelegate::CreateUObject(this, &ASequencerMeshTrail::UpdateTrailAppearance, 0.0005f), 0.0005f, true);
}
}
void ASequencerMeshTrail::Cleanup()
{
// Destroy all the key actors this trail created
for (FKeyActorData KeyMesh : KeyMeshActors)
{
KeyMesh.KeyActor->Destroy();
}
this->Destroy();
}
void ASequencerMeshTrail::AddKeyMeshActor(float KeyTime, const FTransform KeyTransform, class UMovieScene3DTransformSection* TrackSection)
{
ASequencerKeyActor* KeyMeshActor = nullptr;
UStaticMesh* KeyEditorMesh = nullptr;
UMaterialInstance* KeyEditorMaterial = nullptr;
MaxTrailTime = FMath::Max(KeyTime, MaxTrailTime);
FKeyActorData* KeyPtr = KeyMeshActors.FindByPredicate([KeyTime](const FKeyActorData InKey)
{
return FMath::IsNearlyEqual(KeyTime, InKey.Time);
});
// If we don't currently have an actor for this time, create one
if (KeyPtr == nullptr)
{
UViewportWorldInteraction* WorldInteraction = Cast<UViewportWorldInteraction>( GEditor->GetEditorWorldExtensionsManager()->GetEditorWorldExtensions( GetWorld() )->FindExtension( UViewportWorldInteraction::StaticClass() ) );
if( WorldInteraction != nullptr )
{
KeyMeshActor = WorldInteraction->SpawnTransientSceneActor<ASequencerKeyActor>( TEXT( "KeyMesh" ), false );
KeyMeshActor->SetActorTransform(KeyTransform);
// Destroy all the frame components this trail created
for (FFrameComponentData FrameMesh : FrameMeshComponents)
{
FrameMesh.FrameComponent->DestroyComponent();
}
FrameMeshComponents.Reset();
KeyMeshActor->SetKeyData(TrackSection, KeyTime);
KeyMeshActor->SetOwner(this);
FKeyActorData NewKey = FKeyActorData(KeyTime, KeyMeshActor);
KeyMeshActors.Add(NewKey);
}
}
else
{
// Just update the transform
KeyPtr->KeyActor->SetActorTransform(KeyTransform);
}
}
void ASequencerMeshTrail::AddFrameMeshComponent(const float FrameTime, const FTransform FrameTransform)
{
UStaticMeshComponent* FrameMeshComponent = nullptr;
UStaticMesh* FrameEditorMesh = nullptr;
UMaterial* FrameEditorMaterial = nullptr;
FFrameComponentData* FramePtr = FrameMeshComponents.FindByPredicate([FrameTime](const FFrameComponentData InFrame)
{
return FMath::IsNearlyEqual(FrameTime, InFrame.Time);
});
// If we don't currently have a component for this time, create one
if (FramePtr == nullptr)
{
FrameMeshComponent = NewObject<UStaticMeshComponent>(this);
this->AddOwnedComponent(FrameMeshComponent);
FrameMeshComponent->RegisterComponent();
FrameEditorMesh = LoadObject<UStaticMesh>(nullptr, TEXT("/Engine/VREditor/TransformGizmo/SM_Sequencer_Node"));
check(FrameEditorMesh != nullptr);
FrameEditorMaterial = LoadObject<UMaterial>(nullptr, TEXT("/Engine/VREditor/TransformGizmo/Main"));
check(FrameEditorMaterial != nullptr);
FrameMeshComponent->SetStaticMesh(FrameEditorMesh);
FrameMeshComponent->CreateAndSetMaterialInstanceDynamicFromMaterial(0, FrameEditorMaterial);
FrameMeshComponent->SetMobility(EComponentMobility::Movable);
FrameMeshComponent->SetWorldTransform(FrameTransform);
FrameMeshComponent->SetCastShadow(false);
FrameMeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
FrameMeshComponent->bSelectable = false;
FFrameComponentData NewFrame = FFrameComponentData(FrameTime, FrameMeshComponent);
FrameMeshComponents.Add(NewFrame);
}
else
{
// Just update the transform
FramePtr->FrameComponent->SetWorldTransform(FrameTransform);
}
}
void ASequencerMeshTrail::UpdateTrailAppearance(float UpdateTime)
{
if (FMath::IsNearlyEqual(MaxTrailTime, 0.0f))
{
MaxTrailTime = 1.0f;
}
// TODO: No hardcoded glow values
TrailTime = FMath::Fmod(TrailTime + UpdateTime, MaxTrailTime);
for (FFrameComponentData Frame : FrameMeshComponents)
{
UMaterialInstanceDynamic* FrameMaterial = Cast<UMaterialInstanceDynamic>(Frame.FrameComponent->GetMaterial(0));
if (FrameMaterial != nullptr)
{
float GlowValue = 0.0f;
if (FMath::IsNearlyEqual(TrailTime, Frame.Time, 0.1f))
{
GlowValue = 12.0f;
}
else
{
GlowValue = 3.0f;
}
FrameMaterial->SetScalarParameterValue("GlowAmount", GlowValue);
}
}
for (FKeyActorData Key : KeyMeshActors)
{
UMaterialInstanceDynamic* KeyMaterial = Cast<UMaterialInstanceDynamic>(Key.KeyActor->GetMeshComponent()->GetMaterial(0));
if (KeyMaterial != nullptr)
{
float GlowValue = 0.0f;
if (FMath::IsNearlyEqual(TrailTime, Key.Time, 0.1f))
{
GlowValue = 20.0f;
}
else
{
GlowValue = 5.0f;
}
KeyMaterial->SetScalarParameterValue("GlowAmount", GlowValue);
}
}
}