mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
handControllerGrab.js is now eslint clean.
This commit is contained in:
parent
b01eb0439d
commit
28b6cc2777
1 changed files with 43 additions and 84 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, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */
|
||||
/*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 */
|
||||
|
||||
Script.include("/~/system/libraries/utils.js");
|
||||
|
||||
|
@ -47,7 +47,6 @@ var DISTANCE_HOLDING_RADIUS_FACTOR = 3.5; // multiplied by distance between hand
|
|||
var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position
|
||||
var DISTANCE_HOLDING_UNITY_MASS = 1200; // The mass at which the distance holding action timeframe is unmodified
|
||||
var DISTANCE_HOLDING_UNITY_DISTANCE = 6; // The distance at which the distance holding action timeframe is unmodified
|
||||
var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did
|
||||
var MOVE_WITH_HEAD = true; // experimental head-control of distantly held objects
|
||||
var FAR_TO_NEAR_GRAB_PADDING_FACTOR = 1.2;
|
||||
|
||||
|
@ -81,13 +80,6 @@ var NEAR_GRABBING_KINEMATIC = true; // force objects to be kinematic when near-g
|
|||
var SHOW_GRAB_SPHERE = false; // draw a green sphere to show the grab search position and size
|
||||
var CHECK_TOO_FAR_UNEQUIP_TIME = 1.0; // seconds
|
||||
|
||||
//
|
||||
// equip
|
||||
//
|
||||
|
||||
var EQUIP_SPRING_SHUTOFF_DISTANCE = 0.05;
|
||||
var EQUIP_SPRING_TIMEFRAME = 0.4; // how quickly objects move to their new position
|
||||
|
||||
//
|
||||
// other constants
|
||||
//
|
||||
|
@ -158,7 +150,7 @@ var STATE_SEARCHING = 1;
|
|||
var STATE_HOLD_SEARCHING = 2;
|
||||
var STATE_DISTANCE_HOLDING = 3;
|
||||
var STATE_NEAR_GRABBING = 4;
|
||||
var STATE_NEAR_TRIGGER = 4;
|
||||
var STATE_NEAR_TRIGGER = 5;
|
||||
var STATE_CONTINUE_NEAR_TRIGGER = 6;
|
||||
var STATE_FAR_TRIGGER = 7;
|
||||
var STATE_CONTINUE_FAR_TRIGGER = 8;
|
||||
|
@ -200,7 +192,7 @@ CONTROLLER_STATE_MACHINE[STATE_NEAR_GRABBING] = {
|
|||
updateMethod: "nearGrabbing"
|
||||
};
|
||||
CONTROLLER_STATE_MACHINE[STATE_HOLD] = {
|
||||
name: "continue_hold",
|
||||
name: "hold",
|
||||
enterMethod: "nearGrabbingEnter",
|
||||
updateMethod: "nearGrabbing"
|
||||
};
|
||||
|
@ -505,7 +497,7 @@ function MyController(hand) {
|
|||
this.overlayLine = Overlays.addOverlay("line3d", lineProperties);
|
||||
|
||||
} else {
|
||||
var success = Overlays.editOverlay(this.overlayLine, {
|
||||
Overlays.editOverlay(this.overlayLine, {
|
||||
lineWidth: 5,
|
||||
start: closePoint,
|
||||
end: farPoint,
|
||||
|
@ -621,13 +613,6 @@ function MyController(hand) {
|
|||
})
|
||||
};
|
||||
|
||||
this.renewParticleBeamLifetime = function() {
|
||||
var props = Entities.getEntityProperties(this.particleBeamObject, "age");
|
||||
Entities.editEntity(this.particleBeamObject, {
|
||||
lifetime: TEMPORARY_PARTICLE_BEAM_LIFETIME + props.age // renew lifetime
|
||||
})
|
||||
}
|
||||
|
||||
this.evalLightWorldTransform = function(modelPos, modelRot) {
|
||||
|
||||
var MODEL_LIGHT_POSITION = {
|
||||
|
@ -648,7 +633,7 @@ function MyController(hand) {
|
|||
};
|
||||
};
|
||||
|
||||
this.handleSpotlight = function(parentID, position) {
|
||||
this.handleSpotlight = function(parentID) {
|
||||
var LIFETIME = 100;
|
||||
|
||||
var modelProperties = Entities.getEntityProperties(parentID, ['position', 'rotation']);
|
||||
|
@ -672,7 +657,7 @@ function MyController(hand) {
|
|||
exponent: 0.3,
|
||||
cutoff: 20,
|
||||
lifetime: LIFETIME,
|
||||
position: lightTransform.p,
|
||||
position: lightTransform.p
|
||||
};
|
||||
|
||||
if (this.spotlight === null) {
|
||||
|
@ -680,12 +665,12 @@ function MyController(hand) {
|
|||
} else {
|
||||
Entities.editEntity(this.spotlight, {
|
||||
//without this, this light would maintain rotation with its parent
|
||||
rotation: Quat.fromPitchYawRollDegrees(-90, 0, 0),
|
||||
rotation: Quat.fromPitchYawRollDegrees(-90, 0, 0)
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
this.handlePointLight = function(parentID, position) {
|
||||
this.handlePointLight = function(parentID) {
|
||||
var LIFETIME = 100;
|
||||
|
||||
var modelProperties = Entities.getEntityProperties(parentID, ['position', 'rotation']);
|
||||
|
@ -709,13 +694,11 @@ function MyController(hand) {
|
|||
exponent: 0.3,
|
||||
cutoff: 20,
|
||||
lifetime: LIFETIME,
|
||||
position: lightTransform.p,
|
||||
position: lightTransform.p
|
||||
};
|
||||
|
||||
if (this.pointlight === null) {
|
||||
this.pointlight = Entities.addEntity(lightProperties);
|
||||
} else {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -915,12 +898,9 @@ function MyController(hand) {
|
|||
}
|
||||
|
||||
var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
var currentHandRotation = Controller.getPoseValue(controllerHandInput).rotation;
|
||||
var currentControllerPosition = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation,
|
||||
Controller.getPoseValue(controllerHandInput).translation),
|
||||
MyAvatar.position);
|
||||
var handDeltaRotation = Quat.multiply(currentHandRotation, Quat.inverse(this.startingHandRotation));
|
||||
|
||||
var avatarControllerPose = Controller.getPoseValue((this.hand === RIGHT_HAND) ?
|
||||
Controller.Standard.RightHand : Controller.Standard.LeftHand);
|
||||
var controllerRotation = Quat.multiply(MyAvatar.orientation, avatarControllerPose.rotation);
|
||||
|
@ -941,7 +921,7 @@ function MyController(hand) {
|
|||
this.lastPickTime = now;
|
||||
}
|
||||
|
||||
rayPickedCandidateEntities = []; // the list of candidates to consider grabbing
|
||||
var rayPickedCandidateEntities = []; // the list of candidates to consider grabbing
|
||||
|
||||
this.intersectionDistance = 0.0;
|
||||
for (var index = 0; index < pickRays.length; ++index) {
|
||||
|
@ -974,8 +954,8 @@ function MyController(hand) {
|
|||
}
|
||||
}
|
||||
|
||||
nearPickedCandidateEntities = Entities.findEntities(handPosition, GRAB_RADIUS);
|
||||
candidateEntities = rayPickedCandidateEntities.concat(nearPickedCandidateEntities);
|
||||
var nearPickedCandidateEntities = Entities.findEntities(handPosition, GRAB_RADIUS);
|
||||
var candidateEntities = rayPickedCandidateEntities.concat(nearPickedCandidateEntities);
|
||||
|
||||
var forbiddenNames = ["Grab Debug Entity", "grab pointer"];
|
||||
var forbiddenTypes = ['Unknown', 'Light', 'PolyLine', 'Zone'];
|
||||
|
@ -990,9 +970,9 @@ function MyController(hand) {
|
|||
var propsForCandidate = Entities.getEntityProperties(candidateEntities[i], GRABBABLE_PROPERTIES);
|
||||
var near = (nearPickedCandidateEntities.indexOf(candidateEntities[i]) >= 0);
|
||||
|
||||
var isPhysical = propsArePhysical(propsForCandidate);
|
||||
var physical = propsArePhysical(propsForCandidate);
|
||||
var grabbable;
|
||||
if (isPhysical) {
|
||||
if (physical) {
|
||||
// physical things default to grabbable
|
||||
grabbable = true;
|
||||
} else {
|
||||
|
@ -1051,7 +1031,7 @@ function MyController(hand) {
|
|||
}
|
||||
|
||||
if (this.state == STATE_SEARCHING &&
|
||||
!isPhysical && distance > NEAR_PICK_MAX_DISTANCE && !near && !grabbableDataForCandidate.wantsTrigger) {
|
||||
!physical && distance > NEAR_PICK_MAX_DISTANCE && !near && !grabbableDataForCandidate.wantsTrigger) {
|
||||
// we can't distance-grab non-physical
|
||||
if (WANT_DEBUG_SEARCH_NAME && propsForCandidate.name == WANT_DEBUG_SEARCH_NAME) {
|
||||
print("grab is skipping '" + WANT_DEBUG_SEARCH_NAME + "': not physical and too far for near-grab");
|
||||
|
@ -1068,18 +1048,18 @@ function MyController(hand) {
|
|||
}
|
||||
if ((this.grabbedEntity !== null) && (this.triggerSmoothedGrab() || this.secondarySqueezed())) {
|
||||
// We are squeezing enough to grab, and we've found an entity that we'll try to do something with.
|
||||
var near = (nearPickedCandidateEntities.indexOf(this.grabbedEntity) >= 0) || minDistance <= NEAR_PICK_MAX_DISTANCE;
|
||||
var isNear = (nearPickedCandidateEntities.indexOf(this.grabbedEntity) >= 0) || minDistance <= NEAR_PICK_MAX_DISTANCE;
|
||||
var isPhysical = propsArePhysical(props);
|
||||
|
||||
// near or far trigger
|
||||
if (grabbableData.wantsTrigger) {
|
||||
this.setState(near ? STATE_NEAR_TRIGGER : STATE_FAR_TRIGGER);
|
||||
this.setState(isNear ? STATE_NEAR_TRIGGER : STATE_FAR_TRIGGER);
|
||||
return;
|
||||
}
|
||||
// near grab with action or equip
|
||||
var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {});
|
||||
var refCount = ("refCount" in grabData) ? grabData.refCount : 0;
|
||||
if (near && (refCount < 1 || entityHasActions(this.grabbedEntity))) {
|
||||
if (isNear && (refCount < 1 || entityHasActions(this.grabbedEntity))) {
|
||||
if (this.state == STATE_SEARCHING) {
|
||||
this.setState(STATE_NEAR_GRABBING);
|
||||
} else { // (this.state == STATE_HOLD_SEARCHING)
|
||||
|
@ -1092,7 +1072,7 @@ function MyController(hand) {
|
|||
return;
|
||||
}
|
||||
// far grab
|
||||
if (isPhysical && !near) {
|
||||
if (isPhysical && !isNear) {
|
||||
if (entityIsGrabbedByOther(this.grabbedEntity)) {
|
||||
// don't distance grab something that is already grabbed.
|
||||
if (WANT_DEBUG_SEARCH_NAME && props.name == WANT_DEBUG_SEARCH_NAME) {
|
||||
|
@ -1142,9 +1122,6 @@ function MyController(hand) {
|
|||
}
|
||||
return;
|
||||
}
|
||||
if (WANT_DEBUG_SEARCH_NAME && props.name == WANT_DEBUG_SEARCH_NAME) {
|
||||
print("grab is skipping '" + WANT_DEBUG_SEARCH_NAME + "': fell through.");
|
||||
}
|
||||
}
|
||||
|
||||
//search line visualizations
|
||||
|
@ -1266,10 +1243,13 @@ function MyController(hand) {
|
|||
radius);
|
||||
|
||||
// double delta controller rotation
|
||||
/*
|
||||
var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did
|
||||
var handChange = Quat.multiply(Quat.slerp(this.previousControllerRotation,
|
||||
controllerRotation,
|
||||
DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR),
|
||||
Quat.inverse(this.previousControllerRotation));
|
||||
*/
|
||||
|
||||
// update the currentObject position and rotation.
|
||||
this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, handMoved);
|
||||
|
@ -1323,9 +1303,10 @@ function MyController(hand) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
var defaultConstraintData = {
|
||||
axisStart: false,
|
||||
axisEnd: false,
|
||||
axisEnd: false
|
||||
}
|
||||
|
||||
var constraintData = getEntityCustomData('lightModifierKey', this.grabbedEntity, defaultConstraintData);
|
||||
|
@ -1343,6 +1324,7 @@ function MyController(hand) {
|
|||
z: this.currentObjectPosition.z
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
var handPosition = this.getHandPosition();
|
||||
|
||||
|
@ -1448,7 +1430,6 @@ function MyController(hand) {
|
|||
}
|
||||
|
||||
this.nearGrabbingEnter = function() {
|
||||
var now = Date.now();
|
||||
|
||||
this.lineOff();
|
||||
this.overlayLineOff();
|
||||
|
@ -1503,7 +1484,7 @@ function MyController(hand) {
|
|||
// grab entity via parenting
|
||||
this.actionID = null;
|
||||
var handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "RightHand" : "LeftHand");
|
||||
reparentProps = {
|
||||
var reparentProps = {
|
||||
parentID: MyAvatar.sessionUUID,
|
||||
parentJointIndex: handJointIndex
|
||||
}
|
||||
|
@ -1573,7 +1554,7 @@ function MyController(hand) {
|
|||
var handPosition = this.getHandPosition();
|
||||
// the center of the equipped object being far from the hand isn't enough to autoequip -- we also
|
||||
// need to fail the findEntities test.
|
||||
nearPickedCandidateEntities = Entities.findEntities(handPosition, GRAB_RADIUS);
|
||||
var nearPickedCandidateEntities = Entities.findEntities(handPosition, GRAB_RADIUS);
|
||||
if (nearPickedCandidateEntities.indexOf(this.grabbedEntity) == -1) {
|
||||
// for whatever reason, the held/equipped entity has been pulled away. ungrab or unequip.
|
||||
print("handControllerGrab -- autoreleasing held or equipped item because it is far from hand." +
|
||||
|
@ -1597,9 +1578,7 @@ function MyController(hand) {
|
|||
// from the palm.
|
||||
|
||||
var handControllerPosition = (this.hand === RIGHT_HAND) ? MyAvatar.rightHandPosition : MyAvatar.leftHandPosition;
|
||||
var now = Date.now();
|
||||
|
||||
var deltaPosition = Vec3.subtract(handControllerPosition, this.currentHandControllerTipPosition); // meters
|
||||
var deltaTime = (now - this.currentObjectTime) / MSECS_PER_SEC; // convert to seconds
|
||||
|
||||
if (deltaTime > 0.0) {
|
||||
|
@ -1619,7 +1598,6 @@ function MyController(hand) {
|
|||
this.currentHandControllerTipPosition = handControllerPosition;
|
||||
this.currentObjectTime = now;
|
||||
|
||||
var grabData = getEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, {});
|
||||
if (this.state === STATE_HOLD) {
|
||||
this.callEntityMethodOnGrabbed("continueEquip");
|
||||
}
|
||||
|
@ -1843,6 +1821,8 @@ function MyController(hand) {
|
|||
}
|
||||
|
||||
this.deactivateEntity = function(entityID, noVelocity) {
|
||||
var deactiveProps;
|
||||
|
||||
if (!this.entityActivated) {
|
||||
return;
|
||||
}
|
||||
|
@ -1852,7 +1832,7 @@ function MyController(hand) {
|
|||
if (data && data["refCount"]) {
|
||||
data["refCount"] = data["refCount"] - 1;
|
||||
if (data["refCount"] < 1) {
|
||||
var deactiveProps = {
|
||||
deactiveProps = {
|
||||
gravity: data["gravity"],
|
||||
collidesWith: data["collidesWith"],
|
||||
collisionless: data["collisionless"],
|
||||
|
@ -1865,7 +1845,6 @@ function MyController(hand) {
|
|||
// it looks like the dropped thing should fall, give it a little velocity.
|
||||
var props = Entities.getEntityProperties(entityID, ["parentID", "velocity", "dynamic", "shapeType"])
|
||||
var parentID = props.parentID;
|
||||
var forceVelocity = false;
|
||||
|
||||
var doSetVelocity = false;
|
||||
if (parentID != NULL_UUID && deactiveProps.parentID == NULL_UUID && propsArePhysical(props)) {
|
||||
|
@ -1900,7 +1879,7 @@ function MyController(hand) {
|
|||
// the parent causes it to go off in the wrong direction. This is a bug that should
|
||||
// be fixed.
|
||||
Entities.editEntity(entityID, {
|
||||
velocity: this.currentVelocity,
|
||||
velocity: this.currentVelocity
|
||||
// angularVelocity: this.currentAngularVelocity
|
||||
});
|
||||
}
|
||||
|
@ -1908,7 +1887,7 @@ function MyController(hand) {
|
|||
data = null;
|
||||
} else if (this.shouldResetParentOnRelease) {
|
||||
// we parent-grabbed this from another parent grab. try to put it back where we found it.
|
||||
var deactiveProps = {
|
||||
deactiveProps = {
|
||||
parentID: this.previousParentID,
|
||||
parentJointIndex: this.previousParentJointIndex,
|
||||
velocity: {x: 0.0, y: 0.0, z: 0.0},
|
||||
|
@ -1925,32 +1904,7 @@ function MyController(hand) {
|
|||
}
|
||||
setEntityCustomData(GRAB_USER_DATA_KEY, entityID, data);
|
||||
};
|
||||
|
||||
// AJT: WTF TO DO WITH THIS?
|
||||
/*
|
||||
this.checkNewlyLoaded = function(loadedEntityID) {
|
||||
if (this.state == STATE_OFF ||
|
||||
this.state == STATE_SEARCHING ||
|
||||
this.state == STATE_HOLD_SEARCHING) {
|
||||
var loadedProps = Entities.getEntityProperties(loadedEntityID);
|
||||
if (loadedProps.parentID != MyAvatar.sessionUUID) {
|
||||
return;
|
||||
}
|
||||
var handJointIndex = MyAvatar.getJointIndex(this.hand === RIGHT_HAND ? "RightHand" : "LeftHand");
|
||||
if (loadedProps.parentJointIndex != handJointIndex) {
|
||||
return;
|
||||
}
|
||||
print("--- handControllerGrab found loaded entity ---");
|
||||
// an entity has been loaded and it's where this script would have equipped something, so switch states.
|
||||
this.grabbedEntity = loadedEntityID;
|
||||
this.activateEntity(this.grabbedEntity, loadedProps, true);
|
||||
this.isInitialGrab = true;
|
||||
this.callEntityMethodOnGrabbed("startEquip");
|
||||
this.setState(STATE_EQUIP);
|
||||
}
|
||||
}
|
||||
*/
|
||||
};
|
||||
}
|
||||
|
||||
var rightController = new MyController(RIGHT_HAND);
|
||||
var leftController = new MyController(LEFT_HAND);
|
||||
|
@ -1988,7 +1942,8 @@ Messages.subscribe('Hifi-Hand-Grab');
|
|||
Messages.subscribe('Hifi-Hand-RayPick-Blacklist');
|
||||
Messages.subscribe('Hifi-Object-Manipulation');
|
||||
|
||||
handleHandMessages = function(channel, message, sender) {
|
||||
var handleHandMessages = function(channel, message, sender) {
|
||||
var data;
|
||||
if (sender === MyAvatar.sessionUUID) {
|
||||
if (channel === 'Hifi-Hand-Disabler') {
|
||||
if (message === 'left') {
|
||||
|
@ -2002,17 +1957,19 @@ handleHandMessages = function(channel, message, sender) {
|
|||
}
|
||||
} else if (channel === 'Hifi-Hand-Grab') {
|
||||
try {
|
||||
var data = JSON.parse(message);
|
||||
data = JSON.parse(message);
|
||||
var selectedController = (data.hand === 'left') ? leftController : rightController;
|
||||
selectedController.release();
|
||||
selectedController.setState(STATE_HOLD);
|
||||
selectedController.grabbedEntity = data.entityID;
|
||||
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
print("WARNING: error parsing Hifi-Hand-Grab message");
|
||||
}
|
||||
|
||||
} else if (channel === 'Hifi-Hand-RayPick-Blacklist') {
|
||||
try {
|
||||
var data = JSON.parse(message);
|
||||
data = JSON.parse(message);
|
||||
var action = data.action;
|
||||
var id = data.id;
|
||||
var index = blacklist.indexOf(id);
|
||||
|
@ -2026,7 +1983,9 @@ handleHandMessages = function(channel, message, sender) {
|
|||
}
|
||||
}
|
||||
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
print("WARNING: error parsing Hifi-Hand-RayPick-Blacklist message");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue