@needle-tools/engine 2.35.5-pre → 2.37.0-pre
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 +31 -0
- package/dist/needle-engine.d.ts +312 -232
- package/dist/needle-engine.js +456 -437
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +81 -76
- package/dist/needle-engine.min.js.map +4 -4
- package/lib/engine/api.d.ts +1 -0
- package/lib/engine/api.js +1 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/debug/debug.d.ts +1 -0
- package/lib/engine/debug/debug.js +3 -0
- package/lib/engine/debug/debug.js.map +1 -1
- package/lib/engine/debug/debug_overlay.js +12 -1
- package/lib/engine/debug/debug_overlay.js.map +1 -1
- package/lib/engine/engine_element_loading.js +1 -1
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gameobject.d.ts +1 -0
- package/lib/engine/engine_gameobject.js +15 -2
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.js +4 -0
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.d.ts +1 -1
- package/lib/engine/engine_mainloop_utils.js +7 -3
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +49 -57
- package/lib/engine/engine_physics.js +464 -417
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_physics.types.d.ts +16 -0
- package/lib/engine/engine_physics.types.js +19 -0
- package/lib/engine/engine_physics.types.js.map +1 -0
- package/lib/engine/engine_serialization_core.d.ts +3 -0
- package/lib/engine/engine_serialization_core.js +19 -6
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_setup.js +4 -2
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_time.d.ts +1 -0
- package/lib/engine/engine_time.js +1 -0
- package/lib/engine/engine_time.js.map +1 -1
- package/lib/engine/engine_types.d.ts +46 -26
- package/lib/engine/engine_types.js +24 -37
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_typestore.d.ts +1 -0
- package/lib/engine/engine_typestore.js +1 -0
- package/lib/engine/engine_typestore.js.map +1 -1
- package/lib/engine/engine_util_decorator.d.ts +6 -0
- package/lib/engine/engine_util_decorator.js +54 -0
- package/lib/engine/engine_util_decorator.js.map +1 -0
- package/lib/engine/engine_utils.d.ts +1 -1
- package/lib/engine/engine_utils.js +2 -2
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_animator_controller_model.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_gameobject_data.js +2 -0
- package/lib/engine/extensions/NEEDLE_gameobject_data.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js +5 -0
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
- package/lib/engine-components/Animation.d.ts +5 -0
- package/lib/engine-components/Animation.js +14 -0
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/AnimatorController.d.ts +1 -0
- package/lib/engine-components/AnimatorController.js +14 -7
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.d.ts +2 -2
- package/lib/engine-components/BoxHelperComponent.js +28 -9
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +7 -2
- package/lib/engine-components/Collider.js +27 -15
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +8 -16
- package/lib/engine-components/Component.js +18 -117
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/DragControls.js +9 -6
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/GroundProjection.d.ts +2 -0
- package/lib/engine-components/GroundProjection.js +18 -6
- package/lib/engine-components/GroundProjection.js.map +1 -1
- package/lib/engine-components/NavMesh.d.ts +0 -5
- package/lib/engine-components/NavMesh.js +100 -10
- package/lib/engine-components/NavMesh.js.map +1 -1
- package/lib/engine-components/NestedGltf.js +2 -0
- package/lib/engine-components/NestedGltf.js.map +1 -1
- package/lib/engine-components/ReflectionProbe.d.ts +22 -0
- package/lib/engine-components/ReflectionProbe.js +134 -0
- package/lib/engine-components/ReflectionProbe.js.map +1 -0
- package/lib/engine-components/Renderer.d.ts +13 -2
- package/lib/engine-components/Renderer.js +96 -45
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +40 -25
- package/lib/engine-components/RigidBody.js +253 -142
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.js +1 -1
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.d.ts +1 -0
- package/lib/engine-components/SpectatorCamera.js +9 -2
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SpringJoint.d.ts +0 -13
- package/lib/engine-components/SpringJoint.js +42 -41
- package/lib/engine-components/SpringJoint.js.map +1 -1
- package/lib/engine-components/VideoPlayer.js.map +1 -1
- package/lib/engine-components/WebARSessionRoot.d.ts +7 -7
- package/lib/engine-components/WebARSessionRoot.js +7 -7
- package/lib/engine-components/WebARSessionRoot.js.map +1 -1
- package/lib/engine-components/WebXR.d.ts +10 -8
- package/lib/engine-components/WebXR.js +50 -26
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRAvatar.d.ts +4 -5
- package/lib/engine-components/WebXRAvatar.js +9 -8
- package/lib/engine-components/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/WebXRController.d.ts +21 -21
- package/lib/engine-components/WebXRController.js +90 -68
- package/lib/engine-components/WebXRController.js.map +1 -1
- package/lib/engine-components/WebXRGrabRendering.d.ts +3 -3
- package/lib/engine-components/WebXRGrabRendering.js +2 -2
- package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
- package/lib/engine-components/WebXRSync.d.ts +8 -8
- package/lib/engine-components/WebXRSync.js +15 -15
- package/lib/engine-components/WebXRSync.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +2 -3
- package/lib/engine-components/codegen/components.js +2 -3
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.d.ts +1 -0
- package/lib/engine-components/ui/EventSystem.js +21 -1
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/package.json +3 -4
- package/src/engine/api.ts +2 -1
- package/src/engine/codegen/register_types.js +291 -6
- package/src/engine/debug/debug.ts +4 -0
- package/src/engine/debug/debug_overlay.ts +9 -2
- package/src/engine/engine_element_loading.ts +1 -1
- package/src/engine/engine_gameobject.ts +19 -6
- package/src/engine/engine_gltf_builtin_components.ts +5 -1
- package/src/engine/engine_mainloop_utils.ts +7 -3
- package/src/engine/engine_physics.ts +508 -469
- package/src/engine/engine_physics.types.ts +19 -0
- package/src/engine/engine_serialization_core.ts +22 -8
- package/src/engine/engine_setup.ts +6 -2
- package/src/engine/engine_time.ts +2 -0
- package/src/engine/engine_types.ts +82 -55
- package/src/engine/engine_typestore.ts +2 -0
- package/src/engine/engine_util_decorator.ts +69 -0
- package/src/engine/engine_utils.ts +6 -5
- package/src/engine/extensions/EXT_texture_exr.js +1 -1
- package/src/engine/extensions/NEEDLE_animator_controller_model.ts +2 -1
- package/src/engine/extensions/NEEDLE_gameobject_data.ts +2 -0
- package/src/engine/extensions/NEEDLE_techniques_webgl.ts +7 -0
- package/src/engine-components/Animation.ts +14 -1
- package/src/engine-components/AnimatorController.ts +19 -9
- package/src/engine-components/BoxHelperComponent.ts +30 -9
- package/src/engine-components/Collider.ts +29 -29
- package/src/engine-components/Component.ts +26 -135
- package/src/engine-components/DragControls.ts +9 -5
- package/src/engine-components/GroundProjection.ts +22 -7
- package/src/engine-components/NavMesh.ts +114 -115
- package/src/engine-components/NestedGltf.ts +2 -0
- package/src/engine-components/ReflectionProbe.ts +141 -0
- package/src/engine-components/Renderer.ts +796 -737
- package/src/engine-components/RigidBody.ts +258 -149
- package/src/engine-components/SpatialTrigger.ts +1 -1
- package/src/engine-components/SpectatorCamera.ts +10 -2
- package/src/engine-components/SpringJoint.ts +41 -41
- package/src/engine-components/VideoPlayer.ts +1 -2
- package/src/engine-components/WebARSessionRoot.ts +16 -16
- package/src/engine-components/WebXR.ts +65 -50
- package/src/engine-components/WebXRAvatar.ts +16 -16
- package/src/engine-components/WebXRController.ts +143 -112
- package/src/engine-components/WebXRGrabRendering.ts +6 -6
- package/src/engine-components/WebXRSync.ts +20 -20
- package/src/engine-components/codegen/components.ts +2 -3
- package/src/engine-components/ui/EventSystem.ts +26 -3
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { WebXR } from "./WebXR";
|
|
3
|
-
import * as THREE from "three";
|
|
4
|
-
import { SyncedTransform } from "./SyncedTransform";
|
|
5
|
-
import { Physics, RaycastOptions } from "../engine/engine_physics";
|
|
6
|
-
import { XRControllerModel, XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
|
|
1
|
+
import { BoxHelper, BufferGeometry, Color, Euler, Group, Intersection, Layers, Line, LineBasicMaterial, Material, Mesh, MeshBasicMaterial, Object3D, PerspectiveCamera, Quaternion, Ray, SphereGeometry, Vector2, Vector3, XRInputSource, XRSession } from "three";
|
|
7
2
|
import { OculusHandModel } from 'three/examples/jsm/webxr/OculusHandModel.js';
|
|
8
3
|
import { OculusHandPointerModel } from 'three/examples/jsm/webxr/OculusHandPointerModel.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
4
|
+
import { XRControllerModel, XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
|
|
5
|
+
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
|
|
6
|
+
|
|
7
|
+
import { InstancingUtil } from "../engine/engine_instancing";
|
|
11
8
|
import { Mathf } from "../engine/engine_math";
|
|
12
|
-
import
|
|
9
|
+
import { RaycastOptions } from "../engine/engine_physics";
|
|
10
|
+
import { getWorldPosition, getWorldQuaternion, setWorldPosition, setWorldQuaternion } from "../engine/engine_three_utils";
|
|
11
|
+
import { getParam, getPath } from "../engine/engine_utils";
|
|
12
|
+
import { addDracoAndKTX2Loaders } from "../engine/engine_loaders";
|
|
13
|
+
|
|
14
|
+
import { Avatar_POI } from "./avatar/Avatar_Brain_LookAt";
|
|
15
|
+
import { Behaviour, GameObject } from "./Component";
|
|
13
16
|
import { Interactable, UsageMarker } from "./Interactable";
|
|
14
|
-
import { InstancingUtil } from "../engine/engine_instancing";
|
|
15
17
|
import { Rigidbody } from "./RigidBody";
|
|
16
|
-
import {
|
|
18
|
+
import { SyncedTransform } from "./SyncedTransform";
|
|
17
19
|
import { UIRaycastUtils } from "./ui/RaycastUtils";
|
|
18
|
-
import {
|
|
20
|
+
import { WebXR } from "./WebXR";
|
|
19
21
|
|
|
20
22
|
const debug = getParam("debugwebxrcontroller");
|
|
21
23
|
|
|
@@ -38,28 +40,28 @@ export class WebXRController extends Behaviour {
|
|
|
38
40
|
|
|
39
41
|
public static Factory: XRControllerModelFactory = new XRControllerModelFactory();
|
|
40
42
|
|
|
41
|
-
private static raycastColor:
|
|
42
|
-
private static raycastNoHitColor:
|
|
43
|
-
private static geometry = new
|
|
43
|
+
private static raycastColor: Color = new Color(.9, .3, .3);
|
|
44
|
+
private static raycastNoHitColor: Color = new Color(.6, .6, .6);
|
|
45
|
+
private static geometry = new BufferGeometry().setFromPoints([new Vector3(0, 0, 0), new Vector3(0, 0, -1)]);
|
|
44
46
|
private static handModels: { [index: number]: OculusHandPointerModel } = {};
|
|
45
47
|
|
|
46
|
-
private static CreateRaycastLine():
|
|
47
|
-
const line = new
|
|
48
|
-
const mat = line.material as
|
|
48
|
+
private static CreateRaycastLine(): Line {
|
|
49
|
+
const line = new Line(this.geometry);
|
|
50
|
+
const mat = line.material as LineBasicMaterial;
|
|
49
51
|
mat.color = this.raycastColor;
|
|
50
52
|
// mat.linewidth = 10;
|
|
51
|
-
line.layers.set(
|
|
53
|
+
line.layers.set(2);
|
|
52
54
|
line.name = 'line';
|
|
53
55
|
line.scale.z = 1;
|
|
54
56
|
return line;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
private static CreateRaycastHitPoint():
|
|
58
|
-
const geometry = new
|
|
59
|
-
const material = new
|
|
60
|
-
const sphere = new
|
|
59
|
+
private static CreateRaycastHitPoint(): Mesh {
|
|
60
|
+
const geometry = new SphereGeometry(.5, 22, 22);
|
|
61
|
+
const material = new MeshBasicMaterial({ color: this.raycastColor });
|
|
62
|
+
const sphere = new Mesh(geometry, material);
|
|
61
63
|
sphere.visible = false;
|
|
62
|
-
sphere.layers.set(
|
|
64
|
+
sphere.layers.set(2);
|
|
63
65
|
return sphere;
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -71,7 +73,7 @@ export class WebXRController extends Behaviour {
|
|
|
71
73
|
ctrl.type = type;
|
|
72
74
|
|
|
73
75
|
const context = owner.context;
|
|
74
|
-
// from https://github.com/mrdoob/
|
|
76
|
+
// from https://github.com/mrdoob/js/blob/master/examples/webxr_vr_dragging.html
|
|
75
77
|
// controllers
|
|
76
78
|
ctrl.controller = context.renderer.xr.getController(index);
|
|
77
79
|
ctrl.controllerGrip = context.renderer.xr.getControllerGrip(index);
|
|
@@ -79,25 +81,34 @@ export class WebXRController extends Behaviour {
|
|
|
79
81
|
ctrl.controllerGrip.add(ctrl.controllerModel);
|
|
80
82
|
|
|
81
83
|
ctrl.hand = context.renderer.xr.getHand(index);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
|
|
85
|
+
const loader = new GLTFLoader();
|
|
86
|
+
addDracoAndKTX2Loaders(loader, context);
|
|
87
|
+
if (ctrl.webXR.handModelPath && ctrl.webXR.handModelPath !== "")
|
|
88
|
+
loader.setPath("/" + getPath(owner.sourceId, ctrl.webXR.handModelPath));
|
|
89
|
+
//@ts-ignore
|
|
90
|
+
const hand = new OculusHandModel(ctrl.hand, loader);
|
|
91
|
+
|
|
84
92
|
ctrl.hand.add(hand);
|
|
85
93
|
ctrl.hand.traverse(x => x.layers.set(2));
|
|
86
94
|
|
|
87
95
|
ctrl.handPointerModel = new OculusHandPointerModel(ctrl.hand, ctrl.controller);
|
|
88
96
|
|
|
89
97
|
|
|
90
|
-
// TODO remove all these once https://github.com/mrdoob/
|
|
98
|
+
// TODO remove all these once https://github.com/mrdoob/js/pull/23279 lands
|
|
91
99
|
ctrl.controller.addEventListener('connected', (_) => {
|
|
92
100
|
ctrl.setControllerLayers(ctrl.controllerModel, 2);
|
|
93
101
|
ctrl.setControllerLayers(ctrl.controllerGrip, 2);
|
|
102
|
+
ctrl.setControllerLayers(ctrl.hand, 2);
|
|
94
103
|
setTimeout(() => {
|
|
104
|
+
ctrl.setControllerLayers(ctrl.controllerModel, 2);
|
|
95
105
|
ctrl.setControllerLayers(ctrl.controllerGrip, 2);
|
|
106
|
+
ctrl.setControllerLayers(ctrl.hand, 2);
|
|
96
107
|
}, 1000);
|
|
97
108
|
});
|
|
98
109
|
|
|
99
110
|
// TODO: unsubscribe! this should be moved into onenable and ondisable!
|
|
100
|
-
// TODO remove all these once https://github.com/mrdoob/
|
|
111
|
+
// TODO remove all these once https://github.com/mrdoob/js/pull/23279 lands
|
|
101
112
|
ctrl.hand.addEventListener('connected', (event) => {
|
|
102
113
|
const xrInputSource = event.data;
|
|
103
114
|
if (xrInputSource.hand) {
|
|
@@ -144,12 +155,12 @@ export class WebXRController extends Behaviour {
|
|
|
144
155
|
public webXR!: WebXR;
|
|
145
156
|
public index: number = -1;
|
|
146
157
|
public controllerModel!: XRControllerModel;
|
|
147
|
-
public controller!:
|
|
148
|
-
public controllerGrip!:
|
|
149
|
-
public hand!:
|
|
158
|
+
public controller!: Group;
|
|
159
|
+
public controllerGrip!: Group;
|
|
160
|
+
public hand!: Group;
|
|
150
161
|
public handPointerModel!: OculusHandPointerModel;
|
|
151
162
|
public grabbed: AttachedObject | null = null;
|
|
152
|
-
public input:
|
|
163
|
+
public input: XRInputSource | null = null;
|
|
153
164
|
public type: ControllerType = ControllerType.PhysicalDevice;
|
|
154
165
|
|
|
155
166
|
get isUsingHands(): boolean {
|
|
@@ -157,35 +168,35 @@ export class WebXRController extends Behaviour {
|
|
|
157
168
|
return r !== null && r !== undefined;
|
|
158
169
|
}
|
|
159
170
|
|
|
160
|
-
get wrist():
|
|
171
|
+
get wrist(): Object3D | null {
|
|
161
172
|
if (!this.hand) return null;
|
|
162
173
|
const jnts = this.hand["joints"];
|
|
163
174
|
if (!jnts) return null;
|
|
164
175
|
return jnts["wrist"];
|
|
165
176
|
}
|
|
166
177
|
|
|
167
|
-
private _wristQuaternion:
|
|
168
|
-
getWristQuaternion():
|
|
178
|
+
private _wristQuaternion: Quaternion | null = null;
|
|
179
|
+
getWristQuaternion(): Quaternion | null {
|
|
169
180
|
const wrist = this.wrist;
|
|
170
181
|
if (!wrist) return null;
|
|
171
|
-
if (!this._wristQuaternion) this._wristQuaternion = new
|
|
172
|
-
const wr =
|
|
182
|
+
if (!this._wristQuaternion) this._wristQuaternion = new Quaternion();
|
|
183
|
+
const wr = getWorldQuaternion(wrist).multiply(this._wristQuaternion.setFromEuler(new Euler(-Math.PI / 4, 0, 0)));
|
|
173
184
|
return wr;
|
|
174
185
|
}
|
|
175
186
|
|
|
176
|
-
private movementVector:
|
|
177
|
-
private worldRot:
|
|
178
|
-
private joystick:
|
|
187
|
+
private movementVector: Vector3 = new Vector3();
|
|
188
|
+
private worldRot: Quaternion = new Quaternion();
|
|
189
|
+
private joystick: Vector2 = new Vector2();
|
|
179
190
|
private didRotate: boolean = false;
|
|
180
191
|
private didTeleport: boolean = false;
|
|
181
192
|
private didChangeScale: boolean = false;
|
|
182
193
|
private static PreviousCameraFarDistance: number | undefined = undefined;
|
|
183
194
|
private static MovementSpeedFactor: number = 1;
|
|
184
195
|
|
|
185
|
-
private lastHit:
|
|
196
|
+
private lastHit: Intersection | null = null;
|
|
186
197
|
|
|
187
|
-
private raycastLine:
|
|
188
|
-
private _raycastHitPoint:
|
|
198
|
+
private raycastLine: Line | null = null;
|
|
199
|
+
private _raycastHitPoint: Object3D | null = null;
|
|
189
200
|
private _connnectedCallback: any | null = null;
|
|
190
201
|
private _disconnectedCallback: any | null = null;
|
|
191
202
|
private _selectStartEvt: any | null = null;
|
|
@@ -195,7 +206,7 @@ export class WebXRController extends Behaviour {
|
|
|
195
206
|
public get selectionUp(): boolean { return !this._selectionPressed && this._selectionPressedLastFrame; }
|
|
196
207
|
public get selectionPressed(): boolean { return this._selectionPressed; }
|
|
197
208
|
public get selectionClick(): boolean { return this._selectionEndTime - this._selectionStartTime < 0.3; }
|
|
198
|
-
public get raycastHitPoint():
|
|
209
|
+
public get raycastHitPoint(): Object3D | null { return this._raycastHitPoint; }
|
|
199
210
|
|
|
200
211
|
private _selectionPressed: boolean = false;
|
|
201
212
|
private _selectionPressedLastFrame: boolean = false;
|
|
@@ -336,7 +347,7 @@ export class WebXRController extends Behaviour {
|
|
|
336
347
|
}
|
|
337
348
|
}
|
|
338
349
|
|
|
339
|
-
rayRotation:
|
|
350
|
+
rayRotation: Quaternion = new Quaternion();
|
|
340
351
|
|
|
341
352
|
update(): void {
|
|
342
353
|
|
|
@@ -357,8 +368,13 @@ export class WebXRController extends Behaviour {
|
|
|
357
368
|
let t = 1;
|
|
358
369
|
if (this.type === ControllerType.PhysicalDevice) t = this.context.time.deltaTime / .1;
|
|
359
370
|
else if (this.isUsingHands && this.handPointerModel.pinched) t = this.context.time.deltaTime / .3;
|
|
360
|
-
this.rayRotation.slerp(
|
|
361
|
-
const wp =
|
|
371
|
+
this.rayRotation.slerp(getWorldQuaternion(this.controller), this.useSmoothing ? t : 1.0);
|
|
372
|
+
const wp = getWorldPosition(this.controller);
|
|
373
|
+
|
|
374
|
+
// hide hand pointer model, it's giant and doesn't really help
|
|
375
|
+
if (this.isUsingHands && this.handPointerModel.cursorObject) {
|
|
376
|
+
this.handPointerModel.cursorObject.visible = false;
|
|
377
|
+
}
|
|
362
378
|
|
|
363
379
|
if (this.raycastLine) {
|
|
364
380
|
if (this.type === ControllerType.Touch) {
|
|
@@ -366,7 +382,7 @@ export class WebXRController extends Behaviour {
|
|
|
366
382
|
}
|
|
367
383
|
else if (this.isUsingHands) {
|
|
368
384
|
this.raycastLine.visible = !this.grabbed;
|
|
369
|
-
|
|
385
|
+
setWorldPosition(this.raycastLine, wp);
|
|
370
386
|
const jnts = this.hand!['joints'];
|
|
371
387
|
if (jnts) {
|
|
372
388
|
const wrist = jnts['wrist'];
|
|
@@ -377,12 +393,12 @@ export class WebXRController extends Behaviour {
|
|
|
377
393
|
// this.rayRotation.slerp(wr, this.useSmoothing ? t * 2 : 1);
|
|
378
394
|
}
|
|
379
395
|
}
|
|
380
|
-
|
|
396
|
+
setWorldQuaternion(this.raycastLine, this.rayRotation);
|
|
381
397
|
}
|
|
382
398
|
else {
|
|
383
399
|
this.raycastLine.visible = true;
|
|
384
|
-
|
|
385
|
-
|
|
400
|
+
setWorldQuaternion(this.raycastLine, this.rayRotation);
|
|
401
|
+
setWorldPosition(this.raycastLine, wp);
|
|
386
402
|
}
|
|
387
403
|
}
|
|
388
404
|
|
|
@@ -480,8 +496,8 @@ export class WebXRController extends Behaviour {
|
|
|
480
496
|
if (pinched && this._pinchStartTime && this.context.time.time - this._pinchStartTime > .8) {
|
|
481
497
|
// hacky approach for basic hand teleportation -
|
|
482
498
|
// we teleport if we pinch and the back of the hand points down (open hand gesture)
|
|
483
|
-
// const v1 = new
|
|
484
|
-
// const worldQuaternion = new
|
|
499
|
+
// const v1 = new Vector3();
|
|
500
|
+
// const worldQuaternion = new Quaternion();
|
|
485
501
|
// this.controller.getWorldQuaternion(worldQuaternion);
|
|
486
502
|
// v1.copy(this.controller.up).applyQuaternion(worldQuaternion);
|
|
487
503
|
// const dotPr = -v1.dot(this.controller.up);
|
|
@@ -510,7 +526,7 @@ export class WebXRController extends Behaviour {
|
|
|
510
526
|
doTeleport = true;
|
|
511
527
|
newRigScale = .1;
|
|
512
528
|
WebXRController.MovementSpeedFactor = newRigScale * 2;
|
|
513
|
-
const cam = this.context.mainCamera as
|
|
529
|
+
const cam = this.context.mainCamera as PerspectiveCamera;
|
|
514
530
|
WebXRController.PreviousCameraFarDistance = cam.far;
|
|
515
531
|
cam.far /= newRigScale;
|
|
516
532
|
}
|
|
@@ -519,7 +535,7 @@ export class WebXRController extends Behaviour {
|
|
|
519
535
|
rig.scale.set(1, 1, 1);
|
|
520
536
|
newRigScale = 1;
|
|
521
537
|
WebXRController.MovementSpeedFactor = 1;
|
|
522
|
-
const cam = this.context.mainCamera as
|
|
538
|
+
const cam = this.context.mainCamera as PerspectiveCamera;
|
|
523
539
|
if (WebXRController.PreviousCameraFarDistance)
|
|
524
540
|
cam.far = WebXRController.PreviousCameraFarDistance;
|
|
525
541
|
}
|
|
@@ -539,7 +555,7 @@ export class WebXRController extends Behaviour {
|
|
|
539
555
|
const hit = rc[0];
|
|
540
556
|
if (isInMiniatureMode || this.isValidTeleportTarget(hit.object)) {
|
|
541
557
|
const point = hit.point;
|
|
542
|
-
|
|
558
|
+
setWorldPosition(rig, point);
|
|
543
559
|
}
|
|
544
560
|
}
|
|
545
561
|
}
|
|
@@ -554,17 +570,17 @@ export class WebXRController extends Behaviour {
|
|
|
554
570
|
}
|
|
555
571
|
}
|
|
556
572
|
|
|
557
|
-
private isValidTeleportTarget(obj:
|
|
573
|
+
private isValidTeleportTarget(obj: Object3D): boolean {
|
|
558
574
|
return GameObject.getComponentInParent(obj, TeleportTarget) != null;
|
|
559
575
|
}
|
|
560
576
|
|
|
561
|
-
private updateStick(inputSource:
|
|
577
|
+
private updateStick(inputSource: XRInputSource) {
|
|
562
578
|
if (!inputSource || !inputSource.gamepad || inputSource.gamepad.axes?.length < 4) return;
|
|
563
579
|
this.joystick.x = inputSource.gamepad.axes[2];
|
|
564
580
|
this.joystick.y = inputSource.gamepad.axes[3];
|
|
565
581
|
}
|
|
566
582
|
|
|
567
|
-
private updateLastHit():
|
|
583
|
+
private updateLastHit(): Intersection | null {
|
|
568
584
|
const rc = this.raycast();
|
|
569
585
|
const hit = rc ? rc[0] : null;
|
|
570
586
|
this.lastHit = hit;
|
|
@@ -576,7 +592,7 @@ export class WebXRController extends Behaviour {
|
|
|
576
592
|
|
|
577
593
|
if (this.raycastLine) {
|
|
578
594
|
this.raycastLine.scale.z = factor * (this.lastHit?.distance ?? 9999);
|
|
579
|
-
const mat = this.raycastLine.material as
|
|
595
|
+
const mat = this.raycastLine.material as LineBasicMaterial;
|
|
580
596
|
if (hit != null) mat.color = WebXRController.raycastColor;
|
|
581
597
|
else mat.color = WebXRController.raycastNoHitColor;
|
|
582
598
|
}
|
|
@@ -603,7 +619,7 @@ export class WebXRController extends Behaviour {
|
|
|
603
619
|
}
|
|
604
620
|
|
|
605
621
|
private selectStartCallback: Function | null = null;
|
|
606
|
-
private lastSelectStartObject:
|
|
622
|
+
private lastSelectStartObject: Object3D | null = null;;
|
|
607
623
|
|
|
608
624
|
private onHandleSelectStart() {
|
|
609
625
|
this.selectStartCallback = null;
|
|
@@ -613,7 +629,7 @@ export class WebXRController extends Behaviour {
|
|
|
613
629
|
// console.log("DOWN", this.index, WebXRController.eventSubs);
|
|
614
630
|
|
|
615
631
|
// let maxDistance = this.isUsingHands ? .1 : undefined;
|
|
616
|
-
let intersections:
|
|
632
|
+
let intersections: Intersection[] | null = null;
|
|
617
633
|
let closeGrab: boolean = false;
|
|
618
634
|
if (this.isUsingHands) {
|
|
619
635
|
intersections = this.overlap();
|
|
@@ -627,14 +643,12 @@ export class WebXRController extends Behaviour {
|
|
|
627
643
|
}
|
|
628
644
|
else intersections = this.raycast();
|
|
629
645
|
|
|
646
|
+
if (debug)
|
|
647
|
+
console.log("onHandleSelectStart", "close grab? " + closeGrab, "intersections", intersections);
|
|
648
|
+
|
|
630
649
|
if (intersections && intersections.length > 0) {
|
|
631
650
|
for (const intersection of intersections) {
|
|
632
651
|
const object = intersection.object;
|
|
633
|
-
// if (!this.testIsVisible(object)) {
|
|
634
|
-
// if (debug)
|
|
635
|
-
// console.log("not visible");
|
|
636
|
-
// continue;
|
|
637
|
-
// }
|
|
638
652
|
this.lastSelectStartObject = object;
|
|
639
653
|
const args = { selected: object, grab: object };
|
|
640
654
|
const subs = WebXRController.eventSubs[ControllerEvents.SelectStart];
|
|
@@ -691,7 +705,7 @@ export class WebXRController extends Behaviour {
|
|
|
691
705
|
}
|
|
692
706
|
}
|
|
693
707
|
|
|
694
|
-
private testIsVisible(obj:
|
|
708
|
+
private testIsVisible(obj: Object3D | null): boolean {
|
|
695
709
|
if (!obj) return false;
|
|
696
710
|
if (GameObject.isActiveInHierarchy(obj) === false) return false;
|
|
697
711
|
if (UIRaycastUtils.isInteractable(obj) === false) {
|
|
@@ -702,7 +716,7 @@ export class WebXRController extends Behaviour {
|
|
|
702
716
|
// return this.testIsVisible(obj.parent);
|
|
703
717
|
}
|
|
704
718
|
|
|
705
|
-
private setControllerLayers(obj:
|
|
719
|
+
private setControllerLayers(obj: Object3D, layer: number) {
|
|
706
720
|
if (!obj) return;
|
|
707
721
|
obj.layers.set(layer);
|
|
708
722
|
if (obj.children) {
|
|
@@ -715,28 +729,43 @@ export class WebXRController extends Behaviour {
|
|
|
715
729
|
}
|
|
716
730
|
}
|
|
717
731
|
|
|
718
|
-
public getRay():
|
|
719
|
-
const ray = new
|
|
732
|
+
public getRay(): Ray {
|
|
733
|
+
const ray = new Ray();
|
|
720
734
|
// this.tempMatrix.identity().extractRotation(this.controller.matrixWorld);
|
|
721
735
|
// ray.origin.setFromMatrixPosition(this.controller.matrixWorld);
|
|
722
|
-
ray.origin.copy(
|
|
736
|
+
ray.origin.copy(getWorldPosition(this.controller));
|
|
723
737
|
ray.direction.set(0, 0, -1).applyQuaternion(this.rayRotation);
|
|
724
738
|
return ray;
|
|
725
739
|
}
|
|
726
740
|
|
|
727
|
-
|
|
741
|
+
private closeGrabBoundingBoxHelper?: BoxHelper;
|
|
742
|
+
|
|
743
|
+
public overlap(): Intersection[] {
|
|
728
744
|
const overlapCenter = (this.isUsingHands && this.handPointerModel) ? this.handPointerModel.pointerObject : this.controllerGrip;
|
|
745
|
+
|
|
746
|
+
if (debug) {
|
|
747
|
+
if (!this.closeGrabBoundingBoxHelper && overlapCenter) {
|
|
748
|
+
this.closeGrabBoundingBoxHelper = new BoxHelper(overlapCenter, 0xffff00);
|
|
749
|
+
this.scene.add(this.closeGrabBoundingBoxHelper);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if (this.closeGrabBoundingBoxHelper && overlapCenter) {
|
|
753
|
+
this.closeGrabBoundingBoxHelper.setFromObject(overlapCenter);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
729
757
|
if (!overlapCenter)
|
|
730
|
-
return new Array<
|
|
758
|
+
return new Array<Intersection>();
|
|
731
759
|
|
|
732
|
-
const wp =
|
|
760
|
+
const wp = getWorldPosition(overlapCenter).clone();
|
|
733
761
|
return this.context.physics.sphereOverlap(wp, .02);
|
|
734
762
|
}
|
|
735
763
|
|
|
736
|
-
public raycast():
|
|
764
|
+
public raycast(): Intersection[] {
|
|
737
765
|
const opts = new RaycastOptions();
|
|
738
|
-
opts.layerMask = new
|
|
766
|
+
opts.layerMask = new Layers();
|
|
739
767
|
opts.layerMask.set(0);
|
|
768
|
+
opts.layerMask.disable(2);
|
|
740
769
|
opts.ray = this.getRay();
|
|
741
770
|
const hits = this.context.physics.raycast(opts);
|
|
742
771
|
for (let i = 0; i < hits.length; i++) {
|
|
@@ -795,7 +824,7 @@ export class AttachedObject {
|
|
|
795
824
|
}
|
|
796
825
|
}
|
|
797
826
|
|
|
798
|
-
public static TryTake(controller: WebXRController, candidate:
|
|
827
|
+
public static TryTake(controller: WebXRController, candidate: Object3D, intersection: Intersection, closeGrab: boolean): AttachedObject | null {
|
|
799
828
|
const interactable = GameObject.getComponentInParent(candidate, Interactable);
|
|
800
829
|
if (!interactable) {
|
|
801
830
|
if (debug)
|
|
@@ -803,7 +832,7 @@ export class AttachedObject {
|
|
|
803
832
|
return null;
|
|
804
833
|
}
|
|
805
834
|
else candidate = interactable.gameObject;
|
|
806
|
-
|
|
835
|
+
|
|
807
836
|
|
|
808
837
|
let objectToAttach = candidate;
|
|
809
838
|
const sync = GameObject.getComponentInParent(candidate, SyncedTransform);
|
|
@@ -828,24 +857,24 @@ export class AttachedObject {
|
|
|
828
857
|
|
|
829
858
|
|
|
830
859
|
public sync: SyncedTransform | null = null;
|
|
831
|
-
public selected:
|
|
832
|
-
public selectedParent:
|
|
833
|
-
public selectedMesh:
|
|
860
|
+
public selected: Object3D | null = null;
|
|
861
|
+
public selectedParent: Object3D | null = null;
|
|
862
|
+
public selectedMesh: Mesh | null = null;
|
|
834
863
|
public controller: WebXRController | null = null;
|
|
835
864
|
public grabTime: number = 0;
|
|
836
865
|
public grabUUID: string = "";
|
|
837
866
|
public isCloseGrab: boolean = false; // when taken via sphere cast with hands
|
|
838
867
|
|
|
839
|
-
private originalMaterial:
|
|
868
|
+
private originalMaterial: Material | Material[] | null = null;
|
|
840
869
|
private usageMarker: UsageMarker | null = null;
|
|
841
870
|
private rigidbodies: Rigidbody[] | null = null;
|
|
842
871
|
private didReparent: boolean = false;
|
|
843
872
|
private grabDistance: number = 0;
|
|
844
873
|
private interactable: Interactable | null = null;
|
|
845
|
-
private positionSource:
|
|
874
|
+
private positionSource: Object3D | null = null;
|
|
846
875
|
|
|
847
|
-
private Take(controller: WebXRController, take:
|
|
848
|
-
intersection:
|
|
876
|
+
private Take(controller: WebXRController, take: Object3D, hit: Object3D, sync: SyncedTransform | null, _interactable: Interactable,
|
|
877
|
+
intersection: Intersection, closeGrab: boolean)
|
|
849
878
|
: AttachedObject {
|
|
850
879
|
console.assert(take !== null, "Expected object to be taken but was", take);
|
|
851
880
|
|
|
@@ -864,11 +893,11 @@ export class AttachedObject {
|
|
|
864
893
|
AttachedObject.Events.WillTake?.forEach(x => x(this, args));
|
|
865
894
|
|
|
866
895
|
|
|
867
|
-
const mesh = hit as
|
|
896
|
+
const mesh = hit as Mesh;
|
|
868
897
|
if (mesh?.material) {
|
|
869
898
|
this.originalMaterial = mesh.material;
|
|
870
899
|
if (!Array.isArray(mesh.material)) {
|
|
871
|
-
mesh.material = (mesh.material as
|
|
900
|
+
mesh.material = (mesh.material as Material).clone();
|
|
872
901
|
if (mesh.material && mesh.material["emissive"])
|
|
873
902
|
mesh.material["emissive"].b = .2;
|
|
874
903
|
}
|
|
@@ -895,7 +924,7 @@ export class AttachedObject {
|
|
|
895
924
|
this.grabUUID = Date.now().toString();
|
|
896
925
|
this.usageMarker = GameObject.addNewComponent(this.selected, UsageMarker);
|
|
897
926
|
this.rigidbodies = GameObject.getComponentsInChildren(this.selected, Rigidbody);
|
|
898
|
-
|
|
927
|
+
getWorldPosition(this.positionSource, this.lastControllerWorldPos);
|
|
899
928
|
const getGrabPoint = () => closeGrab ? this.lastControllerWorldPos.clone() : intersection.point.clone();
|
|
900
929
|
this.grabDistance = getGrabPoint().distanceTo(this.lastControllerWorldPos);
|
|
901
930
|
this.totalChangeAlongDirection = 0.0;
|
|
@@ -904,11 +933,11 @@ export class AttachedObject {
|
|
|
904
933
|
// we're storing rotation relative to the ray
|
|
905
934
|
this.localPositionOffsetToGrab = this.selected.worldToLocal(getGrabPoint());
|
|
906
935
|
const rot = controller.isUsingHands && closeGrab ? this.controller.getWristQuaternion()!.clone() : controller.rayRotation.clone();
|
|
907
|
-
|
|
936
|
+
getWorldQuaternion(this.selected, this.localQuaternionToGrab).premultiply(rot.invert());
|
|
908
937
|
|
|
909
938
|
const rig = this.controller.webXR.Rig;
|
|
910
939
|
if (rig)
|
|
911
|
-
this.rigPositionLastFrame.copy(
|
|
940
|
+
this.rigPositionLastFrame.copy(getWorldPosition(rig))
|
|
912
941
|
|
|
913
942
|
Avatar_POI.Add(controller.context, this.selected);
|
|
914
943
|
AttachedObject.Register(this);
|
|
@@ -959,12 +988,11 @@ export class AttachedObject {
|
|
|
959
988
|
this.sync = null;
|
|
960
989
|
|
|
961
990
|
|
|
962
|
-
// TODO:
|
|
991
|
+
// TODO: make throwing work again
|
|
963
992
|
if (this.rigidbodies) {
|
|
964
993
|
for (const rb of this.rigidbodies) {
|
|
965
994
|
rb.wakeUp();
|
|
966
|
-
|
|
967
|
-
rb.setVelocity(rb.smoothedVelocity.x, rb.smoothedVelocity.y, rb.smoothedVelocity.z);
|
|
995
|
+
rb.setVelocity(rb.smoothedVelocity);
|
|
968
996
|
}
|
|
969
997
|
}
|
|
970
998
|
this.rigidbodies = null;
|
|
@@ -975,20 +1003,20 @@ export class AttachedObject {
|
|
|
975
1003
|
AttachedObject.Events.DidFree?.forEach(x => x(this, args));
|
|
976
1004
|
}
|
|
977
1005
|
|
|
978
|
-
public grabPoint:
|
|
1006
|
+
public grabPoint: Vector3 = new Vector3();
|
|
979
1007
|
|
|
980
|
-
private localPositionOffsetToGrab:
|
|
981
|
-
private localPositionOffsetToGrab_worldSpace:
|
|
982
|
-
private localQuaternionToGrab:
|
|
983
|
-
private targetDir:
|
|
984
|
-
private quaternionLerp:
|
|
1008
|
+
private localPositionOffsetToGrab: Vector3 | null = null;
|
|
1009
|
+
private localPositionOffsetToGrab_worldSpace: Vector3 = new Vector3();
|
|
1010
|
+
private localQuaternionToGrab: Quaternion = new Quaternion(0, 0, 0, 1);
|
|
1011
|
+
private targetDir: Vector3 | null = null;
|
|
1012
|
+
private quaternionLerp: Quaternion | null = null;
|
|
985
1013
|
|
|
986
|
-
private controllerDir = new
|
|
987
|
-
private controllerWorldPos = new
|
|
988
|
-
private lastControllerWorldPos = new
|
|
989
|
-
private controllerPosDelta = new
|
|
1014
|
+
private controllerDir = new Vector3();
|
|
1015
|
+
private controllerWorldPos = new Vector3();
|
|
1016
|
+
private lastControllerWorldPos = new Vector3();
|
|
1017
|
+
private controllerPosDelta = new Vector3();
|
|
990
1018
|
private totalChangeAlongDirection = 0.0;
|
|
991
|
-
private rigPositionLastFrame = new
|
|
1019
|
+
private rigPositionLastFrame = new Vector3();
|
|
992
1020
|
|
|
993
1021
|
private controllerMovementSinceLastFrame() {
|
|
994
1022
|
if (!this.positionSource || !this.controller) return 0.0;
|
|
@@ -998,13 +1026,13 @@ export class AttachedObject {
|
|
|
998
1026
|
this.controllerDir.applyQuaternion(this.controller.rayRotation);
|
|
999
1027
|
|
|
1000
1028
|
// controller delta
|
|
1001
|
-
|
|
1029
|
+
getWorldPosition(this.positionSource, this.controllerWorldPos);
|
|
1002
1030
|
this.controllerPosDelta.copy(this.controllerWorldPos);
|
|
1003
1031
|
this.controllerPosDelta.sub(this.lastControllerWorldPos);
|
|
1004
1032
|
this.lastControllerWorldPos.copy(this.controllerWorldPos);
|
|
1005
1033
|
const rig = this.controller.webXR.Rig;
|
|
1006
1034
|
if (rig) {
|
|
1007
|
-
const rigPos =
|
|
1035
|
+
const rigPos = getWorldPosition(rig);
|
|
1008
1036
|
const rigDelta = this.rigPositionLastFrame.sub(rigPos);
|
|
1009
1037
|
this.controllerPosDelta.add(rigDelta);
|
|
1010
1038
|
this.rigPositionLastFrame.copy(rigPos);
|
|
@@ -1017,6 +1045,9 @@ export class AttachedObject {
|
|
|
1017
1045
|
}
|
|
1018
1046
|
|
|
1019
1047
|
public update() {
|
|
1048
|
+
if (this.rigidbodies)
|
|
1049
|
+
for (const rb of this.rigidbodies)
|
|
1050
|
+
rb.resetVelocities();
|
|
1020
1051
|
// TODO: add/use sync lost ownership event
|
|
1021
1052
|
if (this.sync && this.controller && this.controller.context.connection.isInRoom) {
|
|
1022
1053
|
const td = this.controller.context.time.time - this.grabTime;
|
|
@@ -1052,7 +1083,7 @@ export class AttachedObject {
|
|
|
1052
1083
|
if (this.grabDistance / rigScale < 0.8) currentDist = 1.0; // don't accelerate if this is a close grab, want full control
|
|
1053
1084
|
|
|
1054
1085
|
if (!this.targetDir) {
|
|
1055
|
-
this.targetDir = new
|
|
1086
|
+
this.targetDir = new Vector3();
|
|
1056
1087
|
}
|
|
1057
1088
|
this.targetDir.set(0, 0, -this.grabDistance * currentDist);
|
|
1058
1089
|
const target = this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos);
|
|
@@ -1063,7 +1094,7 @@ export class AttachedObject {
|
|
|
1063
1094
|
this.quaternionLerp = targetQuat.clone();
|
|
1064
1095
|
}
|
|
1065
1096
|
this.quaternionLerp.slerp(targetQuat, this.controller.useSmoothing ? this.controller.context.time.deltaTime / .03 : 1.0);
|
|
1066
|
-
|
|
1097
|
+
setWorldQuaternion(this.selected, this.quaternionLerp);
|
|
1067
1098
|
this.selected.updateWorldMatrix(false, false); // necessary so that rotation is correct for the following position update
|
|
1068
1099
|
|
|
1069
1100
|
// apply position
|
|
@@ -1071,10 +1102,10 @@ export class AttachedObject {
|
|
|
1071
1102
|
// apply local grab offset
|
|
1072
1103
|
if (this.localPositionOffsetToGrab) {
|
|
1073
1104
|
this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab);
|
|
1074
|
-
this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(
|
|
1105
|
+
this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(getWorldPosition(this.selected));
|
|
1075
1106
|
target.sub(this.localPositionOffsetToGrab_worldSpace);
|
|
1076
1107
|
}
|
|
1077
|
-
|
|
1108
|
+
setWorldPosition(this.selected, target);
|
|
1078
1109
|
}
|
|
1079
1110
|
|
|
1080
1111
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getWorldPosition, setWorldPosition, setWorldPositionXYZ } from "../engine/engine_three_utils";
|
|
2
2
|
import { Behaviour, GameObject } from "./Component";
|
|
3
3
|
import { AttachedObject, AttachedObjectEvents } from "./WebXRController";
|
|
4
|
-
import
|
|
4
|
+
import { Object3D, Vector3 } from "three";
|
|
5
5
|
import { PlayerColor } from "./PlayerColor";
|
|
6
6
|
import { Context } from "../engine/engine_setup";
|
|
7
7
|
import { IModel, SendQueue } from "../engine/engine_networking_types";
|
|
@@ -20,7 +20,7 @@ export class XRGrabModel implements IModel {
|
|
|
20
20
|
source: { x: number, y: number, z: number } = { x: 0, y: 0, z: 0 };
|
|
21
21
|
target: string | undefined;
|
|
22
22
|
|
|
23
|
-
update(context : Context, point:
|
|
23
|
+
update(context : Context, point: Vector3, source: Vector3, target: string | undefined = undefined) {
|
|
24
24
|
this.userId = context.connection.connectionId;
|
|
25
25
|
this.point.x = point.x;
|
|
26
26
|
this.point.y = point.y;
|
|
@@ -34,14 +34,14 @@ export class XRGrabModel implements IModel {
|
|
|
34
34
|
|
|
35
35
|
// sends grab info to other users and creates rendering instances
|
|
36
36
|
export class XRGrabRendering extends Behaviour {
|
|
37
|
-
prefab:
|
|
37
|
+
prefab: Object3D | null = null;
|
|
38
38
|
|
|
39
39
|
private _grabModels: Array<XRGrabModel> = [];
|
|
40
40
|
private _grabModelsUpdateTime: Array<number> = [];
|
|
41
41
|
private _addOrUpdateSub: Function | null = null;
|
|
42
42
|
private _endSub: Function | null = null;
|
|
43
43
|
private _freeSub: Function | null = null;
|
|
44
|
-
private _instances: { [key: string]: {instance:
|
|
44
|
+
private _instances: { [key: string]: {instance:Object3D, model:XRGrabModel} } = {};
|
|
45
45
|
|
|
46
46
|
awake(): void {
|
|
47
47
|
if(this.prefab) this.prefab.visible = false;
|
|
@@ -72,7 +72,7 @@ export class XRGrabRendering extends Behaviour {
|
|
|
72
72
|
const inst = this._instances[data.guid];
|
|
73
73
|
if(!inst)
|
|
74
74
|
{
|
|
75
|
-
const instance = GameObject.instantiate(this.prefab) as
|
|
75
|
+
const instance = GameObject.instantiate(this.prefab) as Object3D;
|
|
76
76
|
instance.visible = true;
|
|
77
77
|
this._instances[data.guid] = {instance, model:data};
|
|
78
78
|
if(data.userId){
|
|
@@ -135,7 +135,7 @@ export class XRGrabRendering extends Behaviour {
|
|
|
135
135
|
model.update(this.context, att.grabPoint, att.controller.worldPosition, targetObject);
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
private temp :
|
|
138
|
+
private temp : Vector3 = new Vector3();
|
|
139
139
|
private updateRendering() {
|
|
140
140
|
const step = this.context.time.deltaTime / .5;
|
|
141
141
|
for(const key in this._instances){
|