Home | Trees | Indices | Help |
|
---|
|
1 """ 2 :mod:`pyffi.formats.dae` --- COLLADA (.dae) 3 =========================================== 4 5 .. warning:: 6 7 This module is not yet fully implemented, and is certainly not 8 yet useful in its current state. 9 10 Implementation 11 -------------- 12 13 .. autoclass:: DaeFormat 14 :show-inheritance: 15 :members: 16 17 Regression tests 18 ---------------- 19 20 Create a DAE file 21 ^^^^^^^^^^^^^^^^^ 22 23 >>> daedata = DaeFormat.Data() 24 >>> print(daedata.collada) # doctest: +ELLIPSIS 25 <pyffi.formats.dae.Collada object at ...> 26 27 Read a DAE file 28 ^^^^^^^^^^^^^^^ 29 30 >>> # check and read dae file 31 >>> stream = open('tests/dae/cube.dae', 'rb') 32 >>> daedata = DaeFormat.Data() 33 >>> daedata.read(stream) # doctest: +ELLIPSIS 34 Traceback (most recent call last): 35 ... 36 NotImplementedError 37 >>> # get DAE file root element 38 >>> #print(daedata.getRootElement()) 39 >>> stream.close() 40 41 Parse all DAE files in a directory tree 42 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 43 44 >>> for stream, data in DaeFormat.walkData('tests/dae'): 45 ... try: 46 ... # the replace call makes the doctest also pass on windows 47 ... print("reading %s" % stream.name.replace("\\\\", "/")) 48 ... data.read(stream) 49 ... except Exception: 50 ... print("Warning: read failed due corrupt file, corrupt format description, or bug.") 51 reading tests/dae/cube.dae 52 Warning: read failed due corrupt file, corrupt format description, or bug. 53 54 Create a DAE file from scratch and write to file 55 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 56 57 >>> daedata = DaeFormat.Data() 58 >>> from tempfile import TemporaryFile 59 >>> stream = TemporaryFile() 60 >>> daedata.write(stream) # doctest: +ELLIPSIS 61 Traceback (most recent call last): 62 ... 63 NotImplementedError 64 """ 65 66 # ***** BEGIN LICENSE BLOCK ***** 67 # 68 # Copyright (c) 2007-2011, Python File Format Interface 69 # All rights reserved. 70 # 71 # Redistribution and use in source and binary forms, with or without 72 # modification, are permitted provided that the following conditions 73 # are met: 74 # 75 # * Redistributions of source code must retain the above copyright 76 # notice, this list of conditions and the following disclaimer. 77 # 78 # * Redistributions in binary form must reproduce the above 79 # copyright notice, this list of conditions and the following 80 # disclaimer in the documentation and/or other materials provided 81 # with the distribution. 82 # 83 # * Neither the name of the Python File Format Interface 84 # project nor the names of its contributors may be used to endorse 85 # or promote products derived from this software without specific 86 # prior written permission. 87 # 88 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 89 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 90 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 91 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 92 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 93 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 94 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 95 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 96 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 97 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 98 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 99 # POSSIBILITY OF SUCH DAMAGE. 100 # 101 # ***** END LICENSE BLOCK ***** 102 103 import struct 104 import os 105 import re 106 107 import pyffi.object_models.xsd 108110 """This class implements the DAE format.""" 111 xsdFileName = 'COLLADASchema.xsd' 112 # where to look for the xsd file and in what order: 113 # DAEXSDPATH env var, or XsdFormat module directory 114 xsdFilePath = [os.getenv('DAEXSDPATH'), os.path.dirname(__file__)] 115 # file name regular expression match 116 RE_FILENAME = re.compile(r'^.*\.dae$', re.IGNORECASE) 117 # used for comparing floats 118 _EPSILON = 0.0001 119174 175 # basic types 176 # TODO 177 178 # implementation of dae-specific basic types 179 # TODO 180121 """A class to contain the actual collada data.""" 122124 """Initialize collada data. By default, this creates an 125 empty collada 1.4.1 root element. 126 127 :param version: The collada version (for instance, 0x01040100 for 128 1.4.1). 129 :type version: int 130 """ 131 # TODO integrate the Collada and Data elements 132 self.collada = DaeFormat.Collada()133135 """Get the collada version, as integer (for instance, 1.4.1 would be 136 0x01040100). 137 138 :return: The version, as integer. 139 """ 140 return 0x01040100141 142 # overriding pyffi.object_models.FileFormat.Data methods 143145 """Quickly checks whether the stream appears to contain 146 collada data. Resets stream to original position. If the stream 147 turns out to be collada, L{getVersion} is guaranteed to return 148 the version. 149 150 Call this function if you simply wish to check that a file is 151 a collada file without having to parse it completely. 152 153 :param stream: The file to inspect. 154 :type stream: file 155 :return: ``True`` if stream is collada, ``False`` otherwise. 156 """ 157 raise NotImplementedError158160 """Read collada data from stream. 161 162 :param stream: The file to read from. 163 :type stream: file 164 """ 165 raise NotImplementedError166
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Oct 10 19:04:13 2011 | http://epydoc.sourceforge.net |