Regression tests
Read a CGF file
>>>
>>> stream = open('tests/cgf/test.cgf', 'rb')
>>> data = CgfFormat.Data()
>>>
>>> data.inspect(stream)
>>>
>>> list(chunktype.__name__ for chunktype in data.chunk_table.get_chunk_types())
['SourceInfoChunk', 'TimingChunk']
>>> data.chunks
[]
>>>
>>> data.read(stream)
>>>
>>> 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>
Parse all CGF files in a directory tree
>>> 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))
...
... 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
Create a CGF file from scratch
>>> 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()
>>> data.chunks = [node1, node2]
>>>
>>> data.write(stream)
0
>>>
>>> if stream.seek(0): pass
>>> data.inspect_version_only(stream)
>>> hex(data.header.version)
'0x744'
>>> data.read(stream)
>>>
>>> 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>