@wildshard/shard-format 0.48.0 → 0.49.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 +1 -1
- package/src/format/creature-ability-push.ts +67 -0
- package/src/format/creature-layers.ts +5 -24
- package/src/format/directorStages.ts +6 -3
- package/src/format/entryClearance.ts +2 -0
- package/src/format/entryLanding.ts +1 -1
- package/src/format/headless-sections.ts +2 -0
- package/src/format/liftApproach.ts +1 -0
- package/src/format/portalFloor.ts +1 -1
- package/src/format/prop-hull.ts +158 -0
- package/src/format/props.ts +35 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.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": {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
check,
|
|
3
|
+
exactOptional,
|
|
4
|
+
finite,
|
|
5
|
+
maxValue,
|
|
6
|
+
minValue,
|
|
7
|
+
number,
|
|
8
|
+
picklist,
|
|
9
|
+
pipe,
|
|
10
|
+
} from 'valibot'
|
|
11
|
+
|
|
12
|
+
import type { CheckAction, ExactOptionalSchema, GenericSchema } from 'valibot'
|
|
13
|
+
|
|
14
|
+
/** How an ability pushes the player it strikes, and where on that player it aims (OF20c1). */
|
|
15
|
+
interface CreatureAbilityPush {
|
|
16
|
+
/** `knockback` slides the struck player; `impulse` throws it along the strike's facing. */
|
|
17
|
+
effect?: 'knockback' | 'impulse'
|
|
18
|
+
/** Knockback: horizontal travel in metres on clear ground. Impulse: horizontal speed in m/s (at most 40). */
|
|
19
|
+
strength?: number
|
|
20
|
+
/** Impulse only: upward speed in m/s. */
|
|
21
|
+
lift?: number
|
|
22
|
+
/** Metres above the target's feet the strike aims at (a stoop at the chest); absent, the feet. */
|
|
23
|
+
aimHeight?: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const ZERO = 0
|
|
27
|
+
const MAX_KNOCKBACK_DISTANCE = 60
|
|
28
|
+
const MAX_IMPULSE_SPEED = 40
|
|
29
|
+
const MAX_AIM_HEIGHT = 10
|
|
30
|
+
const scalar = pipe(number(), finite())
|
|
31
|
+
const knockback = pipe(scalar, minValue(ZERO), maxValue(MAX_KNOCKBACK_DISTANCE))
|
|
32
|
+
const impulse = pipe(scalar, minValue(ZERO), maxValue(MAX_IMPULSE_SPEED))
|
|
33
|
+
const aim = pipe(scalar, minValue(ZERO), maxValue(MAX_AIM_HEIGHT))
|
|
34
|
+
|
|
35
|
+
/** The ability row's push fields, spread into its strict object. */
|
|
36
|
+
type Optional<Value> = ExactOptionalSchema<GenericSchema<Value>, undefined>
|
|
37
|
+
const abilityPushFields: {
|
|
38
|
+
effect: Optional<'knockback' | 'impulse'>
|
|
39
|
+
strength: Optional<number>
|
|
40
|
+
lift: Optional<number>
|
|
41
|
+
aimHeight: Optional<number>
|
|
42
|
+
} = {
|
|
43
|
+
effect: exactOptional(picklist(['knockback', 'impulse'])),
|
|
44
|
+
strength: exactOptional(knockback),
|
|
45
|
+
lift: exactOptional(impulse),
|
|
46
|
+
aimHeight: exactOptional(aim),
|
|
47
|
+
}
|
|
48
|
+
const PUSH_RULE =
|
|
49
|
+
'Creature push effect and strength go together; lift needs an impulse of at most 40 m/s'
|
|
50
|
+
const pushRule = ({
|
|
51
|
+
effect,
|
|
52
|
+
strength,
|
|
53
|
+
lift,
|
|
54
|
+
}: Readonly<CreatureAbilityPush>): boolean =>
|
|
55
|
+
(effect === undefined) === (strength === undefined) &&
|
|
56
|
+
(lift === undefined || effect === 'impulse') &&
|
|
57
|
+
(effect !== 'impulse' || (strength ?? ZERO) <= MAX_IMPULSE_SPEED)
|
|
58
|
+
/** The push rule, typed to the row it guards. */
|
|
59
|
+
function abilityPushCheck<Row extends CreatureAbilityPush>(): CheckAction<
|
|
60
|
+
Row,
|
|
61
|
+
typeof PUSH_RULE
|
|
62
|
+
> {
|
|
63
|
+
return check<Row, typeof PUSH_RULE>(pushRule, PUSH_RULE)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { abilityPushCheck, abilityPushFields }
|
|
67
|
+
export type { CreatureAbilityPush }
|
|
@@ -20,12 +20,14 @@ import {
|
|
|
20
20
|
union,
|
|
21
21
|
} from 'valibot'
|
|
22
22
|
|
|
23
|
+
import { abilityPushCheck, abilityPushFields } from './creature-ability-push.ts'
|
|
23
24
|
import { CreatureProjectileSchema } from './creature-projectile.ts'
|
|
24
25
|
import { CreatureSocketNameSchema } from './creature-volumes.ts'
|
|
25
26
|
import { CreatureSkinClipNameSchema } from './skinData.ts'
|
|
26
27
|
import { StrikeTellKindSchema } from './spawnCombat.ts'
|
|
27
28
|
import { HuntTuningSchema } from './speciesPrograms.ts'
|
|
28
29
|
|
|
30
|
+
import type { CreatureAbilityPush } from './creature-ability-push.ts'
|
|
29
31
|
import type { CreatureAttackable } from './creature-attackable.ts'
|
|
30
32
|
import type { CreatureBody } from './creature-body.ts'
|
|
31
33
|
import type { CreatureMount } from './creature-mount.ts'
|
|
@@ -78,7 +80,7 @@ interface CreatureSenses {
|
|
|
78
80
|
reveal?: number
|
|
79
81
|
}
|
|
80
82
|
/** Ordered strike-row references. A scalar range means zero through that radius. */
|
|
81
|
-
interface CreatureAbility {
|
|
83
|
+
interface CreatureAbility extends CreatureAbilityPush {
|
|
82
84
|
use: string
|
|
83
85
|
range: number | [number, number]
|
|
84
86
|
cooldown: number
|
|
@@ -90,9 +92,6 @@ interface CreatureAbility {
|
|
|
90
92
|
duration?: number
|
|
91
93
|
from?: string
|
|
92
94
|
clip?: CreatureSkinClipName
|
|
93
|
-
effect?: 'knockback'
|
|
94
|
-
/** Horizontal travel in metres on clear ground. */
|
|
95
|
-
strength?: number
|
|
96
95
|
tell?: StrikeTellKind
|
|
97
96
|
projectile?: CreatureProjectile
|
|
98
97
|
}
|
|
@@ -127,7 +126,6 @@ const MAX_SOUND = 4096
|
|
|
127
126
|
const MAX_RADIUS = 500
|
|
128
127
|
const MAX_SPEED = 15
|
|
129
128
|
const MAX_TIME = 86_400
|
|
130
|
-
const MAX_KNOCKBACK_DISTANCE = 60
|
|
131
129
|
const MAX_AMOUNT = 10_000_000
|
|
132
130
|
const MAX_CALLS = 32
|
|
133
131
|
const MAX_TUNING_FIELDS = 64
|
|
@@ -140,11 +138,6 @@ const speed = pipe(scalar, minValue(ZERO), maxValue(MAX_SPEED))
|
|
|
140
138
|
const unit = pipe(scalar, minValue(ZERO), maxValue(ONE))
|
|
141
139
|
const time = pipe(scalar, minValue(ZERO), maxValue(MAX_TIME))
|
|
142
140
|
const amount = pipe(scalar, minValue(ZERO), maxValue(MAX_AMOUNT))
|
|
143
|
-
const knockbackDistance = pipe(
|
|
144
|
-
scalar,
|
|
145
|
-
minValue(ZERO),
|
|
146
|
-
maxValue(MAX_KNOCKBACK_DISTANCE),
|
|
147
|
-
)
|
|
148
141
|
const orderedRadius = pipe(
|
|
149
142
|
tuple([radius, radius]),
|
|
150
143
|
check<[number, number], 'Ordered creature ability range'>(
|
|
@@ -235,26 +228,14 @@ const abilityRow = strictObject({
|
|
|
235
228
|
duration: exactOptional(time),
|
|
236
229
|
from: exactOptional(CreatureSocketNameSchema),
|
|
237
230
|
clip: exactOptional(CreatureSkinClipNameSchema),
|
|
238
|
-
|
|
239
|
-
strength: exactOptional(knockbackDistance),
|
|
231
|
+
...abilityPushFields,
|
|
240
232
|
tell: exactOptional(StrikeTellKindSchema),
|
|
241
233
|
projectile: exactOptional(CreatureProjectileSchema),
|
|
242
234
|
})
|
|
243
|
-
const abilityEffectCheck = check<
|
|
244
|
-
CreatureAbility,
|
|
245
|
-
'Creature knockback effect and strength must be specified together'
|
|
246
|
-
>(
|
|
247
|
-
({
|
|
248
|
-
effect,
|
|
249
|
-
strength,
|
|
250
|
-
}: Readonly<Pick<CreatureAbility, 'effect' | 'strength'>>): boolean =>
|
|
251
|
-
(effect === undefined) === (strength === undefined),
|
|
252
|
-
'Creature knockback effect and strength must be specified together',
|
|
253
|
-
)
|
|
254
235
|
const CreatureAbilitySchema: GenericSchema<
|
|
255
236
|
CreatureAbilityInput,
|
|
256
237
|
CreatureAbility
|
|
257
|
-
> = pipe(abilityRow,
|
|
238
|
+
> = pipe(abilityRow, abilityPushCheck<CreatureAbility>())
|
|
258
239
|
const callVariants = pipe(array(sound), maxLength(MAX_CALLS))
|
|
259
240
|
const CreaturePresentationSchema: GenericSchema<CreaturePresentation> =
|
|
260
241
|
strictObject({
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
2
|
import { compileDirectorWhen } from './directorWhen.ts';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const KEY_LENGTH = 128;
|
|
5
|
+
const key = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*$/u), v.maxLength(KEY_LENGTH));
|
|
6
|
+
// A quest flag can include the source's colon-delimited namespace.
|
|
7
|
+
const questFlag = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*(?::[a-z0-9][a-z0-9.-]*)*$/u), v.maxLength(KEY_LENGTH));
|
|
5
8
|
const name = v.pipe(v.string(), v.regex(/^[A-Za-z_][A-Za-z0-9_]*$/u), v.maxLength(64));
|
|
6
|
-
const bindingSchema = v.pipe(v.string(), v.maxLength(256), v.regex(/^(?:(?:
|
|
9
|
+
const bindingSchema = v.pipe(v.string(), v.maxLength(256), v.regex(/^(?:flag:[a-z][a-z0-9.-]*(?::[a-z0-9][a-z0-9.-]*)*|(?:zone|event):[a-z][a-z0-9.-]*|actor:[a-z][a-z0-9.-]*\.(?:dead|present)|day:(?:0(?:\.[0-9]+)?|1)\.\.(?:0(?:\.[0-9]+)?|1))$/u));
|
|
7
10
|
const value = v.pipe(v.number(), v.finite(), v.minValue(-10000), v.maxValue(10000));
|
|
8
11
|
const action = v.union([
|
|
9
12
|
v.strictObject({ spawn: key }), v.strictObject({ despawn: key }),
|
|
10
|
-
v.strictObject({ flag: v.strictObject({ key, value: v.boolean() }) }),
|
|
13
|
+
v.strictObject({ flag: v.strictObject({ key: questFlag, value: v.boolean() }) }),
|
|
11
14
|
v.strictObject({ score: key }), v.strictObject({ weather: key }),
|
|
12
15
|
v.strictObject({ toast: key }), v.strictObject({ reward: key }),
|
|
13
16
|
v.strictObject({ emit: key, value: v.optional(v.union([v.boolean(), value]), 0) }),
|
|
@@ -1,5 +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
4
|
import type { ShardWater } from './water.ts';
|
|
4
5
|
import { entryFootprints, clipEntryPolygon, obstructsEntry, type EntryVertex, type EntryFootprint } from './entryGeometry.ts';
|
|
5
6
|
import { PropExtent, visitGlbTriangles } from './shardfile-assets.ts';
|
|
@@ -51,6 +52,7 @@ export function validateEntrywayClearance(source: { entryways: ShardEntryways; p
|
|
|
51
52
|
// Hidden/inactive panels can become active, so their authored shapes still count.
|
|
52
53
|
for (const row of props.colliders) for (const shape of row.shapes) {
|
|
53
54
|
if (shape.kind === 'box') boxTriangles(shape, inspect);
|
|
55
|
+
else if (shape.kind === 'hull') { boxTriangles(propHullBounds(shape), inspect); }
|
|
54
56
|
else {
|
|
55
57
|
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;
|
|
56
58
|
for (let i = 0; i < shape.count; i++) {
|
|
@@ -39,7 +39,7 @@ export function validateSocketLandings(source: { entryways: ShardEntryways; terr
|
|
|
39
39
|
if (!row.initialActive || row.panel !== null) continue;
|
|
40
40
|
for (const shape of row.shapes) {
|
|
41
41
|
if (shape.kind === 'box') decks.push(...boxTop(shape));
|
|
42
|
-
else {
|
|
42
|
+
else if (shape.kind === 'treads') {
|
|
43
43
|
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;
|
|
44
44
|
for (let i = 0; i < shape.count; i++) {
|
|
45
45
|
const f = (i + 0.5) / shape.count, hy = Math.max(0.01, rise * (i + 1) / 2);
|
|
@@ -14,6 +14,8 @@ export const HEADLESS_CONTEXT_SECTIONS = [
|
|
|
14
14
|
'world/targets',
|
|
15
15
|
'sim/runtime-plan',
|
|
16
16
|
'sim/bodies',
|
|
17
|
+
// The offline simulation reads the ordinary portal ride from this plan.
|
|
18
|
+
'client/plan',
|
|
17
19
|
] as const
|
|
18
20
|
|
|
19
21
|
/** Explicit admitted decision/move context crossing the worker boundary; no ABI is inferred from bytes. */
|
|
@@ -22,6 +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
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;
|
|
26
27
|
return Array.from({ length: shape.count }, (_unused, i) => {
|
|
27
28
|
const f = (i + 0.5) / shape.count, hy = Math.max(0.01, rise * (i + 1) / 2);
|
|
@@ -24,7 +24,7 @@ export function validatePortalFloors(entries: readonly PortalLinkEntry[], source
|
|
|
24
24
|
if (!row.initialActive || row.panel !== null) throw new Error('Portal floor is not permanent');
|
|
25
25
|
for (const shape of row.shapes) {
|
|
26
26
|
if (shape.kind === 'box') result.push(...boxTop(shape));
|
|
27
|
-
else {
|
|
27
|
+
else if (shape.kind === 'treads') {
|
|
28
28
|
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;
|
|
29
29
|
for (let i = 0; i < shape.count; i++) {
|
|
30
30
|
const f = (i + 0.5) / shape.count, hy = Math.max(0.01, rise * (i + 1) / 2);
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/* oxlint-disable id-length -- The collision and GLB wire contracts use x, y, z, w and half extents. */
|
|
2
|
+
import { CELL_ABOVE, CELL_BELOW } from './contentBounds.ts'
|
|
3
|
+
import { glbPoint, glbTransform } from './glbTriangles.ts'
|
|
4
|
+
|
|
5
|
+
import type { GlbVertex } from './glbTriangles.ts'
|
|
6
|
+
|
|
7
|
+
type HullPose = Readonly<GlbVertex> & {
|
|
8
|
+
readonly points: readonly number[]
|
|
9
|
+
readonly yaw?: number | undefined
|
|
10
|
+
readonly rot?: (Readonly<GlbVertex> & { readonly w: number }) | undefined
|
|
11
|
+
}
|
|
12
|
+
type HullBounds = GlbVertex & {
|
|
13
|
+
readonly kind: 'box'
|
|
14
|
+
readonly hx: number
|
|
15
|
+
readonly hy: number
|
|
16
|
+
readonly hz: number
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const CELL_HALF_WIDTH = 250
|
|
20
|
+
const DIAMETER = 2
|
|
21
|
+
const ZERO = 0
|
|
22
|
+
const CELL_WIDTH = CELL_HALF_WIDTH * DIAMETER
|
|
23
|
+
const LOCAL_LIMIT = Math.hypot(CELL_WIDTH, CELL_ABOVE + CELL_BELOW, CELL_WIDTH)
|
|
24
|
+
const COMPONENTS = 3
|
|
25
|
+
const MIN_VERTICES = 4
|
|
26
|
+
const PLANE_EPSILON = 1e-5
|
|
27
|
+
|
|
28
|
+
function pointsInWorld(shape: HullPose): GlbVertex[] {
|
|
29
|
+
const halfYaw = (shape.yaw ?? ZERO) / DIAMETER
|
|
30
|
+
const rotation = shape.rot ?? {
|
|
31
|
+
x: 0,
|
|
32
|
+
y: Math.sin(halfYaw),
|
|
33
|
+
z: 0,
|
|
34
|
+
w: Math.cos(halfYaw),
|
|
35
|
+
}
|
|
36
|
+
const matrix = glbTransform({
|
|
37
|
+
translation: [shape.x, shape.y, shape.z],
|
|
38
|
+
rotation: [rotation.x, rotation.y, rotation.z, rotation.w],
|
|
39
|
+
})
|
|
40
|
+
const result: GlbVertex[] = []
|
|
41
|
+
for (let index = 0; index < shape.points.length; index += COMPONENTS) {
|
|
42
|
+
const [localX, localY, localZ] = shape.points.slice(
|
|
43
|
+
index,
|
|
44
|
+
index + COMPONENTS,
|
|
45
|
+
)
|
|
46
|
+
if (localX === undefined || localY === undefined || localZ === undefined) {
|
|
47
|
+
return []
|
|
48
|
+
}
|
|
49
|
+
result.push(
|
|
50
|
+
glbPoint(matrix, {
|
|
51
|
+
x: Math.fround(localX),
|
|
52
|
+
y: Math.fround(localY),
|
|
53
|
+
z: Math.fround(localZ),
|
|
54
|
+
}),
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
return result
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function insideCell(vertex: Readonly<GlbVertex>): boolean {
|
|
61
|
+
return (
|
|
62
|
+
Math.abs(vertex.x) <= CELL_HALF_WIDTH &&
|
|
63
|
+
Math.abs(vertex.z) <= CELL_HALF_WIDTH &&
|
|
64
|
+
vertex.y >= -CELL_BELOW &&
|
|
65
|
+
vertex.y <= CELL_ABOVE
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function longest(points: readonly Readonly<GlbVertex>[]): Readonly<GlbVertex> {
|
|
70
|
+
let vector = { x: 0, y: 0, z: 0 }
|
|
71
|
+
let maxLength = 0
|
|
72
|
+
for (const point of points) {
|
|
73
|
+
const length = point.x * point.x + point.y * point.y + point.z * point.z
|
|
74
|
+
if (length > maxLength) {
|
|
75
|
+
maxLength = length
|
|
76
|
+
vector = point
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return vector
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function hasVolume(
|
|
83
|
+
vertices: readonly Readonly<GlbVertex>[],
|
|
84
|
+
first: Readonly<GlbVertex>,
|
|
85
|
+
): boolean {
|
|
86
|
+
const offsets = vertices.map((point: Readonly<GlbVertex>): GlbVertex => ({
|
|
87
|
+
x: point.x - first.x,
|
|
88
|
+
y: point.y - first.y,
|
|
89
|
+
z: point.z - first.z,
|
|
90
|
+
}))
|
|
91
|
+
const axis = longest(offsets)
|
|
92
|
+
const normal = longest(
|
|
93
|
+
offsets.map((point: Readonly<GlbVertex>): GlbVertex => ({
|
|
94
|
+
x: axis.y * point.z - axis.z * point.y,
|
|
95
|
+
y: axis.z * point.x - axis.x * point.z,
|
|
96
|
+
z: axis.x * point.y - axis.y * point.x,
|
|
97
|
+
})),
|
|
98
|
+
)
|
|
99
|
+
const length = Math.hypot(normal.x, normal.y, normal.z)
|
|
100
|
+
return (
|
|
101
|
+
length > ZERO &&
|
|
102
|
+
offsets.some(
|
|
103
|
+
(point: Readonly<GlbVertex>): boolean =>
|
|
104
|
+
Math.abs(normal.x * point.x + normal.y * point.y + normal.z * point.z) >
|
|
105
|
+
PLANE_EPSILON * length,
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Require volume after rounding the local vertices to Rapier's float32 coordinates. */
|
|
111
|
+
function solidHullWithinCell(shape: HullPose): boolean {
|
|
112
|
+
const { points } = shape
|
|
113
|
+
if (
|
|
114
|
+
points.length < MIN_VERTICES * COMPONENTS ||
|
|
115
|
+
points.length % COMPONENTS !== ZERO ||
|
|
116
|
+
!points.every((value): boolean => Math.abs(value) <= LOCAL_LIMIT)
|
|
117
|
+
) {
|
|
118
|
+
return false
|
|
119
|
+
}
|
|
120
|
+
const posed = pointsInWorld(shape)
|
|
121
|
+
const [first] = posed
|
|
122
|
+
if (
|
|
123
|
+
first === undefined ||
|
|
124
|
+
!posed.every((vertex: Readonly<GlbVertex>): boolean => insideCell(vertex))
|
|
125
|
+
) {
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
return hasVolume(posed, first)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function axisBounds(values: readonly number[]): readonly [number, number] {
|
|
132
|
+
return [Math.min(...values), Math.max(...values)]
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** A conservative clearance envelope for the posed convex solid. */
|
|
136
|
+
function propHullBounds(shape: HullPose): HullBounds {
|
|
137
|
+
const points = pointsInWorld(shape)
|
|
138
|
+
const [minX, maxX] = axisBounds(
|
|
139
|
+
points.map((point: Readonly<GlbVertex>): number => point.x),
|
|
140
|
+
)
|
|
141
|
+
const [minY, maxY] = axisBounds(
|
|
142
|
+
points.map((point: Readonly<GlbVertex>): number => point.y),
|
|
143
|
+
)
|
|
144
|
+
const [minZ, maxZ] = axisBounds(
|
|
145
|
+
points.map((point: Readonly<GlbVertex>): number => point.z),
|
|
146
|
+
)
|
|
147
|
+
return {
|
|
148
|
+
kind: 'box',
|
|
149
|
+
x: (minX + maxX) / DIAMETER,
|
|
150
|
+
y: (minY + maxY) / DIAMETER,
|
|
151
|
+
z: (minZ + maxZ) / DIAMETER,
|
|
152
|
+
hx: (maxX - minX) / DIAMETER,
|
|
153
|
+
hy: (maxY - minY) / DIAMETER,
|
|
154
|
+
hz: (maxZ - minZ) / DIAMETER,
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { propHullBounds, solidHullWithinCell }
|
package/src/format/props.ts
CHANGED
|
@@ -4,6 +4,8 @@ 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';
|
|
8
|
+
import type { GlbVertex } from './glbTriangles.ts';
|
|
7
9
|
|
|
8
10
|
const ref = v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u));
|
|
9
11
|
const id = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*$/u), v.maxLength(128));
|
|
@@ -25,8 +27,25 @@ function boxWithinCell(b: v.InferOutput<typeof boxData>): boolean {
|
|
|
25
27
|
})).every(vertex => Math.abs(vertex.x) <= 250 && Math.abs(vertex.z) <= 250 && vertex.y >= -CELL_BELOW && vertex.y <= CELL_ABOVE);
|
|
26
28
|
}
|
|
27
29
|
const box = v.pipe(boxData, v.check(boxWithinCell, 'collider within cell'));
|
|
30
|
+
interface PropHull extends GlbVertex {
|
|
31
|
+
kind: 'hull';
|
|
32
|
+
points: number[];
|
|
33
|
+
yaw?: number | undefined;
|
|
34
|
+
// oxlint-disable-next-line eslint/id-length -- Quaternion components are part of the wire.
|
|
35
|
+
rot?: (GlbVertex & { w: number }) | undefined;
|
|
36
|
+
surface?: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt' | undefined;
|
|
37
|
+
}
|
|
38
|
+
const MIN_HULL_COORDS = 12;
|
|
39
|
+
const MAX_HULL_COORDS = 192;
|
|
40
|
+
const AXES_PER_VERTEX = 3;
|
|
41
|
+
const COLLIDER_UNIT = 1;
|
|
42
|
+
const hullPoints = v.pipe(v.array(finite), v.minLength(MIN_HULL_COORDS), v.maxLength(MAX_HULL_COORDS));
|
|
43
|
+
// oxlint-disable-next-line eslint/id-length -- A hull has the same cell-local pose as a prop box.
|
|
44
|
+
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 });
|
|
46
|
+
const hull = v.pipe(hullData, v.check<v.InferOutput<typeof hullData>, string>(solidHullWithinCell, 'solid hull within cell'));
|
|
28
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'));
|
|
29
|
-
const collider = v.strictObject({ id, panel: v.nullable(id), initialActive: v.boolean(), shapes: v.pipe(v.array(v.variant('kind', [box, treads])), v.minLength(1), v.maxLength(256)) });
|
|
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)) });
|
|
30
49
|
const BODY_EXTENT_MIN = 0.005;
|
|
31
50
|
const BODY_EXTENT_MAX = 8;
|
|
32
51
|
const BODY_DENSITY_MIN = 1;
|
|
@@ -62,6 +81,19 @@ function bodiesAdmitted(section: { readonly bodies?: readonly { readonly id: str
|
|
|
62
81
|
const owned = new Set(rows.map((row): string => row.panel));
|
|
63
82
|
return ids.size === rows.length && owned.size === rows.length && rows.every((row): boolean => declared.has(row.panel) && !claimed.has(row.panel));
|
|
64
83
|
}
|
|
84
|
+
type CostedShape = Readonly<{ kind: 'treads'; count: number }> | Readonly<{ kind: 'hull'; points: readonly number[] }> | Readonly<{ kind: 'box' }>;
|
|
85
|
+
const COLLIDER_BUDGET = 2048;
|
|
86
|
+
function withinColliderBudget(rows: readonly Readonly<{ shapes: readonly CostedShape[] }>[]): boolean {
|
|
87
|
+
let total = 0;
|
|
88
|
+
for (const row of rows) {
|
|
89
|
+
for (const shape of row.shapes) {
|
|
90
|
+
if (shape.kind === 'treads') { total += shape.count; }
|
|
91
|
+
else if (shape.kind === 'hull') { total += shape.points.length / AXES_PER_VERTEX; }
|
|
92
|
+
else { total += COLLIDER_UNIT; }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return total <= COLLIDER_BUDGET;
|
|
96
|
+
}
|
|
65
97
|
/** Declared self-contained GLBs: merged tile meshes, EXT_mesh_gpu_instancing lists, far proxy and script-addressable panels. */
|
|
66
98
|
export const PropsSchema: v.GenericSchema<PropsDataInput, PropsData> = v.pipe(v.unknown(), v.check(isJsonData, 'JSON-only props'), v.strictObject({ version: v.literal(1), family: id,
|
|
67
99
|
materials: v.exactOptional(PropMaterialsSchema),
|
|
@@ -76,7 +108,7 @@ export const PropsSchema: v.GenericSchema<PropsDataInput, PropsData> = v.pipe(v.
|
|
|
76
108
|
colliders: v.optional(v.pipe(v.array(collider), v.maxLength(1024)), []),
|
|
77
109
|
textures: v.pipe(v.array(v.strictObject({ model: ref, colour: ref })), v.maxLength(256)),
|
|
78
110
|
bodies: v.exactOptional(bodies),
|
|
79
|
-
}), v.check((s) => new Set(s.tiles.map((tile) => `${tile.lod}/${tile.x}/${tile.z}`)).size === s.tiles.length && s.tiles.every((tile) => tile.x < (tile.lod === 0 ? 8 : 4) && tile.z < (tile.lod === 0 ? 8 : 4)) && new Set([...s.panels, ...s.models].map((entry) => entry.id)).size === s.panels.length + s.models.length && new Set(s.textures.map((texture) => texture.model)).size === s.textures.length && new Set(s.colliders.map((solid) => solid.id)).size === s.colliders.length && s.colliders
|
|
111
|
+
}), v.check((s) => new Set(s.tiles.map((tile) => `${tile.lod}/${tile.x}/${tile.z}`)).size === s.tiles.length && s.tiles.every((tile) => tile.x < (tile.lod === 0 ? 8 : 4) && tile.z < (tile.lod === 0 ? 8 : 4)) && new Set([...s.panels, ...s.models].map((entry) => entry.id)).size === s.panels.length + s.models.length && new Set(s.textures.map((texture) => texture.model)).size === s.textures.length && new Set(s.colliders.map((solid) => solid.id)).size === s.colliders.length && withinColliderBudget(s.colliders) && s.colliders.every((solid) => solid.panel === null || s.panels.some((panel) => panel.id === solid.panel)), 'unique props addresses and ids'), v.check<PropsData, string>(bodiesAdmitted, 'touchable bodies have unique ids and each names its own panel, which no static collider claims'));
|
|
80
112
|
/** Validated data for the props renderer; no callbacks, URLs or generator code enter this section. */
|
|
81
113
|
export type ShardProps = v.InferOutput<typeof PropsSchema>;
|
|
82
114
|
/** Check every render binding against ordinary admitted file, tile and library rows before allocating content. */
|
|
@@ -148,7 +180,7 @@ interface PropsDataFields {
|
|
|
148
180
|
w: number;
|
|
149
181
|
} | undefined;
|
|
150
182
|
surface?: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt' | undefined;
|
|
151
|
-
}) | ({
|
|
183
|
+
}) | PropHull | ({
|
|
152
184
|
kind: 'treads';
|
|
153
185
|
from: {
|
|
154
186
|
x: number;
|