Skip to content

Commit

Permalink
Merge pull request #53 from LumaPictures/pr/layer_refactor
Browse files Browse the repository at this point in the history
Refactor of way serialization of layers is done within a maya scene file
  • Loading branch information
dbaz authored Jan 16, 2018
2 parents 62762a1 + a9dfcaf commit 9fd4545
Show file tree
Hide file tree
Showing 39 changed files with 2,568 additions and 2,827 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## v0.??.? (????-??-??)

### Added


### Changed

* Using -muted/-m flag with AL_usdmaya_LayerGetLayers now returns layer display names by default, and identifiers if
the -identifiers/-id flag is set. This makes it more in line with all the other flags for the command (and more
flexible), but is a change in behavior - previously, the muted layers would ALWAYS be returned as identifier.


## v0.25.0 (2017-11-28)

### Added
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ include_directories(${PXR_INCLUDE_DIRS})
# is the rationale for listing them here.
find_package(Boost COMPONENTS
python
thread
REQUIRED
)

Expand Down
1 change: 0 additions & 1 deletion docs/layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Normally, the default Edit Target in USD will be the Root Layer of the scene, al
#### Commands
There are a number of layer-related commands available, all are available via MEL, and some from the USD->Layers dropdow in the UI.
+ AL_usdmaya_LayerSave
+ AL_usdmaya_LayerCreateSubLayer
+ AL_usdmaya_LayerCreateLayer
+ AL_usdmaya_LayerCurrentEditTarget
+ AL_usdmaya_LayerGetLayers
Expand Down
58 changes: 56 additions & 2 deletions lib/AL_USDMaya/AL/maya/CommandGuiHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,56 @@ CommandGuiHelper::~CommandGuiHelper()
MGlobal::executeCommand(MString(m_controls.str().data(), m_controls.str().size()));
}

//----------------------------------------------------------------------------------------------------------------------
void CommandGuiHelper::addExecuteText(const char* toAdd)
{
// TODO: write a proper string encoder for MEL (tricky, because can't represent
// all 256 character-bytes using mel string literals - would have to resort to
// calling out to python for a truly string rerpr encoder.
// (note that even mel's builtin "encodeString" command doesn't actually always
// return a mel string that will evaluate to the input - ie, it will return
// "\004", but that isn't a valid mel escape sequence, and will just result in "004"

// for now, just check to make sure we have printable characters... only need to
// implement a full MEL-string-encoder if we really have a need...
m_execute << " $str += \"";
bool printedError = false;

for(size_t i = 0; toAdd[i] != '\0'; ++i)
{
if(toAdd[i] < 32 || toAdd[i] > 126)
{
if (toAdd[i] == '\b') m_execute << "\\b";
else if (toAdd[i] == '\t') m_execute << "\\t";
else if (toAdd[i] == '\n') m_execute << "\\n";
else if (toAdd[i] == '\r') m_execute << "\\r";
// Just throwing, if we ever need to use a string with weird chars, need to
// update this function...
else if (!printedError)
{
// Make our own stream (instead of steaming straigt to cerr)
// both because we also want to output to maya, and
// because we need to set a flag (ie, std::hex)
std::ostringstream err;
err << "CommandGuiHelper::addExecuteText encountered bad character at index ";
err << i;
err << ": 0x";
err << std::hex;
// if you just reinterpret_cast as uint8_t, it still treats as a char
err << static_cast<int>(reinterpret_cast<const unsigned char*>(toAdd)[i]);
std::string errStr = err.str();
MGlobal::displayError(errStr.c_str());
std::cerr << errStr;
printedError = true;
}
}
else if (toAdd[i] == '"') m_execute << "\\\"";
else if (toAdd[i] == '\\') m_execute << "\\\\";
else m_execute << toAdd[i];
}
m_execute << "\";\n";
}

//----------------------------------------------------------------------------------------------------------------------
void CommandGuiHelper::addFlagOption(const char* commandFlag, const char* label, const bool defaultVal, bool persist)
{
Expand Down Expand Up @@ -314,7 +364,7 @@ void CommandGuiHelper::addBoolOption(const char* commandFlag, const char* label,
}

//----------------------------------------------------------------------------------------------------------------------
void CommandGuiHelper::addListOption(const char* commandFlag, const char* label, GenerateListFn generateList)
void CommandGuiHelper::addListOption(const char* commandFlag, const char* label, GenerateListFn generateList, bool isMandatory)
{
const std::string optionVar = m_commandName + "_" + commandFlag;
const std::string getOptionVar = std::string("`optionVar -q -sl \"") + optionVar + "\"`";
Expand All @@ -336,7 +386,11 @@ void CommandGuiHelper::addListOption(const char* commandFlag, const char* label,

//
m_execute << " global string $" << optionVar << "_sl;"
<< " $str += \" -" << commandFlag << " $" << optionVar << "_sl \";\n";
<< " $str += \" ";
if (!isMandatory) {
m_execute << "-" << commandFlag << " ";
}
m_execute << "$" << optionVar << "_sl \";\n";
}

//----------------------------------------------------------------------------------------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion lib/AL_USDMaya/AL/maya/CommandGuiHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class CommandGuiHelper
/// \brief dtor - auto generates, and executes the GUI code.
~CommandGuiHelper();

/// \brief add some text to the execute command, unconditionally
/// Useful if, ie, you always want to set a non-default command flag
/// \param toAdd extra flags / text to add to the execution command
void addExecuteText(const char* toAdd);

/// \brief add a boolean option value to the GUI
/// \param commandFlag the flag for the command
/// \param label human readable GUI label for the option
Expand Down Expand Up @@ -230,7 +235,8 @@ class CommandGuiHelper
/// \param commandFlag the flag for the command
/// \param label human readable GUI label for the option
/// \param generateList The C++ command to build up a list of text strings for the GUI to display
void addListOption(const char* commandFlag, const char* label, GenerateListFn generateList);
/// \param isMandatory If true, our commandFlag is actually a mandatory argument, not a option / flag
void addListOption(const char* commandFlag, const char* label, GenerateListFn generateList, bool isMandatory=false);

/// \brief add an enum option value to the GUI
/// \param commandFlag the flag for the command
Expand Down
51 changes: 51 additions & 0 deletions lib/AL_USDMaya/AL/maya/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,40 @@ class ProfilerSectionTag;
MGlobal::displayError(maya_error_string); \
} }

/// \brief Given the status, validates that the status is ok. If not, an error is logged using the specified error
/// message. If an error occurs, then a "continue" statement is issued (and so should be used in loops).
/// \ingroup mayautils
#define AL_MAYA_CHECK_ERROR_CONTINUE(status, ErrorString) { \
MStatus _status_##__LINE__ = status; \
if (!_status_##__LINE__) \
{ \
MString maya_error_string = __FILE__ ":"; \
maya_error_string += __LINE__; \
maya_error_string += " "; \
maya_error_string += _status_##__LINE__.errorString(); \
maya_error_string += " : "; \
maya_error_string += ErrorString; \
MGlobal::displayError(maya_error_string); \
continue; \
} }

/// \brief Given the status, validates that the status is ok. If not, an error is logged using the specified error
/// message. If an error occurs, then exit immediately, with no return.
/// \ingroup mayautils
#define AL_MAYA_CHECK_ERROR_RETURN(status, ErrorString) { \
MStatus _status_##__LINE__ = status; \
if (!_status_##__LINE__) \
{ \
MString maya_error_string = __FILE__ ":"; \
maya_error_string += __LINE__; \
maya_error_string += " "; \
maya_error_string += _status_##__LINE__.errorString(); \
maya_error_string += " : "; \
maya_error_string += ErrorString; \
MGlobal::displayError(maya_error_string); \
return; \
} }

/// \brief Given the status, validates that the status is ok. If not, an error is logged using the specified error
/// message. If an error occurs, a null MObject is returned.
/// \ingroup mayautils
Expand All @@ -146,6 +180,23 @@ class ProfilerSectionTag;
return MObject::kNullObj; \
} }

/// \brief Given the status, validates that the status is ok. If not, an error is logged using the specified error
/// message. If an error occurs, then exit immediately, returning the given value.
/// \ingroup mayautils
#define AL_MAYA_CHECK_ERROR_RETURN_VAL(status, returnVal, ErrorString) { \
MStatus _status_##__LINE__ = status; \
if (!_status_##__LINE__) \
{ \
MString maya_error_string = __FILE__ ":"; \
maya_error_string += __LINE__; \
maya_error_string += " "; \
maya_error_string += _status_##__LINE__.errorString(); \
maya_error_string += " : "; \
maya_error_string += ErrorString; \
MGlobal::displayError(maya_error_string); \
return returnVal; \
} }

/// \ingroup mayautils
/// \brief utility macro to check that an SdfLayerHandle is actually valid.
#define LAYER_HANDLE_CHECK(X) \
Expand Down
14 changes: 14 additions & 0 deletions lib/AL_USDMaya/AL/maya/NodeHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,20 @@ MStatus NodeHelper::outputDataValue(MDataBlock& dataBlock, const MObject& attrib
return status;
}

//----------------------------------------------------------------------------------------------------------------------
MPxData* NodeHelper::outputDataValue(MDataBlock& dataBlock, const MObject& attribute)
{
MStatus status;
MDataHandle outDataHandle = dataBlock.outputValue(attribute, &status);
if(status)
{
return outDataHandle.asPluginData();
}
report_get_error(attribute, MPxData, status);
return 0;
}


//----------------------------------------------------------------------------------------------------------------------
MPxData* NodeHelper::createData(const MTypeId& dataTypeId, MObject& data)
{
Expand Down
39 changes: 37 additions & 2 deletions lib/AL_USDMaya/AL/maya/NodeHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,21 @@ namespace maya {
/// \endcode
/// \ingroup mayagui
//----------------------------------------------------------------------------------------------------------------------
#define AL_DECL_ATTRIBUTE(XX) \

// For children of multi-attribute, a generic XXPlug() method
// isn't very helpful, as we need to attach to a specific indexed
// element plug of the parent array... and defining it just
// creates a confusing name
#define AL_DECL_MULTI_CHILD_ATTRIBUTE(XX) \
private: \
static MObject m_##XX; \
public: \
MPlug XX##Plug() const { return MPlug( thisMObject(), m_##XX ); } \
static const MObject& XX () { return m_##XX; }

#define AL_DECL_ATTRIBUTE(XX) \
AL_DECL_MULTI_CHILD_ATTRIBUTE(XX) \
MPlug XX##Plug() const { return MPlug( thisMObject(), m_##XX ); } \

//----------------------------------------------------------------------------------------------------------------------
/// \brief This is a little helper object designed to reduce the amount of boilerplate GUI code you need to jump through
/// to add your own nodes that match a USD schema type. It has been designed to attempt to match the attribute
Expand Down Expand Up @@ -481,6 +489,33 @@ class NodeHelper
/// \return MS::kSuccess if all went well
static MStatus outputDataValue(MDataBlock& dataBlock, const MObject& attribute, MPxData* value);

/// \brief get an output data value from the dataBlock from the specified attribute
/// \param dataBlock the data block to get the value from
/// \param attribute the handle to the attribute to get an MPxData for
/// \return the value
/// \note If the value could not be queried, and error will be logged to std::cerr
/// Useful when you want to modify something on the underlying MPxData, without
/// creating / setting an entirely new instance of the MPxData
static MPxData* outputDataValue(MDataBlock& dataBlock, const MObject& attribute);

/// \brief get an output data value from the dataBlock from the specified attribute
/// \param dataBlock the data block to get the value from
/// \param attribute the handle to the attribute to get an MPxData subclass for
/// \return the value
/// \note If the value could not be queried, and error will be logged to std::cerr
/// Useful when you want to modify something on the underlying MPxData subclass, without
/// creating / setting an entirely new instance of the MPxData subclass
template<typename MPxDataType>
static MPxDataType* outputDataValue(MDataBlock& dataBlock, const MObject& attribute)
{
MPxData* data = NodeHelper::outputDataValue(dataBlock, attribute);
if(data)
{
return dynamic_cast<MPxDataType*>(data);
}
return 0;
}

/// \brief helper method to create new data objects of the specified data type
/// \param dataTypeId the MTypeId of the plugin data object to create
/// \param data the returned handle to the created data object, usually passed to MDataHandle::set, or MPlug::setValue.
Expand Down
1 change: 0 additions & 1 deletion lib/AL_USDMaya/AL/usdmaya/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ namespace cmds {
struct CompareLayerHandle;
class LayerCommandBase;
class LayerConstructTree;
class LayerCreateSubLayer;
class LayerCurrentEditTarget;
class LayerExport;
class LayerGetLayers;
Expand Down
Loading

0 comments on commit 9fd4545

Please sign in to comment.