Esempio n. 1
0
    def _compile(self):
        """Compile the Image into a data.DisplayList"""
        self.offset = self.get_width() / 2, self.get_height() / 2
        self.rect.center = self.offset[0] + self.pos[0], self.offset[
            1] + self.pos[1]

        self.display_list = data.DisplayList()
        self.display_list.begin()

        off = self.offset

        l = -off[0]
        r = off[0]
        t = -off[1]
        b = off[1]

        w = self.get_width() * 1.0 / self._altered_image_size[0]
        h = self.get_height() * 1.0 / self._altered_image_size[1]

        glBegin(GL_QUADS)
        glTexCoord2f(0, 0)
        glVertex3f(l, t, 0)

        glTexCoord2f(0, h)
        glVertex3f(l, b, 0)

        glTexCoord2f(w, h)
        glVertex3f(r, b, 0)

        glTexCoord2f(w, 0)
        glVertex3f(r, t, 0)

        glEnd()

        self.display_list.end()
Esempio n. 2
0
    def __init__(self,
                 verts=[],
                 texture=None,
                 texcs=[],
                 colorize=(1, 1, 1, 1),
                 scale=1,
                 pos=(0, 0, 0),
                 rotation=(0, 0, 0),
                 fix_order=True,
                 usage=GL_POLYGON):
        BaseSceneObject.__init__(self)

        self.verts = verts
        if texture:
            self.texture = texture
        if texcs:
            self.texcs = texcs
        else:
            self.texcs = [(0, 0)] * len(self.verts)
        self.colorize = colorize
        self.scale = scale

        self.pos = pos
        self.rotation = rotation

        self.usage = usage

        self.display_list = data.DisplayList()
        self._compile(fix_order)
Esempio n. 3
0
    def __init__(self,
                 size,
                 pos=(0, 0, 0),
                 rotation=(0, 0, 0),
                 colorize=(1, 1, 1, 1),
                 texture=None,
                 detail=30,
                 show_inside=False):
        """Create the Sphere
           size is the radius of the Sphere
           pos ithe position of the sphere
           rotation is the rotation of the sphere
           colorize is the color of the sphere
           texture can be None, a string filename of an image to load or a data.Texture object that will be mapped to the sphere
           detail is the level of detail for the Sphere, higher = a more smooth sphere
           show_inside indicates whether the inside of the sphere is rendered or not"""
        BaseSceneObject.__init__(self)

        self.size = size
        self.pos = pos
        self.rotation = rotation
        self.colorize = colorize
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        self.detail = detail
        self.scale = 1
        self.show_inside = show_inside

        self.display_list = data.DisplayList()

        self._compile()
Esempio n. 4
0
    def __init__(self,
                 size,
                 pos=(0, 0, 0),
                 rotation=(0, 0, 0),
                 colorize=(1, 1, 1, 1),
                 texture=None,
                 hide_faces=[]):
        """Create the Quad
           size is the quad
           pos is the position of the quad
           rotation is the rotation of the quad
           colorize is the color of the quad
           texture can be None, a string filename of an image to load or a data.Texture object - entire texture is mapped to the face
           hide_faces are the same as for Cube, except only front and back are allowed"""

        BaseSceneObject.__init__(self)
        self.size = size
        self.pos = pos
        self.rotation = rotation
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        self.colorize = colorize

        self.scale = 1

        self.display_list = data.DisplayList()

        self.hide_faces = hide_faces

        self._compile()
Esempio n. 5
0
    def __init__(self, objects=[]):
        """Create the group.
           objects must be a list of renderable objects"""
        BaseSceneObject.__init__(self)

        if not hasattr(objects, "__iter__"):
            objects = [objects]
        self.objects = objects
        self.gl_list = data.DisplayList()
        self.pickable = False

        self.compile()
Esempio n. 6
0
    def __init__(self, objects=[]):
        """Create the group.
           objects must be a list of renderable objects"""
        self.objects = objects
        self.gl_list = data.DisplayList()

        self.visible = True
        self.pickable = False
        self.outline = False
        self.outline_size = 4
        self.outline_color = (1, 0, 0)
        self.pos = (0, 0, 0)

        self.compile()
Esempio n. 7
0
    def compile(self):
        """Compile the text so rendering is even fast, but text/color/etc. is even slower."""
        self._compiled = True
        li = self._compiled_list
        gl = []
        if not li:
            li = data.DisplayList()

        li.begin()
        for i in self.glyphs:
            if isinstance(i, image.Image):
                i.render()
            else:
                gl.append(i)
        li.end()
        gl.append(li)
        self._compiled_glyphs = gl
        self._compiled_list = li
Esempio n. 8
0
    def _compile(self):
        """Compile the rendering data into a data.DisplayList"""
        self.offset = self.get_width() / 2, self.get_height() / 2

        self.display_list = data.DisplayList()
        self.display_list.begin()

        w = self.get_width() * 1.0 / self._altered_image_size[0]
        h = self.get_height() * 1.0 / self._altered_image_size[1]

        gw, gh = self.get_size()

        if gw < gh:
            uw = gw * 1.0 / gh
            uh = 1
        elif gh < gw:
            uw = 1
            uh = gh * 1.0 / gw
        else:
            uw = uh = 1

        glBegin(GL_QUADS)
        glTexCoord2f(0, h)
        glVertex3f(-uw, -uh, 0)

        glTexCoord2f(w, h)
        glVertex3f(uw, -uh, 0)

        glTexCoord2f(w, 0)
        glVertex3f(uw, uh, 0)

        glTexCoord2f(0, 0)
        glVertex3f(-uw, uh, 0)
        glEnd()

        self.display_list.end()
Esempio n. 9
0
    def compile(self, vertices, normals, texcoords):
        """Compile the ObjGroup into a CompiledGroup for rendering/using."""
        faces = []
        for face in self.faces:
            v, n, t = face
            uv, un, ut = [], [], []
            for i in xrange(len(v)):
                if n[i] > 0:
                    un.append(normals[n[i] - 1])
                else:
                    un.append(None)

                if t[i] > 0:
                    ut.append(texcoords[t[i] - 1])
                else:
                    ut.append(None)
                uv.append(vertices[v[i] - 1])
            faces.append((uv, un, ut))

        final = []
        for face in faces:
            v, n, t = face
            nv = []
            for i in v:
                a, b, c = i
                nv.append((a, b, c))
            final.append((nv, n, t))

        #now build our display list!
        dlist = data.DisplayList()
        dlist.begin()

        minx = miny = minz = 0
        maxx = maxy = maxz = 0

        avgx, avgy, avgz = 0, 0, 0
        num = 0

        for face in final:
            v = face[0]
            for i in xrange(len(v)):
                num += 1
                x, y, z = v[i]
                avgx += x
                avgy += y
                avgz += z

        avgx = math3d.safe_div(float(avgx), num)
        avgy = math3d.safe_div(float(avgy), num)
        avgz = math3d.safe_div(float(avgz), num)

        for face in final:
            v, n, t = face
            glBegin(GL_POLYGON)
            for i in xrange(len(v)):
                if n[i]:
                    glNormal3fv(n[i])
                if t[i]:
                    glTexCoord2fv(t[i])
                x, y, z = v[i]
                glVertex3f(x - avgx, y - avgy, z - avgz)
                minx = min((minx, x))
                maxx = max((maxx, x))
                miny = min((miny, y))
                maxy = max((maxy, y))
                minz = min((minz, z))
                maxz = max((maxz, z))
            glEnd()

        dlist.end()

        if self.material == None:
            self.material = data.Material("null")

        return CompiledGroup(self.name, self.material, dlist,
                             (minx, miny, minz, maxx, maxy, maxz),
                             (avgx, avgy, avgz))
Esempio n. 10
0
    def __init__(self,
                 size,
                 pos=(0, 0, 0),
                 rotation=(0, 0, 0),
                 colorize=(1, 1, 1, 1),
                 texture=None,
                 mirror=True,
                 hide_faces=[]):
        """Create a cube
           size is the absolute size of the cube
           pos is the position of the cube
           rotation is the rotation of the cube
           colorize is the color of the cube (0-1 RGBA)
           texture can be None, a data.Texture object or a string representing the filename of a texture to load
           mirror indicates whether each face of the cube has the full texture on it (so each is identicle) or
               if True, each face will have the entire texture mapped to it
               if False, the Texture is considered a cube map, like this:
                   blank, blank, top, blank,
                   back, left, front, right,
                   blank, blank, bottom, blank
           hide_faces must be a list of the sides of the cube not to add:
               acceptable values are left, right, top, bottom, back, front"""
        BaseSceneObject.__init__(self)

        self.hide_faces = hide_faces

        self.size = size
        self.pos = pos
        self.rotation = rotation
        if type(texture) is type(""):
            texture = Texture(texture)
        if texture:
            self.texture = texture
        self.colorize = colorize

        self.mirror = mirror

        self.corners = (
            (-1, -1, 1),  #topleftfront
            (1, -1, 1),  #toprightfront
            (1, 1, 1),  #bottomrightfront
            (-1, 1, 1),  #bottomleftfront
            (-1, -1, -1),  #topleftback
            (1, -1, -1),  #toprightback
            (1, 1, -1),  #bottomrightback
            (-1, 1, -1))  #bottomleftback

        sides = (
            (7, 4, 0, 3, 2, 2, 5),  #left
            (2, 1, 5, 6, 3, 4, 4),  #right
            (7, 3, 2, 6, 5, 0, 3),  #top
            (0, 4, 5, 1, 4, 5, 2),  #bottom
            (3, 0, 1, 2, 0, 1, 0),  #front
            (6, 5, 4, 7, 1, 3, 1))  #back
        self.sides = []
        if not "left" in hide_faces:
            self.sides.append(sides[0])
        if not "right" in hide_faces:
            self.sides.append(sides[1])
        if not "top" in hide_faces:
            self.sides.append(sides[2])
        if not "bottom" in hide_faces:
            self.sides.append(sides[3])
        if not "front" in hide_faces:
            self.sides.append(sides[4])
        if not "back" in hide_faces:
            self.sides.append(sides[5])

        self.normals = (
            (0, 0, 1),  #front
            (0, 0, -1),  #back
            (0, -1, 0),  #top
            (0, 1, 0),  #bottom
            (1, 0, 0),  #right
            (-1, 0, 0))  #left

        self.split_coords = (
            (2, 2),  #top
            (0, 1),  #back
            (1, 1),  #left
            (2, 1),  #front
            (3, 1),  #right
            (2, 0))  #bottom

        self.scale = 1

        self.display_list = data.DisplayList()

        self._compile()