From cd24b1db902190e131aa2a6fe2c47e25723d5bac Mon Sep 17 00:00:00 2001 From: Morne Chamberlain Date: Tue, 7 Dec 2021 09:48:29 -0500 Subject: [PATCH] Version 2 - The PDG translator will now also use the HAC's static mesh generation / build settings, instead of the plugin default settings, if the asset link is owned by a valid HAC. --- .../Private/HoudiniGeoImportCommandlet.cpp | 20 +- .../Private/HoudiniGeoImportCommandlet.h | 306 +++++++------- .../Private/HoudiniGeoImporter.cpp | 27 +- .../Private/HoudiniGeoImporter.h | 249 +++++------ .../Private/HoudiniPDGImporterMessages.cpp | 240 ++++++----- .../Private/HoudiniPDGImporterMessages.h | 396 +++++++++--------- .../Private/HoudiniPDGManager.cpp | 9 +- .../Private/HoudiniPDGTranslator.cpp | 15 +- .../Private/HoudiniPDGTranslator.h | 175 ++++---- .../Private/HoudiniGeoFactory.cpp | 4 +- 10 files changed, 767 insertions(+), 674 deletions(-) diff --git a/Source/HoudiniEngine/Private/HoudiniGeoImportCommandlet.cpp b/Source/HoudiniEngine/Private/HoudiniGeoImportCommandlet.cpp index d7e44081f2..731f873917 100755 --- a/Source/HoudiniEngine/Private/HoudiniGeoImportCommandlet.cpp +++ b/Source/HoudiniEngine/Private/HoudiniGeoImportCommandlet.cpp @@ -45,6 +45,7 @@ #include "Interfaces/ISlateNullRendererModule.h" #include "Rendering/SlateRenderer.h" #include "Framework/Application/SlateApplication.h" +#include "HAL/ThreadManager.h" #include "HoudiniPackageParams.h" #include "HoudiniGeoImporter.h" @@ -52,8 +53,7 @@ #include "HoudiniEngineUtils.h" #include "HoudiniOutput.h" #include "HoudiniPDGImporterMessages.h" -#include "HoudiniMeshTranslator.h" -#include "HAL/ThreadManager.h" +#include "HoudiniEngineRuntimeUtils.h" UHoudiniGeoImportCommandlet::UHoudiniGeoImportCommandlet() @@ -308,7 +308,7 @@ void UHoudiniGeoImportCommandlet::HandleImportBGEOMessage( TArray Outputs; TMap> OutputObjectAttributes; TMap InstancedOutputPartData; - if (ImportBGEO(InMessage.FilePath, PackageParams, Outputs, &OutputObjectAttributes, &InstancedOutputPartData) == 0) + if (ImportBGEO(InMessage.FilePath, PackageParams, Outputs, &InMessage.StaticMeshGenerationProperties, &InMessage.MeshBuildSettings, &OutputObjectAttributes, &InstancedOutputPartData) == 0) { FHoudiniPDGImportBGEOResultMessage* Reply = new FHoudiniPDGImportBGEOResultMessage(); (*Reply) = InMessage; @@ -436,8 +436,10 @@ bool UHoudiniGeoImportCommandlet::StartHoudiniEngineSession() int32 UHoudiniGeoImportCommandlet::ImportBGEO( const FString &InFilename, - const FHoudiniPackageParams &InPackageParams, + const FHoudiniPackageParams &InPackageParams, TArray& OutOutputs, + const FHoudiniStaticMeshGenerationProperties* InStaticMeshGenerationProperties, + const FMeshBuildSettings* InMeshBuildSettings, TMap>* OutGenericAttributes, TMap* OutInstancedOutputPartData) { @@ -525,8 +527,16 @@ int32 UHoudiniGeoImportCommandlet::ImportBGEO( UObject* Outer = this; // 5. Create the static meshes in the outputs + const FHoudiniStaticMeshGenerationProperties& StaticMeshGenerationProperties = + InStaticMeshGenerationProperties? + *InStaticMeshGenerationProperties : + FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(); + + const FMeshBuildSettings& MeshBuildSettings = + InMeshBuildSettings ? *InMeshBuildSettings : FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(); + HOUDINI_LOG_DISPLAY(TEXT("Create Static Meshes")); - if (!GeoImporter->CreateStaticMeshes(OutOutputs, Outer, PackageParams)) + if (!GeoImporter->CreateStaticMeshes(OutOutputs, Outer, PackageParams, StaticMeshGenerationProperties, MeshBuildSettings)) return CleanUpAndExit(1); //// 6. Create the landscape in the outputs diff --git a/Source/HoudiniEngine/Private/HoudiniGeoImportCommandlet.h b/Source/HoudiniEngine/Private/HoudiniGeoImportCommandlet.h index 23734611cd..431d955373 100755 --- a/Source/HoudiniEngine/Private/HoudiniGeoImportCommandlet.h +++ b/Source/HoudiniEngine/Private/HoudiniGeoImportCommandlet.h @@ -1,153 +1,155 @@ -/* -* 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 "UObject/ObjectMacros.h" -#include "Commandlets/Commandlet.h" -#include "MessageEndpoint.h" - -#include "HoudiniEngine.h" -#include "HoudiniGenericAttribute.h" -#include "HoudiniPDGImporterMessages.h" -#include "HoudiniGeoPartObject.h" - -#include "HoudiniGeoImportCommandlet.generated.h" - -class FSocket; - -class UHoudiniGeoImporter; -class UHoudiniOutput; - -struct FHoudiniPackageParams; - -enum class EHoudiniGeoImportCommandletMode : uint8 -{ - // Unspecified - None, - // Import of specified file - SpecifiedFiles, - // Directory watch mode - Watch, - // Listen mode (via PDGManager) - Listen -}; - -struct FDiscoveredFileData -{ -public: - FDiscoveredFileData() : FileName(), bImportNextTick(false), ImportAttempts(0), bImported(false) {} - - FDiscoveredFileData(const FString& InFileName, bool bInImportNextTick=false) : FileName(InFileName), bImportNextTick(bInImportNextTick), ImportAttempts(0), bImported(false) {} - - FDiscoveredFileData(FString&& InFileName, bool bInImportNextTick=false) : FileName(InFileName), bImportNextTick(bInImportNextTick), ImportAttempts(0), bImported(false) {} - - // Full/absolute file path - FString FileName; - - // Try to import this file on the next tick - bool bImportNextTick; - - // Number of attempts at importing this file - uint32 ImportAttempts; - - // The file has been imported successfully - bool bImported; -}; - -UCLASS() -class HOUDINIENGINE_API UHoudiniGeoImportCommandlet : public UCommandlet -{ - GENERATED_BODY() - -public: - - UHoudiniGeoImportCommandlet(); - - void PrintUsage() const; - - /** - * Entry point for your commandlet - * - * @param Params the string containing the parameters for the commandlet - */ - virtual int32 Main(const FString& Params) override; - - void HandleImportBGEOMessage( - const struct FHoudiniPDGImportBGEOMessage& InMessage, - const TSharedRef& InContext); - - void HandleDirectoryChanged(const TArray& InFileChangeDatas); - -protected: - - void PopulatePackageParams(const FString& InBGEOFilename, FHoudiniPackageParams& OutPackageParams); - - bool StartHoudiniEngineSession(); - - bool IsHoudiniEngineSessionRunning() { return FHoudiniEngine::Get().GetSession() != nullptr; }; - - int32 MainLoop(); - - int32 ImportBGEO( - const FString& InFilename, - const FHoudiniPackageParams& InPackageParams, - TArray& OutOutputs, - TMap>* OutGenericAttributes=nullptr, - TMap* OutInstancedOutputPartData=nullptr); - - void TickDiscoveredFiles(); - -private: - - // Messaging end point for receiving messages from PDG manager - TSharedPtr PDGEndpoint; - - // The messaging address of the manager - FMessageAddress ManagerAddress; - - // Unique ID of the commandlet. - FGuid Guid; - - // The proc handle of our owner (if in listen mode, quit when the owner stops running). - FProcHandle OwnerProcHandle; - - // TODO: Map so that we can watch multiple directories? - // Directory to watch - FString DirectoryToWatch; - // Handle if we are watching a directory for changes. - FDelegateHandle DirectoryWatcherHandle; - - // Keep track of files discovered by the watcher, and their state - TMap DiscoveredFiles; - - // Mode in which commandlet is running - EHoudiniGeoImportCommandletMode Mode; - - // Bake outputs via FHoudiniEngineBakeUtils - bool bBakeOutputs; +/* +* 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 "UObject/ObjectMacros.h" +#include "Commandlets/Commandlet.h" +#include "MessageEndpoint.h" + +#include "HoudiniEngine.h" +#include "HoudiniGenericAttribute.h" +#include "HoudiniPDGImporterMessages.h" +#include "HoudiniGeoPartObject.h" + +#include "HoudiniGeoImportCommandlet.generated.h" + +class FSocket; + +class UHoudiniGeoImporter; +class UHoudiniOutput; + +struct FHoudiniPackageParams; + +enum class EHoudiniGeoImportCommandletMode : uint8 +{ + // Unspecified + None, + // Import of specified file + SpecifiedFiles, + // Directory watch mode + Watch, + // Listen mode (via PDGManager) + Listen +}; + +struct FDiscoveredFileData +{ +public: + FDiscoveredFileData() : FileName(), bImportNextTick(false), ImportAttempts(0), bImported(false) {} + + FDiscoveredFileData(const FString& InFileName, bool bInImportNextTick=false) : FileName(InFileName), bImportNextTick(bInImportNextTick), ImportAttempts(0), bImported(false) {} + + FDiscoveredFileData(FString&& InFileName, bool bInImportNextTick=false) : FileName(InFileName), bImportNextTick(bInImportNextTick), ImportAttempts(0), bImported(false) {} + + // Full/absolute file path + FString FileName; + + // Try to import this file on the next tick + bool bImportNextTick; + + // Number of attempts at importing this file + uint32 ImportAttempts; + + // The file has been imported successfully + bool bImported; +}; + +UCLASS() +class HOUDINIENGINE_API UHoudiniGeoImportCommandlet : public UCommandlet +{ + GENERATED_BODY() + +public: + + UHoudiniGeoImportCommandlet(); + + void PrintUsage() const; + + /** + * Entry point for your commandlet + * + * @param Params the string containing the parameters for the commandlet + */ + virtual int32 Main(const FString& Params) override; + + void HandleImportBGEOMessage( + const struct FHoudiniPDGImportBGEOMessage& InMessage, + const TSharedRef& InContext); + + void HandleDirectoryChanged(const TArray& InFileChangeDatas); + +protected: + + void PopulatePackageParams(const FString& InBGEOFilename, FHoudiniPackageParams& OutPackageParams); + + bool StartHoudiniEngineSession(); + + bool IsHoudiniEngineSessionRunning() { return FHoudiniEngine::Get().GetSession() != nullptr; }; + + int32 MainLoop(); + + int32 ImportBGEO( + const FString& InFilename, + const FHoudiniPackageParams& InPackageParams, + TArray& OutOutputs, + const FHoudiniStaticMeshGenerationProperties* InStaticMeshGenerationProperties=nullptr, + const FMeshBuildSettings* InMeshBuildSettings=nullptr, + TMap>* OutGenericAttributes=nullptr, + TMap* OutInstancedOutputPartData=nullptr); + + void TickDiscoveredFiles(); + +private: + + // Messaging end point for receiving messages from PDG manager + TSharedPtr PDGEndpoint; + + // The messaging address of the manager + FMessageAddress ManagerAddress; + + // Unique ID of the commandlet. + FGuid Guid; + + // The proc handle of our owner (if in listen mode, quit when the owner stops running). + FProcHandle OwnerProcHandle; + + // TODO: Map so that we can watch multiple directories? + // Directory to watch + FString DirectoryToWatch; + // Handle if we are watching a directory for changes. + FDelegateHandle DirectoryWatcherHandle; + + // Keep track of files discovered by the watcher, and their state + TMap DiscoveredFiles; + + // Mode in which commandlet is running + EHoudiniGeoImportCommandletMode Mode; + + // Bake outputs via FHoudiniEngineBakeUtils + bool bBakeOutputs; }; \ No newline at end of file diff --git a/Source/HoudiniEngine/Private/HoudiniGeoImporter.cpp b/Source/HoudiniEngine/Private/HoudiniGeoImporter.cpp index 84ab084261..ff85671d6d 100755 --- a/Source/HoudiniEngine/Private/HoudiniGeoImporter.cpp +++ b/Source/HoudiniEngine/Private/HoudiniGeoImporter.cpp @@ -39,6 +39,7 @@ #include "HoudiniInstanceTranslator.h" #include "HoudiniSplineTranslator.h" #include "HoudiniSplineComponent.h" +#include "HoudiniEngineRuntimeUtils.h" #include "CoreMinimal.h" #include "Misc/Paths.h" @@ -159,7 +160,10 @@ UHoudiniGeoImporter::BuildOutputsForNode(const HAPI_NodeId& InNodeId, TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams) +UHoudiniGeoImporter::CreateStaticMeshes( + TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams, + const FHoudiniStaticMeshGenerationProperties& InStaticMeshGenerationProperties, + const FMeshBuildSettings& InMeshBuildSettings) { TMap AllOutputMaterials; for (auto& CurOutput : InOutputs) @@ -207,8 +211,6 @@ UHoudiniGeoImporter::CreateStaticMeshes(TArray& InOutputs, UObj } } - FHoudiniStaticMeshGenerationProperties SMGP = FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(); - FMeshBuildSettings MBS = FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(); FHoudiniMeshTranslator::CreateStaticMeshFromHoudiniGeoPartObject( CurHGPO, PackageParams, @@ -219,8 +221,8 @@ UHoudiniGeoImporter::CreateStaticMeshes(TArray& InOutputs, UObj AllOutputMaterials, true, EHoudiniStaticMeshMethod::RawMesh, - SMGP, - MBS); + InStaticMeshGenerationProperties, + InMeshBuildSettings); for (auto& CurMat : AssignementMaterials) { @@ -633,7 +635,10 @@ UHoudiniGeoImporter::DeleteCreatedNode(const HAPI_NodeId& InNodeId) } bool -UHoudiniGeoImporter::ImportBGEOFile(const FString& InBGEOFile, UObject* InParent, const FHoudiniPackageParams* InPackageParams) +UHoudiniGeoImporter::ImportBGEOFile( + const FString& InBGEOFile, UObject* InParent, const FHoudiniPackageParams* InPackageParams, + const FHoudiniStaticMeshGenerationProperties* InStaticMeshGenerationProperties, + const FMeshBuildSettings* InMeshBuildSettings) { if (InBGEOFile.IsEmpty()) return false; @@ -699,7 +704,15 @@ UHoudiniGeoImporter::ImportBGEOFile(const FString& InBGEOFile, UObject* InParent } // 5. Create the static meshes in the outputs - if (!CreateStaticMeshes(NewOutputs, InParent, PackageParams)) + const FHoudiniStaticMeshGenerationProperties& StaticMeshGenerationProperties = + InStaticMeshGenerationProperties? + *InStaticMeshGenerationProperties : + FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(); + + const FMeshBuildSettings& MeshBuildSettings = + InMeshBuildSettings ? *InMeshBuildSettings : FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(); + + if (!CreateStaticMeshes(NewOutputs, InParent, PackageParams, StaticMeshGenerationProperties, MeshBuildSettings)) return CleanUpAndReturn(false); // 6. Create the static meshes in the outputs diff --git a/Source/HoudiniEngine/Private/HoudiniGeoImporter.h b/Source/HoudiniEngine/Private/HoudiniGeoImporter.h index 33ed94820a..1e91b73084 100755 --- a/Source/HoudiniEngine/Private/HoudiniGeoImporter.h +++ b/Source/HoudiniEngine/Private/HoudiniGeoImporter.h @@ -1,122 +1,129 @@ -/* -* 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 "HAPI/HAPI_Common.h" - -#include "HoudiniGeoImporter.generated.h" - -class UHoudiniOutput; - -struct FHoudiniPackageParams; - -UCLASS() -class HOUDINIENGINE_API UHoudiniGeoImporter : public UObject -{ -public: - - GENERATED_UCLASS_BODY() - - public: - //UHoudiniGeoImporter(); - //~UHoudiniGeoImporter(); - - void SetBakeRootFolder(const FString& InFolder) { BakeRootFolder = InFolder; }; - void SetOutputFilename(const FString& InOutFilename) { OutputFilename = InOutFilename; }; - - TArray& GetOutputObjects() { return OutputObjects; }; - - // BEGIN: Static API - // Open a BGEO file: create a file node in HAPI and cook it - static bool OpenBGEOFile(const FString& InBGEOFile, HAPI_NodeId& OutNodeId, bool bInUseWorldComposition=false); - // Cook the file node specified by the valid NodeId. - static bool CookFileNode(const HAPI_NodeId& InNodeId); - // Extract the outputs for a given node ID - static bool BuildAllOutputsForNode(const HAPI_NodeId& InNodeId, UObject* InOuter, TArray& InOldOutputs, TArray& OutNewOutputs, bool bInAddOutputsToRootSet=false); - // Delete the HAPI node and remove InOutputs from the root set. - static bool CloseBGEOFile(const HAPI_NodeId& InNodeId); - // END: Static API - - // Import the BGEO file - bool ImportBGEOFile(const FString& InBGEOFile, UObject* InParent, const FHoudiniPackageParams* InPackageParams=nullptr); - - // 1. Start a HE session if needed - static bool AutoStartHoudiniEngineSessionIfNeeded(); - // 2. Update our file members fromn the input file path - bool SetFilePath(const FString& InFilePath); - // 3. Creates a new file node and loads the bgeo file in HAPI - bool LoadBGEOFileInHAPI(HAPI_NodeId& NodeId); - // 4. Extract the outputs for a given node ID - bool BuildOutputsForNode(const HAPI_NodeId& InNodeId, TArray& InOldOutputs, TArray& OutNewOutputs); - // 5. Creates the static meshes object found in the output - bool CreateStaticMeshes(TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams); - // 6. Create the output curves - bool CreateCurves(TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams); - // 7. Create the output landscapes - bool CreateLandscapes(TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams); - // 8. Create the output instancers - bool CreateInstancers(TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams); - // 9. Clean up the created node - static bool DeleteCreatedNode(const HAPI_NodeId& InNodeId); - - static bool CreateInstancerOutputPartData( - TArray& InOutputs, - TMap& OutInstancedOutputPartData); - - private: - - // - // Input file - // - // Path how the file we're currently loading - FString SourceFilePath; - // Absolute Path to the file - FString AbsoluteFilePath; - FString AbsoluteFileDirectory; - // File Name / Extension - FString FileName; - FString FileExtension; - - - // - // Output file - // - // Output filename, if empty, will be set to the input filename - FString OutputFilename; - // Root Folder for storing the created files - FString BakeRootFolder; - - // - // Output Objects - // - TArray OutputObjects; - - //TArray OutputStaticMeshes; - //TArray OutputLandscapes; - //TArray OutputInstancers; - +/* +* 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 "HAPI/HAPI_Common.h" + +#include "HoudiniGeoImporter.generated.h" + +class UHoudiniOutput; + +struct FHoudiniPackageParams; +struct FHoudiniStaticMeshGenerationProperties; +struct FMeshBuildSettings; + +UCLASS() +class HOUDINIENGINE_API UHoudiniGeoImporter : public UObject +{ +public: + + GENERATED_UCLASS_BODY() + + public: + //UHoudiniGeoImporter(); + //~UHoudiniGeoImporter(); + + void SetBakeRootFolder(const FString& InFolder) { BakeRootFolder = InFolder; }; + void SetOutputFilename(const FString& InOutFilename) { OutputFilename = InOutFilename; }; + + TArray& GetOutputObjects() { return OutputObjects; }; + + // BEGIN: Static API + // Open a BGEO file: create a file node in HAPI and cook it + static bool OpenBGEOFile(const FString& InBGEOFile, HAPI_NodeId& OutNodeId, bool bInUseWorldComposition=false); + // Cook the file node specified by the valid NodeId. + static bool CookFileNode(const HAPI_NodeId& InNodeId); + // Extract the outputs for a given node ID + static bool BuildAllOutputsForNode(const HAPI_NodeId& InNodeId, UObject* InOuter, TArray& InOldOutputs, TArray& OutNewOutputs, bool bInAddOutputsToRootSet=false); + // Delete the HAPI node and remove InOutputs from the root set. + static bool CloseBGEOFile(const HAPI_NodeId& InNodeId); + // END: Static API + + // Import the BGEO file + bool ImportBGEOFile( + const FString& InBGEOFile, UObject* InParent, const FHoudiniPackageParams* InPackageParams=nullptr, + const FHoudiniStaticMeshGenerationProperties* InStaticMeshGenerationProperties=nullptr, + const FMeshBuildSettings* InMeshBuildSettings=nullptr); + + // 1. Start a HE session if needed + static bool AutoStartHoudiniEngineSessionIfNeeded(); + // 2. Update our file members fromn the input file path + bool SetFilePath(const FString& InFilePath); + // 3. Creates a new file node and loads the bgeo file in HAPI + bool LoadBGEOFileInHAPI(HAPI_NodeId& NodeId); + // 4. Extract the outputs for a given node ID + bool BuildOutputsForNode(const HAPI_NodeId& InNodeId, TArray& InOldOutputs, TArray& OutNewOutputs); + // 5. Creates the static meshes object found in the output + bool CreateStaticMeshes( + TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams, + const FHoudiniStaticMeshGenerationProperties& InStaticMeshGenerationProperties, const FMeshBuildSettings& InMeshBuildSettings); + // 6. Create the output curves + bool CreateCurves(TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams); + // 7. Create the output landscapes + bool CreateLandscapes(TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams); + // 8. Create the output instancers + bool CreateInstancers(TArray& InOutputs, UObject* InParent, FHoudiniPackageParams InPackageParams); + // 9. Clean up the created node + static bool DeleteCreatedNode(const HAPI_NodeId& InNodeId); + + static bool CreateInstancerOutputPartData( + TArray& InOutputs, + TMap& OutInstancedOutputPartData); + + private: + + // + // Input file + // + // Path how the file we're currently loading + FString SourceFilePath; + // Absolute Path to the file + FString AbsoluteFilePath; + FString AbsoluteFileDirectory; + // File Name / Extension + FString FileName; + FString FileExtension; + + + // + // Output file + // + // Output filename, if empty, will be set to the input filename + FString OutputFilename; + // Root Folder for storing the created files + FString BakeRootFolder; + + // + // Output Objects + // + TArray OutputObjects; + + //TArray OutputStaticMeshes; + //TArray OutputLandscapes; + //TArray OutputInstancers; + }; \ No newline at end of file diff --git a/Source/HoudiniEngine/Private/HoudiniPDGImporterMessages.cpp b/Source/HoudiniEngine/Private/HoudiniPDGImporterMessages.cpp index dfcb7b46a6..6979ce8958 100755 --- a/Source/HoudiniEngine/Private/HoudiniPDGImporterMessages.cpp +++ b/Source/HoudiniEngine/Private/HoudiniPDGImporterMessages.cpp @@ -1,107 +1,133 @@ -/* -* 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 "HoudiniPDGImporterMessages.h" - -FHoudiniPDGImportBGEOMessage::FHoudiniPDGImportBGEOMessage() - : FilePath() - , Name() - , TOPNodeId(-1) - , WorkItemId(-1) -{ - -} - -FHoudiniPDGImportBGEOMessage::FHoudiniPDGImportBGEOMessage( - const FString& InFilePath, - const FString& InName, - const FHoudiniPackageParams& InPackageParams -) - : FilePath(InFilePath) - , Name(InName) - , TOPNodeId(-1) - , WorkItemId(-1) -{ - SetPackageParams(InPackageParams); -} - -FHoudiniPDGImportBGEOMessage::FHoudiniPDGImportBGEOMessage( - const FString& InFilePath, - const FString& InName, - const FHoudiniPackageParams& InPackageParams, - HAPI_NodeId InTOPNodeId, - HAPI_PDG_WorkitemId InWorkItemId -) - : FilePath(InFilePath) - , Name(InName) - , TOPNodeId(InTOPNodeId) - , WorkItemId(InWorkItemId) -{ - SetPackageParams(InPackageParams); -} - -void FHoudiniPDGImportBGEOMessage::SetPackageParams(const FHoudiniPackageParams& InPackageParams) -{ - PackageParams = InPackageParams; - PackageParams.OuterPackage = nullptr; -} - -void FHoudiniPDGImportBGEOMessage::PopulatePackageParams(FHoudiniPackageParams& OutPackageParams) const -{ - UObject* KeepOuter = OutPackageParams.OuterPackage; - OutPackageParams = PackageParams; - OutPackageParams.OuterPackage = KeepOuter; -} - -FHoudiniPDGImportBGEOResultMessage::FHoudiniPDGImportBGEOResultMessage() - : ImportResult(EHoudiniPDGImportBGEOResult::HPIBR_Failed) -{ - -} - -FHoudiniPDGImportBGEOResultMessage::FHoudiniPDGImportBGEOResultMessage( - const FString& InFilePath, - const FString& InName, - const FHoudiniPackageParams& InPackageParams, - const EHoudiniPDGImportBGEOResult& InImportResult -) - : FHoudiniPDGImportBGEOMessage(InFilePath, InName, InPackageParams) - , ImportResult(InImportResult) -{ -} - -FHoudiniPDGImportBGEODiscoverMessage::FHoudiniPDGImportBGEODiscoverMessage() - : CommandletGuid() -{ - -} - -FHoudiniPDGImportBGEODiscoverMessage::FHoudiniPDGImportBGEODiscoverMessage(const FGuid& InCommandletGuid) - : CommandletGuid(InCommandletGuid) -{ - -} - +/* +* 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 "HoudiniPDGImporterMessages.h" +#include "HoudiniEngineRuntimeUtils.h" + + +FHoudiniPDGImportBGEOMessage::FHoudiniPDGImportBGEOMessage() + : FilePath() + , Name() + , TOPNodeId(-1) + , WorkItemId(-1) +{ + StaticMeshGenerationProperties = FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(); + MeshBuildSettings = FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(); +} + +FHoudiniPDGImportBGEOMessage::FHoudiniPDGImportBGEOMessage( + const FString& InFilePath, + const FString& InName, + const FHoudiniPackageParams& InPackageParams +) + : FilePath(InFilePath) + , Name(InName) + , TOPNodeId(-1) + , WorkItemId(-1) +{ + SetPackageParams(InPackageParams); + StaticMeshGenerationProperties = FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(); + MeshBuildSettings = FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(); +} + +FHoudiniPDGImportBGEOMessage::FHoudiniPDGImportBGEOMessage( + const FString& InFilePath, + const FString& InName, + const FHoudiniPackageParams& InPackageParams, + HAPI_NodeId InTOPNodeId, + HAPI_PDG_WorkitemId InWorkItemId +) + : FilePath(InFilePath) + , Name(InName) + , TOPNodeId(InTOPNodeId) + , WorkItemId(InWorkItemId) +{ + SetPackageParams(InPackageParams); + StaticMeshGenerationProperties = FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(); + MeshBuildSettings = FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(); +} + +FHoudiniPDGImportBGEOMessage::FHoudiniPDGImportBGEOMessage( + const FString& InFilePath, + const FString& InName, + const FHoudiniPackageParams& InPackageParams, + HAPI_NodeId InTOPNodeId, + HAPI_PDG_WorkitemId InWorkItemId, + const FHoudiniStaticMeshGenerationProperties& InStaticMeshGenerationProperties, + const FMeshBuildSettings& InMeshBuildSettings +) + : FilePath(InFilePath) + , Name(InName) + , TOPNodeId(InTOPNodeId) + , WorkItemId(InWorkItemId) + , StaticMeshGenerationProperties(InStaticMeshGenerationProperties) + , MeshBuildSettings(InMeshBuildSettings) +{ + SetPackageParams(InPackageParams); +} + +void FHoudiniPDGImportBGEOMessage::SetPackageParams(const FHoudiniPackageParams& InPackageParams) +{ + PackageParams = InPackageParams; + PackageParams.OuterPackage = nullptr; +} + +void FHoudiniPDGImportBGEOMessage::PopulatePackageParams(FHoudiniPackageParams& OutPackageParams) const +{ + UObject* KeepOuter = OutPackageParams.OuterPackage; + OutPackageParams = PackageParams; + OutPackageParams.OuterPackage = KeepOuter; +} + +FHoudiniPDGImportBGEOResultMessage::FHoudiniPDGImportBGEOResultMessage() + : ImportResult(EHoudiniPDGImportBGEOResult::HPIBR_Failed) +{ + +} + +FHoudiniPDGImportBGEOResultMessage::FHoudiniPDGImportBGEOResultMessage( + const FString& InFilePath, + const FString& InName, + const FHoudiniPackageParams& InPackageParams, + const EHoudiniPDGImportBGEOResult& InImportResult +) + : FHoudiniPDGImportBGEOMessage(InFilePath, InName, InPackageParams) + , ImportResult(InImportResult) +{ +} + +FHoudiniPDGImportBGEODiscoverMessage::FHoudiniPDGImportBGEODiscoverMessage() + : CommandletGuid() +{ + +} + +FHoudiniPDGImportBGEODiscoverMessage::FHoudiniPDGImportBGEODiscoverMessage(const FGuid& InCommandletGuid) + : CommandletGuid(InCommandletGuid) +{ + +} + diff --git a/Source/HoudiniEngine/Private/HoudiniPDGImporterMessages.h b/Source/HoudiniEngine/Private/HoudiniPDGImporterMessages.h index fa2f6f6853..50806c2d35 100755 --- a/Source/HoudiniEngine/Private/HoudiniPDGImporterMessages.h +++ b/Source/HoudiniEngine/Private/HoudiniPDGImporterMessages.h @@ -1,188 +1,208 @@ -/* -* 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 "Misc/Guid.h" - -#include "HAPI/HAPI_Common.h" - -#include "HoudiniPackageParams.h" -#include "HoudiniGeoPartObject.h" -#include "HoudiniOutput.h" -#include "HoudiniGenericAttribute.h" -#include "HoudiniInstanceTranslator.h" - -#include "HoudiniPDGImporterMessages.generated.h" - -// Message used to find/discover running commandlets -USTRUCT() -struct HOUDINIENGINE_API FHoudiniPDGImportBGEODiscoverMessage -{ -public: - GENERATED_BODY(); - - FHoudiniPDGImportBGEODiscoverMessage(); - - FHoudiniPDGImportBGEODiscoverMessage(const FGuid& InCommandletGuid); - - // The GUID of the commandlet we are looking for - UPROPERTY() - FGuid CommandletGuid; -}; - -USTRUCT() -struct HOUDINIENGINE_API FHoudiniPDGImportBGEOMessage -{ -public: - GENERATED_BODY(); - - FHoudiniPDGImportBGEOMessage(); - - FHoudiniPDGImportBGEOMessage(const FString& InFilePath, const FString& InName, const FHoudiniPackageParams& InPackageParams); - - FHoudiniPDGImportBGEOMessage( - const FString& InFilePath, - const FString& InName, - const FHoudiniPackageParams& InPackageParams, - HAPI_NodeId InTOPNodeId, - HAPI_PDG_WorkitemId InWorkItemId); - - void SetPackageParams(const FHoudiniPackageParams& InPackageParams); - - void PopulatePackageParams(FHoudiniPackageParams &OutPackageParams) const; - - // BGEO file path - UPROPERTY() - FString FilePath; - - // PDG work item name - UPROPERTY() - FString Name; - - // TOP/PDG info - // TOP node ID - UPROPERTY() - // HAPI_NodeId TOPNodeId; - int32 TOPNodeId; - - // Work item id - UPROPERTY() - // HAPI_PDG_WorkitemId WorkItemId; - int32 WorkItemId; - - // Package params for the asset - UPROPERTY() - FHoudiniPackageParams PackageParams; -}; - - -UENUM() -enum class EHoudiniPDGImportBGEOResult : uint8 -{ - // Create uassets from the bgeo completely failed. - HPIBR_Failed UMETA(DisplayName="Failed"), - - // Successfully created uassets for all content in the bgeo - HPIBR_Success UMETA(DisplayName = "Success"), - - // Some uassets were created, but there were unsupported objects in the bgeo as well - HPIBR_PartialSuccess UMETA(DisplayName = "Partial Success"), - - HIBPR_MAX -}; - -USTRUCT() -struct HOUDINIENGINE_API FHoudiniGenericAttributes -{ -public: - GENERATED_BODY() - - FHoudiniGenericAttributes() {}; - FHoudiniGenericAttributes(const TArray& InPropertyAttributes) : PropertyAttributes(InPropertyAttributes) {}; - FHoudiniGenericAttributes(TArray&& InPropertyAttributes) : PropertyAttributes(InPropertyAttributes) {}; - - UPROPERTY() - TArray PropertyAttributes; -}; - -USTRUCT() -struct HOUDINIENGINE_API FHoudiniPDGImportNodeOutputObject -{ -public: - GENERATED_BODY(); - - UPROPERTY() - FHoudiniOutputObjectIdentifier Identifier; - - UPROPERTY() - FString PackagePath; - - UPROPERTY() - FHoudiniGenericAttributes GenericAttributes; - - UPROPERTY() - TMap CachedAttributes; -}; - -USTRUCT() -struct HOUDINIENGINE_API FHoudiniPDGImportNodeOutput -{ -public: - GENERATED_BODY(); - - UPROPERTY() - TArray HoudiniGeoPartObjects; - - UPROPERTY() - TArray OutputObjects; - - UPROPERTY() - TArray InstancedOutputPartData; -}; - -USTRUCT() -struct HOUDINIENGINE_API FHoudiniPDGImportBGEOResultMessage : public FHoudiniPDGImportBGEOMessage -{ -public: - GENERATED_BODY(); - - FHoudiniPDGImportBGEOResultMessage(); - - FHoudiniPDGImportBGEOResultMessage(const FString& InFilePath, const FString& InName, const FHoudiniPackageParams& InPackageParams, const EHoudiniPDGImportBGEOResult& InImportResult); - - void operator=(const FHoudiniPDGImportBGEOMessage& InRHS) { (*static_cast(this)) = InRHS; } - - // Result of the bgeo import -> uassets - UPROPERTY() - EHoudiniPDGImportBGEOResult ImportResult; - - UPROPERTY() - TArray Outputs; - -}; - +/* +* 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 "Misc/Guid.h" + +#include "HAPI/HAPI_Common.h" + +#include "HoudiniPackageParams.h" +#include "HoudiniGeoPartObject.h" +#include "HoudiniOutput.h" +#include "HoudiniGenericAttribute.h" +#include "HoudiniInstanceTranslator.h" + +#include "HoudiniPDGImporterMessages.generated.h" + +struct FHoudiniStaticMeshGenerationProperties; +struct FMeshBuildSettings; + +// Message used to find/discover running commandlets +USTRUCT() +struct HOUDINIENGINE_API FHoudiniPDGImportBGEODiscoverMessage +{ +public: + GENERATED_BODY(); + + FHoudiniPDGImportBGEODiscoverMessage(); + + FHoudiniPDGImportBGEODiscoverMessage(const FGuid& InCommandletGuid); + + // The GUID of the commandlet we are looking for + UPROPERTY() + FGuid CommandletGuid; +}; + +USTRUCT() +struct HOUDINIENGINE_API FHoudiniPDGImportBGEOMessage +{ +public: + GENERATED_BODY(); + + FHoudiniPDGImportBGEOMessage(); + + FHoudiniPDGImportBGEOMessage(const FString& InFilePath, const FString& InName, const FHoudiniPackageParams& InPackageParams); + + FHoudiniPDGImportBGEOMessage( + const FString& InFilePath, + const FString& InName, + const FHoudiniPackageParams& InPackageParams, + HAPI_NodeId InTOPNodeId, + HAPI_PDG_WorkitemId InWorkItemId); + + FHoudiniPDGImportBGEOMessage( + const FString& InFilePath, + const FString& InName, + const FHoudiniPackageParams& InPackageParams, + HAPI_NodeId InTOPNodeId, + HAPI_PDG_WorkitemId InWorkItemId, + const FHoudiniStaticMeshGenerationProperties& InStaticMeshGenerationProperties, + const FMeshBuildSettings& InMeshBuildSettings); + + void SetPackageParams(const FHoudiniPackageParams& InPackageParams); + + void PopulatePackageParams(FHoudiniPackageParams &OutPackageParams) const; + + // BGEO file path + UPROPERTY() + FString FilePath; + + // PDG work item name + UPROPERTY() + FString Name; + + // TOP/PDG info + // TOP node ID + UPROPERTY() + // HAPI_NodeId TOPNodeId; + int32 TOPNodeId; + + // Work item id + UPROPERTY() + // HAPI_PDG_WorkitemId WorkItemId; + int32 WorkItemId; + + // Package params for the asset + UPROPERTY() + FHoudiniPackageParams PackageParams; + + // Settings used during static mesh generation + UPROPERTY() + FHoudiniStaticMeshGenerationProperties StaticMeshGenerationProperties; + + // Static mesh build settings used during mesh builds + UPROPERTY() + FMeshBuildSettings MeshBuildSettings; +}; + + +UENUM() +enum class EHoudiniPDGImportBGEOResult : uint8 +{ + // Create uassets from the bgeo completely failed. + HPIBR_Failed UMETA(DisplayName="Failed"), + + // Successfully created uassets for all content in the bgeo + HPIBR_Success UMETA(DisplayName = "Success"), + + // Some uassets were created, but there were unsupported objects in the bgeo as well + HPIBR_PartialSuccess UMETA(DisplayName = "Partial Success"), + + HIBPR_MAX +}; + +USTRUCT() +struct HOUDINIENGINE_API FHoudiniGenericAttributes +{ +public: + GENERATED_BODY() + + FHoudiniGenericAttributes() {}; + FHoudiniGenericAttributes(const TArray& InPropertyAttributes) : PropertyAttributes(InPropertyAttributes) {}; + FHoudiniGenericAttributes(TArray&& InPropertyAttributes) : PropertyAttributes(InPropertyAttributes) {}; + + UPROPERTY() + TArray PropertyAttributes; +}; + +USTRUCT() +struct HOUDINIENGINE_API FHoudiniPDGImportNodeOutputObject +{ +public: + GENERATED_BODY(); + + UPROPERTY() + FHoudiniOutputObjectIdentifier Identifier; + + UPROPERTY() + FString PackagePath; + + UPROPERTY() + FHoudiniGenericAttributes GenericAttributes; + + UPROPERTY() + TMap CachedAttributes; +}; + +USTRUCT() +struct HOUDINIENGINE_API FHoudiniPDGImportNodeOutput +{ +public: + GENERATED_BODY(); + + UPROPERTY() + TArray HoudiniGeoPartObjects; + + UPROPERTY() + TArray OutputObjects; + + UPROPERTY() + TArray InstancedOutputPartData; +}; + +USTRUCT() +struct HOUDINIENGINE_API FHoudiniPDGImportBGEOResultMessage : public FHoudiniPDGImportBGEOMessage +{ +public: + GENERATED_BODY(); + + FHoudiniPDGImportBGEOResultMessage(); + + FHoudiniPDGImportBGEOResultMessage(const FString& InFilePath, const FString& InName, const FHoudiniPackageParams& InPackageParams, const EHoudiniPDGImportBGEOResult& InImportResult); + + void operator=(const FHoudiniPDGImportBGEOMessage& InRHS) { (*static_cast(this)) = InRHS; } + + // Result of the bgeo import -> uassets + UPROPERTY() + EHoudiniPDGImportBGEOResult ImportResult; + + UPROPERTY() + TArray Outputs; + +}; + diff --git a/Source/HoudiniEngine/Private/HoudiniPDGManager.cpp b/Source/HoudiniEngine/Private/HoudiniPDGManager.cpp index da5754b059..c1a18b451d 100755 --- a/Source/HoudiniEngine/Private/HoudiniPDGManager.cpp +++ b/Source/HoudiniEngine/Private/HoudiniPDGManager.cpp @@ -1704,6 +1704,11 @@ FHoudiniPDGManager::ProcessWorkItemResults() } PackageParams.ObjectName = FString(); + // Static mesh generation / build settings, get it from the HAC if available, otherwise from the plugin + // defaults + const FHoudiniStaticMeshGenerationProperties& StaticMeshGenerationProperties = HAC ? HAC->StaticMeshGenerationProperties : FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(); + const FMeshBuildSettings& MeshBuildSettings = HAC ? HAC->StaticMeshBuildSettings : FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(); + // UWorld *World = ParentActor ? ParentActor->GetWorld() : AssetLink->GetWorld(); UWorld *World = AssetLink->GetWorld(); @@ -1753,7 +1758,9 @@ FHoudiniPDGManager::ProcessWorkItemResults() CurrentWorkResultObj.Name, PackageParams, CurrentTOPNode->NodeId, - CurrentWorkResult.WorkItemID + CurrentWorkResult.WorkItemID, + StaticMeshGenerationProperties, + MeshBuildSettings ), BGEOCommandletAddress); } else diff --git a/Source/HoudiniEngine/Private/HoudiniPDGTranslator.cpp b/Source/HoudiniEngine/Private/HoudiniPDGTranslator.cpp index deb0de7770..84a1a6185d 100755 --- a/Source/HoudiniEngine/Private/HoudiniPDGTranslator.cpp +++ b/Source/HoudiniEngine/Private/HoudiniPDGTranslator.cpp @@ -148,6 +148,7 @@ FHoudiniPDGTranslator::CreateAllResultObjectsForPDGWorkItem( InTOPNode->ClearedLandscapeLayers, AllInputLandscapes, InputLandscapesToUpdate, + InAssetLink, InOutputTypesToProcess, bInTreatExistingMaterialsAsUpToDate); @@ -240,6 +241,7 @@ FHoudiniPDGTranslator::LoadExistingAssetsAsResultObjectsForPDGWorkItem( InTOPNode->ClearedLandscapeLayers, AllInputLandscapes, InputLandscapesToUpdate, + InAssetLink, InOutputTypesToProcess, bInTreatExistingMaterialsAsUpToDate, bOnlyUseExistingAssets, @@ -268,6 +270,7 @@ FHoudiniPDGTranslator::CreateAllResultObjectsFromPDGOutputs( TSet& ClearedLandscapeLayers, TArray AllInputLandscapes, TArray InputLandscapesToUpdate, + UHoudiniPDGAssetLink* const InAssetLink, TArray InOutputTypesToProcess, bool bInTreatExistingMaterialsAsUpToDate, bool bInOnlyUseExistingAssets, @@ -303,6 +306,10 @@ FHoudiniPDGTranslator::CreateAllResultObjectsFromPDGOutputs( //bool bCreatedNewMaps = false; UWorld* PersistentWorld = InOuterComponent->GetTypedOuter(); check(PersistentWorld); + + // Fetch the HAC if the asset link is associated with one + UHoudiniAssetComponent const* const HAC = IsValid(InAssetLink) ? InAssetLink->GetOuterHoudiniAssetComponent() : nullptr; + const bool bIsHACValid = IsValid(HAC); // Keep track of all generated houdini materials to avoid recreating them over and over TMap AllOutputMaterials; @@ -333,15 +340,13 @@ FHoudiniPDGTranslator::CreateAllResultObjectsFromPDGOutputs( } else { - // TODO: If Outer is an HAC, get SMGP/MBS from it ?? - FHoudiniStaticMeshGenerationProperties SMGP = FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(); - FMeshBuildSettings MBS = FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(); + // If we have a valid HAC get SMGP/MBS from it, otherwise use the plugin settings FHoudiniMeshTranslator::CreateAllMeshesAndComponentsFromHoudiniOutput( CurOutput, InPackageParams, EHoudiniStaticMeshMethod::RawMesh, - SMGP, - MBS, + bIsHACValid ? HAC->StaticMeshGenerationProperties : FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(), + bIsHACValid ? HAC->StaticMeshBuildSettings : FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(), AllOutputMaterials, InOuterComponent, bInTreatExistingMaterialsAsUpToDate, diff --git a/Source/HoudiniEngine/Private/HoudiniPDGTranslator.h b/Source/HoudiniEngine/Private/HoudiniPDGTranslator.h index 689b1e9dda..021bb7fd85 100755 --- a/Source/HoudiniEngine/Private/HoudiniPDGTranslator.h +++ b/Source/HoudiniEngine/Private/HoudiniPDGTranslator.h @@ -1,87 +1,88 @@ -/* -* 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" - -class UHoudiniPDGAssetLink; -class UHoudiniOutput; -class AActor; -class UTOPNode; -class ALandscapeProxy; - -enum class EHoudiniOutputType : uint8; - -struct FHoudiniPackageParams; -struct FTOPWorkResultObject; -struct FHoudiniOutputObjectIdentifier; -struct FHoudiniInstancedOutputPartData; -struct FHoudiniLandscapeExtent; -struct FHoudiniLandscapeReferenceLocation; -struct FHoudiniLandscapeTileSizeInfo; - -struct HOUDINIENGINE_API FHoudiniPDGTranslator -{ - public: - // Create/update assets/geometry for all PDG outputs of InWorkResultObject. This will use - // InWorkResultObject.FilePath to load the BGEO file and update/build outputs. - static bool CreateAllResultObjectsForPDGWorkItem( - UHoudiniPDGAssetLink* InAssetLink, - UTOPNode* InTOPNode, - FTOPWorkResultObject& InWorkResultObject, - const FHoudiniPackageParams& InPackageParams, - TArray InOutputTypesToProcess={}, - bool bInTreatExistingMaterialsAsUpToDate=false); - - static bool LoadExistingAssetsAsResultObjectsForPDGWorkItem( - UHoudiniPDGAssetLink* InAssetLink, - UTOPNode* InTOPNode, - FTOPWorkResultObject& InWorkResultObject, - const FHoudiniPackageParams& InPackageParams, - TArray& InOutputs, - TArray InOutputTypesToProcess={}, - const TMap* InPreBuiltInstancedOutputPartData=nullptr); - - // Use the relevant translators to create assets/geometry for all PDG outputs (InOutputs). - // InOuterComponent is the component to attach the created output objects/components to. - static bool CreateAllResultObjectsFromPDGOutputs( - TArray& InOutputs, - const FHoudiniPackageParams& InPackageParams, - UObject* InOuterComponent, - FHoudiniLandscapeExtent& CachedLandscapeExtent, - FHoudiniLandscapeReferenceLocation& CachedLandscapeRefLoc, - FHoudiniLandscapeTileSizeInfo& CachedLandscapeSizeInfo, - TSet& ClearedLandscapeLayers, - TArray AllInputLandscapes, - TArray InputLandscapesToUpdate, - TArray InOutputTypesToProcess={}, - bool bInTreatExistingMaterialsAsUpToDate=false, - bool bInOnlyUseExistingAssets=false, - const TMap* InPreBuiltInstancedOutputPartData=nullptr - ); -}; - +/* +* 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" + +class UHoudiniPDGAssetLink; +class UHoudiniOutput; +class AActor; +class UTOPNode; +class ALandscapeProxy; + +enum class EHoudiniOutputType : uint8; + +struct FHoudiniPackageParams; +struct FTOPWorkResultObject; +struct FHoudiniOutputObjectIdentifier; +struct FHoudiniInstancedOutputPartData; +struct FHoudiniLandscapeExtent; +struct FHoudiniLandscapeReferenceLocation; +struct FHoudiniLandscapeTileSizeInfo; + +struct HOUDINIENGINE_API FHoudiniPDGTranslator +{ + public: + // Create/update assets/geometry for all PDG outputs of InWorkResultObject. This will use + // InWorkResultObject.FilePath to load the BGEO file and update/build outputs. + static bool CreateAllResultObjectsForPDGWorkItem( + UHoudiniPDGAssetLink* InAssetLink, + UTOPNode* InTOPNode, + FTOPWorkResultObject& InWorkResultObject, + const FHoudiniPackageParams& InPackageParams, + TArray InOutputTypesToProcess={}, + bool bInTreatExistingMaterialsAsUpToDate=false); + + static bool LoadExistingAssetsAsResultObjectsForPDGWorkItem( + UHoudiniPDGAssetLink* InAssetLink, + UTOPNode* InTOPNode, + FTOPWorkResultObject& InWorkResultObject, + const FHoudiniPackageParams& InPackageParams, + TArray& InOutputs, + TArray InOutputTypesToProcess={}, + const TMap* InPreBuiltInstancedOutputPartData=nullptr); + + // Use the relevant translators to create assets/geometry for all PDG outputs (InOutputs). + // InOuterComponent is the component to attach the created output objects/components to. + static bool CreateAllResultObjectsFromPDGOutputs( + TArray& InOutputs, + const FHoudiniPackageParams& InPackageParams, + UObject* InOuterComponent, + FHoudiniLandscapeExtent& CachedLandscapeExtent, + FHoudiniLandscapeReferenceLocation& CachedLandscapeRefLoc, + FHoudiniLandscapeTileSizeInfo& CachedLandscapeSizeInfo, + TSet& ClearedLandscapeLayers, + TArray AllInputLandscapes, + TArray InputLandscapesToUpdate, + UHoudiniPDGAssetLink* const InAssetLink, + TArray InOutputTypesToProcess={}, + bool bInTreatExistingMaterialsAsUpToDate=false, + bool bInOnlyUseExistingAssets=false, + const TMap* InPreBuiltInstancedOutputPartData=nullptr + ); +}; + diff --git a/Source/HoudiniEngineEditor/Private/HoudiniGeoFactory.cpp b/Source/HoudiniEngineEditor/Private/HoudiniGeoFactory.cpp index 67224f86d1..5c86d7de09 100755 --- a/Source/HoudiniEngineEditor/Private/HoudiniGeoFactory.cpp +++ b/Source/HoudiniEngineEditor/Private/HoudiniGeoFactory.cpp @@ -240,7 +240,9 @@ UHoudiniGeoFactory::Import(UClass* InClass, UPackage* InParent, const FString & return FailImportAndReturnNull(); // 5. Create the static meshes in the outputs - if (!BGEOImporter->CreateStaticMeshes(NewOutputs, InParent, PackageParams)) + const FHoudiniStaticMeshGenerationProperties& StaticMeshGenerationProperties = FHoudiniEngineRuntimeUtils::GetDefaultStaticMeshGenerationProperties(); + const FMeshBuildSettings& MeshBuildSettings = FHoudiniEngineRuntimeUtils::GetDefaultMeshBuildSettings(); + if (!BGEOImporter->CreateStaticMeshes(NewOutputs, InParent, PackageParams, StaticMeshGenerationProperties, MeshBuildSettings)) return FailImportAndReturnNull(); // 6. Create the curves in the outputs