Skip to content

Add support for setting int, string, color, file parameter on Houdini Asset Component in blueprint #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: Houdini20.0-Unreal5.00
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions Source/HoudiniEngineRuntime/Private/HoudiniAssetBlueprintComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@
#include "UObject/Object.h"
#include "Logging/LogMacros.h"

#include "HoudiniParameterInt.h"
#include "HoudiniParameterFloat.h"
#include "HoudiniParameterString.h"
#include "HoudiniParameterColor.h"
#include "HoudiniParameterToggle.h"
#include "HoudiniParameterFile.h"
#include "HoudiniInput.h"

#if WITH_EDITOR
Expand Down Expand Up @@ -1940,12 +1944,111 @@ UHoudiniAssetBlueprintComponent::HasParameter(FString Name)
return FindParameterByName(Name) != nullptr;
}

int
UHoudiniAssetBlueprintComponent::GetIntParameter(FString Name, int Index)
{
UHoudiniParameterInt* Parameter = Cast<UHoudiniParameterInt>(FindParameterByName(Name));
if (!Parameter)
{
UE_LOG(LogTemp, Warning, TEXT("Int parameter %s doesn't exist at index %s"), *Name, *FString::FromInt(Index));
return 0;
}

int Value;
Parameter->GetValueAt(Index, Value);

return Value;
}

void
UHoudiniAssetBlueprintComponent::SetIntParameter(FString Name, int Value, int Index)
{
SetTypedValueAt<UHoudiniParameterInt>(Name, Value, Index);
}

float
UHoudiniAssetBlueprintComponent::GetFloatParameter(FString Name, int Index)
{
UHoudiniParameterFloat* Parameter = Cast<UHoudiniParameterFloat>(FindParameterByName(Name));
if (!Parameter)
{
UE_LOG(LogTemp, Warning, TEXT("Float parameter %s doesn't exist at index %s"), *Name, *FString::FromInt(Index));
return 0.f;
}

float Value;
Parameter->GetValueAt(Index, Value);

return Value;
}

void
UHoudiniAssetBlueprintComponent::SetFloatParameter(FString Name, float Value, int Index)
{
SetTypedValueAt<UHoudiniParameterFloat>(Name, Value, Index);
}

FString
UHoudiniAssetBlueprintComponent::GetStringParameter(FString Name, int Index)
{
UHoudiniParameterString* Parameter = Cast<UHoudiniParameterString>(FindParameterByName(Name));
if (!Parameter)
{
UE_LOG(LogTemp, Warning, TEXT("String parameter %s doesn't exist at index %s"), *Name, *FString::FromInt(Index));
return TEXT("");
}

FString Value = Parameter->GetValueAt(Index);

return Value;
}

void
UHoudiniAssetBlueprintComponent::SetStringParameter(FString Name, FString Value, int Index)
{
SetTypedValueAt<UHoudiniParameterString>(Name, Value, Index);
}
//
FLinearColor
UHoudiniAssetBlueprintComponent::GetColorParameter(FString Name)
{
UHoudiniParameterColor* Parameter = Cast<UHoudiniParameterColor>(FindParameterByName(Name));
if (!Parameter)
{
UE_LOG(LogTemp, Warning, TEXT("Color parameter %s doesn't exist."), *Name);
return FLinearColor::Black;
}

FLinearColor Value = Parameter->GetColorValue();

return Value;
}

void
UHoudiniAssetBlueprintComponent::SetColorParameter(FString Name, FLinearColor Value)
{
UHoudiniParameterColor* Parameter = Cast<UHoudiniParameterColor>(FindParameterByName(Name));
if (!Parameter)
return;

Parameter->SetColorValue(Value);
}

bool
UHoudiniAssetBlueprintComponent::GetToggleParameter(FString Name, int Index)
{
UHoudiniParameterToggle* Parameter = Cast<UHoudiniParameterToggle>(FindParameterByName(Name));
if (!Parameter)
{
UE_LOG(LogTemp, Warning, TEXT("Toggle parameter %s doesn't exist at index %s"), *Name, *FString::FromInt(Index));
return false;
}

bool Value = Parameter->GetValueAt(Index);

return Value;
}

void
UHoudiniAssetBlueprintComponent::SetToggleValueAt(FString Name, bool Value, int Index)
{
Expand All @@ -1956,6 +2059,27 @@ UHoudiniAssetBlueprintComponent::SetToggleValueAt(FString Name, bool Value, int
Parameter->SetValueAt(Value, Index);
}

FString
UHoudiniAssetBlueprintComponent::GetFileParameter(FString Name, int Index)
{
UHoudiniParameterFile* Parameter = Cast<UHoudiniParameterFile>(FindParameterByName(Name));
if (!Parameter)
{
UE_LOG(LogTemp, Warning, TEXT("File parameter %s doesn't exist at index %s"), *Name, *FString::FromInt(Index));
return "";
}

FString Value = Parameter->GetValueAt(Index);

return Value;
}

void
UHoudiniAssetBlueprintComponent::SetFileParameter(FString Name, FString Value, int Index)
{
SetTypedValueAt<UHoudiniParameterFile>(Name, Value, Index);
}

//void UHoudiniAssetBlueprintComponent::OnPostCookHandler(UHoudiniAssetComponent* InComponent)
//{
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,42 @@ class HOUDINIENGINERUNTIME_API UHoudiniAssetBlueprintComponent : public UHoudini
UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
bool HasParameter(FString Name);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
int GetIntParameter(FString Name, int Index=0);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
void SetIntParameter(FString Name, int Value, int Index=0);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
float GetFloatParameter(FString Name, int Index=0);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
void SetFloatParameter(FString Name, float Value, int Index=0);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
FString GetStringParameter(FString Name, int Index=0);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
void SetStringParameter(FString Name, FString Value, int Index=0);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
FLinearColor GetColorParameter(FString Name);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
void SetColorParameter(FString Name, FLinearColor Value);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
bool GetToggleParameter(FString Name, int Index=0);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
void SetToggleValueAt(FString Name, bool Value, int Index=0);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
FString GetFileParameter(FString Name, int Index=0);

UFUNCTION(BlueprintCallable, Category="Houdini Asset Component")
void SetFileParameter(FString Name, FString Value, int Index=0);

void AddInputObjectMapping(const FGuid& InputGuid, const FGuid& SCSVariableGuid) { CachedInputNodes.Add(InputGuid, SCSVariableGuid); }
bool GetInputObjectSCSVariableGuid(const FGuid& InputGuid, FGuid& OutSCSGuid);
void RemoveInputObjectSCSVariableGuid(const FGuid& InputGuid) { CachedInputNodes.Remove(InputGuid); };
Expand Down