Ejemplo n.º 1
0
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3n3cp()
        vdata = GeomVertexData('plane', format, Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')

        for x in xrange(self._width):
            for y in xrange(self._height):
                cur_index = x * self._height + y
                vertex.addData3f(*self._points[cur_index][0:3])
                if self._normals:
                    normal.addData3f(*self._normals[cur_index])
                else:
                    normal.addData3f(0, 0, 1)
                color.addData4f(*self._color)

        self._vdata = vdata
Ejemplo n.º 2
0
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3n3cp()
        vdata = GeomVertexData("surface", format, Geom.UHDynamic)
        tri = GeomTriangles(Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, "vertex")
        normal = GeomVertexWriter(vdata, "normal")
        color = GeomVertexWriter(vdata, "color")

        for triangle in self._halfedge_mesh.faces:
            for v in triangle.iter_vertices():
                vertex.addData3f(*v.coordinates)
                normal.addData3f(*v.normal)
                color.addData4f(*self._color)
                tri.addNextVertices(1)

        self._vdata = vdata
        tri.closePrimitive()
        self._geom_primitives = [tri]
Ejemplo n.º 3
0
    def _create_vertex_data(self):
        """Creates and fills the vertex data store."""
        format = GeomVertexFormat.getV3n3cp()
        vdata = GeomVertexData('surface', format, Geom.UHDynamic)
        tri = GeomTriangles(Geom.UHDynamic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')

        vertmap = [(0, 1), (1, 2), (2, 3), (3, 0), (4, 5), (5, 6), (6, 7), (7, 4), (0, 4), (1, 5), (2, 6), (3, 7)]

        def generate_index(x, y, z):
            return x + \
                   y * (self._surface.mls_subdivisions+2) + \
                   z * (self._surface.mls_subdivisions+2)**2

        numbering_scheme = [
                (0, 0, 1),
                (1, 0, 1),
                (1, 0, 0),
                (0, 0, 0),
                (0, 1, 1),
                (1, 1, 1),
                (1, 1, 0),
                (0, 1, 0)]

        vertices = zeros((12,), dtype='3f')
        vertex_normals = zeros((12,), dtype='3f')
        # walk the cubes
        for x_index in range(self._surface.mls_subdivisions+1):
            for y_index in range(self._surface.mls_subdivisions+1):
                for z_index in range(self._surface.mls_subdivisions+1):
                    #points = map(lambda offsets: self._surface.mls_points[generate_index(array([x_index, y_index, z_index]) + offsets)], numbering_scheme)
                    points = [
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 0, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 0, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 0, z_index + 0)],
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 0, z_index + 0)],
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 1, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 1, z_index + 1)],
                            self._surface.mls_points[generate_index(x_index + 1, y_index + 1, z_index + 0)],
                            self._surface.mls_points[generate_index(x_index + 0, y_index + 1, z_index + 0)],
                            ]
                    values = [
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 0, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 0, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 0, z_index + 0)],
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 0, z_index + 0)],
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 1, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 1, z_index + 1)],
                            self._surface.mls_distances[generate_index(x_index + 1, y_index + 1, z_index + 0)],
                            self._surface.mls_distances[generate_index(x_index + 0, y_index + 1, z_index + 0)],
                            ]
                    #values = map(lambda offsets: self._surface.mls_distances[generate_index(array([x_index, y_index, z_index]) + offsets)], numbering_scheme)
                    cubeindex = self._get_cubeindex(values)
                    for n in range(12):
                        if self.edge_table[cubeindex] & (2**n):
                            t_v, t_n = self._interpolate(points[vertmap[n][0]], points[vertmap[n][1]], values[vertmap[n][0]], values[vertmap[n][1]])
                            vertices[n] = t_v
                            vertex_normals[n] = t_n/norm(t_n)
                        else:
                            vertices[n] = 0
                            vertex_normals[n] = 0

                    triangles = []
                    i = 0
                    while self.triangle_table[cubeindex][i] != -1:
                        triangles.append([self.triangle_table[cubeindex][i],
                                         self.triangle_table[cubeindex][i+1],
                                         self.triangle_table[cubeindex][i+2]])
                        i += 3

                    for triangle in triangles:
                        vertex.addData3f(*vertices[triangle[0]])
                        vertex.addData3f(*vertices[triangle[1]])
                        vertex.addData3f(*vertices[triangle[2]])
                        normal.addData3f(*vertex_normals[triangle[0]])
                        normal.addData3f(*vertex_normals[triangle[1]])
                        normal.addData3f(*vertex_normals[triangle[2]])
                        #color.addData4f(self._color[0], self._color[1], self._color[2], self._color[3])
                        #color.addData4f(self._color[0], self._color[1], self._color[2], self._color[3])
                        #color.addData4f(self._color[0], self._color[1], self._color[2], self._color[3])
                        color.addData4f(*self._color)
                        color.addData4f(*self._color)
                        color.addData4f(*self._color)
                        tri.addNextVertices(3)

        self._vdata = vdata
        tri.closePrimitive()
        self._geom_primitives = [tri, ]