def polygons(self): """Iterate through all the polygons contained in the set. :rtype: generator of :class:`collada.polylist.Polygon` """ for i in xrange(self.npolygons): yield self[i]
def triangles(self): """Iterate through all the triangles contained in the set. :rtype: generator of :class:`collada.triangleset.Triangle` """ for i in xrange(self.ntriangles): yield self[i]
def lines(self): """Iterate through all the lines contained in the set. :rtype: generator of :class:`collada.lineset.Line` """ for i in xrange(self.nlines): yield self[i]
def __init__(self, sources, material, index, xmlnode=None): """A TriangleSet should not be created manually. Instead, call the :meth:`collada.geometry.Geometry.createTriangleSet` method after creating a geometry instance. """ if len(sources) == 0: raise DaeIncompleteError( 'A triangle set needs at least one input for vertex positions') if not 'VERTEX' in sources: raise DaeIncompleteError('Triangle set requires vertex input') max_offset = max([ max([input[0] for input in input_type_array]) for input_type_array in sources.values() if len(input_type_array) > 0 ]) self.material = material self.index = index self.indices = self.index self.nindices = max_offset + 1 self.index.shape = (-1, 3, self.nindices) self.ntriangles = len(self.index) self.sources = sources if len(self.index) > 0: self._vertex = sources['VERTEX'][0][4].data self._vertex_index = self.index[:, :, sources['VERTEX'][0][0]] self.maxvertexindex = numpy.max(self._vertex_index) checkSource(sources['VERTEX'][0][4], ('X', 'Y', 'Z'), self.maxvertexindex) else: self._vertex = None self._vertex_index = None self.maxvertexindex = -1 if 'NORMAL' in sources and len(sources['NORMAL']) > 0 and len( self.index) > 0: self._normal = sources['NORMAL'][0][4].data self._normal_index = self.index[:, :, sources['NORMAL'][0][0]] self.maxnormalindex = numpy.max(self._normal_index) checkSource(sources['NORMAL'][0][4], ('X', 'Y', 'Z'), self.maxnormalindex) else: self._normal = None self._normal_index = None self.maxnormalindex = -1 if 'TEXCOORD' in sources and len(sources['TEXCOORD']) > 0 and len( self.index) > 0: self._texcoordset = tuple( [texinput[4].data for texinput in sources['TEXCOORD']]) self._texcoord_indexset = tuple([ self.index[:, :, sources['TEXCOORD'][i][0]] for i in xrange(len(sources['TEXCOORD'])) ]) self.maxtexcoordsetindex = [ numpy.max(tex_index) for tex_index in self._texcoord_indexset ] for i, texinput in enumerate(sources['TEXCOORD']): checkSource(texinput[4], ('S', 'T'), self.maxtexcoordsetindex[i]) else: self._texcoordset = tuple() self._texcoord_indexset = tuple() self.maxtexcoordsetindex = -1 if 'TEXTANGENT' in sources and len(sources['TEXTANGENT']) > 0 and len( self.index) > 0: self._textangentset = tuple( [texinput[4].data for texinput in sources['TEXTANGENT']]) self._textangent_indexset = tuple([ self.index[:, :, sources['TEXTANGENT'][i][0]] for i in xrange(len(sources['TEXTANGENT'])) ]) self.maxtextangentsetindex = [ numpy.max(tex_index) for tex_index in self._textangent_indexset ] for i, texinput in enumerate(sources['TEXTANGENT']): checkSource(texinput[4], ('X', 'Y', 'Z'), self.maxtextangentsetindex[i]) else: self._textangentset = tuple() self._textangent_indexset = tuple() self.maxtextangentsetindex = -1 if 'TEXBINORMAL' in sources and len( sources['TEXBINORMAL']) > 0 and len(self.index) > 0: self._texbinormalset = tuple( [texinput[4].data for texinput in sources['TEXBINORMAL']]) self._texbinormal_indexset = tuple([ self.index[:, :, sources['TEXBINORMAL'][i][0]] for i in xrange(len(sources['TEXBINORMAL'])) ]) self.maxtexbinormalsetindex = [ numpy.max(tex_index) for tex_index in self._texbinormal_indexset ] for i, texinput in enumerate(sources['TEXBINORMAL']): checkSource(texinput[4], ('X', 'Y', 'Z'), self.maxtexbinormalsetindex[i]) else: self._texbinormalset = tuple() self._texbinormal_indexset = tuple() self.maxtexbinormalsetindex = -1 if xmlnode is not None: self.xmlnode = xmlnode else: self._recreateXmlNode()
def __init__(self, sources, material, index, xmlnode=None): """A TriangleSet should not be created manually. Instead, call the :meth:`collada.geometry.Geometry.createTriangleSet` method after creating a geometry instance. """ if len(sources) == 0: raise DaeIncompleteError("A triangle set needs at least one input for vertex positions") if not "VERTEX" in sources: raise DaeIncompleteError("Triangle set requires vertex input") max_offset = max( [ max([input[0] for input in input_type_array]) for input_type_array in sources.values() if len(input_type_array) > 0 ] ) self.material = material self.index = index self.indices = self.index self.nindices = max_offset + 1 self.index.shape = (-1, 3, self.nindices) self.ntriangles = len(self.index) self.sources = sources if len(self.index) > 0: self._vertex = sources["VERTEX"][0][4].data self._vertex_index = self.index[:, :, sources["VERTEX"][0][0]] self.maxvertexindex = numpy.max(self._vertex_index) checkSource(sources["VERTEX"][0][4], ("X", "Y", "Z"), self.maxvertexindex) else: self._vertex = None self._vertex_index = None self.maxvertexindex = -1 if "NORMAL" in sources and len(sources["NORMAL"]) > 0 and len(self.index) > 0: self._normal = sources["NORMAL"][0][4].data self._normal_index = self.index[:, :, sources["NORMAL"][0][0]] self.maxnormalindex = numpy.max(self._normal_index) checkSource(sources["NORMAL"][0][4], ("X", "Y", "Z"), self.maxnormalindex) else: self._normal = None self._normal_index = None self.maxnormalindex = -1 if "TEXCOORD" in sources and len(sources["TEXCOORD"]) > 0 and len(self.index) > 0: self._texcoordset = tuple([texinput[4].data for texinput in sources["TEXCOORD"]]) self._texcoord_indexset = tuple( [self.index[:, :, sources["TEXCOORD"][i][0]] for i in xrange(len(sources["TEXCOORD"]))] ) self.maxtexcoordsetindex = [numpy.max(tex_index) for tex_index in self._texcoord_indexset] for i, texinput in enumerate(sources["TEXCOORD"]): checkSource(texinput[4], ("S", "T"), self.maxtexcoordsetindex[i]) else: self._texcoordset = tuple() self._texcoord_indexset = tuple() self.maxtexcoordsetindex = -1 if "TEXTANGENT" in sources and len(sources["TEXTANGENT"]) > 0 and len(self.index) > 0: self._textangentset = tuple([texinput[4].data for texinput in sources["TEXTANGENT"]]) self._textangent_indexset = tuple( [self.index[:, :, sources["TEXTANGENT"][i][0]] for i in xrange(len(sources["TEXTANGENT"]))] ) self.maxtextangentsetindex = [numpy.max(tex_index) for tex_index in self._textangent_indexset] for i, texinput in enumerate(sources["TEXTANGENT"]): checkSource(texinput[4], ("X", "Y", "Z"), self.maxtextangentsetindex[i]) else: self._textangentset = tuple() self._textangent_indexset = tuple() self.maxtextangentsetindex = -1 if "TEXBINORMAL" in sources and len(sources["TEXBINORMAL"]) > 0 and len(self.index) > 0: self._texbinormalset = tuple([texinput[4].data for texinput in sources["TEXBINORMAL"]]) self._texbinormal_indexset = tuple( [self.index[:, :, sources["TEXBINORMAL"][i][0]] for i in xrange(len(sources["TEXBINORMAL"]))] ) self.maxtexbinormalsetindex = [numpy.max(tex_index) for tex_index in self._texbinormal_indexset] for i, texinput in enumerate(sources["TEXBINORMAL"]): checkSource(texinput[4], ("X", "Y", "Z"), self.maxtexbinormalsetindex[i]) else: self._texbinormalset = tuple() self._texbinormal_indexset = tuple() self.maxtexbinormalsetindex = -1 if xmlnode is not None: self.xmlnode = xmlnode else: self._recreateXmlNode()
def __init__(self, sources, material, index, vcounts, xmlnode=None): """A Polylist should not be created manually. Instead, call the :meth:`collada.geometry.Geometry.createPolylist` method after creating a geometry instance. """ if len(sources) == 0: raise DaeIncompleteError( 'A polylist set needs at least one input for vertex positions') if not 'VERTEX' in sources: raise DaeIncompleteError('Polylist requires vertex input') #find max offset max_offset = max([ max([input[0] for input in input_type_array]) for input_type_array in sources.values() if len(input_type_array) > 0 ]) self.material = material self.index = index self.indices = self.index self.nindices = max_offset + 1 self.vcounts = vcounts self.sources = sources self.index.shape = (-1, self.nindices) self.npolygons = len(self.vcounts) self.nvertices = numpy.sum(self.vcounts) if len(self.index) > 0 else 0 self.polyends = numpy.cumsum(self.vcounts) self.polystarts = self.polyends - self.vcounts self.polyindex = numpy.dstack((self.polystarts, self.polyends))[0] if len(self.index) > 0: self._vertex = sources['VERTEX'][0][4].data self._vertex_index = self.index[:, sources['VERTEX'][0][0]] self.maxvertexindex = numpy.max(self._vertex_index) checkSource(sources['VERTEX'][0][4], ('X', 'Y', 'Z'), self.maxvertexindex) else: self._vertex = None self._vertex_index = None self.maxvertexindex = -1 if 'NORMAL' in sources and len(sources['NORMAL']) > 0 and len( self.index) > 0: self._normal = sources['NORMAL'][0][4].data self._normal_index = self.index[:, sources['NORMAL'][0][0]] self.maxnormalindex = numpy.max(self._normal_index) checkSource(sources['NORMAL'][0][4], ('X', 'Y', 'Z'), self.maxnormalindex) else: self._normal = None self._normal_index = None self.maxnormalindex = -1 if 'TEXCOORD' in sources and len(sources['TEXCOORD']) > 0 \ and len(self.index) > 0: self._texcoordset = tuple( [texinput[4].data for texinput in sources['TEXCOORD']]) self._texcoord_indexset = tuple([ self.index[:, sources['TEXCOORD'][i][0]] for i in xrange(len(sources['TEXCOORD'])) ]) self.maxtexcoordsetindex = [ numpy.max(each) for each in self._texcoord_indexset ] for i, texinput in enumerate(sources['TEXCOORD']): checkSource(texinput[4], ('S', 'T'), self.maxtexcoordsetindex[i]) else: self._texcoordset = tuple() self._texcoord_indexset = tuple() self.maxtexcoordsetindex = -1 if xmlnode is not None: self.xmlnode = xmlnode """ElementTree representation of the line set.""" else: txtindices = ' '.join(map(str, self.indices.flatten().tolist())) acclen = len(self.indices) self.xmlnode = E.polylist(count=str(self.npolygons), material=self.material) all_inputs = [] for semantic_list in self.sources.values(): all_inputs.extend(semantic_list) for offset, semantic, sourceid, set, src in all_inputs: inpnode = E.input(offset=str(offset), semantic=semantic, source=sourceid) if set is not None: inpnode.set('set', str(set)) self.xmlnode.append(inpnode) vcountnode = E.vcount(' '.join(map(str, self.vcounts))) self.xmlnode.append(vcountnode) self.xmlnode.append(E.p(txtindices))
def __init__(self, sources, material, index, vcounts, xmlnode=None): """A Polylist should not be created manually. Instead, call the :meth:`collada.geometry.Geometry.createPolylist` method after creating a geometry instance. """ if len(sources) == 0: raise DaeIncompleteError('A polylist set needs at least one input for vertex positions') if not 'VERTEX' in sources: raise DaeIncompleteError('Polylist requires vertex input') #find max offset max_offset = max([ max([input[0] for input in input_type_array]) for input_type_array in sources.values() if len(input_type_array) > 0]) self.material = material self.index = index self.indices = self.index self.nindices = max_offset + 1 self.vcounts = vcounts self.sources = sources self.index.shape = (-1, self.nindices) self.npolygons = len(self.vcounts) self.nvertices = numpy.sum(self.vcounts) if len(self.index) > 0 else 0 self.polyends = numpy.cumsum(self.vcounts) self.polystarts = self.polyends - self.vcounts self.polyindex = numpy.dstack((self.polystarts, self.polyends))[0] if len(self.index) > 0: self._vertex = sources['VERTEX'][0][4].data self._vertex_index = self.index[:,sources['VERTEX'][0][0]] self.maxvertexindex = numpy.max( self._vertex_index ) checkSource(sources['VERTEX'][0][4], ('X', 'Y', 'Z'), self.maxvertexindex) else: self._vertex = None self._vertex_index = None self.maxvertexindex = -1 if 'NORMAL' in sources and len(sources['NORMAL']) > 0 and len(self.index) > 0: self._normal = sources['NORMAL'][0][4].data self._normal_index = self.index[:,sources['NORMAL'][0][0]] self.maxnormalindex = numpy.max( self._normal_index ) checkSource(sources['NORMAL'][0][4], ('X', 'Y', 'Z'), self.maxnormalindex) else: self._normal = None self._normal_index = None self.maxnormalindex = -1 if 'TEXCOORD' in sources and len(sources['TEXCOORD']) > 0 \ and len(self.index) > 0: self._texcoordset = tuple([texinput[4].data for texinput in sources['TEXCOORD']]) self._texcoord_indexset = tuple([ self.index[:,sources['TEXCOORD'][i][0]] for i in xrange(len(sources['TEXCOORD'])) ]) self.maxtexcoordsetindex = [numpy.max(each) for each in self._texcoord_indexset] for i, texinput in enumerate(sources['TEXCOORD']): checkSource(texinput[4], ('S', 'T'), self.maxtexcoordsetindex[i]) else: self._texcoordset = tuple() self._texcoord_indexset = tuple() self.maxtexcoordsetindex = -1 if xmlnode is not None: self.xmlnode = xmlnode """ElementTree representation of the line set.""" else: txtindices = ' '.join(map(str, self.indices.flatten().tolist())) acclen = len(self.indices) self.xmlnode = E.polylist(count=str(self.npolygons), material=self.material) all_inputs = [] for semantic_list in self.sources.values(): all_inputs.extend(semantic_list) for offset, semantic, sourceid, set, src in all_inputs: inpnode = E.input(offset=str(offset), semantic=semantic, source=sourceid) if set is not None: inpnode.set('set', str(set)) self.xmlnode.append(inpnode) vcountnode = E.vcount(' '.join(map(str, self.vcounts))) self.xmlnode.append(vcountnode) self.xmlnode.append(E.p(txtindices))