示例#1
0
    def __init__(self, vertices, center=None):
        Surface.__init__(self)

        c = center or _center_of_point_cloud(vertices)
        self.center = c

        num_vertices = len(vertices)
        if len(vertices) < 2:
            raise Exception('insufficient vertices')

        normal = self._compute_normal(c, vertices)
        v1 = vertices[0]
        i = Vector(v1.x - c.x, v1.y - c.y, v1.z - c.z)
        j = i.cross(normal)

        vertices = vertices[:]
        vertices.append(vertices[0])

        s = Surface()
        for index in xrange(num_vertices):
            a = vertices[index]
            b = vertices[index+1]

            a1 = Vector(a.x - c.x, a.y - c.y, a.z - c.z)
            a.tcoord = (a1.dot(i), a1.dot(j))

            face = Face(Edge(c, a), Edge(a, b), Edge(b, c))
            s.add(face)

        self.add(s)
示例#2
0
    def _compute_normal(self, center, vertices):
        
        normals = []
        c = center
        v1 = vertices[0]
        v1 = Vector(v1.x - c.x, v1.y - c.y, v1.z - c.z)

        for v in vertices[1:2]:
            v = Vector(v.x - c.x, v.y - c.y, v.z - c.z)
            n = v1.cross(v)
            normals.append(n.normalize())

        normal = Vector()
        for _n in normals:
            normal =  normal + _n
        
        return normal.normalize()