Skip to content
Open

test #175

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
146 changes: 146 additions & 0 deletions Content/Examples/Cpp/CurveInputExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright (c) <2021> Side Effects Software Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "CurveInputExample.h"

#include "Engine/StaticMesh.h"

#include "HoudiniAsset.h"
#include "HoudiniPublicAPI.h"
#include "HoudiniPublicAPIBlueprintLib.h"
#include "HoudiniPublicAPIAssetWrapper.h"
#include "HoudiniPublicAPIInputTypes.h"

ACurveInputExample::ACurveInputExample()
: AssetWrapper(nullptr)
{

}

void ACurveInputExample::RunCurveInputExample_Implementation()
{
// Get the API instance
UHoudiniPublicAPI* const API = UHoudiniPublicAPIBlueprintLib::GetAPI();
// Ensure we have a running session
if (!API->IsSessionValid())
API->CreateSession();
// Load our HDA uasset
UHoudiniAsset* const ExampleHDA = Cast<UHoudiniAsset>(StaticLoadObject(UHoudiniAsset::StaticClass(), nullptr, TEXT("/HoudiniEngine/Examples/hda/copy_to_curve_1_0.copy_to_curve_1_0")));
// Create an API wrapper instance for instantiating the HDA and interacting with it
AssetWrapper = API->InstantiateAsset(ExampleHDA, FTransform::Identity);
if (IsValid(AssetWrapper))
{
// Pre-instantiation is the earliest point where we can set parameter values
AssetWrapper->GetOnPreInstantiationDelegate().AddUniqueDynamic(this, &ACurveInputExample::SetInitialParameterValues);
// Post-instantiation is the earliest point where we can set inputs
AssetWrapper->GetOnPostInstantiationDelegate().AddUniqueDynamic(this, &ACurveInputExample::SetInputs);
// After a cook and after the plugin has created/updated objects/assets from the node's outputs
AssetWrapper->GetOnPostProcessingDelegate().AddUniqueDynamic(this, &ACurveInputExample::PrintOutputs);
}
}

void ACurveInputExample::SetInitialParameterValues_Implementation(UHoudiniPublicAPIAssetWrapper* InWrapper)
{
// Uncheck the upvectoratstart parameter
InWrapper->SetBoolParameterValue(TEXT("upvectoratstart"), false);

// Set the scale to 0.2
InWrapper->SetFloatParameterValue(TEXT("scale"), 0.2f);

// Since we are done with setting the initial values, we can unbind from the delegate
InWrapper->GetOnPreInstantiationDelegate().RemoveDynamic(this, &ACurveInputExample::SetInitialParameterValues);
}

void ACurveInputExample::SetInputs_Implementation(UHoudiniPublicAPIAssetWrapper* InWrapper)
{
// Create an empty geometry input
UHoudiniPublicAPIGeoInput* const GeoInput = Cast<UHoudiniPublicAPIGeoInput>(InWrapper->CreateEmptyInput(UHoudiniPublicAPIGeoInput::StaticClass()));
// Load the cube static mesh asset
UStaticMesh* const Cube = Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, TEXT("/Engine/BasicShapes/Cube.Cube")));
// Set the input object array for our geometry input, in this case containing only the cube
GeoInput->SetInputObjects({Cube});

// Set the input on the instantiated HDA via the wrapper
InWrapper->SetInputAtIndex(0, GeoInput);

// Create an empty curve input
UHoudiniPublicAPICurveInput* const CurveInput = Cast<UHoudiniPublicAPICurveInput>(InWrapper->CreateEmptyInput(UHoudiniPublicAPICurveInput::StaticClass()));
// Create the curve input object
UHoudiniPublicAPICurveInputObject* const CurveObject = NewObject<UHoudiniPublicAPICurveInputObject>(CurveInput);
// Make it a Nurbs curve
CurveObject->SetCurveType(EHoudiniPublicAPICurveType::Nurbs);
// Set the points of the curve, for this example we create a helix consisting of 100 points
TArray<FTransform> CurvePoints;
CurvePoints.Reserve(100);
for (int32 i = 0; i < 100; ++i)
{
const float t = i / 20.0f * PI * 2.0f;
const float x = 100.0f * cos(t);
const float y = 100.0f * sin(t);
const float z = i;
CurvePoints.Emplace(FTransform(FVector(x, y, z)));
}
CurveObject->SetCurvePoints(CurvePoints);
// Set the curve wrapper as an input object
CurveInput->SetInputObjects({CurveObject});
// Copy the input data to the HDA as node input 1
InWrapper->SetInputAtIndex(1, CurveInput);

// Since we are done with setting the initial values, we can unbind from the delegate
InWrapper->GetOnPostInstantiationDelegate().RemoveDynamic(this, &ACurveInputExample::SetInputs);
}

void ACurveInputExample::PrintOutputs_Implementation(UHoudiniPublicAPIAssetWrapper* InWrapper)
{
// Print out all outputs generated by the HDA
const int32 NumOutputs = InWrapper->GetNumOutputs();
UE_LOG(LogTemp, Log, TEXT("NumOutputs: %d"), NumOutputs);
if (NumOutputs > 0)
{
for (int32 OutputIndex = 0; OutputIndex < NumOutputs; ++OutputIndex)
{
TArray<FHoudiniPublicAPIOutputObjectIdentifier> Identifiers;
InWrapper->GetOutputIdentifiersAt(OutputIndex, Identifiers);
UE_LOG(LogTemp, Log, TEXT("\toutput index: %d"), OutputIndex);
UE_LOG(LogTemp, Log, TEXT("\toutput type: %d"), InWrapper->GetOutputTypeAt(OutputIndex));
UE_LOG(LogTemp, Log, TEXT("\tnum_output_objects: %d"), Identifiers.Num());
if (Identifiers.Num() > 0)
{
for (const FHoudiniPublicAPIOutputObjectIdentifier& Identifier : Identifiers)
{
UObject* const OutputObject = InWrapper->GetOutputObjectAt(OutputIndex, Identifier);
UObject* const OutputComponent = InWrapper->GetOutputComponentAt(OutputIndex, Identifier);
const bool bIsProxy = InWrapper->IsOutputCurrentProxyAt(OutputIndex, Identifier);
UE_LOG(LogTemp, Log, TEXT("\t\tidentifier: %s_%s"), *(Identifier.PartName), *(Identifier.SplitIdentifier));
UE_LOG(LogTemp, Log, TEXT("\t\toutput_object: %s"), IsValid(OutputObject) ? *(OutputObject->GetFName().ToString()) : TEXT("None"))
UE_LOG(LogTemp, Log, TEXT("\t\toutput_component: %s"), IsValid(OutputComponent) ? *(OutputComponent->GetFName().ToString()) : TEXT("None"))
UE_LOG(LogTemp, Log, TEXT("\t\tis_proxy: %d"), bIsProxy)
UE_LOG(LogTemp, Log, TEXT(""))
}
}
}
}
}
62 changes: 62 additions & 0 deletions Content/Examples/Cpp/CurveInputExample.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) <2021> Side Effects Software Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#include "CoreMinimal.h"
#include "EditorUtilityActor.h"

#include "CurveInputExample.generated.h"

class UHoudiniPublicAPIAssetWrapper;

UCLASS()
class ACurveInputExample : public AEditorUtilityActor
{
GENERATED_BODY()

public:
ACurveInputExample();

UFUNCTION(BlueprintNativeEvent, BlueprintCallable, CallInEditor)
void RunCurveInputExample();

protected:
/** Set our initial parameter values: disable upvectorstart and set the scale to 0.2. */
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, CallInEditor)
void SetInitialParameterValues(UHoudiniPublicAPIAssetWrapper* InWrapper);

/** Configure our inputs: input 0 is a cube and input 1 a helix. */
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, CallInEditor)
void SetInputs(UHoudiniPublicAPIAssetWrapper* InWrapper);

/** Print the outputs that were generated by the HDA (after a cook) */
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, CallInEditor)
void PrintOutputs(UHoudiniPublicAPIAssetWrapper* InWrapper);

UPROPERTY(BlueprintReadWrite)
UHoudiniPublicAPIAssetWrapper* AssetWrapper;
};
128 changes: 128 additions & 0 deletions Content/Examples/Cpp/IterateOverHoudiniActorsExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) <2021> Side Effects Software Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#include "IterateOverHoudiniActorsExample.h"

#include "EngineUtils.h"

#include "HoudiniAssetActor.h"
#include "HoudiniPublicAPI.h"
#include "HoudiniPublicAPIBlueprintLib.h"
#include "HoudiniPublicAPIAssetWrapper.h"


// Sets default values
AIterateOverHoudiniActorsExample::AIterateOverHoudiniActorsExample()
{
}

void AIterateOverHoudiniActorsExample::RunIterateOverHoudiniActorsExample_Implementation()
{
// Get the API instance
UHoudiniPublicAPI* const API = UHoudiniPublicAPIBlueprintLib::GetAPI();
// Ensure we have a running Houdini Engine session
if (!API->IsSessionValid())
API->CreateSession();

// Iterate over HoudiniAssetActors in the world (by default when instantiating an HDA in the world an
// AHoudiniAssetActor is spawned, which has a component that manages the instantiated HDA node in Houdini Engine.
UWorld* const OurWorld = GetWorld();
for (TActorIterator<AHoudiniAssetActor> It(OurWorld); It; ++It)
{
AHoudiniAssetActor* const HDAActor = *It;
if (!IsValid(HDAActor))
continue;

// Print the name of the actor
UE_LOG(LogTemp, Display, TEXT("HDA Actor (Name, Label): %s, %s"), *(HDAActor->GetName()), *(HDAActor->GetActorLabel()));

// Wrap it with the API
UHoudiniPublicAPIAssetWrapper* const Wrapper = UHoudiniPublicAPIAssetWrapper::CreateWrapper(this, HDAActor);
if (!IsValid(Wrapper))
continue;

// Print its parameters via the API
TMap<FName, FHoudiniParameterTuple> ParameterTuples;
if (!Wrapper->GetParameterTuples(ParameterTuples))
{
// The operation failed, log the error
FString ErrorMessage;
if (Wrapper->GetLastErrorMessage(ErrorMessage))
UE_LOG(LogTemp, Warning, TEXT("%s"), *ErrorMessage);

continue;
}

UE_LOG(LogTemp, Display, TEXT("# Parameter Tuples: %d"), ParameterTuples.Num());
for (const auto& Entry : ParameterTuples)
{
UE_LOG(LogTemp, Display, TEXT("\tParameter Tuple Name: %s"), *(Entry.Key.ToString()));

const FHoudiniParameterTuple& ParameterTuple = Entry.Value;
TArray<FString> Strings;
FString Type;
if (ParameterTuple.BoolValues.Num() > 0)
{
Type = TEXT("Bool");
for (const bool Value : ParameterTuple.BoolValues)
{
Strings.Add(Value ? TEXT("1") : TEXT("0"));
}
}
else if (ParameterTuple.FloatValues.Num() > 0)
{
Type = TEXT("Float");
for (const float Value : ParameterTuple.FloatValues)
{
Strings.Add(FString::Printf(TEXT("%.4f"), Value));
}
}
else if (ParameterTuple.Int32Values.Num() > 0)
{
Type = TEXT("Int32");
for (const int32 Value : ParameterTuple.Int32Values)
{
Strings.Add(FString::Printf(TEXT("%d"), Value));
}
}
else if (ParameterTuple.StringValues.Num() > 0)
{
Type = TEXT("String");
Strings = ParameterTuple.StringValues;
}

if (Type.Len() == 0)
{
UE_LOG(LogTemp, Display, TEXT("\t\tEmpty"));
}
else
{
UE_LOG(LogTemp, Display, TEXT("\t\t%s Values: %s"), *Type, *FString::Join(Strings, TEXT("; ")));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) <2018> Side Effects Software Inc.
/*
* Copyright (c) <2021> Side Effects Software Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand All @@ -26,3 +26,20 @@

#pragma once

#include "CoreMinimal.h"
#include "EditorUtilityActor.h"

#include "IterateOverHoudiniActorsExample.generated.h"

UCLASS()
class APIEXAMPLEEDITOR_API AIterateOverHoudiniActorsExample : public AEditorUtilityActor
{
GENERATED_BODY()

public:
// Sets default values for this actor's properties
AIterateOverHoudiniActorsExample();

UFUNCTION(BlueprintNativeEvent, BlueprintCallable, CallInEditor)
void RunIterateOverHoudiniActorsExample();
};
Binary file not shown.
Binary file added Content/Examples/EUW/EUW_APIExample.uasset
Binary file not shown.
Binary file added Content/Examples/Maps/LandscapeInputExample.umap
Binary file not shown.
Binary file not shown.
Loading