Skip to content

Commit

Permalink
Scale only pdf and video menus
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jan 25, 2024
1 parent 22dd263 commit 83ac743
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/bit-systems/object-menu-transform-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const tmpMat42 = new Matrix4();
const aabb = new Box3();
const sphere = new Sphere();
const yVector = new Vector3(0, 1, 0);
const UNIT_V3 = new Vector3(1, 1, 1);

// Calculate the AABB without accounting for the root object rotation
function getAABB(obj: Object3D, box: Box3, onlyVisible: boolean = false) {
Expand Down Expand Up @@ -84,8 +85,14 @@ function transformMenu(world: HubsWorld, menu: EntityID) {
} else {
targetObj.updateMatrices(true, true);
targetObj.matrixWorld.decompose(tmpVec1, tmpQuat1, tmpVec2);
targetObj.getWorldScale(tmpVec2);
tmpMat42.compose(tmpVec1, tmpQuat1, tmpVec2);

const scale = (ObjectMenuTransform.flags[menu] & ObjectMenuTransformFlags.Scale) !== 0 ? true : false;
if (scale) {
targetObj.getWorldScale(tmpVec2);
tmpMat42.compose(tmpVec1, tmpQuat1, tmpVec2);
} else {
tmpMat42.compose(tmpVec1, tmpQuat1, UNIT_V3);
}
tmpMat4.copy(tmpMat42);

const isFacing = isFacingCamera(targetObj);
Expand Down
7 changes: 6 additions & 1 deletion src/inflators/object-menu-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { ObjectMenuTransform } from "../bit-components";

export const ObjectMenuTransformFlags = {
Enabled: 1 << 0,
Center: 1 << 1
Center: 1 << 1,
Scale: 1 << 2
};

export type ObjectMenuTransformParams = {
center?: boolean;
scale?: boolean;
};

const DEFAULTS = {
Expand All @@ -22,4 +24,7 @@ export function inflateObjectMenuTransform(world: HubsWorld, eid: EntityID, para
if (params.center === true) {
ObjectMenuTransform.flags[eid] |= ObjectMenuTransformFlags.Center;
}
if (params.scale === true) {
ObjectMenuTransform.flags[eid] |= ObjectMenuTransformFlags.Scale;
}
}
2 changes: 1 addition & 1 deletion src/prefabs/pdf-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function PDFMenuPrefab() {
return (
<entity
name="PDF Menu"
objectMenuTransform={{ center: false }}
objectMenuTransform={{ center: false, scale: true }}
pdfMenu={{
prevButtonRef: refPrev,
nextButtonRef: refNext,
Expand Down
2 changes: 1 addition & 1 deletion src/prefabs/video-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function VideoMenuPrefab() {
return (
<entity
name="Video Menu"
objectMenuTransform={{ center: false }}
objectMenuTransform={{ center: false, scale: true }}
videoMenu={{
sliderRef,
timeLabelRef,
Expand Down

0 comments on commit 83ac743

Please sign in to comment.