@needle-tools/engine 3.9.0-alpha.1 → 3.10.0-alpha

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 (36) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/needle-engine.js +1 -1
  3. package/dist/needle-engine.light.js +1 -1
  4. package/dist/needle-engine.light.min.js +1 -1
  5. package/dist/needle-engine.light.umd.cjs +1 -1
  6. package/dist/needle-engine.min.js +1 -1
  7. package/dist/needle-engine.umd.cjs +1 -1
  8. package/lib/engine/engine_element_overlay.js +9 -2
  9. package/lib/engine/engine_element_overlay.js.map +1 -1
  10. package/lib/engine/engine_loaders.js.map +1 -1
  11. package/lib/engine/engine_mainloop_utils.js +6 -1
  12. package/lib/engine/engine_mainloop_utils.js.map +1 -1
  13. package/lib/engine/engine_networking_auto.d.ts +4 -1
  14. package/lib/engine/engine_networking_auto.js +43 -12
  15. package/lib/engine/engine_networking_auto.js.map +1 -1
  16. package/lib/engine/engine_types.d.ts +4 -2
  17. package/lib/engine/engine_types.js.map +1 -1
  18. package/lib/engine-components/Camera.js +3 -1
  19. package/lib/engine-components/Camera.js.map +1 -1
  20. package/lib/engine-components/ParticleSystem.js +15 -14
  21. package/lib/engine-components/ParticleSystem.js.map +1 -1
  22. package/lib/engine-components/SceneSwitcher.d.ts +5 -0
  23. package/lib/engine-components/SceneSwitcher.js +25 -2
  24. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  25. package/lib/engine-components/webxr/WebXR.js +14 -2
  26. package/lib/engine-components/webxr/WebXR.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/engine/engine_element_overlay.ts +9 -2
  29. package/src/engine/engine_loaders.ts +1 -1
  30. package/src/engine/engine_mainloop_utils.ts +8 -3
  31. package/src/engine/engine_networking_auto.ts +48 -22
  32. package/src/engine/engine_types.ts +6 -3
  33. package/src/engine-components/Camera.ts +6 -3
  34. package/src/engine-components/ParticleSystem.ts +16 -13
  35. package/src/engine-components/SceneSwitcher.ts +24 -2
  36. package/src/engine-components/webxr/WebXR.ts +25 -14
@@ -38,6 +38,13 @@ export class SceneSwitcher extends Behaviour {
38
38
  @serializable()
39
39
  queryParameterName: string = "scene";
40
40
 
41
+ /**
42
+ * when enabled the scene name will be used as the query parameter (otherwise the scene index will be used)
43
+ * Needs `queryParameterName` set
44
+ * */
45
+ @serializable()
46
+ useSceneName: boolean = true;
47
+
41
48
  @serializable()
42
49
  clamp: boolean = true;
43
50
 
@@ -281,9 +288,15 @@ export class SceneSwitcher extends Behaviour {
281
288
  if (this.useSceneLighting)
282
289
  this.context.sceneLighting.enable(scene)
283
290
  if (this.useHistory && index >= 0) {
291
+ // take the index as the query parameter value
292
+ let queryParameterValue = index.toString();
293
+ // unless the user defines that he wants to use the scene name
294
+ if (this.useSceneName) {
295
+ queryParameterValue = sceneUriToName(scene.uri);
296
+ }
284
297
  // save the loaded scene as an url parameter
285
298
  if (this.queryParameterName?.length)
286
- setParamWithoutReload(this.queryParameterName, index.toString(), this.useHistory);
299
+ setParamWithoutReload(this.queryParameterName, queryParameterValue, this.useHistory);
287
300
  // or set the history state without updating the url parameter
288
301
  else {
289
302
  const lastState = history.state;
@@ -328,9 +341,11 @@ export class SceneSwitcher extends Behaviour {
328
341
  }
329
342
  else {
330
343
  // Try to find a scene with a matching name
344
+ // we don't care about casing. e.g. Scene1 and scene1 should both match
345
+ const lowerCaseValue = value.toLowerCase();
331
346
  for (let i = 0; i < this.scenes.length; i++) {
332
347
  const scene = this.scenes[i];
333
- if (scene.uri.toLowerCase().includes(value)) {
348
+ if (sceneUriToName(scene.uri).toLowerCase().includes(lowerCaseValue)) {
334
349
  return this.select(i);;
335
350
  }
336
351
  }
@@ -349,6 +364,13 @@ export class SceneSwitcher extends Behaviour {
349
364
  }
350
365
 
351
366
 
367
+ function sceneUriToName(uri: string): string {
368
+ const name = uri.split("/").pop();
369
+ let value = name?.split(".").shift();
370
+ if (value?.length) return value;
371
+ return uri;
372
+ }
373
+
352
374
 
353
375
 
354
376
  class PreLoadScheduler {
@@ -21,7 +21,7 @@ import { showBalloonWarning } from '../../engine/debug';
21
21
  const debugWebXR = getParam("debugwebxr");
22
22
 
23
23
  export async function detectARSupport() {
24
- if(isMozillaXR()) return true;
24
+ if (isMozillaXR()) return true;
25
25
  if ("xr" in navigator) {
26
26
  //@ts-ignore
27
27
  return (await navigator["xr"].isSessionSupported('immersive-ar')) === true;
@@ -136,7 +136,7 @@ export class WebXR extends Behaviour {
136
136
  return arButton;
137
137
  }
138
138
 
139
- private static onModifyAROptions(options){
139
+ private static onModifyAROptions(options) {
140
140
  WebXR.dispatchEvent(WebXREvent.ModifyAROptions, options);
141
141
  }
142
142
 
@@ -255,11 +255,10 @@ export class WebXR extends Behaviour {
255
255
  this.context.appendHTMLElement(buttonsContainer);
256
256
 
257
257
  const forceButtons = debugWebXR;
258
- if(debugWebXR) console.log("ARSupported?", arSupported, "VRSupported?", vrSupported);
258
+ if (debugWebXR) console.log("ARSupported?", arSupported, "VRSupported?", vrSupported);
259
259
 
260
260
  // AR support
261
- if (forceButtons || (this.createARButton && this.enableAR && arSupported))
262
- {
261
+ if (forceButtons || (this.createARButton && this.enableAR && arSupported)) {
263
262
  arButton = WebXR.createARButton(this);
264
263
  this._arButton = arButton;
265
264
  buttonsContainer.appendChild(arButton);
@@ -271,7 +270,7 @@ export class WebXR extends Behaviour {
271
270
  this._vrButton = vrButton;
272
271
  buttonsContainer.appendChild(vrButton);
273
272
  }
274
-
273
+
275
274
  setTimeout(() => {
276
275
  WebXR.resetButtonStyles(vrButton);
277
276
  WebXR.resetButtonStyles(arButton);
@@ -289,11 +288,11 @@ export class WebXR extends Behaviour {
289
288
  // TODO: figure out why screen is black if we enable the code written here
290
289
  // const referenceSpace = renderer.xr.getReferenceSpace();
291
290
  const session = this.context.renderer.xr.getSession();
292
-
291
+
293
292
 
294
293
  if (session) {
295
294
  const pose = frame.getViewerPose(this.context.renderer.xr.getReferenceSpace());
296
- if(!pose) return;
295
+ if (!pose) return;
297
296
  this._currentHeadPose = pose;
298
297
  const transform: XRRigidTransform = pose?.transform;
299
298
  if (transform) {
@@ -356,7 +355,7 @@ export class WebXR extends Behaviour {
356
355
  this._originalCameraRotation.copy(getWorldQuaternion(this.context.mainCamera));
357
356
  this._originalCameraParent = this.context.mainCamera.parent;
358
357
  }
359
- if(this.Rig){
358
+ if (this.Rig) {
360
359
  this._originalXRRigParent = this.Rig.parent;
361
360
  this._originalXRRigPosition.copy(this.Rig.position);
362
361
  this._originalXRRigRotation.copy(this.Rig.quaternion);
@@ -415,9 +414,9 @@ export class WebXR extends Behaviour {
415
414
  const xr = this.context.renderer.xr;
416
415
  if (this.context.mainCamera) {
417
416
  const cam = xr.getCamera() as WebXRArrayCamera;
418
- if(debugWebXR) console.log("WebXRCamera", cam);
417
+ if (debugWebXR) console.log("WebXRCamera", cam);
419
418
  const cull = this.context.mainCameraComponent?.cullingMask;
420
- if(cam && cull !== undefined){
419
+ if (cam && cull !== undefined) {
421
420
  for (const c of cam.cameras) {
422
421
  c.layers.mask = cull;
423
422
  }
@@ -467,8 +466,14 @@ export class WebXR extends Behaviour {
467
466
 
468
467
  const wasInAR = this._isInAR;
469
468
 
470
- if (this._isInAR && session) {
471
- this.webAR?.onEnd(session);
469
+ if (session) {
470
+ if (this._isInAR) {
471
+ this.webAR?.onEnd(session);
472
+ }
473
+ else {
474
+ // if in VR we want to restore the FOV
475
+ this.context.mainCameraComponent?.applyClearFlagsIfIsActiveCamera();
476
+ }
472
477
  }
473
478
 
474
479
  this._isInAR = false;
@@ -491,7 +496,7 @@ export class WebXR extends Behaviour {
491
496
  this.context.mainCamera.scale.set(1, 1, 1);
492
497
  }
493
498
 
494
- if(wasInAR){
499
+ if (wasInAR) {
495
500
  this._originalXRRigParent?.add(this.rig);
496
501
  this.rig.position.copy(this._originalXRRigPosition);
497
502
  this.rig.quaternion.copy(this._originalXRRigRotation);
@@ -599,6 +604,12 @@ export class WebAR {
599
604
 
600
605
  if (!this.sessionRoot || this.sessionRoot.destroyed || !this.sessionRoot.activeAndEnabled)
601
606
  this.sessionRoot = GameObject.findObjectOfType(WebARSessionRoot, context);
607
+ if (!this.sessionRoot) {
608
+ // TODO: adding it on the scene directly doesnt work (probably because then everything in the scene is disabled including this component). See code a bit furhter below where we add this component to a temporary object inside the scene
609
+ const obj = this.webxr.gameObject;
610
+ this.sessionRoot = GameObject.addNewComponent(obj, WebARSessionRoot);
611
+ console.warn("WebAR: No ARSessionRoot found, creating one automatically on the WebXR object");
612
+ }
602
613
 
603
614
  this.previousBackground = context.scene.background;
604
615
  this.previousEnvironment = context.scene.environment;