void FMovieScene3DAttachTrackInstance::UpdateConstraint( float Position, const TArray<TWeakObjectPtr<UObject>>& RuntimeObjects, AActor* Actor, UMovieScene3DConstraintSection* ConstraintSection ) 
{
	FVector Translation;
	FRotator Rotation;

	UMovieScene3DAttachSection* AttachSection = CastChecked<UMovieScene3DAttachSection>(ConstraintSection);

	for( int32 ObjIndex = 0; ObjIndex < RuntimeObjects.Num(); ++ObjIndex )
	{
		USceneComponent* SceneComponent = MovieSceneHelpers::SceneComponentFromRuntimeObject(RuntimeObjects[ObjIndex].Get());

		if (SceneComponent != nullptr)
		{
			AttachSection->Eval(SceneComponent, Position, Actor, Translation, Rotation);

			// Set the relative translation and rotation.  Note they are set once instead of individually to avoid a redundant component transform update.
			SceneComponent->SetRelativeLocationAndRotation(Translation, Rotation);
		}
	}
}
void FMovieScene3DTransformTrackInstance::Update( float Position, float LastPosition, const TArray<UObject*>& RuntimeObjects, class IMovieScenePlayer& Player ) 
{
	FVector Translation;
	FRotator Rotation;
	FVector Scale;
	bool bHasTranslationKeys = false;
	bool bHasRotationKeys = false;
	bool bHasScaleKeys = false;

	if( TransformTrack->Eval( Position, LastPosition, Translation, Rotation, Scale, bHasTranslationKeys, bHasRotationKeys, bHasScaleKeys ) )
	{
		for( int32 ObjIndex = 0; ObjIndex < RuntimeObjects.Num(); ++ObjIndex )
		{
			UObject* Object = RuntimeObjects[ObjIndex];

			AActor* Actor = Cast<AActor>( Object );

			USceneComponent* SceneComponent = NULL;
			if( Actor && Actor->GetRootComponent() )
			{
				// If there is an actor, modify its root component
				SceneComponent = Actor->GetRootComponent();
			}
			else
			{
				// No actor was found.  Attempt to get the object as a component in the case that we are editing them directly.
				SceneComponent = Cast<USceneComponent>( Object );
			}

			// Set the relative translation and rotation.  Note they are set once instead of individually to avoid a redundant component transform update.
			SceneComponent->SetRelativeLocationAndRotation(
				bHasTranslationKeys ? Translation : SceneComponent->RelativeLocation,
				bHasRotationKeys ? Rotation : SceneComponent->RelativeRotation );

			if( bHasScaleKeys )
			{
				SceneComponent->SetRelativeScale3D( Scale );
			}
		}
	}
}
Пример #3
0
void FLevelUtils::ApplyLevelTransform( ULevel* Level, const FTransform& LevelTransform, bool bDoPostEditMove )
{
	bool bTransformActors =  !LevelTransform.Equals(FTransform::Identity);
	if (bTransformActors)
	{
		if (!LevelTransform.GetRotation().IsIdentity())
		{
			// If there is a rotation applied, then the relative precomputed bounds become invalid.
			Level->bTextureStreamingRotationChanged = true;
		}

		// Iterate over all actors in the level and transform them
		for( int32 ActorIndex=0; ActorIndex<Level->Actors.Num(); ActorIndex++ )
		{
			AActor* Actor = Level->Actors[ActorIndex];

			// Don't want to transform children they should stay relative to there parents.
			if( Actor && Actor->GetAttachParentActor() == NULL )
			{
				// Has to modify root component directly as GetActorPosition is incorrect this early
				USceneComponent *RootComponent = Actor->GetRootComponent();
				if (RootComponent)
				{
					RootComponent->SetRelativeLocationAndRotation( LevelTransform.TransformPosition(RootComponent->RelativeLocation), (FTransform(RootComponent->RelativeRotation) * LevelTransform).Rotator());
				}			
			}
		}

#if WITH_EDITOR
		if( bDoPostEditMove )
		{
			ApplyPostEditMove( Level );						
		}
#endif // WITH_EDITOR

		Level->OnApplyLevelTransform.Broadcast(LevelTransform);
	}
}