-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HYDRA-764 : Add prim instancing unit test (#33)
* HYDRA-764 : Create minimalized version of ALab workbench scene * HYDRA-764 : Further simplify the USD scene * HYDRA-764 : Convert geometry usdc file to usda and remove some meshes * HYDRA-764 : Replace workbench with simple cube * HYDRA-764 : Have just the root Xform reference the cube in the scene file * HYDRA-674 : Rename Xform and mesh in cube.usda * HYDRA-764 : First working test * HYDRA-764 : Extract USD stage load from file logic into utils * HYDRA-764 : Add extra checks in scene hierarchy * HYDRA-764 : Comment scene file * HYDRA-764 : Cleanup unused imports and includes * HYDRA-764 : Rename root prim * HYDRA-764 : Move usdUtils import inside a function called after MayaUSD is loaded * HYDRA-764 : Remove incorrect comment in usda scene file * HYDRA-764 : Rename scene file
- Loading branch information
1 parent
6dbf905
commit dd5cf14
Showing
7 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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
68 changes: 68 additions & 0 deletions
68
test/lib/mayaUsd/render/mayaToHydra/cpp/testPrimInstancing.cpp
This file contains 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,68 @@ | ||
// Copyright 2023 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. | ||
// | ||
|
||
#include "testUtils.h" | ||
|
||
#include <pxr/imaging/hd/tokens.h> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
|
||
namespace { | ||
FindPrimPredicate findInstanceableCubePredicate = PrimNamePredicate("instanceableCube"); | ||
HdDataSourceLocator instancerLocator = HdDataSourceLocator(TfToken("instance"), TfToken("instancer")); | ||
} // namespace | ||
|
||
TEST(PrimInstancing, testUsdPrimInstancing) | ||
{ | ||
// Get the terminal scene index | ||
const auto& sceneIndices = GetTerminalSceneIndices(); | ||
ASSERT_GT(sceneIndices.size(), 0u); | ||
SceneIndexInspector inspector(sceneIndices.front()); | ||
|
||
// Find the instanceable cube prim | ||
PrimEntriesVector instanceableCubePrims = inspector.FindPrims(findInstanceableCubePredicate); | ||
ASSERT_EQ(instanceableCubePrims.size(), 1u); | ||
HdSceneIndexPrim instanceableCubePrim = instanceableCubePrims.front().prim; | ||
|
||
// Retrieve the instancer data source | ||
auto instancerDataSource = HdTypedSampledDataSource<SdfPath>::Cast( | ||
HdContainerDataSource::Get(instanceableCubePrim.dataSource, instancerLocator)); | ||
ASSERT_TRUE(instancerDataSource); | ||
|
||
// Ensure the instancer prim exists and is populated | ||
SdfPath instancerPath = instancerDataSource->GetTypedValue(0); | ||
auto findInstancerPredicate | ||
= [instancerPath](const HdSceneIndexBasePtr& sceneIndex, const SdfPath& primPath) -> bool { | ||
return primPath == instancerPath; | ||
}; | ||
PrimEntriesVector instancerPrims = inspector.FindPrims(findInstancerPredicate); | ||
ASSERT_EQ(instancerPrims.size(), 1u); | ||
HdSceneIndexPrim instancerPrim = instancerPrims.front().prim; | ||
ASSERT_EQ(instancerPrim.primType, HdPrimTypeTokens->instancer); | ||
ASSERT_NE(instancerPrim.dataSource, nullptr); | ||
|
||
// Ensure the reference cube prim exists and is populated | ||
auto findCubePredicate | ||
= [instancerPath](const HdSceneIndexBasePtr& sceneIndex, const SdfPath& primPath) -> bool { | ||
return primPath.HasPrefix(instancerPath) && primPath.GetName() == "cubeMesh"; | ||
}; | ||
PrimEntriesVector cubePrims = inspector.FindPrims(findCubePredicate); | ||
ASSERT_EQ(cubePrims.size(), 1u); | ||
HdSceneIndexPrim cubePrim = cubePrims.front().prim; | ||
ASSERT_EQ(cubePrim.primType, HdPrimTypeTokens->mesh); | ||
ASSERT_NE(cubePrim.dataSource, nullptr); | ||
} |
42 changes: 42 additions & 0 deletions
42
test/lib/mayaUsd/render/mayaToHydra/cpp/testPrimInstancing.py
This file contains 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,42 @@ | ||
# Copyright 2023 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. | ||
# | ||
import maya.cmds as cmds | ||
|
||
import fixturesUtils | ||
import mtohUtils | ||
import unittest | ||
|
||
import testUtils | ||
from testUtils import PluginLoaded | ||
|
||
class TestPrimInstancing(mtohUtils.MayaHydraBaseTestCase): | ||
# MayaHydraBaseTestCase.setUpClass requirement. | ||
_file = __file__ | ||
|
||
def loadUsdScene(self): | ||
import usdUtils | ||
usdScenePath = testUtils.getTestScene('testPrimInstancing', 'instanceableCube.usda') | ||
usdUtils.createStageFromFile(usdScenePath) | ||
self.setHdStormRenderer() | ||
cmds.refresh() | ||
|
||
@unittest.skipUnless(mtohUtils.checkForMayaUsdPlugin(), "Requires Maya USD Plugin.") | ||
def test_UsdPrimInstancing(self): | ||
self.loadUsdScene() | ||
with PluginLoaded('mayaHydraCppTests'): | ||
cmds.mayaHydraCppTest(f="PrimInstancing.testUsdPrimInstancing") | ||
|
||
if __name__ == '__main__': | ||
fixturesUtils.runTests(globals()) |
This file contains 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,14 @@ | ||
#usda 1.0 | ||
( | ||
defaultPrim = "cube" | ||
) | ||
|
||
def Xform "cube" | ||
{ | ||
def Mesh "cubeMesh" | ||
{ | ||
int[] faceVertexCounts = [4, 4, 4, 4, 4, 4] | ||
int[] faceVertexIndices = [0, 1, 3, 2, 2, 3, 5, 4, 4, 5, 7, 6, 6, 7, 1, 0, 1, 7, 5, 3, 6, 0, 2, 4] | ||
point3f[] points = [(-0.5, -0.5, 0.5), (0.5, -0.5, 0.5), (-0.5, 0.5, 0.5), (0.5, 0.5, 0.5), (-0.5, 0.5, -0.5), (0.5, 0.5, -0.5), (-0.5, -0.5, -0.5), (0.5, -0.5, -0.5)] | ||
} | ||
} |
This file contains 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,11 @@ | ||
#usda 1.0 | ||
( | ||
defaultPrim = "instanceableCube" | ||
) | ||
|
||
def Xform "instanceableCube" ( | ||
instanceable = true | ||
prepend references = @cube.usda@ | ||
) | ||
{ | ||
} |
This file contains 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