mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 21:18:43 +02:00
cleanup
This commit is contained in:
parent
f56c4ff575
commit
945243306b
5 changed files with 74 additions and 361 deletions
|
@ -37,6 +37,7 @@ var BUMPER_ON_VALUE = 0.5;
|
|||
var DISTANCE_HOLDING_RADIUS_FACTOR = 5; // multiplied by distance between hand and object
|
||||
var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position
|
||||
var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did
|
||||
|
||||
var NO_INTERSECT_COLOR = {
|
||||
red: 10,
|
||||
green: 10,
|
||||
|
@ -86,6 +87,7 @@ var ZERO_VEC = {
|
|||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
|
||||
var NULL_ACTION_ID = "{00000000-0000-0000-000000000000}";
|
||||
var MSEC_PER_SEC = 1000.0;
|
||||
|
||||
|
@ -95,7 +97,8 @@ var ACTION_TTL = 15; // seconds
|
|||
var ACTION_TTL_REFRESH = 5;
|
||||
var PICKS_PER_SECOND_PER_HAND = 5;
|
||||
var MSECS_PER_SEC = 1000.0;
|
||||
var GRABBABLE_PROPERTIES = ["position",
|
||||
var GRABBABLE_PROPERTIES = [
|
||||
"position",
|
||||
"rotation",
|
||||
"gravity",
|
||||
"ignoreForCollisions",
|
||||
|
@ -104,7 +107,6 @@ var GRABBABLE_PROPERTIES = ["position",
|
|||
"name"
|
||||
];
|
||||
|
||||
|
||||
var GRABBABLE_DATA_KEY = "grabbableKey"; // shared with grab.js
|
||||
var GRAB_USER_DATA_KEY = "grabKey"; // shared with grab.js
|
||||
|
||||
|
@ -115,7 +117,6 @@ var DEFAULT_GRABBABLE_DATA = {
|
|||
|
||||
var disabledHand = 'none';
|
||||
|
||||
|
||||
// states for the state machine
|
||||
var STATE_OFF = 0;
|
||||
var STATE_SEARCHING = 1;
|
||||
|
@ -461,7 +462,7 @@ function MyController(hand) {
|
|||
|
||||
//this code will disabled the beam for the opposite hand of the one that grabbed it if the entity says so
|
||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA);
|
||||
if (grabbableData["turnOffOppositeBeam"]) {
|
||||
if (grabbableData["turnOffOppositeBeam"]===true) {
|
||||
if (this.hand === RIGHT_HAND) {
|
||||
disabledHand = LEFT_HAND;
|
||||
} else {
|
||||
|
@ -758,16 +759,16 @@ function MyController(hand) {
|
|||
|
||||
this.nearGrabbing = function() {
|
||||
var now = Date.now();
|
||||
print('HAND IN NEAR GRAB:::'+this.hand)
|
||||
print('HAND IN NEAR GRAB:::' + this.hand)
|
||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
||||
|
||||
var turnOffOtherHand = grabbableData["turnOffOtherHand"];
|
||||
print('TURN OFF OTHER HAND??'+turnOffOtherHand);
|
||||
if(turnOffOtherHand==='left' && this.hand ===1){
|
||||
print('TURN OFF OTHER HAND??' + turnOffOtherHand);
|
||||
if (turnOffOtherHand === 'left' && this.hand === 1) {
|
||||
print('IGNORE RIGHT')
|
||||
return
|
||||
}
|
||||
if(turnOffOtherHand==='right'&&this.hand===0){
|
||||
if (turnOffOtherHand === 'right' && this.hand === 0) {
|
||||
print('IGNORE LEFT')
|
||||
return
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@
|
|||
};
|
||||
|
||||
var LINE_ENTITY_DIMENSIONS = {
|
||||
x: 1000,
|
||||
y: 1000,
|
||||
z: 1000
|
||||
x: 10,
|
||||
y: 10,
|
||||
z: 10
|
||||
};
|
||||
|
||||
var ARROW_OFFSET = -0.36;
|
||||
|
@ -66,21 +66,11 @@
|
|||
|
||||
var DRAW_STRING_THRESHOLD = 0.80;
|
||||
|
||||
var TARGET_LINE_LENGTH = 1;
|
||||
|
||||
var LEFT_TIP = 1;
|
||||
var RIGHT_TIP = 3;
|
||||
|
||||
var NOTCH_DETECTOR_OFFSET_FORWARD = 0.08;
|
||||
var NOTCH_DETECTOR_OFFSET_UP = 0.035;
|
||||
|
||||
var NOTCH_DETECTOR_DIMENSIONS = {
|
||||
x: 0.05,
|
||||
y: 0.05,
|
||||
z: 0.05
|
||||
};
|
||||
|
||||
var NOTCH_DETECTOR_DISTANCE = 0.1;
|
||||
var NOTCH_OFFSET_FORWARD = 0.08;
|
||||
var NOTCH_OFFSET_UP = 0.035;
|
||||
|
||||
var SHOT_SCALE = {
|
||||
min1: 0,
|
||||
|
@ -136,7 +126,7 @@
|
|||
}
|
||||
},
|
||||
preload: function(entityID) {
|
||||
print('preload bow')
|
||||
print('preload bow');
|
||||
this.entityID = entityID;
|
||||
this.stringPullSound = SoundCache.getSound(STRING_PULL_SOUND_URL);
|
||||
this.shootArrowSound = SoundCache.getSound(SHOOT_ARROW_SOUND_URL);
|
||||
|
@ -150,7 +140,6 @@
|
|||
this.deleteStrings();
|
||||
Entities.deleteEntity(this.preNotchString);
|
||||
Entities.deleteEntity(this.arrow);
|
||||
|
||||
},
|
||||
|
||||
setLeftHand: function() {
|
||||
|
@ -177,20 +166,14 @@
|
|||
setEntityCustomData('grabbableKey', this.entityID, {
|
||||
turnOffOtherHand: this.initialHand,
|
||||
invertSolidWhileHeld: true,
|
||||
turnOffOppositebeam: true,
|
||||
spatialKey: BOW_SPATIAL_KEY
|
||||
});
|
||||
|
||||
},
|
||||
continueNearGrab: function() {
|
||||
this.deltaTime = checkInterval();
|
||||
|
||||
// print('collidable bow' + Entities.getEntityProperties(this.entityID, "collisionsWillMove").collisionsWillMove)
|
||||
// print('collidable arrow' + Entities.getEntityProperties(this.arrow, "collisionsWillMove").collisionsWillMove)
|
||||
// print('collidable topstring' + Entities.getEntityProperties(this.topString, "collisionsWillMove").collisionsWillMove)
|
||||
// print('collidable bottomstring' + Entities.getEntityProperties(this.bottomString, "collisionsWillMove").collisionsWillMove)
|
||||
// print('collidable prenotchstring' + Entities.getEntityProperties(this.preNotchString, "collisionsWillMove").collisionsWillMove)
|
||||
|
||||
this.bowProperties = Entities.getEntityProperties(this.entityID, ["position", "rotation", "userData"]);
|
||||
this.bowProperties = Entities.getEntityProperties(this.entityID);
|
||||
|
||||
//create a string across the bow when we pick it up
|
||||
if (this.preNotchString === null) {
|
||||
|
@ -228,6 +211,7 @@
|
|||
setEntityCustomData('grabbableKey', this.entityID, {
|
||||
turnOffOtherHand: false,
|
||||
invertSolidWhileHeld: true,
|
||||
turnOffOppositebeam: true,
|
||||
spatialKey: BOW_SPATIAL_KEY
|
||||
});
|
||||
Entities.deleteEntity(this.preNotchString);
|
||||
|
@ -253,12 +237,12 @@
|
|||
collisionsWillMove: false,
|
||||
ignoreForCollisions: true,
|
||||
collisionSoundURL: ARROW_HIT_SOUND_URL,
|
||||
gravity: ARROW_GRAVITY,
|
||||
damping: 0.01,
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
invertSolidWhileHeld: true,
|
||||
grabbable: false
|
||||
//shouldnbt need this but just in case
|
||||
invertSolidWhileHeld: true,
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -381,10 +365,6 @@
|
|||
return [topVector, bottomVector];
|
||||
},
|
||||
|
||||
drawStringsBeforePickup: function() {
|
||||
_this.drawPreNotchStrings();
|
||||
},
|
||||
|
||||
createPreNotchString: function() {
|
||||
this.bowProperties = Entities.getEntityProperties(_this.entityID, ["position", "rotation", "userData"]);
|
||||
|
||||
|
@ -393,8 +373,8 @@
|
|||
position: Vec3.sum(this.bowProperties.position, TOP_NOTCH_OFFSET),
|
||||
dimensions: LINE_DIMENSIONS,
|
||||
visible: true,
|
||||
ignoreForCollisions: true,
|
||||
collisionsWillMove: false,
|
||||
ignoreForCollisions: true,
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
grabbable: false
|
||||
|
@ -408,7 +388,6 @@
|
|||
drawPreNotchStrings: function() {
|
||||
this.bowProperties = Entities.getEntityProperties(_this.entityID, ["position", "rotation", "userData"]);
|
||||
|
||||
|
||||
this.updateStringPositions();
|
||||
|
||||
var downVector = Vec3.multiply(-1, Quat.getUp(this.bowProperties.rotation));
|
||||
|
@ -441,12 +420,11 @@
|
|||
}
|
||||
|
||||
this.triggerValue = Controller.getActionValue(this.stringTriggerAction);
|
||||
// print('TRIGGER VALUE:::' + this.triggerValue)
|
||||
// print('TRIGGER VALUE:::' + this.triggerValue);
|
||||
|
||||
if (this.triggerValue < DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
||||
|
||||
// firing the arrow
|
||||
print('HIT RELEASE LOOP IN CHECK')
|
||||
print('HIT RELEASE LOOP IN CHECK');
|
||||
this.updateArrowPositionInNotch(true);
|
||||
this.hasArrowNotched = false;
|
||||
this.aiming = false;
|
||||
|
@ -454,79 +432,68 @@
|
|||
|
||||
} else if (this.triggerValue > DRAW_STRING_THRESHOLD && this.stringDrawn === true) {
|
||||
// print('HIT CONTINUE LOOP IN CHECK')
|
||||
this.aiming = true;
|
||||
//continuing to aim the arrow
|
||||
|
||||
this.aiming = true;
|
||||
this.drawStrings();
|
||||
this.updateArrowPositionInNotch();
|
||||
|
||||
} else if (this.triggerValue > DRAW_STRING_THRESHOLD && this.stringDrawn === false) {
|
||||
print('HIT START LOOP IN CHECK');
|
||||
this.arrow = this.createArrow();
|
||||
print('HIT START LOOP IN CHECK')
|
||||
this.playStringPullSound();
|
||||
|
||||
//the first time aiming the arrow
|
||||
this.stringDrawn = true;
|
||||
this.createStrings();
|
||||
this.drawStrings();
|
||||
// this.updateArrowPositionInNotch();
|
||||
this.updateArrowPositionInNotch();
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
setArrowTipPosition: function(arrowPosition, arrowRotation) {
|
||||
var frontVector = Quat.getFront(arrowRotation);
|
||||
var frontOffset = Vec3.multiply(frontVector, ARROW_TIP_OFFSET);
|
||||
var arrowTipPosition = Vec3.sum(arrowPosition, frontOffset);
|
||||
this.arrowTipPosition = arrowTipPosition;
|
||||
return arrowTipPosition;
|
||||
|
||||
},
|
||||
setArrowRearPosition: function(arrowPosition, arrowRotation) {
|
||||
var frontVector = Quat.getFront(arrowRotation);
|
||||
var frontOffset = Vec3.multiply(frontVector, -ARROW_TIP_OFFSET);
|
||||
var arrowTipPosition = Vec3.sum(arrowPosition, frontOffset);
|
||||
this.arrowRearPosition = arrowTipPosition;
|
||||
return arrowTipPosition;
|
||||
var arrorRearPosition = Vec3.sum(arrowPosition, frontOffset);
|
||||
this.arrowRearPosition = arrorRearPosition;
|
||||
return arrorRearPosition;
|
||||
|
||||
},
|
||||
|
||||
updateArrowPositionInNotch: function(shouldReleaseArrow) {
|
||||
var stringHandPosition = this.getStringHandPosition();
|
||||
var bowProperties = Entities.getEntityProperties(this.entityID);
|
||||
|
||||
var notchPosition;
|
||||
//set the notch that the arrow should go through
|
||||
var frontVector = Quat.getFront(bowProperties.rotation);
|
||||
var notchVectorForward = Vec3.multiply(frontVector, NOTCH_DETECTOR_OFFSET_FORWARD);
|
||||
var notchVectorForward = Vec3.multiply(frontVector, NOTCH_OFFSET_FORWARD);
|
||||
var upVector = Quat.getUp(bowProperties.rotation);
|
||||
var notchVectorUp = Vec3.multiply(upVector, NOTCH_DETECTOR_OFFSET_UP);
|
||||
|
||||
var notchVectorUp = Vec3.multiply(upVector, NOTCH_OFFSET_UP);
|
||||
var notchPosition;
|
||||
notchPosition = Vec3.sum(bowProperties.position, notchVectorForward);
|
||||
notchPosition = Vec3.sum(notchPosition, notchVectorUp);
|
||||
|
||||
//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);
|
||||
|
||||
//we draw strings to the rear of the arrow
|
||||
this.setArrowRearPosition(notchPosition, arrowRotation);
|
||||
|
||||
// var pullBackDistance = Vec3.length(handToNotch);
|
||||
|
||||
// if (pullBackDistance >= 0.6) {
|
||||
// pullBackDistance = 0.6;
|
||||
// }
|
||||
|
||||
pullBackDistance = 0.5;
|
||||
//modulate the sound by the
|
||||
var pullBackDistance = Vec3.length(handToNotch);
|
||||
// this.changeStringPullSoundVolume(pullBackDistance);
|
||||
|
||||
// //pull the arrow back a bit
|
||||
// var pullBackOffset = Vec3.multiply(handToNotch, -pullBackDistance);
|
||||
// var arrowPosition = Vec3.sum(detectorPosition, pullBackOffset);
|
||||
|
||||
//move it forward a bit
|
||||
// // move it forward a bit
|
||||
// var pushForwardOffset = Vec3.multiply(handToNotch, -ARROW_OFFSET);
|
||||
// var finalArrowPosition = Vec3.sum(arrowPosition, pushForwardOffset);
|
||||
|
||||
var arrowRotation = Quat.rotationBetween(Vec3.FRONT, handToNotch);
|
||||
var handToNotch = Vec3.normalize(handToNotch);
|
||||
this.setArrowTipPosition(notchPosition, arrowRotation);
|
||||
this.setArrowRearPosition(notchPosition, arrowRotation);
|
||||
|
||||
// this.pullBackDistance = pullBackDistance;
|
||||
//if we're not shooting, we're updating the arrow's orientation
|
||||
if (shouldReleaseArrow !== true) {
|
||||
Entities.editEntity(this.arrow, {
|
||||
position: notchPosition,
|
||||
|
@ -534,40 +501,36 @@
|
|||
})
|
||||
}
|
||||
|
||||
//shoot the arrow
|
||||
if (shouldReleaseArrow === true) {
|
||||
|
||||
var forwardVec = Vec3.multiply(handToNotch, 1 / this.deltaTime);
|
||||
var arrowForce = this.scaleArrowShotStrength(0.5)
|
||||
var forwardVec = Vec3.multiply(forwardVec, arrowForce)
|
||||
|
||||
// var velocity = Quat.getFront(bowProperties.rotation)
|
||||
//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 releaseVelocity = Vec3.multiply(handToNotch, arrowForce);
|
||||
|
||||
//make the arrow physical, give it gravity, a lifetime, and set our velocity
|
||||
var arrowProperties = {
|
||||
ignoreForCollisions: true,
|
||||
// collisionsWillMove: true,
|
||||
velocity: forwardVec,
|
||||
collisionsWillMove: true,
|
||||
velocity: releaseVelocity,
|
||||
gravity: ARROW_GRAVITY,
|
||||
lifetime: 10
|
||||
};
|
||||
|
||||
//actually shoot the arrow and play its sound
|
||||
Entities.editEntity(this.arrow, arrowProperties);
|
||||
this.playShootArrowSound();
|
||||
|
||||
Entities.editEntity(this.arrow, arrowProperties);
|
||||
|
||||
|
||||
|
||||
//clear the strings back to only the single straight one
|
||||
this.deleteStrings();
|
||||
Entities.editEntity(this.preNotchString, {
|
||||
visible: true
|
||||
});
|
||||
|
||||
this.deleteStrings();
|
||||
|
||||
var afterVelocity = Entities.getEntityProperties(this.arrow).velocity;
|
||||
print('VELOCITY AT RELEASE:::' + JSON.stringify(afterVelocity))
|
||||
print('VELOCITY AFTER RELEASE:::' + JSON.stringify(afterVelocity))
|
||||
|
||||
// this.arrow = null;
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
|
||||
scaleArrowShotStrength: function(value) {
|
||||
|
@ -580,51 +543,45 @@
|
|||
|
||||
playStringPullSound: function() {
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
volume: 0.15,
|
||||
position: this.bowProperties.position
|
||||
};
|
||||
this.stringPullInjector = Audio.playSound(this.stringPullSound, audioProperties);
|
||||
},
|
||||
|
||||
playShootArrowSound: function(sound) {
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
volume: 0.20,
|
||||
position: this.bowProperties.position
|
||||
};
|
||||
Audio.playSound(this.shootArrowSound, audioProperties);
|
||||
},
|
||||
playArrowHitSound: function(position) {
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
position: position
|
||||
};
|
||||
Audio.playSound(this.arrowHitSound, audioProperties);
|
||||
},
|
||||
|
||||
playArrowNotchSound: function() {
|
||||
print('play arrow notch sound')
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
position: this.bowProperties.position
|
||||
};
|
||||
Audio.playSound(this.arrowNotchSound, audioProperties);
|
||||
},
|
||||
|
||||
changeStringPullSoundVolume: function(pullBackDistance) {
|
||||
var audioProperties = {
|
||||
volume: 0.25,
|
||||
volume: this.scaleSoundVolume(pullBackDistance),
|
||||
position: this.bowProperties.position
|
||||
}
|
||||
|
||||
this.stringPullInjector.options = audioProperties
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
getArrowTrackerByArrowID = function(arrowID) {
|
||||
var result = arrowTrackers.filter(function(tracker) {
|
||||
return tracker.arrowID === arrowID;
|
||||
});
|
||||
var tracker = result[0]
|
||||
return tracker
|
||||
}
|
||||
return new Bow();
|
||||
});
|
|
@ -46,7 +46,8 @@ var bow = Entities.addEntity({
|
|||
script: SCRIPT_URL,
|
||||
userData: JSON.stringify({
|
||||
grabbableKey: {
|
||||
// turnOffOtherHand:true,
|
||||
turnOffOtherHand:false,
|
||||
turnOffOppositebeam:true,
|
||||
invertSolidWhileHeld: true,
|
||||
spatialKey: {
|
||||
relativePosition: {
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
//
|
||||
// createFireSource.js
|
||||
//
|
||||
// Created byJames Pollack @imgntn on 10/19/2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// This script creates a fire that you can use to light arrows on fire.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var TORCH_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/bow_and_arrow/models/torch.fbx';
|
||||
var TORCH_DIMENSIONS = {
|
||||
x: 0.07,
|
||||
y: 1.6,
|
||||
z: 0.08
|
||||
};
|
||||
|
||||
var FIRE_VERTICAL_OFFSET = 0.9;
|
||||
|
||||
function createFireSource(position) {
|
||||
|
||||
var torchProperties = {
|
||||
type: 'Model',
|
||||
name: 'Hifi-Fire-Torch',
|
||||
modelURL: TORCH_MODEL_URL,
|
||||
shapeType: 'box',
|
||||
collisionsWillMove: false,
|
||||
ignoreForCollisions: true,
|
||||
dimensions: TORCH_DIMENSIONS,
|
||||
position: position
|
||||
};
|
||||
|
||||
var torch = Entities.addEntity(torchProperties);
|
||||
torches.push(torch);
|
||||
var torchProperties = Entities.getEntityProperties(torch);
|
||||
|
||||
var upVector = Quat.getUp(torchProperties.rotation);
|
||||
var upOffset = Vec3.multiply(upVector, FIRE_VERTICAL_OFFSET);
|
||||
var fireTipPosition = Vec3.sum(torchProperties.position, upOffset);
|
||||
|
||||
var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0);
|
||||
|
||||
var animationSettings = JSON.stringify({
|
||||
fps: 30,
|
||||
running: true,
|
||||
loop: true,
|
||||
firstFrame: 1,
|
||||
lastFrame: 10000
|
||||
});
|
||||
|
||||
var fire = Entities.addEntity({
|
||||
type: "ParticleEffect",
|
||||
name: "Hifi-Arrow-Fire-Source",
|
||||
animationSettings: animationSettings,
|
||||
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
|
||||
emitRate: 100,
|
||||
position: fireTipPosition,
|
||||
colorStart: {
|
||||
red: 70,
|
||||
green: 70,
|
||||
blue: 137
|
||||
},
|
||||
color: {
|
||||
red: 200,
|
||||
green: 99,
|
||||
blue: 42
|
||||
},
|
||||
colorFinish: {
|
||||
red: 255,
|
||||
green: 99,
|
||||
blue: 32
|
||||
},
|
||||
radiusSpread: 0.01,
|
||||
radiusStart: 0.02,
|
||||
radiusEnd: 0.001,
|
||||
particleRadius: 0.5,
|
||||
radiusFinish: 0.0,
|
||||
emitOrientation: myOrientation,
|
||||
emitSpeed: 0.3,
|
||||
speedSpread: 0.1,
|
||||
alphaStart: 0.05,
|
||||
alpha: 0.1,
|
||||
alphaFinish: 0.05,
|
||||
emitDimensions: {
|
||||
x: 1,
|
||||
y: 1,
|
||||
z: 0.1
|
||||
},
|
||||
polarFinish: 0.1,
|
||||
emitAcceleration: {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
z: 0.0
|
||||
},
|
||||
accelerationSpread: {
|
||||
x: 0.1,
|
||||
y: 0.01,
|
||||
z: 0.1
|
||||
},
|
||||
lifespan: 1
|
||||
});
|
||||
|
||||
fires.push(fire)
|
||||
}
|
||||
|
||||
var fireSourcePositions = [{
|
||||
x: 100,
|
||||
y: -1,
|
||||
z: 100
|
||||
}, {
|
||||
x: 100,
|
||||
y: -1,
|
||||
z: 102
|
||||
}, {
|
||||
x: 100,
|
||||
y: -1,
|
||||
z: 104
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
var fires = [];
|
||||
var torches = [];
|
||||
|
||||
fireSourcePositions.forEach(function(position) {
|
||||
createFireSource(position);
|
||||
})
|
||||
|
||||
function cleanup() {
|
||||
while (fires.length > 0) {
|
||||
Entities.deleteEntity(fires.pop());
|
||||
}
|
||||
while (torches.length > 0) {
|
||||
Entities.deleteEntity(torches.pop());
|
||||
}
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
|
@ -1,106 +0,0 @@
|
|||
// fieldSpawner.js
|
||||
// examples
|
||||
//
|
||||
// Created by James B. Pollack @imgntn on 11/16/2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Spawns ground, targets, and fire sources.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
var ground, wall;
|
||||
var boxes = [];
|
||||
var dustSystems = [];
|
||||
var ZERO_VEC = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
};
|
||||
|
||||
Script.include("../libraries/utils.js");
|
||||
|
||||
var startPosition = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0
|
||||
}
|
||||
|
||||
function spawnGround() {
|
||||
var groundModelURL = "https://hifi-public.s3.amazonaws.com/alan/Playa/Ground.fbx";
|
||||
var groundPosition = Vec3.sum(startPosition, {
|
||||
x: 0,
|
||||
y: -2,
|
||||
z: 0
|
||||
});
|
||||
ground = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: groundModelURL,
|
||||
shapeType: "box",
|
||||
position: groundPosition,
|
||||
dimensions: {
|
||||
x: 900,
|
||||
y: 0.82,
|
||||
z: 900
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function spawnBoxes() {
|
||||
var boxModelURL = "http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target.fbx";
|
||||
var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/target_collision_hull.obj';
|
||||
var TARGET_DIMENSIONS = {
|
||||
x: 0.12,
|
||||
y: 0.84,
|
||||
z: 0.84
|
||||
};
|
||||
|
||||
var collisionSoundURL = "https://hifi-public.s3.amazonaws.com/sounds/Collisions-otherorganic/ToyWoodBlock.L.wav";
|
||||
var numBoxes = 200;
|
||||
for (var i = 0; i < numBoxes; i++) {
|
||||
var position = Vec3.sum(startPosition, {
|
||||
x: Math.random() * numBoxes,
|
||||
y: Math.random() * 2,
|
||||
z: Math.random() * numBoxes
|
||||
})
|
||||
var box = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: boxModelURL,
|
||||
collisionSoundURL: collisionSoundURL,
|
||||
shapeType: "compound",
|
||||
compoundShapeURL: COLLISION_HULL_URL,
|
||||
position: position,
|
||||
collisionsWillMove: true,
|
||||
dimensions: TARGET_DIMENSIONS,
|
||||
|
||||
});
|
||||
|
||||
Script.addEventHandler(box, "collisionWithEntity", boxCollision);
|
||||
boxes.push(box);
|
||||
}
|
||||
}
|
||||
|
||||
function boxCollision(me, other, collision) {
|
||||
Entities.editEntity(me, {
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -9.8,
|
||||
z: 0
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
spawnGround();
|
||||
spawnBoxes();
|
||||
|
||||
|
||||
// function cleanup() {
|
||||
// Entities.deleteEntity(ground);
|
||||
// boxes.forEach(function(box) {
|
||||
// Entities.deleteEntity(box);
|
||||
// });
|
||||
|
||||
// }
|
||||
|
||||
// Script.scriptEnding.connect(cleanup);
|
Loading…
Reference in a new issue