Skip to content

Commit

Permalink
Fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirox committed Sep 6, 2023
1 parent 49333bc commit 3981547
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 42 deletions.
58 changes: 40 additions & 18 deletions src/react-components/room/hooks/useObjectList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
24 changes: 13 additions & 11 deletions src/react-components/room/object-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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"];
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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")
);

Expand Down
26 changes: 13 additions & 13 deletions src/systems/camera-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 3981547

Please sign in to comment.