@zaisma/physics 2.4.1 → 2.5.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/declare.js CHANGED
@@ -42,21 +42,50 @@ export const WORLD_REACH_M = 10_000;
42
42
  /** How heavy a cubic metre of a body is when it doesn't say its mass: furniture is mostly air. */
43
43
  export const DEFAULT_DENSITY_KG_PER_M3_NUMBER = 250;
44
44
 
45
- const WORLD_KEYS = ["bodies", "bodyKinds", "character", "playerCharacterMode", "startPositionsM", "fallOutHeightM", "collisionLayers", "joints", "substepCount", "groundReachM"];
46
- const BODY_KEYS = ["id", "bodyKindName", "motionKind", "positionM", "rotationDeg", "massKg", "bouncePct", "gripPct", "linearDampingNumber", "angularDampingNumber", "canBeGrabbed", "shapes", "collisionLayerName", "wheels", "vehicle", "seats"];
45
+ const WORLD_KEYS = ["bodies", "bodyKinds", "character", "playerCharacterMode", "startPositionsM", "fallOutHeightM", "collisionLayers", "surfaceNames", "joints", "substepCount", "groundReachM"];
46
+ const BODY_KEYS = ["id", "bodyKindName", "motionKind", "positionM", "rotationDeg", "massKg", "bouncePct", "gripPct", "linearDampingNumber", "angularDampingNumber", "canBeGrabbed", "shapes", "collisionLayerName", "wheels", "vehicle", "seats", "timetable"];
47
47
  const BODY_KIND_KEYS = ["massKg", "bouncePct", "gripPct", "linearDampingNumber", "angularDampingNumber", "canBeGrabbed", "shapes", "collisionLayerName", "wheels", "vehicle", "seats"];
48
48
  const WHEEL_KEYS = ["positionM", "radiusM", "suspensionRestM", "suspensionTravelM", "isSteered", "isDriven"];
49
49
  const VEHICLE_KEYS = ["maximumEngineForceNewtons", "maximumBrakeForceNewtons", "maximumSteerDeg", "suspensionStiffnessNumber", "suspensionDampingNumber", "frictionSlipNumber", "sideFrictionNumber", "maximumSuspensionForceNewtons", "wheelCollisionLayerNames"];
50
50
  const SEAT_KEYS = ["positionM", "facingYawDeg"];
51
+ const TIMETABLE_KEYS = ["stops", "repeatMode", "easeKind"];
52
+ const TIMETABLE_STOP_KEYS = ["positionM", "rotationDeg", "travelDurationSec", "waitDurationSec"];
53
+ /** What a timetable does after its last stop: goes on to its first again, runs back the way it came, or stays. */
54
+ export const TIMETABLE_REPEAT_MODES = ["loop", "back_and_forth", "once"];
55
+ /** How a body goes from a stop to the next: at one speed, or easing out of one and into the other. */
56
+ export const TIMETABLE_EASE_KINDS = ["linear", "smooth"];
57
+ /** Stops one timetable has at most. */
58
+ export const MAXIMUM_TIMETABLE_STOP_COUNT = 32;
59
+ /**
60
+ * The grain of a timetable's places: the wire's own for a place (a millimetre). A character carried by a body moves
61
+ * by whole steps of it, so being put on the wire's steps every step never leaves it behind.
62
+ */
63
+ const TIMETABLE_STEPS_PER_M = 1000;
64
+ /** The longest a trip between two stops, or a wait at one, lasts, in seconds. */
65
+ export const MAXIMUM_TIMETABLE_DURATION_SEC = 3600;
51
66
  const JOINT_KEYS = ["id", "jointKind", "bodyId", "otherBodyId", "anchorM", "otherAnchorM", "axis", "minimumNumber", "maximumNumber", "restLengthM", "stiffnessNumber", "dampingNumber"];
52
67
  const COLLISION_LAYER_KEYS = ["touches"];
53
68
  const DATA_PATH_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_./-]{0,199}$/;
54
69
  const BODY_KIND_NAME_PATTERN = /^[a-z][a-z0-9_]{0,39}$/;
55
70
  /** Kinds of body one world declares at most. */
56
71
  export const MAXIMUM_BODY_KIND_COUNT = 250;
57
- const SHAPE_KEYS = ["shapeKind", "sizeM", "radiusM", "heightM", "pointsM", "triangleIndices", "triangleGroupNumbers", "positionM", "rotationDeg", "dataPath", "heightsM", "rowCount", "columnCount", "cellSizeM"];
72
+ const SHAPE_KEYS = ["shapeKind", "sizeM", "radiusM", "heightM", "pointsM", "triangleIndices", "triangleGroupNumbers", "triangleGroups", "triangleSurfaceIndices", "surfaceName", "positionM", "rotationDeg", "dataPath", "heightsM", "rowCount", "columnCount", "cellSizeM"];
73
+ const TRIANGLE_GROUP_KEYS = ["groupNumber", "collisionLayerName"];
58
74
  /** A mesh's triangle groups a world switches on and off while playing (doors, bridges): numbered 1 to this; 0 is always there. */
59
- export const MAXIMUM_TRIANGLE_GROUP_NUMBER = 31;
75
+ export const MAXIMUM_TRIANGLE_GROUP_NUMBER = 63;
76
+ /**
77
+ * Which groups are off travels as whole numbers with a bit for each group, and a whole number on the wire holds 31
78
+ * bits: so three of them, 21 groups each. Group 1 is the first's lowest bit.
79
+ */
80
+ export const TRIANGLE_GROUP_MASK_COUNT = 3;
81
+ const TRIANGLE_GROUP_MASK_BIT_COUNT = 21;
82
+ export const MAXIMUM_TRIANGLE_GROUP_MASK_NUMBER = 2 ** TRIANGLE_GROUP_MASK_BIT_COUNT - 1;
83
+ /** Which of the masks a group's bit is in, from 0. */
84
+ export const triangleGroupMaskIndexOf = (groupNumber) => Math.floor((groupNumber - 1) / TRIANGLE_GROUP_MASK_BIT_COUNT);
85
+ /** A group's bit in its mask. */
86
+ export const triangleGroupBitNumberOf = (groupNumber) => 1 << ((groupNumber - 1) % TRIANGLE_GROUP_MASK_BIT_COUNT);
87
+ /** Surfaces one world names at most (what a hit says it met: concrete, metal, water). */
88
+ export const MAXIMUM_SURFACE_COUNT = 255;
60
89
  const CHARACTER_KEYS = ["heightM", "radiusM", "stepHeightM", "maximumSlopeDeg"];
61
90
 
62
91
  const isPlainObject = (given) => given !== null && typeof given === "object" && !Array.isArray(given);
@@ -109,13 +138,115 @@ function lengthOf(given, code, what, { minimumM = 0.01, maximumM = WORLD_REACH_M
109
138
  return given;
110
139
  }
111
140
 
141
+ function timetableDurationOf(given, minimumSec, what, fix) {
142
+ if (!isFiniteNumber(given) || given < minimumSec || given > MAXIMUM_TIMETABLE_DURATION_SEC) refuse("bad_body", `${what} is ${JSON.stringify(given)}.`, what, fix);
143
+ return given;
144
+ }
145
+
146
+ /**
147
+ * A kinematic body's timetable, checked: the stops it goes between and how long each trip and wait lasts, so where
148
+ * it is at any step is the same in every game and on the game server, and nothing of it is sent. Answers
149
+ * { repeatMode, easeKind, stops, legs, durationSec }: each stop's place and rotation, and one round's legs (a trip
150
+ * from a stop to another, or a wait at one) with when each starts.
151
+ */
152
+ function timetableOf(given, positionM, rotation, motionKind, what) {
153
+ if (given === undefined || given === null) return null;
154
+ if (motionKind !== "kinematic") refuse("bad_body", `${what} is on a body that's ${motionKind}.`, what, 'Give the body motionKind "kinematic": a timetable moves it, whatever it meets.');
155
+ if (!isPlainObject(given)) refuse("bad_body", `${what} isn't a timetable.`, what, "Give { stops: [{ positionM }, { positionM, travelDurationSec: 4 }] }.");
156
+ refuseUnknownKeys(given, TIMETABLE_KEYS, "bad_body", what);
157
+ const { repeatMode = "loop", easeKind = "linear" } = given;
158
+ if (!TIMETABLE_REPEAT_MODES.includes(repeatMode)) refuse("bad_body", `${what}.repeatMode is ${JSON.stringify(repeatMode)}.`, `${what}.repeatMode`, `Use: ${TIMETABLE_REPEAT_MODES.join(", ")}.`);
159
+ if (!TIMETABLE_EASE_KINDS.includes(easeKind)) refuse("bad_body", `${what}.easeKind is ${JSON.stringify(easeKind)}.`, `${what}.easeKind`, `Use: ${TIMETABLE_EASE_KINDS.join(", ")}.`);
160
+ if (!Array.isArray(given.stops) || given.stops.length < 2 || given.stops.length > MAXIMUM_TIMETABLE_STOP_COUNT) refuse("bad_body", `${what}.stops isn't a list of 2 to ${MAXIMUM_TIMETABLE_STOP_COUNT} stops.`, `${what}.stops`, "Give each place it stops at, in the order it visits them.");
161
+ const isLoop = repeatMode === "loop";
162
+ const stops = given.stops.map((stop, stopIndex) => {
163
+ const stopWhat = `${what}.stops[${stopIndex}]`;
164
+ if (!isPlainObject(stop)) refuse("bad_body", `${stopWhat} isn't a stop.`, stopWhat, "Give { positionM, rotationDeg, travelDurationSec, waitDurationSec }: any left out is the body's own place or turn, and no wait.");
165
+ refuseUnknownKeys(stop, TIMETABLE_STOP_KEYS, "bad_body", stopWhat);
166
+ // The first stop's trip is the one back to it from the last, which only a loop makes.
167
+ const hasTrip = stopIndex > 0 || isLoop;
168
+ if (!hasTrip && stop.travelDurationSec !== undefined) refuse("bad_body", `${stopWhat} is the first stop and has a travelDurationSec.`, `${stopWhat}.travelDurationSec`, 'Leave it out: only a timetable with repeatMode "loop" travels to its first stop, from its last.');
169
+ const place = pointOf(stop.positionM, positionM, "bad_body", `${stopWhat}.positionM`);
170
+ const turn = stop.rotationDeg === undefined ? rotation : rotationOf(stop.rotationDeg, "bad_body", `${stopWhat}.rotationDeg`);
171
+ return {
172
+ x: place.x,
173
+ y: place.y,
174
+ z: place.z,
175
+ // On the engine's own grain, so every side starts from the same numbers.
176
+ rotation: { x: Math.fround(turn.x), y: Math.fround(turn.y), z: Math.fround(turn.z), w: Math.fround(turn.w) },
177
+ travelDurationSec: hasTrip ? timetableDurationOf(stop.travelDurationSec, 0.01, `${stopWhat}.travelDurationSec`, `Give how long the trip to this stop takes in seconds, from 0.01 to ${MAXIMUM_TIMETABLE_DURATION_SEC}.`) : 0,
178
+ waitDurationSec: stop.waitDurationSec === undefined ? 0 : timetableDurationOf(stop.waitDurationSec, 0, `${stopWhat}.waitDurationSec`, `Give how long it waits at this stop in seconds, from 0 to ${MAXIMUM_TIMETABLE_DURATION_SEC}, or leave it out for no wait.`),
179
+ };
180
+ });
181
+ const legs = [];
182
+ let durationSec = 0;
183
+ const addLeg = (fromStopIndex, toStopIndex, legDurationSec) => {
184
+ if (legDurationSec <= 0) return;
185
+ legs.push({ fromStopIndex, toStopIndex, startSec: durationSec, durationSec: legDurationSec });
186
+ durationSec += legDurationSec;
187
+ };
188
+ const lastStopIndex = stops.length - 1;
189
+ for (let stopIndex = 0; stopIndex <= lastStopIndex; stopIndex += 1) {
190
+ if (stopIndex > 0) addLeg(stopIndex - 1, stopIndex, stops[stopIndex].travelDurationSec);
191
+ addLeg(stopIndex, stopIndex, stops[stopIndex].waitDurationSec);
192
+ }
193
+ if (isLoop) addLeg(lastStopIndex, 0, stops[0].travelDurationSec);
194
+ // Back the way it came, each trip as long as it was, waiting again at each stop between.
195
+ if (repeatMode === "back_and_forth") {
196
+ for (let stopIndex = lastStopIndex; stopIndex > 0; stopIndex -= 1) {
197
+ addLeg(stopIndex, stopIndex - 1, stops[stopIndex].travelDurationSec);
198
+ if (stopIndex > 1) addLeg(stopIndex - 1, stopIndex - 1, stops[stopIndex - 1].waitDurationSec);
199
+ }
200
+ }
201
+ return { repeatMode, easeKind, stops, legs, durationSec };
202
+ }
203
+
204
+ /**
205
+ * Where a timetable has its body, clockSec after it started (a room's step index times a step's length): written
206
+ * into { x, y, z, rotationX, rotationY, rotationZ, rotationW } and answered, its place on the wire's millimetres.
207
+ * Only adding, multiplying, rounding and a square root, so every browser and the game server get the same numbers.
208
+ */
209
+ export function timetablePlaceInto(timetable, clockSec, into) {
210
+ const { legs, stops, durationSec } = timetable;
211
+ let roundSec = 0;
212
+ if (clockSec > 0) roundSec = timetable.repeatMode === "once" ? Math.min(clockSec, durationSec) : clockSec - Math.floor(clockSec / durationSec) * durationSec;
213
+ let leg = legs[legs.length - 1];
214
+ for (let legIndex = 0; legIndex < legs.length; legIndex += 1) {
215
+ if (roundSec < legs[legIndex].startSec + legs[legIndex].durationSec) {
216
+ leg = legs[legIndex];
217
+ break;
218
+ }
219
+ }
220
+ let shareNumber = Math.min(Math.max((roundSec - leg.startSec) / leg.durationSec, 0), 1);
221
+ if (timetable.easeKind === "smooth") shareNumber = shareNumber * shareNumber * (3 - 2 * shareNumber);
222
+ const from = stops[leg.fromStopIndex];
223
+ const to = stops[leg.toStopIndex];
224
+ into.x = Math.round((from.x + (to.x - from.x) * shareNumber) * TIMETABLE_STEPS_PER_M) / TIMETABLE_STEPS_PER_M;
225
+ into.y = Math.round((from.y + (to.y - from.y) * shareNumber) * TIMETABLE_STEPS_PER_M) / TIMETABLE_STEPS_PER_M;
226
+ into.z = Math.round((from.z + (to.z - from.z) * shareNumber) * TIMETABLE_STEPS_PER_M) / TIMETABLE_STEPS_PER_M;
227
+ // The shorter way round, straight between the two rotations and brought back to length: even for a quarter turn or less.
228
+ const fromRotation = from.rotation;
229
+ const toRotation = to.rotation;
230
+ const signNumber = fromRotation.x * toRotation.x + fromRotation.y * toRotation.y + fromRotation.z * toRotation.z + fromRotation.w * toRotation.w < 0 ? -1 : 1;
231
+ const rotationX = fromRotation.x + (toRotation.x * signNumber - fromRotation.x) * shareNumber;
232
+ const rotationY = fromRotation.y + (toRotation.y * signNumber - fromRotation.y) * shareNumber;
233
+ const rotationZ = fromRotation.z + (toRotation.z * signNumber - fromRotation.z) * shareNumber;
234
+ const rotationRealNumber = fromRotation.w + (toRotation.w * signNumber - fromRotation.w) * shareNumber;
235
+ const lengthNumber = Math.sqrt(rotationX * rotationX + rotationY * rotationY + rotationZ * rotationZ + rotationRealNumber * rotationRealNumber) || 1;
236
+ into.rotationX = rotationX / lengthNumber;
237
+ into.rotationY = rotationY / lengthNumber;
238
+ into.rotationZ = rotationZ / lengthNumber;
239
+ into.rotationW = rotationRealNumber / lengthNumber;
240
+ return into;
241
+ }
242
+
112
243
  /** One shape of a body, checked. Answers it with how much room it takes, for a body's mass when it gives none. */
113
244
  function shapeOf(given, isFixed, what) {
114
245
  refuseUnknownKeys(given, SHAPE_KEYS, "bad_body", what);
115
246
  const { shapeKind } = given;
116
247
  if (!SHAPE_KINDS.includes(shapeKind)) refuse("bad_body", `${what}.shapeKind is ${JSON.stringify(shapeKind)}.`, `${what}.shapeKind`, `Use: ${SHAPE_KINDS.join(", ")}.`);
117
248
  if (shapeKind === "heightfield" || (shapeKind === "mesh" && given.dataPath !== undefined)) return groundShapeOf(given, isFixed, what);
118
- if (shapeKind !== "mesh" && given.triangleGroupNumbers !== undefined) refuse("bad_body", `${what} is a ${shapeKind}, which has no triangleGroupNumbers.`, `${what}.triangleGroupNumbers`, "Only a mesh's triangles come in groups.");
249
+ for (const key of ["triangleGroupNumbers", "triangleGroups", "triangleSurfaceIndices"]) if (shapeKind !== "mesh" && given[key] !== undefined) refuse("bad_body", `${what} is a ${shapeKind}, which has no ${key}.`, `${what}.${key}`, key === "triangleSurfaceIndices" ? "Only a mesh says its surface triangle by triangle: give this shape a surfaceName." : "Only a mesh's triangles come in groups.");
119
250
  for (const key of ["dataPath", "heightsM", "rowCount", "columnCount", "cellSizeM"]) if (given[key] !== undefined) refuse("bad_body", `${what} is a ${shapeKind}, which has no ${key}.`, `${what}.${key}`, key === "dataPath" ? "Only a mesh or a heightfield is read from a data file." : "rowCount, columnCount, cellSizeM and heightsM are a heightfield's.");
120
251
  const takes = { box: ["sizeM"], ball: ["radiusM"], capsule: ["radiusM", "heightM"], cylinder: ["radiusM", "heightM"], hull: ["pointsM"], mesh: ["pointsM", "triangleIndices"] }[shapeKind];
121
252
  for (const key of ["sizeM", "radiusM", "heightM", "pointsM", "triangleIndices"]) {
@@ -123,7 +254,7 @@ function shapeOf(given, isFixed, what) {
123
254
  refuse("bad_body", takes.includes(key) ? `${what} is a ${shapeKind} with no ${key}.` : `${what} is a ${shapeKind}, which has no ${key}.`, `${what}.${key}`, `A ${shapeKind} takes: ${takes.join(", ")}.`);
124
255
  }
125
256
  }
126
- const shape = { shapeKind, sizeM: null, radiusM: null, heightM: null, pointsM: null, triangleIndices: null, triangleGroupNumbers: null, dataPath: null, heightsM: null, rowCount: null, columnCount: null, cellSizeM: null, positionM: pointOf(given.positionM, { x: 0, y: 0, z: 0 }, "bad_body", `${what}.positionM`), rotation: rotationOf(given.rotationDeg, "bad_body", `${what}.rotationDeg`) };
257
+ const shape = { shapeKind, sizeM: null, radiusM: null, heightM: null, pointsM: null, triangleIndices: null, triangleGroupNumbers: null, triangleGroups: null, triangleSurfaceIndices: null, surfaceName: surfaceNameOf(given.surfaceName, what), dataPath: null, heightsM: null, rowCount: null, columnCount: null, cellSizeM: null, positionM: pointOf(given.positionM, { x: 0, y: 0, z: 0 }, "bad_body", `${what}.positionM`), rotation: rotationOf(given.rotationDeg, "bad_body", `${what}.rotationDeg`) };
127
258
  let volumeNumber = 0;
128
259
  if (shapeKind === "box") {
129
260
  if (!isPlainObject(given.sizeM)) refuse("bad_body", `${what}.sizeM isn't a size.`, `${what}.sizeM`, "Give { x, y, z }: how wide, tall and deep the box is, in metres.");
@@ -170,12 +301,65 @@ function shapeOf(given, isFixed, what) {
170
301
  }
171
302
  shape.triangleIndices = isTypedIndices ? indices : indices.slice();
172
303
  shape.triangleGroupNumbers = triangleGroupsOf(given.triangleGroupNumbers, indices.length / 3, what);
304
+ shape.triangleGroups = groupLayersOf(given.triangleGroups, shape.triangleGroupNumbers, what);
305
+ shape.triangleSurfaceIndices = triangleSurfacesOf(given.triangleSurfaceIndices, indices.length / 3, given.surfaceName, what);
173
306
  }
174
307
  }
175
308
  return { shape, volumeNumber };
176
309
  }
177
310
 
178
- /** A mesh's triangle groups, checked: one number a triangle, 0 (always there) or a group from 1 to 31 the world switches. */
311
+ /** A shape's surfaceName, checked: one of the world's surfaceNames (which the world checks), or left out. */
312
+ function surfaceNameOf(given, what) {
313
+ if (given === undefined || given === null) return null;
314
+ if (typeof given !== "string" || !BODY_KIND_NAME_PATTERN.test(given)) refuse("bad_body", `${what}.surfaceName is ${JSON.stringify(given)}.`, `${what}.surfaceName`, 'Give one of the world\'s surfaceNames, like "metal", or leave it out.');
315
+ return given;
316
+ }
317
+
318
+ /** A mesh's surface triangle by triangle, checked: for each triangle, which of the world's surfaceNames it is, from 0. */
319
+ function triangleSurfacesOf(given, triangleCount, surfaceName, what) {
320
+ if (given === undefined) return null;
321
+ if (surfaceName !== undefined && surfaceName !== null) refuse("bad_body", `${what} has a surfaceName and triangleSurfaceIndices.`, `${what}.triangleSurfaceIndices`, "Give one: surfaceName for a mesh that's one surface all over, or triangleSurfaceIndices for one that isn't.");
322
+ const isList = Array.isArray(given) || given instanceof Uint8Array;
323
+ if (!isList || given.length !== triangleCount || Array.prototype.some.call(given, (surfaceIndex) => !Number.isInteger(surfaceIndex) || surfaceIndex < 0 || surfaceIndex >= MAXIMUM_SURFACE_COUNT)) {
324
+ refuse("bad_body", `${what}.triangleSurfaceIndices isn't a surface for each of its ${triangleCount} triangles.`, `${what}.triangleSurfaceIndices`, "Give one number a triangle (a list or a Uint8Array): which of the world's surfaceNames the triangle is, from 0.");
325
+ }
326
+ return given instanceof Uint8Array ? given : Uint8Array.from(given);
327
+ }
328
+
329
+ /** A mesh's triangleGroups, checked: the groups that are on a collision layer of their own, [{ groupNumber, collisionLayerName }]. */
330
+ function groupLayersOf(given, groupNumbers, what) {
331
+ if (given === undefined) return null;
332
+ const fix = `Give the groups that aren't on the body's own collision layer, like [{ groupNumber: 4, collisionLayerName: "glass" }]: groupNumber from 0 (the triangles always there) to ${MAXIMUM_TRIANGLE_GROUP_NUMBER}, each once.`;
333
+ if (!groupNumbers) refuse("bad_body", `${what} has triangleGroups and no triangleGroupNumbers.`, `${what}.triangleGroups`, "Give triangleGroupNumbers too: the group each triangle is in.");
334
+ if (!Array.isArray(given) || given.length > MAXIMUM_TRIANGLE_GROUP_NUMBER + 1) refuse("bad_body", `${what}.triangleGroups isn't a list of groups.`, `${what}.triangleGroups`, fix);
335
+ const seenNumbers = new Set();
336
+ return given.map((group, groupIndex) => {
337
+ refuseUnknownKeys(group, TRIANGLE_GROUP_KEYS, "bad_body", `${what}.triangleGroups[${groupIndex}]`);
338
+ const { groupNumber, collisionLayerName } = group;
339
+ if (!Number.isInteger(groupNumber) || groupNumber < 0 || groupNumber > MAXIMUM_TRIANGLE_GROUP_NUMBER || seenNumbers.has(groupNumber)) refuse("bad_body", `${what}.triangleGroups[${groupIndex}].groupNumber is ${JSON.stringify(groupNumber)}.`, `${what}.triangleGroups[${groupIndex}].groupNumber`, fix);
340
+ if (typeof collisionLayerName !== "string" || !BODY_KIND_NAME_PATTERN.test(collisionLayerName)) refuse("bad_body", `${what}.triangleGroups[${groupIndex}].collisionLayerName is ${JSON.stringify(collisionLayerName)}.`, `${what}.triangleGroups[${groupIndex}].collisionLayerName`, "Give the name of one of the world's collisionLayers.");
341
+ seenNumbers.add(groupNumber);
342
+ return { groupNumber, collisionLayerName };
343
+ });
344
+ }
345
+
346
+ /**
347
+ * A body's names, checked against its world's: the collision layers its mesh's groups are on, and its shapes'
348
+ * surfaces. For a declared body as the world is defined, and for one added while playing.
349
+ */
350
+ export function checkBodyNames(body, what, world) {
351
+ const layerNames = world.collisionLayers.map((layer) => layer.name);
352
+ for (const [shapeIndex, shape] of body.shapes.entries()) {
353
+ const shapeWhat = `${what}.shapes[${shapeIndex}]`;
354
+ if (shape.surfaceName !== null && shape.surfaceName !== undefined && !world.surfaceNames.includes(shape.surfaceName)) refuse("bad_body", `${shapeWhat}.surfaceName is "${shape.surfaceName}".`, `${shapeWhat}.surfaceName`, world.surfaceNames.length ? `Use one of the world's surfaceNames: ${world.surfaceNames.join(", ")}.` : 'Name the world\'s surfaces first, like surfaceNames: ["concrete", "metal"].');
355
+ if (shape.triangleSurfaceIndices && Array.prototype.some.call(shape.triangleSurfaceIndices, (surfaceIndex) => surfaceIndex >= world.surfaceNames.length)) refuse("bad_body", `${shapeWhat}.triangleSurfaceIndices names a surface the world doesn't have.`, `${shapeWhat}.triangleSurfaceIndices`, `Give numbers from 0 to ${world.surfaceNames.length - 1}: the world has ${world.surfaceNames.length} surfaceNames.`);
356
+ for (const [groupIndex, group] of (shape.triangleGroups ?? []).entries()) {
357
+ if (!layerNames.includes(group.collisionLayerName) || group.collisionLayerName === RIDING_LAYER_NAME) refuse("bad_body", `${shapeWhat}.triangleGroups[${groupIndex}].collisionLayerName is "${group.collisionLayerName}".`, `${shapeWhat}.triangleGroups[${groupIndex}].collisionLayerName`, `Use one of the world's collisionLayers: ${layerNames.filter((name) => name !== RIDING_LAYER_NAME).join(", ")}.`);
358
+ }
359
+ }
360
+ }
361
+
362
+ /** A mesh's triangle groups, checked: one number a triangle, 0 (always there) or a group from 1 to 63 the world switches. */
179
363
  function triangleGroupsOf(given, triangleCount, what) {
180
364
  if (given === undefined) return null;
181
365
  const isList = Array.isArray(given) || given instanceof Uint8Array;
@@ -195,8 +379,8 @@ function triangleGroupsOf(given, triangleCount, what) {
195
379
  function groundShapeOf(given, isFixed, what) {
196
380
  const { shapeKind } = given;
197
381
  if (!isFixed) refuse("bad_body", `${what} is a ${shapeKind} on a body that moves.`, `${what}.shapeKind`, "A heightfield or a mesh read from a file is the fixed world's ground: give its body motionKind \"fixed\".");
198
- const shape = { shapeKind, sizeM: null, radiusM: null, heightM: null, pointsM: null, triangleIndices: null, triangleGroupNumbers: null, dataPath: null, heightsM: null, rowCount: null, columnCount: null, cellSizeM: null, positionM: pointOf(given.positionM, { x: 0, y: 0, z: 0 }, "bad_body", `${what}.positionM`), rotation: rotationOf(given.rotationDeg, "bad_body", `${what}.rotationDeg`) };
199
- for (const key of ["sizeM", "radiusM", "heightM", "pointsM", "triangleIndices", ...(shapeKind === "heightfield" ? ["triangleGroupNumbers"] : [])]) if (given[key] !== undefined) refuse("bad_body", `${what} is a ${shapeKind} ${shapeKind === "mesh" ? "read from a file" : ""}, which has no ${key}.`, `${what}.${key}`, shapeKind === "mesh" ? "A mesh gives either pointsM and triangleIndices, or dataPath." : "A heightfield takes rowCount, columnCount, cellSizeM, and heightsM or dataPath.");
382
+ const shape = { shapeKind, sizeM: null, radiusM: null, heightM: null, pointsM: null, triangleIndices: null, triangleGroupNumbers: null, triangleGroups: null, triangleSurfaceIndices: null, surfaceName: surfaceNameOf(given.surfaceName, what), dataPath: null, heightsM: null, rowCount: null, columnCount: null, cellSizeM: null, positionM: pointOf(given.positionM, { x: 0, y: 0, z: 0 }, "bad_body", `${what}.positionM`), rotation: rotationOf(given.rotationDeg, "bad_body", `${what}.rotationDeg`) };
383
+ for (const key of ["sizeM", "radiusM", "heightM", "pointsM", "triangleIndices", ...(shapeKind === "heightfield" ? ["triangleGroupNumbers", "triangleGroups", "triangleSurfaceIndices"] : [])]) if (given[key] !== undefined) refuse("bad_body", `${what} is a ${shapeKind} ${shapeKind === "mesh" ? "read from a file" : ""}, which has no ${key}.`, `${what}.${key}`, shapeKind === "mesh" ? "A mesh gives either pointsM and triangleIndices, or dataPath." : "A heightfield takes rowCount, columnCount, cellSizeM, and heightsM or dataPath.");
200
384
  if (given.dataPath !== undefined) {
201
385
  if (typeof given.dataPath !== "string" || !DATA_PATH_PATTERN.test(given.dataPath) || given.dataPath.includes("..")) refuse("bad_body", `${what}.dataPath is ${JSON.stringify(given.dataPath)}.`, `${what}.dataPath`, 'Give the data file\'s path from the game\'s folder (and the same from zaisma-server/), like "levels/valley-heights.bin".');
202
386
  shape.dataPath = given.dataPath;
@@ -204,6 +388,8 @@ function groundShapeOf(given, isFixed, what) {
204
388
  if (shapeKind === "mesh") {
205
389
  // A mesh read from a file may still say its triangles' groups; how many it has is known once the file is read.
206
390
  if (given.triangleGroupNumbers !== undefined) shape.triangleGroupNumbers = triangleGroupsOf(given.triangleGroupNumbers, given.triangleGroupNumbers?.length, what);
391
+ shape.triangleGroups = groupLayersOf(given.triangleGroups, shape.triangleGroupNumbers, what);
392
+ shape.triangleSurfaceIndices = triangleSurfacesOf(given.triangleSurfaceIndices, given.triangleSurfaceIndices?.length, given.surfaceName, what);
207
393
  return { shape, volumeNumber: 0 };
208
394
  }
209
395
  for (const key of ["rowCount", "columnCount"]) {
@@ -246,7 +432,7 @@ export function checkBody(declared, what = "body", bodyKinds = []) {
246
432
  bodyKindNumber = bodyKinds.findIndex((bodyKind) => bodyKind.name === declared.bodyKindName) + 1;
247
433
  if (bodyKindNumber === 0) refuse("bad_body", `${what}.bodyKindName is ${JSON.stringify(declared.bodyKindName)}.`, `${what}.bodyKindName`, bodyKinds.length ? `Use one of the world's bodyKinds: ${bodyKinds.map((bodyKind) => bodyKind.name).join(", ")}.` : "Declare the kind in the world's bodyKinds first, or give the body shapes of its own.");
248
434
  for (const key of [...BODY_KIND_KEYS, "motionKind"]) if (declared[key] !== undefined) refuse("bad_body", `${what} has a bodyKindName and its own ${key}.`, `${what}.${key}`, `Leave ${key} out: a body of a kind is what the kind says. Give it shapes of its own instead of a bodyKindName to make it different.`);
249
- given = { ...bodyKinds[bodyKindNumber - 1].declared, id: declared.id, positionM: declared.positionM, rotationDeg: declared.rotationDeg };
435
+ given = { ...bodyKinds[bodyKindNumber - 1].declared, id: declared.id, positionM: declared.positionM, rotationDeg: declared.rotationDeg, timetable: declared.timetable };
250
436
  for (const key of Object.keys(given)) if (given[key] === undefined) delete given[key];
251
437
  }
252
438
  const { id, motionKind = "moving" } = given;
@@ -267,13 +453,17 @@ export function checkBody(declared, what = "body", bodyKinds = []) {
267
453
  const seats = checkSeats(given.seats, isFixed, what);
268
454
  if (given.canBeGrabbed !== undefined && typeof given.canBeGrabbed !== "boolean") refuse("bad_body", `${what}.canBeGrabbed isn't true or false.`, `${what}.canBeGrabbed`, "Give true or false, or leave it out: a moving body can be grabbed, the fixed world can't.");
269
455
  if (given.canBeGrabbed === true && isFixed) refuse("bad_body", `${what} is fixed and canBeGrabbed.`, `${what}.canBeGrabbed`, "Only a moving body can be grabbed and carried.");
456
+ const positionM = pointOf(given.positionM, { x: 0, y: 0, z: 0 }, "bad_body", `${what}.positionM`);
457
+ const rotation = rotationOf(given.rotationDeg, "bad_body", `${what}.rotationDeg`);
270
458
  return {
271
459
  id,
272
460
  // 0 for a body with shapes of its own; else the place of its kind among the world's bodyKinds, from 1.
273
461
  bodyKindNumber,
274
462
  motionKind,
275
- positionM: pointOf(given.positionM, { x: 0, y: 0, z: 0 }, "bad_body", `${what}.positionM`),
276
- rotation: rotationOf(given.rotationDeg, "bad_body", `${what}.rotationDeg`),
463
+ positionM,
464
+ rotation,
465
+ // null, or where a kinematic body is at every step: its stops, and one round's trips and waits.
466
+ timetable: timetableOf(given.timetable, positionM, rotation, motionKind, `${what}.timetable`),
277
467
  massKg,
278
468
  bouncePct: percentOf(given.bouncePct, 100, `${what}.bouncePct`),
279
469
  gripPct: percentOf(given.gripPct, 300, `${what}.gripPct`),
@@ -438,6 +628,11 @@ export function definePhysicsWorld(given = {}) {
438
628
  ids.add(checked.id);
439
629
  return checked;
440
630
  });
631
+ const { surfaceNames = [] } = given;
632
+ if (!Array.isArray(surfaceNames) || surfaceNames.length > MAXIMUM_SURFACE_COUNT || surfaceNames.some((name) => typeof name !== "string" || !BODY_KIND_NAME_PATTERN.test(name)) || new Set(surfaceNames).size !== surfaceNames.length) refuse("bad_world", "world.surfaceNames isn't a list of surfaces, each named once.", "world.surfaceNames", `Give up to ${MAXIMUM_SURFACE_COUNT} names in lowercase words joined by underscores, like ["concrete", "metal", "wet_grass"]: what a shape's surfaceName and a mesh's triangleSurfaceIndices pick from, and what a hit says it met.`);
633
+ const named = { collisionLayers, surfaceNames };
634
+ for (const [bodyIndex, body] of checkedBodies.entries()) checkBodyNames(body, `world.bodies[${bodyIndex}]`, named);
635
+ for (const bodyKind of bodyKinds) checkBodyNames(checkBody({ ...bodyKind.declared, id: "kind" }, `world.bodyKinds.${bodyKind.name}`), `world.bodyKinds.${bodyKind.name}`, named);
441
636
  const layerNames = collisionLayers.map((layer) => layer.name);
442
637
  for (const [bodyIndex, body] of checkedBodies.entries()) if (!layerNames.includes(body.collisionLayerName)) refuse("bad_world", `world.bodies[${bodyIndex}].collisionLayerName is "${body.collisionLayerName}".`, `world.bodies[${bodyIndex}].collisionLayerName`, `Use one of the world's collisionLayers: ${layerNames.join(", ")}.`);
443
638
  for (const bodyKind of bodyKinds) {
@@ -473,6 +668,7 @@ export function definePhysicsWorld(given = {}) {
473
668
  bodyKinds,
474
669
  character: { heightM, radiusM, stepHeightM, maximumSlopeDeg },
475
670
  collisionLayers,
671
+ surfaceNames: [...surfaceNames],
476
672
  joints: checkedJoints,
477
673
  substepCount,
478
674
  groundReachM: groundReach,
package/index.d.ts CHANGED
@@ -117,8 +117,14 @@ export interface ShapeDeclaration {
117
117
  /** A hull's or a mesh's points, x, y, z of each in a row: a list, or for a mesh a Float32Array the game already holds (taken as it is, up to 2,000,000 triangles with a Uint32Array of indices). */
118
118
  pointsM?: number[] | Float32Array;
119
119
  triangleIndices?: number[] | Uint32Array;
120
- /** A mesh's triangles in groups the world switches on and off while playing (a door, a bridge): one number a triangle, 0 for always there, 1 to 31 for a group (setTriangleGroup). */
120
+ /** A mesh's triangles in groups the world switches on and off while playing (a door, a bridge): one number a triangle, 0 for always there, 1 to 63 for a group (setTriangleGroup). */
121
121
  triangleGroupNumbers?: number[] | Uint8Array;
122
+ /** Groups of a mesh that sit on a collision layer of their own, not their body's: glass that stops soldiers and lets shots through. Needs triangleGroupNumbers. */
123
+ triangleGroups?: { groupNumber: number; collisionLayerName: string }[];
124
+ /** One of the world's surfaceNames, for the whole shape: what a hit on it says (footsteps, bullet marks, tyre grip). */
125
+ surfaceName?: string;
126
+ /** A mesh's surface triangle by triangle: for each, its place in the world's surfaceNames, from 0. In place of surfaceName. */
127
+ triangleSurfaceIndices?: number[] | Uint8Array;
122
128
  dataPath?: string;
123
129
  heightsM?: number[] | Float32Array;
124
130
  rowCount?: number;
@@ -201,6 +207,32 @@ export interface BodyDeclaration extends Partial<BodyKindDeclaration> {
201
207
  positionM?: Point;
202
208
  /** How it starts turned; default not at all. */
203
209
  rotationDeg?: TurnDeg;
210
+ /** A kinematic body's timetable: it goes between its stops by itself (a lift, a moving platform, a turning arm). Only in the world's own bodies. */
211
+ timetable?: TimetableDeclaration;
212
+ }
213
+
214
+ /**
215
+ * Where a kinematic body is at every step: 2 to 32 stops it visits in order. Every game and the game server work out
216
+ * its place from the room's step alone, so nothing of it is sent, and a step run again finds it where it was. It
217
+ * carries the characters and bodies standing on it and pushes what's in its way; nothing stops it. In a room its
218
+ * clock starts with the room; in a world played alone, with the world.
219
+ */
220
+ export interface TimetableDeclaration {
221
+ stops: TimetableStop[];
222
+ /** After the last stop: "loop" (the default) goes on to the first again, "back_and_forth" runs back the way it came, "once" stays. */
223
+ repeatMode?: "loop" | "back_and_forth" | "once";
224
+ /** "linear" (the default): each trip at one speed. "smooth": easing out of a stop and into the next. */
225
+ easeKind?: "linear" | "smooth";
226
+ }
227
+ export interface TimetableStop {
228
+ /** Where the body's middle is at this stop; default the body's own positionM. */
229
+ positionM?: Point;
230
+ /** How it's turned at this stop; default the body's own rotationDeg. It turns the short way between two stops, evenly for a quarter turn or less. */
231
+ rotationDeg?: TurnDeg;
232
+ /** How long the trip to this stop takes, 0.01 to 3600 seconds. For the first stop, the trip back to it from the last: only with repeatMode "loop", which needs it. */
233
+ travelDurationSec?: number;
234
+ /** How long it waits here before leaving, 0 to 3600 seconds; default 0. */
235
+ waitDurationSec?: number;
204
236
  }
205
237
 
206
238
  /** A body added while playing: one of the world's bodyKinds, somewhere. */
@@ -250,6 +282,8 @@ export interface WorldDeclaration {
250
282
  * touching nothing.
251
283
  */
252
284
  collisionLayers?: Record<string, { touches?: string[] }>;
285
+ /** What the world's surfaces are called, up to 255 names like "grass" or "metal_grate": a shape's surfaceName and a mesh's triangleSurfaceIndices pick from them, and a hit says which it met. */
286
+ surfaceNames?: string[];
253
287
  /**
254
288
  * How big every character is (heightM default 1.5, radiusM default 0.28), the highest step it walks up
255
289
  * (stepHeightM, default 0.35) and the steepest slope it climbs (maximumSlopeDeg, default 50).
@@ -320,13 +354,19 @@ export interface SteppedCharacter {
320
354
  readonly collider: Engine.Collider;
321
355
  }
322
356
 
323
- /** A query's hit: whose it was (a body's or a character's id, the other null), where, the surface's normal there, and how far along. */
357
+ /**
358
+ * A query's hit: whose it was (a body's or a character's id, the other null), where, the surface's normal there, how
359
+ * far along, which of a mesh's triangles it's on (its place in the mesh's triangleIndices, from 0; null off a mesh)
360
+ * and that triangle's or shape's surface (one of the world's surfaceNames, or null).
361
+ */
324
362
  export interface QueryHit {
325
363
  bodyId: string | null;
326
364
  characterId: string | null;
327
365
  pointM: Point;
328
366
  normal: Point;
329
367
  distanceM: number;
368
+ triangleIndex: number | null;
369
+ surfaceName: string | null;
330
370
  }
331
371
  export interface RayQuery {
332
372
  fromM: Point;
@@ -357,14 +397,25 @@ export interface CapsuleOverlapQuery {
357
397
  marginM?: number;
358
398
  collisionLayerNames?: string[];
359
399
  excludedId?: string;
400
+ /** true for a contact with every triangle of a mesh the capsule touches; default false, a mesh's deepest only. */
401
+ isEachTriangle?: boolean;
402
+ /** true to leave out triangles facing away from the capsule's middle; default false. */
403
+ isOneSided?: boolean;
360
404
  }
361
- /** Where a capsule touches the world: whose, the point, the surface's normal there (out of it, toward the capsule), and how deep the capsule is in it. */
405
+ /**
406
+ * Where a capsule touches the world: whose, the point, the surface's normal there (out of it, toward the capsule),
407
+ * how deep the capsule is in it, the flat normal of the triangle or face it's on, which of a mesh's triangles that is
408
+ * and its surface.
409
+ */
362
410
  export interface CapsuleContact {
363
411
  bodyId: string | null;
364
412
  characterId: string | null;
365
413
  pointM: Point;
366
414
  normal: Point;
367
415
  depthM: number;
416
+ faceNormal: Point;
417
+ triangleIndex: number | null;
418
+ surfaceName: string | null;
368
419
  }
369
420
  export interface BallOverlapQuery {
370
421
  centerM: Point;
@@ -401,12 +452,13 @@ export interface CharacterStepContext {
401
452
  * it can climb, snapped down to the ground under it, pushing what's in its way. Answers how far it went and
402
453
  * whether it stands.
403
454
  */
404
- moveAndSlide(character: SteppedCharacter, movedM: Point): { movedM: Point; isGrounded: boolean };
455
+ moveAndSlide(character: SteppedCharacter, movedM: Point, into?: { movedM: Point; isGrounded: boolean }): { movedM: Point; isGrounded: boolean };
405
456
  castRay(query: RayQuery, into?: QueryHit): QueryHit | null;
406
457
  castBall(query: BallCastQuery, into?: QueryHit): QueryHit | null;
407
458
  castCapsule(query: CapsuleCastQuery, into?: QueryHit): QueryHit | null;
408
459
  overlapBall(query: BallOverlapQuery): { bodyId: string | null; characterId: string | null }[];
409
- overlapCapsule(query: CapsuleOverlapQuery): CapsuleContact[];
460
+ /** With into (a list of the caller's own, kept and given again), written there: nothing is left for the garbage collector. */
461
+ overlapCapsule(query: CapsuleOverlapQuery, into?: CapsuleContact[]): CapsuleContact[];
410
462
  /** A body as the world has it now, read only (pulling a cart: how fast it lets him go), or null. */
411
463
  bodyState(bodyId: string): (Omit<BodyState, "riderCharacterIds"> & { massKg: number | null }) | null;
412
464
  /** Another character as the world has it now, read only, or null. */
@@ -501,7 +553,7 @@ export declare function walkingCharacters(): CharacterKind;
501
553
  /** One step of the piece's walk, for a kind of the game's own to call for its walking part. */
502
554
  export declare function walkStep(character: SteppedCharacter, input: Record<string, any>, stepContext: CharacterStepContext): void;
503
555
  /** Where the player pushes, in the world, from a stick and where they look. */
504
- export declare function wishOf(input: { moveX?: number; moveY?: number; viewYawRad?: number }): { x: number; z: number; lengthNumber: number };
556
+ export declare function wishOf(input: { moveX?: number; moveY?: number; viewYawRad?: number }, into?: { x: number; z: number; lengthNumber: number }): { x: number; z: number; lengthNumber: number };
505
557
  /** Drives a vehicle from its driver's stick: moveY forward and back, moveX steering, isBraking. */
506
558
  export declare function stickVehicleControls(input: Record<string, any>): { engineNumber: number; steerNumber: number; brakeNumber: number };
507
559
 
@@ -599,8 +651,9 @@ export interface PhysicsChanges {
599
651
  castCapsule(query: CapsuleCastQuery, into?: QueryHit): QueryHit | null;
600
652
  overlapBall(query: BallOverlapQuery): { bodyId: string | null; characterId: string | null }[];
601
653
  /** Where a capsule touches the world, with each contact's normal and depth: what a game's own movement pushes out of walls by. */
602
- overlapCapsule(query: CapsuleOverlapQuery): CapsuleContact[];
603
- /** Switches one of the world's triangle groups on or off for everyone (a door that opens, a bridge that falls), 1 to 31. */
654
+ /** With into (a list of the caller's own, kept and given again), written there: nothing is left for the garbage collector. */
655
+ overlapCapsule(query: CapsuleOverlapQuery, into?: CapsuleContact[]): CapsuleContact[];
656
+ /** Switches one of the world's triangle groups on or off for everyone (a door that opens, a bridge that falls), 1 to 63. */
604
657
  setTriangleGroup(groupNumber: number, isEnabled: boolean): boolean;
605
658
  isTriangleGroupEnabled(groupNumber: number): boolean;
606
659
  }
@@ -708,23 +761,33 @@ export interface LevelCharacters extends import("../net/index.js").Characters {
708
761
  /** Where and how to draw a character this frame: its feet, facing, speed, footing and its kind's own fields. */
709
762
  drawnCharacter(characterId: string): CharacterView | null;
710
763
  characterState(characterId: string): CharacterView | null;
764
+ /** Where to draw one of the level's bodies this frame: one on a timetable is where this frame's moment has it. null for a body that isn't the level's. */
765
+ drawnBody(bodyId: string): { positionM: Point; rotation: Rotation } | null;
766
+ /** Puts a three.js object (anything with position.set and quaternion.set) where one of the level's bodies is drawn this frame. */
767
+ applyTo(object3d: { position: { set(x: number, y: number, z: number): void }; quaternion: { set(...parts: number[]): unknown } }, bodyId: string): boolean;
768
+ /** One of the level's bodies as this game has it now, or null. */
769
+ bodyState(bodyId: string): { positionM: Point; rotation: Rotation } | null;
711
770
  castRay(query: RayQuery, into?: QueryHit): QueryHit | null;
712
771
  castBall(query: BallCastQuery, into?: QueryHit): QueryHit | null;
713
772
  castCapsule(query: CapsuleCastQuery, into?: QueryHit): QueryHit | null;
714
773
  overlapBall(query: BallOverlapQuery): { bodyId: string | null; characterId: string | null }[];
715
- overlapCapsule(query: CapsuleOverlapQuery): CapsuleContact[];
774
+ /** With into (a list of the caller's own, kept and given again), written there: nothing is left for the garbage collector. */
775
+ overlapCapsule(query: CapsuleOverlapQuery, into?: CapsuleContact[]): CapsuleContact[];
716
776
  }
717
777
 
718
778
  /** The same on a game server: kind.onServer(state, room). */
719
779
  export interface ServerLevelCharacters extends import("../net/index.js").ServerCharacters {
720
780
  readonly world: PhysicsWorld;
721
781
  characterState(characterId: string): CharacterView | null;
782
+ /** One of the level's bodies as this room has it now, or null. */
783
+ bodyState(bodyId: string): { positionM: Point; rotation: Rotation } | null;
722
784
  castRay(query: RayQuery, into?: QueryHit): QueryHit | null;
723
785
  castBall(query: BallCastQuery, into?: QueryHit): QueryHit | null;
724
786
  castCapsule(query: CapsuleCastQuery, into?: QueryHit): QueryHit | null;
725
787
  overlapBall(query: BallOverlapQuery): { bodyId: string | null; characterId: string | null }[];
726
- overlapCapsule(query: CapsuleOverlapQuery): CapsuleContact[];
727
- /** Switches one of the level's triangle groups in this room (a door, a bridge), 1 to 31: every player's game from the next step. */
788
+ /** With into (a list of the caller's own, kept and given again), written there: nothing is left for the garbage collector. */
789
+ overlapCapsule(query: CapsuleOverlapQuery, into?: CapsuleContact[]): CapsuleContact[];
790
+ /** Switches one of the level's triangle groups in this room (a door, a bridge), 1 to 63: every player's game from the next step. */
728
791
  setTriangleGroup(groupNumber: number, isEnabled: boolean): boolean;
729
792
  }
730
793
 
@@ -737,7 +800,8 @@ export interface LevelCharactersKind extends Kind<LevelCharacters, ServerLevelCh
737
800
  /**
738
801
  * Characters that each move on their own over a world's level (its fixed and kinematic bodies): a shooter's soldiers.
739
802
  * The online core shares them as characters, not a world: each player's game predicts only its own, everyone else is
740
- * drawn a moment behind, and a hit is judged by what the shooter saw (stateAt, viewTickNumber). Nothing in the level
741
- * moves, characters walk through each other, and one copy of the level serves every room a game server runs.
803
+ * drawn a moment behind, and a hit is judged by what the shooter saw (stateAt, viewTickNumber). The level moves only
804
+ * by timetable (a lift, a platform: a soldier rides it and is pushed by it; a query finds it where the room's present
805
+ * step has it), characters walk through each other, and one copy of the level serves every room a game server runs.
742
806
  */
743
807
  export declare function levelCharactersKind(world: PhysicsWorld | WorldDeclaration, options?: LevelCharactersOptions): LevelCharactersKind;