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

Boudrey/maya 113462/wrapshader #1744

Merged
merged 12 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from 11 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
6 changes: 2 additions & 4 deletions lib/mayaUsd/fileio/shaderReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ TfToken UsdMayaShaderReader::GetMayaNameForUsdAttrName(const TfToken& usdAttrNam

void UsdMayaShaderReader::PostConnectSubtree(UsdMayaPrimReaderContext* context) { }

bool UsdMayaShaderReader::IsConverter(
UsdShadeShader& downstreamSchema,
TfToken& downstreamOutputName)
boost::optional<UsdMayaShaderReader::IsConverterResult> UsdMayaShaderReader::IsConverter()
{
return false;
return {};
}

void UsdMayaShaderReader::SetDownstreamReader(std::shared_ptr<UsdMayaShaderReader> downstreamReader)
Expand Down
9 changes: 8 additions & 1 deletion lib/mayaUsd/fileio/shaderReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <mayaUsd/fileio/primReader.h>

#include <pxr/pxr.h>
#include <pxr/usd/usdShade/shader.h>

#include <maya/MObject.h>
#include <maya/MPlug.h>
Expand Down Expand Up @@ -88,6 +89,12 @@ class UsdMayaShaderReader : public UsdMayaPrimReader
MAYAUSD_CORE_PUBLIC
virtual void PostConnectSubtree(UsdMayaPrimReaderContext* context);

struct IsConverterResult
{
UsdShadeShader downstreamSchema;
TfToken downstreamOutputName;
};

/// Is this a converter importer.
///
/// Converters do not create any Maya object. They represent a UsdShade node which functions as
Expand All @@ -98,7 +105,7 @@ class UsdMayaShaderReader : public UsdMayaPrimReader
/// returned in \p downstreamSchema and the requested output will be in \p downstreamOutputName
///
MAYAUSD_CORE_PUBLIC
virtual bool IsConverter(UsdShadeShader& downstreamSchema, TfToken& downstreamOutputName);
virtual boost::optional<IsConverterResult> IsConverter();

/// Sets a downstream converter to use for caching calls to GetCreatedObject and
/// GetMayaPlugForUsdAttrName
Expand Down
10 changes: 5 additions & 5 deletions lib/mayaUsd/fileio/shading/shadingModeUseRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,14 @@ class UseRegistryShadingModeImporter

shaderReader = std::dynamic_pointer_cast<UsdMayaShaderReader>(factoryFn(args));

UsdShadeShader downstreamSchema;
TfToken downstreamName;
if (shaderReader->IsConverter(downstreamSchema, downstreamName)) {
auto converter = shaderReader->IsConverter();
if (converter) {
// Recurse downstream:
sourcePlug = _GetSourcePlug(downstreamSchema, downstreamName);
sourcePlug = _GetSourcePlug(
converter.get().downstreamSchema, converter.get().downstreamOutputName);
if (!sourcePlug.isNull()) {
shaderReader->SetDownstreamReader(
_shaderReaderMap[downstreamSchema.GetPath()]);
_shaderReaderMap[converter.get().downstreamSchema.GetPath()]);
sourceObj = sourcePlug.node();
} else {
// Read failed. Invalidate the reader.
Expand Down
6 changes: 4 additions & 2 deletions lib/mayaUsd/fileio/shading/symmetricShaderReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ TF_DEFINE_PRIVATE_TOKENS(
void UsdMayaSymmetricShaderReader::RegisterReader(
const TfToken& usdShaderId,
const TfToken& mayaNodeTypeName,
const TfToken& materialConversion)
const TfToken& materialConversion,
bool fromPython)
{
UsdMayaShaderReaderRegistry::Register(
usdShaderId,
Expand All @@ -71,7 +72,8 @@ void UsdMayaSymmetricShaderReader::RegisterReader(
},
[mayaNodeTypeName](const UsdMayaPrimReaderArgs& readerArgs) {
return std::make_shared<UsdMayaSymmetricShaderReader>(readerArgs, mayaNodeTypeName);
});
},
fromPython);
}

/* static */
Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/fileio/shading/symmetricShaderReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class UsdMayaSymmetricShaderReader : public UsdMayaShaderReader
static void RegisterReader(
const TfToken& usdShaderId,
const TfToken& mayaNodeTypeName,
const TfToken& materialConversion = TfToken());
const TfToken& materialConversion = TfToken(),
bool fromPython = false);

MAYAUSD_CORE_PUBLIC
static ContextSupport CanImport(
Expand Down
6 changes: 4 additions & 2 deletions lib/mayaUsd/fileio/shading/symmetricShaderWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ PXR_NAMESPACE_OPEN_SCOPE
void UsdMayaSymmetricShaderWriter::RegisterWriter(
const TfToken& mayaNodeTypeName,
const TfToken& usdShaderId,
const TfToken& materialConversionName)
const TfToken& materialConversionName,
bool fromPython)
{
UsdMayaShaderWriterRegistry::Register(
mayaNodeTypeName,
Expand All @@ -61,7 +62,8 @@ void UsdMayaSymmetricShaderWriter::RegisterWriter(
UsdMayaWriteJobContext& jobCtx) {
return std::make_shared<UsdMayaSymmetricShaderWriter>(
depNodeFn, usdPath, jobCtx, usdShaderId);
});
},
fromPython);
}

/* static */
Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/fileio/shading/symmetricShaderWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class UsdMayaSymmetricShaderWriter : public UsdMayaShaderWriter
static void RegisterWriter(
const TfToken& mayaNodeTypeName,
const TfToken& usdShaderId,
const TfToken& materialConversionName = TfToken());
const TfToken& materialConversionName = TfToken(),
bool fromPython = false);

MAYAUSD_CORE_PUBLIC
static ContextSupport CanExport(
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ target_sources(${PYTHON_TARGET_NAME}
wrapPrimWriter.cpp
wrapExportChaser.cpp
wrapImportChaser.cpp
wrapShadingUtil.cpp
)

# -----------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions lib/mayaUsd/python/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ TF_WRAP_MODULE
TF_WRAP(JobImportArgs);
TF_WRAP(PrimWriter);
TF_WRAP(ShaderWriter);
TF_WRAP(ShadingModeImportContext);
TF_WRAP(ShaderReader);
TF_WRAP(ExportChaser);
TF_WRAP(ImportChaser);
TF_WRAP(ShadingUtil);
}
22 changes: 5 additions & 17 deletions lib/mayaUsd/python/wrapExportChaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,14 @@ class ExportChaserWrapper
//----------------------------------------------------------------------------------------------------------------------
void wrapExportChaser()
{
typedef ExportChaserWrapper* ExportChaserWrapperPtr;
typedef UsdMayaExportChaser This;

boost::python::class_<ExportChaserWrapper, boost::noncopyable>(
"ExportChaser", boost::python::no_init)
.def("__init__", make_constructor(&ExportChaserWrapper::New))
.def(
"ExportDefault",
&ExportChaserWrapper::ExportDefault,
&ExportChaserWrapper::default_ExportDefault)
.def(
"ExportFrame",
&ExportChaserWrapper::ExportFrame,
&ExportChaserWrapper::default_ExportFrame)
.def(
"PostExport",
&ExportChaserWrapper::PostExport,
&ExportChaserWrapper::default_PostExport)
.def(
"Register",
&ExportChaserWrapper::Register,
(boost::python::arg("class"), boost::python::arg("mayaTypeName")))
.def("ExportDefault", &This::ExportDefault, &ExportChaserWrapper::default_ExportDefault)
.def("ExportFrame", &This::ExportFrame, &ExportChaserWrapper::default_ExportFrame)
.def("PostExport", &This::PostExport, &ExportChaserWrapper::default_PostExport)
.def("Register", &ExportChaserWrapper::Register)
.staticmethod("Register");
}
16 changes: 5 additions & 11 deletions lib/mayaUsd/python/wrapImportChaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,14 @@ class ImportChaserWrapper
//----------------------------------------------------------------------------------------------------------------------
void wrapImportChaser()
{
typedef ImportChaserWrapper* ImportChaserWrapperPtr;
typedef UsdMayaImportChaser This;

boost::python::class_<ImportChaserWrapper, boost::noncopyable>(
"ImportChaser", boost::python::no_init)
.def("__init__", make_constructor(&ImportChaserWrapper::New))
.def(
"PostImport",
&ImportChaserWrapper::PostImport,
&ImportChaserWrapper::default_PostImport)
.def("Redo", &ImportChaserWrapper::Redo, &ImportChaserWrapper::default_Redo)
.def("Undo", &ImportChaserWrapper::Undo, &ImportChaserWrapper::default_Undo)
.def(
"Register",
&ImportChaserWrapper::Register,
(boost::python::arg("class"), boost::python::arg("type")))
.def("PostImport", &This::PostImport, &ImportChaserWrapper::default_PostImport)
.def("Redo", &This::Redo, &ImportChaserWrapper::default_Redo)
.def("Undo", &This::Undo, &ImportChaserWrapper::default_Undo)
.def("Register", &ImportChaserWrapper::Register)
.staticmethod("Register");
}
34 changes: 28 additions & 6 deletions lib/mayaUsd/python/wrapOpenMaya.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,35 @@ template <class MayaClass> struct MayaClassConverter
}
};
#endif

// Register both converters from and to Python for a type T
template <class T> struct registerConverter
{
public:
registerConverter()
{
boost::python::to_python_converter<T, MayaClassConverter<T>>();
boost::python::converter::registry::push_back(&convertible, &construct, typeid(T));
}

private:
static void* convertible(PyObject* obj) { return obj; }

static void
construct(PyObject* obj, boost::python::converter::rvalue_from_python_stage1_data* data)
{
MPyObject<T>* thePyObject = (MPyObject<T>*)obj;
data->convertible = thePyObject->fPtr;
}
};

} // namespace

void wrapOpenMaya()
{
boost::python::to_python_converter<MObject, MayaClassConverter<MObject>>();
boost::python::to_python_converter<MDagPath, MayaClassConverter<MDagPath>>();
boost::python::to_python_converter<MDagPathArray, MayaClassConverter<MDagPathArray>>();
boost::python::to_python_converter<MPlug, MayaClassConverter<MPlug>>();
boost::python::to_python_converter<MDGModifier, MayaClassConverter<MDGModifier>>();
}
registerConverter<MObject>();
registerConverter<MDagPath>();
registerConverter<MDagPathArray>();
registerConverter<MPlug>();
registerConverter<MDGModifier>();
}
Loading