Ejemplo n.º 1
0
    def create_mesh(self) -> MeshObject:
        mesh = TriangleMesh()
        mesh.create_attribute("a_part", 1, 0., gl.GLfloat)
        factory = MeshFactory()

        # head
        mesh.set_attribute_value("a_part", 0.)
        #factory.add_dodecahedron(mesh)
        factory.add_uv_sphere(mesh, .5, num_u=24, num_v=12)
        # eyes
        with factory:
            factory.translate((-.3, .3, .2))
            factory.rotate_z(20)
            factory.add_cylinder(mesh, .2, .3)
        with factory:
            factory.translate((.3, .3, .2))
            factory.rotate_z(-20)
            factory.add_cylinder(mesh, .2, .3)

        # left food
        mesh.set_attribute_value("a_part", 1.)
        factory.add_dodecahedron(mesh)
        # right food
        mesh.set_attribute_value("a_part", 2.)
        factory.add_dodecahedron(mesh)

        return MeshObject(mesh, num_parts=3, name="walker-mesh")
Ejemplo n.º 2
0
    def create_mesh(self) -> MeshObject:
        mesh = TriangleMesh()
        mesh.create_attribute("a_part", 1, 0., gl.GLfloat)
        factory = MeshFactory()

        mesh.set_attribute_value("a_part", 0.)
        factory.add_uv_sphere(mesh, .5, num_u=12, num_v=6)

        return MeshObject(mesh, num_parts=3, name=f"{self.id}-mesh")
Ejemplo n.º 3
0
    def build_object_mesh(self) -> TriangleMesh:
        mesh = TriangleMesh()
        mesh.create_attribute("a_color", 4, (1, 1, 1, .9))
        #mesh.set_attribute_value("a_color", (1, 1, 1, .5))
        for o in self.object_map.static_objects.values():
            o.add_to_mesh(mesh)

        for o in self.object_map.objects:
            o.add_to_mesh(mesh)

        return mesh
Ejemplo n.º 4
0
    def create_mesh(self, do_ambient=True):
        mesh = TriangleMesh()
        mesh.create_attribute("a_ambient", 3)

        def add_quad(p1, p2, p3, p4, *uvquad):
            mesh.add_quad(p1, p2, p3, p4, *uvquad)
            for p in (p1, p2, p3, p1, p3, p4):
                if do_ambient:
                    mesh.add_attribute("a_ambient", self.get_ambient_color(*p))
                else:
                    mesh.add_attribute("a_ambient", (1, 1, 1))

        for z in range(self.num_z):
            z1 = z + 1
            for y in range(self.num_y):
                y1 = y + 1
                for x in range(self.num_x):
                    x1 = x + 1
                    b = self.block(x, y, z)
                    if b.space_type:
                        uvquad = self.tileset.get_uv_quad(b.texture)
                        # bottom
                        if not self.is_wall(x, y, z - 1, self.TOP):
                            add_quad((x, y1, z), (x1, y1, z), (x1, y, z),
                                     (x, y, z), *uvquad)
                        # top
                        if not self.is_wall(x, y, z + 1, self.BOTTOM):
                            add_quad((x, y, z1), (x1, y, z1), (x1, y1, z1),
                                     (x, y1, z1), *uvquad)
                        # front
                        if not self.is_wall(x, y - 1, z, self.BACK):
                            add_quad((x, y, z), (x1, y, z), (x1, y, z1),
                                     (x, y, z1), *uvquad)
                        # back
                        if not self.is_wall(x, y + 1, z, self.FRONT):
                            add_quad((x, y1, z), (x, y1, z1), (x1, y1, z1),
                                     (x1, y1, z), *uvquad)
                        # left
                        if not self.is_wall(x - 1, y, z, self.RIGHT):
                            add_quad((x, y1, z), (x, y, z), (x, y, z1),
                                     (x, y1, z1), *uvquad)
                        # right
                        if not self.is_wall(x + 1, y, z, self.LEFT):
                            add_quad((x1, y, z), (x1, y1, z), (x1, y1, z1),
                                     (x1, y, z1), *uvquad)

        #print("LEN", len(mesh._vertices), len(mesh._attributes["a_ambient"]["values"]))
        return mesh