From b240a4248dfe7476fa869c25559ef323ea6eec2e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 10 Aug 2018 12:51:06 +1200 Subject: [PATCH] Size and position according to avatar scale --- scripts/system/tabletRezzer.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/system/tabletRezzer.js b/scripts/system/tabletRezzer.js index e338e767bb..a34f79da11 100644 --- a/scripts/system/tabletRezzer.js +++ b/scripts/system/tabletRezzer.js @@ -56,6 +56,7 @@ updateTimer = null, UPDATE_INTERVAL = 250, HIFI_OBJECT_MANIPULATION_CHANNEL = "Hifi-Object-Manipulation", + avatarScale = 1, LEFT_HAND = 0, RIGHT_HAND = 1, @@ -115,9 +116,10 @@ proxyOverlay = Overlays.addOverlay("cube", { parentID: MyAvatar.SELF_ID, parentJointIndex: handJointIndex(proxyHand), - localPosition: proxyHand === LEFT_HAND ? TABLET_PROXY_POSITION_LEFT_HAND : TABLET_PROXY_POSITION_RIGHT_HAND, + localPosition: Vec3.multiply(avatarScale, + proxyHand === LEFT_HAND ? TABLET_PROXY_POSITION_LEFT_HAND : TABLET_PROXY_POSITION_RIGHT_HAND), localRotation: proxyHand === LEFT_HAND ? TABLET_PROXY_ROTATION_LEFT_HAND : TABLET_PROXY_ROTATION_RIGHT_HAND, - dimensions: TABLET_PROXY_DIMENSIONS, + dimensions: Vec3.multiply(avatarScale, TABLET_PROXY_DIMENSIONS), solid: true, grabbable: true, displayInFront: true, @@ -130,7 +132,7 @@ if (scaleFactor < 1) { Overlays.editOverlay(proxyOverlay, { dimensions: Vec3.multiply( - 1 + scaleFactor * (proxyTargetWidth - proxyInitialWidth) / proxyInitialWidth, + avatarScale * (1 + scaleFactor * (proxyTargetWidth - proxyInitialWidth) / proxyInitialWidth), TABLET_PROXY_DIMENSIONS) }); proxyExpandTimer = Script.setTimeout(expandProxy, PROXY_EXPAND_TIMEOUT); @@ -282,6 +284,12 @@ updateTimer = Script.setTimeout(update, UPDATE_INTERVAL); } + function onScaleChanged() { + avatarScale = MyAvatar.scale; + // Clamp scale in order to work around M17434. + avatarScale = Math.max(MyAvatar.getDomainMinScale(), Math.min(MyAvatar.getDomainMaxScale(), avatarScale)); + } + function onMessageReceived(channel, data, senderID, localOnly) { var message; @@ -327,6 +335,8 @@ // #region Start-up and tear-down ========================================================================================== function setUp() { + MyAvatar.scaleChanged.connect(onScaleChanged); + Messages.subscribe(HIFI_OBJECT_MANIPULATION_CHANNEL); Messages.messageReceived.connect(onMessageReceived); @@ -343,6 +353,8 @@ Messages.messageReceived.disconnect(onMessageReceived); Messages.unsubscribe(HIFI_OBJECT_MANIPULATION_CHANNEL); + MyAvatar.scaleChanged.disconnect(onScaleChanged); + HMD.displayModeChanged.disconnect(onMountedChanged); HMD.mountedChanged.disconnect(onMountedChanged); if (updateTimer !== null) {