@threenative/core 0.3.4 → 0.3.6

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 (176) hide show
  1. package/capabilities.json +1505 -79
  2. package/dist/{audio-7i3Xl0l3.d.ts → audio-DIJE5HTr.d.ts} +43 -3
  3. package/dist/{canvas-layer-DDmC_VVF.d.ts → canvas-layer-C1-5CviZ.d.ts} +5 -1
  4. package/dist/{game-CljaDv4D.d.ts → game-Jz4Fdoeb.d.ts} +114 -11
  5. package/dist/hot.d.ts +4 -4
  6. package/dist/index.d.ts +712 -118
  7. package/dist/index.js +12437 -4955
  8. package/dist/{gpu-readback-CqJEfWNQ.d.ts → model-lod-BDAUYgsS.d.ts} +80 -5
  9. package/dist/playtest.d.ts +6 -10
  10. package/dist/playtest.js +57 -24
  11. package/dist/react-css.d.ts +62 -0
  12. package/dist/react-css.js +591 -0
  13. package/dist/react.d.ts +2 -2
  14. package/dist/{renderer-CfsS2hxi.d.ts → renderer-9yEo9hPa.d.ts} +489 -22
  15. package/dist/terrain-jobs-worker.d.ts +2 -0
  16. package/dist/terrain-jobs-worker.js +130 -0
  17. package/dist/ui-layer.js +59 -8
  18. package/dist/world.d.ts +766 -73
  19. package/dist/world.js +9307 -3543
  20. package/gpl/recipes/export_world.py +18 -1
  21. package/mcp/blender-server.mjs +7 -4
  22. package/mcp/blender.mjs +3 -4
  23. package/mcp/engine-server.mjs +2 -2
  24. package/mcp/servers.mjs +4 -4
  25. package/package.json +15 -9
  26. package/patches/three@0.185.1-prd269-upgrade.patch +22418 -0
  27. package/patches/three@0.185.1.patch +6594 -700
  28. package/scripts/apply-three-patch.mjs +62 -4
  29. package/src/animation-blend.ts +264 -0
  30. package/src/animation-composition.ts +362 -0
  31. package/src/animation-layers.ts +260 -0
  32. package/src/animation-root-motion.ts +283 -0
  33. package/src/animation.ts +896 -0
  34. package/src/assets.ts +1303 -0
  35. package/src/atmosphere/index.ts +335 -0
  36. package/src/atmosphere/luts.ts +298 -0
  37. package/src/atmosphere/params.ts +323 -0
  38. package/src/audio.ts +912 -0
  39. package/src/billboard.ts +124 -0
  40. package/src/bone-lengths.ts +157 -0
  41. package/src/camera-shake.ts +116 -0
  42. package/src/canvas-layer.ts +47 -0
  43. package/src/clip-audit.ts +401 -0
  44. package/src/clustered-batch.ts +492 -0
  45. package/src/clustered-mesh.ts +638 -0
  46. package/src/compute-driven.ts +176 -0
  47. package/src/compute-timing.ts +318 -0
  48. package/src/config.ts +593 -0
  49. package/src/debug.ts +82 -0
  50. package/src/engine-render-hook.ts +25 -0
  51. package/src/entities.ts +79 -0
  52. package/src/entity-snapshot.ts +53 -0
  53. package/src/flight.ts +683 -0
  54. package/src/fluid-field.ts +748 -0
  55. package/src/fluid-particles.ts +1253 -0
  56. package/src/frame-budget.ts +1368 -0
  57. package/src/game.ts +2408 -0
  58. package/src/geometry-capture.ts +1098 -0
  59. package/src/gpu-class.ts +160 -0
  60. package/src/gpu-frame-observation.ts +424 -0
  61. package/src/gpu-readback.ts +143 -0
  62. package/src/gpu-scene-bvh.ts +464 -0
  63. package/src/grounding.ts +100 -0
  64. package/src/hot.ts +161 -0
  65. package/src/import-meta.d.ts +13 -0
  66. package/src/index.ts +1536 -0
  67. package/src/input.ts +690 -0
  68. package/src/instanced-batch-lod.ts +283 -0
  69. package/src/instanced-batch.ts +274 -0
  70. package/src/interpolation.ts +129 -0
  71. package/src/launch-diagnostics.ts +161 -0
  72. package/src/loop.ts +574 -0
  73. package/src/matrix-world.ts +245 -0
  74. package/src/merge-parts.ts +812 -0
  75. package/src/model-lod.ts +1315 -0
  76. package/src/net-protocol.ts +333 -0
  77. package/src/net-session.ts +477 -0
  78. package/src/net.ts +80 -0
  79. package/src/ocean/fft.ts +72 -0
  80. package/src/ocean/spectral.ts +728 -0
  81. package/src/particle-significance.ts +102 -0
  82. package/src/particles.ts +648 -0
  83. package/src/path-follow.ts +175 -0
  84. package/src/picking.ts +250 -0
  85. package/src/pipeline-census.ts +1566 -0
  86. package/src/platform.ts +210 -0
  87. package/src/playtest.ts +850 -0
  88. package/src/pointer-events.ts +411 -0
  89. package/src/pose-measure.ts +435 -0
  90. package/src/profiling/FrameCounters.ts +231 -0
  91. package/src/profiling/Spans.ts +548 -0
  92. package/src/profiling/opacity-convention.ts +21 -0
  93. package/src/profiling/render-list-validate.ts +175 -0
  94. package/src/profiling/render-trap-audit.ts +84 -0
  95. package/src/profiling/scene-warning.ts +190 -0
  96. package/src/profiling/span-probes.ts +191 -0
  97. package/src/profiling/unlit-foliage-warning.ts +149 -0
  98. package/src/projection-apply.ts +1529 -0
  99. package/src/projection-marker.ts +142 -0
  100. package/src/projection-plan.ts +1258 -0
  101. package/src/projection-skinned.ts +419 -0
  102. package/src/projection-stability.ts +409 -0
  103. package/src/projection-uniform.ts +328 -0
  104. package/src/random.ts +41 -0
  105. package/src/react-css.ts +604 -0
  106. package/src/react-glyphs.ts +114 -0
  107. package/src/react-host.ts +576 -0
  108. package/src/react-layout.ts +265 -0
  109. package/src/react.ts +60 -0
  110. package/src/render/alpha-antialiasing.ts +159 -0
  111. package/src/render/batched-velocity.ts +126 -0
  112. package/src/render/chain.ts +1021 -0
  113. package/src/render/daylight.ts +189 -0
  114. package/src/render/depth-pyramid.ts +596 -0
  115. package/src/render/foliage-alpha.ts +166 -0
  116. package/src/render/material-key.ts +60 -0
  117. package/src/render/mesh-pool.ts +144 -0
  118. package/src/render/probe-volume.ts +1668 -0
  119. package/src/render/resolution-subrect.ts +253 -0
  120. package/src/render/velocity.ts +442 -0
  121. package/src/render/virtual-shadow-pages.ts +827 -0
  122. package/src/render/virtual-shadow-partial.ts +174 -0
  123. package/src/render/virtual-shadow.ts +3330 -0
  124. package/src/render/world-impostor-surface.ts +722 -0
  125. package/src/render/world-impostor.ts +558 -0
  126. package/src/render-camera-cull.ts +441 -0
  127. package/src/render-pass-budget.ts +501 -0
  128. package/src/renderProjection.ts +758 -0
  129. package/src/renderer-config.ts +127 -0
  130. package/src/renderer.ts +1847 -0
  131. package/src/replay-protocol.ts +85 -0
  132. package/src/replay.ts +205 -0
  133. package/src/resolution-scaler.ts +819 -0
  134. package/src/rig-preparation.ts +271 -0
  135. package/src/ripple-field.ts +432 -0
  136. package/src/scale.ts +109 -0
  137. package/src/scene.ts +239 -0
  138. package/src/schedule.ts +155 -0
  139. package/src/skeletal-mesh.ts +61 -0
  140. package/src/skeleton.ts +100 -0
  141. package/src/snow-field.ts +744 -0
  142. package/src/softbody-topology.ts +269 -0
  143. package/src/softbody.ts +516 -0
  144. package/src/sprite-animator.ts +222 -0
  145. package/src/startup-readiness.ts +386 -0
  146. package/src/state.ts +66 -0
  147. package/src/static-transform.ts +274 -0
  148. package/src/storage-buffer.ts +253 -0
  149. package/src/streaming.ts +308 -0
  150. package/src/target-fps.ts +92 -0
  151. package/src/terrain-jobs-worker.ts +17 -0
  152. package/src/terrain-jobs.ts +353 -0
  153. package/src/textures.ts +39 -0
  154. package/src/tracers.ts +237 -0
  155. package/src/ui-bridge.ts +368 -0
  156. package/src/ui-hit-regions.ts +380 -0
  157. package/src/ui-layer.ts +83 -0
  158. package/src/ui-state.ts +220 -0
  159. package/src/version.ts +2 -0
  160. package/src/viewport.ts +253 -0
  161. package/src/warmup.ts +1357 -0
  162. package/src/water-surface.ts +384 -0
  163. package/src/wave-field.ts +524 -0
  164. package/src/world-capabilities.ts +131 -0
  165. package/src/world-cell-proxy.ts +392 -0
  166. package/src/world-cells.ts +10564 -0
  167. package/src/world-gpu-scene.ts +3354 -0
  168. package/src/world-heightmap.ts +82 -0
  169. package/src/world-package.ts +469 -0
  170. package/src/world-passes.ts +582 -0
  171. package/src/world-region.ts +17 -0
  172. package/src/world-terrain-splat.ts +564 -0
  173. package/src/world-tiles.ts +3826 -0
  174. package/src/world-topology.ts +370 -0
  175. package/src/world-validate.ts +48 -0
  176. package/src/world.ts +805 -0
@@ -0,0 +1,253 @@
1
+ import {
2
+ type Camera,
3
+ OrthographicCamera,
4
+ PerspectiveCamera,
5
+ Plane,
6
+ Raycaster,
7
+ Vector2,
8
+ Vector3,
9
+ } from "three";
10
+ import { type IRendererLike, observeCanvasResize, readCanvasSize } from "./renderer.js";
11
+
12
+ export interface IViewportSize {
13
+ readonly aspect: number;
14
+ readonly height: number;
15
+ readonly width: number;
16
+ }
17
+
18
+ export interface IViewportInsets {
19
+ readonly bottom: number;
20
+ readonly left: number;
21
+ readonly right: number;
22
+ readonly top: number;
23
+ }
24
+
25
+ export interface IViewportSafeArea extends IViewportInsets {
26
+ /** The safe rectangle in drawable pixel coordinates, with y measured from the top edge. */
27
+ readonly height: number;
28
+ readonly source: "full-drawable-fallback" | "measured";
29
+ readonly width: number;
30
+ readonly x: number;
31
+ readonly y: number;
32
+ }
33
+
34
+ export interface IViewportOptions {
35
+ readonly camera: Camera;
36
+ readonly renderer: IRendererLike;
37
+ readonly source?: IViewportPlatformSource;
38
+ }
39
+
40
+ export type ViewportResizeHandler = (size: IViewportSize) => void;
41
+
42
+ export interface IViewportPlatformSource {
43
+ observeResize(canvas: HTMLCanvasElement, resize: () => void): () => void;
44
+ readSize(canvas: HTMLCanvasElement): IViewportSize;
45
+ readSafeArea?(canvas: HTMLCanvasElement, size: IViewportSize): IViewportInsets | undefined;
46
+ }
47
+
48
+ export class Viewport {
49
+ readonly camera: Camera;
50
+ readonly renderer: IRendererLike;
51
+ #source: IViewportPlatformSource | undefined;
52
+ #listeners = new Set<ViewportResizeHandler>();
53
+ #size: IViewportSize = { aspect: 1, height: 1, width: 1 };
54
+ #safeArea: IViewportSafeArea = fullDrawableSafeArea(this.#size);
55
+ #stopObserving: () => void = () => undefined;
56
+ #disposed = false;
57
+ #raycaster = new Raycaster();
58
+ #ndc = new Vector2();
59
+ #plane = new Plane(new Vector3(0, 0, 1));
60
+ #projected = new Vector3();
61
+ #unprojected = new Vector3();
62
+
63
+ constructor(options: IViewportOptions) {
64
+ this.camera = options.camera;
65
+ this.renderer = options.renderer;
66
+ this.#source = options.source;
67
+ this.#stopObserving =
68
+ this.#source?.observeResize(this.renderer.domElement, this.#resize) ??
69
+ observeCanvasResize(this.renderer.domElement, this.#resize);
70
+ this.resize();
71
+ }
72
+
73
+ get size(): IViewportSize {
74
+ return this.#size;
75
+ }
76
+
77
+ get safeArea(): IViewportSafeArea {
78
+ return this.#safeArea;
79
+ }
80
+
81
+ projectPosition(screen: Vector2, z = 0, target?: Vector3): Vector3 {
82
+ if (!Number.isFinite(z)) throw new Error("Viewport.projectPosition z must be finite.");
83
+ this.#ndc.set((screen.x / this.#size.width) * 2 - 1, -((screen.y / this.#size.height) * 2 - 1));
84
+ this.#raycaster.setFromCamera(this.#ndc, this.camera);
85
+ this.#plane.constant = -z;
86
+ const point = this.#raycaster.ray.intersectPlane(this.#plane, this.#projected);
87
+ if (point === null)
88
+ throw new Error("Viewport.projectPosition cannot reach the requested z plane.");
89
+ return target?.copy(point) ?? point.clone();
90
+ }
91
+
92
+ unprojectPosition(world: Vector3, target?: Vector2): Vector2 {
93
+ this.#unprojected.copy(world).project(this.camera);
94
+ const result = target ?? new Vector2();
95
+ return result.set(
96
+ ((this.#unprojected.x + 1) / 2) * this.#size.width,
97
+ ((1 - this.#unprojected.y) / 2) * this.#size.height,
98
+ );
99
+ }
100
+
101
+ onResize(handler: ViewportResizeHandler): () => void {
102
+ if (this.#disposed) return () => undefined;
103
+ this.#listeners.add(handler);
104
+ return () => this.#listeners.delete(handler);
105
+ }
106
+
107
+ resize(): void {
108
+ if (this.#disposed) return;
109
+ let next = this.#source?.readSize(this.renderer.domElement);
110
+ if (next === undefined) {
111
+ const [width, height] = readCanvasSize(this.renderer.domElement);
112
+ next = { aspect: width / height, height, width };
113
+ }
114
+ const safeArea = readSafeArea(this.#source, this.renderer.domElement, next);
115
+ const changed =
116
+ next.width !== this.#size.width ||
117
+ next.height !== this.#size.height ||
118
+ next.aspect !== this.#size.aspect;
119
+ const safeAreaChanged = !sameSafeArea(safeArea, this.#safeArea);
120
+ this.#size = next;
121
+ this.#safeArea = safeArea;
122
+ if (this.camera instanceof PerspectiveCamera) {
123
+ this.camera.aspect = next.aspect;
124
+ this.camera.updateProjectionMatrix();
125
+ } else if (this.camera instanceof OrthographicCamera) {
126
+ const size = (this.camera.top - this.camera.bottom) / 2;
127
+ this.camera.left = -size * next.aspect;
128
+ this.camera.right = size * next.aspect;
129
+ this.camera.top = size;
130
+ this.camera.bottom = -size;
131
+ this.camera.updateProjectionMatrix();
132
+ }
133
+ if (changed || safeAreaChanged) for (const listener of this.#listeners) listener(next);
134
+ }
135
+
136
+ dispose(): void {
137
+ if (this.#disposed) return;
138
+ this.#disposed = true;
139
+ this.#stopObserving();
140
+ this.#stopObserving = () => undefined;
141
+ this.#listeners.clear();
142
+ }
143
+
144
+ #resize = (): void => this.resize();
145
+ }
146
+
147
+ function fullDrawableSafeArea(size: IViewportSize): IViewportSafeArea {
148
+ return {
149
+ bottom: 0,
150
+ height: size.height,
151
+ left: 0,
152
+ right: 0,
153
+ source: "full-drawable-fallback",
154
+ top: 0,
155
+ width: size.width,
156
+ x: 0,
157
+ y: 0,
158
+ };
159
+ }
160
+
161
+ function clampInset(value: number, maximum: number): number {
162
+ return Number.isFinite(value) ? Math.max(0, Math.min(maximum, value)) : 0;
163
+ }
164
+
165
+ function safeAreaFromInsets(size: IViewportSize, raw: IViewportInsets): IViewportSafeArea {
166
+ const top = clampInset(raw.top, size.height);
167
+ const bottom = clampInset(raw.bottom, size.height - top);
168
+ const left = clampInset(raw.left, size.width);
169
+ const right = clampInset(raw.right, size.width - left);
170
+ return {
171
+ bottom,
172
+ height: Math.max(0, size.height - top - bottom),
173
+ left,
174
+ right,
175
+ source: "measured",
176
+ top,
177
+ width: Math.max(0, size.width - left - right),
178
+ x: left,
179
+ y: top,
180
+ };
181
+ }
182
+
183
+ function nativeInsets(): IViewportInsets | undefined {
184
+ // biome-ignore lint/style/useNamingConvention: this is the native host's public global contract.
185
+ const host = (globalThis as { __THREENATIVE_NATIVE__?: unknown }).__THREENATIVE_NATIVE__;
186
+ if (typeof host !== "object" || host === null) return undefined;
187
+ const value = (host as { safeAreaInsets?: unknown }).safeAreaInsets;
188
+ if (typeof value !== "object" || value === null) return undefined;
189
+ const insets = value as Partial<IViewportInsets>;
190
+ if (
191
+ typeof insets.top !== "number" ||
192
+ typeof insets.right !== "number" ||
193
+ typeof insets.bottom !== "number" ||
194
+ typeof insets.left !== "number"
195
+ )
196
+ return undefined;
197
+ return insets as IViewportInsets;
198
+ }
199
+
200
+ function browserInsets(): IViewportInsets | undefined {
201
+ if (typeof document === "undefined" || typeof window === "undefined") return undefined;
202
+ if (typeof window.getComputedStyle !== "function") return undefined;
203
+ const probe = document.createElement("div");
204
+ probe.style.cssText = [
205
+ "position:fixed",
206
+ "inset:0",
207
+ "padding-top:env(safe-area-inset-top)",
208
+ "padding-right:env(safe-area-inset-right)",
209
+ "padding-bottom:env(safe-area-inset-bottom)",
210
+ "padding-left:env(safe-area-inset-left)",
211
+ "visibility:hidden",
212
+ "pointer-events:none",
213
+ ].join(";");
214
+ // Nothing is measured until the probe is in the document. A detached element resolves every
215
+ // computed padding to the empty string, which parses to zero — four zeroes indistinguishable
216
+ // from a device that genuinely has no insets, reported as `measured`. The full-drawable
217
+ // fallback is the honest answer when there was no measurement to take.
218
+ const body = document.body;
219
+ if (body === null || body === undefined) return undefined;
220
+ body.appendChild(probe);
221
+ const style = window.getComputedStyle(probe);
222
+ const value = {
223
+ bottom: Number.parseFloat(style.paddingBottom) || 0,
224
+ left: Number.parseFloat(style.paddingLeft) || 0,
225
+ right: Number.parseFloat(style.paddingRight) || 0,
226
+ top: Number.parseFloat(style.paddingTop) || 0,
227
+ };
228
+ probe.remove();
229
+ return value;
230
+ }
231
+
232
+ function readSafeArea(
233
+ source: IViewportPlatformSource | undefined,
234
+ canvas: HTMLCanvasElement,
235
+ size: IViewportSize,
236
+ ): IViewportSafeArea {
237
+ const measured = source?.readSafeArea?.(canvas, size) ?? nativeInsets() ?? browserInsets();
238
+ return measured === undefined ? fullDrawableSafeArea(size) : safeAreaFromInsets(size, measured);
239
+ }
240
+
241
+ function sameSafeArea(left: IViewportSafeArea, right: IViewportSafeArea): boolean {
242
+ return (
243
+ left.bottom === right.bottom &&
244
+ left.height === right.height &&
245
+ left.left === right.left &&
246
+ left.right === right.right &&
247
+ left.source === right.source &&
248
+ left.top === right.top &&
249
+ left.width === right.width &&
250
+ left.x === right.x &&
251
+ left.y === right.y
252
+ );
253
+ }