Bases: pyffi.object_models.xml.FileFormat
Stores all information about the cgf file format.
Bases: pyffi.formats.cgf.Chunk
Common parent for MtlChunk and MtlNameChunk.
Bases: pyffi.formats.cgf.Chunk
Common parent for HelperChunk and MeshChunk.
Bases: pyffi.object_models.xml.struct_.StructBase
A bone link.
Vertex weight.
The bone chunk.
The bone offset?
Bases: exceptions.Exception
Exception for CGF specific errors.
Bases: pyffi.object_models.xml.struct_.StructBase
A CGF chunk header.
The chunk identifier.
Position of the chunk in the CGF file.
Type of chunk referred to.
Version of the chunk referred to.
Bases: pyffi.object_models.xml.enum.EnumBase
An unsigned 32-bit integer, describing the chunk type.
Bases: pyffi.object_models.common.UInt
The version of a particular chunk, or the version of the chunk table.
Bases: pyffi.object_models.Data
A class to contain the actual cgf data.
Note that L{versions} and L{chunk_table} are not automatically kept in sync with the L{chunks}, but they are resynchronized when calling L{write}.
Variables: |
|
---|
Returns chunks without parent.
Quickly checks whether the stream appears to contain cgf data, and read the cgf header and chunk table. Resets stream to original position.
Call this function if you only need to inspect the header and chunk table.
Parameters: | stream (file) – The file to inspect. |
---|
This function checks the version only, and is faster than the usual inspect function (which reads the full chunk table). Sets the L{header} and L{game} instance variables if the stream contains a valid cgf file.
Call this function if you simply wish to check that a file is a cgf file without having to parse even the header.
Raises ValueError: | |
---|---|
If the stream does not contain a cgf file. | |
Parameters: | stream (file) – The stream from which to read. |
Read a cgf file. Does not reset stream position.
Parameters: | stream (file) – The stream from which to read. |
---|
Update L{versions} for the given chunks and game.
Write a cgf file. The L{header} and L{chunk_table} are recalculated from L{chunks}. Returns number of padding bytes written (this is for debugging purposes only).
Parameters: | stream (file) – The stream to which to write. |
---|---|
Returns: | Number of padding bytes written. |
Bases: pyffi.formats.cgf.Chunk
Export information.
Bases: pyffi.object_models.xml.struct_.StructBase
R32G32B32 (float).
Bases: pyffi.object_models.xml.struct_.StructBase
A mesh face.
Material index.
Smoothing group.
First vertex index.
Second vertex index.
Third vertex index.
Bases: pyffi.object_models.common.Int
Points to a position in a file.
Bases: pyffi.object_models.xml.basic.BasicBase
The CryTek file signature with which every cgf file starts.
Return a hash value for the signature.
Returns: | An immutable object that can be used as a hash. |
---|
Return number of bytes that the signature occupies in a file.
Returns: | Number of bytes. |
---|
Get signature.
Returns: | The signature. |
---|
Read signature from stream.
Parameters: | stream (file) – The stream to read from. |
---|
Not implemented.
Write signature to stream.
Parameters: | stream (file) – The stream to read from. |
---|
Bases: pyffi.object_models.xml.enum.EnumBase
An unsigned 32-bit integer, describing the file type.
Bases: pyffi.object_models.xml.struct_.StructBase
Obsolete, not decoded.
Bases: pyffi.object_models.xml.struct_.StructBase
The CGF header.
Position of the chunk table in the CGF file.
The CGF file signature.
The CGF file type (geometry or animation).
The version of the chunk table.
Bases: pyffi.object_models.xml.struct_.StructBase
R8G8B8.
Bases: pyffi.object_models.xml.struct_.StructBase
R8G8B8A8.
Bases: pyffi.object_models.xml.struct_.StructBase
A bone initial position matrix.
Bases: pyffi.object_models.xml.struct_.StructBase
Obsolete, not decoded.
Bases: pyffi.object_models.xml.struct_.StructBase
Obsolete, not decoded.
Bases: pyffi.object_models.xml.struct_.StructBase
Obsolete, not decoded.
Bases: pyffi.formats.cgf.Ref
Reference to a chunk, down the hierarchy.
Ptr does not point down, so get_refs returns empty list.
Returns: | C{[]} |
---|
Bases: pyffi.object_models.xml.struct_.StructBase
A quaternion (x,y,z,w).
Fourth coordinate.
First coordinate.
Second coordinate.
Third coordinate.
Bases: pyffi.object_models.xml.basic.BasicBase
Reference to a chunk, up the hierarchy.
Resolve chunk index into a chunk.
Parameters: | block_dct (dict) – Dictionary mapping block index to block. |
---|
Return a hash value for the chunk referred to.
Returns: | An immutable object that can be used as a hash. |
---|
Return the chunk reference.
Returns: | Empty list if no reference, or single item list containing the reference. |
---|
Return the chunk reference.
Returns: | Empty list if no reference, or single item list containing the reference. |
---|
Return number of bytes this type occupies in a file.
Returns: | Number of bytes. |
---|
Get chunk being referred to.
Returns: | The chunk being referred to. |
---|
Read chunk index.
Parameters: | stream (file) – The stream to read from. |
---|
Set chunk reference.
Parameters: | value (L{CgfFormat.Chunk}) – The value to assign. |
---|
Write chunk index.
Parameters: | stream (file) – The stream to write to. |
---|
Bases: pyffi.object_models.xml.struct_.StructBase
Not decoded. Nowhere used?
Bases: pyffi.object_models.xml.basic.BasicBase, pyffi.object_models.editable.EditableLineEdit
Basic type for strings. The type starts with an unsigned int which describes the length of the string.
>>> from tempfile import TemporaryFile
>>> f = TemporaryFile()
>>> from pyffi.object_models import FileFormat
>>> data = FileFormat.Data()
>>> s = SizedString()
>>> if f.write('\x07\x00\x00\x00abcdefg'.encode("ascii")): pass # ignore result for py3k
>>> if f.seek(0): pass # ignore result for py3k
>>> s.read(f, data)
>>> str(s)
'abcdefg'
>>> if f.seek(0): pass # ignore result for py3k
>>> s.set_value('Hi There')
>>> s.write(f, data)
>>> if f.seek(0): pass # ignore result for py3k
>>> m = SizedString()
>>> m.read(f, data)
>>> str(m)
'Hi There'
Return a hash value for this string.
Returns: | An immutable object that can be used as a hash. |
---|
Return number of bytes this type occupies in a file.
Returns: | Number of bytes. |
---|
Return the string.
Returns: | The stored string. |
---|
Read string from stream.
Parameters: | stream (file) – The stream to read from. |
---|
Set string to C{value}.
Parameters: | value (str) – The value to assign. |
---|
Write string to stream.
Parameters: | stream (file) – The stream to write to. |
---|
alias of ZString
Bases: pyffi.object_models.common.FixedString
String of fixed length 128.
Bases: pyffi.object_models.common.FixedString
String of fixed length 16.
Bases: pyffi.object_models.common.FixedString
String of fixed length 256.
Bases: pyffi.object_models.common.FixedString
String of fixed length 32.
Bases: pyffi.object_models.common.FixedString
String of fixed length 64.
Bases: pyffi.object_models.xml.struct_.StructBase
Tangents. Divide each component by 32767 to get the actual value.
Handness? Either 32767 (+1.0) or -32767 (-1.0).
Bases: pyffi.object_models.xml.struct_.StructBase
Texture coordinate.
Bases: pyffi.object_models.xml.struct_.StructBase
A texture face (vertex indices).
First vertex index.
Second vertex index.
Third vertex index.
Bases: pyffi.formats.cgf.Chunk
Unknown. An extra block written by the XSI exporter.
alias of Bool
alias of Byte
alias of Char
alias of Float
alias of Int
alias of Short
alias of UByte
alias of UInt
alias of UShort
Converts version string into an integer.
Parameters: | version_str (str) – The version string. |
---|---|
Returns: | A version integer. |
>>> hex(CgfFormat.version_number('744'))
'0x744'
>>> # get file version and file type, and read cgf file
>>> stream = open('tests/cgf/test.cgf', 'rb')
>>> data = CgfFormat.Data()
>>> # read chunk table only
>>> data.inspect(stream)
>>> # check chunk types
>>> list(chunktype.__name__ for chunktype in data.chunk_table.get_chunk_types())
['SourceInfoChunk', 'TimingChunk']
>>> data.chunks # no chunks yet
[]
>>> # read full file
>>> data.read(stream)
>>> # get all chunks
>>> for chunk in data.chunks:
... print(chunk)
<class 'pyffi.formats.cgf.SourceInfoChunk'> instance at ...
* source_file : <None>
* date : Fri Sep 28 22:40:44 2007
* author : blender@BLENDER
<BLANKLINE>
<class 'pyffi.formats.cgf.TimingChunk'> instance at ...
* secs_per_tick : 0.000208333338378
* ticks_per_frame : 160
* global_range :
<class 'pyffi.formats.cgf.RangeEntity'> instance at ...
* name : GlobalRange
* start : 0
* end : 100
* num_sub_ranges : 0
<BLANKLINE>
>>> for stream, data in CgfFormat.walkData('tests/cgf'):
... print(stream.name)
... try:
... data.read(stream)
... except Exception:
... print("Warning: read failed due corrupt file, corrupt format description, or bug.")
... print(len(data.chunks))
... # do something with the chunks
... for chunk in data.chunks:
... chunk.apply_scale(2.0)
tests/cgf/invalid.cgf
Warning: read failed due corrupt file, corrupt format description, or bug.
0
tests/cgf/monkey.cgf
14
tests/cgf/test.cgf
2
tests/cgf/vcols.cgf
6
>>> from pyffi.formats.cgf import CgfFormat
>>> node1 = CgfFormat.NodeChunk()
>>> node1.name = "hello"
>>> node2 = CgfFormat.NodeChunk()
>>> node1.num_children = 1
>>> node1.children.update_size()
>>> node1.children[0] = node2
>>> node2.name = "world"
>>> from tempfile import TemporaryFile
>>> stream = TemporaryFile()
>>> data = CgfFormat.Data() # default is far cry
>>> data.chunks = [node1, node2]
>>> # note: write returns number of padding bytes
>>> data.write(stream)
0
>>> # py3k returns 0 on seek; this hack removes return code from doctest
>>> if stream.seek(0): pass
>>> data.inspect_version_only(stream)
>>> hex(data.header.version)
'0x744'
>>> data.read(stream)
>>> # get all chunks
>>> for chunk in data.chunks:
... print(chunk)
<class 'pyffi.formats.cgf.NodeChunk'> instance at 0x...
* name : hello
* object : None
* parent : None
* num_children : 1
* material : None
* is_group_head : False
* is_group_member : False
* reserved_1 :
<class 'pyffi.object_models.xml.array.Array'> instance at 0x...
0: 0
1: 0
* transform :
[ 0.000 0.000 0.000 0.000 ]
[ 0.000 0.000 0.000 0.000 ]
[ 0.000 0.000 0.000 0.000 ]
[ 0.000 0.000 0.000 0.000 ]
* pos : [ 0.000 0.000 0.000 ]
* rot :
<class 'pyffi.formats.cgf.Quat'> instance at 0x...
* x : 0.0
* y : 0.0
* z : 0.0
* w : 0.0
* scl : [ 0.000 0.000 0.000 ]
* pos_ctrl : None
* rot_ctrl : None
* scl_ctrl : None
* property_string : <None>
* children :
<class 'pyffi.object_models.xml.array.Array'> instance at 0x...
0: <class 'pyffi.formats.cgf.NodeChunk'> instance at 0x...
<BLANKLINE>
<class 'pyffi.formats.cgf.NodeChunk'> instance at 0x...
* name : world
* object : None
* parent : None
* num_children : 0
* material : None
* is_group_head : False
* is_group_member : False
* reserved_1 :
<class 'pyffi.object_models.xml.array.Array'> instance at 0x...
0: 0
1: 0
* transform :
[ 0.000 0.000 0.000 0.000 ]
[ 0.000 0.000 0.000 0.000 ]
[ 0.000 0.000 0.000 0.000 ]
[ 0.000 0.000 0.000 0.000 ]
* pos : [ 0.000 0.000 0.000 ]
* rot :
<class 'pyffi.formats.cgf.Quat'> instance at 0x...
* x : 0.0
* y : 0.0
* z : 0.0
* w : 0.0
* scl : [ 0.000 0.000 0.000 ]
* pos_ctrl : None
* rot_ctrl : None
* scl_ctrl : None
* property_string : <None>
* children : <class 'pyffi.object_models.xml.array.Array'> instance at 0x...
<BLANKLINE>