Skip to content

Commit

Permalink
Merge pull request Hubs-Foundation#6462 from mozilla/bitecs-scale-gra…
Browse files Browse the repository at this point in the history
…bbed

Handle grab scaled object
  • Loading branch information
keianhzo authored Jan 26, 2024
2 parents 9ed5183 + 66896f6 commit 0ee6757
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/bit-systems/scale-when-grabbed-system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineQuery, entityExists, hasComponent } from "bitecs";
import { HubsWorld } from "../app";
import { Held, HeldRemoteLeft, HeldRemoteRight } from "../bit-components";
import { UserInputSystem } from "aframe";
import { paths } from "../systems/userinput/paths";

const heldQuery = defineQuery([Held]);
export function scaleWhenGrabbedSystem(world: HubsWorld, userInput: UserInputSystem) {
heldQuery(world).forEach(eid => {
let deltaScale: number = 0;
if (hasComponent(world, HeldRemoteRight, eid)) {
deltaScale = userInput.get(paths.actions.cursor.right.scaleGrabbedGrabbable);
}
if (hasComponent(world, HeldRemoteLeft, eid)) {
deltaScale = userInput.get(paths.actions.cursor.left.scaleGrabbedGrabbable);
}
if (!deltaScale) return;
const obj = world.eid2obj.get(eid)!;
obj.scale.addScalar(deltaScale).clampScalar(0.1, 100);
obj.matrixNeedsUpdate = true;
});
}
2 changes: 2 additions & 0 deletions src/systems/hubs-systems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import { linkedVideoSystem } from "../bit-systems/linked-video-system";
import { linkedPDFSystem } from "../bit-systems/linked-pdf-system";
import { inspectSystem } from "../bit-systems/inspect-system";
import { snapMediaSystem } from "../bit-systems/snap-media-system";
import { scaleWhenGrabbedSystem } from "../bit-systems/scale-when-grabbed-system";

declare global {
interface Window {
Expand Down Expand Up @@ -286,6 +287,7 @@ export function mainTick(xrFrame: XRFrame, renderer: WebGLRenderer, scene: Scene
linkedVideoSystem(world);
linkedPDFSystem(world);
inspectSystem(world, hubsSystems.cameraSystem);
scaleWhenGrabbedSystem(world, aframeSystems.userinput);

objectMenuTransformSystem(world);

Expand Down

0 comments on commit 0ee6757

Please sign in to comment.