Skip to content

Commit

Permalink
Streamlined block mesh
Browse files Browse the repository at this point in the history
Removed face_mode. This was always 3
  • Loading branch information
gentlegiantJGC committed Oct 8, 2024
1 parent ec4be49 commit 889870b
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 27 deletions.
31 changes: 10 additions & 21 deletions src/amulet/mesh/block/block_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def merge(cls, models: Iterable[BlockMesh]) -> BlockMesh:
texture_indexes_src[cull_dir].append(texture_index)

vert_count[cull_dir] += int(
temp_model.verts[cull_dir].shape[0] / temp_model.face_mode
temp_model.verts[cull_dir].shape[0] / 3
)

textures_src += temp_model.textures
Expand Down Expand Up @@ -124,16 +124,14 @@ def merge(cls, models: Iterable[BlockMesh]) -> BlockMesh:
tint_verts[cull_dir] = numpy.zeros(0, float)

return cls(
3, verts, tverts, tint_verts, faces, texture_indexes, textures, transparent
verts, tverts, tint_verts, faces, texture_indexes, textures, transparent
)

def __init__(
self,
face_width: int,
verts: dict[Optional[str], numpy.ndarray],
texture_coords: dict[Optional[str], numpy.ndarray],
tint_verts: dict[Optional[str], numpy.ndarray],
# normals: dict[Optional[str], numpy.ndarray],
faces: dict[Optional[str], numpy.ndarray],
texture_index: dict[Optional[str], numpy.ndarray],
textures: tuple[str, ...],
Expand Down Expand Up @@ -186,7 +184,7 @@ def __init__(
and isinstance(val, numpy.ndarray)
and numpy.issubdtype(val.dtype, numpy.unsignedinteger)
and val.ndim == 1
and val.shape[0] % face_width == 0
and val.shape[0] % 3 == 0
for key, val in faces.items()
), "The format of faces is incorrect"

Expand All @@ -195,15 +193,14 @@ def __init__(
and isinstance(val, numpy.ndarray)
and numpy.issubdtype(val.dtype, numpy.unsignedinteger)
and val.ndim == 1
and val.shape[0] == faces[key].shape[0] / face_width
and val.shape[0] == faces[key].shape[0] / 3
for key, val in texture_index.items()
), "The format of texture index is incorrect"

assert isinstance(textures, Iterable) and all(
isinstance(texture, str) for texture in textures
), "The format of the textures is incorrect"

self._face_mode = face_width
self._verts = verts
self._texture_coords = texture_coords
self._tint_verts = tint_verts
Expand All @@ -222,21 +219,15 @@ def __init__(
):
array.setflags(write=False)

@property
def face_mode(self) -> int:
"""The number of vertices per face"""
return self._face_mode

@property
def vert_tables(self) -> dict[Optional[str], numpy.ndarray]:
"""A dictionary of cull dir -> the flat vert table containing vertices, texture coords and (in the future) normals"""
"""A dictionary of cull dir -> the flat vert table containing vertices and texture coords."""
if self._vert_tables is None:
self._vert_tables = {
key: numpy.hstack(
(
self._verts[key].reshape(-1, self._face_mode),
self._texture_coords[key].reshape(-1, 2),
# TODO: add in face normals
self._verts[key].reshape(-1, 3),
self._texture_coords[key].reshape(-1, 2)
)
).ravel()
for key in self._verts.keys()
Expand Down Expand Up @@ -269,7 +260,7 @@ def tint_verts(self) -> dict[Optional[str], numpy.ndarray]:
@property
def faces(self) -> dict[Optional[str], numpy.ndarray]:
"""A dictionary mapping face cull direction to the face table for that direction.
The face table is a flat numpy array of multiple 3 or 4 depending on face_mode.
The face table is a flat numpy array of multiple 3.
First 3 or 4 columns index into the verts table.
Last column indexes into textures."""
return self._faces
Expand Down Expand Up @@ -309,11 +300,10 @@ def rotate(self, rotx: int, roty: int) -> BlockMesh:
if rotx or roty and (roty, rotx) in cull_remap_all:
cull_remap = cull_remap_all[(roty, rotx)]
return BlockMesh(
self.face_mode,
{
cull_remap[cull_dir]: rotate_3d(
rotate_3d(
self.verts[cull_dir].reshape((-1, self.face_mode)),
self.verts[cull_dir].reshape((-1, 3)),
rotx * 90,
0,
0,
Expand Down Expand Up @@ -352,8 +342,7 @@ def __eq__(self, other: Any) -> bool:
if not isinstance(other, BlockMesh):
return NotImplemented
return (
self.face_mode == other.face_mode
and all(
all(
obj1.keys() == obj2.keys()
and all(numpy.array_equal(obj1[key], obj2[key]) for key in obj1.keys())
for obj1, obj2 in (
Expand Down
1 change: 0 additions & 1 deletion src/amulet/mesh/block/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def get_cube(
del _tri_faces[key]

return BlockMesh(
3,
_verts,
_texture_coords,
_tint_verts,
Expand Down
2 changes: 1 addition & 1 deletion src/amulet/resource_pack/bedrock/blockshapes/air.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_block_model(
west: str,
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
return BlockMesh(3, {}, {}, {}, {}, {}, (), Transparency.Partial)
return BlockMesh({}, {}, {}, {}, {}, (), Transparency.Partial)


BlockShape = Air()
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def get_block_model(
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
return BlockMesh(
3,
{
None: numpy.array(
[
Expand Down
1 change: 0 additions & 1 deletion src/amulet/resource_pack/bedrock/blockshapes/flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def get_block_model(
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
return BlockMesh(
3,
{
None: numpy.array(
[
Expand Down
1 change: 0 additions & 1 deletion src/amulet/resource_pack/bedrock/blockshapes/flat_wall.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def get_block_model(
transparency: tuple[bool, bool, bool, bool, bool, bool],
) -> BlockMesh:
return BlockMesh(
3,
{
None: numpy.array(
[
Expand Down
1 change: 0 additions & 1 deletion src/amulet/resource_pack/java/resource_pack_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ def _load_block_model(self, model_path: str) -> BlockMesh:
)

return BlockMesh(
3,
verts,
tverts,
tint_verts,
Expand Down

0 comments on commit 889870b

Please sign in to comment.