Ejemplo n.º 1
0
 def get_center(self):
     """Return the current center point of the bone."""
     a,b,c = self.cur_start
     d,e,f = self.cur_end
     return (math3d.safe_div(a+d, 2.0),
             math3d.safe_div(b+e, 2.0),
             math3d.safe_div(c+f, 2.0))
Ejemplo n.º 2
0
    def _build_tex(self):
        chars = self.renderable + "\a"
        mapping = {}
        x = 0
        y = 0
        max_height = 0

        pyg_im = pygame.Surface((512,512)).convert_alpha()
        pyg_im.fill((0,0,0,0))

        for i in chars:
            g = self.font_obj.render(i, True, (255,255,255))
            tdata = pygame.image.tostring(g, "RGBA", 1)
            xs, ys = g.get_size()
            if x + xs >= 512:
                x = 0
                y += max_height
                max_height = 0
            if y+ys >= 512:
                raise Exception("Ran out of room for Font texture map - reduce internal_font_size when creating font.")

            max_height = max((max_height, ys))

            pyg_im.blit(g, (x,y))

            mapping[i] = (math3d.safe_div(x, 512.0),#tex start x
                          math3d.safe_div(y, 512.0),#tex start y
                          math3d.safe_div(x+xs, 512.0),#tex end x
                          math3d.safe_div(y+ys, 512.0),#tex end y
                          xs,#width
                          ys)#height

            x += xs
        pygame.draw.line(pyg_im, (255,255,255), (0,511), (511,511))

        self.font_tex = data.Texture(pyg_im)
        self.font_mapping = mapping
        self.font_image = image.Image(pyg_im)
Ejemplo n.º 3
0
    def _compile(self):
        """Compile the Sphere into a data.DisplayList"""
        self.display_list.begin()
        verts = []
        texcs = []
        norms = []

        space = self.detail

        for b in xrange(0, 180, space):
            b *= 1.0
            for a in xrange(0, 360, space):
                a *= 1.0
                _v = []
                _t = []
                for i in xrange(2):
                    for j in xrange(2):
                        s1 = space * i
                        s2 = space * j
                        x = math.sin(
                            math3d.safe_div(a + s1, 180) * math.pi) * math.sin(
                                math3d.safe_div(b + s2, 180) * math.pi)
                        z = math.cos(
                            math3d.safe_div(a + s1, 180) * math.pi) * math.sin(
                                math3d.safe_div(b + s2, 180) * math.pi)
                        y = math.cos(math3d.safe_div(b + s2, 180) * math.pi)
                        u = math3d.safe_div(a + s1, 360)
                        v = math3d.safe_div(b + s2, 360)
                        _v.append((x, y, z))
                        _t.append((u, 1 - v * 2))
                verts.extend([_v[0], _v[1], _v[3], _v[0], _v[3], _v[2]])
                texcs.extend([_t[0], _t[1], _t[3], _t[0], _t[3], _t[2]])
                norms.extend([math3d.calcTriNormal(*verts[-6:-3])] * 3)
                norms.extend([math3d.calcTriNormal(*verts[-3::])] * 3)
                if self.show_inside:
                    verts.extend(reversed(verts[-6::]))
                    texcs.extend(reversed(texcs[-6::]))
                    norms.extend([math3d.calcTriNormal(*verts[-6:-3])] * 3)
                    norms.extend([math3d.calcTriNormal(*verts[-3::])] * 3)
        glBegin(GL_TRIANGLES)
        for i in xrange(len(verts)):
            u, v = texcs[i]
            glTexCoord2f(u, v)
            glNormal3f(*norms[i])
            x, y, z = verts[i]
            glVertex3f(x, y, z)
        glEnd()
        self.display_list.end()
Ejemplo n.º 4
0
 def update(self, skeleton, tstamp_last, tstamp_cur):
     "Update the skeleton based on the last and current timestamps." ""
     if self.obj in skeleton.bones:
         obj = skeleton.bones[self.obj]
     else:
         return None
     pos, rotation, scale = obj.get_center(), obj.rotation, obj.scale
     if tstamp_last > self.end or tstamp_cur < self.start:
         return None
     _s = max((tstamp_last, self.start))
     _e = min((tstamp_cur, self.end))
     mult = math3d.safe_div(float(_e - _s), self.end - _s)
     if self.ident == "RT":
         a, b, c = self._d(self.val, rotation, mult)
         obj.rotate(a, b, c)
     if self.ident == "MT":
         pos = self._d(self.val, pos, mult)
         obj.move(*pos)
     if self.ident == "ST":
         scale = self._d(self.val, scale, mult)
         obj.scaled(*scale)
Ejemplo n.º 5
0
 def update(self, skeleton, tstamp_last, tstamp_cur):
     "Update the skeleton based on the last and current timestamps."""
     if self.obj in skeleton.bones:
         obj = skeleton.bones[self.obj]
     else:
         return None
     pos, rotation, scale = obj.get_center(), obj.rotation, obj.scale
     if tstamp_last > self.end or tstamp_cur < self.start:
         return None
     _s = max((tstamp_last, self.start))
     _e = min((tstamp_cur, self.end))
     mult = math3d.safe_div(float(_e-_s), self.end-_s)
     if self.ident == "RT":
         a,b,c = self._d(self.val, rotation, mult)
         obj.rotate(a,b,c)
     if self.ident == "MT":
         pos = self._d(self.val, pos, mult)
         obj.move(*pos)
     if self.ident == "ST":
         scale = self._d(self.val, scale, mult)
         obj.scaled(*scale)
Ejemplo n.º 6
0
 def get_center(self):
     """Return the current center point of the bone."""
     a, b, c = self.cur_start
     d, e, f = self.cur_end
     return (math3d.safe_div(a + d, 2.0), math3d.safe_div(b + e, 2.0),
             math3d.safe_div(c + f, 2.0))
Ejemplo n.º 7
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))
Ejemplo n.º 8
0
    def compile(self, vertices, normals, texcoords):
        """Compile the ObjGroup into a CompiledGroup for rendering/using.
           vertices/normals/texcoords are a list of all attributes in the mesh file, fo reference"""
        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))