@viggle/splat-engine-three 0.2.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0
4
+
5
+ What games remade from the PlayCanvas build need beyond 0.2.0. Every addition is new API or an opt-in; nothing an existing app calls changes behaviour.
6
+
7
+ ### Added
8
+
9
+ - **`Scene.timeScale` and `Scene.maxDeltaTime`**, PlayCanvas's `app.timeScale` / `app.maxDeltaTime`: the loop clamps each step to `maxDeltaTime` (default 0.1 s, as before), then scales it by `timeScale` (default 1) for physics, characters and listeners. `0` pauses while drawing. A hand-called `tick(dt)` is unaffected.
10
+ - **`Scene.once(event, fn)`**; `off(event, fn)` cancels it.
11
+ - **`CreateSceneOptions.updateOrder`.** `'characters-first'`, the default, is 0.2.0's order: every character, then the `'update'` listeners. `'registration'` runs characters and listeners in the order they were added, as the PlayCanvas build does, so a listener added before a character sets a pose that is drawn the same frame.
12
+ - **`Vec3`, `Quat`, `Mat4`** exported: the math types `getBoneWorldMatrix`, `Pose` and the rig hand out, now with all of PlayCanvas 2.23's methods for each (degrees, `transformPoint`, `setFromAxisAngle`, `getEulerAngles`, statics like `Vec3.UP`), bit-identical to PlayCanvas's. The methods the rig already used are unchanged; `normalize`, `conjugate`, `mulScalar` and `invert` gain PlayCanvas's optional `src` argument.
13
+ - **`createPointToPointJoint`**: a point on one body held on a point of another, or at a point in the world, with `setPivotB` to move it and an optional `breakImpulse`. Tied to its bodies like the other joints (removed with them, re-made when one changes type). The PlayCanvas build has no such helper.
14
+ - **`setPlayCanvasLightColor`**, the conversion `SplatRelight` applies to its own lights, for lights a game sets itself.
15
+ - **`buildSourceBoneRemap`** and **`evictExpired`** (the old name of `indexAssetCache`), exported as in the PlayCanvas build.
16
+ - `ab/check-gaps.mjs`, with `ab/check-math.mjs`, checks all of the above on both backends and the math against PlayCanvas.
17
+
18
+ ### Changed
19
+
20
+ - **Bundle size.** The math methods are class methods, which do not tree-shake: every app grows by 9 KB minified (2.7 KB gzipped). Loaders-only 227.7 → 236.7 KB, engine layer 246.7 → 255.7 KB, measured as for 0.2.0 against 0.2.0 as published.
21
+ - The loop steps 0 rather than a negative time if the clock it is given goes backwards.
22
+
3
23
  ## 0.2.0
4
24
 
5
25
  Brings the port level with `@viggle/splat-engine` 0.3.2, the PlayCanvas build the mini games run on. An app written against 0.1.1 keeps working unchanged: the API is a superset of 0.1.1's, the legacy lights (`SunLight`, `SkyLight`, `PointLight`) are as they were, and characters face and move as they did. The PlayCanvas build's newer behaviour comes with `Scene`, the entry point games ported from it use.
package/README.md CHANGED
@@ -240,7 +240,10 @@ scene.start();
240
240
  | `scene.app`, `scene.graphicsDevice` | `scene.renderer`, `scene.threeScene` |
241
241
  | `scene.cameraEntity` | `scene.camera` (a `PerspectiveCamera`) |
242
242
  | `scene.graphicsDevice.setResolution(w, h)` / `.maxPixelRatio` | `scene.setResolution(w, h)` / `scene.maxPixelRatio` |
243
- | `scene.app.on('update', fn)` | `scene.on('update', fn)` (also `postUpdate`, `preRender`, `postRender`) |
243
+ | `scene.app.on('update', fn)` | `scene.on('update', fn)` (also `postUpdate`, `preRender`, `postRender`; see [Update order](#update-order)) |
244
+ | `scene.app.once('frameend', fn)` | `scene.once('postRender', fn)` |
245
+ | `scene.app.timeScale`, `scene.app.maxDeltaTime` | `scene.timeScale`, `scene.maxDeltaTime` |
246
+ | `pc.Vec3`, `pc.Quat`, `pc.Mat4` | `Vec3`, `Quat`, `Mat4` from this package (see [Math](#math)) |
244
247
  | `armature.entity`, `splat.entity`, `environment.entity` | `.object3D` |
245
248
  | `entity.addComponent('rigidbody' / 'collision', …)` | `scene.physics.addBody(object, { shape, type, mass, … })` |
246
249
  | `entity.rigidbody`, `app.systems.rigidbody.raycastFirst` | `scene.physics.getBody(object)`, `scene.physics.raycastFirst` |
@@ -249,6 +252,23 @@ scene.start();
249
252
 
250
253
  The `PhysicsWorld` class comment carries the full rigid-body mapping.
251
254
 
255
+ ### Update order
256
+
257
+ By default a frame runs physics, then every character, then the `'update'` listeners, so a listener reads the pose drawn this frame. The PlayCanvas build makes each character an `app.on('update')` handler of its own instead, so characters and listeners run in the order they were added: a listener added before a character runs before it, and a pose it sets (a scrubbed clip, a gun placed on a hand) is drawn the same frame. A game ported from that build that relies on this passes `updateOrder: 'registration'` to `Scene.create`:
258
+
259
+ ```typescript
260
+ const scene = await Scene.create(canvas, { updateOrder: 'registration' });
261
+ scene.on('update', drive); // before any character: runs first
262
+ const hero = await Character.load(scene, url);
263
+ scene.on('update', followHand); // after the hero: reads its pose for this frame
264
+ ```
265
+
266
+ `timeScale` and `maxDeltaTime` work as PlayCanvas's: the loop clamps each frame's step to `maxDeltaTime` (default 0.1 s), then multiplies it by `timeScale` (default 1) for physics, the characters and every listener. `timeScale = 0` pauses the game while it keeps drawing. A `scene.tick(dt)` called by hand takes `dt` as given.
267
+
268
+ ### Math
269
+
270
+ The rig works in PlayCanvas's own math types, ported with their formulas, so `getBoneWorldMatrix`, `Pose` and `armature.skeleton` hand out `Mat4`, `Vec3` and `Quat` rather than three.js types. The package exports them with all of PlayCanvas 2.23's methods for each (angles in degrees, `lerp(a, b, t)`, `transformPoint`, `setFromAxisAngle`, …), checked against PlayCanvas by `ab/check-math.mjs`, so game code that used `pc.Vec3` and friends keeps its maths by changing an import. `Mat4.data` has the layout of `THREE.Matrix4.elements`: `new Matrix4().fromArray(m.data)` crosses over.
271
+
252
272
  ### Colour hooks
253
273
 
254
274
  The PlayCanvas build let a game splice its own code into the engine's splat shader. Here a game hands the engine a function, which runs on every splat after the engine's own colour work - lighting, tint, relight, grade, reveal, opacity:
@@ -274,6 +294,8 @@ fade.uFade.value = 0.5; // next frame
274
294
 
275
295
  The two lighting paths are independent. `SunLight` / `SkyLight` / `PointLight` multiply each splat's colour by a factor evaluated at its centre, and are kept exactly as they were. `SplatRelight` is the PlayCanvas build's current lighting: each target gets a voxel proxy, the proxies are lit and shadowed by three.js lights into a screen-space texture, and every splat looks its lighting up there. It costs a proxy render per frame, so give it the player and a few actors, not a crowd. New lighting work happens in `SplatRelight` only.
276
296
 
297
+ A three.js light given a PlayCanvas light's `color` and `intensity` delivers a different colour: PlayCanvas linearizes the colour and, below intensity 1, the colour times the intensity. `setPlayCanvasLightColor(light, color, intensity)` gives a three.js light the PlayCanvas result; `SplatRelight` uses it for its own lights, and a game that sets the lights it passes to `relight.addLight` by hand, a flicker or a fade say, calls it on every change.
298
+
277
299
  ### GLB clips and the root bone
278
300
 
279
301
  The MetaHuman GLB presets carry a constant 180° yaw on their root bone. Up to 0.1.1 this package pinned the root bone's rotation to bind every frame, which threw that yaw away; the PlayCanvas build 0.3.2 keeps it, so a preset faces the way the clip says. Both behaviours are here, picked by where the character lives:
@@ -326,6 +348,8 @@ One difference to know when mixing the two: `Character.setPosition` lowers the m
326
348
  - **`Ragdoll.writePose` places every bone on its body.** The PlayCanvas build up to 0.3.2 reuses a scratch matrix inside a recursion, which puts the spine top, neck and arms 4-18 cm off their bodies; this port has the fix that build is getting next. The bodies simulate the same either way (final pelvis height equal to 1e-4 m).
327
349
  - **Relight shadow bias is taken at the proxy.** `shadowBias` and `normalOffsetBias` mean what they mean in PlayCanvas and give the same picture (see [Verification](#verification)), but PlayCanvas's slope-scaled offset is applied where the proxies receive the key light's shadow rather than to every caster as it draws. Meshes of the game's own that receive that shadow get the constant part only. `shadowBiasMode: 'three'` takes the numbers as three.js's `shadow.bias` / `normalBias` instead.
328
350
  - **Joints survive a body changing type.** Changing a `RigidBody`'s `type` rebuilds its Ammo body; joints holding it are re-made against the new one. The PlayCanvas build leaves them on the freed body.
351
+ - **`createPointToPointJoint`** joins a point on one body to a point on another, or holds it at a point in the world (`setPivotB` moves that point, to drag a body by it). The PlayCanvas build has no such helper; its games build `btPoint2PointConstraint` on Ammo themselves.
352
+ - **`'update'` listeners run after the characters** unless the scene is created with `updateOrder: 'registration'`; see [Update order](#update-order).
329
353
  - **`OutlineEffect` shows through walls and `PixelartEffect`'s character mask does not,** as in the PlayCanvas build.
330
354
  - **Splats under a `CameraFrame` blend in linear light,** as in the PlayCanvas build; the background is display colour on the canvas and linear inside a frame, also as there.
331
355
  - **Environments always respond to lights.** In the PlayCanvas build an environment only follows `SunLight` / `SkyLight` once a `ShadowSystem` is bound; without one it stays unlit whatever lights exist. Here it follows them from the start.
@@ -544,6 +568,7 @@ npm install --prefix ab/ref-pc # the current PlayCanvas build, once
544
568
  npm run ab -- --ref current # against it: poses, and the newer splat effects
545
569
  node ab/check-scene.mjs # the Scene facade
546
570
  node ab/check-fixes.mjs # one check per fix from the 0.2.0 review
571
+ node ab/check-gaps.mjs # time scale, update order, point-to-point joints, exported math vs PlayCanvas
547
572
  node ab/run-relight.mjs # SplatRelight vs PlayCanvas
548
573
  node ab/run-postfx-check.mjs # CameraFrame, PostFX, pixel-art, outline vs PlayCanvas
549
574
  node ab/check-physics.mjs # rigid bodies, events, raycasts, ragdoll (Ammo from test-assets/ammo/)
@@ -553,7 +578,7 @@ node ab/run-vfx.mjs # VFX and presets vs PlayCanvas
553
578
 
554
579
  `--ref` picks the PlayCanvas build: `start` (the default) is the version this port began from, which still has the legacy lights; `current` is 0.3.2, which no longer does. Against `current` - run with `legacyRootRotation` off, as a `Scene` has it - bone matrices are bit-identical in every case and frames score 49-63 dB (median 59.5), the newer effects (opacity, multiply tint, reveal, cut, colour hooks) included. Against `start`, with a `SplatEngine`'s default of pinning the root, the table above holds; see [GLB clips and the root bone](#glb-clips-and-the-root-bone).
555
580
 
556
- `node ab/check-fixes.mjs` holds one check per fix from the 0.2.0 review: the root-rotation defaults, cut bounds, sprite disposal, WebGPU buffer reuse, relight ignoring `scene.environment`, LOD manifest validation, the fetch interceptor, decoding without a worker, and the shape of `dist`.
581
+ `node ab/check-fixes.mjs` holds one check per fix from the 0.2.0 review: the root-rotation defaults, cut bounds, sprite disposal, WebGPU buffer reuse, relight ignoring `scene.environment`, LOD manifest validation, the fetch interceptor, decoding without a worker, and the shape of `dist`. `node ab/check-gaps.mjs` checks what was added for games remade from the PlayCanvas build: `timeScale` / `maxDeltaTime` / `once`, both update orders, point-to-point joints (pinned, chained, rebuilt, broken), the exported helpers, and every `Vec3` / `Quat` / `Mat4` method bit for bit against PlayCanvas 2.23.3.
557
582
 
558
583
  The module checks, against the PlayCanvas reference where it has a counterpart, both backends: relight 54-62 dB on the lit frames of the character and stage cases and 39-40 dB in the room (`chamber`), with PlayCanvas's own default bias reproduced at 36 dB; post-processing 34-48 dB; `.spz` / SOG scenes 41-64 dB and streamed LOD bundles 33-45 dB; VFX and the reveal 32-88 dB (WebGPU blends in linear light, which sets the low end); ragdoll final pelvis height equal to 1e-4 m.
559
584