@needle-tools/engine 2.49.1-pre → 2.51.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 +24 -0
- package/dist/needle-engine.d.ts +19 -17
- package/dist/needle-engine.js +517 -3590
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +22 -22
- package/dist/needle-engine.min.js.map +3 -3
- package/lib/engine/engine_addressables.d.ts +1 -1
- package/lib/engine/engine_create_objects.d.ts +1 -1
- package/lib/engine/engine_element.d.ts +5 -4
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_overlay.d.ts +3 -2
- package/lib/engine/engine_element_overlay.js.map +1 -1
- package/lib/engine/engine_gameobject.js +6 -0
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_input.js +15 -9
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +1 -1
- package/lib/engine/engine_physics.js +1 -1
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_scenetools.d.ts +1 -1
- package/lib/engine/engine_serialization_core.d.ts +1 -1
- package/lib/engine/engine_setup.d.ts +2 -1
- package/lib/engine/engine_setup.js +28 -5
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_three_utils.d.ts +1 -0
- package/lib/engine/engine_three_utils.js +6 -0
- package/lib/engine/engine_three_utils.js.map +1 -1
- package/lib/engine/engine_types.d.ts +10 -9
- package/lib/engine/engine_utils.d.ts +1 -1
- package/lib/engine/extensions/NEEDLE_components.js +15 -11
- package/lib/engine/extensions/NEEDLE_components.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_lighting_settings.d.ts +1 -1
- package/lib/engine-components/Animator.js +4 -2
- package/lib/engine-components/Animator.js.map +1 -1
- package/lib/engine-components/AnimatorController.js +22 -2
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/Component.d.ts +2 -1
- package/lib/engine-components/DragControls.js +10 -4
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/Light.js +15 -12
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +19 -14
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +1 -1
- package/lib/engine-components/RigidBody.js +19 -10
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/ScreenCapture.js +2 -0
- package/lib/engine-components/ScreenCapture.js.map +1 -1
- package/lib/engine-components/ShadowCatcher.js +5 -1
- package/lib/engine-components/ShadowCatcher.js.map +1 -1
- package/lib/engine-components/Skybox.js +14 -2
- package/lib/engine-components/Skybox.js.map +1 -1
- package/lib/engine-components/VideoPlayer.js +2 -1
- package/lib/engine-components/VideoPlayer.js.map +1 -1
- package/lib/engine-components/WebARSessionRoot.d.ts +2 -2
- package/lib/engine-components/WebARSessionRoot.js.map +1 -1
- package/lib/engine-components/WebXR.d.ts +2 -1
- package/lib/engine-components/WebXR.js +9 -3
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRAvatar.d.ts +1 -1
- package/lib/engine-components/WebXRAvatar.js +6 -1
- package/lib/engine-components/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/WebXRController.d.ts +2 -1
- package/lib/engine-components/WebXRController.js +3 -2
- package/lib/engine-components/WebXRController.js.map +1 -1
- package/lib/engine-components/WebXRSync.js +5 -0
- package/lib/engine-components/WebXRSync.js.map +1 -1
- package/lib/engine-components/XRFlag.js +6 -6
- package/lib/engine-components/XRFlag.js.map +1 -1
- package/lib/engine-components/js-extensions/Vector.js +2 -5
- package/lib/engine-components/js-extensions/Vector.js.map +1 -1
- package/lib/engine-components/timeline/PlayableDirector.d.ts +1 -1
- package/lib/engine-components/timeline/PlayableDirector.js +1 -5
- package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.d.ts +2 -1
- package/lib/engine-components/ui/EventSystem.js +9 -1
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/lib/engine-components/ui/Utils.d.ts +1 -1
- package/package.json +2 -4
- package/src/engine/engine_element.ts +5 -5
- package/src/engine/engine_element_overlay.ts +2 -2
- package/src/engine/engine_gameobject.ts +7 -1
- package/src/engine/engine_input.ts +12 -8
- package/src/engine/engine_physics.ts +1 -1
- package/src/engine/engine_setup.ts +25 -6
- package/src/engine/engine_three_utils.ts +7 -0
- package/src/engine/engine_types.ts +3 -3
- package/src/engine/extensions/NEEDLE_components.ts +13 -9
- package/src/engine-components/Animator.ts +3 -3
- package/src/engine-components/AnimatorController.ts +27 -7
- package/src/engine-components/Component.ts +1 -1
- package/src/engine-components/DragControls.ts +8 -4
- package/src/engine-components/Light.ts +15 -10
- package/src/engine-components/OrbitControls.ts +19 -14
- package/src/engine-components/RigidBody.ts +19 -11
- package/src/engine-components/ScreenCapture.ts +1 -0
- package/src/engine-components/ShadowCatcher.ts +6 -1
- package/src/engine-components/Skybox.ts +15 -3
- package/src/engine-components/VideoPlayer.ts +2 -1
- package/src/engine-components/WebARSessionRoot.ts +1 -2
- package/src/engine-components/WebXR.ts +10 -4
- package/src/engine-components/WebXRAvatar.ts +6 -1
- package/src/engine-components/WebXRController.ts +4 -3
- package/src/engine-components/WebXRSync.ts +6 -1
- package/src/engine-components/XRFlag.ts +7 -6
- package/src/engine-components/js-extensions/Vector.ts +2 -5
- package/src/engine-components/timeline/PlayableDirector.ts +1 -4
- package/src/engine-components/ui/EventSystem.ts +12 -1
|
@@ -3,13 +3,13 @@ import { Behaviour, GameObject } from "./Component";
|
|
|
3
3
|
import { OrbitControls as ThreeOrbitControls } from "three/examples/jsm/controls/OrbitControls";
|
|
4
4
|
import { LookAtConstraint } from "./LookAtConstraint";
|
|
5
5
|
import * as THREE from "three";
|
|
6
|
-
import { getWorldPosition } from "../engine/engine_three_utils";
|
|
6
|
+
import { getWorldPosition, setWorldPosition, slerp } from "../engine/engine_three_utils";
|
|
7
7
|
import { RaycastOptions } from "../engine/engine_physics";
|
|
8
8
|
import { serializable } from "../engine/engine_serialization_decorator";
|
|
9
9
|
import { Camera } from "./Camera";
|
|
10
|
-
import { getParam } from "../engine/engine_utils";
|
|
10
|
+
import { getParam, isMobileDevice } from "../engine/engine_utils";
|
|
11
11
|
|
|
12
|
-
const
|
|
12
|
+
const freeCam = getParam("freecam");
|
|
13
13
|
|
|
14
14
|
export class OrbitControls extends Behaviour {
|
|
15
15
|
public get controls() {
|
|
@@ -40,7 +40,7 @@ export class OrbitControls extends Behaviour {
|
|
|
40
40
|
doubleClickToFocus: boolean = true;
|
|
41
41
|
|
|
42
42
|
// remove once slerp works correctly
|
|
43
|
-
useSlerp: boolean =
|
|
43
|
+
useSlerp: boolean = true;
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
debugLog: boolean = false;
|
|
@@ -76,13 +76,21 @@ export class OrbitControls extends Behaviour {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
if (this._controls) {
|
|
79
|
+
if (freeCam) {
|
|
80
|
+
this.enablePan = true;
|
|
81
|
+
this.enableZoom = true;
|
|
82
|
+
this.middleClickToFocus = true;
|
|
83
|
+
if(isMobileDevice()) this.doubleClickToFocus = true;
|
|
84
|
+
}
|
|
85
|
+
|
|
79
86
|
this._controls.enableDamping = this.enableDamping;
|
|
87
|
+
//@ts-ignore (not in types)
|
|
80
88
|
this._controls.enableKeys = this.enableKeys;
|
|
81
89
|
this._controls.autoRotate = this.autoRotate;
|
|
82
90
|
this._controls.autoRotateSpeed = this.autoRotateSpeed;
|
|
83
91
|
this._controls.enableZoom = this.enableZoom;
|
|
84
92
|
if (cam?.type === "PerspectiveCamera") {
|
|
85
|
-
if (
|
|
93
|
+
if (freeCam) {
|
|
86
94
|
// dont set limits
|
|
87
95
|
}
|
|
88
96
|
else {
|
|
@@ -91,7 +99,7 @@ export class OrbitControls extends Behaviour {
|
|
|
91
99
|
}
|
|
92
100
|
}
|
|
93
101
|
else {
|
|
94
|
-
if (
|
|
102
|
+
if (freeCam) {
|
|
95
103
|
// dont set limits
|
|
96
104
|
}
|
|
97
105
|
else {
|
|
@@ -183,14 +191,10 @@ export class OrbitControls extends Behaviour {
|
|
|
183
191
|
|
|
184
192
|
// lerp the camera
|
|
185
193
|
if (this._lerpCameraToTarget && this._cameraTargetPosition && this._cameraObject) {
|
|
186
|
-
|
|
194
|
+
// setWorldPosition(this._cameraObject, this._cameraTargetPosition);
|
|
195
|
+
if (this.useSlerp) {
|
|
187
196
|
const position = this._cameraObject?.position;
|
|
188
|
-
position
|
|
189
|
-
// TODO fix the offset here
|
|
190
|
-
// .sub(this._cameraTargetPosition)
|
|
191
|
-
//@ts-ignore
|
|
192
|
-
.slerp(this._cameraTargetPosition, step)
|
|
193
|
-
// .add(this._cameraTargetPosition);
|
|
197
|
+
slerp(position, this._cameraTargetPosition, step);
|
|
194
198
|
}
|
|
195
199
|
else {
|
|
196
200
|
this._cameraObject?.position.lerp(this._cameraTargetPosition, step);
|
|
@@ -210,7 +214,7 @@ export class OrbitControls extends Behaviour {
|
|
|
210
214
|
}
|
|
211
215
|
}
|
|
212
216
|
|
|
213
|
-
if (this.lookAtConstraint?.locked) this.setFromTargetPosition(0, this.lookAtConstraint01);
|
|
217
|
+
if (!freeCam && this.lookAtConstraint?.locked) this.setFromTargetPosition(0, this.lookAtConstraint01);
|
|
214
218
|
|
|
215
219
|
|
|
216
220
|
if (this._controls && !this.context.isInXR) {
|
|
@@ -281,6 +285,7 @@ export class OrbitControls extends Behaviour {
|
|
|
281
285
|
this._lerpCameraToTarget = true;
|
|
282
286
|
const pos = getWorldPosition(this.context.mainCamera);
|
|
283
287
|
this._cameraTargetPosition = pos.clone().sub(this.controls.target).add(this._lookTargetPosition);
|
|
288
|
+
this._cameraObject?.parent?.worldToLocal(this._cameraTargetPosition);
|
|
284
289
|
}
|
|
285
290
|
break;
|
|
286
291
|
}
|
|
@@ -3,7 +3,7 @@ import * as THREE from 'three'
|
|
|
3
3
|
import { getWorldPosition } from "../engine/engine_three_utils";
|
|
4
4
|
import { serializable } from "../engine/engine_serialization_decorator";
|
|
5
5
|
import { Watch } from "../engine/engine_utils";
|
|
6
|
-
import { Object3D, Vector3 } from "three";
|
|
6
|
+
import { Matrix4, Object3D, Vector3 } from "three";
|
|
7
7
|
import { IRigidbody } from "../engine/engine_types";
|
|
8
8
|
import { CollisionDetectionMode, RigidbodyConstraints } from "../engine/engine_physics.types";
|
|
9
9
|
import { validate } from "../engine/engine_util_decorator";
|
|
@@ -110,6 +110,18 @@ class TransformWatch {
|
|
|
110
110
|
this.rotationChanged = true;
|
|
111
111
|
})
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
// detect changes in the parent matrix
|
|
115
|
+
const original = this.obj.matrixWorld.multiplyMatrices.bind(this.obj.matrixWorld);
|
|
116
|
+
const lastParentMatrix = new Matrix4();
|
|
117
|
+
this.obj.matrixWorld["multiplyMatrices"] = (parent: Matrix4, matrix: Matrix4) => {
|
|
118
|
+
if (!lastParentMatrix.equals(parent)) {
|
|
119
|
+
this.positionChanged = true;
|
|
120
|
+
this.rotationChanged = true;
|
|
121
|
+
lastParentMatrix.copy(parent);
|
|
122
|
+
}
|
|
123
|
+
return original(parent, matrix);;
|
|
124
|
+
}
|
|
113
125
|
}
|
|
114
126
|
|
|
115
127
|
stop() {
|
|
@@ -201,22 +213,18 @@ export class Rigidbody extends Behaviour implements IRigidbody {
|
|
|
201
213
|
else this.constraints &= ~RigidbodyConstraints.FreezeRotationZ;
|
|
202
214
|
}
|
|
203
215
|
|
|
204
|
-
private _propertiesChanged: boolean = false;
|
|
205
216
|
private static tempPosition: THREE.Vector3 = new THREE.Vector3();
|
|
206
|
-
private
|
|
207
|
-
private
|
|
208
|
-
private
|
|
209
|
-
private
|
|
217
|
+
private _propertiesChanged: boolean = false;
|
|
218
|
+
private _currentVelocity: THREE.Vector3 = new THREE.Vector3();
|
|
219
|
+
private _smoothedVelocity: THREE.Vector3 = new THREE.Vector3();
|
|
220
|
+
private _smoothedVelocityGetter: THREE.Vector3 = new THREE.Vector3();
|
|
221
|
+
private _lastPosition: THREE.Vector3 = new THREE.Vector3();
|
|
210
222
|
|
|
211
223
|
private _watch?: TransformWatch;
|
|
212
224
|
|
|
213
|
-
|
|
214
225
|
awake() {
|
|
215
226
|
this._watch = undefined;
|
|
216
|
-
this.
|
|
217
|
-
this._smoothedVelocity = new THREE.Vector3();
|
|
218
|
-
this._smoothedVelocityGetter = new THREE.Vector3();
|
|
219
|
-
this._lastPosition = new THREE.Vector3();
|
|
227
|
+
this._propertiesChanged = false;
|
|
220
228
|
}
|
|
221
229
|
|
|
222
230
|
onEnable() {
|
|
@@ -40,6 +40,7 @@ declare type ScreenCaptureOptions = {
|
|
|
40
40
|
export class ScreenCapture extends Behaviour implements IPointerClickHandler {
|
|
41
41
|
|
|
42
42
|
onPointerClick() {
|
|
43
|
+
if(this.context.connection.isInRoom === false) return;
|
|
43
44
|
if (this.isReceiving) {
|
|
44
45
|
if (this.videoPlayer)
|
|
45
46
|
this.videoPlayer.screenspace = !this.videoPlayer.screenspace;
|
|
@@ -45,7 +45,12 @@ export class ShadowCatcher extends Behaviour {
|
|
|
45
45
|
this.applyMaterialOptions(material);
|
|
46
46
|
material.onBeforeCompile = (shader) => {
|
|
47
47
|
// see https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderLib/meshphysical.glsl.js#L181
|
|
48
|
-
|
|
48
|
+
// see https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderLib.js#LL284C11-L284C11
|
|
49
|
+
// see https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderLib/shadow.glsl.js#L40
|
|
50
|
+
// see https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js#L2
|
|
51
|
+
// see https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js#L281
|
|
52
|
+
|
|
53
|
+
shader.fragmentShader.replace("vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;",
|
|
49
54
|
`vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
|
|
50
55
|
|
|
51
56
|
// diffuse-only lighting with overdrive to somewhat compensate
|
|
@@ -2,7 +2,7 @@ import { serializable } from "../engine/engine_serialization_decorator";
|
|
|
2
2
|
import { Behaviour, GameObject } from "./Component";
|
|
3
3
|
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
|
|
4
4
|
import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader";
|
|
5
|
-
import { EquirectangularRefractionMapping, Texture } from "three"
|
|
5
|
+
import { EquirectangularRefractionMapping, sRGBEncoding, Texture, TextureLoader } from "three"
|
|
6
6
|
import { syncField } from "../engine/engine_networking_auto";
|
|
7
7
|
|
|
8
8
|
|
|
@@ -21,7 +21,7 @@ export class RemoteSkybox extends Behaviour {
|
|
|
21
21
|
@serializable()
|
|
22
22
|
environment: boolean = true;
|
|
23
23
|
|
|
24
|
-
private _loader?: RGBELoader | EXRLoader;
|
|
24
|
+
private _loader?: RGBELoader | EXRLoader | TextureLoader;
|
|
25
25
|
private _prevLoadedEnvironment?: Texture;
|
|
26
26
|
private _prevEnvironment: Texture | null = null;
|
|
27
27
|
private _prevBackground: any = null;
|
|
@@ -50,13 +50,25 @@ export class RemoteSkybox extends Behaviour {
|
|
|
50
50
|
|
|
51
51
|
if (!this._loader) {
|
|
52
52
|
const isEXR = url.endsWith(".exr");
|
|
53
|
-
|
|
53
|
+
const isHdr = url.endsWith(".hdr");
|
|
54
|
+
if (isEXR) {
|
|
55
|
+
this._loader = new EXRLoader();
|
|
56
|
+
}
|
|
57
|
+
else if (isHdr) {
|
|
58
|
+
this._loader = new RGBELoader();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this._loader = new TextureLoader();
|
|
62
|
+
}
|
|
54
63
|
}
|
|
55
64
|
const envMap = await this._loader.loadAsync(url);
|
|
56
65
|
if (!envMap) return;
|
|
57
66
|
if (!this.enabled) return;
|
|
58
67
|
this.url = url;
|
|
59
68
|
envMap.mapping = EquirectangularRefractionMapping;
|
|
69
|
+
if (this._loader instanceof TextureLoader) {
|
|
70
|
+
envMap.encoding = sRGBEncoding;
|
|
71
|
+
}
|
|
60
72
|
this._prevBackground = this.context.scene.background;
|
|
61
73
|
this._prevEnvironment = this.context.scene.environment;
|
|
62
74
|
console.log("Set skybox", this.url);
|
|
@@ -290,7 +290,8 @@ export class VideoPlayer extends Behaviour {
|
|
|
290
290
|
this._videoTexture.flipY = false;
|
|
291
291
|
this._videoTexture.encoding = THREE.sRGBEncoding;
|
|
292
292
|
this.handleBeginPlaying(playAutomatically);
|
|
293
|
-
|
|
293
|
+
if(debug)
|
|
294
|
+
console.log(this);
|
|
294
295
|
}
|
|
295
296
|
|
|
296
297
|
updateAspect() {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Behaviour, GameObject } from "./Component";
|
|
2
|
-
import {
|
|
3
|
-
import { Matrix4, Object3D, XRPose } from "three";
|
|
2
|
+
import { Matrix4, Object3D } from "three";
|
|
4
3
|
import { WebAR, WebXR } from "./WebXR";
|
|
5
4
|
import { InstancingUtil } from "../engine/engine_instancing";
|
|
6
5
|
import { serializable } from "../engine/engine_serialization_decorator";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ArrayCamera, Color, Euler, EventDispatcher, Group, Matrix4, Mesh, MeshBasicMaterial, Object3D, Quaternion, RingGeometry, Texture, Vector3
|
|
1
|
+
import { ArrayCamera, Color, Euler, EventDispatcher, Group, Matrix4, Mesh, MeshBasicMaterial, Object3D, Quaternion, RingGeometry, Texture, Vector3 } from 'three';
|
|
2
2
|
import { ARButton } from '../include/three/ARButton.js';
|
|
3
3
|
import { VRButton } from '../include/three/VRButton.js';
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ import { serializable } from "../engine/engine_serialization_decorator";
|
|
|
7
7
|
import { XRSessionMode } from "../engine/engine_setup";
|
|
8
8
|
import { getWorldPosition, getWorldQuaternion, setWorldPosition, setWorldQuaternion } from "../engine/engine_three_utils";
|
|
9
9
|
import { INeedleEngineComponent } from "../engine/engine_types";
|
|
10
|
-
import { getParam, setOrAddParamsToUrl } from "../engine/engine_utils";
|
|
10
|
+
import { getParam, isMozillaXR, setOrAddParamsToUrl } from "../engine/engine_utils";
|
|
11
11
|
|
|
12
12
|
import { Behaviour, GameObject } from "./Component";
|
|
13
13
|
import { noVoip } from "./Voip";
|
|
@@ -19,6 +19,7 @@ import { XRFlag, XRState, XRStateFlag } from "./XRFlag";
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
export async function detectARSupport() {
|
|
22
|
+
if(isMozillaXR()) return true;
|
|
22
23
|
if ("xr" in navigator) {
|
|
23
24
|
//@ts-ignore
|
|
24
25
|
return (await navigator["xr"].isSessionSupported('immersive-ar')) === true;
|
|
@@ -110,8 +111,12 @@ export class WebXR extends Behaviour {
|
|
|
110
111
|
features.optionalFeatures = ['hit-test', 'dom-overlay'];
|
|
111
112
|
}
|
|
112
113
|
else {
|
|
113
|
-
console.warn("No dom overlay root found, AR will not work");
|
|
114
|
+
console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");
|
|
114
115
|
}
|
|
116
|
+
features.optionalFeatures.push('plane-detection');
|
|
117
|
+
// features.optionalFeatures.push('light-estimation');
|
|
118
|
+
features.optionalFeatures.push('anchors');
|
|
119
|
+
|
|
115
120
|
const arButton = ARButton.createButton(webXR.context.renderer, features);
|
|
116
121
|
arButton.classList.add('webxr-ar-button');
|
|
117
122
|
arButton.classList.add('webxr-button');
|
|
@@ -368,6 +373,7 @@ export class WebXR extends Behaviour {
|
|
|
368
373
|
// we set layers to sync raycasting and have a similar behaviour to unity
|
|
369
374
|
const xr = this.context.renderer.xr;
|
|
370
375
|
if (this.context.mainCamera) {
|
|
376
|
+
//@ts-ignore
|
|
371
377
|
const cam = xr.getCamera(this.context.mainCamera) as ArrayCamera;
|
|
372
378
|
for (const c of cam.cameras) {
|
|
373
379
|
c.layers.enableAll();
|
|
@@ -549,7 +555,7 @@ export class WebAR {
|
|
|
549
555
|
context.scene.background = null;
|
|
550
556
|
|
|
551
557
|
session.requestReferenceSpace('viewer').then((referenceSpace) => {
|
|
552
|
-
session.requestHitTestSource({ space: referenceSpace })
|
|
558
|
+
session.requestHitTestSource?.call(session, { space: referenceSpace })?.then((source) => {
|
|
553
559
|
this.hitTestSource = source;
|
|
554
560
|
}).catch((err) => {
|
|
555
561
|
this.noHitTestAvailable = true;
|
|
@@ -125,7 +125,12 @@ export class WebXRAvatar {
|
|
|
125
125
|
if (!this.flags)
|
|
126
126
|
return;
|
|
127
127
|
let mask = this.isLocalAvatar ? XRStateFlag.FirstPerson : XRStateFlag.ThirdPerson;
|
|
128
|
-
|
|
128
|
+
if (this.context.isInVR)
|
|
129
|
+
mask |= XRStateFlag.VR;
|
|
130
|
+
else if (this.context.isInAR)
|
|
131
|
+
mask |= XRStateFlag.AR;
|
|
132
|
+
else
|
|
133
|
+
mask |= XRStateFlag.Browser;
|
|
129
134
|
for (const f of this.flags) {
|
|
130
135
|
f.gameObject.visible = true;
|
|
131
136
|
f.UpdateVisible(mask);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BoxHelper, BufferGeometry, Color, Euler, Group, Intersection, Layers, Line, LineBasicMaterial, Material, Mesh, MeshBasicMaterial, Object3D, PerspectiveCamera, Quaternion, Ray, SphereGeometry, Vector2, Vector3
|
|
1
|
+
import { BoxHelper, BufferGeometry, Color, Euler, Group, Intersection, Layers, Line, LineBasicMaterial, Material, Mesh, MeshBasicMaterial, Object3D, PerspectiveCamera, Quaternion, Ray, SphereGeometry, Vector2, Vector3 } from "three";
|
|
2
2
|
import { OculusHandModel } from 'three/examples/jsm/webxr/OculusHandModel.js';
|
|
3
3
|
import { OculusHandPointerModel } from 'three/examples/jsm/webxr/OculusHandPointerModel.js';
|
|
4
4
|
import { XRControllerModel, XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
|
|
@@ -381,11 +381,12 @@ export class WebXRController extends Behaviour {
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
if (this.raycastLine) {
|
|
384
|
+
const allowRaycastLineVisible = this.showRaycastLine && this.context.isInVR;
|
|
384
385
|
if (this.type === ControllerType.Touch) {
|
|
385
386
|
this.raycastLine.visible = false;
|
|
386
387
|
}
|
|
387
388
|
else if (this.isUsingHands) {
|
|
388
|
-
this.raycastLine.visible = !this.grabbed &&
|
|
389
|
+
this.raycastLine.visible = !this.grabbed && allowRaycastLineVisible;
|
|
389
390
|
setWorldPosition(this.raycastLine, wp);
|
|
390
391
|
const jnts = this.hand!['joints'];
|
|
391
392
|
if (jnts) {
|
|
@@ -400,7 +401,7 @@ export class WebXRController extends Behaviour {
|
|
|
400
401
|
setWorldQuaternion(this.raycastLine, this.rayRotation);
|
|
401
402
|
}
|
|
402
403
|
else {
|
|
403
|
-
this.raycastLine.visible =
|
|
404
|
+
this.raycastLine.visible = allowRaycastLineVisible;
|
|
404
405
|
setWorldQuaternion(this.raycastLine, this.rayRotation);
|
|
405
406
|
setWorldPosition(this.raycastLine, wp);
|
|
406
407
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Behaviour, GameObject } from "./Component";
|
|
2
2
|
import { RoomEvents, OwnershipModel, NetworkConnection } from "../engine/engine_networking";
|
|
3
3
|
import { WebXR, WebXREvent } from "./WebXR";
|
|
4
|
-
import { Group, Quaternion, Vector3, Vector4, WebXRManager
|
|
4
|
+
import { Group, Quaternion, Vector3, Vector4, WebXRManager } from "three";
|
|
5
5
|
import { getParam } from "../engine/engine_utils";
|
|
6
6
|
import { Voip } from "./Voip";
|
|
7
7
|
import { Builder, Long } from "flatbuffers";
|
|
@@ -402,6 +402,11 @@ export class WebXRSync extends Behaviour {
|
|
|
402
402
|
private onXRSessionEnded(_evt: { session: XRSession }) {
|
|
403
403
|
console.log("XR session ended");
|
|
404
404
|
this.context.connection.send(WebXRSyncEvent.WebXR_UserLeft, { id: this.context.connection.connectionId, mode: XRMode.VR });
|
|
405
|
+
if(this.localAvatar){
|
|
406
|
+
this.localAvatar?.destroy();
|
|
407
|
+
this.avatars[this.localAvatar.guid] = undefined;
|
|
408
|
+
this.localAvatar = null;
|
|
409
|
+
}
|
|
405
410
|
}
|
|
406
411
|
|
|
407
412
|
private ownership: OwnershipModel | null = null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Behaviour, GameObject } from "./Component";
|
|
2
2
|
import * as utils from "../engine/engine_utils";
|
|
3
|
+
|
|
4
|
+
|
|
3
5
|
const debug = utils.getParam("debugflags");
|
|
4
6
|
|
|
5
7
|
export enum XRStateFlag {
|
|
@@ -21,13 +23,12 @@ export class XRState {
|
|
|
21
23
|
public Mask: XRStateFlag = XRStateFlag.Browser | XRStateFlag.ThirdPerson;
|
|
22
24
|
|
|
23
25
|
public Has(state: XRStateFlag) {
|
|
24
|
-
|
|
25
26
|
const res = (this.Mask & state);
|
|
26
|
-
if (debug) console.log("HAS", state, this.Mask, "Result=" + res);
|
|
27
27
|
return res !== 0;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
public Set(state: number) {
|
|
31
|
+
if(debug) console.warn("Set XR flag state to", state)
|
|
31
32
|
this.Mask = state as number;
|
|
32
33
|
XRFlag.Apply();
|
|
33
34
|
}
|
|
@@ -108,23 +109,23 @@ export class XRFlag extends Behaviour {
|
|
|
108
109
|
const st = state as XRState;
|
|
109
110
|
if (st) {
|
|
110
111
|
if (debug)
|
|
111
|
-
console.
|
|
112
|
+
console.warn(this.name, "use passed in mask", st.Mask, this.visibleIn)
|
|
112
113
|
res = st.Has(this.visibleIn);
|
|
113
114
|
}
|
|
114
115
|
else {
|
|
115
116
|
if (debug)
|
|
116
|
-
console.log("use global mask")
|
|
117
|
+
console.log(this.name, "use global mask")
|
|
117
118
|
XRState.Global.Has(this.visibleIn);
|
|
118
119
|
}
|
|
119
120
|
if (res === undefined) return;
|
|
120
121
|
if (res) {
|
|
121
122
|
if (debug)
|
|
122
|
-
console.
|
|
123
|
+
console.log(this.name, "is visible", this.gameObject.uuid)
|
|
123
124
|
// this.gameObject.visible = true;
|
|
124
125
|
GameObject.setActive(this.gameObject, true);
|
|
125
126
|
} else {
|
|
126
127
|
if (debug)
|
|
127
|
-
console.
|
|
128
|
+
console.log(this.name, "is not visible", this.gameObject.uuid);
|
|
128
129
|
const isVisible = this.gameObject.visible;
|
|
129
130
|
if(!isVisible) return;
|
|
130
131
|
this.gameObject.visible = false;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { applyPrototypeExtensions, registerPrototypeExtensions } from "./ExtensionUtils";
|
|
2
|
-
import { Mathf } from "../../engine/engine_math";
|
|
3
2
|
import { Vector3 } from "three";
|
|
3
|
+
import { slerp } from "../../engine/engine_three_utils";
|
|
4
4
|
|
|
5
5
|
export function apply(object: Vector3) {
|
|
6
6
|
if (object && object.isVector3 === true) {
|
|
@@ -10,10 +10,7 @@ export function apply(object: Vector3) {
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
Vector3.prototype["slerp"] = function (end: Vector3, t: number) {
|
|
13
|
-
|
|
14
|
-
const len2 = end.length();
|
|
15
|
-
const targetLen = Mathf.lerp(len1, len2, t);
|
|
16
|
-
return this.lerp(end, t).normalize().multiplyScalar(targetLen);
|
|
13
|
+
return slerp(this, end, t);
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
registerPrototypeExtensions(Vector3);
|
|
@@ -85,9 +85,6 @@ export class PlayableDirector extends Behaviour {
|
|
|
85
85
|
console.log(this, this.playableAsset?.tracks);
|
|
86
86
|
|
|
87
87
|
this.rebuildGraph();
|
|
88
|
-
if (this.playOnAwake)
|
|
89
|
-
this.play();
|
|
90
|
-
else this.evaluate();
|
|
91
88
|
|
|
92
89
|
if (!this.isValid()) console.warn("PlayableDirector is not valid", this.playableAsset, this.playableAsset?.tracks, Array.isArray(this.playableAsset?.tracks), this);
|
|
93
90
|
}
|
|
@@ -230,7 +227,7 @@ export class PlayableDirector extends Behaviour {
|
|
|
230
227
|
];
|
|
231
228
|
|
|
232
229
|
private *internalUpdate() {
|
|
233
|
-
while (this._isPlaying) {
|
|
230
|
+
while (this._isPlaying && this.activeAndEnabled) {
|
|
234
231
|
if (!this._isPaused && this._isPlaying) {
|
|
235
232
|
this._time += this.context.time.deltaTime;
|
|
236
233
|
this.evaluate();
|
|
@@ -18,6 +18,9 @@ const debug = getParam("debugeventsystem");
|
|
|
18
18
|
|
|
19
19
|
export class EventSystem extends Behaviour {
|
|
20
20
|
|
|
21
|
+
|
|
22
|
+
private static _eventSystemMap = new Map<Context, EventSystem[]>();
|
|
23
|
+
|
|
21
24
|
static didSearchEventSystem: boolean = false;
|
|
22
25
|
static createIfNoneExists(context: Context) {
|
|
23
26
|
if (!this.didSearchEventSystem) {
|
|
@@ -33,7 +36,15 @@ export class EventSystem extends Behaviour {
|
|
|
33
36
|
GameObject.addNewComponent(go, EventSystem);
|
|
34
37
|
context.scene.add(go);
|
|
35
38
|
}
|
|
36
|
-
|
|
39
|
+
|
|
40
|
+
static get systems(): EventSystem[]
|
|
41
|
+
{
|
|
42
|
+
const context = Context.Current;
|
|
43
|
+
if (!this._eventSystemMap.has(context)) {
|
|
44
|
+
this._eventSystemMap.set(context, []);
|
|
45
|
+
}
|
|
46
|
+
return this._eventSystemMap.get(context)!;
|
|
47
|
+
}
|
|
37
48
|
|
|
38
49
|
//@ts-ignore
|
|
39
50
|
static ensureUpdateMeshUI(instance, context: Context) {
|