Пример #1
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
Пример #2
0
    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