mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-16 10:00:23 +02:00
Merge pull request #6019 from ericrius1/entityReset
Adding a discreet entity to toybox that, when a user clicks on it, or near grabs it, will reset toybox
This commit is contained in:
commit
7c286a41db
3 changed files with 2311 additions and 1057 deletions
1176
unpublishedScripts/hiddenEntityReset.js
Normal file
1176
unpublishedScripts/hiddenEntityReset.js
Normal file
File diff suppressed because it is too large
Load diff
56
unpublishedScripts/immediateClientReset.js
Normal file
56
unpublishedScripts/immediateClientReset.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// immediateClientReset.js
|
||||
// Created by Eric Levin on 9/23/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 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, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */
|
||||
|
||||
|
||||
var masterResetScript = Script.resolvePath("masterReset.js");
|
||||
var hiddenEntityScriptURL = Script.resolvePath("hiddenEntityReset.js");
|
||||
|
||||
|
||||
Script.include(masterResetScript);
|
||||
|
||||
|
||||
|
||||
function createHiddenMasterSwitch() {
|
||||
|
||||
var resetKey = "resetMe";
|
||||
var masterSwitch = Entities.addEntity({
|
||||
type: "Box",
|
||||
name: "Master Switch",
|
||||
script: hiddenEntityScriptURL,
|
||||
dimensions: {
|
||||
x: 0.2,
|
||||
y: 0.2,
|
||||
z: 0.2
|
||||
},
|
||||
color: {
|
||||
red: 42,
|
||||
green: 36,
|
||||
blue: 30
|
||||
},
|
||||
position: {
|
||||
x: 554,
|
||||
y: 495.5,
|
||||
z: 503.2
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var entities = Entities.findEntities(MyAvatar.position, 100);
|
||||
|
||||
entities.forEach(function (entity) {
|
||||
//params: customKey, id, defaultValue
|
||||
var name = Entities.getEntityProperties(entity, "name").name
|
||||
if (name === "Master Switch") {
|
||||
Entities.deleteEntity(entity);
|
||||
}
|
||||
});
|
||||
createHiddenMasterSwitch();
|
||||
MasterReset();
|
|
@ -9,34 +9,40 @@
|
|||
/*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, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */
|
||||
//per script
|
||||
|
||||
|
||||
/*global deleteAllToys, createAllToys, createGates, createPingPongBallGun, createFire, createPottedPlant, createCombinedArmChair, createBasketballHoop, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLights */
|
||||
var utilitiesScript = Script.resolvePath("../examples/libraries/utils.js");
|
||||
Script.include(utilitiesScript);
|
||||
|
||||
var resetKey = "resetMe";
|
||||
var GRABBABLE_DATA_KEY = "grabbableKey";
|
||||
var sprayPaintScriptURL = Script.resolvePath("../examples/toys/sprayPaintCan.js");
|
||||
var catScriptURL = Script.resolvePath("../examples/toys/cat.js");
|
||||
var flashlightScriptURL = Script.resolvePath('../examples/toys/flashlight/flashlight.js');
|
||||
var pingPongScriptURL = Script.resolvePath('../examples/toys/ping_pong_gun/pingPongGun.js');
|
||||
var wandScriptURL = Script.resolvePath("../examples/toys/bubblewand/wand.js");
|
||||
var dollScriptURL = Script.resolvePath("../examples/toys/doll/doll.js");
|
||||
var lightsScriptURL = Script.resolvePath("../examples/toys/lightSwitch.js");
|
||||
|
||||
var HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||
|
||||
var shouldDeleteOnEndScript = false;
|
||||
|
||||
//Before creating anything, first search a radius and delete all the things that should be deleted
|
||||
deleteAllToys();
|
||||
createAllToys();
|
||||
MasterReset = function () {
|
||||
var resetKey = "resetMe";
|
||||
var GRABBABLE_DATA_KEY = "grabbableKey";
|
||||
|
||||
function createAllToys() {
|
||||
var HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
||||
|
||||
var shouldDeleteOnEndScript = false;
|
||||
|
||||
//Before creating anything, first search a radius and delete all the things that should be deleted
|
||||
deleteAllToys();
|
||||
createAllToys();
|
||||
|
||||
function createAllToys() {
|
||||
createBlocks({
|
||||
x: 548.3,
|
||||
y: 495.55,
|
||||
z: 504.4
|
||||
});
|
||||
|
||||
createSprayCan({
|
||||
x: 549.7,
|
||||
y: 495.6,
|
||||
z: 503.91
|
||||
});
|
||||
|
||||
createBasketBall({
|
||||
x: 547.73,
|
||||
y: 495.5,
|
||||
|
@ -63,11 +69,6 @@ function createAllToys() {
|
|||
z: 505.78
|
||||
});
|
||||
|
||||
createCat({
|
||||
x: 551.09,
|
||||
y: 494.98,
|
||||
z: 503.49
|
||||
});
|
||||
|
||||
|
||||
createCombinedArmChair({
|
||||
|
@ -85,7 +86,6 @@ function createAllToys() {
|
|||
createPingPongBallGun();
|
||||
|
||||
createBasketballHoop();
|
||||
|
||||
createBasketballRack();
|
||||
|
||||
createGates();
|
||||
|
@ -94,24 +94,323 @@ function createAllToys() {
|
|||
// Handles toggling of all sconce lights
|
||||
createLights();
|
||||
|
||||
}
|
||||
|
||||
function deleteAllToys() {
|
||||
|
||||
createCat({
|
||||
x: 551.09,
|
||||
y: 494.98,
|
||||
z: 503.49
|
||||
});
|
||||
|
||||
|
||||
createSprayCan({
|
||||
x: 549.7,
|
||||
y: 495.6,
|
||||
z: 503.91
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function deleteAllToys() {
|
||||
var entities = Entities.findEntities(MyAvatar.position, 100);
|
||||
|
||||
entities.forEach(function(entity) {
|
||||
entities.forEach(function (entity) {
|
||||
//params: customKey, id, defaultValue
|
||||
var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe;
|
||||
if (shouldReset === true) {
|
||||
Entities.deleteEntity(entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createLights() {
|
||||
function createFire() {
|
||||
|
||||
|
||||
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: "fire",
|
||||
animationSettings: animationSettings,
|
||||
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
|
||||
position: {
|
||||
x: 551.45,
|
||||
y: 494.82,
|
||||
z: 502.05
|
||||
},
|
||||
emitRate: 100,
|
||||
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.05,
|
||||
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
|
||||
});
|
||||
|
||||
|
||||
setEntityCustomData(resetKey, fire, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
|
||||
function createBasketballRack() {
|
||||
var NUMBER_OF_BALLS = 4;
|
||||
var DIAMETER = 0.30;
|
||||
var RESET_DISTANCE = 1;
|
||||
var MINIMUM_MOVE_LENGTH = 0.05;
|
||||
var basketballURL = HIFI_PUBLIC_BUCKET + "models/content/basketball2.fbx";
|
||||
var basketballCollisionSoundURL = HIFI_PUBLIC_BUCKET + "sounds/basketball/basketball.wav";
|
||||
var rackURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/basketball_rack.fbx";
|
||||
var rackCollisionHullURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/rack_collision_hull.obj";
|
||||
|
||||
var rackRotation = Quat.fromPitchYawRollDegrees(0, -90, 0);
|
||||
|
||||
var rackStartPosition = {
|
||||
x: 542.86,
|
||||
y: 494.84,
|
||||
z: 475.06
|
||||
};
|
||||
var rack = Entities.addEntity({
|
||||
name: 'Basketball Rack',
|
||||
type: "Model",
|
||||
modelURL: rackURL,
|
||||
position: rackStartPosition,
|
||||
rotation: rackRotation,
|
||||
shapeType: 'compound',
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -9.8,
|
||||
z: 0
|
||||
},
|
||||
linearDamping: 1,
|
||||
dimensions: {
|
||||
x: 0.4,
|
||||
y: 1.37,
|
||||
z: 1.73
|
||||
},
|
||||
collisionsWillMove: true,
|
||||
ignoreForCollisions: false,
|
||||
compoundShapeURL: rackCollisionHullURL
|
||||
});
|
||||
|
||||
setEntityCustomData(resetKey, rack, {
|
||||
resetMe: true
|
||||
});
|
||||
|
||||
setEntityCustomData(GRABBABLE_DATA_KEY, rack, {
|
||||
grabbable: false
|
||||
});
|
||||
|
||||
var collidingBalls = [];
|
||||
var originalBallPositions = [];
|
||||
|
||||
function createCollidingBalls() {
|
||||
var position = rackStartPosition;
|
||||
|
||||
var i;
|
||||
for (i = 0; i < NUMBER_OF_BALLS; i++) {
|
||||
var ballPosition = {
|
||||
x: position.x,
|
||||
y: position.y + DIAMETER * 2,
|
||||
z: position.z + (DIAMETER) - (DIAMETER * i)
|
||||
};
|
||||
|
||||
var collidingBall = Entities.addEntity({
|
||||
type: "Model",
|
||||
name: 'Colliding Basketball',
|
||||
shapeType: 'Sphere',
|
||||
position: {
|
||||
x: position.x + (DIAMETER * 2) - (DIAMETER * i),
|
||||
y: position.y + DIAMETER * 2,
|
||||
z: position.z
|
||||
},
|
||||
dimensions: {
|
||||
x: DIAMETER,
|
||||
y: DIAMETER,
|
||||
z: DIAMETER
|
||||
},
|
||||
restitution: 1.0,
|
||||
linearDamping: 0.00001,
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -9.8,
|
||||
z: 0
|
||||
},
|
||||
collisionsWillMove: true,
|
||||
ignoreForCollisions: false,
|
||||
modelURL: basketballURL,
|
||||
});
|
||||
|
||||
collidingBalls.push(collidingBall);
|
||||
originalBallPositions.push(position);
|
||||
|
||||
setEntityCustomData(resetKey, collidingBall, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function testBallDistanceFromStart() {
|
||||
var resetCount = 0;
|
||||
|
||||
collidingBalls.forEach(function (ball, index) {
|
||||
var currentPosition = Entities.getEntityProperties(ball, "position").position;
|
||||
var originalPosition = originalBallPositions[index];
|
||||
var distance = Vec3.subtract(originalPosition, currentPosition);
|
||||
var length = Vec3.length(distance);
|
||||
|
||||
if (length > RESET_DISTANCE) {
|
||||
Script.setTimeout(function () {
|
||||
var newPosition = Entities.getEntityProperties(ball, "position").position;
|
||||
var moving = Vec3.length(Vec3.subtract(currentPosition, newPosition));
|
||||
if (moving < MINIMUM_MOVE_LENGTH) {
|
||||
resetCount++;
|
||||
if (resetCount === NUMBER_OF_BALLS) {
|
||||
deleteCollidingBalls();
|
||||
createCollidingBalls();
|
||||
}
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteEntity(entityID) {
|
||||
if (entityID === rack) {
|
||||
deleteCollidingBalls();
|
||||
Script.clearInterval(distanceCheckInterval);
|
||||
Entities.deletingEntity.disconnect(deleteEntity);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteCollidingBalls() {
|
||||
while (collidingBalls.length > 0) {
|
||||
Entities.deleteEntity(collidingBalls.pop());
|
||||
}
|
||||
}
|
||||
|
||||
createCollidingBalls();
|
||||
Entities.deletingEntity.connect(deleteEntity);
|
||||
|
||||
var distanceCheckInterval = Script.setInterval(testBallDistanceFromStart, 1000);
|
||||
}
|
||||
|
||||
function createCat(position) {
|
||||
|
||||
var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx";
|
||||
var animationURL = "http://hifi-public.s3.amazonaws.com/ryan/sleeping.fbx";
|
||||
var animationSettings = JSON.stringify({
|
||||
running: true,
|
||||
});
|
||||
var cat = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: modelURL,
|
||||
name: "cat",
|
||||
script: catScriptURL,
|
||||
animationURL: animationURL,
|
||||
animationSettings: animationSettings,
|
||||
position: position,
|
||||
rotation: {
|
||||
w: 0.35020983219146729,
|
||||
x: -4.57763671875e-05,
|
||||
y: 0.93664455413818359,
|
||||
z: -1.52587890625e-05
|
||||
},
|
||||
dimensions: {
|
||||
x: 0.15723302960395813,
|
||||
y: 0.50762706995010376,
|
||||
z: 0.90716040134429932
|
||||
},
|
||||
});
|
||||
|
||||
setEntityCustomData(resetKey, cat, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
|
||||
function createFlashlight(position) {
|
||||
var modelURL = "https://hifi-public.s3.amazonaws.com/models/props/flashlight.fbx";
|
||||
|
||||
var flashlight = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: modelURL,
|
||||
name: "flashlight",
|
||||
script: flashlightScriptURL,
|
||||
position: position,
|
||||
dimensions: {
|
||||
x: 0.08,
|
||||
y: 0.30,
|
||||
z: 0.08
|
||||
},
|
||||
collisionsWillMove: true,
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -3.5,
|
||||
z: 0
|
||||
},
|
||||
velocity: {
|
||||
x: 0,
|
||||
y: -0.01,
|
||||
z: 0
|
||||
},
|
||||
shapeType: 'box',
|
||||
});
|
||||
|
||||
setEntityCustomData(resetKey, flashlight, {
|
||||
resetMe: true
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function createLights() {
|
||||
var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/lightswitch.fbx";
|
||||
|
||||
var scriptURL = Script.resolvePath("../examples/toys/lightSwitch.js");
|
||||
|
||||
var rotation = {
|
||||
w: 0.63280689716339111,
|
||||
|
@ -131,7 +430,7 @@ function createLights() {
|
|||
type: "Model",
|
||||
modelURL: modelURL,
|
||||
name: "Light Switch Hall",
|
||||
script: scriptURL,
|
||||
script: lightsScriptURL,
|
||||
position: {
|
||||
x: 543.27764892578125,
|
||||
y: 495.67999267578125,
|
||||
|
@ -221,7 +520,7 @@ function createLights() {
|
|||
type: "Model",
|
||||
modelURL: modelURL,
|
||||
name: "Light Switch Garage",
|
||||
script: scriptURL,
|
||||
script: lightsScriptURL,
|
||||
position: {
|
||||
x: 545.62,
|
||||
y: 495.68,
|
||||
|
@ -323,145 +622,11 @@ function createLights() {
|
|||
type: "Garage Light",
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createFire() {
|
||||
|
||||
|
||||
var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0);
|
||||
|
||||
var fire = Entities.addEntity({
|
||||
type: "ParticleEffect",
|
||||
name: "fire",
|
||||
isEmitting: true,
|
||||
textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png",
|
||||
position: {
|
||||
x: 551.45,
|
||||
y: 494.82,
|
||||
z: 502.05
|
||||
},
|
||||
emitRate: 100,
|
||||
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.05,
|
||||
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
|
||||
});
|
||||
|
||||
|
||||
setEntityCustomData(resetKey, fire, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function createCat(position) {
|
||||
var scriptURL = Script.resolvePath("../examples/toys/cat.js");
|
||||
var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx";
|
||||
var animationSettings = {
|
||||
url: "http://hifi-public.s3.amazonaws.com/ryan/sleeping.fbx",
|
||||
running: true,
|
||||
};
|
||||
var cat = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: modelURL,
|
||||
name: "cat",
|
||||
script: scriptURL,
|
||||
animation: animationSettings,
|
||||
position: position,
|
||||
rotation: {
|
||||
w: 0.35020983219146729,
|
||||
x: -4.57763671875e-05,
|
||||
y: 0.93664455413818359,
|
||||
z: -1.52587890625e-05
|
||||
},
|
||||
dimensions: {
|
||||
x: 0.15723302960395813,
|
||||
y: 0.50762706995010376,
|
||||
z: 0.90716040134429932
|
||||
},
|
||||
});
|
||||
|
||||
setEntityCustomData(resetKey, cat, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
|
||||
function createFlashlight(position) {
|
||||
var scriptURL = Script.resolvePath('../examples/toys/flashlight/flashlight.js');
|
||||
var modelURL = "https://hifi-public.s3.amazonaws.com/models/props/flashlight.fbx";
|
||||
|
||||
var flashlight = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: modelURL,
|
||||
name: "flashlight",
|
||||
script: scriptURL,
|
||||
position: position,
|
||||
dimensions: {
|
||||
x: 0.08,
|
||||
y: 0.30,
|
||||
z: 0.08
|
||||
},
|
||||
collisionsWillMove: true,
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -3.5,
|
||||
z: 0
|
||||
},
|
||||
velocity: {
|
||||
x: 0,
|
||||
y: -0.01,
|
||||
z: 0
|
||||
},
|
||||
shapeType: 'box',
|
||||
});
|
||||
|
||||
setEntityCustomData(resetKey, flashlight, {
|
||||
resetMe: true
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function createDice() {
|
||||
function createDice() {
|
||||
var diceProps = {
|
||||
type: "Model",
|
||||
modelURL: "http://s3.amazonaws.com/hifi-public/models/props/Dice/goldDie.fbx",
|
||||
|
@ -507,10 +672,10 @@ function createDice() {
|
|||
setEntityCustomData(resetKey, dice2, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createGates() {
|
||||
function createGates() {
|
||||
var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/ryan/fence.fbx';
|
||||
|
||||
var rotation1 = Quat.fromPitchYawRollDegrees(0, 36, 0);
|
||||
|
@ -586,12 +751,11 @@ function createGates() {
|
|||
setEntityCustomData(GRABBABLE_DATA_KEY, gate2, {
|
||||
grabbable: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createPingPongBallGun() {
|
||||
function createPingPongBallGun() {
|
||||
var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun.fbx';
|
||||
var COLLISION_HULL_URL = 'http://hifi-public.s3.amazonaws.com/models/ping_pong_gun/ping_pong_gun_collision_hull.obj';
|
||||
var scriptURL = Script.resolvePath('../examples/toys/ping_pong_gun/pingPongGun.js');
|
||||
|
||||
var position = {
|
||||
x: 548.6,
|
||||
|
@ -605,7 +769,7 @@ function createPingPongBallGun() {
|
|||
type: "Model",
|
||||
modelURL: MODEL_URL,
|
||||
shapeType: 'box',
|
||||
script: scriptURL,
|
||||
script: pingPongScriptURL,
|
||||
position: position,
|
||||
rotation: rotation,
|
||||
gravity: {
|
||||
|
@ -624,9 +788,9 @@ function createPingPongBallGun() {
|
|||
setEntityCustomData(resetKey, pingPongGun, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createBasketballHoop() {
|
||||
function createBasketballHoop() {
|
||||
var position = {
|
||||
x: 539.23,
|
||||
y: 496.13,
|
||||
|
@ -663,153 +827,11 @@ function createBasketballHoop() {
|
|||
setEntityCustomData(GRABBABLE_DATA_KEY, hoop, {
|
||||
grabbable: false
|
||||
});
|
||||
}
|
||||
|
||||
function createBasketballRack() {
|
||||
var NUMBER_OF_BALLS = 4;
|
||||
var DIAMETER = 0.30;
|
||||
var RESET_DISTANCE = 1;
|
||||
var MINIMUM_MOVE_LENGTH = 0.05;
|
||||
var basketballURL = HIFI_PUBLIC_BUCKET + "models/content/basketball2.fbx";
|
||||
var basketballCollisionSoundURL = HIFI_PUBLIC_BUCKET + "sounds/basketball/basketball.wav";
|
||||
var rackURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/basketball_rack.fbx";
|
||||
var rackCollisionHullURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/rack_collision_hull.obj";
|
||||
|
||||
var rackRotation = Quat.fromPitchYawRollDegrees(0, -90, 0);
|
||||
|
||||
var rackStartPosition = {
|
||||
x: 542.86,
|
||||
y: 494.84,
|
||||
z: 475.06
|
||||
};
|
||||
var rack = Entities.addEntity({
|
||||
name: 'Basketball Rack',
|
||||
type: "Model",
|
||||
modelURL: rackURL,
|
||||
position: rackStartPosition,
|
||||
rotation: rackRotation,
|
||||
shapeType: 'compound',
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -9.8,
|
||||
z: 0
|
||||
},
|
||||
linearDamping: 1,
|
||||
dimensions: {
|
||||
x: 0.4,
|
||||
y: 1.37,
|
||||
z: 1.73
|
||||
},
|
||||
collisionsWillMove: true,
|
||||
ignoreForCollisions: false,
|
||||
compoundShapeURL: rackCollisionHullURL
|
||||
});
|
||||
|
||||
setEntityCustomData(resetKey, rack, {
|
||||
resetMe: true
|
||||
});
|
||||
|
||||
setEntityCustomData(GRABBABLE_DATA_KEY, rack, {
|
||||
grabbable: false
|
||||
});
|
||||
|
||||
var collidingBalls = [];
|
||||
var originalBallPositions = [];
|
||||
|
||||
function createCollidingBalls() {
|
||||
var position = rackStartPosition;
|
||||
|
||||
var i;
|
||||
for (i = 0; i < NUMBER_OF_BALLS; i++) {
|
||||
var ballPosition = {
|
||||
x: position.x,
|
||||
y: position.y + DIAMETER * 2,
|
||||
z: position.z + (DIAMETER) - (DIAMETER * i)
|
||||
};
|
||||
|
||||
var collidingBall = Entities.addEntity({
|
||||
type: "Model",
|
||||
name: 'Colliding Basketball',
|
||||
shapeType: 'Sphere',
|
||||
position: {
|
||||
x: position.x + (DIAMETER * 2) - (DIAMETER * i),
|
||||
y: position.y + DIAMETER * 2,
|
||||
z: position.z
|
||||
},
|
||||
dimensions: {
|
||||
x: DIAMETER,
|
||||
y: DIAMETER,
|
||||
z: DIAMETER
|
||||
},
|
||||
restitution: 1.0,
|
||||
linearDamping: 0.00001,
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -9.8,
|
||||
z: 0
|
||||
},
|
||||
collisionsWillMove: true,
|
||||
ignoreForCollisions: false,
|
||||
modelURL: basketballURL,
|
||||
});
|
||||
|
||||
collidingBalls.push(collidingBall);
|
||||
originalBallPositions.push(position);
|
||||
}
|
||||
}
|
||||
|
||||
function testBallDistanceFromStart() {
|
||||
var resetCount = 0;
|
||||
|
||||
collidingBalls.forEach(function(ball, index) {
|
||||
var currentPosition = Entities.getEntityProperties(ball, "position").position;
|
||||
var originalPosition = originalBallPositions[index];
|
||||
var distance = Vec3.subtract(originalPosition, currentPosition);
|
||||
var length = Vec3.length(distance);
|
||||
|
||||
if (length > RESET_DISTANCE) {
|
||||
Script.setTimeout(function() {
|
||||
var newPosition = Entities.getEntityProperties(ball, "position").position;
|
||||
var moving = Vec3.length(Vec3.subtract(currentPosition, newPosition));
|
||||
if (moving < MINIMUM_MOVE_LENGTH) {
|
||||
resetCount++;
|
||||
if (resetCount === NUMBER_OF_BALLS) {
|
||||
deleteCollidingBalls();
|
||||
createCollidingBalls();
|
||||
}
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteEntity(entityID) {
|
||||
if (entityID === rack) {
|
||||
deleteCollidingBalls();
|
||||
Script.clearInterval(distanceCheckInterval);
|
||||
Entities.deletingEntity.disconnect(deleteEntity);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteCollidingBalls() {
|
||||
while (collidingBalls.length > 0) {
|
||||
Entities.deleteEntity(collidingBalls.pop());
|
||||
}
|
||||
}
|
||||
|
||||
createCollidingBalls();
|
||||
Entities.deletingEntity.connect(deleteEntity);
|
||||
|
||||
var distanceCheckInterval = Script.setInterval(testBallDistanceFromStart, 1000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function createWand(position) {
|
||||
function createWand(position) {
|
||||
var WAND_MODEL = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/wand.fbx';
|
||||
var WAND_COLLISION_SHAPE = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/actual_no_top_collision_hull.obj';
|
||||
var scriptURL = Script.resolvePath("../examples/toys/bubblewand/wand.js");
|
||||
|
||||
var entity = Entities.addEntity({
|
||||
name: 'Bubble Wand',
|
||||
|
@ -833,15 +855,15 @@ function createWand(position) {
|
|||
//Look into why bubble wand is going through table when gravity is enabled
|
||||
// gravity: {x: 0, y: -3.5, z: 0},
|
||||
// velocity: {x: 0, y: -0.01, z:0},
|
||||
script: scriptURL
|
||||
script: wandScriptURL
|
||||
});
|
||||
|
||||
setEntityCustomData(resetKey, entity, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createBasketBall(position) {
|
||||
function createBasketBall(position) {
|
||||
|
||||
var modelURL = "http://s3.amazonaws.com/hifi-public/models/content/basketball2.fbx";
|
||||
|
||||
|
@ -875,11 +897,10 @@ function createBasketBall(position) {
|
|||
setEntityCustomData(resetKey, entity, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createDoll(position) {
|
||||
function createDoll(position) {
|
||||
var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx";
|
||||
var scriptURL = Script.resolvePath("../examples/toys/doll/doll.js");
|
||||
|
||||
var naturalDimensions = {
|
||||
x: 1.63,
|
||||
|
@ -891,7 +912,7 @@ function createDoll(position) {
|
|||
type: "Model",
|
||||
name: "doll",
|
||||
modelURL: modelURL,
|
||||
script: scriptURL,
|
||||
script: dollScriptURL,
|
||||
position: position,
|
||||
shapeType: 'box',
|
||||
dimensions: desiredDimensions,
|
||||
|
@ -911,15 +932,16 @@ function createDoll(position) {
|
|||
setEntityCustomData(resetKey, entity, {
|
||||
resetMe: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createSprayCan(position) {
|
||||
|
||||
function createSprayCan(position) {
|
||||
var scriptURL = Script.resolvePath("../examples/toys/sprayPaintCan.js");
|
||||
var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx";
|
||||
|
||||
var entity = Entities.addEntity({
|
||||
type: "Model",
|
||||
name: "spraycan",
|
||||
script: sprayPaintScriptURL,
|
||||
modelURL: modelURL,
|
||||
position: position,
|
||||
dimensions: {
|
||||
|
@ -929,7 +951,6 @@ function createSprayCan(position) {
|
|||
},
|
||||
collisionsWillMove: true,
|
||||
shapeType: 'box',
|
||||
script: scriptURL,
|
||||
gravity: {
|
||||
x: 0,
|
||||
y: -0.5,
|
||||
|
@ -946,9 +967,9 @@ function createSprayCan(position) {
|
|||
resetMe: true
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function createPottedPlant(position) {
|
||||
function createPottedPlant(position) {
|
||||
var modelURL = "http://hifi-public.s3.amazonaws.com/models/potted_plant/potted_plant.fbx";
|
||||
|
||||
var entity = Entities.addEntity({
|
||||
|
@ -984,10 +1005,10 @@ function createPottedPlant(position) {
|
|||
setEntityCustomData(GRABBABLE_DATA_KEY, entity, {
|
||||
grabbable: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function createCombinedArmChair(position) {
|
||||
function createCombinedArmChair(position) {
|
||||
var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/combined_chair.fbx";
|
||||
var RED_ARM_CHAIR_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_collision_hull.obj";
|
||||
|
||||
|
@ -1027,9 +1048,9 @@ function createCombinedArmChair(position) {
|
|||
setEntityCustomData(GRABBABLE_DATA_KEY, entity, {
|
||||
grabbable: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function createBlocks(position) {
|
||||
function createBlocks(position) {
|
||||
var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/";
|
||||
var collisionSoundURL = "https://hifi-public.s3.amazonaws.com/sounds/Collisions-otherorganic/ToyWoodBlock.L.wav";
|
||||
var NUM_BLOCKS_PER_COLOR = 4;
|
||||
|
@ -1107,13 +1128,14 @@ function createBlocks(position) {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
function cleanup() {
|
||||
deleteAllToys();
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldDeleteOnEndScript) {
|
||||
if (shouldDeleteOnEndScript) {
|
||||
|
||||
Script.scriptEnding.connect(cleanup);
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in a new issue