DKL9 GitList
Repositories
DKL9 home
voxels
Code
Commits
Branches
Tags
Search
Tree:
be2e5cd
Branches
Tags
master
voxels
mesh.py
Gravity, sun-disc, voxel picking, hand indicator
dkl9
commited
be2e5cd
at 2025-177 00:03:49
mesh.py
Blame
History
Raw
from libs import * import entity class SquareMesh(entity.Entity): def __init__(self, **kwargs): 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, **kwargs ) 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[1:3] = sq[2:0:-1] sq[4:6] = sq[5:3:-1] 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 cube_mat(self, fd, axis, corner): if not isinstance(fd, int): fd = self.grid[*fd] match fd: case 0: return (vec([0.0, 0.0, 0.0, 0.0]), vec([1.0, 0.0, 0.0, 1.0])) case 1: return (vec([*np.add(0.5, axis2offset(axis, 0.5)), 1.0]), vec([1.0, 0.0, 0.1, 128.0])) case 2: top = (vec([0.2, 0.2, 1.0, 1.0]), vec([1.0, 0.0, 0.0, 1.0])) bottom = (vec([0.0, 0.0, 0.2, 1.0]), vec([1.0, 0.0, 0.0, 1.0])) match axis: case 2: return top case -2: return bottom case a: return bottom if corner & (1 << ((a % 4) // 2)) else top case 3: return (vec([0.7, 0.7, 0.8, 1.0]), vec([0.5, 0.5, 0.01, 2.0])) case 4: top = (vec([0.2, 0.6, 0.2, 1.0]), vec([0.6, 0.4, 0.0, 1.0])) bottom = (vec([0.5, 0.2, 0.0, 1.0]), vec([0.8, 0.2, 0.0, 1.0])) match axis: case 2: return top case -2: return bottom case a: return bottom if corner & (1 << ((a % 4) // 2)) else top return case 5: core = (vec([1.0, 1.0, 0.8, 1.0]), vec([0.4, 1.6, 0.0, 1.0])) bark = (vec([0.4, 0.3, 0.0, 1.0]), vec([0.5, 0.5, 0.0, 1.0])) match axis: case 2 | -2: return core case _: return bark case 6: return (vec([0.0, 0.4, 0.0, 0.5]), vec([0.6, 0.4, 0.01, 4.0])) def mat_list(self): cl = np.empty((2, 3 * len(self.faces), 4), dtype=FLOAT) for s in range(len(self.faces) // 2): axis, fd = self.faces[2 * s] for (t, c) in enumerate([0, 1, 2, 3, 2, 1] if (True or axis > 0) else [1, 2, 3, 2, 1, 0]): cl[0][6 * s + t], cl[1][6 * s + t] = self.cube_mat(fd, axis, c) return cl