mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 20:17:00 +02:00
* Added getDomainMaxScale() and getDomainMinScale() to JS api. * Updated scaleAvatar controller module to use this to prevent scaling past the limits. * Made sure that getDomainMaxScale() getDomainMinScale() and getUnscaledEyeHeight are thread safe, so that they can be invoked on the script thread. * Added signals to Model class that can be used to let observers know when the Rig has finished initializing it's skeleton. and also when the skeleton is no longer valid. These hooks are used to cache the unscaled eye height of the avatar.
88 lines
3.7 KiB
JavaScript
88 lines
3.7 KiB
JavaScript
// scaleAvatar.js
|
|
//
|
|
// Created by Dante Ruiz on 9/11/17
|
|
//
|
|
// Grabs physically moveable entities with hydra-like controllers; it works for either near or far objects.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
|
|
/* global Script, Vec3, MyAvatar, RIGHT_HAND */
|
|
|
|
(function () {
|
|
var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
|
|
|
|
function clamp(val, min, max) {
|
|
return Math.max(min, Math.min(max, val));
|
|
}
|
|
|
|
function ScaleAvatar(hand) {
|
|
this.hand = hand;
|
|
this.scalingStartAvatarScale = 0;
|
|
this.scalingStartDistance = 0;
|
|
|
|
this.parameters = dispatcherUtils.makeDispatcherModuleParameters(
|
|
120,
|
|
this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
|
|
[],
|
|
100
|
|
);
|
|
|
|
this.otherHand = function() {
|
|
return this.hand === dispatcherUtils.RIGHT_HAND ? dispatcherUtils.LEFT_HAND : dispatcherUtils.RIGHT_HAND;
|
|
};
|
|
|
|
this.getOtherModule = function() {
|
|
var otherModule = this.hand === dispatcherUtils.RIGHT_HAND ? leftScaleAvatar : rightScaleAvatar;
|
|
return otherModule;
|
|
};
|
|
|
|
this.triggersPressed = function(controllerData) {
|
|
if (controllerData.triggerClicks[this.hand] &&
|
|
controllerData.secondaryValues[this.hand] > dispatcherUtils.BUMPER_ON_VALUE) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
this.isReady = function(controllerData) {
|
|
var otherModule = this.getOtherModule();
|
|
if (this.triggersPressed(controllerData) && otherModule.triggersPressed(controllerData)) {
|
|
this.scalingStartAvatarScale = MyAvatar.scale;
|
|
this.scalingStartDistance = Vec3.length(Vec3.subtract(controllerData.controllerLocations[this.hand].position,
|
|
controllerData.controllerLocations[this.otherHand()].position));
|
|
return dispatcherUtils.makeRunningValues(true, [], []);
|
|
}
|
|
return dispatcherUtils.makeRunningValues(false, [], []);
|
|
};
|
|
|
|
this.run = function(controllerData) {
|
|
var otherModule = this.getOtherModule();
|
|
if (this.triggersPressed(controllerData) && otherModule.triggersPressed(controllerData)) {
|
|
if (this.hand === dispatcherUtils.RIGHT_HAND) {
|
|
var scalingCurrentDistance =
|
|
Vec3.length(Vec3.subtract(controllerData.controllerLocations[this.hand].position,
|
|
controllerData.controllerLocations[this.otherHand()].position));
|
|
|
|
var newAvatarScale = (scalingCurrentDistance / this.scalingStartDistance) * this.scalingStartAvatarScale;
|
|
MyAvatar.scale = clamp(newAvatarScale, MyAvatar.getDomainMinScale(), MyAvatar.getDomainMaxScale());
|
|
MyAvatar.scaleChanged();
|
|
}
|
|
return dispatcherUtils.makeRunningValues(true, [], []);
|
|
}
|
|
return dispatcherUtils.makeRunningValues(false, [], []);
|
|
};
|
|
}
|
|
|
|
var leftScaleAvatar = new ScaleAvatar(dispatcherUtils.LEFT_HAND);
|
|
var rightScaleAvatar = new ScaleAvatar(dispatcherUtils.RIGHT_HAND);
|
|
|
|
dispatcherUtils.enableDispatcherModule("LeftScaleAvatar", leftScaleAvatar);
|
|
dispatcherUtils.enableDispatcherModule("RightScaleAvatar", rightScaleAvatar);
|
|
|
|
function cleanup() {
|
|
dispatcherUtils.disableDispatcherModule("LeftScaleAvatar");
|
|
dispatcherUtils.disableDispatcherModule("RightScaleAvatar");
|
|
}
|
|
Script.scriptEnding.connect(cleanup);
|
|
})();
|