mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:03:53 +02:00
merge from upstream
This commit is contained in:
commit
5741782f45
6 changed files with 126 additions and 2 deletions
|
@ -27,6 +27,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
|||
var BASIC_TIMER_INTERVAL_MS = 1000 / TARGET_UPDATE_HZ;
|
||||
|
||||
var PROFILE = false;
|
||||
var DEBUG = false;
|
||||
|
||||
if (typeof Test !== "undefined") {
|
||||
PROFILE = true;
|
||||
|
@ -299,6 +300,9 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
|||
// activity-slots which this plugin consumes as "in use"
|
||||
_this.runningPluginNames[orderedPluginName] = true;
|
||||
_this.markSlots(candidatePlugin, orderedPluginName);
|
||||
if (DEBUG) {
|
||||
print("controllerDispatcher running " + orderedPluginName);
|
||||
}
|
||||
}
|
||||
if (PROFILE) {
|
||||
Script.endProfileRange("dispatch.isReady." + orderedPluginName);
|
||||
|
@ -331,6 +335,9 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js");
|
|||
// of running plugins and mark its activity-slots as "not in use"
|
||||
delete _this.runningPluginNames[runningPluginName];
|
||||
_this.markSlots(plugin, false);
|
||||
if (DEBUG) {
|
||||
print("controllerDispatcher stopping " + runningPluginName);
|
||||
}
|
||||
}
|
||||
if (PROFILE) {
|
||||
Script.endProfileRange("dispatch.run." + runningPluginName);
|
||||
|
|
|
@ -98,8 +98,13 @@ Script.include("/~/system/libraries/cloneEntityUtils.js");
|
|||
|
||||
if (this.thisHandIsParent(targetProps)) {
|
||||
// this should never happen, but if it does, don't set previous parent to be this hand.
|
||||
<<<<<<< HEAD
|
||||
this.previousParentID[targetProps.id] = null;
|
||||
this.previousParentJointIndex[targetProps.id] = -1;
|
||||
=======
|
||||
// this.previousParentID[targetProps.id] = NULL;
|
||||
// this.previousParentJointIndex[targetProps.id] = -1;
|
||||
>>>>>>> 030da7d850d0291e8e94443ee784b39881836c17
|
||||
} else {
|
||||
this.previousParentID[targetProps.id] = targetProps.parentID;
|
||||
this.previousParentJointIndex[targetProps.id] = targetProps.parentJointIndex;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// handControllerGrab.js
|
||||
// scaleAvatar.js
|
||||
//
|
||||
// Created by Dante Ruiz on 9/11/17
|
||||
//
|
||||
|
@ -80,4 +80,5 @@
|
|||
dispatcherUtils.disableDispatcherModule("LeftScaleAvatar");
|
||||
dispatcherUtils.disableDispatcherModule("RightScaleAvatar");
|
||||
};
|
||||
Script.scriptEnding.connect(this.cleanup);
|
||||
})();
|
||||
|
|
106
scripts/system/controllers/controllerModules/scaleEntity.js
Normal file
106
scripts/system/controllers/controllerModules/scaleEntity.js
Normal file
|
@ -0,0 +1,106 @@
|
|||
// scaleEntity.js
|
||||
//
|
||||
// Created by Dante Ruiz on 9/18/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 */
|
||||
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
|
||||
|
||||
(function() {
|
||||
var dispatcherUtils = Script.require("/~/system/libraries/controllerDispatcherUtils.js");
|
||||
|
||||
function ScaleEntity(hand) {
|
||||
this.hand = hand;
|
||||
this.grabbedThingID = false;
|
||||
this.scalingStartDistance = false;
|
||||
this.scalingStartDimensions = false;
|
||||
|
||||
this.parameters = dispatcherUtils.makeDispatcherModuleParameters(
|
||||
120,
|
||||
this.hand === RIGHT_HAND ? ["rightHandTrigger"] : ["leftHandTrigger"],
|
||||
[],
|
||||
100
|
||||
);
|
||||
|
||||
this.otherHand = function() {
|
||||
return this.hand === dispatcherUtils.RIGHT_HAND ? dispatcherUtils.LEFT_HAND : dispatcherUtils.RIGHT_HAND;
|
||||
};
|
||||
|
||||
this.otherModule = function() {
|
||||
return this.hand === dispatcherUtils.RIGHT_HAND ? leftScaleEntity : rightScaleEntity;
|
||||
};
|
||||
|
||||
this.bumperPressed = function(controllerData) {
|
||||
return ( controllerData.secondaryValues[this.hand] > dispatcherUtils.BUMPER_ON_VALUE);
|
||||
};
|
||||
|
||||
this.getTargetProps = function(controllerData) {
|
||||
// nearbyEntityProperties is already sorted by length from controller
|
||||
var nearbyEntityProperties = controllerData.nearbyEntityProperties[this.hand];
|
||||
var sensorScaleFactor = MyAvatar.sensorToWorldScale;
|
||||
for (var i = 0; i < nearbyEntityProperties.length; i++) {
|
||||
var props = nearbyEntityProperties[i];
|
||||
var handPosition = controllerData.controllerLocations[this.hand].position;
|
||||
var distance = Vec3.distance(props.position, handPosition);
|
||||
if (distance > dispatcherUtils.NEAR_GRAB_RADIUS * sensorScaleFactor) {
|
||||
continue;
|
||||
}
|
||||
if ((dispatcherUtils.entityIsGrabbable(props) ||
|
||||
dispatcherUtils.propsArePhysical(props)) && !props.locked) {
|
||||
return props;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
this.isReady = function(controllerData) {
|
||||
var otherModule = this.otherModule();
|
||||
if (this.bumperPressed(controllerData) && otherModule.bumperPressed(controllerData)) {
|
||||
var thisHandTargetProps = this.getTargetProps(controllerData);
|
||||
var otherHandTargetProps = otherModule.getTargetProps(controllerData);
|
||||
if (thisHandTargetProps && otherHandTargetProps) {
|
||||
if (thisHandTargetProps.id === otherHandTargetProps.id) {
|
||||
this.grabbedThingID = thisHandTargetProps.id;
|
||||
this.scalingStartDistance = Vec3.length(Vec3.subtract(controllerData.controllerLocations[this.hand].position,
|
||||
controllerData.controllerLocations[this.otherHand()].position));
|
||||
this.scalingStartDimensions = thisHandTargetProps.dimensions;
|
||||
return dispatcherUtils.makeRunningValues(true, [], []);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dispatcherUtils.makeRunningValues(false, [], []);
|
||||
};
|
||||
|
||||
this.run = function(controllerData) {
|
||||
var otherModule = this.otherModule();
|
||||
if (this.bumperPressed(controllerData) && otherModule.bumperPressed(controllerData)) {
|
||||
if (this.hand === dispatcherUtils.RIGHT_HAND) {
|
||||
var scalingCurrentDistance =
|
||||
Vec3.length(Vec3.subtract(controllerData.controllerLocations[this.hand].position,
|
||||
controllerData.controllerLocations[this.otherHand()].position));
|
||||
var currentRescale = scalingCurrentDistance / this.scalingStartDistance;
|
||||
var newDimensions = Vec3.multiply(currentRescale, this.scalingStartDimensions);
|
||||
Entities.editEntity(this.grabbedThingID, { dimensions: newDimensions });
|
||||
}
|
||||
return dispatcherUtils.makeRunningValues(true, [], []);
|
||||
}
|
||||
return dispatcherUtils.makeRunningValues(false, [], []);
|
||||
};
|
||||
}
|
||||
|
||||
var leftScaleEntity = new ScaleEntity(dispatcherUtils.LEFT_HAND);
|
||||
var rightScaleEntity = new ScaleEntity(dispatcherUtils.RIGHT_HAND);
|
||||
|
||||
dispatcherUtils.enableDispatcherModule("LeftScaleEntity", leftScaleEntity);
|
||||
dispatcherUtils.enableDispatcherModule("RightScaleEntity", rightScaleEntity);
|
||||
|
||||
this.cleanup = function() {
|
||||
dispatcherUtils.disableDispatcherModule("LeftScaleEntity");
|
||||
dispatcherUtils.disableDispatcherModule("RightScaleEntity");
|
||||
};
|
||||
Script.scriptEnding.connect(this.cleanup);
|
||||
})();
|
|
@ -29,7 +29,8 @@ var CONTOLLER_SCRIPTS = [
|
|||
"controllerModules/disableOtherModule.js",
|
||||
"controllerModules/farTrigger.js",
|
||||
"controllerModules/teleport.js",
|
||||
"controllerModules/scaleAvatar.js"
|
||||
"controllerModules/scaleAvatar.js",
|
||||
"controllerModules/scaleEntity.js"
|
||||
];
|
||||
|
||||
var DEBUG_MENU_ITEM = "Debug defaultScripts.js";
|
||||
|
|
|
@ -362,7 +362,11 @@ if (typeof module !== 'undefined') {
|
|||
RIGHT_HAND: RIGHT_HAND,
|
||||
BUMPER_ON_VALUE: BUMPER_ON_VALUE,
|
||||
TEAR_AWAY_DISTANCE: TEAR_AWAY_DISTANCE,
|
||||
propsArePhysical: propsArePhysical,
|
||||
entityIsGrabbable: entityIsGrabbable,
|
||||
NEAR_GRAB_RADIUS: NEAR_GRAB_RADIUS,
|
||||
projectOntoOverlayXYPlane: projectOntoOverlayXYPlane,
|
||||
projectOntoEntityXYPlane: projectOntoEntityXYPlane
|
||||
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue