Esempio n. 1
0
    def triangleset(self):
        """This performs a simple triangulation of the polylist using the fanning method.

        :rtype: :class:`collada.triangleset.TriangleSet`
        """

        if self._triangleset is None:
            indexselector = numpy.zeros(self.nvertices) == 0
            indexselector[self.polyindex[:, 1] - 1] = False
            indexselector[self.polyindex[:, 1] - 2] = False
            indexselector = numpy.arange(self.nvertices)[indexselector]

            firstpolyindex = numpy.arange(self.nvertices)
            firstpolyindex = firstpolyindex - numpy.repeat(
                self.polyends - self.vcounts, self.vcounts)
            firstpolyindex = firstpolyindex[indexselector]

            if len(self.index) > 0:
                triindex = numpy.dstack(
                    (self.index[indexselector - firstpolyindex],
                     self.index[indexselector + 1],
                     self.index[indexselector + 2]))
                triindex = numpy.swapaxes(triindex, 1, 2).flatten()
            else:
                triindex = numpy.array([], dtype=self.index.dtype)

            triset = triangleset.TriangleSet(self.sources, self.material,
                                             triindex, self.xmlnode)

            self._triangleset = triset
        return self._triangleset
Esempio n. 2
0
    def createTriangleSet(self, indices, inputlist, materialid):
        """Create a set of triangles for use in this geometry instance.

        :param numpy.array indices:
          unshaped numpy array that contains the indices for
          the inputs referenced in inputlist
        :param collada.source.InputList inputlist:
          The inputs for this primitive
        :param str materialid:
          A string containing a symbol that will get used to bind this triangleset
          to a material when instantiating into a scene

        :rtype: :class:`collada.triangleset.TriangleSet`
        """
        inputdict = primitive.Primitive._getInputsFromList(self.collada, self.sourceById, inputlist.getList())
        return triangleset.TriangleSet(inputdict, materialid, indices)