@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.
- package/CHANGELOG.md +4 -1
- package/dist/needle-engine.js +7706 -7641
- package/dist/needle-engine.min.js +262 -262
- package/dist/needle-engine.umd.cjs +280 -280
- package/lib/engine/engine_input.d.ts +5 -89
- package/lib/engine/engine_input.js +49 -103
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +5 -0
- package/lib/engine/engine_physics.js +39 -4
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_types.d.ts +1 -0
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_utils.js +4 -8
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine-components/CharacterController.js +2 -2
- package/lib/engine-components/CharacterController.js.map +1 -1
- package/lib/engine-components/DragControls.js +3 -4
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/WebXR.js +12 -2
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRController.js +1 -1
- package/lib/engine-components/WebXRController.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.js +1 -3
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/lib/engine-components-experimental/Presentation.js +2 -3
- package/lib/engine-components-experimental/Presentation.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/plugins/vite/alias.js +5 -2
- package/src/engine/engine_input.ts +134 -108
- package/src/engine/engine_physics.ts +41 -4
- package/src/engine/engine_types.ts +1 -0
- package/src/engine/engine_utils.ts +4 -8
- package/src/engine-components/CharacterController.ts +2 -2
- package/src/engine-components/DragControls.ts +3 -4
- package/src/engine-components/SpectatorCamera.ts +1 -1
- package/src/engine-components/WebXR.ts +12 -3
- package/src/engine-components/WebXRController.ts +1 -1
- package/src/engine-components/ui/EventSystem.ts +2 -3
- 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.
|
|
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
|
},
|
package/plugins/vite/alias.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
|
261
|
-
|
|
262
|
-
|
|
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:
|
|
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.
|
|
384
|
+
const ex = this.keysPressed[evt.code];
|
|
359
385
|
if (ex && ex.pressed) return;
|
|
360
|
-
this.keysPressed[evt.
|
|
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.
|
|
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.
|
|
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.
|
|
556
|
-
const dy = evt.
|
|
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
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
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 (
|
|
288
|
-
this.context.input.convertScreenspaceToRaycastSpace(
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
388
|
-
const
|
|
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
|
|
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
|
-
|
|
394
|
-
|
|
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.
|
|
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
|
|
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
|
-
|
|
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
|
|
6
|
+
toggleKey: KeyCode = "KeyP";
|
|
7
7
|
|
|
8
8
|
update(): void {
|
|
9
|
-
if (this.context.input.isKeyDown(
|
|
9
|
+
if (this.context.input.isKeyDown(this.toggleKey)) {
|
|
10
10
|
this.context.domElement.classList.toggle("presentation-mode");
|
|
11
11
|
}
|
|
12
12
|
}
|