mirror of
https://github.com/overte-org/overte.git
synced 2025-04-11 11:13:06 +02:00
Add bow to tower defense
This commit is contained in:
parent
e2e0e9d96d
commit
ef62e6feb1
12 changed files with 1675 additions and 0 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
594
unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js
Normal file
594
unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js
Normal file
|
@ -0,0 +1,594 @@
|
|||
//
|
||||
// bow.js
|
||||
//
|
||||
// This script attaches to a bow that you can pick up with a hand controller.
|
||||
// Created by James B. Pollack @imgntn on 10/19/2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// 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, Controller, SoundCache, Entities, getEntityCustomData, setEntityCustomData, MyAvatar, Vec3, Quat, Messages */
|
||||
|
||||
(function() {
|
||||
|
||||
Script.include("/~/system/libraries/utils.js");
|
||||
|
||||
var NULL_UUID = "{00000000-0000-0000-0000-000000000000}";
|
||||
|
||||
var NOTCH_ARROW_SOUND_URL = Script.resolvePath('notch.wav');
|
||||
var SHOOT_ARROW_SOUND_URL = Script.resolvePath('String_release2.L.wav');
|
||||
var STRING_PULL_SOUND_URL = Script.resolvePath('Bow_draw.1.L.wav');
|
||||
var ARROW_HIT_SOUND_URL = Script.resolvePath('Arrow_impact1.L.wav');
|
||||
|
||||
var ARROW_TIP_OFFSET = 0.47;
|
||||
var ARROW_GRAVITY = {
|
||||
x: 0,
|
||||
y: -4.8,
|
||||
z: 0
|
||||
};
|
||||
|
||||
var ARROW_MODEL_URL = Script.resolvePath('newarrow_textured.fbx');
|
||||
var ARROW_COLLISION_HULL_URL = Script.resolvePath('newarrow_collision_hull.obj');
|
||||
|
||||
var ARROW_DIMENSIONS = {
|
||||
x: 0.03,
|
||||
y: 0.03,
|
||||
z: 0.96
|
||||
};
|
||||
|
||||
var ARROW_LIFETIME = 15; // seconds
|
||||
|
||||
|
||||
var TOP_NOTCH_OFFSET = 0.6;
|
||||
var BOTTOM_NOTCH_OFFSET = 0.6;
|
||||
|
||||
var LINE_DIMENSIONS = {
|
||||
x: 5,
|
||||
y: 5,
|
||||
z: 5
|
||||
};
|
||||
|
||||
var DRAW_STRING_THRESHOLD = 0.80;
|
||||
var DRAW_STRING_PULL_DELTA_HAPTIC_PULSE = 0.09;
|
||||
var DRAW_STRING_MAX_DRAW = 0.7;
|
||||
var NEAR_TO_RELAXED_KNOCK_DISTANCE = 0.5; // if the hand is this close, rez the arrow
|
||||
var NEAR_TO_RELAXED_SCHMITT = 0.05;
|
||||
|
||||
var NOTCH_OFFSET_FORWARD = 0.08;
|
||||
var NOTCH_OFFSET_UP = 0.035;
|
||||
|
||||
var SHOT_SCALE = {
|
||||
min1: 0,
|
||||
max1: 0.6,
|
||||
min2: 1,
|
||||
max2: 15
|
||||
};
|
||||
|
||||
var USE_DEBOUNCE = false;
|
||||
|
||||
var TRIGGER_CONTROLS = [
|
||||
Controller.Standard.LT,
|
||||
Controller.Standard.RT,
|
||||
];
|
||||
|
||||
function interval() {
|
||||
var lastTime = new Date().getTime();
|
||||
|
||||
return function getInterval() {
|
||||
var newTime = new Date().getTime();
|
||||
var delta = newTime - lastTime;
|
||||
lastTime = newTime;
|
||||
return delta;
|
||||
};
|
||||
}
|
||||
|
||||
var checkInterval = interval();
|
||||
|
||||
var _this;
|
||||
|
||||
function Bow() {
|
||||
_this = this;
|
||||
return;
|
||||
}
|
||||
|
||||
const STRING_NAME = 'Hifi-Bow-String';
|
||||
const ARROW_NAME = 'Hifi-Arrow-projectile';
|
||||
|
||||
const STATE_IDLE = 0;
|
||||
const STATE_ARROW_KNOCKED = 1;
|
||||
const STATE_ARROW_GRABBED = 2;
|
||||
const STATE_ARROW_GRABBED_AND_PULLED = 3;
|
||||
|
||||
Bow.prototype = {
|
||||
topString: null,
|
||||
aiming: false,
|
||||
arrowTipPosition: null,
|
||||
preNotchString: null,
|
||||
stringID: null,
|
||||
arrow: null,
|
||||
stringData: {
|
||||
currentColor: {
|
||||
red: 255,
|
||||
green: 255,
|
||||
blue: 255
|
||||
}
|
||||
},
|
||||
|
||||
state: STATE_IDLE,
|
||||
sinceLastUpdate: 0,
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
this.stringPullSound = SoundCache.getSound(STRING_PULL_SOUND_URL);
|
||||
this.shootArrowSound = SoundCache.getSound(SHOOT_ARROW_SOUND_URL);
|
||||
this.arrowHitSound = SoundCache.getSound(ARROW_HIT_SOUND_URL);
|
||||
this.arrowNotchSound = SoundCache.getSound(NOTCH_ARROW_SOUND_URL);
|
||||
var userData = Entities.getEntityProperties(this.entityID, ["userData"]).userData;
|
||||
this.userData = JSON.parse(userData);
|
||||
this.stringID = null;
|
||||
},
|
||||
|
||||
unload: function() {
|
||||
Messages.sendLocalMessage('Hifi-Hand-Disabler', "none");
|
||||
Entities.deleteEntity(this.arrow);
|
||||
},
|
||||
|
||||
startEquip: function(entityID, args) {
|
||||
this.hand = args[0];
|
||||
|
||||
if (this.hand === 'left') {
|
||||
this.getStringHandPosition = function() { return _this.getControllerLocation("right").position; };
|
||||
} else if (this.hand === 'right') {
|
||||
this.getStringHandPosition = function() { return _this.getControllerLocation("left").position; };
|
||||
}
|
||||
Entities.editEntity(_this.entityID, {
|
||||
collidesWith: "",
|
||||
});
|
||||
|
||||
var data = getEntityCustomData('grabbableKey', this.entityID, {});
|
||||
data.grabbable = false;
|
||||
setEntityCustomData('grabbableKey', this.entityID, data);
|
||||
|
||||
this.initString();
|
||||
},
|
||||
continueEquip: function(entityID, args) {
|
||||
this.deltaTime = checkInterval();
|
||||
//debounce during debugging -- maybe we're updating too fast?
|
||||
if (USE_DEBOUNCE === true) {
|
||||
this.sinceLastUpdate = this.sinceLastUpdate + this.deltaTime;
|
||||
|
||||
if (this.sinceLastUpdate > 60) {
|
||||
this.sinceLastUpdate = 0;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.checkStringHand();
|
||||
},
|
||||
releaseEquip: function(entityID, args) {
|
||||
Messages.sendLocalMessage('Hifi-Hand-Disabler', "none");
|
||||
|
||||
this.stringDrawn = false;
|
||||
|
||||
var data = getEntityCustomData('grabbableKey', this.entityID, {});
|
||||
data.grabbable = true;
|
||||
setEntityCustomData('grabbableKey', this.entityID, data);
|
||||
Entities.deleteEntity(this.arrow);
|
||||
this.resetStringToIdlePosition();
|
||||
this.destroyArrow();
|
||||
Entities.editEntity(_this.entityID, {
|
||||
collidesWith: "static,dynamic,kinematic,otherAvatar,myAvatar"
|
||||
});
|
||||
},
|
||||
|
||||
destroyArrow: function() {
|
||||
var children = Entities.getChildrenIDs(this.entityID);
|
||||
children.forEach(function(childID) {
|
||||
var childName = Entities.getEntityProperties(childID, ["name"]).name;
|
||||
if (childName == ARROW_NAME) {
|
||||
Entities.deleteEntity(childID);
|
||||
// Continue iterating through children in case we've ended up in
|
||||
// a bad state where there are multiple arrows.
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
createArrow: function() {
|
||||
this.playArrowNotchSound();
|
||||
|
||||
var arrow = Entities.addEntity({
|
||||
name: ARROW_NAME,
|
||||
type: 'Model',
|
||||
modelURL: ARROW_MODEL_URL,
|
||||
shapeType: 'compound',
|
||||
compoundShapeURL: ARROW_COLLISION_HULL_URL,
|
||||
dimensions: ARROW_DIMENSIONS,
|
||||
position: this.bowProperties.position,
|
||||
parentID: this.entityID,
|
||||
dynamic: false,
|
||||
collisionless: true,
|
||||
collisionSoundURL: ARROW_HIT_SOUND_URL,
|
||||
damping: 0.01,
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
grabbable: false
|
||||
},
|
||||
creatorSessionUUID: MyAvatar.sessionUUID
|
||||
})
|
||||
});
|
||||
|
||||
var makeArrowStick = function(entityA, entityB, collision) {
|
||||
Entities.editEntity(entityA, {
|
||||
localAngularVelocity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
localVelocity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
},
|
||||
parentID: entityB,
|
||||
dynamic: false,
|
||||
collisionless: true,
|
||||
collidesWith: ""
|
||||
});
|
||||
Script.removeEventHandler(arrow, "collisionWithEntity", makeArrowStick);
|
||||
};
|
||||
|
||||
Script.addEventHandler(arrow, "collisionWithEntity", makeArrowStick);
|
||||
|
||||
return arrow;
|
||||
},
|
||||
|
||||
initString: function() {
|
||||
// Check for existence of string
|
||||
var children = Entities.getChildrenIDs(this.entityID);
|
||||
children.forEach(function(childID) {
|
||||
var childName = Entities.getEntityProperties(childID, ["name"]).name;
|
||||
if (childName == STRING_NAME) {
|
||||
this.stringID = childID;
|
||||
}
|
||||
});
|
||||
|
||||
// If thie string wasn't found, create it
|
||||
if (this.stringID === null) {
|
||||
this.stringID = Entities.addEntity({
|
||||
collisionless: true,
|
||||
dimensions: { "x": 5, "y": 5, "z": 5 },
|
||||
ignoreForCollisions: 1,
|
||||
linePoints: [ { "x": 0, "y": 0, "z": 0 }, { "x": 0, "y": -1.2, "z": 0 } ],
|
||||
lineWidth: 5,
|
||||
name: STRING_NAME,
|
||||
parentID: this.entityID,
|
||||
localPosition: { "x": 0, "y": 0.6, "z": 0.1 },
|
||||
localRotation: { "w": 1, "x": 0, "y": 0, "z": 0 },
|
||||
type: 'Line',
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
grabbable: false
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
this.resetStringToIdlePosition();
|
||||
},
|
||||
|
||||
// This resets the string to a straight line
|
||||
resetStringToIdlePosition: function() {
|
||||
Entities.editEntity(this.stringID, {
|
||||
linePoints: [ { "x": 0, "y": 0, "z": 0 }, { "x": 0, "y": -1.2, "z": 0 } ],
|
||||
lineWidth: 5,
|
||||
localPosition: { "x": 0, "y": 0.6, "z": 0.1 },
|
||||
localRotation: { "w": 1, "x": 0, "y": 0, "z": 0 },
|
||||
});
|
||||
},
|
||||
|
||||
updateString: function() {
|
||||
var upVector = Quat.getUp(this.bowProperties.rotation);
|
||||
var upOffset = Vec3.multiply(upVector, TOP_NOTCH_OFFSET);
|
||||
var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation));
|
||||
var downOffset = Vec3.multiply(downVector, BOTTOM_NOTCH_OFFSET);
|
||||
var backOffset = Vec3.multiply(-0.1, Quat.getFront(this.bowProperties.rotation));
|
||||
|
||||
var topStringPosition = Vec3.sum(this.bowProperties.position, upOffset);
|
||||
this.topStringPosition = Vec3.sum(topStringPosition, backOffset);
|
||||
var bottomStringPosition = Vec3.sum(this.bowProperties.position, downOffset);
|
||||
this.bottomStringPosition = Vec3.sum(bottomStringPosition, backOffset);
|
||||
|
||||
var stringProps = Entities.getEntityProperties(this.stringID, ['position', 'rotation']);
|
||||
var handPositionLocal = Vec3.subtract(this.arrowRearPosition, stringProps.position);
|
||||
//handPositionLocal = Vec3.subtract(handPositionLocal, { x: 0, y: 0.6, z: 0 });
|
||||
handPositionLocal = Vec3.multiplyQbyV(Quat.inverse(stringProps.rotation), handPositionLocal);
|
||||
|
||||
var linePoints = [
|
||||
{ x: 0, y: 0, z: 0 },
|
||||
//{ x: 0, y: -0.6, z: 1 },
|
||||
handPositionLocal,
|
||||
{ x: 0, y: -1.2, z: 0 },
|
||||
];
|
||||
|
||||
Entities.editEntity(this.stringID, {
|
||||
linePoints: linePoints,
|
||||
});
|
||||
},
|
||||
|
||||
getLocalLineVectors: function() {
|
||||
var topVector = Vec3.subtract(this.arrowRearPosition, this.topStringPosition);
|
||||
var bottomVector = Vec3.subtract(this.bottomStringPosition, this.topStringPosition);
|
||||
return [topVector, bottomVector];
|
||||
},
|
||||
|
||||
getControllerLocation: function (controllerHand) {
|
||||
var standardControllerValue =
|
||||
(controllerHand === "right") ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
|
||||
var pose = Controller.getPoseValue(standardControllerValue);
|
||||
var orientation = Quat.multiply(MyAvatar.orientation, pose.rotation);
|
||||
var position = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, pose.translation), MyAvatar.position);
|
||||
return {position: position, orientation: orientation};
|
||||
},
|
||||
|
||||
checkStringHand: function() {
|
||||
//invert the hands because our string will be held with the opposite hand of the first one we pick up the bow with
|
||||
this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[(this.hand === 'left') ? 1 : 0]);
|
||||
|
||||
this.bowProperties = Entities.getEntityProperties(this.entityID);
|
||||
var notchPosition = this.getNotchPosition(this.bowProperties);
|
||||
var stringHandPosition = this.getStringHandPosition();
|
||||
var handToNotch = Vec3.subtract(notchPosition, stringHandPosition);
|
||||
var pullBackDistance = Vec3.length(handToNotch);
|
||||
|
||||
if (this.state === STATE_IDLE) {
|
||||
this.pullBackDistance = 0;
|
||||
|
||||
this.resetStringToIdlePosition();
|
||||
//this.deleteStrings();
|
||||
if (pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE - NEAR_TO_RELAXED_SCHMITT) && !this.backHandBusy) {
|
||||
//the first time aiming the arrow
|
||||
var handToDisable = (this.hand === 'right' ? 'left' : 'right');
|
||||
Messages.sendLocalMessage('Hifi-Hand-Disabler', handToDisable);
|
||||
this.arrow = this.createArrow();
|
||||
this.playStringPullSound();
|
||||
this.state = STATE_ARROW_KNOCKED;
|
||||
}
|
||||
}
|
||||
if (this.state === STATE_ARROW_KNOCKED) {
|
||||
|
||||
if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
||||
// delete the unpulled arrow
|
||||
Messages.sendLocalMessage('Hifi-Hand-Disabler', "none");
|
||||
Entities.deleteEntity(this.arrow);
|
||||
this.arrow = null;
|
||||
this.state = STATE_IDLE;
|
||||
} else if (this.triggerValue >= DRAW_STRING_THRESHOLD) {
|
||||
// they've grabbed the arrow
|
||||
this.pullBackDistance = 0;
|
||||
this.state = STATE_ARROW_GRABBED;
|
||||
} else {
|
||||
this.updateString();
|
||||
this.updateArrowPositionInNotch(false, false);
|
||||
}
|
||||
}
|
||||
if (this.state === STATE_ARROW_GRABBED) {
|
||||
if (this.triggerValue < DRAW_STRING_THRESHOLD) {
|
||||
// they let go without pulling
|
||||
this.state = STATE_ARROW_KNOCKED;
|
||||
} else if (pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
||||
// they've grabbed the arrow and pulled it
|
||||
this.state = STATE_ARROW_GRABBED_AND_PULLED;
|
||||
} else {
|
||||
this.updateString();
|
||||
this.updateArrowPositionInNotch(false, true);
|
||||
}
|
||||
}
|
||||
if (this.state === STATE_ARROW_GRABBED_AND_PULLED) {
|
||||
if (pullBackDistance < (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
||||
// they unpulled without firing
|
||||
this.state = STATE_ARROW_GRABBED;
|
||||
} else if (this.triggerValue < DRAW_STRING_THRESHOLD) {
|
||||
// they've fired the arrow
|
||||
Messages.sendLocalMessage('Hifi-Hand-Disabler', "none");
|
||||
this.updateArrowPositionInNotch(true, true);
|
||||
this.state = STATE_IDLE;
|
||||
this.resetStringToIdlePosition();
|
||||
} else {
|
||||
this.updateString();
|
||||
this.updateArrowPositionInNotch(false, true);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
setArrowRearPosition: function(arrowPosition, arrowRotation) {
|
||||
var frontVector = Quat.getFront(arrowRotation);
|
||||
var frontOffset = Vec3.multiply(frontVector, -ARROW_TIP_OFFSET);
|
||||
var arrorRearPosition = Vec3.sum(arrowPosition, frontOffset);
|
||||
this.arrowRearPosition = arrorRearPosition;
|
||||
return arrorRearPosition;
|
||||
|
||||
},
|
||||
|
||||
getNotchPosition: function(bowProperties) {
|
||||
var frontVector = Quat.getFront(bowProperties.rotation);
|
||||
var notchVectorForward = Vec3.multiply(frontVector, NOTCH_OFFSET_FORWARD);
|
||||
var upVector = Quat.getUp(bowProperties.rotation);
|
||||
var notchVectorUp = Vec3.multiply(upVector, NOTCH_OFFSET_UP);
|
||||
var notchPosition = Vec3.sum(bowProperties.position, notchVectorForward);
|
||||
notchPosition = Vec3.sum(notchPosition, notchVectorUp);
|
||||
return notchPosition;
|
||||
},
|
||||
|
||||
updateArrowPositionInNotch: function(shouldReleaseArrow, doHapticPulses) {
|
||||
//set the notch that the arrow should go through
|
||||
var notchPosition = this.getNotchPosition(this.bowProperties);
|
||||
//set the arrow rotation to be between the notch and other hand
|
||||
var stringHandPosition = this.getStringHandPosition();
|
||||
var handToNotch = Vec3.subtract(notchPosition, stringHandPosition);
|
||||
var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch);
|
||||
|
||||
var backHand = this.hand === 'left' ? 1 : 0;
|
||||
var pullBackDistance = Vec3.length(handToNotch);
|
||||
// pulse as arrow is drawn
|
||||
if (doHapticPulses &&
|
||||
Math.abs(pullBackDistance - this.pullBackDistance) > DRAW_STRING_PULL_DELTA_HAPTIC_PULSE) {
|
||||
Controller.triggerHapticPulse(1, 20, backHand);
|
||||
this.pullBackDistance = pullBackDistance;
|
||||
}
|
||||
// this.changeStringPullSoundVolume(pullBackDistance);
|
||||
|
||||
if (pullBackDistance > DRAW_STRING_MAX_DRAW) {
|
||||
pullBackDistance = DRAW_STRING_MAX_DRAW;
|
||||
}
|
||||
|
||||
// //pull the arrow back a bit
|
||||
// var pullBackOffset = Vec3.multiply(handToNotch, -pullBackDistance);
|
||||
// var arrowPosition = Vec3.sum(notchPosition, pullBackOffset);
|
||||
|
||||
// // // move it forward a bit
|
||||
// var pushForwardOffset = Vec3.multiply(handToNotch, -ARROW_OFFSET);
|
||||
// var finalArrowPosition = Vec3.sum(arrowPosition, pushForwardOffset);
|
||||
|
||||
//we draw strings to the rear of the arrow
|
||||
// this.setArrowRearPosition(finalArrowPosition, arrowRotation);
|
||||
|
||||
var halfArrowVec = Vec3.multiply(Vec3.normalize(handToNotch), ARROW_DIMENSIONS.z / 2.0);
|
||||
var arrowPosition = Vec3.sum(stringHandPosition, halfArrowVec);
|
||||
this.setArrowRearPosition(arrowPosition, arrowRotation);
|
||||
|
||||
//if we're not shooting, we're updating the arrow's orientation
|
||||
if (shouldReleaseArrow !== true) {
|
||||
Entities.editEntity(this.arrow, {
|
||||
position: arrowPosition,
|
||||
rotation: arrowRotation
|
||||
});
|
||||
}
|
||||
|
||||
//shoot the arrow
|
||||
if (shouldReleaseArrow === true) { // && pullBackDistance >= (NEAR_TO_RELAXED_KNOCK_DISTANCE + NEAR_TO_RELAXED_SCHMITT)) {
|
||||
var arrowAge = Entities.getEntityProperties(this.arrow, ["age"]).age;
|
||||
|
||||
//scale the shot strength by the distance you've pulled the arrow back and set its release velocity to be
|
||||
// in the direction of the v
|
||||
var arrowForce = this.scaleArrowShotStrength(pullBackDistance);
|
||||
var handToNotchNorm = Vec3.normalize(handToNotch);
|
||||
|
||||
var releaseVelocity = Vec3.multiply(handToNotchNorm, arrowForce);
|
||||
// var releaseVelocity2 = Vec3.multiply()
|
||||
|
||||
//make the arrow physical, give it gravity, a lifetime, and set our velocity
|
||||
var arrowProperties = {
|
||||
dynamic: true,
|
||||
collisionless: false,
|
||||
collidesWith: "static,dynamic,otherAvatar", // workaround: not with kinematic --> no collision with bow
|
||||
velocity: releaseVelocity,
|
||||
parentID: NULL_UUID,
|
||||
gravity: ARROW_GRAVITY,
|
||||
lifetime: ARROW_LIFETIME + arrowAge,
|
||||
};
|
||||
|
||||
//actually shoot the arrow and play its sound
|
||||
Entities.editEntity(this.arrow, arrowProperties);
|
||||
this.playShootArrowSound();
|
||||
|
||||
Controller.triggerShortHapticPulse(1, backHand);
|
||||
|
||||
Entities.addAction("travel-oriented", this.arrow, {
|
||||
forward: { x: 0, y: 0, z: -1 },
|
||||
angularTimeScale: 0.1,
|
||||
tag: "arrow from hifi-bow",
|
||||
ttl: ARROW_LIFETIME
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
scaleArrowShotStrength: function(value) {
|
||||
var min1 = SHOT_SCALE.min1;
|
||||
var max1 = SHOT_SCALE.max1;
|
||||
var min2 = SHOT_SCALE.min2;
|
||||
var max2 = SHOT_SCALE.max2;
|
||||
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
||||
},
|
||||
|
||||
playStringPullSound: function() {
|
||||
var audioProperties = {
|
||||
volume: 0.10,
|
||||
position: this.bowProperties.position
|
||||
};
|
||||
this.stringPullInjector = Audio.playSound(this.stringPullSound, audioProperties);
|
||||
},
|
||||
|
||||
playShootArrowSound: function(sound) {
|
||||
var audioProperties = {
|
||||
volume: 0.15,
|
||||
position: this.bowProperties.position
|
||||
};
|
||||
Audio.playSound(this.shootArrowSound, audioProperties);
|
||||
},
|
||||
|
||||
playArrowNotchSound: function() {
|
||||
var audioProperties = {
|
||||
volume: 0.15,
|
||||
position: this.bowProperties.position
|
||||
};
|
||||
Audio.playSound(this.arrowNotchSound, audioProperties);
|
||||
},
|
||||
|
||||
changeStringPullSoundVolume: function(pullBackDistance) {
|
||||
var audioProperties = {
|
||||
volume: this.scaleSoundVolume(pullBackDistance),
|
||||
position: this.bowProperties.position
|
||||
};
|
||||
|
||||
this.stringPullInjector.options = audioProperties;
|
||||
},
|
||||
|
||||
scaleSoundVolume: function(value) {
|
||||
var min1 = SHOT_SCALE.min1;
|
||||
var max1 = SHOT_SCALE.max1;
|
||||
var min2 = 0;
|
||||
var max2 = 0.2;
|
||||
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
||||
},
|
||||
|
||||
handleMessages: function(channel, message, sender) {
|
||||
if (sender !== MyAvatar.sessionUUID) {
|
||||
return;
|
||||
}
|
||||
if (channel !== 'Hifi-Object-Manipulation') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var data = JSON.parse(message);
|
||||
var action = data.action;
|
||||
var hand = data.joint;
|
||||
var isBackHand = ((_this.hand == "left" && hand == "RightHand") ||
|
||||
(_this.hand == "right" && hand == "LeftHand"));
|
||||
if ((action == "equip" || action == "grab") && isBackHand) {
|
||||
_this.backHandBusy = true;
|
||||
}
|
||||
if (action == "release" && isBackHand) {
|
||||
_this.backHandBusy = false;
|
||||
}
|
||||
} catch (e) {
|
||||
print("WARNING: bow.js -- error parsing Hifi-Object-Manipulation message: " + message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var bow = new Bow();
|
||||
|
||||
Messages.subscribe('Hifi-Object-Manipulation');
|
||||
Messages.messageReceived.connect(bow.handleMessages);
|
||||
|
||||
return bow;
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"Entities": [ {
|
||||
"collisionsWillMove": 1,
|
||||
"compoundShapeURL": "http://hifi-content.s3.amazonaws.com/caitlyn/production/bow/bow_collision_hull.obj",
|
||||
"created": "2016-09-01T23:57:55Z",
|
||||
"dimensions": {
|
||||
"x": 0.039999999105930328,
|
||||
"y": 1.2999999523162842,
|
||||
"z": 0.20000000298023224
|
||||
},
|
||||
"dynamic": 1,
|
||||
"gravity": {
|
||||
"x": 0,
|
||||
"y": -1,
|
||||
"z": 0
|
||||
},
|
||||
"modelURL": "http://hifi-content.s3.amazonaws.com/caitlyn/production/bow/bow-deadly.fbx",
|
||||
"name": "Hifi-Bow",
|
||||
"rotation": {
|
||||
"w": 0.9718012809753418,
|
||||
"x": 0.15440607070922852,
|
||||
"y": -0.10469216108322144,
|
||||
"z": -0.14418250322341919
|
||||
},
|
||||
"script": "http://hifi-content.s3.amazonaws.com/caitlyn/production/bow/bow.js",
|
||||
"shapeType": "compound",
|
||||
"type": "Model",
|
||||
"userData": "{\"grabbableKey\":{\"grabbable\":true},\"wearable\":{\"joints\":{\"RightHand\":[{\"x\":0.0813,\"y\":0.0452,\"z\":0.0095},{\"x\":-0.3946,\"y\":-0.6604,\"z\":0.4748,\"w\":-0.4275}],\"LeftHand\":[{\"x\":-0.0881,\"y\":0.0259,\"z\":0.0159},{\"x\":0.4427,\"y\":-0.6519,\"z\":0.4592,\"w\":0.4099}]}}}"
|
||||
}
|
||||
],
|
||||
"Version": 57
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
v -0.016461 -0.431491 -0.033447
|
||||
v -0.007624 0.437384 -0.046243
|
||||
v 0.011984 -0.424659 -0.03691
|
||||
v 0.015514 0.425913 -0.028648
|
||||
v -0.010788 -0.421429 0.093711
|
||||
v 0.007135 -0.423115 0.098735
|
||||
v -0.010208 0.425558 0.096005
|
||||
v 0.006734 0.43913 0.088902
|
||||
|
||||
f 1 2 3
|
||||
f 3 2 4
|
||||
f 5 6 7
|
||||
f 7 6 8
|
||||
f 1 5 2
|
||||
f 2 5 7
|
||||
f 3 4 6
|
||||
f 6 4 8
|
||||
f 1 3 5
|
||||
f 5 3 6
|
||||
f 2 7 4
|
||||
f 4 7 8
|
|
@ -0,0 +1,682 @@
|
|||
# Blender v2.76 (sub 0) OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib newarrow_collision_hull.mtl
|
||||
o Base_ACD.007_Base_ACD
|
||||
v -0.000000 -0.005000 0.000000
|
||||
v 0.000948 -0.000638 -0.083304
|
||||
v 0.001339 0.001317 -0.077051
|
||||
v 0.000948 0.001317 -0.077051
|
||||
v 0.000948 -0.001420 -0.075876
|
||||
v 0.003684 -0.000638 -0.078223
|
||||
v 0.003684 0.000926 -0.077441
|
||||
v 0.001339 0.000535 -0.083304
|
||||
v 0.001339 0.001317 -0.075876
|
||||
v 0.003684 -0.000638 -0.077051
|
||||
v 0.001339 -0.001420 -0.077051
|
||||
v 0.003684 0.000926 -0.078223
|
||||
v 0.001339 -0.000638 -0.083304
|
||||
v 0.000948 0.000535 -0.083304
|
||||
v 0.001730 -0.000638 -0.075876
|
||||
v 0.002902 -0.000638 -0.080176
|
||||
v 0.003684 0.000535 -0.077051
|
||||
v 0.000948 0.001317 -0.075876
|
||||
v 0.001339 0.000926 -0.080567
|
||||
vn 0.000000 0.989900 -0.141400
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn 0.164500 0.986400 0.000000
|
||||
vn 1.000000 -0.000000 0.000000
|
||||
vn 0.316400 -0.948600 0.000000
|
||||
vn -0.300100 -0.948700 -0.099900
|
||||
vn 0.314600 -0.943400 0.104700
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.000000 -0.992300 -0.124100
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn 0.458100 -0.458100 0.761800
|
||||
vn 0.266200 -0.958000 -0.106600
|
||||
vn 0.928300 0.000000 -0.371700
|
||||
vn 0.903100 0.076200 -0.422700
|
||||
vn 0.894500 0.000000 -0.447000
|
||||
vn 0.241000 -0.963000 -0.120400
|
||||
vn 0.508300 0.608200 0.609700
|
||||
vn 0.470900 0.094200 0.877100
|
||||
vn 0.515300 0.000000 0.857000
|
||||
vn 0.000000 0.993900 -0.110500
|
||||
vn 0.109800 0.987900 -0.109900
|
||||
vn 0.140000 0.980200 -0.140000
|
||||
vn -0.122700 0.984800 -0.123200
|
||||
usemtl Shape.007
|
||||
s off
|
||||
f 8//1 14//1 19//1
|
||||
f 4//2 2//2 5//2
|
||||
f 3//3 4//3 9//3
|
||||
f 7//4 3//4 9//4
|
||||
f 6//5 7//5 10//5
|
||||
f 6//6 10//6 11//6
|
||||
f 5//7 2//7 11//7
|
||||
f 10//8 5//8 11//8
|
||||
f 3//4 7//4 12//4
|
||||
f 7//5 6//5 12//5
|
||||
f 2//9 8//9 13//9
|
||||
f 11//10 2//10 13//10
|
||||
f 2//2 4//2 14//2
|
||||
f 8//9 2//9 14//9
|
||||
f 9//11 5//11 15//11
|
||||
f 5//12 10//12 15//12
|
||||
f 6//13 11//13 16//13
|
||||
f 12//14 6//14 16//14
|
||||
f 8//15 12//15 16//15
|
||||
f 13//16 8//16 16//16
|
||||
f 11//17 13//17 16//17
|
||||
f 7//18 9//18 17//18
|
||||
f 10//5 7//5 17//5
|
||||
f 9//19 15//19 17//19
|
||||
f 15//20 10//20 17//20
|
||||
f 4//2 5//2 18//2
|
||||
f 9//3 4//3 18//3
|
||||
f 5//11 9//11 18//11
|
||||
f 4//21 3//21 19//21
|
||||
f 3//22 12//22 19//22
|
||||
f 12//23 8//23 19//23
|
||||
f 14//24 4//24 19//24
|
||||
o Base_ACD.006_Base_ACD.007
|
||||
v -0.000000 -0.005000 0.000000
|
||||
v 0.000948 -0.003765 -0.077442
|
||||
v 0.000948 0.003662 -0.078224
|
||||
v -0.000616 0.003662 -0.078224
|
||||
v 0.000166 -0.000246 -0.086432
|
||||
v -0.001007 -0.001419 -0.075876
|
||||
v -0.001007 -0.000637 -0.084866
|
||||
v 0.000948 -0.000246 -0.085257
|
||||
v -0.000616 -0.003765 -0.078224
|
||||
v 0.000948 0.001316 -0.075876
|
||||
v -0.001007 0.001316 -0.075876
|
||||
v -0.001007 0.000925 -0.084476
|
||||
v 0.000557 0.000534 -0.086039
|
||||
v 0.000557 0.003662 -0.077051
|
||||
v 0.000948 -0.001419 -0.075876
|
||||
v 0.000948 -0.003765 -0.078224
|
||||
v -0.000616 -0.003765 -0.077051
|
||||
v 0.000166 -0.000637 -0.086039
|
||||
v -0.000616 0.003662 -0.077051
|
||||
v -0.000225 0.000925 -0.085257
|
||||
v -0.000616 0.000143 -0.086039
|
||||
v 0.000948 -0.001028 -0.084476
|
||||
v 0.000948 0.000925 -0.084476
|
||||
v -0.000616 -0.000637 -0.085649
|
||||
v -0.000616 0.001707 -0.075876
|
||||
v -0.001007 -0.001028 -0.084084
|
||||
v 0.000557 -0.003765 -0.077051
|
||||
vn 0.000000 -0.447800 0.894100
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn -0.987500 0.157400 -0.007200
|
||||
vn 0.824700 -0.136900 -0.548800
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn 0.904500 0.301700 0.301500
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn -0.986400 -0.164400 0.000000
|
||||
vn 0.000000 -0.928400 -0.371600
|
||||
vn -0.986400 0.164400 0.000000
|
||||
vn 0.000000 0.931900 -0.362700
|
||||
vn -0.355600 0.864200 -0.356100
|
||||
vn 0.087700 0.923300 -0.373900
|
||||
vn -0.248100 0.744200 -0.620200
|
||||
vn -0.959200 0.068500 -0.274200
|
||||
vn -0.170000 0.510100 -0.843200
|
||||
vn -0.484700 0.727700 -0.485300
|
||||
vn 0.728400 -0.484200 -0.484800
|
||||
vn 0.725800 -0.487600 -0.485100
|
||||
vn 0.324900 -0.866400 -0.379300
|
||||
vn 0.566300 0.755000 -0.330500
|
||||
vn 0.940600 0.188400 -0.282400
|
||||
vn -0.331800 -0.668700 -0.665300
|
||||
vn -0.190100 -0.904800 -0.381200
|
||||
vn -0.557700 -0.371200 -0.742400
|
||||
vn -0.873100 -0.218000 -0.436000
|
||||
vn 0.115000 0.460100 0.880400
|
||||
vn -0.458000 0.457900 0.761900
|
||||
vn 0.000000 0.515100 0.857100
|
||||
vn -0.987600 -0.157100 -0.007500
|
||||
vn -0.667100 -0.666300 -0.333100
|
||||
vn -0.534500 -0.778900 -0.328100
|
||||
vn 0.639400 -0.426900 0.639500
|
||||
usemtl Shape.006
|
||||
s off
|
||||
f 34//25 36//25 46//25
|
||||
f 22//26 21//26 27//26
|
||||
f 21//26 22//26 29//26
|
||||
f 25//27 29//27 30//27
|
||||
f 26//28 25//28 30//28
|
||||
f 26//28 30//28 31//28
|
||||
f 30//29 23//29 31//29
|
||||
f 27//30 24//30 32//30
|
||||
f 22//31 23//31 33//31
|
||||
f 29//32 22//32 33//32
|
||||
f 21//26 29//26 34//26
|
||||
f 29//27 25//27 34//27
|
||||
f 27//26 21//26 35//26
|
||||
f 21//33 28//33 35//33
|
||||
f 28//33 21//33 36//33
|
||||
f 25//34 28//34 36//34
|
||||
f 34//25 25//25 36//25
|
||||
f 35//35 28//35 37//35
|
||||
f 23//36 30//36 38//36
|
||||
f 33//31 23//31 38//31
|
||||
f 23//37 22//37 39//37
|
||||
f 31//38 23//38 39//38
|
||||
f 22//39 32//39 39//39
|
||||
f 39//40 32//40 40//40
|
||||
f 26//41 31//41 40//41
|
||||
f 32//42 24//42 40//42
|
||||
f 31//43 39//43 40//43
|
||||
f 24//44 27//44 41//44
|
||||
f 27//26 35//26 41//26
|
||||
f 37//45 24//45 41//45
|
||||
f 35//46 37//46 41//46
|
||||
f 22//26 27//26 42//26
|
||||
f 32//47 22//47 42//47
|
||||
f 27//48 32//48 42//48
|
||||
f 24//49 37//49 43//49
|
||||
f 37//50 28//50 43//50
|
||||
f 40//51 24//51 43//51
|
||||
f 26//52 40//52 43//52
|
||||
f 30//27 29//27 44//27
|
||||
f 29//53 33//53 44//53
|
||||
f 38//54 30//54 44//54
|
||||
f 33//55 38//55 44//55
|
||||
f 25//28 26//28 45//28
|
||||
f 28//56 25//56 45//56
|
||||
f 26//57 43//57 45//57
|
||||
f 43//58 28//58 45//58
|
||||
f 21//59 34//59 46//59
|
||||
f 36//33 21//33 46//33
|
||||
o Base_ACD.005_Base_ACD.006
|
||||
v -0.000000 -0.005000 0.000000
|
||||
v -0.001007 0.000534 -0.083304
|
||||
v -0.003744 -0.000638 -0.077051
|
||||
v -0.001398 -0.001029 -0.075876
|
||||
v -0.001007 0.001317 -0.075876
|
||||
v -0.003744 0.000925 -0.078223
|
||||
v -0.001398 -0.000638 -0.083304
|
||||
v -0.001007 -0.001029 -0.079785
|
||||
v -0.003744 -0.000638 -0.078223
|
||||
v -0.003744 0.000534 -0.077051
|
||||
v -0.001007 -0.001029 -0.075876
|
||||
v -0.001398 0.001317 -0.077051
|
||||
v -0.001398 0.000534 -0.083304
|
||||
v -0.001398 0.001317 -0.075876
|
||||
v -0.001007 -0.000638 -0.083304
|
||||
v -0.002571 -0.000638 -0.080958
|
||||
v -0.001398 -0.001029 -0.079785
|
||||
v -0.003352 0.000925 -0.079004
|
||||
vn -0.074700 0.989500 -0.123900
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn -0.164400 -0.986400 0.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn -0.447800 0.000000 0.894100
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 0.300500 0.948500 -0.100000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.000000 0.992300 -0.124200
|
||||
vn -0.429100 0.856800 0.285800
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn -0.164800 0.986300 0.000000
|
||||
vn 0.000000 -0.993900 -0.110400
|
||||
vn -0.919000 0.000000 -0.394200
|
||||
vn -0.904500 0.060100 -0.422200
|
||||
vn -0.894400 0.000000 -0.447200
|
||||
vn -0.215700 -0.970500 -0.107800
|
||||
vn -0.226100 -0.969300 -0.097000
|
||||
vn -0.132100 0.989000 -0.066300
|
||||
vn -0.809800 0.423100 -0.406500
|
||||
usemtl Shape.005
|
||||
s off
|
||||
f 58//60 59//60 64//60
|
||||
f 48//61 51//61 54//61
|
||||
f 50//62 49//62 55//62
|
||||
f 49//63 52//63 55//63
|
||||
f 49//64 50//64 56//64
|
||||
f 52//63 49//63 56//63
|
||||
f 51//65 50//65 57//65
|
||||
f 50//66 54//66 57//66
|
||||
f 54//61 51//61 57//61
|
||||
f 51//67 48//67 58//67
|
||||
f 48//68 53//68 59//68
|
||||
f 58//69 48//69 59//69
|
||||
f 50//65 51//65 60//65
|
||||
f 56//64 50//64 60//64
|
||||
f 52//70 56//70 60//70
|
||||
f 51//71 58//71 60//71
|
||||
f 58//72 52//72 60//72
|
||||
f 53//68 48//68 61//68
|
||||
f 48//61 54//61 61//61
|
||||
f 54//73 53//73 61//73
|
||||
f 55//74 52//74 62//74
|
||||
f 52//75 59//75 62//75
|
||||
f 59//76 53//76 62//76
|
||||
f 54//66 50//66 63//66
|
||||
f 53//73 54//73 63//73
|
||||
f 50//62 55//62 63//62
|
||||
f 62//77 53//77 63//77
|
||||
f 55//78 62//78 63//78
|
||||
f 52//79 58//79 64//79
|
||||
f 59//80 52//80 64//80
|
||||
o Base_ACD.004_Base_ACD.005
|
||||
v -0.000000 -0.005000 0.000000
|
||||
v 0.000557 0.003662 0.075021
|
||||
v 0.000166 0.004835 0.067211
|
||||
v 0.000166 0.004444 0.064868
|
||||
v -0.000225 0.001317 0.085974
|
||||
v 0.000557 0.001317 0.052747
|
||||
v -0.000225 0.001317 0.051180
|
||||
v -0.000225 0.004835 0.073069
|
||||
v 0.000557 0.001317 0.075804
|
||||
v 0.000557 0.004835 0.067603
|
||||
v 0.000166 0.001708 0.085974
|
||||
v -0.000225 0.001708 0.051180
|
||||
v -0.000225 0.004835 0.067211
|
||||
v 0.000557 0.002490 0.055482
|
||||
v 0.000557 0.004444 0.073069
|
||||
v 0.000166 0.004835 0.073069
|
||||
v -0.000225 0.001708 0.085974
|
||||
v 0.000166 0.001708 0.051180
|
||||
v 0.000166 0.001317 0.085974
|
||||
vn 0.999300 0.000000 0.038400
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn 1.000000 -0.000000 0.000000
|
||||
vn 0.162800 0.973200 -0.162400
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn 0.999200 0.012700 0.037900
|
||||
vn 0.000000 0.986400 -0.164600
|
||||
vn -0.163500 0.968300 -0.188900
|
||||
vn 0.327700 0.927600 -0.179500
|
||||
vn 0.985400 0.158300 0.063400
|
||||
vn 0.696900 0.697000 0.168900
|
||||
vn 0.000000 0.971900 0.235500
|
||||
vn 0.706200 0.706200 0.050500
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn 0.666800 -0.666800 -0.332800
|
||||
vn 0.000000 0.980600 -0.196000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.191700 0.962400 -0.192400
|
||||
vn 0.928400 0.341500 -0.146500
|
||||
usemtl Shape.004
|
||||
s off
|
||||
f 73//81 75//81 83//81
|
||||
f 70//82 69//82 71//82
|
||||
f 71//83 69//83 72//83
|
||||
f 70//84 66//84 73//84
|
||||
f 69//82 70//82 73//82
|
||||
f 68//85 67//85 74//85
|
||||
f 66//84 70//84 74//84
|
||||
f 67//86 72//86 74//86
|
||||
f 73//87 66//87 75//87
|
||||
f 71//83 72//83 76//83
|
||||
f 67//88 68//88 77//88
|
||||
f 72//86 67//86 77//86
|
||||
f 68//89 76//89 77//89
|
||||
f 76//83 72//83 77//83
|
||||
f 68//90 74//90 78//90
|
||||
f 74//84 70//84 78//84
|
||||
f 66//84 74//84 79//84
|
||||
f 75//91 66//91 79//91
|
||||
f 75//92 79//92 80//92
|
||||
f 74//86 72//86 80//86
|
||||
f 72//93 75//93 80//93
|
||||
f 79//94 74//94 80//94
|
||||
f 72//83 69//83 81//83
|
||||
f 69//95 75//95 81//95
|
||||
f 75//93 72//93 81//93
|
||||
f 70//96 71//96 82//96
|
||||
f 76//97 68//97 82//97
|
||||
f 71//98 76//98 82//98
|
||||
f 68//99 78//99 82//99
|
||||
f 78//100 70//100 82//100
|
||||
f 69//82 73//82 83//82
|
||||
f 75//95 69//95 83//95
|
||||
o Base_ACD.003_Base_ACD.004
|
||||
v -0.000000 -0.005000 0.000000
|
||||
v 0.003684 -0.000247 0.060958
|
||||
v -0.004917 -0.000247 0.072678
|
||||
v -0.004917 0.000144 0.072678
|
||||
v 0.001729 -0.000247 0.085972
|
||||
v 0.001338 0.001317 0.051180
|
||||
v 0.001338 0.001317 0.085972
|
||||
v -0.001397 -0.000247 0.051180
|
||||
v 0.004857 0.000535 0.068387
|
||||
v -0.001006 0.001317 0.051180
|
||||
v -0.001006 0.001317 0.086365
|
||||
v -0.001397 -0.000247 0.085972
|
||||
v -0.004524 0.000535 0.067212
|
||||
v 0.004857 -0.000247 0.073071
|
||||
v 0.001729 -0.000247 0.051180
|
||||
v -0.004524 -0.000247 0.065256
|
||||
v -0.002179 0.000535 0.053918
|
||||
v 0.004857 0.000144 0.073071
|
||||
v 0.004466 0.000144 0.064867
|
||||
v -0.004524 0.000535 0.072678
|
||||
v -0.001397 0.000926 0.085972
|
||||
v 0.004857 -0.000247 0.067212
|
||||
v -0.004917 0.000144 0.067602
|
||||
v -0.002179 -0.000247 0.053529
|
||||
v -0.001397 0.000926 0.051180
|
||||
v 0.001729 0.000144 0.051180
|
||||
v 0.004466 0.000535 0.065256
|
||||
v 0.000947 0.000535 0.086365
|
||||
v 0.001729 0.000144 0.085972
|
||||
v 0.004466 0.000535 0.072678
|
||||
v -0.004524 0.000144 0.065256
|
||||
v -0.004917 -0.000247 0.067602
|
||||
vn -0.986300 0.000000 -0.165200
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 0.216900 0.976200 0.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn -0.966700 0.000000 0.256000
|
||||
vn -0.217000 0.976200 0.000000
|
||||
vn 0.971800 0.000000 0.235600
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn -0.698400 0.702000 0.139400
|
||||
vn -0.705300 0.708900 0.000000
|
||||
vn -0.777000 0.606100 0.170100
|
||||
vn -0.708900 0.000000 0.705300
|
||||
vn 0.975500 -0.121800 -0.183000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn -0.958400 0.127100 -0.255600
|
||||
vn -0.702000 0.702000 -0.119800
|
||||
vn -0.948800 0.000000 -0.315900
|
||||
vn 0.980600 0.000000 -0.196100
|
||||
vn 0.980600 -0.000800 -0.196100
|
||||
vn 0.962400 0.191500 -0.192500
|
||||
vn 0.494700 0.866800 -0.061800
|
||||
vn 0.975500 0.183000 -0.121800
|
||||
vn 0.980300 0.139500 -0.140200
|
||||
vn 0.931400 0.310500 -0.189700
|
||||
vn 0.152800 0.381700 0.911600
|
||||
vn 0.000000 -0.449000 0.893500
|
||||
vn -0.088800 -0.221800 0.971000
|
||||
vn 0.924500 0.308200 0.224200
|
||||
vn 0.449000 0.000000 0.893500
|
||||
vn 0.508900 0.169600 0.843900
|
||||
vn 0.377500 0.925400 0.034400
|
||||
vn 0.646700 0.755100 0.107800
|
||||
vn 0.674200 0.736000 0.061400
|
||||
vn -0.760200 0.637100 -0.127300
|
||||
vn -0.980600 0.000000 -0.196100
|
||||
vn -0.975200 0.098600 -0.198300
|
||||
vn -0.800100 0.581900 -0.145400
|
||||
vn -0.748200 0.650600 -0.130100
|
||||
usemtl Shape.003
|
||||
s off
|
||||
f 106//101 99//101 115//101
|
||||
f 86//102 85//102 88//102
|
||||
f 85//102 86//102 91//102
|
||||
f 89//103 90//103 92//103
|
||||
f 90//104 89//104 93//104
|
||||
f 89//105 91//105 93//105
|
||||
f 90//104 93//104 94//104
|
||||
f 87//106 86//106 95//106
|
||||
f 86//102 88//102 95//102
|
||||
f 94//107 93//107 96//107
|
||||
f 88//102 85//102 97//102
|
||||
f 85//102 91//102 98//102
|
||||
f 91//105 89//105 98//105
|
||||
f 91//102 86//102 99//102
|
||||
f 88//108 97//108 101//108
|
||||
f 97//109 92//109 101//109
|
||||
f 87//110 94//110 103//110
|
||||
f 96//111 87//111 103//111
|
||||
f 94//107 96//107 103//107
|
||||
f 94//112 87//112 104//112
|
||||
f 87//106 95//106 104//106
|
||||
f 95//113 94//113 104//113
|
||||
f 97//102 85//102 105//102
|
||||
f 92//109 97//109 105//109
|
||||
f 85//114 102//114 105//114
|
||||
f 86//115 87//115 106//115
|
||||
f 87//111 96//111 106//111
|
||||
f 91//102 99//102 107//102
|
||||
f 107//116 100//116 108//116
|
||||
f 93//105 91//105 108//105
|
||||
f 96//117 93//117 108//117
|
||||
f 91//118 107//118 108//118
|
||||
f 85//119 98//119 109//119
|
||||
f 98//105 89//105 109//105
|
||||
f 102//120 85//120 109//120
|
||||
f 102//121 109//121 110//121
|
||||
f 89//122 92//122 110//122
|
||||
f 92//123 105//123 110//123
|
||||
f 105//124 102//124 110//124
|
||||
f 109//125 89//125 110//125
|
||||
f 90//126 94//126 111//126
|
||||
f 95//127 88//127 111//127
|
||||
f 94//128 95//128 111//128
|
||||
f 88//108 101//108 112//108
|
||||
f 101//129 90//129 112//129
|
||||
f 111//130 88//130 112//130
|
||||
f 90//131 111//131 112//131
|
||||
f 92//132 90//132 113//132
|
||||
f 90//133 101//133 113//133
|
||||
f 101//134 92//134 113//134
|
||||
f 106//135 96//135 114//135
|
||||
f 99//101 106//101 114//101
|
||||
f 107//136 99//136 114//136
|
||||
f 100//137 107//137 114//137
|
||||
f 108//138 100//138 114//138
|
||||
f 96//139 108//139 114//139
|
||||
f 99//102 86//102 115//102
|
||||
f 86//115 106//115 115//115
|
||||
o Base_ACD.002_Base_ACD.003
|
||||
v -0.000000 -0.005000 0.000000
|
||||
v 0.001339 -0.001029 0.051180
|
||||
v -0.001398 -0.001029 0.085972
|
||||
v -0.001007 -0.001420 0.086365
|
||||
v 0.001339 -0.000247 0.085972
|
||||
v -0.001398 -0.000247 0.051180
|
||||
v -0.001007 -0.001420 0.051180
|
||||
v 0.000947 -0.001420 0.086365
|
||||
v -0.001398 -0.000247 0.085972
|
||||
v 0.001339 -0.000247 0.051180
|
||||
v 0.000947 -0.001420 0.051180
|
||||
v 0.001339 -0.001029 0.085972
|
||||
v -0.001398 -0.001029 0.051180
|
||||
v 0.000947 -0.000638 0.086365
|
||||
vn 0.000000 0.708900 0.705300
|
||||
vn -0.707100 -0.707100 0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn -0.708900 0.000000 0.705300
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn 0.706200 -0.708000 0.000000
|
||||
vn 0.708000 0.000000 0.706200
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn -0.112700 0.281700 0.952900
|
||||
usemtl Shape.002
|
||||
s off
|
||||
f 120//140 124//140 129//140
|
||||
f 119//141 118//141 122//141
|
||||
f 121//142 117//142 122//142
|
||||
f 119//143 122//143 123//143
|
||||
f 118//144 119//144 124//144
|
||||
f 120//145 121//145 124//145
|
||||
f 121//146 118//146 124//146
|
||||
f 120//147 117//147 125//147
|
||||
f 117//142 121//142 125//142
|
||||
f 121//145 120//145 125//145
|
||||
f 122//142 117//142 126//142
|
||||
f 123//143 122//143 126//143
|
||||
f 117//148 123//148 126//148
|
||||
f 117//147 120//147 127//147
|
||||
f 120//149 123//149 127//149
|
||||
f 123//148 117//148 127//148
|
||||
f 118//146 121//146 128//146
|
||||
f 122//141 118//141 128//141
|
||||
f 121//142 122//142 128//142
|
||||
f 119//150 123//150 129//150
|
||||
f 123//149 120//149 129//149
|
||||
f 124//151 119//151 129//151
|
||||
o Base_ACD.001_Base_ACD.002
|
||||
v -0.000000 -0.005000 0.000000
|
||||
v -0.000225 -0.004547 0.073854
|
||||
v 0.000557 -0.001420 0.052744
|
||||
v 0.000557 -0.001811 0.052744
|
||||
v 0.000557 -0.001420 0.075810
|
||||
v -0.000225 -0.001420 0.052744
|
||||
v 0.000557 -0.004547 0.067598
|
||||
v -0.000225 -0.001420 0.075810
|
||||
v -0.000225 -0.004938 0.067598
|
||||
v 0.000557 -0.003765 0.075026
|
||||
v -0.000225 -0.002202 0.053527
|
||||
v 0.000166 -0.004938 0.072678
|
||||
v 0.000166 -0.004547 0.065252
|
||||
v 0.000557 -0.002202 0.053920
|
||||
v -0.000225 -0.002202 0.075810
|
||||
v 0.000557 -0.004547 0.072290
|
||||
v 0.000166 -0.004938 0.067598
|
||||
v -0.000225 -0.003765 0.075026
|
||||
v -0.000225 -0.004938 0.072678
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn -0.333500 -0.667000 -0.666200
|
||||
vn 0.292700 -0.874000 0.387900
|
||||
vn -0.161400 -0.968700 -0.188400
|
||||
vn 0.099700 -0.975100 -0.198300
|
||||
vn 0.156600 -0.937200 -0.311600
|
||||
vn 0.712000 -0.692100 -0.118700
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn 0.302200 -0.302200 0.904000
|
||||
vn 0.707100 -0.707100 0.000000
|
||||
vn 0.777000 -0.605300 0.173000
|
||||
vn 0.702200 -0.702200 -0.117000
|
||||
vn 0.000000 -0.986400 -0.164400
|
||||
vn 0.000000 -0.831800 0.555000
|
||||
vn 0.000000 -0.448400 0.893900
|
||||
vn 0.000000 -0.948900 0.315500
|
||||
usemtl Shape.001
|
||||
s off
|
||||
f 138//152 141//152 148//152
|
||||
f 133//153 132//153 134//153
|
||||
f 132//154 133//154 135//154
|
||||
f 134//155 132//155 135//155
|
||||
f 133//153 134//153 136//153
|
||||
f 135//156 131//156 137//156
|
||||
f 134//155 135//155 137//155
|
||||
f 131//156 135//156 138//156
|
||||
f 136//153 134//153 139//153
|
||||
f 135//157 133//157 140//157
|
||||
f 138//156 135//156 140//156
|
||||
f 139//158 131//158 141//158
|
||||
f 138//159 140//159 142//159
|
||||
f 142//160 140//160 143//160
|
||||
f 133//153 136//153 143//153
|
||||
f 140//161 133//161 143//161
|
||||
f 136//162 142//162 143//162
|
||||
f 137//156 131//156 144//156
|
||||
f 134//163 137//163 144//163
|
||||
f 139//164 134//164 144//164
|
||||
f 136//153 139//153 145//153
|
||||
f 141//165 136//165 145//165
|
||||
f 139//166 141//166 145//166
|
||||
f 141//152 138//152 146//152
|
||||
f 136//165 141//165 146//165
|
||||
f 142//167 136//167 146//167
|
||||
f 138//168 142//168 146//168
|
||||
f 131//169 139//169 147//169
|
||||
f 144//156 131//156 147//156
|
||||
f 139//170 144//170 147//170
|
||||
f 131//156 138//156 148//156
|
||||
f 141//171 131//171 148//171
|
||||
o Base_ACD_Base_ACD.001
|
||||
v -0.000000 -0.005000 0.000000
|
||||
v 0.001339 0.001316 -0.075876
|
||||
v -0.001398 -0.001028 0.051180
|
||||
v -0.001007 -0.001420 0.051180
|
||||
v -0.001398 -0.001028 -0.075876
|
||||
v 0.000948 -0.001420 -0.075876
|
||||
v 0.001730 -0.000247 0.051180
|
||||
v -0.001007 0.001316 0.051180
|
||||
v -0.001398 0.000926 -0.075876
|
||||
v 0.001339 0.001316 0.051180
|
||||
v -0.000225 0.001708 -0.075876
|
||||
v 0.000948 -0.001420 0.051180
|
||||
v 0.001729 -0.000247 -0.075876
|
||||
v 0.000166 0.001708 0.051180
|
||||
v -0.001007 -0.001420 -0.075876
|
||||
v -0.001398 0.000926 0.051180
|
||||
v 0.001339 -0.001028 -0.075876
|
||||
v 0.001730 0.000144 0.042188
|
||||
v -0.000225 0.001708 0.051180
|
||||
v 0.000166 0.001708 -0.075876
|
||||
v -0.001007 0.001316 -0.075876
|
||||
v 0.001339 -0.001028 0.051180
|
||||
v 0.001729 0.000144 -0.075876
|
||||
v 0.001730 0.000144 0.051180
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn -0.708000 -0.706200 0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 0.317000 0.948400 0.000000
|
||||
vn -0.706200 0.708000 0.000000
|
||||
vn 0.708000 -0.706200 0.000000
|
||||
vn 0.894700 -0.446800 -0.000000
|
||||
vn 0.948600 0.316500 0.000000
|
||||
vn 1.000000 -0.000200 -0.000000
|
||||
vn -0.448100 0.894000 0.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn 0.894200 -0.447700 0.000000
|
||||
vn 0.948800 0.315700 -0.000000
|
||||
usemtl Shape
|
||||
s off
|
||||
f 155//172 166//172 172//172
|
||||
f 152//173 151//173 153//173
|
||||
f 153//174 150//174 154//174
|
||||
f 151//175 152//175 155//175
|
||||
f 151//175 155//175 156//175
|
||||
f 153//176 151//176 157//176
|
||||
f 150//174 153//174 157//174
|
||||
f 156//175 155//175 158//175
|
||||
f 150//174 157//174 159//174
|
||||
f 152//177 154//177 160//177
|
||||
f 155//175 152//175 160//175
|
||||
f 154//174 150//174 161//174
|
||||
f 158//178 150//178 162//178
|
||||
f 156//175 158//175 162//175
|
||||
f 152//173 153//173 163//173
|
||||
f 153//174 154//174 163//174
|
||||
f 154//177 152//177 163//177
|
||||
f 151//175 156//175 164//175
|
||||
f 157//176 151//176 164//176
|
||||
f 156//179 157//179 164//179
|
||||
f 160//180 154//180 165//180
|
||||
f 154//174 161//174 165//174
|
||||
f 161//181 155//181 165//181
|
||||
f 150//182 158//182 166//182
|
||||
f 155//183 161//183 166//183
|
||||
f 159//184 156//184 167//184
|
||||
f 156//175 162//175 167//175
|
||||
f 162//185 159//185 167//185
|
||||
f 150//174 159//174 168//174
|
||||
f 162//178 150//178 168//178
|
||||
f 159//185 162//185 168//185
|
||||
f 157//179 156//179 169//179
|
||||
f 156//184 159//184 169//184
|
||||
f 159//174 157//174 169//174
|
||||
f 155//175 160//175 170//175
|
||||
f 160//180 165//180 170//180
|
||||
f 165//186 155//186 170//186
|
||||
f 161//174 150//174 171//174
|
||||
f 150//187 166//187 171//187
|
||||
f 166//172 161//172 171//172
|
||||
f 158//175 155//175 172//175
|
||||
f 166//182 158//182 172//182
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,29 @@
|
|||
Entities.addEntity({
|
||||
position: MyAvatar.position,
|
||||
"collisionsWillMove": 1,
|
||||
"compoundShapeURL": Script.resolvePath("bow_collision_hull.obj"),
|
||||
"created": "2016-09-01T23:57:55Z",
|
||||
"dimensions": {
|
||||
"x": 0.039999999105930328,
|
||||
"y": 1.2999999523162842,
|
||||
"z": 0.20000000298023224
|
||||
},
|
||||
"dynamic": 1,
|
||||
"gravity": {
|
||||
"x": 0,
|
||||
"y": -1,
|
||||
"z": 0
|
||||
},
|
||||
"modelURL": "http://hifi-content.s3.amazonaws.com/alan/dev/newarrow_textured.fbx",
|
||||
"name": "Hifi-Bow",
|
||||
"rotation": {
|
||||
"w": 0.9718012809753418,
|
||||
"x": 0.15440607070922852,
|
||||
"y": -0.10469216108322144,
|
||||
"z": -0.14418250322341919
|
||||
},
|
||||
"script": Script.resolvePath("bow.js"),
|
||||
"shapeType": "compound",
|
||||
"type": "Model",
|
||||
"userData": "{\"grabbableKey\":{\"grabbable\":true},\"wearable\":{\"joints\":{\"RightHand\":[{\"x\":0.0813,\"y\":0.0452,\"z\":0.0095},{\"x\":-0.3946,\"y\":-0.6604,\"z\":0.4748,\"w\":-0.4275}],\"LeftHand\":[{\"x\":-0.0881,\"y\":0.0259,\"z\":0.0159},{\"x\":0.4427,\"y\":-0.6519,\"z\":0.4592,\"w\":0.4099}]}}}"
|
||||
});
|
|
@ -0,0 +1,317 @@
|
|||
//
|
||||
// Created by Bradley Austin Davis on 2015/08/29
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
vec3toStr = function(v, digits) {
|
||||
if (!digits) { digits = 3; }
|
||||
return "{ " + v.x.toFixed(digits) + ", " + v.y.toFixed(digits) + ", " + v.z.toFixed(digits)+ " }";
|
||||
}
|
||||
|
||||
quatToStr = function(q, digits) {
|
||||
if (!digits) { digits = 3; }
|
||||
return "{ " + q.w.toFixed(digits) + ", " + q.x.toFixed(digits) + ", " +
|
||||
q.y.toFixed(digits) + ", " + q.z.toFixed(digits)+ " }";
|
||||
}
|
||||
|
||||
vec3equal = function(v0, v1) {
|
||||
return (v0.x == v1.x) && (v0.y == v1.y) && (v0.z == v1.z);
|
||||
}
|
||||
|
||||
colorMix = function(colorA, colorB, mix) {
|
||||
var result = {};
|
||||
for (var key in colorA) {
|
||||
result[key] = (colorA[key] * (1 - mix)) + (colorB[key] * mix);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
scaleLine = function (start, end, scale) {
|
||||
var v = Vec3.subtract(end, start);
|
||||
var length = Vec3.length(v);
|
||||
v = Vec3.multiply(scale, v);
|
||||
return Vec3.sum(start, v);
|
||||
}
|
||||
|
||||
findAction = function(name) {
|
||||
return Controller.findAction(name);
|
||||
}
|
||||
|
||||
addLine = function(origin, vector, color) {
|
||||
if (!color) {
|
||||
color = COLORS.WHITE
|
||||
}
|
||||
return Entities.addEntity(mergeObjects(LINE_PROTOTYPE, {
|
||||
position: origin,
|
||||
linePoints: [
|
||||
ZERO_VECTOR,
|
||||
vector,
|
||||
],
|
||||
color: color
|
||||
}));
|
||||
}
|
||||
|
||||
// FIXME fetch from a subkey of user data to support non-destructive modifications
|
||||
setEntityUserData = function(id, data) {
|
||||
var json = JSON.stringify(data)
|
||||
Entities.editEntity(id, { userData: json });
|
||||
}
|
||||
|
||||
// FIXME do non-destructive modification of the existing user data
|
||||
getEntityUserData = function(id) {
|
||||
var results = null;
|
||||
var properties = Entities.getEntityProperties(id, "userData");
|
||||
if (properties.userData) {
|
||||
try {
|
||||
results = JSON.parse(properties.userData);
|
||||
} catch(err) {
|
||||
logDebug(err);
|
||||
logDebug(properties.userData);
|
||||
}
|
||||
}
|
||||
return results ? results : {};
|
||||
}
|
||||
|
||||
|
||||
// Non-destructively modify the user data of an entity.
|
||||
setEntityCustomData = function(customKey, id, data) {
|
||||
var userData = getEntityUserData(id);
|
||||
if (data == null) {
|
||||
delete userData[customKey];
|
||||
} else {
|
||||
userData[customKey] = data;
|
||||
}
|
||||
setEntityUserData(id, userData);
|
||||
}
|
||||
|
||||
getEntityCustomData = function(customKey, id, defaultValue) {
|
||||
var userData = getEntityUserData(id);
|
||||
if (undefined != userData[customKey]) {
|
||||
return userData[customKey];
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
mergeObjects = function(proto, custom) {
|
||||
var result = {};
|
||||
for (var attrname in proto) {
|
||||
if (proto.hasOwnProperty(attrname)) {
|
||||
result[attrname] = proto[attrname];
|
||||
}
|
||||
}
|
||||
for (var attrname in custom) {
|
||||
if (custom.hasOwnProperty(attrname)) {
|
||||
result[attrname] = custom[attrname];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
LOG_WARN = 1;
|
||||
|
||||
logWarn = function(str) {
|
||||
if (LOG_WARN) {
|
||||
print(str);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_ERROR = 1;
|
||||
|
||||
logError = function(str) {
|
||||
if (LOG_ERROR) {
|
||||
print(str);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_INFO = 1;
|
||||
|
||||
logInfo = function(str) {
|
||||
if (LOG_INFO) {
|
||||
print(str);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DEBUG = 0;
|
||||
|
||||
logDebug = function(str) {
|
||||
if (LOG_DEBUG) {
|
||||
print(str);
|
||||
}
|
||||
}
|
||||
|
||||
LOG_TRACE = 0;
|
||||
|
||||
logTrace = function(str) {
|
||||
if (LOG_TRACE) {
|
||||
print(str);
|
||||
}
|
||||
}
|
||||
|
||||
// Computes the penetration between a point and a sphere (centered at the origin)
|
||||
// if point is inside sphere: returns true and stores the result in 'penetration'
|
||||
// (the vector that would move the point outside the sphere)
|
||||
// otherwise returns false
|
||||
findSphereHit = function(point, sphereRadius) {
|
||||
var EPSILON = 0.000001; //smallish positive number - used as margin of error for some computations
|
||||
var vectorLength = Vec3.length(point);
|
||||
if (vectorLength < EPSILON) {
|
||||
return true;
|
||||
}
|
||||
var distance = vectorLength - sphereRadius;
|
||||
if (distance < 0.0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
findSpherePointHit = function(sphereCenter, sphereRadius, point) {
|
||||
return findSphereHit(Vec3.subtract(point,sphereCenter), sphereRadius);
|
||||
}
|
||||
|
||||
findSphereSphereHit = function(firstCenter, firstRadius, secondCenter, secondRadius) {
|
||||
return findSpherePointHit(firstCenter, firstRadius + secondRadius, secondCenter);
|
||||
}
|
||||
|
||||
// Given a vec3 v, return a vec3 that is the same vector relative to the avatars
|
||||
// DEFAULT eye position, rotated into the avatars reference frame.
|
||||
getEyeRelativePosition = function(v) {
|
||||
return Vec3.sum(MyAvatar.getDefaultEyePosition(), Vec3.multiplyQbyV(MyAvatar.orientation, v));
|
||||
}
|
||||
|
||||
getAvatarRelativeRotation = function(q) {
|
||||
return Quat.multiply(MyAvatar.orientation, q);
|
||||
}
|
||||
|
||||
pointInExtents = function(point, minPoint, maxPoint) {
|
||||
return (point.x >= minPoint.x && point.x <= maxPoint.x) &&
|
||||
(point.y >= minPoint.y && point.y <= maxPoint.y) &&
|
||||
(point.z >= minPoint.z && point.z <= maxPoint.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an HSL color value to RGB. Conversion formula
|
||||
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
|
||||
* Assumes h, s, and l are contained in the set [0, 1] and
|
||||
* returns r, g, and b in the set [0, 255].
|
||||
*
|
||||
* @param Number h The hue
|
||||
* @param Number s The saturation
|
||||
* @param Number l The lightness
|
||||
* @return Array The RGB representation
|
||||
*/
|
||||
hslToRgb = function(hsl) {
|
||||
var r, g, b;
|
||||
if (hsl.s == 0) {
|
||||
r = g = b = hsl.l; // achromatic
|
||||
} else {
|
||||
var hue2rgb = function hue2rgb(p, q, t) {
|
||||
if (t < 0) t += 1;
|
||||
if (t > 1) t -= 1;
|
||||
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
||||
if (t < 1 / 2) return q;
|
||||
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
||||
return p;
|
||||
}
|
||||
|
||||
var q = hsl.l < 0.5 ? hsl.l * (1 + hsl.s) : hsl.l + hsl.s - hsl.l * hsl.s;
|
||||
var p = 2 * hsl.l - q;
|
||||
r = hue2rgb(p, q, hsl.h + 1 / 3);
|
||||
g = hue2rgb(p, q, hsl.h);
|
||||
b = hue2rgb(p, q, hsl.h - 1 / 3);
|
||||
}
|
||||
|
||||
return {
|
||||
red: Math.round(r * 255),
|
||||
green: Math.round(g * 255),
|
||||
blue: Math.round(b * 255)
|
||||
};
|
||||
}
|
||||
|
||||
map = function(value, min1, max1, min2, max2) {
|
||||
return min2 + (max2 - min2) * ((value - min1) / (max1 - min1));
|
||||
}
|
||||
|
||||
orientationOf = function(vector) {
|
||||
var Y_AXIS = {
|
||||
x: 0,
|
||||
y: 1,
|
||||
z: 0
|
||||
};
|
||||
var X_AXIS = {
|
||||
x: 1,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
|
||||
var theta = 0.0;
|
||||
|
||||
var RAD_TO_DEG = 180.0 / Math.PI;
|
||||
var direction, yaw, pitch;
|
||||
direction = Vec3.normalize(vector);
|
||||
yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS);
|
||||
pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS);
|
||||
return Quat.multiply(yaw, pitch);
|
||||
}
|
||||
|
||||
randFloat = function(low, high) {
|
||||
return low + Math.random() * (high - low);
|
||||
}
|
||||
|
||||
|
||||
randInt = function(low, high) {
|
||||
return Math.floor(randFloat(low, high));
|
||||
}
|
||||
|
||||
|
||||
randomColor = function() {
|
||||
return {
|
||||
red: randInt(0, 255),
|
||||
green: randInt(0, 255),
|
||||
blue: randInt(0, 255)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hexToRgb = function(hex) {
|
||||
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return result ? {
|
||||
red: parseInt(result[1], 16),
|
||||
green: parseInt(result[2], 16),
|
||||
blue: parseInt(result[3], 16)
|
||||
} : null;
|
||||
}
|
||||
|
||||
calculateHandSizeRatio = function() {
|
||||
// Get the ratio of the current avatar's hand to Owen's hand
|
||||
|
||||
var standardCenterHandPoint = 0.11288;
|
||||
var jointNames = MyAvatar.getJointNames();
|
||||
//get distance from handJoint up to leftHandIndex3 as a proxy for center of hand
|
||||
var wristToFingertipDistance = 0;;
|
||||
for (var i = 0; i < jointNames.length; i++) {
|
||||
var jointName = jointNames[i];
|
||||
print(jointName)
|
||||
if (jointName.indexOf("LeftHandIndex") !== -1) {
|
||||
// translations are relative to parent joint, so simply add them together
|
||||
// joints face down the y-axis
|
||||
var translation = MyAvatar.getDefaultJointTranslation(i).y;
|
||||
wristToFingertipDistance += translation;
|
||||
}
|
||||
}
|
||||
// Right now units are in cm, so convert to meters
|
||||
wristToFingertipDistance /= 100;
|
||||
|
||||
var centerHandPoint = wristToFingertipDistance/2;
|
||||
|
||||
// Compare against standard hand (Owen)
|
||||
var handSizeRatio = centerHandPoint/standardCenterHandPoint;
|
||||
return handSizeRatio;
|
||||
}
|
||||
|
||||
clamp = function(val, min, max){
|
||||
return Math.max(min, Math.min(max, val))
|
||||
}
|
||||
|
Loading…
Reference in a new issue