-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add "-upAxis" (-upa) option to the export command. - Document it. - Add upAxis to the export job arguments structure. - Add upAxis and its possible values to the export tokens. - Expose upAxis job args to Python. - Add up axis UI to the export dialog. - Add AutoUndoCommands class to execute and automatically undo a set of MEL commands. - Use AutoUndoCommand to automatically change and restore the up-axis. - Implement temporarily changing Maya up-axis. We rotate all root nodes 90 degrees before and after the export. - We use undo so that the values are perfectly restored. - Add unit test.
- Loading branch information
1 parent
6ef3a6b
commit 7993964
Showing
16 changed files
with
450 additions
and
12 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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// | ||
// Copyright 2024 Autodesk | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Modifications copyright (C) 2020 Autodesk | ||
// | ||
|
||
#include "autoUndoCommands.h" | ||
|
||
#include <maya/MGlobal.h> | ||
#include <maya/MString.h> | ||
|
||
namespace MAYAUSD_NS_DEF { | ||
|
||
AutoUndoCommands::AutoUndoCommands(const char* scriptName, const std::string& commands) | ||
: _scriptName(scriptName) | ||
{ | ||
_executeCommands(commands); | ||
} | ||
|
||
AutoUndoCommands::~AutoUndoCommands() | ||
{ | ||
try { | ||
_undoCommands(); | ||
} catch (const std::exception&) { | ||
} | ||
} | ||
|
||
void AutoUndoCommands::undo() { _undoCommands(); } | ||
|
||
void AutoUndoCommands::disableUndo() { _needUndo = false; } | ||
|
||
void AutoUndoCommands::_executeCommands(const std::string& commands) | ||
{ | ||
// If no commands were provided, we do nothing. | ||
// This allow sub-classes to cancel the execution if needed by providing | ||
// no commands. | ||
if (commands.empty()) | ||
return; | ||
|
||
// Put all the requested commands inside a function to isolate any | ||
// variable they migh declare. | ||
static const char scriptPrefix[] = "proc _executeCommandsToBeUndone() {\n"; | ||
|
||
// Wrap all commands in a undo block (undo chunk in Maya parlance). | ||
static const char scriptSuffix[] | ||
= "}\n" | ||
"proc _executeCommandsWithUndo() {\n" | ||
// We need to re-enable undo for this because we may be executed | ||
// in a context that disbaled undo. | ||
" int $undoWereActive = `undoInfo -query -state`;\n" | ||
" undoInfo -stateWithoutFlush 1;\n" | ||
// Open the undo block. to make all commands undoable as a unit. | ||
" undoInfo -openChunk;\n" | ||
// Execute the commands. | ||
" _executeCommandsToBeUndone();\n" | ||
// Close the undo bloack to make the whole process undoable as a unit. | ||
" undoInfo -closeChunk;\n" | ||
// Restore the undo active flag. | ||
" undoInfo -stateWithoutFlush $undoWereActive;\n" | ||
"}\n" | ||
"_executeCommandsWithUndo();\n"; | ||
|
||
std::string fullScript = std::string(scriptPrefix) + commands + std::string(scriptSuffix); | ||
|
||
const bool displayEnabled = false; | ||
const bool undoEnabled = true; | ||
|
||
if (!MGlobal::executeCommand(fullScript.c_str(), displayEnabled, undoEnabled)) { | ||
MString errMsg; | ||
errMsg.format("Failed to ^1s.", _scriptName.c_str()); | ||
MGlobal::displayWarning(errMsg); | ||
return; | ||
} | ||
|
||
_needUndo = true; | ||
} | ||
|
||
void AutoUndoCommands::_undoCommands() | ||
{ | ||
if (!_needUndo) | ||
return; | ||
|
||
// Make sure undo will not be done twice even if there are exceptions. | ||
_needUndo = false; | ||
|
||
static const char fullScript[] = "proc _undoCommands() {\n" | ||
// We need to re-enable undo for this because we may be | ||
// executed in a context that disbaled undo. | ||
" int $undoWereActive = `undoInfo -query -state`;\n" | ||
" undoInfo -stateWithoutFlush 1;\n" | ||
// Undo the commands. | ||
" undo;\n" | ||
// Restore the undo active flag. | ||
" undoInfo -stateWithoutFlush $undoWereActive;\n" | ||
"}\n" | ||
"_undoCommands();\n"; | ||
|
||
const bool displayEnabled = false; | ||
const bool undoEnabled = true; | ||
|
||
if (!MGlobal::executeCommand(fullScript, displayEnabled, undoEnabled)) { | ||
MString errMsg; | ||
errMsg.format("Failed to undo ^1s.", _scriptName.c_str()); | ||
MGlobal::displayWarning(errMsg); | ||
} | ||
} | ||
} // namespace MAYAUSD_NS_DEF |
Oops, something went wrong.