Ejemplo n.º 1
0
    def createPolyhedron(self, parent=None, name=None):
        """Create a polyhedron from the current set of faces.

        Returns the Polyhedron object.
        """

        # Build lookup tables (so that only the verts that are really
        # required are stored in the Polyhedron)
        #
        # Key: Original vertex index - Value: New vertex index
        vert_lut = {}
        has_normals = True
        has_tverts = True
        iv = 0
        for f in self.faces:
            for v,tv,n in f:
                if v not in vert_lut:
                    vert_lut[v] = iv
                    iv+=1
                if tv==None:
                    has_tverts = False
                if n==None:
                    has_normals = False

        numpolys = len(self.faces)
        numverts = len(vert_lut)

        pg = PolyhedronGeom()
        pg.verts.resize(numverts)
        pg.setNumPolys(numpolys)

        # Set vertices
        for v in vert_lut:
            newidx = vert_lut[v]
            pg.verts[newidx] = self.verts[v]

        # Set polys (this has to be done *before* any FACEVARYING variable
        # is created, otherwise the size of the variable wouldn't be known)
        idx = 0
        for i,f in enumerate(self.faces):
            loop = []
            for v,tv,n in f:
                loop.append(vert_lut[v])
            pg.setPoly(i,[loop])

        # Create variable N for storing the normals
        if has_normals:
            pg.newVariable("N", FACEVARYING, NORMAL)
            N = pg.slot("N")
            idx = 0
            for f in self.faces:
                for v,tv,n in f:
                    N[idx] = self.normals[n]
                    idx += 1

        # Set texture vertices
        if has_tverts:
            pg.newVariable("st", FACEVARYING, FLOAT, 2)
            st = pg.slot("st")
            idx = 0
            for f in self.faces:
                for v,tv,n in f:
                    st[idx] = self.tverts[tv]
                    idx += 1

        obj = Polyhedron(name=name, parent=parent)
        obj.geom = pg
        # Set the materials
        self.initMaterial(obj)
        return obj
Ejemplo n.º 2
0
    def createPolyhedron(self, parent=None, name=None):
        """Create a polyhedron from the current set of faces.

        Returns the Polyhedron object.
        """

        # Build lookup tables (so that only the verts that are really
        # required are stored in the Polyhedron)
        #
        # Key: Original vertex index - Value: New vertex index
        vert_lut = {}
        has_normals = True
        has_tverts = True
        iv = 0
        for f in self.faces:
            for v, tv, n in f:
                if v not in vert_lut:
                    vert_lut[v] = iv
                    iv += 1
                if tv == None:
                    has_tverts = False
                if n == None:
                    has_normals = False

        numpolys = len(self.faces)
        numverts = len(vert_lut)

        pg = PolyhedronGeom()
        pg.verts.resize(numverts)
        pg.setNumPolys(numpolys)

        # Set vertices
        for v in vert_lut:
            newidx = vert_lut[v]
            pg.verts[newidx] = self.verts[v]

        # Set polys (this has to be done *before* any FACEVARYING variable
        # is created, otherwise the size of the variable wouldn't be known)
        idx = 0
        for i, f in enumerate(self.faces):
            loop = []
            for v, tv, n in f:
                loop.append(vert_lut[v])
            pg.setPoly(i, [loop])

        # Create variable N for storing the normals
        if has_normals:
            pg.newVariable("N", FACEVARYING, NORMAL)
            N = pg.slot("N")
            idx = 0
            for f in self.faces:
                for v, tv, n in f:
                    N[idx] = self.normals[n]
                    idx += 1

        # Set texture vertices
        if has_tverts:
            pg.newVariable("st", FACEVARYING, FLOAT, 2)
            st = pg.slot("st")
            idx = 0
            for f in self.faces:
                for v, tv, n in f:
                    st[idx] = self.tverts[tv]
                    idx += 1

        obj = Polyhedron(name=name, parent=parent)
        obj.geom = pg
        # Set the materials
        self.initMaterial(obj)
        return obj