Skip to content

Commit

Permalink
Update audio when media is rotate through menus
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed May 30, 2023
1 parent 1b8498d commit 711f4a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/bit-systems/object-menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineQuery, enterQuery, entityExists, exitQuery, hasComponent } from "bitecs";
import { addComponent, defineQuery, enterQuery, entityExists, exitQuery, hasComponent, removeComponent } from "bitecs";
import { Matrix4, Quaternion, Vector3 } from "three";
import type { HubsWorld } from "../app";
import {
Expand All @@ -20,6 +20,7 @@ import { deleteTheDeletableAncestor } from "./delete-entity-system";
import { createMessageDatas, isPinned } from "./networking";
import { TRANSFORM_MODE } from "../components/transform-object-button";
import { ScalingHandler } from "../components/scale-button";
import { BodyAtRest } from "../systems/floaty-object-system";

// Working variables.
const _vec3_1 = new Vector3();
Expand Down Expand Up @@ -88,11 +89,13 @@ function startRotation(world: HubsWorld, targetEid: EntityID) {
transformSystem.startTransform(world.eid2obj.get(targetEid)!, world.eid2obj.get(rightCursorEid)!, {
mode: TRANSFORM_MODE.CURSOR
});
removeComponent(APP.world, BodyAtRest, targetEid);
}

function stopRotation() {
function stopRotation(world: HubsWorld, targetEid: EntityID) {
const transformSystem = APP.scene!.systems["transform-selected-object"];
transformSystem.stopTransform();
addComponent(APP.world, BodyAtRest, targetEid);
}

function startScaling(world: HubsWorld, targetEid: EntityID) {
Expand Down Expand Up @@ -188,7 +191,7 @@ function handleHeldEnter(world: HubsWorld, eid: EntityID, menuEid: EntityID) {
function handleHeldExit(world: HubsWorld, eid: EntityID, menuEid: EntityID) {
switch (eid) {
case ObjectMenu.rotateButtonRef[menuEid]:
stopRotation();
stopRotation(world, ObjectMenu.targetRef[menuEid]);
break;
case ObjectMenu.scaleButtonRef[menuEid]:
stopScaling(world);
Expand Down
7 changes: 7 additions & 0 deletions src/components/transform-object-button.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { paths } from "../systems/userinput/paths";
import { waitForDOMContentLoaded } from "../utils/async-utils";
import { COLLISION_LAYERS } from "../constants";
import { addComponent, removeComponent } from "bitecs";
import { BodyAtRest } from "../systems/floaty-object-system";
const AMMO_BODY_ATTRIBUTES = { type: "kinematic", collisionFilterMask: COLLISION_LAYERS.HANDS };

export const TRANSFORM_MODE = {
Expand Down Expand Up @@ -145,6 +147,7 @@ AFRAME.registerSystem("transform-selected-object", {
pInv.invert();
this.target.quaternion.copy(pInv).multiply(q);
this.target.matrixNeedsUpdate = true;
addComponent(APP.world, BodyAtRest, this.target.el.eid);
}
}
};
Expand Down Expand Up @@ -241,6 +244,7 @@ AFRAME.registerSystem("transform-selected-object", {
.premultiply(controllerOrientationDelta)
.premultiply(controllerOrientationDelta);
this.target.matrixNeedsUpdate = true;
removeComponent(APP.world, BodyAtRest, this.target.el.eid);
},

cursorAxisOrScaleTick() {
Expand Down Expand Up @@ -295,6 +299,7 @@ AFRAME.registerSystem("transform-selected-object", {
q2.setFromAxisAngle(v, this.dxApplied);

this.target.quaternion.premultiply(q).premultiply(q2);
removeComponent(APP.world, BodyAtRest, this.target.el.eid);
}

this.target.matrixNeedsUpdate = true;
Expand All @@ -305,6 +310,7 @@ AFRAME.registerSystem("transform-selected-object", {

this.target.quaternion.multiply(q.setFromAxisAngle(this.axis, -this.sign * this.dxApplied));
this.target.matrixNeedsUpdate = true;
removeComponent(APP.world, BodyAtRest, this.target.el.eid);
}

previousPointOnPlane.copy(currentPointOnPlane);
Expand All @@ -323,6 +329,7 @@ AFRAME.registerSystem("transform-selected-object", {
this.el.camera.getWorldPosition(CAMERA_WORLD_POSITION);
this.target.lookAt(CAMERA_WORLD_POSITION);
this.transforming = false;
removeComponent(APP.world, BodyAtRest, this.target.el.eid);
return;
}

Expand Down

0 comments on commit 711f4a8

Please sign in to comment.