From b9985031dacaa6e762a7f717a1562840e473f702 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 09:03:42 -0700 Subject: [PATCH 001/138] adding blocks --- examples/acScripts/toybox.js | 17 ++++++++++ examples/toybox/spawners/blockSpawner.js | 43 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 examples/acScripts/toybox.js create mode 100644 examples/toybox/spawners/blockSpawner.js diff --git a/examples/acScripts/toybox.js b/examples/acScripts/toybox.js new file mode 100644 index 0000000000..f4b9fc3d95 --- /dev/null +++ b/examples/acScripts/toybox.js @@ -0,0 +1,17 @@ +//TODO: Figure out why importing svo is only working locally + +print("SHNUR SHNUR SHNUR") + +var light = Entities.addEntity({ + type: "Box", + position: {x: 493, y: 505, z: 602}, + dimensions: {x: 3, y: 3, z: 3}, + color: {red: 200, green : 10, blue: 200} +}); + + +// function cleanup() { +// Entities.deleteEntity(light); +// } + +// Script.scriptEnding.connect(cleanup); diff --git a/examples/toybox/spawners/blockSpawner.js b/examples/toybox/spawners/blockSpawner.js new file mode 100644 index 0000000000..b62f62b594 --- /dev/null +++ b/examples/toybox/spawners/blockSpawner.js @@ -0,0 +1,43 @@ +HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; +var modelUrl = HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/block.fbx'; + +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); +var BASE_DIMENSIONS = Vec3.multiply({x: 0.2, y: 0.1, z: 0.8}, 0.2); +var NUM_BLOCKS = 4; + +var blocks = []; + +spawnBlocks(); + +var table = Entities.addEntity({ + type: "Box", + position: Vec3.sum(center, {x: 0, y: -0.2, z: 0}), + dimensions: {x: 2, y: .01, z: 2}, + color: {red: 20, green: 20, blue: 20} +}) +function spawnBlocks() { + for (var i = 0; i < NUM_BLOCKS; i++) { + var block = Entities.addEntity({ + type: "Model", + modelURL: modelUrl, + position: center, + shapeType: 'box', + name: "block", + dimensions: Vec3.sum(BASE_DIMENSIONS, {x: Math.random()/10, y: Math.random()/10, z:Math.random()/10}), + collisionsWillMove: true, + gravity: {x: 0, y: -9.8, z: 0}, + velocity: {x: 0, y: -.01, z: 0} + + }); + blocks.push(block); + } +} + +function cleanup() { + Entities.deleteEntity(table); + blocks.forEach(function(block) { + Entities.deleteEntity(block); + }); +} + +Script.scriptEnding.connect(cleanup); \ No newline at end of file From 7ffcce589dcf30405cde806d99fc2d5dbfd188e6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 09:09:25 -0700 Subject: [PATCH 002/138] blocks spawning --- examples/toybox/spawners/blockSpawner.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/toybox/spawners/blockSpawner.js b/examples/toybox/spawners/blockSpawner.js index b62f62b594..2ea17988f0 100644 --- a/examples/toybox/spawners/blockSpawner.js +++ b/examples/toybox/spawners/blockSpawner.js @@ -9,18 +9,18 @@ var blocks = []; spawnBlocks(); -var table = Entities.addEntity({ - type: "Box", - position: Vec3.sum(center, {x: 0, y: -0.2, z: 0}), - dimensions: {x: 2, y: .01, z: 2}, - color: {red: 20, green: 20, blue: 20} -}) +// var table = Entities.addEntity({ +// type: "Box", +// position: Vec3.sum(center, {x: 0, y: -0.2, z: 0}), +// dimensions: {x: 2, y: .01, z: 2}, +// color: {red: 20, green: 20, blue: 20} +// }) function spawnBlocks() { for (var i = 0; i < NUM_BLOCKS; i++) { var block = Entities.addEntity({ type: "Model", modelURL: modelUrl, - position: center, + position: {x: 548.3, y:495.55, z:504.4}, shapeType: 'box', name: "block", dimensions: Vec3.sum(BASE_DIMENSIONS, {x: Math.random()/10, y: Math.random()/10, z:Math.random()/10}), @@ -34,10 +34,10 @@ function spawnBlocks() { } function cleanup() { - Entities.deleteEntity(table); - blocks.forEach(function(block) { - Entities.deleteEntity(block); - }); + // Entities.deleteEntity(table); +// blocks.forEach(function(block) { +// Entities.deleteEntity(block); +// }); } Script.scriptEnding.connect(cleanup); \ No newline at end of file From c5b7de2156fb3d8ad099712968036c158c5240a5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 10:00:01 -0700 Subject: [PATCH 003/138] added fire spawner --- examples/toybox/spawners/fireSpawner.js | 103 ++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 examples/toybox/spawners/fireSpawner.js diff --git a/examples/toybox/spawners/fireSpawner.js b/examples/toybox/spawners/fireSpawner.js new file mode 100644 index 0000000000..b361c6bdfb --- /dev/null +++ b/examples/toybox/spawners/fireSpawner.js @@ -0,0 +1,103 @@ +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); +var ZERO_VEC = { + x: 0, + y: 0, + z: 0 +} +var totalTime = 0; +var FIRE_COLOR = { + red: 255, + green: 255, + blue: 255 +}; +var minLightIntensity = 3; +var maxLightIntensity = 11; + +var minTimeFactor = .1; +var maxTimeFactor = 1; + +var LIGHT_COLOR = { + red: 255, + green: 100, + blue: 28 +} + +var animationSettings = JSON.stringify({ + fps: 30, + running: true, + loop: true, + firstFrame: 1, + lastFrame: 10000 +}); + + +var fire = Entities.addEntity({ + type: "ParticleEffect", + animationSettings: animationSettings, + textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", + position: { + x: 551.5435791015625, + y: 494.87728881835938, + z: 502.01531982421875 + }, + emitRate: 100, + colorStart: { + red: 46, + green: 39, + blue: 137 + }, + color: { + red: 200, + green: 99, + blue: 42 + }, + colorFinish: { + red: 255, + green: 99, + blue: 32 + }, + emitVelocity: { + x: .0, + y: 0.1, + z: 0 + }, + + velocitySpread: { + x: .1, + y: .01, + z: .1 + }, + radiusSpread: .1, + radiusStart: .1, + particleRadius: .05, + radiusFinish: 0.01, + + alphaStart: 0.5, + alpha: 1, + alphaFinish: 0.0, + emitAcceleration: { + x: 0.1, + y: 1, + z: .0 + }, + accelerationSpread: { + x: .01, + y: .1, + z: .01 + }, + lifespan: 2 +}); + + +function cleanup() { + Entities.deleteEntity(fire); +} +Script.scriptEnding.connect(cleanup); + +function randFloat(min, max) { + return Math.random() * (max - min) + min; +} + +function randInt(min, max) { + return Math.floor(Math.random() * (max - min)) + min; +} \ No newline at end of file From cdae5452ceca496f252b1bf1f9d3509fe2009045 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 14:21:11 -0700 Subject: [PATCH 004/138] going ac script route for entity reset --- examples/acScripts/toybox.js | 17 --- .../{spawners => managers}/blockSpawner.js | 0 examples/toybox/managers/fireManager.js | 103 ++++++++++++++++++ examples/toybox/managers/lightSpawner.js | 14 +++ examples/toybox/masterResetEntity.js | 14 +++ examples/toybox/masterResetEntitySpawner.js | 19 ++++ examples/toybox/spawners/fireSpawner.js | 103 ------------------ 7 files changed, 150 insertions(+), 120 deletions(-) delete mode 100644 examples/acScripts/toybox.js rename examples/toybox/{spawners => managers}/blockSpawner.js (100%) create mode 100644 examples/toybox/managers/fireManager.js create mode 100644 examples/toybox/managers/lightSpawner.js create mode 100644 examples/toybox/masterResetEntity.js create mode 100644 examples/toybox/masterResetEntitySpawner.js delete mode 100644 examples/toybox/spawners/fireSpawner.js diff --git a/examples/acScripts/toybox.js b/examples/acScripts/toybox.js deleted file mode 100644 index f4b9fc3d95..0000000000 --- a/examples/acScripts/toybox.js +++ /dev/null @@ -1,17 +0,0 @@ -//TODO: Figure out why importing svo is only working locally - -print("SHNUR SHNUR SHNUR") - -var light = Entities.addEntity({ - type: "Box", - position: {x: 493, y: 505, z: 602}, - dimensions: {x: 3, y: 3, z: 3}, - color: {red: 200, green : 10, blue: 200} -}); - - -// function cleanup() { -// Entities.deleteEntity(light); -// } - -// Script.scriptEnding.connect(cleanup); diff --git a/examples/toybox/spawners/blockSpawner.js b/examples/toybox/managers/blockSpawner.js similarity index 100% rename from examples/toybox/spawners/blockSpawner.js rename to examples/toybox/managers/blockSpawner.js diff --git a/examples/toybox/managers/fireManager.js b/examples/toybox/managers/fireManager.js new file mode 100644 index 0000000000..15afb0d5ea --- /dev/null +++ b/examples/toybox/managers/fireManager.js @@ -0,0 +1,103 @@ +FireManager = function() { + + this.reset = function() { + if (!this.fire) { + var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); + var ZERO_VEC = { + x: 0, + y: 0, + z: 0 + } + var totalTime = 0; + var FIRE_COLOR = { + red: 255, + green: 255, + blue: 255 + }; + var minLightIntensity = 3; + var maxLightIntensity = 11; + + var minTimeFactor = .1; + var maxTimeFactor = 1; + + var LIGHT_COLOR = { + red: 255, + green: 100, + blue: 28 + } + + var animationSettings = JSON.stringify({ + fps: 30, + running: true, + loop: true, + firstFrame: 1, + lastFrame: 10000 + }); + + var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); + + this.fire = Entities.addEntity({ + type: "ParticleEffect", + animationSettings: animationSettings, + textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", + position: { + x: 551.5435791015625, + y: 494.87728881835938, + z: 502.01531982421875 + }, + name: "fire", + emitRate: 100, + colorStart: { + red: 46, + green: 39, + blue: 137 + }, + color: { + red: 200, + green: 99, + blue: 42 + }, + colorFinish: { + red: 255, + green: 99, + blue: 32 + }, + emitVelocity: { + x: .0, + y: 0.1, + z: 0 + }, + + velocitySpread: { + x: .1, + y: .01, + z: .1 + }, + radiusSpread: .1, + radiusStart: .1, + particleRadius: .05, + radiusFinish: 0.01, + + alphaStart: 0.5, + alpha: 1, + alphaFinish: 0.0, + emitAcceleration: { + x: 0.1, + y: 1, + z: .0 + }, + accelerationSpread: { + x: .01, + y: .1, + z: .01 + }, + lifespan: 2 + }); + + } else { + Entities.deleteEntity(this.fire); + this.fire = null; + } + + } +} \ No newline at end of file diff --git a/examples/toybox/managers/lightSpawner.js b/examples/toybox/managers/lightSpawner.js new file mode 100644 index 0000000000..4a52d4775b --- /dev/null +++ b/examples/toybox/managers/lightSpawner.js @@ -0,0 +1,14 @@ +var light = Entities.addEntity({ + type: "light", + position: {x: 544, y: 498.9, z: 506.7}, + intensity: 10, + dimensions: {x: 10, y: 10, z: 10}, + color: {red: 200, green : 10, blue: 200} +}); + + +function cleanup() { + Entities.deleteEntity(light); +} + +Script.scriptEnding.connect(cleanup); diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js new file mode 100644 index 0000000000..cefaa61fe3 --- /dev/null +++ b/examples/toybox/masterResetEntity.js @@ -0,0 +1,14 @@ +var fireScriptURL = Script.resolvePath("managers/fireManager.js"); +Script.include(fireScriptURL); + +var fireManager = new FireManager(); + +fireManager.reset(); + + + +function cleanup() { + fireManager.reset(); +} + +Script.scriptEnding.connect(cleanup); diff --git a/examples/toybox/masterResetEntitySpawner.js b/examples/toybox/masterResetEntitySpawner.js new file mode 100644 index 0000000000..8938595d7f --- /dev/null +++ b/examples/toybox/masterResetEntitySpawner.js @@ -0,0 +1,19 @@ +var scriptURL = Script.resolvePath("masterResetEntity.js?v1" + Math.random()); + +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation()))); + +var resetEntity = Entities.addEntity({ + type: "Box", + dimensions: {x: .3, y: 0.3, z: 0.3}, + position: center, + color: {red: 100, green: 10, blue: 100}, + script: scriptURL +}); + + + +function cleanup() { + Entities.deleteEntity(resetEntity); +} + +Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/examples/toybox/spawners/fireSpawner.js b/examples/toybox/spawners/fireSpawner.js deleted file mode 100644 index b361c6bdfb..0000000000 --- a/examples/toybox/spawners/fireSpawner.js +++ /dev/null @@ -1,103 +0,0 @@ -var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); -var ZERO_VEC = { - x: 0, - y: 0, - z: 0 -} -var totalTime = 0; -var FIRE_COLOR = { - red: 255, - green: 255, - blue: 255 -}; -var minLightIntensity = 3; -var maxLightIntensity = 11; - -var minTimeFactor = .1; -var maxTimeFactor = 1; - -var LIGHT_COLOR = { - red: 255, - green: 100, - blue: 28 -} - -var animationSettings = JSON.stringify({ - fps: 30, - running: true, - loop: true, - firstFrame: 1, - lastFrame: 10000 -}); - - -var fire = Entities.addEntity({ - type: "ParticleEffect", - animationSettings: animationSettings, - textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", - position: { - x: 551.5435791015625, - y: 494.87728881835938, - z: 502.01531982421875 - }, - emitRate: 100, - colorStart: { - red: 46, - green: 39, - blue: 137 - }, - color: { - red: 200, - green: 99, - blue: 42 - }, - colorFinish: { - red: 255, - green: 99, - blue: 32 - }, - emitVelocity: { - x: .0, - y: 0.1, - z: 0 - }, - - velocitySpread: { - x: .1, - y: .01, - z: .1 - }, - radiusSpread: .1, - radiusStart: .1, - particleRadius: .05, - radiusFinish: 0.01, - - alphaStart: 0.5, - alpha: 1, - alphaFinish: 0.0, - emitAcceleration: { - x: 0.1, - y: 1, - z: .0 - }, - accelerationSpread: { - x: .01, - y: .1, - z: .01 - }, - lifespan: 2 -}); - - -function cleanup() { - Entities.deleteEntity(fire); -} -Script.scriptEnding.connect(cleanup); - -function randFloat(min, max) { - return Math.random() * (max - min) + min; -} - -function randInt(min, max) { - return Math.floor(Math.random() * (max - min)) + min; -} \ No newline at end of file From 75c1e4956785188ce3aa0f6a2198a5adb34c0018 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 15:32:40 -0700 Subject: [PATCH 005/138] more tweaks yeah --- examples/toybox/managers/blockManager.js | 68 ++++++++++++++++++++++++ examples/toybox/managers/blockSpawner.js | 43 --------------- examples/toybox/masterResetEntity.js | 8 ++- 3 files changed, 75 insertions(+), 44 deletions(-) create mode 100644 examples/toybox/managers/blockManager.js delete mode 100644 examples/toybox/managers/blockSpawner.js diff --git a/examples/toybox/managers/blockManager.js b/examples/toybox/managers/blockManager.js new file mode 100644 index 0000000000..3f2ee15151 --- /dev/null +++ b/examples/toybox/managers/blockManager.js @@ -0,0 +1,68 @@ +BlockManager = function() { + + this.spawned = false; + this.blocks = []; + + this.reset = function() { + if (this.spawned) { + this.clearBlocks(); + } else { + this.createBlocks(); + } + + this.spawned = !this.spawned; + } + + this.clearBlocks = function() { + this.blocks.forEach(function(block) { + Entities.deleteEntity(block); + }); + this.blocks = []; + } + + this.createBlocks = function() { + + HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; + var modelUrl = HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/block.fbx'; + + var BASE_DIMENSIONS = Vec3.multiply({ + x: 0.2, + y: 0.1, + z: 0.8 + }, 0.2); + var NUM_BLOCKS = 4; + + for (var i = 0; i < NUM_BLOCKS; i++) { + var block = Entities.addEntity({ + type: "Model", + modelURL: modelUrl, + position: { + x: 548.3, + y: 495.55 + i/5, + z: 504.4 + }, + shapeType: 'box', + name: "block", + dimensions: Vec3.sum(BASE_DIMENSIONS, { + x: Math.random() / 10, + y: Math.random() / 10, + z: Math.random() / 10 + }), + collisionsWillMove: true, + gravity: { + x: 0, + y: -2.5, + z: 0 + }, + velocity: { + x: 0, + y: -.01, + z: 0 + } + + }); + this.blocks.push(block); + } + + } +} \ No newline at end of file diff --git a/examples/toybox/managers/blockSpawner.js b/examples/toybox/managers/blockSpawner.js deleted file mode 100644 index 2ea17988f0..0000000000 --- a/examples/toybox/managers/blockSpawner.js +++ /dev/null @@ -1,43 +0,0 @@ -HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; -var modelUrl = HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/block.fbx'; - -var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); -var BASE_DIMENSIONS = Vec3.multiply({x: 0.2, y: 0.1, z: 0.8}, 0.2); -var NUM_BLOCKS = 4; - -var blocks = []; - -spawnBlocks(); - -// var table = Entities.addEntity({ -// type: "Box", -// position: Vec3.sum(center, {x: 0, y: -0.2, z: 0}), -// dimensions: {x: 2, y: .01, z: 2}, -// color: {red: 20, green: 20, blue: 20} -// }) -function spawnBlocks() { - for (var i = 0; i < NUM_BLOCKS; i++) { - var block = Entities.addEntity({ - type: "Model", - modelURL: modelUrl, - position: {x: 548.3, y:495.55, z:504.4}, - shapeType: 'box', - name: "block", - dimensions: Vec3.sum(BASE_DIMENSIONS, {x: Math.random()/10, y: Math.random()/10, z:Math.random()/10}), - collisionsWillMove: true, - gravity: {x: 0, y: -9.8, z: 0}, - velocity: {x: 0, y: -.01, z: 0} - - }); - blocks.push(block); - } -} - -function cleanup() { - // Entities.deleteEntity(table); -// blocks.forEach(function(block) { -// Entities.deleteEntity(block); -// }); -} - -Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index cefaa61fe3..783926daad 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -1,14 +1,20 @@ var fireScriptURL = Script.resolvePath("managers/fireManager.js"); Script.include(fireScriptURL); -var fireManager = new FireManager(); +var blockScriptURL = Script.resolvePath("managers/blockManager.js"); +Script.include(blockScriptURL); +var fireManager = new FireManager(); fireManager.reset(); +var blockManager = new BlockManager(); +blockManager.reset(); + function cleanup() { fireManager.reset(); + blockManager.reset(); } Script.scriptEnding.connect(cleanup); From 109f2d8a1afd30d2cb02d7077ad195b63c721655 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 15:39:31 -0700 Subject: [PATCH 006/138] base positions --- examples/toybox/managers/blockManager.js | 10 +++------- examples/toybox/managers/fireManager.js | 12 +++--------- examples/toybox/masterResetEntity.js | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/examples/toybox/managers/blockManager.js b/examples/toybox/managers/blockManager.js index 3f2ee15151..7158e4499f 100644 --- a/examples/toybox/managers/blockManager.js +++ b/examples/toybox/managers/blockManager.js @@ -1,5 +1,5 @@ -BlockManager = function() { - +BlockManager = function(position) { + this.position = position; this.spawned = false; this.blocks = []; @@ -36,11 +36,7 @@ BlockManager = function() { var block = Entities.addEntity({ type: "Model", modelURL: modelUrl, - position: { - x: 548.3, - y: 495.55 + i/5, - z: 504.4 - }, + position: Vec3.sum(this.position, {x: 0, y: i/5, z:0}), shapeType: 'box', name: "block", dimensions: Vec3.sum(BASE_DIMENSIONS, { diff --git a/examples/toybox/managers/fireManager.js b/examples/toybox/managers/fireManager.js index 15afb0d5ea..30a65698fd 100644 --- a/examples/toybox/managers/fireManager.js +++ b/examples/toybox/managers/fireManager.js @@ -1,5 +1,5 @@ -FireManager = function() { - +FireManager = function(position) { + this.position = position; this.reset = function() { if (!this.fire) { var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); @@ -34,17 +34,11 @@ FireManager = function() { lastFrame: 10000 }); - var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); - this.fire = Entities.addEntity({ type: "ParticleEffect", animationSettings: animationSettings, textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", - position: { - x: 551.5435791015625, - y: 494.87728881835938, - z: 502.01531982421875 - }, + position: this.position, name: "fire", emitRate: 100, colorStart: { diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 783926daad..9612745d93 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -4,10 +4,19 @@ Script.include(fireScriptURL); var blockScriptURL = Script.resolvePath("managers/blockManager.js"); Script.include(blockScriptURL); -var fireManager = new FireManager(); +var fireManager = new FireManager({ + x: 551.5435791015625, + y: 494.87728881835938, + z: 502.01531982421875 +}); + fireManager.reset(); -var blockManager = new BlockManager(); +var blockManager = new BlockManager({ + x: 548.3, + y: 495.55, + z: 504.4 + }); blockManager.reset(); @@ -17,4 +26,4 @@ function cleanup() { blockManager.reset(); } -Script.scriptEnding.connect(cleanup); +Script.scriptEnding.connect(cleanup); \ No newline at end of file From 9614a69b19f48e1fb2b80c5fd9c6961f335e6917 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 16:12:16 -0700 Subject: [PATCH 007/138] adding spray can --- examples/toybox/managers/lightSpawner.js | 14 -------------- examples/toybox/managers/sprayCanManager.js | 0 2 files changed, 14 deletions(-) delete mode 100644 examples/toybox/managers/lightSpawner.js create mode 100644 examples/toybox/managers/sprayCanManager.js diff --git a/examples/toybox/managers/lightSpawner.js b/examples/toybox/managers/lightSpawner.js deleted file mode 100644 index 4a52d4775b..0000000000 --- a/examples/toybox/managers/lightSpawner.js +++ /dev/null @@ -1,14 +0,0 @@ -var light = Entities.addEntity({ - type: "light", - position: {x: 544, y: 498.9, z: 506.7}, - intensity: 10, - dimensions: {x: 10, y: 10, z: 10}, - color: {red: 200, green : 10, blue: 200} -}); - - -function cleanup() { - Entities.deleteEntity(light); -} - -Script.scriptEnding.connect(cleanup); diff --git a/examples/toybox/managers/sprayCanManager.js b/examples/toybox/managers/sprayCanManager.js new file mode 100644 index 0000000000..e69de29bb2 From 78642e3c79858f8e3134d43328e90cdeebd570dc Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 17:04:09 -0700 Subject: [PATCH 008/138] Getting rid of managers --- examples/toybox/managers/blockManager.js | 64 -------------- examples/toybox/managers/fireManager.js | 97 --------------------- examples/toybox/managers/sprayCanManager.js | 0 examples/toybox/masterResetEntity.js | 97 ++++++++++++++++----- 4 files changed, 77 insertions(+), 181 deletions(-) delete mode 100644 examples/toybox/managers/blockManager.js delete mode 100644 examples/toybox/managers/fireManager.js delete mode 100644 examples/toybox/managers/sprayCanManager.js diff --git a/examples/toybox/managers/blockManager.js b/examples/toybox/managers/blockManager.js deleted file mode 100644 index 7158e4499f..0000000000 --- a/examples/toybox/managers/blockManager.js +++ /dev/null @@ -1,64 +0,0 @@ -BlockManager = function(position) { - this.position = position; - this.spawned = false; - this.blocks = []; - - this.reset = function() { - if (this.spawned) { - this.clearBlocks(); - } else { - this.createBlocks(); - } - - this.spawned = !this.spawned; - } - - this.clearBlocks = function() { - this.blocks.forEach(function(block) { - Entities.deleteEntity(block); - }); - this.blocks = []; - } - - this.createBlocks = function() { - - HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; - var modelUrl = HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/block.fbx'; - - var BASE_DIMENSIONS = Vec3.multiply({ - x: 0.2, - y: 0.1, - z: 0.8 - }, 0.2); - var NUM_BLOCKS = 4; - - for (var i = 0; i < NUM_BLOCKS; i++) { - var block = Entities.addEntity({ - type: "Model", - modelURL: modelUrl, - position: Vec3.sum(this.position, {x: 0, y: i/5, z:0}), - shapeType: 'box', - name: "block", - dimensions: Vec3.sum(BASE_DIMENSIONS, { - x: Math.random() / 10, - y: Math.random() / 10, - z: Math.random() / 10 - }), - collisionsWillMove: true, - gravity: { - x: 0, - y: -2.5, - z: 0 - }, - velocity: { - x: 0, - y: -.01, - z: 0 - } - - }); - this.blocks.push(block); - } - - } -} \ No newline at end of file diff --git a/examples/toybox/managers/fireManager.js b/examples/toybox/managers/fireManager.js deleted file mode 100644 index 30a65698fd..0000000000 --- a/examples/toybox/managers/fireManager.js +++ /dev/null @@ -1,97 +0,0 @@ -FireManager = function(position) { - this.position = position; - this.reset = function() { - if (!this.fire) { - var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); - var ZERO_VEC = { - x: 0, - y: 0, - z: 0 - } - var totalTime = 0; - var FIRE_COLOR = { - red: 255, - green: 255, - blue: 255 - }; - var minLightIntensity = 3; - var maxLightIntensity = 11; - - var minTimeFactor = .1; - var maxTimeFactor = 1; - - var LIGHT_COLOR = { - red: 255, - green: 100, - blue: 28 - } - - var animationSettings = JSON.stringify({ - fps: 30, - running: true, - loop: true, - firstFrame: 1, - lastFrame: 10000 - }); - - this.fire = Entities.addEntity({ - type: "ParticleEffect", - animationSettings: animationSettings, - textures: "https://hifi-public.s3.amazonaws.com/alan/Particles/Particle-Sprite-Smoke-1.png", - position: this.position, - name: "fire", - emitRate: 100, - colorStart: { - red: 46, - green: 39, - blue: 137 - }, - color: { - red: 200, - green: 99, - blue: 42 - }, - colorFinish: { - red: 255, - green: 99, - blue: 32 - }, - emitVelocity: { - x: .0, - y: 0.1, - z: 0 - }, - - velocitySpread: { - x: .1, - y: .01, - z: .1 - }, - radiusSpread: .1, - radiusStart: .1, - particleRadius: .05, - radiusFinish: 0.01, - - alphaStart: 0.5, - alpha: 1, - alphaFinish: 0.0, - emitAcceleration: { - x: 0.1, - y: 1, - z: .0 - }, - accelerationSpread: { - x: .01, - y: .1, - z: .01 - }, - lifespan: 2 - }); - - } else { - Entities.deleteEntity(this.fire); - this.fire = null; - } - - } -} \ No newline at end of file diff --git a/examples/toybox/managers/sprayCanManager.js b/examples/toybox/managers/sprayCanManager.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 9612745d93..cb82034f11 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -1,29 +1,86 @@ -var fireScriptURL = Script.resolvePath("managers/fireManager.js"); -Script.include(fireScriptURL); +var utilitiesScript = Script.resolvePath("../libraries/utils.js"); +Script.include(utilitiesScript); -var blockScriptURL = Script.resolvePath("managers/blockManager.js"); -Script.include(blockScriptURL); +var resetKey = "resetMe"; -var fireManager = new FireManager({ - x: 551.5435791015625, - y: 494.87728881835938, - z: 502.01531982421875 -}); - -fireManager.reset(); - -var blockManager = new BlockManager({ - x: 548.3, - y: 495.55, - z: 504.4 - }); -blockManager.reset(); +HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; +//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 + }); +} + +function deleteAllToys() { + var entities = Entities.findEntities(MyAvatar.position, 100); + + entities.forEach(function(entity) { + //params: customKey, id, defaultValue + var shouldReset = getEntityCustomData(resetKey, entity, false); + if (shouldReset) { + Entities.deleteEntity(entity); + } + }) +} + +function createBlocks(position) { + print("CREATE BLOCKS") + var modelUrl = HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/block.fbx'; + var BASE_DIMENSIONS = Vec3.multiply({ + x: 0.2, + y: 0.1, + z: 0.8 + }, 0.2); + var NUM_BLOCKS = 4; + + for (var i = 0; i < NUM_BLOCKS; i++) { + var block = Entities.addEntity({ + type: "Model", + modelURL: modelUrl, + position: Vec3.sum(position, { + x: 0, + y: i / 5, + z: 0 + }), + shapeType: 'box', + name: "block", + dimensions: Vec3.sum(BASE_DIMENSIONS, { + x: Math.random() / 10, + y: Math.random() / 10, + z: Math.random() / 10 + }), + collisionsWillMove: true, + gravity: { + x: 0, + y: -2.5, + z: 0 + }, + velocity: { + x: 0, + y: -.01, + z: 0 + } + }); + + //customKey, id, data + setEntityCustomData(resetKey, block, { + resetMe: true + }); + } +} function cleanup() { - fireManager.reset(); - blockManager.reset(); + deleteAllToys(); } Script.scriptEnding.connect(cleanup); \ No newline at end of file From ae795a5c4fad36561332bdf39e2e59373dd40abf Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 17:15:59 -0700 Subject: [PATCH 009/138] spray paint spawner working --- examples/entityScripts/sprayPaintCan.js | 1 + examples/toybox/masterResetEntity.js | 52 +++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/examples/entityScripts/sprayPaintCan.js b/examples/entityScripts/sprayPaintCan.js index aa04e94341..29ff451b76 100644 --- a/examples/entityScripts/sprayPaintCan.js +++ b/examples/entityScripts/sprayPaintCan.js @@ -238,6 +238,7 @@ Entities.deleteEntity(stroke); }); } + Script.update.connect(this.update); }); diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index cb82034f11..964070bd90 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -19,6 +19,12 @@ function createAllToys() { y: 495.55, z: 504.4 }); + + createSprayCan({ + x: 549.12, + y: 495.55, + z: 503.77 + }); } function deleteAllToys() { @@ -33,8 +39,48 @@ function deleteAllToys() { }) } +function createSprayCan(position) { + var scriptURL = Script.resolvePath("../entityScripts/sprayPaintCan.js"); + var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; + + var entity = Entities.addEntity({ + type: "Model", + name: "spraycan", + modelURL: modelURL, + position: position , + rotation: { + x: 0, + y: 0, + z: 0, + w: 1 + }, + dimensions: { + x: 0.07, + y: 0.17, + z: 0.07 + }, + collisionsWillMove: true, + shapeType: 'box', + script: scriptURL, + gravity: { + x: 0, + y: -0.5, + z: 0 + }, + velocity: { + x: 0, + y: -1, + z: 0 + } + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); + +} + function createBlocks(position) { - print("CREATE BLOCKS") var modelUrl = HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/block.fbx'; var BASE_DIMENSIONS = Vec3.multiply({ x: 0.2, @@ -44,7 +90,7 @@ function createBlocks(position) { var NUM_BLOCKS = 4; for (var i = 0; i < NUM_BLOCKS; i++) { - var block = Entities.addEntity({ + var entity = Entities.addEntity({ type: "Model", modelURL: modelUrl, position: Vec3.sum(position, { @@ -73,7 +119,7 @@ function createBlocks(position) { }); //customKey, id, data - setEntityCustomData(resetKey, block, { + setEntityCustomData(resetKey, entity, { resetMe: true }); } From d6377ee6bb1f1960a3c97b6340e3c08f167ba185 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Sep 2015 10:55:29 -0700 Subject: [PATCH 010/138] Added basketball to master reset script --- examples/toybox/masterResetEntity.js | 50 +++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 964070bd90..eef5af50e3 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -25,6 +25,12 @@ function createAllToys() { y: 495.55, z: 503.77 }); + + createBasketBall({ + x: 548.1, + y: 497, + z: 504.6 + }); } function deleteAllToys() { @@ -39,6 +45,42 @@ function deleteAllToys() { }) } +function createBasketBall(position) { + + var modelURL = "http://s3.amazonaws.com/hifi-public/models/content/basketball2.fbx"; + + var entity = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + position: position, + collisionsWillMove: true, + shapeType: "sphere", + name: "basketball", + dimensions: { + x: 0.25, + y: 0.26, + z: 0.25 + }, + gravity: { + x: 0, + y: -7, + z: 0 + }, + restitution: 10, + linearDamping: 0.0, + velocity: { + x: 0, + y: -.01, + z: 0 + } + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); + +} + function createSprayCan(position) { var scriptURL = Script.resolvePath("../entityScripts/sprayPaintCan.js"); var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; @@ -47,7 +89,7 @@ function createSprayCan(position) { type: "Model", name: "spraycan", modelURL: modelURL, - position: position , + position: position, rotation: { x: 0, y: 0, @@ -74,9 +116,9 @@ function createSprayCan(position) { } }); - setEntityCustomData(resetKey, entity, { - resetMe: true - }); + setEntityCustomData(resetKey, entity, { + resetMe: true + }); } From 6e4b838bf9c97fba4dfae8abe4f187369bd263f1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Sep 2015 10:59:28 -0700 Subject: [PATCH 011/138] added collision sound to bbal --- examples/toybox/masterResetEntity.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index eef5af50e3..b4c8f370f9 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -72,7 +72,8 @@ function createBasketBall(position) { x: 0, y: -.01, z: 0 - } + }, + collisionSoundURL : "http://s3.amazonaws.com/hifi-public/sounds/basketball/basketball.wav" }); setEntityCustomData(resetKey, entity, { From 65722dc87036f4215b664daf3e38ac097d8763a3 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Sep 2015 11:01:33 -0700 Subject: [PATCH 012/138] Removed master spawner as its no longer needed --- examples/toybox/masterResetEntitySpawner.js | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 examples/toybox/masterResetEntitySpawner.js diff --git a/examples/toybox/masterResetEntitySpawner.js b/examples/toybox/masterResetEntitySpawner.js deleted file mode 100644 index 8938595d7f..0000000000 --- a/examples/toybox/masterResetEntitySpawner.js +++ /dev/null @@ -1,19 +0,0 @@ -var scriptURL = Script.resolvePath("masterResetEntity.js?v1" + Math.random()); - -var center = Vec3.sum(MyAvatar.position, Vec3.multiply(1, Quat.getFront(Camera.getOrientation()))); - -var resetEntity = Entities.addEntity({ - type: "Box", - dimensions: {x: .3, y: 0.3, z: 0.3}, - position: center, - color: {red: 100, green: 10, blue: 100}, - script: scriptURL -}); - - - -function cleanup() { - Entities.deleteEntity(resetEntity); -} - -Script.scriptEnding.connect(cleanup); \ No newline at end of file From 8ada3dec6e335af6e5ff6d59466af12af5fd93d5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Sep 2015 11:29:16 -0700 Subject: [PATCH 013/138] Adding doll in --- examples/toybox/masterResetEntity.js | 42 ++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index b4c8f370f9..c0c6e31287 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -31,6 +31,12 @@ function createAllToys() { y: 497, z: 504.6 }); + + createDoll({ + x: 545.9, + y: 496, + z: 506.2 + }) } function deleteAllToys() { @@ -57,7 +63,7 @@ function createBasketBall(position) { shapeType: "sphere", name: "basketball", dimensions: { - x: 0.25, + x: 0.25, y: 0.26, z: 0.25 }, @@ -73,7 +79,7 @@ function createBasketBall(position) { y: -.01, z: 0 }, - collisionSoundURL : "http://s3.amazonaws.com/hifi-public/sounds/basketball/basketball.wav" + collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/basketball/basketball.wav" }); setEntityCustomData(resetKey, entity, { @@ -82,6 +88,38 @@ function createBasketBall(position) { } +function createDoll(position) { + var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; + + var naturalDimensions = {x: 1.63, y: 1.67, z: 0.26}; + var desiredDimensions = Vec3.multiply(naturalDimensions, 0.15); + + var entity = Entities.addEntity({ + type: "Model", + name: "doll", + modelURL: modelURL, + position: position, + shapeType: 'box', + dimensions: desiredDimensions, + gravity: { + x: 0, + y: -5, + z: 0 + }, + velocity: { + x: 0, + y: -.1, + z: 0 + }, + collisionsWillMove: true + }); + + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +} + function createSprayCan(position) { var scriptURL = Script.resolvePath("../entityScripts/sprayPaintCan.js"); var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; From 86dfa6f590c3feb6784ea33930c8ab892717c10f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Sep 2015 12:35:49 -0700 Subject: [PATCH 014/138] 2 sizes for blocks --- examples/toybox/masterResetEntity.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index c0c6e31287..695730b49d 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -163,12 +163,11 @@ function createSprayCan(position) { function createBlocks(position) { var modelUrl = HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/block.fbx'; - var BASE_DIMENSIONS = Vec3.multiply({ - x: 0.2, - y: 0.1, - z: 0.8 - }, 0.2); - var NUM_BLOCKS = 4; + var dimensionsArray = [ + {x: .1, y: 0.05, z: 0.25}, + {x: 0.06, y: 0.04, z: 0.28} + ]; + var NUM_BLOCKS = 12; for (var i = 0; i < NUM_BLOCKS; i++) { var entity = Entities.addEntity({ @@ -181,11 +180,7 @@ function createBlocks(position) { }), shapeType: 'box', name: "block", - dimensions: Vec3.sum(BASE_DIMENSIONS, { - x: Math.random() / 10, - y: Math.random() / 10, - z: Math.random() / 10 - }), + dimensions: dimensionsArray[randInt(0, dimensionsArray.length)], collisionsWillMove: true, gravity: { x: 0, @@ -210,4 +205,12 @@ function cleanup() { deleteAllToys(); } -Script.scriptEnding.connect(cleanup); \ No newline at end of file +Script.scriptEnding.connect(cleanup); + +function randFloat(low, high) { + return low + Math.random() * (high - low); +} + +function randInt(low, high) { + return Math.floor(randFloat(low, high)); +} From dd3f1301e651095514585ed41865695ad74a9846 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Sep 2015 14:36:41 -0700 Subject: [PATCH 015/138] Blocks are now multi colored --- examples/toybox/masterResetEntity.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 695730b49d..68510c1dfb 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -162,7 +162,8 @@ function createSprayCan(position) { } function createBlocks(position) { - var modelUrl = HIFI_PUBLIC_BUCKET + 'marketplace/hificontent/Games/blocks/block.fbx'; + var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/" + var modelURLs = ['planky_blue.fbx', 'planky_green.fbx', 'planky_natural.fbx', "planky_red.fbx", "planky_yellow.fbx"]; var dimensionsArray = [ {x: .1, y: 0.05, z: 0.25}, {x: 0.06, y: 0.04, z: 0.28} @@ -170,12 +171,13 @@ function createBlocks(position) { var NUM_BLOCKS = 12; for (var i = 0; i < NUM_BLOCKS; i++) { + var modelURL = baseURL + modelURLs[randInt(0, modelURLs.length)]; var entity = Entities.addEntity({ type: "Model", - modelURL: modelUrl, + modelURL: modelURL, position: Vec3.sum(position, { x: 0, - y: i / 5, + y: i / 10, z: 0 }), shapeType: 'box', From de14fc64f60ccb2ec4493a5510965f9e901f2df8 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Sep 2015 17:17:55 -0700 Subject: [PATCH 016/138] screaming on grab. Need to get release working --- examples/toybox/entityScripts/doll.js | 72 +++++++++++++++++++++++++++ examples/toybox/masterResetEntity.js | 18 ++++++- 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 examples/toybox/entityScripts/doll.js diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js new file mode 100644 index 0000000000..04a5e4f7eb --- /dev/null +++ b/examples/toybox/entityScripts/doll.js @@ -0,0 +1,72 @@ +// +// detectGrabExample.js +// examples/entityScripts +// +// Created by Brad Hefta-Gaub on 9/3/15. +// Copyright 2015 High Fidelity, Inc. +// +// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + + var _this; + HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; + + // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember + // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) + Doll = function() { + _this = this; + var screamSoundDirectory = HIFI_PUBLIC_BUCKET + "eric/sounds/" + this.screamSound = SoundCache.getSound(screamSoundDirectory + "dollScream1.wav") + this.startAnimationSetting = JSON.stringify({ + running: true + }); + + this.stopAnimationSetting = JSON.stringify({ + running: false + }); + }; + + Doll.prototype = { + + + startNearGrab: function() { + print("I was just grabbed... entity:" + this.entityID); + Entities.editEntity(this.entityID, { + animationSettings: this.startAnimationSetting + }); + + var position = Entities.getEntityProperties(this.entityID, "position").position; + print("POSITIONNN " + JSON.stringify(position)) + print("SCREAM SOUND ") + Audio.playSound(this.screamSound[0], { + position: position, + volume: 0.1 + }); + + }, + + release: function() { + print("RELEASE") + Entities.editEntity(this.entityID, { + animationSettings: this.stopAnimationSetting + }); + }, + + + // preload() will be called when the entity has become visible (or known) to the interface + // it gives us a chance to set our local JavaScript object up. In this case it means: + // * remembering our entityID, so we can access it in cases where we're called without an entityID + // * connecting to the update signal so we can check our grabbed state + preload: function(entityID) { + this.entityID = entityID; + }, + }; + + // entity scripts always need to return a newly constructed object of our type + return new Doll(); +}) \ No newline at end of file diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 68510c1dfb..23f4b46503 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -5,6 +5,8 @@ var resetKey = "resetMe"; 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(); @@ -90,14 +92,23 @@ function createBasketBall(position) { function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; + var animationURL = "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx"; + var animationSettings = JSON.stringify({ + running: false + }); + + var scriptURL = Script.resolvePath("entityScripts/doll.js"); + // var scriptURL = Script.resolvePath("../entityScripts/sprayPaintCan.js"); var naturalDimensions = {x: 1.63, y: 1.67, z: 0.26}; var desiredDimensions = Vec3.multiply(naturalDimensions, 0.15); - var entity = Entities.addEntity({ type: "Model", name: "doll", modelURL: modelURL, + animationSettings: animationSettings, + animationURL: animationURL, + script: scriptURL, position: position, shapeType: 'box', dimensions: desiredDimensions, @@ -207,7 +218,10 @@ function cleanup() { deleteAllToys(); } -Script.scriptEnding.connect(cleanup); +if(shouldDeleteOnEndScript) { + + Script.scriptEnding.connect(cleanup); +} function randFloat(low, high) { return low + Math.random() * (high - low); From b62807011c8f774d6ab6b5717071f06e635c297d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Sep 2015 17:22:45 -0700 Subject: [PATCH 017/138] Doll screams and writhes when picked up, returns to default position when let go --- examples/toybox/entityScripts/doll.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js index 04a5e4f7eb..76da29a14b 100644 --- a/examples/toybox/entityScripts/doll.js +++ b/examples/toybox/entityScripts/doll.js @@ -27,6 +27,7 @@ }); this.stopAnimationSetting = JSON.stringify({ + frameIndex: 0, running: false }); }; @@ -43,14 +44,14 @@ var position = Entities.getEntityProperties(this.entityID, "position").position; print("POSITIONNN " + JSON.stringify(position)) print("SCREAM SOUND ") - Audio.playSound(this.screamSound[0], { + Audio.playSound(this.screamSound, { position: position, volume: 0.1 }); }, - release: function() { + releaseGrab: function() { print("RELEASE") Entities.editEntity(this.entityID, { animationSettings: this.stopAnimationSetting From fb9896019400c8de908266802a53de14bb092a08 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 18 Sep 2015 17:45:28 -0700 Subject: [PATCH 018/138] Adding wand to master script --- examples/toybox/entityScripts/wand.js | 0 examples/toybox/masterResetEntity.js | 77 +++++++++++++++++++++------ 2 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 examples/toybox/entityScripts/wand.js diff --git a/examples/toybox/entityScripts/wand.js b/examples/toybox/entityScripts/wand.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 23f4b46503..722705b254 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -38,7 +38,13 @@ function createAllToys() { x: 545.9, y: 496, z: 506.2 - }) + }); + + createWand({ + x: 546.48, + y: 495.63, + z: 506.25 + }); } function deleteAllToys() { @@ -53,6 +59,38 @@ function deleteAllToys() { }) } +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/collisionHull.obj'; + //Just using abs path for demo purposes on sunday, since this PR for wand has not been merged + var scriptURL = "https://raw.githubusercontent.com/imgntn/hifi/ccf125c047426a2c481d3ee8c58a05fc6048fdde/examples/toys/bubblewand/wand.js" + + var entity = Entities.addEntity({ + name: 'Bubble Wand', + type: "Model", + modelURL: WAND_MODEL, + position: position, + gravity: { + x: 0, + y: 0, + z: 0, + }, + dimensions: { + x: 0.05, + y: 0.25, + z: 0.05 + }, + //must be enabled to be grabbable in the physics engine + collisionsWillMove: true, + compoundShapeURL: WAND_COLLISION_SHAPE, + script: scriptURL + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +} + function createBasketBall(position) { var modelURL = "http://s3.amazonaws.com/hifi-public/models/content/basketball2.fbx"; @@ -93,14 +131,18 @@ function createBasketBall(position) { function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; var animationURL = "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx"; - var animationSettings = JSON.stringify({ + var animationSettings = JSON.stringify({ running: false }); - - var scriptURL = Script.resolvePath("entityScripts/doll.js"); - // var scriptURL = Script.resolvePath("../entityScripts/sprayPaintCan.js"); - var naturalDimensions = {x: 1.63, y: 1.67, z: 0.26}; + var scriptURL = Script.resolvePath("entityScripts/doll.js"); + // var scriptURL = Script.resolvePath("../entityScripts/sprayPaintCan.js"); + + var naturalDimensions = { + x: 1.63, + y: 1.67, + z: 0.26 + }; var desiredDimensions = Vec3.multiply(naturalDimensions, 0.15); var entity = Entities.addEntity({ type: "Model", @@ -175,10 +217,15 @@ function createSprayCan(position) { function createBlocks(position) { var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/" var modelURLs = ['planky_blue.fbx', 'planky_green.fbx', 'planky_natural.fbx', "planky_red.fbx", "planky_yellow.fbx"]; - var dimensionsArray = [ - {x: .1, y: 0.05, z: 0.25}, - {x: 0.06, y: 0.04, z: 0.28} - ]; + var dimensionsArray = [{ + x: .1, + y: 0.05, + z: 0.25 + }, { + x: 0.06, + y: 0.04, + z: 0.28 + }]; var NUM_BLOCKS = 12; for (var i = 0; i < NUM_BLOCKS; i++) { @@ -218,15 +265,15 @@ function cleanup() { deleteAllToys(); } -if(shouldDeleteOnEndScript) { +if (shouldDeleteOnEndScript) { - Script.scriptEnding.connect(cleanup); + Script.scriptEnding.connect(cleanup); } function randFloat(low, high) { - return low + Math.random() * (high - low); + return low + Math.random() * (high - low); } function randInt(low, high) { - return Math.floor(randFloat(low, high)); -} + return Math.floor(randFloat(low, high)); +} \ No newline at end of file From 5cd69c4f03a6ea51097eef19dee7b389a40221d0 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 21 Sep 2015 09:17:23 -0700 Subject: [PATCH 019/138] Added dice to master reset script --- examples/toybox/masterResetEntity.js | 36 ++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 722705b254..57924fb6e2 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -41,10 +41,12 @@ function createAllToys() { }); createWand({ - x: 546.48, + x: 546.45, y: 495.63, - z: 506.25 + z: 506.18 }); + + createDice(); } function deleteAllToys() { @@ -59,6 +61,34 @@ function deleteAllToys() { }) } +function createDice() { + var diceProps = { + type: "Model", + modelURL: "http://s3.amazonaws.com/hifi-public/models/props/Dice/goldDie.fbx", + collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", + name: "dice", + position: {x: 541.1, y: 494.94, z: 509.21 }, + dimensions: {x: 0.09, y: 0.09, z: 0.09}, + gravity: {x: 0, y: -3.5, z: 0}, + velocity: {x: 0, y: -.01, z: 0}, + shapeType: "box", + collisionsWillMove: true + } + var dice1 = Entities.addEntity(diceProps); + + diceProps.position = {x: 540.99, y: 494.4, z: 509.08}; + + var dice2 = Entities.addEntity(diceProps); + + setEntityCustomData(resetKey, dice1, { + resetMe: true + }); + + setEntityCustomData(resetKey, dice2, { + resetMe: true + }); +} + 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/collisionHull.obj'; @@ -83,6 +113,8 @@ function createWand(position) { //must be enabled to be grabbable in the physics engine collisionsWillMove: true, compoundShapeURL: WAND_COLLISION_SHAPE, + // gravity: {x: 0, y: -3.5, z: 0}, + // velocity: {x: 0, y: -0.01, z:0}, script: scriptURL }); From a71f1495e91d17d3b9e18b2e9b1da447b24c1ad6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 21 Sep 2015 11:15:40 -0700 Subject: [PATCH 020/138] Lowered sound volume on doll, now choose between two screams --- examples/toybox/entityScripts/doll.js | 24 +++++++++++++++--------- examples/toybox/masterResetEntity.js | 3 +-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js index 76da29a14b..f3850d760d 100644 --- a/examples/toybox/entityScripts/doll.js +++ b/examples/toybox/entityScripts/doll.js @@ -21,7 +21,7 @@ Doll = function() { _this = this; var screamSoundDirectory = HIFI_PUBLIC_BUCKET + "eric/sounds/" - this.screamSound = SoundCache.getSound(screamSoundDirectory + "dollScream1.wav") + this.screamSounds = [SoundCache.getSound(screamSoundDirectory + "dollScream2.wav?=v2"), SoundCache.getSound(screamSoundDirectory + "dollScream1.wav?=v2")]; this.startAnimationSetting = JSON.stringify({ running: true }); @@ -36,25 +36,23 @@ startNearGrab: function() { - print("I was just grabbed... entity:" + this.entityID); Entities.editEntity(this.entityID, { + animationURL: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", animationSettings: this.startAnimationSetting }); var position = Entities.getEntityProperties(this.entityID, "position").position; - print("POSITIONNN " + JSON.stringify(position)) - print("SCREAM SOUND ") - Audio.playSound(this.screamSound, { + Audio.playSound(this.screamSounds[randInt(0, this.screamSounds.length)], { position: position, - volume: 0.1 + volume: 0.01 }); }, releaseGrab: function() { - print("RELEASE") Entities.editEntity(this.entityID, { - animationSettings: this.stopAnimationSetting + animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx", + // animationSettings: this.stopAnimationSetting }); }, @@ -70,4 +68,12 @@ // entity scripts always need to return a newly constructed object of our type return new Doll(); -}) \ No newline at end of file +}) + +function randFloat(low, high) { + return low + Math.random() * (high - low); +} + +function randInt(low, high) { + return Math.floor(randFloat(low, high)); +} \ No newline at end of file diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 57924fb6e2..0ce949562d 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -113,6 +113,7 @@ function createWand(position) { //must be enabled to be grabbable in the physics engine collisionsWillMove: true, compoundShapeURL: WAND_COLLISION_SHAPE, + //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 @@ -168,7 +169,6 @@ function createDoll(position) { }); var scriptURL = Script.resolvePath("entityScripts/doll.js"); - // var scriptURL = Script.resolvePath("../entityScripts/sprayPaintCan.js"); var naturalDimensions = { x: 1.63, @@ -199,7 +199,6 @@ function createDoll(position) { collisionsWillMove: true }); - setEntityCustomData(resetKey, entity, { resetMe: true }); From 30198aa6f22ddf29901a94b9f48503538d4d2b10 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 21 Sep 2015 11:22:35 -0700 Subject: [PATCH 021/138] Only play animation once for screaming doll when picked up --- examples/toybox/entityScripts/doll.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js index f3850d760d..63b4fcc43d 100644 --- a/examples/toybox/entityScripts/doll.js +++ b/examples/toybox/entityScripts/doll.js @@ -23,11 +23,11 @@ var screamSoundDirectory = HIFI_PUBLIC_BUCKET + "eric/sounds/" this.screamSounds = [SoundCache.getSound(screamSoundDirectory + "dollScream2.wav?=v2"), SoundCache.getSound(screamSoundDirectory + "dollScream1.wav?=v2")]; this.startAnimationSetting = JSON.stringify({ - running: true + running: true, + lastFrame: 64 }); this.stopAnimationSetting = JSON.stringify({ - frameIndex: 0, running: false }); }; From 4e517b78e122acd9e681f1247314d262e5952b0a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 21 Sep 2015 11:26:56 -0700 Subject: [PATCH 022/138] dice spawning higher so they fall onto craps table --- examples/toybox/masterResetEntity.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 0ce949562d..627927e109 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -67,7 +67,7 @@ function createDice() { modelURL: "http://s3.amazonaws.com/hifi-public/models/props/Dice/goldDie.fbx", collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", name: "dice", - position: {x: 541.1, y: 494.94, z: 509.21 }, + position: {x: 541.1, y: 496, z: 509.21 }, dimensions: {x: 0.09, y: 0.09, z: 0.09}, gravity: {x: 0, y: -3.5, z: 0}, velocity: {x: 0, y: -.01, z: 0}, @@ -76,7 +76,7 @@ function createDice() { } var dice1 = Entities.addEntity(diceProps); - diceProps.position = {x: 540.99, y: 494.4, z: 509.08}; + diceProps.position = {x: 540.99, y: 496, z: 509.08}; var dice2 = Entities.addEntity(diceProps); From d24df99445e8c95f0d00de55ae54a642e4ab8a18 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 21 Sep 2015 11:51:00 -0700 Subject: [PATCH 023/138] Updated block logic to sync with desired behavior (each color block maps to a different size) --- examples/toybox/masterResetEntity.js | 95 ++++++++++++++++------------ 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 627927e109..7fbcc97f4a 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -248,47 +248,64 @@ function createSprayCan(position) { function createBlocks(position) { var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/" var modelURLs = ['planky_blue.fbx', 'planky_green.fbx', 'planky_natural.fbx', "planky_red.fbx", "planky_yellow.fbx"]; - var dimensionsArray = [{ - x: .1, - y: 0.05, - z: 0.25 - }, { - x: 0.06, - y: 0.04, - z: 0.28 - }]; - var NUM_BLOCKS = 12; + var blockTypes = [ + { + url: "planky_blue.fbx", + dimensions: {x: 0.05, y: 0.05, z: 0.25} + }, + { + url: "planky_green.fbx", + dimensions: {x: 0.1, y: 0.1, z: 0.25} + }, + { + url: "planky_natural.fbx", + dimensions: {x: 0.05, y: 0.05, z: 0.05} + }, + { + url: "planky_yellow.fbx", + dimensions: {x: 0.03, y: 0.05, z: 0.25} + }, + { + url: "planky_red.fbx", + dimensions: {x: 0.1, y: 0.05, z: 0.25} + }, - for (var i = 0; i < NUM_BLOCKS; i++) { - var modelURL = baseURL + modelURLs[randInt(0, modelURLs.length)]; - var entity = Entities.addEntity({ - type: "Model", - modelURL: modelURL, - position: Vec3.sum(position, { - x: 0, - y: i / 10, - z: 0 - }), - shapeType: 'box', - name: "block", - dimensions: dimensionsArray[randInt(0, dimensionsArray.length)], - collisionsWillMove: true, - gravity: { - x: 0, - y: -2.5, - z: 0 - }, - velocity: { - x: 0, - y: -.01, - z: 0 - } - }); - //customKey, id, data - setEntityCustomData(resetKey, entity, { - resetMe: true - }); + ]; + var NUM_BLOCKS_PER_COLOR = 4; + + for (var i = 0; i < blockTypes.length; i++) { + for(j = 0; j < NUM_BLOCKS_PER_COLOR; j++) { + var modelURL = baseURL + blockTypes[i].url; + var entity = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + position: Vec3.sum(position, { + x: j/10, + y: i / 10, + z: 0 + }), + shapeType: 'box', + name: "block", + dimensions: blockTypes[i].dimensions, + collisionsWillMove: true, + gravity: { + x: 0, + y: -2.5, + z: 0 + }, + velocity: { + x: 0, + y: -.01, + z: 0 + } + }); + + //customKey, id, data + setEntityCustomData(resetKey, entity, { + resetMe: true + }); + } } } From b727256377b852244bee7ba499682a580a0aef73 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 21 Sep 2015 13:05:37 -0700 Subject: [PATCH 024/138] animation of doll plays longer now to give user a chance to see it play --- examples/toybox/entityScripts/doll.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js index 63b4fcc43d..0f4aaf5cd7 100644 --- a/examples/toybox/entityScripts/doll.js +++ b/examples/toybox/entityScripts/doll.js @@ -24,7 +24,8 @@ this.screamSounds = [SoundCache.getSound(screamSoundDirectory + "dollScream2.wav?=v2"), SoundCache.getSound(screamSoundDirectory + "dollScream1.wav?=v2")]; this.startAnimationSetting = JSON.stringify({ running: true, - lastFrame: 64 + startFrame: 0, + lastFrame: 128 }); this.stopAnimationSetting = JSON.stringify({ From 8678e07c21555c35cc05f1bd622358279de7513a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 21 Sep 2015 15:45:54 -0700 Subject: [PATCH 025/138] Adding in light triggering logic --- examples/toybox/entityScripts/doll.js | 8 +- examples/toybox/entityScripts/lightSwitch.js | 97 +++++++++++++++ examples/toybox/entityScripts/wand.js | 0 examples/toybox/masterResetEntity.js | 119 +++++++++++++++---- 4 files changed, 195 insertions(+), 29 deletions(-) create mode 100644 examples/toybox/entityScripts/lightSwitch.js delete mode 100644 examples/toybox/entityScripts/wand.js diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js index 0f4aaf5cd7..86e7fcc62c 100644 --- a/examples/toybox/entityScripts/doll.js +++ b/examples/toybox/entityScripts/doll.js @@ -1,11 +1,11 @@ // -// detectGrabExample.js -// examples/entityScripts +// doll.js +// examples/toybox/entityScripts // -// Created by Brad Hefta-Gaub on 9/3/15. +// Created by Eric Levin on 9/21/15. // Copyright 2015 High Fidelity, Inc. // -// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script +// This entity script breathes movement and sound- one might even say life- into a doll. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html diff --git a/examples/toybox/entityScripts/lightSwitch.js b/examples/toybox/entityScripts/lightSwitch.js new file mode 100644 index 0000000000..bb80d76f57 --- /dev/null +++ b/examples/toybox/entityScripts/lightSwitch.js @@ -0,0 +1,97 @@ +// +// detectGrabExample.js +// examples/entityScripts +// +// Created by Eric Levin on 9/21/15. +// Copyright 2015 High Fidelity, Inc. +// +// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + + var _this; + + + // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember + // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) + LightSwitch = function() { + _this = this; + + this.lightStateKey = "lightStateKey"; + this.resetKey = "resetMe"; + + }; + + LightSwitch.prototype = { + + + startNearGrab: function() { + print("TOGGLE LIGHT") + + // var position = Entities.getEntityProperties(this.entityID, "position").position; + // Audio.playSound(clickSound, { + // position: position, + // volume: 0.05 + // }); + + }, + + createLights: function() { + print("CREATE LIGHTS *******************") + this.sconceLight1 = Entities.addEntity({ + type: "Light", + position: { + x: 543.62, + y: 496.24, + z: 511.23 + }, + name: "Sconce 1 Light", + dimensions: { + x: 2.545, + y: 2.545, + z: 2.545 + }, + cutoff: 90, + color: { + red: 217, + green: 146, + blue: 24 + } + }); + + setEntityCustomData(this.resetKey, this.sconceLight1, { + resetMe: true + }); + }, + + // clickReleaseOnEntity: function(entityId, mouseEvent) { + // print("CLIIICK ON MOUSE") + // if (!mouseEvent.isLeftButton) { + // return; + // } + // }, + + // preload() will be called when the entity has become visible (or known) to the interface + // it gives us a chance to set our local JavaScript object up. In this case it means: + preload: function(entityID) { + this.entityID = entityID; + var defaultLightData= { + on: false + }; + this.lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData); + + //If light is off, then we create two new lights- at the position of the sconces + if (this.lightState.on === false) { + this.createLights(); + } + + }, + }; + + // entity scripts always need to return a newly constructed object of our type + return new LightSwitch(); +}) \ No newline at end of file diff --git a/examples/toybox/entityScripts/wand.js b/examples/toybox/entityScripts/wand.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 7fbcc97f4a..ecc657ecc7 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -47,6 +47,8 @@ function createAllToys() { }); createDice(); + + createLightSwitch(); } function deleteAllToys() { @@ -61,32 +63,84 @@ function deleteAllToys() { }) } +function createLightSwitch() { + var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.obj"; + var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js?v1"); + var lightSwitch = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + name: "Light Switch Hall", + collisionsWillMove: true, + script: scriptURL, + position: { + x: 543.27764892578125, + y: 495.67999267578125, + z: 511.00564575195312 + }, + rotation: { + w: 0.63280689716339111, + x: 0.63280689716339111, + y: -0.31551080942153931, + z: 0.31548023223876953 + }, + dimensions: { + x: 0.10546875, + y: 0.032372996211051941, + z: 0.16242524981498718 + } + }); + + setEntityCustomData(resetKey, lightSwitch, { + resetMe: true + }); +} + function createDice() { var diceProps = { type: "Model", modelURL: "http://s3.amazonaws.com/hifi-public/models/props/Dice/goldDie.fbx", collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", name: "dice", - position: {x: 541.1, y: 496, z: 509.21 }, - dimensions: {x: 0.09, y: 0.09, z: 0.09}, - gravity: {x: 0, y: -3.5, z: 0}, - velocity: {x: 0, y: -.01, z: 0}, + position: { + x: 541.1, + y: 496, + z: 509.21 + }, + dimensions: { + x: 0.09, + y: 0.09, + z: 0.09 + }, + gravity: { + x: 0, + y: -3.5, + z: 0 + }, + velocity: { + x: 0, + y: -.01, + z: 0 + }, shapeType: "box", collisionsWillMove: true } var dice1 = Entities.addEntity(diceProps); - diceProps.position = {x: 540.99, y: 496, z: 509.08}; + diceProps.position = { + x: 540.99, + y: 496, + z: 509.08 + }; var dice2 = Entities.addEntity(diceProps); - setEntityCustomData(resetKey, dice1, { + setEntityCustomData(resetKey, dice1, { resetMe: true }); - setEntityCustomData(resetKey, dice2, { + setEntityCustomData(resetKey, dice2, { resetMe: true - }); + }); } function createWand(position) { @@ -248,26 +302,41 @@ function createSprayCan(position) { function createBlocks(position) { var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/" var modelURLs = ['planky_blue.fbx', 'planky_green.fbx', 'planky_natural.fbx', "planky_red.fbx", "planky_yellow.fbx"]; - var blockTypes = [ - { + var blockTypes = [{ url: "planky_blue.fbx", - dimensions: {x: 0.05, y: 0.05, z: 0.25} - }, - { + dimensions: { + x: 0.05, + y: 0.05, + z: 0.25 + } + }, { url: "planky_green.fbx", - dimensions: {x: 0.1, y: 0.1, z: 0.25} - }, - { + dimensions: { + x: 0.1, + y: 0.1, + z: 0.25 + } + }, { url: "planky_natural.fbx", - dimensions: {x: 0.05, y: 0.05, z: 0.05} - }, - { + dimensions: { + x: 0.05, + y: 0.05, + z: 0.05 + } + }, { url: "planky_yellow.fbx", - dimensions: {x: 0.03, y: 0.05, z: 0.25} - }, - { + dimensions: { + x: 0.03, + y: 0.05, + z: 0.25 + } + }, { url: "planky_red.fbx", - dimensions: {x: 0.1, y: 0.05, z: 0.25} + dimensions: { + x: 0.1, + y: 0.05, + z: 0.25 + } }, @@ -275,13 +344,13 @@ function createBlocks(position) { var NUM_BLOCKS_PER_COLOR = 4; for (var i = 0; i < blockTypes.length; i++) { - for(j = 0; j < NUM_BLOCKS_PER_COLOR; j++) { + for (j = 0; j < NUM_BLOCKS_PER_COLOR; j++) { var modelURL = baseURL + blockTypes[i].url; var entity = Entities.addEntity({ type: "Model", modelURL: modelURL, position: Vec3.sum(position, { - x: j/10, + x: j / 10, y: i / 10, z: 0 }), From e4d630b1fc6b3899d6862f3e26ed6a1dca792f67 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 21 Sep 2015 15:57:03 -0700 Subject: [PATCH 026/138] more light toggling additions --- examples/toybox/entityScripts/lightSwitch.js | 12 ++++++++++-- examples/toybox/masterResetEntity.js | 5 +++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/toybox/entityScripts/lightSwitch.js b/examples/toybox/entityScripts/lightSwitch.js index bb80d76f57..17709764d6 100644 --- a/examples/toybox/entityScripts/lightSwitch.js +++ b/examples/toybox/entityScripts/lightSwitch.js @@ -31,7 +31,14 @@ startNearGrab: function() { print("TOGGLE LIGHT") - + this.lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData); + if (this.lightState.on === true) { + //Delete the all the sconce lights + var entities = Entities.findEntities(MyAvatar.position, 100); + entities.forEach(function(entity){ + var resetData = getEntityCustomData(this.resetKey, entity, {}) + }); + } // var position = Entities.getEntityProperties(this.entityID, "position").position; // Audio.playSound(clickSound, { // position: position, @@ -64,7 +71,8 @@ }); setEntityCustomData(this.resetKey, this.sconceLight1, { - resetMe: true + resetMe: true, + lightType: "sconceLight" }); }, diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index ecc657ecc7..f7e0f3524b 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -56,8 +56,9 @@ function deleteAllToys() { entities.forEach(function(entity) { //params: customKey, id, defaultValue - var shouldReset = getEntityCustomData(resetKey, entity, false); - if (shouldReset) { + var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; + print("should reset " + JSON.stringify(shouldReset)); + if (shouldReset === true) { Entities.deleteEntity(entity); } }) From a4e5f707cc0f78f8c09c7420f0c2cc22659b3bf9 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 21 Sep 2015 16:35:30 -0700 Subject: [PATCH 027/138] Toggling lights --- examples/toybox/entityScripts/lightSwitch.js | 61 +++++++++++++------- examples/toybox/masterResetEntity.js | 1 - 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/examples/toybox/entityScripts/lightSwitch.js b/examples/toybox/entityScripts/lightSwitch.js index 17709764d6..30f490a303 100644 --- a/examples/toybox/entityScripts/lightSwitch.js +++ b/examples/toybox/entityScripts/lightSwitch.js @@ -30,25 +30,39 @@ startNearGrab: function() { - print("TOGGLE LIGHT") - this.lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData); - if (this.lightState.on === true) { - //Delete the all the sconce lights - var entities = Entities.findEntities(MyAvatar.position, 100); - entities.forEach(function(entity){ - var resetData = getEntityCustomData(this.resetKey, entity, {}) - }); + + var defaultLightData = { + on: false + }; + var lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData); + if (lightState.on === true) { + this.clearLights(); + } else if (lightState.on === false) { + this.createLights(); } - // var position = Entities.getEntityProperties(this.entityID, "position").position; - // Audio.playSound(clickSound, { - // position: position, - // volume: 0.05 - // }); }, + clearLights: function() { + print("CLEAR LIGHTS") + var entities = Entities.findEntities(MyAvatar.position, 100); + var self = this;0 + entities.forEach(function(entity) { + var resetData = getEntityCustomData(self.resetKey, entity, {}) + print("NAME OF THING " + Entities.getEntityProperties(entity).name) + print("RESET DATA " + JSON.stringify(resetData)) + if (resetData.resetMe === true && resetData.lightType === "Sconce Light") { + print("DELETE LIGHT") + Entities.deleteEntity(entity); + } + }); + + setEntityCustomData(this.lightStateKey, this.entityID, { + on: false + }); + }, + createLights: function() { - print("CREATE LIGHTS *******************") this.sconceLight1 = Entities.addEntity({ type: "Light", position: { @@ -72,8 +86,13 @@ setEntityCustomData(this.resetKey, this.sconceLight1, { resetMe: true, - lightType: "sconceLight" + lightType: "Sconce Light" }); + + setEntityCustomData(this.lightStateKey, this.entityID, { + on: true + }); + }, // clickReleaseOnEntity: function(entityId, mouseEvent) { @@ -85,18 +104,18 @@ // preload() will be called when the entity has become visible (or known) to the interface // it gives us a chance to set our local JavaScript object up. In this case it means: - preload: function(entityID) { + preload: function(entityID) { this.entityID = entityID; - var defaultLightData= { + var defaultLightData = { on: false }; - this.lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData); + var lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData); //If light is off, then we create two new lights- at the position of the sconces - if (this.lightState.on === false) { + if (lightState.on === false) { this.createLights(); - } - + } + //If lights are on, do nothing! }, }; diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index f7e0f3524b..5736e0d29f 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -57,7 +57,6 @@ function deleteAllToys() { entities.forEach(function(entity) { //params: customKey, id, defaultValue var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; - print("should reset " + JSON.stringify(shouldReset)); if (shouldReset === true) { Entities.deleteEntity(entity); } From 68bee8228b5f25bbd3d3220eb503a7efa856dad1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 08:53:46 -0700 Subject: [PATCH 028/138] abstracted toggle logic to work with mouse click as well --- examples/toybox/entityScripts/lightSwitch.js | 56 ++++++++++++++------ examples/toybox/masterResetEntity.js | 3 ++ 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/examples/toybox/entityScripts/lightSwitch.js b/examples/toybox/entityScripts/lightSwitch.js index 30f490a303..99d98d943f 100644 --- a/examples/toybox/entityScripts/lightSwitch.js +++ b/examples/toybox/entityScripts/lightSwitch.js @@ -30,7 +30,18 @@ startNearGrab: function() { + this.toggleLights(); + }, + + clickReleaseOnEntity: function(entityId, mouseEvent) { + if (!mouseEvent.isLeftButton) { + return; + } + this.toggleLights(); + }, + + toggleLights: function() { var defaultLightData = { on: false }; @@ -44,15 +55,11 @@ }, clearLights: function() { - print("CLEAR LIGHTS") var entities = Entities.findEntities(MyAvatar.position, 100); - var self = this;0 + var self = this; entities.forEach(function(entity) { var resetData = getEntityCustomData(self.resetKey, entity, {}) - print("NAME OF THING " + Entities.getEntityProperties(entity).name) - print("RESET DATA " + JSON.stringify(resetData)) if (resetData.resetMe === true && resetData.lightType === "Sconce Light") { - print("DELETE LIGHT") Entities.deleteEntity(entity); } }); @@ -63,7 +70,7 @@ }, createLights: function() { - this.sconceLight1 = Entities.addEntity({ + var sconceLight1 = Entities.addEntity({ type: "Light", position: { x: 543.62, @@ -84,7 +91,33 @@ } }); - setEntityCustomData(this.resetKey, this.sconceLight1, { + setEntityCustomData(this.resetKey, sconceLight1, { + resetMe: true, + lightType: "Sconce Light" + }); + + var sconceLight2 = Entities.addEntity({ + type: "Light", + position: { + x: 539.87, + y: 496.24, + z: 505.77 + }, + name: "Sconce 2 Light", + dimensions: { + x: 2.545, + y: 2.545, + z: 2.545 + }, + cutoff: 90, + color: { + red: 217, + green: 146, + blue: 24 + } + }); + + setEntityCustomData(this.resetKey, sconceLight2, { resetMe: true, lightType: "Sconce Light" }); @@ -95,13 +128,6 @@ }, - // clickReleaseOnEntity: function(entityId, mouseEvent) { - // print("CLIIICK ON MOUSE") - // if (!mouseEvent.isLeftButton) { - // return; - // } - // }, - // preload() will be called when the entity has become visible (or known) to the interface // it gives us a chance to set our local JavaScript object up. In this case it means: preload: function(entityID) { @@ -114,7 +140,7 @@ //If light is off, then we create two new lights- at the position of the sconces if (lightState.on === false) { this.createLights(); - } + } //If lights are on, do nothing! }, }; diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 5736e0d29f..1fe1f570d9 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -48,6 +48,7 @@ function createAllToys() { createDice(); + //Handles toggling of all sconce lights createLightSwitch(); } @@ -57,6 +58,8 @@ function deleteAllToys() { entities.forEach(function(entity) { //params: customKey, id, defaultValue var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; + print("ENTITY " + Entities.getEntityProperties(entity).name) + print("SHOULD RESET " + JSON.stringify(shouldReset)) if (shouldReset === true) { Entities.deleteEntity(entity); } From 703545bac311904e82d4fd5204a7ba60e1e0f322 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 09:34:54 -0700 Subject: [PATCH 029/138] Modified lightSwitch entity to use new incoming grab API --- examples/toybox/entityScripts/lightSwitch.js | 10 ++++------ examples/toybox/masterResetEntity.js | 3 --- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/examples/toybox/entityScripts/lightSwitch.js b/examples/toybox/entityScripts/lightSwitch.js index 99d98d943f..2420011951 100644 --- a/examples/toybox/entityScripts/lightSwitch.js +++ b/examples/toybox/entityScripts/lightSwitch.js @@ -28,12 +28,6 @@ LightSwitch.prototype = { - - startNearGrab: function() { - this.toggleLights(); - - }, - clickReleaseOnEntity: function(entityId, mouseEvent) { if (!mouseEvent.isLeftButton) { return; @@ -41,6 +35,10 @@ this.toggleLights(); }, + startNearTouch: function(){ + this.toggleLights(); + }, + toggleLights: function() { var defaultLightData = { on: false diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 1fe1f570d9..80a45ef9bc 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -58,8 +58,6 @@ function deleteAllToys() { entities.forEach(function(entity) { //params: customKey, id, defaultValue var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; - print("ENTITY " + Entities.getEntityProperties(entity).name) - print("SHOULD RESET " + JSON.stringify(shouldReset)) if (shouldReset === true) { Entities.deleteEntity(entity); } @@ -73,7 +71,6 @@ function createLightSwitch() { type: "Model", modelURL: modelURL, name: "Light Switch Hall", - collisionsWillMove: true, script: scriptURL, position: { x: 543.27764892578125, From 98faf3d712bec241f1da347c83107fbfcd4c1505 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 09:53:22 -0700 Subject: [PATCH 030/138] Added light switch sound --- examples/controllers/handControllerGrab.js | 98 +++++++++++++++----- examples/toybox/entityScripts/lightSwitch.js | 10 ++ 2 files changed, 83 insertions(+), 25 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index f57e79e974..40e3879220 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -29,9 +29,21 @@ var TRIGGER_ON_VALUE = 0.2; 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, blue: 255}; // line color when pick misses -var INTERSECT_COLOR = {red: 250, green: 10, blue: 10}; // line color when pick hits -var LINE_ENTITY_DIMENSIONS = {x: 1000, y: 1000, z: 1000}; +var NO_INTERSECT_COLOR = { + red: 10, + green: 10, + blue: 255 +}; // line color when pick misses +var INTERSECT_COLOR = { + red: 250, + green: 10, + blue: 10 +}; // line color when pick hits +var LINE_ENTITY_DIMENSIONS = { + x: 1000, + y: 1000, + z: 1000 +}; var LINE_LENGTH = 500; @@ -54,7 +66,11 @@ var RELEASE_VELOCITY_MULTIPLIER = 1.5; // affects throwing things var RIGHT_HAND = 1; var LEFT_HAND = 0; -var ZERO_VEC = {x: 0, y: 0, z: 0}; +var ZERO_VEC = { + x: 0, + y: 0, + z: 0 +}; var NULL_ACTION_ID = "{00000000-0000-0000-000000000000}"; var MSEC_PER_SEC = 1000.0; @@ -68,7 +84,9 @@ var STATE_DISTANCE_HOLDING = 1; var STATE_CONTINUE_DISTANCE_HOLDING = 2; var STATE_NEAR_GRABBING = 3; var STATE_CONTINUE_NEAR_GRABBING = 4; -var STATE_RELEASE = 5; +var STATE_NEAR_TOUCHING = 5; +var STATE_CONTINUE_NEAR_TOUCHING = 6; +var STATE_RELEASE = 7; var GRAB_USER_DATA_KEY = "grabKey"; @@ -93,7 +111,7 @@ function controller(hand, triggerAction) { this.triggerValue = 0; // rolling average of trigger value this.update = function() { - switch(this.state) { + switch (this.state) { case STATE_SEARCHING: this.search(); break; @@ -109,6 +127,12 @@ function controller(hand, triggerAction) { case STATE_CONTINUE_NEAR_GRABBING: this.continueNearGrabbing(); break; + case STATE_NEAR_TOUCHING: + this.nearTouching(); + break; + case STATE_CONTINUE_NEAR_TOUCHING: + this.continueNearTouching(); + break; case STATE_RELEASE: this.release(); break; @@ -125,14 +149,14 @@ function controller(hand, triggerAction) { dimensions: LINE_ENTITY_DIMENSIONS, visible: true, position: closePoint, - linePoints: [ ZERO_VEC, farPoint ], + linePoints: [ZERO_VEC, farPoint], color: color, lifetime: LIFETIME }); } else { Entities.editEntity(this.pointer, { position: closePoint, - linePoints: [ ZERO_VEC, farPoint ], + linePoints: [ZERO_VEC, farPoint], color: color, lifetime: (Date.now() - startTime) / MSEC_PER_SEC + LIFETIME }); @@ -171,7 +195,10 @@ function controller(hand, triggerAction) { // the trigger is being pressed, do a ray test var handPosition = this.getHandPosition(); - var pickRay = {origin: handPosition, direction: Quat.getUp(this.getHandRotation())}; + var pickRay = { + origin: handPosition, + direction: Quat.getUp(this.getHandRotation()) + }; var intersection = Entities.findRayIntersection(pickRay, true); if (intersection.intersects && intersection.properties.collisionsWillMove === 1 && @@ -196,17 +223,18 @@ function controller(hand, triggerAction) { for (var i = 0; i < nearbyEntities.length; i++) { var props = Entities.getEntityProperties(nearbyEntities[i]); var distance = Vec3.distance(props.position, handPosition); - if (distance < minDistance && props.name !== "pointer" && - props.collisionsWillMove === 1 && - props.locked === 0) { + if (distance < minDistance && props.name !== "pointer") { this.grabbedEntity = nearbyEntities[i]; minDistance = distance; } } if (this.grabbedEntity === null) { this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); - } else { + } else if (props.locked === 0 && props.collisionsWillMove === 1) { this.state = STATE_NEAR_GRABBING; + } else if (props.collisionsWillMove === 0) { + // We have grabbed a non-physical object, so we want to trigger a touch event as opposed to a grab event + this.state = STATE_NEAR_TOUCHING; } } } @@ -215,7 +243,7 @@ function controller(hand, triggerAction) { this.distanceHolding = function() { var handControllerPosition = Controller.getSpatialControlPosition(this.palm); var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(this.palm)); - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position","rotation"]); + var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]); // add the action and initialize some variables this.currentObjectPosition = grabbedProperties.position; @@ -263,8 +291,8 @@ function controller(hand, triggerAction) { // the action was set up on a previous call. update the targets. var radius = Math.max(Vec3.distance(this.currentObjectPosition, - handControllerPosition) * DISTANCE_HOLDING_RADIUS_FACTOR, - DISTANCE_HOLDING_RADIUS_FACTOR); + handControllerPosition) * DISTANCE_HOLDING_RADIUS_FACTOR, + DISTANCE_HOLDING_RADIUS_FACTOR); var handMoved = Vec3.subtract(handControllerPosition, this.handPreviousPosition); this.handPreviousPosition = handControllerPosition; @@ -281,16 +309,18 @@ function controller(hand, triggerAction) { // this doubles hand rotation var handChange = Quat.multiply(Quat.slerp(this.handPreviousRotation, handRotation, - DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR), - Quat.inverse(this.handPreviousRotation)); + DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR), + Quat.inverse(this.handPreviousRotation)); this.handPreviousRotation = handRotation; this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation); Entities.callEntityMethod(this.grabbedEntity, "continueDistantGrab"); Entities.updateAction(this.grabbedEntity, this.actionID, { - targetPosition: this.currentObjectPosition, linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, - targetRotation: this.currentObjectRotation, angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME + targetPosition: this.currentObjectPosition, + linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, + targetRotation: this.currentObjectRotation, + angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME }); } @@ -339,6 +369,23 @@ function controller(hand, triggerAction) { this.currentObjectTime = Date.now(); } + this.nearTouching = function() { + if (!this.triggerSmoothedSqueezed()) { + this.state = STATE_RELEASE; + return; + } + Entities.callEntityMethod(this.grabbedEntity, "startNearTouch") + this.state = STATE_CONTINUE_NEAR_TOUCHING; + } + + this.continueNearTouching = function() { + if (!this.triggerSmoothedSqueezed()) { + this.state = STATE_RELEASE; + return; + } + Entities.callEntityMethod(this.grabbedEntity, "continueNearTouch"); + } + this.continueNearGrabbing = function() { if (!this.triggerSmoothedSqueezed()) { @@ -367,9 +414,8 @@ function controller(hand, triggerAction) { // value would otherwise give the held object time to slow down. if (this.triggerSqueezed()) { this.grabbedVelocity = - Vec3.sum(Vec3.multiply(this.grabbedVelocity, - (1.0 - NEAR_GRABBING_VELOCITY_SMOOTH_RATIO)), - Vec3.multiply(grabbedVelocity, NEAR_GRABBING_VELOCITY_SMOOTH_RATIO)); + Vec3.sum(Vec3.multiply(this.grabbedVelocity, (1.0 - NEAR_GRABBING_VELOCITY_SMOOTH_RATIO)), + Vec3.multiply(grabbedVelocity, NEAR_GRABBING_VELOCITY_SMOOTH_RATIO)); } if (useMultiplier) { @@ -389,7 +435,9 @@ function controller(hand, triggerAction) { // the action will tend to quickly bring an object's velocity to zero. now that // the action is gone, set the objects velocity to something the holder might expect. - Entities.editEntity(this.grabbedEntity, {velocity: this.grabbedVelocity}); + Entities.editEntity(this.grabbedEntity, { + velocity: this.grabbedVelocity + }); this.deactivateEntity(this.grabbedEntity); this.grabbedVelocity = ZERO_VEC; @@ -438,4 +486,4 @@ function cleanup() { Script.scriptEnding.connect(cleanup); -Script.update.connect(update) +Script.update.connect(update) \ No newline at end of file diff --git a/examples/toybox/entityScripts/lightSwitch.js b/examples/toybox/entityScripts/lightSwitch.js index 2420011951..5bf2b5a04d 100644 --- a/examples/toybox/entityScripts/lightSwitch.js +++ b/examples/toybox/entityScripts/lightSwitch.js @@ -24,6 +24,8 @@ this.lightStateKey = "lightStateKey"; this.resetKey = "resetMe"; + this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); + }; LightSwitch.prototype = { @@ -50,6 +52,11 @@ this.createLights(); } + Audio.playSound(this.switchSound, { + volume: 1, + position: this.position + }); + }, clearLights: function() { @@ -130,6 +137,9 @@ // it gives us a chance to set our local JavaScript object up. In this case it means: preload: function(entityID) { this.entityID = entityID; + + //The light switch is static, so just cache its position once + this.position = Entities.getEntityProperties(this.entityID, "position").position; var defaultLightData = { on: false }; From b704ebd9348a55b372b309368fe60d2d803be360 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 09:55:24 -0700 Subject: [PATCH 031/138] modified dice starting position --- examples/toybox/masterResetEntity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 80a45ef9bc..be035d4252 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -102,7 +102,7 @@ function createDice() { collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", name: "dice", position: { - x: 541.1, + x: 540.74, y: 496, z: 509.21 }, From 2557b32e1a70cc78724c0e478e938ff27ea9fba4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 12:40:09 -0700 Subject: [PATCH 032/138] Updated switch model to be fbx --- examples/toybox/masterResetEntity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index be035d4252..8cc25dc3bf 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -65,7 +65,7 @@ function deleteAllToys() { } function createLightSwitch() { - var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.obj"; + var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.fbx"; var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js?v1"); var lightSwitch = Entities.addEntity({ type: "Model", From a266e8d65a47d994515520c9f8b58d95db7aab28 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 12:49:45 -0700 Subject: [PATCH 033/138] updated reset script to use new wand script --- examples/toybox/masterResetEntity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 8cc25dc3bf..4b0a2f986a 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -147,7 +147,7 @@ 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/collisionHull.obj'; //Just using abs path for demo purposes on sunday, since this PR for wand has not been merged - var scriptURL = "https://raw.githubusercontent.com/imgntn/hifi/ccf125c047426a2c481d3ee8c58a05fc6048fdde/examples/toys/bubblewand/wand.js" + var scriptURL = "https://raw.githubusercontent.com/imgntn/hifi/f8d743aff0700f81d7f2ace92b8718e1e5e64978/examples/toys/bubblewand/wand.js" var entity = Entities.addEntity({ name: 'Bubble Wand', From d273852bf9af6d063c30150b317d1fd8539d1ea7 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 12:56:01 -0700 Subject: [PATCH 034/138] New wand script --- examples/toybox/masterResetEntity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 4b0a2f986a..27b07968a9 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -147,7 +147,7 @@ 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/collisionHull.obj'; //Just using abs path for demo purposes on sunday, since this PR for wand has not been merged - var scriptURL = "https://raw.githubusercontent.com/imgntn/hifi/f8d743aff0700f81d7f2ace92b8718e1e5e64978/examples/toys/bubblewand/wand.js" + var scriptURL = "https://raw.githubusercontent.com/imgntn/hifi/bubblewand_hotfix_2/examples/toys/bubblewand/wand.js" var entity = Entities.addEntity({ name: 'Bubble Wand', From 6298dcb2fc9f3b4c374c7192608bdc67bb625c12 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 13:03:44 -0700 Subject: [PATCH 035/138] attempt fix for doll animation --- examples/toybox/entityScripts/doll.js | 2 +- examples/toybox/masterResetEntity.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js index 86e7fcc62c..ed4f7983ba 100644 --- a/examples/toybox/entityScripts/doll.js +++ b/examples/toybox/entityScripts/doll.js @@ -53,7 +53,7 @@ releaseGrab: function() { Entities.editEntity(this.entityID, { animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx", - // animationSettings: this.stopAnimationSetting + animationSettings: this.stopAnimationSetting }); }, diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 27b07968a9..f397616487 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -48,6 +48,8 @@ function createAllToys() { createDice(); + createFlashlight(); + //Handles toggling of all sconce lights createLightSwitch(); } From a0bf7b65297ee65dc2dc529180f5478ec999b554 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 13:20:17 -0700 Subject: [PATCH 036/138] doll animation fixes --- examples/toybox/entityScripts/doll.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js index ed4f7983ba..63a3d91ef6 100644 --- a/examples/toybox/entityScripts/doll.js +++ b/examples/toybox/entityScripts/doll.js @@ -29,7 +29,7 @@ }); this.stopAnimationSetting = JSON.stringify({ - running: false + running: false, }); }; @@ -37,6 +37,7 @@ startNearGrab: function() { + print("START GRAB") Entities.editEntity(this.entityID, { animationURL: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", animationSettings: this.startAnimationSetting @@ -53,7 +54,8 @@ releaseGrab: function() { Entities.editEntity(this.entityID, { animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx", - animationSettings: this.stopAnimationSetting + // animationSettings: this.stopAnimationSetting, + // animationFrameIndex: 0 }); }, From a28cf5ce8bdb5b0eb397e65090d03fa0e55b2d61 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 13:29:16 -0700 Subject: [PATCH 037/138] updated grab script --- examples/controllers/handControllerGrab.js | 2 +- examples/toybox/entityScripts/doll.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 40e3879220..af1c97da68 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -221,7 +221,7 @@ function controller(hand, triggerAction) { var minDistance = GRAB_RADIUS; var grabbedEntity = null; for (var i = 0; i < nearbyEntities.length; i++) { - var props = Entities.getEntityProperties(nearbyEntities[i]); + var props = Entities.getEntityProperties(nearbyEntities[i], ["position", "name", "collisionsWillMove", "locked"]); var distance = Vec3.distance(props.position, handPosition); if (distance < minDistance && props.name !== "pointer") { this.grabbedEntity = nearbyEntities[i]; diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js index 63a3d91ef6..a9c2d4e830 100644 --- a/examples/toybox/entityScripts/doll.js +++ b/examples/toybox/entityScripts/doll.js @@ -37,7 +37,6 @@ startNearGrab: function() { - print("START GRAB") Entities.editEntity(this.entityID, { animationURL: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", animationSettings: this.startAnimationSetting From 5546a04f4d83d4fda5fc2c6d2d5ac9bfc934470e Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 13:48:10 -0700 Subject: [PATCH 038/138] Added flashlight to master script --- examples/toybox/masterResetEntity.js | 55 ++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index f397616487..85df03e3b4 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -48,10 +48,18 @@ function createAllToys() { createDice(); - createFlashlight(); + createFlashlight({ + x: 546, + y: 495.65, + z: 506.1 + }); //Handles toggling of all sconce lights - createLightSwitch(); + createLightSwitch({ + x: 543.27764892578125, + y: 495.67999267578125, + z: 511.00564575195312 + }); } function deleteAllToys() { @@ -66,7 +74,42 @@ function deleteAllToys() { }) } -function createLightSwitch() { +function createFlashlight(position) { + var scriptURL = Script.resolvePath('../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: -.01, + z: 0 + }, + shapeType: 'box', + }); + + setEntityCustomData(resetKey, flashlight, { + resetMe: true + }); + +} + +function createLightSwitch(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.fbx"; var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js?v1"); var lightSwitch = Entities.addEntity({ @@ -74,11 +117,7 @@ function createLightSwitch() { modelURL: modelURL, name: "Light Switch Hall", script: scriptURL, - position: { - x: 543.27764892578125, - y: 495.67999267578125, - z: 511.00564575195312 - }, + position: position, rotation: { w: 0.63280689716339111, x: 0.63280689716339111, From 55f76a4296df0a17dd0a9f83384c561f885cb58b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 15:45:18 -0700 Subject: [PATCH 039/138] Added more sconce lights to lightSwitch.js --- examples/toybox/entityScripts/lightSwitch.js | 86 +++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) diff --git a/examples/toybox/entityScripts/lightSwitch.js b/examples/toybox/entityScripts/lightSwitch.js index 5bf2b5a04d..089e532400 100644 --- a/examples/toybox/entityScripts/lightSwitch.js +++ b/examples/toybox/entityScripts/lightSwitch.js @@ -37,7 +37,7 @@ this.toggleLights(); }, - startNearTouch: function(){ + startNearTouch: function() { this.toggleLights(); }, @@ -54,7 +54,7 @@ Audio.playSound(this.switchSound, { volume: 1, - position: this.position + position: this.position }); }, @@ -127,6 +127,88 @@ lightType: "Sconce Light" }); + var sconceLight3 = Entities.addEntity({ + type: "Light", + position: { + x: 545.49468994140625, + y: 496.24026489257812, + z: 500.63516235351562 + }, + + name: "Sconce 3 Light", + dimensions: { + x: 2.545, + y: 2.545, + z: 2.545 + }, + cutoff: 90, + color: { + red: 217, + green: 146, + blue: 24 + } + }); + + setEntityCustomData(this.resetKey, sconceLight3, { + resetMe: true, + lightType: "Sconce Light" + }); + + var sconceLight4 = Entities.addEntity({ + type: "Light", + position: { + x: 550.90399169921875, + y: 496.24026489257812, + z: 507.90237426757812 + }, + + name: "Sconce 4 Light", + dimensions: { + x: 2.545, + y: 2.545, + z: 2.545 + }, + cutoff: 90, + color: { + red: 217, + green: 146, + blue: 24 + } + }); + + setEntityCustomData(this.resetKey, sconceLight4, { + resetMe: true, + lightType: "Sconce Light" + }); + + var sconceLight5 = Entities.addEntity({ + type: "Light", + position: { + x: 548.407958984375, + y: 496.24026489257812, + z: 509.5504150390625 + }, + name: "Sconce 5 Light", + dimensions: { + x: 2.545, + y: 2.545, + z: 2.545 + }, + cutoff: 90, + color: { + red: 217, + green: 146, + blue: 24 + } + }); + + setEntityCustomData(this.resetKey, sconceLight5, { + resetMe: true, + lightType: "Sconce Light" + }); + + + setEntityCustomData(this.lightStateKey, this.entityID, { on: true }); From ad0c0d3b2bb8210571475dacd317e164008d8f4f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 15:50:06 -0700 Subject: [PATCH 040/138] no v1 to avoid caching --- examples/toybox/masterResetEntity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 85df03e3b4..06deafce98 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -111,7 +111,7 @@ function createFlashlight(position) { function createLightSwitch(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.fbx"; - var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js?v1"); + var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js"); var lightSwitch = Entities.addEntity({ type: "Model", modelURL: modelURL, From f2afd666156f7ac1ad6068a40521d2cd5433d907 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 15:50:46 -0700 Subject: [PATCH 041/138] v2? --- examples/toybox/masterResetEntity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 06deafce98..ed1d3727f1 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -111,7 +111,7 @@ function createFlashlight(position) { function createLightSwitch(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.fbx"; - var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js"); + var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js?v2"); var lightSwitch = Entities.addEntity({ type: "Model", modelURL: modelURL, From 99dc5a51273ec78c49c7c35e5a61c4d1f0b6f58c Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Sep 2015 15:55:35 -0700 Subject: [PATCH 042/138] updated doll's sound when picked up --- examples/toybox/entityScripts/doll.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/toybox/entityScripts/doll.js b/examples/toybox/entityScripts/doll.js index a9c2d4e830..673d143d02 100644 --- a/examples/toybox/entityScripts/doll.js +++ b/examples/toybox/entityScripts/doll.js @@ -21,7 +21,7 @@ Doll = function() { _this = this; var screamSoundDirectory = HIFI_PUBLIC_BUCKET + "eric/sounds/" - this.screamSounds = [SoundCache.getSound(screamSoundDirectory + "dollScream2.wav?=v2"), SoundCache.getSound(screamSoundDirectory + "dollScream1.wav?=v2")]; + this.screamSounds = [SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/KenDoll_1%2303.wav")]; this.startAnimationSetting = JSON.stringify({ running: true, startFrame: 0, @@ -45,7 +45,7 @@ var position = Entities.getEntityProperties(this.entityID, "position").position; Audio.playSound(this.screamSounds[randInt(0, this.screamSounds.length)], { position: position, - volume: 0.01 + volume: 0.1 }); }, From cf701095c4457096c8726bcfa8d228142c0c7c76 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 09:33:02 -0700 Subject: [PATCH 043/138] updated light switch sound volume to be 50% of what it was --- examples/toybox/entityScripts/lightSwitch.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toybox/entityScripts/lightSwitch.js b/examples/toybox/entityScripts/lightSwitch.js index 089e532400..20c11fe721 100644 --- a/examples/toybox/entityScripts/lightSwitch.js +++ b/examples/toybox/entityScripts/lightSwitch.js @@ -53,7 +53,7 @@ } Audio.playSound(this.switchSound, { - volume: 1, + volume: 0.5, position: this.position }); From 9d9de61afa8a215bbed70b32d0f416b3ffcaaeb8 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 09:36:30 -0700 Subject: [PATCH 044/138] updated die starting positions --- examples/toybox/masterResetEntity.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index ed1d3727f1..9355f01419 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -143,9 +143,9 @@ function createDice() { collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", name: "dice", position: { - x: 540.74, - y: 496, - z: 509.21 + x: 540.92, + y: 494.96, + z: 509.8 }, dimensions: { x: 0.09, @@ -168,9 +168,9 @@ function createDice() { var dice1 = Entities.addEntity(diceProps); diceProps.position = { - x: 540.99, - y: 496, - z: 509.08 + x: 541.03, + y: 494.96, + z: 509.25 }; var dice2 = Entities.addEntity(diceProps); From 573cdc5271396bf29ed3a84137142b07bd48056f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 10:07:59 -0700 Subject: [PATCH 045/138] Added another light switch- the garage light switch controls the three lights closest to it, and hallway light controls the two near hall --- .../{lightSwitch.js => lightSwitchGarage.js} | 66 +------- .../toybox/entityScripts/lightSwitchHall.js | 158 ++++++++++++++++++ examples/toybox/masterResetEntity.js | 51 ++++-- 3 files changed, 207 insertions(+), 68 deletions(-) rename examples/toybox/entityScripts/{lightSwitch.js => lightSwitchGarage.js} (76%) create mode 100644 examples/toybox/entityScripts/lightSwitchHall.js diff --git a/examples/toybox/entityScripts/lightSwitch.js b/examples/toybox/entityScripts/lightSwitchGarage.js similarity index 76% rename from examples/toybox/entityScripts/lightSwitch.js rename to examples/toybox/entityScripts/lightSwitchGarage.js index 20c11fe721..090e1260bf 100644 --- a/examples/toybox/entityScripts/lightSwitch.js +++ b/examples/toybox/entityScripts/lightSwitchGarage.js @@ -18,7 +18,7 @@ // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) - LightSwitch = function() { + LightSwitchGarage = function() { _this = this; this.lightStateKey = "lightStateKey"; @@ -28,7 +28,7 @@ }; - LightSwitch.prototype = { + LightSwitchGarage.prototype = { clickReleaseOnEntity: function(entityId, mouseEvent) { if (!mouseEvent.isLeftButton) { @@ -64,7 +64,7 @@ var self = this; entities.forEach(function(entity) { var resetData = getEntityCustomData(self.resetKey, entity, {}) - if (resetData.resetMe === true && resetData.lightType === "Sconce Light") { + if (resetData.resetMe === true && resetData.lightType === "Sconce Light Garage") { Entities.deleteEntity(entity); } }); @@ -75,57 +75,7 @@ }, createLights: function() { - var sconceLight1 = Entities.addEntity({ - type: "Light", - position: { - x: 543.62, - y: 496.24, - z: 511.23 - }, - name: "Sconce 1 Light", - dimensions: { - x: 2.545, - y: 2.545, - z: 2.545 - }, - cutoff: 90, - color: { - red: 217, - green: 146, - blue: 24 - } - }); - - setEntityCustomData(this.resetKey, sconceLight1, { - resetMe: true, - lightType: "Sconce Light" - }); - - var sconceLight2 = Entities.addEntity({ - type: "Light", - position: { - x: 539.87, - y: 496.24, - z: 505.77 - }, - name: "Sconce 2 Light", - dimensions: { - x: 2.545, - y: 2.545, - z: 2.545 - }, - cutoff: 90, - color: { - red: 217, - green: 146, - blue: 24 - } - }); - - setEntityCustomData(this.resetKey, sconceLight2, { - resetMe: true, - lightType: "Sconce Light" - }); + var sconceLight3 = Entities.addEntity({ type: "Light", @@ -151,7 +101,7 @@ setEntityCustomData(this.resetKey, sconceLight3, { resetMe: true, - lightType: "Sconce Light" + lightType: "Sconce Light Garage" }); var sconceLight4 = Entities.addEntity({ @@ -178,7 +128,7 @@ setEntityCustomData(this.resetKey, sconceLight4, { resetMe: true, - lightType: "Sconce Light" + lightType: "Sconce Light Garage" }); var sconceLight5 = Entities.addEntity({ @@ -204,7 +154,7 @@ setEntityCustomData(this.resetKey, sconceLight5, { resetMe: true, - lightType: "Sconce Light" + lightType: "Sconce Light Garage" }); @@ -236,5 +186,5 @@ }; // entity scripts always need to return a newly constructed object of our type - return new LightSwitch(); + return new LightSwitchGarage(); }) \ No newline at end of file diff --git a/examples/toybox/entityScripts/lightSwitchHall.js b/examples/toybox/entityScripts/lightSwitchHall.js new file mode 100644 index 0000000000..356dee928c --- /dev/null +++ b/examples/toybox/entityScripts/lightSwitchHall.js @@ -0,0 +1,158 @@ +// +// detectGrabExample.js +// examples/entityScripts +// +// Created by Eric Levin on 9/21/15. +// Copyright 2015 High Fidelity, Inc. +// +// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + + var _this; + + + // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember + // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) + LightSwitchHall = function() { + _this = this; + + this.lightStateKey = "lightStateKey"; + this.resetKey = "resetMe"; + + this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); + + }; + + LightSwitchHall.prototype = { + + clickReleaseOnEntity: function(entityId, mouseEvent) { + if (!mouseEvent.isLeftButton) { + return; + } + this.toggleLights(); + }, + + startNearTouch: function() { + this.toggleLights(); + }, + + toggleLights: function() { + var defaultLightData = { + on: false + }; + var lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData); + if (lightState.on === true) { + this.clearLights(); + } else if (lightState.on === false) { + this.createLights(); + } + + Audio.playSound(this.switchSound, { + volume: 0.5, + position: this.position + }); + + }, + + clearLights: function() { + var entities = Entities.findEntities(MyAvatar.position, 100); + var self = this; + entities.forEach(function(entity) { + var resetData = getEntityCustomData(self.resetKey, entity, {}) + if (resetData.resetMe === true && resetData.lightType === "Sconce Light Hall") { + Entities.deleteEntity(entity); + } + }); + + setEntityCustomData(this.lightStateKey, this.entityID, { + on: false + }); + }, + + createLights: function() { + var sconceLight1 = Entities.addEntity({ + type: "Light", + position: { + x: 543.75, + y: 496.24, + z: 511.13 + }, + name: "Sconce 1 Light", + dimensions: { + x: 2.545, + y: 2.545, + z: 2.545 + }, + cutoff: 90, + color: { + red: 217, + green: 146, + blue: 24 + } + }); + + setEntityCustomData(this.resetKey, sconceLight1, { + resetMe: true, + lightType: "Sconce Light Hall" + }); + + var sconceLight2 = Entities.addEntity({ + type: "Light", + position: { + x: 540.1 , + y: 496.24, + z: 505.57 + }, + name: "Sconce 2 Light", + dimensions: { + x: 2.545, + y: 2.545, + z: 2.545 + }, + cutoff: 90, + color: { + red: 217, + green: 146, + blue: 24 + } + }); + + setEntityCustomData(this.resetKey, sconceLight2, { + resetMe: true, + lightType: "Sconce Light Hall" + }); + + setEntityCustomData(this.lightStateKey, this.entityID, { + on: true + }); + + }, + + // preload() will be called when the entity has become visible (or known) to the interface + // it gives us a chance to set our local JavaScript object up. In this case it means: + preload: function(entityID) { + this.entityID = entityID; + + //The light switch is static, so just cache its position once + this.position = Entities.getEntityProperties(this.entityID, "position").position; + var defaultLightData = { + on: false + }; + var lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData); + + //If light is off, then we create two new lights- at the position of the sconces + if (lightState.on === false) { + this.createLights(); + } + //If lights are on, do nothing! + }, + }; + + // entity scripts always need to return a newly constructed object of our type + return new LightSwitchHall(); +}) \ No newline at end of file diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 9355f01419..14758fbc73 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -55,11 +55,7 @@ function createAllToys() { }); //Handles toggling of all sconce lights - createLightSwitch({ - x: 543.27764892578125, - y: 495.67999267578125, - z: 511.00564575195312 - }); + createLightSwitches(); } function deleteAllToys() { @@ -109,15 +105,20 @@ function createFlashlight(position) { } -function createLightSwitch(position) { +function createLightSwitches() { var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.fbx"; - var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js?v2"); - var lightSwitch = Entities.addEntity({ + var scriptURL = Script.resolvePath("entityScripts/lightSwitchHall.js?v1"); + + var lightSwitchHall = Entities.addEntity({ type: "Model", modelURL: modelURL, name: "Light Switch Hall", script: scriptURL, - position: position, + position: { + x: 543.27764892578125, + y: 495.67999267578125, + z: 511.00564575195312 + }, rotation: { w: 0.63280689716339111, x: 0.63280689716339111, @@ -131,9 +132,39 @@ function createLightSwitch(position) { } }); - setEntityCustomData(resetKey, lightSwitch, { + setEntityCustomData(resetKey, lightSwitchHall, { resetMe: true }); + + scriptURL = Script.resolvePath("entityScripts/lightSwitchGarage.js?v1"); + + var lightSwitchGarage = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + name: "Light Switch Garage", + script: scriptURL, + position: { + x: 545.62, + y: 495.68, + z: 500.21 + }, + rotation: { + w: 0.20082402229309082, + x: 0.20082402229309082, + y: -0.67800414562225342, + z: 0.67797362804412842 + }, + dimensions: { + x: 0.10546875, + y: 0.032372996211051941, + z: 0.16242524981498718 + } + }); + + setEntityCustomData(resetKey, lightSwitchGarage, { + resetMe: true + }); + } function createDice() { From 8feabdb51805b6eed3f2108e670954a793c457e1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 10:54:56 -0700 Subject: [PATCH 046/138] adding cat, modified dice positions --- examples/toybox/masterResetEntity.js | 47 +++++++++++++++++++++------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 14758fbc73..b3ef69b294 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -54,6 +54,12 @@ function createAllToys() { z: 506.1 }); + createCat({ + x: 551.107421875, + y: 494.60513305664062, + z: 503.1910400390625 + }) + //Handles toggling of all sconce lights createLightSwitches(); } @@ -70,6 +76,32 @@ function deleteAllToys() { }) } +function createCat(position) { + var scriptURL = Script.resolvePath("entityScripts/cat.js"); + var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx"; + var animationURL = "http://hifi-public.s3.amazonaws.com/ryan/sleeping.fbx"; + Entities.addEntity({ + type: "Model", + modelURL: modelURL, + name: "cat", + script: scriptURL, + animationURL: animationURL, + animationIsPlaying: 1, + position: position, + rotation: { + w: 0.9510490894317627, + x: -1.52587890625e-05, + y: 0.30901050567626953, + z: -1.52587890625e-05 + }, + dimensions: { + x: 0.15723302960395813, + y: 0.50762706995010376, + z: 0.90716040134429932 + }, + }) +} + function createFlashlight(position) { var scriptURL = Script.resolvePath('../toys/flashlight/flashlight.js'); var modelURL = "https://hifi-public.s3.amazonaws.com/models/props/flashlight.fbx"; @@ -174,9 +206,9 @@ function createDice() { collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", name: "dice", position: { - x: 540.92, + x: 541, y: 494.96, - z: 509.8 + z: 509.1 }, dimensions: { x: 0.09, @@ -199,9 +231,9 @@ function createDice() { var dice1 = Entities.addEntity(diceProps); diceProps.position = { - x: 541.03, + x: 541.05, y: 494.96, - z: 509.25 + z: 509.0 }; var dice2 = Entities.addEntity(diceProps); @@ -289,11 +321,6 @@ function createBasketBall(position) { function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; - var animationURL = "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx"; - var animationSettings = JSON.stringify({ - running: false - }); - var scriptURL = Script.resolvePath("entityScripts/doll.js"); var naturalDimensions = { @@ -306,8 +333,6 @@ function createDoll(position) { type: "Model", name: "doll", modelURL: modelURL, - animationSettings: animationSettings, - animationURL: animationURL, script: scriptURL, position: position, shapeType: 'box', From a7facc9f3c428d08f13a7d7beefc21e6709d4bc8 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 11:10:27 -0700 Subject: [PATCH 047/138] Adding a mew sound to cat when user moves hand close --- examples/toybox/entityScripts/cat.js | 58 ++++++++++++++++++++++++++++ examples/toybox/masterResetEntity.js | 15 +++++-- 2 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 examples/toybox/entityScripts/cat.js diff --git a/examples/toybox/entityScripts/cat.js b/examples/toybox/entityScripts/cat.js new file mode 100644 index 0000000000..573b8997d1 --- /dev/null +++ b/examples/toybox/entityScripts/cat.js @@ -0,0 +1,58 @@ +// +// doll.js +// examples/toybox/entityScripts +// +// Created by Eric Levin on 9/21/15. +// Copyright 2015 High Fidelity, Inc. +// +// This entity script breathes movement and sound- one might even say life- into a doll. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + + var _this; + + // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember + // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) + Cat = function() { + _this = this; + this.meowSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Animals/cat_meow.wav"); + + }; + + Cat.prototype = { + + clickReleaseOnEntity: function(entityId, mouseEvent) { + if (!mouseEvent.isLeftButton) { + return; + } + this.meow(); + }, + + startNearTouch: function() { + this.meow(); + }, + + meow: function() { + print("PLAYYY") + Audio.playSound(this.meowSound, { + position: this.position, + volume: .1 + }); + }, + // preload() will be called when the entity has become visible (or known) to the interface + // it gives us a chance to set our local JavaScript object up. In this case it means: + // * remembering our entityID, so we can access it in cases where we're called without an entityID + // * connecting to the update signal so we can check our grabbed state + preload: function(entityID) { + this.entityID = entityID; + this.position = Entities.getEntityProperties(this.entityID, "position").position; + } + }; + + // entity scripts always need to return a newly constructed object of our type + return new Cat(); +}); diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index b3ef69b294..9ca17eae6b 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -77,16 +77,19 @@ function deleteAllToys() { } function createCat(position) { - var scriptURL = Script.resolvePath("entityScripts/cat.js"); + var scriptURL = Script.resolvePath("entityScripts/cat.js?v1"); var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx"; var animationURL = "http://hifi-public.s3.amazonaws.com/ryan/sleeping.fbx"; - Entities.addEntity({ + var animationSettings = JSON.stringify({ + running: true, + }); + var cat = Entities.addEntity({ type: "Model", modelURL: modelURL, name: "cat", script: scriptURL, animationURL: animationURL, - animationIsPlaying: 1, + animationSettings: animationSettings, position: position, rotation: { w: 0.9510490894317627, @@ -99,7 +102,11 @@ function createCat(position) { y: 0.50762706995010376, z: 0.90716040134429932 }, - }) + }); + + setEntityCustomData(resetKey, cat, { + resetMe: true + }); } function createFlashlight(position) { From cc69f518823c7fa3e649271a90c2bac44f824c9e Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 11:30:14 -0700 Subject: [PATCH 048/138] Cat meows when hand is close --- examples/toybox/entityScripts/cat.js | 32 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/examples/toybox/entityScripts/cat.js b/examples/toybox/entityScripts/cat.js index 573b8997d1..3aae7c6391 100644 --- a/examples/toybox/entityScripts/cat.js +++ b/examples/toybox/entityScripts/cat.js @@ -20,25 +20,28 @@ Cat = function() { _this = this; this.meowSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Animals/cat_meow.wav"); - + this.distanceThreshold = 0.5; + this.canMeow = true; + this.meowBreakTime = 3000; }; Cat.prototype = { - clickReleaseOnEntity: function(entityId, mouseEvent) { - if (!mouseEvent.isLeftButton) { - return; + update: function() { + var leftHandPosition = MyAvatar.getLeftPalmPosition(); + var rightHandPosition = MyAvatar.getRightPalmPosition(); + if (Vec3.distance(leftHandPosition, _this.position) < _this.distanceThreshold || Vec3.distance(rightHandPosition, _this.position) < _this.distanceThreshold && _this.canMeow) { + _this.meow(); + _this.canMeow = false; + Script.setTimeout(function() { + _this.canMeow = true + }, _this.meowBreakTime) } - this.meow(); - }, - - startNearTouch: function() { - this.meow(); }, meow: function() { - print("PLAYYY") - Audio.playSound(this.meowSound, { + + Audio.playSound(this.meowSound, { position: this.position, volume: .1 }); @@ -50,9 +53,14 @@ preload: function(entityID) { this.entityID = entityID; this.position = Entities.getEntityProperties(this.entityID, "position").position; + Script.update.connect(this.update); + }, + + unload: function() { + Script.update.disconnect(this.update); } }; // entity scripts always need to return a newly constructed object of our type return new Cat(); -}); +}); \ No newline at end of file From 9818e2549c36e01e35a1c08ada6d32a99490d7f3 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 11:38:30 -0700 Subject: [PATCH 049/138] handControllerscript is now on par with master --- examples/controllers/handControllerGrab.js | 38 ++++------------------ 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index af1c97da68..251d78e273 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -84,9 +84,7 @@ var STATE_DISTANCE_HOLDING = 1; var STATE_CONTINUE_DISTANCE_HOLDING = 2; var STATE_NEAR_GRABBING = 3; var STATE_CONTINUE_NEAR_GRABBING = 4; -var STATE_NEAR_TOUCHING = 5; -var STATE_CONTINUE_NEAR_TOUCHING = 6; -var STATE_RELEASE = 7; +var STATE_RELEASE = 5; var GRAB_USER_DATA_KEY = "grabKey"; @@ -127,12 +125,6 @@ function controller(hand, triggerAction) { case STATE_CONTINUE_NEAR_GRABBING: this.continueNearGrabbing(); break; - case STATE_NEAR_TOUCHING: - this.nearTouching(); - break; - case STATE_CONTINUE_NEAR_TOUCHING: - this.continueNearTouching(); - break; case STATE_RELEASE: this.release(); break; @@ -221,20 +213,19 @@ function controller(hand, triggerAction) { var minDistance = GRAB_RADIUS; var grabbedEntity = null; for (var i = 0; i < nearbyEntities.length; i++) { - var props = Entities.getEntityProperties(nearbyEntities[i], ["position", "name", "collisionsWillMove", "locked"]); + var props = Entities.getEntityProperties(nearbyEntities[i]); var distance = Vec3.distance(props.position, handPosition); - if (distance < minDistance && props.name !== "pointer") { + if (distance < minDistance && props.name !== "pointer" && + props.collisionsWillMove === 1 && + props.locked === 0) { this.grabbedEntity = nearbyEntities[i]; minDistance = distance; } } if (this.grabbedEntity === null) { this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); - } else if (props.locked === 0 && props.collisionsWillMove === 1) { + } else { this.state = STATE_NEAR_GRABBING; - } else if (props.collisionsWillMove === 0) { - // We have grabbed a non-physical object, so we want to trigger a touch event as opposed to a grab event - this.state = STATE_NEAR_TOUCHING; } } } @@ -369,23 +360,6 @@ function controller(hand, triggerAction) { this.currentObjectTime = Date.now(); } - this.nearTouching = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - Entities.callEntityMethod(this.grabbedEntity, "startNearTouch") - this.state = STATE_CONTINUE_NEAR_TOUCHING; - } - - this.continueNearTouching = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - Entities.callEntityMethod(this.grabbedEntity, "continueNearTouch"); - } - this.continueNearGrabbing = function() { if (!this.triggerSmoothedSqueezed()) { From c7cb77a6abf48f28256aa4b50bd5a7e2e88beb77 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 12:08:28 -0700 Subject: [PATCH 050/138] moved spraycan into toybox folder, and added spraypaint sound --- examples/{ => toybox}/entityScripts/sprayPaintCan.js | 8 ++++++++ examples/toybox/masterResetEntity.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) rename examples/{ => toybox}/entityScripts/sprayPaintCan.js (96%) diff --git a/examples/entityScripts/sprayPaintCan.js b/examples/toybox/entityScripts/sprayPaintCan.js similarity index 96% rename from examples/entityScripts/sprayPaintCan.js rename to examples/toybox/entityScripts/sprayPaintCan.js index 29ff451b76..a9538f13c0 100644 --- a/examples/entityScripts/sprayPaintCan.js +++ b/examples/toybox/entityScripts/sprayPaintCan.js @@ -6,6 +6,8 @@ GRAB_FRAME_USER_DATA_KEY = "grabFrame"; this.userData = {}; + this.spraySound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/sprayPaintSound.wav"); + var TIP_OFFSET_Z = 0.14; var TIP_OFFSET_Y = 0.04; @@ -101,12 +103,18 @@ }, lifetime: 50, //probably wont be holding longer than this straight }); + + this.sprayInjector = Audio.playSound(this.spraySound, { + position: this.properties.position, + volume: 0.1 + }); } this.letGo = function() { this.activated = false; Entities.deleteEntity(this.paintStream); this.paintStream = null; + this.sprayInjector.stop(); } this.reset = function() { diff --git a/examples/toybox/masterResetEntity.js b/examples/toybox/masterResetEntity.js index 9ca17eae6b..836cbb9d9c 100644 --- a/examples/toybox/masterResetEntity.js +++ b/examples/toybox/masterResetEntity.js @@ -363,7 +363,7 @@ function createDoll(position) { } function createSprayCan(position) { - var scriptURL = Script.resolvePath("../entityScripts/sprayPaintCan.js"); + var scriptURL = Script.resolvePath("entityScripts/sprayPaintCan.js"); var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; var entity = Entities.addEntity({ From 6bd89f968905e347ff13903d41d1148616a17a0f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 12:22:18 -0700 Subject: [PATCH 051/138] Toys re-org --- examples/{toybox/entityScripts => toys}/cat.js | 0 examples/{toybox/entityScripts => toys}/doll.js | 0 examples/{toybox/entityScripts => toys}/lightSwitchGarage.js | 0 examples/{toybox/entityScripts => toys}/lightSwitchHall.js | 0 examples/{toybox => toys}/masterResetEntity.js | 0 examples/{toybox/entityScripts => toys}/sprayPaintCan.js | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename examples/{toybox/entityScripts => toys}/cat.js (100%) rename examples/{toybox/entityScripts => toys}/doll.js (100%) rename examples/{toybox/entityScripts => toys}/lightSwitchGarage.js (100%) rename examples/{toybox/entityScripts => toys}/lightSwitchHall.js (100%) rename examples/{toybox => toys}/masterResetEntity.js (100%) rename examples/{toybox/entityScripts => toys}/sprayPaintCan.js (100%) diff --git a/examples/toybox/entityScripts/cat.js b/examples/toys/cat.js similarity index 100% rename from examples/toybox/entityScripts/cat.js rename to examples/toys/cat.js diff --git a/examples/toybox/entityScripts/doll.js b/examples/toys/doll.js similarity index 100% rename from examples/toybox/entityScripts/doll.js rename to examples/toys/doll.js diff --git a/examples/toybox/entityScripts/lightSwitchGarage.js b/examples/toys/lightSwitchGarage.js similarity index 100% rename from examples/toybox/entityScripts/lightSwitchGarage.js rename to examples/toys/lightSwitchGarage.js diff --git a/examples/toybox/entityScripts/lightSwitchHall.js b/examples/toys/lightSwitchHall.js similarity index 100% rename from examples/toybox/entityScripts/lightSwitchHall.js rename to examples/toys/lightSwitchHall.js diff --git a/examples/toybox/masterResetEntity.js b/examples/toys/masterResetEntity.js similarity index 100% rename from examples/toybox/masterResetEntity.js rename to examples/toys/masterResetEntity.js diff --git a/examples/toybox/entityScripts/sprayPaintCan.js b/examples/toys/sprayPaintCan.js similarity index 100% rename from examples/toybox/entityScripts/sprayPaintCan.js rename to examples/toys/sprayPaintCan.js From b0923acc2ff5d14f5c4ee9ca827f1d40b97cfa66 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 12:34:10 -0700 Subject: [PATCH 052/138] Reorg for pathing --- examples/toys/masterResetEntity.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 836cbb9d9c..b8997afe58 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -77,7 +77,7 @@ function deleteAllToys() { } function createCat(position) { - var scriptURL = Script.resolvePath("entityScripts/cat.js?v1"); + var scriptURL = Script.resolvePath("cat.js?v1"); 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({ @@ -110,7 +110,7 @@ function createCat(position) { } function createFlashlight(position) { - var scriptURL = Script.resolvePath('../toys/flashlight/flashlight.js'); + var scriptURL = Script.resolvePath('flashlight/flashlight.js'); var modelURL = "https://hifi-public.s3.amazonaws.com/models/props/flashlight.fbx"; var flashlight = Entities.addEntity({ @@ -146,7 +146,7 @@ function createFlashlight(position) { function createLightSwitches() { var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.fbx"; - var scriptURL = Script.resolvePath("entityScripts/lightSwitchHall.js?v1"); + var scriptURL = Script.resolvePath("lightSwitchHall.js?v1"); var lightSwitchHall = Entities.addEntity({ type: "Model", @@ -175,7 +175,7 @@ function createLightSwitches() { resetMe: true }); - scriptURL = Script.resolvePath("entityScripts/lightSwitchGarage.js?v1"); + scriptURL = Script.resolvePath("lightSwitchGarage.js?v1"); var lightSwitchGarage = Entities.addEntity({ type: "Model", @@ -258,7 +258,7 @@ 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/collisionHull.obj'; //Just using abs path for demo purposes on sunday, since this PR for wand has not been merged - var scriptURL = "https://raw.githubusercontent.com/imgntn/hifi/bubblewand_hotfix_2/examples/toys/bubblewand/wand.js" + var scriptURL = Script.resolvePath("bubblewand/wand.js"); var entity = Entities.addEntity({ name: 'Bubble Wand', @@ -328,7 +328,7 @@ function createBasketBall(position) { function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; - var scriptURL = Script.resolvePath("entityScripts/doll.js"); + var scriptURL = Script.resolvePath("doll.js"); var naturalDimensions = { x: 1.63, @@ -363,7 +363,7 @@ function createDoll(position) { } function createSprayCan(position) { - var scriptURL = Script.resolvePath("entityScripts/sprayPaintCan.js"); + var scriptURL = Script.resolvePath("sprayPaintCan.js"); var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; var entity = Entities.addEntity({ From 2c20a12f1300045eb17037d50626dd80cef7ad66 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 13:34:21 -0700 Subject: [PATCH 053/138] refactoring spraypaint to use new events --- examples/toys/sprayPaintCan.js | 107 ++++----------------------------- 1 file changed, 13 insertions(+), 94 deletions(-) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index a9538f13c0..75a2cc10f5 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -21,59 +21,8 @@ var MIN_POINT_DISTANCE = 0.01; var STROKE_WIDTH = 0.02; - var self = this; - - var timeSinceLastMoved = 0; - var RESET_TIME_THRESHOLD = 5; - var DISTANCE_FROM_HOME_THRESHOLD = 0.5; - var HOME_POSITION = { - x: 549.12, - y: 495.555, - z: 503.77 - }; - this.getUserData = function() { - - - if (this.properties.userData) { - this.userData = JSON.parse(this.properties.userData); - } - } - - this.updateUserData = function() { - Entities.editEntity(this.entityId, { - userData: JSON.stringify(this.userData) - }); - } - - this.update = function(deltaTime) { - self.getUserData(); - self.properties = Entities.getEntityProperties(self.entityId); - - if (Vec3.length(self.properties.velocity) < 0.1 && Vec3.distance(HOME_POSITION, self.properties.position) > DISTANCE_FROM_HOME_THRESHOLD) { - timeSinceLastMoved += deltaTime; - if (timeSinceLastMoved > RESET_TIME_THRESHOLD) { - self.reset(); - timeSinceLastMoved = 0; - } - } else { - timeSinceLastMoved = 0; - } - - //Only activate for the user who grabbed the object - if (self.userData.grabKey && self.userData.grabKey.activated === true && self.userData.grabKey.avatarId == MyAvatar.sessionUUID) { - if (self.activated !== true) { - //We were just grabbed, so create a particle system - self.grab(); - } - //Move emitter to where entity is always when its activated - self.sprayStream(); - } else if (self.userData.grabKey && self.userData.grabKey.activated === false && self.activated) { - self.letGo(); - } - } - - this.grab = function() { - this.activated = true; + this.startNearGrab = function() { + var position = Entities.getEntityProperties(this.entityId, "position").position; var animationSettings = JSON.stringify({ fps: 30, loop: true, @@ -85,7 +34,7 @@ this.paintStream = Entities.addEntity({ type: "ParticleEffect", animationSettings: animationSettings, - position: this.properties.position, + position: position, textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", emitVelocity: ZERO_VEC, emitAcceleration: ZERO_VEC, @@ -110,30 +59,24 @@ }); } - this.letGo = function() { - this.activated = false; + + this.releaseGrab = function() { Entities.deleteEntity(this.paintStream); this.paintStream = null; + this.painting = false; this.sprayInjector.stop(); } - this.reset = function() { - Entities.editEntity(self.entityId, { - position: HOME_POSITION, - rotation: Quat.fromPitchYawRollDegrees(0, 0, 0), - angularVelocity: ZERO_VEC, - velocity: ZERO_VEC - }); - } - this.sprayStream = function() { - var forwardVec = Quat.getFront(Quat.multiply(self.properties.rotation , Quat.fromPitchYawRollDegrees(0, 90, 0))); + this.continueNearGrab = function() { + var props = Entities.getEntityProperties(this.entityId, ["position, rotation"]); + var forwardVec = Quat.getFront(Quat.multiply(props.rotation, Quat.fromPitchYawRollDegrees(0, 90, 0))); forwardVec = Vec3.normalize(forwardVec); - var upVec = Quat.getUp(self.properties.rotation); - var position = Vec3.sum(self.properties.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z)); + var upVec = Quat.getUp(props.rotation); + var position = Vec3.sum(props.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z)); position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y)) - Entities.editEntity(self.paintStream, { + Entities.editEntity(this.paintStream, { position: position, emitVelocity: Vec3.multiply(5, forwardVec) }); @@ -151,8 +94,6 @@ var normal = Vec3.multiply(-1, Quat.getFront(intersection.properties.rotation)); this.paint(intersection.intersection, normal); } - - } this.paint = function(position, normal) { @@ -214,40 +155,18 @@ this.preload = function(entityId) { this.strokes = []; - this.activated = false; this.entityId = entityId; - this.properties = Entities.getEntityProperties(self.entityId); - this.getUserData(); - - //Only activate for the avatar who is grabbing the can! - if (this.userData.grabKey && this.userData.grabKey.activated) { - this.activated = true; - } - if (!this.userData.grabFrame) { - var data = { - relativePosition: { - x: 0, - y: 0, - z: 0 - }, - relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0) - } - setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, this.entityId, data); - } } this.unload = function() { - Script.update.disconnect(this.update); - if(this.paintStream) { + if (this.paintStream) { Entities.deleteEntity(this.paintStream); } this.strokes.forEach(function(stroke) { Entities.deleteEntity(stroke); }); } - - Script.update.connect(this.update); }); From a2b0e66e13da7f6395ce3361715346d3c3aab3d6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 13:36:00 -0700 Subject: [PATCH 054/138] Sound working for spraypaint --- examples/toys/sprayPaintCan.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 75a2cc10f5..40a702762a 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -54,7 +54,7 @@ }); this.sprayInjector = Audio.playSound(this.spraySound, { - position: this.properties.position, + position: position, volume: 0.1 }); } From 276b0b71cbfc536cfc3022f10fdbb8316f3c557a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 14:52:59 -0700 Subject: [PATCH 055/138] Added tin can to master script and changed its position --- examples/toys/doll.js | 8 ---- examples/toys/masterResetEntity.js | 70 +++++++++++++++++++++++------- examples/toys/sprayPaintCan.js | 10 ++++- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/examples/toys/doll.js b/examples/toys/doll.js index 673d143d02..708d6200b1 100644 --- a/examples/toys/doll.js +++ b/examples/toys/doll.js @@ -71,11 +71,3 @@ // entity scripts always need to return a newly constructed object of our type return new Doll(); }) - -function randFloat(low, high) { - return low + Math.random() * (high - low); -} - -function randInt(low, high) { - return Math.floor(randFloat(low, high)); -} \ No newline at end of file diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index b8997afe58..fda7d90908 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -23,42 +23,48 @@ function createAllToys() { }); createSprayCan({ - x: 549.12, - y: 495.55, - z: 503.77 + x: 549.8, + y: 495.6, + z: 503.94 }); createBasketBall({ - x: 548.1, - y: 497, - z: 504.6 + x: 547.73, + y: 495.5, + z: 505.47 }); createDoll({ - x: 545.9, - y: 496, - z: 506.2 + x: 546.67, + y: 495.41, + z: 505.09 }); createWand({ - x: 546.45, - y: 495.63, - z: 506.18 + x: 546.71, + y: 495.55, + z: 506.15 }); createDice(); createFlashlight({ - x: 546, - y: 495.65, - z: 506.1 + x: 545.72, + y: 495.41, + z: 505.78 }); createCat({ x: 551.107421875, y: 494.60513305664062, z: 503.1910400390625 - }) + }); + + createMagballs({ + x: 548.73, + y: 495.51, + z: 503.54 + }); //Handles toggling of all sconce lights createLightSwitches(); @@ -76,6 +82,38 @@ function deleteAllToys() { }) } +function createMagballs(position) { + + + var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/tin2.fbx"; + var tinCan = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + name: "Tin Can", + position: position, + rotation: { + w: 0.93041884899139404, + x: -1.52587890625e-05, + y: 0.36647593975067139, + z: -1.52587890625e-05 + }, + dimensions: { + x: 0.16946873068809509, + y: 0.21260403096675873, + z: 0.16946862637996674 + }, + }); + + + setEntityCustomData(resetKey, tinCan, { + resetMe: true + }); + + setEntityCustomData("OmniTool", tinCan, { + script: "../toys/magBalls.js" + }); +} + function createCat(position) { var scriptURL = Script.resolvePath("cat.js?v1"); var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/Dark_Cat.fbx"; diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 40a702762a..e31f7f43c6 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -3,7 +3,6 @@ //Need absolute path for now, for testing before PR merge and s3 cloning. Will change post-merge Script.include("../libraries/utils.js"); - GRAB_FRAME_USER_DATA_KEY = "grabFrame"; this.userData = {}; this.spraySound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/sprayPaintSound.wav"); @@ -21,7 +20,16 @@ var MIN_POINT_DISTANCE = 0.01; var STROKE_WIDTH = 0.02; + this.setRightHand = function() { + this.hand = 'RIGHT'; + } + + this.setLeftHand = function() { + this.hand = 'LEFT'; + } + this.startNearGrab = function() { + this.whichHand = this.hand; var position = Entities.getEntityProperties(this.entityId, "position").position; var animationSettings = JSON.stringify({ fps: 30, From a1dccc2a9236781b49a7b145bff263280b08211d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 16:13:31 -0700 Subject: [PATCH 056/138] Changed cat position --- examples/toys/cat.js | 2 +- examples/toys/masterResetEntity.js | 38 ++++++++++++++++++------------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index 3aae7c6391..1f1e7cc9d4 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -20,7 +20,7 @@ Cat = function() { _this = this; this.meowSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Animals/cat_meow.wav"); - this.distanceThreshold = 0.5; + this.distanceThreshold = 1; this.canMeow = true; this.meowBreakTime = 3000; }; diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index fda7d90908..9f8bd036c8 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -1,20 +1,28 @@ +// +// 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 deleteAllToys, print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ +//per script +/*global createAllToys, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLightSwitches */ var utilitiesScript = Script.resolvePath("../libraries/utils.js"); Script.include(utilitiesScript); var resetKey = "resetMe"; -HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; +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, @@ -55,9 +63,9 @@ function createAllToys() { }); createCat({ - x: 551.107421875, - y: 494.60513305664062, - z: 503.1910400390625 + x: 551.49859619140625, + y: 495.49111938476562, + z: 502.26498413085938 }); createMagballs({ @@ -73,13 +81,13 @@ function createAllToys() { 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 createMagballs(position) { @@ -130,9 +138,9 @@ function createCat(position) { animationSettings: animationSettings, position: position, rotation: { - w: 0.9510490894317627, - x: -1.52587890625e-05, - y: 0.30901050567626953, + w: 0.35020983219146729, + x: -4.57763671875e-05, + y: 0.93664455413818359, z: -1.52587890625e-05 }, dimensions: { @@ -170,7 +178,7 @@ function createFlashlight(position) { }, velocity: { x: 0, - y: -.01, + y: -0.01, z: 0 }, shapeType: 'box', @@ -267,12 +275,12 @@ function createDice() { }, velocity: { x: 0, - y: -.01, + y: -0.01, z: 0 }, shapeType: "box", collisionsWillMove: true - } + }; var dice1 = Entities.addEntity(diceProps); diceProps.position = { From d0b5d62bb76cf6bb06c5e5de4173fe5ae460fa8a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 16:21:36 -0700 Subject: [PATCH 057/138] Updated master script to make jslint happy --- examples/toys/masterResetEntity.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 9f8bd036c8..c38e8c0a26 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -360,7 +360,7 @@ function createBasketBall(position) { linearDamping: 0.0, velocity: { x: 0, - y: -.01, + y: -0.01, z: 0 }, collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/basketball/basketball.wav" @@ -397,7 +397,7 @@ function createDoll(position) { }, velocity: { x: 0, - y: -.1, + y: -0.1, z: 0 }, collisionsWillMove: true @@ -450,8 +450,10 @@ function createSprayCan(position) { } function createBlocks(position) { - var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/" - var modelURLs = ['planky_blue.fbx', 'planky_green.fbx', 'planky_natural.fbx', "planky_red.fbx", "planky_yellow.fbx"]; + var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/"; + var NUM_BLOCKS_PER_COLOR = 4; + var i, j; + var blockTypes = [{ url: "planky_blue.fbx", dimensions: { @@ -487,16 +489,13 @@ function createBlocks(position) { y: 0.05, z: 0.25 } - }, + }]; - - ]; - var NUM_BLOCKS_PER_COLOR = 4; - - for (var i = 0; i < blockTypes.length; i++) { + var modelURL, entity; + for (i = 0; i < blockTypes.length; i++) { for (j = 0; j < NUM_BLOCKS_PER_COLOR; j++) { - var modelURL = baseURL + blockTypes[i].url; - var entity = Entities.addEntity({ + modelURL = baseURL + blockTypes[i].url; + entity = Entities.addEntity({ type: "Model", modelURL: modelURL, position: Vec3.sum(position, { @@ -515,7 +514,7 @@ function createBlocks(position) { }, velocity: { x: 0, - y: -.01, + y: -0.01, z: 0 } }); From 153a30de0dfa42f2b237a81484af35c3a50df1fd Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 17:24:56 -0700 Subject: [PATCH 058/138] flip --- examples/toys/lightSwitchGarage.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/examples/toys/lightSwitchGarage.js b/examples/toys/lightSwitchGarage.js index 090e1260bf..97cd0a6ac3 100644 --- a/examples/toys/lightSwitchGarage.js +++ b/examples/toys/lightSwitchGarage.js @@ -30,7 +30,7 @@ LightSwitchGarage.prototype = { - clickReleaseOnEntity: function(entityId, mouseEvent) { + clickReleaseOnEntity: function(entityID, mouseEvent) { if (!mouseEvent.isLeftButton) { return; } @@ -52,6 +52,18 @@ this.createLights(); } + // flip model to give illusion of light switch being flicked + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = Quat.axis(rotation); + var angle = Quat.angle(rotation); + + angle += 180; + rotation = Quat.angleAxis(angle, axis); + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + Audio.playSound(this.switchSound, { volume: 0.5, position: this.position From 81c175eabf524f44011aa56ba1f4599ef23a113d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 23 Sep 2015 17:34:37 -0700 Subject: [PATCH 059/138] toggle light switch --- examples/toys/lightSwitchGarage.js | 7 +++---- examples/toys/lightSwitchHall.js | 17 ++++++++++++++++- examples/toys/masterResetEntity.js | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/examples/toys/lightSwitchGarage.js b/examples/toys/lightSwitchGarage.js index 97cd0a6ac3..a68a09cf7d 100644 --- a/examples/toys/lightSwitchGarage.js +++ b/examples/toys/lightSwitchGarage.js @@ -54,11 +54,10 @@ // flip model to give illusion of light switch being flicked var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; - var axis = Quat.axis(rotation); - var angle = Quat.angle(rotation); + var axis = {x: 0, y: 1, z: 0}; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); - angle += 180; - rotation = Quat.angleAxis(angle, axis); Entities.editEntity(this.entityID, { rotation: rotation diff --git a/examples/toys/lightSwitchHall.js b/examples/toys/lightSwitchHall.js index 356dee928c..6bc1eeab83 100644 --- a/examples/toys/lightSwitchHall.js +++ b/examples/toys/lightSwitchHall.js @@ -52,6 +52,21 @@ this.createLights(); } + // flip model to give illusion of light switch being flicked + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + Audio.playSound(this.switchSound, { volume: 0.5, position: this.position @@ -104,7 +119,7 @@ var sconceLight2 = Entities.addEntity({ type: "Light", position: { - x: 540.1 , + x: 540.1, y: 496.24, z: 505.57 }, diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index c38e8c0a26..c94f1bde9b 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -191,7 +191,7 @@ function createFlashlight(position) { } function createLightSwitches() { - var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.fbx"; + var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/lightswitch.fbx?v1"; var scriptURL = Script.resolvePath("lightSwitchHall.js?v1"); var lightSwitchHall = Entities.addEntity({ From f334651a57eab4dccd07db87cc705a8477d6eb85 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Sep 2015 10:05:27 -0700 Subject: [PATCH 060/138] deleted handControllerGrab --- examples/controllers/handControllerGrab.js | 463 --------------------- 1 file changed, 463 deletions(-) delete mode 100644 examples/controllers/handControllerGrab.js diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js deleted file mode 100644 index 251d78e273..0000000000 --- a/examples/controllers/handControllerGrab.js +++ /dev/null @@ -1,463 +0,0 @@ -// hydraGrab.js -// examples -// -// Created by Eric Levin on 9/2/15 -// Copyright 2015 High Fidelity, Inc. -// -// Grabs physically moveable entities with hydra-like controllers; it works for either near or far objects. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -Script.include("../libraries/utils.js"); - - -///////////////////////////////////////////////////////////////// -// -// these tune time-averaging and "on" value for analog trigger -// - -var TRIGGER_SMOOTH_RATIO = 0.1; // 0.0 disables smoothing of trigger value -var TRIGGER_ON_VALUE = 0.2; - -///////////////////////////////////////////////////////////////// -// -// distant manipulation -// - -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, - blue: 255 -}; // line color when pick misses -var INTERSECT_COLOR = { - red: 250, - green: 10, - blue: 10 -}; // line color when pick hits -var LINE_ENTITY_DIMENSIONS = { - x: 1000, - y: 1000, - z: 1000 -}; -var LINE_LENGTH = 500; - - -///////////////////////////////////////////////////////////////// -// -// near grabbing -// - -var GRAB_RADIUS = 0.3; // if the ray misses but an object is this close, it will still be selected -var NEAR_GRABBING_ACTION_TIMEFRAME = 0.05; // how quickly objects move to their new position -var NEAR_GRABBING_VELOCITY_SMOOTH_RATIO = 1.0; // adjust time-averaging of held object's velocity. 1.0 to disable. -var NEAR_PICK_MAX_DISTANCE = 0.6; // max length of pick-ray for close grabbing to be selected -var RELEASE_VELOCITY_MULTIPLIER = 1.5; // affects throwing things - -///////////////////////////////////////////////////////////////// -// -// other constants -// - -var RIGHT_HAND = 1; -var LEFT_HAND = 0; - -var ZERO_VEC = { - x: 0, - y: 0, - z: 0 -}; -var NULL_ACTION_ID = "{00000000-0000-0000-000000000000}"; -var MSEC_PER_SEC = 1000.0; - -// these control how long an abandoned pointer line will hang around -var startTime = Date.now(); -var LIFETIME = 10; - -// states for the state machine -var STATE_SEARCHING = 0; -var STATE_DISTANCE_HOLDING = 1; -var STATE_CONTINUE_DISTANCE_HOLDING = 2; -var STATE_NEAR_GRABBING = 3; -var STATE_CONTINUE_NEAR_GRABBING = 4; -var STATE_RELEASE = 5; - -var GRAB_USER_DATA_KEY = "grabKey"; - -function controller(hand, triggerAction) { - this.hand = hand; - if (this.hand === RIGHT_HAND) { - this.getHandPosition = MyAvatar.getRightPalmPosition; - this.getHandRotation = MyAvatar.getRightPalmRotation; - } else { - this.getHandPosition = MyAvatar.getLeftPalmPosition; - this.getHandRotation = MyAvatar.getLeftPalmRotation; - } - this.triggerAction = triggerAction; - this.palm = 2 * hand; - // this.tip = 2 * hand + 1; // unused, but I'm leaving this here for fear it will be needed - - this.actionID = null; // action this script created... - this.grabbedEntity = null; // on this entity. - this.grabbedVelocity = ZERO_VEC; // rolling average of held object's velocity - this.state = 0; - this.pointer = null; // entity-id of line object - this.triggerValue = 0; // rolling average of trigger value - - this.update = function() { - switch (this.state) { - case STATE_SEARCHING: - this.search(); - break; - case STATE_DISTANCE_HOLDING: - this.distanceHolding(); - break; - case STATE_CONTINUE_DISTANCE_HOLDING: - this.continueDistanceHolding(); - break; - case STATE_NEAR_GRABBING: - this.nearGrabbing(); - break; - case STATE_CONTINUE_NEAR_GRABBING: - this.continueNearGrabbing(); - break; - case STATE_RELEASE: - this.release(); - break; - } - } - - - this.lineOn = function(closePoint, farPoint, color) { - // draw a line - if (this.pointer == null) { - this.pointer = Entities.addEntity({ - type: "Line", - name: "pointer", - dimensions: LINE_ENTITY_DIMENSIONS, - visible: true, - position: closePoint, - linePoints: [ZERO_VEC, farPoint], - color: color, - lifetime: LIFETIME - }); - } else { - Entities.editEntity(this.pointer, { - position: closePoint, - linePoints: [ZERO_VEC, farPoint], - color: color, - lifetime: (Date.now() - startTime) / MSEC_PER_SEC + LIFETIME - }); - } - } - - - this.lineOff = function() { - if (this.pointer != null) { - Entities.deleteEntity(this.pointer); - } - this.pointer = null; - } - - - this.triggerSmoothedSqueezed = function() { - var triggerValue = Controller.getActionValue(this.triggerAction); - // smooth out trigger value - this.triggerValue = (this.triggerValue * TRIGGER_SMOOTH_RATIO) + - (triggerValue * (1.0 - TRIGGER_SMOOTH_RATIO)); - return this.triggerValue > TRIGGER_ON_VALUE; - } - - - this.triggerSqueezed = function() { - var triggerValue = Controller.getActionValue(this.triggerAction); - return triggerValue > TRIGGER_ON_VALUE; - } - - - this.search = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - - // the trigger is being pressed, do a ray test - var handPosition = this.getHandPosition(); - var pickRay = { - origin: handPosition, - direction: Quat.getUp(this.getHandRotation()) - }; - var intersection = Entities.findRayIntersection(pickRay, true); - if (intersection.intersects && - intersection.properties.collisionsWillMove === 1 && - intersection.properties.locked === 0) { - // the ray is intersecting something we can move. - var handControllerPosition = Controller.getSpatialControlPosition(this.palm); - var intersectionDistance = Vec3.distance(handControllerPosition, intersection.intersection); - this.grabbedEntity = intersection.entityID; - if (intersectionDistance < NEAR_PICK_MAX_DISTANCE) { - // the hand is very close to the intersected object. go into close-grabbing mode. - this.state = STATE_NEAR_GRABBING; - } else { - // the hand is far from the intersected object. go into distance-holding mode - this.state = STATE_DISTANCE_HOLDING; - this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); - } - } else { - // forward ray test failed, try sphere test. - var nearbyEntities = Entities.findEntities(handPosition, GRAB_RADIUS); - var minDistance = GRAB_RADIUS; - var grabbedEntity = null; - for (var i = 0; i < nearbyEntities.length; i++) { - var props = Entities.getEntityProperties(nearbyEntities[i]); - var distance = Vec3.distance(props.position, handPosition); - if (distance < minDistance && props.name !== "pointer" && - props.collisionsWillMove === 1 && - props.locked === 0) { - this.grabbedEntity = nearbyEntities[i]; - minDistance = distance; - } - } - if (this.grabbedEntity === null) { - this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); - } else { - this.state = STATE_NEAR_GRABBING; - } - } - } - - - this.distanceHolding = function() { - var handControllerPosition = Controller.getSpatialControlPosition(this.palm); - var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(this.palm)); - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]); - - // add the action and initialize some variables - this.currentObjectPosition = grabbedProperties.position; - this.currentObjectRotation = grabbedProperties.rotation; - this.currentObjectTime = Date.now(); - this.handPreviousPosition = handControllerPosition; - this.handPreviousRotation = handRotation; - - this.actionID = Entities.addAction("spring", this.grabbedEntity, { - targetPosition: this.currentObjectPosition, - linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, - targetRotation: this.currentObjectRotation, - angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME - }); - if (this.actionID == NULL_ACTION_ID) { - this.actionID = null; - } - - if (this.actionID != null) { - this.state = STATE_CONTINUE_DISTANCE_HOLDING; - this.activateEntity(this.grabbedEntity); - Entities.callEntityMethod(this.grabbedEntity, "startDistantGrab"); - - if (this.hand === RIGHT_HAND) { - Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); - } else { - Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); - } - } - } - - - this.continueDistanceHolding = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - - var handPosition = this.getHandPosition(); - var handControllerPosition = Controller.getSpatialControlPosition(this.palm); - var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(this.palm)); - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]); - - this.lineOn(handPosition, Vec3.subtract(grabbedProperties.position, handPosition), INTERSECT_COLOR); - - // the action was set up on a previous call. update the targets. - var radius = Math.max(Vec3.distance(this.currentObjectPosition, - handControllerPosition) * DISTANCE_HOLDING_RADIUS_FACTOR, - DISTANCE_HOLDING_RADIUS_FACTOR); - - var handMoved = Vec3.subtract(handControllerPosition, this.handPreviousPosition); - this.handPreviousPosition = handControllerPosition; - var superHandMoved = Vec3.multiply(handMoved, radius); - - var newObjectPosition = Vec3.sum(this.currentObjectPosition, superHandMoved); - var deltaPosition = Vec3.subtract(newObjectPosition, this.currentObjectPosition); // meters - var now = Date.now(); - var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds - this.computeReleaseVelocity(deltaPosition, deltaTime, false); - - this.currentObjectPosition = newObjectPosition; - this.currentObjectTime = now; - - // this doubles hand rotation - var handChange = Quat.multiply(Quat.slerp(this.handPreviousRotation, handRotation, - DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR), - Quat.inverse(this.handPreviousRotation)); - this.handPreviousRotation = handRotation; - this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation); - - Entities.callEntityMethod(this.grabbedEntity, "continueDistantGrab"); - - Entities.updateAction(this.grabbedEntity, this.actionID, { - targetPosition: this.currentObjectPosition, - linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, - targetRotation: this.currentObjectRotation, - angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME - }); - } - - - this.nearGrabbing = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - - this.lineOff(); - - this.activateEntity(this.grabbedEntity); - - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]); - - var handRotation = this.getHandRotation(); - var handPosition = this.getHandPosition(); - - var objectRotation = grabbedProperties.rotation; - var offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); - - currentObjectPosition = grabbedProperties.position; - var offset = Vec3.subtract(currentObjectPosition, handPosition); - var offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, offsetRotation)), offset); - - this.actionID = Entities.addAction("hold", this.grabbedEntity, { - hand: this.hand == RIGHT_HAND ? "right" : "left", - timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, - relativePosition: offsetPosition, - relativeRotation: offsetRotation - }); - if (this.actionID == NULL_ACTION_ID) { - this.actionID = null; - } else { - this.state = STATE_CONTINUE_NEAR_GRABBING; - Entities.callEntityMethod(this.grabbedEntity, "startNearGrab"); - if (this.hand === RIGHT_HAND) { - Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); - } else { - Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); - } - } - - this.currentHandControllerPosition = Controller.getSpatialControlPosition(this.palm); - this.currentObjectTime = Date.now(); - } - - - this.continueNearGrabbing = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - - // keep track of the measured velocity of the held object - var handControllerPosition = Controller.getSpatialControlPosition(this.palm); - var now = Date.now(); - - var deltaPosition = Vec3.subtract(handControllerPosition, this.currentHandControllerPosition); // meters - var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds - this.computeReleaseVelocity(deltaPosition, deltaTime, true); - - this.currentHandControllerPosition = handControllerPosition; - this.currentObjectTime = now; - Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab"); - } - - - this.computeReleaseVelocity = function(deltaPosition, deltaTime, useMultiplier) { - if (deltaTime > 0.0 && !vec3equal(deltaPosition, ZERO_VEC)) { - var grabbedVelocity = Vec3.multiply(deltaPosition, 1.0 / deltaTime); - // don't update grabbedVelocity if the trigger is off. the smoothing of the trigger - // value would otherwise give the held object time to slow down. - if (this.triggerSqueezed()) { - this.grabbedVelocity = - Vec3.sum(Vec3.multiply(this.grabbedVelocity, (1.0 - NEAR_GRABBING_VELOCITY_SMOOTH_RATIO)), - Vec3.multiply(grabbedVelocity, NEAR_GRABBING_VELOCITY_SMOOTH_RATIO)); - } - - if (useMultiplier) { - this.grabbedVelocity = Vec3.multiply(this.grabbedVelocity, RELEASE_VELOCITY_MULTIPLIER); - } - } - } - - - this.release = function() { - this.lineOff(); - - if (this.grabbedEntity != null && this.actionID != null) { - Entities.deleteAction(this.grabbedEntity, this.actionID); - Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); - } - - // the action will tend to quickly bring an object's velocity to zero. now that - // the action is gone, set the objects velocity to something the holder might expect. - Entities.editEntity(this.grabbedEntity, { - velocity: this.grabbedVelocity - }); - this.deactivateEntity(this.grabbedEntity); - - this.grabbedVelocity = ZERO_VEC; - this.grabbedEntity = null; - this.actionID = null; - this.state = STATE_SEARCHING; - } - - - this.cleanup = function() { - release(); - } - - this.activateEntity = function(entity) { - var data = { - activated: true, - avatarId: MyAvatar.sessionUUID - }; - setEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, data); - } - - this.deactivateEntity = function(entity) { - var data = { - activated: false, - avatarId: null - }; - setEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, data); - } -} - - -var rightController = new controller(RIGHT_HAND, Controller.findAction("RIGHT_HAND_CLICK")); -var leftController = new controller(LEFT_HAND, Controller.findAction("LEFT_HAND_CLICK")); - - -function update() { - rightController.update(); - leftController.update(); -} - - -function cleanup() { - rightController.cleanup(); - leftController.cleanup(); -} - - -Script.scriptEnding.connect(cleanup); -Script.update.connect(update) \ No newline at end of file From 1e1cfb6aae197aa5af6828a768a064c1471b87dd Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Sep 2015 10:15:50 -0700 Subject: [PATCH 061/138] Flipped lights so up is lights on and vica versa --- examples/toys/lightSwitchGarage.js | 33 ++++++++++++++++++--------- examples/toys/lightSwitchHall.js | 36 ++++++++++++++++++------------ 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/examples/toys/lightSwitchGarage.js b/examples/toys/lightSwitchGarage.js index a68a09cf7d..99d827aa06 100644 --- a/examples/toys/lightSwitchGarage.js +++ b/examples/toys/lightSwitchGarage.js @@ -52,16 +52,7 @@ this.createLights(); } - // flip model to give illusion of light switch being flicked - var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; - var axis = {x: 0, y: 1, z: 0}; - var dQ = Quat.angleAxis(180, axis); - rotation = Quat.multiply(rotation, dQ); - - - Entities.editEntity(this.entityID, { - rotation: rotation - }); + this.flipLights(); Audio.playSound(this.switchSound, { volume: 0.5, @@ -86,7 +77,7 @@ }, createLights: function() { - + var sconceLight3 = Entities.addEntity({ type: "Light", @@ -176,6 +167,25 @@ }, + flipLights: function() { + // flip model to give illusion of light switch being flicked + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + + }, + + // preload() will be called when the entity has become visible (or known) to the interface // it gives us a chance to set our local JavaScript object up. In this case it means: preload: function(entityID) { @@ -191,6 +201,7 @@ //If light is off, then we create two new lights- at the position of the sconces if (lightState.on === false) { this.createLights(); + this.flipLights(); } //If lights are on, do nothing! }, diff --git a/examples/toys/lightSwitchHall.js b/examples/toys/lightSwitchHall.js index 6bc1eeab83..49ccc51b79 100644 --- a/examples/toys/lightSwitchHall.js +++ b/examples/toys/lightSwitchHall.js @@ -53,19 +53,7 @@ } // flip model to give illusion of light switch being flicked - var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; - var axis = { - x: 0, - y: 1, - z: 0 - }; - var dQ = Quat.angleAxis(180, axis); - rotation = Quat.multiply(rotation, dQ); - - - Entities.editEntity(this.entityID, { - rotation: rotation - }); + this.flipLights(); Audio.playSound(this.switchSound, { volume: 0.5, @@ -148,9 +136,27 @@ }, + flipLights: function() { + // flip model to give illusion of light switch being flicked + var rotation = Entities.getEntityProperties(this.entityID, "rotation").rotation; + var axis = { + x: 0, + y: 1, + z: 0 + }; + var dQ = Quat.angleAxis(180, axis); + rotation = Quat.multiply(rotation, dQ); + + + Entities.editEntity(this.entityID, { + rotation: rotation + }); + + }, + // preload() will be called when the entity has become visible (or known) to the interface // it gives us a chance to set our local JavaScript object up. In this case it means: - preload: function(entityID) { + preload: function(entityID) { this.entityID = entityID; //The light switch is static, so just cache its position once @@ -163,6 +169,8 @@ //If light is off, then we create two new lights- at the position of the sconces if (lightState.on === false) { this.createLights(); + this.flipLights(); + } //If lights are on, do nothing! }, From 8609769c2081f539f2b0c8fdeafabd032f7f1f38 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Sep 2015 11:58:54 -0700 Subject: [PATCH 062/138] cat now listens for touch event from controller --- examples/toys/cat.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index 1f1e7cc9d4..f1fcb81e8f 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -27,17 +27,10 @@ Cat.prototype = { - update: function() { - var leftHandPosition = MyAvatar.getLeftPalmPosition(); - var rightHandPosition = MyAvatar.getRightPalmPosition(); - if (Vec3.distance(leftHandPosition, _this.position) < _this.distanceThreshold || Vec3.distance(rightHandPosition, _this.position) < _this.distanceThreshold && _this.canMeow) { - _this.meow(); - _this.canMeow = false; - Script.setTimeout(function() { - _this.canMeow = true - }, _this.meowBreakTime) - } - }, + startTouch: function() { + print("START TOUCH") + this.meow(); + } meow: function() { From 2883319fb0fe4d3810df53983262c850830dda7c Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 24 Sep 2015 13:33:43 -0700 Subject: [PATCH 063/138] Add potted plant, arm chair, and pillow --- examples/toys/masterResetEntity.js | 195 +++++++++++++++++++++++------ 1 file changed, 158 insertions(+), 37 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index c94f1bde9b..901777be09 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -8,7 +8,7 @@ /*global deleteAllToys, print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ //per script -/*global createAllToys, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLightSwitches */ +/*global createAllToys, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLightSwitches,createPottedPlant,createArmChair,createPillow */ var utilitiesScript = Script.resolvePath("../libraries/utils.js"); Script.include(utilitiesScript); @@ -455,41 +455,41 @@ function createBlocks(position) { var i, j; var blockTypes = [{ - url: "planky_blue.fbx", - dimensions: { - x: 0.05, - y: 0.05, - z: 0.25 - } - }, { - url: "planky_green.fbx", - dimensions: { - x: 0.1, - y: 0.1, - z: 0.25 - } - }, { - url: "planky_natural.fbx", - dimensions: { - x: 0.05, - y: 0.05, - z: 0.05 - } - }, { - url: "planky_yellow.fbx", - dimensions: { - x: 0.03, - y: 0.05, - z: 0.25 - } - }, { - url: "planky_red.fbx", - dimensions: { - x: 0.1, - y: 0.05, - z: 0.25 - } - }]; + url: "planky_blue.fbx", + dimensions: { + x: 0.05, + y: 0.05, + z: 0.25 + } + }, { + url: "planky_green.fbx", + dimensions: { + x: 0.1, + y: 0.1, + z: 0.25 + } + }, { + url: "planky_natural.fbx", + dimensions: { + x: 0.05, + y: 0.05, + z: 0.05 + } + }, { + url: "planky_yellow.fbx", + dimensions: { + x: 0.03, + y: 0.05, + z: 0.25 + } + }, { + url: "planky_red.fbx", + dimensions: { + x: 0.1, + y: 0.05, + z: 0.25 + } + }]; var modelURL, entity; for (i = 0; i < blockTypes.length; i++) { @@ -527,12 +527,133 @@ function createBlocks(position) { } } +//createPottedPlant,createArmChair,createPillow + +function createPottedPlant() { + var modelURL = "https://hifi-public.s3.amazonaws.com/ryan/potted_plant.fbx"; + + var position = { + x: 554.26, + y: 495.23, + z: 504.53 + } + + var entity = Entities.addEntity({ + type: "Model", + name: "Potted Plant", + modelURL: modelURL, + position: position, + dimensions: { + x: 1.10 + y: 2.18, + z: 1.07 + }, + collisionsWillMove: true, + shapeType: 'box', + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + velocity: { + x: 0, + y: -0.1, + z: 0 + }, + linearDamping: 0.4 + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +}; + +function createArmChair() { + var modelURL = "https://hifi-public.s3.amazonaws.com/ryan/red_arm_chair.fbx"; + var position = { + x: 549.39, + y: 494.57, + z: 508.37 + } + + var ARM_CHAIR_COLLISION_SHAPE = ""; + var entity = Entities.addEntity({ + type: "Model", + name: "Arm Chair", + modelURL: modelURL, + shapeType:'compound', + compoundShapeURL: ARM_CHAIR_COLLISION_SHAPE, + position: position, + rotation: { + x: 0, + y: -143.01, + z: 0 + }, + dimensions: { + x: 1.26, + y: 1.56, + z: 1.35 + }, + collisionsWillMove: true, + shapeType: 'box', + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + velocity: { + x: 0, + y: -0.1, + z: 0 + } + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +}; + +function createPillow() { + var modelURL = "https://hifi-public.s3.amazonaws.com/ryan/red_arm_chair_pillow.fbx"; + var position = { + x: 549.39, + y: 495.00, + z: 508.37 + } + var entity = Entities.addEntity({ + type: "Model", + name: "Arm Chair Pillow", + modelURL: modelURL, + position: position, + dimensions: { + x: 0.07, + y: 0.17, + z: 0.07 + }, + collisionsWillMove: true, + shapeType: 'box', + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + velocity: { + x: 0, + y: -0.1, + z: 0 + } + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +}; + function cleanup() { deleteAllToys(); } if (shouldDeleteOnEndScript) { - Script.scriptEnding.connect(cleanup); } From 16f9140a08ca4dacb34805eb644958caab439e02 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Sep 2015 14:04:37 -0700 Subject: [PATCH 064/138] updated master script so objects with fewer properties are on one line --- examples/toys/masterResetEntity.js | 344 +++++------------------------ 1 file changed, 60 insertions(+), 284 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index c94f1bde9b..eebcefaaed 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -24,54 +24,24 @@ deleteAllToys(); createAllToys(); function createAllToys() { - createBlocks({ - x: 548.3, - y: 495.55, - z: 504.4 - }); + createBlocks({ x: 548.3, y: 495.55, z: 504.4 }); - createSprayCan({ - x: 549.8, - y: 495.6, - z: 503.94 - }); + createSprayCan({ x: 549.8, y: 495.6, z: 503.94 }); - createBasketBall({ - x: 547.73, - y: 495.5, - z: 505.47 - }); + createBasketBall({ x: 547.73, y: 495.5, z: 505.47}); - createDoll({ - x: 546.67, - y: 495.41, - z: 505.09 - }); + createDoll({x: 546.67, y: 495.41, z: 505.09}); - createWand({ - x: 546.71, - y: 495.55, - z: 506.15 - }); + createWand({ x: 546.71, y: 495.55, z: 506.15}); createDice(); - createFlashlight({ - x: 545.72, - y: 495.41, - z: 505.78 + createFlashlight({ x: 545.72, y: 495.41, z: 505.78 }); - createCat({ - x: 551.49859619140625, - y: 495.49111938476562, - z: 502.26498413085938 - }); + createCat({ x: 551.49859619140625, y: 495.49111938476562, z: 502.26498413085938 }); - createMagballs({ - x: 548.73, - y: 495.51, - z: 503.54 + createMagballs({ x: 548.73, y: 495.51, z: 503.54 }); //Handles toggling of all sconce lights @@ -99,36 +69,21 @@ function createMagballs(position) { modelURL: modelURL, name: "Tin Can", position: position, - rotation: { - w: 0.93041884899139404, - x: -1.52587890625e-05, - y: 0.36647593975067139, - z: -1.52587890625e-05 - }, - dimensions: { - x: 0.16946873068809509, - y: 0.21260403096675873, - z: 0.16946862637996674 - }, + rotation: { w: 0.93041884899139404, x: -1.52587890625e-05, y: 0.36647593975067139, z: -1.52587890625e-05}, + dimensions: { x: 0.16946873068809509, y: 0.21260403096675873, z: 0.16946862637996674 }, }); - setEntityCustomData(resetKey, tinCan, { - resetMe: true - }); + setEntityCustomData(resetKey, tinCan, { resetMe: true }); - setEntityCustomData("OmniTool", tinCan, { - script: "../toys/magBalls.js" - }); + setEntityCustomData("OmniTool", tinCan, { script: "../toys/magBalls.js"}); } function createCat(position) { var scriptURL = Script.resolvePath("cat.js?v1"); 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 animationSettings = JSON.stringify({running: true,}); var cat = Entities.addEntity({ type: "Model", modelURL: modelURL, @@ -137,22 +92,11 @@ function createCat(position) { 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 - }, + 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 - }); + setEntityCustomData(resetKey, cat, { resetMe: true }); } function createFlashlight(position) { @@ -165,28 +109,14 @@ function createFlashlight(position) { name: "flashlight", script: scriptURL, position: position, - dimensions: { - x: 0.08, - y: 0.30, - z: 0.08 - }, + 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 - }, + gravity: {x: 0, y: -3.5, z: 0}, + velocity: { x: 0, y: -0.01, z: 0}, shapeType: 'box', }); - setEntityCustomData(resetKey, flashlight, { - resetMe: true - }); + setEntityCustomData(resetKey, flashlight, {resetMe: true}); } @@ -199,22 +129,9 @@ function createLightSwitches() { modelURL: modelURL, name: "Light Switch Hall", script: scriptURL, - position: { - x: 543.27764892578125, - y: 495.67999267578125, - z: 511.00564575195312 - }, - rotation: { - w: 0.63280689716339111, - x: 0.63280689716339111, - y: -0.31551080942153931, - z: 0.31548023223876953 - }, - dimensions: { - x: 0.10546875, - y: 0.032372996211051941, - z: 0.16242524981498718 - } + position: {x: 543.27764892578125, y: 495.67999267578125, z: 511.00564575195312}, + rotation: {w: 0.63280689716339111, x: 0.63280689716339111, y: -0.31551080942153931, z: 0.31548023223876953}, + dimensions: {x: 0.10546875, y: 0.032372996211051941, z: 0.16242524981498718} }); setEntityCustomData(resetKey, lightSwitchHall, { @@ -228,27 +145,12 @@ function createLightSwitches() { modelURL: modelURL, name: "Light Switch Garage", script: scriptURL, - position: { - x: 545.62, - y: 495.68, - z: 500.21 - }, - rotation: { - w: 0.20082402229309082, - x: 0.20082402229309082, - y: -0.67800414562225342, - z: 0.67797362804412842 - }, - dimensions: { - x: 0.10546875, - y: 0.032372996211051941, - z: 0.16242524981498718 - } + position: {x: 545.62, y: 495.68,z: 500.21}, + rotation: { w: 0.20082402229309082, x: 0.20082402229309082, y: -0.67800414562225342, z: 0.67797362804412842}, + dimensions: { x:0.10546875, y: 0.032372996211051941, z: 0.16242524981498718} }); - setEntityCustomData(resetKey, lightSwitchGarage, { - resetMe: true - }); + setEntityCustomData(resetKey, lightSwitchGarage, {resetMe: true}); } @@ -258,46 +160,22 @@ function createDice() { modelURL: "http://s3.amazonaws.com/hifi-public/models/props/Dice/goldDie.fbx", collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", name: "dice", - position: { - x: 541, - y: 494.96, - z: 509.1 - }, - dimensions: { - x: 0.09, - y: 0.09, - z: 0.09 - }, - gravity: { - x: 0, - y: -3.5, - z: 0 - }, - velocity: { - x: 0, - y: -0.01, - z: 0 - }, + position: {x: 541, y: 494.96, z: 509.1}, + dimensions: {x: 0.09, y: 0.09, z: 0.09}, + gravity: {x: 0, y: -3.5, z: 0}, + velocity: {x: 0,y: -0.01, z: 0}, shapeType: "box", collisionsWillMove: true }; var dice1 = Entities.addEntity(diceProps); - diceProps.position = { - x: 541.05, - y: 494.96, - z: 509.0 - }; + diceProps.position = { x: 541.05, y: 494.96, z: 509.0 }; var dice2 = Entities.addEntity(diceProps); - setEntityCustomData(resetKey, dice1, { - resetMe: true - }); + setEntityCustomData(resetKey, dice1, {resetMe: true}); - setEntityCustomData(resetKey, dice2, { - resetMe: true - }); + setEntityCustomData(resetKey, dice2, {resetMe: true}); } function createWand(position) { @@ -311,16 +189,8 @@ function createWand(position) { type: "Model", modelURL: WAND_MODEL, position: position, - gravity: { - x: 0, - y: 0, - z: 0, - }, - dimensions: { - x: 0.05, - y: 0.25, - z: 0.05 - }, + gravity: {x: 0, y: 0, z: 0}, + dimensions: { x: 0.05, y: 0.25,z: 0.05}, //must be enabled to be grabbable in the physics engine collisionsWillMove: true, compoundShapeURL: WAND_COLLISION_SHAPE, @@ -330,9 +200,7 @@ function createWand(position) { script: scriptURL }); - setEntityCustomData(resetKey, entity, { - resetMe: true - }); + setEntityCustomData(resetKey, entity, {resetMe: true}); } function createBasketBall(position) { @@ -346,41 +214,22 @@ function createBasketBall(position) { collisionsWillMove: true, shapeType: "sphere", name: "basketball", - dimensions: { - x: 0.25, - y: 0.26, - z: 0.25 - }, - gravity: { - x: 0, - y: -7, - z: 0 - }, + dimensions: {x: 0.25, y: 0.26, z: 0.25}, + gravity: {x: 0, y: -7, z: 0}, restitution: 10, linearDamping: 0.0, - velocity: { - x: 0, - y: -0.01, - z: 0 - }, + velocity: { x: 0, y: -0.01, z: 0}, collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/basketball/basketball.wav" }); - setEntityCustomData(resetKey, entity, { - resetMe: true - }); - + setEntityCustomData(resetKey, entity, {resetMe: true}); } function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; var scriptURL = Script.resolvePath("doll.js"); - var naturalDimensions = { - x: 1.63, - y: 1.67, - z: 0.26 - }; + var naturalDimensions = {x: 1.63, y: 1.67, z: 0.26}; var desiredDimensions = Vec3.multiply(naturalDimensions, 0.15); var entity = Entities.addEntity({ type: "Model", @@ -390,22 +239,12 @@ function createDoll(position) { position: position, shapeType: 'box', dimensions: desiredDimensions, - gravity: { - x: 0, - y: -5, - z: 0 - }, - velocity: { - x: 0, - y: -0.1, - z: 0 - }, + gravity: {x: 0, y: -5, z: 0}, + velocity: {x: 0, y: -0.1, z: 0}, collisionsWillMove: true }); - setEntityCustomData(resetKey, entity, { - resetMe: true - }); + setEntityCustomData(resetKey, entity, {resetMe: true}); } function createSprayCan(position) { @@ -417,35 +256,15 @@ function createSprayCan(position) { name: "spraycan", modelURL: modelURL, position: position, - rotation: { - x: 0, - y: 0, - z: 0, - w: 1 - }, - dimensions: { - x: 0.07, - y: 0.17, - z: 0.07 - }, + dimensions: {x: 0.07, y: 0.17, z: 0.07}, collisionsWillMove: true, shapeType: 'box', script: scriptURL, - gravity: { - x: 0, - y: -0.5, - z: 0 - }, - velocity: { - x: 0, - y: -1, - z: 0 - } + gravity: {x: 0, y: -0.5, z: 0}, + velocity: { x: 0, y: -1, z: 0} }); - setEntityCustomData(resetKey, entity, { - resetMe: true - }); + setEntityCustomData(resetKey, entity, {resetMe: true}); } @@ -454,42 +273,13 @@ function createBlocks(position) { var NUM_BLOCKS_PER_COLOR = 4; var i, j; - var blockTypes = [{ - url: "planky_blue.fbx", - dimensions: { - x: 0.05, - y: 0.05, - z: 0.25 - } - }, { - url: "planky_green.fbx", - dimensions: { - x: 0.1, - y: 0.1, - z: 0.25 - } - }, { - url: "planky_natural.fbx", - dimensions: { - x: 0.05, - y: 0.05, - z: 0.05 - } - }, { - url: "planky_yellow.fbx", - dimensions: { - x: 0.03, - y: 0.05, - z: 0.25 - } - }, { - url: "planky_red.fbx", - dimensions: { - x: 0.1, - y: 0.05, - z: 0.25 - } - }]; + var blockTypes = [ + { url: "planky_blue.fbx", dimensions: {x: 0.05, y: 0.05, z: 0.25} } + { url: "planky_green.fbx", dimensions: {x: 0.1, y: 0.1, z: 0.25} } + { url: "planky_natural.fbx", dimensions: { x: 0.05, y: 0.05, z: 0.05} } + { url: "planky_yellow.fbx", dimensions: {x: 0.03, y: 0.05, z: 0.25} } + { url: "planky_red.fbx", dimensions: {x: 0.1, y: 0.05, z: 0.25} } + ]; var modelURL, entity; for (i = 0; i < blockTypes.length; i++) { @@ -498,31 +288,17 @@ function createBlocks(position) { entity = Entities.addEntity({ type: "Model", modelURL: modelURL, - position: Vec3.sum(position, { - x: j / 10, - y: i / 10, - z: 0 - }), + position: Vec3.sum(position, { x: j / 10, y: i / 10, z: 0}), shapeType: 'box', name: "block", dimensions: blockTypes[i].dimensions, collisionsWillMove: true, - gravity: { - x: 0, - y: -2.5, - z: 0 - }, - velocity: { - x: 0, - y: -0.01, - z: 0 - } + gravity: {x: 0, y: -2.5, z: 0}, + velocity: { x: 0, y: -0.01, z: 0} }); //customKey, id, data - setEntityCustomData(resetKey, entity, { - resetMe: true - }); + setEntityCustomData(resetKey, entity, {resetMe: true}); } } } From 536adf898184fc0145147a3f817b2afe75acfd8d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Sep 2015 14:39:11 -0700 Subject: [PATCH 065/138] testing paintcan --- examples/toys/cat.js | 1 - examples/toys/masterResetEntity.js | 2 +- examples/toys/sprayPaintCan.js | 145 +++++++++++++++++++++++------ 3 files changed, 116 insertions(+), 32 deletions(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index f1fcb81e8f..98d08969a7 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -28,7 +28,6 @@ Cat.prototype = { startTouch: function() { - print("START TOUCH") this.meow(); } diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index c94f1bde9b..f3950eb32c 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -33,7 +33,7 @@ function createAllToys() { createSprayCan({ x: 549.8, y: 495.6, - z: 503.94 + z: 503.84 }); createBasketBall({ diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 28eb8adaf4..8f3bb12307 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -3,10 +3,9 @@ //Need absolute path for now, for testing before PR merge and s3 cloning. Will change post-merge Script.include("../libraries/utils.js"); + GRAB_FRAME_USER_DATA_KEY = "grabFrame"; this.userData = {}; - this.spraySound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/sprayPaintSound.wav"); - var TIP_OFFSET_Z = 0.14; var TIP_OFFSET_Y = 0.04; @@ -20,17 +19,59 @@ var MIN_POINT_DISTANCE = 0.01; var STROKE_WIDTH = 0.02; - this.setRightHand = function() { - this.hand = 'RIGHT'; + var self = this; + + var timeSinceLastMoved = 0; + var RESET_TIME_THRESHOLD = 5; + var DISTANCE_FROM_HOME_THRESHOLD = 0.5; + var HOME_POSITION = { + x: 549.12, + y: 495.555, + z: 503.77 + }; + this.getUserData = function() { + + + if (this.properties.userData) { + this.userData = JSON.parse(this.properties.userData); + } } - this.setLeftHand = function() { - this.hand = 'LEFT'; + this.updateUserData = function() { + Entities.editEntity(this.entityId, { + userData: JSON.stringify(this.userData) + }); } - this.startNearGrab = function() { - this.whichHand = this.hand; - var position = Entities.getEntityProperties(this.entityId, "position").position; + this.update = function(deltaTime) { + self.getUserData(); + self.properties = Entities.getEntityProperties(self.entityId); + + if (Vec3.length(self.properties.velocity) < 0.1 && Vec3.distance(HOME_POSITION, self.properties.position) > DISTANCE_FROM_HOME_THRESHOLD) { + timeSinceLastMoved += deltaTime; + if (timeSinceLastMoved > RESET_TIME_THRESHOLD) { + self.reset(); + timeSinceLastMoved = 0; + } + } else { + timeSinceLastMoved = 0; + } + + //Only activate for the user who grabbed the object + if (self.userData.grabKey && self.userData.grabKey.activated === true && self.userData.grabKey.avatarId == MyAvatar.sessionUUID) { + if (self.activated !== true) { + //We were just grabbed, so create a particle system + self.grab(); + } + //Move emitter to where entity is always when its activated + self.sprayStream(); + } else if (self.userData.grabKey && self.userData.grabKey.activated === false && self.activated) { + self.letGo(); + } + } + + this.grab = function() { + this.activated = true; var animationSettings = JSON.stringify({ fps: 30, loop: true, @@ -44,7 +85,7 @@ this.paintStream = Entities.addEntity({ type: "ParticleEffect", animationSettings: animationSettings, - position: position, + position: this.properties.position, textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", emitSpeed: 0, speedSpread: 0.02, @@ -59,33 +100,34 @@ }, lifetime: 50, //probably wont be holding longer than this straight }); + } - this.sprayInjector = Audio.playSound(this.spraySound, { - position: position, - volume: 0.1 + this.letGo = function() { + this.activated = false; + Entities.deleteEntity(this.paintStream); + this.paintStream = null; + } + + this.reset = function() { + Entities.editEntity(self.entityId, { + position: HOME_POSITION, + rotation: Quat.fromPitchYawRollDegrees(0, 0, 0), + angularVelocity: ZERO_VEC, + velocity: ZERO_VEC }); } - - this.releaseGrab = function() { - Entities.deleteEntity(this.paintStream); - this.paintStream = null; - this.painting = false; - this.sprayInjector.stop(); - } - - - this.continueNearGrab = function() { - var props = Entities.getEntityProperties(this.entityId, ["position, rotation"]); - var forwardVec = Quat.getFront(Quat.multiply(props.rotation, Quat.fromPitchYawRollDegrees(0, 90, 0))); + this.sprayStream = function() { + var forwardQuat = Quat.multiply(self.properties.rotation, Quat.fromPitchYawRollDegrees(0, 90, 0)); + var forwardVec = Quat.getFront(self.properties.rotation); forwardVec = Vec3.normalize(forwardVec); - var upVec = Quat.getUp(props.rotation); - var position = Vec3.sum(props.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z)); + var upVec = Quat.getUp(self.properties.rotation); + var position = Vec3.sum(self.properties.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z)); position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y)) - Entities.editEntity(this.paintStream, { - position: position, - emitOrientation: forwardVec, + Entities.editEntity(self.paintStream, { + position: self.properties.position, + emitOrientation: self.properties.rotation, emitSpeed: 5 }); @@ -163,11 +205,31 @@ this.preload = function(entityId) { this.strokes = []; + this.activated = false; this.entityId = entityId; + this.properties = Entities.getEntityProperties(self.entityId); + this.getUserData(); + + //Only activate for the avatar who is grabbing the can! + if (this.userData.grabKey && this.userData.grabKey.activated) { + this.activated = true; + } + if (!this.userData.grabFrame) { + var data = { + relativePosition: { + x: 0, + y: 0, + z: 0 + }, + relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0) + } + setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, this.entityId, data); + } } this.unload = function() { + Script.update.disconnect(this.update); if (this.paintStream) { Entities.deleteEntity(this.paintStream); } @@ -175,6 +237,7 @@ Entities.deleteEntity(stroke); }); } + Script.update.connect(this.update); }); @@ -185,4 +248,26 @@ function randFloat(min, max) { function randInt(min, max) { return Math.floor(Math.random() * (max - min)) + min; +} + +function orientationOf(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); } \ No newline at end of file From 5da8b689c5a182d07c86a556daa89d0a43b557ae Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Sep 2015 14:41:22 -0700 Subject: [PATCH 066/138] fix missing commas --- examples/toys/masterResetEntity.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index eebcefaaed..9eaa0e56d5 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -274,11 +274,11 @@ function createBlocks(position) { var i, j; var blockTypes = [ - { url: "planky_blue.fbx", dimensions: {x: 0.05, y: 0.05, z: 0.25} } - { url: "planky_green.fbx", dimensions: {x: 0.1, y: 0.1, z: 0.25} } - { url: "planky_natural.fbx", dimensions: { x: 0.05, y: 0.05, z: 0.05} } - { url: "planky_yellow.fbx", dimensions: {x: 0.03, y: 0.05, z: 0.25} } - { url: "planky_red.fbx", dimensions: {x: 0.1, y: 0.05, z: 0.25} } + { url: "planky_blue.fbx", dimensions: {x: 0.05, y: 0.05, z: 0.25} }, + { url: "planky_green.fbx", dimensions: {x: 0.1, y: 0.1, z: 0.25} }, + { url: "planky_natural.fbx", dimensions: { x: 0.05, y: 0.05, z: 0.05} }, + { url: "planky_yellow.fbx", dimensions: {x: 0.03, y: 0.05, z: 0.25} }, + { url: "planky_red.fbx", dimensions: {x: 0.1, y: 0.05, z: 0.25} }, ]; var modelURL, entity; From ce0a726eb908f6864ee86f3bf8631664743b3f74 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Sep 2015 16:27:17 -0700 Subject: [PATCH 067/138] Fixed spraypaint for new particles --- examples/toys/sprayPaintCan.js | 138 ++++++++++----------------------- 1 file changed, 40 insertions(+), 98 deletions(-) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 8f3bb12307..0508cab038 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -3,11 +3,12 @@ //Need absolute path for now, for testing before PR merge and s3 cloning. Will change post-merge Script.include("../libraries/utils.js"); - GRAB_FRAME_USER_DATA_KEY = "grabFrame"; this.userData = {}; - var TIP_OFFSET_Z = 0.14; - var TIP_OFFSET_Y = 0.04; + this.spraySound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/sprayPaintSound.wav"); + + var TIP_OFFSET_Z = 0.02; + var TIP_OFFSET_Y = 0.08; var ZERO_VEC = { x: 0, @@ -19,59 +20,17 @@ var MIN_POINT_DISTANCE = 0.01; var STROKE_WIDTH = 0.02; - var self = this; - - var timeSinceLastMoved = 0; - var RESET_TIME_THRESHOLD = 5; - var DISTANCE_FROM_HOME_THRESHOLD = 0.5; - var HOME_POSITION = { - x: 549.12, - y: 495.555, - z: 503.77 - }; - this.getUserData = function() { - - - if (this.properties.userData) { - this.userData = JSON.parse(this.properties.userData); - } + this.setRightHand = function() { + this.hand = 'RIGHT'; } - this.updateUserData = function() { - Entities.editEntity(this.entityId, { - userData: JSON.stringify(this.userData) - }); + this.setLeftHand = function() { + this.hand = 'LEFT'; } - this.update = function(deltaTime) { - self.getUserData(); - self.properties = Entities.getEntityProperties(self.entityId); - - if (Vec3.length(self.properties.velocity) < 0.1 && Vec3.distance(HOME_POSITION, self.properties.position) > DISTANCE_FROM_HOME_THRESHOLD) { - timeSinceLastMoved += deltaTime; - if (timeSinceLastMoved > RESET_TIME_THRESHOLD) { - self.reset(); - timeSinceLastMoved = 0; - } - } else { - timeSinceLastMoved = 0; - } - - //Only activate for the user who grabbed the object - if (self.userData.grabKey && self.userData.grabKey.activated === true && self.userData.grabKey.avatarId == MyAvatar.sessionUUID) { - if (self.activated !== true) { - //We were just grabbed, so create a particle system - self.grab(); - } - //Move emitter to where entity is always when its activated - self.sprayStream(); - } else if (self.userData.grabKey && self.userData.grabKey.activated === false && self.activated) { - self.letGo(); - } - } - - this.grab = function() { - this.activated = true; + this.startNearGrab = function() { + this.whichHand = this.hand; + var position = Entities.getEntityProperties(this.entityId, "position").position; var animationSettings = JSON.stringify({ fps: 30, loop: true, @@ -85,14 +44,15 @@ this.paintStream = Entities.addEntity({ type: "ParticleEffect", animationSettings: animationSettings, - position: this.properties.position, + position: position, textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", - emitSpeed: 0, + emitSpeed: 3, speedSpread: 0.02, - polarFinish: 2 * DEG_TO_RAD, emitAcceleration: ZERO_VEC, emitRate: 100, particleRadius: 0.01, + radiusSpread: 0.005, + accelerationSpread: {x: 1, y: 1, x: 1}, color: { red: 170, green: 20, @@ -100,35 +60,38 @@ }, lifetime: 50, //probably wont be holding longer than this straight }); - } - this.letGo = function() { - this.activated = false; - Entities.deleteEntity(this.paintStream); - this.paintStream = null; - } - - this.reset = function() { - Entities.editEntity(self.entityId, { - position: HOME_POSITION, - rotation: Quat.fromPitchYawRollDegrees(0, 0, 0), - angularVelocity: ZERO_VEC, - velocity: ZERO_VEC + this.sprayInjector = Audio.playSound(this.spraySound, { + position: position, + volume: 0.1 }); } - this.sprayStream = function() { - var forwardQuat = Quat.multiply(self.properties.rotation, Quat.fromPitchYawRollDegrees(0, 90, 0)); - var forwardVec = Quat.getFront(self.properties.rotation); + + this.releaseGrab = function() { + Entities.deleteEntity(this.paintStream); + this.paintStream = null; + this.painting = false; + this.sprayInjector.stop(); + } + + + this.continueNearGrab = function() { + var props = Entities.getEntityProperties(this.entityId, ["position, rotation"]); + var forwardVec = Quat.getFront(Quat.multiply(props.rotation, Quat.fromPitchYawRollDegrees(0, 90, 0))); forwardVec = Vec3.normalize(forwardVec); - var upVec = Quat.getUp(self.properties.rotation); - var position = Vec3.sum(self.properties.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z)); + + var forwardQuat = orientationOf(forwardVec); + + + var upVec = Quat.getUp(props.rotation); + var position = Vec3.sum(props.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z)); position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y)) - Entities.editEntity(self.paintStream, { - position: self.properties.position, - emitOrientation: self.properties.rotation, - emitSpeed: 5 + Entities.editEntity(this.paintStream, { + position: position, + emitOrientation: forwardQuat, + // emitSpeed: 3 }); //Now check for an intersection with an entity @@ -205,31 +168,11 @@ this.preload = function(entityId) { this.strokes = []; - this.activated = false; this.entityId = entityId; - this.properties = Entities.getEntityProperties(self.entityId); - this.getUserData(); - - //Only activate for the avatar who is grabbing the can! - if (this.userData.grabKey && this.userData.grabKey.activated) { - this.activated = true; - } - if (!this.userData.grabFrame) { - var data = { - relativePosition: { - x: 0, - y: 0, - z: 0 - }, - relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0) - } - setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, this.entityId, data); - } } this.unload = function() { - Script.update.disconnect(this.update); if (this.paintStream) { Entities.deleteEntity(this.paintStream); } @@ -237,7 +180,6 @@ Entities.deleteEntity(stroke); }); } - Script.update.connect(this.update); }); From be1952797c071c609dce76868ad82dd59010ae8d Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 24 Sep 2015 16:31:59 -0700 Subject: [PATCH 068/138] Changes to rotations --- examples/toys/masterResetEntity.js | 82 +++++++++++++++++------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 901777be09..f674e3673d 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -76,6 +76,24 @@ function createAllToys() { //Handles toggling of all sconce lights createLightSwitches(); + + createArmChair({ + x: 549.39, + y: 494.57, + z: 508.37 + }) + + createPillow({ + x: 549.39, + y: 495.00, + z: 508.37 + }); + + createPottedPlant({ + x: 554.26, + y: 495.23, + z: 504.53 + }); } function deleteAllToys() { @@ -527,16 +545,11 @@ function createBlocks(position) { } } -//createPottedPlant,createArmChair,createPillow -function createPottedPlant() { +function createPottedPlant(position) { var modelURL = "https://hifi-public.s3.amazonaws.com/ryan/potted_plant.fbx"; - var position = { - x: 554.26, - y: 495.23, - z: 504.53 - } + var rotation = Quat.fromPitchYawRollDegress(0,0,0); var entity = Entities.addEntity({ type: "Model", @@ -544,7 +557,7 @@ function createPottedPlant() { modelURL: modelURL, position: position, dimensions: { - x: 1.10 + x: 1.10, y: 2.18, z: 1.07 }, @@ -568,34 +581,28 @@ function createPottedPlant() { }); }; -function createArmChair() { - var modelURL = "https://hifi-public.s3.amazonaws.com/ryan/red_arm_chair.fbx"; - var position = { - x: 549.39, - y: 494.57, - z: 508.37 - } - var ARM_CHAIR_COLLISION_SHAPE = ""; + +function createArmChair(position) { + var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair.fbx"; + var RED_ARM_CHAIR_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_collision_hull.obj" + +var rotation = Quat.fromPitchYawRollDegrees(0,-143,0); + var entity = Entities.addEntity({ type: "Model", - name: "Arm Chair", + name: "Red Arm Chair", modelURL: modelURL, - shapeType:'compound', - compoundShapeURL: ARM_CHAIR_COLLISION_SHAPE, + shapeType: 'compound', + compoundShapeURL: RED_ARM_CHAIR_COLLISION_HULL, position: position, - rotation: { - x: 0, - y: -143.01, - z: 0 - }, + rotation:rotation, dimensions: { x: 1.26, y: 1.56, z: 1.35 }, collisionsWillMove: true, - shapeType: 'box', gravity: { x: 0, y: -9.8, @@ -605,7 +612,8 @@ function createArmChair() { x: 0, y: -0.1, z: 0 - } + }, + linearDamping: 0.4 }); setEntityCustomData(resetKey, entity, { @@ -613,25 +621,26 @@ function createArmChair() { }); }; -function createPillow() { - var modelURL = "https://hifi-public.s3.amazonaws.com/ryan/red_arm_chair_pillow.fbx"; - var position = { - x: 549.39, - y: 495.00, - z: 508.37 - } +function createPillow(position) { + var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_pillow.fbx"; + var RED_ARM_CHAIR_PILLOW_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_pillow_collision_hull.obj" + + var rotation = Quat.fromPitchYawRollDegrees(0,-143,0); + var entity = Entities.addEntity({ type: "Model", - name: "Arm Chair Pillow", + name: "Red Arm Chair Pillow", modelURL: modelURL, + shapeType: 'compound', + compoundShapeURL: RED_ARM_CHAIR_PILLOW_COLLISION_HULL, position: position, + rotation:rotation, dimensions: { x: 0.07, y: 0.17, z: 0.07 }, collisionsWillMove: true, - shapeType: 'box', gravity: { x: 0, y: -9.8, @@ -641,7 +650,8 @@ function createPillow() { x: 0, y: -0.1, z: 0 - } + }, + linearDamping:0.4 }); setEntityCustomData(resetKey, entity, { From c2f1141d6915fc3cf998babb5d38af158f1d78b6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Sep 2015 16:40:20 -0700 Subject: [PATCH 069/138] fix cat script --- examples/toys/cat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index 98d08969a7..a71cec95c2 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -29,7 +29,7 @@ startTouch: function() { this.meow(); - } + }, meow: function() { From baf47777506a89f2f55c252db7788070b80b8727 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 24 Sep 2015 17:13:45 -0700 Subject: [PATCH 070/138] Can now hold spray paint can without painting unless squeezing hard --- examples/toys/masterResetEntity.js | 2 +- examples/toys/sprayPaintCan.js | 83 +++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index b7bfc708e3..a2f6c9f233 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -26,7 +26,7 @@ createAllToys(); function createAllToys() { createBlocks({ x: 548.3, y: 495.55, z: 504.4 }); - createSprayCan({ x: 549.8, y: 495.6, z: 503.94 }); + createSprayCan({ x: 549.7, y: 495.6, z: 503.91 }); createBasketBall({ x: 547.73, y: 495.5, z: 505.47}); diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 0508cab038..945dc4322f 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -3,7 +3,6 @@ //Need absolute path for now, for testing before PR merge and s3 cloning. Will change post-merge Script.include("../libraries/utils.js"); - this.userData = {}; this.spraySound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/sprayPaintSound.wav"); @@ -16,6 +15,9 @@ z: 0 } + // if the trigger value goes below this while held, the can will stop spraying. if it goes above, it will spray + var DISABLE_SPRAY_THRESHOLD = 0.7; + var MAX_POINTS_PER_LINE = 40; var MIN_POINT_DISTANCE = 0.01; var STROKE_WIDTH = 0.02; @@ -30,6 +32,24 @@ this.startNearGrab = function() { this.whichHand = this.hand; + } + + this.toggleWithTriggerPressure = function() { + var handClickString = this.whichHand + "_HAND_CLICK"; + + var handClick = Controller.findAction(handClickString); + + this.triggerValue = Controller.getActionValue(handClick); + if (this.triggerValue < DISABLE_SPRAY_THRESHOLD && this.spraying === true) { + this.spraying = false; + this.disableStream(); + } else if (this.triggerValue >= DISABLE_SPRAY_THRESHOLD && this.spraying === false) { + this.spraying = true; + this.enableStream(); + } + } + + this.enableStream = function() { var position = Entities.getEntityProperties(this.entityId, "position").position; var animationSettings = JSON.stringify({ fps: 30, @@ -43,6 +63,7 @@ this.paintStream = Entities.addEntity({ type: "ParticleEffect", + name: "streamEffect", animationSettings: animationSettings, position: position, textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", @@ -52,7 +73,6 @@ emitRate: 100, particleRadius: 0.01, radiusSpread: 0.005, - accelerationSpread: {x: 1, y: 1, x: 1}, color: { red: 170, green: 20, @@ -61,14 +81,23 @@ lifetime: 50, //probably wont be holding longer than this straight }); + setEntityCustomData(this.resetKey, this.paintStream, { + resetMe: true + }); + this.sprayInjector = Audio.playSound(this.spraySound, { position: position, volume: 0.1 }); + } - this.releaseGrab = function() { + this.disableStream(); + } + + this.disableStream = function() { + print("DEKETE STEREAAAM") Entities.deleteEntity(this.paintStream); this.paintStream = null; this.painting = false; @@ -77,21 +106,23 @@ this.continueNearGrab = function() { + + this.toggleWithTriggerPressure(); + + if (this.spraying === false) { + return; + } + var props = Entities.getEntityProperties(this.entityId, ["position, rotation"]); var forwardVec = Quat.getFront(Quat.multiply(props.rotation, Quat.fromPitchYawRollDegrees(0, 90, 0))); forwardVec = Vec3.normalize(forwardVec); - - var forwardQuat = orientationOf(forwardVec); - - var upVec = Quat.getUp(props.rotation); var position = Vec3.sum(props.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z)); position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y)) Entities.editEntity(this.paintStream, { position: position, emitOrientation: forwardQuat, - // emitSpeed: 3 }); //Now check for an intersection with an entity @@ -168,7 +199,9 @@ this.preload = function(entityId) { this.strokes = []; + this.spraying = false; this.entityId = entityId; + this.resetKey = "resetMe"; } @@ -193,23 +226,23 @@ function randInt(min, max) { } function orientationOf(vector) { - var Y_AXIS = { - x: 0, - y: 1, - z: 0 - }; - var X_AXIS = { - x: 1, - y: 0, - z: 0 - }; + var Y_AXIS = { + x: 0, + y: 1, + z: 0 + }; + var X_AXIS = { + x: 1, + y: 0, + z: 0 + }; - var theta = 0.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); + 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); } \ No newline at end of file From 337bdfdaf6c07afea435baa5d2bd28467346151f Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 24 Sep 2015 18:35:26 -0700 Subject: [PATCH 071/138] end of day --- examples/toys/masterResetEntity.js | 47 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index f674e3673d..25e97829ad 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -78,15 +78,15 @@ function createAllToys() { createLightSwitches(); createArmChair({ - x: 549.39, - y: 494.57, - z: 508.37 + x: 549.29, + y: 495.05, + z: 508.22 }) createPillow({ - x: 549.39, - y: 495.00, - z: 508.37 + x: 549.29, + y: 495.25, + z: 508.22 }); createPottedPlant({ @@ -99,7 +99,7 @@ function createAllToys() { 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) { @@ -547,9 +547,9 @@ function createBlocks(position) { function createPottedPlant(position) { - var modelURL = "https://hifi-public.s3.amazonaws.com/ryan/potted_plant.fbx"; + var modelURL = "http://hifi-public.s3.amazonaws.com/models/potted_plant/potted_plant.fbx"; - var rotation = Quat.fromPitchYawRollDegress(0,0,0); + var rotation = Quat.fromPitchYawRollDegress(0, 0, 0); var entity = Entities.addEntity({ type: "Model", @@ -570,7 +570,7 @@ function createPottedPlant(position) { }, velocity: { x: 0, - y: -0.1, + y: 0, z: 0 }, linearDamping: 0.4 @@ -587,7 +587,7 @@ function createArmChair(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair.fbx"; var RED_ARM_CHAIR_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_collision_hull.obj" -var rotation = Quat.fromPitchYawRollDegrees(0,-143,0); + var rotation = Quat.fromPitchYawRollDegrees(0, -143, 0); var entity = Entities.addEntity({ type: "Model", @@ -596,7 +596,7 @@ var rotation = Quat.fromPitchYawRollDegrees(0,-143,0); shapeType: 'compound', compoundShapeURL: RED_ARM_CHAIR_COLLISION_HULL, position: position, - rotation:rotation, + rotation: rotation, dimensions: { x: 1.26, y: 1.56, @@ -605,15 +605,15 @@ var rotation = Quat.fromPitchYawRollDegrees(0,-143,0); collisionsWillMove: true, gravity: { x: 0, - y: -9.8, + y: -0.5, z: 0 }, velocity: { x: 0, - y: -0.1, + y: 0, z: 0 }, - linearDamping: 0.4 + linearDamping: 0.3 }); setEntityCustomData(resetKey, entity, { @@ -624,8 +624,8 @@ var rotation = Quat.fromPitchYawRollDegrees(0,-143,0); function createPillow(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_pillow.fbx"; var RED_ARM_CHAIR_PILLOW_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_pillow_collision_hull.obj" - - var rotation = Quat.fromPitchYawRollDegrees(0,-143,0); + + var rotation = Quat.fromPitchYawRollDegrees(-0.29, -143.05, 0.32); var entity = Entities.addEntity({ type: "Model", @@ -634,16 +634,17 @@ function createPillow(position) { shapeType: 'compound', compoundShapeURL: RED_ARM_CHAIR_PILLOW_COLLISION_HULL, position: position, - rotation:rotation, + rotation: rotation, dimensions: { - x: 0.07, - y: 0.17, - z: 0.07 + x: 0.4, + y: 0.4, + z: 0.4 }, collisionsWillMove: true, + ignoreForCollisions: false, gravity: { x: 0, - y: -9.8, + y: -10.1, z: 0 }, velocity: { @@ -651,7 +652,7 @@ function createPillow(position) { y: -0.1, z: 0 }, - linearDamping:0.4 + linearDamping: 1 }); setEntityCustomData(resetKey, entity, { From 0815b8e939138402fed27ffbcdd0325e0d7ce63b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 10:59:20 -0700 Subject: [PATCH 072/138] Added polar finish to spray paint stream --- examples/toys/sprayPaintCan.js | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 945dc4322f..0cce03de89 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -73,6 +73,7 @@ emitRate: 100, particleRadius: 0.01, radiusSpread: 0.005, + polarFinish: 0.1, color: { red: 170, green: 20, From f4007584e120ff880a40479555e3aba15e9a2269 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 11:02:41 -0700 Subject: [PATCH 073/138] formatted master script --- examples/toys/masterResetEntity.js | 339 +++++++++++++++++++++++------ 1 file changed, 278 insertions(+), 61 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index a2f6c9f233..b65d13a911 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -24,24 +24,54 @@ deleteAllToys(); createAllToys(); function createAllToys() { - createBlocks({ x: 548.3, y: 495.55, z: 504.4 }); + createBlocks({ + x: 548.3, + y: 495.55, + z: 504.4 + }); - createSprayCan({ x: 549.7, y: 495.6, z: 503.91 }); + createSprayCan({ + x: 549.7, + y: 495.6, + z: 503.91 + }); - createBasketBall({ x: 547.73, y: 495.5, z: 505.47}); + createBasketBall({ + x: 547.73, + y: 495.5, + z: 505.47 + }); - createDoll({x: 546.67, y: 495.41, z: 505.09}); + createDoll({ + x: 546.67, + y: 495.41, + z: 505.09 + }); - createWand({ x: 546.71, y: 495.55, z: 506.15}); + createWand({ + x: 546.71, + y: 495.55, + z: 506.15 + }); createDice(); - createFlashlight({ x: 545.72, y: 495.41, z: 505.78 + createFlashlight({ + x: 545.72, + y: 495.41, + z: 505.78 }); - createCat({ x: 551.49859619140625, y: 495.49111938476562, z: 502.26498413085938 }); + createCat({ + x: 551.49859619140625, + y: 495.49111938476562, + z: 502.26498413085938 + }); - createMagballs({ x: 548.73, y: 495.51, z: 503.54 + createMagballs({ + x: 548.73, + y: 495.51, + z: 503.54 }); //Handles toggling of all sconce lights @@ -51,7 +81,7 @@ function createAllToys() { 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) { @@ -69,21 +99,36 @@ function createMagballs(position) { modelURL: modelURL, name: "Tin Can", position: position, - rotation: { w: 0.93041884899139404, x: -1.52587890625e-05, y: 0.36647593975067139, z: -1.52587890625e-05}, - dimensions: { x: 0.16946873068809509, y: 0.21260403096675873, z: 0.16946862637996674 }, + rotation: { + w: 0.93041884899139404, + x: -1.52587890625e-05, + y: 0.36647593975067139, + z: -1.52587890625e-05 + }, + dimensions: { + x: 0.16946873068809509, + y: 0.21260403096675873, + z: 0.16946862637996674 + }, }); - setEntityCustomData(resetKey, tinCan, { resetMe: true }); + setEntityCustomData(resetKey, tinCan, { + resetMe: true + }); - setEntityCustomData("OmniTool", tinCan, { script: "../toys/magBalls.js"}); + setEntityCustomData("OmniTool", tinCan, { + script: "../toys/magBalls.js" + }); } function createCat(position) { var scriptURL = Script.resolvePath("cat.js?v1"); 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 animationSettings = JSON.stringify({ + running: true, + }); var cat = Entities.addEntity({ type: "Model", modelURL: modelURL, @@ -92,11 +137,22 @@ function createCat(position) { 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}, + 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 }); + setEntityCustomData(resetKey, cat, { + resetMe: true + }); } function createFlashlight(position) { @@ -109,14 +165,28 @@ function createFlashlight(position) { name: "flashlight", script: scriptURL, position: position, - dimensions: { x: 0.08, y: 0.30, z: 0.08}, + 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}, + gravity: { + x: 0, + y: -3.5, + z: 0 + }, + velocity: { + x: 0, + y: -0.01, + z: 0 + }, shapeType: 'box', }); - setEntityCustomData(resetKey, flashlight, {resetMe: true}); + setEntityCustomData(resetKey, flashlight, { + resetMe: true + }); } @@ -129,9 +199,22 @@ function createLightSwitches() { modelURL: modelURL, name: "Light Switch Hall", script: scriptURL, - position: {x: 543.27764892578125, y: 495.67999267578125, z: 511.00564575195312}, - rotation: {w: 0.63280689716339111, x: 0.63280689716339111, y: -0.31551080942153931, z: 0.31548023223876953}, - dimensions: {x: 0.10546875, y: 0.032372996211051941, z: 0.16242524981498718} + position: { + x: 543.27764892578125, + y: 495.67999267578125, + z: 511.00564575195312 + }, + rotation: { + w: 0.63280689716339111, + x: 0.63280689716339111, + y: -0.31551080942153931, + z: 0.31548023223876953 + }, + dimensions: { + x: 0.10546875, + y: 0.032372996211051941, + z: 0.16242524981498718 + } }); setEntityCustomData(resetKey, lightSwitchHall, { @@ -145,12 +228,27 @@ function createLightSwitches() { modelURL: modelURL, name: "Light Switch Garage", script: scriptURL, - position: {x: 545.62, y: 495.68,z: 500.21}, - rotation: { w: 0.20082402229309082, x: 0.20082402229309082, y: -0.67800414562225342, z: 0.67797362804412842}, - dimensions: { x:0.10546875, y: 0.032372996211051941, z: 0.16242524981498718} + position: { + x: 545.62, + y: 495.68, + z: 500.21 + }, + rotation: { + w: 0.20082402229309082, + x: 0.20082402229309082, + y: -0.67800414562225342, + z: 0.67797362804412842 + }, + dimensions: { + x: 0.10546875, + y: 0.032372996211051941, + z: 0.16242524981498718 + } }); - setEntityCustomData(resetKey, lightSwitchGarage, {resetMe: true}); + setEntityCustomData(resetKey, lightSwitchGarage, { + resetMe: true + }); } @@ -160,22 +258,46 @@ function createDice() { modelURL: "http://s3.amazonaws.com/hifi-public/models/props/Dice/goldDie.fbx", collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", name: "dice", - position: {x: 541, y: 494.96, z: 509.1}, - dimensions: {x: 0.09, y: 0.09, z: 0.09}, - gravity: {x: 0, y: -3.5, z: 0}, - velocity: {x: 0,y: -0.01, z: 0}, + position: { + x: 541, + y: 494.96, + z: 509.1 + }, + dimensions: { + x: 0.09, + y: 0.09, + z: 0.09 + }, + gravity: { + x: 0, + y: -3.5, + z: 0 + }, + velocity: { + x: 0, + y: -0.01, + z: 0 + }, shapeType: "box", collisionsWillMove: true }; var dice1 = Entities.addEntity(diceProps); - diceProps.position = { x: 541.05, y: 494.96, z: 509.0 }; + diceProps.position = { + x: 541.05, + y: 494.96, + z: 509.0 + }; var dice2 = Entities.addEntity(diceProps); - setEntityCustomData(resetKey, dice1, {resetMe: true}); + setEntityCustomData(resetKey, dice1, { + resetMe: true + }); - setEntityCustomData(resetKey, dice2, {resetMe: true}); + setEntityCustomData(resetKey, dice2, { + resetMe: true + }); } function createWand(position) { @@ -189,8 +311,16 @@ function createWand(position) { type: "Model", modelURL: WAND_MODEL, position: position, - gravity: {x: 0, y: 0, z: 0}, - dimensions: { x: 0.05, y: 0.25,z: 0.05}, + gravity: { + x: 0, + y: 0, + z: 0 + }, + dimensions: { + x: 0.05, + y: 0.25, + z: 0.05 + }, //must be enabled to be grabbable in the physics engine collisionsWillMove: true, compoundShapeURL: WAND_COLLISION_SHAPE, @@ -200,7 +330,9 @@ function createWand(position) { script: scriptURL }); - setEntityCustomData(resetKey, entity, {resetMe: true}); + setEntityCustomData(resetKey, entity, { + resetMe: true + }); } function createBasketBall(position) { @@ -214,22 +346,40 @@ function createBasketBall(position) { collisionsWillMove: true, shapeType: "sphere", name: "basketball", - dimensions: {x: 0.25, y: 0.26, z: 0.25}, - gravity: {x: 0, y: -7, z: 0}, + dimensions: { + x: 0.25, + y: 0.26, + z: 0.25 + }, + gravity: { + x: 0, + y: -7, + z: 0 + }, restitution: 10, linearDamping: 0.0, - velocity: { x: 0, y: -0.01, z: 0}, + velocity: { + x: 0, + y: -0.01, + z: 0 + }, collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/basketball/basketball.wav" }); - setEntityCustomData(resetKey, entity, {resetMe: true}); + setEntityCustomData(resetKey, entity, { + resetMe: true + }); } function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; var scriptURL = Script.resolvePath("doll/doll.js"); - var naturalDimensions = {x: 1.63, y: 1.67, z: 0.26}; + var naturalDimensions = { + x: 1.63, + y: 1.67, + z: 0.26 + }; var desiredDimensions = Vec3.multiply(naturalDimensions, 0.15); var entity = Entities.addEntity({ type: "Model", @@ -239,12 +389,22 @@ function createDoll(position) { position: position, shapeType: 'box', dimensions: desiredDimensions, - gravity: {x: 0, y: -5, z: 0}, - velocity: {x: 0, y: -0.1, z: 0}, + gravity: { + x: 0, + y: -5, + z: 0 + }, + velocity: { + x: 0, + y: -0.1, + z: 0 + }, collisionsWillMove: true }); - setEntityCustomData(resetKey, entity, {resetMe: true}); + setEntityCustomData(resetKey, entity, { + resetMe: true + }); } function createSprayCan(position) { @@ -256,15 +416,29 @@ function createSprayCan(position) { name: "spraycan", modelURL: modelURL, position: position, - dimensions: {x: 0.07, y: 0.17, z: 0.07}, + dimensions: { + x: 0.07, + y: 0.17, + z: 0.07 + }, collisionsWillMove: true, shapeType: 'box', script: scriptURL, - gravity: {x: 0, y: -0.5, z: 0}, - velocity: { x: 0, y: -1, z: 0} + gravity: { + x: 0, + y: -0.5, + z: 0 + }, + velocity: { + x: 0, + y: -1, + z: 0 + } }); - setEntityCustomData(resetKey, entity, {resetMe: true}); + setEntityCustomData(resetKey, entity, { + resetMe: true + }); } @@ -273,13 +447,42 @@ function createBlocks(position) { var NUM_BLOCKS_PER_COLOR = 4; var i, j; - var blockTypes = [ - { url: "planky_blue.fbx", dimensions: {x: 0.05, y: 0.05, z: 0.25} }, - { url: "planky_green.fbx", dimensions: {x: 0.1, y: 0.1, z: 0.25} }, - { url: "planky_natural.fbx", dimensions: { x: 0.05, y: 0.05, z: 0.05} }, - { url: "planky_yellow.fbx", dimensions: {x: 0.03, y: 0.05, z: 0.25} }, - { url: "planky_red.fbx", dimensions: {x: 0.1, y: 0.05, z: 0.25} }, - ]; + var blockTypes = [{ + url: "planky_blue.fbx", + dimensions: { + x: 0.05, + y: 0.05, + z: 0.25 + } + }, { + url: "planky_green.fbx", + dimensions: { + x: 0.1, + y: 0.1, + z: 0.25 + } + }, { + url: "planky_natural.fbx", + dimensions: { + x: 0.05, + y: 0.05, + z: 0.05 + } + }, { + url: "planky_yellow.fbx", + dimensions: { + x: 0.03, + y: 0.05, + z: 0.25 + } + }, { + url: "planky_red.fbx", + dimensions: { + x: 0.1, + y: 0.05, + z: 0.25 + } + }, ]; var modelURL, entity; for (i = 0; i < blockTypes.length; i++) { @@ -288,17 +491,31 @@ function createBlocks(position) { entity = Entities.addEntity({ type: "Model", modelURL: modelURL, - position: Vec3.sum(position, { x: j / 10, y: i / 10, z: 0}), + position: Vec3.sum(position, { + x: j / 10, + y: i / 10, + z: 0 + }), shapeType: 'box', name: "block", dimensions: blockTypes[i].dimensions, collisionsWillMove: true, - gravity: {x: 0, y: -2.5, z: 0}, - velocity: { x: 0, y: -0.01, z: 0} + gravity: { + x: 0, + y: -2.5, + z: 0 + }, + velocity: { + x: 0, + y: -0.01, + z: 0 + } }); //customKey, id, data - setEntityCustomData(resetKey, entity, {resetMe: true}); + setEntityCustomData(resetKey, entity, { + resetMe: true + }); } } } From a62970136282a22d062468660d4f9c17c716991f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 11:15:19 -0700 Subject: [PATCH 074/138] couch --- examples/toys/masterResetEntity.js | 134 +++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index b65d13a911..d039bfbb6e 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -74,6 +74,24 @@ function createAllToys() { z: 503.54 }); + createArmChair({ + x: 549.29, + y: 495.05, + z: 508.22 + }) + + createPillow({ + x: 549.29, + y: 495.35, + z: 508.22 + }); + + createPottedPlant({ + x: 554.26, + y: 495.23, + z: 504.53 + }); + //Handles toggling of all sconce lights createLightSwitches(); } @@ -442,6 +460,122 @@ function createSprayCan(position) { } +//createPottedPlant,createArmChair,createPillow +function createPottedPlant(position) { + var modelURL = "http://hifi-public.s3.amazonaws.com/models/potted_plant/potted_plant.fbx"; + + var rotation = Quat.fromPitchYawRollDegress(0, 0, 0); + + var entity = Entities.addEntity({ + type: "Model", + name: "Potted Plant", + modelURL: modelURL, + position: position, + dimensions: { + x: 1.10, + y: 2.18, + z: 1.07 + }, + collisionsWillMove: true, + shapeType: 'box', + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + velocity: { + x: 0, + y: 0, + z: 0 + }, + linearDamping: 0.4 + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +}; + + + +function createArmChair(position) { + var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair.fbx"; + var RED_ARM_CHAIR_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_collision_hull.obj" + + var rotation = Quat.fromPitchYawRollDegrees(0, -143, 0); + + var entity = Entities.addEntity({ + type: "Model", + name: "Red Arm Chair", + modelURL: modelURL, + shapeType: 'compound', + compoundShapeURL: RED_ARM_CHAIR_COLLISION_HULL, + position: position, + rotation: rotation, + dimensions: { + x: 1.26, + y: 1.56, + z: 1.35 + }, + collisionsWillMove: true, + gravity: { + x: 0, + y: -0.5, + z: 0 + }, + velocity: { + x: 0, + y: 0, + z: 0 + }, + linearDamping: 0.3 + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +}; + +function createPillow(position) { + var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_pillow.fbx"; + var RED_ARM_CHAIR_PILLOW_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_pillow_collision_hull.obj" + + var rotation = Quat.fromPitchYawRollDegrees(-0.29, -143.05, 0.32); + + var entity = Entities.addEntity({ + type: "Model", + name: "Red Arm Chair Pillow", + modelURL: modelURL, + shapeType: 'compound', + compoundShapeURL: RED_ARM_CHAIR_PILLOW_COLLISION_HULL, + position: position, + rotation: rotation, + dimensions: { + x: 0.4, + y: 0.4, + z: 0.4 + }, + collisionsWillMove: true, + ignoreForCollisions: false, + gravity: { + x: 0, + y: -10.1, + z: 0 + }, + restitution: 0, + velocity: { + x: 0, + y: -0.1, + z: 0 + }, + linearDamping: 1 + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +}; + function createBlocks(position) { var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/"; var NUM_BLOCKS_PER_COLOR = 4; From d29c337e9549a7feb299ab288aadee3e5abd289a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 11:32:41 -0700 Subject: [PATCH 075/138] moved light switches up --- examples/toys/masterResetEntity.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index d039bfbb6e..b5f08a75d5 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -68,6 +68,9 @@ function createAllToys() { z: 502.26498413085938 }); + //Handles toggling of all sconce lights + createLightSwitches(); + createMagballs({ x: 548.73, y: 495.51, @@ -92,8 +95,7 @@ function createAllToys() { z: 504.53 }); - //Handles toggling of all sconce lights - createLightSwitches(); + } function deleteAllToys() { From 7789d8b3a8c77761c2b8a3f4f0a30adb43144de7 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 11:37:04 -0700 Subject: [PATCH 076/138] fixed potted plant bug --- examples/toys/masterResetEntity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index b5f08a75d5..3ee991ea4c 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -466,7 +466,7 @@ function createSprayCan(position) { function createPottedPlant(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/potted_plant/potted_plant.fbx"; - var rotation = Quat.fromPitchYawRollDegress(0, 0, 0); + var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); var entity = Entities.addEntity({ type: "Model", From ccc6a343fcd0a72842de07ce3095a5e8c230da7d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 11:49:51 -0700 Subject: [PATCH 077/138] updated lights to use newly named grab events --- examples/controllers/handControllerGrab.js | 1 + examples/toys/lightSwitchGarage.js | 2 +- examples/toys/lightSwitchHall.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index ce2f1b5249..09b73e6808 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -371,6 +371,7 @@ function MyController(hand, triggerAction) { this.state = STATE_RELEASE; return; } + print("JAYKJAGHKJAHKJAHKJAHKJ") Entities.callEntityMethod(this.grabbedEntity, "startNearGrabNonColliding"); this.state = STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING; }; diff --git a/examples/toys/lightSwitchGarage.js b/examples/toys/lightSwitchGarage.js index 99d827aa06..5f302ff47e 100644 --- a/examples/toys/lightSwitchGarage.js +++ b/examples/toys/lightSwitchGarage.js @@ -37,7 +37,7 @@ this.toggleLights(); }, - startNearTouch: function() { + startNearGrabNonColliding: function() { this.toggleLights(); }, diff --git a/examples/toys/lightSwitchHall.js b/examples/toys/lightSwitchHall.js index 49ccc51b79..4dd1a867de 100644 --- a/examples/toys/lightSwitchHall.js +++ b/examples/toys/lightSwitchHall.js @@ -37,7 +37,7 @@ this.toggleLights(); }, - startNearTouch: function() { + startNearGrabNonColliding: function() { this.toggleLights(); }, From 65169da64d042a8e4540bebdaf8936f937ba6ca5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 11:58:05 -0700 Subject: [PATCH 078/138] removed old doll script --- examples/toys/doll.js | 73 ------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 examples/toys/doll.js diff --git a/examples/toys/doll.js b/examples/toys/doll.js deleted file mode 100644 index 708d6200b1..0000000000 --- a/examples/toys/doll.js +++ /dev/null @@ -1,73 +0,0 @@ -// -// doll.js -// examples/toybox/entityScripts -// -// Created by Eric Levin on 9/21/15. -// Copyright 2015 High Fidelity, Inc. -// -// This entity script breathes movement and sound- one might even say life- into a doll. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -(function() { - - var _this; - HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; - - // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember - // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) - Doll = function() { - _this = this; - var screamSoundDirectory = HIFI_PUBLIC_BUCKET + "eric/sounds/" - this.screamSounds = [SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/KenDoll_1%2303.wav")]; - this.startAnimationSetting = JSON.stringify({ - running: true, - startFrame: 0, - lastFrame: 128 - }); - - this.stopAnimationSetting = JSON.stringify({ - running: false, - }); - }; - - Doll.prototype = { - - - startNearGrab: function() { - Entities.editEntity(this.entityID, { - animationURL: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", - animationSettings: this.startAnimationSetting - }); - - var position = Entities.getEntityProperties(this.entityID, "position").position; - Audio.playSound(this.screamSounds[randInt(0, this.screamSounds.length)], { - position: position, - volume: 0.1 - }); - - }, - - releaseGrab: function() { - Entities.editEntity(this.entityID, { - animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx", - // animationSettings: this.stopAnimationSetting, - // animationFrameIndex: 0 - }); - }, - - - // preload() will be called when the entity has become visible (or known) to the interface - // it gives us a chance to set our local JavaScript object up. In this case it means: - // * remembering our entityID, so we can access it in cases where we're called without an entityID - // * connecting to the update signal so we can check our grabbed state - preload: function(entityID) { - this.entityID = entityID; - }, - }; - - // entity scripts always need to return a newly constructed object of our type - return new Doll(); -}) From f5e44675bb8493e54ffb9744918647066c8271b3 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 12:11:22 -0700 Subject: [PATCH 079/138] removed start and end frame --- examples/toys/doll/doll.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index f97b6de378..09dd06a2ec 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -25,8 +25,8 @@ startAnimationSetting: JSON.stringify({ running: true, fps: 30, - startFrame: 0, - lastFrame: 128, + // startFrame: 0, + // lastFrame: 128, startAutomatically: true }), stopAnimationSetting: JSON.stringify({running: false}), From c53ad3c5340e3821cbd070ff3ffacedf40d7dd82 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 12:34:35 -0700 Subject: [PATCH 080/138] combined arm chair --- examples/toys/doll/doll.js | 9 ++++-- examples/toys/masterResetEntity.js | 51 ++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index 09dd06a2ec..62eac78166 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -25,11 +25,14 @@ startAnimationSetting: JSON.stringify({ running: true, fps: 30, - // startFrame: 0, - // lastFrame: 128, + firstFrame: 0, + lastFrame: 120, startAutomatically: true }), - stopAnimationSetting: JSON.stringify({running: false}), + stopAnimationSetting: JSON.stringify({ + running: false, + frameIndex: 0 + }), audioInjector: null, isGrabbed: false, setLeftHand: function() { diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 3ee991ea4c..2e7f9bdae3 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -77,17 +77,17 @@ function createAllToys() { z: 503.54 }); - createArmChair({ + createCombinedArmChair({ x: 549.29, y: 495.05, z: 508.22 }) - createPillow({ - x: 549.29, - y: 495.35, - z: 508.22 - }); + // createPillow({ + // x: 549.29, + // y: 495.35, + // z: 508.22 + // }); createPottedPlant({ x: 554.26, @@ -393,7 +393,7 @@ function createBasketBall(position) { function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; - var scriptURL = Script.resolvePath("doll/doll.js"); + var scriptURL = Script.resolvePath("doll/doll.js?v2"+ Math.random()); var naturalDimensions = { x: 1.63, @@ -499,6 +499,43 @@ function createPottedPlant(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" + + var rotation = Quat.fromPitchYawRollDegrees(0, -143, 0); + + var entity = Entities.addEntity({ + type: "Model", + name: "Red Arm Chair", + modelURL: modelURL, + shapeType: 'compound', + compoundShapeURL: RED_ARM_CHAIR_COLLISION_HULL, + position: position, + rotation: rotation, + dimensions: { + x: 1.26, + y: 1.56, + z: 1.35 + }, + collisionsWillMove: true, + gravity: { + x: 0, + y: -0.8, + z: 0 + }, + velocity: { + x: 0, + y: 0, + z: 0 + }, + linearDamping: 0.2 + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +}; function createArmChair(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair.fbx"; From e94d9b39fdb0413a405cd7f2524f2e079316f625 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 15:42:13 -0700 Subject: [PATCH 081/138] made pots and chair not grabbable --- examples/toys/doll/doll.js | 12 ++++++------ examples/toys/masterResetEntity.js | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index 62eac78166..e81f3e0c0e 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -25,13 +25,12 @@ startAnimationSetting: JSON.stringify({ running: true, fps: 30, - firstFrame: 0, - lastFrame: 120, - startAutomatically: true + // firstFrame: 1, + // lastFrame: 120, }), stopAnimationSetting: JSON.stringify({ running: false, - frameIndex: 0 + frameIndex: 1 }), audioInjector: null, isGrabbed: false, @@ -74,10 +73,11 @@ if (this.isGrabbed === true && this.hand === this.initialHand) { this.audioInjector.stop(); - + print("STTTOP ANIMATION") Entities.editEntity(this.entityID, { animationSettings: this.stopAnimationSetting, - animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx", + animationIsPlaying: false + // animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx", }); this.isGrabbed = false; } diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 2e7f9bdae3..88a71cd58e 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -13,6 +13,7 @@ var utilitiesScript = Script.resolvePath("../libraries/utils.js"); Script.include(utilitiesScript); var resetKey = "resetMe"; +var GRABBABLE_DATA_KEY = "grabbableKey"; var HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; @@ -68,7 +69,7 @@ function createAllToys() { z: 502.26498413085938 }); - //Handles toggling of all sconce lights + //Handles toggling of all sconce lights createLightSwitches(); createMagballs({ @@ -393,7 +394,7 @@ function createBasketBall(position) { function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; - var scriptURL = Script.resolvePath("doll/doll.js?v2"+ Math.random()); + var scriptURL = Script.resolvePath("doll/doll.js?v2" + Math.random()); var naturalDimensions = { x: 1.63, @@ -496,6 +497,11 @@ function createPottedPlant(position) { setEntityCustomData(resetKey, entity, { resetMe: true }); + + + setEntityCustomData(GRABBABLE_DATA_KEY, entity, { + grabbable: false + }); }; @@ -535,6 +541,10 @@ function createCombinedArmChair(position) { setEntityCustomData(resetKey, entity, { resetMe: true }); + + setEntityCustomData(GRABBABLE_DATA_KEY, entity, { + grabbable: false + }); }; function createArmChair(position) { From 534cffcf85d83ab1880701812dfe64e5d2f24b8d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 16:23:35 -0700 Subject: [PATCH 082/138] fixed animation bug with doll --- examples/toys/doll/doll.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index e81f3e0c0e..f0b789273c 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -25,12 +25,14 @@ startAnimationSetting: JSON.stringify({ running: true, fps: 30, - // firstFrame: 1, - // lastFrame: 120, + loop: false, + firstFrame: 1, + lastFrame: 120, }), stopAnimationSetting: JSON.stringify({ running: false, - frameIndex: 1 + frameIndex: 1, + lastFrame: 10000 }), audioInjector: null, isGrabbed: false, @@ -73,13 +75,14 @@ if (this.isGrabbed === true && this.hand === this.initialHand) { this.audioInjector.stop(); - print("STTTOP ANIMATION") Entities.editEntity(this.entityID, { animationSettings: this.stopAnimationSetting, - animationIsPlaying: false - // animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx", + animationIsPlaying: false, + animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx", }); this.isGrabbed = false; + + var frameIndex = Entities.getEntityProperties(this.entityID, {}) } }, From bcd21714910d5f115692964120a4e99557c039fa Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 25 Sep 2015 16:28:12 -0700 Subject: [PATCH 083/138] updated chair model --- examples/toys/masterResetEntity.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 88a71cd58e..5a8732e348 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -548,8 +548,8 @@ function createCombinedArmChair(position) { }; function createArmChair(position) { - var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair.fbx"; - var RED_ARM_CHAIR_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_collision_hull.obj" + var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/new_red_arm_chair.fbx"; + var RED_ARM_CHAIR_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/new_red_arm_chair_collision_hull.obj" var rotation = Quat.fromPitchYawRollDegrees(0, -143, 0); From bab3c6fcf217ec80d56bd05e3e08841f60f9ef38 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 28 Sep 2015 09:31:11 -0700 Subject: [PATCH 084/138] adjust lastFrame --- examples/toys/doll/doll.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index f0b789273c..3d1fed5bbb 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -26,8 +26,9 @@ running: true, fps: 30, loop: false, - firstFrame: 1, - lastFrame: 120, + // firstFrame: 1, + // lastFrame: 65, + startAutomatically: true }), stopAnimationSetting: JSON.stringify({ running: false, From 660490d754d6cad57272d85eee682443c598d17d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 28 Sep 2015 10:29:12 -0700 Subject: [PATCH 085/138] removed magBalls --- examples/toys/masterResetEntity.js | 37 +----------------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 5a8732e348..46a9bbe788 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -72,11 +72,7 @@ function createAllToys() { //Handles toggling of all sconce lights createLightSwitches(); - createMagballs({ - x: 548.73, - y: 495.51, - z: 503.54 - }); + createCombinedArmChair({ x: 549.29, @@ -111,37 +107,6 @@ function deleteAllToys() { }); } -function createMagballs(position) { - - - var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/tin2.fbx"; - var tinCan = Entities.addEntity({ - type: "Model", - modelURL: modelURL, - name: "Tin Can", - position: position, - rotation: { - w: 0.93041884899139404, - x: -1.52587890625e-05, - y: 0.36647593975067139, - z: -1.52587890625e-05 - }, - dimensions: { - x: 0.16946873068809509, - y: 0.21260403096675873, - z: 0.16946862637996674 - }, - }); - - - setEntityCustomData(resetKey, tinCan, { - resetMe: true - }); - - setEntityCustomData("OmniTool", tinCan, { - script: "../toys/magBalls.js" - }); -} function createCat(position) { var scriptURL = Script.resolvePath("cat.js?v1"); From 45281f8aae296b6d9c933250a3a003f174042b5b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 28 Sep 2015 10:34:03 -0700 Subject: [PATCH 086/138] modified spraypaint can to spray out particles but no paint --- examples/toys/sprayPaintCan.js | 71 +--------------------------------- 1 file changed, 1 insertion(+), 70 deletions(-) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 0cce03de89..526e5e4ea4 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -101,7 +101,6 @@ print("DEKETE STEREAAAM") Entities.deleteEntity(this.paintStream); this.paintStream = null; - this.painting = false; this.sprayInjector.stop(); } @@ -125,81 +124,13 @@ position: position, emitOrientation: forwardQuat, }); - - //Now check for an intersection with an entity - //move forward so ray doesnt intersect with gun - var origin = Vec3.sum(position, forwardVec); - var pickRay = { - origin: origin, - direction: Vec3.multiply(forwardVec, 2) - } - - var intersection = Entities.findRayIntersection(pickRay, true); - if (intersection.intersects) { - var normal = Vec3.multiply(-1, Quat.getFront(intersection.properties.rotation)); - this.paint(intersection.intersection, normal); - } } - this.paint = function(position, normal) { - if (!this.painting) { - - this.newStroke(position); - this.painting = true; - } - - if (this.strokePoints.length > MAX_POINTS_PER_LINE) { - this.painting = false; - return; - } - - var localPoint = Vec3.subtract(position, this.strokeBasePosition); - //Move stroke a bit forward along normal so it doesnt zfight with mesh its drawing on - localPoint = Vec3.sum(localPoint, Vec3.multiply(normal, .1)); - - if (this.strokePoints.length > 0 && Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]) < MIN_POINT_DISTANCE) { - //need a minimum distance to avoid binormal NANs - return; - } - - this.strokePoints.push(localPoint); - this.strokeNormals.push(normal); - this.strokeWidths.push(STROKE_WIDTH); - Entities.editEntity(this.currentStroke, { - linePoints: this.strokePoints, - normals: this.strokeNormals, - strokeWidths: this.strokeWidths - }); - } - - this.newStroke = function(position) { - this.strokeBasePosition = position; - this.currentStroke = Entities.addEntity({ - position: position, - type: "PolyLine", - color: { - red: randInt(160, 250), - green: randInt(10, 20), - blue: randInt(190, 250) - }, - dimensions: { - x: 50, - y: 50, - z: 50 - }, - lifetime: 100 - }); - this.strokePoints = []; - this.strokeNormals = []; - this.strokeWidths = []; - - this.strokes.push(this.currentStroke); - } + this.preload = function(entityId) { - this.strokes = []; this.spraying = false; this.entityId = entityId; this.resetKey = "resetMe"; From 09a53d553af341eff20a7b3d8a89e0a50bf7f0a3 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Mon, 28 Sep 2015 15:55:25 -0700 Subject: [PATCH 087/138] Add fences to Toybox master script, add gravity to bubble wand --- examples/toys/masterResetEntity.js | 84 ++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 4 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 46a9bbe788..996a9b40b9 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -8,7 +8,7 @@ /*global deleteAllToys, print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ //per script -/*global createAllToys, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLightSwitches */ +/*global createAllToys, createGates, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLightSwitches */ var utilitiesScript = Script.resolvePath("../libraries/utils.js"); Script.include(utilitiesScript); @@ -92,7 +92,7 @@ function createAllToys() { z: 504.53 }); - + createGates(); } function deleteAllToys() { @@ -286,10 +286,85 @@ function createDice() { }); } + +function createGates() { + var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/ryan/fence.fbx'; + + var rotation1 = Quat.fromPitchYawRollDegrees(0, 36, 0); + var gate1 = Entities.addEntity({ + name: 'Back Door Gate', + position: { + x: 546.52, + y: 494.76, + z: 498.93 + }, + dimensions: { + x: 1.42, + y: 1.13, + z: 0.02 + }, + rotation: rotation1, + collisionsWillMove: true, + gravity: { + x: 0, + y: -0.8, + z: 0 + }, + velocity: { + x: 0, + y: 0, + z: 0 + }, + linearDamping: 0.2 + }); + + setEntityCustomData(resetKey, gate1, { + resetMe: true + }); + + setEntityCustomData(GRABBABLE_DATA_KEY, gate1, { + grabbable: false + }); + var rotation2 = Quat.fromPitchYawRollDegrees(0, -16, 0); + var gate2 = Entities.addEntity({ + name: 'Front Door Fence', + position: { + x: 531.15, + y: 495.11, + z: 520.20 + }, + dimensions: { + x: 1.42, + y: 1.13, + z: 0.02 + }, + rotation: rotation2, + collisionsWillMove: true, + gravity: { + x: 0, + y: -0.8, + z: 0 + }, + velocity: { + x: 0, + y: 0, + z: 0 + }, + linearDamping: 0.2 + }); + + setEntityCustomData(resetKey, gate2, { + resetMe: true + }); + + setEntityCustomData(GRABBABLE_DATA_KEY, gate2, { + grabbable: false + }); +} + 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/collisionHull.obj'; - //Just using abs path for demo purposes on sunday, since this PR for wand has not been merged var scriptURL = Script.resolvePath("bubblewand/wand.js"); var entity = Entities.addEntity({ @@ -299,7 +374,7 @@ function createWand(position) { position: position, gravity: { x: 0, - y: 0, + y: -9.8, z: 0 }, dimensions: { @@ -308,6 +383,7 @@ function createWand(position) { z: 0.05 }, //must be enabled to be grabbable in the physics engine + shapeType: 'compound', collisionsWillMove: true, compoundShapeURL: WAND_COLLISION_SHAPE, //Look into why bubble wand is going through table when gravity is enabled From f79414649ec53ca6ab2dae68b3fb34853ad36c7b Mon Sep 17 00:00:00 2001 From: James Pollack Date: Mon, 28 Sep 2015 15:57:53 -0700 Subject: [PATCH 088/138] add gravity to fences --- examples/toys/masterResetEntity.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 996a9b40b9..cba5424d58 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -307,7 +307,7 @@ function createGates() { collisionsWillMove: true, gravity: { x: 0, - y: -0.8, + y: -9.8, z: 0 }, velocity: { @@ -342,7 +342,7 @@ function createGates() { collisionsWillMove: true, gravity: { x: 0, - y: -0.8, + y: -9.8, z: 0 }, velocity: { From 5e28462e2ac62235f7dce1e1c6e39316485907a9 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 28 Sep 2015 16:51:23 -0700 Subject: [PATCH 089/138] testing doll animation --- examples/toys/doll/doll.js | 62 +++++++++++++++--------------- examples/toys/masterResetEntity.js | 16 ++++---- examples/toys/sprayPaintCan.js | 3 +- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index 3d1fed5bbb..429274de04 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -15,26 +15,14 @@ (function() { Script.include("../../utilities.js"); Script.include("../../libraries/utils.js"); - + var _this; // this is the "constructor" for the entity as a JS object we don't do much here var Doll = function() { + _this = this; this.screamSounds = [SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/KenDoll_1%2303.wav")]; }; Doll.prototype = { - startAnimationSetting: JSON.stringify({ - running: true, - fps: 30, - loop: false, - // firstFrame: 1, - // lastFrame: 65, - startAutomatically: true - }), - stopAnimationSetting: JSON.stringify({ - running: false, - frameIndex: 1, - lastFrame: 10000 - }), audioInjector: null, isGrabbed: false, setLeftHand: function() { @@ -46,41 +34,50 @@ }, startNearGrab: function() { - if (this.isGrabbed === false) { + // if (this.isGrabbed === false) { + print("START GRAB") + Entities.editEntity(this.entityID, { + animationURL: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", + animationFrameIndex: 0 + }); - Entities.editEntity(this.entityID, { - animationURL: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", - animationSettings: this.startAnimationSetting - }); + Entities.editEntity(_this.entityID, { + animationIsPlaying: true + }) - var position = Entities.getEntityProperties(this.entityID, "position").position; - this.audioInjector = Audio.playSound(this.screamSounds[randInt(0, this.screamSounds.length)], { - position: position, - volume: 0.1 - }); + var position = Entities.getEntityProperties(this.entityID, "position").position; + this.audioInjector = Audio.playSound(this.screamSounds[randInt(0, this.screamSounds.length)], { + position: position, + volume: 0.1 + }); - this.isGrabbed = true; - this.initialHand = this.hand; - } + this.isGrabbed = true; + this.initialHand = this.hand; }, continueNearGrab: function() { - var props = Entities.getEntityProperties(this.entityID, "position"); + var props = Entities.getEntityProperties(this.entityID, ["position", "animationFrameIndex"]); var audioOptions = { position: props.position }; this.audioInjector.options = audioOptions; + // print("ANIMATION FRAME INDEX " + props.animationFrameIndex) + }, releaseGrab: function() { if (this.isGrabbed === true && this.hand === this.initialHand) { - + print("RELEASE GRAB") this.audioInjector.stop(); Entities.editEntity(this.entityID, { - animationSettings: this.stopAnimationSetting, - animationIsPlaying: false, - animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx", + // animationSettings: this.stopAnimationSetting, + animationFrameIndex: 0 }); + + Entities.editEntity(this.entityID, { + animationURL: "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx" + }); + this.isGrabbed = false; var frameIndex = Entities.getEntityProperties(this.entityID, {}) @@ -92,6 +89,7 @@ // it gives us a chance to set our local JavaScript object up. In this case it means: // * remembering our entityID, so we can access it in cases where we're called without an entityID this.entityID = entityID; + this.lastFrame = 80; }, }; // entity scripts always need to return a newly constructed object of our type diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 46a9bbe788..cb0325b30d 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -25,11 +25,11 @@ deleteAllToys(); createAllToys(); function createAllToys() { - createBlocks({ - x: 548.3, - y: 495.55, - z: 504.4 - }); + // createBlocks({ + // x: 548.3, + // y: 495.55, + // z: 504.4 + // }); createSprayCan({ x: 549.7, @@ -661,9 +661,9 @@ function createBlocks(position) { }); //customKey, id, data - setEntityCustomData(resetKey, entity, { - resetMe: true - }); + // setEntityCustomData(resetKey, entity, { + // resetMe: true + // }); } } } diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 526e5e4ea4..2dc49b4f63 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -13,7 +13,7 @@ x: 0, y: 0, z: 0 - } + }; // if the trigger value goes below this while held, the can will stop spraying. if it goes above, it will spray var DISABLE_SPRAY_THRESHOLD = 0.7; @@ -98,7 +98,6 @@ } this.disableStream = function() { - print("DEKETE STEREAAAM") Entities.deleteEntity(this.paintStream); this.paintStream = null; this.sprayInjector.stop(); From a21530282b8969aff967816a953c6d0be3f739a4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 28 Sep 2015 16:56:46 -0700 Subject: [PATCH 090/138] logging frame --- examples/toys/doll/doll.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index 429274de04..8cdcd9329e 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -61,7 +61,7 @@ position: props.position }; this.audioInjector.options = audioOptions; - // print("ANIMATION FRAME INDEX " + props.animationFrameIndex) + print("ANIMATION FRAME INDEX " + props.animationFrameIndex) }, From afcd59a549596b2afc2f9b8bfae508c845c66e21 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 28 Sep 2015 17:04:03 -0700 Subject: [PATCH 091/138] Moved cat to stool --- examples/toys/masterResetEntity.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index cb0325b30d..6397066bcc 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -64,9 +64,9 @@ function createAllToys() { }); createCat({ - x: 551.49859619140625, - y: 495.49111938476562, - z: 502.26498413085938 + x: 551.09, + y: 494.98, + z: 503.49 }); //Handles toggling of all sconce lights From d47f938f8d6721400399147203bb0c3789ee849f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 28 Sep 2015 17:05:58 -0700 Subject: [PATCH 092/138] blocks --- examples/toys/masterResetEntity.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 6397066bcc..f4fbce2b1b 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -25,11 +25,11 @@ deleteAllToys(); createAllToys(); function createAllToys() { - // createBlocks({ - // x: 548.3, - // y: 495.55, - // z: 504.4 - // }); + createBlocks({ + x: 548.3, + y: 495.55, + z: 504.4 + }); createSprayCan({ x: 549.7, @@ -660,10 +660,10 @@ function createBlocks(position) { } }); - //customKey, id, data - // setEntityCustomData(resetKey, entity, { - // resetMe: true - // }); + customKey, id, data + setEntityCustomData(resetKey, entity, { + resetMe: true + }); } } } From 3f83d5a99afde6a1bbc732140ee15a4ada80f90d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 28 Sep 2015 17:14:35 -0700 Subject: [PATCH 093/138] Animation playing for doll, but looping --- examples/toys/doll/doll.js | 2 -- examples/toys/masterResetEntity.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index 8cdcd9329e..eeb4f8ee8a 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -61,7 +61,6 @@ position: props.position }; this.audioInjector.options = audioOptions; - print("ANIMATION FRAME INDEX " + props.animationFrameIndex) }, @@ -89,7 +88,6 @@ // it gives us a chance to set our local JavaScript object up. In this case it means: // * remembering our entityID, so we can access it in cases where we're called without an entityID this.entityID = entityID; - this.lastFrame = 80; }, }; // entity scripts always need to return a newly constructed object of our type diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index f4fbce2b1b..92f32bbb74 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -660,7 +660,7 @@ function createBlocks(position) { } }); - customKey, id, data + //customKey, id, data setEntityCustomData(resetKey, entity, { resetMe: true }); From 04d797e964c7e4979667b42c9942222ca657d6f5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 28 Sep 2015 17:59:42 -0700 Subject: [PATCH 094/138] paint can --- examples/toys/masterResetEntity.js | 4 +- examples/toys/sprayPaintCan.js | 91 +++++++++++++++++++++++++++--- 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 92f32bbb74..c34d8d1e22 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -359,7 +359,7 @@ function createBasketBall(position) { function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; - var scriptURL = Script.resolvePath("doll/doll.js?v2" + Math.random()); + var scriptURL = Script.resolvePath("doll/doll.js?v2"); var naturalDimensions = { x: 1.63, @@ -394,7 +394,7 @@ function createDoll(position) { } function createSprayCan(position) { - var scriptURL = Script.resolvePath("sprayPaintCan.js"); + var scriptURL = Script.resolvePath("sprayPaintCan.js?v1" + Math.random()); var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; var entity = Entities.addEntity({ diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 2dc49b4f63..db944276c2 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -13,13 +13,14 @@ x: 0, y: 0, z: 0 - }; + } // if the trigger value goes below this while held, the can will stop spraying. if it goes above, it will spray - var DISABLE_SPRAY_THRESHOLD = 0.7; + var DISABLE_SPRAY_THRESHOLD = 0.5; var MAX_POINTS_PER_LINE = 40; var MIN_POINT_DISTANCE = 0.01; + var MAX_POINT_DISTANCE = 0.5; var STROKE_WIDTH = 0.02; this.setRightHand = function() { @@ -67,19 +68,19 @@ animationSettings: animationSettings, position: position, textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", - emitSpeed: 3, + emitSpeed: 20, speedSpread: 0.02, emitAcceleration: ZERO_VEC, emitRate: 100, particleRadius: 0.01, radiusSpread: 0.005, - polarFinish: 0.1, + polarFinish: 0.01, color: { red: 170, green: 20, blue: 150 }, - lifetime: 50, //probably wont be holding longer than this straight + lifetime: 500, //probably wont be holding longer than this straight }); setEntityCustomData(this.resetKey, this.paintStream, { @@ -94,12 +95,14 @@ } this.releaseGrab = function() { - this.disableStream(); + // this.disableStream(); } this.disableStream = function() { + print("DISABLE STREAM") Entities.deleteEntity(this.paintStream); this.paintStream = null; + this.painting = false; this.sprayInjector.stop(); } @@ -123,13 +126,87 @@ position: position, emitOrientation: forwardQuat, }); + + //Now check for an intersection with an entity + //move forward so ray doesnt intersect with gun + var origin = Vec3.sum(position, forwardVec); + var pickRay = { + origin: origin, + direction: Vec3.multiply(forwardVec, 2) + } + + var intersection = Entities.findRayIntersection(pickRay, true); + if (intersection.intersects) { + var normal = intersection.surfaceNormal; + this.paint(intersection.intersection, normal); + } } + this.paint = function(position, normal) { + if (!this.painting) { + + this.newStroke(position); + this.painting = true; + } + + if (this.strokePoints.length > MAX_POINTS_PER_LINE) { + this.painting = false; + return; + } + + var localPoint = Vec3.subtract(position, this.strokeBasePosition); + //Move stroke a bit forward along normal so it doesnt zfight with mesh its drawing on + localPoint = Vec3.sum(localPoint, Vec3.multiply(normal, .01)); + + var pointToPointDistance = Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]) + if (this.strokePoints.length > 0 && pointToPointDistance < MIN_POINT_DISTANCE) { + //need a minimum distance to avoid binormal NANs + //Also distance should not be too high, or it means we probably moved from one surface to the next and may be drawing through air + return; + } else if(this.strokePoints.length > 0 && pointToPointDistance > MAX_POINT_DISTANCE) { + this.painting = false; + return; + } - + this.strokePoints.push(localPoint); + this.strokeNormals.push(normal); + this.strokeWidths.push(STROKE_WIDTH); + Entities.editEntity(this.currentStroke, { + linePoints: this.strokePoints, + normals: this.strokeNormals, + strokeWidths: this.strokeWidths + }); + + + } + + this.newStroke = function(position) { + this.strokeBasePosition = position; + this.currentStroke = Entities.addEntity({ + position: position, + type: "PolyLine", + color: { + red: randInt(160, 250), + green: randInt(10, 20), + blue: randInt(190, 250) + }, + dimensions: { + x: 50, + y: 50, + z: 50 + }, + lifetime: 100 + }); + this.strokePoints = []; + this.strokeNormals = []; + this.strokeWidths = []; + + this.strokes.push(this.currentStroke); + } this.preload = function(entityId) { + this.strokes = []; this.spraying = false; this.entityId = entityId; this.resetKey = "resetMe"; From 80405450ced11dc8c2bec360993262693f04a1de Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 09:00:12 -0700 Subject: [PATCH 095/138] Paint can now just sprays out stream --- examples/toys/sprayPaintCan.js | 89 +++------------------------------- 1 file changed, 7 insertions(+), 82 deletions(-) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index db944276c2..18063474a0 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -20,7 +20,6 @@ var MAX_POINTS_PER_LINE = 40; var MIN_POINT_DISTANCE = 0.01; - var MAX_POINT_DISTANCE = 0.5; var STROKE_WIDTH = 0.02; this.setRightHand = function() { @@ -68,19 +67,19 @@ animationSettings: animationSettings, position: position, textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", - emitSpeed: 20, + emitSpeed: 3, speedSpread: 0.02, emitAcceleration: ZERO_VEC, emitRate: 100, particleRadius: 0.01, radiusSpread: 0.005, - polarFinish: 0.01, + polarFinish: 0.05, color: { red: 170, green: 20, blue: 150 }, - lifetime: 500, //probably wont be holding longer than this straight + lifetime: 50, //probably wont be holding longer than this straight }); setEntityCustomData(this.resetKey, this.paintStream, { @@ -89,20 +88,20 @@ this.sprayInjector = Audio.playSound(this.spraySound, { position: position, - volume: 0.1 + volume: 0.1, + loop: true }); } this.releaseGrab = function() { - // this.disableStream(); + this.disableStream(); } this.disableStream = function() { - print("DISABLE STREAM") + print("DEKETE STEREAAAM") Entities.deleteEntity(this.paintStream); this.paintStream = null; - this.painting = false; this.sprayInjector.stop(); } @@ -126,87 +125,13 @@ position: position, emitOrientation: forwardQuat, }); - - //Now check for an intersection with an entity - //move forward so ray doesnt intersect with gun - var origin = Vec3.sum(position, forwardVec); - var pickRay = { - origin: origin, - direction: Vec3.multiply(forwardVec, 2) - } - - var intersection = Entities.findRayIntersection(pickRay, true); - if (intersection.intersects) { - var normal = intersection.surfaceNormal; - this.paint(intersection.intersection, normal); - } } - this.paint = function(position, normal) { - if (!this.painting) { - - this.newStroke(position); - this.painting = true; - } - - if (this.strokePoints.length > MAX_POINTS_PER_LINE) { - this.painting = false; - return; - } - - var localPoint = Vec3.subtract(position, this.strokeBasePosition); - //Move stroke a bit forward along normal so it doesnt zfight with mesh its drawing on - localPoint = Vec3.sum(localPoint, Vec3.multiply(normal, .01)); - - var pointToPointDistance = Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]) - if (this.strokePoints.length > 0 && pointToPointDistance < MIN_POINT_DISTANCE) { - //need a minimum distance to avoid binormal NANs - //Also distance should not be too high, or it means we probably moved from one surface to the next and may be drawing through air - return; - } else if(this.strokePoints.length > 0 && pointToPointDistance > MAX_POINT_DISTANCE) { - this.painting = false; - return; - } - this.strokePoints.push(localPoint); - this.strokeNormals.push(normal); - this.strokeWidths.push(STROKE_WIDTH); - Entities.editEntity(this.currentStroke, { - linePoints: this.strokePoints, - normals: this.strokeNormals, - strokeWidths: this.strokeWidths - }); - } - - this.newStroke = function(position) { - this.strokeBasePosition = position; - this.currentStroke = Entities.addEntity({ - position: position, - type: "PolyLine", - color: { - red: randInt(160, 250), - green: randInt(10, 20), - blue: randInt(190, 250) - }, - dimensions: { - x: 50, - y: 50, - z: 50 - }, - lifetime: 100 - }); - this.strokePoints = []; - this.strokeNormals = []; - this.strokeWidths = []; - - this.strokes.push(this.currentStroke); - } - this.preload = function(entityId) { - this.strokes = []; this.spraying = false; this.entityId = entityId; this.resetKey = "resetMe"; From 8857042363ea8d301a872d53c30badffd4927cdf Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 09:46:49 -0700 Subject: [PATCH 096/138] whiteboard --- examples/toys/masterResetEntity.js | 38 ++++++++++++++++++++---- examples/toys/whiteboard.js | 46 ++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 examples/toys/whiteboard.js diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index c34d8d1e22..4e38ee4693 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -69,6 +69,12 @@ function createAllToys() { z: 503.49 }); + createWhiteboard({ + x: 540, + y: 495.41, + z: 506.15 + }); + //Handles toggling of all sconce lights createLightSwitches(); @@ -80,12 +86,6 @@ function createAllToys() { z: 508.22 }) - // createPillow({ - // x: 549.29, - // y: 495.35, - // z: 508.22 - // }); - createPottedPlant({ x: 554.26, y: 495.23, @@ -141,6 +141,32 @@ function createCat(position) { }); } +function createWhiteboard(position) { + var scriptURL = Script.resolvePath('whiteboard.js?v1'); + var whiteboard = Entities.addEntity({ + type: "Box", + position: position, + script: scriptURL, + name: "whiteboard", + dimensions: { + x: 2, + y: 1.5, + z: .01 + }, + color: { + red: 250, + green: 250, + blue: 250 + } + }); + + + setEntityCustomData(resetKey, whiteboard, { + resetMe: true + }); + +} + function createFlashlight(position) { var scriptURL = Script.resolvePath('flashlight/flashlight.js'); var modelURL = "https://hifi-public.s3.amazonaws.com/models/props/flashlight.fbx"; diff --git a/examples/toys/whiteboard.js b/examples/toys/whiteboard.js new file mode 100644 index 0000000000..e67076f165 --- /dev/null +++ b/examples/toys/whiteboard.js @@ -0,0 +1,46 @@ +// +// detectGrabExample.js +// examples/entityScripts +// +// Created by Eric Levin on 9/21/15. +// Copyright 2015 High Fidelity, Inc. +// +// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + + var _this; + + + // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember + // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) + Whiteboard = function() { + _this = this; + + }; + + Whiteboard.prototype = { + + + startNearGrabNonColliding: function() { + print("HEY") + }, + + + // preload() will be called when the entity has become visible (or known) to the interface + // it gives us a chance to set our local JavaScript object up. In this case it means: + preload: function(entityID) { + this.entityID = entityID; + + this.position = Entities.getEntityProperties(this.entityID, "position").position; + + }, + }; + + // entity scripts always need to return a newly constructed object of our type + return new Whiteboard(); +}) \ No newline at end of file From 1ceefc3c63748a4fa3461a6009befa28fa713aec Mon Sep 17 00:00:00 2001 From: James Pollack Date: Tue, 29 Sep 2015 10:00:45 -0700 Subject: [PATCH 097/138] add model key and url --- examples/toys/masterResetEntity.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index cba5424d58..47b960e8c4 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -293,6 +293,8 @@ function createGates() { var rotation1 = Quat.fromPitchYawRollDegrees(0, 36, 0); var gate1 = Entities.addEntity({ name: 'Back Door Gate', + type:'Model', + modelURL:'MODEL_URL', position: { x: 546.52, y: 494.76, @@ -328,6 +330,8 @@ function createGates() { var rotation2 = Quat.fromPitchYawRollDegrees(0, -16, 0); var gate2 = Entities.addEntity({ name: 'Front Door Fence', + type:'Model', + modelURL:'MODEL_URL', position: { x: 531.15, y: 495.11, From 1662471583274aa56f1f912f64449adb5394395e Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 10:16:44 -0700 Subject: [PATCH 098/138] whiteboard changes --- examples/toys/masterResetEntity.js | 98 +++++++++++++++--------------- examples/toys/whiteboard.js | 29 ++++++++- 2 files changed, 75 insertions(+), 52 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 4e38ee4693..5e69b35c2f 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -25,49 +25,49 @@ deleteAllToys(); createAllToys(); function createAllToys() { - createBlocks({ - x: 548.3, - y: 495.55, - z: 504.4 - }); + // createBlocks({ + // x: 548.3, + // y: 495.55, + // z: 504.4 + // }); - createSprayCan({ - x: 549.7, - y: 495.6, - z: 503.91 - }); + // createSprayCan({ + // x: 549.7, + // y: 495.6, + // z: 503.91 + // }); - createBasketBall({ - x: 547.73, - y: 495.5, - z: 505.47 - }); + // createBasketBall({ + // x: 547.73, + // y: 495.5, + // z: 505.47 + // }); - createDoll({ - x: 546.67, - y: 495.41, - z: 505.09 - }); + // createDoll({ + // x: 546.67, + // y: 495.41, + // z: 505.09 + // }); - createWand({ - x: 546.71, - y: 495.55, - z: 506.15 - }); + // createWand({ + // x: 546.71, + // y: 495.55, + // z: 506.15 + // }); - createDice(); + // createDice(); - createFlashlight({ - x: 545.72, - y: 495.41, - z: 505.78 - }); + // createFlashlight({ + // x: 545.72, + // y: 495.41, + // z: 505.78 + // }); - createCat({ - x: 551.09, - y: 494.98, - z: 503.49 - }); + // createCat({ + // x: 551.09, + // y: 494.98, + // z: 503.49 + // }); createWhiteboard({ x: 540, @@ -75,22 +75,22 @@ function createAllToys() { z: 506.15 }); - //Handles toggling of all sconce lights - createLightSwitches(); + // //Handles toggling of all sconce lights + // createLightSwitches(); - createCombinedArmChair({ - x: 549.29, - y: 495.05, - z: 508.22 - }) + // createCombinedArmChair({ + // x: 549.29, + // y: 495.05, + // z: 508.22 + // }) - createPottedPlant({ - x: 554.26, - y: 495.23, - z: 504.53 - }); + // createPottedPlant({ + // x: 554.26, + // y: 495.23, + // z: 504.53 + // }); } @@ -142,7 +142,7 @@ function createCat(position) { } function createWhiteboard(position) { - var scriptURL = Script.resolvePath('whiteboard.js?v1'); + var scriptURL = Script.resolvePath('whiteboard.js?v1' + Math.random()); var whiteboard = Entities.addEntity({ type: "Box", position: position, diff --git a/examples/toys/whiteboard.js b/examples/toys/whiteboard.js index e67076f165..94b99124c0 100644 --- a/examples/toys/whiteboard.js +++ b/examples/toys/whiteboard.js @@ -25,9 +25,32 @@ Whiteboard.prototype = { - + setRightHand: function() { + this.hand = 'RIGHT'; + this.getHandPosition = MyAvatar.getRightPalmPosition; + this.getHandRotation = MyAvatar.getRightPalmRotation; + }, + setLeftHand: function() { + this.hand = 'LEFT'; + this.getHandPosition = MyAvatar.getLeftPalmPosition; + this.getHandRotation = MyAvatar.getLeftPalmRotation; + }, + startNearGrabNonColliding: function() { - print("HEY") + this.whichHand = this.hand; + }, + + continueNearGrabbingNonColliding: function() { + var handPosition = this.getHandPosition(); + var pickRay = { + origin: handPosition, + direction: Quat.getUp(this.getHandRotation()) + }; + var intersection = Entities.findRayIntersection(pickRay, true); + print("YA") + if(intersection.intersects) { + print("INTERSECTION") + } }, @@ -37,7 +60,7 @@ this.entityID = entityID; this.position = Entities.getEntityProperties(this.entityID, "position").position; - + }, }; From d07c93ef8f4754ceca9853d63d735fe6d61158cb Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 10:22:03 -0700 Subject: [PATCH 099/138] adds hand setting when grabbing near non physical objects --- examples/controllers/handControllerGrab.js | 32 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 02c003d622..1b891f56b5 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -29,9 +29,21 @@ var TRIGGER_ON_VALUE = 0.2; 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, blue: 255}; // line color when pick misses -var INTERSECT_COLOR = { red: 250, green: 10, blue: 10}; // line color when pick hits -var LINE_ENTITY_DIMENSIONS = { x: 1000, y: 1000, z: 1000}; +var NO_INTERSECT_COLOR = { + red: 10, + green: 10, + blue: 255 +}; // line color when pick misses +var INTERSECT_COLOR = { + red: 250, + green: 10, + blue: 10 +}; // line color when pick hits +var LINE_ENTITY_DIMENSIONS = { + x: 1000, + y: 1000, + z: 1000 +}; var LINE_LENGTH = 500; @@ -54,7 +66,11 @@ var RELEASE_VELOCITY_MULTIPLIER = 1.5; // affects throwing things var RIGHT_HAND = 1; var LEFT_HAND = 0; -var ZERO_VEC = { x: 0, y: 0, z: 0}; +var ZERO_VEC = { + x: 0, + y: 0, + z: 0 +}; var NULL_ACTION_ID = "{00000000-0000-0000-000000000000}"; var MSEC_PER_SEC = 1000.0; @@ -391,7 +407,11 @@ function MyController(hand, triggerAction) { this.state = STATE_RELEASE; return; } - print("JAYKJAGHKJAHKJAHKJAHKJ") + if (this.hand === RIGHT_HAND) { + Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); + } else { + Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); + } Entities.callEntityMethod(this.grabbedEntity, "startNearGrabNonColliding"); this.state = STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING; }; @@ -547,4 +567,4 @@ function cleanup() { } Script.scriptEnding.connect(cleanup); -Script.update.connect(update); +Script.update.connect(update); \ No newline at end of file From 932f7ce92c2a957c3b46825aa9253970ec589c70 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 10:39:07 -0700 Subject: [PATCH 100/138] up to date --- examples/toys/masterResetEntity.js | 108 +++++++++++++++-------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 5e69b35c2f..aa21589ff4 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -25,74 +25,76 @@ deleteAllToys(); createAllToys(); function createAllToys() { - // createBlocks({ - // x: 548.3, - // y: 495.55, - // z: 504.4 - // }); + createBlocks({ + x: 548.3, + y: 495.55, + z: 504.4 + }); - // createSprayCan({ - // x: 549.7, - // y: 495.6, - // z: 503.91 - // }); + createSprayCan({ + x: 549.7, + y: 495.6, + z: 503.91 + }); - // createBasketBall({ - // x: 547.73, - // y: 495.5, - // z: 505.47 - // }); + createBasketBall({ + x: 547.73, + y: 495.5, + z: 505.47 + }); - // createDoll({ - // x: 546.67, - // y: 495.41, - // z: 505.09 - // }); - - // createWand({ - // x: 546.71, - // y: 495.55, - // z: 506.15 - // }); - - // createDice(); - - // createFlashlight({ - // x: 545.72, - // y: 495.41, - // z: 505.78 - // }); - - // createCat({ - // x: 551.09, - // y: 494.98, - // z: 503.49 - // }); - - createWhiteboard({ - x: 540, + createDoll({ + x: 546.67, y: 495.41, + z: 505.09 + }); + + createWand({ + x: 546.71, + y: 495.55, z: 506.15 }); + createDice(); + + createFlashlight({ + x: 545.72, + y: 495.41, + z: 505.78 + }); + + createCat({ + x: 551.09, + y: 494.98, + z: 503.49 + }); + // //Handles toggling of all sconce lights - // createLightSwitches(); + createLightSwitches(); - // createCombinedArmChair({ - // x: 549.29, - // y: 495.05, - // z: 508.22 - // }) + createCombinedArmChair({ + x: 549.29, + y: 495.05, + z: 508.22 + }) - // createPottedPlant({ - // x: 554.26, - // y: 495.23, - // z: 504.53 + createPottedPlant({ + x: 554.26, + y: 495.23, + z: 504.53 + }); + + + // createWhiteboard({ + // x: 540, + // y: 495.41, + // z: 506.15 // }); + } function deleteAllToys() { From 337909b53944f1f7c6a8b0c2f692b27f9560fa14 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Tue, 29 Sep 2015 10:47:32 -0700 Subject: [PATCH 101/138] actual model url --- examples/toys/masterResetEntity.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 47b960e8c4..28183d5477 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -294,7 +294,7 @@ function createGates() { var gate1 = Entities.addEntity({ name: 'Back Door Gate', type:'Model', - modelURL:'MODEL_URL', + modelURL:MODEL_URL, position: { x: 546.52, y: 494.76, @@ -331,7 +331,7 @@ function createGates() { var gate2 = Entities.addEntity({ name: 'Front Door Fence', type:'Model', - modelURL:'MODEL_URL', + modelURL:MODEL_URL, position: { x: 531.15, y: 495.11, From 63c02712c151bec3f9178b03a9825b57346150dd Mon Sep 17 00:00:00 2001 From: James Pollack Date: Tue, 29 Sep 2015 10:52:54 -0700 Subject: [PATCH 102/138] add shape types --- examples/toys/masterResetEntity.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 28183d5477..bb9ee0eeaf 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -293,8 +293,9 @@ function createGates() { var rotation1 = Quat.fromPitchYawRollDegrees(0, 36, 0); var gate1 = Entities.addEntity({ name: 'Back Door Gate', - type:'Model', - modelURL:MODEL_URL, + type: 'Model', + shapeType: 'box', + modelURL: MODEL_URL, position: { x: 546.52, y: 494.76, @@ -330,8 +331,9 @@ function createGates() { var rotation2 = Quat.fromPitchYawRollDegrees(0, -16, 0); var gate2 = Entities.addEntity({ name: 'Front Door Fence', - type:'Model', - modelURL:MODEL_URL, + type: 'Model', + modelURL: MODEL_URL, + shapeType: 'box', position: { x: 531.15, y: 495.11, From a58cf66f2e78dff9421ca43f72b0f131f526d06d Mon Sep 17 00:00:00 2001 From: James Pollack Date: Tue, 29 Sep 2015 11:07:21 -0700 Subject: [PATCH 103/138] wand adjustments --- examples/toys/masterResetEntity.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index bb9ee0eeaf..fd2df04c49 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -389,9 +389,9 @@ function createWand(position) { z: 0.05 }, //must be enabled to be grabbable in the physics engine - shapeType: 'compound', + shapeType: 'box', collisionsWillMove: true, - compoundShapeURL: WAND_COLLISION_SHAPE, + // compoundShapeURL: WAND_COLLISION_SHAPE, //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}, From 66ef92b659e475733bc6c5a4531390488a414b98 Mon Sep 17 00:00:00 2001 From: James Pollack Date: Tue, 29 Sep 2015 12:52:34 -0700 Subject: [PATCH 104/138] thicker, heavier gates, wand collision shape --- examples/toys/masterResetEntity.js | 42 ++++++++++++++---------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index fd2df04c49..50337cdbea 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -6,9 +6,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -/*global deleteAllToys, print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ +/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ //per script -/*global createAllToys, createGates, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLightSwitches */ +/*global deleteAllToys, createAllToys, createGates, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLightSwitches */ var utilitiesScript = Script.resolvePath("../libraries/utils.js"); Script.include(utilitiesScript); @@ -19,7 +19,6 @@ 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(); @@ -291,6 +290,7 @@ function createGates() { var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/ryan/fence.fbx'; var rotation1 = Quat.fromPitchYawRollDegrees(0, 36, 0); + var gate1 = Entities.addEntity({ name: 'Back Door Gate', type: 'Model', @@ -299,26 +299,24 @@ function createGates() { position: { x: 546.52, y: 494.76, - z: 498.93 + z: 498.87 }, dimensions: { x: 1.42, y: 1.13, - z: 0.02 + z: 0.25 }, rotation: rotation1, collisionsWillMove: true, gravity: { x: 0, - y: -9.8, + y: -100, z: 0 }, - velocity: { - x: 0, - y: 0, - z: 0 - }, - linearDamping: 0.2 + linearDamping: 1, + angularDamping: 10, + mass: 10, + }); setEntityCustomData(resetKey, gate1, { @@ -328,6 +326,7 @@ function createGates() { setEntityCustomData(GRABBABLE_DATA_KEY, gate1, { grabbable: false }); + var rotation2 = Quat.fromPitchYawRollDegrees(0, -16, 0); var gate2 = Entities.addEntity({ name: 'Front Door Fence', @@ -342,21 +341,18 @@ function createGates() { dimensions: { x: 1.42, y: 1.13, - z: 0.02 + z: 0.2 }, rotation: rotation2, collisionsWillMove: true, gravity: { x: 0, - y: -9.8, + y: -100, z: 0 }, - velocity: { - x: 0, - y: 0, - z: 0 - }, - linearDamping: 0.2 + linearDamping: 1, + angularDamping: 10, + mass: 10, }); setEntityCustomData(resetKey, gate2, { @@ -370,7 +366,7 @@ function createGates() { 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/collisionHull.obj'; + var WAND_COLLISION_SHAPE = 'http://hifi-public.s3.amazonaws.com/james/bubblewand/models/wand/actual_no_top_collision_hull.obj'; var scriptURL = Script.resolvePath("bubblewand/wand.js"); var entity = Entities.addEntity({ @@ -389,9 +385,9 @@ function createWand(position) { z: 0.05 }, //must be enabled to be grabbable in the physics engine - shapeType: 'box', + shapeType: 'compound', collisionsWillMove: true, - // compoundShapeURL: WAND_COLLISION_SHAPE, + compoundShapeURL: WAND_COLLISION_SHAPE, //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}, From 81c5d0c388b3057a5fc1c56ff305b1a815d5be60 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 13:57:17 -0700 Subject: [PATCH 105/138] more whiteboard work --- examples/toys/masterResetEntity.js | 122 ++++++++++++++--------------- examples/toys/whiteboard.js | 29 ++++++- 2 files changed, 86 insertions(+), 65 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 28fa075e8b..50dc064e46 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -24,74 +24,74 @@ deleteAllToys(); createAllToys(); function createAllToys() { - createBlocks({ - x: 548.3, - y: 495.55, - z: 504.4 - }); + // createBlocks({ + // x: 548.3, + // y: 495.55, + // z: 504.4 + // }); - createSprayCan({ - x: 549.7, - y: 495.6, - z: 503.91 - }); + // createSprayCan({ + // x: 549.7, + // y: 495.6, + // z: 503.91 + // }); - createBasketBall({ - x: 547.73, - y: 495.5, - z: 505.47 - }); + // createBasketBall({ + // x: 547.73, + // y: 495.5, + // z: 505.47 + // }); - createDoll({ - x: 546.67, - y: 495.41, - z: 505.09 - }); - - createWand({ - x: 546.71, - y: 495.55, - z: 506.15 - }); - - createDice(); - - createFlashlight({ - x: 545.72, - y: 495.41, - z: 505.78 - }); - - createCat({ - x: 551.09, - y: 494.98, - z: 503.49 - }); - - // //Handles toggling of all sconce lights - createLightSwitches(); - - - - createCombinedArmChair({ - x: 549.29, - y: 495.05, - z: 508.22 - }) - - createPottedPlant({ - x: 554.26, - y: 495.23, - z: 504.53 - }); - - - // createWhiteboard({ - // x: 540, + // createDoll({ + // x: 546.67, // y: 495.41, + // z: 505.09 + // }); + + // createWand({ + // x: 546.71, + // y: 495.55, // z: 506.15 // }); + // createDice(); + + // createFlashlight({ + // x: 545.72, + // y: 495.41, + // z: 505.78 + // }); + + // createCat({ + // x: 551.09, + // y: 494.98, + // z: 503.49 + // }); + + // // //Handles toggling of all sconce lights + // createLightSwitches(); + + + + // createCombinedArmChair({ + // x: 549.29, + // y: 495.05, + // z: 508.22 + // }) + + // createPottedPlant({ + // x: 554.26, + // y: 495.23, + // z: 504.53 + // }); + + + createWhiteboard({ + x: 500, + y: 500, + z: 500 + }); + createGates(); diff --git a/examples/toys/whiteboard.js b/examples/toys/whiteboard.js index 94b99124c0..59d230f52c 100644 --- a/examples/toys/whiteboard.js +++ b/examples/toys/whiteboard.js @@ -37,7 +37,19 @@ }, startNearGrabNonColliding: function() { + print("START") this.whichHand = this.hand; + this.laserPointer = Entities.addEntity({ + type: "Box", + dimensions: {x: .02, y: .02, z: 0.001}, + color: {red: 200, green: 10, blue: 10}, + rotation: this.rotation + }); + + setEntityCustomData(this.resetKey, this.laserPointer, { + resetMe: true + }); + }, continueNearGrabbingNonColliding: function() { @@ -47,10 +59,16 @@ direction: Quat.getUp(this.getHandRotation()) }; var intersection = Entities.findRayIntersection(pickRay, true); - print("YA") if(intersection.intersects) { - print("INTERSECTION") + Entities.editEntity(this.laserPointer, { + position: intersection.intersection + }); } + + }, + + releaseGrab: function() { + Entities.deleteEntity(this.laserPointer); }, @@ -58,10 +76,13 @@ // it gives us a chance to set our local JavaScript object up. In this case it means: preload: function(entityID) { this.entityID = entityID; - - this.position = Entities.getEntityProperties(this.entityID, "position").position; + var props = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); + this.position = props.position; + this.rotation = props.rotation; + this.resetKey = "resetMe"; }, + }; // entity scripts always need to return a newly constructed object of our type From 7681d8d77d5a601d669d69606f91cf87801f06d4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 14:05:57 -0700 Subject: [PATCH 106/138] fixed commenting --- examples/toys/masterResetEntity.js | 106 ++++++++++++++--------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 50dc064e46..c06324b045 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -24,73 +24,73 @@ deleteAllToys(); createAllToys(); function createAllToys() { - // createBlocks({ - // x: 548.3, - // y: 495.55, - // z: 504.4 - // }); + createBlocks({ + x: 548.3, + y: 495.55, + z: 504.4 + }); - // createSprayCan({ - // x: 549.7, - // y: 495.6, - // z: 503.91 - // }); + createSprayCan({ + x: 549.7, + y: 495.6, + z: 503.91 + }); - // createBasketBall({ - // x: 547.73, - // y: 495.5, - // z: 505.47 - // }); + createBasketBall({ + x: 547.73, + y: 495.5, + z: 505.47 + }); - // createDoll({ - // x: 546.67, - // y: 495.41, - // z: 505.09 - // }); + createDoll({ + x: 546.67, + y: 495.41, + z: 505.09 + }); - // createWand({ - // x: 546.71, - // y: 495.55, - // z: 506.15 - // }); + createWand({ + x: 546.71, + y: 495.55, + z: 506.15 + }); - // createDice(); + createDice(); - // createFlashlight({ - // x: 545.72, - // y: 495.41, - // z: 505.78 - // }); + createFlashlight({ + x: 545.72, + y: 495.41, + z: 505.78 + }); - // createCat({ - // x: 551.09, - // y: 494.98, - // z: 503.49 - // }); + createCat({ + x: 551.09, + y: 494.98, + z: 503.49 + }); - // // //Handles toggling of all sconce lights - // createLightSwitches(); + // //Handles toggling of all sconce lights + createLightSwitches(); - // createCombinedArmChair({ - // x: 549.29, - // y: 495.05, - // z: 508.22 - // }) + createCombinedArmChair({ + x: 549.29, + y: 495.05, + z: 508.22 + }) - // createPottedPlant({ - // x: 554.26, - // y: 495.23, - // z: 504.53 - // }); + createPottedPlant({ + x: 554.26, + y: 495.23, + z: 504.53 + }); - createWhiteboard({ - x: 500, - y: 500, - z: 500 - }); + // createWhiteboard({ + // x: 500, + // y: 500, + // z: 500 + // }); From d8e7da7b73d16d52210131e8592e82bc753705a4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 15:43:59 -0700 Subject: [PATCH 107/138] added painting to whiteboard --- examples/toys/whiteboard.js | 81 +++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/examples/toys/whiteboard.js b/examples/toys/whiteboard.js index 59d230f52c..55a2fcb443 100644 --- a/examples/toys/whiteboard.js +++ b/examples/toys/whiteboard.js @@ -14,7 +14,10 @@ (function() { var _this; - + var MAX_POINTS_PER_LINE = 40; + var MIN_POINT_DISTANCE = 0.01; + var STROKE_WIDTH = 0.02; + var STROKE_COLOR = {red: 200, green: 20, blue: 160}; // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) @@ -37,18 +40,21 @@ }, startNearGrabNonColliding: function() { - print("START") this.whichHand = this.hand; this.laserPointer = Entities.addEntity({ type: "Box", - dimensions: {x: .02, y: .02, z: 0.001}, - color: {red: 200, green: 10, blue: 10}, + dimensions: { + x: STROKE_WIDTH, + y: STROKE_WIDTH, + z: 0.001 + }, + color: STROKE_COLOR, rotation: this.rotation }); - setEntityCustomData(this.resetKey, this.laserPointer, { - resetMe: true - }); + setEntityCustomData(this.resetKey, this.laserPointer, { + resetMe: true + }); }, @@ -59,16 +65,74 @@ direction: Quat.getUp(this.getHandRotation()) }; var intersection = Entities.findRayIntersection(pickRay, true); - if(intersection.intersects) { + if (intersection.intersects) { Entities.editEntity(this.laserPointer, { position: intersection.intersection }); + this.paint(intersection.intersection, intersection.surfaceNormal); } }, releaseGrab: function() { Entities.deleteEntity(this.laserPointer); + this.painting = false; + }, + + paint: function(position, normal) { + if (!this.painting) { + this.newStroke(position); + this.painting = true; + } + + if (this.strokePoints.length > MAX_POINTS_PER_LINE) { + this.painting = false; + return; + } + + + var localPoint = Vec3.subtract(position, this.strokeBasePosition); + //Move stroke a bit forward along normal so it doesnt zfight with mesh its drawing on + localPoint = Vec3.sum(localPoint, Vec3.multiply(normal, .001)); + + if (this.strokePoints.length > 0 && Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]) < MIN_POINT_DISTANCE) { + //need a minimum distance to avoid binormal NANs + return; + } + + this.strokePoints.push(localPoint); + this.strokeNormals.push(normal); + this.strokeWidths.push(STROKE_WIDTH); + Entities.editEntity(this.currentStroke, { + linePoints: this.strokePoints, + normals: this.strokeNormals, + strokeWidths: this.strokeWidths + }); + }, + + newStroke: function(position) { + print("NEW STROKE") + this.strokeBasePosition = position; + this.currentStroke = Entities.addEntity({ + position: position, + type: "PolyLine", + color: STROKE_COLOR, + dimensions: { + x: 50, + y: 50, + z: 50 + }, + lifetime: 100 + }); + + setEntityCustomData(this.resetKey, this.currentStroke, { + resetMe: true + }); + this.strokePoints = []; + this.strokeNormals = []; + this.strokeWidths = []; + + this.strokes.push(this.currentStroke); }, @@ -80,6 +144,7 @@ this.position = props.position; this.rotation = props.rotation; this.resetKey = "resetMe"; + this.strokes = []; }, From 68615e171a5303f1ca779b0eaea7196f5ef24495 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Tue, 29 Sep 2015 17:40:05 -0700 Subject: [PATCH 108/138] Update masterResetEntity.js --- examples/toys/masterResetEntity.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index c06324b045..3ed5e9a839 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -86,11 +86,11 @@ function createAllToys() { }); - // createWhiteboard({ - // x: 500, - // y: 500, - // z: 500 - // }); + createWhiteboard({ + x: 500, + y: 500, + z: 500 + }); @@ -790,4 +790,4 @@ function randFloat(low, high) { function randInt(low, high) { return Math.floor(randFloat(low, high)); -} \ No newline at end of file +} From ba17225c1964a1b3713b0341cdd928594e0b9df7 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 18:32:52 -0700 Subject: [PATCH 109/138] Remove hand control script from PR --- examples/controllers/handControllerGrab.js | 616 --------------------- 1 file changed, 616 deletions(-) delete mode 100644 examples/controllers/handControllerGrab.js diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js deleted file mode 100644 index 1ba82c2247..0000000000 --- a/examples/controllers/handControllerGrab.js +++ /dev/null @@ -1,616 +0,0 @@ -// hydraGrab.js -// examples -// -// Created by Eric Levin on 9/2/15 -// Additions by James B. Pollack @imgntn on 9/24/2015 -// Copyright 2015 High Fidelity, Inc. -// -// Grabs physically moveable entities with hydra-like controllers; it works for either near or far objects. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ - -Script.include("../libraries/utils.js"); - -///////////////////////////////////////////////////////////////// -// -// these tune time-averaging and "on" value for analog trigger -// - -var TRIGGER_SMOOTH_RATIO = 0.1; // 0.0 disables smoothing of trigger value -var TRIGGER_ON_VALUE = 0.2; - -///////////////////////////////////////////////////////////////// -// -// distant manipulation -// - -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, - blue: 255 -}; // line color when pick misses -var INTERSECT_COLOR = { - red: 250, - green: 10, - blue: 10 -}; // line color when pick hits -var LINE_ENTITY_DIMENSIONS = { - x: 1000, - y: 1000, - z: 1000 -}; -var LINE_LENGTH = 500; - - -///////////////////////////////////////////////////////////////// -// -// near grabbing -// - -var GRAB_RADIUS = 0.3; // if the ray misses but an object is this close, it will still be selected -var NEAR_GRABBING_ACTION_TIMEFRAME = 0.05; // how quickly objects move to their new position -var NEAR_GRABBING_VELOCITY_SMOOTH_RATIO = 1.0; // adjust time-averaging of held object's velocity. 1.0 to disable. -var NEAR_PICK_MAX_DISTANCE = 0.6; // max length of pick-ray for close grabbing to be selected -var RELEASE_VELOCITY_MULTIPLIER = 1.5; // affects throwing things - -///////////////////////////////////////////////////////////////// -// -// other constants -// - -var RIGHT_HAND = 1; -var LEFT_HAND = 0; - -var ZERO_VEC = { - x: 0, - y: 0, - z: 0 -}; -var NULL_ACTION_ID = "{00000000-0000-0000-000000000000}"; -var MSEC_PER_SEC = 1000.0; - -// these control how long an abandoned pointer line will hang around -var startTime = Date.now(); -var LIFETIME = 10; - -// states for the state machine -var STATE_SEARCHING = 0; -var STATE_DISTANCE_HOLDING = 1; -var STATE_CONTINUE_DISTANCE_HOLDING = 2; -var STATE_NEAR_GRABBING = 3; -var STATE_CONTINUE_NEAR_GRABBING = 4; -var STATE_NEAR_GRABBING_NON_COLLIDING = 5; -var STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING = 6; -var STATE_RELEASE = 7; - -var GRAB_USER_DATA_KEY = "grabKey"; -var GRABBABLE_DATA_KEY = "grabbableKey"; - -function MyController(hand, triggerAction) { - this.hand = hand; - if (this.hand === RIGHT_HAND) { - this.getHandPosition = MyAvatar.getRightPalmPosition; - this.getHandRotation = MyAvatar.getRightPalmRotation; - } else { - this.getHandPosition = MyAvatar.getLeftPalmPosition; - this.getHandRotation = MyAvatar.getLeftPalmRotation; - } - - var SPATIAL_CONTROLLERS_PER_PALM = 2; - var TIP_CONTROLLER_OFFSET = 1; - this.triggerAction = triggerAction; - this.palm = SPATIAL_CONTROLLERS_PER_PALM * hand; - this.tip = SPATIAL_CONTROLLERS_PER_PALM * hand + TIP_CONTROLLER_OFFSET; - - this.actionID = null; // action this script created... - this.grabbedEntity = null; // on this entity. - this.grabbedVelocity = ZERO_VEC; // rolling average of held object's velocity - this.state = 0; - this.pointer = null; // entity-id of line object - this.triggerValue = 0; // rolling average of trigger value - var _this = this; - - this.update = function() { - switch (this.state) { - case STATE_SEARCHING: - this.search(); - this.touchTest(); - break; - case STATE_DISTANCE_HOLDING: - this.distanceHolding(); - break; - case STATE_CONTINUE_DISTANCE_HOLDING: - this.continueDistanceHolding(); - break; - case STATE_NEAR_GRABBING: - this.nearGrabbing(); - break; - case STATE_CONTINUE_NEAR_GRABBING: - this.continueNearGrabbing(); - break; - case STATE_NEAR_GRABBING_NON_COLLIDING: - this.nearGrabbingNonColliding(); - break; - case STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING: - this.continueNearGrabbingNonColliding(); - break; - case STATE_RELEASE: - this.release(); - break; - } - }; - - this.lineOn = function(closePoint, farPoint, color) { - // draw a line - if (this.pointer === null) { - this.pointer = Entities.addEntity({ - type: "Line", - name: "pointer", - dimensions: LINE_ENTITY_DIMENSIONS, - visible: true, - position: closePoint, - linePoints: [ZERO_VEC, farPoint], - color: color, - lifetime: LIFETIME - }); - } else { - Entities.editEntity(this.pointer, { - position: closePoint, - linePoints: [ZERO_VEC, farPoint], - color: color, - lifetime: (Date.now() - startTime) / MSEC_PER_SEC + LIFETIME - }); - } - - }; - - this.lineOff = function() { - if (this.pointer !== null) { - Entities.deleteEntity(this.pointer); - } - this.pointer = null; - }; - - this.triggerSmoothedSqueezed = function() { - var triggerValue = Controller.getActionValue(this.triggerAction); - // smooth out trigger value - this.triggerValue = (this.triggerValue * TRIGGER_SMOOTH_RATIO) + - (triggerValue * (1.0 - TRIGGER_SMOOTH_RATIO)); - return this.triggerValue > TRIGGER_ON_VALUE; - }; - - this.triggerSqueezed = function() { - var triggerValue = Controller.getActionValue(this.triggerAction); - return triggerValue > TRIGGER_ON_VALUE; - }; - - this.search = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - - // the trigger is being pressed, do a ray test - var handPosition = this.getHandPosition(); - var pickRay = { - origin: handPosition, - direction: Quat.getUp(this.getHandRotation()) - }; - - var defaultGrabbableData = { - grabbable: true - }; - - var intersection = Entities.findRayIntersection(pickRay, true); - if (intersection.intersects && - intersection.properties.collisionsWillMove === 1 && - intersection.properties.locked === 0) { - // the ray is intersecting something we can move. - var handControllerPosition = Controller.getSpatialControlPosition(this.palm); - var intersectionDistance = Vec3.distance(handControllerPosition, intersection.intersection); - this.grabbedEntity = intersection.entityID; - - var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, defaultGrabbableData); - if (grabbableData.grabbable === false) { - return; - } - if (intersectionDistance < NEAR_PICK_MAX_DISTANCE) { - // the hand is very close to the intersected object. go into close-grabbing mode. - this.state = STATE_NEAR_GRABBING; - - } else { - // the hand is far from the intersected object. go into distance-holding mode - this.state = STATE_DISTANCE_HOLDING; - this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); - } - } else { - // forward ray test failed, try sphere test. - var nearbyEntities = Entities.findEntities(handPosition, GRAB_RADIUS); - var minDistance = GRAB_RADIUS; - var i, props, distance; - - for (i = 0; i < nearbyEntities.length; i++) { - - var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, nearbyEntities[i], defaultGrabbableData); - if (grabbableData.grabbable === false) { - return; - } - - props = Entities.getEntityProperties(nearbyEntities[i], ["position", "name", "collisionsWillMove", "locked"]); - - distance = Vec3.distance(props.position, handPosition); - if (distance < minDistance && props.name !== "pointer") { - this.grabbedEntity = nearbyEntities[i]; - minDistance = distance; - } - } - if (this.grabbedEntity === null) { - this.lineOn(pickRay.origin, Vec3.multiply(pickRay.direction, LINE_LENGTH), NO_INTERSECT_COLOR); - } else if (props.locked === 0 && props.collisionsWillMove === 1) { - this.state = STATE_NEAR_GRABBING; - } else if (props.collisionsWillMove === 0) { - // We have grabbed a non-physical object, so we want to trigger a non-colliding event as opposed to a grab event - this.state = STATE_NEAR_GRABBING_NON_COLLIDING; - } - } - - }; - - this.distanceHolding = function() { - var handControllerPosition = Controller.getSpatialControlPosition(this.palm); - var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(this.palm)); - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]); - - // add the action and initialize some variables - this.currentObjectPosition = grabbedProperties.position; - this.currentObjectRotation = grabbedProperties.rotation; - this.currentObjectTime = Date.now(); - this.handPreviousPosition = handControllerPosition; - this.handPreviousRotation = handRotation; - - this.actionID = Entities.addAction("spring", this.grabbedEntity, { - targetPosition: this.currentObjectPosition, - linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, - targetRotation: this.currentObjectRotation, - angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME - }); - if (this.actionID === NULL_ACTION_ID) { - this.actionID = null; - } - - if (this.actionID !== null) { - this.state = STATE_CONTINUE_DISTANCE_HOLDING; - this.activateEntity(this.grabbedEntity); - if (this.hand === RIGHT_HAND) { - Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); - } else { - Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); - } - Entities.callEntityMethod(this.grabbedEntity, "startDistantGrab"); - } - - this.currentAvatarPosition = MyAvatar.position; - this.currentAvatarOrientation = MyAvatar.orientation; - - }; - - this.continueDistanceHolding = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - - var handPosition = this.getHandPosition(); - var handControllerPosition = Controller.getSpatialControlPosition(this.palm); - var handRotation = Quat.multiply(MyAvatar.orientation, Controller.getSpatialControlRawRotation(this.palm)); - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]); - - this.lineOn(handPosition, Vec3.subtract(grabbedProperties.position, handPosition), INTERSECT_COLOR); - - // the action was set up on a previous call. update the targets. - var radius = Math.max(Vec3.distance(this.currentObjectPosition, handControllerPosition) * DISTANCE_HOLDING_RADIUS_FACTOR, DISTANCE_HOLDING_RADIUS_FACTOR); - - // how far did avatar move this timestep? - var currentPosition = MyAvatar.position; - var avatarDeltaPosition = Vec3.subtract(currentPosition, this.currentAvatarPosition); - this.currentAvatarPosition = currentPosition; - - // How far did the avatar turn this timestep? - // Note: The following code is too long because we need a Quat.quatBetween() function - // that returns the minimum quaternion between two quaternions. - var currentOrientation = MyAvatar.orientation; - if (Quat.dot(currentOrientation, this.currentAvatarOrientation) < 0.0) { - var negativeCurrentOrientation = { - x: -currentOrientation.x, - y: -currentOrientation.y, - z: -currentOrientation.z, - w: -currentOrientation.w - }; - var avatarDeltaOrientation = Quat.multiply(negativeCurrentOrientation, Quat.inverse(this.currentAvatarOrientation)); - } else { - var avatarDeltaOrientation = Quat.multiply(currentOrientation, Quat.inverse(this.currentAvatarOrientation)); - } - var handToAvatar = Vec3.subtract(handControllerPosition, this.currentAvatarPosition); - var objectToAvatar = Vec3.subtract(this.currentObjectPosition, this.currentAvatarPosition); - var handMovementFromTurning = Vec3.subtract(Quat.multiply(avatarDeltaOrientation, handToAvatar), handToAvatar); - var objectMovementFromTurning = Vec3.subtract(Quat.multiply(avatarDeltaOrientation, objectToAvatar), objectToAvatar); - this.currentAvatarOrientation = currentOrientation; - - // how far did hand move this timestep? - var handMoved = Vec3.subtract(handControllerPosition, this.handPreviousPosition); - this.handPreviousPosition = handControllerPosition; - - // magnify the hand movement but not the change from avatar movement & rotation - handMoved = Vec3.subtract(handMoved, avatarDeltaPosition); - handMoved = Vec3.subtract(handMoved, handMovementFromTurning); - var superHandMoved = Vec3.multiply(handMoved, radius); - - // Move the object by the magnified amount and then by amount from avatar movement & rotation - var newObjectPosition = Vec3.sum(this.currentObjectPosition, superHandMoved); - newObjectPosition = Vec3.sum(newObjectPosition, avatarDeltaPosition); - newObjectPosition = Vec3.sum(newObjectPosition, objectMovementFromTurning); - - var deltaPosition = Vec3.subtract(newObjectPosition, this.currentObjectPosition); // meters - var now = Date.now(); - var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds - this.computeReleaseVelocity(deltaPosition, deltaTime, false); - - this.currentObjectPosition = newObjectPosition; - this.currentObjectTime = now; - - // this doubles hand rotation - var handChange = Quat.multiply(Quat.slerp(this.handPreviousRotation, handRotation, DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR), Quat.inverse(this.handPreviousRotation)); - this.handPreviousRotation = handRotation; - this.currentObjectRotation = Quat.multiply(handChange, this.currentObjectRotation); - - Entities.callEntityMethod(this.grabbedEntity, "continueDistantGrab"); - - Entities.updateAction(this.grabbedEntity, this.actionID, { - targetPosition: this.currentObjectPosition, - linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, - targetRotation: this.currentObjectRotation, - angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME - }); - }; - - this.nearGrabbing = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - - this.lineOff(); - - this.activateEntity(this.grabbedEntity); - - var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, ["position", "rotation"]); - - var handRotation = this.getHandRotation(); - var handPosition = this.getHandPosition(); - - var objectRotation = grabbedProperties.rotation; - var offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation); - - var currentObjectPosition = grabbedProperties.position; - var offset = Vec3.subtract(currentObjectPosition, handPosition); - var offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, offsetRotation)), offset); - - this.actionID = Entities.addAction("hold", this.grabbedEntity, { - hand: this.hand === RIGHT_HAND ? "right" : "left", - timeScale: NEAR_GRABBING_ACTION_TIMEFRAME, - relativePosition: offsetPosition, - relativeRotation: offsetRotation - }); - if (this.actionID === NULL_ACTION_ID) { - this.actionID = null; - } else { - this.state = STATE_CONTINUE_NEAR_GRABBING; - if (this.hand === RIGHT_HAND) { - Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); - } else { - Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); - } - Entities.callEntityMethod(this.grabbedEntity, "startNearGrab"); - - } - - this.currentHandControllerTipPosition = Controller.getSpatialControlPosition(this.tip); - - this.currentObjectTime = Date.now(); - }; - - this.continueNearGrabbing = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - - // Keep track of the fingertip velocity to impart when we release the object - // Note that the idea of using a constant 'tip' velocity regardless of the - // object's actual held offset is an idea intended to make it easier to throw things: - // Because we might catch something or transfer it between hands without a good idea - // of it's actual offset, let's try imparting a velocity which is at a fixed radius - // from the palm. - - var handControllerPosition = Controller.getSpatialControlPosition(this.tip); - var now = Date.now(); - - var deltaPosition = Vec3.subtract(handControllerPosition, this.currentHandControllerTipPosition); // meters - var deltaTime = (now - this.currentObjectTime) / MSEC_PER_SEC; // convert to seconds - this.computeReleaseVelocity(deltaPosition, deltaTime, true); - - this.currentHandControllerTipPosition = handControllerPosition; - this.currentObjectTime = now; - Entities.callEntityMethod(this.grabbedEntity, "continueNearGrab"); - }; - - this.nearGrabbingNonColliding = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - if (this.hand === RIGHT_HAND) { - Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); - } else { - Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); - } - Entities.callEntityMethod(this.grabbedEntity, "startNearGrabNonColliding"); - this.state = STATE_CONTINUE_NEAR_GRABBING_NON_COLLIDING; - }; - - this.continueNearGrabbingNonColliding = function() { - if (!this.triggerSmoothedSqueezed()) { - this.state = STATE_RELEASE; - return; - } - Entities.callEntityMethod(this.grabbedEntity, "continueNearGrabbingNonColliding"); - }; - - _this.allTouchedIDs = {}; - this.touchTest = function() { - var maxDistance = 0.05; - var leftHandPosition = MyAvatar.getLeftPalmPosition(); - var rightHandPosition = MyAvatar.getRightPalmPosition(); - var leftEntities = Entities.findEntities(leftHandPosition, maxDistance); - var rightEntities = Entities.findEntities(rightHandPosition, maxDistance); - var ids = []; - - if (leftEntities.length !== 0) { - leftEntities.forEach(function(entity) { - ids.push(entity); - }); - - } - - if (rightEntities.length !== 0) { - rightEntities.forEach(function(entity) { - ids.push(entity); - }); - } - - ids.forEach(function(id) { - - var props = Entities.getEntityProperties(id, ["boundingBox", "name"]); - if (props.name === 'pointer') { - return; - } else { - var entityMinPoint = props.boundingBox.brn; - var entityMaxPoint = props.boundingBox.tfl; - var leftIsTouching = pointInExtents(leftHandPosition, entityMinPoint, entityMaxPoint); - var rightIsTouching = pointInExtents(rightHandPosition, entityMinPoint, entityMaxPoint); - - if ((leftIsTouching || rightIsTouching) && _this.allTouchedIDs[id] === undefined) { - // we haven't been touched before, but either right or left is touching us now - _this.allTouchedIDs[id] = true; - _this.startTouch(id); - } else if ((leftIsTouching || rightIsTouching) && _this.allTouchedIDs[id] === true) { - // we have been touched before and are still being touched - // continue touch - _this.continueTouch(id); - } else if (_this.allTouchedIDs[id] === true) { - delete _this.allTouchedIDs[id]; - _this.stopTouch(id); - - } else { - //we are in another state - return; - } - } - - }); - - }; - - this.startTouch = function(entityID) { - Entities.callEntityMethod(entityID, "startTouch"); - }; - - this.continueTouch = function(entityID) { - Entities.callEntityMethod(entityID, "continueTouch"); - }; - - this.stopTouch = function(entityID) { - Entities.callEntityMethod(entityID, "stopTouch"); - }; - - this.computeReleaseVelocity = function(deltaPosition, deltaTime, useMultiplier) { - if (deltaTime > 0.0 && !vec3equal(deltaPosition, ZERO_VEC)) { - var grabbedVelocity = Vec3.multiply(deltaPosition, 1.0 / deltaTime); - // don't update grabbedVelocity if the trigger is off. the smoothing of the trigger - // value would otherwise give the held object time to slow down. - if (this.triggerSqueezed()) { - this.grabbedVelocity = - Vec3.sum(Vec3.multiply(this.grabbedVelocity, (1.0 - NEAR_GRABBING_VELOCITY_SMOOTH_RATIO)), - Vec3.multiply(grabbedVelocity, NEAR_GRABBING_VELOCITY_SMOOTH_RATIO)); - } - - if (useMultiplier) { - this.grabbedVelocity = Vec3.multiply(this.grabbedVelocity, RELEASE_VELOCITY_MULTIPLIER); - } - } - }; - - this.release = function() { - this.lineOff(); - - if (this.grabbedEntity !== null) { - if(this.actionID !== null) { - Entities.deleteAction(this.grabbedEntity, this.actionID); - } - Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); - } - - // the action will tend to quickly bring an object's velocity to zero. now that - // the action is gone, set the objects velocity to something the holder might expect. - Entities.editEntity(this.grabbedEntity, { - velocity: this.grabbedVelocity - }); - this.deactivateEntity(this.grabbedEntity); - - this.grabbedVelocity = ZERO_VEC; - this.grabbedEntity = null; - this.actionID = null; - this.state = STATE_SEARCHING; - }; - - this.cleanup = function() { - this.release(); - }; - - this.activateEntity = function() { - var data = { - activated: true, - avatarId: MyAvatar.sessionUUID - }; - setEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, data); - }; - - this.deactivateEntity = function() { - var data = { - activated: false, - avatarId: null - }; - setEntityCustomData(GRAB_USER_DATA_KEY, this.grabbedEntity, data); - }; -} - -var rightController = new MyController(RIGHT_HAND, Controller.findAction("RIGHT_HAND_CLICK")); -var leftController = new MyController(LEFT_HAND, Controller.findAction("LEFT_HAND_CLICK")); - -function update() { - rightController.update(); - leftController.update(); -} - -function cleanup() { - rightController.cleanup(); - leftController.cleanup(); -} - -Script.scriptEnding.connect(cleanup); -Script.update.connect(update); \ No newline at end of file From 00cab85a1151b1fde7be3df9f399861945c7c270 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 18:33:31 -0700 Subject: [PATCH 110/138] Removed whiteboard from reset script --- examples/toys/masterResetEntity.js | 32 ------ examples/toys/whiteboard.js | 155 ----------------------------- 2 files changed, 187 deletions(-) delete mode 100644 examples/toys/whiteboard.js diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 3ed5e9a839..984baa6fed 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -86,12 +86,6 @@ function createAllToys() { }); - createWhiteboard({ - x: 500, - y: 500, - z: 500 - }); - createGates(); @@ -143,32 +137,6 @@ function createCat(position) { }); } -function createWhiteboard(position) { - var scriptURL = Script.resolvePath('whiteboard.js?v1' + Math.random()); - var whiteboard = Entities.addEntity({ - type: "Box", - position: position, - script: scriptURL, - name: "whiteboard", - dimensions: { - x: 2, - y: 1.5, - z: .01 - }, - color: { - red: 250, - green: 250, - blue: 250 - } - }); - - - setEntityCustomData(resetKey, whiteboard, { - resetMe: true - }); - -} - function createFlashlight(position) { var scriptURL = Script.resolvePath('flashlight/flashlight.js'); var modelURL = "https://hifi-public.s3.amazonaws.com/models/props/flashlight.fbx"; diff --git a/examples/toys/whiteboard.js b/examples/toys/whiteboard.js deleted file mode 100644 index 55a2fcb443..0000000000 --- a/examples/toys/whiteboard.js +++ /dev/null @@ -1,155 +0,0 @@ -// -// detectGrabExample.js -// examples/entityScripts -// -// Created by Eric Levin on 9/21/15. -// Copyright 2015 High Fidelity, Inc. -// -// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -(function() { - - var _this; - var MAX_POINTS_PER_LINE = 40; - var MIN_POINT_DISTANCE = 0.01; - var STROKE_WIDTH = 0.02; - var STROKE_COLOR = {red: 200, green: 20, blue: 160}; - - // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember - // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) - Whiteboard = function() { - _this = this; - - }; - - Whiteboard.prototype = { - - setRightHand: function() { - this.hand = 'RIGHT'; - this.getHandPosition = MyAvatar.getRightPalmPosition; - this.getHandRotation = MyAvatar.getRightPalmRotation; - }, - setLeftHand: function() { - this.hand = 'LEFT'; - this.getHandPosition = MyAvatar.getLeftPalmPosition; - this.getHandRotation = MyAvatar.getLeftPalmRotation; - }, - - startNearGrabNonColliding: function() { - this.whichHand = this.hand; - this.laserPointer = Entities.addEntity({ - type: "Box", - dimensions: { - x: STROKE_WIDTH, - y: STROKE_WIDTH, - z: 0.001 - }, - color: STROKE_COLOR, - rotation: this.rotation - }); - - setEntityCustomData(this.resetKey, this.laserPointer, { - resetMe: true - }); - - }, - - continueNearGrabbingNonColliding: function() { - var handPosition = this.getHandPosition(); - var pickRay = { - origin: handPosition, - direction: Quat.getUp(this.getHandRotation()) - }; - var intersection = Entities.findRayIntersection(pickRay, true); - if (intersection.intersects) { - Entities.editEntity(this.laserPointer, { - position: intersection.intersection - }); - this.paint(intersection.intersection, intersection.surfaceNormal); - } - - }, - - releaseGrab: function() { - Entities.deleteEntity(this.laserPointer); - this.painting = false; - }, - - paint: function(position, normal) { - if (!this.painting) { - this.newStroke(position); - this.painting = true; - } - - if (this.strokePoints.length > MAX_POINTS_PER_LINE) { - this.painting = false; - return; - } - - - var localPoint = Vec3.subtract(position, this.strokeBasePosition); - //Move stroke a bit forward along normal so it doesnt zfight with mesh its drawing on - localPoint = Vec3.sum(localPoint, Vec3.multiply(normal, .001)); - - if (this.strokePoints.length > 0 && Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]) < MIN_POINT_DISTANCE) { - //need a minimum distance to avoid binormal NANs - return; - } - - this.strokePoints.push(localPoint); - this.strokeNormals.push(normal); - this.strokeWidths.push(STROKE_WIDTH); - Entities.editEntity(this.currentStroke, { - linePoints: this.strokePoints, - normals: this.strokeNormals, - strokeWidths: this.strokeWidths - }); - }, - - newStroke: function(position) { - print("NEW STROKE") - this.strokeBasePosition = position; - this.currentStroke = Entities.addEntity({ - position: position, - type: "PolyLine", - color: STROKE_COLOR, - dimensions: { - x: 50, - y: 50, - z: 50 - }, - lifetime: 100 - }); - - setEntityCustomData(this.resetKey, this.currentStroke, { - resetMe: true - }); - this.strokePoints = []; - this.strokeNormals = []; - this.strokeWidths = []; - - this.strokes.push(this.currentStroke); - }, - - - // preload() will be called when the entity has become visible (or known) to the interface - // it gives us a chance to set our local JavaScript object up. In this case it means: - preload: function(entityID) { - this.entityID = entityID; - var props = Entities.getEntityProperties(this.entityID, ["position", "rotation"]); - this.position = props.position; - this.rotation = props.rotation; - this.resetKey = "resetMe"; - this.strokes = []; - - }, - - }; - - // entity scripts always need to return a newly constructed object of our type - return new Whiteboard(); -}) \ No newline at end of file From c03a9ddd584dfa935840b288f68f1533da8cd72b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 30 Sep 2015 11:14:18 -0700 Subject: [PATCH 111/138] Added fire to master script --- examples/toys/masterResetEntity.js | 82 ++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 3 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 984baa6fed..f087d77929 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -85,10 +85,10 @@ function createAllToys() { z: 504.53 }); - - createGates(); + + createFire(); } function deleteAllToys() { @@ -103,6 +103,82 @@ function deleteAllToys() { }); } +function createFire() { + + + 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: .01, + radiusStart: .02, + radiusEnd: 0.001, + particleRadius: .05, + radiusFinish: 0.0, + emitOrientation: myOrientation, + emitSpeed: .3, + speedSpread: 0.1, + alphaStart: 0.05, + alpha: 0.1, + alphaFinish: 0.05, + emitDimensions: { + x: 1, + y: 1, + z: .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("cat.js?v1"); @@ -758,4 +834,4 @@ function randFloat(low, high) { function randInt(low, high) { return Math.floor(randFloat(low, high)); -} +} \ No newline at end of file From 5aef7475d6c2f8d2ad6d107b7083ce24a19da320 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 14:42:51 -0700 Subject: [PATCH 112/138] Sound position updates every frame based on new position of can --- examples/toys/sprayPaintCan.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 18063474a0..dec6a8976a 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -99,7 +99,6 @@ } this.disableStream = function() { - print("DEKETE STEREAAAM") Entities.deleteEntity(this.paintStream); this.paintStream = null; this.sprayInjector.stop(); @@ -125,6 +124,8 @@ position: position, emitOrientation: forwardQuat, }); + this.sprayInjector.setOptions({position: position}); + } From 55c6b9d9c45b59a2279cb37d75d7c15a05e16ca6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 14:57:03 -0700 Subject: [PATCH 113/138] Added collision sound to blocks --- examples/toys/masterResetEntity.js | 2 ++ examples/toys/sprayPaintCan.js | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index f087d77929..4750b5657b 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -743,6 +743,7 @@ function createPillow(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; var i, j; @@ -799,6 +800,7 @@ function createBlocks(position) { name: "block", dimensions: blockTypes[i].dimensions, collisionsWillMove: true, + collisionSoundURL: collisionSoundURL, gravity: { x: 0, y: -2.5, diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index dec6a8976a..4716885ac3 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -129,9 +129,6 @@ } - - - this.preload = function(entityId) { this.spraying = false; this.entityId = entityId; From 8e2c1a6b170a518923238a9456bc78952644e5bd Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 1 Oct 2015 15:22:45 -0700 Subject: [PATCH 114/138] Add ping pong ball gun, add basketball hoop, reduce gate gravity, lint code --- examples/toys/masterResetEntity.js | 190 ++++++++++++++--------------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 4750b5657b..501e59fc5b 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -8,7 +8,7 @@ /*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ //per script -/*global deleteAllToys, createAllToys, createGates, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLightSwitches */ +/*global deleteAllToys, createAllToys, createGates, createPingPongBallGun, createFire, createPottedPlant, createCombinedArmChair, createBasketballHoop, createBasketBall, createSprayCan, createDoll, createWand, createDice, createCat, deleteAllToys, createFlashlight, createBlocks, createMagballs, createLightSwitches */ var utilitiesScript = Script.resolvePath("../libraries/utils.js"); Script.include(utilitiesScript); @@ -71,13 +71,11 @@ function createAllToys() { // //Handles toggling of all sconce lights createLightSwitches(); - - createCombinedArmChair({ x: 549.29, y: 495.05, z: 508.22 - }) + }); createPottedPlant({ x: 554.26, @@ -85,6 +83,9 @@ function createAllToys() { z: 504.53 }); + createPingPongBallGun(); + + createBasketballHoop(); createGates(); @@ -106,7 +107,7 @@ function deleteAllToys() { function createFire() { - myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0); + var myOrientation = Quat.fromPitchYawRollDegrees(-90, 0, 0.0); var animationSettings = JSON.stringify({ fps: 30, @@ -143,13 +144,13 @@ function createFire() { green: 99, blue: 32 }, - radiusSpread: .01, - radiusStart: .02, + radiusSpread: 0.01, + radiusStart: 0.02, radiusEnd: 0.001, - particleRadius: .05, + particleRadius: 0.05, radiusFinish: 0.0, emitOrientation: myOrientation, - emitSpeed: .3, + emitSpeed: 0.3, speedSpread: 0.1, alphaStart: 0.05, alpha: 0.1, @@ -157,7 +158,7 @@ function createFire() { emitDimensions: { x: 1, y: 1, - z: .1 + z: 0.1 }, polarFinish: 0.1, emitAcceleration: { @@ -383,7 +384,7 @@ function createGates() { collisionsWillMove: true, gravity: { x: 0, - y: -100, + y: -50, z: 0 }, linearDamping: 1, @@ -437,6 +438,86 @@ function createGates() { }); } +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('ping_pong_gun/pingPongGun.js'); + + var position = { + x: 548.6, + y: 495.4, + z: 503.39 + }; + + var rotation = Quat.fromPitchYawRollDegrees(0, 36, 0); + + var pingPongGun = Entities.addEntity({ + type: "Model", + modelURL: MODEL_URL, + shapeType: 'compound', + compoundShapeURL: COLLISION_HULL_URL, + script: scriptURL, + position: position, + rotation: rotation, + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + dimensions: { + x: 0.67, + y: 0.14, + z: 0.09 + }, + collisionsWillMove: true, + }); + + setEntityCustomData(resetKey, pingPongGun, { + resetMe: true + }); + + +} + +function createBasketballHoop() { + var position = { + x: 539.23, + y: 496.13, + z: 475.89 + }; + var rotation = Quat.fromPitchYawRollDegrees(0, 58.49, 0); + + var hoopURL = "http://hifi-public.s3.amazonaws.com/models/basketball_hoop/basketball_hoop.fbx"; + var hoopCollisionHullURL = "http://hifi-public.s3.amazonaws.com/models/basketball_hoop/basketball_hoop_collision_hull.obj"; + + var hoop = Entities.addEntity({ + type: "Model", + modelURL: hoopURL, + position: position, + rotation: rotation, + shapeType: 'compound', + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + dimensions: { + x: 1.89, + y: 3.99, + z: 3.79 + }, + compoundShapeURL: hoopCollisionHullURL + }); + + setEntityCustomData(resetKey, hoop, { + resetMe: true + }); + + setEntityCustomData(GRABBABLE_DATA_KEY, hoop, { + grabbable: false + }); +} + 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'; @@ -579,12 +660,9 @@ function createSprayCan(position) { } -//createPottedPlant,createArmChair,createPillow function createPottedPlant(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/potted_plant/potted_plant.fbx"; - var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - var entity = Entities.addEntity({ type: "Model", name: "Potted Plant", @@ -618,12 +696,12 @@ function createPottedPlant(position) { setEntityCustomData(GRABBABLE_DATA_KEY, entity, { grabbable: false }); -}; +} 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" + var RED_ARM_CHAIR_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_collision_hull.obj"; var rotation = Quat.fromPitchYawRollDegrees(0, -143, 0); @@ -661,85 +739,7 @@ function createCombinedArmChair(position) { setEntityCustomData(GRABBABLE_DATA_KEY, entity, { grabbable: false }); -}; - -function createArmChair(position) { - var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/new_red_arm_chair.fbx"; - var RED_ARM_CHAIR_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/new_red_arm_chair_collision_hull.obj" - - var rotation = Quat.fromPitchYawRollDegrees(0, -143, 0); - - var entity = Entities.addEntity({ - type: "Model", - name: "Red Arm Chair", - modelURL: modelURL, - shapeType: 'compound', - compoundShapeURL: RED_ARM_CHAIR_COLLISION_HULL, - position: position, - rotation: rotation, - dimensions: { - x: 1.26, - y: 1.56, - z: 1.35 - }, - collisionsWillMove: true, - gravity: { - x: 0, - y: -0.5, - z: 0 - }, - velocity: { - x: 0, - y: 0, - z: 0 - }, - linearDamping: 0.3 - }); - - setEntityCustomData(resetKey, entity, { - resetMe: true - }); -}; - -function createPillow(position) { - var modelURL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_pillow.fbx"; - var RED_ARM_CHAIR_PILLOW_COLLISION_HULL = "http://hifi-public.s3.amazonaws.com/models/red_arm_chair/red_arm_chair_pillow_collision_hull.obj" - - var rotation = Quat.fromPitchYawRollDegrees(-0.29, -143.05, 0.32); - - var entity = Entities.addEntity({ - type: "Model", - name: "Red Arm Chair Pillow", - modelURL: modelURL, - shapeType: 'compound', - compoundShapeURL: RED_ARM_CHAIR_PILLOW_COLLISION_HULL, - position: position, - rotation: rotation, - dimensions: { - x: 0.4, - y: 0.4, - z: 0.4 - }, - collisionsWillMove: true, - ignoreForCollisions: false, - gravity: { - x: 0, - y: -10.1, - z: 0 - }, - restitution: 0, - velocity: { - x: 0, - y: -0.1, - z: 0 - }, - linearDamping: 1 - }); - - setEntityCustomData(resetKey, entity, { - resetMe: true - }); -}; +} function createBlocks(position) { var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/"; From 25e25726d59d09c719234ea7694f376336fcd856 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 15:43:25 -0700 Subject: [PATCH 115/138] only lights --- examples/toys/masterResetEntity.js | 116 ++++++++++++++++------------- 1 file changed, 65 insertions(+), 51 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 4750b5657b..0382e569bb 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -20,75 +20,89 @@ 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(); +// deleteAllToys(); +deleteLights(); createAllToys(); function createAllToys() { - createBlocks({ - x: 548.3, - y: 495.55, - z: 504.4 - }); + // createBlocks({ + // x: 548.3, + // y: 495.55, + // z: 504.4 + // }); - createSprayCan({ - x: 549.7, - y: 495.6, - z: 503.91 - }); + // createSprayCan({ + // x: 549.7, + // y: 495.6, + // z: 503.91 + // }); - createBasketBall({ - x: 547.73, - y: 495.5, - z: 505.47 - }); + // createBasketBall({ + // x: 547.73, + // y: 495.5, + // z: 505.47 + // }); - createDoll({ - x: 546.67, - y: 495.41, - z: 505.09 - }); + // createDoll({ + // x: 546.67, + // y: 495.41, + // z: 505.09 + // }); - createWand({ - x: 546.71, - y: 495.55, - z: 506.15 - }); + // createWand({ + // x: 546.71, + // y: 495.55, + // z: 506.15 + // }); - createDice(); + // createDice(); - createFlashlight({ - x: 545.72, - y: 495.41, - z: 505.78 - }); + // createFlashlight({ + // x: 545.72, + // y: 495.41, + // z: 505.78 + // }); - createCat({ - x: 551.09, - y: 494.98, - z: 503.49 - }); + // createCat({ + // x: 551.09, + // y: 494.98, + // z: 503.49 + // }); + // createCombinedArmChair({ + // x: 549.29, + // y: 495.05, + // z: 508.22 + // }) + + // createPottedPlant({ + // x: 554.26, + // y: 495.23, + // z: 504.53 + // }); + + + // createGates(); + + // createFire(); // //Handles toggling of all sconce lights createLightSwitches(); - createCombinedArmChair({ - x: 549.29, - y: 495.05, - z: 508.22 - }) +} - createPottedPlant({ - x: 554.26, - y: 495.23, - z: 504.53 +function deleteLights() { + var entities = Entities.findEntities(MyAvatar.position, 100); + + entities.forEach(function(entity) { + //params: customKey, id, defaultValue + var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; + var lightType = getEntityCustomData(resetKey, entity, {}).lightType; + if (shouldReset === true && (lightType === "Sconce Light Garage" || lightType === "Sconce Light Hall")) { + Entities.deleteEntity(entity); + } }); - - - createGates(); - - createFire(); } function deleteAllToys() { From cdb249c6ff1add3932d1759429c3f0de8efd8363 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 15:53:28 -0700 Subject: [PATCH 116/138] original master script --- examples/toys/masterResetEntity.js | 100 ++++++++++++++--------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index 0382e569bb..ef7990b942 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -20,71 +20,71 @@ 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(); -deleteLights(); +deleteAllToys(); +// deleteLights(); createAllToys(); function createAllToys() { - // createBlocks({ - // x: 548.3, - // y: 495.55, - // z: 504.4 - // }); + createBlocks({ + x: 548.3, + y: 495.55, + z: 504.4 + }); - // createSprayCan({ - // x: 549.7, - // y: 495.6, - // z: 503.91 - // }); + createSprayCan({ + x: 549.7, + y: 495.6, + z: 503.91 + }); - // createBasketBall({ - // x: 547.73, - // y: 495.5, - // z: 505.47 - // }); + createBasketBall({ + x: 547.73, + y: 495.5, + z: 505.47 + }); - // createDoll({ - // x: 546.67, - // y: 495.41, - // z: 505.09 - // }); + createDoll({ + x: 546.67, + y: 495.41, + z: 505.09 + }); - // createWand({ - // x: 546.71, - // y: 495.55, - // z: 506.15 - // }); + createWand({ + x: 546.71, + y: 495.55, + z: 506.15 + }); - // createDice(); + createDice(); - // createFlashlight({ - // x: 545.72, - // y: 495.41, - // z: 505.78 - // }); + createFlashlight({ + x: 545.72, + y: 495.41, + z: 505.78 + }); - // createCat({ - // x: 551.09, - // y: 494.98, - // z: 503.49 - // }); + createCat({ + x: 551.09, + y: 494.98, + z: 503.49 + }); - // createCombinedArmChair({ - // x: 549.29, - // y: 495.05, - // z: 508.22 - // }) + createCombinedArmChair({ + x: 549.29, + y: 495.05, + z: 508.22 + }) - // createPottedPlant({ - // x: 554.26, - // y: 495.23, - // z: 504.53 - // }); + createPottedPlant({ + x: 554.26, + y: 495.23, + z: 504.53 + }); - // createGates(); + createGates(); - // createFire(); + createFire(); // //Handles toggling of all sconce lights createLightSwitches(); From 0fb51a67778bc6bfe902aabe2bd2162127bf9b12 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 15:56:16 -0700 Subject: [PATCH 117/138] got rid of unneeded light test code --- examples/toys/masterResetEntity.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index ef7990b942..966acc19b2 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -21,7 +21,6 @@ var shouldDeleteOnEndScript = false; //Before creating anything, first search a radius and delete all the things that should be deleted deleteAllToys(); -// deleteLights(); createAllToys(); function createAllToys() { @@ -92,19 +91,6 @@ function createAllToys() { } -function deleteLights() { - var entities = Entities.findEntities(MyAvatar.position, 100); - - entities.forEach(function(entity) { - //params: customKey, id, defaultValue - var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; - var lightType = getEntityCustomData(resetKey, entity, {}).lightType; - if (shouldReset === true && (lightType === "Sconce Light Garage" || lightType === "Sconce Light Hall")) { - Entities.deleteEntity(entity); - } - }); -} - function deleteAllToys() { var entities = Entities.findEntities(MyAvatar.position, 100); From 407b6b8158b34dc1a729cb15e2f2bc90f78ae5f3 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 16:10:29 -0700 Subject: [PATCH 118/138] Fixed bug in spray paint where sometimes would not spray --- examples/toys/sprayPaintCan.js | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 4716885ac3..0de95f5d93 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -101,6 +101,7 @@ this.disableStream = function() { Entities.deleteEntity(this.paintStream); this.paintStream = null; + this.spraying = false; this.sprayInjector.stop(); } @@ -145,35 +146,3 @@ }); } }); - - - -function randFloat(min, max) { - return Math.random() * (max - min) + min; -} - -function randInt(min, max) { - return Math.floor(Math.random() * (max - min)) + min; -} - -function orientationOf(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); -} \ No newline at end of file From b352ab473632a4c1bbecb73cc28ab8b233866772 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:04:37 -0700 Subject: [PATCH 119/138] Update lightSwitchGarage.js fix header and spacing issues --- examples/toys/lightSwitchGarage.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/examples/toys/lightSwitchGarage.js b/examples/toys/lightSwitchGarage.js index 5f302ff47e..19d33117df 100644 --- a/examples/toys/lightSwitchGarage.js +++ b/examples/toys/lightSwitchGarage.js @@ -1,11 +1,10 @@ // -// detectGrabExample.js +// lightSwitchGarage.js.js // examples/entityScripts // // Created by Eric Levin on 9/21/15. // Copyright 2015 High Fidelity, Inc. // -// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -15,7 +14,6 @@ var _this; - // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) LightSwitchGarage = function() { @@ -78,7 +76,6 @@ createLights: function() { - var sconceLight3 = Entities.addEntity({ type: "Light", position: { @@ -113,7 +110,6 @@ y: 496.24026489257812, z: 507.90237426757812 }, - name: "Sconce 4 Light", dimensions: { x: 2.545, @@ -159,12 +155,9 @@ lightType: "Sconce Light Garage" }); - - setEntityCustomData(this.lightStateKey, this.entityID, { on: true }); - }, flipLights: function() { @@ -185,9 +178,6 @@ }, - - // preload() will be called when the entity has become visible (or known) to the interface - // it gives us a chance to set our local JavaScript object up. In this case it means: preload: function(entityID) { this.entityID = entityID; @@ -209,4 +199,4 @@ // entity scripts always need to return a newly constructed object of our type return new LightSwitchGarage(); -}) \ No newline at end of file +}) From 9098585e2fa975abef2a5694713bb9eaee3c740d Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:14:08 -0700 Subject: [PATCH 120/138] Update cat.js remove a lot of unused code and add flag for whether cat is already meowing so that it doesn't start another one until its done. unfortunately i dont know how to read the audio isplaying state so we have to use a lame timeout --- examples/toys/cat.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index a71cec95c2..156765ed00 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -1,12 +1,11 @@ // -// doll.js +// cat.js // examples/toybox/entityScripts // // Created by Eric Levin on 9/21/15. // Copyright 2015 High Fidelity, Inc. // -// This entity script breathes movement and sound- one might even say life- into a doll. -// + // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // @@ -15,20 +14,23 @@ var _this; - // this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember - // our this object, so we can access it in cases where we're called without a this (like in the case of various global signals) Cat = function() { _this = this; this.meowSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Animals/cat_meow.wav"); - this.distanceThreshold = 1; - this.canMeow = true; - this.meowBreakTime = 3000; }; Cat.prototype = { - + isMeowing:false, startTouch: function() { - this.meow(); + var _ t=this; + if(this.isMeowing!==true){ + this.meow(); + this.isMeowing=true; + Script.setTimeout(function(){ + _t.isMeowing=false; + },2000) + } + }, meow: function() { @@ -38,14 +40,10 @@ volume: .1 }); }, - // preload() will be called when the entity has become visible (or known) to the interface - // it gives us a chance to set our local JavaScript object up. In this case it means: - // * remembering our entityID, so we can access it in cases where we're called without an entityID - // * connecting to the update signal so we can check our grabbed state + preload: function(entityID) { this.entityID = entityID; this.position = Entities.getEntityProperties(this.entityID, "position").position; - Script.update.connect(this.update); }, unload: function() { @@ -55,4 +53,4 @@ // entity scripts always need to return a newly constructed object of our type return new Cat(); -}); \ No newline at end of file +}); From cfb9728fdb8d4478d0cc2d9e3be4b8dd394bc697 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:17:35 -0700 Subject: [PATCH 121/138] Update doll.js remove some unused code --- examples/toys/doll/doll.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index eeb4f8ee8a..79e8a28fb5 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -56,12 +56,11 @@ }, continueNearGrab: function() { - var props = Entities.getEntityProperties(this.entityID, ["position", "animationFrameIndex"]); + var props = Entities.getEntityProperties(this.entityID, ["position"]); var audioOptions = { position: props.position }; this.audioInjector.options = audioOptions; - }, releaseGrab: function() { @@ -84,12 +83,9 @@ }, preload: function(entityID) { - // preload() will be called when the entity has become visible (or known) to the interface - // it gives us a chance to set our local JavaScript object up. In this case it means: - // * remembering our entityID, so we can access it in cases where we're called without an entityID this.entityID = entityID; }, }; // entity scripts always need to return a newly constructed object of our type return new Doll(); -}); \ No newline at end of file +}); From 6523a057a866418d77dfead1efde6175bc56f442 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:18:27 -0700 Subject: [PATCH 122/138] Update lightSwitchHall.js fix header file --- examples/toys/lightSwitchHall.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/toys/lightSwitchHall.js b/examples/toys/lightSwitchHall.js index 4dd1a867de..e1093311f9 100644 --- a/examples/toys/lightSwitchHall.js +++ b/examples/toys/lightSwitchHall.js @@ -1,11 +1,10 @@ // -// detectGrabExample.js +// lightSwitchHall.js // examples/entityScripts // // Created by Eric Levin on 9/21/15. // Copyright 2015 High Fidelity, Inc. // -// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -25,7 +24,6 @@ this.resetKey = "resetMe"; this.switchSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/sounds/Switches%20and%20sliders/lamp_switch_2.wav"); - }; LightSwitchHall.prototype = { @@ -178,4 +176,4 @@ // entity scripts always need to return a newly constructed object of our type return new LightSwitchHall(); -}) \ No newline at end of file +}) From 54a51e6b8b11a210bbf2939e774d5ceba63fac4e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:19:36 -0700 Subject: [PATCH 123/138] Update and rename masterResetEntity.js to masterReset.js remove reference to 'entities' in the file name since this script does more than that. also update the header file. --- examples/toys/{masterResetEntity.js => masterReset.js} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename examples/toys/{masterResetEntity.js => masterReset.js} (99%) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterReset.js similarity index 99% rename from examples/toys/masterResetEntity.js rename to examples/toys/masterReset.js index f9471611be..8137f27f70 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterReset.js @@ -1,4 +1,4 @@ -// +// masterReset.js // Created by Eric Levin on 9/23/2015 // Copyright 2015 High Fidelity, Inc. // @@ -842,4 +842,4 @@ function randFloat(low, high) { function randInt(low, high) { return Math.floor(randFloat(low, high)); -} \ No newline at end of file +} From 3565d96ffb19b225798e161cc492e85d860c3240 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:21:15 -0700 Subject: [PATCH 124/138] Update sprayPaintCan.js add a header, cleanup --- examples/toys/sprayPaintCan.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 0de95f5d93..5c524a38bc 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -1,3 +1,14 @@ +// +// sprayPaintCan.js +// examples/entityScripts +// +// Created by Eric Levin on 9/21/15. +// 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 +// + + (function() { // Script.include("../libraries/utils.js"); //Need absolute path for now, for testing before PR merge and s3 cloning. Will change post-merge @@ -13,7 +24,7 @@ x: 0, y: 0, z: 0 - } + }; // if the trigger value goes below this while held, the can will stop spraying. if it goes above, it will spray var DISABLE_SPRAY_THRESHOLD = 0.5; @@ -129,14 +140,12 @@ } - this.preload = function(entityId) { this.spraying = false; this.entityId = entityId; this.resetKey = "resetMe"; } - this.unload = function() { if (this.paintStream) { Entities.deleteEntity(this.paintStream); From 6cc2df90524511a57e491f9c90b0850a914e5c84 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:34:22 -0700 Subject: [PATCH 125/138] Update cat.js hook into isPlaying for sounds --- examples/toys/cat.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index 156765ed00..34dea1fb80 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -21,29 +21,36 @@ Cat.prototype = { isMeowing:false, + this.injector:null, startTouch: function() { var _ t=this; if(this.isMeowing!==true){ this.meow(); this.isMeowing=true; - Script.setTimeout(function(){ - _t.isMeowing=false; - },2000) } }, - + + update:function(){ + if(this.injector!==null){ + this.isMeowing = this.injector.isPlaying; + } + if(this.isMeowing===false){ + this.injector=null + } + } + meow: function() { - - Audio.playSound(this.meowSound, { + this.injector = Audio.playSound(this.meowSound, { position: this.position, - volume: .1 + volume: 0.1 }); }, preload: function(entityID) { this.entityID = entityID; this.position = Entities.getEntityProperties(this.entityID, "position").position; + Script.update.connect(this.update); }, unload: function() { From f200fcdfa2704a9fc0edcfc1e5078ed92e284dc4 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:35:34 -0700 Subject: [PATCH 126/138] Update cat.js --- examples/toys/cat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index 34dea1fb80..bde0a5a2c4 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -21,7 +21,7 @@ Cat.prototype = { isMeowing:false, - this.injector:null, + injector:null, startTouch: function() { var _ t=this; if(this.isMeowing!==true){ From 59c1c7ee6a6502dc14340a598ebae718d4a0e607 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:40:12 -0700 Subject: [PATCH 127/138] Update masterReset.js remove file versioning --- examples/toys/masterReset.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/toys/masterReset.js b/examples/toys/masterReset.js index 8137f27f70..029f7f1ba6 100644 --- a/examples/toys/masterReset.js +++ b/examples/toys/masterReset.js @@ -188,7 +188,7 @@ function createFire() { function createCat(position) { - var scriptURL = Script.resolvePath("cat.js?v1"); + var scriptURL = Script.resolvePath("cat.js"); 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({ @@ -256,8 +256,8 @@ function createFlashlight(position) { } function createLightSwitches() { - var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/lightswitch.fbx?v1"; - var scriptURL = Script.resolvePath("lightSwitchHall.js?v1"); + var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/lightswitch.fbx"; + var scriptURL = Script.resolvePath("lightSwitchHall.js"); var lightSwitchHall = Entities.addEntity({ type: "Model", @@ -286,7 +286,7 @@ function createLightSwitches() { resetMe: true }); - scriptURL = Script.resolvePath("lightSwitchGarage.js?v1"); + scriptURL = Script.resolvePath("lightSwitchGarage.js"); var lightSwitchGarage = Entities.addEntity({ type: "Model", @@ -597,7 +597,7 @@ function createBasketBall(position) { function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; - var scriptURL = Script.resolvePath("doll/doll.js?v2"); + var scriptURL = Script.resolvePath("doll/doll.js"); var naturalDimensions = { x: 1.63, @@ -632,7 +632,7 @@ function createDoll(position) { } function createSprayCan(position) { - var scriptURL = Script.resolvePath("sprayPaintCan.js?v1" + Math.random()); + var scriptURL = Script.resolvePath("sprayPaintCan.js") ; var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; var entity = Entities.addEntity({ From 55d20e9d4cd30b9f10a8405ad1e710f90207241e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:41:24 -0700 Subject: [PATCH 128/138] Update cat.js --- examples/toys/cat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index bde0a5a2c4..44991dd9bd 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -23,7 +23,7 @@ isMeowing:false, injector:null, startTouch: function() { - var _ t=this; + var _t=this; if(this.isMeowing!==true){ this.meow(); this.isMeowing=true; From d0e079ee9dd48e82c74e2d36b86701cb50377cf5 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:46:32 -0700 Subject: [PATCH 129/138] Update cat.js add globals, lint the code --- examples/toys/cat.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index 44991dd9bd..537e0c21b4 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -8,45 +8,42 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// +/*global Cat, print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */ + (function() { - var _this; - Cat = function() { - _this = this; this.meowSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Animals/cat_meow.wav"); }; Cat.prototype = { - isMeowing:false, - injector:null, + isMeowing: false, + injector: null, startTouch: function() { - var _t=this; - if(this.isMeowing!==true){ + if (this.isMeowing !== true) { this.meow(); - this.isMeowing=true; + this.isMeowing = true; } }, - - update:function(){ - if(this.injector!==null){ - this.isMeowing = this.injector.isPlaying; + + update: function() { + if (this.injector !== null) { + this.isMeowing = this.injector.isPlaying; } - if(this.isMeowing===false){ - this.injector=null + if (this.isMeowing === false) { + this.injector = null; } - } - + }, + meow: function() { this.injector = Audio.playSound(this.meowSound, { position: this.position, volume: 0.1 }); }, - + preload: function(entityID) { this.entityID = entityID; this.position = Entities.getEntityProperties(this.entityID, "position").position; From 0ce6a305bdb200fa85949eda66f4e918fd9642f6 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:52:08 -0700 Subject: [PATCH 130/138] Update cat.js --- examples/toys/cat.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index 537e0c21b4..63a8a351d4 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -13,7 +13,9 @@ (function() { +var _this; Cat = function() { + _this=this; this.meowSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Animals/cat_meow.wav"); }; @@ -29,11 +31,11 @@ }, update: function() { - if (this.injector !== null) { - this.isMeowing = this.injector.isPlaying; + if (_this.injector !== null) { + _this.isMeowing = this.injector.isPlaying; } - if (this.isMeowing === false) { - this.injector = null; + if (_this.isMeowing === false) { + _this.injector = null; } }, From a3c91b12b9c8d1fa7cb83739adc95cd482279b78 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:56:38 -0700 Subject: [PATCH 131/138] Update cat.js --- examples/toys/cat.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index 63a8a351d4..beca627539 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -33,10 +33,11 @@ var _this; update: function() { if (_this.injector !== null) { _this.isMeowing = this.injector.isPlaying; + if (_this.isMeowing === false) { + _this.injector = null; + } } - if (_this.isMeowing === false) { - _this.injector = null; - } + }, meow: function() { From 36f7bba87e3f1d269b1d57b7e048ba23aa27cbd1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 09:53:30 -0700 Subject: [PATCH 132/138] Fixed some syntax errors, tweaked cat script so doesn't meow while it's already meowing --- examples/toys/cat.js | 25 +- examples/toys/doll/doll.js | 5 +- examples/toys/masterResetEntity.js | 845 +++++++++++++++++++++++++++++ 3 files changed, 853 insertions(+), 22 deletions(-) create mode 100644 examples/toys/masterResetEntity.js diff --git a/examples/toys/cat.js b/examples/toys/cat.js index beca627539..64736e9978 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -13,9 +13,9 @@ (function() { -var _this; + var _this; Cat = function() { - _this=this; + _this = this; this.meowSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Animals/cat_meow.wav"); }; @@ -29,35 +29,24 @@ var _this; } }, - - update: function() { - if (_this.injector !== null) { - _this.isMeowing = this.injector.isPlaying; - if (_this.isMeowing === false) { - _this.injector = null; - } - } - - }, - meow: function() { this.injector = Audio.playSound(this.meowSound, { position: this.position, volume: 0.1 }); + Script.setTimeout(function() { + _this.isMeowing = false; + }, this.soundClipTime) }, preload: function(entityID) { this.entityID = entityID; this.position = Entities.getEntityProperties(this.entityID, "position").position; - Script.update.connect(this.update); + this.soundClipTime = 700; }, - unload: function() { - Script.update.disconnect(this.update); - } }; // entity scripts always need to return a newly constructed object of our type return new Cat(); -}); +}); \ No newline at end of file diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index 79e8a28fb5..453e64f4ef 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -43,7 +43,7 @@ Entities.editEntity(_this.entityID, { animationIsPlaying: true - }) + }); var position = Entities.getEntityProperties(this.entityID, "position").position; this.audioInjector = Audio.playSound(this.screamSounds[randInt(0, this.screamSounds.length)], { @@ -65,7 +65,6 @@ releaseGrab: function() { if (this.isGrabbed === true && this.hand === this.initialHand) { - print("RELEASE GRAB") this.audioInjector.stop(); Entities.editEntity(this.entityID, { // animationSettings: this.stopAnimationSetting, @@ -77,8 +76,6 @@ }); this.isGrabbed = false; - - var frameIndex = Entities.getEntityProperties(this.entityID, {}) } }, diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js new file mode 100644 index 0000000000..f9471611be --- /dev/null +++ b/examples/toys/masterResetEntity.js @@ -0,0 +1,845 @@ +// +// 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, randFloat, randInt, 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, createLightSwitches */ +var utilitiesScript = Script.resolvePath("../libraries/utils.js"); +Script.include(utilitiesScript); + +var resetKey = "resetMe"; +var GRABBABLE_DATA_KEY = "grabbableKey"; + +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, + z: 505.47 + }); + + createDoll({ + x: 546.67, + y: 495.41, + z: 505.09 + }); + + createWand({ + x: 546.71, + y: 495.55, + z: 506.15 + }); + + createDice(); + + createFlashlight({ + x: 545.72, + y: 495.41, + z: 505.78 + }); + + createCat({ + x: 551.09, + y: 494.98, + z: 503.49 + }); + + + // //Handles toggling of all sconce lights + createLightSwitches(); + + createCombinedArmChair({ + x: 549.29, + y: 495.05, + z: 508.22 + }); + + createPottedPlant({ + x: 554.26, + y: 495.23, + z: 504.53 + }); + + createPingPongBallGun(); + + createBasketballHoop(); + + createGates(); + + createFire(); + // //Handles toggling of all sconce lights + createLightSwitches(); + + + +} + +function deleteAllToys() { + var entities = Entities.findEntities(MyAvatar.position, 100); + + entities.forEach(function(entity) { + //params: customKey, id, defaultValue + var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; + if (shouldReset === true) { + Entities.deleteEntity(entity); + } + }); +} + +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 createCat(position) { + var scriptURL = Script.resolvePath("cat.js?v1"); + 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: scriptURL, + 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 scriptURL = Script.resolvePath('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 createLightSwitches() { + var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/lightswitch.fbx?v1"; + var scriptURL = Script.resolvePath("lightSwitchHall.js?v1"); + + var lightSwitchHall = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + name: "Light Switch Hall", + script: scriptURL, + position: { + x: 543.27764892578125, + y: 495.67999267578125, + z: 511.00564575195312 + }, + rotation: { + w: 0.63280689716339111, + x: 0.63280689716339111, + y: -0.31551080942153931, + z: 0.31548023223876953 + }, + dimensions: { + x: 0.10546875, + y: 0.032372996211051941, + z: 0.16242524981498718 + } + }); + + setEntityCustomData(resetKey, lightSwitchHall, { + resetMe: true + }); + + scriptURL = Script.resolvePath("lightSwitchGarage.js?v1"); + + var lightSwitchGarage = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + name: "Light Switch Garage", + script: scriptURL, + position: { + x: 545.62, + y: 495.68, + z: 500.21 + }, + rotation: { + w: 0.20082402229309082, + x: 0.20082402229309082, + y: -0.67800414562225342, + z: 0.67797362804412842 + }, + dimensions: { + x: 0.10546875, + y: 0.032372996211051941, + z: 0.16242524981498718 + } + }); + + setEntityCustomData(resetKey, lightSwitchGarage, { + resetMe: true + }); + +} + +function createDice() { + var diceProps = { + type: "Model", + modelURL: "http://s3.amazonaws.com/hifi-public/models/props/Dice/goldDie.fbx", + collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", + name: "dice", + position: { + x: 541, + y: 494.96, + z: 509.1 + }, + dimensions: { + x: 0.09, + y: 0.09, + z: 0.09 + }, + gravity: { + x: 0, + y: -3.5, + z: 0 + }, + velocity: { + x: 0, + y: -0.01, + z: 0 + }, + shapeType: "box", + collisionsWillMove: true + }; + var dice1 = Entities.addEntity(diceProps); + + diceProps.position = { + x: 541.05, + y: 494.96, + z: 509.0 + }; + + var dice2 = Entities.addEntity(diceProps); + + setEntityCustomData(resetKey, dice1, { + resetMe: true + }); + + setEntityCustomData(resetKey, dice2, { + resetMe: true + }); +} + + +function createGates() { + var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/ryan/fence.fbx'; + + var rotation1 = Quat.fromPitchYawRollDegrees(0, 36, 0); + + var gate1 = Entities.addEntity({ + name: 'Back Door Gate', + type: 'Model', + shapeType: 'box', + modelURL: MODEL_URL, + position: { + x: 546.52, + y: 494.76, + z: 498.87 + }, + dimensions: { + x: 1.42, + y: 1.13, + z: 0.25 + }, + rotation: rotation1, + collisionsWillMove: true, + gravity: { + x: 0, + y: -50, + z: 0 + }, + linearDamping: 1, + angularDamping: 10, + mass: 10, + + }); + + setEntityCustomData(resetKey, gate1, { + resetMe: true + }); + + setEntityCustomData(GRABBABLE_DATA_KEY, gate1, { + grabbable: false + }); + + var rotation2 = Quat.fromPitchYawRollDegrees(0, -16, 0); + var gate2 = Entities.addEntity({ + name: 'Front Door Fence', + type: 'Model', + modelURL: MODEL_URL, + shapeType: 'box', + position: { + x: 531.15, + y: 495.11, + z: 520.20 + }, + dimensions: { + x: 1.42, + y: 1.13, + z: 0.2 + }, + rotation: rotation2, + collisionsWillMove: true, + gravity: { + x: 0, + y: -100, + z: 0 + }, + linearDamping: 1, + angularDamping: 10, + mass: 10, + }); + + setEntityCustomData(resetKey, gate2, { + resetMe: true + }); + + setEntityCustomData(GRABBABLE_DATA_KEY, gate2, { + grabbable: false + }); +} + +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('ping_pong_gun/pingPongGun.js'); + + var position = { + x: 548.6, + y: 495.4, + z: 503.39 + }; + + var rotation = Quat.fromPitchYawRollDegrees(0, 36, 0); + + var pingPongGun = Entities.addEntity({ + type: "Model", + modelURL: MODEL_URL, + shapeType: 'compound', + compoundShapeURL: COLLISION_HULL_URL, + script: scriptURL, + position: position, + rotation: rotation, + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + dimensions: { + x: 0.67, + y: 0.14, + z: 0.09 + }, + collisionsWillMove: true, + }); + + setEntityCustomData(resetKey, pingPongGun, { + resetMe: true + }); + + +} + +function createBasketballHoop() { + var position = { + x: 539.23, + y: 496.13, + z: 475.89 + }; + var rotation = Quat.fromPitchYawRollDegrees(0, 58.49, 0); + + var hoopURL = "http://hifi-public.s3.amazonaws.com/models/basketball_hoop/basketball_hoop.fbx"; + var hoopCollisionHullURL = "http://hifi-public.s3.amazonaws.com/models/basketball_hoop/basketball_hoop_collision_hull.obj"; + + var hoop = Entities.addEntity({ + type: "Model", + modelURL: hoopURL, + position: position, + rotation: rotation, + shapeType: 'compound', + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + dimensions: { + x: 1.89, + y: 3.99, + z: 3.79 + }, + compoundShapeURL: hoopCollisionHullURL + }); + + setEntityCustomData(resetKey, hoop, { + resetMe: true + }); + + setEntityCustomData(GRABBABLE_DATA_KEY, hoop, { + grabbable: false + }); +} + +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("bubblewand/wand.js"); + + var entity = Entities.addEntity({ + name: 'Bubble Wand', + type: "Model", + modelURL: WAND_MODEL, + position: position, + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + dimensions: { + x: 0.05, + y: 0.25, + z: 0.05 + }, + //must be enabled to be grabbable in the physics engine + shapeType: 'compound', + collisionsWillMove: true, + compoundShapeURL: WAND_COLLISION_SHAPE, + //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 + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +} + +function createBasketBall(position) { + + var modelURL = "http://s3.amazonaws.com/hifi-public/models/content/basketball2.fbx"; + + var entity = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + position: position, + collisionsWillMove: true, + shapeType: "sphere", + name: "basketball", + dimensions: { + x: 0.25, + y: 0.26, + z: 0.25 + }, + gravity: { + x: 0, + y: -7, + z: 0 + }, + restitution: 10, + linearDamping: 0.0, + velocity: { + x: 0, + y: -0.01, + z: 0 + }, + collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/basketball/basketball.wav" + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +} + +function createDoll(position) { + var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; + var scriptURL = Script.resolvePath("doll/doll.js?v2"); + + var naturalDimensions = { + x: 1.63, + y: 1.67, + z: 0.26 + }; + var desiredDimensions = Vec3.multiply(naturalDimensions, 0.15); + var entity = Entities.addEntity({ + type: "Model", + name: "doll", + modelURL: modelURL, + script: scriptURL, + position: position, + shapeType: 'box', + dimensions: desiredDimensions, + gravity: { + x: 0, + y: -5, + z: 0 + }, + velocity: { + x: 0, + y: -0.1, + z: 0 + }, + collisionsWillMove: true + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); +} + +function createSprayCan(position) { + var scriptURL = Script.resolvePath("sprayPaintCan.js?v1" + Math.random()); + var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; + + var entity = Entities.addEntity({ + type: "Model", + name: "spraycan", + modelURL: modelURL, + position: position, + dimensions: { + x: 0.07, + y: 0.17, + z: 0.07 + }, + collisionsWillMove: true, + shapeType: 'box', + script: scriptURL, + gravity: { + x: 0, + y: -0.5, + z: 0 + }, + velocity: { + x: 0, + y: -1, + z: 0 + } + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); + +} + +function createPottedPlant(position) { + var modelURL = "http://hifi-public.s3.amazonaws.com/models/potted_plant/potted_plant.fbx"; + + var entity = Entities.addEntity({ + type: "Model", + name: "Potted Plant", + modelURL: modelURL, + position: position, + dimensions: { + x: 1.10, + y: 2.18, + z: 1.07 + }, + collisionsWillMove: true, + shapeType: 'box', + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + velocity: { + x: 0, + y: 0, + z: 0 + }, + linearDamping: 0.4 + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); + + + setEntityCustomData(GRABBABLE_DATA_KEY, entity, { + grabbable: false + }); +} + + +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"; + + var rotation = Quat.fromPitchYawRollDegrees(0, -143, 0); + + var entity = Entities.addEntity({ + type: "Model", + name: "Red Arm Chair", + modelURL: modelURL, + shapeType: 'compound', + compoundShapeURL: RED_ARM_CHAIR_COLLISION_HULL, + position: position, + rotation: rotation, + dimensions: { + x: 1.26, + y: 1.56, + z: 1.35 + }, + collisionsWillMove: true, + gravity: { + x: 0, + y: -0.8, + z: 0 + }, + velocity: { + x: 0, + y: 0, + z: 0 + }, + linearDamping: 0.2 + }); + + setEntityCustomData(resetKey, entity, { + resetMe: true + }); + + setEntityCustomData(GRABBABLE_DATA_KEY, entity, { + grabbable: false + }); +} + +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; + var i, j; + + var blockTypes = [{ + url: "planky_blue.fbx", + dimensions: { + x: 0.05, + y: 0.05, + z: 0.25 + } + }, { + url: "planky_green.fbx", + dimensions: { + x: 0.1, + y: 0.1, + z: 0.25 + } + }, { + url: "planky_natural.fbx", + dimensions: { + x: 0.05, + y: 0.05, + z: 0.05 + } + }, { + url: "planky_yellow.fbx", + dimensions: { + x: 0.03, + y: 0.05, + z: 0.25 + } + }, { + url: "planky_red.fbx", + dimensions: { + x: 0.1, + y: 0.05, + z: 0.25 + } + }, ]; + + var modelURL, entity; + for (i = 0; i < blockTypes.length; i++) { + for (j = 0; j < NUM_BLOCKS_PER_COLOR; j++) { + modelURL = baseURL + blockTypes[i].url; + entity = Entities.addEntity({ + type: "Model", + modelURL: modelURL, + position: Vec3.sum(position, { + x: j / 10, + y: i / 10, + z: 0 + }), + shapeType: 'box', + name: "block", + dimensions: blockTypes[i].dimensions, + collisionsWillMove: true, + collisionSoundURL: collisionSoundURL, + gravity: { + x: 0, + y: -2.5, + z: 0 + }, + velocity: { + x: 0, + y: -0.01, + z: 0 + } + }); + + //customKey, id, data + setEntityCustomData(resetKey, entity, { + resetMe: true + }); + } + } +} + +function cleanup() { + deleteAllToys(); +} + +if (shouldDeleteOnEndScript) { + + Script.scriptEnding.connect(cleanup); +} + +function randFloat(low, high) { + return low + Math.random() * (high - low); +} + +function randInt(low, high) { + return Math.floor(randFloat(low, high)); +} \ No newline at end of file From a6df6c53f1ac23ed54d7d3f3ec22caa00238f4bd Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 09:55:41 -0700 Subject: [PATCH 133/138] fixed more syntax errors --- examples/toys/cat.js | 2 +- examples/toys/doll/doll.js | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/toys/cat.js b/examples/toys/cat.js index 64736e9978..103752bb1b 100644 --- a/examples/toys/cat.js +++ b/examples/toys/cat.js @@ -36,7 +36,7 @@ }); Script.setTimeout(function() { _this.isMeowing = false; - }, this.soundClipTime) + }, this.soundClipTime); }, preload: function(entityID) { diff --git a/examples/toys/doll/doll.js b/examples/toys/doll/doll.js index 453e64f4ef..19a7dacda9 100644 --- a/examples/toys/doll/doll.js +++ b/examples/toys/doll/doll.js @@ -34,8 +34,6 @@ }, startNearGrab: function() { - // if (this.isGrabbed === false) { - print("START GRAB") Entities.editEntity(this.entityID, { animationURL: "https://hifi-public.s3.amazonaws.com/models/Bboys/zombie_scream.fbx", animationFrameIndex: 0 @@ -67,7 +65,6 @@ if (this.isGrabbed === true && this.hand === this.initialHand) { this.audioInjector.stop(); Entities.editEntity(this.entityID, { - // animationSettings: this.stopAnimationSetting, animationFrameIndex: 0 }); From 71fe9b216c92aae72167ec2f15232b1084a1d17d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 10:02:28 -0700 Subject: [PATCH 134/138] Removed extraneous masterReset script, and extra call to lightSwitches in correct script --- examples/toys/masterReset.js | 845 ----------------------------- examples/toys/masterResetEntity.js | 3 - 2 files changed, 848 deletions(-) delete mode 100644 examples/toys/masterReset.js diff --git a/examples/toys/masterReset.js b/examples/toys/masterReset.js deleted file mode 100644 index 029f7f1ba6..0000000000 --- a/examples/toys/masterReset.js +++ /dev/null @@ -1,845 +0,0 @@ -// masterReset.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, randFloat, randInt, 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, createLightSwitches */ -var utilitiesScript = Script.resolvePath("../libraries/utils.js"); -Script.include(utilitiesScript); - -var resetKey = "resetMe"; -var GRABBABLE_DATA_KEY = "grabbableKey"; - -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, - z: 505.47 - }); - - createDoll({ - x: 546.67, - y: 495.41, - z: 505.09 - }); - - createWand({ - x: 546.71, - y: 495.55, - z: 506.15 - }); - - createDice(); - - createFlashlight({ - x: 545.72, - y: 495.41, - z: 505.78 - }); - - createCat({ - x: 551.09, - y: 494.98, - z: 503.49 - }); - - - // //Handles toggling of all sconce lights - createLightSwitches(); - - createCombinedArmChair({ - x: 549.29, - y: 495.05, - z: 508.22 - }); - - createPottedPlant({ - x: 554.26, - y: 495.23, - z: 504.53 - }); - - createPingPongBallGun(); - - createBasketballHoop(); - - createGates(); - - createFire(); - // //Handles toggling of all sconce lights - createLightSwitches(); - - - -} - -function deleteAllToys() { - var entities = Entities.findEntities(MyAvatar.position, 100); - - entities.forEach(function(entity) { - //params: customKey, id, defaultValue - var shouldReset = getEntityCustomData(resetKey, entity, {}).resetMe; - if (shouldReset === true) { - Entities.deleteEntity(entity); - } - }); -} - -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 createCat(position) { - var scriptURL = Script.resolvePath("cat.js"); - 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: scriptURL, - 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 scriptURL = Script.resolvePath('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 createLightSwitches() { - var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/lightswitch.fbx"; - var scriptURL = Script.resolvePath("lightSwitchHall.js"); - - var lightSwitchHall = Entities.addEntity({ - type: "Model", - modelURL: modelURL, - name: "Light Switch Hall", - script: scriptURL, - position: { - x: 543.27764892578125, - y: 495.67999267578125, - z: 511.00564575195312 - }, - rotation: { - w: 0.63280689716339111, - x: 0.63280689716339111, - y: -0.31551080942153931, - z: 0.31548023223876953 - }, - dimensions: { - x: 0.10546875, - y: 0.032372996211051941, - z: 0.16242524981498718 - } - }); - - setEntityCustomData(resetKey, lightSwitchHall, { - resetMe: true - }); - - scriptURL = Script.resolvePath("lightSwitchGarage.js"); - - var lightSwitchGarage = Entities.addEntity({ - type: "Model", - modelURL: modelURL, - name: "Light Switch Garage", - script: scriptURL, - position: { - x: 545.62, - y: 495.68, - z: 500.21 - }, - rotation: { - w: 0.20082402229309082, - x: 0.20082402229309082, - y: -0.67800414562225342, - z: 0.67797362804412842 - }, - dimensions: { - x: 0.10546875, - y: 0.032372996211051941, - z: 0.16242524981498718 - } - }); - - setEntityCustomData(resetKey, lightSwitchGarage, { - resetMe: true - }); - -} - -function createDice() { - var diceProps = { - type: "Model", - modelURL: "http://s3.amazonaws.com/hifi-public/models/props/Dice/goldDie.fbx", - collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav", - name: "dice", - position: { - x: 541, - y: 494.96, - z: 509.1 - }, - dimensions: { - x: 0.09, - y: 0.09, - z: 0.09 - }, - gravity: { - x: 0, - y: -3.5, - z: 0 - }, - velocity: { - x: 0, - y: -0.01, - z: 0 - }, - shapeType: "box", - collisionsWillMove: true - }; - var dice1 = Entities.addEntity(diceProps); - - diceProps.position = { - x: 541.05, - y: 494.96, - z: 509.0 - }; - - var dice2 = Entities.addEntity(diceProps); - - setEntityCustomData(resetKey, dice1, { - resetMe: true - }); - - setEntityCustomData(resetKey, dice2, { - resetMe: true - }); -} - - -function createGates() { - var MODEL_URL = 'http://hifi-public.s3.amazonaws.com/ryan/fence.fbx'; - - var rotation1 = Quat.fromPitchYawRollDegrees(0, 36, 0); - - var gate1 = Entities.addEntity({ - name: 'Back Door Gate', - type: 'Model', - shapeType: 'box', - modelURL: MODEL_URL, - position: { - x: 546.52, - y: 494.76, - z: 498.87 - }, - dimensions: { - x: 1.42, - y: 1.13, - z: 0.25 - }, - rotation: rotation1, - collisionsWillMove: true, - gravity: { - x: 0, - y: -50, - z: 0 - }, - linearDamping: 1, - angularDamping: 10, - mass: 10, - - }); - - setEntityCustomData(resetKey, gate1, { - resetMe: true - }); - - setEntityCustomData(GRABBABLE_DATA_KEY, gate1, { - grabbable: false - }); - - var rotation2 = Quat.fromPitchYawRollDegrees(0, -16, 0); - var gate2 = Entities.addEntity({ - name: 'Front Door Fence', - type: 'Model', - modelURL: MODEL_URL, - shapeType: 'box', - position: { - x: 531.15, - y: 495.11, - z: 520.20 - }, - dimensions: { - x: 1.42, - y: 1.13, - z: 0.2 - }, - rotation: rotation2, - collisionsWillMove: true, - gravity: { - x: 0, - y: -100, - z: 0 - }, - linearDamping: 1, - angularDamping: 10, - mass: 10, - }); - - setEntityCustomData(resetKey, gate2, { - resetMe: true - }); - - setEntityCustomData(GRABBABLE_DATA_KEY, gate2, { - grabbable: false - }); -} - -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('ping_pong_gun/pingPongGun.js'); - - var position = { - x: 548.6, - y: 495.4, - z: 503.39 - }; - - var rotation = Quat.fromPitchYawRollDegrees(0, 36, 0); - - var pingPongGun = Entities.addEntity({ - type: "Model", - modelURL: MODEL_URL, - shapeType: 'compound', - compoundShapeURL: COLLISION_HULL_URL, - script: scriptURL, - position: position, - rotation: rotation, - gravity: { - x: 0, - y: -9.8, - z: 0 - }, - dimensions: { - x: 0.67, - y: 0.14, - z: 0.09 - }, - collisionsWillMove: true, - }); - - setEntityCustomData(resetKey, pingPongGun, { - resetMe: true - }); - - -} - -function createBasketballHoop() { - var position = { - x: 539.23, - y: 496.13, - z: 475.89 - }; - var rotation = Quat.fromPitchYawRollDegrees(0, 58.49, 0); - - var hoopURL = "http://hifi-public.s3.amazonaws.com/models/basketball_hoop/basketball_hoop.fbx"; - var hoopCollisionHullURL = "http://hifi-public.s3.amazonaws.com/models/basketball_hoop/basketball_hoop_collision_hull.obj"; - - var hoop = Entities.addEntity({ - type: "Model", - modelURL: hoopURL, - position: position, - rotation: rotation, - shapeType: 'compound', - gravity: { - x: 0, - y: -9.8, - z: 0 - }, - dimensions: { - x: 1.89, - y: 3.99, - z: 3.79 - }, - compoundShapeURL: hoopCollisionHullURL - }); - - setEntityCustomData(resetKey, hoop, { - resetMe: true - }); - - setEntityCustomData(GRABBABLE_DATA_KEY, hoop, { - grabbable: false - }); -} - -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("bubblewand/wand.js"); - - var entity = Entities.addEntity({ - name: 'Bubble Wand', - type: "Model", - modelURL: WAND_MODEL, - position: position, - gravity: { - x: 0, - y: -9.8, - z: 0 - }, - dimensions: { - x: 0.05, - y: 0.25, - z: 0.05 - }, - //must be enabled to be grabbable in the physics engine - shapeType: 'compound', - collisionsWillMove: true, - compoundShapeURL: WAND_COLLISION_SHAPE, - //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 - }); - - setEntityCustomData(resetKey, entity, { - resetMe: true - }); -} - -function createBasketBall(position) { - - var modelURL = "http://s3.amazonaws.com/hifi-public/models/content/basketball2.fbx"; - - var entity = Entities.addEntity({ - type: "Model", - modelURL: modelURL, - position: position, - collisionsWillMove: true, - shapeType: "sphere", - name: "basketball", - dimensions: { - x: 0.25, - y: 0.26, - z: 0.25 - }, - gravity: { - x: 0, - y: -7, - z: 0 - }, - restitution: 10, - linearDamping: 0.0, - velocity: { - x: 0, - y: -0.01, - z: 0 - }, - collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/basketball/basketball.wav" - }); - - setEntityCustomData(resetKey, entity, { - resetMe: true - }); -} - -function createDoll(position) { - var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; - var scriptURL = Script.resolvePath("doll/doll.js"); - - var naturalDimensions = { - x: 1.63, - y: 1.67, - z: 0.26 - }; - var desiredDimensions = Vec3.multiply(naturalDimensions, 0.15); - var entity = Entities.addEntity({ - type: "Model", - name: "doll", - modelURL: modelURL, - script: scriptURL, - position: position, - shapeType: 'box', - dimensions: desiredDimensions, - gravity: { - x: 0, - y: -5, - z: 0 - }, - velocity: { - x: 0, - y: -0.1, - z: 0 - }, - collisionsWillMove: true - }); - - setEntityCustomData(resetKey, entity, { - resetMe: true - }); -} - -function createSprayCan(position) { - var scriptURL = Script.resolvePath("sprayPaintCan.js") ; - var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; - - var entity = Entities.addEntity({ - type: "Model", - name: "spraycan", - modelURL: modelURL, - position: position, - dimensions: { - x: 0.07, - y: 0.17, - z: 0.07 - }, - collisionsWillMove: true, - shapeType: 'box', - script: scriptURL, - gravity: { - x: 0, - y: -0.5, - z: 0 - }, - velocity: { - x: 0, - y: -1, - z: 0 - } - }); - - setEntityCustomData(resetKey, entity, { - resetMe: true - }); - -} - -function createPottedPlant(position) { - var modelURL = "http://hifi-public.s3.amazonaws.com/models/potted_plant/potted_plant.fbx"; - - var entity = Entities.addEntity({ - type: "Model", - name: "Potted Plant", - modelURL: modelURL, - position: position, - dimensions: { - x: 1.10, - y: 2.18, - z: 1.07 - }, - collisionsWillMove: true, - shapeType: 'box', - gravity: { - x: 0, - y: -9.8, - z: 0 - }, - velocity: { - x: 0, - y: 0, - z: 0 - }, - linearDamping: 0.4 - }); - - setEntityCustomData(resetKey, entity, { - resetMe: true - }); - - - setEntityCustomData(GRABBABLE_DATA_KEY, entity, { - grabbable: false - }); -} - - -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"; - - var rotation = Quat.fromPitchYawRollDegrees(0, -143, 0); - - var entity = Entities.addEntity({ - type: "Model", - name: "Red Arm Chair", - modelURL: modelURL, - shapeType: 'compound', - compoundShapeURL: RED_ARM_CHAIR_COLLISION_HULL, - position: position, - rotation: rotation, - dimensions: { - x: 1.26, - y: 1.56, - z: 1.35 - }, - collisionsWillMove: true, - gravity: { - x: 0, - y: -0.8, - z: 0 - }, - velocity: { - x: 0, - y: 0, - z: 0 - }, - linearDamping: 0.2 - }); - - setEntityCustomData(resetKey, entity, { - resetMe: true - }); - - setEntityCustomData(GRABBABLE_DATA_KEY, entity, { - grabbable: false - }); -} - -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; - var i, j; - - var blockTypes = [{ - url: "planky_blue.fbx", - dimensions: { - x: 0.05, - y: 0.05, - z: 0.25 - } - }, { - url: "planky_green.fbx", - dimensions: { - x: 0.1, - y: 0.1, - z: 0.25 - } - }, { - url: "planky_natural.fbx", - dimensions: { - x: 0.05, - y: 0.05, - z: 0.05 - } - }, { - url: "planky_yellow.fbx", - dimensions: { - x: 0.03, - y: 0.05, - z: 0.25 - } - }, { - url: "planky_red.fbx", - dimensions: { - x: 0.1, - y: 0.05, - z: 0.25 - } - }, ]; - - var modelURL, entity; - for (i = 0; i < blockTypes.length; i++) { - for (j = 0; j < NUM_BLOCKS_PER_COLOR; j++) { - modelURL = baseURL + blockTypes[i].url; - entity = Entities.addEntity({ - type: "Model", - modelURL: modelURL, - position: Vec3.sum(position, { - x: j / 10, - y: i / 10, - z: 0 - }), - shapeType: 'box', - name: "block", - dimensions: blockTypes[i].dimensions, - collisionsWillMove: true, - collisionSoundURL: collisionSoundURL, - gravity: { - x: 0, - y: -2.5, - z: 0 - }, - velocity: { - x: 0, - y: -0.01, - z: 0 - } - }); - - //customKey, id, data - setEntityCustomData(resetKey, entity, { - resetMe: true - }); - } - } -} - -function cleanup() { - deleteAllToys(); -} - -if (shouldDeleteOnEndScript) { - - Script.scriptEnding.connect(cleanup); -} - -function randFloat(low, high) { - return low + Math.random() * (high - low); -} - -function randInt(low, high) { - return Math.floor(randFloat(low, high)); -} diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterResetEntity.js index f9471611be..82d2c18600 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterResetEntity.js @@ -69,9 +69,6 @@ function createAllToys() { }); - // //Handles toggling of all sconce lights - createLightSwitches(); - createCombinedArmChair({ x: 549.29, y: 495.05, From 9f5a3066b83386405bc808e62086fa840434eec0 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 10:07:43 -0700 Subject: [PATCH 135/138] changed masterResetEntity back to masterReset --- examples/toys/{masterResetEntity.js => masterReset.js} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/toys/{masterResetEntity.js => masterReset.js} (99%) diff --git a/examples/toys/masterResetEntity.js b/examples/toys/masterReset.js similarity index 99% rename from examples/toys/masterResetEntity.js rename to examples/toys/masterReset.js index 82d2c18600..72e2d73729 100644 --- a/examples/toys/masterResetEntity.js +++ b/examples/toys/masterReset.js @@ -1,4 +1,4 @@ -// +// masterReset.js // Created by Eric Levin on 9/23/2015 // Copyright 2015 High Fidelity, Inc. // From f6c888599ecbbaa670ce8d8870511ddf64473e76 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 10:22:48 -0700 Subject: [PATCH 136/138] Fixed a bug where particles weren't moving with can. --- examples/toys/sprayPaintCan.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/toys/sprayPaintCan.js b/examples/toys/sprayPaintCan.js index 5c524a38bc..e0aeb19995 100644 --- a/examples/toys/sprayPaintCan.js +++ b/examples/toys/sprayPaintCan.js @@ -99,7 +99,7 @@ this.sprayInjector = Audio.playSound(this.spraySound, { position: position, - volume: 0.1, + volume: this.sprayVolume, loop: true }); @@ -136,16 +136,21 @@ position: position, emitOrientation: forwardQuat, }); - this.sprayInjector.setOptions({position: position}); + this.sprayInjector.setOptions({ + position: position, + volume: this.sprayVolume + }); } this.preload = function(entityId) { + this.sprayVolume = 0.1; this.spraying = false; this.entityId = entityId; this.resetKey = "resetMe"; } + this.unload = function() { if (this.paintStream) { Entities.deleteEntity(this.paintStream); From 4dd2cf9cf547167dc517b8598bd7085c2145bbde Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 11:09:43 -0700 Subject: [PATCH 137/138] Moved master reset script into new directory called unpublished scripts and changed relative pathing --- .../masterReset.js | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) rename {examples/toys => unpublishedScripts}/masterReset.js (95%) diff --git a/examples/toys/masterReset.js b/unpublishedScripts/masterReset.js similarity index 95% rename from examples/toys/masterReset.js rename to unpublishedScripts/masterReset.js index 72e2d73729..94eddd74be 100644 --- a/examples/toys/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -6,10 +6,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt, pointInExtents, vec3equal, setEntityCustomData, getEntityCustomData */ +/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, 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, createLightSwitches */ -var utilitiesScript = Script.resolvePath("../libraries/utils.js"); +var utilitiesScript = Script.resolvePath("../examples/libraries/utils.js"); Script.include(utilitiesScript); var resetKey = "resetMe"; @@ -185,7 +185,7 @@ function createFire() { function createCat(position) { - var scriptURL = Script.resolvePath("cat.js?v1"); + var scriptURL = Script.resolvePath("../examples/toys/cat.js"); 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({ @@ -218,7 +218,7 @@ function createCat(position) { } function createFlashlight(position) { - var scriptURL = Script.resolvePath('flashlight/flashlight.js'); + 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({ @@ -254,7 +254,7 @@ function createFlashlight(position) { function createLightSwitches() { var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/lightswitch.fbx?v1"; - var scriptURL = Script.resolvePath("lightSwitchHall.js?v1"); + var scriptURL = Script.resolvePath("../examples/toys/lightSwitchHall.js"); var lightSwitchHall = Entities.addEntity({ type: "Model", @@ -283,7 +283,7 @@ function createLightSwitches() { resetMe: true }); - scriptURL = Script.resolvePath("lightSwitchGarage.js?v1"); + scriptURL = Script.resolvePath("../examples/toys/lightSwitchGarage.js"); var lightSwitchGarage = Entities.addEntity({ type: "Model", @@ -444,7 +444,7 @@ function createGates() { 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('ping_pong_gun/pingPongGun.js'); + var scriptURL = Script.resolvePath('../examples/toys/ping_pong_gun/pingPongGun.js'); var position = { x: 548.6, @@ -524,7 +524,7 @@ function createBasketballHoop() { 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("bubblewand/wand.js"); + var scriptURL = Script.resolvePath("../examples/toys/bubblewand/wand.js"); var entity = Entities.addEntity({ name: 'Bubble Wand', @@ -594,7 +594,7 @@ function createBasketBall(position) { function createDoll(position) { var modelURL = "http://hifi-public.s3.amazonaws.com/models/Bboys/bboy2/bboy2.fbx"; - var scriptURL = Script.resolvePath("doll/doll.js?v2"); + var scriptURL = Script.resolvePath("../examples/toys/doll/doll.js"); var naturalDimensions = { x: 1.63, @@ -629,7 +629,7 @@ function createDoll(position) { } function createSprayCan(position) { - var scriptURL = Script.resolvePath("sprayPaintCan.js?v1" + Math.random()); + var scriptURL = Script.resolvePath("../examples/toys/sprayPaintCan.js"); var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; var entity = Entities.addEntity({ @@ -832,11 +832,3 @@ if (shouldDeleteOnEndScript) { Script.scriptEnding.connect(cleanup); } - -function randFloat(low, high) { - return low + Math.random() * (high - low); -} - -function randInt(low, high) { - return Math.floor(randFloat(low, high)); -} \ No newline at end of file From b595d916b67459774a6788ca8d5baf0554958245 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 11:10:08 -0700 Subject: [PATCH 138/138] fixed spacing issue --- unpublishedScripts/masterReset.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/masterReset.js b/unpublishedScripts/masterReset.js index 94eddd74be..d6759e2b48 100644 --- a/unpublishedScripts/masterReset.js +++ b/unpublishedScripts/masterReset.js @@ -98,7 +98,7 @@ function createAllToys() { 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) {