From b9985031dacaa6e762a7f717a1562840e473f702 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 17 Sep 2015 09:03:42 -0700 Subject: [PATCH 001/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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/161] 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 e2bee8ec08e441ce16a47ff70be7f1d2cf10b4b9 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 29 Sep 2015 15:40:46 -0700 Subject: [PATCH 107/161] Fix particle radius, color, and alpha starts/finishes --- libraries/entities/src/EntityItemProperties.cpp | 15 +++++++++------ libraries/entities/src/ParticleEffectEntityItem.h | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index b92ea34827..61e369cf96 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -1573,14 +1573,17 @@ void EntityItemProperties::markAllChanged() { _accelerationSpreadChanged = true; _particleRadiusChanged = true; _radiusSpreadChanged = true; - _radiusStartChanged = true; - _radiusFinishChanged = true; _colorSpreadChanged = true; - _colorStartChanged = true; - _colorFinishChanged = true; _alphaSpreadChanged = true; - _alphaStartChanged = true; - _alphaFinishChanged = true; + + // Only mark the following as changed if their values are specified in the properties when the particle is created. If their + // values are specified then they are marked as changed in getChangedProperties(). + //_radiusStartChanged = true; + //_radiusFinishChanged = true; + //_colorStartChanged = true; + //_colorFinishChanged = true; + //_alphaStartChanged = true; + //_alphaFinishChanged = true; _marketplaceIDChanged = true; diff --git a/libraries/entities/src/ParticleEffectEntityItem.h b/libraries/entities/src/ParticleEffectEntityItem.h index 74d39aa4af..6d5b8761b0 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.h +++ b/libraries/entities/src/ParticleEffectEntityItem.h @@ -177,12 +177,12 @@ public: float getParticleRadius() const { return _particleRadius; } static const float DEFAULT_RADIUS_START; - bool _isRadiusStartInitialized; + bool _isRadiusStartInitialized = false; void setRadiusStart(float radiusStart) { _radiusStart = radiusStart; _isRadiusStartInitialized = true; } float getRadiusStart() const { return _isRadiusStartInitialized ? _radiusStart : _particleRadius; } static const float DEFAULT_RADIUS_FINISH; - bool _isRadiusFinishInitialized; + bool _isRadiusFinishInitialized = false; void setRadiusFinish(float radiusFinish) { _radiusFinish = radiusFinish; _isRadiusFinishInitialized = true; } float getRadiusFinish() const { return _isRadiusFinishInitialized ? _radiusFinish : _particleRadius; } From d8e7da7b73d16d52210131e8592e82bc753705a4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 15:43:59 -0700 Subject: [PATCH 108/161] 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 109/161] 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 dc3c9b48eaa092f973f0c7b35ede707ee622b0ab Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 29 Sep 2015 18:28:20 -0700 Subject: [PATCH 110/161] MOving forward on the background beeing drawn last --- libraries/render-utils/src/Environment.cpp | 3 +- .../render-utils/src/FramebufferCache.cpp | 23 ++++ libraries/render-utils/src/FramebufferCache.h | 4 + .../render-utils/src/RenderDeferredTask.cpp | 107 +++++++++++++++++- .../render-utils/src/RenderDeferredTask.h | 17 +++ .../render-utils/src/drawOpaqueStencil.slf | 30 +++++ libraries/render/src/render/DrawTask.h | 1 + 7 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 libraries/render-utils/src/drawOpaqueStencil.slf diff --git a/libraries/render-utils/src/Environment.cpp b/libraries/render-utils/src/Environment.cpp index 7fbd89acc1..365fbdb16a 100644 --- a/libraries/render-utils/src/Environment.cpp +++ b/libraries/render-utils/src/Environment.cpp @@ -62,7 +62,8 @@ void Environment::setupAtmosphereProgram(const char* vertSource, const char* fra auto state = std::make_shared(); state->setCullMode(gpu::State::CULL_NONE); - state->setDepthTest(false); + // state->setDepthTest(false); + state->setDepthTest(true, false, gpu::LESS_EQUAL); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index d6ebd001d2..eb154f77c9 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -35,7 +35,9 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { _frameBufferSize = frameBufferSize; _primaryFramebufferFull.reset(); _primaryFramebufferDepthColor.reset(); + _primaryFramebufferDepthStencilColor.reset(); _primaryDepthTexture.reset(); + _primaryStencilTexture.reset(); _primaryColorTexture.reset(); _primaryNormalTexture.reset(); _primarySpecularTexture.reset(); @@ -47,6 +49,7 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); + _primaryFramebufferDepthStencilColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); auto width = _frameBufferSize.width(); @@ -63,12 +66,19 @@ void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture); + _primaryFramebufferDepthStencilColor->setRenderBuffer(0, _primaryColorTexture); + auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); + auto stencilFormat = gpu::Element(gpu::VEC2, gpu::UINT32, gpu::DEPTH_STENCIL); + _primaryStencilTexture = gpu::TexturePointer(gpu::Texture::create2D(stencilFormat, width, height, defaultSampler)); + _primaryFramebufferFull->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); + + _primaryFramebufferDepthStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat); _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); @@ -89,6 +99,12 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() { return _primaryFramebufferDepthColor; } +gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthStencilColor() { + if (!_primaryFramebufferDepthStencilColor) { + createPrimaryFramebuffer(); + } + return _primaryFramebufferDepthStencilColor; +} gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { if (!_primaryDepthTexture) { @@ -97,6 +113,13 @@ gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { return _primaryDepthTexture; } +gpu::TexturePointer FramebufferCache::getPrimaryStencilTexture() { + if (!_primaryStencilTexture) { + createPrimaryFramebuffer(); + } + return _primaryStencilTexture; +} + gpu::TexturePointer FramebufferCache::getPrimaryColorTexture() { if (!_primaryColorTexture) { createPrimaryFramebuffer(); diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index c2274a77e8..baca07af24 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -31,8 +31,10 @@ public: /// used for scene rendering. gpu::FramebufferPointer getPrimaryFramebuffer(); gpu::FramebufferPointer getPrimaryFramebufferDepthColor(); + gpu::FramebufferPointer getPrimaryFramebufferDepthStencilColor(); gpu::TexturePointer getPrimaryDepthTexture(); + gpu::TexturePointer getPrimaryStencilTexture(); gpu::TexturePointer getPrimaryColorTexture(); gpu::TexturePointer getPrimaryNormalTexture(); gpu::TexturePointer getPrimarySpecularTexture(); @@ -58,7 +60,9 @@ private: gpu::FramebufferPointer _primaryFramebufferFull; gpu::FramebufferPointer _primaryFramebufferDepthColor; + gpu::FramebufferPointer _primaryFramebufferDepthStencilColor; gpu::TexturePointer _primaryDepthTexture; + gpu::TexturePointer _primaryStencilTexture; gpu::TexturePointer _primaryColorTexture; gpu::TexturePointer _primaryNormalTexture; gpu::TexturePointer _primarySpecularTexture; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 65f77689c3..d21b6377be 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "FramebufferCache.h" #include "DeferredLightingEffect.h" @@ -28,6 +29,8 @@ #include "overlay3D_vert.h" #include "overlay3D_frag.h" +#include "drawOpaqueStencil_frag.h" + using namespace render; void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { @@ -65,7 +68,7 @@ void ResolveDeferred::run(const SceneContextPointer& sceneContext, const RenderC RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.push_back(Job(new SetupDeferred::JobModel("SetupFramebuffer"))); - _jobs.push_back(Job(new DrawBackground::JobModel("DrawBackground"))); + // _jobs.push_back(Job(new DrawBackground::JobModel("DrawBackground"))); _jobs.push_back(Job(new PrepareDeferred::JobModel("PrepareDeferred"))); _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", @@ -79,7 +82,10 @@ RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.push_back(Job(new DepthSortItems::JobModel("DepthSortOpaque", _jobs.back().getOutput()))); auto& renderedOpaques = _jobs.back().getOutput(); _jobs.push_back(Job(new DrawOpaqueDeferred::JobModel("DrawOpaqueDeferred", _jobs.back().getOutput()))); - + + _jobs.push_back(Job(new DrawStencilDeferred::JobModel("DrawOpaqueStencil"))); + _jobs.push_back(Job(new DrawBackgroundDeferred::JobModel("DrawBackgroundDeferred"))); + _jobs.push_back(Job(new DrawLight::JobModel("DrawLight"))); _jobs.push_back(Job(new RenderDeferred::JobModel("RenderDeferred"))); _jobs.push_back(Job(new ResolveDeferred::JobModel("ResolveDeferred"))); @@ -289,3 +295,100 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon args->_whiteTexture.reset(); } } + +gpu::PipelinePointer DrawStencilDeferred::_opaquePipeline; +const gpu::PipelinePointer& DrawStencilDeferred::getOpaquePipeline() { + if (!_opaquePipeline) { + auto vs = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); + auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(drawOpaqueStencil_frag))); + auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); + + auto state = std::make_shared(); + state->setDepthTest(true, true, gpu::LESS_EQUAL); + + _opaquePipeline.reset(gpu::Pipeline::create(program, state)); + } + return _opaquePipeline; +} + +void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { + assert(renderContext->args); + assert(renderContext->args->_viewFrustum); + + // from the touched pixel generate the stencil buffer + RenderArgs* args = renderContext->args; + doInBatch(args->_context, [=](gpu::Batch& batch) { + args->_batch = &batch; + + auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthStencilColor(); + auto primaryFboFull = DependencyManager::get()->getPrimaryFramebuffer(); + auto primaryDepth = DependencyManager::get()->getPrimaryDepthTexture(); + + batch.setFramebuffer(primaryFboColorDepthStencil); + + batch.enableStereo(false); + batch.setViewportTransform(args->_viewport); + batch.setStateScissorRect(args->_viewport); + + glm::mat4 projMat; + Transform viewMat; + args->_viewFrustum->evalProjectionMatrix(projMat); + args->_viewFrustum->evalViewTransform(viewMat); + + batch.setProjectionTransform(projMat); + batch.setViewTransform(viewMat); + batch.setPipeline(getOpaquePipeline()); + batch.setResourceTexture(0, primaryDepth); + + batch.draw(gpu::TRIANGLE_STRIP, 4); + batch.setResourceTexture(0, nullptr); + + batch.setFramebuffer(primaryFboFull); + + }); + args->_batch = nullptr; +} + +void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) { + assert(renderContext->args); + assert(renderContext->args->_viewFrustum); + + // render backgrounds + auto& scene = sceneContext->_scene; + auto& items = scene->getMasterBucket().at(ItemFilter::Builder::background()); + + + ItemIDsBounds inItems; + inItems.reserve(items.size()); + for (auto id : items) { + inItems.emplace_back(id); + } + RenderArgs* args = renderContext->args; + doInBatch(args->_context, [=](gpu::Batch& batch) { + args->_batch = &batch; + + // auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthStencilColor(); + auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthColor(); + auto primaryFboFull = DependencyManager::get()->getPrimaryFramebuffer(); + + batch.setFramebuffer(primaryFboColorDepthStencil); + + batch.enableSkybox(true); + batch.setViewportTransform(args->_viewport); + batch.setStateScissorRect(args->_viewport); + + glm::mat4 projMat; + Transform viewMat; + args->_viewFrustum->evalProjectionMatrix(projMat); + args->_viewFrustum->evalViewTransform(viewMat); + + batch.setProjectionTransform(projMat); + batch.setViewTransform(viewMat); + + renderItems(sceneContext, renderContext, inItems); + + batch.setFramebuffer(primaryFboFull); + + }); + args->_batch = nullptr; +} \ No newline at end of file diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 8366a2665d..04483fc037 100755 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -59,6 +59,23 @@ public: typedef render::Job::ModelI JobModel; }; +class DrawStencilDeferred { + static gpu::PipelinePointer _opaquePipeline; //lazy evaluation hence mutable +public: + static const gpu::PipelinePointer& getOpaquePipeline(); + + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); + + typedef render::Job::Model JobModel; +}; + +class DrawBackgroundDeferred { +public: + void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext); + + typedef render::Job::Model JobModel; +}; + class DrawOverlay3D { static gpu::PipelinePointer _opaquePipeline; //lazy evaluation hence mutable public: diff --git a/libraries/render-utils/src/drawOpaqueStencil.slf b/libraries/render-utils/src/drawOpaqueStencil.slf new file mode 100644 index 0000000000..0634d2d66a --- /dev/null +++ b/libraries/render-utils/src/drawOpaqueStencil.slf @@ -0,0 +1,30 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// drawOpaqueStencil.frag +// fragment shader +// +// Created by Sam Gateau on 9/29/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 +// + + +<@include gpu/Transform.slh@> + +<$declareStandardTransform()$> + +in vec2 varTexCoord0; +out vec4 outFragColor; + +uniform sampler2D depthTexture; + +void main(void) { + + float depth = texture(depthTexture, varTexCoord0).r; + + outFragColor = vec4(vec3(depth), 1.0); +} diff --git a/libraries/render/src/render/DrawTask.h b/libraries/render/src/render/DrawTask.h index ec6656c0dc..b7a03b81e2 100755 --- a/libraries/render/src/render/DrawTask.h +++ b/libraries/render/src/render/DrawTask.h @@ -257,6 +257,7 @@ class DrawBackground { public: void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext); + typedef Job::Model JobModel; }; From ba17225c1964a1b3713b0341cdd928594e0b9df7 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Sep 2015 18:32:52 -0700 Subject: [PATCH 111/161] 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 112/161] 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 e78f1521abb9967886948243c5d3286aef70a5f6 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 30 Sep 2015 09:24:36 -0700 Subject: [PATCH 113/161] getting the stencil buffer in place --- libraries/gpu/src/gpu/Framebuffer.cpp | 8 ++- libraries/gpu/src/gpu/Framebuffer.h | 2 + libraries/gpu/src/gpu/GLBackendOutput.cpp | 13 ++++- libraries/gpu/src/gpu/GLBackendTexture.cpp | 49 +++++++++++++------ .../render-utils/src/RenderDeferredTask.cpp | 4 +- .../render-utils/src/drawOpaqueStencil.slf | 6 ++- 6 files changed, 63 insertions(+), 19 deletions(-) diff --git a/libraries/gpu/src/gpu/Framebuffer.cpp b/libraries/gpu/src/gpu/Framebuffer.cpp index 96bd3d3002..d570007b3e 100755 --- a/libraries/gpu/src/gpu/Framebuffer.cpp +++ b/libraries/gpu/src/gpu/Framebuffer.cpp @@ -247,7 +247,13 @@ bool Framebuffer::setDepthStencilBuffer(const TexturePointer& texture, const For _bufferMask = ( _bufferMask & ~BUFFER_DEPTHSTENCIL); if (texture) { - _bufferMask |= BUFFER_DEPTHSTENCIL; + if (format.getSemantic() == gpu::DEPTH) { + _bufferMask |= BUFFER_DEPTH; + } else if (format.getSemantic() == gpu::STENCIL) { + _bufferMask |= BUFFER_STENCIL; + } else if (format.getSemantic() == gpu::DEPTH_STENCIL) { + _bufferMask |= BUFFER_DEPTHSTENCIL; + } } return true; diff --git a/libraries/gpu/src/gpu/Framebuffer.h b/libraries/gpu/src/gpu/Framebuffer.h index 310255af9f..83ff8fbb23 100755 --- a/libraries/gpu/src/gpu/Framebuffer.h +++ b/libraries/gpu/src/gpu/Framebuffer.h @@ -116,6 +116,8 @@ public: bool isEmpty() const { return (_bufferMask == 0); } bool hasColor() const { return (getBufferMask() & BUFFER_COLORS); } bool hasDepthStencil() const { return (getBufferMask() & BUFFER_DEPTHSTENCIL); } + bool hasDepth() const { return (getBufferMask() & BUFFER_DEPTH); } + bool hasStencil() const { return (getBufferMask() & BUFFER_STENCIL); } bool validateTargetCompatibility(const Texture& texture, uint32 subresource = 0) const; diff --git a/libraries/gpu/src/gpu/GLBackendOutput.cpp b/libraries/gpu/src/gpu/GLBackendOutput.cpp index c3f61a67c3..70e4b18b0f 100755 --- a/libraries/gpu/src/gpu/GLBackendOutput.cpp +++ b/libraries/gpu/src/gpu/GLBackendOutput.cpp @@ -100,7 +100,18 @@ GLBackend::GLFramebuffer* GLBackend::syncGPUObject(const Framebuffer& framebuffe if (surface) { auto gltexture = GLBackend::syncGPUObject(*surface); if (gltexture) { - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, gltexture->_texture, 0); + GLenum attachement = GL_DEPTH_STENCIL_ATTACHMENT; + if (!framebuffer.hasStencil()) { + attachement = GL_DEPTH_ATTACHMENT; + glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, gltexture->_texture, 0); + } else if (!framebuffer.hasDepth()) { + attachement = GL_STENCIL_ATTACHMENT; + glFramebufferTexture2D(GL_FRAMEBUFFER, attachement, GL_TEXTURE_2D, gltexture->_texture, 0); + } else { + attachement = GL_DEPTH_STENCIL_ATTACHMENT; + glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachement, GL_RENDERBUFFER, gltexture->_texture); + } + (void) CHECK_GL_ERROR(); } } } diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index dce5236868..044204934c 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -66,7 +66,9 @@ public: texel.internalFormat = GL_RG; break; case gpu::DEPTH_STENCIL: - texel.internalFormat = GL_DEPTH_STENCIL; + texel.type = GL_UNSIGNED_BYTE; + texel.format = GL_DEPTH_STENCIL; + texel.internalFormat = GL_DEPTH24_STENCIL8; break; default: qCDebug(gpulogging) << "Unknown combination of texel format"; @@ -197,7 +199,9 @@ public: texel.internalFormat = GL_RG; break; case gpu::DEPTH_STENCIL: - texel.internalFormat = GL_DEPTH_STENCIL; + texel.type = GL_UNSIGNED_BYTE; + texel.format = GL_DEPTH_STENCIL; + texel.internalFormat = GL_DEPTH24_STENCIL8; break; default: qCDebug(gpulogging) << "Unknown combination of texel format"; @@ -334,22 +338,37 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) { } GLTexelFormat texelFormat = GLTexelFormat::evalGLTexelFormat(texture.getTexelFormat(), srcFormat); - - glTexImage2D(GL_TEXTURE_2D, 0, - texelFormat.internalFormat, texture.getWidth(), texture.getHeight(), 0, - texelFormat.format, texelFormat.type, bytes); - if (bytes && texture.isAutogenerateMips()) { - glGenerateMipmap(GL_TEXTURE_2D); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - }/* else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - }*/ + auto semantic = texture.getTexelFormat().getSemantic(); + + if (semantic == gpu::DEPTH_STENCIL) { + glBindTexture(GL_TEXTURE_2D, 0); + glDeleteTextures(1, &object->_texture); + + glGenRenderbuffers(1, &object->_texture); + glBindRenderbuffer(GL_RENDERBUFFER, object->_texture); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, texture.getWidth(), texture.getHeight()); + // At this point the mip pixels have been loaded, we can notify + texture.notifyMipFaceGPULoaded(0, 0); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + + } else { + glTexImage2D(GL_TEXTURE_2D, 0, + texelFormat.internalFormat, texture.getWidth(), texture.getHeight(), 0, + texelFormat.format, texelFormat.type, bytes); + + if (bytes && texture.isAutogenerateMips()) { + glGenerateMipmap(GL_TEXTURE_2D); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + }/* else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + }*/ - object->_target = GL_TEXTURE_2D; + object->_target = GL_TEXTURE_2D; - syncSampler(texture.getSampler(), texture.getType(), object); + syncSampler(texture.getSampler(), texture.getType(), object); + } // At this point the mip pixels have been loaded, we can notify texture.notifyMipFaceGPULoaded(0, 0); diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index d21b6377be..71bc41e6b6 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -232,7 +232,9 @@ const gpu::PipelinePointer& DrawOverlay3D::getOpaquePipeline() { auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); auto state = std::make_shared(); - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setDepthTest(false); + // additive blending + state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); _opaquePipeline.reset(gpu::Pipeline::create(program, state)); } diff --git a/libraries/render-utils/src/drawOpaqueStencil.slf b/libraries/render-utils/src/drawOpaqueStencil.slf index 0634d2d66a..dae3e56c4d 100644 --- a/libraries/render-utils/src/drawOpaqueStencil.slf +++ b/libraries/render-utils/src/drawOpaqueStencil.slf @@ -26,5 +26,9 @@ void main(void) { float depth = texture(depthTexture, varTexCoord0).r; - outFragColor = vec4(vec3(depth), 1.0); + if (depth >= 0.9) { + outFragColor = vec4(1.0, 0.0, 0.0, 1.0); + } else { + discard; + } } From c03a9ddd584dfa935840b288f68f1533da8cd72b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 30 Sep 2015 11:14:18 -0700 Subject: [PATCH 114/161] 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 75e858cd1314009181c21c0764996dbf266f9ccf Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Sep 2015 15:54:03 -0700 Subject: [PATCH 115/161] Putting together the stencil buffer for opaque vs background and using it for the backgroud render items --- interface/src/Stars.cpp | 2 ++ libraries/gpu/src/gpu/GLBackendState.cpp | 5 +-- libraries/gpu/src/gpu/State.h | 6 ++-- libraries/model/src/model/Skybox.cpp | 1 + .../src/procedural/ProceduralSkybox.cpp | 3 +- libraries/render-utils/src/Environment.cpp | 3 +- .../render-utils/src/FramebufferCache.cpp | 14 ++++----- libraries/render-utils/src/FramebufferCache.h | 4 +-- .../render-utils/src/RenderDeferredTask.cpp | 31 ++++++++++--------- .../render-utils/src/drawOpaqueStencil.slf | 14 +++------ 10 files changed, 44 insertions(+), 39 deletions(-) diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index 4af1a26612..6145529b52 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -141,6 +141,7 @@ void Stars::render(RenderArgs* renderArgs, float alpha) { auto state = gpu::StatePointer(new gpu::State()); // enable decal blend state->setDepthTest(gpu::State::DepthTest(false)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); _gridPipeline.reset(gpu::Pipeline::create(program, state)); } @@ -152,6 +153,7 @@ void Stars::render(RenderArgs* renderArgs, float alpha) { auto state = gpu::StatePointer(new gpu::State()); // enable decal blend state->setDepthTest(gpu::State::DepthTest(false)); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setAntialiasedLineEnable(true); // line smoothing also smooth points state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); _starsPipeline.reset(gpu::Pipeline::create(program, state)); diff --git a/libraries/gpu/src/gpu/GLBackendState.cpp b/libraries/gpu/src/gpu/GLBackendState.cpp index 9fdcbc0870..feba6e6853 100644 --- a/libraries/gpu/src/gpu/GLBackendState.cpp +++ b/libraries/gpu/src/gpu/GLBackendState.cpp @@ -655,11 +655,12 @@ void GLBackend::do_setStateStencil(State::StencilActivation activation, State::S GL_INCR, GL_DECR }; - glStencilFuncSeparate(GL_FRONT, STENCIL_OPS[frontTest.getFailOp()], STENCIL_OPS[frontTest.getPassOp()], STENCIL_OPS[frontTest.getDepthFailOp()]); + glStencilOpSeparate(GL_FRONT, STENCIL_OPS[frontTest.getFailOp()], STENCIL_OPS[frontTest.getPassOp()], STENCIL_OPS[frontTest.getDepthFailOp()]); glStencilFuncSeparate(GL_FRONT, GL_COMPARISON_FUNCTIONS[frontTest.getFunction()], frontTest.getReference(), frontTest.getReadMask()); - glStencilFuncSeparate(GL_BACK, STENCIL_OPS[backTest.getFailOp()], STENCIL_OPS[backTest.getPassOp()], STENCIL_OPS[backTest.getDepthFailOp()]); + glStencilOpSeparate(GL_BACK, STENCIL_OPS[backTest.getFailOp()], STENCIL_OPS[backTest.getPassOp()], STENCIL_OPS[backTest.getDepthFailOp()]); glStencilFuncSeparate(GL_BACK, GL_COMPARISON_FUNCTIONS[backTest.getFunction()], backTest.getReference(), backTest.getReadMask()); + } else { glDisable(GL_STENCIL_TEST); } diff --git a/libraries/gpu/src/gpu/State.h b/libraries/gpu/src/gpu/State.h index 5500f20e06..7740506bce 100755 --- a/libraries/gpu/src/gpu/State.h +++ b/libraries/gpu/src/gpu/State.h @@ -143,11 +143,11 @@ public: static const int PASS_OP_OFFSET = 12; uint16 _functionAndOperations; - uint8 _reference = 0; + int8 _reference = 0; uint8 _readMask = 0xff; public: - StencilTest(uint8 reference = 0, uint8 readMask =0xFF, ComparisonFunction func = ALWAYS, StencilOp failOp = STENCIL_OP_KEEP, StencilOp depthFailOp = STENCIL_OP_KEEP, StencilOp passOp = STENCIL_OP_KEEP) : + StencilTest(int8 reference = 0, uint8 readMask =0xFF, ComparisonFunction func = ALWAYS, StencilOp failOp = STENCIL_OP_KEEP, StencilOp depthFailOp = STENCIL_OP_KEEP, StencilOp passOp = STENCIL_OP_KEEP) : _functionAndOperations(func | (failOp << FAIL_OP_OFFSET) | (depthFailOp << DEPTH_FAIL_OP_OFFSET) | (passOp << PASS_OP_OFFSET)), _reference(reference), _readMask(readMask) {} @@ -157,7 +157,7 @@ public: StencilOp getDepthFailOp() const { return StencilOp((_functionAndOperations & DEPTH_FAIL_OP_MASK) >> DEPTH_FAIL_OP_OFFSET); } StencilOp getPassOp() const { return StencilOp((_functionAndOperations & PASS_OP_MASK) >> PASS_OP_OFFSET); } - uint8 getReference() const { return _reference; } + int8 getReference() const { return _reference; } uint8 getReadMask() const { return _readMask; } int32 getRaw() const { return *(reinterpret_cast(this)); } diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index e27a0d25ce..944d16a6dd 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -89,6 +89,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky } auto skyState = std::make_shared(); + skyState->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); thePipeline = gpu::PipelinePointer(gpu::Pipeline::create(skyShader, skyState)); diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index 8d34f0e7e5..f69e0575de 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -32,7 +32,8 @@ void ProceduralSkybox::setProcedural(const ProceduralPointer& procedural) { if (_procedural) { _procedural->_vertexSource = ProceduralSkybox_vert; _procedural->_fragmentSource = ProceduralSkybox_frag; - // No pipeline state customization + // Adjust the pipeline state for background using the stencil test + _procedural->_state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); } } diff --git a/libraries/render-utils/src/Environment.cpp b/libraries/render-utils/src/Environment.cpp index 365fbdb16a..acb149a3cc 100644 --- a/libraries/render-utils/src/Environment.cpp +++ b/libraries/render-utils/src/Environment.cpp @@ -63,7 +63,8 @@ void Environment::setupAtmosphereProgram(const char* vertSource, const char* fra state->setCullMode(gpu::State::CULL_NONE); // state->setDepthTest(false); - state->setDepthTest(true, false, gpu::LESS_EQUAL); + // state->setDepthTest(true, false, gpu::LESS_EQUAL); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); diff --git a/libraries/render-utils/src/FramebufferCache.cpp b/libraries/render-utils/src/FramebufferCache.cpp index eb154f77c9..cd81a21f9a 100644 --- a/libraries/render-utils/src/FramebufferCache.cpp +++ b/libraries/render-utils/src/FramebufferCache.cpp @@ -35,7 +35,7 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { _frameBufferSize = frameBufferSize; _primaryFramebufferFull.reset(); _primaryFramebufferDepthColor.reset(); - _primaryFramebufferDepthStencilColor.reset(); + _primaryFramebufferStencilColor.reset(); _primaryDepthTexture.reset(); _primaryStencilTexture.reset(); _primaryColorTexture.reset(); @@ -49,7 +49,7 @@ void FramebufferCache::setFrameBufferSize(QSize frameBufferSize) { void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferFull = gpu::FramebufferPointer(gpu::Framebuffer::create()); _primaryFramebufferDepthColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); - _primaryFramebufferDepthStencilColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); + _primaryFramebufferStencilColor = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto colorFormat = gpu::Element(gpu::VEC4, gpu::NUINT8, gpu::RGBA); auto width = _frameBufferSize.width(); @@ -66,7 +66,7 @@ void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferDepthColor->setRenderBuffer(0, _primaryColorTexture); - _primaryFramebufferDepthStencilColor->setRenderBuffer(0, _primaryColorTexture); + _primaryFramebufferStencilColor->setRenderBuffer(0, _primaryColorTexture); auto depthFormat = gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::DEPTH); _primaryDepthTexture = gpu::TexturePointer(gpu::Texture::create2D(depthFormat, width, height, defaultSampler)); @@ -78,7 +78,7 @@ void FramebufferCache::createPrimaryFramebuffer() { _primaryFramebufferDepthColor->setDepthStencilBuffer(_primaryDepthTexture, depthFormat); - _primaryFramebufferDepthStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat); + _primaryFramebufferStencilColor->setDepthStencilBuffer(_primaryStencilTexture, stencilFormat); _selfieFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create()); auto tex = gpu::TexturePointer(gpu::Texture::create2D(colorFormat, width * 0.5, height * 0.5, defaultSampler)); @@ -99,11 +99,11 @@ gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthColor() { return _primaryFramebufferDepthColor; } -gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferDepthStencilColor() { - if (!_primaryFramebufferDepthStencilColor) { +gpu::FramebufferPointer FramebufferCache::getPrimaryFramebufferStencilColor() { + if (!_primaryFramebufferStencilColor) { createPrimaryFramebuffer(); } - return _primaryFramebufferDepthStencilColor; + return _primaryFramebufferStencilColor; } gpu::TexturePointer FramebufferCache::getPrimaryDepthTexture() { diff --git a/libraries/render-utils/src/FramebufferCache.h b/libraries/render-utils/src/FramebufferCache.h index baca07af24..8951ceee80 100644 --- a/libraries/render-utils/src/FramebufferCache.h +++ b/libraries/render-utils/src/FramebufferCache.h @@ -31,7 +31,7 @@ public: /// used for scene rendering. gpu::FramebufferPointer getPrimaryFramebuffer(); gpu::FramebufferPointer getPrimaryFramebufferDepthColor(); - gpu::FramebufferPointer getPrimaryFramebufferDepthStencilColor(); + gpu::FramebufferPointer getPrimaryFramebufferStencilColor(); gpu::TexturePointer getPrimaryDepthTexture(); gpu::TexturePointer getPrimaryStencilTexture(); @@ -60,7 +60,7 @@ private: gpu::FramebufferPointer _primaryFramebufferFull; gpu::FramebufferPointer _primaryFramebufferDepthColor; - gpu::FramebufferPointer _primaryFramebufferDepthStencilColor; + gpu::FramebufferPointer _primaryFramebufferStencilColor; gpu::TexturePointer _primaryDepthTexture; gpu::TexturePointer _primaryStencilTexture; gpu::TexturePointer _primaryColorTexture; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 71bc41e6b6..e16544f5cd 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -301,12 +301,18 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon gpu::PipelinePointer DrawStencilDeferred::_opaquePipeline; const gpu::PipelinePointer& DrawStencilDeferred::getOpaquePipeline() { if (!_opaquePipeline) { + const gpu::int8 STENCIL_OPAQUE = 1; auto vs = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(drawOpaqueStencil_frag))); auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); + + + gpu::Shader::makeProgram((*program)); auto state = std::make_shared(); - state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); + // state->setStencilTest(false, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_INCR, gpu::State::STENCIL_OP_INCR, gpu::State::STENCIL_OP_INCR)); + state->setColorWriteMask(0); _opaquePipeline.reset(gpu::Pipeline::create(program, state)); } @@ -322,23 +328,20 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthStencilColor(); + auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); auto primaryFboFull = DependencyManager::get()->getPrimaryFramebuffer(); auto primaryDepth = DependencyManager::get()->getPrimaryDepthTexture(); + + batch.enableStereo(false); batch.setFramebuffer(primaryFboColorDepthStencil); - - batch.enableStereo(false); + batch.clearStencilFramebuffer(0, true); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - glm::mat4 projMat; - Transform viewMat; - args->_viewFrustum->evalProjectionMatrix(projMat); - args->_viewFrustum->evalViewTransform(viewMat); + Transform modelMat; + batch.setModelTransform(modelMat); - batch.setProjectionTransform(projMat); - batch.setViewTransform(viewMat); batch.setPipeline(getOpaquePipeline()); batch.setResourceTexture(0, primaryDepth); @@ -369,13 +372,13 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const doInBatch(args->_context, [=](gpu::Batch& batch) { args->_batch = &batch; - // auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthStencilColor(); - auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferDepthColor(); + auto primaryFboColorStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); auto primaryFboFull = DependencyManager::get()->getPrimaryFramebuffer(); - batch.setFramebuffer(primaryFboColorDepthStencil); - batch.enableSkybox(true); + + batch.setFramebuffer(primaryFboColorStencil); + batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); diff --git a/libraries/render-utils/src/drawOpaqueStencil.slf b/libraries/render-utils/src/drawOpaqueStencil.slf index dae3e56c4d..883154c624 100644 --- a/libraries/render-utils/src/drawOpaqueStencil.slf +++ b/libraries/render-utils/src/drawOpaqueStencil.slf @@ -12,22 +12,18 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - -<@include gpu/Transform.slh@> - -<$declareStandardTransform()$> - in vec2 varTexCoord0; out vec4 outFragColor; uniform sampler2D depthTexture; void main(void) { + // outFragColor = vec4(varTexCoord0, 0.0, 1.0); - float depth = texture(depthTexture, varTexCoord0).r; - - if (depth >= 0.9) { - outFragColor = vec4(1.0, 0.0, 0.0, 1.0); + float depth = texture(depthTexture, varTexCoord0.xy).r; + outFragColor = vec4(1.0, 0.0, 0.0, 1.0); + if (depth < 1.0) { + outFragColor = vec4(0.0, 1.0, 0.0, 1.0); } else { discard; } From e516281da8c3993be8a702e766145eef0153556a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 30 Sep 2015 16:15:52 -0700 Subject: [PATCH 116/161] Added closePaint script and removed no longer used spray paint scripts --- examples/closePaint.js | 258 ++++++++++++++++++++++++ examples/entityScripts/sprayPaintCan.js | 252 ----------------------- examples/sprayPaintSpawner.js | 41 ---- 3 files changed, 258 insertions(+), 293 deletions(-) create mode 100644 examples/closePaint.js delete mode 100644 examples/entityScripts/sprayPaintCan.js delete mode 100644 examples/sprayPaintSpawner.js diff --git a/examples/closePaint.js b/examples/closePaint.js new file mode 100644 index 0000000000..dc3e567823 --- /dev/null +++ b/examples/closePaint.js @@ -0,0 +1,258 @@ +// +// closePaint.js +// examples +// +// Created by Eric Levina on 9/30/15. +// Copyright 2015 High Fidelity, Inc. +// +// Run this script to be able to paint on entities you are close to, with hydras. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +var RIGHT_HAND = 1; +var LEFT_HAND = 0; + +var MIN_POINT_DISTANCE = 0.01; +var MAX_POINT_DISTANCE = 0.5; + +var SPATIAL_CONTROLLERS_PER_PALM = 2; +var TIP_CONTROLLER_OFFSET = 1; + +var TRIGGER_ON_VALUE = 0.3; + +var MAX_DISTANCE = 10; + +var STROKE_WIDTH = 0.02 +var MAX_POINTS_PER_LINE = 60; + + +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(Camera.getOrientation()))); + + + +function MyController(hand, triggerAction) { + this.hand = hand; + this.strokes = []; + this.painting = false; + + 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 = SPATIAL_CONTROLLERS_PER_PALM * hand; + this.tip = SPATIAL_CONTROLLERS_PER_PALM * hand + TIP_CONTROLLER_OFFSET; + + + this.strokeColor = { + red: 200, + green: 20, + blue: 40 + }; + + this.laserPointer = Overlays.addOverlay("circle3d", { + size: { + x: STROKE_WIDTH / 2, + y: STROKE_WIDTH / 2 + }, + color: this.strokeColor, + solid: true, + position: center + }) + this.triggerValue = 0; + this.prevTriggerValue = 0; + var _this = this; + + + this.update = function() { + this.updateControllerState() + this.search(); + if (this.canPaint === true) { + this.paint(this.intersection.intersection, this.intersection.surfaceNormal); + } + }; + + this.paint = function(position, normal) { + // print("POSITION " + position.z) + if (this.painting === false) { + if (this.oldPosition) { + this.newStroke(this.oldPosition); + } else { + this.newStroke(position); + } + this.painting = true; + } + + + + 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, 0.001 + Math.random() * .001)); //rand avoid z fighting + + var distance = Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]); + if (this.strokePoints.length > 0 && distance < MIN_POINT_DISTANCE) { + //need a minimum distance to avoid binormal NANs + return; + } + if(this.strokePoints.length > 0 && distance > MAX_POINT_DISTANCE) { + //Prevents drawing lines accross models + this.painting = false; + return; + } + if(this.strokePoints.length === 0) { + localPoint = {x: 0, y: 0, z: 0}; + } + + 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 + }); + if (this.strokePoints.length === MAX_POINTS_PER_LINE) { + this.painting = false; + return; + } + this.oldPosition = position + + } + + this.newStroke = function(position) { + this.strokeBasePosition = position; + this.currentStroke = Entities.addEntity({ + position: position, + type: "PolyLine", + color: this.strokeColor, + dimensions: { + x: 50, + y: 50, + z: 50 + }, + lifetime: 100 + }); + this.strokePoints = []; + this.strokeNormals = []; + this.strokeWidths = []; + + this.strokes.push(this.currentStroke); + + } + + this.updateControllerState = function() { + var triggerValue = Controller.getActionValue(this.triggerAction); + if (triggerValue > TRIGGER_ON_VALUE && this.prevTriggerValue <= TRIGGER_ON_VALUE) { + this.squeeze(); + } else if (triggerValue < TRIGGER_ON_VALUE && this.prevTriggerValue >= TRIGGER_ON_VALUE) { + this.release() + } + + this.prevTriggerValue = triggerValue; + } + + this.squeeze = function() { + this.tryPainting = true; + + } + this.release = function() { + this.painting = false; + this.tryPainting = false; + this.canPaint = false; + this.oldPosition = null; + } + this.search = function() { + + // the trigger is being pressed, do a ray test + var handPosition = this.getHandPosition(); + var pickRay = { + origin: handPosition, + direction: Quat.getUp(this.getHandRotation()) + }; + + + this.intersection = Entities.findRayIntersection(pickRay, true); + if (this.intersection.intersects) { + var distance = Vec3.distance(handPosition, this.intersection.intersection); + if (distance < MAX_DISTANCE) { + var displayPoint = this.intersection.intersection; + displayPoint = Vec3.sum(displayPoint, Vec3.multiply(this.intersection.surfaceNormal, .001)); + if (this.tryPainting) { + this.canPaint = true; + } + Overlays.editOverlay(this.laserPointer, { + visible: true, + position: displayPoint, + rotation: orientationOf(this.intersection.surfaceNormal) + }); + + } else { + this.hitFail(); + } + } else { + this.hitFail(); + } + }; + + this.hitFail = function() { + this.canPaint = false; + + Overlays.editOverlay(this.laserPointer, { + visible: false + }); + + } + + this.cleanup = function() { + Overlays.deleteOverlay(this.laserPointer); + this.strokes.forEach(function(stroke) { + Entities.deleteEntity(stroke); + }); + } +} + +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); + + +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 diff --git a/examples/entityScripts/sprayPaintCan.js b/examples/entityScripts/sprayPaintCan.js deleted file mode 100644 index 21613bdeb5..0000000000 --- a/examples/entityScripts/sprayPaintCan.js +++ /dev/null @@ -1,252 +0,0 @@ -(function() { - // Script.include("../libraries/utils.js"); - //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; - - var ZERO_VEC = { - x: 0, - y: 0, - z: 0 - } - - var MAX_POINTS_PER_LINE = 40; - 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; - var animationSettings = JSON.stringify({ - fps: 30, - loop: true, - firstFrame: 1, - lastFrame: 10000, - running: true - }); - var PI = 3.141593; - var DEG_TO_RAD = PI / 180.0; - - this.paintStream = Entities.addEntity({ - type: "ParticleEffect", - animationSettings: animationSettings, - position: this.properties.position, - textures: "https://raw.githubusercontent.com/ericrius1/SantasLair/santa/assets/smokeparticle.png", - emitSpeed: 0, - speedSpread: 0.02, - polarFinish: 2 * DEG_TO_RAD, - emitAcceleration: ZERO_VEC, - emitRate: 100, - particleRadius: 0.01, - color: { - red: 170, - green: 20, - blue: 150 - }, - 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.sprayStream = function() { - var forwardVec = Quat.getFront(Quat.multiply(self.properties.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)); - position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y)) - Entities.editEntity(self.paintStream, { - position: position, - emitOrientation: forwardVec, - emitSpeed: 5 - }); - - //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.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); - } - this.strokes.forEach(function(stroke) { - Entities.deleteEntity(stroke); - }); - } - Script.update.connect(this.update); -}); - - - -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 diff --git a/examples/sprayPaintSpawner.js b/examples/sprayPaintSpawner.js deleted file mode 100644 index 3b9cee6ef4..0000000000 --- a/examples/sprayPaintSpawner.js +++ /dev/null @@ -1,41 +0,0 @@ -// sprayPaintSpawner.js -// -// Created by Eric Levin on 9/3/15 -// Copyright 2015 High Fidelity, Inc. -// -// This is script spwans a spreay paint can model with the sprayPaintCan.js entity script attached -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - -//Just temporarily using my own bucket here so others can test the entity. Once PR is tested and merged, then the entity script will appear in its proper place in S3, and I wil switch it -// var scriptURL = "https://hifi-public.s3.amazonaws.com/eric/scripts/sprayPaintCan.js?=v6 "; -var scriptURL = Script.resolvePath("entityScripts/sprayPaintCan.js?v2"); -var modelURL = "https://hifi-public.s3.amazonaws.com/eric/models/paintcan.fbx"; - -var sprayCan = Entities.addEntity({ - type: "Model", - name: "spraycan", - modelURL: modelURL, - position: {x: 549.12, y:495.55, z:503.77}, - 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} -}); - -function cleanup() { - - // Uncomment the below line to delete sprayCan on script reload- for faster iteration during development - // Entities.deleteEntity(sprayCan); -} - -Script.scriptEnding.connect(cleanup); - From 3592b78b2b1ea4e2c646a8f6385a8bafe4cfc022 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 30 Sep 2015 16:35:43 -0700 Subject: [PATCH 117/161] less points per line --- examples/closePaint.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/closePaint.js b/examples/closePaint.js index dc3e567823..fdd7d7cac6 100644 --- a/examples/closePaint.js +++ b/examples/closePaint.js @@ -26,7 +26,7 @@ var TRIGGER_ON_VALUE = 0.3; var MAX_DISTANCE = 10; var STROKE_WIDTH = 0.02 -var MAX_POINTS_PER_LINE = 60; +var MAX_POINTS_PER_LINE = 40; var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(Camera.getOrientation()))); @@ -221,6 +221,10 @@ function MyController(hand, triggerAction) { var rightController = new MyController(RIGHT_HAND, Controller.findAction("RIGHT_HAND_CLICK")); var leftController = new MyController(LEFT_HAND, Controller.findAction("LEFT_HAND_CLICK")); +Controller.actionEvent.connect(function(action, state) { + print("ACTION " + action) +}); + function update() { rightController.update(); leftController.update(); From 2899962d43f61990b36e78ed977a8e5443b9e579 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 30 Sep 2015 17:14:17 -0700 Subject: [PATCH 118/161] can now cycle colors with 4 and 2 buttons on hydra --- examples/closePaint.js | 100 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 12 deletions(-) diff --git a/examples/closePaint.js b/examples/closePaint.js index fdd7d7cac6..fba2aa0e80 100644 --- a/examples/closePaint.js +++ b/examples/closePaint.js @@ -28,6 +28,14 @@ var MAX_DISTANCE = 10; var STROKE_WIDTH = 0.02 var MAX_POINTS_PER_LINE = 40; +var RIGHT_4_ACTION = 18; +var RIGHT_2_ACTION = 16; + +var LEFT_4_ACTION = 17; +var LEFT_2_ACTION = 16; + +var HUE_INCREMENT = 0.01; + var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(Camera.getOrientation()))); @@ -52,9 +60,9 @@ function MyController(hand, triggerAction) { this.strokeColor = { - red: 200, - green: 20, - blue: 40 + h: 0.8, + s: 0.9, + l: 0.4 }; this.laserPointer = Overlays.addOverlay("circle3d", { @@ -62,7 +70,7 @@ function MyController(hand, triggerAction) { x: STROKE_WIDTH / 2, y: STROKE_WIDTH / 2 }, - color: this.strokeColor, + color: hslToRgb(this.strokeColor), solid: true, position: center }) @@ -80,7 +88,6 @@ function MyController(hand, triggerAction) { }; this.paint = function(position, normal) { - // print("POSITION " + position.z) if (this.painting === false) { if (this.oldPosition) { this.newStroke(this.oldPosition); @@ -101,13 +108,17 @@ function MyController(hand, triggerAction) { //need a minimum distance to avoid binormal NANs return; } - if(this.strokePoints.length > 0 && distance > MAX_POINT_DISTANCE) { + if (this.strokePoints.length > 0 && distance > MAX_POINT_DISTANCE) { //Prevents drawing lines accross models this.painting = false; return; } - if(this.strokePoints.length === 0) { - localPoint = {x: 0, y: 0, z: 0}; + if (this.strokePoints.length === 0) { + localPoint = { + x: 0, + y: 0, + z: 0 + }; } this.strokePoints.push(localPoint); @@ -122,8 +133,7 @@ function MyController(hand, triggerAction) { this.painting = false; return; } - this.oldPosition = position - + this.oldPosition = position } this.newStroke = function(position) { @@ -131,7 +141,7 @@ function MyController(hand, triggerAction) { this.currentStroke = Entities.addEntity({ position: position, type: "PolyLine", - color: this.strokeColor, + color: hslToRgb(this.strokeColor), dimensions: { x: 50, y: 50, @@ -216,13 +226,39 @@ function MyController(hand, triggerAction) { Entities.deleteEntity(stroke); }); } + + this.cycleColorDown = function() { + this.strokeColor.h -= HUE_INCREMENT; + if (this.strokeColor.h < 0) { + this.strokeColor = 1; + } + } + + this.cycleColorUp = function() { + this.strokeColor.h += HUE_INCREMENT; + if (this.strokeColor.h > 1) { + this.strokeColor.h = 0; + } + } } var rightController = new MyController(RIGHT_HAND, Controller.findAction("RIGHT_HAND_CLICK")); var leftController = new MyController(LEFT_HAND, Controller.findAction("LEFT_HAND_CLICK")); Controller.actionEvent.connect(function(action, state) { - print("ACTION " + action) + if (state === 0) { + return; + } + if (action === RIGHT_4_ACTION) { + rightController.cycleColorUp(); + } else if (action === RIGHT_2_ACTION) { + rightController.cycleColorDown(); + } + if (action === LEFT_4_ACTION) { + leftController.cycleColorUp(); + } else if (action === LEFT_2_ACTION) { + leftController.cycleColorDown(); + } }); function update() { @@ -259,4 +295,44 @@ function orientationOf(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); +} + +/** + * Converts an HSL color value to RGB. Conversion formula + * adapted from http://en.wikipedia.org/wiki/HSL_color_space. + * Assumes h, s, and l are contained in the set [0, 1] and + * returns r, g, and b in the set [0, 255]. + * + * @param Number h The hue + * @param Number s The saturation + * @param Number l The lightness + * @return Array The RGB representation + */ +function hslToRgb(hsl) { + var r, g, b; + + if (hsl.s == 0) { + r = g = b = hsl.l; // achromatic + } else { + var hue2rgb = function hue2rgb(p, q, t) { + if (t < 0) t += 1; + if (t > 1) t -= 1; + if (t < 1 / 6) return p + (q - p) * 6 * t; + if (t < 1 / 2) return q; + if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; + return p; + } + + var q = hsl.l < 0.5 ? hsl.l * (1 + hsl.s) : hsl.l + hsl.s - hsl.l * hsl.s; + var p = 2 * hsl.l - q; + r = hue2rgb(p, q, hsl.h + 1 / 3); + g = hue2rgb(p, q, hsl.h); + b = hue2rgb(p, q, hsl.h - 1 / 3); + } + + return { + red: Math.round(r * 255), + green: Math.round(g * 255), + blue: Math.round(b * 255) + }; } \ No newline at end of file From be9b244779a6b4e34156a22d43004f2fde06d18d Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Sep 2015 17:21:52 -0700 Subject: [PATCH 119/161] Fix the skybox color issue with background rendering when no texture is there --- libraries/model/src/model/Skybox.cpp | 113 +++++++++++++++------------ libraries/model/src/model/Skybox.slf | 10 ++- 2 files changed, 69 insertions(+), 54 deletions(-) diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 944d16a6dd..4d49492c39 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -45,11 +45,18 @@ void Skybox::setCubemap(const gpu::TexturePointer& cubemap) { void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) { + const int VERTICES_SLOT = 0; + const int COLOR_SLOT = 1; + + // Create the static shared elements used to render the skybox static gpu::BufferPointer theBuffer; static gpu::Stream::FormatPointer theFormat; - - if (skybox.getCubemap()) { - if (!theBuffer) { + static gpu::BufferPointer theConstants; + static gpu::PipelinePointer thePipeline; + static int SKYBOX_CONSTANTS_SLOT = 0; // need to be defined by the compilation of the shader + static std::once_flag once; + std::call_once(once, [&] { + { const float CLIP = 1.0f; const glm::vec2 vertices[4] = { { -CLIP, -CLIP }, { CLIP, -CLIP }, { -CLIP, CLIP }, { CLIP, CLIP } }; theBuffer = std::make_shared(sizeof(vertices), (const gpu::Byte*) vertices); @@ -57,63 +64,65 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky theFormat->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ)); } - glm::mat4 projMat; - viewFrustum.evalProjectionMatrix(projMat); + { + auto skyVS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(Skybox_vert))); + auto skyFS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(Skybox_frag))); + auto skyShader = gpu::ShaderPointer(gpu::Shader::createProgram(skyVS, skyFS)); - Transform viewTransform; - viewFrustum.evalViewTransform(viewTransform); - batch.setProjectionTransform(projMat); - batch.setViewTransform(viewTransform); - batch.setModelTransform(Transform()); // only for Mac - batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8); - batch.setInputFormat(theFormat); + gpu::Shader::BindingSet bindings; + bindings.insert(gpu::Shader::Binding(std::string("cubeMap"), 0)); + if (!gpu::Shader::makeProgram(*skyShader, bindings)) { - if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) { - static gpu::BufferPointer theConstants; - static gpu::PipelinePointer thePipeline; - static int SKYBOX_CONSTANTS_SLOT = 0; // need to be defined by the compilation of the shader - if (!thePipeline) { - auto skyVS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(Skybox_vert))); - auto skyFS = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(Skybox_frag))); - auto skyShader = gpu::ShaderPointer(gpu::Shader::createProgram(skyVS, skyFS)); - - gpu::Shader::BindingSet bindings; - bindings.insert(gpu::Shader::Binding(std::string("cubeMap"), 0)); - if (!gpu::Shader::makeProgram(*skyShader, bindings)) { - - } - - SKYBOX_CONSTANTS_SLOT = skyShader->getBuffers().findLocation("skyboxBuffer"); - if (SKYBOX_CONSTANTS_SLOT == gpu::Shader::INVALID_LOCATION) { - SKYBOX_CONSTANTS_SLOT = skyShader->getUniforms().findLocation("skyboxBuffer"); - } - - auto skyState = std::make_shared(); - skyState->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); - - thePipeline = gpu::PipelinePointer(gpu::Pipeline::create(skyShader, skyState)); - - auto color = glm::vec4(1.0f); - theConstants = std::make_shared(sizeof(color), (const gpu::Byte*) &color); } - if (glm::all(glm::equal(skybox.getColor(), glm::vec3(0.0f)))) { - auto color = glm::vec4(1.0f); - theConstants->setSubData(0, sizeof(color), (const gpu::Byte*) &color); - } else { - theConstants->setSubData(0, sizeof(Color), (const gpu::Byte*) &skybox.getColor()); + SKYBOX_CONSTANTS_SLOT = skyShader->getBuffers().findLocation("skyboxBuffer"); + if (SKYBOX_CONSTANTS_SLOT == gpu::Shader::INVALID_LOCATION) { + SKYBOX_CONSTANTS_SLOT = skyShader->getUniforms().findLocation("skyboxBuffer"); } - batch.setPipeline(thePipeline); - batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); - batch.setResourceTexture(0, skybox.getCubemap()); - batch.draw(gpu::TRIANGLE_STRIP, 4); + auto skyState = std::make_shared(); + skyState->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); + + thePipeline = gpu::PipelinePointer(gpu::Pipeline::create(skyShader, skyState)); + + auto color = glm::vec4(1.0f); + theConstants = std::make_shared(sizeof(color), (const gpu::Byte*) &color); } + }); - } else { - // skybox has no cubemap, just clear the color buffer - auto color = skybox.getColor(); - batch.clearFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(color, 0.0f), 0.0f, 0, true); + // Render + glm::mat4 projMat; + viewFrustum.evalProjectionMatrix(projMat); + + Transform viewTransform; + viewFrustum.evalViewTransform(viewTransform); + batch.setProjectionTransform(projMat); + batch.setViewTransform(viewTransform); + batch.setModelTransform(Transform()); // only for Mac + batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8); + batch.setInputFormat(theFormat); + + gpu::TexturePointer skymap; + auto color = glm::vec4(skybox.getColor(), 0.0f); + if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) { + skymap = skybox.getCubemap(); + + if (glm::all(glm::equal(skybox.getColor(), glm::vec3(0.0f)))) { + color = glm::vec4(1.0f); + } else { + color.w = 1.0f; + } } + // Update the constant color. + theConstants->setSubData(0, sizeof(glm::vec4), (const gpu::Byte*) &color); + + batch.setPipeline(thePipeline); + batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); + batch.setResourceTexture(0, skymap); + + batch.draw(gpu::TRIANGLE_STRIP, 4); + + batch.setResourceTexture(0, nullptr); + } diff --git a/libraries/model/src/model/Skybox.slf b/libraries/model/src/model/Skybox.slf index 382801f52d..66abee8948 100755 --- a/libraries/model/src/model/Skybox.slf +++ b/libraries/model/src/model/Skybox.slf @@ -40,8 +40,14 @@ void main(void) { #else vec3 coord = normalize(_normal); - vec3 texel = texture(cubeMap, coord).rgb; - vec3 color = texel * _skybox._color.rgb; + + // Skybox color or blend with skymap + vec3 color = _skybox._color.rgb; + if (_skybox._color.a > 0.0) { + vec3 texel = texture(cubeMap, coord).rgb; + color *= texel; + } + vec3 pixel = pow(color, vec3(1.0/2.2)); // manual Gamma correction _fragColor = vec4(pixel, 0.0); From d3d47752327dd0a90fee77e30993d5c16bcb0193 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Sep 2015 17:54:20 -0700 Subject: [PATCH 120/161] THe dataBuffer contining the properties of the skybox is now per instace and not static and shared so it's static from frames to frames --- libraries/model/src/model/Skybox.cpp | 55 ++++++++++--------- libraries/model/src/model/Skybox.h | 18 ++++-- .../src/procedural/ProceduralSkybox.cpp | 1 + 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 4d49492c39..7c22d7a062 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -21,6 +21,8 @@ using namespace model; Skybox::Skybox() { + Data data; + _dataBuffer = gpu::BufferView(std::make_shared(sizeof(Data), (const gpu::Byte*) &data)); /* // PLease create a default engineer skybox _cubemap.reset( gpu::Texture::createCube(gpu::Element::COLOR_RGBA_32, 1)); @@ -36,7 +38,7 @@ Skybox::Skybox() { } void Skybox::setColor(const Color& color) { - _color = color; + _dataBuffer.edit()._color = color; } void Skybox::setCubemap(const gpu::TexturePointer& cubemap) { @@ -44,16 +46,33 @@ void Skybox::setCubemap(const gpu::TexturePointer& cubemap) { } -void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) { - const int VERTICES_SLOT = 0; - const int COLOR_SLOT = 1; +void Skybox::updateDataBuffer() const { + auto blend = 0.0f; + if (getCubemap() && getCubemap()->isDefined()) { + blend = 1.0f; + } + if (blend != _dataBuffer.get()._blend) { + _dataBuffer.edit()._blend = blend; + } +} + + + +void Skybox::render(gpu::Batch& batch, const ViewFrustum& frustum) const { + updateDataBuffer(); + Skybox::render(batch, frustum, (*this)); +} + + +void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) { // Create the static shared elements used to render the skybox static gpu::BufferPointer theBuffer; static gpu::Stream::FormatPointer theFormat; static gpu::BufferPointer theConstants; static gpu::PipelinePointer thePipeline; - static int SKYBOX_CONSTANTS_SLOT = 0; // need to be defined by the compilation of the shader + const int SKYBOX_SKYMAP_SLOT = 0; + const int SKYBOX_CONSTANTS_SLOT = 0; static std::once_flag once; std::call_once(once, [&] { { @@ -70,23 +89,16 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky auto skyShader = gpu::ShaderPointer(gpu::Shader::createProgram(skyVS, skyFS)); gpu::Shader::BindingSet bindings; - bindings.insert(gpu::Shader::Binding(std::string("cubeMap"), 0)); + bindings.insert(gpu::Shader::Binding(std::string("cubeMap"), SKYBOX_SKYMAP_SLOT)); + bindings.insert(gpu::Shader::Binding(std::string("skyboxBuffer"), SKYBOX_CONSTANTS_SLOT)); if (!gpu::Shader::makeProgram(*skyShader, bindings)) { } - SKYBOX_CONSTANTS_SLOT = skyShader->getBuffers().findLocation("skyboxBuffer"); - if (SKYBOX_CONSTANTS_SLOT == gpu::Shader::INVALID_LOCATION) { - SKYBOX_CONSTANTS_SLOT = skyShader->getUniforms().findLocation("skyboxBuffer"); - } - auto skyState = std::make_shared(); skyState->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); thePipeline = gpu::PipelinePointer(gpu::Pipeline::create(skyShader, skyState)); - - auto color = glm::vec4(1.0f); - theConstants = std::make_shared(sizeof(color), (const gpu::Byte*) &color); } }); @@ -103,26 +115,17 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.setInputFormat(theFormat); gpu::TexturePointer skymap; - auto color = glm::vec4(skybox.getColor(), 0.0f); if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) { skymap = skybox.getCubemap(); - - if (glm::all(glm::equal(skybox.getColor(), glm::vec3(0.0f)))) { - color = glm::vec4(1.0f); - } else { - color.w = 1.0f; - } } - // Update the constant color. - theConstants->setSubData(0, sizeof(glm::vec4), (const gpu::Byte*) &color); batch.setPipeline(thePipeline); - batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); - batch.setResourceTexture(0, skymap); + batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, skybox._dataBuffer); + batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, skymap); batch.draw(gpu::TRIANGLE_STRIP, 4); - batch.setResourceTexture(0, nullptr); + batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr); } diff --git a/libraries/model/src/model/Skybox.h b/libraries/model/src/model/Skybox.h index e9f95afa16..14ba9fa005 100755 --- a/libraries/model/src/model/Skybox.h +++ b/libraries/model/src/model/Skybox.h @@ -30,20 +30,28 @@ public: virtual ~Skybox() {}; void setColor(const Color& color); - const Color& getColor() const { return _color; } + const Color getColor() const { return _dataBuffer.get()._color; } void setCubemap(const gpu::TexturePointer& cubemap); const gpu::TexturePointer& getCubemap() const { return _cubemap; } - virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const { - render(batch, frustum, (*this)); - } + virtual void render(gpu::Batch& batch, const ViewFrustum& frustum) const; + static void render(gpu::Batch& batch, const ViewFrustum& frustum, const Skybox& skybox); protected: gpu::TexturePointer _cubemap; - Color _color{1.0f, 1.0f, 1.0f}; + + class Data { + public: + glm::vec3 _color{ 1.0f, 1.0f, 1.0f }; + float _blend = 1.0f; + }; + + mutable gpu::BufferView _dataBuffer; + + void updateDataBuffer() const; }; typedef std::shared_ptr< Skybox > SkyboxPointer; diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index f69e0575de..1c7e7e457c 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -43,6 +43,7 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& frustum) con void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const ProceduralSkybox& skybox) { if (!(skybox._procedural)) { + skybox.updateDataBuffer(); Skybox::render(batch, viewFrustum, skybox); } From 69c40754390f7e70dcfcd16f79bf14f278e5286f Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Sep 2015 18:08:01 -0700 Subject: [PATCH 121/161] Fix the behavior when skybox color is black and skymap is available --- libraries/model/src/model/Skybox.cpp | 4 ++++ libraries/model/src/model/Skybox.slf | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 7c22d7a062..21b40a54c8 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -50,6 +50,10 @@ void Skybox::updateDataBuffer() const { auto blend = 0.0f; if (getCubemap() && getCubemap()->isDefined()) { blend = 1.0f; + // If pitch black neutralize the color + if (glm::all(glm::equal(getColor(), glm::vec3(0.0f)))) { + blend = 2.0f; + } } if (blend != _dataBuffer.get()._blend) { diff --git a/libraries/model/src/model/Skybox.slf b/libraries/model/src/model/Skybox.slf index 66abee8948..a6283055d3 100755 --- a/libraries/model/src/model/Skybox.slf +++ b/libraries/model/src/model/Skybox.slf @@ -45,7 +45,9 @@ void main(void) { vec3 color = _skybox._color.rgb; if (_skybox._color.a > 0.0) { vec3 texel = texture(cubeMap, coord).rgb; - color *= texel; + if (_skybox._color.a < 2.0) { + color *= texel; + } } vec3 pixel = pow(color, vec3(1.0/2.2)); // manual Gamma correction From 0398f9429e9d7d21f181167664b52eb0799aecd7 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 30 Sep 2015 18:39:13 -0700 Subject: [PATCH 122/161] fix the coo/texel blender mode for the case when color is black and the stereo issue --- libraries/model/src/model/Skybox.cpp | 2 +- libraries/model/src/model/Skybox.slf | 2 ++ libraries/render-utils/src/RenderDeferredTask.cpp | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 21b40a54c8..e516fae583 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -129,7 +129,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.draw(gpu::TRIANGLE_STRIP, 4); - batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr); + // batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr); } diff --git a/libraries/model/src/model/Skybox.slf b/libraries/model/src/model/Skybox.slf index a6283055d3..6246bbd9d3 100755 --- a/libraries/model/src/model/Skybox.slf +++ b/libraries/model/src/model/Skybox.slf @@ -47,6 +47,8 @@ void main(void) { vec3 texel = texture(cubeMap, coord).rgb; if (_skybox._color.a < 2.0) { color *= texel; + } else { + color = texel; } } diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index e16544f5cd..504070963d 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -335,9 +335,10 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren batch.enableStereo(false); batch.setFramebuffer(primaryFboColorDepthStencil); - batch.clearStencilFramebuffer(0, true); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); + batch.clearStencilFramebuffer(0, true); + Transform modelMat; batch.setModelTransform(modelMat); From 191a4740a392905e148238aa60198749ea2b11fb Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 09:50:58 -0700 Subject: [PATCH 123/161] laser color matches paint color --- examples/acScripts/rain.js | 6 ++++-- examples/closePaint.js | 17 +++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/acScripts/rain.js b/examples/acScripts/rain.js index 3f38b8d36a..fc02b7163f 100644 --- a/examples/acScripts/rain.js +++ b/examples/acScripts/rain.js @@ -18,7 +18,7 @@ var RainSquall = function (properties) { dropFallSpeed = 1, // m/s dropLifetime = 60, // Seconds dropSpinMax = 0, // Maximum angular velocity per axis; deg/s - debug = false, // Display origin circle; don't use running on Stack Manager + debug = true, // Display origin circle; don't use running on Stack Manager // Other squallCircle, SQUALL_CIRCLE_COLOR = { red: 255, green: 0, blue: 0 }, @@ -151,8 +151,10 @@ var RainSquall = function (properties) { }; }; +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(Camera.getOrientation()))); +center.y += 10; var rainSquall1 = new RainSquall({ - origin: { x: 1195, y: 1223, z: 1020 }, + origin:center, radius: 25, dropsPerMinute: 120, dropSize: { x: 0.1, y: 0.1, z: 0.1 }, diff --git a/examples/closePaint.js b/examples/closePaint.js index fba2aa0e80..c17402857b 100644 --- a/examples/closePaint.js +++ b/examples/closePaint.js @@ -34,7 +34,7 @@ var RIGHT_2_ACTION = 16; var LEFT_4_ACTION = 17; var LEFT_2_ACTION = 16; -var HUE_INCREMENT = 0.01; +var HUE_INCREMENT = 0.02; var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(Camera.getOrientation()))); @@ -61,16 +61,17 @@ function MyController(hand, triggerAction) { this.strokeColor = { h: 0.8, - s: 0.9, + s: 0.8, l: 0.4 }; + this.laserPointer = Overlays.addOverlay("circle3d", { size: { x: STROKE_WIDTH / 2, y: STROKE_WIDTH / 2 }, - color: hslToRgb(this.strokeColor), + color: hslToRgb(this.strokeColor ), solid: true, position: center }) @@ -78,7 +79,6 @@ function MyController(hand, triggerAction) { this.prevTriggerValue = 0; var _this = this; - this.update = function() { this.updateControllerState() this.search(); @@ -232,6 +232,9 @@ function MyController(hand, triggerAction) { if (this.strokeColor.h < 0) { this.strokeColor = 1; } + Overlays.editOverlay(this.laserPointer, { + color: hslToRgb(this.strokeColor) + }); } this.cycleColorUp = function() { @@ -239,6 +242,9 @@ function MyController(hand, triggerAction) { if (this.strokeColor.h > 1) { this.strokeColor.h = 0; } + Overlays.editOverlay(this.laserPointer, { + color: hslToRgb(this.strokeColor) + }); } } @@ -308,9 +314,8 @@ function orientationOf(vector) { * @param Number l The lightness * @return Array The RGB representation */ -function hslToRgb(hsl) { +function hslToRgb(hsl, hueOffset) { var r, g, b; - if (hsl.s == 0) { r = g = b = hsl.l; // achromatic } else { From ef5ad9eeb3eea43592872ec6a139898f00e32749 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 11:02:22 -0700 Subject: [PATCH 124/161] Laser stays visible when further away from surfaces --- examples/closePaint.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/examples/closePaint.js b/examples/closePaint.js index c17402857b..fa692e0bbc 100644 --- a/examples/closePaint.js +++ b/examples/closePaint.js @@ -21,11 +21,10 @@ var MAX_POINT_DISTANCE = 0.5; var SPATIAL_CONTROLLERS_PER_PALM = 2; var TIP_CONTROLLER_OFFSET = 1; -var TRIGGER_ON_VALUE = 0.3; +var TRIGGER_ON_VALUE = 0.1; var MAX_DISTANCE = 10; -var STROKE_WIDTH = 0.02 var MAX_POINTS_PER_LINE = 40; var RIGHT_4_ACTION = 18; @@ -36,6 +35,9 @@ var LEFT_2_ACTION = 16; var HUE_INCREMENT = 0.02; +var MIN_STROKE_WIDTH = 0.005; +var MAX_STROKE_WIDTH = 0.03; + var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(Camera.getOrientation()))); @@ -45,6 +47,7 @@ function MyController(hand, triggerAction) { this.hand = hand; this.strokes = []; this.painting = false; + this.currentStrokeWidth = MIN_STROKE_WIDTH; if (this.hand === RIGHT_HAND) { this.getHandPosition = MyAvatar.getRightPalmPosition; @@ -67,11 +70,7 @@ function MyController(hand, triggerAction) { this.laserPointer = Overlays.addOverlay("circle3d", { - size: { - x: STROKE_WIDTH / 2, - y: STROKE_WIDTH / 2 - }, - color: hslToRgb(this.strokeColor ), + color: hslToRgb(this.strokeColor), solid: true, position: center }) @@ -123,7 +122,7 @@ function MyController(hand, triggerAction) { this.strokePoints.push(localPoint); this.strokeNormals.push(normal); - this.strokeWidths.push(STROKE_WIDTH); + this.strokeWidths.push(this.currentStrokeWidth); Entities.editEntity(this.currentStroke, { linePoints: this.strokePoints, normals: this.strokeNormals, @@ -158,14 +157,14 @@ function MyController(hand, triggerAction) { } this.updateControllerState = function() { - var triggerValue = Controller.getActionValue(this.triggerAction); - if (triggerValue > TRIGGER_ON_VALUE && this.prevTriggerValue <= TRIGGER_ON_VALUE) { + this.triggerValue = Controller.getActionValue(this.triggerAction); + if (this.triggerValue > TRIGGER_ON_VALUE && this.prevTriggerValue <= TRIGGER_ON_VALUE) { this.squeeze(); - } else if (triggerValue < TRIGGER_ON_VALUE && this.prevTriggerValue >= TRIGGER_ON_VALUE) { + } else if (this.triggerValue < TRIGGER_ON_VALUE && this.prevTriggerValue >= TRIGGER_ON_VALUE) { this.release() } - this.prevTriggerValue = triggerValue; + this.prevTriggerValue = this.triggerValue; } this.squeeze = function() { @@ -193,14 +192,21 @@ function MyController(hand, triggerAction) { var distance = Vec3.distance(handPosition, this.intersection.intersection); if (distance < MAX_DISTANCE) { var displayPoint = this.intersection.intersection; - displayPoint = Vec3.sum(displayPoint, Vec3.multiply(this.intersection.surfaceNormal, .001)); + displayPoint = Vec3.sum(displayPoint, Vec3.multiply(this.intersection.surfaceNormal, .01)); if (this.tryPainting) { this.canPaint = true; } + this.currentStrokeWidth = map(this.triggerValue, 0, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH); + var laserSize = map(distance, 1, MAX_DISTANCE, 0.001, 0.1); + laserSize += this.currentStrokeWidth/2; Overlays.editOverlay(this.laserPointer, { visible: true, position: displayPoint, - rotation: orientationOf(this.intersection.surfaceNormal) + rotation: orientationOf(this.intersection.surfaceNormal), + size: { + x: laserSize, + y: laserSize + } }); } else { @@ -340,4 +346,8 @@ function hslToRgb(hsl, hueOffset) { green: Math.round(g * 255), blue: Math.round(b * 255) }; +} + +function map(value, min1, max1, min2, max2) { + return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); } \ No newline at end of file From 290659b9f6650c01e04721e19b16f4f66989b1bf Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 11:46:37 -0700 Subject: [PATCH 125/161] increased lifetime --- examples/closePaint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/closePaint.js b/examples/closePaint.js index fa692e0bbc..136237d4b7 100644 --- a/examples/closePaint.js +++ b/examples/closePaint.js @@ -146,7 +146,7 @@ function MyController(hand, triggerAction) { y: 50, z: 50 }, - lifetime: 100 + lifetime: 200 }); this.strokePoints = []; this.strokeNormals = []; From 7ee26c5d4a8366b2f3399b2bcbe1e40108ce0176 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 14:26:22 -0700 Subject: [PATCH 126/161] tweaked settings --- examples/closePaint.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/closePaint.js b/examples/closePaint.js index 136237d4b7..6590d7e14e 100644 --- a/examples/closePaint.js +++ b/examples/closePaint.js @@ -15,13 +15,13 @@ var RIGHT_HAND = 1; var LEFT_HAND = 0; -var MIN_POINT_DISTANCE = 0.01; +var MIN_POINT_DISTANCE = 0.02; var MAX_POINT_DISTANCE = 0.5; var SPATIAL_CONTROLLERS_PER_PALM = 2; var TIP_CONTROLLER_OFFSET = 1; -var TRIGGER_ON_VALUE = 0.1; +var TRIGGER_ON_VALUE = 0.3; var MAX_DISTANCE = 10; @@ -35,8 +35,8 @@ var LEFT_2_ACTION = 16; var HUE_INCREMENT = 0.02; -var MIN_STROKE_WIDTH = 0.005; -var MAX_STROKE_WIDTH = 0.03; +var MIN_STROKE_WIDTH = 0.002; +var MAX_STROKE_WIDTH = 0.04; var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(Camera.getOrientation()))); @@ -196,7 +196,7 @@ function MyController(hand, triggerAction) { if (this.tryPainting) { this.canPaint = true; } - this.currentStrokeWidth = map(this.triggerValue, 0, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH); + this.currentStrokeWidth = map(this.triggerValue, TRIGGER_ON_VALUE, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH); var laserSize = map(distance, 1, MAX_DISTANCE, 0.001, 0.1); laserSize += this.currentStrokeWidth/2; Overlays.editOverlay(this.laserPointer, { From 5aef7475d6c2f8d2ad6d107b7083ce24a19da320 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 14:42:51 -0700 Subject: [PATCH 127/161] 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 128/161] 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 e1b720d338b9acd15862340dd4ea2ef193e58a68 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 1 Oct 2015 15:18:44 -0700 Subject: [PATCH 129/161] Moved some functions to utils, fixed formatting --- examples/closePaint.js | 490 ++++++++++++++++-------------------- examples/libraries/utils.js | 66 +++++ 2 files changed, 279 insertions(+), 277 deletions(-) diff --git a/examples/closePaint.js b/examples/closePaint.js index 6590d7e14e..d9f70aab3c 100644 --- a/examples/closePaint.js +++ b/examples/closePaint.js @@ -11,6 +11,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +Script.include("libraries/utils.js"); + var RIGHT_HAND = 1; var LEFT_HAND = 0; @@ -44,310 +46,244 @@ var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(Camera.g function MyController(hand, triggerAction) { - this.hand = hand; - this.strokes = []; - this.painting = false; - this.currentStrokeWidth = MIN_STROKE_WIDTH; - - 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 = SPATIAL_CONTROLLERS_PER_PALM * hand; - this.tip = SPATIAL_CONTROLLERS_PER_PALM * hand + TIP_CONTROLLER_OFFSET; - - - this.strokeColor = { - h: 0.8, - s: 0.8, - l: 0.4 - }; - - - this.laserPointer = Overlays.addOverlay("circle3d", { - color: hslToRgb(this.strokeColor), - solid: true, - position: center - }) - this.triggerValue = 0; - this.prevTriggerValue = 0; - var _this = this; - - this.update = function() { - this.updateControllerState() - this.search(); - if (this.canPaint === true) { - this.paint(this.intersection.intersection, this.intersection.surfaceNormal); - } - }; - - this.paint = function(position, normal) { - if (this.painting === false) { - if (this.oldPosition) { - this.newStroke(this.oldPosition); - } else { - this.newStroke(position); - } - this.painting = true; - } - - - - 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, 0.001 + Math.random() * .001)); //rand avoid z fighting - - var distance = Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]); - if (this.strokePoints.length > 0 && distance < MIN_POINT_DISTANCE) { - //need a minimum distance to avoid binormal NANs - return; - } - if (this.strokePoints.length > 0 && distance > MAX_POINT_DISTANCE) { - //Prevents drawing lines accross models - this.painting = false; - return; - } - if (this.strokePoints.length === 0) { - localPoint = { - x: 0, - y: 0, - z: 0 - }; - } - - this.strokePoints.push(localPoint); - this.strokeNormals.push(normal); - this.strokeWidths.push(this.currentStrokeWidth); - Entities.editEntity(this.currentStroke, { - linePoints: this.strokePoints, - normals: this.strokeNormals, - strokeWidths: this.strokeWidths - }); - if (this.strokePoints.length === MAX_POINTS_PER_LINE) { - this.painting = false; - return; - } - this.oldPosition = position - } - - this.newStroke = function(position) { - this.strokeBasePosition = position; - this.currentStroke = Entities.addEntity({ - position: position, - type: "PolyLine", - color: hslToRgb(this.strokeColor), - dimensions: { - x: 50, - y: 50, - z: 50 - }, - lifetime: 200 - }); - this.strokePoints = []; - this.strokeNormals = []; - this.strokeWidths = []; - - this.strokes.push(this.currentStroke); - - } - - this.updateControllerState = function() { - this.triggerValue = Controller.getActionValue(this.triggerAction); - if (this.triggerValue > TRIGGER_ON_VALUE && this.prevTriggerValue <= TRIGGER_ON_VALUE) { - this.squeeze(); - } else if (this.triggerValue < TRIGGER_ON_VALUE && this.prevTriggerValue >= TRIGGER_ON_VALUE) { - this.release() - } - - this.prevTriggerValue = this.triggerValue; - } - - this.squeeze = function() { - this.tryPainting = true; - - } - this.release = function() { + this.hand = hand; + this.strokes = []; this.painting = false; - this.tryPainting = false; - this.canPaint = false; - this.oldPosition = null; - } - this.search = function() { + this.currentStrokeWidth = MIN_STROKE_WIDTH; - // the trigger is being pressed, do a ray test - var handPosition = this.getHandPosition(); - var pickRay = { - origin: handPosition, - direction: Quat.getUp(this.getHandRotation()) + 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 = SPATIAL_CONTROLLERS_PER_PALM * hand; + this.tip = SPATIAL_CONTROLLERS_PER_PALM * hand + TIP_CONTROLLER_OFFSET; + + + this.strokeColor = { + h: 0.8, + s: 0.8, + l: 0.4 }; - this.intersection = Entities.findRayIntersection(pickRay, true); - if (this.intersection.intersects) { - var distance = Vec3.distance(handPosition, this.intersection.intersection); - if (distance < MAX_DISTANCE) { - var displayPoint = this.intersection.intersection; - displayPoint = Vec3.sum(displayPoint, Vec3.multiply(this.intersection.surfaceNormal, .01)); - if (this.tryPainting) { - this.canPaint = true; + this.laserPointer = Overlays.addOverlay("circle3d", { + color: hslToRgb(this.strokeColor), + solid: true, + position: center + }); + this.triggerValue = 0; + this.prevTriggerValue = 0; + var _this = this; + + this.update = function() { + this.updateControllerState(); + this.search(); + if (this.canPaint === true) { + this.paint(this.intersection.intersection, this.intersection.surfaceNormal); } - this.currentStrokeWidth = map(this.triggerValue, TRIGGER_ON_VALUE, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH); - var laserSize = map(distance, 1, MAX_DISTANCE, 0.001, 0.1); - laserSize += this.currentStrokeWidth/2; + }; + + this.paint = function(position, normal) { + if (this.painting === false) { + if (this.oldPosition) { + this.newStroke(this.oldPosition); + } else { + this.newStroke(position); + } + this.painting = true; + } + + + + 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, 0.001 + Math.random() * .001)); //rand avoid z fighting + + var distance = Vec3.distance(localPoint, this.strokePoints[this.strokePoints.length - 1]); + if (this.strokePoints.length > 0 && distance < MIN_POINT_DISTANCE) { + //need a minimum distance to avoid binormal NANs + return; + } + if (this.strokePoints.length > 0 && distance > MAX_POINT_DISTANCE) { + //Prevents drawing lines accross models + this.painting = false; + return; + } + if (this.strokePoints.length === 0) { + localPoint = { + x: 0, + y: 0, + z: 0 + }; + } + + this.strokePoints.push(localPoint); + this.strokeNormals.push(normal); + this.strokeWidths.push(this.currentStrokeWidth); + Entities.editEntity(this.currentStroke, { + linePoints: this.strokePoints, + normals: this.strokeNormals, + strokeWidths: this.strokeWidths + }); + if (this.strokePoints.length === MAX_POINTS_PER_LINE) { + this.painting = false; + return; + } + this.oldPosition = position; + } + + this.newStroke = function(position) { + this.strokeBasePosition = position; + this.currentStroke = Entities.addEntity({ + position: position, + type: "PolyLine", + color: hslToRgb(this.strokeColor), + dimensions: { + x: 50, + y: 50, + z: 50 + }, + lifetime: 200 + }); + this.strokePoints = []; + this.strokeNormals = []; + this.strokeWidths = []; + + this.strokes.push(this.currentStroke); + + } + + this.updateControllerState = function() { + this.triggerValue = Controller.getActionValue(this.triggerAction); + if (this.triggerValue > TRIGGER_ON_VALUE && this.prevTriggerValue <= TRIGGER_ON_VALUE) { + this.squeeze(); + } else if (this.triggerValue < TRIGGER_ON_VALUE && this.prevTriggerValue >= TRIGGER_ON_VALUE) { + this.release(); + } + + this.prevTriggerValue = this.triggerValue; + } + + this.squeeze = function() { + this.tryPainting = true; + + } + this.release = function() { + this.painting = false; + this.tryPainting = false; + this.canPaint = false; + this.oldPosition = null; + } + this.search = function() { + + // the trigger is being pressed, do a ray test + var handPosition = this.getHandPosition(); + var pickRay = { + origin: handPosition, + direction: Quat.getUp(this.getHandRotation()) + }; + + + this.intersection = Entities.findRayIntersection(pickRay, true); + if (this.intersection.intersects) { + var distance = Vec3.distance(handPosition, this.intersection.intersection); + if (distance < MAX_DISTANCE) { + var displayPoint = this.intersection.intersection; + displayPoint = Vec3.sum(displayPoint, Vec3.multiply(this.intersection.surfaceNormal, .01)); + if (this.tryPainting) { + this.canPaint = true; + } + this.currentStrokeWidth = map(this.triggerValue, TRIGGER_ON_VALUE, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH); + var laserSize = map(distance, 1, MAX_DISTANCE, 0.01, 0.1); + laserSize += this.currentStrokeWidth / 2; + Overlays.editOverlay(this.laserPointer, { + visible: true, + position: displayPoint, + rotation: orientationOf(this.intersection.surfaceNormal), + size: { + x: laserSize, + y: laserSize + } + }); + + } else { + this.hitFail(); + } + } else { + this.hitFail(); + } + }; + + this.hitFail = function() { + this.canPaint = false; + Overlays.editOverlay(this.laserPointer, { - visible: true, - position: displayPoint, - rotation: orientationOf(this.intersection.surfaceNormal), - size: { - x: laserSize, - y: laserSize - } + visible: false }); - } else { - this.hitFail(); - } - } else { - this.hitFail(); } - }; - this.hitFail = function() { - this.canPaint = false; - - Overlays.editOverlay(this.laserPointer, { - visible: false - }); - - } - - this.cleanup = function() { - Overlays.deleteOverlay(this.laserPointer); - this.strokes.forEach(function(stroke) { - Entities.deleteEntity(stroke); - }); - } - - this.cycleColorDown = function() { - this.strokeColor.h -= HUE_INCREMENT; - if (this.strokeColor.h < 0) { - this.strokeColor = 1; + this.cleanup = function() { + Overlays.deleteOverlay(this.laserPointer); + this.strokes.forEach(function(stroke) { + Entities.deleteEntity(stroke); + }); } - Overlays.editOverlay(this.laserPointer, { - color: hslToRgb(this.strokeColor) - }); - } - this.cycleColorUp = function() { - this.strokeColor.h += HUE_INCREMENT; - if (this.strokeColor.h > 1) { - this.strokeColor.h = 0; + this.cycleColorDown = function() { + this.strokeColor.h -= HUE_INCREMENT; + if (this.strokeColor.h < 0) { + this.strokeColor = 1; + } + Overlays.editOverlay(this.laserPointer, { + color: hslToRgb(this.strokeColor) + }); + } + + this.cycleColorUp = function() { + this.strokeColor.h += HUE_INCREMENT; + if (this.strokeColor.h > 1) { + this.strokeColor.h = 0; + } + Overlays.editOverlay(this.laserPointer, { + color: hslToRgb(this.strokeColor) + }); } - Overlays.editOverlay(this.laserPointer, { - color: hslToRgb(this.strokeColor) - }); - } } var rightController = new MyController(RIGHT_HAND, Controller.findAction("RIGHT_HAND_CLICK")); var leftController = new MyController(LEFT_HAND, Controller.findAction("LEFT_HAND_CLICK")); Controller.actionEvent.connect(function(action, state) { - if (state === 0) { - return; - } - if (action === RIGHT_4_ACTION) { - rightController.cycleColorUp(); - } else if (action === RIGHT_2_ACTION) { - rightController.cycleColorDown(); - } - if (action === LEFT_4_ACTION) { - leftController.cycleColorUp(); - } else if (action === LEFT_2_ACTION) { - leftController.cycleColorDown(); - } + if (state === 0) { + return; + } + if (action === RIGHT_4_ACTION) { + rightController.cycleColorUp(); + } else if (action === RIGHT_2_ACTION) { + rightController.cycleColorDown(); + } + if (action === LEFT_4_ACTION) { + leftController.cycleColorUp(); + } else if (action === LEFT_2_ACTION) { + leftController.cycleColorDown(); + } }); function update() { - rightController.update(); - leftController.update(); + rightController.update(); + leftController.update(); } function cleanup() { - rightController.cleanup(); - leftController.cleanup(); + rightController.cleanup(); + leftController.cleanup(); } Script.scriptEnding.connect(cleanup); Script.update.connect(update); - - -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); -} - -/** - * Converts an HSL color value to RGB. Conversion formula - * adapted from http://en.wikipedia.org/wiki/HSL_color_space. - * Assumes h, s, and l are contained in the set [0, 1] and - * returns r, g, and b in the set [0, 255]. - * - * @param Number h The hue - * @param Number s The saturation - * @param Number l The lightness - * @return Array The RGB representation - */ -function hslToRgb(hsl, hueOffset) { - var r, g, b; - if (hsl.s == 0) { - r = g = b = hsl.l; // achromatic - } else { - var hue2rgb = function hue2rgb(p, q, t) { - if (t < 0) t += 1; - if (t > 1) t -= 1; - if (t < 1 / 6) return p + (q - p) * 6 * t; - if (t < 1 / 2) return q; - if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; - return p; - } - - var q = hsl.l < 0.5 ? hsl.l * (1 + hsl.s) : hsl.l + hsl.s - hsl.l * hsl.s; - var p = 2 * hsl.l - q; - r = hue2rgb(p, q, hsl.h + 1 / 3); - g = hue2rgb(p, q, hsl.h); - b = hue2rgb(p, q, hsl.h - 1 / 3); - } - - return { - red: Math.round(r * 255), - green: Math.round(g * 255), - blue: Math.round(b * 255) - }; -} - -function map(value, min1, max1, min2, max2) { - return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); -} \ No newline at end of file diff --git a/examples/libraries/utils.js b/examples/libraries/utils.js index f6f635c73a..fa0f36cbb1 100644 --- a/examples/libraries/utils.js +++ b/examples/libraries/utils.js @@ -179,3 +179,69 @@ pointInExtents = function(point, minPoint, maxPoint) { (point.y >= minPoint.y && point.y <= maxPoint.y) && (point.z >= minPoint.z && point.z <= maxPoint.z); } + +/** + * Converts an HSL color value to RGB. Conversion formula + * adapted from http://en.wikipedia.org/wiki/HSL_color_space. + * Assumes h, s, and l are contained in the set [0, 1] and + * returns r, g, and b in the set [0, 255]. + * + * @param Number h The hue + * @param Number s The saturation + * @param Number l The lightness + * @return Array The RGB representation + */ +hslToRgb = function(hsl, hueOffset) { + var r, g, b; + if (hsl.s == 0) { + r = g = b = hsl.l; // achromatic + } else { + var hue2rgb = function hue2rgb(p, q, t) { + if (t < 0) t += 1; + if (t > 1) t -= 1; + if (t < 1 / 6) return p + (q - p) * 6 * t; + if (t < 1 / 2) return q; + if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; + return p; + } + + var q = hsl.l < 0.5 ? hsl.l * (1 + hsl.s) : hsl.l + hsl.s - hsl.l * hsl.s; + var p = 2 * hsl.l - q; + r = hue2rgb(p, q, hsl.h + 1 / 3); + g = hue2rgb(p, q, hsl.h); + b = hue2rgb(p, q, hsl.h - 1 / 3); + } + + return { + red: Math.round(r * 255), + green: Math.round(g * 255), + blue: Math.round(b * 255) + }; +} + +map = function(value, min1, max1, min2, max2) { + return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); +} + +orientationOf = function(vector) { + var Y_AXIS = { + x: 0, + y: 1, + z: 0 + }; + var X_AXIS = { + x: 1, + y: 0, + z: 0 + }; + + var theta = 0.0; + + var RAD_TO_DEG = 180.0 / Math.PI; + var direction, yaw, pitch; + direction = Vec3.normalize(vector); + yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * RAD_TO_DEG, Y_AXIS); + pitch = Quat.angleAxis(Math.asin(-direction.y) * RAD_TO_DEG, X_AXIS); + return Quat.multiply(yaw, pitch); +} + From 8e2c1a6b170a518923238a9456bc78952644e5bd Mon Sep 17 00:00:00 2001 From: James Pollack Date: Thu, 1 Oct 2015 15:22:45 -0700 Subject: [PATCH 130/161] 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 131/161] 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 132/161] 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 133/161] 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 134/161] 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 135/161] 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 136/161] 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 137/161] 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 138/161] 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 139/161] 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 140/161] 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 141/161] 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 142/161] 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 143/161] 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 144/161] 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 3490e08521360bde1d0f0266f64ddacbab48a410 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 1 Oct 2015 18:42:09 -0700 Subject: [PATCH 145/161] Little improvments on the performance side to get the Stencil pass and the masking of the background under reasonable performances --- .../gpu/src/gpu/DrawUnitQuadTexcoord.slv | 28 +++++++++++++ libraries/gpu/src/gpu/GLBackend.cpp | 39 ++++++++++++------- libraries/gpu/src/gpu/GLBackendState.cpp | 23 +++++++---- libraries/gpu/src/gpu/GLBackendTransform.cpp | 30 ++++++++------ libraries/gpu/src/gpu/StandardShaderLib.cpp | 8 ++++ libraries/gpu/src/gpu/StandardShaderLib.h | 4 ++ .../render-utils/src/RenderDeferredTask.cpp | 21 ++++------ 7 files changed, 108 insertions(+), 45 deletions(-) create mode 100644 libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv diff --git a/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv b/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv new file mode 100644 index 0000000000..60ab0bd7dd --- /dev/null +++ b/libraries/gpu/src/gpu/DrawUnitQuadTexcoord.slv @@ -0,0 +1,28 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// Draw the unit quad [-1,-1 -> 1,1] amd pass along the unit texcoords [0, 0 -> 1, 1]. Not transform used. +// Simply draw a Triangle_strip of 2 triangles, no input buffers or index buffer needed +// +// Created by Sam Gateau on 6/22/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 +// +out vec2 varTexCoord0; + +void main(void) { + const vec4 UNIT_QUAD[4] = vec4[4]( + vec4(-1.0, -1.0, 0.0, 1.0), + vec4(1.0, -1.0, 0.0, 1.0), + vec4(-1.0, 1.0, 0.0, 1.0), + vec4(1.0, 1.0, 0.0, 1.0) + ); + vec4 pos = UNIT_QUAD[gl_VertexID]; + + varTexCoord0 = (pos.xy + 1) * 0.5; + + gl_Position = pos; +} diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 250fc4aaac..b1e63a18bd 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -132,20 +132,26 @@ void GLBackend::renderPassTransfer(Batch& batch) { const size_t numCommands = batch.getCommands().size(); const Batch::Commands::value_type* command = batch.getCommands().data(); const Batch::CommandOffsets::value_type* offset = batch.getCommandOffsets().data(); - - for (auto& cached : batch._buffers._items) { - if (cached._data) { - syncGPUObject(*cached._data); + + { // Sync all the buffers + PROFILE_RANGE("syncGPUBuffer"); + + for (auto& cached : batch._buffers._items) { + if (cached._data) { + syncGPUObject(*cached._data); + } } } - // Reset the transform buffers - _transform._cameras.resize(0); - _transform._cameraOffsets.clear(); - _transform._objects.resize(0); - _transform._objectOffsets.clear(); - for (_commandIndex = 0; _commandIndex < numCommands; ++_commandIndex) { - switch (*command) { + { // Sync all the buffers + PROFILE_RANGE("syncCPUTransform"); + _transform._cameras.resize(0); + _transform._cameraOffsets.clear(); + _transform._objects.resize(0); + _transform._objectOffsets.clear(); + + for (_commandIndex = 0; _commandIndex < numCommands; ++_commandIndex) { + switch (*command) { case Batch::COMMAND_draw: case Batch::COMMAND_drawIndexed: case Batch::COMMAND_drawInstanced: @@ -164,11 +170,16 @@ void GLBackend::renderPassTransfer(Batch& batch) { default: break; + } + command++; + offset++; } - command++; - offset++; } - _transform.transfer(); + + { // Sync the transform buffers + PROFILE_RANGE("syncGPUTransform"); + _transform.transfer(); + } } void GLBackend::renderPassDraw(Batch& batch) { diff --git a/libraries/gpu/src/gpu/GLBackendState.cpp b/libraries/gpu/src/gpu/GLBackendState.cpp index feba6e6853..895d0a0027 100644 --- a/libraries/gpu/src/gpu/GLBackendState.cpp +++ b/libraries/gpu/src/gpu/GLBackendState.cpp @@ -642,8 +642,13 @@ void GLBackend::do_setStateStencil(State::StencilActivation activation, State::S if (activation.isEnabled()) { glEnable(GL_STENCIL_TEST); - glStencilMaskSeparate(GL_FRONT, activation.getWriteMaskFront()); - glStencilMaskSeparate(GL_BACK, activation.getWriteMaskBack()); + + if (activation.getWriteMaskFront() != activation.getWriteMaskBack()) { + glStencilMaskSeparate(GL_FRONT, activation.getWriteMaskFront()); + glStencilMaskSeparate(GL_BACK, activation.getWriteMaskBack()); + } else { + glStencilMask(activation.getWriteMaskFront()); + } static GLenum STENCIL_OPS[] = { GL_KEEP, @@ -655,12 +660,16 @@ void GLBackend::do_setStateStencil(State::StencilActivation activation, State::S GL_INCR, GL_DECR }; - glStencilOpSeparate(GL_FRONT, STENCIL_OPS[frontTest.getFailOp()], STENCIL_OPS[frontTest.getPassOp()], STENCIL_OPS[frontTest.getDepthFailOp()]); - glStencilFuncSeparate(GL_FRONT, GL_COMPARISON_FUNCTIONS[frontTest.getFunction()], frontTest.getReference(), frontTest.getReadMask()); - - glStencilOpSeparate(GL_BACK, STENCIL_OPS[backTest.getFailOp()], STENCIL_OPS[backTest.getPassOp()], STENCIL_OPS[backTest.getDepthFailOp()]); - glStencilFuncSeparate(GL_BACK, GL_COMPARISON_FUNCTIONS[backTest.getFunction()], backTest.getReference(), backTest.getReadMask()); + if (frontTest != backTest) { + glStencilOpSeparate(GL_FRONT, STENCIL_OPS[frontTest.getFailOp()], STENCIL_OPS[frontTest.getPassOp()], STENCIL_OPS[frontTest.getDepthFailOp()]); + glStencilFuncSeparate(GL_FRONT, GL_COMPARISON_FUNCTIONS[frontTest.getFunction()], frontTest.getReference(), frontTest.getReadMask()); + glStencilOpSeparate(GL_BACK, STENCIL_OPS[backTest.getFailOp()], STENCIL_OPS[backTest.getPassOp()], STENCIL_OPS[backTest.getDepthFailOp()]); + glStencilFuncSeparate(GL_BACK, GL_COMPARISON_FUNCTIONS[backTest.getFunction()], backTest.getReference(), backTest.getReadMask()); + } else { + glStencilOp(STENCIL_OPS[frontTest.getFailOp()], STENCIL_OPS[frontTest.getPassOp()], STENCIL_OPS[frontTest.getDepthFailOp()]); + glStencilFunc(GL_COMPARISON_FUNCTIONS[frontTest.getFunction()], frontTest.getReference(), frontTest.getReadMask()); + } } else { glDisable(GL_STENCIL_TEST); } diff --git a/libraries/gpu/src/gpu/GLBackendTransform.cpp b/libraries/gpu/src/gpu/GLBackendTransform.cpp index 4a55155a86..5e16421c6a 100755 --- a/libraries/gpu/src/gpu/GLBackendTransform.cpp +++ b/libraries/gpu/src/gpu/GLBackendTransform.cpp @@ -130,19 +130,27 @@ void GLBackend::TransformStageState::preUpdate(size_t commandIndex, const Stereo void GLBackend::TransformStageState::transfer() const { static QByteArray bufferData; - glBindBuffer(GL_UNIFORM_BUFFER, _cameraBuffer); - bufferData.resize(_cameraUboSize * _cameras.size()); - for (size_t i = 0; i < _cameras.size(); ++i) { - memcpy(bufferData.data() + (_cameraUboSize * i), &_cameras[i], sizeof(TransformCamera)); + if (!_cameras.empty()) { + glBindBuffer(GL_UNIFORM_BUFFER, _cameraBuffer); + bufferData.resize(_cameraUboSize * _cameras.size()); + for (size_t i = 0; i < _cameras.size(); ++i) { + memcpy(bufferData.data() + (_cameraUboSize * i), &_cameras[i], sizeof(TransformCamera)); + } + glBufferData(GL_UNIFORM_BUFFER, bufferData.size(), bufferData.data(), GL_DYNAMIC_DRAW); } - glBufferData(GL_UNIFORM_BUFFER, bufferData.size(), bufferData.data(), GL_DYNAMIC_DRAW); - glBindBuffer(GL_UNIFORM_BUFFER, _objectBuffer); - bufferData.resize(_objectUboSize * _objects.size()); - for (size_t i = 0; i < _objects.size(); ++i) { - memcpy(bufferData.data() + (_objectUboSize * i), &_objects[i], sizeof(TransformObject)); + + if (!_objects.empty()) { + glBindBuffer(GL_UNIFORM_BUFFER, _objectBuffer); + bufferData.resize(_objectUboSize * _objects.size()); + for (size_t i = 0; i < _objects.size(); ++i) { + memcpy(bufferData.data() + (_objectUboSize * i), &_objects[i], sizeof(TransformObject)); + } + glBufferData(GL_UNIFORM_BUFFER, bufferData.size(), bufferData.data(), GL_DYNAMIC_DRAW); + } + + if (!_cameras.empty() || !_objects.empty()) { + glBindBuffer(GL_UNIFORM_BUFFER, 0); } - glBufferData(GL_UNIFORM_BUFFER, bufferData.size(), bufferData.data(), GL_DYNAMIC_DRAW); - glBindBuffer(GL_UNIFORM_BUFFER, 0); CHECK_GL_ERROR(); } diff --git a/libraries/gpu/src/gpu/StandardShaderLib.cpp b/libraries/gpu/src/gpu/StandardShaderLib.cpp index 3f27a7fc35..864bff08c9 100755 --- a/libraries/gpu/src/gpu/StandardShaderLib.cpp +++ b/libraries/gpu/src/gpu/StandardShaderLib.cpp @@ -12,6 +12,7 @@ // #include "StandardShaderLib.h" +#include "DrawUnitQuadTexcoord_vert.h" #include "DrawTransformUnitQuad_vert.h" #include "DrawTexcoordRectTransformUnitQuad_vert.h" #include "DrawViewportQuadTransformTexcoord_vert.h" @@ -21,6 +22,7 @@ using namespace gpu; +ShaderPointer StandardShaderLib::_drawUnitQuadTexcoordVS; ShaderPointer StandardShaderLib::_drawTransformUnitQuadVS; ShaderPointer StandardShaderLib::_drawTexcoordRectTransformUnitQuadVS; ShaderPointer StandardShaderLib::_drawViewportQuadTransformTexcoordVS; @@ -55,6 +57,12 @@ ShaderPointer StandardShaderLib::getProgram(GetShader getVS, GetShader getPS) { } +ShaderPointer StandardShaderLib::getDrawUnitQuadTexcoordVS() { + if (!_drawUnitQuadTexcoordVS) { + _drawUnitQuadTexcoordVS = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(DrawUnitQuadTexcoord_vert))); + } + return _drawUnitQuadTexcoordVS; +} ShaderPointer StandardShaderLib::getDrawTransformUnitQuadVS() { if (!_drawTransformUnitQuadVS) { diff --git a/libraries/gpu/src/gpu/StandardShaderLib.h b/libraries/gpu/src/gpu/StandardShaderLib.h index 2d9c168473..12ea9045c2 100755 --- a/libraries/gpu/src/gpu/StandardShaderLib.h +++ b/libraries/gpu/src/gpu/StandardShaderLib.h @@ -23,6 +23,9 @@ namespace gpu { class StandardShaderLib { public: + // Shader draws the unit quad in the full viewport clipPos = ([(-1,-1),(1,1)]) and the unit texcoord = [(0,0),(1,1)]. + static ShaderPointer getDrawUnitQuadTexcoordVS(); + // Shader draw the unit quad objectPos = ([(-1,-1),(1,1)]) and transform it by the full model transform stack (Model, View, Proj). // A texcoord attribute is also generated texcoord = [(0,0),(1,1)] static ShaderPointer getDrawTransformUnitQuadVS(); @@ -44,6 +47,7 @@ public: protected: + static ShaderPointer _drawUnitQuadTexcoordVS; static ShaderPointer _drawTransformUnitQuadVS; static ShaderPointer _drawTexcoordRectTransformUnitQuadVS; static ShaderPointer _drawViewportQuadTransformTexcoordVS; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 504070963d..983c2d44ba 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -37,15 +37,19 @@ void SetupDeferred::run(const SceneContextPointer& sceneContext, const RenderCon RenderArgs* args = renderContext->args; gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { + auto primaryFboStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); auto primaryFbo = DependencyManager::get()->getPrimaryFramebufferDepthColor(); batch.enableStereo(false); - batch.setFramebuffer(nullptr); - batch.setFramebuffer(primaryFbo); - batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); + batch.setFramebuffer(primaryFboStencil); + batch.clearFramebuffer( + gpu::Framebuffer::BUFFER_STENCIL, + vec4(vec3(0), 1), 1.0, 0.0, true); + + batch.setFramebuffer(primaryFbo); batch.clearFramebuffer( gpu::Framebuffer::BUFFER_COLOR0 | gpu::Framebuffer::BUFFER_DEPTH, @@ -68,7 +72,6 @@ void ResolveDeferred::run(const SceneContextPointer& sceneContext, const RenderC RenderDeferredTask::RenderDeferredTask() : Task() { _jobs.push_back(Job(new SetupDeferred::JobModel("SetupFramebuffer"))); - // _jobs.push_back(Job(new DrawBackground::JobModel("DrawBackground"))); _jobs.push_back(Job(new PrepareDeferred::JobModel("PrepareDeferred"))); _jobs.push_back(Job(new FetchItems::JobModel("FetchOpaque", @@ -302,7 +305,7 @@ gpu::PipelinePointer DrawStencilDeferred::_opaquePipeline; const gpu::PipelinePointer& DrawStencilDeferred::getOpaquePipeline() { if (!_opaquePipeline) { const gpu::int8 STENCIL_OPAQUE = 1; - auto vs = gpu::StandardShaderLib::getDrawViewportQuadTransformTexcoordVS(); + auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(drawOpaqueStencil_frag))); auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); @@ -329,7 +332,6 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren args->_batch = &batch; auto primaryFboColorDepthStencil = DependencyManager::get()->getPrimaryFramebufferStencilColor(); - auto primaryFboFull = DependencyManager::get()->getPrimaryFramebuffer(); auto primaryDepth = DependencyManager::get()->getPrimaryDepthTexture(); batch.enableStereo(false); @@ -337,11 +339,6 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren batch.setFramebuffer(primaryFboColorDepthStencil); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); - batch.clearStencilFramebuffer(0, true); - - - Transform modelMat; - batch.setModelTransform(modelMat); batch.setPipeline(getOpaquePipeline()); batch.setResourceTexture(0, primaryDepth); @@ -349,8 +346,6 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren batch.draw(gpu::TRIANGLE_STRIP, 4); batch.setResourceTexture(0, nullptr); - batch.setFramebuffer(primaryFboFull); - }); args->_batch = nullptr; } From d0e079ee9dd48e82c74e2d36b86701cb50377cf5 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 1 Oct 2015 18:46:32 -0700 Subject: [PATCH 146/161] 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 147/161] 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 148/161] 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 690620d74d7889f831a078f18c26f81b7958d935 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 1 Oct 2015 19:23:32 -0700 Subject: [PATCH 149/161] Cleaning code --- libraries/gpu/src/gpu/GLBackendTexture.cpp | 7 ++----- libraries/model/src/model/Skybox.cpp | 2 +- libraries/render-utils/src/Environment.cpp | 2 -- libraries/render-utils/src/RenderDeferredTask.cpp | 1 - libraries/render-utils/src/drawOpaqueStencil.slf | 10 ++-------- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/libraries/gpu/src/gpu/GLBackendTexture.cpp b/libraries/gpu/src/gpu/GLBackendTexture.cpp index 044204934c..ee5e1d3bc6 100755 --- a/libraries/gpu/src/gpu/GLBackendTexture.cpp +++ b/libraries/gpu/src/gpu/GLBackendTexture.cpp @@ -360,11 +360,8 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) { if (bytes && texture.isAutogenerateMips()) { glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - }/* else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - }*/ - + } + object->_target = GL_TEXTURE_2D; syncSampler(texture.getSampler(), texture.getType(), object); diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index e516fae583..21b40a54c8 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -129,7 +129,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.draw(gpu::TRIANGLE_STRIP, 4); - // batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr); + batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr); } diff --git a/libraries/render-utils/src/Environment.cpp b/libraries/render-utils/src/Environment.cpp index acb149a3cc..b26d402fa3 100644 --- a/libraries/render-utils/src/Environment.cpp +++ b/libraries/render-utils/src/Environment.cpp @@ -62,8 +62,6 @@ void Environment::setupAtmosphereProgram(const char* vertSource, const char* fra auto state = std::make_shared(); state->setCullMode(gpu::State::CULL_NONE); - // state->setDepthTest(false); - // state->setDepthTest(true, false, gpu::LESS_EQUAL); state->setStencilTest(true, 0xFF, gpu::State::StencilTest(0, 0xFF, gpu::EQUAL, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP, gpu::State::STENCIL_OP_KEEP)); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 983c2d44ba..0f79dc8b8d 100755 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -314,7 +314,6 @@ const gpu::PipelinePointer& DrawStencilDeferred::getOpaquePipeline() { auto state = std::make_shared(); state->setStencilTest(true, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE, gpu::State::STENCIL_OP_REPLACE)); - // state->setStencilTest(false, 0xFF, gpu::State::StencilTest(STENCIL_OPAQUE, 0xFF, gpu::ALWAYS, gpu::State::STENCIL_OP_INCR, gpu::State::STENCIL_OP_INCR, gpu::State::STENCIL_OP_INCR)); state->setColorWriteMask(0); _opaquePipeline.reset(gpu::Pipeline::create(program, state)); diff --git a/libraries/render-utils/src/drawOpaqueStencil.slf b/libraries/render-utils/src/drawOpaqueStencil.slf index 883154c624..14feda21e9 100644 --- a/libraries/render-utils/src/drawOpaqueStencil.slf +++ b/libraries/render-utils/src/drawOpaqueStencil.slf @@ -13,18 +13,12 @@ // in vec2 varTexCoord0; -out vec4 outFragColor; uniform sampler2D depthTexture; void main(void) { - // outFragColor = vec4(varTexCoord0, 0.0, 1.0); - - float depth = texture(depthTexture, varTexCoord0.xy).r; - outFragColor = vec4(1.0, 0.0, 0.0, 1.0); - if (depth < 1.0) { - outFragColor = vec4(0.0, 1.0, 0.0, 1.0); - } else { + float depth = texture(depthTexture, varTexCoord0.xy).r; + if (depth >= 1.0) { discard; } } From aa8979570c56b4bcafc393af4c3c52d32e90ff2d Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 2 Oct 2015 00:05:15 -0700 Subject: [PATCH 150/161] Working on 2D overlay mouse interaction --- examples/tests/dot.png | Bin 0 -> 8081 bytes examples/tests/overlayMouseTrackingTest.js | 46 ++++++++++++++++++ interface/src/Application.cpp | 31 ++++++++++-- interface/src/ui/overlays/Overlays.cpp | 17 +++++-- interface/src/ui/overlays/Overlays.h | 4 ++ .../render-utils/src/OffscreenQmlSurface.cpp | 14 ++++-- .../render-utils/src/OffscreenQmlSurface.h | 1 + 7 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 examples/tests/dot.png create mode 100644 examples/tests/overlayMouseTrackingTest.js diff --git a/examples/tests/dot.png b/examples/tests/dot.png new file mode 100644 index 0000000000000000000000000000000000000000..4ccfdc80dfbe24bd89447f2dbc3f045f0d01395b GIT binary patch literal 8081 zcmV;CA8z1@P){%BA*2!>1tj=hLW+doTS?WWZh#~PZXkpJ7Z=wyzJVLtAdGEcY{y{P$nxr8Th>}{ ztseW(?m2rNGkyP<)7suvcTdmRvyyy&Rb4Zur>AG;_v!Did!9$||G900c?t9-(5vTn z!T1rFydEm2YTr(ViBr7;v$dz8w+B|Fuu{MZ;8FpX0q09t2z2-k?5;VG@RLbUwfrt|iR04^XY9MQn zHnLTe)q!71cqoR4JK(8HpgMO)*M56d0DcbE#PEB-&A@9UL=hx?5cPoQ0y>*1(pMCL zhbQIn*(PkN%~Xc80!WAiOi6eg`1careJSjl{n5>>owk5C!I?3!Ou*C>jE%wYFboaNOxw0) z%YhUq1Cv=wr?O2;3F`&?uQ9mqbnVMeE5H)O^KgrRj|jL4i26V-glHa3bqWFf{qXwN z!@6~Fbk%HR}l`CEOjs zKMugNC(&iOc3J?w8{$>)E&+cjVO19-iy&S=<~@Xfl`G-4+u){~VC~vwFRPgiSSx^G z=5l?0>sDC59)9}M41St2#Wd_B>%Z4axMK}GaWZ}AvQr9p5IR$MZv>x}a8WNLOCj!8 z1zxKqM~{g5un!f~e7>#v8~Z--lMfezy=ClmzC9%M+_B!MTNgnRFW zhaW~J31h$^Xw;@be`FOrf0A7coC3gGVR-`o0KBaml5-&Lg$(RXH^E>01-#)6(<_96 z2!)eZhYHhrIkUVA`rf_p&2Pf}_d}z>C~z=q0svnEK0g2xC)3|24RA9Y-yXqVMNnD_ z@fm;+0^a&o`26SLHLuAEhp0y{7oxP#dW$p=S6{tvAAIXu@Z%qoG#U&8M?nfW0DNKq z?m1b0KPiBpgG*z$N5bj_z}YkhPb*fym%apVc}tkmAUr%5h1L!QoB2aS@Z~SVv(GXG z?1Q9|4aDx9f)B0D#%FVCa}IbA-Xr1bF?5{=@jQUuUikE<;ZvW2?ryikpnV}))iv9G z*#+B{uhPR0!$1Es967>aU>GE@JB4?yfv4xv|8oZTY3S{SzXv|l3+ed~bqJB2zy8a= zz=anUSE>tqD+*TI$lF#(c=m;D^?PC>>z~)Jrwr_Yqze~tl&r)VXsl2>2g~uL)fBGkq$w~HtJeD!I zZyeq`7gxjD4tNW!mhe*nXI=nNKfrnCWvad5hGKxAI5d^tj()kwd9kgWt&t=N96Shj z-U%gep??{~-9luiJm3B{EM9CM0T%&bOHfSN zvjOQ+v}-hNTc%Q@k@@A(M;VopeIS8B0XMCJ{q17XHo%+Vtr6VQ0UgUA?i2!Uy%oOl zmFzlko^!#Um#6BYWo@J7B7pV&+XmRzC+m6l-w*fQ$3&X4yLmPp!*5*%FSLV8TL2Hj z+kyMKKrDl(6h-ji4`=7L>XzMXRc6)!`G9>5rxn0HrP=`7)UJnfwS417_|~_m)M~r} zNt%V}YX{(^*|M26;LUJj1P^vY=Q4=mIEK%CE(2@>5u#StDN<4Bu5G#2pG&}MUI8}y z`3H*ds0(E&Xd2@#isfWQ4)_`nBdI@T95%{*{J zGt1h5pDe&WmAXLN23~sD-o8Cka<$43q!PAO;QHBI5NR3kAp8dKSP7Oc7b5F(Z@(Qr z`N@3cna)MtMQ(xbu z;1Ctt22!Db)%5Yl;h~2(l%@=4d-k!_@Rg#h3IpB@9~SV{vxH!Y5b)a9!uP(HJz-Hq zeXjhu0&JG^jp{=NSgH;aPN;fqgDx}wfd^pICSFNXIRT9bu3ZJs6ya3}@L={t<5T@m zS{6lu#f!5W-RGQB99l?zD|x_0_OTq>2|YhTNrz6epOEzeYG5ty#+xz;Tjw(}J1 z$}?4&r(k`Vo>U#<<8aqqlq(g6(o_QX3}lZG2U#%SLHIK8@#Rq@dZP&bZ1uX5Ue*RvEmzaL0hSH0o^OU?UBM=3GjGQZ`0?G<#8Nw-g)qy?@Yf%5E4p50JjsmtKo%0cPZFh&!uX8RP0i$4$~~-1KbSN$$7N+p=2aj2VqmM3$QAy=eg>z)n}Fsi6CZO zdRZNsPt~SUUFr?#rfeW>;8i&_U9*Px&>_xB(|B*1-Z%(v9Ds*i44r@np&$6ug+fGK zYGAc??evC1L4>NhNLg27vO#x2Hbb$V=K>r8+8ku%^|NLJ(7~(xB$>|d?S-(Nv37ag`hKvVD;+k4ZcRBxKj10 ztDG<27S8h;lTEQUaCv}32U&RoEFWmsGMjqUv{Zs~&t<`$Jshmp8;O*E3H)|2;Q8=D z2}_ogN|}0ZyDfw3a<0$mCNLi~vuu&Z-~(#@ZWXXz#s}C3&zIk5_+jh6&pQvXZy!se zsI)&xZXSdy2jJHxODkXjpX?Vxc1Mw5+RtR9VzAc2? zLUfV-*9S6G)ghreNwSynmM&${@G!$kk|gj^;Eyou1i*uEjfCG=6vx@~RBw9IG~7`2 zx}dr8eD&&6Us)ZLSwkP1@ z=Cjo&0G9B+2pavRQi;C4?7dv`w8(_%0_-Xq0@9UlQ@ROD-?lH5>+9IUunoK`G~0mZ z^{+nFnxM^oI7zZkQ}pz(AWb=(Bz^PYcYyEf?wJ92F#C?ldl$xWNeBVgT$6R^s{hS{ z<_f8`K-1i-v6Lfdi|%vM9QnyUGQ3+bMkqDzQIRm%6{ z0}Q-H!h(e=Jl}A`ba=Ko*q3iBXXg8$hcu*+P#yx;wOj`U;r*~{-j}DK>C04}d7i8{ zg8B1dc$h_TTsqijym>R6wdVNC5(Z!izuzH5qo-6VaqhXWY}rh}w*J!vEo7N5-`AM( zrmlJY7;NF$2RSc9+wK8}p6llQwkcV^;MCK@f+XQUqY(+XjqKJgpaH%+yR-D4=f`mg zAz)x2T)j4HwX7{H+sfvJXFcBpZVShG3U=kWfQR(OdO6#T2NzUR;oaSo%4NEvD4j~v zw_pRj8m>yAuTO>Nl`CiVy|aO)=P7vR)CN|)72yiO=DbVICUl$1O=auO&Qos@xGr_t zpqe9SJu>L|-Q6Gr{ZSNG)AaR&&^eHO&utp8gc}9O-Z&O?cEUv$%~Y@tnr)Q}i!aVrGDCEz*~*%uWV5UbvJS;ncSwJ%*OLcRhoRQX3&*x)3ba0Ttz+if zLbDE4&#zQK2zuif0g~)Hp3{I|gsvLg&=nf+4P1UA)^*oo7 z%@7^Z2yE(ZC4B3!^v2)|_eqjHbvZGSP1BSpis*@BSxJ)L0`7n&;2K;hp}V(K%A9=m z*~I~yeX1)@CUkwdO})OxV44XvZ)!`vWxAqW zpj{2Y7J6NIE{LvCbn`>02$7{GgUAEy zE32D=Y_4Ooye>emr>J6mDM>OX*6UEKo#=GPoT{7~$1}e@k~c#3_2FhCv4v*kVjXBtV978u(C6XQXxdl(xuY}U<;)-SSApa=UZPN8SCZqx&qURhG!S(YBdXaQ&U+| z_r61tf}!@cqa%Y|D*2(gE{@n5gPAOFiJ~kD15pO}ex=~cI^#H=5uRnvY6|9T9RJd8Nzz*1^N*hG;w+Yh+$<}}C`(T@QmCFmwwXDugdmpU-&Qq(eoC~gQzJ_2ko4Rd)$H%jf ztQ4!3*&2sW#d=tFsaMr+&MPQ7Y*VqiuL2Znrc$=OC6Jv5F9wKRfNg!EE!2kOnf2)N zu0Gbao(|77f>xHMFfx)2p42hv>+AD2sHWNAy40)Y6(Ie$zAtK-?bz}l8+maQA))6* z=qkzPA4WwAuzIlFr&6C%%{<%GRH!e^>rOLUw{nyXs`{NISx8P2w-fbk=7naLl3nU` zfz|iLGb*03Z-GjVn!am5e@VbR2?)KA3D}&^`>p4j%GAs2PIZBI_0=X^9hl0m*Rz3? z9+G{4&1tJ}b;vrv5U52!JCbPnH-*0Gn+>YK&wrl1)ZNu(SC|W~ZR!fez6RlfU~4dD zz0Tv*R13s?c!-wIKN8q~aVBWl$&d?oY z!VOWmtr3`m98Dz5-1BGbyc)`cXsZ$a%J{rn=LGx zs&XmToVS5hzxB{(gK4f)t7XaDb_n1iBj~*TSAnth!LGqxi%NB+w0RtLm?!~90TSC_ zN~MVj*t7{QxFGvvk{O;|>)G;M2W4*Gb;;6JN41(o9DToRQ=3yw&^{H1j+|YmM=m87 zyi%2ylI(bDYoT09;Yh3lb|opZ|Lz+Z$w1GWmk$_DY_YcR?CW=RusQ(sTiwdj!?F#m zEozwadcPY2*EYDafo-EYg8-)~BKspYN+s9}r1d0;oGa<@rl#QKm$RD^XP=#&PT3T# zlIsvz_t;)KEP6C^Das1u+43^1F~ZfTTc=x;T3?=0MrIy zPp#3o&c^#(sWuvkfbGzHCM$*KtM&T%2oasIBY7K}n8;2``unr6-P=38LHz*q zTWG3YQz_=Dg{nsniTXX!5J%Vm>ri#DdbB74x7E3b1Ef`Bq<5ldK_>BFV-53 zn@?yFM$7P~N+lcYbaqbvDRW21Ot`A7>%?De)9mA5=0o^-4bOHAHVf%{L*Tl=hJ@!f zL#|CfOZVb&z$t7KQbzS8p+h}c=?e|M{4|Bh$qaa@l=abFT^VfkMOxDV`u$S9L73rO zk19nWyDSf`@4m0^vZM{TzI?V&9XzVd``iMy9S1C$@w(b*(9wJiqLs=|NNOOYM!D+I zl~O62M$vTA>(wDD=i0!ALbic6VY!s6FUz~A;eu*Qx^hER?DKnbSrf4AY5t){37`u$ z)*!7^t5JV{e`_#{v^=E>-H|#((-A)P+UE6rw!yVQZsojJZL^&>5sHe*SYD}CC9wG- zm;#6ZE`f0gPfwQ1skh>yutOB)Th|6pSG}I}h~S#{t>as6Yh1Sd^QDsjT}ny0Qjr4I zt2V5^eD<@-)YMuD2(zM-0o%3QRItzCu6?wr*cYPB$7l3%t&W^+VYtWu%g3NOtyHU| zQbrLxqIO#!<~@>18I{c^=8J5osCvy7?rZhFa(N20DK$^Md1{;sWwz?;W|}OQ5s*ai z*a-?g2EUjO^~uS}jy`oCI8VjCoysd;v;o-QhC141u0B|ZX%(AgmHDn#xl|dV*ifhz zK9l8g3jFF)IHq>x_?|UCzw`LS$O^`JUQ9AifubK zTcx)vT(=W!XhSWk)`IFC8yNveIxB?UMvojR2G_O2t%6m~(j8j_sB5s5 z2U*WIx9{4YP{<(-zo@@~(IZC^;DMEJI2Z6bXhc~j;pUf!LqkRp@OiLZq0iM9`a*9=Ug&93 zt8haaw_e8Q%jW#V=qQzPIhIo1A;7p2;{goNfd7%EsXVfOe?Hv6aFV-@OR=tyT{LXx zh2xMg?Sg9q-Ku{=de`;V=+?xH^K3j8NvYrNccjMBVeD#whwd& zP?w_3ZRSA@Rd3No@9>)h_V3t{2q9h^wwxLT1HK$y7Vw3U0|zLNkNaC&QMf+XuKw4i z;7~RD6kQ}d`#}4E74bukKacF$L$y+gQz<{X4va6x&NMGzfHC+RA;hlz+qWlDf84Yc z1=ep%(CGeQJtBLqmyxd)B~D^Z4Zgz8)&6lpmd%oQ#j|+2h`+ zyqz!70LHY%FTN;KDXVq((>!(%02p8m{5$Y}hj;8qYn6&~ znCRAX`;1Fg`rY_@P5WNcmS+W^bhAS`c6W0UwiTI=N@lrc|nj z<_fgD;DZhUX;X2Ydh@Pe*|rhV?^>PJB4p2eeQJt*gM*0>;+bLidk3ZyEEw`JA4 ze`S1J9N4bik#e-QV8}(_`hXV+(RnHkh3iwV>v%)`qvcB}+5POZX__RJhLpFi%Nbbd z77Q3*4g4PocOD%YV*KDid!eF`&AfI%c7YBF(X9aWfiCI;i$4!;-AZL_ERs@w;0oC3 zCUl||0^D5Tb|J(w`<{I^Io==pc6PQ0XtO-Xtq!AK$;9BRh8j+_@Tl z5bmVR3IiU1T0_cP(3NGT4=6vPoQTA@! zm?Ffl1$@fCak~`;3~&YPM9SZ-O-?4eo_Hcn^>1+$JP5C~8mfIE+U$c}A>O6VRumj^ z+{W_S#00yZcp^#DbYCLn+tk0P6t$KB0}Q~!0^T(>GQzIM9+NV)Tn=potj}TQ^4UP1 z?ded+zP0Fwdb!NdqmQOZy*?(STz3WRaXZX!EdvG^fFGvtvB}|KvG+l@?uY zE0Y(pTj_Uw+ib-gK1v!5c5T>@G^VC%Ncr0X&6mhpwOIiMSOZ^^@Y%7UA@)4}I94Sq zYX!V-S%~v}1FleInspZ4SKGYB8kGt|>({4KAp7HSjkAJ~uWr z#IA=QmZ|y{bE}pI)|H>9V12OV0u~xEisT1aZG4=a4?dVw$Hr<>%6EiZXAZHp00tO< zI|TgkKtd<7WiE$#CJrg)O+UZ zUKgLSb}d4Eh$S!i%H`EzyRZS%fPMe!X-kbpYs=DB%_nZ{)qLA{PtKj*$ z_Wel#46qq45b%${?{qI&lALq%&2jItWivtK0Sj#uuIH|l>8dUYITWgvMmKHZ;Lm=R zG^$mJlwX{J&##5@$?*G01FUQ_+!966oia_AFTDJ6&U*8kDb1TVJD4GG_0h8#wr2y` z1wBof+P9DW4?K{T_w0#;5F3#4BXcp3^4UoT4DbZ>%!5x0AwCn8O7R)jToW(8;RZ_c z=eG{k2G?~_!`3g`Am>4MD7dnBb|8Rg-Arv0hy-%eG0yQviez{ofd$VZHFaw_&8DY$E4|*9SavW7G8U8 zY2mfk(s|A~e!xDsYJg>iXjfmH2f5Lp{L)K|KKUf$&peYPQ&X{sqOGLqmw|t6_1^7V z*l7h=+1(Hiz)cd~D};Ebl(MVm!V8oB)vM#aRjcS(xss^6J0Gs?y0h!UXE~ud85?7A z%N8cLY~k3ZO^y1P zl1u0t7>IgStf1@s^XWMA%oFbx`R*Ed0Lxm9+P-~MckiaWZ5xxDHz!kj_eMx5L==t5 zG<`6F?>-Mdc{c=JqB}Kq+5^^YCv=zLdf<%+@h0FZDP;^GN~N^x+;e5;`RB)7=bcAs z$r4Hn77#C3K-AX{SieWrNU}!dX%F*SU)&EEEu>&?TTDvani9V6+5BfFqZ| f!B>+qL+$?o)1h`1cDvd;00000NkvXXu0mjfzZKxl literal 0 HcmV?d00001 diff --git a/examples/tests/overlayMouseTrackingTest.js b/examples/tests/overlayMouseTrackingTest.js new file mode 100644 index 0000000000..d18fcfb599 --- /dev/null +++ b/examples/tests/overlayMouseTrackingTest.js @@ -0,0 +1,46 @@ +MouseTracker = function() { + this.WIDTH = 60; + this.HEIGHT = 60; + + this.overlay = Overlays.addOverlay("image", { + imageURL: Script.resolvePath("dot.png"), + width: this.HEIGHT, + height: this.WIDTH, + x: 100, + y: 100, + visible: true + }); + + var that = this; + Script.scriptEnding.connect(function() { + that.onCleanup(); + }); + + Controller.mousePressEvent.connect(function(event) { + that.onMousePress(event); + }); + + Controller.mouseMoveEvent.connect(function(event) { + that.onMouseMove(event); + }); +} + +MouseTracker.prototype.onCleanup = function() { + Overlays.deleteOverlay(this.overlay); +} + +MouseTracker.prototype.onMousePress = function(event) { +} + +MouseTracker.prototype.onMouseMove = function(event) { + var width = Overlays.width(); + var height = Overlays.height(); + var x = Math.max(event.x, 0); + x = Math.min(x, width); + var y = Math.max(event.y, 0); + y = Math.min(y, height); + Overlays.editOverlay(this.overlay, {x: x - this.WIDTH / 2.0, y: y - this.HEIGHT / 2.0}); +} + + +new MouseTracker(); \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2a8f7cf8b5..5f127988e9 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1849,8 +1849,16 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { _entities.mouseMoveEvent(event, deviceID); + { + auto offscreenUi = DependencyManager::get(); + QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget); + QMouseEvent mappedEvent(event->type(), + transformedPos, + event->screenPos(), event->button(), + event->buttons(), event->modifiers()); + _controllerScriptingInterface.emitMouseMoveEvent(&mappedEvent, deviceID); // send events to any registered scripts + } - _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { return; @@ -1865,12 +1873,19 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { // Inhibit the menu if the user is using alt-mouse dragging _altPressed = false; - if (!_aboutToQuit) { _entities.mousePressEvent(event, deviceID); } - _controllerScriptingInterface.emitMousePressEvent(event); // send events to any registered scripts + { + auto offscreenUi = DependencyManager::get(); + QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget); + QMouseEvent mappedEvent(event->type(), + transformedPos, + event->screenPos(), event->button(), + event->buttons(), event->modifiers()); + _controllerScriptingInterface.emitMousePressEvent(&mappedEvent); // send events to any registered scripts + } // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1921,7 +1936,15 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { _entities.mouseReleaseEvent(event, deviceID); } - _controllerScriptingInterface.emitMouseReleaseEvent(event); // send events to any registered scripts + { + auto offscreenUi = DependencyManager::get(); + QPointF transformedPos = offscreenUi->mapToVirtualScreen(event->localPos(), _glWidget); + QMouseEvent mappedEvent(event->type(), + transformedPos, + event->screenPos(), event->button(), + event->buttons(), event->modifiers()); + _controllerScriptingInterface.emitMouseReleaseEvent(&mappedEvent); // send events to any registered scripts + } // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index bc786f3f4c..db3360cbbf 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -10,7 +10,7 @@ #include "Overlays.h" -#include +#include #include @@ -31,6 +31,7 @@ #include "TextOverlay.h" #include "Text3DOverlay.h" #include "Web3DOverlay.h" +#include Overlays::Overlays() : _nextOverlayID(1) { @@ -331,10 +332,6 @@ void Overlays::setParentPanel(unsigned int childId, unsigned int panelId) { unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) { glm::vec2 pointCopy = point; - if (qApp->isHMDMode()) { - pointCopy = qApp->getApplicationCompositor().screenToOverlay(point); - } - QReadLocker lock(&_lock); if (!_enabled) { return 0; @@ -607,3 +604,13 @@ void Overlays::deletePanel(unsigned int panelId) { bool Overlays::isAddedOverlay(unsigned int id) { return _overlaysHUD.contains(id) || _overlaysWorld.contains(id); } + +float Overlays::width() const { + auto offscreenUi = DependencyManager::get(); + return offscreenUi->getWindow()->size().width(); +} + +float Overlays::height() const { + auto offscreenUi = DependencyManager::get(); + return offscreenUi->getWindow()->size().height(); +} \ No newline at end of file diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index 5bd8098150..62f00b8989 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -113,6 +113,10 @@ public slots: /// overlay; in meters if it is a 3D text overlay QSizeF textSize(unsigned int id, const QString& text) const; + // Return the size of the virtual screen + float width() const; + float height() const; + /// adds a panel that has already been created unsigned int addPanel(OverlayPanel::Pointer panel); diff --git a/libraries/render-utils/src/OffscreenQmlSurface.cpp b/libraries/render-utils/src/OffscreenQmlSurface.cpp index 9923849aab..3f940d8569 100644 --- a/libraries/render-utils/src/OffscreenQmlSurface.cpp +++ b/libraries/render-utils/src/OffscreenQmlSurface.cpp @@ -496,6 +496,13 @@ QPointF OffscreenQmlSurface::mapWindowToUi(const QPointF& sourcePosition, QObjec return QPointF(offscreenPosition.x, offscreenPosition.y); } +QPointF OffscreenQmlSurface::mapToVirtualScreen(const QPointF& originalPoint, QObject* originalWidget) { + QPointF transformedPos = _mouseTranslator(originalPoint); + transformedPos = mapWindowToUi(transformedPos, originalWidget); + return transformedPos; +} + + /////////////////////////////////////////////////////// // // Event handling customization @@ -541,8 +548,9 @@ bool OffscreenQmlSurface::eventFilter(QObject* originalDestination, QEvent* even case QEvent::Wheel: { QWheelEvent* wheelEvent = static_cast(event); + QPointF transformedPos = mapToVirtualScreen(wheelEvent->pos(), originalDestination); QWheelEvent mappedEvent( - mapWindowToUi(wheelEvent->pos(), originalDestination), + transformedPos, wheelEvent->delta(), wheelEvent->buttons(), wheelEvent->modifiers(), wheelEvent->orientation()); mappedEvent.ignore(); @@ -558,9 +566,7 @@ bool OffscreenQmlSurface::eventFilter(QObject* originalDestination, QEvent* even case QEvent::MouseButtonRelease: case QEvent::MouseMove: { QMouseEvent* mouseEvent = static_cast(event); - QPointF originalPos = mouseEvent->localPos(); - QPointF transformedPos = _mouseTranslator(originalPos); - transformedPos = mapWindowToUi(transformedPos, originalDestination); + QPointF transformedPos = mapToVirtualScreen(mouseEvent->localPos(), originalDestination); QMouseEvent mappedEvent(mouseEvent->type(), transformedPos, mouseEvent->screenPos(), mouseEvent->button(), diff --git a/libraries/render-utils/src/OffscreenQmlSurface.h b/libraries/render-utils/src/OffscreenQmlSurface.h index 13e467bccd..01dd2b88f9 100644 --- a/libraries/render-utils/src/OffscreenQmlSurface.h +++ b/libraries/render-utils/src/OffscreenQmlSurface.h @@ -61,6 +61,7 @@ public: QQuickWindow* getWindow(); QObject* getEventHandler(); + QPointF mapToVirtualScreen(const QPointF& originalPoint, QObject* originalWidget); virtual bool eventFilter(QObject* originalDestination, QEvent* event); signals: From 98fe06be578b5c29c72654bab8369457dee1c944 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 2 Oct 2015 09:30:18 -0700 Subject: [PATCH 151/161] cleanup sixense/hydra calibration --- .../src/input-plugins/SixenseManager.cpp | 114 +++++------------- .../src/input-plugins/SixenseManager.h | 4 +- 2 files changed, 32 insertions(+), 86 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp index 9bc3a71fd5..dbacc23f26 100644 --- a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp +++ b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp @@ -13,11 +13,12 @@ #include -#include +#include #include +#include +#include #include "NumericalConstants.h" -#include #include "SixenseManager.h" #include "UserActivityLogger.h" @@ -38,14 +39,12 @@ const unsigned int RIGHT_MASK = 1U << 1; const int CALIBRATION_STATE_IDLE = 0; const int CALIBRATION_STATE_X = 1; -const int CALIBRATION_STATE_Y = 2; -const int CALIBRATION_STATE_Z = 3; -const int CALIBRATION_STATE_COMPLETE = 4; +const int CALIBRATION_STATE_COMPLETE = 2; -// default (expected) location of neck in sixense space -const float NECK_X = 0.25f; // meters -const float NECK_Y = 0.3f; // meters -const float NECK_Z = 0.3f; // meters +// default (expected) location of neck in sixense space when sitting +const float NECK_X = -0.25f; // meters +const float NECK_Y = -0.35f; // meters +const float NECK_Z = -0.3f; // meters const float CONTROLLER_THRESHOLD = 0.35f; @@ -92,9 +91,9 @@ bool SixenseManager::isSupported() const { void SixenseManager::activate() { #ifdef HAVE_SIXENSE _calibrationState = CALIBRATION_STATE_IDLE; - // By default we assume the _neckBase (in orb frame) is as high above the orb + // By default we assume the _avatarPosition (in orb frame) is as high above the orb // as the "torso" is below it. - _neckBase = glm::vec3(NECK_X, -NECK_Y, NECK_Z); + _avatarPosition = glm::vec3(NECK_X, NECK_Y, NECK_Z); CONTAINER->addMenu(MENU_PATH); CONTAINER->addMenuItem(MENU_PATH, TOGGLE_SMOOTH, @@ -258,11 +257,13 @@ void SixenseManager::update(float deltaTime, bool jointsCaptured) { #ifdef HAVE_SIXENSE // the calibration sequence is: -// (1) press BUTTON_FWD on both hands -// (2) reach arm straight out to the side (X) -// (3) lift arms staight up above head (Y) -// (4) move arms a bit forward (Z) -// (5) release BUTTON_FWD on both hands +// (1) reach arm straight out to the sides (xAxis is to the left) +// (2) press BUTTON_FWD on both hands and hold for one second +// (3) release both BUTTON_FWDs +// +// The code will: +// (4) assume that the orb is on a flat surface (yAxis is UP) +// (5) compute the forward direction (zAxis = xAxis cross yAxis) const float MINIMUM_ARM_REACH = 0.3f; // meters const float MAXIMUM_NOISE_LEVEL = 0.05f; // meters @@ -279,21 +280,16 @@ void SixenseManager::updateCalibration(void* controllersX) { return; } switch (_calibrationState) { - case CALIBRATION_STATE_Y: - case CALIBRATION_STATE_Z: case CALIBRATION_STATE_COMPLETE: { // compute calibration results - // ATM we only handle the case where the XAxis has been measured, and we assume the rest - // (i.e. that the orb is on a level surface) - // TODO: handle COMPLETE state where all three axes have been defined. This would allow us - // to also handle the case where left and right controllers have been reversed. - _neckBase = 0.5f * (_reachLeft + _reachRight); // neck is midway between right and left reaches + _avatarPosition = - 0.5f * (_reachLeft + _reachRight); // neck is midway between right and left hands glm::vec3 xAxis = glm::normalize(_reachRight - _reachLeft); - glm::vec3 yAxis(0.0f, 1.0f, 0.0f); - glm::vec3 zAxis = glm::normalize(glm::cross(xAxis, yAxis)); - xAxis = glm::normalize(glm::cross(yAxis, zAxis)); - _orbRotation = glm::inverse(glm::quat_cast(glm::mat3(xAxis, yAxis, zAxis))); + glm::vec3 zAxis = glm::normalize(glm::cross(xAxis, Vectors::UNIT_Y)); + xAxis = glm::normalize(glm::cross(Vectors::UNIT_Y, zAxis)); + _avatarRotation = glm::inverse(glm::quat_cast(glm::mat3(xAxis, Vectors::UNIT_Y, zAxis))); + const float Y_OFFSET_CALIBRATED_HANDS_TO_AVATAR = -0.3f; + _avatarPosition.y += Y_OFFSET_CALIBRATED_HANDS_TO_AVATAR; qCDebug(inputplugins, "succeess: sixense calibration"); } break; @@ -349,54 +345,10 @@ void SixenseManager::updateCalibration(void* controllersX) { _lockExpiry = now + LOCK_DURATION; _lastDistance = 0.0f; _reachUp = 0.5f * (_reachLeft + _reachRight); - _calibrationState = CALIBRATION_STATE_Y; + _calibrationState = CALIBRATION_STATE_COMPLETE; qCDebug(inputplugins, "success: sixense calibration: left"); } } - else if (_calibrationState == CALIBRATION_STATE_Y) { - glm::vec3 torso = 0.5f * (_reachLeft + _reachRight); - glm::vec3 averagePosition = 0.5f * (_averageLeft + _averageRight); - float distance = (averagePosition - torso).y; - if (fabsf(distance) > fabsf(_lastDistance) + MAXIMUM_NOISE_LEVEL) { - // distance is increasing so acquire the data and push the expiry out - _reachUp = averagePosition; - _lastDistance = distance; - _lockExpiry = now + LOCK_DURATION; - } else if (now > _lockExpiry) { - if (_lastDistance > MINIMUM_ARM_REACH) { - // lock has expired so clamp the data and move on - _reachForward = _reachUp; - _lastDistance = 0.0f; - _lockExpiry = now + LOCK_DURATION; - _calibrationState = CALIBRATION_STATE_Z; - qCDebug(inputplugins, "success: sixense calibration: up"); - } - } - } - else if (_calibrationState == CALIBRATION_STATE_Z) { - glm::vec3 xAxis = glm::normalize(_reachRight - _reachLeft); - glm::vec3 torso = 0.5f * (_reachLeft + _reachRight); - //glm::vec3 yAxis = glm::normalize(_reachUp - torso); - glm::vec3 yAxis(0.0f, 1.0f, 0.0f); - glm::vec3 zAxis = glm::normalize(glm::cross(xAxis, yAxis)); - - glm::vec3 averagePosition = 0.5f * (_averageLeft + _averageRight); - float distance = glm::dot((averagePosition - torso), zAxis); - if (fabs(distance) > fabs(_lastDistance)) { - // distance is increasing so acquire the data and push the expiry out - _reachForward = averagePosition; - _lastDistance = distance; - _lockExpiry = now + LOCK_DURATION; - } else if (now > _lockExpiry) { - if (fabsf(_lastDistance) > 0.05f * MINIMUM_ARM_REACH) { - // lock has expired so clamp the data and move on - _calibrationState = CALIBRATION_STATE_COMPLETE; - qCDebug(inputplugins, "success: sixense calibration: forward"); - // TODO: it is theoretically possible to detect that the controllers have been - // accidentally switched (left hand is holding right controller) and to swap the order. - } - } - } } #endif // HAVE_SIXENSE @@ -456,12 +408,9 @@ void SixenseManager::handlePoseEvent(glm::vec3 position, glm::quat rotation, int // z // Transform the measured position into body frame. - glm::vec3 neck = _neckBase; - // Set y component of the "neck" to raise the measured position a little bit. - neck.y = 0.5f; - position = _orbRotation * (position - neck); + position = _avatarRotation * (position + _avatarPosition); - // From ABOVE the hand canonical axes looks like this: + // From ABOVE the hand canonical axes look like this: // // | | | | y | | | | // | | | | | | | | | @@ -480,28 +429,25 @@ void SixenseManager::handlePoseEvent(glm::vec3 position, glm::quat rotation, int // // Qsh = angleAxis(PI, zAxis) * angleAxis(-PI/2, xAxis) // - const glm::vec3 xAxis = glm::vec3(1.0f, 0.0f, 0.0f); - const glm::vec3 yAxis = glm::vec3(0.0f, 1.0f, 0.0f); - const glm::vec3 zAxis = glm::vec3(0.0f, 0.0f, 1.0f); - const glm::quat sixenseToHand = glm::angleAxis(PI, zAxis) * glm::angleAxis(-PI/2.0f, xAxis); + const glm::quat sixenseToHand = glm::angleAxis(PI, Vectors::UNIT_Z) * glm::angleAxis(-PI/2.0f, Vectors::UNIT_X); // In addition to Qsh each hand has pre-offset introduced by the shape of the sixense controllers // and how they fit into the hand in their relaxed state. This offset is a quarter turn about // the sixense's z-axis, with its direction different for the two hands: float sign = (index == 0) ? 1.0f : -1.0f; - const glm::quat preOffset = glm::angleAxis(sign * PI / 2.0f, zAxis); + const glm::quat preOffset = glm::angleAxis(sign * PI / 2.0f, Vectors::UNIT_Z); // Finally, there is a post-offset (same for both hands) to get the hand's rest orientation // (fingers forward, palm down) aligned properly in the avatar's model-frame, // and then a flip about the yAxis to get into model-frame. - const glm::quat postOffset = glm::angleAxis(PI, yAxis) * glm::angleAxis(PI / 2.0f, xAxis); + const glm::quat postOffset = glm::angleAxis(PI, Vectors::UNIT_Y) * glm::angleAxis(PI / 2.0f, Vectors::UNIT_X); // The total rotation of the hand uses the formula: // // rotation = postOffset * Qsh^ * (measuredRotation * preOffset) * Qsh // // TODO: find a shortcut with fewer rotations. - rotation = postOffset * glm::inverse(sixenseToHand) * rotation * preOffset * sixenseToHand; + rotation = _avatarRotation * postOffset * glm::inverse(sixenseToHand) * rotation * preOffset * sixenseToHand; _poseStateMap[makeInput(JointChannel(index)).getChannel()] = UserInputMapper::PoseValue(position, rotation); #endif // HAVE_SIXENSE diff --git a/libraries/input-plugins/src/input-plugins/SixenseManager.h b/libraries/input-plugins/src/input-plugins/SixenseManager.h index 03482287d9..c1cc7049af 100644 --- a/libraries/input-plugins/src/input-plugins/SixenseManager.h +++ b/libraries/input-plugins/src/input-plugins/SixenseManager.h @@ -97,8 +97,8 @@ private: int _calibrationState; // these are calibration results - glm::vec3 _neckBase; // midpoint between controllers during X-axis calibration - glm::quat _orbRotation; // rotates from orb frame into body frame + glm::vec3 _avatarPosition; // in hydra-frame + glm::quat _avatarRotation; // rotation of avatar in orb-frame float _armLength; // these are measured values used to compute the calibration results From 940b8eb529c0c7fa4f9713579bd23e2776add657 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 2 Oct 2015 09:39:13 -0700 Subject: [PATCH 152/161] improve some variable names --- .../input-plugins/src/input-plugins/SixenseManager.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp index dbacc23f26..403eee2d87 100644 --- a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp +++ b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp @@ -41,10 +41,7 @@ const int CALIBRATION_STATE_IDLE = 0; const int CALIBRATION_STATE_X = 1; const int CALIBRATION_STATE_COMPLETE = 2; -// default (expected) location of neck in sixense space when sitting -const float NECK_X = -0.25f; // meters -const float NECK_Y = -0.35f; // meters -const float NECK_Z = -0.3f; // meters +const glm::vec3 DEFAULT_AVATAR_POSITION(-0.25f, -0.35f, -0.3f); // in hydra frame const float CONTROLLER_THRESHOLD = 0.35f; @@ -93,7 +90,7 @@ void SixenseManager::activate() { _calibrationState = CALIBRATION_STATE_IDLE; // By default we assume the _avatarPosition (in orb frame) is as high above the orb // as the "torso" is below it. - _avatarPosition = glm::vec3(NECK_X, NECK_Y, NECK_Z); + _avatarPosition = DEFAULT_AVATAR_POSITION; CONTAINER->addMenu(MENU_PATH); CONTAINER->addMenuItem(MENU_PATH, TOGGLE_SMOOTH, From 50b2c8ae3796282ed80ab9924d8501e7539d084f Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 2 Oct 2015 09:39:34 -0700 Subject: [PATCH 153/161] remove warnings in linux --- libraries/shared/src/Interpolate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/Interpolate.cpp b/libraries/shared/src/Interpolate.cpp index 7acc0c8cbd..bef69c9a33 100644 --- a/libraries/shared/src/Interpolate.cpp +++ b/libraries/shared/src/Interpolate.cpp @@ -23,12 +23,12 @@ float Interpolate::bezierInterpolate(float y1, float y2, float y3, float u) { float Interpolate::interpolate3Points(float y1, float y2, float y3, float u) { assert(0.0f <= u && u <= 1.0f); - if (u <= 0.5f && y1 == y2 || u >= 0.5f && y2 == y3) { + if ((u <= 0.5f && y1 == y2) || (u >= 0.5f && y2 == y3)) { // Flat line. return y2; } - if (y2 >= y1 && y2 >= y3 || y2 <= y1 && y2 <= y3) { + if ((y2 >= y1 && y2 >= y3) || (y2 <= y1 && y2 <= y3)) { // U or inverted-U shape. // Make the slope at y2 = 0, which means that the control points half way between the value points have the value y2. if (u <= 0.5f) { From 36f7bba87e3f1d269b1d57b7e048ba23aa27cbd1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 09:53:30 -0700 Subject: [PATCH 154/161] 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 155/161] 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 e9c71f38677cb4ba08d917d5e3bb5687b0d67812 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 2 Oct 2015 10:02:12 -0700 Subject: [PATCH 156/161] cleanup comments --- libraries/input-plugins/src/input-plugins/SixenseManager.cpp | 2 -- libraries/input-plugins/src/input-plugins/SixenseManager.h | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp index 403eee2d87..aa04c49adb 100644 --- a/libraries/input-plugins/src/input-plugins/SixenseManager.cpp +++ b/libraries/input-plugins/src/input-plugins/SixenseManager.cpp @@ -88,8 +88,6 @@ bool SixenseManager::isSupported() const { void SixenseManager::activate() { #ifdef HAVE_SIXENSE _calibrationState = CALIBRATION_STATE_IDLE; - // By default we assume the _avatarPosition (in orb frame) is as high above the orb - // as the "torso" is below it. _avatarPosition = DEFAULT_AVATAR_POSITION; CONTAINER->addMenu(MENU_PATH); diff --git a/libraries/input-plugins/src/input-plugins/SixenseManager.h b/libraries/input-plugins/src/input-plugins/SixenseManager.h index c1cc7049af..22340cfc95 100644 --- a/libraries/input-plugins/src/input-plugins/SixenseManager.h +++ b/libraries/input-plugins/src/input-plugins/SixenseManager.h @@ -97,8 +97,8 @@ private: int _calibrationState; // these are calibration results - glm::vec3 _avatarPosition; // in hydra-frame - glm::quat _avatarRotation; // rotation of avatar in orb-frame + glm::vec3 _avatarPosition; // in hydra-frame + glm::quat _avatarRotation; // in hydra-frame float _armLength; // these are measured values used to compute the calibration results From 71fe9b216c92aae72167ec2f15232b1084a1d17d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 2 Oct 2015 10:02:28 -0700 Subject: [PATCH 157/161] 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 158/161] 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 159/161] 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 160/161] 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 161/161] 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) {