Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
schetle committed Jul 16, 2024
2 parents 710e8a4 + 1f9af0f commit 7bedff7
Show file tree
Hide file tree
Showing 16 changed files with 433 additions and 56 deletions.
1 change: 1 addition & 0 deletions Config/DefaultRive.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
+ClassRedirects=(OldName="/Script/Rive.RiveObject",NewName="/Script/Rive.RiveTextureObject")
+ClassRedirects=(OldName="/Script/RiveEditor.RiveFile_AssetDefinitionDefault",NewName="/Script/RiveEditor.AssetDefinition_RiveFile")
+PropertyRedirects=(OldName="/Script/Rive.RiveWidget.RiveObject",NewName="/Script/Rive.RiveWidget.RiveTextureObject")
+FunctionRedirects=(OldName="/Script/Rive.RiveArtboard.GetStateMachineNamesForDropdown",NewName="/Script/Rive.RiveArtboard.GetStateMachineNames")
26 changes: 26 additions & 0 deletions Source/Rive/Private/Game/RiveActorComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ void URiveActorComponent::RemoveArtboard(URiveArtboard* InArtboard)
Artboards.RemoveSingle(InArtboard);
}

URiveArtboard* URiveActorComponent::GetDefaultArtboard() const
{
return GetArtboardAtIndex(0);
}

URiveArtboard* URiveActorComponent::GetArtboardAtIndex(int32 InIndex) const
{
if (Artboards.IsEmpty())
{
return nullptr;
}

if (InIndex >= Artboards.Num())
{
UE_LOG(LogRive, Warning, TEXT("GetArtboardAtIndex with index %d is out of bounds"), InIndex);
return nullptr;
}

return Artboards[InIndex];
}

int32 URiveActorComponent::GetArtboardCount() const
{
return Artboards.Num();
}

void URiveActorComponent::OnResourceInitialized_RenderThread(FRHICommandListImmediate& RHICmdList, FTextureRHIRef& NewResource)
{
// When the resource change, we need to tell the Render Target otherwise we will keep on drawing on an outdated RT
Expand Down
32 changes: 3 additions & 29 deletions Source/Rive/Private/Rive/RiveArtboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ void URiveArtboard::BeginDestroy()

void URiveArtboard::AdvanceStateMachine(float InDeltaSeconds)
{
if (!RiveRenderTarget) return;

FRiveStateMachine* StateMachine = GetStateMachine();
if (StateMachine && StateMachine->IsValid() && ensure(RiveRenderTarget))
if (StateMachine && StateMachine->IsValid())
{
if (!bIsReceivingInput)
{
Expand Down Expand Up @@ -811,34 +813,6 @@ void URiveArtboard::Initialize_Internal(const rive::Artboard* InNativeArtboard)
{
EventNames.Add(Event->name().c_str());
}

BoolInputNames.Empty();
NumberInputNames.Empty();
TriggerInputNames.Empty();
if (DefaultStateMachinePtr && DefaultStateMachinePtr.IsValid())
{
for (uint32 i = 0; i < DefaultStateMachinePtr->GetInputCount(); ++i)
{
const rive::SMIInput* Input = DefaultStateMachinePtr->GetInput(i);
if (Input->input()->is<rive::StateMachineBoolBase>())
{
BoolInputNames.Add(Input->name().c_str());
}
else if (Input->input()->is<rive::StateMachineNumberBase>())
{
NumberInputNames.Add(Input->name().c_str());
}
else if (Input->input()->is<rive::StateMachineTriggerBase>())
{
TriggerInputNames.Add(Input->name().c_str());
}
else
{
UE_LOG(LogRive, Warning, TEXT("Found input of unknown type '%d' when getting inputs from StateMachine '%s' from Artboard '%hs'"),
Input->inputCoreType(), *DefaultStateMachinePtr->GetStateMachineName(), InNativeArtboard->name().c_str())
}
}
}

bIsInitialized = true;
}
Expand Down
12 changes: 9 additions & 3 deletions Source/Rive/Private/Rive/RiveFile.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Fill out your copyright notice in the Description page of Project Settings.
// Copyright Rive, Inc. All rights reserved.
#include "Rive/RiveFile.h"

#include "IRiveRenderer.h"
Expand All @@ -15,6 +15,7 @@
#if WITH_RIVE
#include "PreRiveHeaders.h"
THIRD_PARTY_INCLUDES_START
#include "rive/animation/state_machine_input.hpp"
#include "rive/pls/pls_render_context.hpp"
THIRD_PARTY_INCLUDES_END
#endif // WITH_RIVE
Expand Down Expand Up @@ -108,6 +109,7 @@ void URiveFile::Initialize()
if (ensure(PLSRenderContext))
{
ArtboardNames.Empty();
Artboards.Empty();

FScopeLock Lock(&RiveRenderer->GetThreadDataCS());
rive::ImportResult ImportResult;
Expand Down Expand Up @@ -142,8 +144,12 @@ void URiveFile::Initialize()
// UI Helper
for (int i = 0; i < RiveNativeFilePtr->artboardCount(); ++i)
{
rive::Artboard* NativeArtboard = RiveNativeFilePtr->artboard(i);
ArtboardNames.Add(NativeArtboard->name().c_str());
auto Artboard = NewObject<URiveArtboard>();

// We won't tick the artboard, it's just initialized for informational purposes
Artboard->Initialize(this, nullptr, i, "");
Artboards.Add(Artboard);
ArtboardNames.Add(Artboard->GetArtboardName());
}

BroadcastInitializationResult(true);
Expand Down
25 changes: 25 additions & 0 deletions Source/Rive/Private/Rive/RiveStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "PreRiveHeaders.h"
THIRD_PARTY_INCLUDES_START
#include "rive/animation/state_machine_input_instance.hpp"
#include "rive/generated/animation/state_machine_bool_base.hpp"
#include "rive/generated/animation/state_machine_number_base.hpp"
#include "rive/generated/animation/state_machine_trigger_base.hpp"
THIRD_PARTY_INCLUDES_END
#endif // WITH_RIVE

Expand Down Expand Up @@ -44,6 +47,28 @@ FRiveStateMachine::FRiveStateMachine(rive::ArtboardInstance* InNativeArtboardIns
if (NativeStateMachinePtr)
{
StateMachineName = NativeStateMachinePtr->name().c_str();

for (uint32 i = 0; i < GetInputCount(); ++i)
{
const rive::SMIInput* Input = GetInput(i);
if (Input->input()->is<rive::StateMachineBoolBase>())
{
BoolInputNames.Add(Input->name().c_str());
}
else if (Input->input()->is<rive::StateMachineNumberBase>())
{
NumberInputNames.Add(Input->name().c_str());
}
else if (Input->input()->is<rive::StateMachineTriggerBase>())
{
TriggerInputNames.Add(Input->name().c_str());
}
else
{
UE_LOG(LogRive, Warning, TEXT("Found input of unknown type '%d' when getting inputs from StateMachine '%s' from Artboard '%hs'"),
Input->inputCoreType(), *GetStateMachineName(), InNativeArtboardInst->name().c_str())
}
}
}

if (RiveRenderer)
Expand Down
7 changes: 5 additions & 2 deletions Source/Rive/Private/Rive/RiveTextureObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ void URiveTextureObject::PostLoad()
return;
}

if (RiveDescriptor.RiveFile)
if (!IsRunningCommandlet())
{
Initialize(RiveDescriptor);
if (RiveDescriptor.RiveFile)
{
Initialize(RiveDescriptor);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions Source/Rive/Public/Game/RiveActorComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ class RIVE_API URiveActorComponent : public UActorComponent
UFUNCTION(BlueprintCallable, Category = Rive)
void RemoveArtboard(URiveArtboard* InArtboard);

UFUNCTION(BlueprintCallable, Category = Rive)
URiveArtboard* GetDefaultArtboard() const;

UFUNCTION(BlueprintCallable, Category = Rive)
URiveArtboard* GetArtboardAtIndex(int32 InIndex) const;

UFUNCTION(BlueprintCallable, Category = Rive)
int32 GetArtboardCount() const;

protected:
void RiveReady(IRiveRenderer* InRiveRenderer);
void OnResourceInitialized_RenderThread(FRHICommandListImmediate& RHICmdList, FTextureRHIRef& NewResource);
Expand Down
13 changes: 2 additions & 11 deletions Source/Rive/Public/Rive/RiveArtboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,6 @@ class RIVE_API URiveArtboard : public UObject
UPROPERTY(Transient, VisibleInstanceOnly, BlueprintReadOnly, Category=Rive, meta=(NoResetToDefault, AllowPrivateAccess))
int32 ArtboardIndex = -1;

UPROPERTY(Transient, VisibleInstanceOnly, BlueprintReadOnly, Category=Rive, meta=(NoResetToDefault, AllowPrivateAccess))
TArray<FString> BoolInputNames;
UPROPERTY(Transient, VisibleInstanceOnly, BlueprintReadOnly, Category=Rive, meta=(NoResetToDefault, AllowPrivateAccess))
TArray<FString> NumberInputNames;
UPROPERTY(Transient, VisibleInstanceOnly, BlueprintReadOnly, Category=Rive, meta=(NoResetToDefault, AllowPrivateAccess))
TArray<FString> TriggerInputNames;

UPROPERTY(Transient, VisibleInstanceOnly, BlueprintReadOnly, Category=Rive, meta=(NoResetToDefault, AllowPrivateAccess))
TArray<FString> EventNames;

Expand All @@ -237,11 +230,9 @@ class RIVE_API URiveArtboard : public UObject

public:
UFUNCTION()
TArray<FString> GetStateMachineNamesForDropdown() const
TArray<FString> GetStateMachineNames() const
{
TArray<FString> Names {FString{}};
Names.Append(StateMachineNames);
return Names;
return StateMachineNames;
}

protected:
Expand Down
12 changes: 6 additions & 6 deletions Source/Rive/Public/Rive/RiveFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ class RIVE_API URiveFile : public UObject
UPROPERTY(BlueprintAssignable, Category = Rive)
FRiveReadyDelegate OnRiveReady;

UPROPERTY(Transient, VisibleInstanceOnly, BlueprintReadOnly, Category=Rive, meta=(NoResetToDefault, AllowPrivateAccess))
UPROPERTY(Transient, BlueprintReadOnly, Category=Rive, meta=(NoResetToDefault, AllowPrivateAccess))
TArray<FString> ArtboardNames;

// This is only meant as a display feature for the editor, and not meant to be used as functional code
UPROPERTY(Transient, VisibleInstanceOnly, Category=Rive, NonTransactional, meta=(NoResetToDefault, AllowPrivateAccess))
TArray<URiveArtboard*> Artboards;

UFUNCTION()
TArray<FString> GetArtboardNamesForDropdown() const
{
TArray<FString> Names {FString{}};
Names.Append(ArtboardNames);
return Names;
return ArtboardNames;
}

UPROPERTY(meta=(NoResetToDefault))
Expand All @@ -93,8 +95,6 @@ class RIVE_API URiveFile : public UObject
UPROPERTY(VisibleAnywhere, Category=Rive, meta=(NoResetToDefault))
TSubclassOf<UUserWidget> WidgetClass;

// UPROPERTY(Transient, NonTransactional)
// TSet<URiveArtboard*> Artboards;
public:
UPROPERTY(VisibleAnywhere, Category=Rive, meta=(NoResetToDefault))
TMap<uint32, TObjectPtr<URiveAsset>> Assets;
Expand Down
4 changes: 4 additions & 0 deletions Source/Rive/Public/Rive/RiveStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class RIVE_API FRiveStateMachine
*/
const FString& GetStateMachineName() const { return StateMachineName; }

TArray<FString> BoolInputNames;
TArray<FString> NumberInputNames;
TArray<FString> TriggerInputNames;

private:
FString StateMachineName;

Expand Down
2 changes: 1 addition & 1 deletion Source/RiveEditor/Private/Factories/RiveWidgetFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ namespace
UToolMenus::RegisterStartupCallback(FSimpleMulticastDelegate::FDelegate::CreateLambda([]()
{
FToolMenuOwnerScoped OwnerScoped(UE_MODULE_NAME);
UToolMenu* Menu = UE::ContentBrowser::ExtendToolMenu_AssetContextMenu(UTexture2DDynamic::StaticClass());
UToolMenu* Menu = UE::ContentBrowser::ExtendToolMenu_AssetContextMenu(URiveFile::StaticClass());

FToolMenuSection& Section = Menu->FindOrAddSection("GetAssetActions");
Section.AddDynamicEntry(TEXT("Rive"), FNewToolMenuSectionDelegate::CreateLambda([](FToolMenuSection& InSection)
Expand Down
17 changes: 13 additions & 4 deletions Source/RiveEditor/Private/RiveEditorModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "AssetToolsModule.h"
#include "IRiveRendererModule.h"
#include "ISettingsEditorModule.h"
#include "RiveFileDetailCustomization.h"
#include "RiveFileAssetTypeActions.h"
#include "RiveFileThumbnailRenderer.h"
#include "RiveTextureObjectAssetTypeActions.h"
Expand All @@ -27,14 +28,15 @@ void FRiveEditorModule::StartupModule()
UThumbnailManager::Get().RegisterCustomRenderer(URiveFile::StaticClass(), URiveFileThumbnailRenderer::StaticClass());
UThumbnailManager::Get().RegisterCustomRenderer(URiveTextureObject::StaticClass(), URiveTextureObjectThumbnailRenderer::StaticClass());

IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
PropertyModule.RegisterCustomClassLayout(URiveFile::StaticClass()->GetFName(),
FOnGetDetailCustomizationInstance::CreateStatic(&FRiveFileDetailCustomization::MakeInstance));

IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
RiveAssetCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("Rive")), LOCTEXT("RiveFileCategory", "Rive"));

RegisterAssetTypeActions(AssetTools, MakeShareable(new FRiveFileAssetTypeActions(RiveAssetCategory)));
RegisterAssetTypeActions(AssetTools, MakeShareable(new FRiveTextureObjectAssetTypeActions(RiveAssetCategory)));



OnBeginFrameHandle = FCoreDelegates::OnBeginFrame.AddLambda([this]()
{
CheckCurrentRHIAndNotify();
Expand All @@ -54,6 +56,13 @@ void FRiveEditorModule::ShutdownModule()
if (UObjectInitialized())
{
UThumbnailManager::Get().UnregisterCustomRenderer(URiveFile::StaticClass());
UThumbnailManager::Get().UnregisterCustomRenderer(URiveTextureObject::StaticClass());
}

if (FModuleManager::Get().IsModuleLoaded("PropertyEditor"))
{
FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
PropertyModule.UnregisterCustomClassLayout(URiveFile::StaticClass()->GetFName());
}

// Unregister all the asset types that we registered
Expand Down
Loading

0 comments on commit 7bedff7

Please sign in to comment.