diff --git a/src/bit-systems/object-menu.ts b/src/bit-systems/object-menu.ts index 44840632df..420723e414 100644 --- a/src/bit-systems/object-menu.ts +++ b/src/bit-systems/object-menu.ts @@ -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 { @@ -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(); @@ -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) { @@ -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); diff --git a/src/components/transform-object-button.js b/src/components/transform-object-button.js index bdbcdd18fb..9ce8c4a29d 100644 --- a/src/components/transform-object-button.js +++ b/src/components/transform-object-button.js @@ -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 = { @@ -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); } } }; @@ -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() { @@ -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; @@ -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); @@ -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; }