Skip to content

Commit

Permalink
Merge pull request #6310 from mozilla/bitecs-object-inspect
Browse files Browse the repository at this point in the history
bitECS: Object inspection
  • Loading branch information
keianhzo authored Oct 4, 2023
2 parents 0c0929d + bff995f commit 6ff8a7d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/prefabs/duck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function DuckPrefab(): EntityDef {
halfExtents: [0.25, 0.5, 0.45]
}}
scale={[1, 1, 1]}
inspectable
/>
);
}
18 changes: 14 additions & 4 deletions src/systems/camera-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ 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 { HoveredRemoteRight, Inspectable } from "../bit-components";
import { findAncestorWithComponent, shouldUseNewLoader } from "../utils/bit-utils";
import { defineQuery } from "bitecs";

function getInspectableInHierarchy(eid) {
let inspectable = findAncestorWithComponent(APP.world, Inspectable, eid);
Expand Down Expand Up @@ -413,6 +414,7 @@ export class CameraSystem {
tick = (function () {
const translation = new THREE.Matrix4();
let uiRoot;
const hoveredQuery = defineQuery([HoveredRemoteRight]);
return function tick(scene, dt) {
this.viewingCamera.matrixNeedsUpdate = true;
this.viewingCamera.updateMatrix();
Expand Down Expand Up @@ -448,10 +450,18 @@ export class CameraSystem {
this.interaction = this.interaction || scene.systems.interaction;

if (this.userinput.get(paths.actions.startInspecting) && this.mode !== CAMERA_MODE_INSPECT) {
const hoverEl = this.interaction.state.rightRemote.hovered || this.interaction.state.leftRemote.hovered;
if (shouldUseNewLoader()) {
if (hoveredQuery(APP.world).length) {
const hovered = hoveredQuery(APP.world)[0];
const obj = APP.world.eid2obj.get(hovered);
this.inspect(obj, 1.5);
}
} else {
const hoverEl = this.interaction.state.rightRemote.hovered || this.interaction.state.leftRemote.hovered;

if (hoverEl) {
this.inspect(hoverEl.object3D, 1.5);
if (hoverEl) {
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 6ff8a7d

Please sign in to comment.