From 5b81046bfb4a2d19992477fc97ff6cf59e2ca27d Mon Sep 17 00:00:00 2001 From: Infernalspawn Date: Mon, 29 Jul 2024 06:50:32 +1200 Subject: [PATCH] Adding Hydra Generative Procedural Example of a simple Triangle Signed-off-by: Infernalspawn --- README.md | 5 +- src/CMakeLists.txt | 1 + src/hdGpTri/CMakeLists.txt | 41 +++++++ src/hdGpTri/plugInfo.json | 22 ++++ src/hdGpTri/scenes/triangle.usda | 27 +++++ src/hdGpTri/triGenerative.cpp | 193 +++++++++++++++++++++++++++++++ src/hdGpTri/triGenerative.h | 54 +++++++++ 7 files changed, 341 insertions(+), 2 deletions(-) create mode 100644 src/hdGpTri/CMakeLists.txt create mode 100644 src/hdGpTri/plugInfo.json create mode 100644 src/hdGpTri/scenes/triangle.usda create mode 100644 src/hdGpTri/triGenerative.cpp create mode 100644 src/hdGpTri/triGenerative.h diff --git a/README.md b/README.md index 82a384b..7ca2338 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ A collection of example plugins for [Pixar's USD](https://github.com/PixarAnimationStudios/USD) (Universal Scene Description). -This project also aims to provide a set of CMake utilities for building USD plugins outside of the USD project source tree. The utilities are heavily based on the build logic prescribed by the USD project itself. +This project also aims to provide a set of CMake utilities for building USD plugins outside of the USD project source tree. The utilities are heavily based on the build logic prescribed by the USD project itself. -We hope the minimal examples and surrounding build infrastructure can be useful to USD community developers interested in building and deploying their own plugin(s). +We hope the minimal examples and surrounding build infrastructure can be useful to USD community developers interested in building and deploying their own plugin(s). Huge thanks to Pixar's USD team for providing a highly extensible platform! @@ -25,6 +25,7 @@ Huge thanks to Pixar's USD team for providing a highly extensible platform! - [usdTriImaging](./src/usdTriImaging): A 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. There are many other USD plugins available online - check out [USD Working Group: Projects & Resources](https://wiki.aswf.io/display/WGUSD/USD+Projects+and+Resources) for more! diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8e8323b..5852381 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,6 +11,7 @@ add_subdirectory(usdviewTri) add_subdirectory(usdTriImaging) 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..9b358a6 --- /dev/null +++ b/src/hdGpTri/CMakeLists.txt @@ -0,0 +1,41 @@ +usd_plugin(hdGpTri + + PUBLIC_HEADERS_INSTALL_PREFIX + ${ORGANIZATION} + + PYTHON_INSTALL_PREFIX + ${ORGANIZATION} + + LIBRARIES + js + plug + tf + sdf + vt + gf + hdGp + arch + + CPPFILES + triGenerative.cpp + + RESOURCE_FILES + plugInfo.json +) + + +#add_subdirectory(tests) + +#usd_test(usdTriGenerative_testTriangle + +# CPPFILES +# tests/testUsdImagingGLHdGp.cpp + +# LIBRARIES +# tf +# sdf +# usd +# usdGeom +# hdGp +# usdImagingGL +#) \ No newline at end of file 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..4d4b5ff --- /dev/null +++ b/src/hdGpTri/scenes/triangle.usda @@ -0,0 +1,27 @@ +#usda 1.0 +( + startFrame = 1 + endFrame = 2 +) + +def Scope "World" +{ + def GenerativeProcedural "myGenerativeProc" ( + prepend apiSchemas = ["HydraGenerativeProceduralAPI"] + ) + { + token primvars:hdGp:proceduralType = "triangle" + double primvars:sideLength = 1.0 + } + + def GenerativeProcedural "myGenerativeProTransformed" ( + 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"] + } +} \ No newline at end of file diff --git a/src/hdGpTri/triGenerative.cpp b/src/hdGpTri/triGenerative.cpp new file mode 100644 index 0000000..a317595 --- /dev/null +++ b/src/hdGpTri/triGenerative.cpp @@ -0,0 +1,193 @@ +// +// Copyright © 2024 Weta FX Limited +// +// SPDX-License-Identifier: Apache-2.0 +// + +#include "./triGenerative.h" + +#include +#include +#include +#include + +PXR_NAMESPACE_USING_DIRECTIVE + +namespace { +TF_DEFINE_PRIVATE_TOKENS(_makeSomeStuffTokens, (sideLength)(myTriangle)); +} + +class _PointsFromSideLengthDataSource : public HdVec3fArrayDataSource +{ +public: + HD_DECLARE_DATASOURCE(_PointsFromSideLengthDataSource); + + bool GetContributingSampleTimesForInterval( + Time startTime, + Time endTime, + std::vector