pyffi.formats.dae — COLLADA (.dae)

Warning

This module is not yet fully implemented, and is certainly not yet useful in its current state.

Implementation

class pyffi.formats.dae.DaeFormat

Bases: pyffi.object_models.xsd.FileFormat

This class implements the DAE format.

class Data(version=17039616)

Bases: pyffi.object_models.Data

A class to contain the actual collada data.

getVersion()

Get the collada version, as integer (for instance, 1.4.1 would be 0x01040100).

Returns

The version, as integer.

inspect(stream)

Quickly checks whether the stream appears to contain collada data. Resets stream to original position. If the stream turns out to be collada, L{getVersion} is guaranteed to return the version.

Call this function if you simply wish to check that a file is a collada file without having to parse it completely.

Parameters

stream (file) – The file to inspect.

Returns

True if stream is collada, False otherwise.

read(stream)

Read collada data from stream.

Parameters

stream (file) – The file to read from.

write(stream)

Write collada data to stream.

Parameters

stream (file) – The file to write to.

Regression tests

Create a DAE file

>>> daedata = DaeFormat.Data()
>>> print(daedata.collada) # doctest: +ELLIPSIS
<...Collada object at ...>

Read a DAE file

>>> from os.path import dirname
>>> dirpath = __file__
>>> for i in range(4): #recurse up to root repo dir
...     dirpath = dirname(dirpath)
>>> repo_root = dirpath
>>> format_root = os.path.join(repo_root, 'tests', 'formats', 'dae')
>>> # check and read dae file
>>> stream = open(os.path.join(format_root, 'cube.dae'), 'rb')
>>> daedata = DaeFormat.Data()
>>> daedata.read(stream) # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
NotImplementedError
>>> # get DAE file root element
>>> #print(daedata.getRootElement())
>>> stream.close()

Parse all DAE files in a directory tree

>>> for stream, data in DaeFormat.walkData(format_root):
...     try:
...         # the replace call makes the doctest also pass on windows
...         os_path = stream.name
...         split = (os_path.split(os.sep))[-4:]
...         rejoin = os.path.join(*split).replace(os.sep, "/")
...         print("reading %s" % rejoin)
...         data.read(stream)
...     except Exception:
...         print("Warning: read failed due corrupt file, corrupt format description, or bug.")
reading tests/formats/dae/cube.dae
Warning: read failed due corrupt file, corrupt format description, or bug.

Create a DAE file from scratch and write to file

>>> daedata = DaeFormat.Data()
>>> from tempfile import TemporaryFile
>>> stream = TemporaryFile()
>>> daedata.write(stream) # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
NotImplementedError