4.21. mayabinary — Reading Maya Binary files

This module contains the MBReader class which can be used as a base class for reading Maya Binary (*.mb) files. The class parses the structure of the file and invokes a callback method for every chunk found in the file. The actual decoding of the chunk data has to be done in a derived class.

4.21.1. MBReader class

The MBReader class reads Maya Binary files and calls appropriate methods which have to be implemented in a derived class. A Maya Binary file is composed of chunks that contain the actual data. There can be data chunks that contain the actual data and group chunks that contain the data chunks.

class cgkit.mayabinary.MBReader
Creates an instance of the reader.
MBReader.filename
The file name (if it could be obtained). This may be used for generating warning or error messages.
MBReader.read(file)
Read the content of a file. file is either a file like object that can be used to read the content of the file or the name of a file.
MBReader.abort()
Aborts reading the current file. This method can be called in handler methods to abort reading the file.
MBReader.onBeginGroup(chunk)
Callback that is called whenever a new group tag begins. chunk is a GroupChunk object containing information about the group chunk.
MBReader.onEndGroup(chunk)
Callback that is called whenever a group goes out of scope. chunk is a GroupChunk object containing information about the group chunk (it is the same instance that was passed to onBeginGroup()).
MBReader.onDataChunk(chunk)
Callback that is called for each data chunk. chunk is a Chunk object that contains information about the chunk and that can be used to read the actual chunk data.

4.21.2. Chunk class

A Chunk object is passed to the callback methods of the MBReader class. It contains information about the current chunk and it can be used to read the actual chunk data. A Chunk object has the following attributes and methods:

class cgkit.mayabinary.Chunk
tag
This is a string containing four characters that represent the chunk name.
size
The size in bytes of the data part of the chunk.
pos
The absolute position of the data part within the input file.
depth
The depth of the chunk (i.e. how deep it is nested). The root has a depth of 0.
parent
The GroupChunk object of the parent chunk. In the case of the root group chunk this attribute is None.
chunkPath()
Return a string containing the full path to this chunk. The result is a concatenation of all chunk names that lead to this chunk.
read(bytes=-1)
Read the specified number of bytes from the chunk. If bytes is -1 the entire chunk data is read. The return value is a string containing the binary data.

4.21.3. GroupChunk class

The GroupChunk class is derived from the Chunk class, so it has the same attributes and methods. In addition it defines one more attribute:

class cgkit.mayabinary.GroupChunk
type
This is a string containing four characters that represent the group type.