From d5fb1e6f87d57d9febe70d17f452563d0a2f0266 Mon Sep 17 00:00:00 2001 From: Greg Fodor Date: Fri, 22 Mar 2019 00:02:55 +0000 Subject: [PATCH 1/5] Fix up scaling --- src/utils/media-utils.js | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/utils/media-utils.js b/src/utils/media-utils.js index 36858d1d7..b2a37be7b 100644 --- a/src/utils/media-utils.js +++ b/src/utils/media-utils.js @@ -3,6 +3,8 @@ import { getReticulumFetchUrl } from "./phoenix-utils"; import mediaHighlightFrag from "./media-highlight-frag.glsl"; import { mapMaterials } from "./material-utils"; import { MeshBVH, acceleratedRaycast } from "three-mesh-bvh"; +import { ObjectContentOrigins } from "../object-types"; +import nextTick from "./next-tick"; THREE.Mesh.prototype.raycast = acceleratedRaycast; const nonCorsProxyDomains = (process.env.NON_CORS_PROXY_DOMAINS || "").split(","); @@ -177,13 +179,16 @@ export const addMedia = (src, template, contentOrigin, resolve = false, resize = fileIsOwned: !needsToBeUploaded }); - const [sx, sy, sz] = [entity.object3D.scale.x, entity.object3D.scale.y, entity.object3D.scale.z]; + let [sx, sy, sz] = [entity.object3D.scale.x, entity.object3D.scale.y, entity.object3D.scale.z]; + + entity.object3D.scale.set(0.001, 0.001, 0.001); + entity.object3D.matrixNeedsUpdate = true; entity.setAttribute("animation__loader_spawn-start", { property: "scale", delay: 50, dur: 200, - from: { x: sx / 2, y: sy / 2, z: sz / 2 }, + from: { x: 0.001, y: 0.001, z: 0.001 }, to: { x: sx, y: sy, z: sz }, easing: "easeInQuad" }); @@ -195,23 +200,43 @@ export const addMedia = (src, template, contentOrigin, resolve = false, resize = }, 100); ["model-loaded", "video-loaded", "image-loaded"].forEach(eventName => { - entity.addEventListener(eventName, () => { + entity.addEventListener(eventName, async () => { + entity.object3D.visible = false; + clearTimeout(fireLoadingTimeout); entity.removeAttribute("animation__loader_spawn-start"); - const [sx, sy, sz] = [entity.object3D.scale.x, entity.object3D.scale.y, entity.object3D.scale.z]; + + if (entity.components.scale) { + // Wait for any pending scale component to initialize and set scale (like on the pen) + await nextTick(); + } + + if (contentOrigin !== ObjectContentOrigins.SPAWNER) { + // Spawner will have set scale previously, otherwise we set reset the scale here in case + // the spawner box animation did not complete. + entity.object3D.scale.set(sx, sy, sz); + entity.object3D.matrixNeedsUpdate = true; + } + + [sx, sy, sz] = [entity.object3D.scale.x, entity.object3D.scale.y, entity.object3D.scale.z]; if (!entity.getAttribute("animation__spawn-start")) { + entity.object3D.scale.set(0.001, 0.001, 0.001); + entity.object3D.matrixNeedsUpdate = true; + entity.setAttribute("animation__spawn-start", { property: "scale", delay: 50, - dur: 300, - from: { x: sx / 2, y: sy / 2, z: sz / 2 }, + dur: 350, + from: { x: 0.001, y: 0.001, z: 0.001 }, to: { x: sx, y: sy, z: sz }, easing: "easeOutElastic" }); } + entity.object3D.visible = true; + scene.emit("media-loaded", { src: src }); }); }); From ab784a5490db99c5f45717583585e86920873da7 Mon Sep 17 00:00:00 2001 From: Greg Fodor Date: Fri, 22 Mar 2019 17:32:38 +0000 Subject: [PATCH 2/5] Handle early vr entry on startup --- src/hub.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/hub.js b/src/hub.js index 0cc65b1ee..9679775a0 100644 --- a/src/hub.js +++ b/src/hub.js @@ -563,7 +563,7 @@ document.addEventListener("DOMContentLoaded", async () => { window.APP.scene = scene; window.APP.hubChannel = hubChannel; - scene.addEventListener("enter-vr", () => { + const handleEarlyVRMode = () => { // If VR headset is activated, refreshing page will fire vrdisplayactivate // which puts A-Frame in VR mode, so exit VR mode whenever it is attempted // to be entered and we haven't entered the room yet. @@ -573,6 +573,12 @@ document.addEventListener("DOMContentLoaded", async () => { return true; } + return false; + }; + + scene.addEventListener("enter-vr", () => { + if (handleEarlyVRMode()) return true; + document.body.classList.add("vr-mode"); // Don't stretch canvas on cardboard, since that's drawing the actual VR view :) @@ -581,6 +587,8 @@ document.addEventListener("DOMContentLoaded", async () => { } }); + handleEarlyVRMode(); + // HACK A-Frame 0.9.0 seems to fail to wire up vrdisplaypresentchange early enough // to catch presentation state changes and recognize that an HMD is presenting on startup. window.addEventListener( From a7de99e0c7d3e85cd449f9f879afc942f0ade68d Mon Sep 17 00:00:00 2001 From: Greg Fodor Date: Sat, 23 Mar 2019 06:41:00 +0000 Subject: [PATCH 3/5] Fix for spawning --- src/scene-entry-manager.js | 8 ++++++-- src/utils/vr-interstitial.js | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/scene-entry-manager.js b/src/scene-entry-manager.js index 51893e5e9..46bd24dfb 100644 --- a/src/scene-entry-manager.js +++ b/src/scene-entry-manager.js @@ -10,7 +10,11 @@ const qs = new URLSearchParams(location.search); const aframeInspectorUrl = require("file-loader?name=assets/js/[name]-[hash].[ext]!aframe-inspector/dist/aframe-inspector.min.js"); import { addMedia, getPromotionTokenForFile } from "./utils/media-utils"; -import { handleExitTo2DInterstitial, handleReEntryToVRFrom2DInterstitial } from "./utils/vr-interstitial"; +import { + isIn2DInterstitial, + handleExitTo2DInterstitial, + handleReEntryToVRFrom2DInterstitial +} from "./utils/vr-interstitial"; import { ObjectContentOrigins } from "./object-types"; import { getAvatarSrc } from "./assets/avatars/avatars"; import { pushHistoryState } from "./utils/history"; @@ -452,7 +456,7 @@ export default class SceneEntryManager { if (entry.type === "scene_listing" && this.hubChannel.permissions.update_hub) return; // If user has HMD lifted up, delay spawning for now. eventually show a modal - const delaySpawn = this._in2DInterstitial && !isMobileVR; + const delaySpawn = isIn2DInterstitial() && !isMobileVR; setTimeout(() => { spawnMediaInfrontOfPlayer(entry.url, ObjectContentOrigins.URL); }, delaySpawn ? 3000 : 0); diff --git a/src/utils/vr-interstitial.js b/src/utils/vr-interstitial.js index b3f5e8899..c6f37ddf3 100644 --- a/src/utils/vr-interstitial.js +++ b/src/utils/vr-interstitial.js @@ -1,13 +1,13 @@ import { showFullScreenIfAvailable } from "./fullscreen"; -let isIn2DInterstitial = false; +let _isIn2DInterstitial = false; const isMobileVR = AFRAME.utils.device.isMobileVR(); export function handleExitTo2DInterstitial(isLower) { const scene = document.querySelector("a-scene"); if (!scene.is("vr-mode")) return; - isIn2DInterstitial = true; + _isIn2DInterstitial = true; if (isMobileVR) { // Immersive browser, exit VR. @@ -24,8 +24,8 @@ export function handleExitTo2DInterstitial(isLower) { } export function handleReEntryToVRFrom2DInterstitial() { - if (!isIn2DInterstitial) return; - isIn2DInterstitial = false; + if (!_isIn2DInterstitial) return; + _isIn2DInterstitial = false; document.querySelector(".vr-notice").object3D.visible = false; @@ -34,3 +34,7 @@ export function handleReEntryToVRFrom2DInterstitial() { scene.enterVR(); } } + +export function isIn2DInterstitial() { + return _isIn2DInterstitial; +} From 3255f07ad655b3a6e87217a20290e1b0712be05b Mon Sep 17 00:00:00 2001 From: Greg Fodor Date: Mon, 25 Mar 2019 22:45:45 +0000 Subject: [PATCH 4/5] Bump A-Frame fork --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index db5aa280f..fce9993b4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3279,13 +3279,13 @@ "dev": true }, "aframe": { - "version": "github:mozillareality/aframe#0663d0e2b5a23e405f11857daf5aacc15fd42808", + "version": "github:mozillareality/aframe#05a27f9138ad9cd5f016ab5f35c42aad0e283cbb", "from": "github:mozillareality/aframe#hubs/master", "requires": { "animejs": "^2.2.0", "browserify-css": "^0.8.4", "custom-event-polyfill": "^1.0.6", - "debug": "github:ngokevin/debug#noTimestamp", + "debug": "github:ngokevin/debug#ef5f8e66d49ce8bc64c6f282c15f8b7164409e3a", "deep-assign": "^2.0.0", "document-register-element": "github:dmarcos/document-register-element#8ccc532b7f3744be954574caf3072a5fd260ca90", "envify": "^3.4.1", From 0344964be29383bf7aedc431b468386857b1f8a1 Mon Sep 17 00:00:00 2001 From: Greg Fodor Date: Mon, 25 Mar 2019 23:53:40 +0000 Subject: [PATCH 5/5] Update scale correction --- src/utils/media-utils.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/utils/media-utils.js b/src/utils/media-utils.js index b2a37be7b..05faf1e4d 100644 --- a/src/utils/media-utils.js +++ b/src/utils/media-utils.js @@ -207,14 +207,17 @@ export const addMedia = (src, template, contentOrigin, resolve = false, resize = entity.removeAttribute("animation__loader_spawn-start"); + // Deal with scale. The box animation may not have completed so cover all cases. if (entity.components.scale) { - // Wait for any pending scale component to initialize and set scale (like on the pen) + // Ensure explicit scale from scale component is set. + const scaleData = entity.components.scale.data; + entity.object3D.scale.set(scaleData.x, scaleData.y, scaleData.z); + entity.object3D.matrixNeedsUpdate = true; + } else if (contentOrigin == ObjectContentOrigins.SPAWNER) { + // Spawner will have set scale. await nextTick(); - } - - if (contentOrigin !== ObjectContentOrigins.SPAWNER) { - // Spawner will have set scale previously, otherwise we set reset the scale here in case - // the spawner box animation did not complete. + } else { + // Otherwise, ensure original scale is re-applied. entity.object3D.scale.set(sx, sy, sz); entity.object3D.matrixNeedsUpdate = true; }