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

HYDRA-1328 : Make maya hydra compilable with maya 2024 devkit #237

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 0 additions & 93 deletions cmake/modules/FindMaya.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@
# MAYA_LIGHTAPI_VERSION Maya light API version (1 or 2 or 3)
#
# Cache variables:
# MAYA_HAS_DEFAULT_MATERIAL_API Presence of a default material API on MRenderItem.
# MAYA_NEW_POINT_SNAPPING_SUPPORT Presence of point new snapping support.
# MAYA_HAS_CRASH_DETECTION Presence of isInCrashHandler API
# MAYA_ENABLE_NEW_PRIM_DELETE Enable new delete behaviour for delete command
# MAYA_HAS_DISPLAY_STYLE_ALL_VIEWPORTS Presence of MFrameContext::getDisplayStyleOfAllViewports.
# MAYA_ARRAY_ITERATOR_DIFFERENCE_TYPE_SUPPORT Presence of maya array iterator difference_type trait
# MAYA_HAS_GET_MEMBER_PATHS Presence of MFnSet::getMemberPaths
# 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.
Expand Down Expand Up @@ -322,89 +312,6 @@ if (MAYA_OGSDEVICES_LIBRARY)
endif()
message(STATUS "Using Maya Light API Version ${MAYA_LIGHTAPI_VERSION}")

set(MAYA_HAS_DEFAULT_MATERIAL_API FALSE CACHE INTERNAL "setDefaultMaterialHandling")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h MAYA_HAS_API REGEX "setDefaultMaterialHandling")
if(MAYA_HAS_API)
set(MAYA_HAS_DEFAULT_MATERIAL_API TRUE CACHE INTERNAL "setDefaultMaterialHandling")
message(STATUS "Maya has setDefaultMaterialHandling API")
endif()
endif()

set(MAYA_NEW_POINT_SNAPPING_SUPPORT FALSE CACHE INTERNAL "snapToActive")
if (MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MSelectionContext.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MSelectionContext.h MAYA_HAS_API REGEX "snapToActive")
if(MAYA_HAS_API)
set(MAYA_NEW_POINT_SNAPPING_SUPPORT TRUE CACHE INTERNAL "snapToActive")
message(STATUS "Maya has new point snapping API")
endif()
endif()

set(MAYA_HAS_CRASH_DETECTION FALSE CACHE INTERNAL "isInCrashHandler")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MGlobal.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MGlobal.h MAYA_HAS_API REGEX "isInCrashHandler")
if(MAYA_HAS_API)
set(MAYA_HAS_CRASH_DETECTION TRUE CACHE INTERNAL "isInCrashHandler")
message(STATUS "Maya has isInCrashHandler API")
endif()
endif()

set(MAYA_ENABLE_NEW_PRIM_DELETE FALSE CACHE INTERNAL "enableNewPrimDelete")
if (MAYA_API_VERSION VERSION_GREATER_EQUAL 20230000)
set(MAYA_ENABLE_NEW_PRIM_DELETE TRUE CACHE INTERNAL "enableNewPrimDelete")
endif()

set(MAYA_HAS_DISPLAY_STYLE_ALL_VIEWPORTS FALSE CACHE INTERNAL "DisplayStyleOfAllViewports")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MFrameContext.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MFrameContext.h MAYA_HAS_API REGEX "getDisplayStyleOfAllViewports")
if(MAYA_HAS_API)
set(MAYA_HAS_DISPLAY_STYLE_ALL_VIEWPORTS TRUE CACHE INTERNAL "DisplayStyleOfAllViewports")
message(STATUS "Maya has getDisplayStyleOfAllViewports API")
endif()
endif()

set(MAYA_ARRAY_ITERATOR_DIFFERENCE_TYPE_SUPPORT FALSE CACHE INTERNAL "hasArrayIteratorDifferenceType")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MArrayIteratorTemplate.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MArrayIteratorTemplate.h MAYA_HAS_API REGEX "difference_type")
if(MAYA_HAS_API)
set(MAYA_ARRAY_ITERATOR_DIFFERENCE_TYPE_SUPPORT TRUE CACHE INTERNAL "hasArrayIteratorDifferenceType")
message(STATUS "Maya array iterator has difference_type trait")
endif()
endif()

set(MAYA_HAS_GET_MEMBER_PATHS FALSE CACHE INTERNAL "hasGetMemberPaths")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MFnSet.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MFnSet.h MAYA_HAS_API REGEX "getMemberPaths")
if(MAYA_HAS_API)
set(MAYA_HAS_GET_MEMBER_PATHS TRUE CACHE INTERNAL "hasGetMemberPaths")
message(STATUS "MFnSet has getMemberPaths function")
endif()
endif()

set(MAYA_HAS_DISPLAY_LAYER_API FALSE CACHE INTERNAL "hasDisplayLayerAPI")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MFnDisplayLayer.h")
set(MAYA_HAS_DISPLAY_LAYER_API TRUE CACHE INTERNAL "hasDisplayLayerAPI")
message(STATUS "MFnDisplayLayer exists")
endif()

set(MAYA_HAS_NEW_DISPLAY_LAYER_MESSAGING_API FALSE CACHE INTERNAL "hasDisplayLayerMemberChangedFunction")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MDisplayLayerMessage.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MDisplayLayerMessage.h MAYA_HAS_API REGEX "MDisplayLayerMemberChangedFunction")
if(MAYA_HAS_API)
set(MAYA_HAS_NEW_DISPLAY_LAYER_MESSAGING_API TRUE CACHE INTERNAL "hasDisplayLayerMemberChangedFunction")
message(STATUS "MDisplayLayerMessage has MDisplayLayerMemberChangedFunction")
endif()
endif()

set(MAYA_HAS_RENDER_ITEM_HIDE_ON_PLAYBACK_API FALSE CACHE INTERNAL "hasRenderItemHideOnPlaybackFunction")
if(MAYA_INCLUDE_DIRS AND EXISTS "${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h")
file(STRINGS ${MAYA_INCLUDE_DIR}/maya/MHWGeometry.h MAYA_HAS_API REGEX "isHideOnPlayback")
if(MAYA_HAS_API)
set(MAYA_HAS_RENDER_ITEM_HIDE_ON_PLAYBACK_API TRUE CACHE INTERNAL "hasRenderItemHideOnPlaybackFunction")
message(STATUS "MRenderItem has HideOnPlayback API")
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")
Expand Down
3 changes: 3 additions & 0 deletions doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ Run the script with the ```--help``` parameter to see all the possible flags and

Unit tests can be run by setting ```--stages=test``` or by simply calling `ctest` directly from the build directory.

# Rebuilding with the latest version of OpenUSD and with a previous version of Maya
Please see [Rebuilding with the latest OpenUSD version and with a previous version of Maya](./rebuildingWithLatestOpenUSDAndPreviousMaya.md)

# Additional Build Instruction

##### Python:
Expand Down
206 changes: 206 additions & 0 deletions doc/rebuildingWithLatestOpenUSDAndPreviousMaya.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Building with the latest version of OpenUSD and with a previous version of Maya such as 2024

Let's take as an example rebuilding MayaHydra in <b>Maya 2024</b> and <b>OpenUSD 24.11</b> under Windows.<br>

Please be aware that <b>Maya 2024 is not officially supported </b>since we have added a few features to Maya API in newer versions of Maya.
What is known to be unsupported in Maya 2024 :
- The cull mode from Maya geometries.
- Isolate select will not function correctly.

With Maya 2024 the OpenUSD version used by default was 22.11 which was compiled with Python 3.10.8.

## Rebuilding OpenUSD

If OpenUSD was not built with the same version of Python as the one used in your Maya version, you need to rebuild it with the suitable Python :<br>

| Maya version | Python version |
|:-------------------------:|:----------------:|
| 2024 | 3.10.8 |
| 2025 | 3.11.4 |
| PR | 3.11.9 |

So for Maya 2024, we need to rebuild OpenUSD with Python 3.10.8.<br>
To do so, you need to clone the OpenUSD repository and checkout the version used by MayaUsd and MayaHydra which is [v24.11-MayaUsd-Public](https://github.com/autodesk-forks/USD/tree/v24.11-MayaUsd-Public).<br>
As an example here is a Windows batch file to rebuild OpenUSD with Python 3.10.8 which is provided by mayapy.exe in the Maya/bin folder:<br><br>
First, to rebuild both OpenUSD and MayaUsd, you may need to install the following Python modules for this version of Python: <br>
PyOpenGL==3.1.0, PySide6, jinja2 and pybind11.<br>
We are assuming that Maya 2024 is installed in its default folder such as C:\Program Files\Autodesk\Maya2024.<br>
```
"C:\Program Files\Autodesk\Maya2024\bin\mayapy.exe" -m pip install PyOpenGL==3.1.0
"C:\Program Files\Autodesk\Maya2024\bin\mayapy.exe" -m pip install PySide6
"C:\Program Files\Autodesk\Maya2024\bin\mayapy.exe" -m pip install jinja2
"C:\Program Files\Autodesk\Maya2024\bin\mayapy.exe" -m pip install pybind11
```
To rebuild OpenUSD see the following Windows batch file as an example :
<br>
```
rem rebuild OpenUSD with Python 3.10.8 for maya 2024

rem The following modules may need to be installed in mayapy.exe: PyOpenGL==3.1.0, PySide6 and pybind11.

set openusd_maya_location=C:/Program^ Files/Autodesk/Maya2024
set openusd_python_include=%openusd_maya_location%/include/Python310/Python
set openusd_python_exe=%openusd_maya_location%/bin/mayapy.exe
set openusd_python_lib=%openusd_maya_location%/lib/python310.lib

rem our destination folder for the build
set destination_folder="D:/USD-24.11-Python3.10.8"

rem rebuilding OpenUSD with Python 3.10.8 in release with debug info configuration, if you want to use release only, please change the build-variant
"%openusd_python_exe%" ".\build_scripts\build_usd.py" "%destination_folder%" ^
--build-variant=relwithdebuginfo ^
--build-python-info "%openusd_python_exe%" "%openusd_python_include%" "%openusd_python_lib%" 3.10.8 ^
--onetbb ^
--alembic ^
--openimageio ^
--no-hdf5 ^
--no-embree ^
--materialx ^
--no-debug-python ^
--no-tests
```

## Rebuilding MayaUsd

Since MayaHydra is dependent on MayaUsd (through the MayaUsdAPI module), you need to rebuild MayaUsd with the same version of Python and with OpenUSD previously rebuilt.<br>
To rebuild MayaUsd, you need to clone the MayaUsd repository (see [build.md](./build.md) for more info) and rebuild for Windows with (adjust it to your custom folders) :<br>
```
rem Save the current PATH as we are going to modify it
set original_path=%PATH%

rem OpenUSD 24.11 rebuilt with Python 3.10.8
set mayausd_pixar_usd_location=D:/USD-24.11-Python3.10.8

rem download and install the Maya 2024 devkit in a folder
set mayausd_maya_devkit_location=D:/Autodesk_Maya_2024_DEVKIT_Windows/devkitBase

rem Maya 2024 location
set mayausd_maya_location=C:/Program^ Files/Autodesk/Maya2024
set mayausd_python_include=%mayausd_maya_location%/include/Python310/Python
set mayausd_python_exe=%mayausd_maya_location%/bin/mayapy.exe
set mayausd_python_lib=%mayausd_maya_location%/lib/python310.lib

rem Remove other Python installations from the PATH to avoid conflict
rem As I had Python 3.11 installed. It would also be possible to use a Python virtual environment: https://docs.python.org/3/library/venv.html
set PATH=C:\Program Files\Autodesk\Maya2024\bin;%original_path%
set PATH=%PATH:C:\Users\%username%\AppData\Local\Programs\Python\Python311\Scripts;=%
set PATH=%PATH:C:\Users\%username%\AppData\Local\Programs\Python\Python311;=%
set PATH=%PATH:C:\Users\%username%\AppData\Local\Programs\Python\Python311\=%

rem Add OpenUSD bin and lib path to the Windows PATH
set PATH=%mayausd_pixar_usd_location%\bin;%mayausd_pixar_usd_location%\lib;%PATH%

rem Set necessary environment variables for the build process
set PYTHONPATH=C:\Program Files\Autodesk\Maya2024\Python;C:\Program Files\Autodesk\Maya2024\Lib;%mayausd_pixar_usd_location%\lib\python;

set mayausd_destination=D:/maya-usd-Python3.10.8

rem change this to your local version of Qt
set mayausd_qtlocation=D:/GIT/maya/artifactory/Windows/qt/6.5.3/60c0d89
set mayausd_qtversion=6.5.3

rem Output diagnostic information
echo PATH=%PATH%
echo PYTHONPATH=%PYTHONPATH%

rem Use the mayapy.exe directly for the build process
"%mayausd_python_exe%" build.py "%mayausd_destination%_" ^
-v=3 ^
--stages=clean,configure,build,install ^
--pxrusd-location=%mayausd_pixar_usd_location% ^
--build-relwithdebug ^
--maya-location="%mayausd_maya_location%" ^
--generator="Visual Studio 17 2022" ^
--devkit-location="%mayausd_maya_devkit_location%" ^
--materialx ^
--build-args="-DPYTHON_INCLUDE_DIR=\"%mayausd_python_include%\",-DPython_EXECUTABLE=\"%mayausd_python_exe%\",-DPython3_VERSION=3.10.8,-DPYTHON_LIBRARIES=\"%mayausd_python_lib%\",-DBUILD_WITH_PYTHON_3=ON,-DBUILD_WITH_PYTHON_3_VERSION=3.10,-DBUILD_TESTS=ON,-DBUILD_PXR_PLUGIN=OFF,-DBUILD_AL_PLUGIN=OFF,-DQT_LOCATION=\"%mayausd_qtlocation%\",-DQT_VERSION=%mayausd_qtversion%,-DPython3_ROOT_DIR=\"%mayausd_maya_location%\",-DPython3_FIND_STRATEGY=LOCATION,-DPython3_INCLUDE_DIR=\"%mayausd_python_include%\",-DPython3_LIBRARY=\"%mayausd_python_lib%\""

rem Restore the original PATH
set PATH=%original_path%

rem Unset the Python environment variables
set PYTHONPATH=
```

Note : <br>
You may have the following issue when rebuilding MayaUsd: https://github.com/PixarAnimationStudios/OpenUSD/issues/3310 <br>
In this case remove "OpenGL::GL" from the cmake file :<br>
D:/USD-24.11-Python3.10.8/cmake/pxrTargets.cmake <br>
When rebuilding MayaUsd, manually add the link to "OpenGL32.lib" to the MayaUsd project under Visual Studio in order to link correctly.


## Rebuilding MayaHydra

OpenUSD and MayaUsd are now rebuilt with the same version of Python as Maya 2024. MayaHydra can now be built.<br>
Which under Windows can be made through the follow batch file (adjust it to your custom folders):<br>
```
rem global options to build MayaHydra

set mayahydra_verboseLevel=3

set maya_hydra_python_version=3.10.8

rem MayaUsd
set mayahydra_mayausdlocation=D:/maya-usd-Python3.10.8

rem OpenUSD 24.11 rebuilt with Python 3.10.8
set mayahydra_pxrusdlocation=D:/USD-24.11-Python3.10.8

rem this is for release with debug info, change it to release if you want to build in release only
set mayahydra_buildconfig=relwithdebug

set mayahydra_mayalocation=C:/Program^ Files/Autodesk/Maya2024
set mayahydra_pythonincludedir=%mayahydra_mayalocation%/include/Python310/Python
set mayahydra_pythonexecutable=%mayahydra_mayalocation%/bin/mayapy.exe
set mayahydra_pythonlib=%mayahydra_mayalocation%/lib/python310.lib

set mayahydra_generator="Visual Studio 17 2022"
rem set mayahydra_generator="Ninja" you could use ninja if it is available on your system instead of VS2022

set mayahydra_mayadevkitlocation=D:/Autodesk_Maya_2024_DEVKIT_Windows/devkitBase
set mayahydra_main_pythonversion=3.10

rem change this to your local version of Qt
set mayahydra_qtlocation=D:/GIT/maya/artifactory/Windows/qt/6.5.3/60c0d89
set mayahydra_qtversion=6.5.3

rem Save the current PATH as we are going to modify it
set original_path=%PATH%

rem Remove other Python installations from the PATH to avoid conflict
rem As I had Python 3.11 installed. It would also be possible to use a Python virtual environment: https://docs.python.org/3/library/venv.html
set PATH=C:\Program Files\Autodesk\Maya2024\bin;%original_path%
set PATH=%PATH:C:\Users\%username%\AppData\Local\Programs\Python\Python311\Scripts;=%
set PATH=%PATH:C:\Users\%username%\AppData\Local\Programs\Python\Python311;=%
set PATH=%PATH:C:\Users\%username%\AppData\Local\Programs\Python\Python311\=%

rem Add USD library path to the PATH
set PATH=%mayahydra_pxrusdlocation%\bin;%mayahydra_pxrusdlocation%\lib;%PATH%

rem Set necessary environment variables for the build process
set PYTHONPATH=C:\Program Files\Autodesk\Maya2024\Python;C:\Program Files\Autodesk\Maya2024\Lib;%mayahydra_pxrusdlocation%\lib\python;

rem Output diagnostic information
echo PATH=%PATH%
echo PYTHONPATH=%PYTHONPATH%

"%mayahydra_pythonexecutable%" build.py "D:/maya-hydra-build" ^
-v=%mayahydra_verboseLevel% ^
--mayausd-location=%mayahydra_mayausdlocation% ^
--stages=clean,configure,build,install ^
--pxrusd-location=%mayahydra_pxrusdlocation% ^
--build-%mayahydra_buildconfig% ^
--maya-location="%mayahydra_mayalocation%" ^
--generator=%mayahydra_generator% ^
--devkit-location=%mayahydra_mayadevkitlocation% ^
--build-args="-DPYTHON_INCLUDE_DIR=\"%mayahydra_pythonincludedir%\",-DPython_EXECUTABLE=\"%mayahydra_pythonexecutable%\",-DPYTHON_LIBRARIES=\"%mayahydra_pythonlib%\",-DBUILD_WITH_PYTHON_3=ON,-DBUILD_WITH_PYTHON_3_VERSION=%mayahydra_main_pythonversion%,-DBUILD_TESTS=ON,-DBUILD_PXR_PLUGIN=OFF,-DBUILD_AL_PLUGIN=OFF,-DQT_LOCATION=\"%mayahydra_qtlocation%\",-DQT_VERSION=%mayahydra_qtversion%,-DPython3_VERSION=%maya_hydra_python_version% -DPython3_ROOT_DIR=\"%mayahydra_mayalocation%\",-DPython3_FIND_STRATEGY=LOCATION,-DPython3_INCLUDE_DIR=\"%mayahydra_pythonincludedir%\",-DPython3_LIBRARY=\"%mayahydra_pythonlib%\""


rem Restore the original PATH
set PATH=%original_path%

rem Unset the Python environment variables
set PYTHONPATH=

```

Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ class CubeSceneItem : public Ufe::SceneItem
// Returns the locator parent of the cube.
MhFlowViewportAPILocator* locator() const { return _locator; }

#if (MAYA_API_VERSION >= 20250000) // With Maya 2025 or later
// Unimplemented defaults. These should preferably be in UFE.
// PPT, 6-Jun-2024.
Ufe::Value getMetadata(const std::string& key) const override { return {}; }
Expand All @@ -430,6 +431,7 @@ class CubeSceneItem : public Ufe::SceneItem
Ufe::Value getGroupMetadata(const std::string& group, const std::string& key) const override { return {}; }
UndoableCommandPtr setGroupMetadataCmd(const std::string& group, const std::string& key, const Ufe::Value& value) override { return nullptr; }
UndoableCommandPtr clearGroupMetadataCmd(const std::string& group, const std::string& key) override { return nullptr; }
#endif

private:

Expand Down