Skip to content

Commit

Permalink
Fix avatar inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Oct 3, 2023
1 parent 0c0929d commit e2d2cbe
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/bit-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,5 @@ export const LinearScale = defineComponent({
export const Quack = defineComponent();
export const TrimeshTag = defineComponent();
export const HeightFieldTag = defineComponent();
export const LocalAvatar = defineComponent();
export const RemoteAvatar = defineComponent();
4 changes: 4 additions & 0 deletions src/components/player-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import defaultAvatar from "../assets/models/DefaultAvatar.glb";
import { MediaDevicesEvents } from "../utils/media-devices-utils";
import { createHeadlessModelForSkinnedMesh } from "../utils/three-utils";
import { Layers } from "../camera-layers";
import { addComponent, removeComponent } from "bitecs";
import { LocalAvatar, RemoteAvatar } from "../bit-components";

function ensureAvatarNodes(json) {
const { nodes } = json;
Expand Down Expand Up @@ -63,12 +65,14 @@ AFRAME.registerComponent("player-info", {
}

registerComponentInstance(this, "player-info");
addComponent(APP.world, this.isLocalPlayerInfo ? LocalAvatar : RemoteAvatar, this.el.object3D.eid);
},

remove() {
const avatarEl = this.el.querySelector("[avatar-audio-source]");
APP.isAudioPaused.delete(avatarEl);
deregisterComponentInstance(this, "player-info");
removeComponent(APP.world, this.isLocalPlayerInfo ? LocalAvatar : RemoteAvatar, this.el.object3D.eid);
},

onAvatarModelLoaded(e) {
Expand Down
14 changes: 10 additions & 4 deletions src/systems/camera-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { qsGet } from "../utils/qs_truthy";
const customFOV = qsGet("fov");
const enableThirdPersonMode = qsTruthy("thirdPerson");
import { Layers } from "../camera-layers";
import { Inspectable } from "../bit-components";
import { findAncestorWithComponent, shouldUseNewLoader } from "../utils/bit-utils";
import { Inspectable, LocalAvatar, RemoteAvatar } from "../bit-components";
import { findAncestorWithAnyComponent, findAncestorWithComponent, shouldUseNewLoader } from "../utils/bit-utils";

function getInspectableInHierarchy(eid) {
let inspectable = findAncestorWithComponent(APP.world, Inspectable, eid);
Expand Down Expand Up @@ -49,8 +49,14 @@ function pivotFor(el) {

function getInspectableAndPivot(eid) {
const inspectable = getInspectableInHierarchy(eid);
// TODO Add support for pivotFor (avatars only)
return { inspectable, pivot: inspectable };
let pivot;
if (findAncestorWithAnyComponent(APP.world, [RemoteAvatar, LocalAvatar], eid)) {
// TODO Until avatars are migrated we still handle pivot using the AFrame element
pivot = pivotFor(inspectable.el);
} else {
pivot = inspectable;
}
return { inspectable, pivot };
}

function getInspectableAndPivotAframe(el) {
Expand Down
4 changes: 4 additions & 0 deletions src/utils/bit-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export function findAncestorWithComponent(world: HubsWorld, component: Component
return findAncestorEntity(world, eid, otherId => hasComponent(world, component, otherId));
}

export function findAncestorWithAnyComponent(world: HubsWorld, components: Array<Component>, eid: number) {
return findAncestorEntity(world, eid, otherId => hasAnyComponent(world, components, otherId));
}

export function findChildWithComponent(world: HubsWorld, component: Component, eid: number) {
const obj = world.eid2obj.get(eid);
if (obj) {
Expand Down

0 comments on commit e2d2cbe

Please sign in to comment.