diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000000000000000000000000000000000000..963354f23168f2e9f79b42c261c612cc662e849c --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,3 @@ +{ + "printWidth": 120 +} diff --git a/src/behaviours/oculus-touch-joystick-dpad4.js b/src/behaviours/oculus-touch-joystick-dpad4.js index ed85bca9555cf127d6fd90e196753cfcd47e9f97..758fb603c70faceb932539d722e08976e603046d 100644 --- a/src/behaviours/oculus-touch-joystick-dpad4.js +++ b/src/behaviours/oculus-touch-joystick-dpad4.js @@ -1,4 +1,4 @@ -import { angleTo4Direction, angleTo8Direction } from "../utils"; +import { angleTo4Direction, angleTo8Direction } from "../utils/dpad"; // @TODO specify 4 or 8 direction function oculus_touch_joystick_dpad4(el, outputPrefix) { diff --git a/src/behaviours/vive-trackpad-dpad4.js b/src/behaviours/vive-trackpad-dpad4.js index 4ef7364ab7d8ee4c22780c68b1183b4eba0db82a..3f4e3a275a4c6bad6a74aa6ef3c8836bb3a26500 100644 --- a/src/behaviours/vive-trackpad-dpad4.js +++ b/src/behaviours/vive-trackpad-dpad4.js @@ -1,4 +1,4 @@ -import { angleTo4Direction, angleTo8Direction } from "../utils"; +import { angleTo4Direction, angleTo8Direction } from "../utils/dpad"; function vive_trackpad_dpad4(el, outputPrefix) { this.outputPrefix = outputPrefix; diff --git a/src/room.js b/src/room.js index e4fddbbf31bf2a9d4d5a2065542103cebfa4eb51..a0ef0818d072f7f052f070b9e3035813747f1a58 100644 --- a/src/room.js +++ b/src/room.js @@ -1,5 +1,8 @@ import queryString from "query-string"; +import { patchWebGLRenderingContext } from "./utils/webgl"; +patchWebGLRenderingContext(); + import "aframe"; import "./vendor/GLTFLoader"; import "networked-aframe"; @@ -43,16 +46,13 @@ import "./systems/personal-space-bubble"; import "./elements/a-gltf-entity"; import "./elements/a-proxy-entity"; -import { promptForName, getCookie, parseJwt } from "./utils"; +import { promptForName, getCookie, parseJwt } from "./utils/identity"; import registerNetworkSchemas from "./network-schemas"; import { inGameActions, config } from "./input-mappings"; import registerTelemetry from "./telemetry"; AFRAME.registerInputBehaviour("vive_trackpad_dpad4", vive_trackpad_dpad4); -AFRAME.registerInputBehaviour( - "oculus_touch_joystick_dpad4", - oculus_touch_joystick_dpad4 -); +AFRAME.registerInputBehaviour("oculus_touch_joystick_dpad4", oculus_touch_joystick_dpad4); AFRAME.registerInputActivator("pressedmove", PressedMove); AFRAME.registerInputActivator("reverseY", ReverseY); AFRAME.registerInputActions(inGameActions, "default"); @@ -89,10 +89,7 @@ window.App = { const scene = document.querySelector("a-scene"); scene.setAttribute("networked-scene", { - room: - qs.room && !isNaN(parseInt(qs.room)) - ? parseInt(qs.room) - : window.CONFIG.default_room, + room: qs.room && !isNaN(parseInt(qs.room)) ? parseInt(qs.room) : window.CONFIG.default_room, serverURL: window.CONFIG.janus_server_url }); @@ -134,10 +131,7 @@ window.App = { const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true, - video: - qs.screen === "true" - ? { mediaSource: "screen", height: 720, frameRate: 30 } - : false + video: qs.screen === "true" ? { mediaSource: "screen", height: 720, frameRate: 30 } : false }); // Don't send video by deafult diff --git a/src/utils/dpad.js b/src/utils/dpad.js new file mode 100644 index 0000000000000000000000000000000000000000..6f135122e6408bfdbc0a5a87d373104cbdc2e9bd --- /dev/null +++ b/src/utils/dpad.js @@ -0,0 +1,30 @@ +export function angleTo4Direction(angle) { + angle = (angle * THREE.Math.RAD2DEG + 180 + 45) % 360; + if (angle > 0 && angle < 90) { + return "north"; + } else if (angle >= 90 && angle < 180) { + return "west"; + } else if (angle >= 180 && angle < 270) { + return "south"; + } else { + return "east"; + } +} + +export function angleTo8Direction(angle) { + angle = (angle * THREE.Math.RAD2DEG + 180 + 45) % 360; + var direction = ""; + if ((angle >= 0 && angle < 120) || angle >= 330) { + direction += "north"; + } + if (angle >= 150 && angle < 300) { + direction += "south"; + } + if (angle >= 60 && angle < 210) { + direction += "west"; + } + if ((angle >= 240 && angle < 360) || angle < 30) { + direction += "east"; + } + return direction; +} diff --git a/src/utils.js b/src/utils/identity.js similarity index 78% rename from src/utils.js rename to src/utils/identity.js index 346f0994cf16943b7461a34e778cca16c87eebfc..54539286368182b31b49ae77a4e0d42898d78931 100644 --- a/src/utils.js +++ b/src/utils/identity.js @@ -190,34 +190,3 @@ export function parseJwt(token) { var base64 = base64Url.replace("-", "+").replace("_", "/"); return JSON.parse(window.atob(base64)); } - -export function angleTo4Direction(angle) { - angle = (angle * THREE.Math.RAD2DEG + 180 + 45) % 360; - if (angle > 0 && angle < 90) { - return "north"; - } else if (angle >= 90 && angle < 180) { - return "west"; - } else if (angle >= 180 && angle < 270) { - return "south"; - } else { - return "east"; - } -} - -export function angleTo8Direction(angle) { - angle = (angle * THREE.Math.RAD2DEG + 180 + 45) % 360; - var direction = ""; - if ((angle >= 0 && angle < 120) || angle >= 330) { - direction += "north"; - } - if (angle >= 150 && angle < 300) { - direction += "south"; - } - if (angle >= 60 && angle < 210) { - direction += "west"; - } - if ((angle >= 240 && angle < 360) || angle < 30) { - direction += "east"; - } - return direction; -} diff --git a/src/utils/webgl.js b/src/utils/webgl.js new file mode 100644 index 0000000000000000000000000000000000000000..483454b395625852ec9c2097c391c6b4ffaffbbc --- /dev/null +++ b/src/utils/webgl.js @@ -0,0 +1,36 @@ +import AFRAME from "aframe"; +const THREE = AFRAME.THREE; + +function checkFloatTextureSupport() { + const renderer = new THREE.WebGLRenderer(); + + const scene = new THREE.Scene(); + const size = 2; + const data = new Float32Array(size * size * 4); + const dataTexture = new THREE.DataTexture(data, size, size, THREE.RGBAFormat, THREE.FloatType); + const box = new THREE.Mesh(new THREE.PlaneBufferGeometry(1, 1), new THREE.MeshBasicMaterial({ map: dataTexture })); + box.material.map.needsUpdate = true; + scene.add(box); + + renderer.render(scene, new THREE.Camera()); + const result = renderer.context.getError() === 0; + renderer.dispose(); + return result; +} +const supportsFloatTextures = checkFloatTextureSupport(); + +export function patchWebGLRenderingContext() { + const originalGetExtension = WebGLRenderingContext.prototype.getExtension; + function patchedGetExtension(name) { + // It appears that Galaxy S6 devices falsely report that they support + // OES_texture_float in Firefox. This workaround disables float textures + // for those devices. + // See https://github.com/mozilla/mr-social-client/issues/32 and + // https://bugzilla.mozilla.org/show_bug.cgi?id=1338656 + if (name === "OES_texture_float" && /Android.+Firefox/.test(navigator.userAgent) && !supportsFloatTextures) { + return null; + } + return originalGetExtension.call(this, name); + } + WebGLRenderingContext.prototype.getExtension = patchedGetExtension; +}