from libs import * import entity def cube_col(axis): return vec([ [0.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 1.0], [0.0, 1.0, 0.0, 1.0], [0.0, 0.0, 1.0, 1.0] ][abs(axis)]) + 0.4 * np.sign(axis, dtype=FLOAT) class SquareMesh(entity.Entity): def __init__(self): super().__init__( np.empty((0, 3), dtype=FLOAT), [0.0, 1.0, 0.0, 1.0], [0.0, 0.0, 0.0], mode=GL_TRIANGLES ) self.faces = [] def add_sq(self, axis, width, pos, fd=1): w = width / 2 sq = pos + np.roll(vec([ [w, w, 0], [-w, w, 0], [w, -w, 0], [-w, -w, 0], [w, -w, 0], [-w, w, 0] ]), abs(axis), 1) if axis < 0: sq = np.flip(sq, 0) self.verts = np.concatenate((self.verts, sq), dtype=FLOAT) for i in range(2): self.faces.append((axis, fd)) def del_sq(self, ind): self.verts = np.delete(self.verts, np.s_[3 * ind:3 * (ind + 2)], 0) del self.faces[ind:ind + 2] def col_list(self): return np.repeat([cube_col(x[0]) for x in self.faces], 3, 0)