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
[source]¶ Bases:
pyffi.object_models.xsd.FileFormat
This class implements the DAE format.
-
class
Data
(version=17039616)[source]¶ Bases:
pyffi.object_models.Data
A class to contain the actual collada data.
-
getVersion
()[source]¶ Get the collada version, as integer (for instance, 1.4.1 would be 0x01040100).
- Returns
The version, as integer.
-
inspect
(stream)[source]¶ 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.
-
-
class
Regression tests¶
Create a DAE file¶
>>> daedata = DaeFormat.Data()
>>> print(daedata.collada)
<...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)
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)
Traceback (most recent call last):
...
NotImplementedError