From b3a71c8706b6f7ab22c2f82b532356ff0378b005 Mon Sep 17 00:00:00 2001 From: GENTILHOMME Thomas Date: Tue, 3 Mar 2026 15:30:08 +0100 Subject: [PATCH] refactor(voxel-renderer): remove PoleCross and PoleX and keep PoleZ as Pole --- .changeset/warm-donuts-give.md | 5 + docs/llms/voxel-renderer-llms-full.md | 15 +- .../editors/voxel-map/src/ui/BlockLibrary.ts | 2 +- packages/voxel-renderer/docs/Blocks.md | 4 +- packages/voxel-renderer/docs/BuiltInShapes.md | 11 +- .../examples/scripts/demo-shapes.ts | 15 +- .../voxel-renderer/src/blocks/BlockShape.ts | 4 +- .../src/blocks/BlockShapeRegistry.ts | 5 +- .../voxel-renderer/src/blocks/shapes/Pole.ts | 69 +------ .../src/blocks/shapes/PoleCross.ts | 174 ------------------ packages/voxel-renderer/src/index.ts | 3 +- .../test/blocks/BlockShapeRegistry.spec.ts | 4 +- 12 files changed, 21 insertions(+), 290 deletions(-) create mode 100644 .changeset/warm-donuts-give.md delete mode 100644 packages/voxel-renderer/src/blocks/shapes/PoleCross.ts diff --git a/.changeset/warm-donuts-give.md b/.changeset/warm-donuts-give.md new file mode 100644 index 0000000..11f4d05 --- /dev/null +++ b/.changeset/warm-donuts-give.md @@ -0,0 +1,5 @@ +--- +"@jolly-pixel/voxel.renderer": minor +--- + +Remove PoleCross and PoleX shape and keep PoleZ as Pole diff --git a/docs/llms/voxel-renderer-llms-full.md b/docs/llms/voxel-renderer-llms-full.md index ddab6de..086488f 100644 --- a/docs/llms/voxel-renderer-llms-full.md +++ b/docs/llms/voxel-renderer-llms-full.md @@ -251,9 +251,7 @@ type BlockShapeID = | "slabBottom" | "slabTop" | "poleY" - | "poleX" - | "poleZ" - | "poleCross" + | "pole" | "ramp" | "rampFlip" | "rampCornerInner" @@ -408,16 +406,9 @@ All pole shapes use `collisionHint: "trimesh"` and occlude no faces (sub-voxel c - **`PoleY`** — `shapeId: "poleY"`. Narrow vertical post (3/8–5/8 cross-section) running the full block height. -- **`Pole`** — `shapeId: "poleX"`. - Narrow horizontal beam running along the X axis (full width, centered on Y/Z). - -- **`Pole`** — `shapeId: "poleZ"`. +- **`Pole`** — `shapeId: "pole"`. Narrow horizontal beam running along the Z axis (full depth, centered on X/Y). - -- **`PoleCross`** — `shapeId: "poleCross"`. - Horizontal plus-connector at mid-height — X and Z beams merged at the centre. - Internal intersection faces are omitted to avoid overdraw. - + ### Ramps All ramp shapes use `collisionHint: "trimesh"`. diff --git a/packages/editors/voxel-map/src/ui/BlockLibrary.ts b/packages/editors/voxel-map/src/ui/BlockLibrary.ts index 4a019c9..d631db7 100644 --- a/packages/editors/voxel-map/src/ui/BlockLibrary.ts +++ b/packages/editors/voxel-map/src/ui/BlockLibrary.ts @@ -34,7 +34,7 @@ const kAllShapeIds: BlockShapeID[] = [ "slabBottom", "slabTop", "poleY", - "poleX", + "pole", "ramp", "rampCornerInner", "rampCornerOuter", diff --git a/packages/voxel-renderer/docs/Blocks.md b/packages/voxel-renderer/docs/Blocks.md index 9ca59c6..738ff5e 100644 --- a/packages/voxel-renderer/docs/Blocks.md +++ b/packages/voxel-renderer/docs/Blocks.md @@ -46,9 +46,7 @@ type BlockShapeID = | "slabBottom" | "slabTop" | "poleY" - | "poleX" - | "poleZ" - | "poleCross" + | "pole" | "ramp" | "rampCornerInner" | "rampCornerOuter" diff --git a/packages/voxel-renderer/docs/BuiltInShapes.md b/packages/voxel-renderer/docs/BuiltInShapes.md index 1118cfe..001931a 100644 --- a/packages/voxel-renderer/docs/BuiltInShapes.md +++ b/packages/voxel-renderer/docs/BuiltInShapes.md @@ -31,16 +31,7 @@ All pole shapes use **collisionHint**: [trimesh](./Collision.md) and occlude no | Shape ID | Occludes | |---:|---| | `poleY` | — | -| `poleX` | — | -| `poleZ` | — | -| `poleCross` | — | - -```ts -type PoleAxis = "x" | "z"; -``` - -Passed to the `Pole` constructor to select the axis along which the beam runs. -The default is `"z"`. +| `pole` | — | ### Ramps diff --git a/packages/voxel-renderer/examples/scripts/demo-shapes.ts b/packages/voxel-renderer/examples/scripts/demo-shapes.ts index 39fe6e7..ec57ddd 100644 --- a/packages/voxel-renderer/examples/scripts/demo-shapes.ts +++ b/packages/voxel-renderer/examples/scripts/demo-shapes.ts @@ -17,7 +17,6 @@ import { Cube } from "../../src/blocks/shapes/Cube.ts"; import { Slab } from "../../src/blocks/shapes/Slab.ts"; import { PoleY } from "../../src/blocks/shapes/PoleY.ts"; import { Pole } from "../../src/blocks/shapes/Pole.ts"; -import { PoleCross } from "../../src/blocks/shapes/PoleCross.ts"; import { Ramp } from "../../src/blocks/shapes/Ramp.ts"; import { RampCornerInner, @@ -64,20 +63,10 @@ const kShapes: ShapeEntry[] = [ color: "#26c6da" }, { - shape: new Pole("x"), - label: "poleX", - color: "#ff7043" - }, - { - shape: new Pole("z"), - label: "poleZ", + shape: new Pole(), + label: "pole", color: "#ab47bc" }, - { - shape: new PoleCross(), - label: "poleCross", - color: "#66bb6a" - }, // ── Ramp ──────────────────────────────────────────────────────────────────── { diff --git a/packages/voxel-renderer/src/blocks/BlockShape.ts b/packages/voxel-renderer/src/blocks/BlockShape.ts index 2377d01..eec23b5 100644 --- a/packages/voxel-renderer/src/blocks/BlockShape.ts +++ b/packages/voxel-renderer/src/blocks/BlockShape.ts @@ -38,9 +38,7 @@ export type BlockShapeID = | "slabBottom" | "slabTop" | "poleY" - | "poleX" - | "poleZ" - | "poleCross" + | "pole" | "ramp" | "rampCornerInner" | "rampCornerOuter" diff --git a/packages/voxel-renderer/src/blocks/BlockShapeRegistry.ts b/packages/voxel-renderer/src/blocks/BlockShapeRegistry.ts index ca217be..33b8935 100644 --- a/packages/voxel-renderer/src/blocks/BlockShapeRegistry.ts +++ b/packages/voxel-renderer/src/blocks/BlockShapeRegistry.ts @@ -6,7 +6,6 @@ import { Ramp } from "./shapes/Ramp.ts"; import { RampCornerInner, RampCornerOuter } from "./shapes/RampCorner.ts"; import { PoleY } from "./shapes/PoleY.ts"; import { Pole } from "./shapes/Pole.ts"; -import { PoleCross } from "./shapes/PoleCross.ts"; import { Stair, StairCornerInner, @@ -48,9 +47,7 @@ export class BlockShapeRegistry { .register(new Slab("bottom")) .register(new Slab("top")) .register(new PoleY()) - .register(new Pole("x")) - .register(new Pole("z")) - .register(new PoleCross()) + .register(new Pole()) .register(new Ramp()) .register(new RampCornerInner()) .register(new RampCornerOuter()) diff --git a/packages/voxel-renderer/src/blocks/shapes/Pole.ts b/packages/voxel-renderer/src/blocks/shapes/Pole.ts index e19a858..3f64aa1 100644 --- a/packages/voxel-renderer/src/blocks/shapes/Pole.ts +++ b/packages/voxel-renderer/src/blocks/shapes/Pole.ts @@ -13,28 +13,21 @@ import type { const kW = 3 / 8; const kH = 5 / 8; -export type PoleAxis = "x" | "z"; - /** * Pole — a narrow horizontal beam running along the X or Z axis. * Cross-section: 0.25×0.25 centered at 0.5, full length along the chosen axis. * Uses trimesh collision for accurate sub-voxel physics. * - * "poleZ": z=[0,1], centered x=[kW,kH], y=[kW,kH] - * "poleX": x=[0,1], centered z=[kW,kH], y=[kW,kH] + * "pole": z=[0,1], centered x=[kW,kH], y=[kW,kH] */ export class Pole implements BlockShape { readonly id: BlockShapeID; readonly collisionHint: BlockCollisionHint = "trimesh"; readonly faces: readonly FaceDefinition[]; - constructor( - axis: PoleAxis = "z" - ) { - this.id = axis === "z" ? "poleZ" : "poleX"; - this.faces = axis === "z" ? - Pole.#buildZFaces() : - Pole.#buildXFaces(); + constructor() { + this.id = "pole"; + this.faces = Pole.#buildZFaces(); } occludes( @@ -96,58 +89,4 @@ export class Pole implements BlockShape { } ]; } - - static #buildXFaces(): FaceDefinition[] { - // Beam along X: x=[0,1], centered z=[kW,kH], y=[kW,kH] - return [ - { - // NegX cap (x=0) - // e1=[0,kH-kW,0], e2=[0,kH-kW,kW-kH] → cross=[-(kH-kW)^2,0,0] ✓ - face: FACE.NegX, - normal: [-1, 0, 0], - vertices: [[0, kW, kH], [0, kH, kH], [0, kH, kW], [0, kW, kW]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // PosX cap (x=1) - // e1=[0,kH-kW,0], e2=[0,kH-kW,kH-kW] → cross=[(kH-kW)^2,0,0] ✓ - face: FACE.PosX, - normal: [1, 0, 0], - vertices: [[1, kW, kW], [1, kH, kW], [1, kH, kH], [1, kW, kH]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // Top (PosY, y=kH) - // e1=[0,0,kH-kW], e2=[1,0,kH-kW] → cross=[0,(kH-kW),0] ✓ - face: FACE.PosY, - normal: [0, 1, 0], - vertices: [[0, kH, kW], [0, kH, kH], [1, kH, kH], [1, kH, kW]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // Bottom (NegY, y=kW) - // e1=[0,0,kW-kH], e2=[1,0,kW-kH] → cross=[0,kW-kH,0] ✓ - face: FACE.NegY, - normal: [0, -1, 0], - vertices: [[0, kW, kH], [0, kW, kW], [1, kW, kW], [1, kW, kH]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // NegZ side (z=kW) - // e1=[-1,0,0], e2=[-1,kH-kW,0] → cross=[0,0,-(kH-kW)] ✓ - face: FACE.NegZ, - normal: [0, 0, -1], - vertices: [[1, kW, kW], [0, kW, kW], [0, kH, kW], [1, kH, kW]], - uvs: [[0, 0], [1, 0], [1, 1], [0, 1]] - }, - { - // PosZ side (z=kH) - // e1=[1,0,0], e2=[1,kH-kW,0] → cross=[0,0,kH-kW] ✓ - face: FACE.PosZ, - normal: [0, 0, 1], - vertices: [[0, kW, kH], [1, kW, kH], [1, kH, kH], [0, kH, kH]], - uvs: [[0, 0], [1, 0], [1, 1], [0, 1]] - } - ]; - } } diff --git a/packages/voxel-renderer/src/blocks/shapes/PoleCross.ts b/packages/voxel-renderer/src/blocks/shapes/PoleCross.ts deleted file mode 100644 index 3a9543e..0000000 --- a/packages/voxel-renderer/src/blocks/shapes/PoleCross.ts +++ /dev/null @@ -1,174 +0,0 @@ -// Import Internal Dependencies -import { - FACE -} from "../../utils/math.ts"; -import type { - BlockShape, - BlockCollisionHint, - BlockShapeID, - FaceDefinition -} from "../BlockShape.ts"; - -// CONSTANTS -const kW = 3 / 8; -const kH = 5 / 8; - -/** - * PoleCross — a horizontal plus/cross connector at mid-height. - * Two beams (along X and Z) merge at the center at y=[kW,kH]. - * Internal faces at the intersection are omitted to avoid overdraw. - * - * 18 faces total: - * 3 top (PosY) + 3 bottom (NegY) - * 4 end caps (NegX, PosX, NegZ, PosZ) - * 4 Z-beam outer sides (x=kW and x=kH for z=[0,kW] and z=[kH,1]) - * 4 X-beam outer sides (z=kW and z=kH for x=[0,kW] and x=[kH,1]) - */ -export class PoleCross implements BlockShape { - readonly id: BlockShapeID = "poleCross"; - readonly collisionHint: BlockCollisionHint = "trimesh"; - - readonly faces: readonly FaceDefinition[] = [ - // ── Top (PosY, y=kH) — 3 quads ────────────────────────────────────────── - { - // Z-strip: x=[kW,kH], z=[0,1] - face: FACE.PosY, - normal: [0, 1, 0], - vertices: [[kW, kH, 0], [kW, kH, 1], [kH, kH, 1], [kH, kH, 0]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // Left X-arm: x=[0,kW], z=[kW,kH] - face: FACE.PosY, - normal: [0, 1, 0], - vertices: [[0, kH, kW], [0, kH, kH], [kW, kH, kH], [kW, kH, kW]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // Right X-arm: x=[kH,1], z=[kW,kH] - face: FACE.PosY, - normal: [0, 1, 0], - vertices: [[kH, kH, kW], [kH, kH, kH], [1, kH, kH], [1, kH, kW]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - - // ── Bottom (NegY, y=kW) — 3 quads ──────────────────────────────────────── - { - // Z-strip: x=[kW,kH], z=[0,1] - face: FACE.NegY, - normal: [0, -1, 0], - vertices: [[kW, kW, 1], [kW, kW, 0], [kH, kW, 0], [kH, kW, 1]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // Left X-arm: x=[0,kW], z=[kW,kH] - face: FACE.NegY, - normal: [0, -1, 0], - vertices: [[0, kW, kH], [0, kW, kW], [kW, kW, kW], [kW, kW, kH]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // Right X-arm: x=[kH,1], z=[kW,kH] - face: FACE.NegY, - normal: [0, -1, 0], - vertices: [[kH, kW, kH], [kH, kW, kW], [1, kW, kW], [1, kW, kH]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - - // ── End caps — 4 quads ─────────────────────────────────────────────────── - { - // NegX cap (x=0): x-arm end, cross-section z=[kW,kH] y=[kW,kH] - face: FACE.NegX, - normal: [-1, 0, 0], - vertices: [[0, kW, kH], [0, kH, kH], [0, kH, kW], [0, kW, kW]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // PosX cap (x=1): x-arm end, cross-section z=[kW,kH] y=[kW,kH] - face: FACE.PosX, - normal: [1, 0, 0], - vertices: [[1, kW, kW], [1, kH, kW], [1, kH, kH], [1, kW, kH]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // NegZ cap (z=0): z-arm end, cross-section x=[kW,kH] y=[kW,kH] - face: FACE.NegZ, - normal: [0, 0, -1], - vertices: [[kH, kW, 0], [kW, kW, 0], [kW, kH, 0], [kH, kH, 0]], - uvs: [[0, 0], [1, 0], [1, 1], [0, 1]] - }, - { - // PosZ cap (z=1): z-arm end, cross-section x=[kW,kH] y=[kW,kH] - face: FACE.PosZ, - normal: [0, 0, 1], - vertices: [[kW, kW, 1], [kH, kW, 1], [kH, kH, 1], [kW, kH, 1]], - uvs: [[0, 0], [1, 0], [1, 1], [0, 1]] - }, - - // ── Z-beam outer sides (x=kW and x=kH, excluding intersection z=[kW,kH]) ─ - { - // NegX (x=kW), z=[0,kW] segment - face: FACE.NegX, - normal: [-1, 0, 0], - vertices: [[kW, kW, kW], [kW, kH, kW], [kW, kH, 0], [kW, kW, 0]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // NegX (x=kW), z=[kH,1] segment - face: FACE.NegX, - normal: [-1, 0, 0], - vertices: [[kW, kW, 1], [kW, kH, 1], [kW, kH, kH], [kW, kW, kH]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // PosX (x=kH), z=[0,kW] segment - face: FACE.PosX, - normal: [1, 0, 0], - vertices: [[kH, kW, 0], [kH, kH, 0], [kH, kH, kW], [kH, kW, kW]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - { - // PosX (x=kH), z=[kH,1] segment - face: FACE.PosX, - normal: [1, 0, 0], - vertices: [[kH, kW, kH], [kH, kH, kH], [kH, kH, 1], [kH, kW, 1]], - uvs: [[0, 0], [0, 1], [1, 1], [1, 0]] - }, - - // ── X-beam outer sides (z=kW and z=kH, excluding intersection x=[kW,kH]) ─ - { - // NegZ (z=kW), x=[0,kW] segment - face: FACE.NegZ, - normal: [0, 0, -1], - vertices: [[kW, kW, kW], [0, kW, kW], [0, kH, kW], [kW, kH, kW]], - uvs: [[0, 0], [1, 0], [1, 1], [0, 1]] - }, - { - // NegZ (z=kW), x=[kH,1] segment - face: FACE.NegZ, - normal: [0, 0, -1], - vertices: [[1, kW, kW], [kH, kW, kW], [kH, kH, kW], [1, kH, kW]], - uvs: [[0, 0], [1, 0], [1, 1], [0, 1]] - }, - { - // PosZ (z=kH), x=[0,kW] segment - face: FACE.PosZ, - normal: [0, 0, 1], - vertices: [[0, kW, kH], [kW, kW, kH], [kW, kH, kH], [0, kH, kH]], - uvs: [[0, 0], [1, 0], [1, 1], [0, 1]] - }, - { - // PosZ (z=kH), x=[kH,1] segment - face: FACE.PosZ, - normal: [0, 0, 1], - vertices: [[kH, kW, kH], [1, kW, kH], [1, kH, kH], [kH, kH, kH]], - uvs: [[0, 0], [1, 0], [1, 1], [0, 1]] - } - ]; - - occludes( - _face: FACE - ): boolean { - return false; - } -} diff --git a/packages/voxel-renderer/src/index.ts b/packages/voxel-renderer/src/index.ts index 342568d..c96f28e 100644 --- a/packages/voxel-renderer/src/index.ts +++ b/packages/voxel-renderer/src/index.ts @@ -12,8 +12,7 @@ export * from "./hooks.ts"; export { Cube } from "./blocks/shapes/Cube.ts"; export { Slab, type SlabType } from "./blocks/shapes/Slab.ts"; export { PoleY } from "./blocks/shapes/PoleY.ts"; -export { Pole, type PoleAxis } from "./blocks/shapes/Pole.ts"; -export { PoleCross } from "./blocks/shapes/PoleCross.ts"; +export { Pole } from "./blocks/shapes/Pole.ts"; export { Ramp } from "./blocks/shapes/Ramp.ts"; export { RampCornerInner, diff --git a/packages/voxel-renderer/test/blocks/BlockShapeRegistry.spec.ts b/packages/voxel-renderer/test/blocks/BlockShapeRegistry.spec.ts index 3f1a135..3e4c877 100644 --- a/packages/voxel-renderer/test/blocks/BlockShapeRegistry.spec.ts +++ b/packages/voxel-renderer/test/blocks/BlockShapeRegistry.spec.ts @@ -10,9 +10,7 @@ const kDefaultShapeIds = [ "slabBottom", "slabTop", "poleY", - "poleX", - "poleZ", - "poleCross", + "pole", "ramp", "rampCornerInner", "rampCornerOuter",