Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hdUsdWriter plugin - Render to text delegate #3003

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pxr/usdImaging/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(DIRS
usdrecord
usdview
testusdview
hdcapture
)

foreach(d ${DIRS})
Expand Down
4 changes: 4 additions & 0 deletions pxr/usdImaging/bin/hdcapture/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(PXR_PREFIX pxr/usdImaging)
set(PXR_PACKAGE HdUsdWriter)

pxr_python_bin(hdcapture)
44 changes: 44 additions & 0 deletions pxr/usdImaging/bin/hdcapture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Usage

```hdcapture.py``` has three required arguments:

```--input``` The input USD file to render to text.

```--output``` The filename to write the serialized USD to. Output format is USDA.

```--baseline``` The .usda file to diff the output with.

## Output

This tool will record information it receives from Hydra and dump it to a .usda file. This allows inspection of what Hydra "sees" after data is fed through SceneDelegate/RenderIndex or DataSource/SceneIndex. It ouputs a format like this:

```
#usda 1.0

def "Example"
{
def "Geometry"
{
def Mesh "mesh_1" (
prepend apiSchemas = ["MaterialBindingAPI"]
)
{
custom uniform bool displayStyle:displacementEnabled = 1
custom uniform bool displayStyle:flatShadingEnabled = 0
custom uniform int displayStyle:refineLevel = 0
uniform bool doubleSided = 0
...
}
def Mesh "mesh_2" (
prepend apiSchemas = ["MaterialBindingAPI"]
)
{

token faceVaryingLinearInterpolation = "cornersPlus1"
int[] faceVertexCounts = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
...
}
}
}

```
49 changes: 49 additions & 0 deletions pxr/usdImaging/bin/hdcapture/hdcapture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/pxrpythonsubst
#
# Copyright (c) 2022-2024, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "Apache License")
# with the following modification; you may not use this file except in
# compliance with the Apache License and the following modification to it:
# Section 6. Trademarks. is deleted and replaced with:
#
# 6. Trademarks. This License does not grant permission to use the trade
# names, trademarks, service marks, or product names of the Licensor
# and its affiliates, except as required to comply with Section 4(c) of
# the License and to reproduce the content of the NOTICE file.
#
# You may obtain a copy of the Apache License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Apache License with the above modification is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the Apache License for the specific
# language governing permissions and limitations under the Apache License.
#

import argparse

from pxr.HdUsdWriter import hdusdwriterdriver

parser = argparse.ArgumentParser(
prog='HdUsdWriterRendererDriver',
description="""This tool will record information it receives from Hydra and dump it to a .usda file.
This allows inspection of what Hydra "sees" after data is fed through SceneDelegate/RenderIndex or DataSource/SceneIndex.""")

parser.add_argument('-b', '--baseline', required=False, help='The .usda file to diff the output with.')
parser.add_argument('-i', '--input', required=True, help='The input USD file to render to text.')
parser.add_argument('-o', '--output', required=True, help='The filename to write the serialized USD to. Output format with the default delegate is USDA.')

args = parser.parse_args()

driver = hdusdwriterdriver.HdUsdWriterRendererDriver()
driver.load_stage(args.input)
driver.use_usd_imaging_engine()
driver.use_usda_writer_renderer_plugin()

if (args.baseline):
driver.render_and_compare(args.baseline, args.output)
else:
driver.render(args.output)
3 changes: 2 additions & 1 deletion pxr/usdImaging/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(usdShaders)
add_subdirectory(sdrGlslfx)
add_subdirectory(sdrGlslfx)
add_subdirectory(hdUsdWriter)
91 changes: 91 additions & 0 deletions pxr/usdImaging/plugin/hdUsdWriter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
set(PXR_PREFIX pxr/usdImaging)
set(PXR_PACKAGE HdUsdWriter)
set(optionalPublicClasses "")

pxr_plugin(HdUsdWriter
DISABLE_PRECOMPILED_HEADERS

LIBRARIES
hd
usdImaging
usdLux
usdShade
usdSkel
usdVol
usdVolImaging

PUBLIC_CLASSES
camera
curves
instancer
light
material
mesh
openvdbasset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had some questions internally about whether we need to guard openvdbasset if we don't compile against openvdb; not sure if you know offhand. My memory is the only place we actually invoke OpenVDB is in the render delegate, which makes me think this is ok.

points
renderPass
renderDelegate
rendererPlugin
volume

PUBLIC_HEADERS
api.h
pointBased.h
rprim.h
utils.h

PYMODULE_FILES
fuzzytextdiff.py
hdusdwriterdriver.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had requests even before this has landed to (1) move this to pxr/usdImaging/usdAppUtils; and (2) rewrite it in C++ :). Are you all up for doing that? It's not a ton of code. It would probably mean you'd need to get rid of the fuzzytextdiff reference from the driver, and move fuzzytextdiff and the compare() function to pxr/usdImaging/bin/hdcapture directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made these changes.


RESOURCE_FILES
plugInfo.json

DOXYGEN_FILES
overview.dox
)

pxr_install_test_dir(
SRC testenv/testUsdWriterBaseline
DEST testUsdWriterBaseline
)

pxr_install_test_dir(
SRC testenv/testUsdWriterProtoInstancing
DEST testUsdWriterProtoInstancing
)

pxr_install_test_dir(
SRC testenv/testUsdWriterMaterialAssignToInstanced
DEST testUsdWriterMaterialAssignToInstanced
)

pxr_test_scripts(
testenv/testUsdWriterBaseline.py
)

pxr_test_scripts(
testenv/testUsdWriterProtoInstancing.py
)

pxr_test_scripts(
testenv/testUsdWriterMaterialAssignToInstanced.py
)

pxr_register_test(testUsdWriterBaseline
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdWriterBaseline"
EXPECTED_RETURN_CODE 0
)

pxr_register_test(testUsdWriterProtoInstancing
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdWriterProtoInstancing"
EXPECTED_RETURN_CODE 0
)

pxr_register_test(testUsdWriterMaterialAssignToInstanced
PYTHON
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdWriterMaterialAssignToInstanced"
EXPECTED_RETURN_CODE 0
)
47 changes: 47 additions & 0 deletions pxr/usdImaging/plugin/hdUsdWriter/api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Copyright (c) 2022-2024, NVIDIA CORPORATION.
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_IMAGING_HD_USD_WRITER_API_H
#define PXR_USD_IMAGING_HD_USD_WRITER_API_H

#include "pxr/base/arch/export.h"

#if defined(PXR_STATIC)
# define HDUSDWRITER_API
# define HDUSDWRITER_API_TEMPLATE_CLASS(...)
# define HDUSDWRITER_API_TEMPLATE_STRUCT(...)
# define HDUSDWRITER_LOCAL
#else
# if defined(HDUSDWRITER_EXPORTS)
# define HDUSDWRITER_API ARCH_EXPORT
# define HDUSDWRITER_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
# define HDUSDWRITER_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
# else
# define HDUSDWRITER_API ARCH_IMPORT
# define HDUSDWRITER_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
# define HDUSDWRITER_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
# endif
# define HDUSDWRITER_LOCAL ARCH_HIDDEN
#endif

#endif