Skip to content

Commit 9ffe97b

Browse files
committed
Partially fix rotating and scaling via the spacebar menu buttons
Pass the eid of the object to the updateRigidBody function instead of the bodyId for the bitECS versions of rotating and scaling via the spacebar menu buttons. updateRigidBody attempts to get the bodyId from the eid, so doing it beforehand prevented the body from being found. Update the check for whether the aframe object is a rigid body by checking for the "body-helper" attribute. This allows the update of the object to be kinematic to go through when the spacebar rotate/scale buttons are engaged. Check if what is being hovered over when grabbing something is a HoldableButton and if it is, then use that as the hold target instead of the 3D object. This causes the grab to interact with the button and start the transform instead of just moving the object. Note: if you attempt to throw the object in the aframe loader and then try to rotate it again with the button, the physics system will fight it for some reason and prevent the rotation. Clicking on the object a couple times will cause the physics system to release it, but the reason for this behavior is unknown; it could possibly be related to ownership not being set properly or the rigid body not being updated properly. This behavior was fixed on the bitECS side by passing the eid instead of the bodyId to the updateRigidBody function, but activating the rigid body update on the aframe side (mentioned above) didn't fix it for the aframe side.
1 parent 348c602 commit 9ffe97b

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/bit-systems/object-menu.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function startRotation(world: HubsWorld, menuEid: EntityID, targetEid: EntityID)
105105
}
106106
const transformSystem = APP.scene!.systems["transform-selected-object"];
107107
const physicsSystem = AFRAME.scenes[0].systems["hubs-systems"].physicsSystem;
108-
physicsSystem.updateRigidBody(Rigidbody.bodyId[targetEid], { type: "kinematic" });
108+
physicsSystem.updateRigidBody(targetEid, { type: "kinematic" });
109109
const rightCursorEid = anyEntityWith(world, RemoteRight)!;
110110
transformSystem.startTransform(world.eid2obj.get(targetEid)!, world.eid2obj.get(rightCursorEid)!, {
111111
mode: TRANSFORM_MODE.CURSOR
@@ -137,7 +137,7 @@ function startScaling(world: HubsWorld, menuEid: EntityID, targetEid: EntityID)
137137
// TODO: Remove the dependency with AFRAME
138138
const transformSystem = (AFRAME as any).scenes[0].systems["transform-selected-object"];
139139
const physicsSystem = AFRAME.scenes[0].systems["hubs-systems"].physicsSystem;
140-
physicsSystem.updateRigidBody(Rigidbody.bodyId[targetEid], { type: "kinematic" });
140+
physicsSystem.updateRigidBody(targetEid, { type: "kinematic" });
141141
const rightCursorEid = anyEntityWith(world, RemoteRight)!;
142142
scalingHandler = new ScalingHandler(world.eid2obj.get(targetEid), transformSystem);
143143
scalingHandler!.objectToScale = world.eid2obj.get(targetEid);

src/components/transform-object-button.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ AFRAME.registerComponent("transform-button", {
5555
if (!NAF.utils.isMine(this.targetEl) && !NAF.utils.takeOwnership(this.targetEl)) {
5656
return;
5757
}
58-
if (this.targetEl.body) {
58+
if (this.targetEl.hasAttribute("body-helper")) {
5959
this.targetEl.setAttribute("body-helper", AMMO_BODY_ATTRIBUTES);
6060
}
6161
this.transformSystem = this.transformSystem || AFRAME.scenes[0].systems["transform-selected-object"];

src/systems/hold-system.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import {
1313
HeldHandLeft,
1414
AEntity,
1515
Networked,
16-
Rigidbody
16+
Rigidbody,
17+
HoldableButton
1718
} from "../bit-components";
1819
import { canMove } from "../utils/permissions-utils";
1920
import { canMove as canMoveEntity } from "../utils/bit-permissions-utils";
2021
import { isPinned } from "../bit-systems/networking";
2122
import { takeOwnership } from "../utils/take-ownership";
22-
import { findAncestorWithComponents } from "../utils/bit-utils";
23+
import { findAncestorWithComponents, findAncestorWithComponent } from "../utils/bit-utils";
2324
import { HOLDABLE_FLAGS } from "../inflators/holdable";
2425

2526
const GRAB_REMOTE_RIGHT = paths.actions.cursor.right.grab;
@@ -82,8 +83,10 @@ export function isAEntityPinned(world, eid) {
8283
function grab(world, userinput, queryHovered, held, grabPath) {
8384
const hovered = queryHovered(world)[0];
8485

86+
const holdablebutton = findAncestorWithComponent(world, HoldableButton, hovered);
8587
const interactable = findAncestorWithComponents(world, [Holdable, Rigidbody], hovered);
8688
const target = interactable ? interactable : hovered;
89+
const holdtarget = holdablebutton ? holdablebutton : target;
8790
const isEntityPinned = isPinned(target) || isAEntityPinned(world, target);
8891

8992
if (
@@ -96,8 +99,8 @@ function grab(world, userinput, queryHovered, held, grabPath) {
9699
if (hasComponent(world, Networked, target)) {
97100
takeOwnership(world, target);
98101
}
99-
addComponent(world, held, target);
100-
addComponent(world, Held, target);
102+
addComponent(world, held, holdtarget);
103+
addComponent(world, Held, holdtarget);
101104
}
102105
}
103106

0 commit comments

Comments
 (0)