@needle-tools/engine 4.10.0-next.4f9d92a → 4.10.0-next.870425c

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 (96) hide show
  1. package/CHANGELOG.md +8 -3
  2. package/README.md +2 -1
  3. package/dist/{needle-engine.bundle-D4dO0t5I.umd.cjs → needle-engine.bundle-0b6rexDr.umd.cjs} +139 -137
  4. package/dist/{needle-engine.bundle-BeZ_xmJa.js → needle-engine.bundle-B5GtGvbq.js} +7750 -7653
  5. package/dist/needle-engine.bundle-CicGQeCY.min.js +1652 -0
  6. package/dist/needle-engine.js +15 -14
  7. package/dist/needle-engine.min.js +1 -1
  8. package/dist/needle-engine.umd.cjs +1 -1
  9. package/dist/vendor-CPuBPspY.umd.cjs +1121 -0
  10. package/dist/vendor-DPCU8cUF.min.js +1121 -0
  11. package/dist/vendor-MBoqSyFm.js +16240 -0
  12. package/lib/engine/engine_camera.js +5 -5
  13. package/lib/engine/engine_camera.js.map +1 -1
  14. package/lib/engine/engine_gizmos.d.ts +11 -10
  15. package/lib/engine/engine_gizmos.js +24 -10
  16. package/lib/engine/engine_gizmos.js.map +1 -1
  17. package/lib/engine/engine_license.js +1 -1
  18. package/lib/engine/engine_license.js.map +1 -1
  19. package/lib/engine/engine_lightdata.d.ts +3 -3
  20. package/lib/engine/engine_lightdata.js +10 -10
  21. package/lib/engine/engine_lightdata.js.map +1 -1
  22. package/lib/engine/engine_physics_rapier.js +4 -0
  23. package/lib/engine/engine_physics_rapier.js.map +1 -1
  24. package/lib/engine/engine_scenelighting.d.ts +1 -1
  25. package/lib/engine/engine_scenelighting.js +4 -5
  26. package/lib/engine/engine_scenelighting.js.map +1 -1
  27. package/lib/engine/engine_utils.d.ts +3 -1
  28. package/lib/engine/engine_utils.js +11 -0
  29. package/lib/engine/engine_utils.js.map +1 -1
  30. package/lib/engine/extensions/extension_utils.js +1 -1
  31. package/lib/engine/extensions/extension_utils.js.map +1 -1
  32. package/lib/engine/webcomponents/needle-engine.js +22 -0
  33. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  34. package/lib/engine/xr/NeedleXRController.d.ts +3 -3
  35. package/lib/engine/xr/NeedleXRController.js +28 -0
  36. package/lib/engine/xr/NeedleXRController.js.map +1 -1
  37. package/lib/engine-components/Camera.d.ts +1 -1
  38. package/lib/engine-components/Camera.js +1 -1
  39. package/lib/engine-components/CameraUtils.js +2 -1
  40. package/lib/engine-components/CameraUtils.js.map +1 -1
  41. package/lib/engine-components/CharacterController.d.ts +2 -2
  42. package/lib/engine-components/CharacterController.js +2 -2
  43. package/lib/engine-components/OrbitControls.d.ts +1 -1
  44. package/lib/engine-components/OrbitControls.js +1 -1
  45. package/lib/engine-components/Skybox.js +22 -4
  46. package/lib/engine-components/Skybox.js.map +1 -1
  47. package/lib/engine-components/debug/LogStats.d.ts +1 -0
  48. package/lib/engine-components/debug/LogStats.js +1 -0
  49. package/lib/engine-components/debug/LogStats.js.map +1 -1
  50. package/lib/engine-components/timeline/PlayableDirector.js +1 -1
  51. package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
  52. package/lib/engine-components/timeline/TimelineModels.d.ts +37 -2
  53. package/lib/engine-components/timeline/TimelineModels.js +6 -0
  54. package/lib/engine-components/timeline/TimelineModels.js.map +1 -1
  55. package/lib/engine-components/timeline/TimelineTracks.d.ts +2 -1
  56. package/lib/engine-components/timeline/TimelineTracks.js +26 -23
  57. package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
  58. package/lib/engine-components/web/ScrollFollow.d.ts +2 -0
  59. package/lib/engine-components/web/ScrollFollow.js +114 -99
  60. package/lib/engine-components/web/ScrollFollow.js.map +1 -1
  61. package/lib/engine-components/web/ViewBox.d.ts +33 -3
  62. package/lib/engine-components/web/ViewBox.js +133 -49
  63. package/lib/engine-components/web/ViewBox.js.map +1 -1
  64. package/lib/engine-components/webxr/WebARSessionRoot.js +1 -0
  65. package/lib/engine-components/webxr/WebARSessionRoot.js.map +1 -1
  66. package/lib/engine-components-experimental/Presentation.d.ts +1 -0
  67. package/lib/engine-components-experimental/Presentation.js +1 -0
  68. package/lib/engine-components-experimental/Presentation.js.map +1 -1
  69. package/package.json +2 -1
  70. package/src/engine/engine_camera.ts +5 -7
  71. package/src/engine/engine_gizmos.ts +37 -23
  72. package/src/engine/engine_license.ts +1 -1
  73. package/src/engine/engine_lightdata.ts +11 -11
  74. package/src/engine/engine_physics_rapier.ts +3 -0
  75. package/src/engine/engine_scenelighting.ts +5 -6
  76. package/src/engine/engine_utils.ts +12 -0
  77. package/src/engine/extensions/extension_utils.ts +1 -1
  78. package/src/engine/webcomponents/needle-engine.ts +33 -6
  79. package/src/engine/xr/NeedleXRController.ts +36 -4
  80. package/src/engine-components/Camera.ts +1 -1
  81. package/src/engine-components/CameraUtils.ts +1 -1
  82. package/src/engine-components/CharacterController.ts +2 -2
  83. package/src/engine-components/OrbitControls.ts +1 -1
  84. package/src/engine-components/Skybox.ts +26 -7
  85. package/src/engine-components/debug/LogStats.ts +1 -0
  86. package/src/engine-components/timeline/PlayableDirector.ts +1 -1
  87. package/src/engine-components/timeline/TimelineModels.ts +37 -3
  88. package/src/engine-components/timeline/TimelineTracks.ts +26 -23
  89. package/src/engine-components/web/ScrollFollow.ts +121 -103
  90. package/src/engine-components/web/ViewBox.ts +140 -50
  91. package/src/engine-components/webxr/WebARSessionRoot.ts +1 -0
  92. package/src/engine-components-experimental/Presentation.ts +1 -0
  93. package/dist/needle-engine.bundle-C3bpSNYu.min.js +0 -1650
  94. package/dist/vendor-D0Yvltn9.umd.cjs +0 -1121
  95. package/dist/vendor-DU8tJyl_.js +0 -14366
  96. package/dist/vendor-JyrX4DVM.min.js +0 -1121
@@ -1,4 +1,4 @@
1
- import { AxesHelper, Box3, BoxGeometry, BufferAttribute, BufferGeometry, Color, type ColorRepresentation, CylinderGeometry, EdgesGeometry, Line, LineBasicMaterial, LineSegments, Matrix4, Mesh, MeshBasicMaterial, Object3D, Quaternion, SphereGeometry, Vector3 } from 'three';
1
+ import { AxesHelper, Box3, BoxGeometry, BufferAttribute, BufferGeometry, Color, type ColorRepresentation, CylinderGeometry, EdgesGeometry, Line, LineBasicMaterial, LineSegments, Material,Matrix4, Mesh, MeshBasicMaterial, Object3D, Quaternion, SphereGeometry, Vector3 } from 'three';
2
2
  import ThreeMeshUI, { Inline, Text } from "three-mesh-ui"
3
3
  import { type Options } from 'three-mesh-ui/build/types/core/elements/MeshUIBaseElement.js';
4
4
 
@@ -8,6 +8,7 @@ import { getTempVector, getWorldPosition, lookAtObject, setWorldPositionXYZ } fr
8
8
  import type { Vec3, Vec4 } from './engine_types.js';
9
9
  import { getParam } from './engine_utils.js';
10
10
  import { NeedleXRSession } from './engine_xr.js';
11
+ import { RGBAColor } from './js-extensions/RGBAColor.js';
11
12
 
12
13
  const _tmp = new Vector3();
13
14
  const _tmp2 = new Vector3();
@@ -21,7 +22,7 @@ const circleSegments: number = 32;
21
22
  export type LabelHandle = {
22
23
  setText(str: string);
23
24
  }
24
- declare type ColorWithAlpha = Color & { a: number };
25
+ type GizmoColor = ColorRepresentation | (Color & { a: number }) | RGBAColor;
25
26
 
26
27
  /** Gizmos are temporary objects that are drawn in the scene for debugging or visualization purposes
27
28
  * They are automatically removed after a given duration and cached internally to reduce overhead.
@@ -62,7 +63,7 @@ export class Gizmos {
62
63
  * @param parent the parent object to attach the label to. If no parent is provided the label will be attached to the scene
63
64
  * @returns a handle to the label that can be used to update the text
64
65
  */
65
- static DrawLabel(position: Vec3, text: string, size: number = .05, duration: number = 0, color?: ColorRepresentation, backgroundColor?: ColorRepresentation | ColorWithAlpha, parent?: Object3D,) {
66
+ static DrawLabel(position: Vec3, text: string, size: number = .05, duration: number = 0, color?: ColorRepresentation, backgroundColor?: ColorRepresentation | GizmoColor, parent?: Object3D,) {
66
67
  if (!Gizmos.enabled) return null;
67
68
  if (!color) color = defaultColor;
68
69
  const rigScale = NeedleXRSession.active?.rigScale ?? 1;
@@ -82,7 +83,7 @@ export class Gizmos {
82
83
  * @param duration the duration in seconds the ray will be rendered. If 0 it will be rendered for one frame
83
84
  * @param depthTest if true the ray will be rendered with depth test
84
85
  */
85
- static DrawRay(origin: Vec3, dir: Vec3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
86
+ static DrawRay(origin: Vec3, dir: Vec3, color: GizmoColor = defaultColor, duration: number = 0, depthTest: boolean = true) {
86
87
  if (!Gizmos.enabled) return;
87
88
  const obj = Internal.getLine(duration);
88
89
  const positions = obj.geometry.getAttribute("position");
@@ -90,9 +91,10 @@ export class Gizmos {
90
91
  _tmp.set(dir.x, dir.y, dir.z).multiplyScalar(999999999);
91
92
  positions.setXYZ(1, origin.x + _tmp.x, origin.y + _tmp.y, origin.z + _tmp.z);
92
93
  positions.needsUpdate = true;
93
- obj.material["color"].set(color);
94
94
  obj.material["depthTest"] = depthTest;
95
95
  obj.material["depthWrite"] = false;
96
+ obj.material["fog"] = false;
97
+ applyGizmoColor(obj.material, color);
96
98
  }
97
99
 
98
100
  /**
@@ -104,7 +106,7 @@ export class Gizmos {
104
106
  * @param depthTest if true the line will be rendered with depth test
105
107
  * @param lengthFactor the length of the line. Default is 1
106
108
  */
107
- static DrawDirection(pt: Vec3, direction: Vec3 | Vec4, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true, lengthFactor: number = 1) {
109
+ static DrawDirection(pt: Vec3, direction: Vec3 | Vec4, color: GizmoColor = defaultColor, duration: number = 0, depthTest: boolean = true, lengthFactor: number = 1) {
108
110
  if (!Gizmos.enabled) return;
109
111
  const obj = Internal.getLine(duration);
110
112
  const positions = obj.geometry.getAttribute("position");
@@ -120,10 +122,9 @@ export class Gizmos {
120
122
  }
121
123
  positions.setXYZ(1, pt.x + _tmp.x, pt.y + _tmp.y, pt.z + _tmp.z);
122
124
  positions.needsUpdate = true;
123
- obj.material["color"].set(color);
124
125
  obj.material["depthTest"] = depthTest;
125
126
  obj.material["depthWrite"] = false;
126
-
127
+ applyGizmoColor(obj.material, color);
127
128
  }
128
129
 
129
130
  /**
@@ -134,17 +135,17 @@ export class Gizmos {
134
135
  * @param duration the duration in seconds the line will be rendered. If 0 it will be rendered for one frame
135
136
  * @param depthTest if true the line will be rendered with depth test
136
137
  */
137
- static DrawLine(pt0: Vec3, pt1: Vec3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
138
+ static DrawLine(pt0: Vec3, pt1: Vec3, color: GizmoColor = defaultColor, duration: number = 0, depthTest: boolean = true) {
138
139
  if (!Gizmos.enabled) return;
139
140
  const obj = Internal.getLine(duration);
140
141
  const positions = obj.geometry.getAttribute("position");
141
142
  positions.setXYZ(0, pt0.x, pt0.y, pt0.z);
142
143
  positions.setXYZ(1, pt1.x, pt1.y, pt1.z);
143
144
  positions.needsUpdate = true;
144
- obj.material["color"].set(color);
145
145
  obj.material["depthTest"] = depthTest;
146
146
  obj.material["depthWrite"] = false;
147
147
  obj.material["fog"] = false;
148
+ applyGizmoColor(obj.material, color);
148
149
  }
149
150
 
150
151
  /**
@@ -162,10 +163,10 @@ export class Gizmos {
162
163
  obj.position.set(pt0.x, pt0.y, pt0.z);
163
164
  obj.scale.set(radius, radius, radius);
164
165
  obj.quaternion.setFromUnitVectors(this._up, _tmp.set(normal.x, normal.y, normal.z).normalize());
165
- obj.material["color"].set(color);
166
166
  obj.material["depthTest"] = depthTest;
167
167
  obj.material["depthWrite"] = false;
168
168
  obj.material["fog"] = false;
169
+ applyGizmoColor(obj.material, color);
169
170
  }
170
171
 
171
172
  /**
@@ -176,14 +177,14 @@ export class Gizmos {
176
177
  * @param duration the duration in seconds the sphere will be rendered. If 0 it will be rendered for one frame
177
178
  * @param depthTest if true the sphere will be rendered with depth test
178
179
  */
179
- static DrawWireSphere(center: Vec3, radius: number, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
180
+ static DrawWireSphere(center: Vec3, radius: number, color: GizmoColor = defaultColor, duration: number = 0, depthTest: boolean = true) {
180
181
  if (!Gizmos.enabled) return;
181
182
  const obj = Internal.getSphere(radius, duration, true);
182
183
  setWorldPositionXYZ(obj, center.x, center.y, center.z);
183
- obj.material["color"].set(color);
184
184
  obj.material["depthTest"] = depthTest;
185
185
  obj.material["depthWrite"] = false;
186
186
  obj.material["fog"] = false;
187
+ applyGizmoColor(obj.material, color);
187
188
  }
188
189
 
189
190
  /**
@@ -194,13 +195,13 @@ export class Gizmos {
194
195
  * @param duration the duration in seconds the sphere will be rendered. If 0 it will be rendered for one frame
195
196
  * @param depthTest if true the sphere will be rendered with depth test
196
197
  */
197
- static DrawSphere(center: Vec3, radius: number, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
198
+ static DrawSphere(center: Vec3, radius: number, color: GizmoColor = defaultColor, duration: number = 0, depthTest: boolean = true) {
198
199
  if (!Gizmos.enabled) return;
199
200
  const obj = Internal.getSphere(radius, duration, false);
200
201
  setWorldPositionXYZ(obj, center.x, center.y, center.z);
201
- obj.material["color"].set(color);
202
202
  obj.material["depthTest"] = depthTest;
203
203
  obj.material["depthWrite"] = false;
204
+ applyGizmoColor(obj.material, color);
204
205
  }
205
206
 
206
207
  /**
@@ -212,18 +213,18 @@ export class Gizmos {
212
213
  * @param duration the duration in seconds the box will be rendered. If 0 it will be rendered for one frame
213
214
  * @param depthTest if true the box will be rendered with depth test
214
215
  */
215
- static DrawWireBox(center: Vec3, size: Vec3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true, rotation: Quaternion|undefined = undefined) {
216
+ static DrawWireBox(center: Vec3, size: Vec3, color: GizmoColor = defaultColor, duration: number = 0, depthTest: boolean = true, rotation: Quaternion | undefined = undefined) {
216
217
  if (!Gizmos.enabled) return;
217
218
  const obj = Internal.getBox(duration);
218
219
  obj.position.set(center.x, center.y, center.z);
219
220
  obj.scale.set(size.x, size.y, size.z);
220
- if(rotation) obj.quaternion.copy(rotation);
221
+ if (rotation) obj.quaternion.copy(rotation);
221
222
  else obj.quaternion.identity();
222
- obj.material["color"].set(color);
223
223
  obj.material["depthTest"] = depthTest;
224
224
  obj.material["wireframe"] = true;
225
225
  obj.material["depthWrite"] = false;
226
226
  obj.material["fog"] = false;
227
+ applyGizmoColor(obj.material, color);
227
228
  }
228
229
 
229
230
  /**
@@ -233,16 +234,16 @@ export class Gizmos {
233
234
  * @param duration the duration in seconds the box will be rendered. If 0 it will be rendered for one frame. Default: 0
234
235
  * @param depthTest if true the box will be rendered with depth test. Default: true
235
236
  */
236
- static DrawWireBox3(box: Box3, color: ColorRepresentation = defaultColor, duration: number = 0, depthTest: boolean = true) {
237
+ static DrawWireBox3(box: Box3, color: GizmoColor = defaultColor, duration: number = 0, depthTest: boolean = true) {
237
238
  if (!Gizmos.enabled) return;
238
239
  const obj = Internal.getBox(duration);
239
240
  obj.position.copy(box.getCenter(_tmp));
240
241
  obj.scale.copy(box.getSize(_tmp));
241
- obj.material["color"].set(color);
242
242
  obj.material["depthTest"] = depthTest;
243
243
  obj.material["wireframe"] = true;
244
244
  obj.material["depthWrite"] = false;
245
245
  obj.material["fog"] = false;
246
+ applyGizmoColor(obj.material, color);
246
247
  }
247
248
 
248
249
  private static _up = new Vector3(0, 1, 0);
@@ -263,9 +264,9 @@ export class Gizmos {
263
264
  const dist = _tmp.set(pt1.x, pt1.y, pt1.z).sub(_tmp2.set(pt0.x, pt0.y, pt0.z)).length();
264
265
  const scale = dist * 0.1;
265
266
  obj.scale.set(scale, scale, scale);
266
- obj.material["color"].set(color);
267
267
  obj.material["depthTest"] = depthTest;
268
268
  obj.material["wireframe"] = wireframe;
269
+ applyGizmoColor(obj.material, color);
269
270
  this.DrawLine(pt0, pt1, color, duration, depthTest);
270
271
  }
271
272
 
@@ -296,9 +297,9 @@ export class Gizmos {
296
297
  }
297
298
  mesh.matrixAutoUpdate = false;
298
299
  mesh.matrixWorldAutoUpdate = false;
299
- mesh.material["color"].set(options.color ?? defaultColor);
300
300
  mesh.material["depthTest"] = options.depthTest ?? true;
301
301
  mesh.material["wireframe"] = true;
302
+ applyGizmoColor(mesh.material, options.color ?? defaultColor);
302
303
  }
303
304
  }
304
305
 
@@ -316,6 +317,19 @@ export function CreateWireCube(col: ColorRepresentation | null = null): LineSegm
316
317
  }
317
318
 
318
319
 
320
+ function applyGizmoColor(material: Material | Material[], color: GizmoColor) {
321
+ if (Array.isArray(material)) {
322
+ for (const mat of material) {
323
+ applyGizmoColor(mat, color);
324
+ }
325
+ return;
326
+ }
327
+ const alpha = (color instanceof RGBAColor) ? color.a : 1.0;
328
+ material["color"].set(color);
329
+ material["opacity"] = alpha;
330
+ material["transparent"] = alpha < 1.0;
331
+ }
332
+
319
333
 
320
334
  const $cacheSymbol = Symbol("GizmoCache");
321
335
  class Internal {
@@ -335,7 +349,7 @@ class Internal {
335
349
  }
336
350
  }
337
351
 
338
- static getTextLabel(duration: number, text: string, size: number, color: ColorRepresentation, backgroundColor?: ColorRepresentation | ColorWithAlpha): Text & LabelHandle {
352
+ static getTextLabel(duration: number, text: string, size: number, color: ColorRepresentation, backgroundColor?: ColorRepresentation | GizmoColor): Text & LabelHandle {
339
353
  this.ensureFont();
340
354
  let element = this.textLabelCache.pop();
341
355
 
@@ -342,7 +342,7 @@ async function sendUsageMessageToAnalyticsBackend(context: IContext) {
342
342
  if (window.crossOriginIsolated) return;
343
343
 
344
344
  const licenseType = NEEDLE_ENGINE_LICENSE_TYPE;
345
- if (licenseType === "pro") {
345
+ if (licenseType === "pro" || licenseType === "enterprise") {
346
346
  const attribute = context?.domElement?.getAttribute("no-telemetry");
347
347
  if (attribute === "" || attribute === "true" || attribute === "1") {
348
348
  if (debug) console.debug("Telemetry is disabled");
@@ -1,7 +1,7 @@
1
1
  import { ShaderChunk, Texture, UniformsLib, Vector4 } from "three";
2
2
 
3
3
  import { setDisposable } from "./engine_assetdatabase.js";
4
- import { Context } from "./engine_setup.js";
4
+ import type { Context } from "./engine_setup.js";
5
5
  import type { SourceIdentifier } from "./engine_types.js";
6
6
  import { getParam } from "./engine_utils.js";
7
7
  import { LightmapType } from "./extensions/NEEDLE_lightmaps.js";
@@ -27,22 +27,22 @@ export interface ILightDataRegistry {
27
27
 
28
28
  export class LightDataRegistry implements ILightDataRegistry {
29
29
 
30
- private _context: Context;
31
- private _lightmaps: Map<SourceIdentifier, Map<LightmapType, Texture[]>> = new Map();
30
+ private readonly context: Context;
31
+ private readonly map: Map<SourceIdentifier, Map<LightmapType, Texture[]>> = new Map();
32
32
 
33
33
  clear() {
34
- this._lightmaps.clear();
34
+ this.map.clear();
35
35
  }
36
36
 
37
37
  constructor(context: Context) {
38
- this._context = context;
38
+ this.context = context;
39
39
  }
40
40
 
41
41
  registerTexture(sourceId: SourceIdentifier, type: LightmapType, tex: Texture, index: number) {
42
42
  if (debugLightmap) console.log("Registering ", LightmapType[type] + " \"" + sourceId + "\"", tex);
43
- if (!this._lightmaps.has(sourceId))
44
- this._lightmaps.set(sourceId, new Map());
45
- const map = this._lightmaps.get(sourceId);
43
+ if (!this.map.has(sourceId))
44
+ this.map.set(sourceId, new Map());
45
+ const map = this.map.get(sourceId);
46
46
  const arr = map?.get(type) ?? [];
47
47
  if (arr.length < index) arr.length = index + 1;
48
48
  setDisposable(tex, false);
@@ -55,12 +55,12 @@ export class LightDataRegistry implements ILightDataRegistry {
55
55
  }
56
56
 
57
57
  tryGetSkybox(sourceId?: SourceIdentifier | null): Texture | null {
58
- if (debugLightmap) console.log("[Get Skybox]", sourceId, this._lightmaps)
58
+ if (debugLightmap) console.log("[Get Skybox]", sourceId, this.map)
59
59
  return this.tryGet(sourceId, LightmapType.Skybox, 0);
60
60
  }
61
61
 
62
62
  tryGetReflection(sourceId?: SourceIdentifier | null): Texture | null {
63
- if (debugLightmap) console.log("[Get Reflection]", sourceId, this._lightmaps)
63
+ if (debugLightmap) console.log("[Get Reflection]", sourceId, this.map)
64
64
  return this.tryGet(sourceId, LightmapType.Reflection, 0);
65
65
  }
66
66
 
@@ -69,7 +69,7 @@ export class LightDataRegistry implements ILightDataRegistry {
69
69
  if (debugLightmap) console.warn("Missing source id");
70
70
  return null;
71
71
  }
72
- const entry = this._lightmaps.get(sourceId);
72
+ const entry = this.map.get(sourceId);
73
73
  if (!entry) {
74
74
  if (debugLightmap) console.warn(`[Lighting] No ${LightmapType[type]} texture entry for`, sourceId);
75
75
  return null;
@@ -67,6 +67,7 @@ export class RapierPhysics implements IPhysicsEngine {
67
67
  debugRenderRaycasts: boolean = false;
68
68
 
69
69
  removeBody(obj: IComponent) {
70
+ if(debugPhysics) console.log("REMOVE BODY", obj?.name, obj[$bodyKey]);
70
71
  if (!obj) return;
71
72
  this.validate();
72
73
  const body = obj[$bodyKey];
@@ -901,6 +902,8 @@ export class RapierPhysics implements IPhysicsEngine {
901
902
  // set the collider layers
902
903
  this.updateColliderCollisionGroups(collider);
903
904
 
905
+ if (debugPhysics) console.log("Created collider", collider.name, col);
906
+
904
907
  return col;
905
908
  }
906
909
  catch (e) {
@@ -162,7 +162,7 @@ export class RendererData {
162
162
  private __currentReflectionId: SourceIdentifier | null = null;
163
163
 
164
164
  /** @internal */
165
- internalEnableReflection(sourceId: SourceIdentifier) {
165
+ internalEnableReflection(sourceId: SourceIdentifier) : Texture | null {
166
166
  this.__currentReflectionId = sourceId;
167
167
  const settings = this._sceneLightSettings?.get(sourceId);
168
168
 
@@ -181,7 +181,7 @@ export class RendererData {
181
181
  const tex = existing.Source;
182
182
  tex.mapping = EquirectangularReflectionMapping;
183
183
  scene.environment = tex;
184
- return;
184
+ return tex;
185
185
  }
186
186
  else if (debug) console.warn("Could not find reflection for source", sourceId);
187
187
  break;
@@ -196,22 +196,21 @@ export class RendererData {
196
196
  tex.colorSpace = SRGBColorSpace;
197
197
  tex.mapping = EquirectangularReflectionMapping;
198
198
  this.context.scene.environment = tex;
199
+ return tex;
199
200
  }
200
201
  else console.error("Missing ambient trilight", settings.sourceId);
201
- return;
202
202
  case AmbientMode.Flat:
203
203
  if (settings.ambientLight) {
204
204
  const tex = createFlatTexture(settings.ambientLight, 64);
205
205
  tex.colorSpace = SRGBColorSpace;
206
206
  tex.mapping = EquirectangularReflectionMapping;
207
207
  this.context.scene.environment = tex;
208
+ return tex;
208
209
  }
209
210
  else console.error("Missing ambientlight", settings.sourceId);
210
- return;
211
- default:
212
- return;
213
211
  }
214
212
  }
213
+ return null;
215
214
  }
216
215
 
217
216
  /** @internal */
@@ -381,6 +381,14 @@ export function resolveUrl(source: SourceIdentifier | undefined, uri: string): s
381
381
  }
382
382
  return uri;
383
383
  }
384
+
385
+ export function toSourceId(src: string | null): SourceIdentifier | undefined {
386
+ if (!src) return undefined;
387
+ src = src.trim();
388
+ src = src.split("?")[0]?.split("#")[0];
389
+ return src;
390
+ }
391
+
384
392
  // export function getPath(glbLocation: SourceIdentifier | undefined, path: string) {
385
393
  // if (path && glbLocation && !path.includes("/")) {
386
394
  // // get directory of glb and prepend it to the audio file path
@@ -793,6 +801,7 @@ const mutationObserverMap = new WeakMap<HTMLElement, HtmlElementExtra>();
793
801
  /**
794
802
  * Register a callback when an {@link HTMLElement} attribute changes.
795
803
  * This is used, for example, by the Skybox component to watch for changes to the environment-* and skybox-* attributes.
804
+ * @returns A function that can be used to unregister the callback
796
805
  */
797
806
  export function addAttributeChangeCallback(domElement: HTMLElement, name: string, callback: AttributeChangeCallback) {
798
807
  if (!mutationObserverMap.get(domElement)) {
@@ -811,6 +820,9 @@ export function addAttributeChangeCallback(domElement: HTMLElement, name: string
811
820
  listeners.set(name, []);
812
821
  }
813
822
  listeners.get(name)!.push(callback);
823
+ return () => {
824
+ removeAttributeChangeCallback(domElement, name, callback);
825
+ }
814
826
  };
815
827
 
816
828
  /**
@@ -89,7 +89,7 @@ function internalResolve(paths: DependencyInfo[], parser: GLTFParserWithCache, o
89
89
  for (let i = 0; i < val.length; i++) {
90
90
  const entry = val[i];
91
91
  const ext = resolveExtension(parser, entry);
92
- if (ext !== null) {
92
+ if (ext !== null && ext !== undefined) {
93
93
  if (typeof ext.then === "function")
94
94
  promises.push(ext.then(res => val[i] = res));
95
95
  else val[i] = ext;
@@ -38,14 +38,18 @@ const observedAttributes = [
38
38
  "loadstart",
39
39
  "progress",
40
40
  "loadfinished",
41
+
41
42
  "dracoDecoderPath",
42
43
  "dracoDecoderType",
43
44
  "ktx2DecoderPath",
45
+
44
46
  "tone-mapping",
45
47
  "tone-mapping-exposure",
46
48
  "background-blurriness",
47
49
  "background-color",
48
50
  "environment-intensity",
51
+
52
+ "focus-rect",
49
53
  ]
50
54
 
51
55
  // https://developers.google.com/web/fundamentals/web-components/customelements
@@ -95,7 +99,7 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
95
99
  if (value === null) this.removeAttribute("camera-controls");
96
100
  else this.setAttribute("camera-controls", value ? "true" : "false");
97
101
  }
98
-
102
+
99
103
 
100
104
  /**
101
105
  * Get the current context for this web component instance. The context is created when the src attribute is set and the loading has finished.
@@ -331,17 +335,17 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
331
335
  if (debug) console.log("ktx2DecoderPath", newValue);
332
336
  setKtx2TranscoderPath(newValue);
333
337
  break;
334
-
338
+
335
339
  case "tonemapping":
336
340
  case "tone-mapping":
337
341
  case "tone-mapping-exposure":
338
342
  case "background-blurriness":
339
343
  case "background-color":
340
344
  case "environment-intensity":
341
- {
342
- this.applyAttributes();
343
- break;
344
- }
345
+ {
346
+ this.applyAttributes();
347
+ break;
348
+ }
345
349
  case "public-key": {
346
350
  if (newValue != PUBLIC_KEY)
347
351
  this.setPublicKey();
@@ -352,6 +356,25 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
352
356
  this.setVersion();
353
357
  break;
354
358
  }
359
+
360
+ case "focus-rect":
361
+ {
362
+ const focus_rect = this.getAttribute("focus-rect") as HTMLElement | string | null;
363
+ if (focus_rect && this._context) {
364
+ if (focus_rect === null) {
365
+ this._context.setCameraFocusRect(null);
366
+ }
367
+ else if (typeof focus_rect === "string" && focus_rect.length > 0) {
368
+ const element = document.querySelector(focus_rect);
369
+ this._context.setCameraFocusRect(element instanceof HTMLElement ? element : null);
370
+ }
371
+ else if (focus_rect instanceof HTMLElement) {
372
+ this._context.setCameraFocusRect(focus_rect);
373
+ }
374
+
375
+ }
376
+ }
377
+ break;
355
378
  }
356
379
  }
357
380
 
@@ -570,6 +593,10 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
570
593
  this._context.renderer.setClearColor(rgbaColor, rgbaColor.alpha);
571
594
  this.context.scene.background = null;
572
595
  }
596
+ // HACK: if we set background-color to a color and then back to null we want the background-image attribute to re-apply
597
+ else if (this.getAttribute("background-image")) {
598
+ this.setAttribute("background-image", this.getAttribute("background-image")!);
599
+ }
573
600
  }
574
601
  }
575
602
 
@@ -23,10 +23,10 @@ const debugCustomGesture = getParam("debugcustomgesture");
23
23
  // let _didReceiveSelectStartEvent = false;
24
24
 
25
25
  // https://github.com/immersive-web/webxr-input-profiles/blob/4484a05e30bcd43fe86bb4e06b7a707861a26796/packages/registry/profiles/meta/meta-quest-touch-plus.json
26
- declare type ControllerAxes = "xr-standard-thumbstick";
27
- declare type StickName = "xr-standard-thumbstick";
26
+ declare type ControllerAxes = "xr-standard-thumbstick" | "xr-standard-touchpad";
27
+ declare type StickName = "xr-standard-thumbstick" | "xr-standard-touchpad";
28
28
  declare type Mapping = "xr-standard";
29
- declare type ComponentType = "button" | "thumbstick" | "squeeze";
29
+ declare type ComponentType = "button" | "thumbstick" | "squeeze" | "touchpad";
30
30
  declare type GamepadKey = "button" | "xAxis" | "yAxis";
31
31
 
32
32
  declare type NeedleXRControllerButtonName = ButtonName | "primary-button" | "primary";
@@ -407,6 +407,16 @@ C:${this.connected ? "x" : "-"} T:${this.isTracking ? "x" : "-"} Hand:${this.inp
407
407
  gamepadStr += "\n[axes " + gp.axes.length + "]: " + gp.axes.map(a => a.toPrecision(1)).join(",");
408
408
  debugStr += "\n" + gamepadStr;
409
409
  }
410
+ if (this._layout) {
411
+ debugStr += "\nLayout: ";
412
+ for (const component of Object.keys(this._layout.components || {})) {
413
+ const val = this.getStick(component as StickName);
414
+ const indices = this._layout.components[component]?.gamepadIndices;
415
+ const indicesAsString = indices ? Object.entries(indices).map(e => e[0][0].toUpperCase() + e[0].slice(1) + "=" + e[1]).join(",") : "";
416
+ debugStr += `\n ${component}: ${this._layout.components[component]?.type} [${indicesAsString}] (${val.x.toPrecision(2)},${val.y.toPrecision(2)})`;
417
+ }
418
+ }
419
+
410
420
  Gizmos.DrawLabel(debugLabelPosition, debugStr, .006);
411
421
  }
412
422
 
@@ -730,6 +740,7 @@ C:${this.connected ? "x" : "-"} T:${this.isTracking ? "x" : "-"} Hand:${this.inp
730
740
  if (componentModel?.gamepadIndices) {
731
741
  switch (componentModel.type) {
732
742
  case "thumbstick":
743
+ case "touchpad":
733
744
  if (this.inputSource.gamepad) {
734
745
  const xIndex = componentModel.gamepadIndices!.xAxis!;
735
746
  const yIndex = componentModel.gamepadIndices!.yAxis!;
@@ -760,7 +771,11 @@ C:${this.connected ? "x" : "-"} T:${this.isTracking ? "x" : "-"} Hand:${this.inp
760
771
  this._isMetaQuestTouchController = this.profiles.includes("meta-quest-touch-plus") || this.profiles.includes("oculus-touch-v3");
761
772
 
762
773
  // Proper profile starting with v69 and browser 35.1
763
- this._isMxInk = this.profiles.includes("logitech-mx-ink")
774
+ this._isMxInk = this.profiles.includes("logitech-mx-ink");
775
+
776
+ // For debugging to see ALL available profiles
777
+ /** @ts-ignore */
778
+ // fetchProfilesList(DEFAULT_PROFILES_PATH).then(list => console.log("Available controller profiles", list));
764
779
 
765
780
  if (!this._layout) {
766
781
  // Ignore transient-pointer since we likely don't want to spawn a controller visual just for a temporary pointer.
@@ -780,6 +795,8 @@ C:${this.connected ? "x" : "-"} T:${this.isTracking ? "x" : "-"} Hand:${this.inp
780
795
  res.assetPath || ""
781
796
  );
782
797
 
798
+ // const overrideProfile = await fetch(DEFAULT_PROFILES_PATH + "/htc-vive-focus-3/profile.json").then(r => r.json());
799
+
783
800
  const profile = res.profile as InputDeviceProfile;
784
801
  const layout = profile.layouts[this.inputSource.handedness];
785
802
  this._layout = layout;
@@ -791,6 +808,21 @@ C:${this.connected ? "x" : "-"} T:${this.isTracking ? "x" : "-"} Hand:${this.inp
791
808
  this._layout.gamepad[component.gamepadIndices!.button!] = key as XRControllerButtonName;
792
809
  }
793
810
  }
811
+
812
+ // If we have 4 axes and no thumbstick defined, we define thumbstick for axis 3+4
813
+ // This is a workaround for HTC Vive Focus 3 controllers, which have the profile for Vive Focus Plus...
814
+ // This workaround fixes it for HTC Vive Focus 3 but does not change anything for Vive Focus Plus controllers
815
+ if (this.profiles.length >= 1 && this.profiles[0] === "htc-vive-focus-plus") {
816
+ if (this.inputSource.gamepad && this.inputSource.gamepad.axes.length === 4 && !this._layout.components["xr-standard-thumbstick"]) {
817
+ this._layout.components["xr-standard-thumbstick"] = {
818
+ type: "thumbstick",
819
+ gamepadIndices: {
820
+ xAxis: 2,
821
+ yAxis: 3,
822
+ }
823
+ }
824
+ }
825
+ }
794
826
  }
795
827
  // if (debug) console.log(this._layout, this.inputSource);
796
828
  // debugger;
@@ -36,7 +36,7 @@ const debugscreenpointtoray = getParam("debugscreenpointtoray");
36
36
  * Supports both perspective and orthographic cameras with various rendering options.
37
37
  * Internally, this component uses {@link PerspectiveCamera} and {@link OrthographicCamera} three.js objects.
38
38
  *
39
- * @category Camera Controls
39
+ * @category Camera
40
40
  * @group Components
41
41
  */
42
42
  export class Camera extends Behaviour implements ICamera {
@@ -122,7 +122,7 @@ function createDefaultCameraControls(context: IContext, cam?: ICamera) {
122
122
  orbit.autoRotate = autoRotate != "0" && autoRotate?.toLowerCase() != "false";
123
123
  const autoRotateSpeed = Number.parseFloat(autoRotate || ".5");
124
124
  orbit.autoRotateSpeed = !isNaN(autoRotateSpeed) ? autoRotateSpeed : .5;
125
- console.log("Auto-rotate", orbit.autoRotate, "speed:", orbit.autoRotateSpeed);
125
+ if(debug) console.log("Auto-rotate", orbit.autoRotate, "speed:", orbit.autoRotateSpeed);
126
126
  const autoFit = context.domElement.getAttribute("auto-fit");
127
127
  orbit.autoFit = autoFit !== "0" && autoFit?.toLowerCase() != "false";
128
128
  orbit.autoTarget = true;
@@ -14,7 +14,7 @@ import { Rigidbody } from "./RigidBody.js";
14
14
  const debug = getParam("debugcharactercontroller");
15
15
 
16
16
  /**
17
- * @category Camera Controls
17
+ * @category Camera
18
18
  * @group Components
19
19
  */
20
20
  export class CharacterController extends Behaviour {
@@ -107,7 +107,7 @@ export class CharacterController extends Behaviour {
107
107
  }
108
108
 
109
109
  /**
110
- * @category Camera Controls
110
+ * @category Camera
111
111
  * @category Interactivity
112
112
  * @group Components
113
113
  */
@@ -63,7 +63,7 @@ declare module 'three/examples/jsm/controls/OrbitControls.js' {
63
63
  /** The OrbitControls component is used to control a camera using the [OrbitControls from three.js](https://threejs.org/docs/#examples/en/controls/OrbitControls) library.
64
64
  * The three OrbitControls object can be accessed via the `controls` property.
65
65
  * The object being controlled by the OrbitControls (usually the camera) can be accessed via the `controllerObject` property.
66
- * @category Camera Controls
66
+ * @category Camera
67
67
  * @group Components
68
68
  */
69
69
  export class OrbitControls extends Behaviour implements ICameraController {