@wildshard/shard-format 0.51.0 → 0.52.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  import type { ShardEntryways } from './entryways.ts';
2
2
  import type { ShardProps } from './props.ts';
3
- import { propHullBounds } from './prop-hull.ts';
3
+ import { propCapsuleBounds, propHullBounds } from './prop-hull.ts';
4
4
  import type { ShardWater } from './water.ts';
5
5
  import { entryFootprints, clipEntryPolygon, obstructsEntry, type EntryVertex, type EntryFootprint } from './entryGeometry.ts';
6
6
  import { PropExtent, visitGlbTriangles } from './shardfile-assets.ts';
@@ -53,6 +53,7 @@ export function validateEntrywayClearance(source: { entryways: ShardEntryways; p
53
53
  for (const row of props.colliders) for (const shape of row.shapes) {
54
54
  if (shape.kind === 'box') boxTriangles(shape, inspect);
55
55
  else if (shape.kind === 'hull') { boxTriangles(propHullBounds(shape), inspect); }
56
+ else if (shape.kind === 'capsule') { boxTriangles(propCapsuleBounds(shape), inspect); }
56
57
  else {
57
58
  const dx = shape.to.x - shape.from.x, dz = shape.to.z - shape.from.z, run = Math.hypot(dx, dz) / shape.count, rise = (shape.to.y - shape.from.y) / shape.count;
58
59
  for (let i = 0; i < shape.count; i++) {
@@ -22,7 +22,7 @@ function boxTop(box: Box): EntryVertex[][] {
22
22
  function staticTops(rows: readonly ShardProps['colliders'][number][]): EntryVertex[][] {
23
23
  return rows.flatMap(row => row.shapes.flatMap(shape => {
24
24
  if (shape.kind === 'box') return boxTop(shape);
25
- if (shape.kind === 'hull') { return []; }
25
+ if (shape.kind === 'hull' || shape.kind === 'capsule') { return []; }
26
26
  const dx = shape.to.x - shape.from.x, dz = shape.to.z - shape.from.z, run = Math.hypot(dx, dz) / shape.count, rise = (shape.to.y - shape.from.y) / shape.count;
27
27
  return Array.from({ length: shape.count }, (_unused, i) => {
28
28
  const f = (i + 0.5) / shape.count, hy = Math.max(0.01, rise * (i + 1) / 2);
@@ -155,4 +155,57 @@ function propHullBounds(shape: HullPose): HullBounds {
155
155
  }
156
156
  }
157
157
 
158
- export { propHullBounds, solidHullWithinCell }
158
+ type CapsulePose = Readonly<GlbVertex> & {
159
+ readonly halfHeight: number
160
+ readonly radius: number
161
+ readonly yaw?: number | undefined
162
+ readonly rot?: (Readonly<GlbVertex> & { readonly w: number }) | undefined
163
+ }
164
+ const BELOW = -1
165
+ const ABOVE = 1
166
+ const SIGNS = [BELOW, ABOVE] as const
167
+
168
+ /** OF22a3: a capsule's local bounding box corners, posed as the capsule is. */
169
+ function capsuleCorners(shape: CapsulePose): number[] {
170
+ const across = shape.radius
171
+ const along = shape.halfHeight + shape.radius
172
+ return SIGNS.flatMap((sx: number): number[] =>
173
+ SIGNS.flatMap((sy: number): number[] =>
174
+ SIGNS.flatMap((sz: number): number[] => [
175
+ sx * across,
176
+ sy * along,
177
+ sz * across,
178
+ ]),
179
+ ),
180
+ )
181
+ }
182
+
183
+ /** A conservative clearance envelope for the posed capsule. */
184
+ function propCapsuleBounds(shape: CapsulePose): HullBounds {
185
+ return propHullBounds({ ...shape, points: capsuleCorners(shape) })
186
+ }
187
+
188
+ /** OF22a3: both posed end caps, swollen by the radius, stay inside the cell. */
189
+ function solidCapsuleWithinCell(shape: CapsulePose): boolean {
190
+ const ends = pointsInWorld({
191
+ ...shape,
192
+ points: [ZERO, -shape.halfHeight, ZERO, ZERO, shape.halfHeight, ZERO],
193
+ })
194
+ return (
195
+ ends.length === SIGNS.length &&
196
+ ends.every(
197
+ (end: Readonly<GlbVertex>): boolean =>
198
+ Math.abs(end.x) + shape.radius <= CELL_HALF_WIDTH &&
199
+ Math.abs(end.z) + shape.radius <= CELL_HALF_WIDTH &&
200
+ end.y - shape.radius >= -CELL_BELOW &&
201
+ end.y + shape.radius <= CELL_ABOVE,
202
+ )
203
+ )
204
+ }
205
+
206
+ export {
207
+ propCapsuleBounds,
208
+ propHullBounds,
209
+ solidCapsuleWithinCell,
210
+ solidHullWithinCell,
211
+ }
@@ -4,7 +4,7 @@ import { isJsonData } from './json.ts';
4
4
  import { PropMaterialsSchema, propMaterialTextureRefs, validatePropMaterials } from './propMaterials.ts';
5
5
  import { SplatTerrainSchema, validateSplatTerrain } from './splatTerrain.ts';
6
6
  import { glbPoint, glbTransform } from './glbTriangles.ts';
7
- import { solidHullWithinCell } from './prop-hull.ts';
7
+ import { solidCapsuleWithinCell, solidHullWithinCell } from './prop-hull.ts';
8
8
  import type { GlbVertex } from './glbTriangles.ts';
9
9
 
10
10
  const ref = v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u));
@@ -16,9 +16,18 @@ const height = v.pipe(v.number(), v.finite(), v.minValue(-CELL_BELOW), v.maxValu
16
16
  const finite = v.pipe(v.number(), v.finite());
17
17
  const extent = v.pipe(finite, v.minValue(0.005), v.maxValue(250));
18
18
  const point = v.strictObject({ x: coord, y: height, z: coord });
19
- const surface = v.optional(v.picklist(['wood', 'stone', 'grass', 'sand', 'rock', 'metal', 'earth', 'felt']));
19
+ /** OF22a3: a static solid's material is any engine contact material a bake tags (`planks`, `ground`, `flesh`, `shell` beside the body materials). */
20
+ const SURFACES = ['wood', 'stone', 'grass', 'sand', 'rock', 'metal', 'earth', 'felt', 'planks', 'ground', 'flesh', 'shell'] as const;
21
+ type PropSurface = typeof SURFACES[number];
22
+ const surface = v.optional(v.picklist(SURFACES));
23
+ const CONTACT_LEAST = 0;
24
+ const CONTACT_FRICTION_MAX = 2;
25
+ const GROUPS_MAX = 0xFF_FF_FF_FF;
26
+ /** OF22a3: a baked solid's own contact: its friction, and its Rapier interaction groups (membership high 16 bits, filter low 16). */
27
+ const contact = { friction: v.optional(v.pipe(v.number(), v.finite(), v.minValue(CONTACT_LEAST), v.maxValue(CONTACT_FRICTION_MAX))),
28
+ groups: v.optional(v.pipe(v.number(), v.integer(), v.minValue(CONTACT_LEAST), v.maxValue(GROUPS_MAX))) };
20
29
  const rotation = v.pipe(v.strictObject({ x: finite, y: finite, z: finite, w: finite }), v.check((q) => Math.abs(q.x ** 2 + q.y ** 2 + q.z ** 2 + q.w ** 2 - 1) < 1e-5, 'unit collider rotation'));
21
- const boxData = v.strictObject({ kind: v.literal('box'), x: coord, y: height, z: coord, hx: extent, hy: extent, hz: extent, yaw: v.optional(finite), rot: v.optional(rotation), surface });
30
+ const boxData = v.strictObject({ kind: v.literal('box'), x: coord, y: height, z: coord, hx: extent, hy: extent, hz: extent, yaw: v.optional(finite), rot: v.optional(rotation), surface, ...contact });
22
31
  function boxWithinCell(b: v.InferOutput<typeof boxData>): boolean {
23
32
  const q = b.rot ?? { x: 0, y: Math.sin((b.yaw ?? 0) / 2), z: 0, w: Math.cos((b.yaw ?? 0) / 2) };
24
33
  const transform = glbTransform({ translation: [b.x, b.y, b.z], rotation: [q.x, q.y, q.z, q.w] });
@@ -33,19 +42,27 @@ interface PropHull extends GlbVertex {
33
42
  yaw?: number | undefined;
34
43
  // oxlint-disable-next-line eslint/id-length -- Quaternion components are part of the wire.
35
44
  rot?: (GlbVertex & { w: number }) | undefined;
36
- surface?: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt' | undefined;
45
+ surface?: PropSurface | undefined;
46
+ friction?: number | undefined;
47
+ groups?: number | undefined;
37
48
  }
38
49
  const MIN_HULL_COORDS = 12;
39
- const MAX_HULL_COORDS = 192;
50
+ /** OF22a3: up to 256 points, the largest hull a bake keeps (Driftwood's is 168). */
51
+ const MAX_HULL_COORDS = 768;
40
52
  const AXES_PER_VERTEX = 3;
41
53
  const COLLIDER_UNIT = 1;
42
54
  const hullPoints = v.pipe(v.array(finite), v.minLength(MIN_HULL_COORDS), v.maxLength(MAX_HULL_COORDS));
43
55
  // oxlint-disable-next-line eslint/id-length -- A hull has the same cell-local pose as a prop box.
44
56
  const hullData = v.strictObject({ kind: v.literal('hull'), x: coord, y: height, z: coord, points: hullPoints,
45
- yaw: v.optional(finite), rot: v.optional(rotation), surface });
57
+ yaw: v.optional(finite), rot: v.optional(rotation), surface, ...contact });
46
58
  const hull = v.pipe(hullData, v.check<v.InferOutput<typeof hullData>, string>(solidHullWithinCell, 'solid hull within cell'));
47
- const treads = v.pipe(v.strictObject({ kind: v.literal('treads'), from: point, to: point, width: extent, count: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(256)), surface }), v.check((t) => Math.hypot(t.to.x - t.from.x, t.to.z - t.from.z) > 0 && t.to.y >= t.from.y && [t.from, t.to].every((p) => Math.abs(p.x) + t.width / 2 <= 250 && Math.abs(p.z) + t.width / 2 <= 250), 'bounded nondegenerate stair'));
48
- const collider = v.strictObject({ id, panel: v.nullable(id), initialActive: v.boolean(), shapes: v.pipe(v.array(v.variant('kind', [box, treads, hull])), v.minLength(1), v.maxLength(256)) });
59
+ const treads = v.pipe(v.strictObject({ kind: v.literal('treads'), from: point, to: point, width: extent, count: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(256)), surface, ...contact }), v.check((t) => Math.hypot(t.to.x - t.from.x, t.to.z - t.from.z) > 0 && t.to.y >= t.from.y && [t.from, t.to].every((p) => Math.abs(p.x) + t.width / 2 <= 250 && Math.abs(p.z) + t.width / 2 <= 250), 'bounded nondegenerate stair'));
60
+ /** OF22a3: an upright capsule (or turned by `yaw`/`rot`): the straight part's half height and the radius, whole inside the cell. */
61
+ // oxlint-disable-next-line eslint/id-length -- A capsule has the same cell-local pose as a prop box.
62
+ const capsuleData = v.strictObject({ kind: v.literal('capsule'), x: coord, y: height, z: coord, halfHeight: extent, radius: extent,
63
+ yaw: v.optional(finite), rot: v.optional(rotation), surface, ...contact });
64
+ const capsule = v.pipe(capsuleData, v.check<v.InferOutput<typeof capsuleData>, string>(solidCapsuleWithinCell, 'capsule within cell'));
65
+ const collider = v.strictObject({ id, panel: v.nullable(id), initialActive: v.boolean(), shapes: v.pipe(v.array(v.variant('kind', [box, treads, hull, capsule])), v.minLength(1), v.maxLength(256)) });
49
66
  const BODY_EXTENT_MIN = 0.005;
50
67
  const BODY_EXTENT_MAX = 8;
51
68
  const BODY_DENSITY_MIN = 1;
@@ -81,8 +98,9 @@ function bodiesAdmitted(section: { readonly bodies?: readonly { readonly id: str
81
98
  const owned = new Set(rows.map((row): string => row.panel));
82
99
  return ids.size === rows.length && owned.size === rows.length && rows.every((row): boolean => declared.has(row.panel) && !claimed.has(row.panel));
83
100
  }
84
- type CostedShape = Readonly<{ kind: 'treads'; count: number }> | Readonly<{ kind: 'hull'; points: readonly number[] }> | Readonly<{ kind: 'box' }>;
85
- const COLLIDER_BUDGET = 2048;
101
+ type CostedShape = Readonly<{ kind: 'treads'; count: number }> | Readonly<{ kind: 'hull'; points: readonly number[] }> | Readonly<{ kind: 'box' | 'capsule' }>;
102
+ /** OF22a3: a baked island's solids (Driftwood: about 13,500 units, which its native bake admits today) fit; a hull point costs one unit. */
103
+ const COLLIDER_BUDGET = 16_384;
86
104
  function withinColliderBudget(rows: readonly Readonly<{ shapes: readonly CostedShape[] }>[]): boolean {
87
105
  let total = 0;
88
106
  for (const row of rows) {
@@ -179,8 +197,10 @@ interface PropsDataFields {
179
197
  z: number;
180
198
  w: number;
181
199
  } | undefined;
182
- surface?: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt' | undefined;
183
- }) | PropHull | ({
200
+ surface?: PropSurface | undefined;
201
+ friction?: number | undefined;
202
+ groups?: number | undefined;
203
+ }) | PropHull | PropCapsule | ({
184
204
  kind: 'treads';
185
205
  from: {
186
206
  x: number;
@@ -194,7 +214,9 @@ interface PropsDataFields {
194
214
  };
195
215
  width: number;
196
216
  count: number;
197
- surface?: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt' | undefined;
217
+ surface?: PropSurface | undefined;
218
+ friction?: number | undefined;
219
+ groups?: number | undefined;
198
220
  }))[];
199
221
  })[];
200
222
  textures: ({
@@ -203,6 +225,18 @@ interface PropsDataFields {
203
225
  })[];
204
226
  bodies?: PropsBody[];
205
227
  }
228
+ /** OF22a3: a static capsule solid. */
229
+ interface PropCapsule extends GlbVertex {
230
+ kind: 'capsule';
231
+ halfHeight: number;
232
+ radius: number;
233
+ yaw?: number | undefined;
234
+ // oxlint-disable-next-line eslint/id-length -- Quaternion components are part of the wire.
235
+ rot?: (GlbVertex & { w: number }) | undefined;
236
+ surface?: PropSurface | undefined;
237
+ friction?: number | undefined;
238
+ groups?: number | undefined;
239
+ }
206
240
  /** SS9a: a point, or a cuboid's half extents, in metres. */
207
241
  interface PropsBodyVector { x: number; y: number; z: number }
208
242
  /** SS9a: one touchable panel's body. */