@buley/hexgrid-3d 3.6.0 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  A reusable 3D hexagonal grid visualization component for displaying content in an immersive spherical layout.
4
4
 
5
+ ## Documentation
6
+
7
+ - [Territory README](./src/territory/README.md)
8
+
5
9
  ## Features
6
10
 
7
11
  - **3D Hexagonal Grid Layout** - Spherical projection with customizable curvature
@@ -9,6 +13,7 @@ A reusable 3D hexagonal grid visualization component for displaying content in a
9
13
  - **Image Texture Mapping** - Automatic texture loading and caching
10
14
  - **Real-time Statistics** - Live telemetry and performance metrics
11
15
  - **Narration System** - Play-by-play commentary overlay
16
+ - **Territory Globe** - Deterministic wrapped globe topology for paid seed claims, recursive subdivision, delegated territory overlays, and conquest-driven occupation
12
17
  - **Web Worker Rendering** - High-performance offloaded calculations
13
18
  - **Multi-Input Support** - Touch gestures, mouse, and keyboard controls
14
19
  - **Responsive Design** - Adapts to mobile and desktop viewports
@@ -78,6 +83,39 @@ function AdvancedExample() {
78
83
  }
79
84
  ```
80
85
 
86
+ ### Territory Globe Example
87
+
88
+ ```tsx
89
+ import {
90
+ HexTerritoryGlobe,
91
+ generateCanonicalHexGlobe,
92
+ } from "@buley/hexgrid-3d";
93
+
94
+ const board = generateCanonicalHexGlobe({
95
+ boardId: "main",
96
+ curveUDeg: 360,
97
+ curveVDeg: 180,
98
+ rowCount: 180,
99
+ equatorColumns: 288,
100
+ minimumColumnsPerRow: 24,
101
+ poleMinScale: 0.25,
102
+ });
103
+
104
+ function TerritoryExample() {
105
+ return (
106
+ <HexTerritoryGlobe
107
+ cells={board.cells}
108
+ claimedCellIds={new Set(["main:r90:c144"])}
109
+ colorsByCellId={{ "main:r90:c144": "#59d0ff" }}
110
+ />
111
+ );
112
+ }
113
+ ```
114
+
115
+ When `tileRadius` is omitted, `HexTerritoryGlobe` auto-fits each latitude row to
116
+ the available spacing to avoid overlap on dense boards. Pass `tileRadius` only
117
+ when you intentionally want a manual radius override.
118
+
81
119
  ## Components
82
120
 
83
121
  ### HexGrid
@@ -112,8 +150,42 @@ Displays narration messages and real-time statistics in a dashboard-style overla
112
150
  | `isVisible` | `boolean` | Whether overlay is visible |
113
151
  | `onClose` | `() => void` | Callback when overlay is closed |
114
152
 
153
+ ### HexTerritoryGlobe
154
+
155
+ Wrapped React Three Fiber surface for territory-aware hex cells on a sphere.
156
+
157
+ **Props:**
158
+
159
+ | Prop | Type | Description |
160
+ | ---- | ---- | ----------- |
161
+ | `cells` | `HexTerritoryCell[]` | Deterministic canonical globe cells |
162
+ | `claimedCellIds` | `Iterable<string>` | Occupied or currently held roots |
163
+ | `lockedCellIds` | `Iterable<string>` | Visible but unclaimable roots |
164
+ | `colorsByCellId` | `Record<string, string>` | Per-root color overrides |
165
+ | `selectedCellId` | `string` | Active root highlight |
166
+ | `hoverCellId` | `string` | Hover highlight |
167
+ | `tileRadius` | `number` | Optional manual radius override; omit to auto-fit row-safe tile radii |
168
+ | `onSelectCell` | `(cell) => void` | Selection callback |
169
+ | `onHoverCell` | `(cell) => void` | Hover callback |
170
+
115
171
  ## Types
116
172
 
173
+ ### Territory Types
174
+
175
+ The package now exports territory-specific helpers:
176
+
177
+ - `CanonicalHexGlobeConfig`
178
+ - `HexTerritoryBoard`
179
+ - `HexTerritoryCell`
180
+ - `HexTerritoryAffiliation`
181
+ - `HexTerritoryAllianceBinding`
182
+ - `HexTerritoryRallyMarker`
183
+ - `HexNodePath`
184
+ - `HexwarEmbedRef`
185
+ - `HexTerritoryTickState`
186
+ - `HexwarNarrationEvent`
187
+ - `createHexwarNarrationAdapter()`
188
+
117
189
  ### Photo
118
190
 
119
191
  ```typescript
@@ -207,6 +279,7 @@ setCustomAccentColor("#ff00ff");
207
279
 
208
280
  ### Peer Dependencies
209
281
 
282
+ - `@react-three/fiber` ^9.4.2
210
283
  - `react` ^18.0.0
211
284
  - `react-dom` ^18.0.0
212
285
  - `next` ^14.0.0
@@ -0,0 +1,133 @@
1
+ /**
2
+ * GamePieceRenderer — Three.js mesh factory for game pieces on a geodesic sphere.
3
+ *
4
+ * Builds 3D meshes from PieceShape primitives, accepts custom Object3D instances,
5
+ * handles instanced rendering for performance, surface-normal alignment, stacking,
6
+ * and piece animations (spin, bob, pulse, wobble, orbit, glow).
7
+ */
8
+ import * as THREE from 'three';
9
+ import type { GamePiece, CellGameState } from '../types';
10
+ /**
11
+ * Build a Three.js Object3D from a GamePiece definition.
12
+ * Returns a Group containing the mesh, optional label, and optional count badge.
13
+ */
14
+ export declare function buildPieceMesh(piece: GamePiece): THREE.Group;
15
+ /**
16
+ * Place a piece group onto the sphere surface at a given hex center position.
17
+ * Orients the piece so "up" points away from the sphere center (surface normal).
18
+ *
19
+ * @param pieceGroup - The group returned by buildPieceMesh
20
+ * @param hexCenter - The 3D position of the hex center on the unit sphere
21
+ * @param sphereRadius - Radius of the rendered sphere
22
+ * @param offsetY - Additional height above surface (from GamePiece.offsetY)
23
+ */
24
+ export declare function placePieceOnSphere(pieceGroup: THREE.Group, hexCenter: {
25
+ x: number;
26
+ y: number;
27
+ z: number;
28
+ }, sphereRadius: number, offsetY?: number): void;
29
+ /**
30
+ * Animate a piece group based on its stored animation config.
31
+ * Call this every frame with the elapsed time.
32
+ *
33
+ * @param pieceGroup - The group with userData.animation
34
+ * @param time - Elapsed time in seconds
35
+ * @param deltaTime - Frame delta in seconds
36
+ */
37
+ export declare function animatePiece(pieceGroup: THREE.Group, time: number, _deltaTime: number): void;
38
+ /**
39
+ * Create a flat polygon mesh for a hex or pentagon cell on the sphere surface.
40
+ * Used by GameSphere to render the board itself.
41
+ *
42
+ * @param center - Hex center on unit sphere
43
+ * @param vertices - Ordered vertices of the hex/pentagon (on unit sphere)
44
+ * @param radius - Sphere radius for scaling
45
+ * @param color - Fill color
46
+ * @param elevation - How far above the sphere surface (0 = flush)
47
+ */
48
+ export declare function buildCellMesh(center: {
49
+ x: number;
50
+ y: number;
51
+ z: number;
52
+ }, vertices: {
53
+ x: number;
54
+ y: number;
55
+ z: number;
56
+ }[], radius: number, color?: string, elevation?: number): THREE.Mesh;
57
+ /**
58
+ * Build a cell border (wireframe outline) for a hex/pentagon on the sphere.
59
+ */
60
+ export declare function buildCellBorder(vertices: {
61
+ x: number;
62
+ y: number;
63
+ z: number;
64
+ }[], radius: number, color?: string, lineWidth?: number, elevation?: number): THREE.LineLoop;
65
+ /**
66
+ * Create a fog overlay sphere slightly larger than the game sphere.
67
+ * Individual cell fog is handled by modifying cell material opacity,
68
+ * but this provides a global atmospheric effect.
69
+ */
70
+ export declare function buildFogOverlay(radius: number, fogColor?: string): THREE.Mesh;
71
+ /**
72
+ * Build a glowing ring around a cell for highlights (attack target, selection, etc.)
73
+ */
74
+ export declare function buildHighlightRing(center: {
75
+ x: number;
76
+ y: number;
77
+ z: number;
78
+ }, radius: number, ringRadius?: number, color?: string, intensity?: number): THREE.Mesh;
79
+ export interface AttackAnimationConfig {
80
+ fromCenter: {
81
+ x: number;
82
+ y: number;
83
+ z: number;
84
+ };
85
+ toCenter: {
86
+ x: number;
87
+ y: number;
88
+ z: number;
89
+ };
90
+ sphereRadius: number;
91
+ color?: string;
92
+ particleCount?: number;
93
+ duration?: number;
94
+ }
95
+ /**
96
+ * Create an attack trail particle system between two cells on the sphere.
97
+ * Returns a Points object and an update function.
98
+ */
99
+ export declare function buildAttackTrail(config: AttackAnimationConfig): {
100
+ points: THREE.Points;
101
+ update: (progress: number) => void;
102
+ dispose: () => void;
103
+ };
104
+ export interface OrbitalStrikeConfig {
105
+ targetCenter: {
106
+ x: number;
107
+ y: number;
108
+ z: number;
109
+ };
110
+ sphereRadius: number;
111
+ color?: string;
112
+ trailColor?: string;
113
+ }
114
+ /**
115
+ * Create an orbital strike projectile that falls from high above to a cell.
116
+ * Returns the mesh, update function, and disposal.
117
+ */
118
+ export declare function buildOrbitalStrike(config: OrbitalStrikeConfig): {
119
+ group: THREE.Group;
120
+ update: (progress: number) => void;
121
+ dispose: () => void;
122
+ };
123
+ export declare function disposePieceGroup(group: THREE.Group): void;
124
+ /**
125
+ * Apply CellGameState to a cell's mesh and border.
126
+ * Updates color, opacity (fog), and highlight state.
127
+ */
128
+ export declare function applyCellState(cellMesh: THREE.Mesh, cellBorder: THREE.LineLoop | null, state: CellGameState, config?: {
129
+ fogDimOpacity?: number;
130
+ fogHiddenOpacity?: number;
131
+ fogExploredOpacity?: number;
132
+ }): void;
133
+ //# sourceMappingURL=GamePieceRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GamePieceRenderer.d.ts","sourceRoot":"","sources":["../../src/components/GamePieceRenderer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EACV,SAAS,EAIT,aAAa,EACd,MAAM,UAAU,CAAC;AA+NlB;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,CAAC,KAAK,CAuG5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,KAAK,CAAC,KAAK,EACvB,SAAS,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC9C,YAAY,EAAE,MAAM,EACpB,OAAO,GAAE,MAAU,GAClB,IAAI,CAYN;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,KAAK,CAAC,KAAK,EACvB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,IAAI,CAiDN;AAMD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAC3C,QAAQ,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