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

Setting up the shading mode option menu dynamically. #166

Merged
Merged
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
1 change: 1 addition & 0 deletions third_party/maya/lib/usdMaya/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pxr_shared_library(${PXR_PACKAGE}
referenceAssembly
usdImport
usdExport
usdListShadingModes
usdTranslatorExport
usdTranslatorImport

Expand Down
22 changes: 22 additions & 0 deletions third_party/maya/lib/usdMaya/shadingModeRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ PxrUsdMayaShadingModeRegistry::_GetImporter(const TfToken& name)
return _importReg[name];
}

TfTokenVector
PxrUsdMayaShadingModeRegistry::_ListExporters() {
TfRegistryManager::GetInstance().SubscribeTo<PxrUsdMayaShadingModeExportContext>();
TfTokenVector ret;
ret.reserve(_exportReg.size());
for (const auto& e : _exportReg) {
ret.push_back(e.first);
}
return ret;
}

TfTokenVector
PxrUsdMayaShadingModeRegistry::_ListImporters() {
TfRegistryManager::GetInstance().SubscribeTo<PxrUsdMayaShadingModeImportContext>();
TfTokenVector ret;
ret.reserve(_importReg.size());
for (const auto& e : _importReg) {
ret.push_back(e.first);
}
return ret;
}

TF_INSTANTIATE_SINGLETON(PxrUsdMayaShadingModeRegistry);

PxrUsdMayaShadingModeRegistry&
Expand Down
9 changes: 9 additions & 0 deletions third_party/maya/lib/usdMaya/shadingModeRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class PxrUsdMayaShadingModeRegistry : public TfWeakBase
static PxrUsdMayaShadingModeImporter GetImporter(const TfToken& name) {
return GetInstance()._GetImporter(name);
}
static TfTokenVector ListExporters() {
return GetInstance()._ListExporters();
}
static TfTokenVector ListImporters() {
return GetInstance()._ListImporters();
}

PXRUSDMAYA_API
static PxrUsdMayaShadingModeRegistry& GetInstance();
Expand All @@ -82,6 +88,9 @@ class PxrUsdMayaShadingModeRegistry : public TfWeakBase
PxrUsdMayaShadingModeExporterCreator _GetExporter(const TfToken& name);
PxrUsdMayaShadingModeImporter _GetImporter(const TfToken& name);

TfTokenVector _ListExporters();
TfTokenVector _ListImporters();

PxrUsdMayaShadingModeRegistry();
~PxrUsdMayaShadingModeRegistry();
friend class TfSingleton<PxrUsdMayaShadingModeRegistry>;
Expand Down
73 changes: 73 additions & 0 deletions third_party/maya/lib/usdMaya/usdListShadingModes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "usdMaya/usdListShadingModes.h"

#include "usdMaya/shadingModeRegistry.h"

#include <maya/MSyntax.h>
#include <maya/MStatus.h>
#include <maya/MArgList.h>
#include <maya/MArgDatabase.h>
#include <maya/MGlobal.h>
#include <maya/MString.h>

PXR_NAMESPACE_OPEN_SCOPE

usdListShadingModes::usdListShadingModes() {

}

usdListShadingModes::~usdListShadingModes() {

}

MStatus
usdListShadingModes::doIt(const MArgList& args) {
MStatus status;
MArgDatabase argData(syntax(), args, &status);

if (status != MS::kSuccess) {
MGlobal::displayError("Invalid parameters detected. Exiting.");
return status;
}

TfTokenVector v;
if (argData.isFlagSet("export")) {
v = PxrUsdMayaShadingModeRegistry::ListExporters();
} else if (argData.isFlagSet("import")) {
v = PxrUsdMayaShadingModeRegistry::ListImporters();
}

// This is remapped in JobArgs.cpp manually
appendToResult("None");

for (const auto& e : v) {
// Manual remappings
if (e == PxrUsdMayaShadingModeTokens->displayColor) {
appendToResult("GPrim Colors");
appendToResult("Material Colors");
} else if (e == "pxrRis") {
appendToResult("RfM Shaders");
} else {
appendToResult(e.GetString().c_str());
}
}

return MS::kSuccess;
}

MSyntax
usdListShadingModes::createSyntax() {
MSyntax syntax;
syntax.addFlag("-ex", "-export", MSyntax::kNoArg);
syntax.addFlag("-im", "-import", MSyntax::kNoArg);

syntax.enableQuery(false);
syntax.enableEdit(false);

return syntax;
}

void* usdListShadingModes::creator() {
return new usdListShadingModes();
}

PXR_NAMESPACE_CLOSE_SCOPE
47 changes: 47 additions & 0 deletions third_party/maya/lib/usdMaya/usdListShadingModes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef _usdListShadingModes_usdListShadingModes_h_
#define _usdListShadingModes_usdListShadingModes_h_

#include "pxr/pxr.h"
#include <maya/MPxCommand.h>

PXR_NAMESPACE_OPEN_SCOPE

class usdListShadingModes : public MPxCommand
{
public:
usdListShadingModes();
virtual ~usdListShadingModes();

virtual MStatus doIt(const MArgList& args);
virtual bool isUndoable () const { return false; };

static MSyntax createSyntax();
static void* creator();
};

PXR_NAMESPACE_CLOSE_SCOPE

#endif // _usdListShadingModes_usdListShadingModes_h_
11 changes: 10 additions & 1 deletion third_party/maya/lib/usdMaya/usdTranslatorExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ usdTranslatorExport::writer(const MFileObject &file,
if (PxrUsdMayaShadingModeRegistry::GetInstance().GetExporter(shadingMode)) {
jobArgs.shadingMode = shadingMode;
}
}
} else {
TfToken modeToken(theOption[1].asChar());
if (PxrUsdMayaShadingModeRegistry::GetInstance().GetExporter(modeToken)) {
jobArgs.shadingMode = modeToken;
} else {
MGlobal::displayError(
TfStringPrintf("No shadingMode '%s' found. Setting shadingMode='none'", modeToken.GetText()).c_str());
jobArgs.shadingMode = PxrUsdMayaShadingModeTokens->none;
}
}
}
if (theOption[0] == MString("exportUVs")) {
jobArgs.exportMeshUVs = theOption[1].asInt();
Expand Down
16 changes: 8 additions & 8 deletions third_party/maya/lib/usdMaya/usdTranslatorExport.mel
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ global proc int usdTranslatorExport (string $parent,
if ($action == "post") {
setParent $parent;

columnLayout -adj true usdOptsCol;
optionMenuGrp -l "Shading Mode:" shadingModePopup;
menuItem -l "None";
menuItem -l "GPrim Colors";
menuItem -l "Material Colors";
menuItem -l "RfM Shaders";
columnLayout -adj true usdOptsCol;

string $exporters[] = `usdListShadingModes -export`;
optionMenuGrp -l "Shading Mode:" shadingModePopup;
for ($each in $exporters) {
menuItem -l $each;
}

checkBox -l "Make Instances" exportReferencesAsInstanceableCheckBox;

checkBox -l "Export UVs" exportUVsCheckBox;
Expand Down
9 changes: 9 additions & 0 deletions third_party/maya/lib/usdMaya/usdTranslatorImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ MStatus usdTranslatorImport::reader(const MFileObject & file,
shadingMode.GetText()).c_str());
jobArgs.shadingMode = PxrUsdMayaShadingModeTokens->none;
}
} else {
TfToken modeToken(theOption[1].asChar());
if (PxrUsdMayaShadingModeRegistry::GetInstance().GetExporter(modeToken)) {
jobArgs.shadingMode = modeToken;
} else {
MGlobal::displayError(
TfStringPrintf("No shadingMode '%s' found. Setting shadingMode='none'", modeToken.GetText()).c_str());
jobArgs.shadingMode = PxrUsdMayaShadingModeTokens->none;
}
}
} else if (theOption[0] == MString("readAnimData")) {
jobArgs.readAnimData = theOption[1].asInt();
Expand Down
14 changes: 7 additions & 7 deletions third_party/maya/lib/usdMaya/usdTranslatorImport.mel
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ global proc int usdTranslatorImport (string $parent,
setParent $parent;

columnLayout -adj true usdOptsCol;
optionMenuGrp -l "Shading Mode:" shadingModePopup;
menuItem -l "None";
menuItem -l "GPrim Colors";
menuItem -l "Material Colors";
menuItem -l "RfM Shaders";

string $importers[] = `usdListShadingModes -import`;
optionMenuGrp -l "Shading Mode:" shadingModePopup;
for ($each in $importers) {
menuItem -l $each;
}

checkBox -l "Read Animation Data" -cc ("usdTranslatorImport_AnimationCB") readAnimDataCheckBox;

checkBox -l "Custom Frame Range" -cc ("usdTranslatorImport_AnimationCB") customFrameRangeCheckBox;
Expand Down
14 changes: 14 additions & 0 deletions third_party/maya/plugin/pxrUsd/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "usdMaya/pluginStaticData.h"
#include "usdMaya/usdImport.h"
#include "usdMaya/usdExport.h"
#include "usdMaya/usdListShadingModes.h"
#include "usdMaya/usdTranslatorImport.h"
#include "usdMaya/usdTranslatorExport.h"

Expand Down Expand Up @@ -147,6 +148,14 @@ MStatus initializePlugin(
status.perror("registerCommand usdImport");
}

status = plugin.registerCommand("usdListShadingModes",
usdListShadingModes::creator,
usdListShadingModes::createSyntax);

if (!status) {
status.perror("registerCommand usdListShadingModes");
}

status = plugin.registerFileTranslator("pxrUsdImport",
"",
[]() {
Expand Down Expand Up @@ -202,6 +211,11 @@ MStatus uninitializePlugin(
status.perror("pxrUsd: unable to deregister USD Export translator.");
}

status = plugin.deregisterFileTranslator("usdListShadingModes");
if (!status) {
status.perror("deregisterCommand usdListShadingModes");
}

status = MGlobal::executeCommand("assembly -e -deregister " + _data.referenceAssembly.typeName);
CHECK_MSTATUS(status);

Expand Down