Skip to content

Commit

Permalink
Revived visibility test. (#382)
Browse files Browse the repository at this point in the history
* Revived visibility test.

* Converted code review comment to code comment.

* Disable image comparison test for debugging purposes.

* Trace debugging 1

* Trace debugging 2

* Trace debugging 3

* Trace debugging 4

* Trace debugging 5

* Reinstate disabled tests.

* Clean up debugging and tracing code.
  • Loading branch information
ppt-adsk authored and GitHub Enterprise committed Apr 3, 2023
1 parent f1fa2d5 commit ba51190
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
3 changes: 3 additions & 0 deletions lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ class MayaHydraRenderItemAdapter : public MayaHydraAdapter
MAYAHYDRALIB_API
MGeometry::Primitive GetPrimitive() const { return _primitive; }

MAYAHYDRALIB_API
const char* Name() const { return _name.asChar(); }

private:
MAYAHYDRALIB_API
void _RemoveRprim();
Expand Down
5 changes: 5 additions & 0 deletions lib/mayaHydra/hydraExtensions/delegates/delegateCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

#include <maya/MFnLight.h>
#include <maya/MShaderManager.h>
#include <maya/MDagPath.h>
#include <maya/MFnDependencyNode.h>

#include <array>

Expand Down Expand Up @@ -56,6 +58,9 @@ SdfPath _GetRenderItemMayaPrimPath(const MRenderItem& ri)
mayaPath = mayaPath.MakeRelativePath(SdfPath::AbsoluteRootPath());
}

// Prepend Maya node name, for organisation and readability.
mayaPath = SdfPath(MFnDependencyNode(ri.sourceDagPath().node()).name().asChar()).AppendPath(mayaPath);

if (MHWRender::MGeometry::Primitive::kLines != ri.primitive()
&& MHWRender::MGeometry::Primitive::kLineStrip != ri.primitive()
&& MHWRender::MGeometry::Primitive::kPoints != ri.primitive()) {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(TEST_SCRIPT_FILES
# Fail as of 22-Feb-2023. Entered as MAYA-127898.
# testMtohBasicRender.py
# testMtohDagChanges.py
# testMtohVisibility.py
testMtohVisibility.py
)

foreach(script ${TEST_SCRIPT_FILES})
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions test/lib/mayaUsd/render/mayaToHydra/testMtohVisibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def doHierarchicalVisibilityTest(self, makeNodeVis, makeNodeInvis, prep=None):
cmds.select(clear=1)
cmds.refresh()

self.cubeRprim = self.rprimPath(self.cubeShape)
# Hierarchy changes (like grouping above) cause the render index to be
# rebuilt, so re-read our cubeRprim from the render index.
self.cubeRprim = self.getIndex()[0]
visIndex = [self.cubeRprim]
self.assertEqual(self.getVisibleIndex(), visIndex)

Expand Down Expand Up @@ -154,6 +156,5 @@ def prep(obj):

self.doHierarchicalVisibilityTest(makeNodeVis, makeNodeInvis, prep=prep)


if __name__ == '__main__':
fixturesUtils.runTests(globals())
36 changes: 24 additions & 12 deletions test/testUtils/mtohUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import testUtils
from imageUtils import ImageDiffingTestCase

import sys

HD_STORM = "HdStormRendererPlugin"
HD_STORM_OVERRIDE = "mayaHydraRenderOverride_" + HD_STORM

Expand Down Expand Up @@ -67,8 +69,15 @@ def makeCubeScene(self, camDist=DEFAULT_CAM_DIST):
self.cubeTrans = cmds.polyCube()[0]
self.cubeShape = cmds.listRelatives(self.cubeTrans)[0]
self.setHdStormRenderer()
self.cubeRprim = self.rprimPath(self.cubeShape)
self.assertInIndex(self.cubeRprim)
self.assertNodeNameInIndex(self.cubeShape)
# The single Maya cube shape maps to two rprims, the first once of
# which is the shape's StandardShadedItem. The list is ordered, as the
# Hydra call made is HdRenderIndex::GetRprimIds(), which sorts
# according to std::less<SdfPath>, which will produce
# lexicographically-ordered paths.
self.cubeRprim = self.getIndex()[0]
cmds.select(clear=1)
cmds.refresh()
self.assertVisible(self.cubeRprim)
self.setBasicCam(dist=camDist)
cmds.select(clear=True)
Expand All @@ -80,16 +89,6 @@ def makeCubeScene(self, camDist=DEFAULT_CAM_DIST):
cmds.setAttr("standardSurface1.baseColor", type='float3', *color)
cmds.setAttr("standardSurface1.specularRoughness", 0.4)

def rprimPath(self, fullPath):
if not fullPath.startswith('|'):
nodes = cmds.ls(fullPath, long=1)
if len(nodes) != 1:
raise RuntimeError("given fullPath {!r} mapped to {} nodes"
.format(fullPath, len(nodes)))
fullPath = nodes[0]
return '/'.join([self.delegateId, "rprims",
fullPath.lstrip('|').replace('|', '/')])

def getIndex(self, **kwargs):
return cmds.mayaHydra(renderer=HD_STORM, listRenderIndex=True, **kwargs)

Expand All @@ -102,3 +101,16 @@ def assertVisible(self, rprim):

def assertInIndex(self, rprim):
self.assertIn(rprim, self.getIndex())

def assertNodeNameInIndex(self, nodeName):
for rprim in self.getIndex():
if nodeName in rprim:
return True
return False

def trace(self, msg):
sys.__stdout__.write(msg)
sys.__stdout__.flush()

def traceIndex(self, msg):
self.trace(msg.format(str(self.getIndex())))

0 comments on commit ba51190

Please sign in to comment.