|
| 1 | +/* |
| 2 | +* Copyright (c) <2021> Side Effects Software Inc. |
| 3 | +* All rights reserved. |
| 4 | +* |
| 5 | +* Redistribution and use in source and binary forms, with or without |
| 6 | +* modification, are permitted provided that the following conditions are met: |
| 7 | +* |
| 8 | +* 1. Redistributions of source code must retain the above copyright notice, |
| 9 | +* this list of conditions and the following disclaimer. |
| 10 | +* |
| 11 | +* 2. The name of Side Effects Software may not be used to endorse or |
| 12 | +* promote products derived from this software without specific prior |
| 13 | +* written permission. |
| 14 | +* |
| 15 | +* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE "AS IS" AND ANY EXPRESS |
| 16 | +* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 17 | +* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
| 18 | +* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 19 | +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 20 | +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, |
| 21 | +* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 22 | +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 23 | +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 24 | +* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | +*/ |
| 26 | + |
| 27 | + |
| 28 | +#include "IterateOverHoudiniActorsExample.h" |
| 29 | + |
| 30 | +#include "EngineUtils.h" |
| 31 | + |
| 32 | +#include "HoudiniAssetActor.h" |
| 33 | +#include "HoudiniPublicAPI.h" |
| 34 | +#include "HoudiniPublicAPIBlueprintLib.h" |
| 35 | +#include "HoudiniPublicAPIAssetWrapper.h" |
| 36 | + |
| 37 | + |
| 38 | +// Sets default values |
| 39 | +AIterateOverHoudiniActorsExample::AIterateOverHoudiniActorsExample() |
| 40 | +{ |
| 41 | +} |
| 42 | + |
| 43 | +void AIterateOverHoudiniActorsExample::RunIterateOverHoudiniActorsExample_Implementation() |
| 44 | +{ |
| 45 | + // Get the API instance |
| 46 | + UHoudiniPublicAPI* const API = UHoudiniPublicAPIBlueprintLib::GetAPI(); |
| 47 | + // Ensure we have a running Houdini Engine session |
| 48 | + if (!API->IsSessionValid()) |
| 49 | + API->CreateSession(); |
| 50 | + |
| 51 | + // Iterate over HoudiniAssetActors in the world (by default when instantiating an HDA in the world an |
| 52 | + // AHoudiniAssetActor is spawned, which has a component that manages the instantiated HDA node in Houdini Engine. |
| 53 | + UWorld* const OurWorld = GetWorld(); |
| 54 | + for (TActorIterator<AHoudiniAssetActor> It(OurWorld); It; ++It) |
| 55 | + { |
| 56 | + AHoudiniAssetActor* const HDAActor = *It; |
| 57 | + if (!IsValid(HDAActor)) |
| 58 | + continue; |
| 59 | + |
| 60 | + // Print the name of the actor |
| 61 | + UE_LOG(LogTemp, Display, TEXT("HDA Actor (Name, Label): %s, %s"), *(HDAActor->GetName()), *(HDAActor->GetActorLabel())); |
| 62 | + |
| 63 | + // Wrap it with the API |
| 64 | + UHoudiniPublicAPIAssetWrapper* const Wrapper = UHoudiniPublicAPIAssetWrapper::CreateWrapper(this, HDAActor); |
| 65 | + if (!IsValid(Wrapper)) |
| 66 | + continue; |
| 67 | + |
| 68 | + // Print its parameters via the API |
| 69 | + TMap<FName, FHoudiniParameterTuple> ParameterTuples; |
| 70 | + if (!Wrapper->GetParameterTuples(ParameterTuples)) |
| 71 | + { |
| 72 | + // The operation failed, log the error |
| 73 | + FString ErrorMessage; |
| 74 | + if (Wrapper->GetLastErrorMessage(ErrorMessage)) |
| 75 | + UE_LOG(LogTemp, Warning, TEXT("%s"), *ErrorMessage); |
| 76 | + |
| 77 | + continue; |
| 78 | + } |
| 79 | + |
| 80 | + UE_LOG(LogTemp, Display, TEXT("# Parameter Tuples: %d"), ParameterTuples.Num()); |
| 81 | + for (const auto& Entry : ParameterTuples) |
| 82 | + { |
| 83 | + UE_LOG(LogTemp, Display, TEXT("\tParameter Tuple Name: %s"), *(Entry.Key.ToString())); |
| 84 | + |
| 85 | + const FHoudiniParameterTuple& ParameterTuple = Entry.Value; |
| 86 | + TArray<FString> Strings; |
| 87 | + FString Type; |
| 88 | + if (ParameterTuple.BoolValues.Num() > 0) |
| 89 | + { |
| 90 | + Type = TEXT("Bool"); |
| 91 | + for (const bool Value : ParameterTuple.BoolValues) |
| 92 | + { |
| 93 | + Strings.Add(Value ? TEXT("1") : TEXT("0")); |
| 94 | + } |
| 95 | + } |
| 96 | + else if (ParameterTuple.FloatValues.Num() > 0) |
| 97 | + { |
| 98 | + Type = TEXT("Float"); |
| 99 | + for (const float Value : ParameterTuple.FloatValues) |
| 100 | + { |
| 101 | + Strings.Add(FString::Printf(TEXT("%.4f"), Value)); |
| 102 | + } |
| 103 | + } |
| 104 | + else if (ParameterTuple.Int32Values.Num() > 0) |
| 105 | + { |
| 106 | + Type = TEXT("Int32"); |
| 107 | + for (const int32 Value : ParameterTuple.Int32Values) |
| 108 | + { |
| 109 | + Strings.Add(FString::Printf(TEXT("%d"), Value)); |
| 110 | + } |
| 111 | + } |
| 112 | + else if (ParameterTuple.StringValues.Num() > 0) |
| 113 | + { |
| 114 | + Type = TEXT("String"); |
| 115 | + Strings = ParameterTuple.StringValues; |
| 116 | + } |
| 117 | + |
| 118 | + if (Type.Len() == 0) |
| 119 | + { |
| 120 | + UE_LOG(LogTemp, Display, TEXT("\t\tEmpty")); |
| 121 | + } |
| 122 | + else |
| 123 | + { |
| 124 | + UE_LOG(LogTemp, Display, TEXT("\t\t%s Values: %s"), *Type, *FString::Join(Strings, TEXT("; "))); |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | +} |
0 commit comments