def edit(self, index, p0, p1, p2, n): if index < self._size: addr = self._address.ptr() + index * self._item_size x86.SetFloat(addr, (p0[0], p0[1], p0[2], 0.0), 0) x86.SetFloat(addr + 16, (p1[0], p1[1], p1[2], 0.0), 0) x86.SetFloat(addr + 32, (p2[0], p2[1], p2[2], 0.0), 0) x86.SetFloat(addr + 48, (n[0], n[1], n[2], 0.0), 0)
def add_vertex(self, x, y, z, nx=None, ny=None, nz=None, u=None, v=None): if self.address is None: self.address = x86.MemData(self.vertex_size) self.reserve += 1 elif self.reserve == self.size: if self.size > 0 and self.size <= 100: self.reserve += 1 elif self.size > 100 and self.size <= 10000: self.reserve += 100 elif self.size > 10000 and self.size <= 1000000: self.reserve += 10000 else: self.reserve += 100000 temp = x86.MemData(self.vertex_size*self.reserve) util.memcpy(temp.ptr(), self.address.ptr(), self.size*self.vertex_size) self.address = temp offset = self.vertex_size * self.size x86.SetFloat(self.address.ptr()+offset, (x, y, z, 0.0), 0) if nx is not None: noffset = offset + self.normal_offset x86.SetFloat(self.address.ptr()+noffset, (nx, ny, nz, 0.0), 0) if u is not None: noffset = offset + self.uv_offset x86.SetFloat(self.address.ptr()+noffset, (u, v, 0.0, 0.0), 0) self.size += 1
def add(self, x, y, z, u, v): if self._reserve == self._size: self._resize() offset = self._item_size * self._size x86.SetFloat(self._address.ptr() + offset, (x, y, z, 0.0), 0) x86.SetFloat(self._address.ptr() + offset + 16, (u, v, 0.0, 0.0), 0) self._size += 1
def add(self, p0, p1, p2): if self._reserve == self._size: self._resize() offset = self._item_size * self._size addr = self._address.ptr() + offset x86.SetFloat(addr, (p0[0], p0[1], p0[2], 0.0), 0) x86.SetFloat(addr + 16, (p1[0], p1[1], p1[2], 0.0), 0) x86.SetFloat(addr + 32, (p2[0], p2[1], p2[2], 0.0), 0) self._size += 1
def add_triangle(self, v0, v1, v2, material, nx=None, ny=None, nz=None): if self.address is None: self.address = x86.MemData(self.tri_size) self.reserve += 1 elif self.reserve == self.size: if self.size > 0 and self.size <= 100: self.reserve += 1 elif self.size > 100 and self.size <= 10000: self.reserve += 100 elif self.size > 10000 and self.size <= 1000000: self.reserve += 10000 else: self.reserve += 100000 temp = x86.MemData(self.tri_size*self.reserve) util.memcpy(temp.ptr(), self.address.ptr(), self.size*self.tri_size) self.address = temp offset = self.tri_size * self.size x86.SetInt32(self.address.ptr()+offset, (v0, v1, v2, material), 0) if self.has_normal and nx is not None: offset = offset + 16 # offset to normal x86.SetFloat(self.address.ptr()+offset, (nx, ny, nz, 0.0), 0) self.size += 1
def set_pixel(self, x, y, r, g, b, a=0.99): if x < 0 or x >= self.width: return False if y < 0 or y >= self.height: return False adr = y * self.pitch + x * 16 x86.SetFloat(self._pixels.ptr() + adr, (r, g, b, a), 0) return True
def add(self, v0, v1, v2, nx, ny, nz): if self._reserve == self._size: self._resize() offset = self._item_size * self._size addr = self._address.ptr() + offset x86.SetUInt32(addr, (v0, v1, v2), 0) x86.SetFloat(addr + 16, (nx, ny, nz, 0.0), 0) self._size += 1
def set_pixel(self, x, y, r, g, b, a=0.99): #y = self.height - y - 1 # for flipping image #clipping if x < 0 or x >= self.width: raise ValueError("Out of bounds:x=" + str(x) + " y=" + str(y) + " width=" + str(self.width) + " height=" + str(self.height)) if y < 0 or y >= self.height: raise ValueError("Out of bounds:x=" + str(x) + " y=" + str(y) + " width=" + str(self.width) + " height=" + str(self.height)) adr = y * self.pitch + x * 16 x86.SetFloat(self.pixels.ptr()+adr, (r, g, b, a), 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
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
def set_pixel(self, x, y, r, g, b, a=0.99): """ Set color of pixel at cooridantes x, y. r, g, b, a are red, green blue and alpha color components. Default value for alpha component is 0.99. Function return False if x, y coordinates are out of range otherwise True """ if x < 0 or x >= self.width: return False if y < 0 or y >= self.height: return False adr = y * self.pitch + x * 16 x86.SetFloat(self._pixels.ptr() + adr, (r, g, b, a), 0) return True
def edit_position(self, index, x, y, z): addr = self.address.ptr() + index * self.vertex_size x86.SetFloat(addr, (x, y, z, 0.0), 0)
def write(self, x, y, value): offset = y * self.width * 4 + x * 4 adr = self.buffer.ptr() + offset x86.SetFloat(adr, value, 0)
def edit(self, index, v0, v1, v2, nx, ny, nz): if index < self._size: addr = self._address.ptr() + index * self._item_size x86.SetUInt32(addr, (v0, v1, v2), 0) x86.SetFloat(addr + 16, (nx, ny, nz, 0.0), 0)
def edit(self, index, x, y, z): if index < self._size: addr = self._address.ptr() + index * self._item_size x86.SetFloat(addr, (x, y, z, 0.0), 0)
def edit(self, index, x, y, z, nx, ny, nz, u, v): if index < self._size: addr = self._address.ptr() + index * self._item_size x86.SetFloat(addr, (x, y, z, 0.0), 0) x86.SetFloat(addr + 16, (nx, ny, nz, 0.0), 0) x86.SetFloat(addr + 32, (u, v, 0.0, 0.0), 0)
def _set_item(self, addr, value): x86.SetFloat(addr, float(value), 0)