|
@@ -18324,7 +18324,7 @@ class WebXRManager extends EventDispatcher {
|
|
let initialRenderTarget = null;
|
|
let initialRenderTarget = null;
|
|
let newRenderTarget = null;
|
|
let newRenderTarget = null;
|
|
const controllers = [];
|
|
const controllers = [];
|
|
- const inputSourcesMap = new Map(); //
|
|
|
|
|
|
+ const controllerInputSources = []; //
|
|
|
|
|
|
const cameraL = new PerspectiveCamera();
|
|
const cameraL = new PerspectiveCamera();
|
|
cameraL.layers.enable(1);
|
|
cameraL.layers.enable(1);
|
|
@@ -18378,7 +18378,13 @@ class WebXRManager extends EventDispatcher {
|
|
|
|
|
|
|
|
|
|
function onSessionEvent(event) {
|
|
function onSessionEvent(event) {
|
|
- const controller = inputSourcesMap.get(event.inputSource);
|
|
|
|
|
|
+ const controllerIndex = controllerInputSources.indexOf(event.inputSource);
|
|
|
|
+
|
|
|
|
+ if (controllerIndex === -1) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const controller = controllers[controllerIndex];
|
|
|
|
|
|
if (controller !== undefined) {
|
|
if (controller !== undefined) {
|
|
controller.dispatchEvent({
|
|
controller.dispatchEvent({
|
|
@@ -18397,12 +18403,13 @@ class WebXRManager extends EventDispatcher {
|
|
session.removeEventListener('squeezeend', onSessionEvent);
|
|
session.removeEventListener('squeezeend', onSessionEvent);
|
|
session.removeEventListener('end', onSessionEnd);
|
|
session.removeEventListener('end', onSessionEnd);
|
|
session.removeEventListener('inputsourceschange', onInputSourcesChange);
|
|
session.removeEventListener('inputsourceschange', onInputSourcesChange);
|
|
- inputSourcesMap.forEach(function (controller, inputSource) {
|
|
|
|
- if (controller !== undefined) {
|
|
|
|
- controller.disconnect(inputSource);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- inputSourcesMap.clear();
|
|
|
|
|
|
+
|
|
|
|
+ for (let i = 0; i < controllers.length; i++) {
|
|
|
|
+ const inputSource = controllerInputSources[i];
|
|
|
|
+ if (inputSource === null) continue;
|
|
|
|
+ controllers[i].disconnect(inputSource);
|
|
|
|
+ }
|
|
|
|
+
|
|
_currentDepthNear = null;
|
|
_currentDepthNear = null;
|
|
_currentDepthFar = null; // restore framebuffer/rendering state
|
|
_currentDepthFar = null; // restore framebuffer/rendering state
|
|
|
|
|
|
@@ -18544,31 +18551,44 @@ class WebXRManager extends EventDispatcher {
|
|
};
|
|
};
|
|
|
|
|
|
function onInputSourcesChange(event) {
|
|
function onInputSourcesChange(event) {
|
|
- const inputSources = session.inputSources; // Assign controllers to available inputSources
|
|
|
|
-
|
|
|
|
- for (let i = 0; i < inputSources.length; i++) {
|
|
|
|
- const index = inputSources[i].handedness === 'right' ? 1 : 0;
|
|
|
|
- inputSourcesMap.set(inputSources[i], controllers[index]);
|
|
|
|
- } // Notify disconnected
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ // Notify disconnected
|
|
for (let i = 0; i < event.removed.length; i++) {
|
|
for (let i = 0; i < event.removed.length; i++) {
|
|
const inputSource = event.removed[i];
|
|
const inputSource = event.removed[i];
|
|
- const controller = inputSourcesMap.get(inputSource);
|
|
|
|
|
|
+ const index = controllerInputSources.indexOf(inputSource);
|
|
|
|
|
|
- if (controller) {
|
|
|
|
- controller.dispatchEvent({
|
|
|
|
|
|
+ if (index >= 0) {
|
|
|
|
+ controllerInputSources[index] = null;
|
|
|
|
+ controllers[index].dispatchEvent({
|
|
type: 'disconnected',
|
|
type: 'disconnected',
|
|
data: inputSource
|
|
data: inputSource
|
|
});
|
|
});
|
|
- inputSourcesMap.delete(inputSource);
|
|
|
|
}
|
|
}
|
|
} // Notify connected
|
|
} // Notify connected
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < event.added.length; i++) {
|
|
for (let i = 0; i < event.added.length; i++) {
|
|
const inputSource = event.added[i];
|
|
const inputSource = event.added[i];
|
|
- const controller = inputSourcesMap.get(inputSource);
|
|
|
|
|
|
+ let controllerIndex = controllerInputSources.indexOf(inputSource);
|
|
|
|
+
|
|
|
|
+ if (controllerIndex === -1) {
|
|
|
|
+ // Assign input source a controller that currently has no input source
|
|
|
|
+ for (let i = 0; i < controllers.length; i++) {
|
|
|
|
+ if (i >= controllerInputSources.length) {
|
|
|
|
+ controllerInputSources.push(inputSource);
|
|
|
|
+ controllerIndex = i;
|
|
|
|
+ break;
|
|
|
|
+ } else if (controllerInputSources[i] === null) {
|
|
|
|
+ controllerInputSources[i] = inputSource;
|
|
|
|
+ controllerIndex = i;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } // If all controllers do currently receive input we ignore new ones
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (controllerIndex === -1) break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const controller = controllers[controllerIndex];
|
|
|
|
|
|
if (controller) {
|
|
if (controller) {
|
|
controller.dispatchEvent({
|
|
controller.dispatchEvent({
|
|
@@ -18773,13 +18793,11 @@ class WebXRManager extends EventDispatcher {
|
|
} //
|
|
} //
|
|
|
|
|
|
|
|
|
|
- const inputSources = session.inputSources;
|
|
|
|
-
|
|
|
|
for (let i = 0; i < controllers.length; i++) {
|
|
for (let i = 0; i < controllers.length; i++) {
|
|
- const inputSource = inputSources[i];
|
|
|
|
- const controller = inputSourcesMap.get(inputSource);
|
|
|
|
|
|
+ const inputSource = controllerInputSources[i];
|
|
|
|
+ const controller = controllers[i];
|
|
|
|
|
|
- if (controller !== undefined) {
|
|
|
|
|
|
+ if (inputSource !== null && controller !== undefined) {
|
|
controller.update(inputSource, frame, customReferenceSpace || referenceSpace);
|
|
controller.update(inputSource, frame, customReferenceSpace || referenceSpace);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -29616,31 +29634,31 @@ class MaterialLoader extends Loader {
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ static createMaterialFromType(type) {
|
|
|
|
+ const materialLib = {
|
|
|
|
+ ShadowMaterial,
|
|
|
|
+ SpriteMaterial,
|
|
|
|
+ RawShaderMaterial,
|
|
|
|
+ ShaderMaterial,
|
|
|
|
+ PointsMaterial,
|
|
|
|
+ MeshPhysicalMaterial,
|
|
|
|
+ MeshStandardMaterial,
|
|
|
|
+ MeshPhongMaterial,
|
|
|
|
+ MeshToonMaterial,
|
|
|
|
+ MeshNormalMaterial,
|
|
|
|
+ MeshLambertMaterial,
|
|
|
|
+ MeshDepthMaterial,
|
|
|
|
+ MeshDistanceMaterial,
|
|
|
|
+ MeshBasicMaterial,
|
|
|
|
+ MeshMatcapMaterial,
|
|
|
|
+ LineDashedMaterial,
|
|
|
|
+ LineBasicMaterial,
|
|
|
|
+ Material
|
|
|
|
+ };
|
|
|
|
+ return new materialLib[type]();
|
|
|
|
+ }
|
|
|
|
|
|
-MaterialLoader.createMaterialFromType = function (type) {
|
|
|
|
- const materialLib = {
|
|
|
|
- ShadowMaterial,
|
|
|
|
- SpriteMaterial,
|
|
|
|
- RawShaderMaterial,
|
|
|
|
- ShaderMaterial,
|
|
|
|
- PointsMaterial,
|
|
|
|
- MeshPhysicalMaterial,
|
|
|
|
- MeshStandardMaterial,
|
|
|
|
- MeshPhongMaterial,
|
|
|
|
- MeshToonMaterial,
|
|
|
|
- MeshNormalMaterial,
|
|
|
|
- MeshLambertMaterial,
|
|
|
|
- MeshDepthMaterial,
|
|
|
|
- MeshDistanceMaterial,
|
|
|
|
- MeshBasicMaterial,
|
|
|
|
- MeshMatcapMaterial,
|
|
|
|
- LineDashedMaterial,
|
|
|
|
- LineBasicMaterial,
|
|
|
|
- Material
|
|
|
|
- };
|
|
|
|
- return new materialLib[type]();
|
|
|
|
-};
|
|
|
|
|
|
+}
|
|
|
|
|
|
class LoaderUtils {
|
|
class LoaderUtils {
|
|
static decodeText(array) {
|
|
static decodeText(array) {
|