mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 14:09:01 +02:00
Code tidying
This commit is contained in:
parent
5fd3f563d6
commit
baf1e80445
1 changed files with 18 additions and 24 deletions
|
@ -29,7 +29,6 @@
|
||||||
// Miscellaneous.
|
// Miscellaneous.
|
||||||
HIFI_OBJECT_MANIPULATION_CHANNEL = "Hifi-Object-Manipulation",
|
HIFI_OBJECT_MANIPULATION_CHANNEL = "Hifi-Object-Manipulation",
|
||||||
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"),
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"),
|
||||||
avatarScale = 1, // Sanitized MyAvatar.scale.
|
|
||||||
DEBUG = false;
|
DEBUG = false;
|
||||||
|
|
||||||
// #region Utilities =======================================================================================================
|
// #region Utilities =======================================================================================================
|
||||||
|
@ -263,13 +262,13 @@
|
||||||
Overlays.editOverlay(miniOverlay, {
|
Overlays.editOverlay(miniOverlay, {
|
||||||
parentID: MyAvatar.SELF_ID,
|
parentID: MyAvatar.SELF_ID,
|
||||||
parentJointIndex: handJointIndex(hand),
|
parentJointIndex: handJointIndex(hand),
|
||||||
localPosition: Vec3.multiply(avatarScale, MINI_POSITIONS[hand]),
|
localPosition: Vec3.multiply(MyAvatar.scale, MINI_POSITIONS[hand]),
|
||||||
localRotation: MINI_ROTATIONS[hand],
|
localRotation: MINI_ROTATIONS[hand],
|
||||||
dimensions: Vec3.multiply(initialScale, MINI_DIMENSIONS),
|
dimensions: Vec3.multiply(initialScale, MINI_DIMENSIONS),
|
||||||
visible: true
|
visible: true
|
||||||
});
|
});
|
||||||
Overlays.editOverlay(miniUIOverlay, {
|
Overlays.editOverlay(miniUIOverlay, {
|
||||||
localPosition: Vec3.multiply(avatarScale, MINI_UI_LOCAL_POSITION),
|
localPosition: Vec3.multiply(MyAvatar.scale, MINI_UI_LOCAL_POSITION),
|
||||||
localRotation: MINI_UI_LOCAL_ROTATION,
|
localRotation: MINI_UI_LOCAL_ROTATION,
|
||||||
dimensions: Vec3.multiply(initialScale, MINI_UI_DIMENSIONS),
|
dimensions: Vec3.multiply(initialScale, MINI_UI_DIMENSIONS),
|
||||||
dpi: MINI_UI_DPI / initialScale,
|
dpi: MINI_UI_DPI / initialScale,
|
||||||
|
@ -330,7 +329,7 @@
|
||||||
localRotation,
|
localRotation,
|
||||||
localPosition;
|
localPosition;
|
||||||
|
|
||||||
tabletScaleFactor = avatarScale * (1 + scaleFactor * (miniTargetWidth - miniInitialWidth) / miniInitialWidth);
|
tabletScaleFactor = MyAvatar.scale * (1 + scaleFactor * (miniTargetWidth - miniInitialWidth) / miniInitialWidth);
|
||||||
dimensions = Vec3.multiply(tabletScaleFactor, MINI_DIMENSIONS);
|
dimensions = Vec3.multiply(tabletScaleFactor, MINI_DIMENSIONS);
|
||||||
localRotation = Quat.mix(miniExpandLocalRotation, miniTargetLocalRotation, scaleFactor);
|
localRotation = Quat.mix(miniExpandLocalRotation, miniTargetLocalRotation, scaleFactor);
|
||||||
localPosition =
|
localPosition =
|
||||||
|
@ -368,7 +367,7 @@
|
||||||
function create() {
|
function create() {
|
||||||
miniOverlay = Overlays.addOverlay("model", {
|
miniOverlay = Overlays.addOverlay("model", {
|
||||||
url: MINI_MODEL,
|
url: MINI_MODEL,
|
||||||
dimensions: Vec3.multiply(avatarScale, MINI_DIMENSIONS),
|
dimensions: Vec3.multiply(MyAvatar.scale, MINI_DIMENSIONS),
|
||||||
solid: true,
|
solid: true,
|
||||||
grabbable: true,
|
grabbable: true,
|
||||||
showKeyboardFocusHighlight: false,
|
showKeyboardFocusHighlight: false,
|
||||||
|
@ -378,10 +377,10 @@
|
||||||
miniUIOverlay = Overlays.addOverlay("web3d", {
|
miniUIOverlay = Overlays.addOverlay("web3d", {
|
||||||
url: MINI_UI_HTML,
|
url: MINI_UI_HTML,
|
||||||
parentID: miniOverlay,
|
parentID: miniOverlay,
|
||||||
localPosition: Vec3.multiply(avatarScale, MINI_UI_LOCAL_POSITION),
|
localPosition: Vec3.multiply(MyAvatar.scale, MINI_UI_LOCAL_POSITION),
|
||||||
localRotation: MINI_UI_LOCAL_ROTATION,
|
localRotation: MINI_UI_LOCAL_ROTATION,
|
||||||
dimensions: Vec3.multiply(avatarScale, MINI_UI_DIMENSIONS),
|
dimensions: Vec3.multiply(MyAvatar.scale, MINI_UI_DIMENSIONS),
|
||||||
dpi: MINI_UI_DPI / avatarScale,
|
dpi: MINI_UI_DPI / MyAvatar.scale,
|
||||||
alpha: 0, // Hide overlay while its content is being created.
|
alpha: 0, // Hide overlay while its content is being created.
|
||||||
grabbable: false,
|
grabbable: false,
|
||||||
showKeyboardFocusHighlight: false,
|
showKeyboardFocusHighlight: false,
|
||||||
|
@ -394,7 +393,7 @@
|
||||||
miniOverlayObject = Overlays.getOverlayObject(miniUIOverlay);
|
miniOverlayObject = Overlays.getOverlayObject(miniUIOverlay);
|
||||||
miniOverlayObject.webEventReceived.connect(onWebEventReceived);
|
miniOverlayObject.webEventReceived.connect(onWebEventReceived);
|
||||||
|
|
||||||
// updateMiniTabletID(); Other scripts relying on this may not be ready yet so do this in showUI().
|
// updateMiniTabletID(); Other scripts relying on this may not be ready yet so do this in show().
|
||||||
}
|
}
|
||||||
|
|
||||||
function destroy() {
|
function destroy() {
|
||||||
|
@ -523,7 +522,7 @@
|
||||||
Vec3.multiplyQbyV(MyAvatar.orientation, MyAvatar.getAbsoluteJointTranslationInObjectFrame(jointIndex)));
|
Vec3.multiplyQbyV(MyAvatar.orientation, MyAvatar.getAbsoluteJointTranslationInObjectFrame(jointIndex)));
|
||||||
handOrientation = Quat.multiply(MyAvatar.orientation, MyAvatar.getAbsoluteJointRotationInObjectFrame(jointIndex));
|
handOrientation = Quat.multiply(MyAvatar.orientation, MyAvatar.getAbsoluteJointRotationInObjectFrame(jointIndex));
|
||||||
uiPositionAndOrientation = ui.getUIPositionAndRotation(hand);
|
uiPositionAndOrientation = ui.getUIPositionAndRotation(hand);
|
||||||
miniPosition = Vec3.sum(handPosition, Vec3.multiply(avatarScale,
|
miniPosition = Vec3.sum(handPosition, Vec3.multiply(MyAvatar.scale,
|
||||||
Vec3.multiplyQbyV(handOrientation, uiPositionAndOrientation.position)));
|
Vec3.multiplyQbyV(handOrientation, uiPositionAndOrientation.position)));
|
||||||
miniOrientation = Quat.multiply(handOrientation, uiPositionAndOrientation.rotation);
|
miniOrientation = Quat.multiply(handOrientation, uiPositionAndOrientation.rotation);
|
||||||
miniToCameraDirection = Vec3.normalize(Vec3.subtract(Camera.position, miniPosition));
|
miniToCameraDirection = Vec3.normalize(Vec3.subtract(Camera.position, miniPosition));
|
||||||
|
@ -566,7 +565,7 @@
|
||||||
function scaleMiniDown() {
|
function scaleMiniDown() {
|
||||||
var scaleFactor = (Date.now() - miniScaleStart) / MINI_SCALE_DURATION;
|
var scaleFactor = (Date.now() - miniScaleStart) / MINI_SCALE_DURATION;
|
||||||
if (scaleFactor < 1) {
|
if (scaleFactor < 1) {
|
||||||
ui.size((1 - scaleFactor) * avatarScale);
|
ui.size((1 - scaleFactor) * MyAvatar.scale);
|
||||||
miniScaleTimer = Script.setTimeout(scaleMiniDown, MINI_SCALE_TIMEOUT);
|
miniScaleTimer = Script.setTimeout(scaleMiniDown, MINI_SCALE_TIMEOUT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -595,12 +594,12 @@
|
||||||
function scaleMiniUp() {
|
function scaleMiniUp() {
|
||||||
var scaleFactor = (Date.now() - miniScaleStart) / MINI_SCALE_DURATION;
|
var scaleFactor = (Date.now() - miniScaleStart) / MINI_SCALE_DURATION;
|
||||||
if (scaleFactor < 1) {
|
if (scaleFactor < 1) {
|
||||||
ui.size(scaleFactor * avatarScale);
|
ui.size(scaleFactor * MyAvatar.scale);
|
||||||
miniScaleTimer = Script.setTimeout(scaleMiniUp, MINI_SCALE_TIMEOUT);
|
miniScaleTimer = Script.setTimeout(scaleMiniUp, MINI_SCALE_TIMEOUT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
miniScaleTimer = null;
|
miniScaleTimer = null;
|
||||||
ui.size(avatarScale);
|
ui.size(MyAvatar.scale);
|
||||||
setState(MINI_VISIBLE);
|
setState(MINI_VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,12 +830,6 @@
|
||||||
|
|
||||||
// #region External Events =================================================================================================
|
// #region External Events =================================================================================================
|
||||||
|
|
||||||
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) {
|
function onMessageReceived(channel, data, senderID, localOnly) {
|
||||||
var message,
|
var message,
|
||||||
miniHand,
|
miniHand,
|
||||||
|
@ -846,7 +839,12 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
message = JSON.parse(data);
|
try {
|
||||||
|
message = JSON.parse(data);
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.grabbedEntity !== ui.getMiniTabletID()) {
|
if (message.grabbedEntity !== ui.getMiniTabletID()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -881,8 +879,6 @@
|
||||||
function setUp() {
|
function setUp() {
|
||||||
miniState = new State();
|
miniState = new State();
|
||||||
|
|
||||||
MyAvatar.scaleChanged.connect(onScaleChanged);
|
|
||||||
|
|
||||||
Messages.subscribe(HIFI_OBJECT_MANIPULATION_CHANNEL);
|
Messages.subscribe(HIFI_OBJECT_MANIPULATION_CHANNEL);
|
||||||
Messages.messageReceived.connect(onMessageReceived);
|
Messages.messageReceived.connect(onMessageReceived);
|
||||||
|
|
||||||
|
@ -900,8 +896,6 @@
|
||||||
Messages.messageReceived.disconnect(onMessageReceived);
|
Messages.messageReceived.disconnect(onMessageReceived);
|
||||||
Messages.unsubscribe(HIFI_OBJECT_MANIPULATION_CHANNEL);
|
Messages.unsubscribe(HIFI_OBJECT_MANIPULATION_CHANNEL);
|
||||||
|
|
||||||
MyAvatar.scaleChanged.disconnect(onScaleChanged);
|
|
||||||
|
|
||||||
miniState.destroy();
|
miniState.destroy();
|
||||||
miniState = null;
|
miniState = null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue