Skip to content

Commit

Permalink
Include standard data libraries in Python package (AcademySoftwareFou…
Browse files Browse the repository at this point in the history
…ndation#1237)

Package the standard definition libraries as part of the Python package. This removes the need for users to have to always search for the libraries, and the possibility to mistakenly use libraries which do not match the Python distribution.
  • Loading branch information
kwokcb authored Apr 5, 2023
1 parent 5e3de53 commit 5f32601
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ jobs:
python MaterialXTest/main.py
python MaterialXTest/genshader.py
python Scripts/mxupdate.py ../resources/Materials/TestSuite/stdlib/upgrade --yes
python Scripts/mxvalidate.py ../resources/Materials/Examples/StandardSurface/standard_surface_marble_solid.mtlx --verbose
python Scripts/mxvalidate.py ../resources/Materials/Examples/StandardSurface/standard_surface_marble_solid.mtlx --stdlib --verbose
python Scripts/mxdoc.py --docType md ../libraries/pbrlib/pbrlib_defs.mtlx
python Scripts/mxdoc.py --docType html ../libraries/bxdf/standard_surface.mtlx
python Scripts/generateshader.py ../resources/Materials/Examples/StandardSurface --path .. --target glsl
Expand Down
7 changes: 7 additions & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ endif()

install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pbrlib/genosl/pbrlib_genosl_impl.${PBRLIB_SUFFIX}"
DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}/pbrlib/genosl/" RENAME pbrlib_genosl_impl.mtlx)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "python/MaterialX/${MATERIALX_INSTALL_STDLIB_PATH}"
PATTERN "CMakeLists.txt" EXCLUDE
PATTERN "pbrlib_genosl_impl.*" EXCLUDE)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pbrlib/genosl/pbrlib_genosl_impl.${PBRLIB_SUFFIX}"
DESTINATION "python/MaterialX/${MATERIALX_INSTALL_STDLIB_PATH}/pbrlib/genosl/" RENAME pbrlib_genosl_impl.mtlx)
1 change: 1 addition & 0 deletions python/MaterialX/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include libraries
19 changes: 18 additions & 1 deletion python/MaterialX/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .PyMaterialXCore import *
from .PyMaterialXFormat import *
from .datatype import *

import os

#
# Element
Expand Down Expand Up @@ -292,3 +292,20 @@ def _stringToValue(string, t):
#

readFromXmlFile = readFromXmlFileBase


#
# Data Search Paths
#
def getDefaultDataSearchPath():
"""
Return the default data search path.
"""
root_path = os.path.dirname(__file__)
return root_path

def getDefaultDataLibraryFolders():
"""
Return list of default data library folders
"""
return [ 'libraries' ]
10 changes: 5 additions & 5 deletions python/Scripts/mxvalidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def main():

if opts.stdlib:
stdlib = mx.createDocument()
filePath = os.path.dirname(os.path.abspath(__file__))
searchPath = mx.FileSearchPath(os.path.join(filePath, '..', '..'))
searchPath.append(os.path.dirname(opts.inputFilename))
libraryFolders = [ "libraries" ]
mx.loadLibraries(libraryFolders, searchPath, stdlib)
try:
mx.loadLibraries(mx.getDefaultDataLibraryFolders(), mx.getDefaultDataSearchPath(), stdlib)
except err:
print(err)
sys.exit(0)
doc.importLibrary(stdlib)

(valid, message) = doc.validate()
Expand Down

0 comments on commit 5f32601

Please sign in to comment.