-
Notifications
You must be signed in to change notification settings - Fork 14
HYDRA-2383 : Add unit test for HdArnold custom nodes #462
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
Merged
lilike-adsk
merged 3 commits into
dev
from
yoonb1/HYDRA-2383/add-hdarnold-custom-nodes-test
Jul 9, 2026
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
204 changes: 204 additions & 0 deletions
204
test/lib/mayaUsd/render/mayaToHydra/cpp/testArnoldCustomNodes.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| // Copyright 2026 Autodesk | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // C++ GTest suite for the HdArnoldMtoaSceneIndexPlugin (mtoaSIP). | ||
| // | ||
| // Tests must run with the Arnold renderer active so that mtoaSIP is inserted | ||
| // into the scene index chain. The Python driver (testArnoldCustomNodes.py) sets the | ||
| // Arnold renderer and creates the required scene nodes. | ||
| // | ||
| // Custom node translation: | ||
| // aiPhotometricLight -> sphereLight (verifyPrimType, attrs) | ||
| // aiStandIn -> ArnoldProcedural (verifyPrimType, dso -> arnold:filename) | ||
| // aiVolume -> ArnoldVolume (verifyPrimType, filename -> arnold:filename) | ||
| // | ||
| // NOTE: aiSkyDomeLight and aiAreaLight are NOT tested via the mayaCustomDagNode | ||
| // path because they have existing maya-hydra adapters (aiSkydomeLightAdapter / | ||
| // aiAreaLightAdapter) that produce domeLight / rectLight prims directly, so | ||
| // mtoaSIP's custom node dispatch never sees them. | ||
| // | ||
|
|
||
| #include "testUtils.h" | ||
|
|
||
| #include <mayaHydraLib/adapters/tokens.h> | ||
|
|
||
| #include <pxr/base/gf/vec3f.h> | ||
| #include <pxr/base/tf/token.h> | ||
| #include <pxr/base/vt/value.h> | ||
| #include <pxr/imaging/hd/dataSource.h> | ||
| #include <pxr/imaging/hd/primvarsSchema.h> | ||
| #include <pxr/imaging/hd/tokens.h> | ||
| #include <pxr/usd/sdf/assetPath.h> | ||
| #include <pxr/usd/usdLux/tokens.h> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| PXR_NAMESPACE_USING_DIRECTIVE | ||
| using namespace MayaHydra; | ||
|
|
||
| namespace { | ||
|
|
||
| // Convenience: read a float from a sampled data source, accepting both float | ||
| // and double storage (MtoA stores many attrs as double). | ||
| float GetFloatValue(const HdSampledDataSourceHandle& ds, float fallback = 0.0f) | ||
| { | ||
| if (!ds) | ||
| return fallback; | ||
| const VtValue v = ds->GetValue(0.0f); | ||
| if (v.IsHolding<float>()) | ||
| return v.UncheckedGet<float>(); | ||
| if (v.IsHolding<double>()) | ||
| return static_cast<float>(v.UncheckedGet<double>()); | ||
| return fallback; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| // What: mtoaSIP re-types aiPhotometricLight to sphereLight and maps attributes. | ||
| // How: Python creates aiPhotometricLight (intensity=2.5, aiExposure=3.0, | ||
| // aiFilename="/path/to/test.ies", aiSamples=5) with Arnold renderer active. | ||
| // Expect: prim type = sphereLight; inputs:intensity, inputs:exposure, | ||
| // inputs:shaping:ies:file are set; arnold:samples primvar exists (catch-all). | ||
| TEST(MtoaSIP, photometricLightTranslation) | ||
| { | ||
| auto [argc, argv] = getTestingArgs(); | ||
| ASSERT_GE(argc, 1); | ||
| const std::string shapeFull(argv[0]); | ||
| const std::string shapeNamePart = GetShapeNameFromFullPath(shapeFull); | ||
|
|
||
| const SceneIndicesVector& sceneIndices = GetTerminalSceneIndices(); | ||
| ASSERT_GT(sceneIndices.size(), 0u); | ||
|
|
||
| HdSceneIndexBaseRefPtr si = FindTerminalSceneIndexWithPrim( | ||
| sceneIndices, shapeNamePart, HdPrimTypeTokens->sphereLight); | ||
| ASSERT_TRUE(si) << "sphereLight prim for '" << shapeNamePart | ||
| << "' not found in any scene index"; | ||
|
|
||
| SceneIndexInspector inspector(si); | ||
| PrimEntriesVector found | ||
| = inspector.FindPrims(CreatePrimPredicate(shapeNamePart, HdPrimTypeTokens->sphereLight), 1); | ||
| ASSERT_GE(found.size(), 1u); | ||
|
|
||
| const HdSceneIndexPrim& prim = found.front().prim; | ||
| ASSERT_EQ(prim.primType, HdPrimTypeTokens->sphereLight); | ||
| ASSERT_NE(prim.dataSource, nullptr); | ||
|
|
||
| // Check inputs:intensity = 2.5 | ||
| auto intensityDs = HdTypedSampledDataSource<float>::Cast( | ||
| prim.dataSource->Get(UsdLuxTokens->inputsIntensity)); | ||
| ASSERT_TRUE(intensityDs) << "inputs:intensity not found on sphereLight"; | ||
| EXPECT_NEAR(GetFloatValue(intensityDs), 2.5f, 1e-5f); | ||
|
|
||
| // aiExposure = 3.0 -> inputs:exposure | ||
| auto exposureDs | ||
| = HdTypedSampledDataSource<float>::Cast(prim.dataSource->Get(UsdLuxTokens->inputsExposure)); | ||
| ASSERT_TRUE(exposureDs) << "inputs:exposure not found on sphereLight"; | ||
| EXPECT_NEAR(GetFloatValue(exposureDs), 3.0f, 1e-5f); | ||
|
|
||
|
benyoon-adsk marked this conversation as resolved.
|
||
| // aiFilename -> inputs:shaping:ies:file | ||
| auto iesDs = HdTypedSampledDataSource<SdfAssetPath>::Cast( | ||
| prim.dataSource->Get(UsdLuxTokens->inputsShapingIesFile)); | ||
| ASSERT_TRUE(iesDs) << "inputs:shaping:ies:file not found on sphereLight"; | ||
| EXPECT_EQ(iesDs->GetTypedValue(0.0f).GetAssetPath(), "/path/to/test.ies"); | ||
|
|
||
| // aiSamples = 5 -> arnold:samples primvar (catch-all ai* pass-through). | ||
| HdPrimvarsSchema primvarsSchema = HdPrimvarsSchema::GetFromParent(prim.dataSource); | ||
| HdPrimvarSchema samplesSchema = primvarsSchema.GetPrimvar(TfToken("arnold:samples")); | ||
| EXPECT_TRUE(samplesSchema) | ||
| << "arnold:samples primvar not found; aiSamples not forwarded by mtoaSIP"; | ||
| } | ||
|
|
||
| // What: mtoaSIP re-types aiStandIn to ArnoldProcedural and maps dso -> arnold:filename. | ||
| // How: Python creates aiStandIn (dso="/path/to/test.ass") with Arnold renderer. | ||
| // Expect: prim type = ArnoldProcedural; arnold:filename = "/path/to/test.ass". | ||
| TEST(MtoaSIP, standInTranslation) | ||
| { | ||
| auto [argc, argv] = getTestingArgs(); | ||
| ASSERT_GE(argc, 1); | ||
| const std::string shapeFull(argv[0]); | ||
| const std::string shapeNamePart = GetShapeNameFromFullPath(shapeFull); | ||
|
|
||
| const SceneIndicesVector& sceneIndices = GetTerminalSceneIndices(); | ||
| ASSERT_GT(sceneIndices.size(), 0u); | ||
|
|
||
| static const TfToken kArnoldProcedural("ArnoldProcedural"); | ||
| static const TfToken kArnoldFilename("arnold:filename"); | ||
|
|
||
| HdSceneIndexBaseRefPtr si | ||
| = FindTerminalSceneIndexWithPrim(sceneIndices, shapeNamePart, kArnoldProcedural); | ||
| ASSERT_TRUE(si) << "ArnoldProcedural prim for '" << shapeNamePart | ||
| << "' not found in any scene index"; | ||
|
|
||
| SceneIndexInspector inspector(si); | ||
| PrimEntriesVector found | ||
| = inspector.FindPrims(CreatePrimPredicate(shapeNamePart, kArnoldProcedural), 1); | ||
| ASSERT_GE(found.size(), 1u); | ||
|
|
||
| const HdSceneIndexPrim& prim = found.front().prim; | ||
| ASSERT_EQ(prim.primType, kArnoldProcedural); | ||
| ASSERT_NE(prim.dataSource, nullptr); | ||
|
|
||
| // dso -> arnold:filename | ||
| auto filenameDs | ||
| = HdTypedSampledDataSource<std::string>::Cast(prim.dataSource->Get(kArnoldFilename)); | ||
| ASSERT_TRUE(filenameDs) << "arnold:filename not found on ArnoldProcedural"; | ||
| EXPECT_EQ(filenameDs->GetTypedValue(0.0f), "/path/to/test.ass"); | ||
| } | ||
|
|
||
| // What: mtoaSIP re-types aiVolume to ArnoldVolume and maps filename -> arnold:filename. | ||
| // How: Python creates aiVolume (filename="/path/to/test.vdb") with Arnold renderer. | ||
| // Expect: prim type = ArnoldVolume; arnold:filename = "/path/to/test.vdb". | ||
| TEST(MtoaSIP, volumeTranslation) | ||
| { | ||
| auto [argc, argv] = getTestingArgs(); | ||
| ASSERT_GE(argc, 1); | ||
| const std::string shapeFull(argv[0]); | ||
| const std::string shapeNamePart = GetShapeNameFromFullPath(shapeFull); | ||
|
|
||
| const SceneIndicesVector& sceneIndices = GetTerminalSceneIndices(); | ||
| ASSERT_GT(sceneIndices.size(), 0u); | ||
|
|
||
| static const TfToken kArnoldVolume("ArnoldVolume"); | ||
| static const TfToken kArnoldFilename("arnold:filename"); | ||
|
|
||
| HdSceneIndexBaseRefPtr si | ||
| = FindTerminalSceneIndexWithPrim(sceneIndices, shapeNamePart, kArnoldVolume); | ||
| ASSERT_TRUE(si) << "ArnoldVolume prim for '" << shapeNamePart | ||
| << "' not found in any scene index"; | ||
|
|
||
| SceneIndexInspector inspector(si); | ||
| PrimEntriesVector found | ||
| = inspector.FindPrims(CreatePrimPredicate(shapeNamePart, kArnoldVolume), 1); | ||
| ASSERT_GE(found.size(), 1u); | ||
|
|
||
| const HdSceneIndexPrim& prim = found.front().prim; | ||
| ASSERT_EQ(prim.primType, kArnoldVolume); | ||
| ASSERT_NE(prim.dataSource, nullptr); | ||
|
|
||
| // filename (aiVolume Maya attr) -> arnold:filename | ||
| // _TranslateVolume prefixes ALL mayaAttributes keys with "arnold:". | ||
| // The value is stored via _VtValueDataSource, so use the base HdSampledDataSource. | ||
| auto filenameBase = prim.dataSource->Get(kArnoldFilename); | ||
| ASSERT_TRUE(filenameBase) << "arnold:filename not found on ArnoldVolume — " | ||
| "all-attrs-as-arnold:* pattern not applied by mtoaSIP"; | ||
|
|
||
| // The value is stored via _VtValueDataSource, so use the base HdSampledDataSource. | ||
| auto filenameDs = HdSampledDataSource::Cast(filenameBase); | ||
| ASSERT_TRUE(filenameDs) << "arnold:filename is not a sampled data source"; | ||
| const VtValue filenameVal = filenameDs->GetValue(0.0f); | ||
| ASSERT_TRUE(filenameVal.IsHolding<std::string>()) << "arnold:filename value is not a string"; | ||
| EXPECT_EQ(filenameVal.UncheckedGet<std::string>(), "/path/to/test.vdb"); | ||
| } | ||
128 changes: 128 additions & 0 deletions
128
test/lib/mayaUsd/render/mayaToHydra/cpp/testArnoldCustomNodes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # Copyright 2026 Autodesk | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| # Python test for the custom node translation functionality of the | ||
| # HdArnoldMtoaSceneIndexPlugin (mtoaSIP). | ||
| # | ||
| # Custom node translation: mayaCustomDagNode prims emitted by maya-hydra for | ||
| # Arnold plugin nodes are re-typed and have their attributes mapped to | ||
| # renderer-specific Hydra schemas. | ||
| # Tested: aiPhotometricLight -> sphereLight | ||
| # aiStandIn -> ArnoldProcedural | ||
| # aiVolume -> ArnoldVolume | ||
| # NOT tested here (have existing maya-hydra adapters that bypass mayaCustomDagNode): | ||
| # aiSkyDomeLight, aiAreaLight | ||
| # | ||
| import maya.cmds as cmds | ||
| import fixturesUtils | ||
| import mtohUtils | ||
| from testUtils import PluginLoaded | ||
|
|
||
| HD_ARNOLD = "HdArnoldRendererPlugin" | ||
| HD_ARNOLD_OVERRIDE = "mayaHydraRenderOverride_" + HD_ARNOLD | ||
|
|
||
|
|
||
| class TestArnoldCustomNodes(mtohUtils.MayaHydraBaseTestCase): | ||
| _file = __file__ | ||
| _requiredPlugins = ['mtoa'] | ||
| _setHdStormRenderer = False # Need to use Arnold renderer for the tests | ||
|
|
||
| def tearDown(self): | ||
| """Test will hang if Arnold renderer is not reset before Maya exits.""" | ||
| self.setViewport2Renderer() | ||
|
|
||
| def _setArnoldRenderer(self): | ||
| """Activate the Arnold Hydra renderer so mtoaSIP is in the scene index chain.""" | ||
| self.activeEditor = cmds.playblast(activeEditor=1) | ||
| cmds.modelEditor( | ||
| self.activeEditor, e=1, | ||
| rendererOverrideName=HD_ARNOLD_OVERRIDE) | ||
| cmds.refresh(f=1) | ||
| activeOverride = cmds.modelEditor( | ||
| self.activeEditor, q=1, rendererOverrideName=True) | ||
| self.assertEqual( | ||
| activeOverride, | ||
| HD_ARNOLD_OVERRIDE, | ||
| "Arnold Hydra renderer override not available. " | ||
| "Ensure HdArnoldRendererPlugin is on PXR_PLUGINPATH_NAME.") | ||
|
|
||
| def _setupPhotometricLight(self): | ||
| with PluginLoaded('mtoa'): | ||
| xform = cmds.createNode('transform', name='photometric1') | ||
| shape = cmds.createNode( | ||
| 'aiPhotometricLight', | ||
| name='photometricShape1', | ||
| parent=xform, | ||
| ) | ||
| self._photometricShape = cmds.ls(shape, long=True)[0] | ||
| cmds.setAttr(self._photometricShape + ".intensity", 2.5) | ||
| cmds.setAttr(self._photometricShape + ".aiExposure", 3.0) | ||
| cmds.setAttr(self._photometricShape + ".aiFilename", | ||
| "/path/to/test.ies", type="string") | ||
| cmds.setAttr(self._photometricShape + ".aiSamples", 5) | ||
| cmds.refresh() | ||
|
|
||
| def _setupStandIn(self): | ||
| with PluginLoaded('mtoa'): | ||
| xform = cmds.createNode('transform', name='standIn1') | ||
| shape = cmds.createNode( | ||
| 'aiStandIn', | ||
| name='standInShape1', | ||
| parent=xform, | ||
| ) | ||
| self._standInShape = cmds.ls(shape, long=True)[0] | ||
| cmds.setAttr(self._standInShape + ".dso", | ||
| "/path/to/test.ass", type="string") | ||
| cmds.refresh() | ||
|
|
||
| def _setupVolume(self): | ||
| with PluginLoaded('mtoa'): | ||
| xform = cmds.createNode('transform', name='volume1') | ||
| shape = cmds.createNode( | ||
| 'aiVolume', | ||
| name='volumeShape1', | ||
| parent=xform, | ||
| ) | ||
| self._volumeShape = cmds.ls(shape, long=True)[0] | ||
| cmds.setAttr(self._volumeShape + ".filename", | ||
| "/path/to/test.vdb", type="string") | ||
| cmds.refresh() | ||
|
|
||
| def test_photometricLightTranslation(self): | ||
| self._setArnoldRenderer() | ||
| self._setupPhotometricLight() | ||
| with PluginLoaded('mayaHydraCppTests'): | ||
| cmds.mayaHydraCppTest( | ||
| self._photometricShape, | ||
| f="MtoaSIP.photometricLightTranslation") | ||
|
|
||
| def test_standInTranslation(self): | ||
| self._setArnoldRenderer() | ||
| self._setupStandIn() | ||
| with PluginLoaded('mayaHydraCppTests'): | ||
| cmds.mayaHydraCppTest( | ||
| self._standInShape, | ||
| f="MtoaSIP.standInTranslation") | ||
|
|
||
| def test_volumeTranslation(self): | ||
| self._setArnoldRenderer() | ||
| self._setupVolume() | ||
| with PluginLoaded('mayaHydraCppTests'): | ||
| cmds.mayaHydraCppTest( | ||
| self._volumeShape, | ||
| f="MtoaSIP.volumeTranslation") | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| fixturesUtils.runTests(globals()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a comment to say that mtoaSIP is scene index plugin, it's not obvious