mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 15:50:37 +02:00
Equip-points attachments work
Also made handControllerGrab.js eslint clean.
This commit is contained in:
parent
43d4dba4c0
commit
6072487c9c
1 changed files with 82 additions and 115 deletions
|
@ -10,7 +10,7 @@
|
|||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, Reticle, Messages, setEntityCustomData, getEntityCustomData, vec3toStr, flatten, Xform */
|
||||
/* global setEntityCustomData, getEntityCustomData, vec3toStr, flatten, Xform */
|
||||
|
||||
Script.include("/~/system/libraries/utils.js");
|
||||
Script.include("../libraries/Xform.js");
|
||||
|
@ -255,7 +255,8 @@ function isIn2DMode() {
|
|||
// In this version, we make our own determination of whether we're aimed a HUD element,
|
||||
// because other scripts (such as handControllerPointer) might be using some other visualization
|
||||
// instead of setting Reticle.visible.
|
||||
return EXTERNALLY_MANAGED_2D_MINOR_MODE && (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(Reticle.position));
|
||||
return (EXTERNALLY_MANAGED_2D_MINOR_MODE &&
|
||||
(Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(Reticle.position)));
|
||||
}
|
||||
function restore2DMode() {
|
||||
if (!EXTERNALLY_MANAGED_2D_MINOR_MODE) {
|
||||
|
@ -296,9 +297,9 @@ EntityPropertiesCache.prototype.updateEntity = function(entityID) {
|
|||
};
|
||||
EntityPropertiesCache.prototype.getEntities = function() {
|
||||
return Object.keys(this.cache);
|
||||
}
|
||||
};
|
||||
EntityPropertiesCache.prototype.getProps = function(entityID) {
|
||||
var obj = this.cache[entityID]
|
||||
var obj = this.cache[entityID];
|
||||
return obj ? obj : undefined;
|
||||
};
|
||||
EntityPropertiesCache.prototype.getGrabbableProps = function(entityID) {
|
||||
|
@ -346,7 +347,7 @@ function MyController(hand) {
|
|||
this.getHandRotation = function() {
|
||||
var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
return Quat.multiply(MyAvatar.orientation, Controller.getPoseValue(controllerHandInput).rotation);
|
||||
}
|
||||
};
|
||||
|
||||
this.actionID = null; // action this script created...
|
||||
this.grabbedEntity = null; // on this entity.
|
||||
|
@ -419,7 +420,7 @@ function MyController(hand) {
|
|||
this.callEntityMethodOnGrabbed = function(entityMethodName) {
|
||||
var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID];
|
||||
Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args);
|
||||
}
|
||||
};
|
||||
|
||||
this.setState = function(newState, reason) {
|
||||
|
||||
|
@ -517,7 +518,7 @@ function MyController(hand) {
|
|||
ignoreRayIntersection: true,
|
||||
drawInFront: true, // Even when burried inside of something, show it.
|
||||
visible: true
|
||||
}
|
||||
};
|
||||
this.searchSphere = Overlays.addOverlay("sphere", sphereProperties);
|
||||
} else {
|
||||
Overlays.editOverlay(this.searchSphere, {
|
||||
|
@ -527,7 +528,7 @@ function MyController(hand) {
|
|||
visible: true
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.overlayLineOn = function(closePoint, farPoint, color) {
|
||||
if (this.overlayLine === null) {
|
||||
|
@ -576,7 +577,7 @@ function MyController(hand) {
|
|||
this.overlayLineOn(handPosition, searchSphereLocation,
|
||||
(this.triggerSmoothedGrab() || this.secondarySqueezed()) ? INTERSECT_COLOR : NO_INTERSECT_COLOR);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.handleDistantParticleBeam = function(handPosition, objectPosition, color) {
|
||||
|
||||
|
@ -643,7 +644,7 @@ function MyController(hand) {
|
|||
"alphaFinish": 1,
|
||||
"additiveBlending": 0,
|
||||
"textures": "https://hifi-content.s3.amazonaws.com/alan/dev/textures/grabsprite-3.png"
|
||||
}
|
||||
};
|
||||
|
||||
this.particleBeamObject = Entities.addEntity(particleBeamPropertiesObject);
|
||||
};
|
||||
|
@ -657,7 +658,7 @@ function MyController(hand) {
|
|||
emitSpeed: speed,
|
||||
speedSpread: spread,
|
||||
lifespan: lifespan
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
this.evalLightWorldTransform = function(modelPos, modelRot) {
|
||||
|
@ -713,7 +714,7 @@ function MyController(hand) {
|
|||
Entities.editEntity(this.spotlight, {
|
||||
// without this, this light would maintain rotation with its parent
|
||||
rotation: Quat.fromPitchYawRollDegrees(-90, 0, 0)
|
||||
})
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -777,7 +778,7 @@ function MyController(hand) {
|
|||
Entities.deleteEntity(this.particleBeamObject);
|
||||
this.particleBeamObject = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.turnLightsOff = function() {
|
||||
if (this.spotlight !== null) {
|
||||
|
@ -853,7 +854,7 @@ function MyController(hand) {
|
|||
|
||||
this.thumbPress = function(value) {
|
||||
_this.rawThumbValue = value;
|
||||
}
|
||||
};
|
||||
|
||||
this.thumbPressed = function() {
|
||||
return _this.rawThumbValue > THUMB_ON_VALUE;
|
||||
|
@ -1001,7 +1002,10 @@ function MyController(hand) {
|
|||
_this.entityPropertyCache.updateEntity(overlayInfo.entityID);
|
||||
props = _this.entityPropertyCache.getProps(overlayInfo.entityID);
|
||||
var entityXform = new Xform(props.rotation, props.position);
|
||||
Overlays.editOverlay(overlayInfo.overlay, { position: entityXform.xformPoint(overlayInfo.localPosition), rotation: props.rotation });
|
||||
Overlays.editOverlay(overlayInfo.overlay, {
|
||||
position: entityXform.xformPoint(overlayInfo.localPosition),
|
||||
rotation: props.rotation
|
||||
});
|
||||
} else if (overlayInfo.type === "near") {
|
||||
_this.entityPropertyCache.updateEntity(overlayInfo.entityID);
|
||||
props = _this.entityPropertyCache.getProps(overlayInfo.entityID);
|
||||
|
@ -1025,14 +1029,14 @@ function MyController(hand) {
|
|||
this.destroyHotspots();
|
||||
};
|
||||
|
||||
///
|
||||
// Performs ray pick test from the hand controller into the world
|
||||
// @param {number} which hand to use, RIGHT_HAND or LEFT_HAND
|
||||
// @returns {object} returns object with two keys entityID and distance
|
||||
//
|
||||
this.calcRayPickInfo = function(hand) {
|
||||
|
||||
var pose = Controller.getPoseValue((hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand);
|
||||
var standardControllerValue = (hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
var pose = Controller.getPoseValue(standardControllerValue);
|
||||
var worldHandPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, pose.translation), MyAvatar.position);
|
||||
var worldHandRotation = Quat.multiply(MyAvatar.orientation, pose.rotation);
|
||||
|
||||
|
@ -1071,14 +1075,17 @@ function MyController(hand) {
|
|||
}
|
||||
|
||||
var overlayIntersection = Overlays.findRayIntersection(pickRayBacked);
|
||||
if (!intersection.intersects || (overlayIntersection.intersects && (intersection.distance > overlayIntersection.distance))) {
|
||||
if (!intersection.intersects ||
|
||||
(overlayIntersection.intersects && (intersection.distance > overlayIntersection.distance))) {
|
||||
intersection = overlayIntersection;
|
||||
}
|
||||
|
||||
if (intersection.intersects) {
|
||||
return { entityID: intersection.entityID,
|
||||
return {
|
||||
entityID: intersection.entityID,
|
||||
searchRay: pickRay,
|
||||
distance: Vec3.distance(pickRay.origin, intersection.intersection) }
|
||||
distance: Vec3.distance(pickRay.origin, intersection.intersection)
|
||||
};
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
|
@ -1089,7 +1096,8 @@ function MyController(hand) {
|
|||
return grabbableProps && grabbableProps.wantsTrigger;
|
||||
};
|
||||
|
||||
/// @param {UUID} entityID
|
||||
// returns a list of all equip-hotspots assosiated with this entity.
|
||||
// @param {UUID} entityID
|
||||
// @returns {Object[]} array of objects with the following fields.
|
||||
// * entityID {UUID}
|
||||
// * localPosition {Vec3} position of the hotspot in object space.
|
||||
|
@ -1383,7 +1391,9 @@ function MyController(hand) {
|
|||
|
||||
// search line visualizations
|
||||
if (USE_ENTITY_LINES_FOR_SEARCHING === true) {
|
||||
this.lineOn(rayPickInfo.searchRay.origin, Vec3.multiply(rayPickInfo.searchRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR);
|
||||
this.lineOn(rayPickInfo.searchRay.origin,
|
||||
Vec3.multiply(rayPickInfo.searchRay.direction, LINE_LENGTH),
|
||||
NO_INTERSECT_COLOR);
|
||||
}
|
||||
|
||||
this.searchIndicatorOn(rayPickInfo.searchRay);
|
||||
|
@ -1398,11 +1408,11 @@ function MyController(hand) {
|
|||
timeScale = DISTANCE_HOLDING_ACTION_TIMEFRAME;
|
||||
}
|
||||
return timeScale;
|
||||
}
|
||||
};
|
||||
|
||||
this.getMass = function(dimensions, density) {
|
||||
return (dimensions.x * dimensions.y * dimensions.z) * density;
|
||||
}
|
||||
};
|
||||
|
||||
this.distanceHoldingEnter = function() {
|
||||
|
||||
|
@ -1529,7 +1539,8 @@ function MyController(hand) {
|
|||
|
||||
var RADIAL_GRAB_AMPLIFIER = 10.0;
|
||||
if (Math.abs(this.grabRadialVelocity) > 0.0) {
|
||||
this.grabRadius = this.grabRadius + (this.grabRadialVelocity * deltaObjectTime * this.grabRadius * RADIAL_GRAB_AMPLIFIER);
|
||||
this.grabRadius = this.grabRadius + (this.grabRadialVelocity * deltaObjectTime *
|
||||
this.grabRadius * RADIAL_GRAB_AMPLIFIER);
|
||||
}
|
||||
|
||||
var newTargetPosition = Vec3.multiply(this.grabRadius, Quat.getUp(controllerRotation));
|
||||
|
@ -1557,27 +1568,6 @@ function MyController(hand) {
|
|||
}
|
||||
}
|
||||
|
||||
// var defaultConstraintData = {
|
||||
// axisStart: false,
|
||||
// axisEnd: false
|
||||
// }
|
||||
//
|
||||
// var constraintData = getEntityCustomData('lightModifierKey', this.grabbedEntity, defaultConstraintData);
|
||||
// var clampedVector;
|
||||
// var targetPosition;
|
||||
// if (constraintData.axisStart !== false) {
|
||||
// clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition,
|
||||
// constraintData.axisStart,
|
||||
// constraintData.axisEnd);
|
||||
// targetPosition = clampedVector;
|
||||
// } else {
|
||||
// targetPosition = {
|
||||
// x: this.currentObjectPosition.x,
|
||||
// y: this.currentObjectPosition.y,
|
||||
// z: this.currentObjectPosition.z
|
||||
// }
|
||||
// }
|
||||
|
||||
var handPosition = this.getHandPosition();
|
||||
|
||||
// visualizations
|
||||
|
@ -1588,7 +1578,7 @@ function MyController(hand) {
|
|||
this.overlayLineOn(handPosition, grabbedProperties.position, INTERSECT_COLOR);
|
||||
}
|
||||
if (USE_PARTICLE_BEAM_FOR_MOVING === true) {
|
||||
this.handleDistantParticleBeam(handPosition, grabbedProperties.position, INTERSECT_COLOR)
|
||||
this.handleDistantParticleBeam(handPosition, grabbedProperties.position, INTERSECT_COLOR);
|
||||
}
|
||||
if (USE_POINTLIGHT === true) {
|
||||
this.handlePointLight(this.grabbedEntity);
|
||||
|
@ -1648,46 +1638,17 @@ function MyController(hand) {
|
|||
scalar = 1;
|
||||
}
|
||||
var projection = Vec3.sum(axisStart, Vec3.multiply(scalar, Vec3.normalize(bPrime)));
|
||||
return projection
|
||||
return projection;
|
||||
};
|
||||
|
||||
this.hasPresetOffsets = function() {
|
||||
var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}});
|
||||
if ("joints" in wearableData) {
|
||||
var allowedJoints = wearableData.joints;
|
||||
var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand";
|
||||
if (handJointName in allowedJoints) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
this.getPresetPosition = function() {
|
||||
var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}});
|
||||
var allowedJoints = wearableData.joints;
|
||||
var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand";
|
||||
if (handJointName in allowedJoints) {
|
||||
return allowedJoints[handJointName][0];
|
||||
}
|
||||
}
|
||||
|
||||
this.getPresetRotation = function() {
|
||||
var wearableData = getEntityCustomData('wearable', this.grabbedEntity, {joints: {}});
|
||||
var allowedJoints = wearableData.joints;
|
||||
var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand";
|
||||
if (handJointName in allowedJoints) {
|
||||
return allowedJoints[handJointName][1];
|
||||
}
|
||||
}
|
||||
|
||||
this.dropGestureReset = function() {
|
||||
this.fastHandMoveDetected = false;
|
||||
this.fastHandMoveTimer = 0;
|
||||
};
|
||||
|
||||
this.dropGestureProcess = function(deltaTime) {
|
||||
var pose = Controller.getPoseValue((this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand);
|
||||
var standardControllerValue = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
var pose = Controller.getPoseValue(standardControllerValue);
|
||||
var worldHandVelocity = Vec3.multiplyQbyV(MyAvatar.orientation, pose.velocity);
|
||||
var worldHandRotation = Quat.multiply(MyAvatar.orientation, pose.rotation);
|
||||
|
||||
|
@ -1745,13 +1706,17 @@ function MyController(hand) {
|
|||
var handPosition = this.getHandPosition();
|
||||
|
||||
var hasPresetPosition = false;
|
||||
if (this.state == STATE_HOLD && this.hasPresetOffsets()) {
|
||||
if (this.state == STATE_HOLD && this.grabbedHotspot) {
|
||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
||||
// if an object is "equipped" and has a predefined offset, use it.
|
||||
this.ignoreIK = grabbableData.ignoreIK ? grabbableData.ignoreIK : false;
|
||||
this.offsetPosition = this.getPresetPosition();
|
||||
this.offsetRotation = this.getPresetRotation();
|
||||
|
||||
var handJointName = this.hand === RIGHT_HAND ? "RightHand" : "LeftHand";
|
||||
if (this.grabbedHotspot.joints[handJointName]) {
|
||||
this.offsetPosition = this.grabbedHotspot.joints[handJointName][0];
|
||||
this.offsetRotation = this.grabbedHotspot.joints[handJointName][1];
|
||||
hasPresetPosition = true;
|
||||
}
|
||||
} else {
|
||||
this.ignoreIK = false;
|
||||
|
||||
|
@ -1784,7 +1749,7 @@ function MyController(hand) {
|
|||
var reparentProps = {
|
||||
parentID: MyAvatar.sessionUUID,
|
||||
parentJointIndex: handJointIndex
|
||||
}
|
||||
};
|
||||
if (hasPresetPosition) {
|
||||
reparentProps["localPosition"] = this.offsetPosition;
|
||||
reparentProps["localRotation"] = this.offsetRotation;
|
||||
|
@ -2022,6 +1987,7 @@ function MyController(hand) {
|
|||
}));
|
||||
|
||||
this.grabbedEntity = null;
|
||||
this.grabbedHotspot = null;
|
||||
|
||||
if (this.triggerSmoothedGrab()) {
|
||||
this.waitForTriggerRelease = true;
|
||||
|
@ -2124,7 +2090,7 @@ function MyController(hand) {
|
|||
print("disconnecting stray child of hand: (" + _this.hand + ") " + childID);
|
||||
Entities.editEntity(childID, {parentID: NULL_UUID});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.deactivateEntity = function(entityID, noVelocity) {
|
||||
var deactiveProps;
|
||||
|
@ -2149,7 +2115,7 @@ function MyController(hand) {
|
|||
|
||||
// things that are held by parenting and dropped with no velocity will end up as "static" in bullet. If
|
||||
// it looks like the dropped thing should fall, give it a little velocity.
|
||||
var props = Entities.getEntityProperties(entityID, ["parentID", "velocity", "dynamic", "shapeType"])
|
||||
var props = Entities.getEntityProperties(entityID, ["parentID", "velocity", "dynamic", "shapeType"]);
|
||||
var parentID = props.parentID;
|
||||
|
||||
var doSetVelocity = false;
|
||||
|
@ -2231,7 +2197,8 @@ mapping.from([Controller.Standard.RightPrimaryThumb]).peek().to(rightController.
|
|||
|
||||
Controller.enableMapping(MAPPING_NAME);
|
||||
|
||||
//the section below allows the grab script to listen for messages that disable either one or both hands. useful for two handed items
|
||||
// the section below allows the grab script to listen for messages
|
||||
// that disable either one or both hands. useful for two handed items
|
||||
var handToDisable = 'none';
|
||||
|
||||
function update(deltaTime) {
|
||||
|
@ -2294,7 +2261,7 @@ var handleHandMessages = function(channel, message, sender) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Messages.messageReceived.connect(handleHandMessages);
|
||||
|
||||
|
|
Loading…
Reference in a new issue