forked from PixarAnimationStudios/OpenUSD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
General mechanism for storing USD-specific data in "USD_" Maya attrib…
…utes (Internal change: 1661180)
- Loading branch information
Showing
10 changed files
with
456 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// 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. | ||
// | ||
#include "usdMaya/AttributeConverter.h" | ||
|
||
#include "pxr/usd/usd/prim.h" | ||
|
||
#include <maya/MFnDependencyNode.h> | ||
|
||
FunctionalAttributeConverter::FunctionalAttributeConverter( | ||
MayaToUsdFn mayaToUsdFn, UsdToMayaFn usdToMayaFn) | ||
: _mayaToUsdFn(mayaToUsdFn), _usdToMayaFn(usdToMayaFn) | ||
{ | ||
} | ||
|
||
bool | ||
FunctionalAttributeConverter::MayaToUsd( | ||
const MFnDependencyNode& srcNode, | ||
UsdPrim& destPrim, | ||
const UsdTimeCode usdTime) const | ||
{ | ||
if (_mayaToUsdFn) { | ||
return _mayaToUsdFn(srcNode, destPrim, usdTime); | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
|
||
bool | ||
FunctionalAttributeConverter::UsdToMaya( | ||
const UsdPrim& srcPrim, | ||
MFnDependencyNode& destNode, | ||
const UsdTimeCode usdTime) const | ||
{ | ||
if (_usdToMayaFn) { | ||
return _usdToMayaFn(srcPrim, destNode, usdTime); | ||
} | ||
else { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// 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 PXRUSDMAYA_ATTRIBUTECONVERTER_H | ||
#define PXRUSDMAYA_ATTRIBUTECONVERTER_H | ||
|
||
/// \file AttributeConverter.h | ||
|
||
#include "pxr/usd/usd/prim.h" | ||
#include "pxr/usd/usd/timeCode.h" | ||
|
||
#include <maya/MFnDependencyNode.h> | ||
|
||
#include <functional> | ||
|
||
/// \brief Provides a way to store USD-specific information on a Maya node | ||
/// as an extra Maya attribute (e.g. "USD_hidden" for the hidden state) when no | ||
/// existing Maya attribute maps cleanly. | ||
/// | ||
/// This way, we can store information such as the hidden state or the model | ||
/// kind on a Maya node so that the information isn't lost in the USD to Maya to | ||
/// USD roundtrip. | ||
/// | ||
/// This class encapsulates: | ||
/// (1) a way to store non-attribute metadata or information (such as the hidden | ||
/// state) on a Maya node when importing, and | ||
/// (2) a way to write out the same metadata or information from a Maya node | ||
/// into a \class UsdPrim when exporting. | ||
class AttributeConverter { | ||
public: | ||
/// \brief Takes attribute(s) from a Maya node and modifies a | ||
/// \class UsdPrim accordingly. | ||
virtual bool MayaToUsd( | ||
const MFnDependencyNode& depNode, | ||
UsdPrim& destPrim, | ||
const UsdTimeCode usdTime) const = 0; | ||
|
||
/// \brief Stores information about a source \class UsdPrim in a Maya node. | ||
virtual bool UsdToMaya( | ||
const UsdPrim& srcPrim, | ||
MFnDependencyNode& destNode, | ||
const UsdTimeCode usdTime) const = 0; | ||
}; | ||
|
||
/// \brief An implementation of \class AttributeConverter that allows passing in | ||
/// functions or lambdas to handle the conversion between Maya and USD. | ||
class FunctionalAttributeConverter : public AttributeConverter { | ||
public: | ||
typedef std::function< bool (const MFnDependencyNode&, UsdPrim&, | ||
UsdTimeCode) > MayaToUsdFn; | ||
typedef std::function< bool (const UsdPrim&, MFnDependencyNode&, | ||
UsdTimeCode) > UsdToMayaFn; | ||
|
||
virtual bool MayaToUsd( | ||
const MFnDependencyNode& depNode, | ||
UsdPrim& destPrim, | ||
const UsdTimeCode usdTime) const override; | ||
virtual bool UsdToMaya( | ||
const UsdPrim& srcPrim, | ||
MFnDependencyNode& destNode, | ||
const UsdTimeCode usdTime) const override; | ||
|
||
/// \brief Constructs a FunctionalAttributeConverter that forwards calls to | ||
/// MayaToUsd and UsdToMaya to the given functions. | ||
/// | ||
/// The functions can be empty functions, in which case MayaToUsd and/or | ||
/// UsdToMaya will return false. | ||
FunctionalAttributeConverter( | ||
MayaToUsdFn mayaToUsdFn, | ||
UsdToMayaFn usdToMayaFn); | ||
|
||
private: | ||
const MayaToUsdFn _mayaToUsdFn; | ||
const UsdToMayaFn _usdToMayaFn; | ||
}; | ||
|
||
#endif // PXRUSDMAYA_ATTRIBUTECONVERTER_H |
45 changes: 45 additions & 0 deletions
45
third_party/maya/lib/usdMaya/AttributeConverterRegistry.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// 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. | ||
// | ||
#include "usdMaya/AttributeConverterRegistry.h" | ||
|
||
#include "pxr/base/tf/registryManager.h" | ||
|
||
static std::vector<AttributeConverter*> _reg; | ||
|
||
/* static */ | ||
void | ||
AttributeConverterRegistry::Register(AttributeConverter* converter) { | ||
_reg.push_back(converter); | ||
} | ||
|
||
/* static */ | ||
std::vector<const AttributeConverter*> | ||
AttributeConverterRegistry::GetAllConverters() { | ||
TfRegistryManager::GetInstance().SubscribeTo<AttributeConverterRegistry>(); | ||
std::vector<const AttributeConverter*> ret; | ||
for (AttributeConverter* converter : _reg) { | ||
ret.push_back(converter); | ||
} | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// 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 PXRUSDMAYA_ATTRIBUTECONVERTERREGISTRY_H | ||
#define PXRUSDMAYA_ATTRIBUTECONVERTERREGISTRY_H | ||
|
||
/// \file AttributeConverterRegistry.h | ||
|
||
#include <vector> | ||
|
||
class AttributeConverter; | ||
|
||
/// \brief A registry of all the converters used to import and export | ||
/// USD-specific information stored in Maya attributes (e.g. "USD_hidden"). | ||
struct AttributeConverterRegistry { | ||
/// \brief Registers the given attribute converter. | ||
/// Ownership of the converter \p converter transfers to | ||
/// AttributeConverterRegistry. | ||
static void Register(AttributeConverter* converter); | ||
|
||
/// \brief Gets a copy of the list of all registered converters. | ||
static std::vector<const AttributeConverter*> GetAllConverters(); | ||
}; | ||
|
||
#endif // PXRUSDMAYA_ATTRIBUTECONVERTERREGISTRY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.