@uptimizr/playcanvas 0.1.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.
Files changed (49) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +193 -0
  3. package/dist/collector.d.ts +259 -0
  4. package/dist/collector.d.ts.map +1 -0
  5. package/dist/collector.js +1081 -0
  6. package/dist/collector.js.map +1 -0
  7. package/dist/connector.d.ts +17 -0
  8. package/dist/connector.d.ts.map +1 -0
  9. package/dist/connector.js +30 -0
  10. package/dist/connector.js.map +1 -0
  11. package/dist/device.d.ts +17 -0
  12. package/dist/device.d.ts.map +1 -0
  13. package/dist/device.js +40 -0
  14. package/dist/device.js.map +1 -0
  15. package/dist/graphics.d.ts +16 -0
  16. package/dist/graphics.d.ts.map +1 -0
  17. package/dist/graphics.js +57 -0
  18. package/dist/graphics.js.map +1 -0
  19. package/dist/index.d.ts +27 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +23 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/proxy.d.ts +46 -0
  24. package/dist/proxy.d.ts.map +1 -0
  25. package/dist/proxy.js +225 -0
  26. package/dist/proxy.js.map +1 -0
  27. package/dist/raycast.d.ts +68 -0
  28. package/dist/raycast.d.ts.map +1 -0
  29. package/dist/raycast.js +163 -0
  30. package/dist/raycast.js.map +1 -0
  31. package/dist/renderer.d.ts +48 -0
  32. package/dist/renderer.d.ts.map +1 -0
  33. package/dist/renderer.js +62 -0
  34. package/dist/renderer.js.map +1 -0
  35. package/dist/scene.d.ts +21 -0
  36. package/dist/scene.d.ts.map +1 -0
  37. package/dist/scene.js +51 -0
  38. package/dist/scene.js.map +1 -0
  39. package/dist/trackScene.d.ts +114 -0
  40. package/dist/trackScene.d.ts.map +1 -0
  41. package/dist/trackScene.js +72 -0
  42. package/dist/trackScene.js.map +1 -0
  43. package/dist/uptimizr-playcanvas.global.js +66 -0
  44. package/dist/uptimizr-playcanvas.js +66 -0
  45. package/dist/vec.d.ts +10 -0
  46. package/dist/vec.d.ts.map +1 -0
  47. package/dist/vec.js +9 -0
  48. package/dist/vec.js.map +1 -0
  49. package/package.json +64 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and do
117
+ not modify the License. You may add Your own attribution notices
118
+ within Derivative Works that You distribute, alongside or as an
119
+ addendum to the NOTICE text from the Work, provided that such
120
+ additional attribution notices cannot be construed as modifying
121
+ the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions for
125
+ use, reproduction, or distribution of Your modifications, or for any
126
+ such Derivative Works as a whole, provided Your use, reproduction,
127
+ and distribution of the Work otherwise complies with the conditions
128
+ stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Uptimizr Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,193 @@
1
+ # @uptimizr/playcanvas
2
+
3
+ The PlayCanvas connector for Uptimizr. It registers as an
4
+ [`@uptimizr/sdk-core`](../sdk-core) **collector** and captures:
5
+
6
+ - **camera pose** (position + forward direction) → view-direction heatmap
7
+ - **pointer move / click** (normalized screen + optional raycast hit) → screen heatmaps
8
+ - **mesh picks** → object-engagement analytics
9
+ - **FPS** → performance
10
+ - **mesh visibility** (opt-in) → per-object dwell / attention, with an optional world AABB
11
+ - **hover dwell** (opt-in) → hover hesitation (lingering without acting)
12
+
13
+ `playcanvas` is a **peer dependency**: the connector reads from the host
14
+ application's PlayCanvas instance and never bundles or mutates the scene. It tears
15
+ down all DOM listeners, timers, and `frameend` handlers on stop. World-space data
16
+ is normalized from PlayCanvas' native **right-handed, y-up** frame to the canonical
17
+ wire frame (**left-handed, y-up**) at the emission boundary.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install @uptimizr/playcanvas playcanvas
23
+ ```
24
+
25
+ `playcanvas` is a **peer dependency** — the connector reads your existing
26
+ PlayCanvas instance and never bundles its own.
27
+
28
+ ## Usage
29
+
30
+ The quickest integration is a single call. Because PlayCanvas supports multiple
31
+ camera entities with no single "active" camera, and the connector reads FPS and the
32
+ canvas from `app.graphicsDevice`, the `camera` Entity is an explicit argument:
33
+
34
+ ```ts
35
+ import { trackScene } from "@uptimizr/playcanvas";
36
+
37
+ const client = trackScene(app, cameraEntity, {
38
+ projectId: "your-project",
39
+ endpoint: "https://collect.example.com",
40
+ });
41
+
42
+ // ... later, on teardown
43
+ await client.stop("manual");
44
+ ```
45
+
46
+ `trackScene` creates the client, registers the collector, reads device/GPU caps,
47
+ and starts the session. It returns the [`@uptimizr/sdk-core`](../sdk-core)
48
+ `UptimizrClient`, so you can read `client.sessionId`, emit custom events, or stop it.
49
+
50
+ ### Advanced: wire it up yourself
51
+
52
+ For a custom transport, a `beforeSend` hook, or registering multiple collectors,
53
+ compose the pieces directly:
54
+
55
+ ```ts
56
+ import { UptimizrClient } from "@uptimizr/sdk-core";
57
+ import { playcanvasCollector, readDeviceCaps } from "@uptimizr/playcanvas";
58
+
59
+ const client = new UptimizrClient({
60
+ projectId: "your-project",
61
+ endpoint: "https://collect.example.com",
62
+ });
63
+
64
+ client.use(playcanvasCollector({ app, camera: cameraEntity }));
65
+
66
+ // device/GPU caps ride along on session_start
67
+ client.start({ device: readDeviceCaps(app) });
68
+
69
+ // ... later, on teardown
70
+ client.stop("manual");
71
+ ```
72
+
73
+ ### Options
74
+
75
+ Both `trackScene` and `playcanvasCollector` accept the same sampling/capture knobs
76
+ as the Babylon and three connectors:
77
+
78
+ ```ts
79
+ playcanvasCollector({
80
+ app,
81
+ camera: cameraEntity,
82
+ sampleCameraMs: 1000, // camera-pose sampling interval
83
+ samplePerfMs: 2000, // FPS sampling interval (read from app.stats.frame.fps)
84
+ pointerMoveThrottleMs: 250, // min gap between pointer_move samples
85
+ capture: { camera: true, pointerMove: true, clicks: true, meshPicks: true, perf: true },
86
+ });
87
+ ```
88
+
89
+ ### Capture fidelity
90
+
91
+ The `sampling` profile sets the per-channel fidelity dial in **Hz** (`0` = off,
92
+ `"frame"` = every render tick). It governs continuous channels only — camera pose,
93
+ pointer move, and perf; discrete events (clicks, picks, custom) are always
94
+ captured. `"frame"`-cadence channels are driven by the engine's own `frameend`
95
+ event (the app's render tick), which the connector subscribes to and removes on
96
+ stop.
97
+
98
+ ```ts
99
+ playcanvasCollector({ app, camera, sampling: { camera: 10, pointerMove: 60, perf: 0.5 } });
100
+ ```
101
+
102
+ ### Opt-in dwell capture (mesh_visibility #37, hover_dwell #48)
103
+
104
+ Two attention signals are **off by default** (privacy) and emit one
105
+ bucketed summary per window/episode:
106
+
107
+ - **`mesh_visibility`** — per-object on-screen time, time near the view centre (a
108
+ gaze proxy), and the max screen fraction reached. Enable `capture.meshVisibility`
109
+ and tune via `meshVisibility`. With `boundingBox: true` it rides each object's
110
+ world AABB along (#53) so the dashboard can draw a coarse scene "ghost"; the box
111
+ is sent once and only re-sent when it moves. The connector unions each entity's
112
+ per-`MeshInstance` **world** AABB directly (PlayCanvas exposes `meshInstance.aabb`
113
+ in world space) and uses a forward half-space visibility test — **import-free**.
114
+ - **`hover_dwell`** — fires when the pointer rests on an object for at least
115
+ `minDwellMs` _without clicking it_ (a click is engagement, not hesitation).
116
+ Enable `capture.hoverDwell` and tune via `hoverDwell`.
117
+
118
+ ```ts
119
+ playcanvasCollector({
120
+ app,
121
+ camera,
122
+ capture: { meshVisibility: true, hoverDwell: true },
123
+ meshVisibility: { windowMs: 5000, boundingBox: true, centeredAngleDeg: 12, maxMeshes: 50 },
124
+ hoverDwell: { minDwellMs: 500 },
125
+ });
126
+ ```
127
+
128
+ ### Scene proxy (spatial heatmap backdrop)
129
+
130
+ `scanSceneProxy(app, { sceneId })` walks the scene graph and produces an
131
+ engine-agnostic, per-object **world AABB** proxy (already normalized to the
132
+ canonical frame) so a world-space heatmap has a faint spatial backdrop without
133
+ shipping the host's real assets. PlayCanvas hands back each `MeshInstance`'s world
134
+ AABB directly, so the proxy is a straight min/max union per named entity.
135
+
136
+ ## PlayCanvas adaptations
137
+
138
+ PlayCanvas differs from Babylon and three in a few places; each is handled at the
139
+ connector boundary so the emitted events are identical:
140
+
141
+ - **Camera forward:** a PlayCanvas `Entity.forward` getter already returns the
142
+ **true world-space** look direction (unlike three cameras, which look along local
143
+ **−Z**), so it converts straight through the canonical Z-negation — no extra
144
+ per-camera negation.
145
+ - **Pointer/raycast:** PlayCanvas has no pointer observable, so DOM listeners are
146
+ attached to `app.graphicsDevice.canvas` and hits are resolved with a `pc.Ray`
147
+ against the scene's mesh-instance world AABBs (`BoundingBox.intersectsRay`). The
148
+ pick is **physics-free** — it never touches the rigidbody system, so the
149
+ connector adds no `ammo` dependency.
150
+ - **Pointer lock (ADR 0034):** when the canvas holds the pointer lock
151
+ (`Mouse.enablePointerLock()`, first-person/FPS scenes), the OS cursor freezes, so
152
+ the connector reports `pointer_move`/`pointer_click` from the viewport centre
153
+ (`screen = [0.5, 0.5]`) and raycasts from NDC `(0, 0)` — the crosshair. Read the
154
+ spatial story from the gaze/floor-plan heatmaps, not the 2D pointer heatmap.
155
+ - **FPS:** read directly from `app.stats.frame.fps` (PlayCanvas computes it), so —
156
+ unlike three — there is no frame-counter delta.
157
+ - **"frame" cadence:** the connector owns no animation loop; it subscribes to the
158
+ engine's `frameend` event (the app's own render tick) and removes it on stop, so
159
+ dwell accumulation pauses when the tab is hidden (matching Babylon's
160
+ `onBeforeRender`).
161
+ - **Mesh visibility:** the connector unions each entity's `meshInstance.aabb`
162
+ (already world-space) into one box and uses a **forward half-space** test for
163
+ visibility, rather than a full VP-matrix frustum (PlayCanvas doesn't expose flat
164
+ projection/view matrices structurally without importing the engine). Anything in
165
+ front of the camera counts — the documented divergence from three's clip-space
166
+ frustum path.
167
+ - **Coordinate frame:** fixed right-handed, y-up (PlayCanvas has no per-scene
168
+ handedness flag like Babylon's `useRightHandedSystem`).
169
+ - **`asset_load`:** **not captured.** Mirrors the three connector — the connector
170
+ does not hook PlayCanvas' asset registry; report load timing from your app via
171
+ `client.track(...)` if needed. (Follow-up: a first-class asset-load hook.)
172
+ - **Compile stalls (`compile_stall`, #42):** **not captured.** Babylon exposes
173
+ engine-level shader-compilation observables the connector can time; PlayCanvas has
174
+ no equivalent public compile hook, so compile-stall capture is Babylon-only for now.
175
+ - **Resource footprint (`resource_sample`, #44):** captured, but with **fewer
176
+ metrics** than Babylon. `app.stats.frame.triangles` gives the `triangles`
177
+ submitted last frame; there is no public per-frame vertex count, and resident
178
+ texture/geometry bytes aren't exposed, so those fields are omitted (the read
179
+ API's averages skip unreported metrics). `jsHeapBytes` comes from the
180
+ Chromium-only `performance.memory`. Opt-in (`capture.resourceSample`), low-rate,
181
+ and read-only like the rest.
182
+ - **Capability changes (`capability_change`, #49):** **not auto-captured — by
183
+ design.** A WebGPU→WebGL2 downgrade or a re-init after a lost device is an
184
+ _app/engine decision_ with no reliable runtime hook the connector could observe
185
+ (PlayCanvas picks its backend at device creation). Report these transitions from
186
+ your app with the engine-neutral
187
+ `client.reportCapabilityChange({ kind, from?, to?, reason? })` (sdk-core). The
188
+ raw GPU lifecycle (`context_lost` / `context_restored`) is still captured by the
189
+ connector; `capability_change` is the higher-level companion.
190
+
191
+ ## License
192
+
193
+ [Apache-2.0](./LICENSE) © Uptimizr.
@@ -0,0 +1,259 @@
1
+ import type { AppBase, Entity } from "playcanvas";
2
+ import type { Collector, SamplingProfile } from "@uptimizr/sdk-core";
3
+ import type { GazeProbe, GazeProbeOptions, RaycastProbe } from "./raycast.js";
4
+ /** Which signals the collector captures. All default to `true`. */
5
+ export interface PlayCanvasCaptureOptions {
6
+ camera?: boolean;
7
+ pointerMove?: boolean;
8
+ clicks?: boolean;
9
+ /** Raw `pointer_down` / `pointer_up` button transitions (press-and-hold, drags). */
10
+ buttons?: boolean;
11
+ /**
12
+ * Typed `camera_gesture` navigation capture (ADR 0025). **On by default**: it
13
+ * separates navigation intent (orbit/pan/dolly/zoom/roll/fly) from object
14
+ * selection, costs only a snapshot+diff per gesture, and carries no PII.
15
+ */
16
+ cameraGesture?: boolean;
17
+ meshPicks?: boolean;
18
+ perf?: boolean;
19
+ /** WebGL `webglcontextlost` / `webglcontextrestored` transitions on the canvas. */
20
+ contextLoss?: boolean;
21
+ /**
22
+ * Per-object dwell / attention capture (`mesh_visibility`, #37). **Opt-in, off
23
+ * by default** (privacy, ADR 0003). Each window the connector emits one
24
+ * bucketed summary per tracked object (ADR 0012): on-screen time, time spent
25
+ * near the view centre (a gaze proxy), and the max screen fraction reached.
26
+ * Configure via {@link PlayCanvasCollectorOptions.meshVisibility}.
27
+ */
28
+ meshVisibility?: boolean;
29
+ /**
30
+ * Hover-hesitation capture (`hover_dwell`, #48). **Opt-in, off by default**
31
+ * (privacy, ADR 0003): emits one bucketed summary per hover episode (ADR 0012)
32
+ * when the pointer lingers on an object *without acting on it*. Configure via
33
+ * {@link PlayCanvasCollectorOptions.hoverDwell}.
34
+ */
35
+ hoverDwell?: boolean;
36
+ /**
37
+ * GPU / memory footprint capture (`resource_sample`, #44). **Opt-in, off by
38
+ * default** (privacy + cost, ADR 0003): emits one low-rate summary per window
39
+ * (ADR 0012) of the triangles submitted last frame (`app.stats.frame`) and the
40
+ * JS heap size. Configure cadence via {@link PlayCanvasCollectorOptions.resourceSample}.
41
+ */
42
+ resourceSample?: boolean;
43
+ /**
44
+ * Gaze raycast capture (`camera_sample.hitPoint`/`hitMesh`, ADR 0030). **Opt-in,
45
+ * off by default** (privacy + cost, ADR 0003): when on, each emitted
46
+ * `camera_sample` carries the world-space point (and object name) the camera is
47
+ * looking at — one camera-forward raycast per sample, riding the throttled,
48
+ * idle-suppressed camera cadence. Configure via
49
+ * {@link PlayCanvasCollectorOptions.gaze}.
50
+ */
51
+ gaze?: boolean;
52
+ /**
53
+ * Scene-actor transform capture (`node_transform`, ADR 0027 Tier 1). **On by
54
+ * default**, but inert unless actors are declared in
55
+ * {@link PlayCanvasCollectorOptions.actors} AND given a rate in
56
+ * `sampling.nodes` — so nothing is captured until you opt a node in.
57
+ */
58
+ nodes?: boolean;
59
+ /**
60
+ * Skeleton bone-transform capture (`node_transform` with `boneId`, ADR 0027
61
+ * Tier 2). **On by default**, but inert unless an actor is declared in
62
+ * {@link PlayCanvasCollectorOptions.actors} AND given a per-bone allowlist in
63
+ * `sampling.bones` — each allowlisted bone's skeleton-local pose is captured so
64
+ * replay can re-drive an animated character.
65
+ */
66
+ bones?: boolean;
67
+ /**
68
+ * Keyboard `input_action` capture (ADR 0023). **Off unless `keyBindings` is
69
+ * provided** — only explicitly bound keys are recorded, never arbitrary typing
70
+ * (privacy, ADR 0003). On by default once bindings exist; set `false` to
71
+ * disable even when bindings are present.
72
+ */
73
+ keyboard?: boolean;
74
+ }
75
+ /** Per-object dwell capture options (`mesh_visibility`, #37) — mirrors Babylon. */
76
+ export interface MeshVisibilityOptions {
77
+ /** Summary window length in ms — one event per object per window. Default 5000. */
78
+ windowMs?: number;
79
+ /**
80
+ * Allowlist of mesh names to track (low-cardinality, app-defined — ADR 0003).
81
+ * When omitted, every visible, renderable, non-overlay object is tracked, capped
82
+ * by {@link maxMeshes}.
83
+ */
84
+ meshes?: string[];
85
+ /**
86
+ * Half-angle in degrees from the camera forward axis within which an object's
87
+ * centre counts as "near the view centre" for `centeredMs`. Default 12.
88
+ */
89
+ centeredAngleDeg?: number;
90
+ /** Max meshes to track when no allowlist is given. Default 50. */
91
+ maxMeshes?: number;
92
+ /**
93
+ * Attach each tracked object's world-space AABB to its summary (#53), so the
94
+ * dashboard can render a coarse "ghost" reconstruction of the scene. Off by
95
+ * default (extra volume + discloses layout, ADR 0003). The box is sent once
96
+ * per object and re-sent only when it moves/resizes beyond a small epsilon.
97
+ */
98
+ boundingBox?: boolean;
99
+ }
100
+ /** Hover-hesitation capture options (`hover_dwell`, #48) — mirrors Babylon. */
101
+ export interface HoverDwellOptions {
102
+ /**
103
+ * Minimum uninterrupted hover time in ms before an episode is reported. Short
104
+ * pass-overs aren't hesitation, so they're dropped. Default 500.
105
+ */
106
+ minDwellMs?: number;
107
+ /**
108
+ * Allowlist of mesh names to track (low-cardinality, app-defined — ADR 0003).
109
+ * When omitted, hover over any picked mesh is tracked.
110
+ */
111
+ meshes?: string[];
112
+ }
113
+ /** GPU / memory footprint capture options (`resource_sample`, #44) — mirrors Babylon. */
114
+ export interface ResourceSampleOptions {
115
+ /**
116
+ * Sampling interval in ms — one footprint summary per window (ADR 0012). The
117
+ * footprint moves slowly, so the default is deliberately low-rate. Default
118
+ * 15000 (every 15s).
119
+ */
120
+ intervalMs?: number;
121
+ }
122
+ /**
123
+ * Gaze probe tuning (`camera_sample.hitPoint`/`hitMesh`, ADR 0030). Only consulted
124
+ * when `capture.gaze` is enabled. Mirrors Babylon's `GazeOptions`.
125
+ */
126
+ export interface PlayCanvasGazeOptions extends GazeProbeOptions {
127
+ /**
128
+ * Override the gaze probe (a camera-forward raycaster). Defaults to
129
+ * {@link createGazeRaycaster}. Tests inject a stub so gaze is exercised without
130
+ * real geometry.
131
+ */
132
+ probe?: GazeProbe;
133
+ }
134
+ export interface PlayCanvasCollectorOptions {
135
+ /** The PlayCanvas application to instrument (read-only). */
136
+ app: AppBase;
137
+ /**
138
+ * Camera Entity to record for the view-direction / pose timeline. PlayCanvas
139
+ * supports multiple camera entities with no single "active" camera, so the one
140
+ * the viewer flies must be passed explicitly.
141
+ */
142
+ camera: Entity;
143
+ /** Camera-pose sampling interval in ms. Default 1000. */
144
+ sampleCameraMs?: number;
145
+ /** Performance (FPS) sampling interval in ms. Default 2000. */
146
+ samplePerfMs?: number;
147
+ /** Minimum gap between `pointer_move` samples in ms. Default 250. */
148
+ /** Minimum gap between `pointer_move` samples in ms. Default 250. */
149
+ pointerMoveThrottleMs?: number;
150
+ /**
151
+ * Sensitivity dial for `camera_gesture` classification (ADR 0025). Scales every
152
+ * motion dead-zone together: `> 1` is less sensitive, `< 1` more. Default 1.
153
+ */
154
+ cameraGestureSensitivity?: number;
155
+ /**
156
+ * Per-channel capture-fidelity dial in Hz / `"frame"` / `0`-off (ADR 0012).
157
+ * Governs continuous channels only (camera pose, pointer move, perf); discrete
158
+ * events are always captured. When a channel is set here it overrides the
159
+ * matching legacy ms knob above; omitted channels keep the conservative
160
+ * defaults. There is no enforced upper bound — `"frame"` captures every tick.
161
+ */
162
+ sampling?: SamplingProfile;
163
+ /**
164
+ * Skip timer-based **camera** samples when the pose is unchanged (within
165
+ * {@link cameraEpsilon}). The first sample is always emitted so the timeline has
166
+ * a baseline. Default `true`.
167
+ */
168
+ suppressIdleSamples?: boolean;
169
+ /**
170
+ * Skip timer-based `frame_perf` samples when FPS is unchanged (within
171
+ * {@link perfFpsThreshold}). Default `false` — a steady FPS is meaningful
172
+ * telemetry, so the perf channel reports continuously.
173
+ */
174
+ suppressIdlePerfSamples?: boolean;
175
+ /** Max per-axis pose change treated as "unchanged" for camera dedupe. Default 1e-3. */
176
+ cameraEpsilon?: number;
177
+ /** Max FPS change treated as "unchanged" for perf dedupe. Default 1. */
178
+ perfFpsThreshold?: number;
179
+ /** Toggle individual capture channels. */
180
+ capture?: PlayCanvasCaptureOptions;
181
+ /**
182
+ * Per-object dwell capture tuning (`mesh_visibility`, #37). Only consulted when
183
+ * `capture.meshVisibility` is enabled.
184
+ */
185
+ meshVisibility?: MeshVisibilityOptions;
186
+ /**
187
+ * Hover-hesitation capture tuning (`hover_dwell`, #48). Only consulted when
188
+ * `capture.hoverDwell` is enabled.
189
+ */
190
+ hoverDwell?: HoverDwellOptions;
191
+ /**
192
+ * GPU / memory footprint capture tuning (`resource_sample`, #44). Only consulted
193
+ * when `capture.resourceSample` is enabled.
194
+ */
195
+ resourceSample?: ResourceSampleOptions;
196
+ /**
197
+ * Gaze probe tuning (`camera_sample.hitPoint`/`hitMesh`, ADR 0030). Only
198
+ * consulted when `capture.gaze` is enabled.
199
+ */
200
+ gaze?: PlayCanvasGazeOptions;
201
+ /**
202
+ * Override the raycast probe used to resolve pointer hits (world point + object
203
+ * name). Defaults to a `pc.Ray` against the scene's mesh-instance world AABBs
204
+ * ({@link createSceneRaycaster}). Provide one to customize picking — and tests
205
+ * inject a stub so picking is exercised without real geometry.
206
+ */
207
+ raycast?: RaycastProbe;
208
+ /**
209
+ * Scene-actor map for `node_transform` capture (ADR 0027 Tier 1): developer-
210
+ * controlled, self-moving nodes (a patrolling NPC, a lift, a vehicle) whose
211
+ * world transform is sampled so replay can reproduce them. Each value resolves
212
+ * to a live node — a direct Entity reference, an entity **name** (looked up via
213
+ * `app.root.findByName`), or a `() => Entity` resolver (robust to load order).
214
+ * A node is only captured when its id also has a rate in `sampling.nodes`;
215
+ * cameras are refused (the visitor camera is already `camera_sample`).
216
+ */
217
+ actors?: Record<string, PlayCanvasActor>;
218
+ /**
219
+ * Keyboard bindings to capture as `input_action` events (ADR 0023): a map from
220
+ * `KeyboardEvent.code` (e.g. `"KeyW"`, `"ArrowLeft"`) to a semantic app action
221
+ * (e.g. `"move-forward"`). **Only bound keys are recorded** — unbound keys are
222
+ * never seen, so arbitrary typing is never captured (privacy, ADR 0003).
223
+ * Auto-repeat (held keys) is suppressed; each press and release emits once.
224
+ * PlayCanvas exposes no keyboard observable here, so the connector listens on `window`.
225
+ */
226
+ keyBindings?: Record<string, string>;
227
+ }
228
+ /** A PlayCanvas node that exposes a world transform (a `node_transform` actor, ADR 0027). */
229
+ export type PlayCanvasActorNode = Entity;
230
+ /**
231
+ * A declared scene actor (ADR 0027): a live {@link PlayCanvasActorNode}, an entity
232
+ * **name** resolved via `app.root.findByName`, or a `() => Entity` resolver called
233
+ * each sample (robust to load order and disposal).
234
+ */
235
+ export type PlayCanvasActor = (() => PlayCanvasActorNode | null | undefined) | string | PlayCanvasActorNode;
236
+ /**
237
+ * Create the PlayCanvas connector as an sdk-core {@link Collector}. Register it
238
+ * with `client.use(...)`.
239
+ *
240
+ * It samples camera pose (view-direction heatmap), pointer movement and clicks
241
+ * (screen heatmaps), mesh picks (object engagement), and FPS (perf). It only reads
242
+ * from the scene — it never mutates it — and tears every listener, timer, and
243
+ * frame handler down on stop (ADR 0003: no cookies, no persistent ids).
244
+ *
245
+ * Device/GPU capabilities are captured separately via {@link "./device".readDeviceCaps}.
246
+ *
247
+ * ## PlayCanvas adaptations (vs. the three connector)
248
+ * - **Camera pose:** a PlayCanvas Entity's `forward` getter already returns the
249
+ * true world look direction (no local −Z negation), so it converts straight
250
+ * through `toCanonicalDirection`.
251
+ * - **FPS:** PlayCanvas computes FPS itself, so perf reads `app.stats.frame.fps`
252
+ * directly rather than deriving it from a frame-counter delta.
253
+ * - **"frame" cadence:** the connector owns no rAF loop; it subscribes to the
254
+ * engine's `frameend` event (the app's own render tick) and removes it on stop.
255
+ * - **World AABBs:** `meshInstance.aabb` is already a world-space box, so mesh
256
+ * visibility unions those directly instead of transforming local corners.
257
+ */
258
+ export declare function playcanvasCollector(options: PlayCanvasCollectorOptions): Collector;
259
+ //# sourceMappingURL=collector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collector.d.ts","sourceRoot":"","sources":["../src/collector.ts"],"names":[],"mappings":"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"}