From da444d5172f343a12223218582298ca0126d3a0b Mon Sep 17 00:00:00 2001 From: Bernard Kwok Date: Thu, 22 Jun 2023 19:33:53 -0400 Subject: [PATCH] Add Python bindings for generation and rendering (#1386) Most of these wrapper updates are related to exposing missing APIs in Python for code gen and rendering. --- .../PyMaterialXCore/PyDefinition.cpp | 3 +++ .../PyMaterialXGenShader/PyGenOptions.cpp | 6 ++++++ .../PyMaterialXRender/PyCgltfLoader.cpp | 18 ++++++++++++++++++ .../PyMaterialXRender/PyLightHandler.cpp | 2 ++ 4 files changed, 29 insertions(+) create mode 100644 source/PyMaterialX/PyMaterialXRender/PyCgltfLoader.cpp diff --git a/source/PyMaterialX/PyMaterialXCore/PyDefinition.cpp b/source/PyMaterialX/PyMaterialXCore/PyDefinition.cpp index d79b45850e..d4ccdfb13c 100644 --- a/source/PyMaterialX/PyMaterialXCore/PyDefinition.cpp +++ b/source/PyMaterialX/PyMaterialXCore/PyDefinition.cpp @@ -43,6 +43,9 @@ void bindPyDefinition(py::module& mod) .def("getFunction", &mx::Implementation::getFunction) .def("setNodeDef", &mx::Implementation::setNodeDef) .def("getNodeDef", &mx::Implementation::getNodeDef) + .def("setNodeGraph", &mx::Implementation::setNodeGraph) + .def("hasNodeGraph", &mx::Implementation::hasNodeGraph) + .def("getNodeGraph", &mx::Implementation::getNodeGraph) .def_readonly_static("CATEGORY", &mx::Implementation::CATEGORY) .def_readonly_static("FILE_ATTRIBUTE", &mx::Implementation::FILE_ATTRIBUTE) .def_readonly_static("FUNCTION_ATTRIBUTE", &mx::Implementation::FUNCTION_ATTRIBUTE); diff --git a/source/PyMaterialX/PyMaterialXGenShader/PyGenOptions.cpp b/source/PyMaterialX/PyMaterialXGenShader/PyGenOptions.cpp index 633315d832..75b5fb11bb 100644 --- a/source/PyMaterialX/PyMaterialXGenShader/PyGenOptions.cpp +++ b/source/PyMaterialX/PyMaterialXGenShader/PyGenOptions.cpp @@ -27,12 +27,18 @@ void bindPyGenOptions(py::module& mod) .def_readwrite("shaderInterfaceType", &mx::GenOptions::shaderInterfaceType) .def_readwrite("fileTextureVerticalFlip", &mx::GenOptions::fileTextureVerticalFlip) .def_readwrite("targetColorSpaceOverride", &mx::GenOptions::targetColorSpaceOverride) + .def_readwrite("addUpstreamDependencies", &mx::GenOptions::addUpstreamDependencies) + .def_readwrite("libraryPrefix", &mx::GenOptions::libraryPrefix) .def_readwrite("targetDistanceUnit", &mx::GenOptions::targetDistanceUnit) .def_readwrite("hwTransparency", &mx::GenOptions::hwTransparency) .def_readwrite("hwSpecularEnvironmentMethod", &mx::GenOptions::hwSpecularEnvironmentMethod) + .def_readwrite("hwWriteDepthMoments", &mx::GenOptions::hwWriteDepthMoments) + .def_readwrite("hwShadowMap", &mx::GenOptions::hwShadowMap) .def_readwrite("hwMaxActiveLightSources", &mx::GenOptions::hwMaxActiveLightSources) .def_readwrite("hwNormalizeUdimTexCoords", &mx::GenOptions::hwNormalizeUdimTexCoords) + .def_readwrite("hwAmbientOcclusion", &mx::GenOptions::hwAmbientOcclusion) .def_readwrite("hwWriteAlbedoTable", &mx::GenOptions::hwWriteAlbedoTable) + .def_readwrite("hwImplicitBitangents", &mx::GenOptions::hwImplicitBitangents) .def_readwrite("emitColorTransforms", &mx::GenOptions::emitColorTransforms) .def(py::init<>()); } diff --git a/source/PyMaterialX/PyMaterialXRender/PyCgltfLoader.cpp b/source/PyMaterialX/PyMaterialXRender/PyCgltfLoader.cpp new file mode 100644 index 0000000000..158e6b4849 --- /dev/null +++ b/source/PyMaterialX/PyMaterialXRender/PyCgltfLoader.cpp @@ -0,0 +1,18 @@ +// +// Copyright Contributors to the MaterialX Project +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include + +namespace py = pybind11; +namespace mx = MaterialX; + +void bindPyCgltfLoader(py::module& mod) +{ + py::class_(mod, "CgltfLoader") + .def_static("create", &mx::CgltfLoader::create) + .def(py::init<>()) + .def("load", &mx::CgltfLoader::load); +} diff --git a/source/PyMaterialX/PyMaterialXRender/PyLightHandler.cpp b/source/PyMaterialX/PyMaterialXRender/PyLightHandler.cpp index 39b0d9e1a3..50725a7768 100644 --- a/source/PyMaterialX/PyMaterialXRender/PyLightHandler.cpp +++ b/source/PyMaterialX/PyMaterialXRender/PyLightHandler.cpp @@ -31,6 +31,8 @@ void bindPyLightHandler(py::module& mod) .def("getAlbedoTable", &mx::LightHandler::getAlbedoTable) .def("setEnvSampleCount", &mx::LightHandler::setEnvSampleCount) .def("getEnvSampleCount", &mx::LightHandler::getEnvSampleCount) + .def("setRefractionTwoSided", &mx::LightHandler::setRefractionTwoSided) + .def("getRefractionTwoSided", &mx::LightHandler::getRefractionTwoSided) .def("addLightSource", &mx::LightHandler::addLightSource) .def("setLightSources", &mx::LightHandler::setLightSources) .def("getLightSources", &mx::LightHandler::getLightSources)