DKL9 GitList
Repositories
DKL9 home
voxels
Code
Commits
Branches
Tags
Search
Tree:
a924d65
Branches
Tags
master
voxels
mesh.py
Simple place/break RGB voxel prototype
dkl9
commited
a924d65
at 2025-170 19:41:48
mesh.py
Blame
History
Raw
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], GL_TRIANGLES ) self.faces = [] def add_sq(self, axis, width, pos): 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, 1)) def add_cube(self, width, pos): offset = vec([width / 2, 0, 0]) for a in range(1, 4): self.add_sq(a, width, pos + offset) self.add_sq(-a, width, pos - offset) offset = np.roll(offset, 1, 0) return len(self.faces) - 12 def del_cube(self, ind): self.verts = np.delete(self.verts, np.s_[3 * ind:3 * (ind + 12)], 0) del self.faces[ind:ind + 12] self.update_attr(0) self.update_attr(1) def col_list(self): return np.repeat([cube_col(x[0]) for x in self.faces], 3, 0)