From 37fc7c464e5ca16eb97076ea1c835191c7fd0079 Mon Sep 17 00:00:00 2001 From: SEB SCHMIDT Date: Tue, 30 Jul 2024 01:48:58 +1200 Subject: [PATCH] Adding Hydra Generative Procedural Example of a simple Triangle Signed-off-by: Seb Schmidt --- README.md | 1 + src/CMakeLists.txt | 1 + src/hdGpTri/CMakeLists.txt | 25 +++ src/hdGpTri/debugCodes.cpp | 18 ++ src/hdGpTri/debugCodes.h | 15 ++ src/hdGpTri/plugInfo.json | 22 ++ src/hdGpTri/scenes/triangle.usda | 42 ++++ src/hdGpTri/scenes/triangleAnimated.usda | 23 ++ src/hdGpTri/triGenerative.cpp | 265 +++++++++++++++++++++++ src/hdGpTri/triGenerative.h | 52 +++++ 10 files changed, 464 insertions(+) create mode 100644 src/hdGpTri/CMakeLists.txt create mode 100644 src/hdGpTri/debugCodes.cpp create mode 100644 src/hdGpTri/debugCodes.h create mode 100644 src/hdGpTri/plugInfo.json create mode 100644 src/hdGpTri/scenes/triangle.usda create mode 100644 src/hdGpTri/scenes/triangleAnimated.usda create mode 100644 src/hdGpTri/triGenerative.cpp create mode 100644 src/hdGpTri/triGenerative.h diff --git a/README.md b/README.md index 9bfd1de..74f98ce 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Huge thanks to Pixar's USD team for providing a highly extensible platform! - [usdTriImagingHd2](./src/usdTriImagingHd2): A *Hydra 2 only* prim adapter which images the **Triangle** prim type. [*] - [usdTriFileFormat](./src/usdTriFileFormat): A file format plugin which authors a triangular mesh for a `.triangle` payload. - [hdTri](./src/hdTri): A hydra renderer plugin which images a triangle (in the most direct sense). +- [hdGpTri](./src/hdGpTri): A generative procedural plugin which creates a triangle (in the most direct sense). - [usdviewTri](./src/usdviewTri): An usdview plugin providing a menu command to define child Triangle prim(s) under selected paths. [*] We deliberatly split the Hydra 1 & 2 Triangle Prim Adapters into two plugins/sources to outline the differences diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 42f1746..28864fd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,7 @@ endif() add_subdirectory(usdTriFileFormat) add_subdirectory(hdTri) +add_subdirectory(hdGpTri) # Install top-level plugInfo for including per-library plugInfo(s). install( diff --git a/src/hdGpTri/CMakeLists.txt b/src/hdGpTri/CMakeLists.txt new file mode 100644 index 0000000..3f1124a --- /dev/null +++ b/src/hdGpTri/CMakeLists.txt @@ -0,0 +1,25 @@ +usd_plugin(hdGpTri + + PUBLIC_HEADERS_INSTALL_PREFIX + ${ORGANIZATION} + + PYTHON_INSTALL_PREFIX + ${ORGANIZATION} + + LIBRARIES + js + plug + tf + sdf + vt + gf + hdGp + arch + + CPPFILES + triGenerative.cpp + debugCodes.cpp + + RESOURCE_FILES + plugInfo.json +) diff --git a/src/hdGpTri/debugCodes.cpp b/src/hdGpTri/debugCodes.cpp new file mode 100644 index 0000000..cf720a7 --- /dev/null +++ b/src/hdGpTri/debugCodes.cpp @@ -0,0 +1,18 @@ +// +// Copyright © 2024 Weta Digital Limited +// +// SPDX-License-Identifier: Apache-2.0 +// +#include "debugCodes.h" +#include "pxr/base/tf/debug.h" +#include + +PXR_NAMESPACE_OPEN_SCOPE + +TF_REGISTRY_FUNCTION(TfDebug) +{ + TF_DEBUG_ENVIRONMENT_SYMBOL( + USDTRI_GENERATIVE, "Debug symbol for the usdTri GenerativeProcedural."); +} + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/src/hdGpTri/debugCodes.h b/src/hdGpTri/debugCodes.h new file mode 100644 index 0000000..14f80ec --- /dev/null +++ b/src/hdGpTri/debugCodes.h @@ -0,0 +1,15 @@ +// +// Copyright © 2024 Weta Digital Limited +// +// SPDX-License-Identifier: Apache-2.0 +// +#pragma once + +#include +#include + +PXR_NAMESPACE_OPEN_SCOPE + +TF_DEBUG_CODES(USDTRI_GENERATIVE); + +PXR_NAMESPACE_CLOSE_SCOPE diff --git a/src/hdGpTri/plugInfo.json b/src/hdGpTri/plugInfo.json new file mode 100644 index 0000000..e6e8978 --- /dev/null +++ b/src/hdGpTri/plugInfo.json @@ -0,0 +1,22 @@ +{ + "Plugins": [ + { + "Info": { + "Types": { + "TriProceduralPlugin": { + "bases": [ + "HdGpGenerativeProceduralPlugin" + ], + "displayName": "triangle", + "priority" : 0 + } + } + }, + "LibraryPath": "../../hdGpTri.so", + "Name": "hdGpTri", + "ResourcePath": "resources", + "Root": "..", + "Type": "library" + } + ] +} diff --git a/src/hdGpTri/scenes/triangle.usda b/src/hdGpTri/scenes/triangle.usda new file mode 100644 index 0000000..a3534f3 --- /dev/null +++ b/src/hdGpTri/scenes/triangle.usda @@ -0,0 +1,42 @@ +#usda 1.0 + + +def Scope "World" +{ + def GenerativeProcedural "myGenerativeProc" ( + prepend apiSchemas = ["HydraGenerativeProceduralAPI"] + ) + { + token primvars:hdGp:proceduralType = "triangle" + double primvars:sideLength = 1.0 + } + + def Scope "leaf_transformed" + { + + def GenerativeProcedural "myGenerativeProcTransformed" ( + prepend apiSchemas = ["HydraGenerativeProceduralAPI"] + ) + { + token primvars:hdGp:proceduralType = "triangle" + double primvars:sideLength = 1.0 + + matrix4d xformOp:transform:transform1 = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (15, 15, 15, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform:transform1"] + } + } + def Xform "transformed" + { + matrix4d xformOp:transform:transform1 = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (15, 15, 15, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform:transform1"] + + def GenerativeProcedural "myGenerativeProcTransformed" ( + prepend apiSchemas = ["HydraGenerativeProceduralAPI"] + ) + { + token primvars:hdGp:proceduralType = "triangle" + double primvars:sideLength = 1.0 + + } + } +} \ No newline at end of file diff --git a/src/hdGpTri/scenes/triangleAnimated.usda b/src/hdGpTri/scenes/triangleAnimated.usda new file mode 100644 index 0000000..3b1f115 --- /dev/null +++ b/src/hdGpTri/scenes/triangleAnimated.usda @@ -0,0 +1,23 @@ +#usda 1.0 +( + startFrame = 1 + endFrame = 10 +) + +def Scope "World" +{ + def GenerativeProcedural "myGenerativeProcAnimated" ( + prepend apiSchemas = ["HydraGenerativeProceduralAPI"] + ) + { + token primvars:hdGp:proceduralType = "triangle" + double primvars:sideLength = 1.0 + double primvars:sideLength.timeSamples = { + 1: 1, + 10: 10 + } + + matrix4d xformOp:transform:transform1 = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (30, 30, 30, 1) ) + uniform token[] xformOpOrder = ["xformOp:transform:transform1"] + } +} \ No newline at end of file diff --git a/src/hdGpTri/triGenerative.cpp b/src/hdGpTri/triGenerative.cpp new file mode 100644 index 0000000..00b8d3a --- /dev/null +++ b/src/hdGpTri/triGenerative.cpp @@ -0,0 +1,265 @@ +// +// Copyright © 2024 Weta FX Limited +// +// SPDX-License-Identifier: Apache-2.0 +// + +#include "./triGenerative.h" +#include "./debugCodes.h" +#include +#include +#include +#include +#include +#include +#include + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { +TF_DEFINE_PRIVATE_TOKENS(_makeSomeStuffTokens, (sideLength)(myTriangle)); +} + +/// @brief the data-source containing the Point positions for a triangle +/// based on the sideLength +class _PointsFromSideLengthDataSource : public HdVec3fArrayDataSource +{ +public: + HD_DECLARE_DATASOURCE(_PointsFromSideLengthDataSource); + + bool GetContributingSampleTimesForInterval( + Time startTime, + Time endTime, + std::vector