Skip to content

Commit

Permalink
handle for Maya w and w/o API
Browse files Browse the repository at this point in the history
  • Loading branch information
lilike-adsk committed Nov 25, 2024
1 parent 55f3e43 commit 2ee4f26
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 6 deletions.
10 changes: 10 additions & 0 deletions cmake/modules/FindMaya.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# MAYA_HAS_DISPLAY_LAYER_API Presence of MFnDisplayLayer
# MAYA_HAS_NEW_DISPLAY_LAYER_MESSAGING_API Presence of MDisplayLayerMemberChangedFunction
# MAYA_HAS_RENDER_ITEM_HIDE_ON_PLAYBACK_API Presence of MRenderItem has HideOnPlayback API
# MAYA_HAS_RENDER_ITEM_CULL_MODE_API Presence of MRenderItem has CullMode API
# MAYA_HAS_VIEW_SELECTED_OBJECT_API Presence of M3dView::viewSelectedObject
# MAYA_LINUX_BUILT_WITH_CXX11_ABI Maya Linux was built with new cxx11 ABI.
# MAYA_MACOSX_BUILT_WITH_UB2 Maya OSX was built with Universal Binary 2.
Expand Down Expand Up @@ -404,6 +405,15 @@ if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h")
endif()
endif()

set(MAYA_HAS_RENDER_ITEM_CULL_MODE_API FALSE CACHE INTERNAL "hasRenderItemCullModeFunction")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h MAYA_HAS_API REGEX "cullMode")
if(MAYA_HAS_API)
set(MAYA_HAS_RENDER_ITEM_CULL_MODE_API TRUE CACHE INTERNAL "hasRenderItemCullModeFunction")
message(STATUS "MRenderItem has CullMode API")
endif()
endif()

set(MAYA_HAS_VIEW_SELECTED_OBJECT_API FALSE CACHE INTERNAL "hasViewSelectedObject")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/M3dView.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/M3dView.h MAYA_HAS_API REGEX "numViewSelectedObjects")
Expand Down
7 changes: 7 additions & 0 deletions lib/mayaHydra/hydraExtensions/adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ set(HEADERS
tokens.h
)

if (MAYA_HAS_RENDER_ITEM_CULL_MODE_API)
target_compile_definitions(${TARGET_NAME}
PRIVATE
MAYA_HAS_RENDER_ITEM_CULL_MODE_API=1
)
endif()

# -----------------------------------------------------------------------------
# promoted headers
# -----------------------------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ MayaHydraRenderItemAdapter::MayaHydraRenderItemAdapter(
, _primitive(ri.primitive())
, _name(ri.name())
, _fastId(fastId)
#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
, _cullMode(ri.cullMode())
#endif
{
_InsertRprim(this);
}
Expand Down Expand Up @@ -146,6 +148,7 @@ void MayaHydraRenderItemAdapter::UpdateFromDelta(const UpdateFromDeltaData& data

HdDirtyBits dirtyBits = 0;

#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
MRenderItem::CullMode cullMode = data._ri.cullMode();
if (cullMode != _cullMode) {
// MRenderItem uses CullNone to denote doubleSided
Expand All @@ -155,6 +158,7 @@ void MayaHydraRenderItemAdapter::UpdateFromDelta(const UpdateFromDeltaData& data
dirtyBits |= HdChangeTracker::DirtyCullStyle;
_cullMode = cullMode;
}
#endif

if (data._wireframeColor != _wireframeColor) {
_wireframeColor = data._wireframeColor;
Expand Down Expand Up @@ -559,13 +563,16 @@ HdCullStyle MayaHydraRenderItemAdapter::GetCullStyle() const
if (_isArnoldSkyDomeLightTriangleShape) {
return HdCullStyleFront;
}

#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
switch (_cullMode) {
case MRenderItem::CullNone: return HdCullStyleNothing;
case MRenderItem::CullFront: return HdCullStyleFront;
case MRenderItem::CullBack: return HdCullStyleBack;
default: return HdCullStyleNothing;
}
#else
return HdCullStyleNothing;
#endif
}

///////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 11 additions & 1 deletion lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ static constexpr const char* kPointSize = "pointSize";

static const SdfPath kInvalidMaterial = SdfPath("InvalidMaterial");

#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
// Extract doubleSided attribute from CullMode as MRenderItem uses CullNone to denote doubleSided.
static bool IsDoubleSided(MRenderItem::CullMode cullMode) { return cullMode == MRenderItem::CullNone; }
#endif
} // namespace

using MayaHydraRenderItemAdapterPtr = std::shared_ptr<class MayaHydraRenderItemAdapter>;
Expand Down Expand Up @@ -84,7 +86,13 @@ class MayaHydraRenderItemAdapter : public MayaHydraAdapter
virtual bool IsSupported() const override;

MAYAHYDRALIB_API
bool GetDoubleSided() const override { return IsDoubleSided(_cullMode); };
bool GetDoubleSided() const override {
#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
return IsDoubleSided(_cullMode);
#else
return false;
#endif
};

MAYAHYDRALIB_API
GfBBox3d GetBoundingBox()const override { return _bounds; }
Expand Down Expand Up @@ -212,7 +220,9 @@ class MayaHydraRenderItemAdapter : public MayaHydraAdapter
bool _isHideOnPlayback = false;
bool _isArnoldSkyDomeLightTriangleShape = false;
GfBBox3d _bounds;//Bounding box
#ifdef MAYA_HAS_RENDER_ITEM_CULL_MODE_API
MRenderItem::CullMode _cullMode = MRenderItem::CullNone;
#endif
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
4 changes: 4 additions & 0 deletions test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ foreach(script ${INTERACTIVE_TEST_SCRIPT_FILES_DISABLE_VP2_RENDER_DELEGATE})
"LD_PRELOAD=${ADDITIONAL_LD_PRELOAD}"

"MAYAUSD_DISABLE_VP2_RENDER_DELEGATE=1"

"MAYA_HAS_RENDER_ITEM_CULL_MODE_API=${MAYA_HAS_RENDER_ITEM_CULL_MODE_API}"
)

# Assign a CTest label to these tests for easy filtering.
Expand Down Expand Up @@ -201,6 +203,8 @@ foreach(script ${INTERACTIVE_TEST_SCRIPT_FILES})

# Use standard surface as default for now
"MAYA_DEFAULT_SURFACE_SHADER=standardSurface"

"MAYA_HAS_RENDER_ITEM_CULL_MODE_API=${MAYA_HAS_RENDER_ITEM_CULL_MODE_API}"
)

# Add a ctest label to these tests for easy filtering.
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.
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.
15 changes: 11 additions & 4 deletions test/lib/mayaUsd/render/mayaToHydra/testPolygonPrimitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import mtohUtils

import platform
import os

class TestPolygonPrimitives(mtohUtils.MayaHydraBaseTestCase):
# MayaHydraBaseTestCase.setUpClass requirement.
Expand All @@ -25,10 +26,10 @@ class TestPolygonPrimitives(mtohUtils.MayaHydraBaseTestCase):
IMAGE_DIFF_FAIL_THRESHOLD = 0.05
IMAGE_DIFF_FAIL_PERCENT = 1.5

def compareSnapshot(self, referenceFilename, cameraDistance=15):
def compareSnapshot(self, referenceFilename, cameraDistance=15, imageVersion=None):
self.setBasicCam(cameraDistance)
cmds.refresh()
self.assertSnapshotClose(referenceFilename, self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT)
self.assertSnapshotClose(referenceFilename, self.IMAGE_DIFF_FAIL_THRESHOLD, self.IMAGE_DIFF_FAIL_PERCENT, imageVersion)

def setupScene(self, polygonCreationCallable):
self.setHdStormRenderer()
Expand Down Expand Up @@ -315,7 +316,10 @@ def test_PolygonSphericalHarmonics(self):
self.compareSnapshot("sphericalHarmonics_modified.png")

self.setupSuperShapeHelix(polyCreatorNodeName)
self.compareSnapshot("sphericalHarmonics_helix.png")
imageVersion = None
if(os.getenv('MAYA_HAS_RENDER_ITEM_CULL_MODE_API', 'NOT-FOUND') in ('1', 'TRUE')):
imageVersion = "RenderItemHasCullModeAPI"
self.compareSnapshot("sphericalHarmonics_helix.png", 15, imageVersion)

def test_PolygonUltra(self):
polyCreatorNodeName = self.setupScene(self.getSuperShapeCreationCallable("UltraShape"))
Expand Down Expand Up @@ -346,7 +350,10 @@ def test_PolygonUltra(self):
self.compareSnapshot("ultra_modified.png")

self.setupSuperShapeHelix(polyCreatorNodeName)
self.compareSnapshot("ultra_helix.png")
imageVersion = None
if(os.getenv('MAYA_HAS_RENDER_ITEM_CULL_MODE_API', 'NOT-FOUND') in ('1', 'TRUE')):
imageVersion = "RenderItemHasCullModeAPI"
self.compareSnapshot("ultra_helix.png", 15 , imageVersion)

if __name__ == '__main__':
fixturesUtils.runTests(globals())

0 comments on commit 2ee4f26

Please sign in to comment.