Exemplo n.º 1
0
 def get(self, index):
     if index < self._size:
         addr = self._address.ptr() + index * self._item_size
         p = x86.GetFloat(addr, 0, 3)
         uv = x86.GetFloat(addr + 16, 0, 2)
         return (p, uv)
     return None  #think Trowing exception TODO
Exemplo n.º 2
0
 def get(self, index):
     if index < self._size:
         addr = self._address.ptr() + index * self._item_size
         p0 = x86.GetFloat(addr, 0, 3)
         p1 = x86.GetFloat(addr + 16, 0, 3)
         p2 = x86.GetFloat(addr + 32, 0, 3)
         return (p0, p1, p2)
     return None
Exemplo n.º 3
0
 def get(self, index):
     if index < self._size:
         addr = self._address.ptr() + index * self._item_size
         p = x86.GetUInt32(addr, 0, 3)
         n = x86.GetFloat(addr + 16, 0, 3)
         return (p, n)
     return None
Exemplo n.º 4
0
    def bbox(self):
        if self.addr():
            minx = miny = minz = 9999999.0
            maxx = maxy = maxz = -9999999.0
            epsilon = 0.001
            addr = self._address.ptr()

            for i in range(self._size):
                p = x86.GetFloat(addr, 0, 3)
                if p[0] < minx: minx = p[0]
                if p[1] < miny: miny = p[1]
                if p[2] < minz: minz = p[2]
                if p[0] > maxx: maxx = p[0]
                if p[1] > maxy: maxy = p[1]
                if p[2] > maxz: maxz = p[2]
                addr += self._item_size

            minx = minx - epsilon
            miny = miny - epsilon
            minz = minz - epsilon
            maxx = maxx + epsilon
            maxy = maxy + epsilon
            maxz = maxz + epsilon
            return ((minx, miny, minz), (maxx, maxy, maxz))
        return None
Exemplo n.º 5
0
 def get_pixel(self, x, y):
     if x < 0 or x >= self.width: return None
     if y < 0 or y >= self.height: return None
     adr = y * self.pitch + x * 16
     # return r, g, b, a 
     pix = x86.GetFloat(self.pixels.ptr()+adr, 0, 4)
     return pix
Exemplo n.º 6
0
 def translate(self, dx, dy, dz):
     dx = float(dx)
     dy = float(dy)
     dz = float(dz)
     addr = self._address.ptr()
     for i in range(self._size):
         p = x86.GetFloat(addr, 0, 3)
         v0 = dx + p[0]
         v1 = dy + p[1]
         v2 = dz + p[2]
         x86.SetFloat(addr, (v0, v1, v2, 0.0), 0)
         addr += self._item_size
Exemplo n.º 7
0
 def scale(self, xs, ys, zs):
     xs = float(xs)
     ys = float(ys)
     zs = float(zs)
     addr = self._address.ptr()
     for i in range(self._size):
         p = x86.GetFloat(addr, 0, 3)
         v0 = xs * p[0]
         v1 = xy * p[1]
         v2 = xz * p[2]
         x86.SetFloat(addr, (v0, v1, v2, 0.0), 0)
         addr += self._item_size
Exemplo n.º 8
0
 def bbox_triangle(self, idx1, idx2, idx3):
     address = self._address.ptr()
     addr = address + idx1 * self._item_size
     p0 = x86.GetFloat(addr, 0, 3)
     addr = address + idx2 * self._item_size
     p1 = x86.GetFloat(addr, 0, 3)
     addr = address + idx3 * self._item_size
     p2 = x86.GetFloat(addr, 0, 3)
     epsilon = 0.0001
     minx = p0[0]
     if p1[0] < minx: minx = p1[0]
     if p2[0] < minx: minx = p2[0]
     minx -= epsilon
     maxx = p0[0]
     if p1[0] > maxx: maxx = p1[0]
     if p2[0] > maxx: maxx = p2[0]
     maxx += epsilon
     miny = p0[1]
     if p1[1] < miny: miny = p1[1]
     if p2[1] < miny: miny = p2[1]
     miny -= epsilon
     maxy = p0[1]
     if p1[1] > maxy: maxy = p1[1]
     if p2[1] > maxy: maxy = p2[1]
     maxy += epsilon
     minz = p0[2]
     if p1[2] < minz: minz = p1[2]
     if p2[2] < minz: minz = p2[2]
     minz -= epsilon
     maxz = p0[2]
     if p1[2] > maxz: maxz = p1[2]
     if p2[2] > maxz: maxz = p2[2]
     maxz += epsilon
     #minx = min(min(p0[0], p1[0]), p2[0]) - epsilon
     #maxx = max(max(p0[0], p1[0]), p2[0]) + epsilon
     #miny = min(min(p0[1], p1[1]), p2[1]) - epsilon
     #maxy = max(max(p0[1], p1[1]), p2[1]) + epsilon
     #minz = min(min(p0[2], p1[2]), p2[2]) - epsilon
     #maxz = max(max(p0[2], p1[2]), p2[2]) + epsilon
     return ((minx, miny, minz), (maxx, maxy, maxz))
Exemplo n.º 9
0
 def get_pixel(self, x, y):
     """
         Get color of pixel at cooridantes x, y. (r, g, b, a)
         tuple is returned.
         If x, y cooridantes are out of range None is return.
     """
     if x < 0 or x >= self.width:
         return None
     if y < 0 or y >= self.height:
         return None
     adr = y * self.pitch + x * 16
     # return r, g, b, a
     return x86.GetFloat(self._pixels.ptr() + adr, 0, 4)
Exemplo n.º 10
0
 def read(self, x, y):
     offset = y * self.width * 4 + x * 4
     adr = self.buffer.ptr() + offset
     return x86.GetFloat(adr, 0, 0)
Exemplo n.º 11
0
 def get_normal(self, index):
     addr = self.address.ptr() + index * self.tri_size 
     addr = addr + 16
     return x86.GetFloat(addr, 0, 3)
Exemplo n.º 12
0
 def get_uv(self, index):
     addr = self.address.ptr() + index * self.vertex_size + self.uv_offset
     uv = x86.GetFloat(addr, 0, 2)
     return uv 
Exemplo n.º 13
0
 def get_normal(self, index):
     addr = self.address.ptr() + index * self.vertex_size + self.normal_offset 
     normal = x86.GetFloat(addr, 0, 3)
     return normal 
Exemplo n.º 14
0
 def get_position(self, index):
     addr = self.address.ptr() + index * self.vertex_size 
     position = x86.GetFloat(addr, 0, 3)
     return position
Exemplo n.º 15
0
 def _get_item(self, addr):
     return x86.GetFloat(addr, 0, 0)