@needle-tools/engine 5.1.0-canary.c111c4f → 5.1.0-canary.d110b1f

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 (88) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/components.needle.json +1 -1
  3. package/dist/{needle-engine.bundle-BuaGvme0.js → needle-engine.bundle-CIeJZJtr.js} +7485 -7511
  4. package/dist/{needle-engine.bundle-CayCdkzK.min.js → needle-engine.bundle-DGxfYUoJ.min.js} +145 -144
  5. package/dist/{needle-engine.bundle-DVhVGqQR.umd.cjs → needle-engine.bundle-FP5jA2Rk.umd.cjs} +144 -143
  6. package/dist/needle-engine.d.ts +58 -83
  7. package/dist/needle-engine.js +188 -186
  8. package/dist/needle-engine.min.js +1 -1
  9. package/dist/needle-engine.umd.cjs +1 -1
  10. package/dist/three-examples.js +3778 -4289
  11. package/dist/three-examples.min.js +14 -301
  12. package/dist/three-examples.umd.cjs +14 -301
  13. package/lib/engine/debug/debug_spatial_console.d.ts +2 -0
  14. package/lib/engine/debug/debug_spatial_console.js +10 -7
  15. package/lib/engine/debug/debug_spatial_console.js.map +1 -1
  16. package/lib/engine/engine_addressables.d.ts +2 -0
  17. package/lib/engine/engine_addressables.js +6 -3
  18. package/lib/engine/engine_addressables.js.map +1 -1
  19. package/lib/engine/engine_context.d.ts +16 -19
  20. package/lib/engine/engine_context.js +12 -15
  21. package/lib/engine/engine_context.js.map +1 -1
  22. package/lib/engine/engine_gameobject.js +2 -2
  23. package/lib/engine/engine_gameobject.js.map +1 -1
  24. package/lib/engine/engine_init.js +10 -0
  25. package/lib/engine/engine_init.js.map +1 -1
  26. package/lib/engine/engine_scenedata.d.ts +5 -7
  27. package/lib/engine/engine_scenedata.js +14 -11
  28. package/lib/engine/engine_scenedata.js.map +1 -1
  29. package/lib/engine/engine_serialization_builtin_serializer.d.ts +10 -16
  30. package/lib/engine/engine_serialization_builtin_serializer.js +28 -41
  31. package/lib/engine/engine_serialization_builtin_serializer.js.map +1 -1
  32. package/lib/engine/webcomponents/jsx.d.ts +51 -0
  33. package/lib/engine/webcomponents/logo-element.js.map +1 -1
  34. package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +2 -3
  35. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  36. package/lib/engine/webcomponents/needle-button.js.map +1 -1
  37. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  38. package/lib/engine/xr/NeedleXRSession.d.ts +2 -0
  39. package/lib/engine/xr/NeedleXRSession.js +47 -11
  40. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  41. package/lib/engine-components/AnimatorController.d.ts +2 -0
  42. package/lib/engine-components/AnimatorController.js +4 -1
  43. package/lib/engine-components/AnimatorController.js.map +1 -1
  44. package/lib/engine-components/Light.d.ts +0 -19
  45. package/lib/engine-components/Light.js +4 -96
  46. package/lib/engine-components/Light.js.map +1 -1
  47. package/lib/engine-components/Networking.d.ts +1 -1
  48. package/lib/engine-components/Networking.js +1 -1
  49. package/lib/engine-components/ReflectionProbe.js +2 -0
  50. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  51. package/lib/engine-components/postprocessing/VolumeParameter.d.ts +2 -0
  52. package/lib/engine-components/postprocessing/VolumeParameter.js +4 -1
  53. package/lib/engine-components/postprocessing/VolumeParameter.js.map +1 -1
  54. package/lib/engine-components/ui/Canvas.d.ts +1 -1
  55. package/lib/engine-components/ui/Canvas.js +2 -8
  56. package/lib/engine-components/ui/Canvas.js.map +1 -1
  57. package/lib/needle-engine.d.ts +2 -0
  58. package/lib/needle-engine.js +1 -0
  59. package/lib/needle-engine.js.map +1 -1
  60. package/package.json +1 -1
  61. package/plugins/dts-generator/dts.codegen.js +12 -6
  62. package/plugins/dts-generator/dts.writer.js +1 -1
  63. package/plugins/dts-generator/glb.extractor.js +12 -1
  64. package/plugins/dts-generator/glb.reader.js +42 -33
  65. package/plugins/types/userconfig.d.ts +12 -0
  66. package/plugins/vite/dts-generator.d.ts +2 -2
  67. package/plugins/vite/dts-generator.js +6 -1
  68. package/plugins/vite/reload.js +18 -17
  69. package/src/engine/debug/debug_spatial_console.ts +10 -7
  70. package/src/engine/engine_addressables.ts +6 -3
  71. package/src/engine/engine_context.ts +18 -20
  72. package/src/engine/engine_gameobject.ts +2 -2
  73. package/src/engine/engine_init.ts +10 -0
  74. package/src/engine/engine_scenedata.ts +13 -10
  75. package/src/engine/engine_serialization_builtin_serializer.ts +32 -43
  76. package/src/engine/webcomponents/jsx.d.ts +51 -0
  77. package/src/engine/webcomponents/logo-element.ts +1 -0
  78. package/src/engine/webcomponents/needle menu/needle-menu.ts +2 -1
  79. package/src/engine/webcomponents/needle-button.ts +1 -0
  80. package/src/engine/webcomponents/needle-engine.ts +1 -0
  81. package/src/engine/xr/NeedleXRSession.ts +44 -10
  82. package/src/engine-components/AnimatorController.ts +4 -1
  83. package/src/engine-components/Light.ts +4 -95
  84. package/src/engine-components/Networking.ts +1 -1
  85. package/src/engine-components/ReflectionProbe.ts +2 -0
  86. package/src/engine-components/postprocessing/VolumeParameter.ts +4 -1
  87. package/src/engine-components/ui/Canvas.ts +2 -8
  88. package/src/needle-engine.ts +1 -0
@@ -11,24 +11,6 @@ import { IComponent } from "./engine_types.js";
11
11
  import { resolveUrl } from "./engine_utils.js";
12
12
  import { RGBAColor } from "./js-extensions/index.js";
13
13
 
14
- // export class SourcePath {
15
- // src?:string
16
- // };
17
-
18
- // class SourcePathSerializer extends TypeSerializer{
19
- // constructor(){
20
- // super(SourcePath);
21
- // }
22
- // onDeserialize(data: any, _context: SerializationContext) {
23
- // if(data.src && typeof data.src === "string"){
24
- // return data.src;
25
- // }
26
- // }
27
- // onSerialize(_data: any, _context: SerializationContext) {
28
-
29
- // }
30
- // }
31
- // new SourcePathSerializer();
32
14
 
33
15
  class ColorSerializer extends TypeSerializer {
34
16
  constructor() {
@@ -52,7 +34,6 @@ class ColorSerializer extends TypeSerializer {
52
34
  return { r: data.r, g: data.g, b: data.b }
53
35
  }
54
36
  }
55
- export const colorSerializer = new ColorSerializer();
56
37
 
57
38
  class EulerSerializer extends TypeSerializer {
58
39
  constructor() {
@@ -72,7 +53,6 @@ class EulerSerializer extends TypeSerializer {
72
53
  return { x: data.x, y: data.y, z: data.z, order: data.order };
73
54
  }
74
55
  }
75
- export const euler = new EulerSerializer();
76
56
 
77
57
  declare type ObjectData = {
78
58
  node?: number;
@@ -107,16 +87,6 @@ class ObjectSerializer extends TypeSerializer {
107
87
  console.warn(`Wrong usage of @serializable detected in your script \"${scriptname}\"\n\nIt looks like you used @serializable(Object3D) or @serializable(GameObject) for a prefab or scene reference which is exported to a separate glTF file.\n\nTo fix this please change your code to:\n\n@serializable(AssetReference)\n${context.path}! : AssetReference;\n\0`);
108
88
  }
109
89
  // ACTUALLY: this is already handled by the extension_utils where we resolve json pointers recursively
110
- // if(data.startsWith("/nodes/")){
111
- // const node = parseInt(data.substring("/nodes/".length));
112
- // if (context.nodeToObject) {
113
- // const res = context.nodeToObject[node];
114
- // if (debugExtension)
115
- // console.log("Deserialized object reference?", data, res, context?.nodeToObject);
116
- // if (!res) console.warn("Did not find node: " + data, context.nodeToObject, context.object);
117
- // return res;
118
- // }
119
- // }
120
90
  return undefined;
121
91
  }
122
92
 
@@ -166,7 +136,6 @@ class ObjectSerializer extends TypeSerializer {
166
136
  return undefined;
167
137
  }
168
138
  }
169
- export const objectSerializer = new ObjectSerializer();
170
139
 
171
140
 
172
141
  class ComponentSerializer extends TypeSerializer {
@@ -241,7 +210,6 @@ class ComponentSerializer extends TypeSerializer {
241
210
  }
242
211
  }
243
212
  }
244
- export const componentSerializer = new ComponentSerializer();
245
213
 
246
214
 
247
215
  declare class EventListData {
@@ -396,21 +364,12 @@ class EventListSerializer extends TypeSerializer {
396
364
  // };
397
365
  // }
398
366
  }
399
- export const eventListSerializer = new EventListSerializer();
400
367
 
401
368
 
402
369
  /** Map<Clone, Original> texture. This is used for compressed textures (or when the GLTFLoader is cloning RenderTextures)
403
370
  * It's a weak map so we don't have to worry about memory leaks
404
371
  */
405
372
  const cloneOriginalMap = new WeakMap<Texture, Texture>();
406
- const textureClone = Texture.prototype.clone;
407
- Texture.prototype.clone = function () {
408
- const clone = textureClone.call(this);
409
- if (!cloneOriginalMap.has(clone)) {
410
- cloneOriginalMap.set(clone, this);
411
- }
412
- return clone;
413
- }
414
373
 
415
374
  export class RenderTextureSerializer extends TypeSerializer {
416
375
  constructor() {
@@ -452,7 +411,6 @@ export class RenderTextureSerializer extends TypeSerializer {
452
411
  return undefined;
453
412
  }
454
413
  }
455
- new RenderTextureSerializer();
456
414
 
457
415
 
458
416
  export class UriSerializer extends TypeSerializer {
@@ -471,4 +429,35 @@ export class UriSerializer extends TypeSerializer {
471
429
  return undefined;
472
430
  }
473
431
  }
474
- new UriSerializer();
432
+
433
+
434
+ // Module-level references used by EventListSerializer internally
435
+ export let colorSerializer: ColorSerializer;
436
+ export let objectSerializer: ObjectSerializer;
437
+ export let componentSerializer: ComponentSerializer;
438
+ export let eventListSerializer: EventListSerializer;
439
+
440
+ /** Register all builtin serializers and prototype patches.
441
+ * Must be called from {@link initEngine} so the registrations survive tree-shaking
442
+ * when the package declares `sideEffects: false`.
443
+ */
444
+ export function initBuiltinSerializers() {
445
+ // Prototype patches
446
+ const textureClone = Texture.prototype.clone;
447
+ Texture.prototype.clone = function () {
448
+ const clone = textureClone.call(this);
449
+ if (!cloneOriginalMap.has(clone)) {
450
+ cloneOriginalMap.set(clone, this);
451
+ }
452
+ return clone;
453
+ }
454
+
455
+ // Register all serializers
456
+ colorSerializer = new ColorSerializer();
457
+ new EulerSerializer();
458
+ objectSerializer = new ObjectSerializer();
459
+ componentSerializer = new ComponentSerializer();
460
+ eventListSerializer = new EventListSerializer();
461
+ new RenderTextureSerializer();
462
+ new UriSerializer();
463
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * JSX IntrinsicElements declarations for Needle Engine web components.
3
+ *
4
+ * Covers both the global JSX namespace (Preact, SolidJS, Svelte, vanilla TS)
5
+ * and React's module-scoped JSX namespace (react-jsx / react-jsxdev transform).
6
+ *
7
+ * IMPORTANT: This file must be a module (has a top-level import/export) so that
8
+ * `declare module "react"` is treated as a *module augmentation* (merging into
9
+ * the existing React types) rather than an *ambient module declaration* (which
10
+ * would shadow/replace @types/react).
11
+ */
12
+
13
+ import type { NeedleEngineAttributes } from "./needle-engine.js";
14
+
15
+ interface NeedleButtonJSXAttributes extends Partial<Omit<HTMLElement, "style" | "children">> {
16
+ style?: Partial<CSSStyleDeclaration>;
17
+ ar?: boolean | string;
18
+ vr?: boolean | string;
19
+ quicklook?: boolean | string;
20
+ qrcode?: boolean | string;
21
+ unstyled?: boolean | string;
22
+ }
23
+
24
+ interface NeedleMenuJSXAttributes extends Partial<Omit<HTMLElement, "style" | "children">> {
25
+ style?: Partial<CSSStyleDeclaration>;
26
+ }
27
+
28
+ interface NeedleLogoElementJSXAttributes extends Partial<Omit<HTMLElement, "style" | "children">> {
29
+ style?: Partial<CSSStyleDeclaration>;
30
+ }
31
+
32
+ interface NeedleElements {
33
+ "needle-engine": Partial<NeedleEngineAttributes>;
34
+ "needle-button": NeedleButtonJSXAttributes;
35
+ "needle-menu": NeedleMenuJSXAttributes;
36
+ "needle-logo-element": NeedleLogoElementJSXAttributes;
37
+ }
38
+
39
+ // Global JSX namespace — Preact, SolidJS, Svelte, vanilla TS
40
+ declare global {
41
+ namespace JSX {
42
+ interface IntrinsicElements extends NeedleElements {}
43
+ }
44
+ }
45
+
46
+ // React module-scoped JSX namespace (module augmentation, not ambient declaration)
47
+ declare module "react" {
48
+ namespace JSX {
49
+ interface IntrinsicElements extends NeedleElements {}
50
+ }
51
+ }
@@ -3,6 +3,7 @@ import { HTMLElementBase } from "../engine_ssr.js";
3
3
 
4
4
  const elementName = "needle-logo-element";
5
5
 
6
+ // NOTE: keep JSX attributes in sync with ./jsx.d.ts
6
7
  declare global {
7
8
  interface HTMLElementTagNameMap {
8
9
  "needle-logo-element": NeedleLogoElement;
@@ -12,9 +12,10 @@ import { NeedleLogoElement } from "../logo-element.js";
12
12
  import { getElementPriority, setElementPriority as _setElementPriority } from "./menu-priority.js";
13
13
  import { NeedleSpatialMenu } from "./needle-menu-spatial.js";
14
14
 
15
+ // NOTE: keep JSX attributes in sync with ../jsx.d.ts
15
16
  declare global {
16
17
  interface HTMLElementTagNameMap {
17
- "needle-logo-element": NeedleLogoElement;
18
+ "needle-menu": NeedleMenuElement;
18
19
  }
19
20
  }
20
21
 
@@ -4,6 +4,7 @@ import { ButtonsFactory } from "./buttons.js";
4
4
  import { iconFontUrl, loadFont } from "./fonts.js";
5
5
  import { WebXRButtonFactory } from "./WebXRButtons.js";
6
6
 
7
+ // NOTE: keep JSX attributes in sync with ./jsx.d.ts
7
8
  declare global {
8
9
  interface HTMLElementTagNameMap {
9
10
  "needle-button": NeedleButtonElement;
@@ -17,6 +17,7 @@ import { arContainerClassName, AROverlayHandler } from "./needle-engine.ar-overl
17
17
  import type { registerObservableAttribute } from "./needle-engine.extras.js";
18
18
  import { calculateProgress01, EngineLoadingView, type ILoadingViewHandler } from "./needle-engine.loading.js";
19
19
 
20
+ // NOTE: keep JSX attributes in sync with ./jsx.d.ts
20
21
  declare global {
21
22
  interface HTMLElementTagNameMap {
22
23
  "needle-engine": NeedleEngineWebComponent;
@@ -1053,6 +1053,8 @@ export class NeedleXRSession implements INeedleXRSession {
1053
1053
  private readonly _xr_update_scripts: INeedleXRSessionEventReceiver[] = [];
1054
1054
  /** scripts that are in the scene but inactive (e.g. disabled parent gameObject) */
1055
1055
  private readonly _inactive_scripts: INeedleXRSessionEventReceiver[] = [];
1056
+ /** tracks scripts that have received onEnterXR — prevents spurious onLeaveXR calls */
1057
+ private readonly _scripts_in_xr = new Set<INeedleXRSessionEventReceiver>();
1056
1058
  private readonly _controllerAdded: ControllerChangedEvt[];
1057
1059
  private readonly _controllerRemoved: ControllerChangedEvt[];
1058
1060
  private readonly _originalCameraWorldPosition?: Vector3 | null;
@@ -1163,7 +1165,18 @@ export class NeedleXRSession implements INeedleXRSession {
1163
1165
  // we set the session on the webxr manager at the end because we want to receive inputsource events first
1164
1166
  // e.g. in case there's a bug in the threejs codebase
1165
1167
  this.context.xr = this;
1166
- this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet);
1168
+ this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet)
1169
+ .catch(err => {
1170
+ // Workaround for WebXR emulators on localhost: the polyfilled XRSession fails the
1171
+ // native XRWebGLBinding constructor's instanceof check. Retry with layers disabled.
1172
+ // See https://github.com/meta-quest/immersive-web-emulator/issues/80
1173
+ if (isDevEnvironment() && err instanceof TypeError && typeof XRWebGLBinding !== "undefined") {
1174
+ console.error(`XRWebGLBinding failed (${err.message}).\nSee https://github.com/meta-quest/immersive-web-emulator/issues/80`);
1175
+ }
1176
+ else {
1177
+ console.error("renderer.xr.setSession failed:", err);
1178
+ }
1179
+ });
1167
1180
  // disable three.js renderer controller autoUpdate (added in ac67b31e3548386f8a93e23a4176554c92bbd0d9)
1168
1181
  if ("controllerAutoUpdate" in this.context.renderer.xr) {
1169
1182
  console.debug("Disabling three.js controllerAutoUpdate");
@@ -1331,8 +1344,10 @@ export class NeedleXRSession implements INeedleXRSession {
1331
1344
  // even if they might already be destroyed e.g. by the WebXR component (it destroys the default controller scripts)
1332
1345
  // they should still receive this callback to be properly cleaned up
1333
1346
  for (const listener of this._xr_scripts) {
1347
+ this._scripts_in_xr.delete(listener);
1334
1348
  listener?.onLeaveXR?.({ xr: this });
1335
1349
  }
1350
+ this._scripts_in_xr.clear();
1336
1351
 
1337
1352
  this.sync?.onExitXR(this);
1338
1353
 
@@ -1399,10 +1414,17 @@ export class NeedleXRSession implements INeedleXRSession {
1399
1414
  }
1400
1415
 
1401
1416
  // make sure the camera is parented to the active rig
1402
- if (this.rig && this._mainCamera?.gameObject) {
1403
- const currentParent = this._mainCamera?.gameObject?.parent;
1404
- if (currentParent !== this.rig.gameObject) {
1405
- this.rig.gameObject.add(this._mainCamera?.gameObject);
1417
+ // Note: applyCustomForward() inserts _cameraRenderParent between rig and camera,
1418
+ // so the hierarchy is: rig → _cameraRenderParent → camera. We check the effective parent.
1419
+ if (this.rig) {
1420
+ const cameraObject = this._mainCamera?.gameObject ?? this.context.mainCamera;
1421
+ if (cameraObject) {
1422
+ const effectiveParent = cameraObject.parent === this._cameraRenderParent
1423
+ ? this._cameraRenderParent.parent
1424
+ : cameraObject.parent;
1425
+ if (effectiveParent !== this.rig.gameObject) {
1426
+ this.rig.gameObject.add(cameraObject);
1427
+ }
1406
1428
  }
1407
1429
  }
1408
1430
 
@@ -1534,8 +1556,12 @@ export class NeedleXRSession implements INeedleXRSession {
1534
1556
  }
1535
1557
 
1536
1558
  //performance.mark('NeedleXRSession update scripts start');
1537
- // invoke update on all scripts
1538
- for (const script of this._xr_update_scripts) {
1559
+ // check all XR scripts for destroyed or inactive state
1560
+ // this must cover _xr_scripts (not just _xr_update_scripts) so that scripts
1561
+ // without onUpdateXR are also detected as inactive when removed from the scene
1562
+ // iterate backwards since markInactive/removeScript modifies the array
1563
+ for (let i = this._xr_scripts.length - 1; i >= 0; i--) {
1564
+ const script = this._xr_scripts[i];
1539
1565
  if (script.destroyed === true) {
1540
1566
  this._script_to_remove.push(script);
1541
1567
  continue;
@@ -1544,6 +1570,10 @@ export class NeedleXRSession implements INeedleXRSession {
1544
1570
  this.markInactive(script);
1545
1571
  continue;
1546
1572
  }
1573
+ }
1574
+ // invoke update on scripts that have onUpdateXR
1575
+ for (const script of this._xr_update_scripts) {
1576
+ if (script.destroyed || script.activeAndEnabled === false) continue;
1547
1577
  if (script.onUpdateXR) script.onUpdateXR(args);
1548
1578
  }
1549
1579
  //performance.mark('NeedleXRSession update scripts end');
@@ -1666,9 +1696,11 @@ export class NeedleXRSession implements INeedleXRSession {
1666
1696
  const script = this._inactive_scripts[i];
1667
1697
  if (script.activeAndEnabled) {
1668
1698
  this._inactive_scripts.splice(i, 1);
1669
- this.addScript(script);
1670
- this.invokeCallback_EnterXR(script);
1671
- for (const ctrl of this.controllers) this.invokeCallback_ControllerAdded(script, ctrl);
1699
+ // addScript returns false if already re-added (e.g. via new_scripts_xr processing)
1700
+ if (this.addScript(script)) {
1701
+ this.invokeCallback_EnterXR(script);
1702
+ for (const ctrl of this.controllers) this.invokeCallback_ControllerAdded(script, ctrl);
1703
+ }
1672
1704
  }
1673
1705
  }
1674
1706
  }
@@ -1689,6 +1721,7 @@ export class NeedleXRSession implements INeedleXRSession {
1689
1721
  }
1690
1722
 
1691
1723
  private invokeCallback_EnterXR(script: INeedleXRSessionEventReceiver) {
1724
+ this._scripts_in_xr.add(script);
1692
1725
  if (script.onEnterXR) {
1693
1726
  script.onEnterXR({ xr: this });
1694
1727
  }
@@ -1704,6 +1737,7 @@ export class NeedleXRSession implements INeedleXRSession {
1704
1737
  }
1705
1738
  }
1706
1739
  private invokeCallback_LeaveXR(script: INeedleXRSessionEventReceiver) {
1740
+ if (!this._scripts_in_xr.delete(script)) return;
1707
1741
  if (script.onLeaveXR && !script.destroyed) {
1708
1742
  script.onLeaveXR({ xr: this });
1709
1743
  }
@@ -1586,4 +1586,7 @@ class AnimatorControllerSerializator extends TypeSerializer {
1586
1586
  return undefined;
1587
1587
  }
1588
1588
  }
1589
- new AnimatorControllerSerializator(AnimatorController);
1589
+ /** @internal */
1590
+ export function initAnimatorControllerSerializer() {
1591
+ new AnimatorControllerSerializator(AnimatorController);
1592
+ }
@@ -1,9 +1,7 @@
1
1
  import { CameraHelper, Color, DirectionalLight, DirectionalLightHelper, Light as ThreeLight, OrthographicCamera, PointLight, SpotLight, Vector3 } from "three";
2
- import { CSM } from "three/examples/jsm/csm/CSM.js";
3
- import { CSMHelper } from "three/examples/jsm/csm/CSMHelper.js";
4
2
 
5
3
  import { serializable } from "../engine/engine_serialization_decorator.js";
6
-
4
+ import { FrameEvent } from "../engine/engine_setup.js";
7
5
  import { setWorldPositionXYZ } from "../engine/engine_three_utils.js";
8
6
  import type { ILight } from "../engine/engine_types.js";
9
7
  import { getParam } from "../engine/engine_utils.js";
@@ -205,9 +203,6 @@ export class Light extends Behaviour implements ILight {
205
203
  if (this.light !== undefined) {
206
204
  this.light.color = val;
207
205
  }
208
- if (this._csm) {
209
- for (const l of this._csm.lights) l.color.copy(val);
210
- }
211
206
  }
212
207
  get color(): Color {
213
208
  if (this.light) return this.light.color;
@@ -293,9 +288,6 @@ export class Light extends Behaviour implements ILight {
293
288
  if (this.light) {
294
289
  this.light.intensity = val;
295
290
  }
296
- if (this._csm) {
297
- for (const l of this._csm.lights) l.intensity = val;
298
- }
299
291
  if (debug) console.log("Set light intensity to " + this._intensity, val, this)
300
292
  }
301
293
  get intensity(): number { return this._intensity; }
@@ -349,24 +341,6 @@ export class Light extends Behaviour implements ILight {
349
341
  }
350
342
  private _shadowResolution?: number = undefined;
351
343
 
352
- /**
353
- * Number of shadow cascade levels (only used when `useCascades` is true)
354
- */
355
- @serializable()
356
- cascades: number = 3;
357
-
358
- /**
359
- * Cascade split mode (only used when `useCascades` is true):
360
- * - `practical` — balanced (default, recommended)
361
- * - `logarithmic` — more resolution close up
362
- * - `uniform` — equal splits
363
- */
364
- @serializable()
365
- cascadeMode: "practical" | "logarithmic" | "uniform" = "practical";
366
-
367
- private _csm?: CSM;
368
- private _csmHelper?: CSMHelper;
369
-
370
344
  /**
371
345
  * Whether this light's illumination is entirely baked into lightmaps
372
346
  */
@@ -427,21 +401,13 @@ export class Light extends Behaviour implements ILight {
427
401
  else if (this.light.parent !== this.gameObject)
428
402
  this.gameObject.add(this.light);
429
403
  }
430
- this.context.lights.add(this);
404
+ this.context.lights.push(this);
431
405
  }
432
406
 
433
407
  onDisable() {
434
408
  if (debug) console.log("DISABLE LIGHT", this.name);
435
- this.context.lights.delete(this);
436
- if (this._csm) {
437
- this._csm.remove();
438
- this._csm.dispose();
439
- this._csm = undefined;
440
- if (this._csmHelper) {
441
- this._csmHelper.removeFromParent();
442
- this._csmHelper = undefined;
443
- }
444
- }
409
+ const index = this.context.lights.indexOf(this);
410
+ if (index !== -1) this.context.lights.splice(index, 1);
445
411
  if (this.light) {
446
412
  if (this.selfIsLight)
447
413
  this.light.intensity = 0;
@@ -450,27 +416,6 @@ export class Light extends Behaviour implements ILight {
450
416
  }
451
417
  }
452
418
 
453
- onBeforeRender() {
454
- if (this.type === "directional" && this.shadows !== LightShadows.None) {
455
- // context.mainLight is computed — always returns the brightest registered directional light
456
- const isMain = this.context.mainLight === this;
457
- if (isMain) {
458
- if (!this._csm) this.createCSM();
459
- } else if (this._csm) {
460
- // this light is no longer the main light (a brighter one took over) — tear down CSM
461
- this._csm.remove();
462
- this._csm.dispose();
463
- this._csm = undefined;
464
- }
465
- }
466
- if (this._csm) {
467
- // keep lightDirection in sync with the gameObject's world orientation
468
- this._csm.lightDirection.copy(this.gameObject.worldForward);
469
- this._csm.update();
470
- if (this._csmHelper) this._csmHelper.update();
471
- }
472
- }
473
-
474
419
  /**
475
420
  * Creates the appropriate three.js light based on the configured light type
476
421
  * and applies all settings like shadows, intensity, and color.
@@ -667,41 +612,6 @@ export class Light extends Behaviour implements ILight {
667
612
  }
668
613
  }
669
614
 
670
- /**
671
- * Creates and initializes a CSM instance for this directional light.
672
- * CSM manages its own cascade DirectionalLights internally.
673
- */
674
- private createCSM() {
675
- const camera = this.context.mainCamera;
676
- if (!camera) {
677
- if (debug) console.warn("CSM: no main camera found, deferring");
678
- return;
679
- }
680
-
681
- this._csm = new CSM({
682
- camera,
683
- parent: this.context.scene,
684
- cascades: this.cascades,
685
- mode: this.cascadeMode,
686
- maxFar: this._shadowDistance ?? shadowMaxDistance,
687
- shadowMapSize: this._shadowResolution ?? 2048,
688
- shadowBias: this._shadowBias,
689
- lightDirection: this.gameObject.worldForward.clone(),
690
- lightIntensity: this._intensity >= 0 ? this._intensity : 1,
691
- });
692
- this._csm.fade = true;
693
-
694
- // apply color to all cascade lights
695
- for (const l of this._csm.lights) {
696
- l.color.copy(this._color);
697
- }
698
-
699
- if (debug) {
700
- this._csmHelper = new CSMHelper(this._csm);
701
- this.context.scene.add(this._csmHelper);
702
- }
703
- }
704
-
705
615
  /**
706
616
  * Configures a directional light by adding and positioning its target
707
617
  * @param dirLight The directional light to set up
@@ -714,5 +624,4 @@ export class Light extends Behaviour implements ILight {
714
624
  }
715
625
 
716
626
  const vec = new Vector3(0, 0, 0);
717
- const _csmLightDir = new Vector3();
718
627
 
@@ -37,7 +37,7 @@ const debug = getParam("debugnet");
37
37
  * @see {@link RoomEvents} for room lifecycle events
38
38
  * @see {@link isLocalNetwork} for local network detection
39
39
  * @link https://engine.needle.tools/docs/how-to-guides/networking/
40
- * @summary Networking configuration
40
+ * @summary Configures the websocket server URL for multiplayer networking
41
41
  * @category Networking
42
42
  * @group Components
43
43
  */
@@ -290,6 +290,8 @@ export class ReflectionProbe extends Behaviour {
290
290
  const current = block.getOverride("envMap")?.value;
291
291
  if (current === this.texture) {
292
292
  block.removeOveride("envMap");
293
+ block.removeOveride("envMapRotation");
294
+ block.removeOveride("envMapIntensity");
293
295
  }
294
296
  }
295
297
  }
@@ -156,4 +156,7 @@ class VolumeParameterSerializer extends TypeSerializer {
156
156
  return parameter;
157
157
  }
158
158
  }
159
- new VolumeParameterSerializer();
159
+ /** @internal */
160
+ export function initVolumeParameterSerializer() {
161
+ new VolumeParameterSerializer();
162
+ }
@@ -4,7 +4,7 @@ import * as ThreeMeshUI from 'three-mesh-ui'
4
4
  import { Mathf } from "../../engine/engine_math.js";
5
5
  import { serializable } from "../../engine/engine_serialization_decorator.js";
6
6
  import { FrameEvent } from "../../engine/engine_setup.js";
7
- import { delayForFrames, getParam } from "../../engine/engine_utils.js";
7
+ import { getParam } from "../../engine/engine_utils.js";
8
8
  import { type NeedleXREventArgs } from "../../engine/xr/api.js";
9
9
  import { Camera } from "../Camera.js";
10
10
  import { GameObject } from "../Component.js";
@@ -236,19 +236,13 @@ export class Canvas extends UIRootComponent implements ICanvas {
236
236
  }
237
237
  }
238
238
 
239
- async onEnterXR(args: NeedleXREventArgs) {
239
+ onEnterXR(args: NeedleXREventArgs) {
240
240
  // workaround for https://linear.app/needle/issue/NE-4114
241
241
  if (this.screenspace) {
242
242
  if (args.xr.isVR || args.xr.isPassThrough) {
243
243
  this.gameObject.visible = false;
244
244
  }
245
245
  }
246
- else {
247
- this.gameObject.visible = false;
248
- await delayForFrames(1).then(()=>{
249
- this.gameObject.visible = true;
250
- });
251
- }
252
246
  }
253
247
  onLeaveXR(args: NeedleXREventArgs): void {
254
248
  if (this.screenspace) {
@@ -1,4 +1,5 @@
1
1
  /// <reference path="../plugins/types/needle-bindings.d.ts" />
2
+ /// <reference path="./engine/webcomponents/jsx.d.ts" />
2
3
 
3
4
  import { initEngine } from "./engine/engine_init.js";
4
5
  initEngine();