@needle-tools/engine 3.0.1-alpha.2 → 3.0.1-alpha.3

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 (41) hide show
  1. package/CHANGELOG.md +4 -1
  2. package/dist/needle-engine.js +7706 -7641
  3. package/dist/needle-engine.min.js +262 -262
  4. package/dist/needle-engine.umd.cjs +280 -280
  5. package/lib/engine/engine_input.d.ts +5 -89
  6. package/lib/engine/engine_input.js +49 -103
  7. package/lib/engine/engine_input.js.map +1 -1
  8. package/lib/engine/engine_physics.d.ts +5 -0
  9. package/lib/engine/engine_physics.js +39 -4
  10. package/lib/engine/engine_physics.js.map +1 -1
  11. package/lib/engine/engine_types.d.ts +1 -0
  12. package/lib/engine/engine_types.js.map +1 -1
  13. package/lib/engine/engine_utils.js +4 -8
  14. package/lib/engine/engine_utils.js.map +1 -1
  15. package/lib/engine-components/CharacterController.js +2 -2
  16. package/lib/engine-components/CharacterController.js.map +1 -1
  17. package/lib/engine-components/DragControls.js +3 -4
  18. package/lib/engine-components/DragControls.js.map +1 -1
  19. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  20. package/lib/engine-components/WebXR.js +12 -2
  21. package/lib/engine-components/WebXR.js.map +1 -1
  22. package/lib/engine-components/WebXRController.js +1 -1
  23. package/lib/engine-components/WebXRController.js.map +1 -1
  24. package/lib/engine-components/ui/EventSystem.js +1 -3
  25. package/lib/engine-components/ui/EventSystem.js.map +1 -1
  26. package/lib/engine-components-experimental/Presentation.js +2 -3
  27. package/lib/engine-components-experimental/Presentation.js.map +1 -1
  28. package/lib/tsconfig.tsbuildinfo +1 -1
  29. package/package.json +2 -1
  30. package/plugins/vite/alias.js +5 -2
  31. package/src/engine/engine_input.ts +134 -108
  32. package/src/engine/engine_physics.ts +41 -4
  33. package/src/engine/engine_types.ts +1 -0
  34. package/src/engine/engine_utils.ts +4 -8
  35. package/src/engine-components/CharacterController.ts +2 -2
  36. package/src/engine-components/DragControls.ts +3 -4
  37. package/src/engine-components/SpectatorCamera.ts +1 -1
  38. package/src/engine-components/WebXR.ts +12 -3
  39. package/src/engine-components/WebXRController.ts +1 -1
  40. package/src/engine-components/ui/EventSystem.ts +2 -3
  41. package/src/engine-components-experimental/Presentation.ts +2 -2
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@needle-tools/engine",
3
- "version": "3.0.1-alpha.2",
3
+ "version": "3.0.1-alpha.3",
4
4
  "description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development, and can be deployed anywhere. It is flexible, extensible, and collaboration and XR come naturally.",
5
5
  "main": "dist/needle-engine.umd.cjs",
6
6
  "exports": {
7
7
  ".": {
8
+ "development": "./src/needle-engine.ts",
8
9
  "import": "./lib/needle-engine.js",
9
10
  "require": "./dist/needle-engine.umd.cjs"
10
11
  },
@@ -53,12 +53,15 @@ export const needleViteAlias = (command, config, userSettings) => {
53
53
  // introduced in 89a50718c38940abb99ee16c5e029065e41d7d65
54
54
  const res = path.resolve(projectDir, 'node_modules', name);
55
55
  if (typeof cb !== "function") cb = null;
56
+ const isDevEnvironment = process.env.NODE_ENV === "development";
56
57
  if (existsSync(res)) {
57
58
  aliasDict[name] = (packageName, index, path) => {
58
- if (cb !== null) {
59
+ if (cb !== null && !isDevEnvironment) {
59
60
  const overrideResult = cb(res, packageName, index, path);
60
61
  if (overrideResult !== undefined)
61
- return overrideResult;
62
+ if (existsSync(overrideResult)) {
63
+ return overrideResult;
64
+ }
62
65
  }
63
66
  return res;
64
67
  }
@@ -242,28 +242,54 @@ export class Input extends EventTarget {
242
242
  }
243
243
  return null;
244
244
  }
245
- isKeyDown(keyCode: KeyCode | string | number) {
246
- if (typeof keyCode === "number") {
247
- console.warn("Use of keycode as number is not recommended, please use KeyCode or string instead");
248
- keyCode = String.fromCharCode(keyCode);
245
+ isKeyDown(keyCode: KeyCode | string) {
246
+ const codes = this.getCodeForCommonKeyName(keyCode);
247
+ if (codes !== null) {
248
+ for (const code of codes) if (this.isKeyDown(code)) return true;
249
+ return false;
249
250
  }
250
- // console.log( this.keysPressed[keyCode]?.frame, time.frameCount);
251
251
  return this.context.application.isVisible && this.context.application.hasFocus && this.keysPressed[keyCode]?.startFrame === this.context.time.frameCount && this.keysPressed[keyCode].pressed;
252
252
  }
253
- isKeyUp(keyCode: KeyCode | string | number) {
254
- if (typeof keyCode === "number") {
255
- console.warn("Use of keycode as number is not recommended, please use KeyCode or string instead");
256
- keyCode = String.fromCharCode(keyCode);
253
+ isKeyUp(keyCode: KeyCode | string) {
254
+ const codes = this.getCodeForCommonKeyName(keyCode);
255
+ if (codes !== null) {
256
+ for (const code of codes) if (this.isKeyUp(code)) return true;
257
+ return false;
257
258
  }
258
259
  return this.context.application.isVisible && this.context.application.hasFocus && this.keysPressed[keyCode]?.frame === this.context.time.frameCount && !this.keysPressed[keyCode].pressed;
259
260
  }
260
- isKeyPressed(keyCode: KeyCode | string | number) {
261
- if (typeof keyCode === "number") {
262
- keyCode = String.fromCharCode(keyCode);
261
+ isKeyPressed(keyCode: KeyCode | string) {
262
+ const codes = this.getCodeForCommonKeyName(keyCode);
263
+ if (codes !== null) {
264
+ for (const code of codes) if (this.isKeyPressed(code)) return true;
265
+ return false;
263
266
  }
264
267
  return this.context.application.isVisible && this.context.application.hasFocus && this.keysPressed[keyCode]?.pressed;// && time.frameCount - this.keysPressed[keyCode].frame < 100;
265
268
  }
266
269
 
270
+ // utility helper for mapping common names to actual codes; e.g. "Shift" -> "ShiftLeft" and "ShiftRight" or "a" -> "KeyA"
271
+ private getCodeForCommonKeyName(keyName: string): string[] | null {
272
+ if (keyName.length === 1) {
273
+ // check if this is a digit
274
+ if (keyName >= "0" && keyName <= "9")
275
+ return ["Digit" + keyName];
276
+ // check if this is a letter
277
+ if (keyName >= "a" && keyName <= "z")
278
+ return ["Key" + keyName.toUpperCase()];
279
+ if (keyName == " ")
280
+ return ["Space"];
281
+ }
282
+ switch (keyName) {
283
+ case "Shift":
284
+ return ["ShiftLeft", "ShiftRight"];
285
+ case "Control":
286
+ return ["ControlLeft", "ControlRight"];
287
+ case "Alt":
288
+ return ["AltLeft", "AltRight"];
289
+ }
290
+ return null;
291
+ }
292
+
267
293
  createPointerDown(args: PointerEventArgs) {
268
294
  if (debug) showBalloonMessage("Create Pointer down");
269
295
  this.onDown(args);
@@ -350,20 +376,20 @@ export class Input extends EventTarget {
350
376
  return evt.target === this.context.renderer.domElement;
351
377
  }
352
378
 
353
- private keysPressed: { [key: number]: { pressed: boolean, frame: number, startFrame: number, key: string } } = {};
379
+ private keysPressed: { [key: KeyCode | string]: { pressed: boolean, frame: number, startFrame: number, key: string, code: KeyCode | string } } = {};
354
380
 
355
381
  private onKeyDown(evt: KeyboardEvent) {
356
382
  if (!this.context.application.hasFocus)
357
383
  return;
358
- const ex = this.keysPressed[evt.key];
384
+ const ex = this.keysPressed[evt.code];
359
385
  if (ex && ex.pressed) return;
360
- this.keysPressed[evt.key] = { pressed: true, frame: this.context.time.frameCount + 1, startFrame: this.context.time.frameCount + 1, key: evt.key };
386
+ this.keysPressed[evt.code] = { pressed: true, frame: this.context.time.frameCount + 1, startFrame: this.context.time.frameCount + 1, key: evt.key, code: evt.code };
361
387
  this.onDispatchEvent(InputEvents.KeyDown, new KeyEventArgs(evt));
362
388
  }
363
389
  private onKeyPressed(evt: KeyboardEvent) {
364
390
  if (!this.context.application.hasFocus)
365
391
  return;
366
- const p = this.keysPressed[evt.key];
392
+ const p = this.keysPressed[evt.code];
367
393
  if (!p) return;
368
394
  p.pressed = true;
369
395
  p.frame = this.context.time.frameCount + 1;
@@ -373,7 +399,7 @@ export class Input extends EventTarget {
373
399
  private onKeyUp(evt: KeyboardEvent) {
374
400
  if (!this.context.application.hasFocus)
375
401
  return;
376
- const p = this.keysPressed[evt.key];
402
+ const p = this.keysPressed[evt.code];
377
403
  if (!p) return;
378
404
  p.pressed = false;
379
405
  p.frame = this.context.time.frameCount + 1;
@@ -478,6 +504,8 @@ export class Input extends EventTarget {
478
504
 
479
505
  while (evt.button >= this._pointerPositionDown.length) this._pointerPositionDown.push(new THREE.Vector2());
480
506
  this._pointerPositionDown[evt.button].set(evt.clientX, evt.clientY);
507
+ while (evt.button >= this._pointerPositions.length) this._pointerPositions.push(new THREE.Vector2());
508
+ this._pointerPositions[evt.button].set(evt.clientX, evt.clientY);
481
509
 
482
510
  if (evt.button >= this._pointerDownTime.length) this._pointerDownTime.push(0);
483
511
  this._pointerDownTime[evt.button] = this.context.time.time;
@@ -552,8 +580,8 @@ export class Input extends EventTarget {
552
580
 
553
581
  const lf = this._pointerPositionsLastFrame[evt.button];
554
582
  lf.copy(this._pointerPositions[evt.button]);
555
- const dx = evt.movementX !== undefined ? evt.movementX : evt.clientX - lf.x;
556
- const dy = evt.movementY !== undefined ? evt.movementY : evt.clientY - lf.y;
583
+ const dx = evt.clientX - lf.x;
584
+ const dy = evt.clientY - lf.y;
557
585
  this._pointerPositionsDelta[evt.button].set(dx, dy);
558
586
 
559
587
  this._pointerPositions[evt.button].x = evt.clientX;
@@ -616,95 +644,93 @@ export class Input extends EventTarget {
616
644
  }
617
645
  }
618
646
 
619
-
620
-
621
- export enum KeyCode {
622
- BACKSPACE = "Backspace",
623
- TAB = "Tab",
624
- ENTER = "Enter",
625
- SHIFT = "Shift",
626
- CTRL = "Control",
627
- ALT = "Alt",
628
- PAUSE = "Pause",
629
- CAPS_LOCK = "CapsLock",
630
- ESCAPE = "Escape",
631
- SPACE = " ",
632
- PAGE_UP = "PageUp",
633
- PAGE_DOWN = "PageDown",
634
- END = "End",
635
- HOME = "Home",
636
- LEFT_ARROW = "ArrowLeft",
637
- UP_ARROW = "ArrowUp",
638
- RIGHT_ARROW = "ArrowRight",
639
- DOWN_ARROW = "ArrowDown",
640
- INSERT = "Insert",
641
- DELETE = "Delete",
642
- KEY_0 = "0",
643
- KEY_1 = "1",
644
- KEY_2 = "2",
645
- KEY_3 = "3",
646
- KEY_4 = "4",
647
- KEY_5 = "5",
648
- KEY_6 = "6",
649
- KEY_7 = "7",
650
- KEY_8 = "8",
651
- KEY_9 = "9",
652
- KEY_A = "a",
653
- KEY_B = "b",
654
- KEY_C = "c",
655
- KEY_D = "d",
656
- KEY_E = "e",
657
- KEY_F = "f",
658
- KEY_G = "g",
659
- KEY_H = "h",
660
- KEY_I = "i",
661
- KEY_K = "k",
662
- KEY_J = "j",
663
- KEY_L = "l",
664
- KEY_M = "m",
665
- KEY_N = "n",
666
- KEY_O = "o",
667
- KEY_P = "p",
668
- KEY_Q = "q",
669
- KEY_R = "r",
670
- KEY_S = "s",
671
- KEY_T = "t",
672
- KEY_U = "u",
673
- KEY_V = "v",
674
- KEY_W = "w",
675
- KEY_X = "x",
676
- KEY_Z = "z",
677
- KEY_Y = "y",
678
- SELECT = "Select",
679
- NUMPAD_0 = "Numpad0",
680
- NUMPAD_1 = "Numpad1",
681
- NUMPAD_2 = "Numpad2",
682
- NUMPAD_3 = "Numpad3",
683
- NUMPAD_4 = "Numpad4",
684
- NUMPAD_5 = "Numpad5",
685
- NUMPAD_6 = "Numpad6",
686
- NUMPAD_7 = "Numpad7",
687
- NUMPAD_8 = "Numpad8",
688
- NUMPAD_9 = "Numpad9",
689
- MULTIPLY = "Multiply",
690
- ADD = "Add",
691
- SUBTRACT = "Subtract",
692
- DECIMAL = "Decimal",
693
- DIVIDE = "Divide",
694
- F1 = "F1",
695
- F2 = "F2",
696
- F3 = "F3",
697
- F4 = "F4",
698
- F5 = "F5",
699
- F6 = "F6",
700
- F7 = "F7",
701
- F8 = "F8",
702
- F9 = "F9",
703
- F10 = "F10",
704
- F11 = "F11",
705
- F12 = "F12"
706
- };
707
-
647
+ export declare type KeyCode =
648
+ | "Tab"
649
+ | "Enter"
650
+ | "ShiftLeft"
651
+ | "ShiftRight"
652
+ | "ControlLeft"
653
+ | "ControlRight"
654
+ | "AltLeft"
655
+ | "AltRight"
656
+ | "Pause"
657
+ | "CapsLock"
658
+ | "Escape"
659
+ | "Space"
660
+ | "PageUp"
661
+ | "PageDown"
662
+ | "End"
663
+ | "Home"
664
+ | "ArrowLeft"
665
+ | "ArrowUp"
666
+ | "ArrowRight"
667
+ | "ArrowDown"
668
+ | "Insert"
669
+ | "Delete"
670
+ | "Digit0"
671
+ | "Digit1"
672
+ | "Digit2"
673
+ | "Digit3"
674
+ | "Digit4"
675
+ | "Digit5"
676
+ | "Digit6"
677
+ | "Digit7"
678
+ | "Digit8"
679
+ | "Digit9"
680
+ | "KeyA"
681
+ | "KeyB"
682
+ | "KeyC"
683
+ | "KeyD"
684
+ | "KeyE"
685
+ | "KeyF"
686
+ | "KeyG"
687
+ | "KeyH"
688
+ | "KeyI"
689
+ | "KeyJ"
690
+ | "KeyK"
691
+ | "KeyL"
692
+ | "KeyM"
693
+ | "KeyN"
694
+ | "KeyO"
695
+ | "KeyP"
696
+ | "KeyQ"
697
+ | "KeyR"
698
+ | "KeyS"
699
+ | "KeyT"
700
+ | "KeyU"
701
+ | "KeyV"
702
+ | "KeyW"
703
+ | "KeyX"
704
+ | "KeyY"
705
+ | "KeyZ"
706
+ | "Select"
707
+ | "Numpad0"
708
+ | "Numpad1"
709
+ | "Numpad2"
710
+ | "Numpad3"
711
+ | "Numpad4"
712
+ | "Numpad5"
713
+ | "Numpad6"
714
+ | "Numpad7"
715
+ | "Numpad8"
716
+ | "Numpad9"
717
+ | "Multiply"
718
+ | "Add"
719
+ | "Subtract"
720
+ | "Decimal"
721
+ | "Divide"
722
+ | "F1"
723
+ | "F2"
724
+ | "F3"
725
+ | "F4"
726
+ | "F5"
727
+ | "F6"
728
+ | "F7"
729
+ | "F8"
730
+ | "F9"
731
+ | "F10"
732
+ | "F11"
733
+ | "F12";
708
734
 
709
735
  // KEY_1 = 49,
710
736
  // KEY_2 = 50,
@@ -263,7 +263,10 @@ export class Physics {
263
263
  const ray = this.getPhysicsRay(this.rapierRay, origin, direction);
264
264
  if (!ray) return null;
265
265
 
266
- const hit = this.world?.castRay(ray, maxDistance, solid);
266
+ const hit = this.world?.castRay(ray, maxDistance, solid, undefined, undefined, undefined, undefined, (c) => {
267
+ // ignore objects in the IgnoreRaycast=2 layer
268
+ return !c[$componentKey]?.gameObject.layers.isEnabled(2);
269
+ });
267
270
  if (hit) {
268
271
  const point = ray.pointAt(hit.toi);
269
272
  const vec = this.raycastVectorsBuffer.get();
@@ -274,6 +277,28 @@ export class Physics {
274
277
  return null;
275
278
  }
276
279
 
280
+ public raycastPhysicsFastAndGetNormal(origin: Vec2 | Vec3, direction: Vec3 | undefined = undefined, maxDistance: number = Infinity, solid: boolean = true)
281
+ : null | { point: Vector3, normal: Vector3, collider: ICollider } {
282
+
283
+ const ray = this.getPhysicsRay(this.rapierRay, origin, direction);
284
+ if (!ray) return null;
285
+
286
+ const hit = this.world?.castRayAndGetNormal(ray, maxDistance, solid, undefined, undefined, undefined, undefined, (c) => {
287
+ // ignore objects in the IgnoreRaycast=2 layer
288
+ return !c[$componentKey]?.gameObject.layers.isEnabled(2);
289
+ });
290
+ if (hit) {
291
+ const point = ray.pointAt(hit.toi);
292
+ const normal = hit.normal;
293
+ const vec = this.raycastVectorsBuffer.get();
294
+ const nor = this.raycastVectorsBuffer.get();
295
+ vec.set(point.x, point.y, point.z);
296
+ nor.set(normal.x, normal.y, normal.z);
297
+ return { point: vec, normal: nor, collider: hit.collider[$componentKey] };
298
+ }
299
+ return null;
300
+ }
301
+
277
302
  private getPhysicsRay(ray: RAPIER.Ray, origin: Vec2 | Vec3, direction: Vec3 | undefined = undefined): RAPIER.Ray | null {
278
303
  const cam = this.context.mainCamera;
279
304
  // if we get origin in 2d space we need to project it to 3d space
@@ -283,11 +308,13 @@ export class Physics {
283
308
  return null;
284
309
  }
285
310
  const vec3 = this.raycastVectorsBuffer.get();
311
+ vec3.x = origin.x;
312
+ vec3.y = origin.y;
313
+ vec3.z = 0;
286
314
  // if the origin is in screen space we need to convert it to raycaster space
287
- if (origin.x > 1 || origin.y > 1 || origin.y < -1 || origin.x < -1) {
288
- this.context.input.convertScreenspaceToRaycastSpace(origin);
315
+ if (vec3.x > 1 || vec3.y > 1 || vec3.y < -1 || vec3.x < -1) {
316
+ this.context.input.convertScreenspaceToRaycastSpace(vec3);
289
317
  }
290
- vec3.set(origin.x, origin.y, -1);
291
318
  vec3.unproject(cam);
292
319
  origin = vec3;
293
320
  }
@@ -466,9 +493,15 @@ export class Physics {
466
493
  if (scale.z < 0)
467
494
  scale.z = Math.abs(scale.z);
468
495
 
496
+ // prevent zero scale - seems normals are flipped otherwise
497
+ if (scale.x == 0) scale.x = 0.0000001;
498
+ if (scale.y == 0) scale.y = 0.0000001;
499
+ if (scale.z == 0) scale.z = 0.0000001;
500
+
469
501
  const desc = ColliderDesc.cuboid(scale.x, scale.y, scale.z);
470
502
  // const objectLayerMask = collider.gameObject.layers.mask;
471
503
  // const mask = objectLayerMask & ~2;
504
+ // TODO: https://rapier.rs/docs/user_guides/javascript/colliders/#collision-groups-and-solver-groups
472
505
  // desc.setCollisionGroups(objectLayerMask);
473
506
  this.createCollider(collider, desc, center);
474
507
  }
@@ -612,6 +645,10 @@ export class Physics {
612
645
  col[$componentKey] = collider;
613
646
  collider[$bodyKey] = col;
614
647
  col.setActiveEvents(ActiveEvents.COLLISION_EVENTS);
648
+
649
+ // const objectLayerMask = collider.gameObject.layers.mask;
650
+ // const mask = objectLayerMask & ~2;
651
+ // col.setCollisionGroups(objectLayerMask);
615
652
  this.objects.push(collider);
616
653
  this.bodies.push(col);
617
654
  return col;
@@ -178,6 +178,7 @@ export declare interface ICamera extends IComponent {
178
178
  backgroundColor: RGBAColor | null;
179
179
  backgroundBlurriness: number | undefined;
180
180
  clearFlags: number;
181
+ cullingMask: number;
181
182
  aspect: number;
182
183
  fieldOfView?: number;
183
184
  screenPointToRay(x: number, y: number, ray?: Ray): Ray;
@@ -26,14 +26,10 @@ export class CircularBuffer<T> {
26
26
  }
27
27
 
28
28
  get(): T {
29
- let i = this._index++;
30
- if (i >= this._cache.length) {
31
- if (i >= this._maxSize) {
32
- i = this._index = 0;
33
- }
34
- else {
35
- this._cache.push(this._factory());
36
- }
29
+ const i = this._index % this._maxSize;
30
+ this._index++;
31
+ if (this._cache.length <= i) {
32
+ this._cache[i] = this._factory();
37
33
  }
38
34
  return this._cache[i];
39
35
  }
@@ -120,7 +120,7 @@ export class CharacterControllerInput extends Behaviour {
120
120
  // if (jumpDown) this._jumpDownTime = this.context.time.time;
121
121
  // const jumpUp = this.context.input.isKeyUp(" ");
122
122
 
123
- const step = forward ? 1 : 0 + backward ? -1 : 0;
123
+ const step = (forward ? 1 : 0) + (backward ? -1 : 0);
124
124
  this._currentSpeed.z += step * this.movementSpeed * this.context.time.deltaTime;
125
125
 
126
126
  // if (!this.controller || this.controller.isGrounded)
@@ -132,7 +132,7 @@ export class CharacterControllerInput extends Behaviour {
132
132
  if (this.controller) this.controller.move(this._temp);
133
133
  else this.gameObject.position.add(this._temp);
134
134
 
135
- const rotation = rotateLeft ? 1 : 0 + rotateRight ? -1 : 0;
135
+ const rotation = (rotateLeft ? 1 : 0) + (rotateRight ? -1 : 0);
136
136
  this._currentAngularSpeed.y += Mathf.toRadians(rotation * this.rotationSpeed) * this.context.time.deltaTime;
137
137
  if (this.lookForward && Math.abs(this._currentAngularSpeed.y) < .01) {
138
138
  const forwardVector = this.context.mainCameraComponent!.forward;
@@ -383,10 +383,9 @@ class DragHelper {
383
383
  onUpdate(_context: Context) {
384
384
  if (!this._context) return;
385
385
 
386
-
387
- const mainKey = KeyCode.SPACE;
388
- const secondaryKey = KeyCode.KEY_D;
389
- const scaleKey = KeyCode.KEY_S;
386
+ const mainKey: KeyCode = "Space";
387
+ const secondaryKey: KeyCode = "KeyD";
388
+ const scaleKey: KeyCode = "KeyS";
390
389
 
391
390
  const isRotateKeyPressed = this._context?.input.isKeyPressed(mainKey) || this._context?.input.isKeyPressed(secondaryKey);
392
391
  const isRotating = this._context.input.getTouchesPressedCount() >= 2 || isRotateKeyPressed;
@@ -7,7 +7,7 @@ import { AvatarMarker } from "./WebXRAvatar";
7
7
  import { XRStateFlag } from "./XRFlag";
8
8
  import { SmoothFollow } from "./SmoothFollow";
9
9
  import { Object3D } from "three";
10
- import { InputEvents, KeyCode } from "../engine/engine_input";
10
+ import { InputEvents } from "../engine/engine_input";
11
11
  import { Context } from "../engine/engine_setup";
12
12
  import { getParam } from "../engine/engine_utils";
13
13
  import { PlayerView, ViewDevice } from "../engine/engine_playerview";
@@ -390,10 +390,19 @@ export class WebXR extends Behaviour {
390
390
  if (this.context.mainCamera) {
391
391
  //@ts-ignore
392
392
  const cam = xr.getCamera(this.context.mainCamera) as ArrayCamera;
393
- for (const c of cam.cameras) {
394
- c.layers.enableAll();
393
+ const cull = this.context.mainCameraComponent?.cullingMask;
394
+ if(cull !== undefined){
395
+ for (const c of cam.cameras) {
396
+ c.layers.mask = cull;
397
+ }
398
+ cam.layers.mask = cull;
399
+ }
400
+ else {
401
+ for (const c of cam.cameras) {
402
+ c.layers.enableAll();
403
+ }
404
+ cam.layers.enableAll();
395
405
  }
396
-
397
406
  this.rig.add(this.context.mainCamera);
398
407
  if (this._requestedAR) {
399
408
  this.context.scene.add(this.rig);
@@ -769,7 +769,7 @@ export class WebXRController extends Behaviour {
769
769
  public raycast(): Intersection[] {
770
770
  const opts = new RaycastOptions();
771
771
  opts.layerMask = new Layers();
772
- opts.layerMask.set(0);
772
+ opts.layerMask.enableAll();
773
773
  opts.layerMask.disable(2);
774
774
  opts.ray = this.getRay();
775
775
  const hits = this.context.physics.raycast(opts);
@@ -7,7 +7,7 @@ import { Context } from "../../engine/engine_setup";
7
7
  import { OrbitControls } from "../OrbitControls";
8
8
  import { IPointerEventHandler, PointerEventData } from "./PointerEvents";
9
9
  import { Raycaster } from "./Raycaster";
10
- import { InputEvents, KeyCode } from "../../engine/engine_input";
10
+ import { InputEvents } from "../../engine/engine_input";
11
11
  import { Object3D } from "three";
12
12
  import { ICanvasGroup, IGraphic } from "./Interfaces";
13
13
  import { getParam } from "../../engine/engine_utils";
@@ -208,8 +208,7 @@ export class EventSystem extends Behaviour {
208
208
  this.resetMeshUIStates();
209
209
 
210
210
  if (WebXR.IsInWebXR) return;
211
- // console.log(this.context.input.isKeyPressed(KeyCode.ALT));
212
- if (this.context.input.isKeyPressed(KeyCode.ALT)) {
211
+ if (this.context.input.isKeyPressed("AltLeft") || this.context.input.isKeyPressed("AltRight")) {
213
212
  // console.log("alt pressed");
214
213
  return;
215
214
  }
@@ -3,10 +3,10 @@ import { KeyCode } from "../engine/engine_input";
3
3
 
4
4
  export class PresentationMode extends Behaviour {
5
5
 
6
- toggleKey : KeyCode = KeyCode.KEY_P;
6
+ toggleKey: KeyCode = "KeyP";
7
7
 
8
8
  update(): void {
9
- if (this.context.input.isKeyDown(KeyCode.KEY_P)) {
9
+ if (this.context.input.isKeyDown(this.toggleKey)) {
10
10
  this.context.domElement.classList.toggle("presentation-mode");
11
11
  }
12
12
  }