@uptimizr/godot 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.
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,89 @@
1
+ # @uptimizr/godot
2
+
3
+ The **Godot (Web export)** connector for Uptimizr (ADR 0045). Godot 4 compiles to
4
+ WebAssembly and renders into a `<canvas>`, so there is no live JS scene to read — this
5
+ connector is built on [`@uptimizr/web-export`](../web-export) and works in **two
6
+ tiers**:
7
+
8
+ | Tier | Engine code? | Captures |
9
+ | ----------- | ----------------------------------------------- | --------------------------------------------------------------- |
10
+ | **JS-only** | none | pointer move/click heatmaps, FPS / long frames, JS errors |
11
+ | **Bridged** | a thin copy-in shim (see [`bridge/`](./bridge)) | camera pose → view-direction heatmap, world-space picks, replay |
12
+
13
+ Godot's native world frame is **right-handed, y-up, meters**, so the connector negates
14
+ Z to reach the canonical wire frame (left-handed, y-up — ADR 0018). The engine-side
15
+ shim does **no** coordinate math.
16
+
17
+ ### Verification status
18
+
19
+ | Tier | Status | How it is verified |
20
+ | ----------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
21
+ | **JS-only** | **Stable** | Unit tests plus the web-export Playwright round trip (`examples/playground/e2e/web-export.spec.ts`). |
22
+ | **Bridged** | **Verified** | An **automated headless Godot 4.7.2 Web export** of the reference sample project, driven by Playwright in CI (`godot-export-e2e` job → `examples/playground/e2e/godot-export.spec.ts`). It boots the real WASM export with the shipped `UptimizrGodot.gd` autoload and asserts `camera_sample` (Z negated), `mesh_interaction` (raycast pick named `Crate`), `frame_perf`, and the scene proxy reach the collector. |
23
+
24
+ The **reference integration** is
25
+ [`examples/godot-web-export`](../../../examples/godot-web-export/README.md) — a minimal
26
+ Godot 4 project with the autoload registered, named pickable `StaticBody3D` props, and a
27
+ nothreads Web preset (`pnpm godot:fetch && pnpm godot:export && pnpm test:e2e:godot`
28
+ reproduces the CI proof locally). The sample's copy of the shim is checked byte-for-byte
29
+ against `bridge/UptimizrGodot.gd`, so the test always exercises the asset you ship.
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ npm install @uptimizr/godot
35
+ ```
36
+
37
+ The engine-side bridge is a **copy-in asset** (a `JavaScriptBridge` autoload), not an
38
+ npm dependency — see [`bridge/`](./bridge).
39
+
40
+ ## Usage
41
+
42
+ ```ts
43
+ import { trackGodot } from "@uptimizr/godot";
44
+
45
+ const { client, bridge } = trackGodot({
46
+ projectId: "your-project",
47
+ endpoint: "https://collect.example.com",
48
+ canvas: () => document.querySelector("#godot-canvas"),
49
+ });
50
+
51
+ // ... later, on teardown
52
+ await client.stop("manual");
53
+ ```
54
+
55
+ `trackGodot` creates the client, registers the JS-only tier collector, exposes the
56
+ engine `bridge` (default `window.__uptimizr_godot__`), and starts the session with
57
+ Godot's connector provenance. The JS-only tier captures immediately; wire the
58
+ engine-side shim to `bridge` to add camera pose, picks, and replay.
59
+
60
+ ### Advanced: wire it up yourself
61
+
62
+ ```ts
63
+ import { UptimizrClient } from "@uptimizr/sdk-core";
64
+ import { godotCollector, GODOT_FRAME } from "@uptimizr/godot";
65
+
66
+ const client = new UptimizrClient({ projectId: "your-project", endpoint: "..." });
67
+ client.use(godotCollector({ canvas: () => document.querySelector("#godot-canvas") }));
68
+ client.start();
69
+ ```
70
+
71
+ ## Engine-side bridge
72
+
73
+ The bridged tier needs a thin copy-in shim that pushes world-space pose / picks / FPS
74
+ across Godot's `JavaScriptBridge`. The package ships ready-to-use autoloads in both
75
+ languages — [`bridge/UptimizrGodot.gd`](./bridge/UptimizrGodot.gd) (GDScript) and
76
+ [`bridge/UptimizrGodot.cs`](./bridge/UptimizrGodot.cs) (C#). Copy one into your Godot 4
77
+ project and register it as an Autoload named `UptimizrGodot` (**Project → Project Settings →
78
+ Globals → Autoload**). It guards on `OS.has_feature("web")`, so it is a no-op outside the
79
+ Web export. Full setup, options, and the bridge contract are in
80
+ [`bridge/README.md`](./bridge/README.md).
81
+
82
+ ## Privacy
83
+
84
+ No client-side persistent IDs and no PII by default (ADR 0003). `client.stop()` tears
85
+ down every listener, timer, and animation-frame callback.
86
+
87
+ ## License
88
+
89
+ Apache-2.0.
@@ -0,0 +1,102 @@
1
+ # Godot engine-side bridge (copy-in asset)
2
+
3
+ The thin Godot 4 shim that unlocks the **bridged tier** (camera pose / view-direction
4
+ heatmap, world-space picks, FPS, scene proxy, replay) of the
5
+ [`@uptimizr/godot`](../README.md) connector. The **JS-only tier** (pointer heatmaps, FPS,
6
+ and JS errors) already works with **no** engine code — this shim is only needed for the
7
+ 3D-native channels.
8
+
9
+ It ships as a **copy-in asset**, not an npm/NuGet package:
10
+
11
+ - [`UptimizrGodot.gd`](./UptimizrGodot.gd) — GDScript autoload (recommended).
12
+ - [`UptimizrGodot.cs`](./UptimizrGodot.cs) — C# autoload for Godot 4 .NET projects.
13
+
14
+ Both are Apache-2.0 and functionally identical — use the one matching your project's
15
+ language.
16
+
17
+ ## What the shim is
18
+
19
+ A small, dumb shim that pushes per-sample telemetry from Godot across the JS interop
20
+ boundary to the browser-side connector. It carries **no** analytics logic, IDs, or schema
21
+ knowledge (ADR 0045). For Godot 4 Web exports it is an **autoload** that uses
22
+ `JavaScriptBridge` (`JavaScriptBridge.get_interface(...)` / `create_object`) to call the
23
+ connector each sample with the active `Camera3D` pose, raycast picks, and FPS.
24
+
25
+ ## Setup
26
+
27
+ 1. **Host page** — load `@uptimizr/godot` in the page that hosts the Web export and start
28
+ a session. `trackGodot(...)` exposes the bridge on `window.__uptimizr_godot__`:
29
+
30
+ ```ts
31
+ import { trackGodot } from "@uptimizr/godot";
32
+
33
+ trackGodot({
34
+ projectId: "your-project",
35
+ endpoint: "https://collect.example.com",
36
+ canvas: () => document.querySelector("#godot-canvas"),
37
+ });
38
+ ```
39
+
40
+ 2. **Godot project** — copy `UptimizrGodot.gd` (or `.cs`) into your project, then register
41
+ it as a singleton: **Project → Project Settings → Globals → Autoload**, add the script
42
+ with node name `UptimizrGodot`, and enable it. On the next Web export it finds the
43
+ bridge and starts pushing poses, picks, and FPS automatically.
44
+
45
+ Off the Web export (editor, desktop, mobile) the autoload guards on `OS.has_feature("web")`
46
+ and is a no-op, so it is safe to leave enabled in every build.
47
+
48
+ ### Options (exported on the autoload)
49
+
50
+ | Property | Default | Meaning |
51
+ | ------------------------- | ------- | ----------------------------------------------------------------------- |
52
+ | `pose_samples_per_second` | `30` | Pose push rate cap (`<= 0` pushes every frame). FPS is sent each frame. |
53
+ | `capture_picks` | `true` | Left-click casts a physics ray and pushes the first named collider. |
54
+ | `pick_ray_length` | `1000` | Ray length (metres) for click picks. |
55
+
56
+ ### Scene proxy (optional)
57
+
58
+ For world-space object engagement and replay completeness, mark the nodes you want
59
+ described (developer opt-in — keeps the proxy low-cardinality and PII-free), then push once
60
+ after your scene is built:
61
+
62
+ ```gdscript
63
+ $Crate.add_to_group("uptimizr_tracked") # any VisualInstance3D
64
+ UptimizrGodot.push_scene_proxy()
65
+ ```
66
+
67
+ ## The JS API the shim calls
68
+
69
+ The connector exposes an `EngineBridge` on `window.__uptimizr_godot__` (configurable via
70
+ the connector's `bridgeGlobal` option). **All values are world-space in Godot's native
71
+ frame** (right-handed, y-up, meters); the connector negates Z to reach the canonical wire
72
+ frame and emits the schema events — the shim does **no** coordinate math.
73
+
74
+ ```ts
75
+ interface EngineBridge {
76
+ readonly protocolVersion: number; // assert against BRIDGE_PROTOCOL_VERSION (1)
77
+ pushPose(position: [x, y, z], forward: [x, y, z], up: [x, y, z], fov?: number): void;
78
+ pushPick(objectName: string, hitPoint: [x, y, z]): void;
79
+ pushPerf(fps: number, longFrames?: number): void;
80
+ setSceneProxy(nodes: { name: string; aabb: [minX, minY, minZ, maxX, maxY, maxZ] }[]): void;
81
+ dispose(): void;
82
+ }
83
+ ```
84
+
85
+ The shim asserts `protocolVersion === 1` on startup and disables itself on a mismatch, so a
86
+ newer page bridge never receives malformed pushes.
87
+
88
+ ### Coordinate notes
89
+
90
+ - Pass the camera's **world-space forward vector** — `-cam.global_transform.basis.z`
91
+ (Godot cameras look down local −Z), not a local rotation.
92
+ - `Camera3D.fov` is **vertical degrees** by default (`KEEP_HEIGHT`); the bridge wants
93
+ **radians**, so the shim sends `deg_to_rad(cam.fov)`.
94
+ - Raw GDScript/C# arrays do **not** auto-marshal across the JS boundary, so the shim builds
95
+ real JS arrays via `JavaScriptBridge.create_object("Array", x, y, z)`.
96
+
97
+ ## Privacy (ADR 0003)
98
+
99
+ The shim transmits only low-cardinality, non-PII telemetry: poses, FPS, and
100
+ developer-assigned **named** objects. It MUST NOT invent identifiers or forward raw input
101
+ text. Picks send only the node `name` you authored and the world hit point; the scene proxy
102
+ sends only the nodes you explicitly mark.
@@ -0,0 +1,185 @@
1
+ // UptimizrGodot.cs — C# engine-side bridge for the @uptimizr/godot connector (ADR 0045).
2
+ //
3
+ // Copy-in asset (Apache-2.0). NOT a NuGet/npm package. C# parity of UptimizrGodot.gd for
4
+ // Godot 4 .NET projects. Add it as an Autoload singleton to enable the connector's
5
+ // *bridged tier* (camera pose / world-space picks / FPS / scene proxy). The *JS-only
6
+ // tier* (pointer heatmaps + FPS + JS errors) already works with no engine code.
7
+ //
8
+ // Setup:
9
+ // 1. Load @uptimizr/godot in the Web export's host page and call `trackGodot(...)`,
10
+ // which exposes the bridge on `window.__uptimizr_godot__`.
11
+ // 2. Project > Project Settings > Globals > Autoload: add this script as `UptimizrGodot`.
12
+ //
13
+ // This shim carries NO analytics logic, IDs, or schema knowledge. It hands **world-space
14
+ // values in Godot's NATIVE frame** (right-handed, y-up, meters) to the connector, which
15
+ // owns all normalization (negates Z) and schema mapping.
16
+ //
17
+ // Privacy (ADR 0003): only poses, FPS, and developer-named objects cross the bridge. It
18
+ // MUST NOT invent identifiers or forward raw input.
19
+ using Godot;
20
+
21
+ public partial class UptimizrGodot : Node
22
+ {
23
+ // Expected bridge wire-protocol version (must match BRIDGE_PROTOCOL_VERSION in
24
+ // @uptimizr/web-export).
25
+ private const int ProtocolVersion = 1;
26
+
27
+ // The `window` property the connector exposes the bridge on.
28
+ private const string BridgeGlobal = "__uptimizr_godot__";
29
+
30
+ // Nodes in this group are included when PushSceneProxy() is called (opt-in).
31
+ private const string SceneProxyGroup = "uptimizr_tracked";
32
+
33
+ /// <summary>Push at most this many camera poses per second. Set &lt;= 0 to push every frame.</summary>
34
+ [Export] public float PoseSamplesPerSecond = 30.0f;
35
+
36
+ /// <summary>When true, a left click casts a ray and pushes the first named collider hit.</summary>
37
+ [Export] public bool CapturePicks = true;
38
+
39
+ /// <summary>Physics ray length (metres) used for click picks.</summary>
40
+ [Export] public float PickRayLength = 1000.0f;
41
+
42
+ private JavaScriptObject _bridge;
43
+ private bool _readyOk;
44
+ private float _accum;
45
+
46
+ public override void _Ready()
47
+ {
48
+ if (!OS.HasFeature("web"))
49
+ {
50
+ SetProcess(false);
51
+ SetProcessUnhandledInput(false);
52
+ return;
53
+ }
54
+
55
+ _bridge = JavaScriptBridge.GetInterface(BridgeGlobal);
56
+ if (_bridge == null)
57
+ {
58
+ GD.PushWarning($"[Uptimizr] bridge global '{BridgeGlobal}' not found — call trackGodot() in the host page before this autoload runs.");
59
+ SetProcess(false);
60
+ SetProcessUnhandledInput(false);
61
+ return;
62
+ }
63
+
64
+ var version = (int)_bridge.Get("protocolVersion");
65
+ if (version != ProtocolVersion)
66
+ {
67
+ GD.PushWarning($"[Uptimizr] bridge protocol mismatch (page={version}, shim={ProtocolVersion}) — disabling pose/pick capture.");
68
+ _bridge = null;
69
+ SetProcess(false);
70
+ SetProcessUnhandledInput(false);
71
+ return;
72
+ }
73
+
74
+ _readyOk = true;
75
+ }
76
+
77
+ public override void _Process(double delta)
78
+ {
79
+ if (!_readyOk)
80
+ return;
81
+
82
+ if (PoseSamplesPerSecond > 0.0f)
83
+ {
84
+ _accum += (float)delta;
85
+ float interval = 1.0f / PoseSamplesPerSecond;
86
+ if (_accum < interval)
87
+ {
88
+ PushPerf();
89
+ return;
90
+ }
91
+ _accum = 0.0f;
92
+ }
93
+
94
+ PushPose();
95
+ PushPerf();
96
+ }
97
+
98
+ private void PushPose()
99
+ {
100
+ var cam = GetViewport().GetCamera3D();
101
+ if (cam == null)
102
+ return;
103
+ var xform = cam.GlobalTransform;
104
+ var p = xform.Origin;
105
+ // Godot cameras look down their local -Z; pass the WORLD-space forward vector.
106
+ var f = -xform.Basis.Z;
107
+ var u = xform.Basis.Y;
108
+ // Camera3D.Fov is vertical degrees by default (KEEP_HEIGHT); the bridge wants radians.
109
+ _bridge.Call("pushPose", Vec3(p), Vec3(f), Vec3(u), Mathf.DegToRad(cam.Fov));
110
+ }
111
+
112
+ private void PushPerf()
113
+ {
114
+ _bridge.Call("pushPerf", Engine.GetFramesPerSecond());
115
+ }
116
+
117
+ public override void _UnhandledInput(InputEvent @event)
118
+ {
119
+ if (!_readyOk || !CapturePicks)
120
+ return;
121
+ if (@event is InputEventMouseButton mb && mb.Pressed && mb.ButtonIndex == MouseButton.Left)
122
+ PushPickAt(mb.Position);
123
+ }
124
+
125
+ private void PushPickAt(Vector2 screenPos)
126
+ {
127
+ var cam = GetViewport().GetCamera3D();
128
+ if (cam == null)
129
+ return;
130
+ var from = cam.ProjectRayOrigin(screenPos);
131
+ var to = from + cam.ProjectRayNormal(screenPos) * PickRayLength;
132
+ var space = cam.GetWorld3D().DirectSpaceState;
133
+ var query = PhysicsRayQueryParameters3D.Create(from, to);
134
+ var hit = space.IntersectRay(query);
135
+ if (hit.Count == 0)
136
+ return;
137
+ if (hit["collider"].AsGodotObject() is not Node node)
138
+ return;
139
+ // Only the developer-assigned node name and the world hit point are sent (ADR 0003).
140
+ var point = hit["position"].AsVector3();
141
+ _bridge.Call("pushPick", node.Name.ToString(), Vec3(point));
142
+ }
143
+
144
+ /// <summary>
145
+ /// Push a spatial proxy of the named, developer-marked nodes in the scene-proxy group.
146
+ /// Call this once after your scene is built (opt-in keeps the proxy low-cardinality).
147
+ /// </summary>
148
+ public void PushSceneProxy()
149
+ {
150
+ if (!_readyOk)
151
+ return;
152
+ var nodes = JavaScriptBridge.CreateObject("Array");
153
+ foreach (var node in GetTree().GetNodesInGroup(SceneProxyGroup))
154
+ {
155
+ if (node is not VisualInstance3D vi)
156
+ continue;
157
+ var local = vi.GetAabb();
158
+ var world = vi.GlobalTransform * local;
159
+ var minP = world.Position;
160
+ var maxP = world.Position + world.Size;
161
+ var entry = JavaScriptBridge.CreateObject("Object");
162
+ entry.Set("name", vi.Name.ToString());
163
+ entry.Set("aabb", JavaScriptBridge.CreateObject(
164
+ "Array", minP.X, minP.Y, minP.Z, maxP.X, maxP.Y, maxP.Z));
165
+ nodes.Call("push", entry);
166
+ }
167
+ _bridge.Call("setSceneProxy", nodes);
168
+ }
169
+
170
+ /// <summary>Detach the bridge; subsequent pushes become no-ops.</summary>
171
+ public void Dispose()
172
+ {
173
+ _bridge?.Call("dispose");
174
+ _bridge = null;
175
+ _readyOk = false;
176
+ SetProcess(false);
177
+ SetProcessUnhandledInput(false);
178
+ }
179
+
180
+ // Build a JS `[x, y, z]` array; raw arrays do not auto-marshal across the JS boundary.
181
+ private static JavaScriptObject Vec3(Vector3 v)
182
+ {
183
+ return JavaScriptBridge.CreateObject("Array", v.X, v.Y, v.Z);
184
+ }
185
+ }