Exemple #1
0
 def create_mesh(self):
     """ Create real mesh object from the geometry and material """
     vertices = []
     indices = []
     idx = 0
     for face in self.geometry.faces:
         for i, k in enumerate(['a', 'b', 'c']):
             v_idx = getattr(face, k)
             vertex = self.geometry.vertices[v_idx]
             vertices.extend(vertex)
             try:
                 normal = face.vertex_normals[i]
             except IndexError:
                 normal = Vector3([0, 0, 0])
             vertices.extend(normal)
             try:
                 tex_coords = self.geometry.face_vertex_uvs[0][idx]
                 vertices.extend(tex_coords)
             except IndexError:
                 vertices.extend([0, 0])
             indices.append(idx)
             idx += 1
     kw = {
         "vertices": vertices,
         "indices": indices,
         "fmt": self.vertex_format,
         "mode": self.mode
     }
     if self.material.map:
         kw["texture"] = self.material.map
     self._mesh = KivyMesh(**kw)
Exemple #2
0
    def create_mesh(self):
        """ Create real mesh object from the geometry and material """
        vertices = []
        indices = []

        a = math.radians(360 / (self.peaks * 2))
        for i in range(int(self.peaks * 2)):
            tx = math.cos(i * a)
            x = tx * (self.inner_radius + (i % 2) *
                      (self.outer_radius - self.inner_radius))
            y = 0
            tz = math.sin(i * a)
            z = tz * (self.inner_radius + (i % 2) *
                      (self.outer_radius - self.inner_radius))
            vertices.extend([x, y, z, 0, 1, 0, x, z])
            indices.append(len(indices))

        kw = {
            "vertices": vertices,
            "indices": indices,
            "fmt": self.vertex_format,
            "mode": self.mode
        }
        if self.material.map:
            kw["texture"] = self.material.map
        self._mesh = KivyMesh(**kw)
Exemple #3
0
 def create_mesh(self):
     """ Create real mesh object from the geometry and material """
     vertices = []
     indices = []
     idx = 0
     for face in self.geometry.faces:
         for i, k in enumerate(['a', 'b', 'c']):
             v_idx = getattr(face, k)
             vertex = self.geometry.vertices[v_idx]
             vertices.extend(vertex)
             try:
                 normal = face.vertex_normals[i]
             except IndexError:
                 normal = Vector3([0, 0, 0])
             vertices.extend(normal)
             try:
                 tex_coords = self.geometry.face_vertex_uvs[0][idx]
                 vertices.extend(tex_coords)
             except IndexError:
                 vertices.extend([0, 0])
             indices.append(idx)
             idx += 1
     if idx >= 65535 - 1:
         msg = 'Mesh must not contain more than 65535 indices, {} given'
         raise ValueError(msg.format(idx + 1))
     kw = dict(
         vertices=vertices,
         indices=indices,
         fmt=self.vertex_format,
         mode=self.mesh_mode
     )
     if self.material.map:
         kw['texture'] = self.material.map
     self._mesh = KivyMesh(**kw)
Exemple #4
0
    def create_mesh(self):
        """ Create real mesh object from the geometry and material """
        vertices = []
        indices = []

        for p in self.points:
            vertices.extend(list(p) + [0, 1, 0, p[0], p[2]])
            indices.append(len(indices))

        kw = {
            "vertices": vertices,
            "indices": indices,
            "fmt": self.vertex_format,
            "mode": self.mode
        }
        if self.material.map:
            kw["texture"] = self.material.map
        self._mesh = KivyMesh(**kw)
Exemple #5
0
    def __init__(self, v0, v1, v2, normals, material, **kw):
        super(STLMesh, self).__init__(**kw)
        self.vertex_format = kw.pop('vertex_format', DEFAULT_VERTEX_FORMAT)
        self.mesh_mode = kw.pop('mesh_mode', DEFAULT_MESH_MODE)
        self.material = material
        self.v0 = v0
        self.v1 = v1
        self.v2 = v2
        self.normals = normals
        indices = list(range(0,len(self.v0)*3))
        uvs = np.zeros((len(self.v0), 2)).astype(np.float32)
        vertices = np.block([self.v0,self.normals,uvs,self.v1,self.normals,uvs,self.v2,self.normals,uvs]).flatten()

        kw=dict(vertices=vertices,
                indices=indices,
                fmt=self.vertex_format,
                mode=self.mesh_mode)

        if self.material.map:
            kw['texture'] = self.material.map
        self._mesh = KivyMesh(**kw)
Exemple #6
0
 def create_mesh(self):
     """ Create real mesh object from the geometry and material """
     vertices = [Vector3([0, 0, 0])]
     indices = [0]
     a = math.radians(360 / self.num_points)
     for i in range(self.num_points):
         vertices.append(
             Vector3([
                 math.cos(a * i) * self.radius, 0,
                 math.sin(a * i) * self.radius
             ]))
         indices.append(len(indices))
     kw = {
         "vertices": vertices,
         "indices": indices,
         "fmt": self.vertex_format,
         "mode": "triangle_fan"
     }
     # if self.material.map:
     #     kw["texture"] = self.material.map
     self._mesh = KivyMesh(**kw)
Exemple #7
0
    def create_mesh(self):
        """ Create real mesh object from the geometry and material """
        x, y, z = 0.5 * self.size.x, 0.5 * self.size.y, 0.5 * self.size.z
        vertices = [
            x, y, z, x, y, z, 0, 0, -x, y, z, -x, y, z, 0, 0, -x, y, -z, -x, y,
            -z, 0, 0, x, y, -z, x, y, -z, 0, 0, x, -y, z, x, -y, z, 0, 0, -x,
            -y, z, -x, -y, z, 0, 0, -x, -y, -z, -x, -y, -z, 0, 0, x, -y, -z, x,
            -y, -z, 0, 0
        ]
        indices = [
            0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6,
            3, 7
        ]

        kw = {
            "vertices": vertices,
            "indices": indices,
            "fmt": self.vertex_format,
            "mode": self.mode
        }
        if self.material.map:
            kw["texture"] = self.material.map
        self._mesh = KivyMesh(**kw)
Exemple #8
0
    def loadSingle(obj, texf=None):
        assert len(obj.materials) == 1
        material = obj.materials[0]

        if texf is None:
            texf = material.texture.image_name
        tex = Image(texf).texture

        vertices = material.vertices
        nVertex = len(vertices) / material.vertex_size
        indices = np.arange(nVertex).astype(int).tolist()
        fmt = OBJLoader.formats(material.vertex_format)

        kw = {
            "vertices": vertices,
            "indices": indices,
            "fmt": fmt,
            "mode": "triangles",
            'texture': tex
        }

        mesh = KivyMesh(**kw)
        mat = Material(tex)
        return mesh, mat
Exemple #9
0
    def create_mesh(self):
        """ Create real mesh object from the geometry and material """
        vertices = []
        indices = [0, 1, 2, 3]

        # define basis vectors
        if self.orientation == "x":
            bx = Vector3([0, 0, -1])
            by = Vector3([0, -1, 0])
            normal = Vector3([-1, 0, 0])
        elif self.orientation == "y":
            bx = Vector3([-1, 0, 0])
            by = Vector3([0, 0, -1])
            normal = Vector3([0, 1, 0])
        else:
            bx = Vector3([-1, 0, 0])
            by = Vector3([0, -1, 0])
            normal = Vector3([0, 0, 1])

        bx = bx * 0.5 * self.width
        by = by * 0.5 * self.height

        vertices.extend(list(bx * -1 + by * -1) + list(normal) + [0, 0])
        vertices.extend(list(bx * 1 + by * -1) + list(normal) + [1, 0])
        vertices.extend(list(bx * 1 + by * 1) + list(normal) + [1, 1])
        vertices.extend(list(bx * -1 + by * 1) + list(normal) + [0, 1])

        kw = {
            "vertices": vertices,
            "indices": indices,
            "fmt": self.vertex_format,
            "mode": self.mode
        }
        if self.material.map:
            kw["texture"] = self.material.map
        self._mesh = KivyMesh(**kw)
Exemple #10
0
    def create_mesh(self):
        """ Create real mesh object from the geometry and material """
        vertices = []
        indices = []

        a = math.radians(360 / self.segments)
        for i in range(self.segments):
            tx = math.cos(i * a)
            x = tx * self.radius
            y = 0
            tz = math.sin(i * a)
            z = tz * self.radius
            vertices.extend([x, y, z, 0, 1, 0, tx * 0.5 + 0.5, tz * 0.5 + 0.5])
            indices.append(len(indices))

        kw = {
            "vertices": vertices,
            "indices": indices,
            "fmt": self.vertex_format,
            "mode": self.mode
        }
        if self.material.map:
            kw["texture"] = self.material.map
        self._mesh = KivyMesh(**kw)
Exemple #11
0
    def cube(self, tile):
        DEFAULT_VERTEX_FORMAT = [(b'v_tc0', 2, 'float'),
                                 (b'v_normal', 3, 'float'),
                                 (b'v_pos', 3, 'float')]

        obj = self.blocks[tile].obj
        T()
        obj = pywave.Wavefront('tex/block.obj', collect_faces=True)
        material = obj.materials['grass']
        cube = obj.meshes['Cube']

        vertices = obj.vertices
        faces = cube.faces
        grass = obj.materials['grass']
        dirt = obj.materials['dirt']
        vertices = grass.vertices + dirt.vertices
        #indices  = np.array(faces).ravel().tolist()
        indices = np.arange(36).astype(int).tolist()
        #vertices = np.array(vertices).ravel().tolist()

        tex = Image('tex/grass.png').texture
        mat = Material(tex)
        kw = {
            "vertices": vertices,
            "indices": indices,
            "fmt": DEFAULT_VERTEX_FORMAT,
            "mode": "triangles",
            'texture': tex
        }
        #if self.material.map:
        #     kw["texture"] = self.material.map

        mesh = KivyMesh(**kw)

        class Meshy(Object3D):
            def __init__(self, mesh, material):
                super().__init__()
                self._mesh = mesh
                self.material = material
                self.mtl = material
                self.vertex_format = DEFAULT_VERTEX_FORMAT

        cube = Meshy(mesh, tex)

        #cube.material = orig.material
        #cube.geometry = orig.geometry
        orig._mesh = cube._mesh
        orig.material = mat
        cube = orig

        #cube = kivy3.Mesh([], material)
        if tile == 'lava':
            cube.pos.y = -0.5
        elif tile == 'stone':
            cube.pos.y = 1
        elif tile == 'grass':
            pass
        elif tile == 'forest':
            pass
        elif tile == 'water':
            cube.pos.y = -0.33

        #cube.material.color = 0., .7, 0.  # green
        #cube.material.diffuse = 0., .7, 0.  # green
        return cube