diff --git a/src/react-components/room/hooks/useObjectList.js b/src/react-components/room/hooks/useObjectList.js index ae21274839..e2443dad60 100644 --- a/src/react-components/room/hooks/useObjectList.js +++ b/src/react-components/room/hooks/useObjectList.js @@ -46,14 +46,14 @@ function handleInspect(scene, object, callback) { callback(object); - const object3D = shouldUseNewLoader() ? APP.world.eid2obj.get(object.el.eid) : object.el.object3D; + const object3D = shouldUseNewLoader() ? APP.world.eid2obj.get(object.eid) : object.el.object3D; if (object3D !== cameraSystem.inspectable) { if (cameraSystem.inspectable) { cameraSystem.uninspect(false); } - cameraSystem.inspect(object.el, 1.5, false); + cameraSystem.inspect(object, 1.5, false); } } @@ -65,7 +65,7 @@ function handleDeselect(scene, object, callback) { cameraSystem.uninspect(false); if (object) { - cameraSystem.inspect(object.el, 1.5, false); + cameraSystem.inspect(object, 1.5, false); } } @@ -86,7 +86,7 @@ export function ObjectListProvider({ scene, children }) { id: APP.world.eid2obj.get(eid)?.id, name: getDisplayString(APP.getString(MediaInfo.accessibleUrl[eid])), type: getMediaType(eid), - el: APP.world.eid2obj.get(eid) + eid: eid })); setObjects(objects); } else { @@ -96,6 +96,7 @@ export function ObjectListProvider({ scene, children }) { // so don't crash if there isn't one. name: getDisplayString((el.components["media-loader"] && el.components["media-loader"].data.src) || ""), type: getMediaTypeAframe(el), + eid: el.eid, el })); setObjects(objects); @@ -124,23 +125,44 @@ export function ObjectListProvider({ scene, children }) { function onInspectTargetChanged() { const cameraSystem = scene.systems["hubs-systems"].cameraSystem; - const inspectedEl = cameraSystem.inspectable && cameraSystem.inspectable.el; - - if (inspectedEl) { - const object = objects.find(o => o.el === inspectedEl); - - if (object) { - setSelectedObject(object); + if (shouldUseNewLoader()) { + const inspectedEid = cameraSystem.inspectable && cameraSystem.inspectable.eid; + + if (inspectedEid) { + const object = objects.find(o => o.eid === inspectedEid); + + if (object) { + setSelectedObject(object); + } else { + setSelectedObject({ + id: inspectedEl.object3D.id, + name: getDisplayString(inspectedEl), + type: getMediaType(inspectedEl), + eid: inspectedEid + }); + } } else { - setSelectedObject({ - id: inspectedEl.object3D.id, - name: getDisplayString(inspectedEl), - type: getMediaType(inspectedEl), - el: inspectedEl - }); + setSelectedObject(null); } } else { - setSelectedObject(null); + const inspectedEl = cameraSystem.inspectable && cameraSystem.inspectable.el; + + if (inspectedEl) { + const object = objects.find(o => o.el === inspectedEl); + + if (object) { + setSelectedObject(object); + } else { + setSelectedObject({ + id: inspectedEl.object3D.id, + name: getDisplayString(inspectedEl), + type: getMediaType(inspectedEl), + el: inspectedEl + }); + } + } else { + setSelectedObject(null); + } } } diff --git a/src/react-components/room/object-hooks.js b/src/react-components/room/object-hooks.js index ea4006f1dc..50553a5966 100644 --- a/src/react-components/room/object-hooks.js +++ b/src/react-components/room/object-hooks.js @@ -9,7 +9,7 @@ import { MediaInfo, Static } from "../../bit-components"; import { deleteTheDeletableAncestor } from "../../bit-systems/delete-entity-system"; export function isMe(object) { - return object.el.id === "avatar-rig"; + return object.id === "avatar-rig"; } export function isPlayer(object) { @@ -24,7 +24,7 @@ export function isPlayer(object) { export function getObjectUrl(object) { let url; if (shouldUseNewLoader()) { - const urlSid = MediaInfo.accessibleUrl[object.el.eid]; + const urlSid = MediaInfo.accessibleUrl[object.eid]; url = APP.getString(urlSid); } else { const mediaLoader = object.el.components["media-loader"]; @@ -40,7 +40,7 @@ export function getObjectUrl(object) { } export function usePinObject(hubChannel, scene, object) { - const [isPinned, setIsPinned] = useState(getPinnedState(object.el.eid)); + const [isPinned, setIsPinned] = useState(getPinnedState(object.eid)); const pinObject = useCallback(() => { const el = object.el; @@ -82,14 +82,16 @@ export function usePinObject(hubChannel, scene, object) { }; }, [object]); + if (shouldUseNewLoader()) { + // TODO Add when pinning is migrated + return false; + } + const el = object.el; let userOwnsFile = false; - if (shouldUseNewLoader()) { - // TODO Add when pinning is migrated - return false; - } else if (el.components["media-loader"]) { + if (el.components["media-loader"]) { const { fileIsOwned, fileId } = el.components["media-loader"].data; userOwnsFile = fileIsOwned || (fileId && getPromotionTokenForFile(fileId)); } @@ -135,19 +137,19 @@ export function useGoToSelectedObject(scene, object) { export function useRemoveObject(hubChannel, scene, object) { const removeObject = useCallback(() => { if (shouldUseNewLoader()) { - deleteTheDeletableAncestor(APP.world, object.el.eid); + deleteTheDeletableAncestor(APP.world, object.eid); } else { removeNetworkedObject(scene, object.el); } }, [scene, object]); - const el = object.el; + const eid = object.eid; const canRemoveObject = !!( scene.is("entered") && !isPlayer(object) && - !getPinnedState(el.eid) && - !hasComponent(APP.world, Static, el.eid) && + !getPinnedState(eid) && + !hasComponent(APP.world, Static, eid) && hubChannel.can("spawn_and_move_media") ); diff --git a/src/systems/camera-system.js b/src/systems/camera-system.js index 1593592a4b..7babbcc0c4 100644 --- a/src/systems/camera-system.js +++ b/src/systems/camera-system.js @@ -48,16 +48,16 @@ function pivotFor(el) { return child.object3D; } -function getInspectableAndPivot(el) { - if (shouldUseNewLoader()) { - const inspectable = getInspectableInHierarchy(el.eid); - // TODO Add support for pivotFor (avatars only) - return { inspectable, pivot: inspectable }; - } else { - const inspectable = getInspectableInHierarchyAframe(el); - const pivot = pivotFor(inspectable.el); - return { inspectable, pivot }; - } +function getInspectableAndPivot(eid) { + const inspectable = getInspectableInHierarchy(eid); + // TODO Add support for pivotFor (avatars only) + return { inspectable, pivot: inspectable }; +} + +function getInspectableAndPivotAframe(el) { + const inspectable = getInspectableInHierarchyAframe(el); + const pivot = pivotFor(inspectable.el); + return { inspectable, pivot }; } const decompose = (function () { @@ -264,7 +264,7 @@ export class CameraSystem { this.mode = NEXT_MODES[this.mode] || 0; } - inspect(el, distanceMod, fireChangeEvent = true) { + inspect(obj, distanceMod, fireChangeEvent = true) { this.verticalDelta = 0; this.horizontalDelta = 0; this.inspectZoom = 0; @@ -273,7 +273,7 @@ export class CameraSystem { return; } - const { inspectable, pivot } = getInspectableAndPivot(el); + const { inspectable, pivot } = shouldUseNewLoader() ? getInspectableAndPivot(obj.eid) : getInspectableAndPivotAframe(obj.el); const scene = AFRAME.scenes[0]; scene.object3D.traverse(ensureLightsAreSeenByCamera); @@ -450,7 +450,7 @@ export class CameraSystem { const hoverEl = this.interaction.state.rightRemote.hovered || this.interaction.state.leftRemote.hovered; if (hoverEl) { - this.inspect(hoverEl, 1.5); + this.inspect(hoverEl.object3D, 1.5); } } else if (this.mode === CAMERA_MODE_INSPECT && this.userinput.get(paths.actions.stopInspecting)) { scene.emit("uninspect");