forked from agibli/sansapp
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
223 additions
and
258 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 |
---|---|---|
@@ -1,4 +1,58 @@ | ||
sansapp | ||
======= | ||
### Autodesk Maya Scenefile Parser | ||
|
||
An Experimental Batch Scene Parser | ||
Parse Binary and Ascii Maya scene files with Python. | ||
|
||
Supports Maya 8.5-2017. | ||
|
||
**Alternatives** | ||
|
||
- [cgkit](https://github.com/yamins81/cgkit/blob/master/cgkit/mayabinary.py) | ||
- [westernx/mayatools](https://github.com/westernx/mayatools/blob/master/mayatools/binary.py) | ||
|
||
|
||
<br> | ||
<br> | ||
<br> | ||
|
||
### Usage | ||
|
||
Parsing either an `.ma` of `.mb` involves subclassing a parser superclass and implementing various handles, such as when a node or attribute creation event takes place. | ||
|
||
```python | ||
from maya_scenefile_parser import MayaAsciiParser, MayaBinaryParser | ||
|
||
nodes = dict() | ||
|
||
ext = os.path.splitext(path)[1] | ||
try: | ||
Base, mode = { | ||
".ma": (MayaAsciiParser, "r"), | ||
".mb": (MayaBinaryParser, "rb"), | ||
}[ext] | ||
except KeyError: | ||
raise RuntimeError("Invalid maya file: %s" % path) | ||
|
||
class Parser(Base): | ||
def on_create_node(self, nodetype, name, parent): | ||
self.current_node = (name, parent, nodetype) | ||
|
||
def on_set_attr(self, name, value, type): | ||
if name not in ("nts", "notes"): | ||
return | ||
|
||
if self.current_node not in nodes: | ||
nodes[self.current_node] = {} | ||
|
||
nodes[self.current_node][name] = value | ||
|
||
print("{name} = {value} ({type})".format(**locals())) | ||
|
||
with open(path, mode) as f: | ||
parser = Parser(f) | ||
parser.parse() | ||
|
||
for node, attrs in nodes.iteritems(): | ||
for key, value in attrs.iteritems(): | ||
print("{node}.{key} = {value}".format(**locals())) | ||
|
||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
# API | ||
from .ascii import MayaAsciiParser | ||
from .binary import MayaBinaryParser | ||
|
||
__all__ = [ | ||
"MayaAsciiParser", | ||
"MayaBinaryParser" | ||
] |
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.