From 7fe555d3a59d0b435481335dba4c31eb31ed9e27 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 10 Feb 2016 15:44:34 -0800 Subject: [PATCH 01/87] initial plant script --- examples/homeContent/plant/growingPlant.js | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/homeContent/plant/growingPlant.js diff --git a/examples/homeContent/plant/growingPlant.js b/examples/homeContent/plant/growingPlant.js new file mode 100644 index 0000000000..f2ff9bfa89 --- /dev/null +++ b/examples/homeContent/plant/growingPlant.js @@ -0,0 +1,30 @@ +var orientation = Camera.getOrientation(); +orientation = Quat.safeEulerAngles(orientation); +orientation.x = 0; +orientation = Quat.fromVec3Degrees(orientation); +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); + +var pot; +initializePlant(); + +function initializePlant() { + var MODEL_URL = "file:///C:/Users/Eric/Desktop/pot.fbx"; + pot = Entities.addEntity({ + type: "Model", + modelURL: MODEL_URL, + position: center + }); + + Script.setTimeout(function() { + var naturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions; + Entities.editEntity(pot, {dimensions: naturalDimensions}); + }, 2000); + +} + +function cleanup() { + Entities.deleteEntity(pot); +} + + +Script.scriptEnding.connect(cleanup); \ No newline at end of file From b4340f7b70c400d9d0023522e3183dfa1dd33d77 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 11 Feb 2016 16:28:15 -0800 Subject: [PATCH 02/87] basic flower petal --- examples/homeContent/plant/flower.fs | 60 +++++++++++++++++++ .../plant/growingPlantEntityScript.js | 54 +++++++++++++++++ ...growingPlant.js => growingPlantSpawner.js} | 16 ++++- 3 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 examples/homeContent/plant/flower.fs create mode 100644 examples/homeContent/plant/growingPlantEntityScript.js rename examples/homeContent/plant/{growingPlant.js => growingPlantSpawner.js} (56%) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs new file mode 100644 index 0000000000..d24bedc7d4 --- /dev/null +++ b/examples/homeContent/plant/flower.fs @@ -0,0 +1,60 @@ +#line 2 +//////////////////////////////////////////////////////////////////////////////////// +// +// REPLACE BELOW +// +// Replace the contents of this section with a shadertoy that includes a mainImage +// function +// +//////////////////////////////////////////////////////////////////////////////////// + +#define TWO_PI 6.28318530718 + +vec3 hsb2rgb( in vec3 c ){ + vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0), + 6.0)-3.0)-1.0, + 0.0, + 1.0 ); + rgb = rgb*rgb*(3.0-2.0*rgb); + return c.z * mix( vec3(1.0), rgb, c.y); +} + + +void mainImage( out vec4 fragColor, in vec2 fragCoord ) { + vec2 st = fragCoord.xy/iWorldScale.xz; + vec3 color = vec3(0.0, 0.0, 0.0); + + vec2 toCenter = vec2(0.5) - st; + float angle = atan(toCenter.y, toCenter.x); + float radius = length(toCenter) * 2.0; + + if (radius > 0.8) { + discard; + } + + color = hsb2rgb(vec3((angle/TWO_PI) + 0.5, radius, 1.0)); + + // Map the angle (-PI to PI) to the Hue (from 0 to 1) + // and the Saturation to the radius + // angle = pow(angle, 0.2); + + + fragColor = vec4(color, 1.0); +} + +//////////////////////////////////////////////////////////////////////////////////// +// +// REPLACE ABOVE +// +//////////////////////////////////////////////////////////////////////////////////// + + +vec4 getProceduralColor() { + vec4 result; + vec2 position = _position.xz; + position += 0.5; + + mainImage(result, position * iWorldScale.xz); + + return result; +} \ No newline at end of file diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js new file mode 100644 index 0000000000..fcf86842ea --- /dev/null +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -0,0 +1,54 @@ +// +// growingPlantEntityScript.js +// examples/homeContent/ +// +// Created by Eric Levin on 2/10/16. +// Copyright 2016 High Fidelity, Inc. +// +// This entity script handles the logic for growing a plant when it has water poured on it +// 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; + GrowingPlant = function() { + _this = this; + }; + + GrowingPlant.prototype = { + + createLeaf: function() { + var userData = JSON.stringify({ + ProceduralEntity: { + shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", + // shaderUrl: "file:///C:/Users/Eric/hifi/examples/shaders/shaderToyWrapper.fs", + } + }); + this.leaf = Entities.addEntity({ + type: "Box", + position: Vec3.sum(this.position, {x: 0, y: this.dimensions.y/2, z: 0 }), + color: {red: 100, green: 10, blue: 100}, + dimensions: {x: 0.3, y: 0.001, z: 0.3}, + userData: userData + }); + }, + + preload: function(entityID) { + this.entityID = entityID; + this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); + this.position = this.props.position; + this.dimensions = this.props.dimensions; + this.createLeaf(); + }, + + unload: function() { + Entities.deleteEntity(this.leaf); + } + + }; + + // entity scripts always need to return a newly constructed object of our type + return new GrowingPlant(); +}); \ No newline at end of file diff --git a/examples/homeContent/plant/growingPlant.js b/examples/homeContent/plant/growingPlantSpawner.js similarity index 56% rename from examples/homeContent/plant/growingPlant.js rename to examples/homeContent/plant/growingPlantSpawner.js index f2ff9bfa89..49f155e7d3 100644 --- a/examples/homeContent/plant/growingPlant.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -1,3 +1,15 @@ +// +// growingPlantSpawner.js +// examples/homeContent/ +// +// Created by Eric Levin on 2/10/16. +// Copyright 2016 High Fidelity, Inc. +// +// This entity script handles the logic for growing a plant when it has water poured on it +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + var orientation = Camera.getOrientation(); orientation = Quat.safeEulerAngles(orientation); orientation.x = 0; @@ -9,6 +21,8 @@ initializePlant(); function initializePlant() { var MODEL_URL = "file:///C:/Users/Eric/Desktop/pot.fbx"; + var SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js?v1" + Math.random()); + pot = Entities.addEntity({ type: "Model", modelURL: MODEL_URL, @@ -17,7 +31,7 @@ function initializePlant() { Script.setTimeout(function() { var naturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions; - Entities.editEntity(pot, {dimensions: naturalDimensions}); + Entities.editEntity(pot, {dimensions: naturalDimensions, script: SCRIPT_URL}); }, 2000); } From 12561f8fcffba2d1a750fd3f774cfbd1c28e027b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 11 Feb 2016 17:06:39 -0800 Subject: [PATCH 03/87] pretty flowers --- examples/homeContent/plant/flower.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs index d24bedc7d4..1941f9169d 100644 --- a/examples/homeContent/plant/flower.fs +++ b/examples/homeContent/plant/flower.fs @@ -31,8 +31,8 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { if (radius > 0.8) { discard; } - - color = hsb2rgb(vec3((angle/TWO_PI) + 0.5, radius, 1.0)); + float brightness = (angle * 20./ (TWO_PI)) + 0.5; + color = hsb2rgb(vec3( abs(angle/30) - 0.1, 0.8, pow(fract(brightness), 0.3))); // Map the angle (-PI to PI) to the Hue (from 0 to 1) // and the Saturation to the radius From f09dd81a145b8231b5792a1514ef016821c610d1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 11 Feb 2016 19:06:11 -0800 Subject: [PATCH 04/87] programatically adjusting flower stretching on sphere --- examples/homeContent/plant/flower.fs | 3 +- .../plant/growingPlantEntityScript.js | 48 ++++++++++++++++--- .../homeContent/plant/growingPlantSpawner.js | 4 +- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs index 1941f9169d..5fc849d72d 100644 --- a/examples/homeContent/plant/flower.fs +++ b/examples/homeContent/plant/flower.fs @@ -28,7 +28,8 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float angle = atan(toCenter.y, toCenter.x); float radius = length(toCenter) * 2.0; - if (radius > 0.8) { + // Second check is so we discard the top half of the sphere + if (radius > 0.8 || _position.y > 0) { discard; } float brightness = (angle * 20./ (TWO_PI)) + 0.5; diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index fcf86842ea..49da7a1e98 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -1,6 +1,6 @@ // // growingPlantEntityScript.js -// examples/homeContent/ +// examples/homeContent/plant // // Created by Eric Levin on 2/10/16. // Copyright 2016 High Fidelity, Inc. @@ -10,15 +10,23 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + (function() { + Script.include("../../libraries/tween.js"); var _this; + var TWEEN = loadTween(); GrowingPlant = function() { _this = this; + this.startingFlowerDimensions = { + x: 0.3, + y: 0.001, + z: 0.3 + }; }; GrowingPlant.prototype = { - + createLeaf: function() { var userData = JSON.stringify({ ProceduralEntity: { @@ -26,13 +34,35 @@ // shaderUrl: "file:///C:/Users/Eric/hifi/examples/shaders/shaderToyWrapper.fs", } }); - this.leaf = Entities.addEntity({ - type: "Box", - position: Vec3.sum(this.position, {x: 0, y: this.dimensions.y/2, z: 0 }), - color: {red: 100, green: 10, blue: 100}, - dimensions: {x: 0.3, y: 0.001, z: 0.3}, + _this.leafPosition = Vec3.sum(this.position, { + x: 0, + y: this.dimensions.y/2, + z: 0 + }); + _this.leaf = Entities.addEntity({ + type: "Sphere", + position: _this.leafPosition, + color: { + red: 100, + green: 10, + blue: 100 + }, + dimensions: _this.startingFlowerDimensions, userData: userData }); + + Script.setTimeout(function() { + var newDimensions = Vec3.sum(_this.startingFlowerDimensions, { + x: 0, + y: 1, + z: 0 + }); + var newPosition = Vec3.sum(_this.leafPosition, {x: 0, y: newDimensions.y/2, z: 0}); + Entities.editEntity(_this.leaf, { + dimensions: newDimensions, + position: newPosition + }); + }, 3000) }, preload: function(entityID) { @@ -43,6 +73,10 @@ this.createLeaf(); }, + update: function() { + + }, + unload: function() { Entities.deleteEntity(this.leaf); } diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 49f155e7d3..b138d2f894 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -1,6 +1,6 @@ // // growingPlantSpawner.js -// examples/homeContent/ +// examples/homeContent/plant // // Created by Eric Levin on 2/10/16. // Copyright 2016 High Fidelity, Inc. @@ -32,7 +32,7 @@ function initializePlant() { Script.setTimeout(function() { var naturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions; Entities.editEntity(pot, {dimensions: naturalDimensions, script: SCRIPT_URL}); - }, 2000); + }, 100); } From 332ade1db2daf19a5fce41764b049db8f86b09e3 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 11 Feb 2016 20:34:46 -0800 Subject: [PATCH 05/87] bloom tween --- examples/homeContent/plant/flower.fs | 4 +- .../plant/growingPlantEntityScript.js | 52 ++++++++++++------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs index 5fc849d72d..2b82bcf754 100644 --- a/examples/homeContent/plant/flower.fs +++ b/examples/homeContent/plant/flower.fs @@ -32,8 +32,8 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { if (radius > 0.8 || _position.y > 0) { discard; } - float brightness = (angle * 20./ (TWO_PI)) + 0.5; - color = hsb2rgb(vec3( abs(angle/30) - 0.1, 0.8, pow(fract(brightness), 0.3))); + float brightness = (angle * 10./ (TWO_PI)) + 0.5; + color = hsb2rgb(vec3( abs(angle/20) - 0.1, 0.8, pow(fract(brightness), 0.3))); // Map the angle (-PI to PI) to the Hue (from 0 to 1) // and the Saturation to the radius diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 49da7a1e98..77caefa37e 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -19,29 +19,29 @@ GrowingPlant = function() { _this = this; this.startingFlowerDimensions = { - x: 0.3, + x: 0.6, y: 0.001, - z: 0.3 + z: 0.6 }; }; GrowingPlant.prototype = { - createLeaf: function() { + createFlower: function() { var userData = JSON.stringify({ ProceduralEntity: { shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", // shaderUrl: "file:///C:/Users/Eric/hifi/examples/shaders/shaderToyWrapper.fs", } }); - _this.leafPosition = Vec3.sum(this.position, { + _this.startingFlowerPosition = Vec3.sum(this.position, { x: 0, y: this.dimensions.y/2, z: 0 }); - _this.leaf = Entities.addEntity({ + _this.flower = Entities.addEntity({ type: "Sphere", - position: _this.leafPosition, + position: _this.startingFlowerPosition, color: { red: 100, green: 10, @@ -51,18 +51,26 @@ userData: userData }); - Script.setTimeout(function() { - var newDimensions = Vec3.sum(_this.startingFlowerDimensions, { - x: 0, - y: 1, - z: 0 + var curProps = { + yDimension: _this.startingFlowerDimensions.y, + yPosition: _this.startingFlowerPosition.y + }; + var newYDimension = curProps.yDimension + 2; + var endProps = { + yDimension: newYDimension, + yPosition: _this.startingFlowerPosition.y + newYDimension/2 + }; + + var bloomTween = new TWEEN.Tween(curProps). + to(endProps, 3000). + easing(TWEEN.Easing.Cubic.InOut). + delay( 10000). + onUpdate(function() { + Entities.editEntity(_this.flower, { + dimensions: {x: _this.startingFlowerDimensions.x, y: curProps.yDimension, z: _this.startingFlowerDimensions.z}, + position: {x: _this.startingFlowerPosition.x, y: curProps.yPosition, z: _this.startingFlowerPosition.z} }); - var newPosition = Vec3.sum(_this.leafPosition, {x: 0, y: newDimensions.y/2, z: 0}); - Entities.editEntity(_this.leaf, { - dimensions: newDimensions, - position: newPosition - }); - }, 3000) + }).start(); }, preload: function(entityID) { @@ -70,15 +78,19 @@ this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); this.position = this.props.position; this.dimensions = this.props.dimensions; - this.createLeaf(); + this.createFlower(); + Script.update.connect(_this.update); }, - + update: function() { + print("UPDATE") + TWEEN.update(); }, unload: function() { - Entities.deleteEntity(this.leaf); + Script.update.disconnect(_this.update); + Entities.deleteEntity(_this.flower); } }; From a6087256588a93b40f112bb69b7fddea22a18712 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 11 Feb 2016 20:44:07 -0800 Subject: [PATCH 06/87] changing colors for flower --- examples/homeContent/plant/flower.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs index 2b82bcf754..86fe251d42 100644 --- a/examples/homeContent/plant/flower.fs +++ b/examples/homeContent/plant/flower.fs @@ -33,7 +33,8 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { discard; } float brightness = (angle * 10./ (TWO_PI)) + 0.5; - color = hsb2rgb(vec3( abs(angle/20) - 0.1, 0.8, pow(fract(brightness), 0.3))); + float hueOffset = sin(iGlobalTime * .07); + color = hsb2rgb(vec3( abs(angle/20) + hueOffset, 0.8, pow(fract(brightness), 0.3))); // Map the angle (-PI to PI) to the Hue (from 0 to 1) // and the Saturation to the radius From e32a317533fc4433dd9268ace7472fcbcaf9c3b3 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 12 Feb 2016 10:44:35 -0800 Subject: [PATCH 07/87] working --- examples/homeContent/plant/growingPlantEntityScript.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 77caefa37e..2561b01057 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -18,7 +18,7 @@ var TWEEN = loadTween(); GrowingPlant = function() { _this = this; - this.startingFlowerDimensions = { + _this.startingFlowerDimensions = { x: 0.6, y: 0.001, z: 0.6 @@ -64,7 +64,7 @@ var bloomTween = new TWEEN.Tween(curProps). to(endProps, 3000). easing(TWEEN.Easing.Cubic.InOut). - delay( 10000). + delay(1000). onUpdate(function() { Entities.editEntity(_this.flower, { dimensions: {x: _this.startingFlowerDimensions.x, y: curProps.yDimension, z: _this.startingFlowerDimensions.z}, @@ -74,6 +74,7 @@ }, preload: function(entityID) { + print("EBL PRELOAD"); this.entityID = entityID; this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); this.position = this.props.position; @@ -83,7 +84,6 @@ }, update: function() { - print("UPDATE") TWEEN.update(); }, @@ -91,6 +91,7 @@ unload: function() { Script.update.disconnect(_this.update); Entities.deleteEntity(_this.flower); + print("EBL UNLOAD DONE") } }; From 4f79590919f900200b53ee953680d43062fc2d3c Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 12 Feb 2016 11:10:36 -0800 Subject: [PATCH 08/87] flower growing in --- examples/homeContent/plant/flower.fs | 24 ++++--------------- .../plant/growingPlantEntityScript.js | 21 +++++++++------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs index 86fe251d42..a14d8d2f9d 100644 --- a/examples/homeContent/plant/flower.fs +++ b/examples/homeContent/plant/flower.fs @@ -1,15 +1,9 @@ -#line 2 -//////////////////////////////////////////////////////////////////////////////////// -// -// REPLACE BELOW -// -// Replace the contents of this section with a shadertoy that includes a mainImage -// function -// -//////////////////////////////////////////////////////////////////////////////////// + #define TWO_PI 6.28318530718 +uniform float iBloomPct = 0.2; + vec3 hsb2rgb( in vec3 c ){ vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0), 6.0)-3.0)-1.0, @@ -29,26 +23,18 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float radius = length(toCenter) * 2.0; // Second check is so we discard the top half of the sphere - if (radius > 0.8 || _position.y > 0) { + if ( iBloomPct < radius || _position.y > 0) { discard; } float brightness = (angle * 10./ (TWO_PI)) + 0.5; float hueOffset = sin(iGlobalTime * .07); color = hsb2rgb(vec3( abs(angle/20) + hueOffset, 0.8, pow(fract(brightness), 0.3))); - // Map the angle (-PI to PI) to the Hue (from 0 to 1) - // and the Saturation to the radius - // angle = pow(angle, 0.2); - fragColor = vec4(color, 1.0); } -//////////////////////////////////////////////////////////////////////////////////// -// -// REPLACE ABOVE -// -//////////////////////////////////////////////////////////////////////////////////// + vec4 getProceduralColor() { diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 2561b01057..14a88ef8ad 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -28,12 +28,14 @@ GrowingPlant.prototype = { createFlower: function() { - var userData = JSON.stringify({ + _this.flowerUserData = { ProceduralEntity: { shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", - // shaderUrl: "file:///C:/Users/Eric/hifi/examples/shaders/shaderToyWrapper.fs", + uniforms: { + iBloomPct: 0.0 + } } - }); + }; _this.startingFlowerPosition = Vec3.sum(this.position, { x: 0, y: this.dimensions.y/2, @@ -48,17 +50,19 @@ blue: 100 }, dimensions: _this.startingFlowerDimensions, - userData: userData + userData: JSON.stringify(_this.flowerUserData) }); var curProps = { yDimension: _this.startingFlowerDimensions.y, - yPosition: _this.startingFlowerPosition.y + yPosition: _this.startingFlowerPosition.y, + bloomPct: _this.flowerUserData.ProceduralEntity.uniforms.iBloomPct }; var newYDimension = curProps.yDimension + 2; var endProps = { yDimension: newYDimension, - yPosition: _this.startingFlowerPosition.y + newYDimension/2 + yPosition: _this.startingFlowerPosition.y + newYDimension/2, + bloomPct: 1 }; var bloomTween = new TWEEN.Tween(curProps). @@ -66,9 +70,11 @@ easing(TWEEN.Easing.Cubic.InOut). delay(1000). onUpdate(function() { + _this.flowerUserData.ProceduralEntity.uniforms.iBloomPct = curProps.bloomPct; Entities.editEntity(_this.flower, { dimensions: {x: _this.startingFlowerDimensions.x, y: curProps.yDimension, z: _this.startingFlowerDimensions.z}, - position: {x: _this.startingFlowerPosition.x, y: curProps.yPosition, z: _this.startingFlowerPosition.z} + position: {x: _this.startingFlowerPosition.x, y: curProps.yPosition, z: _this.startingFlowerPosition.z}, + userData: JSON.stringify(_this.flowerUserData) }); }).start(); }, @@ -85,7 +91,6 @@ update: function() { TWEEN.update(); - }, unload: function() { From 4c3e3538e8c80631f789de6a9ed98aef1613b7a1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 12 Feb 2016 13:17:22 -0800 Subject: [PATCH 09/87] multiple plants --- .../plant/growingPlantEntityScript.js | 80 ++++++++++++------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 14a88ef8ad..33ffadbaeb 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -18,17 +18,24 @@ var TWEEN = loadTween(); GrowingPlant = function() { _this = this; - _this.startingFlowerDimensions = { - x: 0.6, - y: 0.001, - z: 0.6 - }; + _this.flowers = []; }; GrowingPlant.prototype = { + createFlowers: function() { + for(var i = 0; i < 3; i++) { + _this.createFlower(); + } + }, + createFlower: function() { - _this.flowerUserData = { + var startingFlowerDimensions = { + x: 0.2, + y: 0.001, + z: 0.2 + }; + var flowerUserData = { ProceduralEntity: { shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", uniforms: { @@ -36,47 +43,56 @@ } } }; - _this.startingFlowerPosition = Vec3.sum(this.position, { - x: 0, - y: this.dimensions.y/2, + var startingFlowerPosition = Vec3.sum(_this.position, { + x: Math.random(), + y: _this.dimensions.y / 2, z: 0 }); - _this.flower = Entities.addEntity({ + var flower = Entities.addEntity({ type: "Sphere", - position: _this.startingFlowerPosition, + position: startingFlowerPosition, color: { red: 100, green: 10, blue: 100 }, - dimensions: _this.startingFlowerDimensions, - userData: JSON.stringify(_this.flowerUserData) + dimensions: startingFlowerDimensions, + userData: JSON.stringify(flowerUserData) }); + _this.flowers.push(flower); var curProps = { - yDimension: _this.startingFlowerDimensions.y, - yPosition: _this.startingFlowerPosition.y, - bloomPct: _this.flowerUserData.ProceduralEntity.uniforms.iBloomPct + yDimension: startingFlowerDimensions.y, + yPosition: startingFlowerPosition.y, + bloomPct: flowerUserData.ProceduralEntity.uniforms.iBloomPct }; - var newYDimension = curProps.yDimension + 2; + var newYDimension = curProps.yDimension + 1; var endProps = { yDimension: newYDimension, - yPosition: _this.startingFlowerPosition.y + newYDimension/2, + yPosition: startingFlowerPosition.y + newYDimension / 2, bloomPct: 1 }; var bloomTween = new TWEEN.Tween(curProps). - to(endProps, 3000). - easing(TWEEN.Easing.Cubic.InOut). - delay(1000). - onUpdate(function() { - _this.flowerUserData.ProceduralEntity.uniforms.iBloomPct = curProps.bloomPct; - Entities.editEntity(_this.flower, { - dimensions: {x: _this.startingFlowerDimensions.x, y: curProps.yDimension, z: _this.startingFlowerDimensions.z}, - position: {x: _this.startingFlowerPosition.x, y: curProps.yPosition, z: _this.startingFlowerPosition.z}, - userData: JSON.stringify(_this.flowerUserData) + to(endProps, 3000). + easing(TWEEN.Easing.Cubic.InOut). + delay(1000). + onUpdate(function() { + flowerUserData.ProceduralEntity.uniforms.iBloomPct = curProps.bloomPct; + Entities.editEntity(flower, { + dimensions: { + x: startingFlowerDimensions.x, + y: curProps.yDimension, + z: startingFlowerDimensions.z + }, + position: { + x: startingFlowerPosition.x, + y: curProps.yPosition, + z: startingFlowerPosition.z + }, + userData: JSON.stringify(flowerUserData) }); - }).start(); + }).start(); }, preload: function(entityID) { @@ -85,17 +101,19 @@ this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); this.position = this.props.position; this.dimensions = this.props.dimensions; - this.createFlower(); + this.createFlowers(); Script.update.connect(_this.update); }, - + update: function() { TWEEN.update(); }, unload: function() { Script.update.disconnect(_this.update); - Entities.deleteEntity(_this.flower); + _this.flowers.forEach(function(flower) { + Entities.deleteEntity(flower); + }); print("EBL UNLOAD DONE") } From 11047f676b0bff4853fae4d3ce77d97ac3c298df Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 12 Feb 2016 13:58:12 -0800 Subject: [PATCH 10/87] stable --- .../plant/growingPlantEntityScript.js | 55 +++++++++++++++++-- .../homeContent/plant/growingPlantSpawner.js | 1 + 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 33ffadbaeb..c0775caaad 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -24,9 +24,51 @@ GrowingPlant.prototype = { createFlowers: function() { - for(var i = 0; i < 3; i++) { - _this.createFlower(); - } + for (var i = 0; i < 3; i++) { + _this.createFlower(); + } + }, + + createCactus: function() { + var MODEL_URL = "file:///C:/Users/Eric/Desktop/cactus.fbx?v1" + Math.random(); + var dimensions = { + x: 0.09, + y: 0.01, + z: 0.09 + }; + _this.cactus = Entities.addEntity({ + type: "Model", + modelURL: MODEL_URL, + position: _this.position, + dimensions: dimensions + }); + + var curProps = { + yDimension: 0.01, + yPosition: _this.position.y + }; + + var endProps = { + yDimension: 0.8, + yPosition: _this.position.y + 0.4 + }; + + var growTween = new TWEEN.Tween(curProps). + to(endProps, 2000). + onUpdate(function() { + Entities.editEntity(_this.cactus, { + dimensions: { + x: dimensions.x, + y: curProps.yDimension, + z: dimensions.z + }, + position: { + x: _this.position.x, + y: curProps.yPosition, + z: _this.position.z + } + }); + }).start(); }, createFlower: function() { @@ -39,7 +81,7 @@ ProceduralEntity: { shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", uniforms: { - iBloomPct: 0.0 + iBloomPct: 0.5 } } }; @@ -64,7 +106,7 @@ var curProps = { yDimension: startingFlowerDimensions.y, yPosition: startingFlowerPosition.y, - bloomPct: flowerUserData.ProceduralEntity.uniforms.iBloomPct + bloomPct: flowerUserData.ProceduralEntity.uniforms.iBloomPct }; var newYDimension = curProps.yDimension + 1; var endProps = { @@ -101,7 +143,9 @@ this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); this.position = this.props.position; this.dimensions = this.props.dimensions; + this.createCactus(); this.createFlowers(); + // this.createFlower(); Script.update.connect(_this.update); }, @@ -111,6 +155,7 @@ unload: function() { Script.update.disconnect(_this.update); + Entities.deleteEntity(_this.cactus); _this.flowers.forEach(function(flower) { Entities.deleteEntity(flower); }); diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index b138d2f894..6f7b7633eb 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -32,6 +32,7 @@ function initializePlant() { Script.setTimeout(function() { var naturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions; Entities.editEntity(pot, {dimensions: naturalDimensions, script: SCRIPT_URL}); + // Entities.editEntity(pot, {dimensions: naturalDimensions}); }, 100); } From b5cc022df01898621dd84936cc9c4816dca16823 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 12 Feb 2016 14:58:31 -0800 Subject: [PATCH 11/87] blooming flowers --- .../plant/growingPlantEntityScript.js | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index c0775caaad..eb52f49a90 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -13,6 +13,7 @@ (function() { Script.include("../../libraries/tween.js"); + Script.include("../../libraries/utils.js"); var _this; var TWEEN = loadTween(); @@ -24,13 +25,13 @@ GrowingPlant.prototype = { createFlowers: function() { - for (var i = 0; i < 3; i++) { + for (var i = 0; i < 10; i++) { _this.createFlower(); } }, createCactus: function() { - var MODEL_URL = "file:///C:/Users/Eric/Desktop/cactus.fbx?v1" + Math.random(); + var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/cactus.fbx" var dimensions = { x: 0.09, y: 0.01, @@ -85,10 +86,15 @@ } } }; + do { + var x = randFloat(-_this.dimensions.x/3, this.dimensions.x/3); + var z = randFloat(-_this.dimensions.z/3, this.dimensions.z/3); + print("EBL X" + x ); + } while(x < 0.1 && z < 0.1); var startingFlowerPosition = Vec3.sum(_this.position, { - x: Math.random(), - y: _this.dimensions.y / 2, - z: 0 + x: x, + y: _this.dimensions.y / 2 - 0.04, + z: z }); var flower = Entities.addEntity({ type: "Sphere", @@ -120,7 +126,7 @@ easing(TWEEN.Easing.Cubic.InOut). delay(1000). onUpdate(function() { - flowerUserData.ProceduralEntity.uniforms.iBloomPct = curProps.bloomPct; + // flowerUserData.ProceduralEntity.uniforms.iBloomPct = curProps.bloomPct; Entities.editEntity(flower, { dimensions: { x: startingFlowerDimensions.x, @@ -132,7 +138,7 @@ y: curProps.yPosition, z: startingFlowerPosition.z }, - userData: JSON.stringify(flowerUserData) + // userData: JSON.stringify(flowerUserData) }); }).start(); }, From 2c895151f62bfa0a0282c92215f681d8829a83a8 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 12 Feb 2016 15:32:07 -0800 Subject: [PATCH 12/87] multiple flowers blooming --- examples/homeContent/plant/flower.fs | 6 +- .../plant/growingPlantEntityScript.js | 140 +++++++++--------- 2 files changed, 72 insertions(+), 74 deletions(-) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs index a14d8d2f9d..47ee24e8d7 100644 --- a/examples/homeContent/plant/flower.fs +++ b/examples/homeContent/plant/flower.fs @@ -26,9 +26,11 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { if ( iBloomPct < radius || _position.y > 0) { discard; } - float brightness = (angle * 10./ (TWO_PI)) + 0.5; + + // simulate ambient occlusion + float brightness = pow(radius, 0.7); float hueOffset = sin(iGlobalTime * .07); - color = hsb2rgb(vec3( abs(angle/20) + hueOffset, 0.8, pow(fract(brightness), 0.3))); + color = hsb2rgb(vec3( abs(angle/20) + hueOffset, 0.8, brightness)); fragColor = vec4(color, 1.0); diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index eb52f49a90..057c1327ec 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -25,11 +25,77 @@ GrowingPlant.prototype = { createFlowers: function() { - for (var i = 0; i < 10; i++) { - _this.createFlower(); + var NUM_FLOWERS = 20 + for (var i = 0; i < NUM_FLOWERS; i++) { + var segment = i / NUM_FLOWERS * Math.PI * 2; + var radius = randFloat(0.13, 0.25); + var position = Vec3.sum(_this.position, { + x: radius * Math.cos(segment), + y: 0.15, + z: radius * Math.sin(segment) + }); + print("EBL position " + JSON.stringify(position)); + _this.createFlower(position); } }, + + createFlower: function(position) { + var startingFlowerDimensions = { + x: 0.2, + y: 0.001, + z: 0.2 + }; + var flowerUserData = { + ProceduralEntity: { + shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", + uniforms: { + iBloomPct: 0.5 + } + } + }; + var flower = Entities.addEntity({ + type: "Sphere", + position: position, + dimensions: startingFlowerDimensions, + userData: JSON.stringify(flowerUserData) + }); + _this.flowers.push(flower); + + var curProps = { + yDimension: startingFlowerDimensions.y, + yPosition: position.y, + bloomPct: flowerUserData.ProceduralEntity.uniforms.iBloomPct + }; + var newYDimension = curProps.yDimension + 1; + var endProps = { + yDimension: newYDimension, + yPosition: position.y + newYDimension / 2 + .05, + bloomPct: 1 + }; + + var bloomTween = new TWEEN.Tween(curProps). + to(endProps, 3000). + easing(TWEEN.Easing.Cubic.InOut). + delay(randInt(1000, 5000)). + onUpdate(function() { + // flowerUserData.ProceduralEntity.uniforms.iBloomPct = curProps.bloomPct; + Entities.editEntity(flower, { + dimensions: { + x: startingFlowerDimensions.x, + y: curProps.yDimension, + z: startingFlowerDimensions.z + }, + position: { + x: position.x, + y: curProps.yPosition, + z: position.z + }, + // userData: JSON.stringify(flowerUserData) + }); + }).start(); + }, + createCactus: function() { var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/cactus.fbx" var dimensions = { @@ -72,76 +138,6 @@ }).start(); }, - createFlower: function() { - var startingFlowerDimensions = { - x: 0.2, - y: 0.001, - z: 0.2 - }; - var flowerUserData = { - ProceduralEntity: { - shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", - uniforms: { - iBloomPct: 0.5 - } - } - }; - do { - var x = randFloat(-_this.dimensions.x/3, this.dimensions.x/3); - var z = randFloat(-_this.dimensions.z/3, this.dimensions.z/3); - print("EBL X" + x ); - } while(x < 0.1 && z < 0.1); - var startingFlowerPosition = Vec3.sum(_this.position, { - x: x, - y: _this.dimensions.y / 2 - 0.04, - z: z - }); - var flower = Entities.addEntity({ - type: "Sphere", - position: startingFlowerPosition, - color: { - red: 100, - green: 10, - blue: 100 - }, - dimensions: startingFlowerDimensions, - userData: JSON.stringify(flowerUserData) - }); - _this.flowers.push(flower); - - var curProps = { - yDimension: startingFlowerDimensions.y, - yPosition: startingFlowerPosition.y, - bloomPct: flowerUserData.ProceduralEntity.uniforms.iBloomPct - }; - var newYDimension = curProps.yDimension + 1; - var endProps = { - yDimension: newYDimension, - yPosition: startingFlowerPosition.y + newYDimension / 2, - bloomPct: 1 - }; - - var bloomTween = new TWEEN.Tween(curProps). - to(endProps, 3000). - easing(TWEEN.Easing.Cubic.InOut). - delay(1000). - onUpdate(function() { - // flowerUserData.ProceduralEntity.uniforms.iBloomPct = curProps.bloomPct; - Entities.editEntity(flower, { - dimensions: { - x: startingFlowerDimensions.x, - y: curProps.yDimension, - z: startingFlowerDimensions.z - }, - position: { - x: startingFlowerPosition.x, - y: curProps.yPosition, - z: startingFlowerPosition.z - }, - // userData: JSON.stringify(flowerUserData) - }); - }).start(); - }, preload: function(entityID) { print("EBL PRELOAD"); From 3d939a7c23a74a82a287425bba0e787310512728 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 09:07:16 -0800 Subject: [PATCH 13/87] twerkin --- examples/homeContent/plant/flower.fs | 6 ++++-- .../plant/growingPlantEntityScript.js | 17 +++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs index 47ee24e8d7..c2b02c13e0 100644 --- a/examples/homeContent/plant/flower.fs +++ b/examples/homeContent/plant/flower.fs @@ -3,6 +3,8 @@ #define TWO_PI 6.28318530718 uniform float iBloomPct = 0.2; +uniform float hueTwerking = 10.0; + vec3 hsb2rgb( in vec3 c ){ vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0), @@ -29,8 +31,8 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // simulate ambient occlusion float brightness = pow(radius, 0.7); - float hueOffset = sin(iGlobalTime * .07); - color = hsb2rgb(vec3( abs(angle/20) + hueOffset, 0.8, brightness)); + float hueOffset = sin(iGlobalTime * 0.07) + hueTwerking; + color = hsb2rgb(vec3( abs(angle/hueTwerking) + hueOffset, 0.8, brightness)); fragColor = vec4(color, 1.0); diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 057c1327ec..71aa37ec76 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -20,6 +20,7 @@ GrowingPlant = function() { _this = this; _this.flowers = []; + _this.delay = 10000; }; GrowingPlant.prototype = { @@ -41,16 +42,18 @@ createFlower: function(position) { + var size = randFloat(0.1, 0.2); var startingFlowerDimensions = { - x: 0.2, + x: size, y: 0.001, - z: 0.2 + z: size }; var flowerUserData = { ProceduralEntity: { shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", uniforms: { - iBloomPct: 0.5 + iBloomPct: randFloat(0.4, 0.7), + hueTwerking: randFloat(10, 30) } } }; @@ -75,9 +78,9 @@ }; var bloomTween = new TWEEN.Tween(curProps). - to(endProps, 3000). + to(endProps, randInt(4000, 6000)). easing(TWEEN.Easing.Cubic.InOut). - delay(randInt(1000, 5000)). + delay(randInt(_this.delay, _this.delay + 3000)). onUpdate(function() { // flowerUserData.ProceduralEntity.uniforms.iBloomPct = curProps.bloomPct; Entities.editEntity(flower, { @@ -121,7 +124,9 @@ }; var growTween = new TWEEN.Tween(curProps). - to(endProps, 2000). + to(endProps, 5000). + easing(TWEEN.Easing.Cubic.InOut). + delay(_this.delay). onUpdate(function() { Entities.editEntity(_this.cactus, { dimensions: { From 13a8557f0341c08f1141a531c30b0fa315118063 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 15:12:15 -0800 Subject: [PATCH 14/87] basic architecture for watering plants set up --- .../plant/growingPlantEntityScript.js | 9 ++- .../homeContent/plant/growingPlantSpawner.js | 18 +++-- .../plant/waterHoseEntityScript.js | 67 +++++++++++++++++++ 3 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 examples/homeContent/plant/waterHoseEntityScript.js diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 71aa37ec76..7a0f5202a0 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -20,11 +20,16 @@ GrowingPlant = function() { _this = this; _this.flowers = []; - _this.delay = 10000; + _this.delay = 1000; }; GrowingPlant.prototype = { + + water: function() { + print("EBL IM BEING WATERED!") + }, + createFlowers: function() { var NUM_FLOWERS = 20 for (var i = 0; i < NUM_FLOWERS; i++) { @@ -35,12 +40,10 @@ y: 0.15, z: radius * Math.sin(segment) }); - print("EBL position " + JSON.stringify(position)); _this.createFlower(position); } }, - createFlower: function(position) { var size = randFloat(0.1, 0.2); var startingFlowerDimensions = { diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 6f7b7633eb..63a2bf465d 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -16,29 +16,39 @@ orientation.x = 0; orientation = Quat.fromVec3Degrees(orientation); var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); -var pot; +var pot, hose; initializePlant(); function initializePlant() { var MODEL_URL = "file:///C:/Users/Eric/Desktop/pot.fbx"; - var SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js?v1" + Math.random()); + var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js?v1" + Math.random()); pot = Entities.addEntity({ type: "Model", + name: "plant pot", modelURL: MODEL_URL, position: center }); + var HOSE_SCRIPT_URL = Script.resolvePath("waterHoseEntityScript.js?v1" + Math.random()); + hose = Entities.addEntity({ + type: "Box", + dimensions: {x: 0.1, y: 0.5, z: 0.1}, + position: Vec3.sum(center, {x: 0.5, y: 0, z: 0}), + color: {red: 200, green: 10, blue: 200}, + script: HOSE_SCRIPT_URL + }); + Script.setTimeout(function() { var naturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions; - Entities.editEntity(pot, {dimensions: naturalDimensions, script: SCRIPT_URL}); - // Entities.editEntity(pot, {dimensions: naturalDimensions}); + Entities.editEntity(pot, {dimensions: naturalDimensions, script: PLANT_SCRIPT_URL}); }, 100); } function cleanup() { Entities.deleteEntity(pot); + Entities.deleteEntity(hose); } diff --git a/examples/homeContent/plant/waterHoseEntityScript.js b/examples/homeContent/plant/waterHoseEntityScript.js new file mode 100644 index 0000000000..b6f8fafc3f --- /dev/null +++ b/examples/homeContent/plant/waterHoseEntityScript.js @@ -0,0 +1,67 @@ +// +// waterHoseEntityScript.js +// examples/homeContent/plant +// +// Created by Eric Levin on 2/15/16. +// Copyright 2016 High Fidelity, Inc. +// +// This entity script handles the logic for spraying water when a user holds down the trigger +// 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"); + + var _this; + var TWEEN = loadTween(); + WaterHose = function() { + _this = this; + this.potName = "plant pot"; + _this.potSearchRadius = 5; + + }; + + WaterHose.prototype = { + + clickDownOnEntity: function() { + // search for a pot with some seeds nearby + var entities = Entities.findEntities(this.position, _this.potSearchRadius); + entities.forEach(function(entity) { + var name = Entities.getEntityProperties(entity, "name").name; + if (name === _this.potName) { + // We've found out potted plant to grow! + _this.pottedPlant = entity; + } + }); + + }, + holdingClickOnEntity: function() { + if (!_this.pottedPlant) { + // No plant nearby to grow, so return + return; + } + Entities.callEntityMethod(_this.pottedPlant, "water"); + + }, + + preload: function(entityID) { + print("EBL PRELOAD"); + this.entityID = entityID; + this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); + this.position = this.props.position; + this.dimensions = this.props.dimensions; + + }, + + + unload: function() { + print("EBL UNLOAD DONE") + } + + }; + + // entity scripts always need to return a newly constructed object of our type + return new WaterHose(); +}); \ No newline at end of file From 678caef9c6e0880b35205db404d8d1b1afcb1e98 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 15:16:49 -0800 Subject: [PATCH 15/87] flowers ready to be grown through watering --- .../plant/growingPlantEntityScript.js | 73 ++----------------- 1 file changed, 5 insertions(+), 68 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 7a0f5202a0..1c24c2f0ea 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -27,7 +27,7 @@ water: function() { - print("EBL IM BEING WATERED!") + print("EBL IM BEING WATERED!"); }, createFlowers: function() { @@ -67,39 +67,7 @@ userData: JSON.stringify(flowerUserData) }); _this.flowers.push(flower); - - var curProps = { - yDimension: startingFlowerDimensions.y, - yPosition: position.y, - bloomPct: flowerUserData.ProceduralEntity.uniforms.iBloomPct - }; - var newYDimension = curProps.yDimension + 1; - var endProps = { - yDimension: newYDimension, - yPosition: position.y + newYDimension / 2 + .05, - bloomPct: 1 - }; - - var bloomTween = new TWEEN.Tween(curProps). - to(endProps, randInt(4000, 6000)). - easing(TWEEN.Easing.Cubic.InOut). - delay(randInt(_this.delay, _this.delay + 3000)). - onUpdate(function() { - // flowerUserData.ProceduralEntity.uniforms.iBloomPct = curProps.bloomPct; - Entities.editEntity(flower, { - dimensions: { - x: startingFlowerDimensions.x, - y: curProps.yDimension, - z: startingFlowerDimensions.z - }, - position: { - x: position.x, - y: curProps.yPosition, - z: position.z - }, - // userData: JSON.stringify(flowerUserData) - }); - }).start(); + }, createCactus: function() { @@ -116,34 +84,8 @@ dimensions: dimensions }); - var curProps = { - yDimension: 0.01, - yPosition: _this.position.y - }; - - var endProps = { - yDimension: 0.8, - yPosition: _this.position.y + 0.4 - }; - - var growTween = new TWEEN.Tween(curProps). - to(endProps, 5000). - easing(TWEEN.Easing.Cubic.InOut). - delay(_this.delay). - onUpdate(function() { - Entities.editEntity(_this.cactus, { - dimensions: { - x: dimensions.x, - y: curProps.yDimension, - z: dimensions.z - }, - position: { - x: _this.position.x, - y: curProps.yPosition, - z: _this.position.z - } - }); - }).start(); + + }, @@ -155,16 +97,11 @@ this.dimensions = this.props.dimensions; this.createCactus(); this.createFlowers(); - // this.createFlower(); - Script.update.connect(_this.update); }, - update: function() { - TWEEN.update(); - }, + unload: function() { - Script.update.disconnect(_this.update); Entities.deleteEntity(_this.cactus); _this.flowers.forEach(function(flower) { Entities.deleteEntity(flower); From 969ae2e07b5e9fc4823a67e28e51f1cc16145923 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 15:26:58 -0800 Subject: [PATCH 16/87] cactus getting watered --- .../homeContent/plant/growingPlantEntityScript.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 1c24c2f0ea..e0aa4b6049 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -28,6 +28,10 @@ water: function() { print("EBL IM BEING WATERED!"); + _this.cactusDimensions = Vec3.sum(_this.cactusDimensions, {x: 0, y: 0.01, z: 0}); + // Need to raise up cactus as it stretches so it doesnt burst out the bottom of the plant + _this.cactusPosition = Vec3.sum(_this.cactusPosition, {x: 0, y: _this.cactusHeightMovement, z: 0}); + Entities.editEntity(_this.cactus, {dimensions: _this.cactusDimensions, position: _this.cactusPosition}); }, createFlowers: function() { @@ -72,16 +76,18 @@ createCactus: function() { var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/cactus.fbx" - var dimensions = { + _this.cactusDimensions = { x: 0.09, y: 0.01, z: 0.09 }; + _this.cactusHeightMovement = _this.cactusDimensions.y/2; + _this.cactusPosition = _this.position; _this.cactus = Entities.addEntity({ type: "Model", modelURL: MODEL_URL, - position: _this.position, - dimensions: dimensions + position: _this.cactusPosition, + dimensions: _this.cactusDimensions }); From 03ca41c0c244559f452d2bb7df2303e97b7e7e67 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 15:43:44 -0800 Subject: [PATCH 17/87] each flower needs to be its own object --- .../homeContent/plant/growingPlantEntityScript.js | 14 +++++++++----- examples/homeContent/plant/growingPlantSpawner.js | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index e0aa4b6049..a1beb37140 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -32,6 +32,14 @@ // Need to raise up cactus as it stretches so it doesnt burst out the bottom of the plant _this.cactusPosition = Vec3.sum(_this.cactusPosition, {x: 0, y: _this.cactusHeightMovement, z: 0}); Entities.editEntity(_this.cactus, {dimensions: _this.cactusDimensions, position: _this.cactusPosition}); + + _this.flowers.forEach(_this.waterFlower) + }, + + waterFlower: function(flower) { + var props = Entities.getEntityProperties(flower, ["position, dimensions"]); + var newDimensions = Vec3.sum(props.dimensions, {x: 0, y: 0.01, z: 0}); + Entities.editEntity(flower, {dimensions: newDimensions}); }, createFlowers: function() { @@ -88,13 +96,9 @@ modelURL: MODEL_URL, position: _this.cactusPosition, dimensions: _this.cactusDimensions - }); - - - + }); }, - preload: function(entityID) { print("EBL PRELOAD"); this.entityID = entityID; diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 63a2bf465d..65bc91ac0d 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -14,7 +14,7 @@ var orientation = Camera.getOrientation(); orientation = Quat.safeEulerAngles(orientation); orientation.x = 0; orientation = Quat.fromVec3Degrees(orientation); -var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(orientation))); +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(orientation))); var pot, hose; initializePlant(); From a12886eebd7e9566066dd20e5959925dec2aa967 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 15:57:07 -0800 Subject: [PATCH 18/87] growing stuff --- .../plant/growingPlantEntityScript.js | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index a1beb37140..798e1a8e23 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -21,6 +21,8 @@ _this = this; _this.flowers = []; _this.delay = 1000; + _this.MAX_CACTUS_Y_DIMENSION = 0.7; + _this.GROW_RATE = 0.001; }; GrowingPlant.prototype = { @@ -28,28 +30,41 @@ water: function() { print("EBL IM BEING WATERED!"); - _this.cactusDimensions = Vec3.sum(_this.cactusDimensions, {x: 0, y: 0.01, z: 0}); + _this.cactusDimensions = Vec3.sum(_this.cactusDimensions, {x: 0, y: _this.GROW_RATE, z: 0}); + + if (_this.cactusDimensions.y > _this.MAX_CACTUS_Y_DIMENSION) { + // We don't want to grow our cactus any more than this or it will look bad + return; + } // Need to raise up cactus as it stretches so it doesnt burst out the bottom of the plant - _this.cactusPosition = Vec3.sum(_this.cactusPosition, {x: 0, y: _this.cactusHeightMovement, z: 0}); + _this.cactusPosition = Vec3.sum(_this.cactusPosition, {x: 0, y: _this.cactusHeightMovement * 0.1, z: 0}); Entities.editEntity(_this.cactus, {dimensions: _this.cactusDimensions, position: _this.cactusPosition}); - _this.flowers.forEach(_this.waterFlower) + _this.flowers.forEach(_this.waterFlower); }, waterFlower: function(flower) { var props = Entities.getEntityProperties(flower, ["position, dimensions"]); - var newDimensions = Vec3.sum(props.dimensions, {x: 0, y: 0.01, z: 0}); - Entities.editEntity(flower, {dimensions: newDimensions}); + var newDimensions = Vec3.sum(props.dimensions, {x: randFloat(0, 0.0001), y: 0.001, z: randFloat(0, 0.0001)}); + var newPosition = Vec3.sum(props.position, {x: 0, y: _this.flowerHeightMovement * 0.55, z: 0}); + Entities.editEntity(flower, {dimensions: newDimensions, position: newPosition}); }, createFlowers: function() { + var size = 0.1; var NUM_FLOWERS = 20 + _this.startingFlowerDimensions = { + x: size, + y: 0.001, + z: size + }; + _this.flowerHeightMovement = _this.startingFlowerDimensions.y; for (var i = 0; i < NUM_FLOWERS; i++) { var segment = i / NUM_FLOWERS * Math.PI * 2; var radius = randFloat(0.13, 0.25); var position = Vec3.sum(_this.position, { x: radius * Math.cos(segment), - y: 0.15, + y: 0.16, z: radius * Math.sin(segment) }); _this.createFlower(position); @@ -57,17 +72,12 @@ }, createFlower: function(position) { - var size = randFloat(0.1, 0.2); - var startingFlowerDimensions = { - x: size, - y: 0.001, - z: size - }; + var flowerUserData = { ProceduralEntity: { shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", uniforms: { - iBloomPct: randFloat(0.4, 0.7), + iBloomPct: randFloat(0.4, 0.8), hueTwerking: randFloat(10, 30) } } @@ -75,7 +85,7 @@ var flower = Entities.addEntity({ type: "Sphere", position: position, - dimensions: startingFlowerDimensions, + dimensions: _this.startingFlowerDimensions, userData: JSON.stringify(flowerUserData) }); _this.flowers.push(flower); From 236ff068e2d0550607ca70f9637277fa2d29e9a6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 16:16:31 -0800 Subject: [PATCH 19/87] hose in --- .../homeContent/plant/growingPlantSpawner.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 65bc91ac0d..7e2d6b3028 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -20,29 +20,32 @@ var pot, hose; initializePlant(); function initializePlant() { - var MODEL_URL = "file:///C:/Users/Eric/Desktop/pot.fbx"; + var POT_MODEL_URL = "file:///C:/Users/Eric/Desktop/pot.fbx"; var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js?v1" + Math.random()); pot = Entities.addEntity({ type: "Model", name: "plant pot", - modelURL: MODEL_URL, + modelURL: POT_MODEL_URL, position: center }); + var HOSE_MODEL_URL = "file:///C:/Users/Eric/Desktop/hose.fbx"; var HOSE_SCRIPT_URL = Script.resolvePath("waterHoseEntityScript.js?v1" + Math.random()); hose = Entities.addEntity({ - type: "Box", - dimensions: {x: 0.1, y: 0.5, z: 0.1}, + type: "Model", + modelURL: HOSE_MODEL_URL, position: Vec3.sum(center, {x: 0.5, y: 0, z: 0}), color: {red: 200, green: 10, blue: 200}, - script: HOSE_SCRIPT_URL }); Script.setTimeout(function() { - var naturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions; - Entities.editEntity(pot, {dimensions: naturalDimensions, script: PLANT_SCRIPT_URL}); - }, 100); + var potNaturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions; + Entities.editEntity(pot, {dimensions: potNaturalDimensions, script: PLANT_SCRIPT_URL}); + + var hoseNaturalDimensions = Entities.getEntityProperties(hose, "naturalDimensions").naturalDimensions; + Entities.editEntity(hose, {dimensions: hoseNaturalDimensions, script: HOSE_SCRIPT_URL}); + }, 200); } From f97eafc4eec6a70dfdacf15cbedd022e5b1d0411 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 16:40:03 -0800 Subject: [PATCH 20/87] hooking up water to hose --- examples/homeContent/plant/growingPlantSpawner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 7e2d6b3028..f3b5ba42a5 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -30,12 +30,12 @@ function initializePlant() { position: center }); - var HOSE_MODEL_URL = "file:///C:/Users/Eric/Desktop/hose.fbx"; + var HOSE_MODEL_URL = "file:///C:/Users/Eric/Desktop/hose.fbx?v1" + Math.random(); var HOSE_SCRIPT_URL = Script.resolvePath("waterHoseEntityScript.js?v1" + Math.random()); hose = Entities.addEntity({ type: "Model", modelURL: HOSE_MODEL_URL, - position: Vec3.sum(center, {x: 0.5, y: 0, z: 0}), + position: Vec3.sum(center, {x: 0.0, y: 1, z: 0}), color: {red: 200, green: 10, blue: 200}, }); From a5d4ec15aba2c869ade8864a2fbe20e9fb5f7400 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 18:00:06 -0800 Subject: [PATCH 21/87] watering on and off --- .../homeContent/plant/growingPlantSpawner.js | 4 +- .../plant/waterHoseEntityScript.js | 65 ++++++++++++++++++- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index f3b5ba42a5..4fa317b75a 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -20,7 +20,7 @@ var pot, hose; initializePlant(); function initializePlant() { - var POT_MODEL_URL = "file:///C:/Users/Eric/Desktop/pot.fbx"; + var POT_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/pot.fbx"; var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js?v1" + Math.random()); pot = Entities.addEntity({ @@ -45,7 +45,7 @@ function initializePlant() { var hoseNaturalDimensions = Entities.getEntityProperties(hose, "naturalDimensions").naturalDimensions; Entities.editEntity(hose, {dimensions: hoseNaturalDimensions, script: HOSE_SCRIPT_URL}); - }, 200); + }, 2000); } diff --git a/examples/homeContent/plant/waterHoseEntityScript.js b/examples/homeContent/plant/waterHoseEntityScript.js index b6f8fafc3f..d56f0dccaf 100644 --- a/examples/homeContent/plant/waterHoseEntityScript.js +++ b/examples/homeContent/plant/waterHoseEntityScript.js @@ -20,13 +20,14 @@ _this = this; this.potName = "plant pot"; _this.potSearchRadius = 5; - + }; WaterHose.prototype = { clickDownOnEntity: function() { // search for a pot with some seeds nearby + Entities.editEntity(_this.waterEffect, {isEmitting: true}); var entities = Entities.findEntities(this.position, _this.potSearchRadius); entities.forEach(function(entity) { var name = Entities.getEntityProperties(entity, "name").name; @@ -46,18 +47,78 @@ }, + clickReleaseOnEntity: function() { + Entities.editEntity(_this.waterEffect, {isEmitting: false}); + }, + preload: function(entityID) { print("EBL PRELOAD"); this.entityID = entityID; this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); this.position = this.props.position; this.dimensions = this.props.dimensions; - + this.createWaterEffect(); + + }, + + createWaterEffect: function() { + _this.waterEffect = Entities.addEntity({ + type: "ParticleEffect", + isEmitting: false, + position: _this.position, + colorStart: { + red: 0, + green: 10, + blue: 20 + }, + color: { + red: 30, + green: 30, + blue: 40 + }, + colorFinish: { + red: 50, + green: 50, + blue: 60 + }, + maxParticles: 20000, + lifespan: 1.5, + emitRate: 10000, + emitSpeed: .1, + speedSpread: 0.0, + emitDimensions: { + x: 0.1, + y: 0.01, + z: 0.1 + }, + emitAcceleration: { + x: 0.0, + y: -1.0, + z: 0 + }, + polarFinish: Math.PI, + accelerationSpread: { + x: 0.1, + y: 0.0, + z: 0.1 + }, + particleRadius: 0.04, + radiusSpread: 0.01, + radiusStart: 0.03, + alpha: 0.9, + alphaSpread: .1, + alphaStart: 0.7, + alphaFinish: 0.5, + textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png", + // emitterShouldTrail: true + }); + }, unload: function() { print("EBL UNLOAD DONE") + Entities.deleteEntity(_this.waterEffect); } }; From f61aea1c9b4f12225e4ea2ce215cce04a53d674f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 18:18:58 -0800 Subject: [PATCH 22/87] adding trigger --- .../plant/growingPlantEntityScript.js | 7 ++--- .../homeContent/plant/growingPlantSpawner.js | 31 +++++++++++++++---- .../plant/waterHoseEntityScript.js | 1 - 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 798e1a8e23..59a972d05a 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -29,7 +29,6 @@ water: function() { - print("EBL IM BEING WATERED!"); _this.cactusDimensions = Vec3.sum(_this.cactusDimensions, {x: 0, y: _this.GROW_RATE, z: 0}); if (_this.cactusDimensions.y > _this.MAX_CACTUS_Y_DIMENSION) { @@ -75,7 +74,7 @@ var flowerUserData = { ProceduralEntity: { - shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs", + shaderUrl: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs", uniforms: { iBloomPct: randFloat(0.4, 0.8), hueTwerking: randFloat(10, 30) @@ -84,6 +83,7 @@ }; var flower = Entities.addEntity({ type: "Sphere", + name: "flower", position: position, dimensions: _this.startingFlowerDimensions, userData: JSON.stringify(flowerUserData) @@ -104,13 +104,13 @@ _this.cactus = Entities.addEntity({ type: "Model", modelURL: MODEL_URL, + name: "cactus", position: _this.cactusPosition, dimensions: _this.cactusDimensions }); }, preload: function(entityID) { - print("EBL PRELOAD"); this.entityID = entityID; this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); this.position = this.props.position; @@ -126,7 +126,6 @@ _this.flowers.forEach(function(flower) { Entities.deleteEntity(flower); }); - print("EBL UNLOAD DONE") } }; diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 4fa317b75a..a289365191 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -30,21 +30,40 @@ function initializePlant() { position: center }); - var HOSE_MODEL_URL = "file:///C:/Users/Eric/Desktop/hose.fbx?v1" + Math.random(); - var HOSE_SCRIPT_URL = Script.resolvePath("waterHoseEntityScript.js?v1" + Math.random()); + var HOSE_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/hose.fbx"; + var HOSE_SCRIPT_URL = Script.resolvePath("waterHoseEntityScript.js?v1" + Math.random()); hose = Entities.addEntity({ type: "Model", modelURL: HOSE_MODEL_URL, - position: Vec3.sum(center, {x: 0.0, y: 1, z: 0}), - color: {red: 200, green: 10, blue: 200}, + position: Vec3.sum(center, { + x: 0.0, + y: 1, + z: 0 + }), + color: { + red: 200, + green: 10, + blue: 200 + }, + userData: JSON.stringify({ + grabbableKey: { + wantsTrigger: true + } + }) }); Script.setTimeout(function() { var potNaturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions; - Entities.editEntity(pot, {dimensions: potNaturalDimensions, script: PLANT_SCRIPT_URL}); + Entities.editEntity(pot, { + dimensions: potNaturalDimensions, + script: PLANT_SCRIPT_URL + }); var hoseNaturalDimensions = Entities.getEntityProperties(hose, "naturalDimensions").naturalDimensions; - Entities.editEntity(hose, {dimensions: hoseNaturalDimensions, script: HOSE_SCRIPT_URL}); + Entities.editEntity(hose, { + dimensions: hoseNaturalDimensions, + script: HOSE_SCRIPT_URL + }); }, 2000); } diff --git a/examples/homeContent/plant/waterHoseEntityScript.js b/examples/homeContent/plant/waterHoseEntityScript.js index d56f0dccaf..5488018538 100644 --- a/examples/homeContent/plant/waterHoseEntityScript.js +++ b/examples/homeContent/plant/waterHoseEntityScript.js @@ -110,7 +110,6 @@ alphaStart: 0.7, alphaFinish: 0.5, textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png", - // emitterShouldTrail: true }); }, From b245499d53edb06e55b502185a203a379cb3f892 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 18:30:36 -0800 Subject: [PATCH 23/87] near trigger --- .../plant/waterHoseEntityScript.js | 63 ++++++++++++++++--- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/examples/homeContent/plant/waterHoseEntityScript.js b/examples/homeContent/plant/waterHoseEntityScript.js index 5488018538..816a6e6d51 100644 --- a/examples/homeContent/plant/waterHoseEntityScript.js +++ b/examples/homeContent/plant/waterHoseEntityScript.js @@ -27,18 +27,64 @@ clickDownOnEntity: function() { // search for a pot with some seeds nearby - Entities.editEntity(_this.waterEffect, {isEmitting: true}); + _this.startWatering(); + + }, + + startFarTrigger: function() { + print("TRIGGER") + _this.startWatering(); + }, + + continueFarTrigger: function() { + print("TRIGGER") + _this.continueWatering(); + }, + + stopFarTrigger : function() { + _this.stopWatering(); + }, + + startNearTrigger: function() { + print("TRIGGER") + _this.startWatering(); + }, + + continueNearTrigger: function() { + print("TRIGGER") + _this.continueWatering(); + }, + + stopNearTrigger : function() { + _this.stopWatering(); + }, + + holdingClickOnEntity: function() { + _this.continueWatering(); + }, + + clickReleaseOnEntity: function() { + _this.stopWatering(); + }, + + startWatering: function() { + Entities.editEntity(_this.waterEffect, { + isEmitting: true + }); var entities = Entities.findEntities(this.position, _this.potSearchRadius); entities.forEach(function(entity) { var name = Entities.getEntityProperties(entity, "name").name; if (name === _this.potName) { // We've found out potted plant to grow! - _this.pottedPlant = entity; + Script.setTimeout(function() { + // Wait a bit to assign the pot so the plants grow once water hits + _this.pottedPlant = entity; + }, 1500); } }); }, - holdingClickOnEntity: function() { + continueWatering: function() { if (!_this.pottedPlant) { // No plant nearby to grow, so return return; @@ -47,8 +93,11 @@ }, - clickReleaseOnEntity: function() { - Entities.editEntity(_this.waterEffect, {isEmitting: false}); + stopWatering: function() { + Entities.editEntity(_this.waterEffect, { + isEmitting: false + }); + _this.pottedPlant = null; }, preload: function(entityID) { @@ -71,12 +120,12 @@ green: 10, blue: 20 }, - color: { + color: { red: 30, green: 30, blue: 40 }, - colorFinish: { + colorFinish: { red: 50, green: 50, blue: 60 From d00b650ee2aceb8325938f2330afd6c29acaed73 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 18:41:56 -0800 Subject: [PATCH 24/87] Water sounds --- examples/homeContent/plant/waterHoseEntityScript.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/homeContent/plant/waterHoseEntityScript.js b/examples/homeContent/plant/waterHoseEntityScript.js index 816a6e6d51..ac0847338a 100644 --- a/examples/homeContent/plant/waterHoseEntityScript.js +++ b/examples/homeContent/plant/waterHoseEntityScript.js @@ -20,6 +20,7 @@ _this = this; this.potName = "plant pot"; _this.potSearchRadius = 5; + _this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav"); }; @@ -32,12 +33,10 @@ }, startFarTrigger: function() { - print("TRIGGER") _this.startWatering(); }, continueFarTrigger: function() { - print("TRIGGER") _this.continueWatering(); }, @@ -46,12 +45,10 @@ }, startNearTrigger: function() { - print("TRIGGER") _this.startWatering(); }, continueNearTrigger: function() { - print("TRIGGER") _this.continueWatering(); }, @@ -68,6 +65,11 @@ }, startWatering: function() { + _this.waterInjector = Audio.playSound(_this.waterSound, { + position: _this.position, + volume: 0.3, + loop: true + }); Entities.editEntity(_this.waterEffect, { isEmitting: true }); @@ -94,6 +96,7 @@ }, stopWatering: function() { + _this.waterInjector.stop(); Entities.editEntity(_this.waterEffect, { isEmitting: false }); @@ -101,7 +104,6 @@ }, preload: function(entityID) { - print("EBL PRELOAD"); this.entityID = entityID; this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); this.position = this.props.position; @@ -165,7 +167,6 @@ unload: function() { - print("EBL UNLOAD DONE") Entities.deleteEntity(_this.waterEffect); } From f8c846f5d11b2fd3384a327805807638cc1be186 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 15 Feb 2016 18:53:41 -0800 Subject: [PATCH 25/87] got rid of query string --- examples/homeContent/plant/growingPlantSpawner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index a289365191..90483e8fc2 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -21,7 +21,7 @@ initializePlant(); function initializePlant() { var POT_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/pot.fbx"; - var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js?v1" + Math.random()); + var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js"); pot = Entities.addEntity({ type: "Model", @@ -31,7 +31,7 @@ function initializePlant() { }); var HOSE_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/hose.fbx"; - var HOSE_SCRIPT_URL = Script.resolvePath("waterHoseEntityScript.js?v1" + Math.random()); + var HOSE_SCRIPT_URL = Script.resolvePath("waterHoseEntityScript.js"); hose = Entities.addEntity({ type: "Model", modelURL: HOSE_MODEL_URL, From bc6e806ef2b728e7982dd4e8b6fed3aa0be45bd6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 16 Feb 2016 10:23:22 -0800 Subject: [PATCH 26/87] removed tween --- examples/homeContent/plant/growingPlantEntityScript.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 59a972d05a..e992899b22 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -12,11 +12,9 @@ (function() { - Script.include("../../libraries/tween.js"); Script.include("../../libraries/utils.js"); var _this; - var TWEEN = loadTween(); GrowingPlant = function() { _this = this; _this.flowers = []; From 1ad4d6474833c5603ef5e1512a40d209cc5a9cfe Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 16 Feb 2016 10:32:24 -0800 Subject: [PATCH 27/87] removed tween --- examples/homeContent/plant/waterHoseEntityScript.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/homeContent/plant/waterHoseEntityScript.js b/examples/homeContent/plant/waterHoseEntityScript.js index ac0847338a..423c547423 100644 --- a/examples/homeContent/plant/waterHoseEntityScript.js +++ b/examples/homeContent/plant/waterHoseEntityScript.js @@ -15,7 +15,6 @@ Script.include("../../libraries/utils.js"); var _this; - var TWEEN = loadTween(); WaterHose = function() { _this = this; this.potName = "plant pot"; From cf88421cf547fbf18894803ef617ef5be5daa00a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 23 Feb 2016 16:30:53 -0800 Subject: [PATCH 28/87] plant and pot are separated for raycasting purposes --- .../homeContent/plant/growingPlantSpawner.js | 74 +++++++------------ 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 90483e8fc2..cf34355544 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -14,63 +14,41 @@ var orientation = Camera.getOrientation(); orientation = Quat.safeEulerAngles(orientation); orientation.x = 0; orientation = Quat.fromVec3Degrees(orientation); -var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(orientation))); +var bowlPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(orientation))); -var pot, hose; -initializePlant(); -function initializePlant() { - var POT_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/pot.fbx"; - var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js"); - pot = Entities.addEntity({ - type: "Model", - name: "plant pot", - modelURL: POT_MODEL_URL, - position: center - }); - var HOSE_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/hose.fbx"; - var HOSE_SCRIPT_URL = Script.resolvePath("waterHoseEntityScript.js"); - hose = Entities.addEntity({ - type: "Model", - modelURL: HOSE_MODEL_URL, - position: Vec3.sum(center, { - x: 0.0, - y: 1, - z: 0 - }), - color: { - red: 200, - green: 10, - blue: 200 - }, - userData: JSON.stringify({ - grabbableKey: { - wantsTrigger: true - } - }) - }); - Script.setTimeout(function() { - var potNaturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions; - Entities.editEntity(pot, { - dimensions: potNaturalDimensions, - script: PLANT_SCRIPT_URL - }); +var BOWL_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Flowers--Bowl.fbx"; +var bowlDimensions = {x: 0.518, y: 0.1938, z: 0.5518}; +var bowl= Entities.addEntity({ + type: "Model", + modelURL: BOWL_MODEL_URL, + dimensions: bowlDimensions, + name: "plant bowl", + position: bowlPosition +}); + + +var PLANT_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Flowers--Moss-Rock.fbx"; +var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js"); +var plantDimensions = {x: 0.52, y: 0.2600, z: 0.52}; +var plantPosition = Vec3.sum(bowlPosition, {x: 0, y: plantDimensions.y/2, z: 0}); +var plant = Entities.addEntity({ + type: "Model", + modelURL: PLANT_MODEL_URL, + name: "plant", + dimensions: plantDimensions, + position: plantPosition, + parentID: bowl +}); - var hoseNaturalDimensions = Entities.getEntityProperties(hose, "naturalDimensions").naturalDimensions; - Entities.editEntity(hose, { - dimensions: hoseNaturalDimensions, - script: HOSE_SCRIPT_URL - }); - }, 2000); -} function cleanup() { - Entities.deleteEntity(pot); - Entities.deleteEntity(hose); + Entities.deleteEntity(plant); + Entities.deleteEntity(bowl); } From 21808242ba887219cfcd89b771a8e980bf151d98 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 25 Feb 2016 14:20:13 -0800 Subject: [PATCH 29/87] stashin --- .../homeContent/plant/growingPlantSpawner.js | 18 +- .../homeContent/plant/waterCanEntityScript.js | 97 ++++++++++ .../plant/waterHoseEntityScript.js | 176 ------------------ 3 files changed, 109 insertions(+), 182 deletions(-) create mode 100644 examples/homeContent/plant/waterCanEntityScript.js delete mode 100644 examples/homeContent/plant/waterHoseEntityScript.js diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index cf34355544..53e647a1af 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -14,12 +14,9 @@ var orientation = Camera.getOrientation(); orientation = Quat.safeEulerAngles(orientation); orientation.x = 0; orientation = Quat.fromVec3Degrees(orientation); + + var bowlPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(orientation))); - - - - - var BOWL_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Flowers--Bowl.fbx"; var bowlDimensions = {x: 0.518, y: 0.1938, z: 0.5518}; var bowl= Entities.addEntity({ @@ -44,11 +41,20 @@ var plant = Entities.addEntity({ parentID: bowl }); - +var WATER_CAN_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/waterCan.fbx"; +var waterCanPosition = Vec3.sum(plantPosition, Vec3.multiply(0.6, Quat.getRight(orientation))); +var waterCan = Entities.addEntity({ + type: "Model", + shapeType: 'box', + modelURL: WATER_CAN_MODEL_URL, + position: waterCanPosition, + dynamic: true +}); function cleanup() { Entities.deleteEntity(plant); Entities.deleteEntity(bowl); + Entities.deleteEntity(waterCan); } diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js new file mode 100644 index 0000000000..6443516524 --- /dev/null +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -0,0 +1,97 @@ +// +// waterCanEntityScript.js +// examples/homeContent/plant +// +// Created by Eric Levin on 2/15/16. +// Copyright 2016 High Fidelity, Inc. +// +// This entity script handles the logic for pouring water when a user tilts the entity the script is attached too. +// 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"); + + var _this; + WaterCan = function() { + _this = this; + _this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav"); + + }; + + WaterCan.prototype = { + + continueNearGrab: function() { + + } + + preload: function(entityID) { + this.entityID = entityID; + + }, + + createWaterEffect: function() { + _this.waterEffect = Entities.addEntity({ + type: "ParticleEffect", + isEmitting: false, + position: _this.position, + colorStart: { + red: 0, + green: 10, + blue: 20 + }, + color: { + red: 30, + green: 30, + blue: 40 + }, + colorFinish: { + red: 50, + green: 50, + blue: 60 + }, + maxParticles: 20000, + lifespan: 1.5, + emitRate: 10000, + emitSpeed: .1, + speedSpread: 0.0, + emitDimensions: { + x: 0.1, + y: 0.01, + z: 0.1 + }, + emitAcceleration: { + x: 0.0, + y: -1.0, + z: 0 + }, + polarFinish: Math.PI, + accelerationSpread: { + x: 0.1, + y: 0.0, + z: 0.1 + }, + particleRadius: 0.04, + radiusSpread: 0.01, + radiusStart: 0.03, + alpha: 0.9, + alphaSpread: .1, + alphaStart: 0.7, + alphaFinish: 0.5, + textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png", + }); + + }, + + + unload: function() { + Entities.deleteEntity(_this.waterEffect); + } + + }; + + // entity scripts always need to return a newly constructed object of our type + return new WaterCan(); +}); \ No newline at end of file diff --git a/examples/homeContent/plant/waterHoseEntityScript.js b/examples/homeContent/plant/waterHoseEntityScript.js deleted file mode 100644 index 423c547423..0000000000 --- a/examples/homeContent/plant/waterHoseEntityScript.js +++ /dev/null @@ -1,176 +0,0 @@ -// -// waterHoseEntityScript.js -// examples/homeContent/plant -// -// Created by Eric Levin on 2/15/16. -// Copyright 2016 High Fidelity, Inc. -// -// This entity script handles the logic for spraying water when a user holds down the trigger -// 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"); - - var _this; - WaterHose = function() { - _this = this; - this.potName = "plant pot"; - _this.potSearchRadius = 5; - _this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav"); - - }; - - WaterHose.prototype = { - - clickDownOnEntity: function() { - // search for a pot with some seeds nearby - _this.startWatering(); - - }, - - startFarTrigger: function() { - _this.startWatering(); - }, - - continueFarTrigger: function() { - _this.continueWatering(); - }, - - stopFarTrigger : function() { - _this.stopWatering(); - }, - - startNearTrigger: function() { - _this.startWatering(); - }, - - continueNearTrigger: function() { - _this.continueWatering(); - }, - - stopNearTrigger : function() { - _this.stopWatering(); - }, - - holdingClickOnEntity: function() { - _this.continueWatering(); - }, - - clickReleaseOnEntity: function() { - _this.stopWatering(); - }, - - startWatering: function() { - _this.waterInjector = Audio.playSound(_this.waterSound, { - position: _this.position, - volume: 0.3, - loop: true - }); - Entities.editEntity(_this.waterEffect, { - isEmitting: true - }); - var entities = Entities.findEntities(this.position, _this.potSearchRadius); - entities.forEach(function(entity) { - var name = Entities.getEntityProperties(entity, "name").name; - if (name === _this.potName) { - // We've found out potted plant to grow! - Script.setTimeout(function() { - // Wait a bit to assign the pot so the plants grow once water hits - _this.pottedPlant = entity; - }, 1500); - } - }); - - }, - continueWatering: function() { - if (!_this.pottedPlant) { - // No plant nearby to grow, so return - return; - } - Entities.callEntityMethod(_this.pottedPlant, "water"); - - }, - - stopWatering: function() { - _this.waterInjector.stop(); - Entities.editEntity(_this.waterEffect, { - isEmitting: false - }); - _this.pottedPlant = null; - }, - - preload: function(entityID) { - this.entityID = entityID; - this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); - this.position = this.props.position; - this.dimensions = this.props.dimensions; - this.createWaterEffect(); - - }, - - createWaterEffect: function() { - _this.waterEffect = Entities.addEntity({ - type: "ParticleEffect", - isEmitting: false, - position: _this.position, - colorStart: { - red: 0, - green: 10, - blue: 20 - }, - color: { - red: 30, - green: 30, - blue: 40 - }, - colorFinish: { - red: 50, - green: 50, - blue: 60 - }, - maxParticles: 20000, - lifespan: 1.5, - emitRate: 10000, - emitSpeed: .1, - speedSpread: 0.0, - emitDimensions: { - x: 0.1, - y: 0.01, - z: 0.1 - }, - emitAcceleration: { - x: 0.0, - y: -1.0, - z: 0 - }, - polarFinish: Math.PI, - accelerationSpread: { - x: 0.1, - y: 0.0, - z: 0.1 - }, - particleRadius: 0.04, - radiusSpread: 0.01, - radiusStart: 0.03, - alpha: 0.9, - alphaSpread: .1, - alphaStart: 0.7, - alphaFinish: 0.5, - textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png", - }); - - }, - - - unload: function() { - Entities.deleteEntity(_this.waterEffect); - } - - }; - - // entity scripts always need to return a newly constructed object of our type - return new WaterHose(); -}); \ No newline at end of file From 0015e28b959218eb34cc4eaa4a4c894bdcb3d04f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 26 Feb 2016 14:14:39 -0800 Subject: [PATCH 30/87] particle tweaks --- .../homeContent/plant/growingPlantSpawner.js | 5 +++ .../homeContent/plant/waterCanEntityScript.js | 32 ++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 53e647a1af..c539e0b37d 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -42,12 +42,17 @@ var plant = Entities.addEntity({ }); var WATER_CAN_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/waterCan.fbx"; +var WATER_CAN_SCRIPT_URL = Script.resolvePath("waterCanEntityScript.js?v2" + Math.random()); var waterCanPosition = Vec3.sum(plantPosition, Vec3.multiply(0.6, Quat.getRight(orientation))); var waterCan = Entities.addEntity({ type: "Model", shapeType: 'box', modelURL: WATER_CAN_MODEL_URL, + script: WATER_CAN_SCRIPT_URL, + dimensions: {x: 0.1859, y: 0.2762, z: 0.4115}, position: waterCanPosition, + angularDamping: 1, + damping: 1, dynamic: true }); diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 6443516524..80e5a33db6 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -24,23 +24,25 @@ WaterCan.prototype = { continueNearGrab: function() { - - } - - preload: function(entityID) { - this.entityID = entityID; - + _this.continueHolding(); }, + continueHolding: function() { + // Check rotation of water can along it's z axis. If it's beyond a threshold, then start spraying water + }, + + + createWaterEffect: function() { _this.waterEffect = Entities.addEntity({ type: "ParticleEffect", - isEmitting: false, + name: "water particle effect", + isEmitting: true, position: _this.position, colorStart: { - red: 0, - green: 10, - blue: 20 + red: 50, + green: 50, + blue: 70 }, color: { red: 30, @@ -53,7 +55,7 @@ blue: 60 }, maxParticles: 20000, - lifespan: 1.5, + lifespan: 10, emitRate: 10000, emitSpeed: .1, speedSpread: 0.0, @@ -67,6 +69,7 @@ y: -1.0, z: 0 }, + polarStart: 0, polarFinish: Math.PI, accelerationSpread: { x: 0.1, @@ -85,6 +88,13 @@ }, + preload: function(entityID) { + _this.entityID = entityID; + _this.position = Entities.getEntityProperties(_this.entityID, "position").position; + _this.createWaterEffect(); + + }, + unload: function() { Entities.deleteEntity(_this.waterEffect); From a544ffc942f4416bfd65bfff00fae7d9a0a82484 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 26 Feb 2016 14:20:40 -0800 Subject: [PATCH 31/87] not emitting right now --- examples/homeContent/plant/waterCanEntityScript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 80e5a33db6..ec6fab1cf2 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -37,7 +37,7 @@ _this.waterEffect = Entities.addEntity({ type: "ParticleEffect", name: "water particle effect", - isEmitting: true, + isEmitting: false, position: _this.position, colorStart: { red: 50, From 2cd8e088f5f9f339638d7871e8829419ee8d7c43 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 29 Feb 2016 10:36:32 -0800 Subject: [PATCH 32/87] water pouring out of can linked to angle can is held --- examples/homeContent/plant/waterCanEntityScript.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index ec6fab1cf2..b3beec7ceb 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -18,6 +18,8 @@ WaterCan = function() { _this = this; _this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav"); + _this.POUR_ANGLE_THRESHOLD = -30; + _this.waterPouring = false; }; @@ -29,6 +31,16 @@ continueHolding: function() { // Check rotation of water can along it's z axis. If it's beyond a threshold, then start spraying water + var rotation = Entities.getEntityProperties(_this.entityID, "rotation").rotation; + var pitch = Quat.safeEulerAngles(rotation).x; + if (pitch < _this.POUR_ANGLE_THRESHOLD && !_this.waterPouring) { + Entities.editEntity(_this.waterEffect, {isEmitting: true}); + _this.waterPouring = true; + } else if ( pitch > _this.POUR_ANGLE_THRESHOLD && _this.waterPouring) { + Entities.editEntity(_this.waterEffect, {isEmitting: false}); + _this.waterPouring = false; + } + print("PITCH " + pitch); }, From 00dcddd838091ed2470c4a414dc20aa21eceb88b Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 29 Feb 2016 11:44:33 -0800 Subject: [PATCH 33/87] changed to water spout entity script --- .../homeContent/plant/growingPlantSpawner.js | 16 +++++++++++++++- ...EntityScript.js => waterSpoutEntityScript.js} | 11 +++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) rename examples/homeContent/plant/{waterCanEntityScript.js => waterSpoutEntityScript.js} (94%) diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index c539e0b37d..8150246344 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -44,6 +44,7 @@ var plant = Entities.addEntity({ var WATER_CAN_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/waterCan.fbx"; var WATER_CAN_SCRIPT_URL = Script.resolvePath("waterCanEntityScript.js?v2" + Math.random()); var waterCanPosition = Vec3.sum(plantPosition, Vec3.multiply(0.6, Quat.getRight(orientation))); +var waterCanRotation = orientation; var waterCan = Entities.addEntity({ type: "Model", shapeType: 'box', @@ -53,13 +54,26 @@ var waterCan = Entities.addEntity({ position: waterCanPosition, angularDamping: 1, damping: 1, - dynamic: true + dynamic: true, + rotation: waterCanRotation +}); + + +var waterSpoutPosition = Vec3.sum(waterCanPosition, Vec3.multiply(0.2, Quat.getFront(orientation))) +var waterSpout = Entities.addEntity({ + type: "Box", + dimensions: {x: 0.02, y: 0.02, z: 0.07}, + color: {red: 200, green: 10, blue: 200}, + position: waterSpoutPosition, + rotation: waterCanRotation, + parentID: waterCan }); function cleanup() { Entities.deleteEntity(plant); Entities.deleteEntity(bowl); Entities.deleteEntity(waterCan); + Entities.deleteEntity(waterSpout); } diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterSpoutEntityScript.js similarity index 94% rename from examples/homeContent/plant/waterCanEntityScript.js rename to examples/homeContent/plant/waterSpoutEntityScript.js index b3beec7ceb..80bf94a5b5 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterSpoutEntityScript.js @@ -1,5 +1,5 @@ // -// waterCanEntityScript.js +// waterSpoutEntityScript.js // examples/homeContent/plant // // Created by Eric Levin on 2/15/16. @@ -15,7 +15,7 @@ Script.include("../../libraries/utils.js"); var _this; - WaterCan = function() { + WaterSpout = function() { _this = this; _this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav"); _this.POUR_ANGLE_THRESHOLD = -30; @@ -23,7 +23,10 @@ }; - WaterCan.prototype = { + WaterSpout.prototype = { + continueEquip: function() { + _this.continueHolding(); + }, continueNearGrab: function() { _this.continueHolding(); @@ -115,5 +118,5 @@ }; // entity scripts always need to return a newly constructed object of our type - return new WaterCan(); + return new WaterSpout(); }); \ No newline at end of file From 03ae48d4657fd24114b142f1933597fa74e84f1a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 29 Feb 2016 11:53:26 -0800 Subject: [PATCH 34/87] going to find water spout from water can --- .../{waterSpoutEntityScript.js => waterCanEntityScript.js} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename examples/homeContent/plant/{waterSpoutEntityScript.js => waterCanEntityScript.js} (99%) diff --git a/examples/homeContent/plant/waterSpoutEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js similarity index 99% rename from examples/homeContent/plant/waterSpoutEntityScript.js rename to examples/homeContent/plant/waterCanEntityScript.js index 80bf94a5b5..cde2dd8b7c 100644 --- a/examples/homeContent/plant/waterSpoutEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -1,5 +1,5 @@ // -// waterSpoutEntityScript.js +// waterCanEntityScript.js // examples/homeContent/plant // // Created by Eric Levin on 2/15/16. From b301b71c7d9ab8a76325184319fc36a02dbb7e61 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 29 Feb 2016 15:06:28 -0800 Subject: [PATCH 35/87] cast ray from spout in its direction --- .../homeContent/plant/growingPlantSpawner.js | 4 +- .../homeContent/plant/waterCanEntityScript.js | 53 ++++++++++++++----- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 8150246344..c381a122ba 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -60,12 +60,14 @@ var waterCan = Entities.addEntity({ var waterSpoutPosition = Vec3.sum(waterCanPosition, Vec3.multiply(0.2, Quat.getFront(orientation))) +var waterSpoutRotation = Quat.multiply(waterCanRotation, Quat.fromPitchYawRollDegrees(30, 0, 0)); var waterSpout = Entities.addEntity({ type: "Box", + name: "hifi-water-spout", dimensions: {x: 0.02, y: 0.02, z: 0.07}, color: {red: 200, green: 10, blue: 200}, position: waterSpoutPosition, - rotation: waterCanRotation, + rotation: waterSpoutRotation, parentID: waterCan }); diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index cde2dd8b7c..0ad2a5758e 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -20,6 +20,7 @@ _this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav"); _this.POUR_ANGLE_THRESHOLD = -30; _this.waterPouring = false; + _this.WATER_SPOUT_NAME = "hifi-water-spout"; }; @@ -33,6 +34,9 @@ }, continueHolding: function() { + if (!_this.waterSpout) { + return; + } // Check rotation of water can along it's z axis. If it's beyond a threshold, then start spraying water var rotation = Entities.getEntityProperties(_this.entityID, "rotation").rotation; var pitch = Quat.safeEulerAngles(rotation).x; @@ -43,7 +47,7 @@ Entities.editEntity(_this.waterEffect, {isEmitting: false}); _this.waterPouring = false; } - print("PITCH " + pitch); + // print("PITCH " + pitch); }, @@ -52,8 +56,9 @@ _this.waterEffect = Entities.addEntity({ type: "ParticleEffect", name: "water particle effect", + position: _this.waterSpoutPosition, isEmitting: false, - position: _this.position, + parentID: _this.waterSpout, colorStart: { red: 50, green: 50, @@ -70,27 +75,28 @@ blue: 60 }, maxParticles: 20000, - lifespan: 10, - emitRate: 10000, - emitSpeed: .1, + lifespan: 2, + emitRate: 1000, + emitSpeed: .2, speedSpread: 0.0, emitDimensions: { - x: 0.1, - y: 0.01, - z: 0.1 + x: 0, + y: 0, + z: 0 }, emitAcceleration: { x: 0.0, - y: -1.0, + y: 0, z: 0 }, polarStart: 0, - polarFinish: Math.PI, + polarFinish: .2, accelerationSpread: { - x: 0.1, + x: 0.01, y: 0.0, - z: 0.1 + z: 0.01 }, + emitOrientation: _this.waterSpoutRotation, particleRadius: 0.04, radiusSpread: 0.01, radiusStart: 0.03, @@ -98,7 +104,8 @@ alphaSpread: .1, alphaStart: 0.7, alphaFinish: 0.5, - textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png", + emitterShouldTrail: true, + textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png?v2", }); }, @@ -106,7 +113,25 @@ preload: function(entityID) { _this.entityID = entityID; _this.position = Entities.getEntityProperties(_this.entityID, "position").position; - _this.createWaterEffect(); + + // Wait a a bit for spout to spawn for case where preload is initial spawn, then save it + Script.setTimeout(function() { + var entities = Entities.findEntities(_this.position, 1); + entities.forEach (function(entity) { + var name = Entities.getEntityProperties(entity, "name").name; + if (name === _this.WATER_SPOUT_NAME) { + _this.waterSpout = entity; + + } + }); + + if (_this.waterSpout) { + _this.waterSpoutPosition = Entities.getEntityProperties(_this.waterSpout, "position").position; + _this.waterSpoutRotation = Entities.getEntityProperties(_this.waterSpout, "rotation").rotation; + _this.createWaterEffect(); + } + + }, 3000); }, From 0d9a8b22c84f31e3b1d8d702802b1675aeba5d14 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 29 Feb 2016 15:48:56 -0800 Subject: [PATCH 36/87] water flowing in ray direction --- .../homeContent/plant/waterCanEntityScript.js | 56 +++++++++++++++---- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 0ad2a5758e..529c86f31a 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -18,7 +18,7 @@ WaterSpout = function() { _this = this; _this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav"); - _this.POUR_ANGLE_THRESHOLD = -30; + _this.POUR_ANGLE_THRESHOLD = -10; _this.waterPouring = false; _this.WATER_SPOUT_NAME = "hifi-water-spout"; @@ -38,18 +38,40 @@ return; } // Check rotation of water can along it's z axis. If it's beyond a threshold, then start spraying water + _this.updateRayLine(); var rotation = Entities.getEntityProperties(_this.entityID, "rotation").rotation; var pitch = Quat.safeEulerAngles(rotation).x; - if (pitch < _this.POUR_ANGLE_THRESHOLD && !_this.waterPouring) { - Entities.editEntity(_this.waterEffect, {isEmitting: true}); - _this.waterPouring = true; - } else if ( pitch > _this.POUR_ANGLE_THRESHOLD && _this.waterPouring) { - Entities.editEntity(_this.waterEffect, {isEmitting: false}); + if (pitch < _this.POUR_ANGLE_THRESHOLD) { + if (!_this.waterPouring) { + Entities.editEntity(_this.waterEffect, { + isEmitting: true + }); + _this.waterPouring = true; + } + _this.waterSpoutRotation = Entities.getEntityProperties(_this.waterSpout, "rotation").rotation; + var waterEmitOrientation = Quat.multiply(_this.waterSpoutRotation, Quat.fromPitchYawRollDegrees(0, 180, 0)); + Entities.editEntity(_this.waterEffect, { + emitOrientation: waterEmitOrientation + }); + } else if (pitch > _this.POUR_ANGLE_THRESHOLD && _this.waterPouring) { + Entities.editEntity(_this.waterEffect, { + isEmitting: false + }); _this.waterPouring = false; } // print("PITCH " + pitch); }, + updateRayLine: function() { + var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["position, rotation"]); + var end = Vec3.sum(spoutProps.position, Vec3.multiply(10, Quat.getFront(spoutProps.rotation))); + Overlays.editOverlay(_this.rayCastLine, { + start: spoutProps.position, + end: end + }); + print("EBL ray line " + JSON.stringify(_this.rayCastLine)) + }, + createWaterEffect: function() { @@ -96,7 +118,7 @@ y: 0.0, z: 0.01 }, - emitOrientation: _this.waterSpoutRotation, + emitOrientation: Quat.fromPitchYawRollDegrees(0, 180, 0), particleRadius: 0.04, radiusSpread: 0.01, radiusStart: 0.03, @@ -113,22 +135,31 @@ preload: function(entityID) { _this.entityID = entityID; _this.position = Entities.getEntityProperties(_this.entityID, "position").position; - + _this.rayCastLine = Overlays.addOverlay("line3d", { + color: { + red: 200, + green: 10, + blue: 200 + }, + lineWidth: 1, + alpha: 1, + visible: true, + ignoreRayIntersection: true + }); // Wait a a bit for spout to spawn for case where preload is initial spawn, then save it - Script.setTimeout(function() { + Script.setTimeout(function() { var entities = Entities.findEntities(_this.position, 1); - entities.forEach (function(entity) { + entities.forEach(function(entity) { var name = Entities.getEntityProperties(entity, "name").name; if (name === _this.WATER_SPOUT_NAME) { _this.waterSpout = entity; - } }); if (_this.waterSpout) { _this.waterSpoutPosition = Entities.getEntityProperties(_this.waterSpout, "position").position; _this.waterSpoutRotation = Entities.getEntityProperties(_this.waterSpout, "rotation").rotation; - _this.createWaterEffect(); + _this.createWaterEffect(); } }, 3000); @@ -137,6 +168,7 @@ unload: function() { + Overlays.deleteOverlay(_this.rayCastLine); Entities.deleteEntity(_this.waterEffect); } From def0df9bff85ba26813c9e887136ec8e4f861798 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 29 Feb 2016 16:59:03 -0800 Subject: [PATCH 37/87] intersection with growable object --- .../homeContent/plant/growingPlantSpawner.js | 2 +- .../homeContent/plant/waterCanEntityScript.js | 33 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index c381a122ba..dbec22254b 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -35,7 +35,7 @@ var plantPosition = Vec3.sum(bowlPosition, {x: 0, y: plantDimensions.y/2, z: 0}) var plant = Entities.addEntity({ type: "Model", modelURL: PLANT_MODEL_URL, - name: "plant", + name: "hifi-growable-plant", dimensions: plantDimensions, position: plantPosition, parentID: bowl diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 529c86f31a..d3f4672983 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -38,7 +38,7 @@ return; } // Check rotation of water can along it's z axis. If it's beyond a threshold, then start spraying water - _this.updateRayLine(); + _this.castRay(); var rotation = Entities.getEntityProperties(_this.entityID, "rotation").rotation; var pitch = Quat.safeEulerAngles(rotation).x; if (pitch < _this.POUR_ANGLE_THRESHOLD) { @@ -62,14 +62,26 @@ // print("PITCH " + pitch); }, - updateRayLine: function() { + castRay: function() { var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["position, rotation"]); - var end = Vec3.sum(spoutProps.position, Vec3.multiply(10, Quat.getFront(spoutProps.rotation))); + var direction = Quat.getFront(spoutProps.rotation) + var end = Vec3.sum(spoutProps.position, Vec3.multiply(10, direction)); Overlays.editOverlay(_this.rayCastLine, { start: spoutProps.position, end: end }); - print("EBL ray line " + JSON.stringify(_this.rayCastLine)) + + var pickRay = { + origin: spoutProps.position, + direction: direction + }; + var intersection = Entities.findRayIntersection(pickRay, true, _this.growableEntities); + + if (intersection.intersects) { + print(intersection.properties.name) + print("intersection with growable object"); + } + }, @@ -132,6 +144,18 @@ }, + findGrowableEntities: function() { + _this.growableEntities = []; + var entities = Entities.findEntities(_this.position, 50); + entities.forEach( function(entity) { + var name = Entities.getEntityProperties(entity, "name").name; + if (name.length > 0 && name.indexOf("growable") !== -1) { + _this.growableEntities.push(entity); + } + }); + + }, + preload: function(entityID) { _this.entityID = entityID; _this.position = Entities.getEntityProperties(_this.entityID, "position").position; @@ -146,6 +170,7 @@ visible: true, ignoreRayIntersection: true }); + _this.findGrowableEntities(); // Wait a a bit for spout to spawn for case where preload is initial spawn, then save it Script.setTimeout(function() { var entities = Entities.findEntities(_this.position, 1); From cf891ef5d919acc15761a50b2a8f5256de37f5e1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 29 Feb 2016 18:22:12 -0800 Subject: [PATCH 38/87] ray casting works --- .../plant/growingPlantEntityScript.js | 102 ++---------------- .../homeContent/plant/growingPlantSpawner.js | 1 + .../homeContent/plant/waterCanEntityScript.js | 2 + 3 files changed, 11 insertions(+), 94 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index e992899b22..9d4f42b191 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -17,113 +17,27 @@ var _this; GrowingPlant = function() { _this = this; - _this.flowers = []; - _this.delay = 1000; - _this.MAX_CACTUS_Y_DIMENSION = 0.7; - _this.GROW_RATE = 0.001; + }; GrowingPlant.prototype = { - water: function() { - _this.cactusDimensions = Vec3.sum(_this.cactusDimensions, {x: 0, y: _this.GROW_RATE, z: 0}); - - if (_this.cactusDimensions.y > _this.MAX_CACTUS_Y_DIMENSION) { - // We don't want to grow our cactus any more than this or it will look bad - return; - } - // Need to raise up cactus as it stretches so it doesnt burst out the bottom of the plant - _this.cactusPosition = Vec3.sum(_this.cactusPosition, {x: 0, y: _this.cactusHeightMovement * 0.1, z: 0}); - Entities.editEntity(_this.cactus, {dimensions: _this.cactusDimensions, position: _this.cactusPosition}); - - _this.flowers.forEach(_this.waterFlower); - }, - - waterFlower: function(flower) { - var props = Entities.getEntityProperties(flower, ["position, dimensions"]); - var newDimensions = Vec3.sum(props.dimensions, {x: randFloat(0, 0.0001), y: 0.001, z: randFloat(0, 0.0001)}); - var newPosition = Vec3.sum(props.position, {x: 0, y: _this.flowerHeightMovement * 0.55, z: 0}); - Entities.editEntity(flower, {dimensions: newDimensions, position: newPosition}); - }, - - createFlowers: function() { - var size = 0.1; - var NUM_FLOWERS = 20 - _this.startingFlowerDimensions = { - x: size, - y: 0.001, - z: size - }; - _this.flowerHeightMovement = _this.startingFlowerDimensions.y; - for (var i = 0; i < NUM_FLOWERS; i++) { - var segment = i / NUM_FLOWERS * Math.PI * 2; - var radius = randFloat(0.13, 0.25); - var position = Vec3.sum(_this.position, { - x: radius * Math.cos(segment), - y: 0.16, - z: radius * Math.sin(segment) - }); - _this.createFlower(position); - } - }, - - createFlower: function(position) { - - var flowerUserData = { - ProceduralEntity: { - shaderUrl: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs", - uniforms: { - iBloomPct: randFloat(0.4, 0.8), - hueTwerking: randFloat(10, 30) - } - } - }; - var flower = Entities.addEntity({ - type: "Sphere", - name: "flower", - position: position, - dimensions: _this.startingFlowerDimensions, - userData: JSON.stringify(flowerUserData) - }); - _this.flowers.push(flower); - - }, - - createCactus: function() { - var MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/cactus.fbx" - _this.cactusDimensions = { - x: 0.09, - y: 0.01, - z: 0.09 - }; - _this.cactusHeightMovement = _this.cactusDimensions.y/2; - _this.cactusPosition = _this.position; - _this.cactus = Entities.addEntity({ - type: "Model", - modelURL: MODEL_URL, - name: "cactus", - position: _this.cactusPosition, - dimensions: _this.cactusDimensions - }); + grow: function() { + print(" I AM BEING GROWN RIGHT NOW") }, preload: function(entityID) { - this.entityID = entityID; - this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]); - this.position = this.props.position; - this.dimensions = this.props.dimensions; - this.createCactus(); - this.createFlowers(); + _this.entityID = entityID; + + }, unload: function() { - Entities.deleteEntity(_this.cactus); - _this.flowers.forEach(function(flower) { - Entities.deleteEntity(flower); - }); + + } }; diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index dbec22254b..27a7a44255 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -38,6 +38,7 @@ var plant = Entities.addEntity({ name: "hifi-growable-plant", dimensions: plantDimensions, position: plantPosition, + script: PLANT_SCRIPT_URL, parentID: bowl }); diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index d3f4672983..c197c35665 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -78,8 +78,10 @@ var intersection = Entities.findRayIntersection(pickRay, true, _this.growableEntities); if (intersection.intersects) { + //We've intersected with a growable object, now print(intersection.properties.name) print("intersection with growable object"); + Entities.callEntityMethod(intersection.entityID, 'grow'); } }, From 17dec9446abd2b334806967388820bb409f14f44 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 4 Mar 2016 16:15:37 -0800 Subject: [PATCH 39/87] flowers are growing when watered --- .../plant/growingPlantEntityScript.js | 58 ++++++++++++++++--- .../homeContent/plant/growingPlantSpawner.js | 6 +- .../homeContent/plant/waterCanEntityScript.js | 8 +-- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 9d4f42b191..89b84f3ffb 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -17,27 +17,71 @@ var _this; GrowingPlant = function() { _this = this; + _this.flowers = []; + // _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1} + _this.STARTING_FLOWER_DIMENSIONS = {x: 0.01, y: 0.01, z: 0.02} }; GrowingPlant.prototype = { - grow: function() { - print(" I AM BEING GROWN RIGHT NOW") + continueWatering: function(entityID, data) { + // we're being watered- every now and then spawn a new flower to add to our growing list + // If we don't have any flowers yet, immediately grow one + var data = JSON.parse(data[0]); + if (_this.flowers.length < 10) { + + _this.createFlower(data.position, data.surfaceNormal); + } + + _this.flowers.forEach( function(flower) { + flower.grow(); + }); + + + }, + + createFlower: function(position, surfaceNormal) { + var flowerRotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, surfaceNormal); + print("flower rotation " + flowerRotation.x) + var flowerEntityID = Entities.addEntity({ + type: "Sphere", + name: "flower", + position: position, + rotation: flowerRotation, + dimensions: _this.STARTING_FLOWER_DIMENSIONS, + // userData: JSON.stringify(_this.flowerUserData) + }); + + var flower = {id: flowerEntityID, dimensions: _this.STARTING_FLOWER_DIMENSIONS}; + flower.grow = function() { + // grow flower a bit + flower.dimensions.z += 0.0001; + Entities.editEntity(flower.id, {dimensions: flower.dimensions}); + } + _this.flowers.push(flower); }, preload: function(entityID) { _this.entityID = entityID; - - + _this.flowerUserData = { + ProceduralEntity: { + shaderUrl: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs", + uniforms: { + iBloomPct: randFloat(0.4, 0.8), + hueTwerking: randFloat(10, 30) + } + } + }; }, - - unload: function() { + _this.flowers.forEach(function(flower) { + Entities.deleteEntity(flower.id); + }) + - } }; diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 27a7a44255..37339e1bcb 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -29,7 +29,7 @@ var bowl= Entities.addEntity({ var PLANT_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Flowers--Moss-Rock.fbx"; -var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js"); +var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js?v1" + Math.random().toFixed(2)); var plantDimensions = {x: 0.52, y: 0.2600, z: 0.52}; var plantPosition = Vec3.sum(bowlPosition, {x: 0, y: plantDimensions.y/2, z: 0}); var plant = Entities.addEntity({ @@ -42,8 +42,8 @@ var plant = Entities.addEntity({ parentID: bowl }); -var WATER_CAN_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/waterCan.fbx"; -var WATER_CAN_SCRIPT_URL = Script.resolvePath("waterCanEntityScript.js?v2" + Math.random()); +var WATER_CAN_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/waterCan.fbx?v1" + Math.random(); +var WATER_CAN_SCRIPT_URL = Script.resolvePath("waterCanEntityScript.js?v2" + Math.random().toFixed()); var waterCanPosition = Vec3.sum(plantPosition, Vec3.multiply(0.6, Quat.getRight(orientation))); var waterCanRotation = orientation; var waterCan = Entities.addEntity({ diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index c197c35665..5c89010386 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -59,7 +59,6 @@ }); _this.waterPouring = false; } - // print("PITCH " + pitch); }, castRay: function() { @@ -78,10 +77,9 @@ var intersection = Entities.findRayIntersection(pickRay, true, _this.growableEntities); if (intersection.intersects) { - //We've intersected with a growable object, now - print(intersection.properties.name) - print("intersection with growable object"); - Entities.callEntityMethod(intersection.entityID, 'grow'); + //We've intersected with a waterable object + var data = JSON.stringify({position: intersection.intersection, surfaceNormal: intersection.surfaceNormal}); + Entities.callEntityMethod(intersection.entityID, 'continueWatering', [data]); } }, From ef437b7f99b695304d0206af88c63ca9ccd04204 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 4 Mar 2016 16:48:55 -0800 Subject: [PATCH 40/87] flowers staying in place --- .../plant/growingPlantEntityScript.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 89b84f3ffb..63bd60023b 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -19,7 +19,7 @@ _this = this; _this.flowers = []; // _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1} - _this.STARTING_FLOWER_DIMENSIONS = {x: 0.01, y: 0.01, z: 0.02} + _this.STARTING_FLOWER_DIMENSIONS = {x: 0.2, y: 0.01, z: 0.2} }; @@ -30,7 +30,7 @@ // we're being watered- every now and then spawn a new flower to add to our growing list // If we don't have any flowers yet, immediately grow one var data = JSON.parse(data[0]); - if (_this.flowers.length < 10) { + if (_this.flowers.length < 1000) { _this.createFlower(data.position, data.surfaceNormal); } @@ -43,7 +43,7 @@ }, createFlower: function(position, surfaceNormal) { - var flowerRotation = Quat.rotationBetween(Vec3.UNIT_NEG_Z, surfaceNormal); + var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal); print("flower rotation " + flowerRotation.x) var flowerEntityID = Entities.addEntity({ type: "Sphere", @@ -51,14 +51,16 @@ position: position, rotation: flowerRotation, dimensions: _this.STARTING_FLOWER_DIMENSIONS, - // userData: JSON.stringify(_this.flowerUserData) + userData: JSON.stringify(_this.flowerUserData) }); - var flower = {id: flowerEntityID, dimensions: _this.STARTING_FLOWER_DIMENSIONS}; + var flower = {id: flowerEntityID, dimensions: _this.STARTING_FLOWER_DIMENSIONS, startingPosition: position, rotation: flowerRotation}; flower.grow = function() { // grow flower a bit - flower.dimensions.z += 0.0001; - Entities.editEntity(flower.id, {dimensions: flower.dimensions}); + flower.dimensions.y += 0.001; + flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y/2)); + //As we grow we must also move ourselves in direction we grow! + Entities.editEntity(flower.id, {dimensions: flower.dimensions, position: flower.position}); } _this.flowers.push(flower); }, From 3ad2d1aa9bf3d3571cfd27345e7440a57d586368 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 4 Mar 2016 17:32:29 -0800 Subject: [PATCH 41/87] flowers spawning and growing correctly --- .../plant/growingPlantEntityScript.js | 36 ++++++++++++++----- .../homeContent/plant/growingPlantSpawner.js | 1 + .../homeContent/plant/waterCanEntityScript.js | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 63bd60023b..0849a3931b 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -19,7 +19,11 @@ _this = this; _this.flowers = []; // _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1} - _this.STARTING_FLOWER_DIMENSIONS = {x: 0.2, y: 0.01, z: 0.2} + _this.STARTING_FLOWER_DIMENSIONS = { + x: 0.1, + y: 0.01, + z: 0.1 + } }; @@ -30,13 +34,13 @@ // we're being watered- every now and then spawn a new flower to add to our growing list // If we don't have any flowers yet, immediately grow one var data = JSON.parse(data[0]); - if (_this.flowers.length < 1000) { + if (_this.flowers.length < 1000) { _this.createFlower(data.position, data.surfaceNormal); } - _this.flowers.forEach( function(flower) { - flower.grow(); + _this.flowers.forEach(function(flower) { + flower.grow(); }); @@ -44,23 +48,37 @@ createFlower: function(position, surfaceNormal) { var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal); - print("flower rotation " + flowerRotation.x) var flowerEntityID = Entities.addEntity({ type: "Sphere", name: "flower", position: position, + collisionless: true, rotation: flowerRotation, dimensions: _this.STARTING_FLOWER_DIMENSIONS, userData: JSON.stringify(_this.flowerUserData) }); - var flower = {id: flowerEntityID, dimensions: _this.STARTING_FLOWER_DIMENSIONS, startingPosition: position, rotation: flowerRotation}; + var flower = { + id: flowerEntityID, + dimensions: {x: _this.STARTING_FLOWER_DIMENSIONS.x, y: _this.STARTING_FLOWER_DIMENSIONS.y, z: _this.STARTING_FLOWER_DIMENSIONS.z}, + startingPosition: position, + rotation: flowerRotation, + maxYDimension: randFloat(0.2, 1.5), + growthRate: randFloat(0.0001, 0.001) + }; + print(_this.STARTING_FLOWER_DIMENSIONS.y) flower.grow = function() { // grow flower a bit - flower.dimensions.y += 0.001; - flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y/2)); + if (flower.dimensions.y > flower.maxYDimension) { + return; + } + flower.dimensions.y += flower.growthRate; + flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y / 2)); //As we grow we must also move ourselves in direction we grow! - Entities.editEntity(flower.id, {dimensions: flower.dimensions, position: flower.position}); + Entities.editEntity(flower.id, { + dimensions: flower.dimensions, + position: flower.position + }); } _this.flowers.push(flower); }, diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index 37339e1bcb..f62ffdc8fe 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -49,6 +49,7 @@ var waterCanRotation = orientation; var waterCan = Entities.addEntity({ type: "Model", shapeType: 'box', + name: "hifi-water-can", modelURL: WATER_CAN_MODEL_URL, script: WATER_CAN_SCRIPT_URL, dimensions: {x: 0.1859, y: 0.2762, z: 0.4115}, diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 5c89010386..63841d08d4 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -165,7 +165,7 @@ green: 10, blue: 200 }, - lineWidth: 1, + lineWidth: 2, alpha: 1, visible: true, ignoreRayIntersection: true From 65c8f7cc45d9839671d6c71c7007af2c4149e366 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 4 Mar 2016 17:55:45 -0800 Subject: [PATCH 42/87] flowers growing --- .../plant/growingPlantEntityScript.js | 23 +++++++++++++------ .../homeContent/plant/waterCanEntityScript.js | 9 ++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 0849a3931b..4664a710f8 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -20,11 +20,14 @@ _this.flowers = []; // _this.STARTING_FLOWER_DIMENSIONS = {x: 0.1, y: 0.001, z: 0.1} _this.STARTING_FLOWER_DIMENSIONS = { - x: 0.1, - y: 0.01, - z: 0.1 + x: 0.001, + y: 0.001, + z: 0.001 } + _this.debounceRange = {min: 500, max: 1000}; + _this.canCreateFlower = true; + }; GrowingPlant.prototype = { @@ -34,9 +37,14 @@ // we're being watered- every now and then spawn a new flower to add to our growing list // If we don't have any flowers yet, immediately grow one var data = JSON.parse(data[0]); - if (_this.flowers.length < 1000) { - _this.createFlower(data.position, data.surfaceNormal); + if(_this.canCreateFlower) { + _this.createFlower(data.position, data.surfaceNormal); + _this.canCreateFlower = false; + Script.setTimeout(function() { + _this.canCreateFlower = true; + }, randFloat(_this.debounceRange.min, this.debounceRange.max)); + } _this.flowers.forEach(function(flower) { @@ -44,6 +52,7 @@ }); + }, createFlower: function(position, surfaceNormal) { @@ -64,7 +73,7 @@ startingPosition: position, rotation: flowerRotation, maxYDimension: randFloat(0.2, 1.5), - growthRate: randFloat(0.0001, 0.001) + growthRate: {x: 0.0002, y: 0.001, z: 0.0002} }; print(_this.STARTING_FLOWER_DIMENSIONS.y) flower.grow = function() { @@ -72,7 +81,7 @@ if (flower.dimensions.y > flower.maxYDimension) { return; } - flower.dimensions.y += flower.growthRate; + flower.dimensions = Vec3.sum(flower.dimensions, flower.growthRate); flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y / 2)); //As we grow we must also move ourselves in direction we grow! Entities.editEntity(flower.id, { diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 63841d08d4..0734b98885 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -64,7 +64,7 @@ castRay: function() { var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["position, rotation"]); var direction = Quat.getFront(spoutProps.rotation) - var end = Vec3.sum(spoutProps.position, Vec3.multiply(10, direction)); + var end = Vec3.sum(spoutProps.position, Vec3.multiply(5, direction)); Overlays.editOverlay(_this.rayCastLine, { start: spoutProps.position, end: end @@ -131,9 +131,10 @@ z: 0.01 }, emitOrientation: Quat.fromPitchYawRollDegrees(0, 180, 0), - particleRadius: 0.04, - radiusSpread: 0.01, - radiusStart: 0.03, + particleRadius: 0.01, + radiusSpread: 0.001, + radiusStart: 0.01, + radiusFinish: 0.01, alpha: 0.9, alphaSpread: .1, alphaStart: 0.7, From cdd4fdb03e263f9a14ed7793d0c44a4f74a109ea Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 7 Mar 2016 14:04:45 -0800 Subject: [PATCH 43/87] slower growth --- examples/homeContent/plant/flower.fs | 9 ++-- .../plant/growingPlantEntityScript.js | 50 +++++++++++++------ .../homeContent/plant/growingPlantSpawner.js | 5 +- .../homeContent/plant/waterCanEntityScript.js | 35 ++++++++----- 4 files changed, 67 insertions(+), 32 deletions(-) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs index c2b02c13e0..d6dc310e85 100644 --- a/examples/homeContent/plant/flower.fs +++ b/examples/homeContent/plant/flower.fs @@ -3,7 +3,8 @@ #define TWO_PI 6.28318530718 uniform float iBloomPct = 0.2; -uniform float hueTwerking = 10.0; +uniform float hueAngleRange = 20.0; +uniform float hueOffset = 0.5; vec3 hsb2rgb( in vec3 c ){ @@ -30,9 +31,9 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { } // simulate ambient occlusion - float brightness = pow(radius, 0.7); - float hueOffset = sin(iGlobalTime * 0.07) + hueTwerking; - color = hsb2rgb(vec3( abs(angle/hueTwerking) + hueOffset, 0.8, brightness)); + float brightness = pow(radius, 0.8); + float hueTimeOffset = sin(iGlobalTime * 0.01) + hueOffset; + color = hsb2rgb(vec3( abs(angle/hueAngleRange) + hueTimeOffset, 0.7, brightness)); fragColor = vec4(color, 1.0); diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index 4664a710f8..d9d1d5bf2c 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -25,7 +25,13 @@ z: 0.001 } - _this.debounceRange = {min: 500, max: 1000}; + _this.MAX_FLOWERS = 50; + _this.MIN_FLOWER_TO_FLOWER_DISTANCE = 0.03; + + _this.debounceRange = { + min: 500, + max: 1000 + }; _this.canCreateFlower = true; }; @@ -38,13 +44,13 @@ // If we don't have any flowers yet, immediately grow one var data = JSON.parse(data[0]); - if(_this.canCreateFlower) { - _this.createFlower(data.position, data.surfaceNormal); - _this.canCreateFlower = false; - Script.setTimeout(function() { + if (_this.canCreateFlower && _this.flowers.length < _this.MAX_FLOWERS) { + _this.createFlower(data.position, data.surfaceNormal); + _this.canCreateFlower = false; + Script.setTimeout(function() { _this.canCreateFlower = true; - }, randFloat(_this.debounceRange.min, this.debounceRange.max)); - + }, randFloat(_this.debounceRange.min, this.debounceRange.max)); + } _this.flowers.forEach(function(flower) { @@ -56,7 +62,13 @@ }, createFlower: function(position, surfaceNormal) { + if (_this.previousFlowerPosition && Vec3.distance(position, _this.previousFlowerPosition) < _this.MIN_FLOWER_TO_FLOWER_DISTANCE) { + // Reduces flower overlap + return; + } var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal); + _this.flowerUserData.ProceduralEntity.uniforms.hueAngleRange = randFloat(20, 40); + _this.flowerUserData.ProceduralEntity.uniforms.hueOffset = Math.random(); var flowerEntityID = Entities.addEntity({ type: "Sphere", name: "flower", @@ -66,16 +78,23 @@ dimensions: _this.STARTING_FLOWER_DIMENSIONS, userData: JSON.stringify(_this.flowerUserData) }); - + var xzGrowthRate = randFloat(0.0001, 0.0002); var flower = { id: flowerEntityID, - dimensions: {x: _this.STARTING_FLOWER_DIMENSIONS.x, y: _this.STARTING_FLOWER_DIMENSIONS.y, z: _this.STARTING_FLOWER_DIMENSIONS.z}, + dimensions: { + x: _this.STARTING_FLOWER_DIMENSIONS.x, + y: _this.STARTING_FLOWER_DIMENSIONS.y, + z: _this.STARTING_FLOWER_DIMENSIONS.z + }, startingPosition: position, rotation: flowerRotation, - maxYDimension: randFloat(0.2, 1.5), - growthRate: {x: 0.0002, y: 0.001, z: 0.0002} + maxYDimension: randFloat(0.4, 1.0), + growthRate: { + x: xzGrowthRate, + y: randFloat(0.001, 0.0025), + z: xzGrowthRate + } }; - print(_this.STARTING_FLOWER_DIMENSIONS.y) flower.grow = function() { // grow flower a bit if (flower.dimensions.y > flower.maxYDimension) { @@ -90,16 +109,19 @@ }); } _this.flowers.push(flower); + _this.previousFlowerPosition = position; }, preload: function(entityID) { _this.entityID = entityID; + var SHADER_URL = "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs" + // var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs"; _this.flowerUserData = { ProceduralEntity: { - shaderUrl: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs", + shaderUrl: SHADER_URL, uniforms: { iBloomPct: randFloat(0.4, 0.8), - hueTwerking: randFloat(10, 30) + hueTwerking: Math.random() } } }; diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index f62ffdc8fe..f00c893030 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -62,7 +62,7 @@ var waterCan = Entities.addEntity({ var waterSpoutPosition = Vec3.sum(waterCanPosition, Vec3.multiply(0.2, Quat.getFront(orientation))) -var waterSpoutRotation = Quat.multiply(waterCanRotation, Quat.fromPitchYawRollDegrees(30, 0, 0)); +var waterSpoutRotation = Quat.multiply(waterCanRotation, Quat.fromPitchYawRollDegrees(10, 0, 0)); var waterSpout = Entities.addEntity({ type: "Box", name: "hifi-water-spout", @@ -70,7 +70,8 @@ var waterSpout = Entities.addEntity({ color: {red: 200, green: 10, blue: 200}, position: waterSpoutPosition, rotation: waterSpoutRotation, - parentID: waterCan + parentID: waterCan, + visible: false }); function cleanup() { diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 0734b98885..d27309a662 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -18,7 +18,7 @@ WaterSpout = function() { _this = this; _this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav"); - _this.POUR_ANGLE_THRESHOLD = -10; + _this.POUR_ANGLE_THRESHOLD = 0; _this.waterPouring = false; _this.WATER_SPOUT_NAME = "hifi-water-spout"; @@ -42,13 +42,22 @@ var rotation = Entities.getEntityProperties(_this.entityID, "rotation").rotation; var pitch = Quat.safeEulerAngles(rotation).x; if (pitch < _this.POUR_ANGLE_THRESHOLD) { + // Water is pouring + var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["rotation", "position"]); if (!_this.waterPouring) { Entities.editEntity(_this.waterEffect, { isEmitting: true }); _this.waterPouring = true; + if (!_this.waterInjector) { + print ("PLAY SOUND") + _this.waterInjector = Audio.playSound(_this.waterSound, {position: spoutProps.position, loop: true}); + + } else { + _this.waterInjector.restart(); + } } - _this.waterSpoutRotation = Entities.getEntityProperties(_this.waterSpout, "rotation").rotation; + _this.waterSpoutRotation = spoutProps.rotation; var waterEmitOrientation = Quat.multiply(_this.waterSpoutRotation, Quat.fromPitchYawRollDegrees(0, 180, 0)); Entities.editEntity(_this.waterEffect, { emitOrientation: waterEmitOrientation @@ -58,6 +67,8 @@ isEmitting: false }); _this.waterPouring = false; + //water no longer pouring... + _this.waterInjector.stop(); } }, @@ -94,19 +105,19 @@ isEmitting: false, parentID: _this.waterSpout, colorStart: { - red: 50, - green: 50, - blue: 70 + red: 90, + green: 90, + blue: 110 }, color: { - red: 30, - green: 30, - blue: 40 + red: 70, + green: 70, + blue: 130 }, colorFinish: { - red: 50, - green: 50, - blue: 60 + red: 60, + green: 30, + blue: 140 }, maxParticles: 20000, lifespan: 2, @@ -124,7 +135,7 @@ z: 0 }, polarStart: 0, - polarFinish: .2, + polarFinish: .1, accelerationSpread: { x: 0.01, y: 0.0, From b9bd4cae932934fd490d94cde0cfef7bd6fda40f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 7 Mar 2016 14:58:59 -0800 Subject: [PATCH 44/87] better water effect --- .../homeContent/plant/waterCanEntityScript.js | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index d27309a662..348c3737a8 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -98,10 +98,11 @@ createWaterEffect: function() { + var waterEffectPosition = Vec3.sum(_this.waterSpoutPosition, Vec3.multiply(Quat.getFront(_this.waterSpoutRotation), -0.04)); _this.waterEffect = Entities.addEntity({ type: "ParticleEffect", name: "water particle effect", - position: _this.waterSpoutPosition, + position: waterEffectPosition, isEmitting: false, parentID: _this.waterSpout, colorStart: { @@ -115,41 +116,41 @@ blue: 130 }, colorFinish: { - red: 60, - green: 30, - blue: 140 + red: 23, + green: 195, + blue: 206 }, maxParticles: 20000, lifespan: 2, - emitRate: 1000, + emitRate: 2000, emitSpeed: .2, speedSpread: 0.0, emitDimensions: { - x: 0, - y: 0, - z: 0 + x: 0.0, + y: 0.0, + z: 0.0 }, emitAcceleration: { x: 0.0, y: 0, z: 0 }, - polarStart: 0, - polarFinish: .1, + polarStart: 0.0, + polarFinish: 0.1, accelerationSpread: { x: 0.01, y: 0.0, z: 0.01 }, - emitOrientation: Quat.fromPitchYawRollDegrees(0, 180, 0), - particleRadius: 0.01, - radiusSpread: 0.001, - radiusStart: 0.01, - radiusFinish: 0.01, - alpha: 0.9, - alphaSpread: .1, - alphaStart: 0.7, - alphaFinish: 0.5, + emitOrientation: Quat.fromPitchYawRollDegrees(0, 0, 0), + radiusSpread: 0.0001, + radiusStart: 0.005, + particleRadius: 0.003, + radiusFinish: 0.001, + alphaSpread: 0, + alphaStart: 0.1, + alpha: 1.0, + alphaFinish: 1.0, emitterShouldTrail: true, textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png?v2", }); @@ -207,6 +208,10 @@ unload: function() { Overlays.deleteOverlay(_this.rayCastLine); Entities.deleteEntity(_this.waterEffect); + if (_this.waterInjector) { + _this.waterInjector.stop(); + delete _this.waterInjector; + } } }; From 3dc39600cd23d5a438063f885215aa0f5a4e29bf Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 7 Mar 2016 15:32:40 -0800 Subject: [PATCH 45/87] stop pouring on release --- .../plant/growingPlantEntityScript.js | 9 +- .../homeContent/plant/growingPlantSpawner.js | 10 +-- .../homeContent/plant/waterCanEntityScript.js | 87 +++++++++++-------- 3 files changed, 63 insertions(+), 43 deletions(-) diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index d9d1d5bf2c..f0992db45a 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -78,7 +78,7 @@ dimensions: _this.STARTING_FLOWER_DIMENSIONS, userData: JSON.stringify(_this.flowerUserData) }); - var xzGrowthRate = randFloat(0.0001, 0.0002); + var xzGrowthRate = randFloat(0.00005, 0.00015); var flower = { id: flowerEntityID, dimensions: { @@ -128,9 +128,10 @@ }, unload: function() { - _this.flowers.forEach(function(flower) { - Entities.deleteEntity(flower.id); - }) + print("EBL UNLOAD GROWING PLANT SCRIPT"); + // _this.flowers.forEach(function(flower) { + // Entities.deleteEntity(flower.id); + // }) } diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index f00c893030..b9f0ef147d 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -55,8 +55,8 @@ var waterCan = Entities.addEntity({ dimensions: {x: 0.1859, y: 0.2762, z: 0.4115}, position: waterCanPosition, angularDamping: 1, - damping: 1, dynamic: true, + gravity: { x: 0.0, y: -2.0, z: 0}, rotation: waterCanRotation }); @@ -75,10 +75,10 @@ var waterSpout = Entities.addEntity({ }); function cleanup() { - Entities.deleteEntity(plant); - Entities.deleteEntity(bowl); - Entities.deleteEntity(waterCan); - Entities.deleteEntity(waterSpout); + // Entities.deleteEntity(plant); + // Entities.deleteEntity(bowl); + // Entities.deleteEntity(waterCan); + // Entities.deleteEntity(waterSpout); } diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 348c3737a8..2817524ab0 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -21,10 +21,45 @@ _this.POUR_ANGLE_THRESHOLD = 0; _this.waterPouring = false; _this.WATER_SPOUT_NAME = "hifi-water-spout"; + _this.GROWABLE_ENTITIES_SEARCH_RANGE = 100; }; WaterSpout.prototype = { + + startNearGrab: function() { + _this.startHold(); + }, + + startEquip: function() { + _this.startHold(); + }, + + startHold: function() { + _this.findGrowableEntities(); + print("EB: GROWABLE ENTITIES length " + _this.growableEntities.length) + }, + + releaseEquip: function() { + _this.releaseHold(); + }, + + releaseGrab: function() { + _this.releaseHold(); + }, + + releaseHold: function() { + _this.stopPouring(); + }, + + stopPouring: function() { + Entities.editEntity(_this.waterEffect, { + isEmitting: false + }); + _this.waterPouring = false; + //water no longer pouring... + _this.waterInjector.stop(); + }, continueEquip: function() { _this.continueHolding(); }, @@ -43,16 +78,19 @@ var pitch = Quat.safeEulerAngles(rotation).x; if (pitch < _this.POUR_ANGLE_THRESHOLD) { // Water is pouring - var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["rotation", "position"]); + var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["rotation", "position"]); if (!_this.waterPouring) { Entities.editEntity(_this.waterEffect, { isEmitting: true }); _this.waterPouring = true; if (!_this.waterInjector) { - print ("PLAY SOUND") - _this.waterInjector = Audio.playSound(_this.waterSound, {position: spoutProps.position, loop: true}); - + print("PLAY SOUND") + _this.waterInjector = Audio.playSound(_this.waterSound, { + position: spoutProps.position, + loop: true + }); + } else { _this.waterInjector.restart(); } @@ -63,23 +101,14 @@ emitOrientation: waterEmitOrientation }); } else if (pitch > _this.POUR_ANGLE_THRESHOLD && _this.waterPouring) { - Entities.editEntity(_this.waterEffect, { - isEmitting: false - }); - _this.waterPouring = false; - //water no longer pouring... - _this.waterInjector.stop(); + _this.stopPouring(); } }, - castRay: function() { + castRay: function() { var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["position, rotation"]); - var direction = Quat.getFront(spoutProps.rotation) + var direction = Quat.getFront(spoutProps.rotation) var end = Vec3.sum(spoutProps.position, Vec3.multiply(5, direction)); - Overlays.editOverlay(_this.rayCastLine, { - start: spoutProps.position, - end: end - }); var pickRay = { origin: spoutProps.position, @@ -89,7 +118,10 @@ if (intersection.intersects) { //We've intersected with a waterable object - var data = JSON.stringify({position: intersection.intersection, surfaceNormal: intersection.surfaceNormal}); + var data = JSON.stringify({ + position: intersection.intersection, + surfaceNormal: intersection.surfaceNormal + }); Entities.callEntityMethod(intersection.entityID, 'continueWatering', [data]); } @@ -123,8 +155,8 @@ maxParticles: 20000, lifespan: 2, emitRate: 2000, - emitSpeed: .2, - speedSpread: 0.0, + emitSpeed: .3, + speedSpread: 0.1, emitDimensions: { x: 0.0, y: 0.0, @@ -159,8 +191,8 @@ findGrowableEntities: function() { _this.growableEntities = []; - var entities = Entities.findEntities(_this.position, 50); - entities.forEach( function(entity) { + var entities = Entities.findEntities(_this.position, _this.GROWABLE_ENTITIES_SEARCH_RANGE); + entities.forEach(function(entity) { var name = Entities.getEntityProperties(entity, "name").name; if (name.length > 0 && name.indexOf("growable") !== -1) { _this.growableEntities.push(entity); @@ -172,18 +204,6 @@ preload: function(entityID) { _this.entityID = entityID; _this.position = Entities.getEntityProperties(_this.entityID, "position").position; - _this.rayCastLine = Overlays.addOverlay("line3d", { - color: { - red: 200, - green: 10, - blue: 200 - }, - lineWidth: 2, - alpha: 1, - visible: true, - ignoreRayIntersection: true - }); - _this.findGrowableEntities(); // Wait a a bit for spout to spawn for case where preload is initial spawn, then save it Script.setTimeout(function() { var entities = Entities.findEntities(_this.position, 1); @@ -206,7 +226,6 @@ unload: function() { - Overlays.deleteOverlay(_this.rayCastLine); Entities.deleteEntity(_this.waterEffect); if (_this.waterInjector) { _this.waterInjector.stop(); From d4bc83f408c1f3fa4095501e070ca0fc73010f9e Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 7 Mar 2016 16:16:06 -0800 Subject: [PATCH 46/87] cleanup and bug fixes --- examples/homeContent/plant/flower.fs | 10 +++ .../plant/growingPlantEntityScript.js | 26 ++++--- .../homeContent/plant/growingPlantSpawner.js | 72 ++++++++++++++++--- .../homeContent/plant/waterCanEntityScript.js | 10 +-- 4 files changed, 96 insertions(+), 22 deletions(-) diff --git a/examples/homeContent/plant/flower.fs b/examples/homeContent/plant/flower.fs index d6dc310e85..8e35bd1014 100644 --- a/examples/homeContent/plant/flower.fs +++ b/examples/homeContent/plant/flower.fs @@ -1,3 +1,13 @@ +// +// flowers.fs +// examples/homeContent/plant +// +// Created by Eric Levin on 3/7/16. +// Copyright 2016 High Fidelity, Inc. +// +// This fragment shader is designed to shader a sphere to create the effect of a blooming flower +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html #define TWO_PI 6.28318530718 diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/examples/homeContent/plant/growingPlantEntityScript.js index f0992db45a..6f59d808a5 100644 --- a/examples/homeContent/plant/growingPlantEntityScript.js +++ b/examples/homeContent/plant/growingPlantEntityScript.js @@ -33,6 +33,9 @@ max: 1000 }; _this.canCreateFlower = true; + _this.flowersBloomingSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/flowersBlooming.wav"); + _this.soundPlaying = false; + _this.BLOOM_VOLUME = 0.4; }; @@ -57,8 +60,16 @@ flower.grow(); }); + if (!_this.soundPlaying) { + _this.position = Entities.getEntityProperties(_this.entityID, "position").position; + _this.soundPlaying = true; + _this.bloomSoundInjector = Audio.playSound(_this.flowersBloomingSound, {position: _this.position, volume: _this.BLOOM_VOLUME}); + } + }, - + stopWatering: function() { + _this.bloomSoundInjector.stop(); + _this.soundPlaying = false; }, createFlower: function(position, surfaceNormal) { @@ -114,8 +125,7 @@ preload: function(entityID) { _this.entityID = entityID; - var SHADER_URL = "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs" - // var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs"; + var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs?v1"; _this.flowerUserData = { ProceduralEntity: { shaderUrl: SHADER_URL, @@ -128,12 +138,10 @@ }, unload: function() { - print("EBL UNLOAD GROWING PLANT SCRIPT"); - // _this.flowers.forEach(function(flower) { - // Entities.deleteEntity(flower.id); - // }) - - + if (_this.bloomSoundInjector) { + _this.bloomSoundInjector.stop(); + delete _this.bloomSoundInjector; + } } }; diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/examples/homeContent/plant/growingPlantSpawner.js index b9f0ef147d..a48708eb8a 100644 --- a/examples/homeContent/plant/growingPlantSpawner.js +++ b/examples/homeContent/plant/growingPlantSpawner.js @@ -18,8 +18,12 @@ orientation = Quat.fromVec3Degrees(orientation); var bowlPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(orientation))); var BOWL_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Flowers--Bowl.fbx"; -var bowlDimensions = {x: 0.518, y: 0.1938, z: 0.5518}; -var bowl= Entities.addEntity({ +var bowlDimensions = { + x: 0.518, + y: 0.1938, + z: 0.5518 +}; +var bowl = Entities.addEntity({ type: "Model", modelURL: BOWL_MODEL_URL, dimensions: bowlDimensions, @@ -30,8 +34,16 @@ var bowl= Entities.addEntity({ var PLANT_MODEL_URL = "http://hifi-content.s3.amazonaws.com/alan/dev/Flowers--Moss-Rock.fbx"; var PLANT_SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js?v1" + Math.random().toFixed(2)); -var plantDimensions = {x: 0.52, y: 0.2600, z: 0.52}; -var plantPosition = Vec3.sum(bowlPosition, {x: 0, y: plantDimensions.y/2, z: 0}); +var plantDimensions = { + x: 0.52, + y: 0.2600, + z: 0.52 +}; +var plantPosition = Vec3.sum(bowlPosition, { + x: 0, + y: plantDimensions.y / 2, + z: 0 +}); var plant = Entities.addEntity({ type: "Model", modelURL: PLANT_MODEL_URL, @@ -52,12 +64,46 @@ var waterCan = Entities.addEntity({ name: "hifi-water-can", modelURL: WATER_CAN_MODEL_URL, script: WATER_CAN_SCRIPT_URL, - dimensions: {x: 0.1859, y: 0.2762, z: 0.4115}, + dimensions: { + x: 0.1859, + y: 0.2762, + z: 0.4115 + }, position: waterCanPosition, angularDamping: 1, dynamic: true, - gravity: { x: 0.0, y: -2.0, z: 0}, - rotation: waterCanRotation + gravity: { + x: 0.0, + y: -2.0, + z: 0 + }, + rotation: waterCanRotation, + userData: JSON.stringify({ + wearable: { + joints: { + RightHand: [{ + x: 0.024, + y: 0.173, + z: 0.152 + }, { + x: 0.374, + y: 0.636, + z: -0.638, + w: -0.215 + }], + LeftHand: [{ + x: -0.0348, + y: 0.201, + z: 0.166 + }, { + x: 0.4095, + y: -0.625, + z: 0.616, + w: -0.247 + }] + } + } + }) }); @@ -66,8 +112,16 @@ var waterSpoutRotation = Quat.multiply(waterCanRotation, Quat.fromPitchYawRollDe var waterSpout = Entities.addEntity({ type: "Box", name: "hifi-water-spout", - dimensions: {x: 0.02, y: 0.02, z: 0.07}, - color: {red: 200, green: 10, blue: 200}, + dimensions: { + x: 0.02, + y: 0.02, + z: 0.07 + }, + color: { + red: 200, + green: 10, + blue: 200 + }, position: waterSpoutPosition, rotation: waterSpoutRotation, parentID: waterCan, diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/examples/homeContent/plant/waterCanEntityScript.js index 2817524ab0..551c74bc47 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/examples/homeContent/plant/waterCanEntityScript.js @@ -37,7 +37,6 @@ startHold: function() { _this.findGrowableEntities(); - print("EB: GROWABLE ENTITIES length " + _this.growableEntities.length) }, releaseEquip: function() { @@ -58,7 +57,10 @@ }); _this.waterPouring = false; //water no longer pouring... - _this.waterInjector.stop(); + if (_this.waterInjector) { + _this.waterInjector.stop(); + } + Entities.callEntityMethod(_this.mostRecentIntersectedGrowableEntity, 'stopWatering'); }, continueEquip: function() { _this.continueHolding(); @@ -85,7 +87,6 @@ }); _this.waterPouring = true; if (!_this.waterInjector) { - print("PLAY SOUND") _this.waterInjector = Audio.playSound(_this.waterSound, { position: spoutProps.position, loop: true @@ -122,6 +123,7 @@ position: intersection.intersection, surfaceNormal: intersection.surfaceNormal }); + _this.mostRecentIntersectedGrowableEntity = intersection.entityID; Entities.callEntityMethod(intersection.entityID, 'continueWatering', [data]); } @@ -184,7 +186,7 @@ alpha: 1.0, alphaFinish: 1.0, emitterShouldTrail: true, - textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png?v2", + textures: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/images/raindrop.png", }); }, From 0d62b10a8f0c0a363f6a7185a4f2b59932b4ff20 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 7 Mar 2016 16:16:14 -0800 Subject: [PATCH 47/87] Added Mat4 support to script Also, hooked up MyAvatar.sensorToWorldMatrix access to script. --- examples/tests/mat4test.js | 165 +++++++++++++++++++ interface/src/avatar/MyAvatar.cpp | 5 +- interface/src/avatar/MyAvatar.h | 9 +- libraries/script-engine/src/Mat4.cpp | 71 ++++++++ libraries/script-engine/src/Mat4.h | 45 +++++ libraries/script-engine/src/ScriptEngine.cpp | 1 + libraries/script-engine/src/ScriptEngine.h | 4 +- libraries/shared/src/GLMHelpers.cpp | 9 + libraries/shared/src/GLMHelpers.h | 1 + libraries/shared/src/RegisteredMetaTypes.cpp | 41 +++++ libraries/shared/src/RegisteredMetaTypes.h | 5 + 11 files changed, 352 insertions(+), 4 deletions(-) create mode 100644 examples/tests/mat4test.js create mode 100644 libraries/script-engine/src/Mat4.cpp create mode 100644 libraries/script-engine/src/Mat4.h diff --git a/examples/tests/mat4test.js b/examples/tests/mat4test.js new file mode 100644 index 0000000000..ebce420dcb --- /dev/null +++ b/examples/tests/mat4test.js @@ -0,0 +1,165 @@ +// +// mat4test.js +// examples/tests +// +// Created by Anthony Thibault on 2016/3/7 +// Copyright 2016 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 +// + +var IDENTITY = {r0c0: 1, r0c1: 0, r0c2: 0, r0c3: 0, + r1c0: 0, r1c1: 1, r1c2: 0, r1c3: 0, + r2c0: 0, r2c1: 0, r2c2: 1, r2c3: 0, + r3c0: 0, r3c1: 0, r3c2: 0, r3c3: 1}; + +var ROT_ZERO = {x: 0, y: 0, z: 0, w: 1}; +var ROT_Y_180 = {x: 0, y: 1, z: 0, w: 0}; + +var ONE = {x: 1, y: 1, z: 1}; +var ZERO = {x: 0, y: 0, z: 0}; +var ONE_TWO_THREE = {x: 1, y: 2, z: 3}; +var ONE_HALF = {x: 0.5, y: 0.5, z: 0.5}; + +var EPSILON = 0.000001; + +function mat4FuzzyEqual(a, b) { + var r, c; + for (r = 0; r < 4; r++) { + for (c = 0; c < 4; c++) { + if (Math.abs(a["r" + r + "c" + c] - b["r" + r + "c" + c]) > EPSILON) { + return false; + } + } + } + return true; +} + +function vec3FuzzyEqual(a, b) { + if (Math.abs(a.x - b.x) > EPSILON || + Math.abs(a.y - b.y) > EPSILON || + Math.abs(a.z - b.z) > EPSILON) { + return false; + } + return true; +} + +function quatFuzzyEqual(a, b) { + if (Math.abs(a.x - b.x) > EPSILON || + Math.abs(a.y - b.y) > EPSILON || + Math.abs(a.z - b.z) > EPSILON || + Math.abs(a.w - b.w) > EPSILON) { + return false; + } + return true; +} + +var failureCount = 0; +var testCount = 0; +function assert(test) { + testCount++; + if (!test) { + print("MAT4 TEST " + testCount + " failed!"); + failureCount++; + } +} + +function testCreate() { + var test0 = Mat4.createFromScaleRotAndTrans(ONE, {x: 0, y: 0, z: 0, w: 1}, ZERO); + assert(mat4FuzzyEqual(test0, IDENTITY)); + + var test1 = Mat4.createFromRotAndTrans({x: 0, y: 0, z: 0, w: 1}, ZERO); + assert(mat4FuzzyEqual(test1, IDENTITY)); + + var test2 = Mat4.createFromRotAndTrans(ROT_Y_180, ONE_TWO_THREE); + assert(mat4FuzzyEqual(test2, {r0c0: -1, r0c1: 0, r0c2: 0, r0c3: 1, + r1c0: 0, r1c1: 1, r1c2: 0, r1c3: 2, + r2c0: 0, r2c1: 0, r2c2: -1, r2c3: 3, + r3c0: 0, r3c1: 0, r3c2: 0, r3c3: 1})); + + var test3 = Mat4.createFromScaleRotAndTrans(ONE_HALF, ROT_Y_180, ONE_TWO_THREE); + assert(mat4FuzzyEqual(test3, {r0c0: -0.5, r0c1: 0, r0c2: 0, r0c3: 1, + r1c0: 0, r1c1: 0.5, r1c2: 0, r1c3: 2, + r2c0: 0, r2c1: 0, r2c2: -0.5, r2c3: 3, + r3c0: 0, r3c1: 0, r3c2: 0, r3c3: 1})); +} + +function testExtractTranslation() { + var test0 = Mat4.extractTranslation(IDENTITY); + assert(vec3FuzzyEqual(ZERO, test0)); + + var test1 = Mat4.extractTranslation(Mat4.createFromRotAndTrans(ROT_Y_180, ONE_TWO_THREE)); + assert(vec3FuzzyEqual(ONE_TWO_THREE, test1)); +} + +function testExtractRotation() { + var test0 = Mat4.extractRotation(IDENTITY); + assert(quatFuzzyEqual(ROT_ZERO, test0)); + + var test1 = Mat4.extractRotation(Mat4.createFromRotAndTrans(ROT_Y_180, ONE_TWO_THREE)); + assert(quatFuzzyEqual(ROT_Y_180, test1)); +} + +function testExtractScale() { + var test0 = Mat4.extractScale(IDENTITY); + assert(vec3FuzzyEqual(ONE, test0)); + + var test1 = Mat4.extractScale(Mat4.createFromScaleRotAndTrans(ONE_HALF, ROT_Y_180, ONE_TWO_THREE)); + assert(vec3FuzzyEqual(ONE_HALF, test1)); + + var test2 = Mat4.extractScale(Mat4.createFromScaleRotAndTrans(ONE_TWO_THREE, ROT_ZERO, ONE_TWO_THREE)); + assert(vec3FuzzyEqual(ONE_TWO_THREE, test2)); +} + +function testTransformPoint() { + var test0 = Mat4.transformPoint(IDENTITY, ONE); + assert(vec3FuzzyEqual(ONE, test0)); + + var m = Mat4.createFromScaleRotAndTrans(ONE_HALF, ROT_Y_180, ONE_TWO_THREE); + var test1 = Mat4.transformPoint(m, ONE); + assert(vec3FuzzyEqual({x: 0.5, y: 2.5, z: 2.5}, test1)); +} + +function testTransformVector() { + var test0 = Mat4.transformVector(IDENTITY, ONE); + assert(vec3FuzzyEqual(ONE, test0)); + + var m = Mat4.createFromScaleRotAndTrans(ONE_HALF, ROT_Y_180, ONE_TWO_THREE); + var test1 = Mat4.transformVector(m, ONE); + assert(vec3FuzzyEqual({x: -0.5, y: 0.5, z: -0.5}, test1)); +} + +function testInverse() { + var test0 = IDENTITY; + assert(mat4FuzzyEqual(IDENTITY, Mat4.multiply(test0, Mat4.inverse(test0)))); + + var test1 = Mat4.createFromScaleRotAndTrans(ONE_HALF, ROT_Y_180, ONE_TWO_THREE); + assert(mat4FuzzyEqual(IDENTITY, Mat4.multiply(test1, Mat4.inverse(test1)))); + + var test2 = Mat4.extractScale(Mat4.createFromScaleRotAndTrans(ONE_TWO_THREE, ROT_ZERO, ONE_TWO_THREE)); + assert(mat4FuzzyEqual(IDENTITY, Mat4.multiply(test2, Mat4.inverse(test2)))); +} + +function testFront() { + var test0 = IDENTITY; + assert(mat4FuzzyEqual({x: 0, y: 0, z: -1}, Mat4.getFront(test0))); + + var test1 = Mat4.createFromScaleRotAndTrans(ONE_HALF, ROT_Y_180, ONE_TWO_THREE); + assert(mat4FuzzyEqual({x: 0, y: 0, z: 1}, Mat4.getFront(test1))); +} + +function testMat4() { + testCreate(); + testExtractTranslation(); + testExtractRotation(); + testExtractScale(); + testTransformPoint(); + testTransformVector(); + testInverse(); + testFront(); + + print("MAT4 TEST complete! (" + (testCount - failureCount) + "/" + testCount + ") tests passed!"); +} + +testMat4(); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 397627434f..26e0ce56dd 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -416,8 +416,9 @@ void MyAvatar::simulate(float deltaTime) { } } +// thread-safe glm::mat4 MyAvatar::getSensorToWorldMatrix() const { - return _sensorToWorldMatrix; + return _sensorToWorldMatrixCache.get(); } // Pass a recent sample of the HMD to the avatar. @@ -442,6 +443,8 @@ void MyAvatar::updateSensorToWorldMatrix() { _sensorToWorldMatrix = desiredMat * glm::inverse(_bodySensorMatrix); lateUpdatePalms(); + + _sensorToWorldMatrixCache.set(_sensorToWorldMatrix); } // Update avatar head rotation with sensor data diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 731cba8153..fd5c2920a9 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -22,7 +22,7 @@ #include "Avatar.h" #include "AtRestDetector.h" #include "MyCharacterController.h" - +#include class ModelItemID; @@ -78,6 +78,9 @@ class MyAvatar : public Avatar { Q_PROPERTY(controller::Pose rightHandPose READ getRightHandPose) Q_PROPERTY(controller::Pose leftHandTipPose READ getLeftHandTipPose) Q_PROPERTY(controller::Pose rightHandTipPose READ getRightHandTipPose) + + Q_PROPERTY(glm::mat4 sensorToWorldMatrix READ getSensorToWorldMatrix) + Q_PROPERTY(float energy READ getEnergy WRITE setEnergy) public: @@ -98,8 +101,9 @@ public: const glm::vec3& getHMDSensorPosition() const { return _hmdSensorPosition; } const glm::quat& getHMDSensorOrientation() const { return _hmdSensorOrientation; } const glm::vec2& getHMDSensorFacingMovingAverage() const { return _hmdSensorFacingMovingAverage; } - glm::mat4 getSensorToWorldMatrix() const; + // thread safe + Q_INVOKABLE glm::mat4 getSensorToWorldMatrix() const; // Pass a recent sample of the HMD to the avatar. // This can also update the avatar's position to follow the HMD @@ -390,6 +394,7 @@ private: // used to transform any sensor into world space, including the _hmdSensorMat, or hand controllers. glm::mat4 _sensorToWorldMatrix; + ThreadSafeValueCache _sensorToWorldMatrixCache { glm::mat4() }; struct FollowHelper { FollowHelper(); diff --git a/libraries/script-engine/src/Mat4.cpp b/libraries/script-engine/src/Mat4.cpp new file mode 100644 index 0000000000..bb65cb1e26 --- /dev/null +++ b/libraries/script-engine/src/Mat4.cpp @@ -0,0 +1,71 @@ +// +// Mat4.cpp +// libraries/script-engine/src +// +// Created by Anthony Thibault on 3/7/16. +// Copyright 2016 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 +#include +#include "ScriptEngineLogging.h" +#include "Mat4.h" + +glm::mat4 Mat4::multiply(const glm::mat4& m1, const glm::mat4& m2) const { + return m1 * m2; +} + +glm::mat4 Mat4::createFromRotAndTrans(const glm::quat& rot, const glm::vec3& trans) const { + return ::createMatFromQuatAndPos(rot, trans); +} + +glm::mat4 Mat4::createFromScaleRotAndTrans(const glm::vec3& scale, const glm::quat& rot, const glm::vec3& trans) const { + return createMatFromScaleQuatAndPos(scale, rot, trans); +} + +glm::vec3 Mat4::extractTranslation(const glm::mat4& m) const { + return ::extractTranslation(m); +} + +glm::quat Mat4::extractRotation(const glm::mat4& m) const { + return ::glmExtractRotation(m); +} + +glm::vec3 Mat4::extractScale(const glm::mat4& m) const { + return ::extractScale(m); +} + +glm::vec3 Mat4::transformPoint(const glm::mat4& m, const glm::vec3& point) const { + return ::transformPoint(m, point); +} + +glm::vec3 Mat4::transformVector(const glm::mat4& m, const glm::vec3& vector) const { + return ::transformVectorFast(m, vector); +} + +glm::mat4 Mat4::inverse(const glm::mat4& m) const { + return glm::inverse(m); +} + +glm::vec3 Mat4::getFront(const glm::mat4& m) const { + return glm::vec3(-m[0][2], -m[1][2], -m[2][2]); +} + +glm::vec3 Mat4::getRight(const glm::mat4& m) const { + return glm::vec3(m[0][0], m[1][0], m[2][0]); +} + +glm::vec3 Mat4::getUp(const glm::mat4& m) const { + return glm::vec3(m[0][1], m[1][1], m[2][1]); +} + +void Mat4::print(const QString& label, const glm::mat4& m) const { + qCDebug(scriptengine) << qPrintable(label) << + "row0 =" << m[0][0] << "," << m[1][0] << "," << m[2][0] << "," << m[3][0] << + "row1 =" << m[0][1] << "," << m[1][1] << "," << m[2][1] << "," << m[3][1] << + "row2 =" << m[0][2] << "," << m[1][2] << "," << m[2][2] << "," << m[3][2] << + "row3 =" << m[0][3] << "," << m[1][3] << "," << m[2][3] << "," << m[3][3]; +} diff --git a/libraries/script-engine/src/Mat4.h b/libraries/script-engine/src/Mat4.h new file mode 100644 index 0000000000..047bf56079 --- /dev/null +++ b/libraries/script-engine/src/Mat4.h @@ -0,0 +1,45 @@ +// +// Mat4.h +// libraries/script-engine/src +// +// Created by Anthony Thibault on 3/7/16. +// Copyright 2016 High Fidelity, Inc. +// +// Scriptable 4x4 Matrix class library. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_Mat4_h +#define hifi_Mat4_h + +#include +#include + +/// Scriptable Mat4 object. Used exclusively in the JavaScript API +class Mat4 : public QObject { + Q_OBJECT + +public slots: + glm::mat4 multiply(const glm::mat4& m1, const glm::mat4& m2) const; + glm::mat4 createFromRotAndTrans(const glm::quat& rot, const glm::vec3& trans) const; + glm::mat4 createFromScaleRotAndTrans(const glm::vec3& scale, const glm::quat& rot, const glm::vec3& trans) const; + + glm::vec3 extractTranslation(const glm::mat4& m) const; + glm::quat extractRotation(const glm::mat4& m) const; + glm::vec3 extractScale(const glm::mat4& m) const; + + glm::vec3 transformPoint(const glm::mat4& m, const glm::vec3& point) const; + glm::vec3 transformVector(const glm::mat4& m, const glm::vec3& vector) const; + + glm::mat4 inverse(const glm::mat4& m) const; + + glm::vec3 getFront(const glm::mat4& m) const; + glm::vec3 getRight(const glm::mat4& m) const; + glm::vec3 getUp(const glm::mat4& m) const; + + void print(const QString& label, const glm::mat4& m) const; +}; + +#endif // hifi_Mat4_h diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 9ee2c374c5..61ebfe4515 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -315,6 +315,7 @@ void ScriptEngine::init() { registerGlobalObject("Entities", entityScriptingInterface.data()); registerGlobalObject("Quat", &_quatLibrary); registerGlobalObject("Vec3", &_vec3Library); + registerGlobalObject("Mat4", &_mat4Library); registerGlobalObject("Uuid", &_uuidLibrary); registerGlobalObject("AnimationCache", DependencyManager::get().data()); registerGlobalObject("Messages", DependencyManager::get().data()); diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 91d4c3f5a5..8056a4f487 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -34,6 +34,7 @@ #include "ArrayBufferClass.h" #include "AudioScriptingInterface.h" #include "Quat.h" +#include "Mat4.h" #include "ScriptCache.h" #include "ScriptUUID.h" #include "Vec3.h" @@ -199,6 +200,7 @@ protected: QString _fileNameString; Quat _quatLibrary; Vec3 _vec3Library; + Mat4 _mat4Library; ScriptUUID _uuidLibrary; std::atomic _isUserLoaded { false }; bool _isReloading { false }; @@ -219,4 +221,4 @@ protected: static std::atomic _stoppingAllScripts; }; -#endif // hifi_ScriptEngine_h \ No newline at end of file +#endif // hifi_ScriptEngine_h diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index e9d6591cac..b2294f9ef3 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -376,6 +376,15 @@ glm::mat4 createMatFromQuatAndPos(const glm::quat& q, const glm::vec3& p) { return m; } +// create matrix from a non-uniform scale, orientation and position +glm::mat4 createMatFromScaleQuatAndPos(const glm::vec3& scale, const glm::quat& rot, const glm::vec3& trans) { + glm::vec3 xAxis = rot * glm::vec3(scale.x, 0.0f, 0.0f); + glm::vec3 yAxis = rot * glm::vec3(0.0f, scale.y, 0.0f); + glm::vec3 zAxis = rot * glm::vec3(0.0f, 0.0f, scale.z); + return glm::mat4(glm::vec4(xAxis, 0.0f), glm::vec4(yAxis, 0.0f), + glm::vec4(zAxis, 0.0f), glm::vec4(trans, 1.0f)); +} + // cancel out roll and pitch glm::quat cancelOutRollAndPitch(const glm::quat& q) { glm::vec3 zAxis = q * glm::vec3(0.0f, 0.0f, 1.0f); diff --git a/libraries/shared/src/GLMHelpers.h b/libraries/shared/src/GLMHelpers.h index 15f3f60cf7..4a37d68240 100644 --- a/libraries/shared/src/GLMHelpers.h +++ b/libraries/shared/src/GLMHelpers.h @@ -212,6 +212,7 @@ glm::detail::tvec4 lerp(const glm::detail::tvec4& x, const glm::deta } glm::mat4 createMatFromQuatAndPos(const glm::quat& q, const glm::vec3& p); +glm::mat4 createMatFromScaleQuatAndPos(const glm::vec3& scale, const glm::quat& rot, const glm::vec3& trans); glm::quat cancelOutRollAndPitch(const glm::quat& q); glm::mat4 cancelOutRollAndPitch(const glm::mat4& m); glm::vec3 transformPoint(const glm::mat4& m, const glm::vec3& p); diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 94d9b0ae26..953fdb3582 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -34,6 +34,7 @@ static int collisionMetaTypeId = qRegisterMetaType(); static int qMapURLStringMetaTypeId = qRegisterMetaType>(); void registerMetaTypes(QScriptEngine* engine) { + qScriptRegisterMetaType(engine, mat4toScriptValue, mat4FromScriptValue); qScriptRegisterMetaType(engine, vec4toScriptValue, vec4FromScriptValue); qScriptRegisterMetaType(engine, vec3toScriptValue, vec3FromScriptValue); qScriptRegisterMetaType(engine, qVectorVec3ToScriptValue, qVectorVec3FromScriptValue); @@ -53,6 +54,46 @@ void registerMetaTypes(QScriptEngine* engine) { qScriptRegisterMetaType(engine, aaCubeToScriptValue, aaCubeFromScriptValue); } +QScriptValue mat4toScriptValue(QScriptEngine* engine, const glm::mat4& mat4) { + QScriptValue obj = engine->newObject(); + obj.setProperty("r0c0", mat4[0][0]); + obj.setProperty("r1c0", mat4[0][1]); + obj.setProperty("r2c0", mat4[0][2]); + obj.setProperty("r3c0", mat4[0][3]); + obj.setProperty("r0c1", mat4[1][0]); + obj.setProperty("r1c1", mat4[1][1]); + obj.setProperty("r2c1", mat4[1][2]); + obj.setProperty("r3c1", mat4[1][3]); + obj.setProperty("r0c2", mat4[2][0]); + obj.setProperty("r1c2", mat4[2][1]); + obj.setProperty("r2c2", mat4[2][2]); + obj.setProperty("r3c2", mat4[2][3]); + obj.setProperty("r0c3", mat4[3][0]); + obj.setProperty("r1c3", mat4[3][1]); + obj.setProperty("r2c3", mat4[3][2]); + obj.setProperty("r3c3", mat4[3][3]); + return obj; +} + +void mat4FromScriptValue(const QScriptValue& object, glm::mat4& mat4) { + mat4[0][0] = object.property("r0c0").toVariant().toFloat(); + mat4[0][1] = object.property("r1c0").toVariant().toFloat(); + mat4[0][2] = object.property("r2c0").toVariant().toFloat(); + mat4[0][3] = object.property("r3c0").toVariant().toFloat(); + mat4[1][0] = object.property("r0c1").toVariant().toFloat(); + mat4[1][1] = object.property("r1c1").toVariant().toFloat(); + mat4[1][2] = object.property("r2c1").toVariant().toFloat(); + mat4[1][3] = object.property("r3c1").toVariant().toFloat(); + mat4[2][0] = object.property("r0c2").toVariant().toFloat(); + mat4[2][1] = object.property("r1c2").toVariant().toFloat(); + mat4[2][2] = object.property("r2c2").toVariant().toFloat(); + mat4[2][3] = object.property("r3c2").toVariant().toFloat(); + mat4[3][0] = object.property("r0c3").toVariant().toFloat(); + mat4[3][1] = object.property("r1c3").toVariant().toFloat(); + mat4[3][2] = object.property("r2c3").toVariant().toFloat(); + mat4[3][3] = object.property("r3c3").toVariant().toFloat(); +} + QScriptValue vec4toScriptValue(QScriptEngine* engine, const glm::vec4& vec4) { QScriptValue obj = engine->newObject(); obj.setProperty("x", vec4.x); diff --git a/libraries/shared/src/RegisteredMetaTypes.h b/libraries/shared/src/RegisteredMetaTypes.h index 0a3e94a5b6..652ec26fe7 100644 --- a/libraries/shared/src/RegisteredMetaTypes.h +++ b/libraries/shared/src/RegisteredMetaTypes.h @@ -28,6 +28,7 @@ Q_DECLARE_METATYPE(glm::vec4) Q_DECLARE_METATYPE(glm::vec3) Q_DECLARE_METATYPE(glm::vec2) Q_DECLARE_METATYPE(glm::quat) +Q_DECLARE_METATYPE(glm::mat4) Q_DECLARE_METATYPE(xColor) Q_DECLARE_METATYPE(QVector) Q_DECLARE_METATYPE(QVector) @@ -35,6 +36,10 @@ Q_DECLARE_METATYPE(AACube) void registerMetaTypes(QScriptEngine* engine); +// Mat4 +QScriptValue mat4toScriptValue(QScriptEngine* engine, const glm::mat4& mat4); +void mat4FromScriptValue(const QScriptValue& object, glm::mat4& mat4); + // Vec4 QScriptValue vec4toScriptValue(QScriptEngine* engine, const glm::vec4& vec4); void vec4FromScriptValue(const QScriptValue& object, glm::vec4& vec4); From 7b69aa375e94587767e319b5b4b5e9a1eedc7ec6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 7 Mar 2016 18:18:38 -0800 Subject: [PATCH 48/87] moved plant to home folder --- examples/VR-VJ/cartridgesSpawner.js | 0 .../DomainContent/Home}/plant/flower.fs | 0 .../DomainContent/Home}/plant/growingPlantEntityScript.js | 0 .../DomainContent/Home}/plant/growingPlantSpawner.js | 0 .../DomainContent/Home}/plant/waterCanEntityScript.js | 2 +- 5 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 examples/VR-VJ/cartridgesSpawner.js rename {examples/homeContent => unpublishedScripts/DomainContent/Home}/plant/flower.fs (100%) rename {examples/homeContent => unpublishedScripts/DomainContent/Home}/plant/growingPlantEntityScript.js (100%) rename {examples/homeContent => unpublishedScripts/DomainContent/Home}/plant/growingPlantSpawner.js (100%) rename {examples/homeContent => unpublishedScripts/DomainContent/Home}/plant/waterCanEntityScript.js (99%) diff --git a/examples/VR-VJ/cartridgesSpawner.js b/examples/VR-VJ/cartridgesSpawner.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/homeContent/plant/flower.fs b/unpublishedScripts/DomainContent/Home/plant/flower.fs similarity index 100% rename from examples/homeContent/plant/flower.fs rename to unpublishedScripts/DomainContent/Home/plant/flower.fs diff --git a/examples/homeContent/plant/growingPlantEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js similarity index 100% rename from examples/homeContent/plant/growingPlantEntityScript.js rename to unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js diff --git a/examples/homeContent/plant/growingPlantSpawner.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js similarity index 100% rename from examples/homeContent/plant/growingPlantSpawner.js rename to unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js diff --git a/examples/homeContent/plant/waterCanEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/waterCanEntityScript.js similarity index 99% rename from examples/homeContent/plant/waterCanEntityScript.js rename to unpublishedScripts/DomainContent/Home/plant/waterCanEntityScript.js index 551c74bc47..d306cf8b6b 100644 --- a/examples/homeContent/plant/waterCanEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/plant/waterCanEntityScript.js @@ -12,7 +12,7 @@ (function() { - Script.include("../../libraries/utils.js"); + Script.include('../../../../libraries/utils.js'); var _this; WaterSpout = function() { From 3a810152fb8e93a73411bdf7f97ed1f739c4f995 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 7 Mar 2016 18:30:22 -0800 Subject: [PATCH 49/87] Trying to consolidate the FBX reader for Blender /maya --- libraries/fbx/src/FBXReader.cpp | 58 +++++++++++++----------- libraries/fbx/src/FBXReader.h | 4 ++ libraries/fbx/src/FBXReader_Material.cpp | 21 ++++++--- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 500f856450..2be04c30bd 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -865,11 +865,10 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS } } else if (object.name == "Material") { FBXMaterial material; - if (object.properties.at(1).toByteArray().contains("StingrayPBS")) { - material.isPBSMaterial = true; - } + material.name = (object.properties.at(1).toString()); foreach (const FBXNode& subobject, object.children) { bool properties = false; + QByteArray propertyName; int index; if (subobject.name == "Properties60") { @@ -882,25 +881,33 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS propertyName = "P"; index = 4; } - if (!material.isPBSMaterial && properties) { - foreach (const FBXNode& property, subobject.children) { + if (properties) { + std::vector unknowns; + foreach(const FBXNode& property, subobject.children) { if (property.name == propertyName) { if (property.properties.at(0) == "DiffuseColor") { material.diffuseColor = getVec3(property.properties, index); - } else if (property.properties.at(0) == "Diffuse") { - material.diffuseColor = getVec3(property.properties, index); } else if (property.properties.at(0) == "DiffuseFactor") { material.diffuseFactor = property.properties.at(index).value(); + } else if (property.properties.at(0) == "Diffuse") { + // material.diffuseColor = getVec3(property.properties, index); + // material.diffuseFactor = 1.0; } else if (property.properties.at(0) == "SpecularColor") { material.specularColor = getVec3(property.properties, index); - } else if (property.properties.at(0) == "Specular") { - material.specularColor = getVec3(property.properties, index); } else if (property.properties.at(0) == "SpecularFactor") { material.specularFactor = property.properties.at(index).value(); + } else if (property.properties.at(0) == "Specular") { + // material.specularColor = getVec3(property.properties, index); + // material.specularFactor = 1.0; - } else if (property.properties.at(0) == "Emissive") { + } else if (property.properties.at(0) == "EmissiveColor") { material.emissiveColor = getVec3(property.properties, index); + } else if (property.properties.at(0) == "EmissiveFactor") { + material.emissiveFactor = property.properties.at(index).value(); + } else if (property.properties.at(0) == "Emissive") { + // material.emissiveColor = getVec3(property.properties, index); + // material.emissiveFactor = 1.0; } else if (property.properties.at(0) == "Shininess") { material.shininess = property.properties.at(index).value(); @@ -908,42 +915,39 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS } else if (property.properties.at(0) == "Opacity") { material.opacity = property.properties.at(index).value(); } -#if defined(DEBUG_FBXREADER) - else { - const QString propname = property.properties.at(0).toString(); - if (propname == "EmissiveFactor") { - } - } -#endif - } - } - } else if (material.isPBSMaterial && properties) { - std::vector unknowns; - foreach(const FBXNode& property, subobject.children) { - if (property.name == propertyName) { - if (property.properties.at(0) == "Maya|use_normal_map") { + // Sting Ray Material Properties!!!! + else if (property.properties.at(0) == "Maya|use_normal_map") { + material.isPBSMaterial = true; material.useNormalMap = (bool)property.properties.at(index).value(); } else if (property.properties.at(0) == "Maya|base_color") { + material.isPBSMaterial = true; material.diffuseColor = getVec3(property.properties, index); } else if (property.properties.at(0) == "Maya|use_color_map") { + material.isPBSMaterial = true; material.useAlbedoMap = (bool) property.properties.at(index).value(); } else if (property.properties.at(0) == "Maya|roughness") { + material.isPBSMaterial = true; material.roughness = property.properties.at(index).value(); } else if (property.properties.at(0) == "Maya|use_roughness_map") { + material.isPBSMaterial = true; material.useRoughnessMap = (bool)property.properties.at(index).value(); } else if (property.properties.at(0) == "Maya|metallic") { + material.isPBSMaterial = true; material.metallic = property.properties.at(index).value(); } else if (property.properties.at(0) == "Maya|use_metallic_map") { + material.isPBSMaterial = true; material.useMetallicMap = (bool)property.properties.at(index).value(); - } else if (property.properties.at(0) == "Maya|emissive") { + material.isPBSMaterial = true; material.emissiveColor = getVec3(property.properties, index); } else if (property.properties.at(0) == "Maya|emissive_intensity") { + material.isPBSMaterial = true; material.emissiveIntensity = property.properties.at(index).value(); } else if (property.properties.at(0) == "Maya|use_emissive_map") { + material.isPBSMaterial = true; material.useEmissiveMap = (bool)property.properties.at(index).value(); } else if (property.properties.at(0) == "Maya|use_ao_map") { @@ -1071,7 +1075,9 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS if (connection.properties.at(0) == "OP") { int counter = 0; QByteArray type = connection.properties.at(3).toByteArray().toLower(); - if ((type.contains("diffuse") && !type.contains("tex_global_diffuse"))) { + if (type.contains("DiffuseFactor")) { + diffuseFactorTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1)); + } else if ((type.contains("diffuse") && !type.contains("tex_global_diffuse"))) { diffuseTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1)); } else if (type.contains("tex_color_map")) { diffuseTextures.insert(getID(connection.properties, 2), getID(connection.properties, 1)); diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index 3fefd837f3..53918bd149 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -143,6 +143,8 @@ public: float specularFactor = 1.0f; glm::vec3 emissiveColor{ 0.0f }; + float emissiveFactor = 0.0f; + float shininess = 23.0f; float opacity = 1.0f; @@ -151,6 +153,7 @@ public: float emissiveIntensity{ 1.0f }; QString materialID; + QString name; model::MaterialPointer _material; FBXTexture normalTexture; @@ -417,6 +420,7 @@ public: QHash diffuseTextures; + QHash diffuseFactorTextures; QHash transparentTextures; QHash bumpTextures; QHash normalTextures; diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index d87eac405f..f3b728ef46 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -68,12 +68,22 @@ void FBXReader::consolidateFBXMaterials() { // the pure material associated with this part bool detectDifferentUVs = false; FBXTexture diffuseTexture; + FBXTexture diffuseFactorTexture; QString diffuseTextureID = diffuseTextures.value(material.materialID); - if (!diffuseTextureID.isNull()) { + QString diffuseFactorTextureID = diffuseFactorTextures.value(material.materialID); + + if (!diffuseFactorTextureID.isNull() || !diffuseTextureID.isNull()) { + // If both factor and color are specified, color wins + if (!diffuseFactorTextureID.isNull() && diffuseTextureID.isNull()) { + diffuseTextureID = diffuseFactorTextureID; + // Avoid the DiffuseFactor effect in this case because here Maya would put 0.5... + material.diffuseFactor = 1.0; + } + diffuseTexture = getTexture(diffuseTextureID); - + // FBX files generated by 3DSMax have an intermediate texture parent, apparently - foreach (const QString& childTextureID, _connectionChildMap.values(diffuseTextureID)) { + foreach(const QString& childTextureID, _connectionChildMap.values(diffuseTextureID)) { if (_textureFilenames.contains(childTextureID)) { diffuseTexture = getTexture(diffuseTextureID); } @@ -173,11 +183,10 @@ void FBXReader::consolidateFBXMaterials() { // Finally create the true material representation material._material = std::make_shared(); - material._material->setEmissive(material.emissiveColor); + material._material->setEmissive(material.emissiveColor * material.emissiveFactor); + // Do not use the Diffuse Factor from FBX at all, this simpliies the export path auto diffuse = material.diffuseColor; - // FIXME: Do not use the Diffuse Factor yet as some FBX models have it set to 0 - // diffuse *= material.diffuseFactor; material._material->setAlbedo(diffuse); if (material.isPBSMaterial) { From 3d71226f72d4e5ca234cfedfe1982ca3cbd0fd4c Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 7 Mar 2016 18:33:09 -0800 Subject: [PATCH 50/87] Crash fix for moving reticle via script. sendMessage is not thread-safe, use invokeMethod to call into application thread instead. --- interface/src/Application.cpp | 4 ++-- interface/src/Application.h | 4 ++-- interface/src/ui/ApplicationCompositor.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 81b633a1aa..3139c21a1d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2173,9 +2173,9 @@ void Application::maybeToggleMenuVisible(QMouseEvent* event) { } /// called by ApplicationCompositor when in HMD mode and we're faking our mouse movement -void Application::fakeMouseEvent(QMouseEvent* event) { +void Application::fakeMouseEvent(QMouseEvent event) { _fakedMouseEvent = true; - sendEvent(_glWidget, event); + sendEvent(_glWidget, &event); _fakedMouseEvent = false; } diff --git a/interface/src/Application.h b/interface/src/Application.h index c16175a333..9a1f54a266 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -221,8 +221,6 @@ public: float getAverageSimsPerSecond(); - void fakeMouseEvent(QMouseEvent* event); - signals: void svoImportRequested(const QString& url); @@ -283,6 +281,8 @@ public slots: void runTests(); + void fakeMouseEvent(QMouseEvent event); + private slots: void showDesktop(); void clearDomainOctreeDetails(); diff --git a/interface/src/ui/ApplicationCompositor.cpp b/interface/src/ui/ApplicationCompositor.cpp index efd69c7859..04630fbbc8 100644 --- a/interface/src/ui/ApplicationCompositor.cpp +++ b/interface/src/ui/ApplicationCompositor.cpp @@ -457,7 +457,7 @@ void ApplicationCompositor::setReticlePosition(glm::vec2 position, bool sendFake auto buttons = QApplication::mouseButtons(); auto modifiers = QApplication::keyboardModifiers(); QMouseEvent event(QEvent::MouseMove, globalPos, button, buttons, modifiers); - qApp->fakeMouseEvent(&event); + QMetaObject::invokeMethod(qApp, "fakeMouseEvent", Qt::AutoConnection, Q_ARG(QMouseEvent, event)); } } else { // NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies, From 26b4c904f3b0dc41632c1d35574e50cd909d8b95 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 7 Mar 2016 18:42:52 -0800 Subject: [PATCH 51/87] handControllerMouse.js: transform hand controllers into sensor frame --- examples/controllers/handControllerMouse.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/controllers/handControllerMouse.js b/examples/controllers/handControllerMouse.js index e53fc34df1..29e7972cf0 100644 --- a/examples/controllers/handControllerMouse.js +++ b/examples/controllers/handControllerMouse.js @@ -10,9 +10,9 @@ // var DEBUGGING = false; -var angularVelocityTrailingAverage = 0.0; // Global trailing average used to decide whether to move reticle at all +var angularVelocityTrailingAverage = 0.0; // Global trailing average used to decide whether to move reticle at all var lastX = 0; -var lastY = 0; +var lastY = 0; Math.clamp=function(a,b,c) { return Math.max(b,Math.min(c,a)); @@ -57,6 +57,7 @@ var filteredRotatedRight = Vec3.UNIT_NEG_Y; Script.update.connect(function(deltaTime) { + // avatar frame var poseRight = Controller.getPoseValue(Controller.Standard.RightHand); var poseLeft = Controller.getPoseValue(Controller.Standard.LeftHand); @@ -65,15 +66,16 @@ Script.update.connect(function(deltaTime) { var screenSizeX = screenSize.x; var screenSizeY = screenSize.y; - var rotatedRight = Vec3.multiplyQbyV(poseRight.rotation, Vec3.UNIT_NEG_Y); - var rotatedLeft = Vec3.multiplyQbyV(poseLeft.rotation, Vec3.UNIT_NEG_Y); + // transform hand facing vectors from avatar frame into sensor frame. + var worldToSensorMatrix = Mat4.inverse(MyAvatar.sensorToWorldMatrix); + var rotatedRight = Mat4.transformVector(worldToSensorMatrix, Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiplyQbyV(poseRight.rotation, Vec3.UNIT_NEG_Y))); + var rotatedLeft = Mat4.transformVector(worldToSensorMatrix, Vec3.multiplyQbyV(MyAvatar.orientation, Vec3.multiplyQbyV(poseLeft.rotation, Vec3.UNIT_NEG_Y))); lastRotatedRight = rotatedRight; - // Decide which hand should be controlling the pointer - // by comparing which one is moving more, and by - // tending to stay with the one moving more. + // by comparing which one is moving more, and by + // tending to stay with the one moving more. var BIAS_ADJUST_RATE = 0.5; var BIAS_ADJUST_DEADZONE = 0.05; leftRightBias += (Vec3.length(poseRight.angularVelocity) - Vec3.length(poseLeft.angularVelocity)) * BIAS_ADJUST_RATE; @@ -105,7 +107,7 @@ Script.update.connect(function(deltaTime) { // don't move the reticle with the hand controllers unless the controllers are actually being moved // take a time average of angular velocity, and don't move mouse at all if it's below threshold - + var AVERAGING_INTERVAL = 0.95; var MINIMUM_CONTROLLER_ANGULAR_VELOCITY = 0.03; var angularVelocityMagnitude = Vec3.length(poseLeft.angularVelocity) * (1.0 - leftRightBias) + Vec3.length(poseRight.angularVelocity) * leftRightBias; @@ -121,5 +123,3 @@ Script.update.connect(function(deltaTime) { Script.scriptEnding.connect(function(){ mapping.disable(); }); - - From 451856ae679ec1fa632d4e546d7efafc2d21af07 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 08:14:57 -0800 Subject: [PATCH 52/87] fixed path --- .../DomainContent/Home/plant/growingPlantEntityScript.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js index 6f59d808a5..353c2f825c 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js @@ -12,7 +12,7 @@ (function() { - Script.include("../../libraries/utils.js"); + Script.include('../../../../libraries/utils.js'); var _this; GrowingPlant = function() { From e046ba64ddeb8e94456c0c7c0ebe62d73ad56a47 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 8 Mar 2016 10:58:54 -0800 Subject: [PATCH 53/87] Properly marshal fakeMouseEvent data from script thread to main thread --- interface/src/Application.cpp | 3 ++- interface/src/Application.h | 2 +- interface/src/ui/ApplicationCompositor.cpp | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3139c21a1d..b4003e24c4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2173,8 +2173,9 @@ void Application::maybeToggleMenuVisible(QMouseEvent* event) { } /// called by ApplicationCompositor when in HMD mode and we're faking our mouse movement -void Application::fakeMouseEvent(QMouseEvent event) { +void Application::fakeMouseEvent(int type, int x, int y, uint32_t button, uint32_t buttons, uint32_t modifiers) { _fakedMouseEvent = true; + QMouseEvent event(QEvent::MouseMove, QPoint(x, y), (Qt::MouseButton)button, (Qt::MouseButtons)buttons, (Qt::KeyboardModifiers)modifiers); sendEvent(_glWidget, &event); _fakedMouseEvent = false; } diff --git a/interface/src/Application.h b/interface/src/Application.h index 9a1f54a266..b1908fbc34 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -281,7 +281,7 @@ public slots: void runTests(); - void fakeMouseEvent(QMouseEvent event); + void fakeMouseEvent(int type, int x, int y, quint32 button, quint32 buttons, quint32 modifiers); private slots: void showDesktop(); diff --git a/interface/src/ui/ApplicationCompositor.cpp b/interface/src/ui/ApplicationCompositor.cpp index 04630fbbc8..3420ed07a8 100644 --- a/interface/src/ui/ApplicationCompositor.cpp +++ b/interface/src/ui/ApplicationCompositor.cpp @@ -457,7 +457,9 @@ void ApplicationCompositor::setReticlePosition(glm::vec2 position, bool sendFake auto buttons = QApplication::mouseButtons(); auto modifiers = QApplication::keyboardModifiers(); QMouseEvent event(QEvent::MouseMove, globalPos, button, buttons, modifiers); - QMetaObject::invokeMethod(qApp, "fakeMouseEvent", Qt::AutoConnection, Q_ARG(QMouseEvent, event)); + QMetaObject::invokeMethod(qApp, "fakeMouseEvent", Qt::AutoConnection, + Q_ARG(int, (int)QEvent::MouseMove), Q_ARG(int, globalPos.x()), Q_ARG(int, globalPos.y()), + Q_ARG(quint32, (quint32)button), Q_ARG(quint32, (quint32)buttons), Q_ARG(quint32, (quint32)modifiers)); } } else { // NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies, From 5299b06e832da5ea3ffb1f5da5bdf0ac03ee1920 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 8 Mar 2016 11:26:16 -0800 Subject: [PATCH 54/87] Reintroducing the use of the DiffuseFactor so both Bender and MAya looks closer to Hifi --- libraries/fbx/src/FBXReader_Material.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index f3b728ef46..bd70bafe65 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -183,10 +183,13 @@ void FBXReader::consolidateFBXMaterials() { // Finally create the true material representation material._material = std::make_shared(); - material._material->setEmissive(material.emissiveColor * material.emissiveFactor); - // Do not use the Diffuse Factor from FBX at all, this simpliies the export path - auto diffuse = material.diffuseColor; + // Emissive color is the mix of emissiveColor with emissiveFactor + auto emissive = material.emissiveColor * material.emissiveFactor; + material._material->setEmissive(emissive); + + // Final diffuse color is the mix of diffuseColor with diffuseFactor + auto diffuse = material.diffuseColor * material.diffuseFactor; material._material->setAlbedo(diffuse); if (material.isPBSMaterial) { From 925ea8bcdaef7ba9d169b46b2de659cb47165c4a Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 8 Mar 2016 13:30:58 -0800 Subject: [PATCH 55/87] Add Resource::isCacheable --- libraries/networking/src/ResourceCache.cpp | 8 ++++---- libraries/networking/src/ResourceCache.h | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index e5771401b9..b312067d49 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -278,20 +278,20 @@ void Resource::refresh() { } void Resource::allReferencesCleared() { - if (_cache) { + if (_cache && isCacheable()) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "allReferencesCleared"); return; } - + // create and reinsert new shared pointer QSharedPointer self(this, &Resource::allReferencesCleared); setSelf(self); reinsert(); - + // add to the unused list _cache->addUnusedResource(self); - + } else { delete this; } diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 97e46f088a..2a89ad9b92 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -192,6 +192,9 @@ protected slots: protected: virtual void init(); + /// Checks whether the resource is cacheable. + virtual bool isCacheable() const { return true; } + /// Called when the download has finished virtual void downloadFinished(const QByteArray& data); From b08a9baa5ca9dd4280f1c596228b399c4f1c0f7c Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 8 Mar 2016 13:44:03 -0800 Subject: [PATCH 56/87] move cellscience --- .../CellScience/Scripts/navigationButton.js | 2 +- .../CellScience/importCellScience.js | 138 +++++++++++------- .../CellScience/motorProteinControllerAC.js | 48 ++++-- .../DomainContent/CellScience/moveCellsAC.js | 23 ++- .../CellScience/moveVesiclesAC.js | 23 ++- 5 files changed, 157 insertions(+), 77 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js index c1187bc6d5..b143678b42 100644 --- a/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js +++ b/unpublishedScripts/DomainContent/CellScience/Scripts/navigationButton.js @@ -24,7 +24,7 @@ this.initialize = function(entityId) { var properties = Entities.getEntityProperties(entityId); - if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false) { + if (properties.userData.length === 0 || properties.hasOwnProperty('userData') === false || properties.userData==="") { self.initTimeout = Script.setTimeout(function() { // print(' no user data yet, try again in one second') self.initialize(entityId); diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index 876df8adb1..97fbee5135 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,80 +5,115 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1112; +var version = 1207; + +var WORLD_OFFSET = { + x: -6000, + y: -6000, + z: -6000 +} + +var WORLD_SCALE_AMOUNT = 1.0; + + +function offsetVectorToWorld(vector) { + var newVector; + + newVector = Vec3.sum(vector, WORLD_OFFSET); + + print('JBP NEW VECTOR IS:: ' + JSON.stringify(newVector)) + return newVector +} + +function scaleVectorToWorld(vector) { + var newVector; + + newVector = Vec3.multiply(vector, WORLD_SCALE_AMOUNT); + + return newVector +} + +function transformToSmallerWorld(vector) { + var newVector = offsetVectorToWorld(vector); + // newVector = scaleVectorToWorld(newVector); + return newVector; +} + var cellLayout; var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/"; var utilsScript = Script.resolvePath('Scripts/utils.js'); Script.include(utilsScript); -function makeUngrabbable(entityID) { - setEntityCustomData('grabbableKey', entityID, { - grabbable: false - }); -} +// function makeUngrabbable(entityID) { +// setEntityCustomData('grabbableKey', entityID, { +// grabbable: false +// }); +// } -Entities.addingEntity.connect(makeUngrabbable); +// Entities.addingEntity.connect(makeUngrabbable); assignVariables(); var locations = { - cellLayout: [{ + cellLayout: [offsetVectorToWorld({ x: 3000, - y: 13500, + y: 10500, z: 3000 - }, { + }), offsetVectorToWorld({ x: 3276.6, - y: 13703.3, + y: 10703.3, z: 4405.6 - }, 1800], - cells: [{ + }), 1800], + cells: [offsetVectorToWorld({ x: 13500, - y: 13500, + y: 10500, z: 13500 - }, { + }), offsetVectorToWorld({ x: 13501, - y: 13501, + y: 10501, z: 13501 - }, 400], - ribosome: [{ + }), 400], + ribosome: [offsetVectorToWorld({ x: 13500, y: 3000, z: 3000 - }, { + }), offsetVectorToWorld({ x: 13685, y: 3248, z: 2861 - }, 1000], - hexokinase: [{ + }), 1000], + hexokinase: [offsetVectorToWorld({ x: 3000, y: 3000, z: 13500 - }, { + }), offsetVectorToWorld({ x: 2755, y: 3121, z: 13501 - }, 2000], - mitochondria: [{ + }), 2000], + mitochondria: [offsetVectorToWorld({ x: 3000, - y: 13500, + y: 10500, z: 3000 - }, { + }), offsetVectorToWorld({ x: 3240, y: 13519, z: 3874 - }, 1000], - translation: [{ + }), 1000], + translation: [offsetVectorToWorld({ x: 3000, - y: 13500, + y: 10500, z: 3000 - }, { + }), offsetVectorToWorld({ x: 2962, - y: 13492, + y: 10492, z: 3342 - }, 1000] + }), 1000] }; +print('JBP locations locations' +JSON.stringify(locations)) + var scenes = [{ name: "Cells", objects: "", @@ -507,7 +542,6 @@ var scenes = [{ function ImportScene(scene) { - var sceneDataLines = scene.objects.split(";"); for (var i = 1; i < sceneDataLines.length; i++) { var data = sceneDataLines[i].split(","); @@ -565,27 +599,15 @@ function ImportScene(scene) { } -clearAllNav(); - -function clearAllNav() { - var result = Entities.findEntities(MyAvatar.position, 25000); - result.forEach(function(r) { - var properties = Entities.getEntityProperties(r, "name"); - if (properties.name.indexOf('navigation button') > -1) { - Entities.deleteEntity(r); - } - }) -} - function createLayoutLights() { Entities.addEntity({ type: "Light", name: "Cell layout light", - position: { + position:offsetVectorToWorld( { x: 3110, - y: 13660, + y: 10660, z: 3785 - }, + }), dimensions: { x: 1500, y: 1500, @@ -602,7 +624,8 @@ function createLayoutLights() { } function CreateNavigationButton(scene, number) { - Entities.addEntity({ + + var nav = Entities.addEntity({ type: "Box", name: scene.name + " navigation button", color: { @@ -634,7 +657,7 @@ function CreateNavigationButton(scene, number) { script: baseLocation + "Scripts/navigationButton.js?" + version, collisionless: true, }); - + print('JBP CREATE NAV AT::' +nav+" name: " + scene.name + ": " + JSON.stringify(scene.location)) } function CreateBoundary(scene) { @@ -8990,10 +9013,13 @@ function assignVariables() { for (var i = 0; i < scenes.length; i++) { // print('setting up scene. first, delete' + JSON.stringify(scenes[i])) - deleteAllInRadius(scenes[i].location, scenes[i].zone.dimensions.x); + // deleteAllInRadius(scenes[i].location, scenes[i].zone.dimensions.x); + CreateNavigationButton(scenes[i], i); + ImportScene(scenes[i]); // print('setting up scene. then import') - CreateNavigationButton(scenes[i], i); + + } createLayoutLights(); @@ -9002,7 +9028,7 @@ Script.scriptEnding.connect(function() { Entities.addingEntity.disconnect(makeUngrabbable); }); -Script.setTimeout(function() { - print('JBP stopping cell science import'); - Script.stop(); -}, 30000) \ No newline at end of file +// Script.setTimeout(function() { +// print('JBP stopping cell science import'); +// Script.stop(); +// }, 30000) \ No newline at end of file diff --git a/unpublishedScripts/DomainContent/CellScience/motorProteinControllerAC.js b/unpublishedScripts/DomainContent/CellScience/motorProteinControllerAC.js index 59577d49ba..bceed9153c 100644 --- a/unpublishedScripts/DomainContent/CellScience/motorProteinControllerAC.js +++ b/unpublishedScripts/DomainContent/CellScience/motorProteinControllerAC.js @@ -16,13 +16,32 @@ if (USE_LOCAL_HOST === true) { baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/" } +var WORLD_OFFSET = { + x: -6000, + y: -6000, + z: -6000 +} + +var WORLD_SCALE_AMOUNT = 1.0; + +function offsetVectorToWorld(vector) { + var newVector; + + newVector = Vec3.sum(vector, WORLD_OFFSET); + + print('JBP NEW VECTOR IS:: ' + JSON.stringify(newVector)) + return newVector +} + var USE_LOCAL_HOST = false; -EntityViewer.setPosition({ +var basePosition = offsetVectorToWorld({ x: 3000, - y: 13500, + y: 10500, z: 3000 }); + +EntityViewer.setPosition(basePosition); EntityViewer.setKeyholeRadius(60000); var octreeQueryInterval = Script.setInterval(function() { EntityViewer.queryOctree(); @@ -44,11 +63,12 @@ var scriptURL = this.baseLocation + "Scripts/clickToRideAndLook.js?" + Math.rand var t = 0; var tInc = 0.001; -var sceneOffset = { +var sceneOffset = offsetVectorToWorld({ x: 3000, - y: 13500, + y: 10500, z: 3000 -}; +}); + var yOffset = { dynein: 16, kinesin: -28 @@ -60,11 +80,11 @@ var terms; var secondaryInit = false; function deleteAllMotorProteins() { - var position = { + var position = offsetVectorToWorld({ x: 3280, - y: 13703, + y: 10703, z: 4405 - }; + }); if (secondaryInit === true) { return; @@ -83,7 +103,7 @@ function deleteAllMotorProteins() { results.forEach(function(r) { var name = Entities.getEntityProperties(r, 'name').name; if (name.indexOf('Hifi-Motor-Protein-Anchor') > -1) { - // print('Script.clearTimeout DELETING A MOTOR PROTEIN::' + r) + // print('Script.clearTimeout DELETING A MOTOR PROTEIN::' + r) Entities.deleteEntity(r); } @@ -95,7 +115,7 @@ function deleteAllMotorProteins() { } function makeAll() { - // print('CREATING MOTOR PROTEINS') + // print('CREATING MOTOR PROTEINS') var segment; var segments = shuffleSegments(); var lastSegment = []; @@ -195,11 +215,11 @@ function update(deltaTime) { print("servers exist -- makeAll..."); Entities.setPacketsPerSecond(6000); print("PPS:" + Entities.getPacketsPerSecond()); - Script.setTimeout(function(){ + Script.setTimeout(function() { //print('SETTING TIMEOUT') - deleteAllMotorProteins() - },10000) - + deleteAllMotorProteins() + }, 10000) + initialized = true; } return; diff --git a/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js b/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js index cf35e081e0..c4ab9dbb5d 100644 --- a/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js +++ b/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js @@ -4,12 +4,29 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +var WORLD_OFFSET = { + x: -6000, + y: -6000, + z: -6000 +} -var basePosition = { +var WORLD_SCALE_AMOUNT = 1.0; + + +function offsetVectorToWorld(vector) { + var newVector; + + newVector = Vec3.sum(vector, WORLD_OFFSET); + + print('JBP NEW VECTOR IS:: ' + JSON.stringify(newVector)) + return newVector +} + +var basePosition = offsetVectorToWorld({ x: 3000, - y: 13500, + y: 10500, z: 3000 -}; +}, WORLD_OFFSET); var initialized = false; diff --git a/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js b/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js index 922f0d94cf..919d0b21df 100644 --- a/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js +++ b/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js @@ -4,12 +4,29 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +var WORLD_OFFSET = { + x: -6000, + y: -6000, + z: -6000 +} -var basePosition = { +var WORLD_SCALE_AMOUNT = 1.0; + +function offsetVectorToWorld(vector) { + var newVector; + + newVector = Vec3.sum(vector, WORLD_OFFSET); + + print('JBP NEW VECTOR IS:: ' + JSON.stringify(newVector)) + return newVector +} + +var basePosition = offsetVectorToWorld({ x: 3000, - y: 13500, + y: 10500, z: 3000 -}; +}, WORLD_OFFSET); + var initialized = false; From 883d4ba006faefc08b253ed7a651098d2d0ac548 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 8 Mar 2016 13:31:23 -0800 Subject: [PATCH 57/87] Only cache processed textures --- .../model-networking/src/model-networking/TextureCache.cpp | 1 + libraries/model-networking/src/model-networking/TextureCache.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index d49ff91abf..82a0b35cc9 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -344,6 +344,7 @@ void NetworkTexture::setImage(const QImage& image, void* voidTexture, int origin _width = _height = 0; } + _isCacheable = true; finishedLoading(true); emit networkTextureCreated(qWeakPointerCast (_self)); diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index af82d2a1ad..ee2279540b 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -132,6 +132,8 @@ signals: protected: + virtual bool isCacheable() const override { return _isCacheable; } + virtual void downloadFinished(const QByteArray& data) override; Q_INVOKABLE void loadContent(const QByteArray& content); @@ -146,6 +148,7 @@ private: int _originalHeight { 0 }; int _width { 0 }; int _height { 0 }; + bool _isCacheable { false }; }; #endif // hifi_TextureCache_h From 27fb7a3143e64471450d6e608192ad92f6c2c2f3 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 8 Mar 2016 15:14:37 -0800 Subject: [PATCH 58/87] handControllerMouse: improve determination of which controller is moving the most That controller will have exclusive control of the mouse reticle. --- examples/controllers/handControllerMouse.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/controllers/handControllerMouse.js b/examples/controllers/handControllerMouse.js index 29e7972cf0..a3f315e10e 100644 --- a/examples/controllers/handControllerMouse.js +++ b/examples/controllers/handControllerMouse.js @@ -76,20 +76,20 @@ Script.update.connect(function(deltaTime) { // Decide which hand should be controlling the pointer // by comparing which one is moving more, and by // tending to stay with the one moving more. - var BIAS_ADJUST_RATE = 0.5; - var BIAS_ADJUST_DEADZONE = 0.05; - leftRightBias += (Vec3.length(poseRight.angularVelocity) - Vec3.length(poseLeft.angularVelocity)) * BIAS_ADJUST_RATE; - if (leftRightBias < BIAS_ADJUST_DEADZONE) { - leftRightBias = 0.0; - } else if (leftRightBias > (1.0 - BIAS_ADJUST_DEADZONE)) { - leftRightBias = 1.0; + var BIAS_ADJUST_PERIOD = 1.0; + if (deltaTime > 0.001) { + var tau = Math.clamp(deltaTime / BIAS_ADJUST_PERIOD, 0, 1); + newLeftRightBias = Vec3.length(poseRight.angularVelocity) - Vec3.length(poseLeft.angularVelocity); + leftRightBias = (1 - tau) * leftRightBias + tau * newLeftRightBias; } + var alpha = leftRightBias > 0 ? 1 : 0; + // Velocity filter the hand rotation used to position reticle so that it is easier to target small things with the hand controllers var VELOCITY_FILTER_GAIN = 0.5; filteredRotatedLeft = Vec3.mix(filteredRotatedLeft, rotatedLeft, Math.clamp(Vec3.length(poseLeft.angularVelocity) * VELOCITY_FILTER_GAIN, 0.0, 1.0)); filteredRotatedRight = Vec3.mix(filteredRotatedRight, rotatedRight, Math.clamp(Vec3.length(poseRight.angularVelocity) * VELOCITY_FILTER_GAIN, 0.0, 1.0)); - var rotated = Vec3.mix(filteredRotatedLeft, filteredRotatedRight, leftRightBias); + var rotated = Vec3.mix(filteredRotatedLeft, filteredRotatedRight, alpha); var absolutePitch = rotated.y; // from 1 down to -1 up ... but note: if you rotate down "too far" it starts to go up again... var absoluteYaw = -rotated.x; // from -1 left to 1 right @@ -110,7 +110,7 @@ Script.update.connect(function(deltaTime) { var AVERAGING_INTERVAL = 0.95; var MINIMUM_CONTROLLER_ANGULAR_VELOCITY = 0.03; - var angularVelocityMagnitude = Vec3.length(poseLeft.angularVelocity) * (1.0 - leftRightBias) + Vec3.length(poseRight.angularVelocity) * leftRightBias; + var angularVelocityMagnitude = Vec3.length(poseLeft.angularVelocity) * (1.0 - alpha) + Vec3.length(poseRight.angularVelocity) * alpha; angularVelocityTrailingAverage = angularVelocityTrailingAverage * AVERAGING_INTERVAL + angularVelocityMagnitude * (1.0 - AVERAGING_INTERVAL); if (!(xRatio == 0.5 && yRatio == 0) && (angularVelocityTrailingAverage > MINIMUM_CONTROLLER_ANGULAR_VELOCITY) && ((x != lastX) || (y != lastY))) { From ce5d83d551fed25bd84467ea401aff4950b12cf4 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 8 Mar 2016 15:32:12 -0800 Subject: [PATCH 59/87] handConttollerMouse.js: improved comments --- examples/controllers/handControllerMouse.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/controllers/handControllerMouse.js b/examples/controllers/handControllerMouse.js index a3f315e10e..518735bdc0 100644 --- a/examples/controllers/handControllerMouse.js +++ b/examples/controllers/handControllerMouse.js @@ -76,13 +76,15 @@ Script.update.connect(function(deltaTime) { // Decide which hand should be controlling the pointer // by comparing which one is moving more, and by // tending to stay with the one moving more. - var BIAS_ADJUST_PERIOD = 1.0; if (deltaTime > 0.001) { + // leftRightBias is a running average of the difference in angular hand speed. + // a positive leftRightBias indicates the right hand is spinning faster then the left hand. + // a negative leftRightBias indicates the left hand is spnning faster. + var BIAS_ADJUST_PERIOD = 1.0; var tau = Math.clamp(deltaTime / BIAS_ADJUST_PERIOD, 0, 1); newLeftRightBias = Vec3.length(poseRight.angularVelocity) - Vec3.length(poseLeft.angularVelocity); leftRightBias = (1 - tau) * leftRightBias + tau * newLeftRightBias; } - var alpha = leftRightBias > 0 ? 1 : 0; // Velocity filter the hand rotation used to position reticle so that it is easier to target small things with the hand controllers From bcd8d8fb30fe6f76f8f7427c5630dd19fa2437b0 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 15:46:55 -0800 Subject: [PATCH 60/87] no water sound --- .../Home/plant/growingPlantEntityScript.js | 22 +------------------ .../Home/plant/growingPlantSpawner.js | 8 +++---- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js index 353c2f825c..1153bd1fdb 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js @@ -33,9 +33,6 @@ max: 1000 }; _this.canCreateFlower = true; - _this.flowersBloomingSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/flowersBlooming.wav"); - _this.soundPlaying = false; - _this.BLOOM_VOLUME = 0.4; }; @@ -60,16 +57,7 @@ flower.grow(); }); - if (!_this.soundPlaying) { - _this.position = Entities.getEntityProperties(_this.entityID, "position").position; - _this.soundPlaying = true; - _this.bloomSoundInjector = Audio.playSound(_this.flowersBloomingSound, {position: _this.position, volume: _this.BLOOM_VOLUME}); - } - }, - - stopWatering: function() { - _this.bloomSoundInjector.stop(); - _this.soundPlaying = false; + }, createFlower: function(position, surfaceNormal) { @@ -135,15 +123,7 @@ } } }; - }, - - unload: function() { - if (_this.bloomSoundInjector) { - _this.bloomSoundInjector.stop(); - delete _this.bloomSoundInjector; - } } - }; // entity scripts always need to return a newly constructed object of our type diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js index a48708eb8a..7b791f74d3 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js @@ -129,10 +129,10 @@ var waterSpout = Entities.addEntity({ }); function cleanup() { - // Entities.deleteEntity(plant); - // Entities.deleteEntity(bowl); - // Entities.deleteEntity(waterCan); - // Entities.deleteEntity(waterSpout); + Entities.deleteEntity(plant); + Entities.deleteEntity(bowl); + Entities.deleteEntity(waterCan); + Entities.deleteEntity(waterSpout); } From 41782dbd8dde437c8243cc15b0ea916f00a1679a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 15:56:06 -0800 Subject: [PATCH 61/87] basic shader --- .../DomainContent/Home/plant/flower.fs | 2 +- .../Home/plant/growingPlantEntityScript.js | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/plant/flower.fs b/unpublishedScripts/DomainContent/Home/plant/flower.fs index 8e35bd1014..d49d283e2c 100644 --- a/unpublishedScripts/DomainContent/Home/plant/flower.fs +++ b/unpublishedScripts/DomainContent/Home/plant/flower.fs @@ -46,7 +46,7 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { color = hsb2rgb(vec3( abs(angle/hueAngleRange) + hueTimeOffset, 0.7, brightness)); - fragColor = vec4(color, 1.0); + fragColor = vec4(1.0, 0.1, 1.0, 1.0); } diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js index 1153bd1fdb..15d720bd51 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js @@ -77,7 +77,10 @@ dimensions: _this.STARTING_FLOWER_DIMENSIONS, userData: JSON.stringify(_this.flowerUserData) }); - var xzGrowthRate = randFloat(0.00005, 0.00015); + // var xzGrowthRate = randFloat(0.00005, 0.00015); + var xzGrowthRate = randFloat(0.0005, 0.0015); + // var growthRate = {x: xzGrowthRate, y: randFloat(0.001, 0.0025, z: xzGrowthRate)}; + var growthRate = {x: xzGrowthRate, y: randFloat(0.01, 0.025), z: xzGrowthRate}; var flower = { id: flowerEntityID, dimensions: { @@ -87,12 +90,9 @@ }, startingPosition: position, rotation: flowerRotation, - maxYDimension: randFloat(0.4, 1.0), - growthRate: { - x: xzGrowthRate, - y: randFloat(0.001, 0.0025), - z: xzGrowthRate - } + // maxYDimension: randFloat(0.4, 1.0), + maxYDimension: randFloat(4, 10.0), + growthRate: growthRate }; flower.grow = function() { // grow flower a bit @@ -113,7 +113,8 @@ preload: function(entityID) { _this.entityID = entityID; - var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs?v1"; + // var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs?v1"; + var SHADER_URL = "file:///C:/Users/Eric/hifi/unpublishedScripts/DomainContent/Home/plant/flower.fs"; _this.flowerUserData = { ProceduralEntity: { shaderUrl: SHADER_URL, From f82dc4569eedbbbc0ebb2153891bb78d5a709983 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 8 Mar 2016 15:59:17 -0800 Subject: [PATCH 62/87] handControllerMouse.js: removed non-uniform scaling. If your controller moves in a circle, the mouse pointer should as well. --- examples/controllers/handControllerMouse.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/examples/controllers/handControllerMouse.js b/examples/controllers/handControllerMouse.js index 518735bdc0..abac0ee397 100644 --- a/examples/controllers/handControllerMouse.js +++ b/examples/controllers/handControllerMouse.js @@ -96,16 +96,8 @@ Script.update.connect(function(deltaTime) { var absolutePitch = rotated.y; // from 1 down to -1 up ... but note: if you rotate down "too far" it starts to go up again... var absoluteYaw = -rotated.x; // from -1 left to 1 right - var ROTATION_BOUND = 0.6; - var clampYaw = Math.clamp(absoluteYaw, -ROTATION_BOUND, ROTATION_BOUND); - var clampPitch = Math.clamp(absolutePitch, -ROTATION_BOUND, ROTATION_BOUND); - - // using only from -ROTATION_BOUND to ROTATION_BOUND - var xRatio = (clampYaw + ROTATION_BOUND) / (2 * ROTATION_BOUND); - var yRatio = (clampPitch + ROTATION_BOUND) / (2 * ROTATION_BOUND); - - var x = screenSizeX * xRatio; - var y = screenSizeY * yRatio; + var x = Math.clamp(screenSizeX * (absoluteYaw + 0.5), 0, screenSizeX); + var y = Math.clamp(screenSizeX * (absolutePitch + 0.5), 0, screenSizeY); // don't move the reticle with the hand controllers unless the controllers are actually being moved // take a time average of angular velocity, and don't move mouse at all if it's below threshold @@ -115,7 +107,7 @@ Script.update.connect(function(deltaTime) { var angularVelocityMagnitude = Vec3.length(poseLeft.angularVelocity) * (1.0 - alpha) + Vec3.length(poseRight.angularVelocity) * alpha; angularVelocityTrailingAverage = angularVelocityTrailingAverage * AVERAGING_INTERVAL + angularVelocityMagnitude * (1.0 - AVERAGING_INTERVAL); - if (!(xRatio == 0.5 && yRatio == 0) && (angularVelocityTrailingAverage > MINIMUM_CONTROLLER_ANGULAR_VELOCITY) && ((x != lastX) || (y != lastY))) { + if ((angularVelocityTrailingAverage > MINIMUM_CONTROLLER_ANGULAR_VELOCITY) && ((x != lastX) || (y != lastY))) { moveReticleAbsolute(x, y); lastX = x; lastY = y; From c928b9e4114d8687d3f17468850bebcfbb40d333 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 16:09:19 -0800 Subject: [PATCH 63/87] starting color --- .../DomainContent/Home/plant/flower.fs | 58 ++++++++++++++----- .../Home/plant/growingPlantEntityScript.js | 25 ++++---- 2 files changed, 56 insertions(+), 27 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/plant/flower.fs b/unpublishedScripts/DomainContent/Home/plant/flower.fs index d49d283e2c..5aed4e7ca0 100644 --- a/unpublishedScripts/DomainContent/Home/plant/flower.fs +++ b/unpublishedScripts/DomainContent/Home/plant/flower.fs @@ -13,19 +13,51 @@ #define TWO_PI 6.28318530718 uniform float iBloomPct = 0.2; -uniform float hueAngleRange = 20.0; -uniform float hueOffset = 0.5; +uniform vec3 iHSLColor = vec3(0.7, 0.5, 0.5); -vec3 hsb2rgb( in vec3 c ){ - vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0), - 6.0)-3.0)-1.0, - 0.0, - 1.0 ); - rgb = rgb*rgb*(3.0-2.0*rgb); - return c.z * mix( vec3(1.0), rgb, c.y); +float hue2rgb(float f1, float f2, float hue) { + if (hue < 0.0) + hue += 1.0; + else if (hue > 1.0) + hue -= 1.0; + float res; + if ((6.0 * hue) < 1.0) + res = f1 + (f2 - f1) * 6.0 * hue; + else if ((2.0 * hue) < 1.0) + res = f2; + else if ((3.0 * hue) < 2.0) + res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0; + else + res = f1; + return res; } +vec3 hsl2rgb(vec3 hsl) { + vec3 rgb; + + if (hsl.y == 0.0) { + rgb = vec3(hsl.z); // Luminance + } else { + float f2; + + if (hsl.z < 0.5) + f2 = hsl.z * (1.0 + hsl.y); + else + f2 = hsl.z + hsl.y - hsl.y * hsl.z; + + float f1 = 2.0 * hsl.z - f2; + + rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0)); + rgb.g = hue2rgb(f1, f2, hsl.x); + rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0)); + } + return rgb; +} + +vec3 hsl2rgb(float h, float s, float l) { + return hsl2rgb(vec3(h, s, l)); +} void mainImage( out vec4 fragColor, in vec2 fragCoord ) { vec2 st = fragCoord.xy/iWorldScale.xz; @@ -41,12 +73,10 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { } // simulate ambient occlusion - float brightness = pow(radius, 0.8); - float hueTimeOffset = sin(iGlobalTime * 0.01) + hueOffset; - color = hsb2rgb(vec3( abs(angle/hueAngleRange) + hueTimeOffset, 0.7, brightness)); - - fragColor = vec4(1.0, 0.1, 1.0, 1.0); + + vec3 rgbColor =hsl2rgb(iHSLColor); + fragColor = vec4(rgbColor, 1.0); } diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js index 15d720bd51..60db78fa0a 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js @@ -66,23 +66,11 @@ return; } var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal); - _this.flowerUserData.ProceduralEntity.uniforms.hueAngleRange = randFloat(20, 40); - _this.flowerUserData.ProceduralEntity.uniforms.hueOffset = Math.random(); - var flowerEntityID = Entities.addEntity({ - type: "Sphere", - name: "flower", - position: position, - collisionless: true, - rotation: flowerRotation, - dimensions: _this.STARTING_FLOWER_DIMENSIONS, - userData: JSON.stringify(_this.flowerUserData) - }); // var xzGrowthRate = randFloat(0.00005, 0.00015); var xzGrowthRate = randFloat(0.0005, 0.0015); // var growthRate = {x: xzGrowthRate, y: randFloat(0.001, 0.0025, z: xzGrowthRate)}; var growthRate = {x: xzGrowthRate, y: randFloat(0.01, 0.025), z: xzGrowthRate}; var flower = { - id: flowerEntityID, dimensions: { x: _this.STARTING_FLOWER_DIMENSIONS.x, y: _this.STARTING_FLOWER_DIMENSIONS.y, @@ -92,8 +80,20 @@ rotation: flowerRotation, // maxYDimension: randFloat(0.4, 1.0), maxYDimension: randFloat(4, 10.0), + startingHSLColor: {hue: 80/360, saturation: 0.47, light: 0.48}, + endingHSLColor: {hue: 19/260, saturation: 0.92, light: 0.41}, growthRate: growthRate }; + _this.flowerUserData.ProceduralEntity.uniforms.iHSLColor= [flower.startingHSLColor.hue, flower.startingHSLColor.saturation, flower.startingHSLColor.light]; + flower.id = Entities.addEntity({ + type: "Sphere", + name: "flower", + position: position, + collisionless: true, + rotation: flowerRotation, + dimensions: _this.STARTING_FLOWER_DIMENSIONS, + userData: JSON.stringify(_this.flowerUserData) + }); flower.grow = function() { // grow flower a bit if (flower.dimensions.y > flower.maxYDimension) { @@ -120,7 +120,6 @@ shaderUrl: SHADER_URL, uniforms: { iBloomPct: randFloat(0.4, 0.8), - hueTwerking: Math.random() } } }; From 17454fdb01caa24e68cb38b1a660a11a9c493895 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 16:36:59 -0800 Subject: [PATCH 64/87] two colors --- .../Home/plant/growingPlantEntityScript.js | 67 +++++++++++++------ 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js index 60db78fa0a..1cf639cd2c 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js @@ -33,6 +33,18 @@ max: 1000 }; _this.canCreateFlower = true; + // _this.SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs?v1"; + _this.SHADER_URL = "file:///C:/Users/Eric/hifi/unpublishedScripts/DomainContent/Home/plant/flower.fs"; + + _this.flowerHSLColors = [{ + hue: 19 / 360, + saturation: 0.92, + light: 0.41 + }, { + hue: 161 / 360, + saturation: 0.28, + light: 0.72 + }]; }; @@ -57,7 +69,7 @@ flower.grow(); }); - + }, createFlower: function(position, surfaceNormal) { @@ -65,11 +77,14 @@ // Reduces flower overlap return; } - var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal); // var xzGrowthRate = randFloat(0.00005, 0.00015); var xzGrowthRate = randFloat(0.0005, 0.0015); // var growthRate = {x: xzGrowthRate, y: randFloat(0.001, 0.0025, z: xzGrowthRate)}; - var growthRate = {x: xzGrowthRate, y: randFloat(0.01, 0.025), z: xzGrowthRate}; + var growthRate = { + x: xzGrowthRate, + y: randFloat(0.01, 0.025), + z: xzGrowthRate + }; var flower = { dimensions: { x: _this.STARTING_FLOWER_DIMENSIONS.x, @@ -77,22 +92,39 @@ z: _this.STARTING_FLOWER_DIMENSIONS.z }, startingPosition: position, - rotation: flowerRotation, + rotation: Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal), // maxYDimension: randFloat(0.4, 1.0), maxYDimension: randFloat(4, 10.0), - startingHSLColor: {hue: 80/360, saturation: 0.47, light: 0.48}, - endingHSLColor: {hue: 19/260, saturation: 0.92, light: 0.41}, + // startingHSLColor: { + // hue: 80 / 360, + // saturation: 0.47, + // light: 0.48 + // }, + // endingHSLColor: { + // hue: 19 / 260, + // saturation: 0.92, + // light: 0.41 + // }, + hslColor: Math.random() < 0.5 ? _this.flowerHSLColors[0] : _this.flowerHSLColors[1], growthRate: growthRate }; - _this.flowerUserData.ProceduralEntity.uniforms.iHSLColor= [flower.startingHSLColor.hue, flower.startingHSLColor.saturation, flower.startingHSLColor.light]; + flower.userData = { + ProceduralEntity: { + shaderUrl: _this.SHADER_URL, + uniforms: { + iBloomPct: randFloat(0.4, 0.8), + iHSLColor: [flower.hslColor.hue, flower.hslColor.saturation, flower.hslColor.light] + } + } + }; flower.id = Entities.addEntity({ type: "Sphere", name: "flower", position: position, collisionless: true, - rotation: flowerRotation, + rotation: flower.rotation, dimensions: _this.STARTING_FLOWER_DIMENSIONS, - userData: JSON.stringify(_this.flowerUserData) + userData: JSON.stringify(flower.userData) }); flower.grow = function() { // grow flower a bit @@ -102,9 +134,14 @@ flower.dimensions = Vec3.sum(flower.dimensions, flower.growthRate); flower.position = Vec3.sum(flower.startingPosition, Vec3.multiply(Quat.getUp(flower.rotation), flower.dimensions.y / 2)); //As we grow we must also move ourselves in direction we grow! + //TODO: Add this color changing back once we fix bug https://app.asana.com/0/inbox/31759584831096/96943843100173/98022172055918 + // var newHue = map(flower.dimensions.y, _this.STARTING_FLOWER_DIMENSIONS.y, flower.maxYDimension, flower.startingHSLColor.hue, flower.endingHSLColor.hue); + // var newSaturation = map(flower.dimensions.y, _this.STARTING_FLOWER_DIMENSIONS.y, flower.maxYDimension, flower.startingHSLColor.saturation, flower.endingHSLColor.saturation); + // var newLight = map(flower.dimensions.y, _this.STARTING_FLOWER_DIMENSIONS.y, flower.maxYDimension, flower.startingHSLColor.light, flower.endingHSLColor.light); + // flower.userData.PrsoceduralEntity.uniforms.iHSLColor = [newHue, newSaturation, newLight]; Entities.editEntity(flower.id, { dimensions: flower.dimensions, - position: flower.position + position: flower.position, }); } _this.flowers.push(flower); @@ -113,16 +150,6 @@ preload: function(entityID) { _this.entityID = entityID; - // var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs?v1"; - var SHADER_URL = "file:///C:/Users/Eric/hifi/unpublishedScripts/DomainContent/Home/plant/flower.fs"; - _this.flowerUserData = { - ProceduralEntity: { - shaderUrl: SHADER_URL, - uniforms: { - iBloomPct: randFloat(0.4, 0.8), - } - } - }; } }; From f7028cef6ed1c2f5e4779fd03af323c8d6827eee Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 16:51:24 -0800 Subject: [PATCH 65/87] Flowers blending more into rocks --- .../DomainContent/Home/plant/flower.fs | 7 ++++--- .../Home/plant/growingPlantEntityScript.js | 18 ++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/plant/flower.fs b/unpublishedScripts/DomainContent/Home/plant/flower.fs index 5aed4e7ca0..b67c910074 100644 --- a/unpublishedScripts/DomainContent/Home/plant/flower.fs +++ b/unpublishedScripts/DomainContent/Home/plant/flower.fs @@ -73,9 +73,10 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) { } // simulate ambient occlusion - - - vec3 rgbColor =hsl2rgb(iHSLColor); + float brightness = pow(radius, 0.8); + vec3 hslColor = iHSLColor + (abs(angle) * 0.02); + hslColor.z = 0.15 + pow(radius, 2.); + vec3 rgbColor = hsl2rgb(hslColor); fragColor = vec4(rgbColor, 1.0); } diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js index 1cf639cd2c..7fb6bb731d 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js @@ -39,11 +39,11 @@ _this.flowerHSLColors = [{ hue: 19 / 360, saturation: 0.92, - light: 0.41 + light: 0.31 }, { hue: 161 / 360, saturation: 0.28, - light: 0.72 + light: 0.62 }]; }; @@ -77,14 +77,9 @@ // Reduces flower overlap return; } - // var xzGrowthRate = randFloat(0.00005, 0.00015); - var xzGrowthRate = randFloat(0.0005, 0.0015); - // var growthRate = {x: xzGrowthRate, y: randFloat(0.001, 0.0025, z: xzGrowthRate)}; - var growthRate = { - x: xzGrowthRate, - y: randFloat(0.01, 0.025), - z: xzGrowthRate - }; + var xzGrowthRate = randFloat(0.00008, 0.00018); + var growthRate = {x: xzGrowthRate, y: randFloat(0.001, 0.0035), z: xzGrowthRate}; + var flower = { dimensions: { x: _this.STARTING_FLOWER_DIMENSIONS.x, @@ -93,8 +88,7 @@ }, startingPosition: position, rotation: Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal), - // maxYDimension: randFloat(0.4, 1.0), - maxYDimension: randFloat(4, 10.0), + maxYDimension: randFloat(0.5, 1.3), // startingHSLColor: { // hue: 80 / 360, // saturation: 0.47, From a236fceeadd0e668d2db967a4fcaa70122c4e7b4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 16:58:42 -0800 Subject: [PATCH 66/87] color pallete --- .../Home/plant/growingPlantEntityScript.js | 13 +++++++------ .../DomainContent/Home/plant/growingPlantSpawner.js | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js index 7fb6bb731d..b6c242f17d 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js @@ -33,8 +33,8 @@ max: 1000 }; _this.canCreateFlower = true; - // _this.SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs?v1"; - _this.SHADER_URL = "file:///C:/Users/Eric/hifi/unpublishedScripts/DomainContent/Home/plant/flower.fs"; + _this.SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs"; + // _this.SHADER_URL = "file:///C:/Users/Eric/hifi/unpublishedScripts/DomainContent/Home/plant/flower.fs"; _this.flowerHSLColors = [{ hue: 19 / 360, @@ -77,8 +77,8 @@ // Reduces flower overlap return; } - var xzGrowthRate = randFloat(0.00008, 0.00018); - var growthRate = {x: xzGrowthRate, y: randFloat(0.001, 0.0035), z: xzGrowthRate}; + var xzGrowthRate = randFloat(0.00006, 0.00016); + var growthRate = {x: xzGrowthRate, y: randFloat(0.001, 0.003), z: xzGrowthRate}; var flower = { dimensions: { @@ -88,7 +88,7 @@ }, startingPosition: position, rotation: Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal), - maxYDimension: randFloat(0.5, 1.3), + maxYDimension: randFloat(0.4, 1.1), // startingHSLColor: { // hue: 80 / 360, // saturation: 0.47, @@ -144,7 +144,8 @@ preload: function(entityID) { _this.entityID = entityID; - } + }, + }; // entity scripts always need to return a newly constructed object of our type diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js index 7b791f74d3..a48708eb8a 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantSpawner.js @@ -129,10 +129,10 @@ var waterSpout = Entities.addEntity({ }); function cleanup() { - Entities.deleteEntity(plant); - Entities.deleteEntity(bowl); - Entities.deleteEntity(waterCan); - Entities.deleteEntity(waterSpout); + // Entities.deleteEntity(plant); + // Entities.deleteEntity(bowl); + // Entities.deleteEntity(waterCan); + // Entities.deleteEntity(waterSpout); } From 9d1217e02d4705d8e16e7a3b53f8adee048a04c0 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 17:37:56 -0800 Subject: [PATCH 67/87] aded lifetime to flowers so they die after a while --- .../DomainContent/Home/plant/growingPlantEntityScript.js | 1 + 1 file changed, 1 insertion(+) diff --git a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js index b6c242f17d..585c603d02 100644 --- a/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js +++ b/unpublishedScripts/DomainContent/Home/plant/growingPlantEntityScript.js @@ -114,6 +114,7 @@ flower.id = Entities.addEntity({ type: "Sphere", name: "flower", + lifetime: 3600, position: position, collisionless: true, rotation: flower.rotation, From bb9957b7f17bc2eb59c718b8f807ce219df41eae Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 8 Mar 2016 18:45:20 -0800 Subject: [PATCH 68/87] using comments from review --- libraries/fbx/src/FBXReader.cpp | 23 +++++++++++++++++------ libraries/fbx/src/FBXReader.h | 10 +++++----- libraries/fbx/src/FBXReader_Material.cpp | 6 ++++-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 17b4cc7c9a..a63cf78393 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -892,24 +892,27 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS } else if (property.properties.at(0) == "DiffuseFactor") { material.diffuseFactor = property.properties.at(index).value(); } else if (property.properties.at(0) == "Diffuse") { - // material.diffuseColor = getVec3(property.properties, index); - // material.diffuseFactor = 1.0; + // NOTE: this is uneeded but keep it for now for debug + // material.diffuseColor = getVec3(property.properties, index); + // material.diffuseFactor = 1.0; } else if (property.properties.at(0) == "SpecularColor") { material.specularColor = getVec3(property.properties, index); } else if (property.properties.at(0) == "SpecularFactor") { material.specularFactor = property.properties.at(index).value(); } else if (property.properties.at(0) == "Specular") { - // material.specularColor = getVec3(property.properties, index); - // material.specularFactor = 1.0; + // NOTE: this is uneeded but keep it for now for debug + // material.specularColor = getVec3(property.properties, index); + // material.specularFactor = 1.0; } else if (property.properties.at(0) == "EmissiveColor") { material.emissiveColor = getVec3(property.properties, index); } else if (property.properties.at(0) == "EmissiveFactor") { material.emissiveFactor = property.properties.at(index).value(); } else if (property.properties.at(0) == "Emissive") { - // material.emissiveColor = getVec3(property.properties, index); - // material.emissiveFactor = 1.0; + // NOTE: this is uneeded but keep it for now for debug + // material.emissiveColor = getVec3(property.properties, index); + // material.emissiveFactor = 1.0; } else if (property.properties.at(0) == "Shininess") { material.shininess = property.properties.at(index).value(); @@ -917,6 +920,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS } else if (property.properties.at(0) == "Opacity") { material.opacity = property.properties.at(index).value(); } + // Sting Ray Material Properties!!!! else if (property.properties.at(0) == "Maya|use_normal_map") { material.isPBSMaterial = true; @@ -925,6 +929,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS } else if (property.properties.at(0) == "Maya|base_color") { material.isPBSMaterial = true; material.diffuseColor = getVec3(property.properties, index); + } else if (property.properties.at(0) == "Maya|use_color_map") { material.isPBSMaterial = true; material.useAlbedoMap = (bool) property.properties.at(index).value(); @@ -932,6 +937,7 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS } else if (property.properties.at(0) == "Maya|roughness") { material.isPBSMaterial = true; material.roughness = property.properties.at(index).value(); + } else if (property.properties.at(0) == "Maya|use_roughness_map") { material.isPBSMaterial = true; material.useRoughnessMap = (bool)property.properties.at(index).value(); @@ -939,20 +945,25 @@ FBXGeometry* FBXReader::extractFBXGeometry(const QVariantHash& mapping, const QS } else if (property.properties.at(0) == "Maya|metallic") { material.isPBSMaterial = true; material.metallic = property.properties.at(index).value(); + } else if (property.properties.at(0) == "Maya|use_metallic_map") { material.isPBSMaterial = true; material.useMetallicMap = (bool)property.properties.at(index).value(); + } else if (property.properties.at(0) == "Maya|emissive") { material.isPBSMaterial = true; material.emissiveColor = getVec3(property.properties, index); + } else if (property.properties.at(0) == "Maya|emissive_intensity") { material.isPBSMaterial = true; material.emissiveIntensity = property.properties.at(index).value(); + } else if (property.properties.at(0) == "Maya|use_emissive_map") { material.isPBSMaterial = true; material.useEmissiveMap = (bool)property.properties.at(index).value(); } else if (property.properties.at(0) == "Maya|use_ao_map") { + material.isPBSMaterial = true; material.useOcclusionMap = (bool)property.properties.at(index).value(); } else { diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index c2b777b0db..a1fc30d1f4 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -138,15 +138,15 @@ public: opacity(opacity) {} glm::vec3 diffuseColor{ 1.0f }; - float diffuseFactor = 1.0f; + float diffuseFactor{ 1.0f }; glm::vec3 specularColor{ 0.02f }; - float specularFactor = 1.0f; + float specularFactor{ 1.0f }; glm::vec3 emissiveColor{ 0.0f }; - float emissiveFactor = 0.0f; + float emissiveFactor{ 0.0f }; - float shininess = 23.0f; - float opacity = 1.0f; + float shininess{ 23.0f }; + float opacity{ 1.0f }; float metallic{ 0.0f }; float roughness{ 1.0f }; diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index b8bca16ef0..60c1e747c0 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -80,10 +80,12 @@ void FBXReader::consolidateFBXMaterials() { QString diffuseFactorTextureID = diffuseFactorTextures.value(material.materialID); if (!diffuseFactorTextureID.isNull() || !diffuseTextureID.isNull()) { - // If both factor and color are specified, color wins + // If both factor and color are specified, the texture bound to DiffuseColor wins if (!diffuseFactorTextureID.isNull() && diffuseTextureID.isNull()) { diffuseTextureID = diffuseFactorTextureID; - // Avoid the DiffuseFactor effect in this case because here Maya would put 0.5... + // If the diffuseTextureID comes from the Texture bound to DiffuseFactor, we know it s exported from maya + // And the DiffuseFactor is forced to 0.5 by Maya which is bad + // So we need to force it to 1.0 material.diffuseFactor = 1.0; } From 5487c4cdab049baf5543edd91eac52a1f87a0072 Mon Sep 17 00:00:00 2001 From: PhilipRosedale Date: Tue, 8 Mar 2016 19:42:11 -0800 Subject: [PATCH 69/87] Firefly script --- examples/fireflies/firefly.js | 100 ++++++++++++++++++++++++++++ examples/fireflies/makeFireflies.js | 89 +++++++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 examples/fireflies/firefly.js create mode 100644 examples/fireflies/makeFireflies.js diff --git a/examples/fireflies/firefly.js b/examples/fireflies/firefly.js new file mode 100644 index 0000000000..e4b1d3f989 --- /dev/null +++ b/examples/fireflies/firefly.js @@ -0,0 +1,100 @@ +// +// A firefly which is animated by passerbys. It's physical, no gravity, periodic forces applied. +// If a firefly is found to +// + +(function () { + var entityID, + timeoutID = null, + properties, + shouldSimulate = false, + ACTIVE_CHECK_INTERVAL = 100, // milliseconds + INACTIVE_CHECK_INTERVAL = 1000, // milliseconds + MAX_DISTANCE_TO_SIMULATE = 20, // meters + LIGHT_LIFETIME = 1400, // milliseconds a firefly light will stay alive + BUMP_SPEED = 1.5, // average velocity given by a bump + BUMP_CHANCE = 0.33, + MIN_SPEED = 0.125, // below this speed, firefly gets a new bump + SPIN_SPEED = 3.5, + BRIGHTNESS = 0.25, + wantDebug = false + + function randomVector(size) { + return { x: (Math.random() - 0.5) * size, + y: (Math.random() - 0.5) * size, + z: (Math.random() - 0.5) * size }; + } + + function printDebug(message) { + if (wantDebug) { + print(message); + } + } + + function maybe() { + properties = Entities.getEntityProperties(entityID); + var speed = Vec3.length(properties.velocity); + var distance = Vec3.distance(MyAvatar.position, properties.position); + printDebug("maybe: speed: " + speed + ", distance: " + distance); + if (shouldSimulate) { + // We are simulating this firefly, so do stuff: + if (distance > MAX_DISTANCE_TO_SIMULATE) { + shouldSimulate = false; + } else if ((speed < MIN_SPEED) && (Math.random() < BUMP_CHANCE)) { + bump(); + makeLight(); + } + } else if (Vec3.length(properties.velocity) == 0.0) { + // We've found a firefly that is not being simulated, so maybe take it over + if (distance < MAX_DISTANCE_TO_SIMULATE) { + shouldSimulate = true; + } + } + timeoutID = Script.setTimeout(maybe, (shouldSimulate == true) ? ACTIVE_CHECK_INTERVAL : INACTIVE_CHECK_INTERVAL); + } + + function bump() { + // Give the firefly a little brownian hop + printDebug("bump!"); + var velocity = randomVector(BUMP_SPEED); + if (velocity.y < 0.0) { velocity.y *= -1.0 }; + Entities.editEntity(entityID, { velocity: velocity, + angularVelocity: randomVector(SPIN_SPEED) }); + } + + function makeLight() { + printDebug("make light!"); + // create a light attached to the firefly that lives for a while + Entities.addEntity({ + type: "Light", + name: "firefly light", + intensity: 4.0 * BRIGHTNESS, + falloffRadius: 8.0 * BRIGHTNESS, + dimensions: { + x: 30 * BRIGHTNESS, + y: 30 * BRIGHTNESS, + z: 30 * BRIGHTNESS + }, + position: Vec3.sum(properties.position, { x: 0, y: 0.2, z: 0 }), + parentID: entityID, + color: { + red: 150 + Math.random() * 100, + green: 100 + Math.random() * 50, + blue: 150 + Math.random() * 100 + }, + lifetime: LIGHT_LIFETIME / 1000 + }); + } + + this.preload = function (givenEntityID) { + printDebug("preload firefly..."); + entityID = givenEntityID; + timeoutID = Script.setTimeout(maybe, ACTIVE_CHECK_INTERVAL); + }; + this.unload = function () { + printDebug("unload firefly..."); + if (timeoutID !== undefined) { + Script.clearTimeout(timeoutID); + } + }; +}) \ No newline at end of file diff --git a/examples/fireflies/makeFireflies.js b/examples/fireflies/makeFireflies.js new file mode 100644 index 0000000000..e4faf54307 --- /dev/null +++ b/examples/fireflies/makeFireflies.js @@ -0,0 +1,89 @@ +// +// Created by Philip Rosedale on March 7, 2016 +// Copyright 2016 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 +// +// Make some fireflies +// + +var SIZE = 0.05; +var TYPE = "Box"; // Right now this can be "Box" or "Model" or "Sphere" +var MODEL_URL = "http://s3.amazonaws.com/hifi-public/models/content/basketball2.fbx"; +var MODEL_DIMENSION = { x: 0.3, y: 0.3, z: 0.3 }; +//var ENTITY_URL = "file:///c:/users/dev/philip/examples/fireflies/firefly.js?"+Math.random() +var ENTITY_URL = "https://s3.amazonaws.com/hifi-public/philip/firefly.js" + +var RATE_PER_SECOND = 50; // The entity server will drop data if we create things too fast. +var SCRIPT_INTERVAL = 100; +var LIFETIME = 3600; + +var NUMBER_TO_CREATE = 200; + +var GRAVITY = { x: 0, y: -1.0, z: 0 }; +var VELOCITY = { x: 0.0, y: 0, z: 0 }; +var ANGULAR_VELOCITY = { x: 1, y: 1, z: 1 }; + +var DAMPING = 0.5; +var ANGULAR_DAMPING = 0.5; + +var collidable = true; +var gravity = true; + + +var x = 0; +var z = 0; +var totalCreated = 0; + +var RANGE = 50; +var HEIGHT = 3; +var HOW_FAR_IN_FRONT_OF_ME = 1.0; + + +var center = Vec3.sum(MyAvatar.position, Vec3.multiply(HOW_FAR_IN_FRONT_OF_ME, Quat.getFront(Camera.orientation))); + + +function randomVector(range) { + return { + x: (Math.random() - 0.5) * range.x, + y: (Math.random() - 0.5) * range.y, + z: (Math.random() - 0.5) * range.z + } +} + +Vec3.print("Center: ", center); + +Script.setInterval(function () { + if (!Entities.serversExist() || !Entities.canRez() || (totalCreated > NUMBER_TO_CREATE)) { + return; + } + + var numToCreate = RATE_PER_SECOND * (SCRIPT_INTERVAL / 1000.0); + for (var i = 0; (i < numToCreate) && (totalCreated < NUMBER_TO_CREATE); i++) { + + var position = Vec3.sum(center, randomVector({ x: RANGE, y: HEIGHT, z: RANGE })); + position.y += HEIGHT / 2.0; + + Entities.addEntity({ + type: TYPE, + modelURL: MODEL_URL, + name: "firefly", + position: position, + dimensions: (TYPE == "Model") ? MODEL_DIMENSION : { x: SIZE, y: SIZE, z: SIZE }, + color: { red: 150 + Math.random() * 100, green: 100 + Math.random() * 50, blue: 0 }, + velocity: VELOCITY, + angularVelocity: Vec3.multiply(Math.random(), ANGULAR_VELOCITY), + damping: DAMPING, + angularDamping: ANGULAR_DAMPING, + gravity: (gravity ? GRAVITY : { x: 0, y: 0, z: 0}), + dynamic: collidable, + script: ENTITY_URL, + lifetime: LIFETIME + }); + + totalCreated++; + print("Firefly #" + totalCreated); + } +}, SCRIPT_INTERVAL); + From 4728eeb862a55fb9a10d234d89cc708ca1fa7b61 Mon Sep 17 00:00:00 2001 From: PhilipRosedale Date: Tue, 8 Mar 2016 20:22:29 -0800 Subject: [PATCH 70/87] less of them --- examples/fireflies/makeFireflies.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/examples/fireflies/makeFireflies.js b/examples/fireflies/makeFireflies.js index e4faf54307..4af7867646 100644 --- a/examples/fireflies/makeFireflies.js +++ b/examples/fireflies/makeFireflies.js @@ -9,21 +9,16 @@ // var SIZE = 0.05; -var TYPE = "Box"; // Right now this can be "Box" or "Model" or "Sphere" -var MODEL_URL = "http://s3.amazonaws.com/hifi-public/models/content/basketball2.fbx"; -var MODEL_DIMENSION = { x: 0.3, y: 0.3, z: 0.3 }; //var ENTITY_URL = "file:///c:/users/dev/philip/examples/fireflies/firefly.js?"+Math.random() -var ENTITY_URL = "https://s3.amazonaws.com/hifi-public/philip/firefly.js" +var ENTITY_URL = "https://s3.amazonaws.com/hifi-public/scripts/fireflies/firefly.js" var RATE_PER_SECOND = 50; // The entity server will drop data if we create things too fast. var SCRIPT_INTERVAL = 100; -var LIFETIME = 3600; +var LIFETIME = 120; -var NUMBER_TO_CREATE = 200; +var NUMBER_TO_CREATE = 100; var GRAVITY = { x: 0, y: -1.0, z: 0 }; -var VELOCITY = { x: 0.0, y: 0, z: 0 }; -var ANGULAR_VELOCITY = { x: 1, y: 1, z: 1 }; var DAMPING = 0.5; var ANGULAR_DAMPING = 0.5; @@ -31,15 +26,11 @@ var ANGULAR_DAMPING = 0.5; var collidable = true; var gravity = true; - -var x = 0; -var z = 0; -var totalCreated = 0; - -var RANGE = 50; +var RANGE = 10; var HEIGHT = 3; var HOW_FAR_IN_FRONT_OF_ME = 1.0; + var totalCreated = 0; var center = Vec3.sum(MyAvatar.position, Vec3.multiply(HOW_FAR_IN_FRONT_OF_ME, Quat.getFront(Camera.orientation))); @@ -66,14 +57,11 @@ Script.setInterval(function () { position.y += HEIGHT / 2.0; Entities.addEntity({ - type: TYPE, - modelURL: MODEL_URL, + type: "Box", name: "firefly", position: position, - dimensions: (TYPE == "Model") ? MODEL_DIMENSION : { x: SIZE, y: SIZE, z: SIZE }, + dimensions: { x: SIZE, y: SIZE, z: SIZE }, color: { red: 150 + Math.random() * 100, green: 100 + Math.random() * 50, blue: 0 }, - velocity: VELOCITY, - angularVelocity: Vec3.multiply(Math.random(), ANGULAR_VELOCITY), damping: DAMPING, angularDamping: ANGULAR_DAMPING, gravity: (gravity ? GRAVITY : { x: 0, y: 0, z: 0}), From 95f5d82d37405bde429133d9348a680dc7682e1a Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 8 Mar 2016 23:45:51 -0800 Subject: [PATCH 71/87] Add a watchdog thread to trigger a crash on detecting a deadlock --- interface/src/Application.cpp | 48 +++++++++++++++++++++++++++++++++++ interface/src/Application.h | 1 + interface/src/Menu.cpp | 2 ++ interface/src/Menu.h | 1 + 4 files changed, 52 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 660e597752..0d6a36f583 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -235,6 +235,42 @@ const QHash Application::_acceptedExtensi { AVA_JSON_EXTENSION, &Application::askToWearAvatarAttachmentUrl } }; +class DeadlockWatchdogThread : public QThread { +public: + static const unsigned long HEARTBEAT_CHECK_INTERVAL_SECS = 1; + static const unsigned long HEARTBEAT_UPDATE_INTERVAL_SECS = 1; + static const unsigned long MAX_HEARTBEAT_AGE_USECS = 10 * USECS_PER_SECOND; + + // Set the heartbeat on launch + DeadlockWatchdogThread() { + QTimer* heartbeatTimer = new QTimer(); + connect(heartbeatTimer, &QTimer::timeout, [this] { + _heartbeat = usecTimestampNow(); + }); + heartbeatTimer->start(HEARTBEAT_UPDATE_INTERVAL_SECS * MSECS_PER_SECOND); + } + + void deadlockDetectionCrash() { + uint32_t* crashTrigger = nullptr; + *crashTrigger = 0xDEAD10CC; + } + + void run() override { + while (!qApp->isAboutToQuit()) { + QThread::sleep(HEARTBEAT_UPDATE_INTERVAL_SECS); + auto now = usecTimestampNow(); + auto lastHeartbeatAge = now - _heartbeat; + if (lastHeartbeatAge > MAX_HEARTBEAT_AGE_USECS) { + deadlockDetectionCrash(); + } + } + } + + static std::atomic _heartbeat; +}; + +std::atomic DeadlockWatchdogThread::_heartbeat; + #ifdef Q_OS_WIN class MyNativeEventFilter : public QAbstractNativeEventFilter { public: @@ -457,6 +493,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) : auto nodeList = DependencyManager::get(); + // Set up a watchdog thread to intentionally crash the application on deadlocks + (new DeadlockWatchdogThread())->start(); + qCDebug(interfaceapp) << "[VERSION] Build sequence:" << qPrintable(applicationVersion()); _bookmarks = new Bookmarks(); // Before setting up the menu @@ -4960,6 +4999,15 @@ void Application::crashApplication() { Q_UNUSED(value); } +void Application::deadlockApplication() { + qCDebug(interfaceapp) << "Intentionally deadlocked Interface"; + // Using a loop that will *technically* eventually exit (in ~600 billion years) + // to avoid compiler warnings about a loop that will never exit + for (uint64_t i = 1; i != 0; ++i) { + QThread::sleep(1); + } +} + void Application::setActiveDisplayPlugin(const QString& pluginName) { auto menu = Menu::getInstance(); foreach(DisplayPluginPointer displayPlugin, PluginManager::getInstance()->getDisplayPlugins()) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 3a727db533..c93b7431f3 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -276,6 +276,7 @@ public slots: void reloadResourceCaches(); void crashApplication(); + void deadlockApplication(); void rotationModeChanged(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index d605516380..164f94a094 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -590,6 +590,8 @@ Menu::Menu() { addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::DisplayCrashOptions, 0, true); // Developer > Crash Application addActionToQMenuAndActionHash(developerMenu, MenuOption::CrashInterface, 0, qApp, SLOT(crashApplication())); + // Developer > Deadlock Application + addActionToQMenuAndActionHash(developerMenu, MenuOption::DeadlockInterface, 0, qApp, SLOT(deadlockApplication())); // Developer > Log... addActionToQMenuAndActionHash(developerMenu, MenuOption::Log, Qt::CTRL | Qt::SHIFT | Qt::Key_L, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index fb00416af0..6d5fd45b66 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -66,6 +66,7 @@ namespace MenuOption { const QString CopyPath = "Copy Path to Clipboard"; const QString CoupleEyelids = "Couple Eyelids"; const QString CrashInterface = "Crash Interface"; + const QString DeadlockInterface = "Deadlock Interface"; const QString DecreaseAvatarSize = "Decrease Avatar Size"; const QString DeleteBookmark = "Delete Bookmark..."; const QString DisableActivityLogger = "Disable Activity Logger"; From 1c0727650123448d612cbee2c09dc6ba4c9aec49 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Wed, 9 Mar 2016 09:45:55 -0800 Subject: [PATCH 72/87] fix a couple bugs --- interface/resources/qml/Stats.qml | 2 +- interface/src/ui/Stats.cpp | 4 +++- interface/src/ui/Stats.h | 4 +++- libraries/entities/src/EntityTree.h | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/interface/resources/qml/Stats.qml b/interface/resources/qml/Stats.qml index 72f92f4d2d..e50f43674e 100644 --- a/interface/resources/qml/Stats.qml +++ b/interface/resources/qml/Stats.qml @@ -115,7 +115,7 @@ Item { color: root.fontColor font.pixelSize: root.fontSize visible: root.expanded; - text: "Voxel max ping: " + 0 + text: "Messages max ping: " + root.messagePing } } } diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index daf6d39cc3..c711560b53 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -136,10 +136,12 @@ void Stats::updateStats(bool force) { SharedNodePointer audioMixerNode = nodeList->soloNodeOfType(NodeType::AudioMixer); SharedNodePointer avatarMixerNode = nodeList->soloNodeOfType(NodeType::AvatarMixer); SharedNodePointer assetServerNode = nodeList->soloNodeOfType(NodeType::AssetServer); + SharedNodePointer messageMixerNode = nodeList->soloNodeOfType(NodeType::MessagesMixer); STAT_UPDATE(audioPing, audioMixerNode ? audioMixerNode->getPingMs() : -1); STAT_UPDATE(avatarPing, avatarMixerNode ? avatarMixerNode->getPingMs() : -1); STAT_UPDATE(assetPing, assetServerNode ? assetServerNode->getPingMs() : -1); - + STAT_UPDATE(messagePing, messageMixerNode ? messageMixerNode->getPingMs() : -1); + //// Now handle entity servers, since there could be more than one, we average their ping times int totalPingOctree = 0; int octreeServerCount = 0; diff --git a/interface/src/ui/Stats.h b/interface/src/ui/Stats.h index 3476087852..ebcb80c404 100644 --- a/interface/src/ui/Stats.h +++ b/interface/src/ui/Stats.h @@ -45,7 +45,8 @@ class Stats : public QQuickItem { STATS_PROPERTY(int, avatarPing, 0) STATS_PROPERTY(int, entitiesPing, 0) STATS_PROPERTY(int, assetPing, 0) - STATS_PROPERTY(QVector3D, position, QVector3D(0, 0, 0) ) + STATS_PROPERTY(int, messagePing, 0) + STATS_PROPERTY(QVector3D, position, QVector3D(0, 0, 0)) STATS_PROPERTY(float, speed, 0) STATS_PROPERTY(float, yaw, 0) STATS_PROPERTY(int, avatarMixerInKbps, 0) @@ -123,6 +124,7 @@ signals: void avatarPingChanged(); void entitiesPingChanged(); void assetPingChanged(); + void messagePingChanged(); void positionChanged(); void speedChanged(); void yawChanged(); diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index b1d8a31254..8190f7225b 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -114,8 +114,8 @@ public: // use this method if you have a pointer to the entity (avoid an extra entity lookup) bool updateEntity(EntityItemPointer entity, const EntityItemProperties& properties, const SharedNodePointer& senderNode = SharedNodePointer(nullptr)); - void deleteEntity(const EntityItemID& entityID, bool force = false, bool ignoreWarnings = false); - void deleteEntities(QSet entityIDs, bool force = false, bool ignoreWarnings = false); + void deleteEntity(const EntityItemID& entityID, bool force = false, bool ignoreWarnings = true); + void deleteEntities(QSet entityIDs, bool force = false, bool ignoreWarnings = true); /// \param position point of query in world-frame (meters) /// \param targetRadius radius of query (meters) From e1a3c5b618eb42a87da22cbeb0d88e35b2f640c8 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Mar 2016 10:31:58 -0800 Subject: [PATCH 73/87] Fix for vertical pitch offset. Also, added hysteresis to the controller selection, to prevent flapping back and forth between controllers when they are at rest. --- examples/controllers/handControllerMouse.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/controllers/handControllerMouse.js b/examples/controllers/handControllerMouse.js index abac0ee397..921999f96a 100644 --- a/examples/controllers/handControllerMouse.js +++ b/examples/controllers/handControllerMouse.js @@ -54,6 +54,7 @@ function debugPrint(message) { var leftRightBias = 0.0; var filteredRotatedLeft = Vec3.UNIT_NEG_Y; var filteredRotatedRight = Vec3.UNIT_NEG_Y; +var lastAlpha = 0; Script.update.connect(function(deltaTime) { @@ -85,7 +86,18 @@ Script.update.connect(function(deltaTime) { newLeftRightBias = Vec3.length(poseRight.angularVelocity) - Vec3.length(poseLeft.angularVelocity); leftRightBias = (1 - tau) * leftRightBias + tau * newLeftRightBias; } - var alpha = leftRightBias > 0 ? 1 : 0; + + // add a bit of hysteresis to prevent control flopping back and forth + // between hands when they are both mostly stationary. + var alpha; + var HYSTERESIS_OFFSET = 0.25; + if (lastAlpha > 0.5) { + // prefer right hand over left + alpha = leftRightBias > -HYSTERESIS_OFFSET ? 1 : 0; + } else { + alpha = leftRightBias > HYSTERESIS_OFFSET ? 1 : 0; + } + lastAlpha = alpha; // Velocity filter the hand rotation used to position reticle so that it is easier to target small things with the hand controllers var VELOCITY_FILTER_GAIN = 0.5; @@ -97,7 +109,7 @@ Script.update.connect(function(deltaTime) { var absoluteYaw = -rotated.x; // from -1 left to 1 right var x = Math.clamp(screenSizeX * (absoluteYaw + 0.5), 0, screenSizeX); - var y = Math.clamp(screenSizeX * (absolutePitch + 0.5), 0, screenSizeY); + var y = Math.clamp(screenSizeX * absolutePitch, 0, screenSizeY); // don't move the reticle with the hand controllers unless the controllers are actually being moved // take a time average of angular velocity, and don't move mouse at all if it's below threshold From 54af58834a9038c517c7acf749816d7efbe29fcd Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 8 Mar 2016 18:19:01 -0800 Subject: [PATCH 74/87] Mark Resource loaded after postprocessing --- libraries/animation/src/AnimationCache.cpp | 1 + libraries/audio/src/Sound.cpp | 2 ++ .../src/model-networking/ShaderCache.cpp | 1 + .../src/model-networking/TextureCache.cpp | 2 -- .../src/model-networking/TextureCache.h | 3 +-- libraries/networking/src/ResourceCache.cpp | 5 ----- libraries/networking/src/ResourceCache.h | 15 +++++++++------ libraries/recording/src/recording/ClipCache.cpp | 1 + 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libraries/animation/src/AnimationCache.cpp b/libraries/animation/src/AnimationCache.cpp index 149e1a3761..ca666443fa 100644 --- a/libraries/animation/src/AnimationCache.cpp +++ b/libraries/animation/src/AnimationCache.cpp @@ -132,6 +132,7 @@ void Animation::animationParseSuccess(FBXGeometry* geometry) { void Animation::animationParseError(int error, QString str) { qCCritical(animation) << "Animation failure parsing " << _url.toDisplayString() << "code =" << error << str; emit failed(QNetworkReply::UnknownContentError); + finishedLoading(false); } AnimationDetails::AnimationDetails() : diff --git a/libraries/audio/src/Sound.cpp b/libraries/audio/src/Sound.cpp index 089ff7544b..9816b1b61d 100644 --- a/libraries/audio/src/Sound.cpp +++ b/libraries/audio/src/Sound.cpp @@ -80,6 +80,8 @@ void Sound::downloadFinished(const QByteArray& data) { qCDebug(audio) << "Unknown sound file type"; } + finishedLoading(true); + _isReady = true; emit ready(); } diff --git a/libraries/model-networking/src/model-networking/ShaderCache.cpp b/libraries/model-networking/src/model-networking/ShaderCache.cpp index d0c5d6631f..7e52052c30 100644 --- a/libraries/model-networking/src/model-networking/ShaderCache.cpp +++ b/libraries/model-networking/src/model-networking/ShaderCache.cpp @@ -15,6 +15,7 @@ NetworkShader::NetworkShader(const QUrl& url, bool delayLoad) void NetworkShader::downloadFinished(const QByteArray& data) { _source = QString::fromUtf8(data); + finishedLoading(true); } ShaderCache& ShaderCache::instance() { diff --git a/libraries/model-networking/src/model-networking/TextureCache.cpp b/libraries/model-networking/src/model-networking/TextureCache.cpp index 82a0b35cc9..a2cd3284ef 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.cpp +++ b/libraries/model-networking/src/model-networking/TextureCache.cpp @@ -344,9 +344,7 @@ void NetworkTexture::setImage(const QImage& image, void* voidTexture, int origin _width = _height = 0; } - _isCacheable = true; finishedLoading(true); emit networkTextureCreated(qWeakPointerCast (_self)); } - diff --git a/libraries/model-networking/src/model-networking/TextureCache.h b/libraries/model-networking/src/model-networking/TextureCache.h index ee2279540b..72a09a8b3f 100644 --- a/libraries/model-networking/src/model-networking/TextureCache.h +++ b/libraries/model-networking/src/model-networking/TextureCache.h @@ -132,7 +132,7 @@ signals: protected: - virtual bool isCacheable() const override { return _isCacheable; } + virtual bool isCacheable() const override { return _loaded; } virtual void downloadFinished(const QByteArray& data) override; @@ -148,7 +148,6 @@ private: int _originalHeight { 0 }; int _width { 0 }; int _height { 0 }; - bool _isCacheable { false }; }; #endif // hifi_TextureCache_h diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index b312067d49..dabf1b098b 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -371,7 +371,6 @@ void Resource::handleReplyFinished() { auto extraInfo = _url == _activeUrl ? "" : QString(", %1").arg(_activeUrl.toDisplayString()); qCDebug(networking).noquote() << QString("Request finished for %1%2").arg(_url.toDisplayString(), extraInfo); - finishedLoading(true); emit loaded(_data); downloadFinished(_data); } else { @@ -409,10 +408,6 @@ void Resource::handleReplyFinished() { _request = nullptr; } - -void Resource::downloadFinished(const QByteArray& data) { -} - uint qHash(const QPointer& value, uint seed) { return qHash(value.data(), seed); } diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 2a89ad9b92..6fbf54c49d 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -177,13 +177,14 @@ public: const QByteArray& getData() const { return _data; } signals: - /// Fired when the resource has been loaded. + /// Fired when the resource has been downloaded. + /// This can be used instead of downloadFinished to access data before it is processed. void loaded(const QByteArray& request); - /// Fired when resource failed to load. + /// Fired when the resource failed to load. void failed(QNetworkReply::NetworkError error); - /// Fired when resource is refreshed. + /// Fired when the resource is refreshed. void onRefresh(); protected slots: @@ -195,10 +196,12 @@ protected: /// Checks whether the resource is cacheable. virtual bool isCacheable() const { return true; } - /// Called when the download has finished - virtual void downloadFinished(const QByteArray& data); + /// Called when the download has finished. + /// This should be overridden by subclasses that need to process the data once it is downloaded. + virtual void downloadFinished(const QByteArray& data) { finishedLoading(true); } - /// Should be called by subclasses when all the loading that will be done has been done. + /// Called when the download is finished and processed. + /// This should be called by subclasses that override downloadFinished to mark the end of processing. Q_INVOKABLE void finishedLoading(bool success); /// Reinserts this resource into the cache. diff --git a/libraries/recording/src/recording/ClipCache.cpp b/libraries/recording/src/recording/ClipCache.cpp index fb09245bf9..37c15b0ca4 100644 --- a/libraries/recording/src/recording/ClipCache.cpp +++ b/libraries/recording/src/recording/ClipCache.cpp @@ -23,6 +23,7 @@ void NetworkClip::init(const QByteArray& clipData) { void NetworkClipLoader::downloadFinished(const QByteArray& data) { _clip->init(data); + finishedLoading(true); } ClipCache& ClipCache::instance() { From f82bd441a955e4cfc38378483d70d8de92f01e1d Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 9 Mar 2016 10:34:49 -0800 Subject: [PATCH 75/87] IMproving th ecomment --- libraries/fbx/src/FBXReader_Material.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXReader_Material.cpp index 60c1e747c0..fb272a1af9 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXReader_Material.cpp @@ -79,8 +79,8 @@ void FBXReader::consolidateFBXMaterials() { QString diffuseTextureID = diffuseTextures.value(material.materialID); QString diffuseFactorTextureID = diffuseFactorTextures.value(material.materialID); + // If both factor and color textures are specified, the texture bound to DiffuseColor wins if (!diffuseFactorTextureID.isNull() || !diffuseTextureID.isNull()) { - // If both factor and color are specified, the texture bound to DiffuseColor wins if (!diffuseFactorTextureID.isNull() && diffuseTextureID.isNull()) { diffuseTextureID = diffuseFactorTextureID; // If the diffuseTextureID comes from the Texture bound to DiffuseFactor, we know it s exported from maya From 80fdef434832784111a161c243b598f2ca6fdafd Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 9 Mar 2016 10:53:01 -0800 Subject: [PATCH 76/87] Ensure the heartbeat has a valid value before the thread starts --- interface/src/Application.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0d6a36f583..ab1a326698 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -244,6 +244,8 @@ public: // Set the heartbeat on launch DeadlockWatchdogThread() { QTimer* heartbeatTimer = new QTimer(); + // Give the heartbeat an initial value + _heartbeat = usecTimestampNow(); connect(heartbeatTimer, &QTimer::timeout, [this] { _heartbeat = usecTimestampNow(); }); From 5daacdf9524407fb9a26793db88b73d0946a7767 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 9 Mar 2016 12:01:22 -0800 Subject: [PATCH 77/87] set offset to zeros --- .../CellScience/importCellScience.js | 31 +++++++++---------- .../CellScience/motorProteinControllerAC.js | 14 ++++----- .../DomainContent/CellScience/moveCellsAC.js | 8 ++--- .../CellScience/moveVesiclesAC.js | 8 ++--- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index 97fbee5135..1e344e6fc2 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,12 +5,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1207; +var version = 1209; var WORLD_OFFSET = { - x: -6000, - y: -6000, - z: -6000 + x: 0, + y: 0, + z: 0 } var WORLD_SCALE_AMOUNT = 1.0; @@ -21,7 +21,6 @@ function offsetVectorToWorld(vector) { newVector = Vec3.sum(vector, WORLD_OFFSET); - print('JBP NEW VECTOR IS:: ' + JSON.stringify(newVector)) return newVector } @@ -58,7 +57,7 @@ assignVariables(); var locations = { cellLayout: [offsetVectorToWorld({ x: 3000, - y: 10500, + y: 13500, z: 3000 }), offsetVectorToWorld({ x: 3276.6, @@ -67,11 +66,11 @@ var locations = { }), 1800], cells: [offsetVectorToWorld({ x: 13500, - y: 10500, + y: 13500, z: 13500 }), offsetVectorToWorld({ x: 13501, - y: 10501, + y: 13501, z: 13501 }), 400], ribosome: [offsetVectorToWorld({ @@ -94,7 +93,7 @@ var locations = { }), 2000], mitochondria: [offsetVectorToWorld({ x: 3000, - y: 10500, + y: 13500, z: 3000 }), offsetVectorToWorld({ x: 3240, @@ -103,16 +102,16 @@ var locations = { }), 1000], translation: [offsetVectorToWorld({ x: 3000, - y: 10500, + y: 13500, z: 3000 }), offsetVectorToWorld({ x: 2962, - y: 10492, + y: 13492, z: 3342 }), 1000] }; -print('JBP locations locations' +JSON.stringify(locations)) +print('JBP locations locations' + JSON.stringify(locations)) var scenes = [{ name: "Cells", @@ -603,7 +602,7 @@ function createLayoutLights() { Entities.addEntity({ type: "Light", name: "Cell layout light", - position:offsetVectorToWorld( { + position: offsetVectorToWorld({ x: 3110, y: 10660, z: 3785 @@ -625,7 +624,7 @@ function createLayoutLights() { function CreateNavigationButton(scene, number) { - var nav = Entities.addEntity({ + var nav = Entities.addEntity({ type: "Box", name: scene.name + " navigation button", color: { @@ -657,7 +656,7 @@ function CreateNavigationButton(scene, number) { script: baseLocation + "Scripts/navigationButton.js?" + version, collisionless: true, }); - print('JBP CREATE NAV AT::' +nav+" name: " + scene.name + ": " + JSON.stringify(scene.location)) + print('JBP CREATE NAV AT::' + nav + " name: " + scene.name + ": " + JSON.stringify(scene.location)) } function CreateBoundary(scene) { @@ -9014,7 +9013,7 @@ function assignVariables() { for (var i = 0; i < scenes.length; i++) { // print('setting up scene. first, delete' + JSON.stringify(scenes[i])) // deleteAllInRadius(scenes[i].location, scenes[i].zone.dimensions.x); - CreateNavigationButton(scenes[i], i); + CreateNavigationButton(scenes[i], i); ImportScene(scenes[i]); // print('setting up scene. then import') diff --git a/unpublishedScripts/DomainContent/CellScience/motorProteinControllerAC.js b/unpublishedScripts/DomainContent/CellScience/motorProteinControllerAC.js index bceed9153c..5f2ef48369 100644 --- a/unpublishedScripts/DomainContent/CellScience/motorProteinControllerAC.js +++ b/unpublishedScripts/DomainContent/CellScience/motorProteinControllerAC.js @@ -8,7 +8,7 @@ var numDynein = 2; var numKinesin = 2; var percentOnMainMT = 100; -//print('RUNNING AC!!'); + var baseLocation; if (USE_LOCAL_HOST === true) { baseLocation = "http://localhost:8080/"; @@ -17,9 +17,9 @@ if (USE_LOCAL_HOST === true) { } var WORLD_OFFSET = { - x: -6000, - y: -6000, - z: -6000 + x: 0, + y: 0, + z: 0 } var WORLD_SCALE_AMOUNT = 1.0; @@ -37,7 +37,7 @@ var USE_LOCAL_HOST = false; var basePosition = offsetVectorToWorld({ x: 3000, - y: 10500, + y: 13500, z: 3000 }); @@ -65,7 +65,7 @@ var t = 0; var tInc = 0.001; var sceneOffset = offsetVectorToWorld({ x: 3000, - y: 10500, + y: 13500, z: 3000 }); @@ -82,7 +82,7 @@ var secondaryInit = false; function deleteAllMotorProteins() { var position = offsetVectorToWorld({ x: 3280, - y: 10703, + y: 13703, z: 4405 }); diff --git a/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js b/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js index c4ab9dbb5d..595da71774 100644 --- a/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js +++ b/unpublishedScripts/DomainContent/CellScience/moveCellsAC.js @@ -5,9 +5,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // var WORLD_OFFSET = { - x: -6000, - y: -6000, - z: -6000 + x: 0, + y: 0, + z: 0 } var WORLD_SCALE_AMOUNT = 1.0; @@ -24,7 +24,7 @@ function offsetVectorToWorld(vector) { var basePosition = offsetVectorToWorld({ x: 3000, - y: 10500, + y: 13500, z: 3000 }, WORLD_OFFSET); diff --git a/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js b/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js index 919d0b21df..b222abdb72 100644 --- a/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js +++ b/unpublishedScripts/DomainContent/CellScience/moveVesiclesAC.js @@ -5,9 +5,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // var WORLD_OFFSET = { - x: -6000, - y: -6000, - z: -6000 + x: 0, + y: 0, + z: 0 } var WORLD_SCALE_AMOUNT = 1.0; @@ -23,7 +23,7 @@ function offsetVectorToWorld(vector) { var basePosition = offsetVectorToWorld({ x: 3000, - y: 10500, + y: 13500, z: 3000 }, WORLD_OFFSET); From dee532e84f9f428c8543124f4741ae41fb6d0a10 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 9 Mar 2016 12:14:53 -0800 Subject: [PATCH 78/87] try to make loading of nav buttons more realiable, etc --- .../CellScience/importCellScience.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index 1e344e6fc2..d051974629 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -5,7 +5,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var version = 1209; +var version = 1211; var WORLD_OFFSET = { x: 0, @@ -15,7 +15,6 @@ var WORLD_OFFSET = { var WORLD_SCALE_AMOUNT = 1.0; - function offsetVectorToWorld(vector) { var newVector; @@ -61,7 +60,7 @@ var locations = { z: 3000 }), offsetVectorToWorld({ x: 3276.6, - y: 10703.3, + y: 13703.3, z: 4405.6 }), 1800], cells: [offsetVectorToWorld({ @@ -9010,6 +9009,8 @@ function assignVariables() { cellLayout = "Object Name,TranslateX,TranslateY,TranslateZ,DimensionX,DimensionY,DimensionZ, RotateX, RotateY, RotateZ;NPC,197.8817968,187.1750856,343.3718791,24.13382446,34.22486206,30.38697693,46.23119528,-8.353895581,8.869973765;NPC,213.3709151,2.456316462,423.9885128,25.53621185,34.58618774,24.07834717,90.38281992,-7.832244708,0;NPC,33.34912856,2.090308135,365.04642,25.53621185,34.58618774,24.07834717,90.39885078,-38.49088523,0;NPC,397.5101386,159.5911591,319.6113615,25.53621185,34.58618774,24.07834717,50.3605842,37.83254121,0;NPC,156.5827125,-122.5087526,377.9210147,25.53621185,34.58618774,24.07834717,115.9481277,-11.66518146,0;golgi,-318.7046145,66.9773569,976.6478796,211.1744971,156.6775269,204.0570996,115.0039041,-35.67118658,-77.29622127;golgi,456.0077009,0,-837.4997205,235.0718115,174.4077612,227.1489771,-25.72753579,12.39046363,101.1906405;microtubule1,212.4149854,132.4649414,944.2434082,142.5869824,122.8758984,880.6406836,0,0,0;microtubule10,673.8832031,311.0911194,-148.9548248,200.3548828,452.0626831,200.2862878,0,0,0;microtubule11,732.2112598,361.0221094,-546.264873,89.10005859,364.5919922,488.656582,0,0,0;microtubule12,739.5973828,340.5306592,-314.7477979,71.43855469,381.5696191,163.5716895,0,0,0;microtubule13,547.683501,315.5453137,-194.0386853,450.7195605,452.5557788,230.4621606,0,0,0;microtubule14,556.663916,415.2724512,-436.4479395,283.920293,207.0583008,657.0294727,0,0,0;microtubule15,660.601377,201.7332788,-572.2047363,508.4347852,224.4388916,408.4554492,0,0,0;microtubule16,506.7585205,204.8784119,-527.3789355,154.4813965,242.6824146,450.410918,0,0,0;microtubule17,212.1601877,58.27322021,-728.5755762,367.6139996,489.4616455,107.694668,0,0,0;microtubule18,398.5259912,137.8724231,-665.1991992,112.6322754,371.4562866,196.6646484,0,0,0;microtubule19,380.7953174,226.3009131,-449.3071655,81.91825195,156.3450879,654.2884424,0,0,0;microtubule2,30.6969873,141.0839227,876.8226709,232.4791699,192.0579456,920.3092676,0,0,0;microtubule20,-17.70177979,102.1328238,-793.8511963,249.8578271,254.9617255,626.1412793,0,0,0;microtubule21,77.27729828,414.6652734,-875.5563281,112.0010284,370.8857812,414.7598437,0,0,0;microtubule22,206.3877283,127.7296783,-799.063623,248.5948755,233.9102527,596.1479883,0,0,0;microtubule23,26.83012939,306.4021143,-869.8149609,151.6807324,229.8870996,438.0902344,0,0,0;microtubule24,130.2055444,10.68804199,-875.882373,102.7668896,337.1855273,478.814707,0,0,0;microtubule25,466.3101562,323.6335986,125.3250128,363.4645312,146.882959,368.3232751,0,0,0;microtubule26,486.9932666,242.030116,363.5398682,289.2078809,287.3686157,132.0589746,0,0,0;microtubule27,577.1186426,218.112627,122.2437305,136.8993164,381.0901172,311.8405664,0,0,0;microtubule28,477.9364307,294.2746069,284.5083691,329.104834,203.73854,36.79857422,0,0,0;microtubule29,602.5964648,317.1294214,80.40759521,130.0769531,205.3262549,366.1346924,0,0,0;microtubule3,-139.0224133,-173.8191055,-427.1847363,337.7971655,363.020246,759.5431055,0,0,0;microtubule30,559.5994629,-337.2936108,210.2427393,166.3097461,468.162583,203.6533301,0,0,0;microtubule31,419.9002661,-500.184126,316.3121631,407.9912256,122.8493262,84.17920898,0,0,0;microtubule32,532.1963672,-447.1643115,104.0702747,257.4648047,199.2719238,389.7403491,0,0,0;microtubule33,482.8850098,-448.0571045,311.7472119,325.9098633,212.6162988,44.34436523,0,0,0;microtubule34,621.9338965,-416.982041,118.7065613,126.4250977,271.4240039,329.2003931,0,0,0;microtubule35,-118.3220728,110.4977856,955.7098828,622.6587451,493.0616748,154.8304687,0,0,0;microtubule36,-38.73700195,295.7910132,735.6735938,813.0149414,130.0887158,432.2794922,0,0,0;microtubule37,-147.0284253,183.0389575,716.1807568,518.7239502,341.7746631,490.7852051,0,0,0;microtubule38,-505.4994727,260.7653027,570.3792847,172.7321484,194.3118164,730.0565479,0,0,0;microtubule39,-330.203606,255.0918164,658.6816846,226.97896,194.4717773,593.7860449,0,0,0;microtubule4,97.25859375,-81.19509682,-651.4826221,787.3532813,177.7109001,338.228584,0,0,0;microtubule40,-200.9843848,60.38698975,720.7139062,519.6625781,586.7271533,430.7780859,0,0,0;microtubule41,287.1684814,114.7601161,777.7985156,734.9856152,206.0788889,468.8053125,0,0,0;microtubule42,589.3171875,134.296333,583.4237842,159.3030469,180.6350391,838.2054785,0,0,0;microtubule43,445.5135352,-95.13089355,938.1663281,392.8723828,599.7641895,169.9720312,0,0,0;microtubule44,428.9714355,45.15916992,676.3465869,449.8033008,347.0653711,673.1271387,0,0,0;microtubule45,505.1379199,-83.39869629,677.9993848,336.0916992,599.8922168,643.4302148,0,0,0;microtubule46,-279.8748102,-401.6762476,540.5428711,625.014364,334.9703174,104.5120312,0,0,0;microtubule47,-522.0736963,-360.1754443,303.4938977,123.0875684,374.5616895,402.6039624,0,0,0;microtubule48,-264.077915,-531.3914502,398.5253467,593.5828418,83.4909668,304.2609082,0,0,0;microtubule49,-462.3454541,-368.403479,406.0618945,204.1284668,400.7098389,246.7103906,0,0,0;microtubule5,-235.8658887,142.852633,-458.1761499,168.1641211,281.0347536,659.5777002,0,0,0;microtubule50,-270.6177164,-552.1942676,517.5230713,567.2812079,107.8213477,107.9428418,0,0,0;microtubule51,-309.9686316,345.4123975,-270.0235071,393.3619556,196.0721777,612.4700171,0,0,0;microtubule52,-461.5955127,164.0074951,-133.1996063,94.17870117,568.1300684,386.5102991,0,0,0;microtubule53,-349.3235669,233.7860156,-66.56753998,315.557124,399.5180273,164.2730255,0,0,0;microtubule54,-363.6500024,351.6772412,320.7801343,276.5947998,201.2884863,511.4768408,0,0,0;microtubule55,-393.347124,280.0743311,102.1417091,227.8053223,299.9349316,204.8680662,0,0,0;microtubule56,-227.535769,288.7856909,-53.67977051,539.6171338,325.6723096,250.9921875,0,0,0;microtubule6,-20.18329102,-70.09014084,-483.5474414,577.0610156,153.2483414,647.0252344,0,0,0;microtubule7,15.20736328,62.57915131,-463.1074878,619.3040039,159.3178107,683.8982666,0,0,0;microtubule8,557.853501,434.7157031,14.36625,435.7967871,218.8402734,572.1272461,0,0,0;microtubule9,790.0964648,302.6857306,-46.75898437,106.6875,484.5883044,487.1542383,0,0,0;mitochondria1,509.9553464,60.67585787,598.6037478,56.38573425,55.78621948,97.22390625,18.53970718,0,0;mitochondria2,236.1862652,8.347496228,771.7170695,69.44670044,68.70831848,160.0913306,0,-58.66119162,0;mitochondria3,-237.8879342,-80.8010362,794.9918666,74.3063324,72.65880615,278.4640576,12.50616674,-13.37802957,-34.78928216;mitochondria4,-480.3502638,0,623.5202907,56.38573425,55.78621948,97.22390625,0,0,0;mitochondria5,654.307804,246.0744739,370.0455458,69.44670044,68.70831848,160.0913306,-55.07883972,0,0;mitochondria6,0,-464.9341727,0,69.44670044,68.70831848,160.0913306,-25.64558815,-58.48676953,-21.37185167;mitochondria7,0,0,-581.7224431,69.44670044,68.70831848,160.0913306,4.948279917,-70.48661547,121.4859061;mitochondria8,624.0007,49.31601383,-87.21635338,69.44670044,68.70831848,160.0913306,89.76656115,-5.023110397,-48.14947773;nucleus,208.5936936,6.113100222,153.3202277,522.7149005,515.7176939,518.1826595,0,0,0;rough_ER1,253.871543,-69.16218018,184.1513013,624.6314062,553.1499756,621.0511084,0,0,0;rough_ER2,221.76854,64.61654297,146.9922729,621.8760059,558.2816016,585.9084229,0,0,0;smoothER,-132.954492,-89.25859014,80.62120204,376.5313623,386.0319287,318.3009668,122.954661,-71.58529221,-50.75833529;smoothER,-139.2748633,-37.55435675,275.4559992,350.3096777,359.3174121,299.3762402,-12.50517141,-27.97002065,5.954923214;smoothER,243.6573639,10.98815226,-278.1663356,402.7864746,412.9494434,340.4957227,0,0,0;"; } +Script.setTimeout(function(){ + for (var i = 0; i < scenes.length; i++) { // print('setting up scene. first, delete' + JSON.stringify(scenes[i])) // deleteAllInRadius(scenes[i].location, scenes[i].zone.dimensions.x); @@ -9022,10 +9023,12 @@ for (var i = 0; i < scenes.length; i++) { } createLayoutLights(); +},3500) -Script.scriptEnding.connect(function() { - Entities.addingEntity.disconnect(makeUngrabbable); -}); + +// Script.scriptEnding.connect(function() { +// Entities.addingEntity.disconnect(makeUngrabbable); +// }); // Script.setTimeout(function() { // print('JBP stopping cell science import'); From 5a54bc548ba2495feea656d3ff7bb10b4aba043e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 9 Mar 2016 12:19:02 -0800 Subject: [PATCH 79/87] remove ungrabbable signal --- .../CellScience/importCellScience.js | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/unpublishedScripts/DomainContent/CellScience/importCellScience.js b/unpublishedScripts/DomainContent/CellScience/importCellScience.js index d051974629..bd9da50989 100644 --- a/unpublishedScripts/DomainContent/CellScience/importCellScience.js +++ b/unpublishedScripts/DomainContent/CellScience/importCellScience.js @@ -43,14 +43,6 @@ var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScie var utilsScript = Script.resolvePath('Scripts/utils.js'); Script.include(utilsScript); -// function makeUngrabbable(entityID) { -// setEntityCustomData('grabbableKey', entityID, { -// grabbable: false -// }); -// } - -// Entities.addingEntity.connect(makeUngrabbable); - assignVariables(); var locations = { @@ -9013,7 +9005,7 @@ Script.setTimeout(function(){ for (var i = 0; i < scenes.length; i++) { // print('setting up scene. first, delete' + JSON.stringify(scenes[i])) - // deleteAllInRadius(scenes[i].location, scenes[i].zone.dimensions.x); + CreateNavigationButton(scenes[i], i); ImportScene(scenes[i]); @@ -9026,11 +9018,3 @@ createLayoutLights(); },3500) -// Script.scriptEnding.connect(function() { -// Entities.addingEntity.disconnect(makeUngrabbable); -// }); - -// Script.setTimeout(function() { -// print('JBP stopping cell science import'); -// Script.stop(); -// }, 30000) \ No newline at end of file From 6e24b66b38905a752b3970e795a03206f921b640 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 9 Mar 2016 12:21:31 -0800 Subject: [PATCH 80/87] Fix edit.js upload button --- libraries/ui/src/OffscreenUi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ui/src/OffscreenUi.cpp b/libraries/ui/src/OffscreenUi.cpp index ce7ea169f3..745a28eb0b 100644 --- a/libraries/ui/src/OffscreenUi.cpp +++ b/libraries/ui/src/OffscreenUi.cpp @@ -326,8 +326,8 @@ QVariant OffscreenUi::inputDialog(const Icon icon, const QString& title, const Q QVariant result; QMetaObject::invokeMethod(this, "inputDialog", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QVariant, result), - Q_ARG(QString, title), Q_ARG(Icon, icon), + Q_ARG(QString, title), Q_ARG(QString, label), Q_ARG(QVariant, current)); return result; From bdc2ac73f6439971f73ed66eda171d7ff1699bb7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 9 Mar 2016 11:37:07 -0800 Subject: [PATCH 81/87] manually remove Raleway font that has incorrect casing --- cmake/templates/NSIS.template.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/templates/NSIS.template.in b/cmake/templates/NSIS.template.in index ee59f4a3ac..c4bf975f60 100644 --- a/cmake/templates/NSIS.template.in +++ b/cmake/templates/NSIS.template.in @@ -589,6 +589,9 @@ Section "-Core installation" Delete "$INSTDIR\version" Delete "$INSTDIR\xinput1_3.dll" + ; Delete the incorrectly cased Raleway font + Delete "$INSTDIR\resources\qml\styles-uit\RalewaySemibold.qml" + ; Remove the Old Interface directory and vcredist_x64.exe (from installs prior to Server Console) RMDir /r "$INSTDIR\Interface" Delete "$INSTDIR\vcredist_x64.exe" From 0c45ed038cb54542117f2976aad8262f5e68c0da Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 9 Mar 2016 12:58:23 -0800 Subject: [PATCH 82/87] attempt rename to change casing of Raleway font --- cmake/templates/NSIS.template.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/templates/NSIS.template.in b/cmake/templates/NSIS.template.in index c4bf975f60..ca26be6ab0 100644 --- a/cmake/templates/NSIS.template.in +++ b/cmake/templates/NSIS.template.in @@ -589,8 +589,8 @@ Section "-Core installation" Delete "$INSTDIR\version" Delete "$INSTDIR\xinput1_3.dll" - ; Delete the incorrectly cased Raleway font - Delete "$INSTDIR\resources\qml\styles-uit\RalewaySemibold.qml" + ; Rename the incorrectly cased Raleway font + Rename "$INSTDIR\resources\qml\styles-uit\RalewaySemibold.qml" "$INSTDIR\resources\qml\styles-uit\RalewaySemiBold.qml" ; Remove the Old Interface directory and vcredist_x64.exe (from installs prior to Server Console) RMDir /r "$INSTDIR\Interface" From 21719b3980a34f9c7eaaa20948fe96bce07d4748 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Wed, 9 Mar 2016 13:44:46 -0800 Subject: [PATCH 83/87] Wait 10m for DEBUG deadlocks --- interface/src/Application.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ab1a326698..f84a60a332 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -239,7 +239,11 @@ class DeadlockWatchdogThread : public QThread { public: static const unsigned long HEARTBEAT_CHECK_INTERVAL_SECS = 1; static const unsigned long HEARTBEAT_UPDATE_INTERVAL_SECS = 1; +#ifdef DEBUG + static const unsigned long MAX_HEARTBEAT_AGE_USECS = 600 * USECS_PER_SECOND; +#else static const unsigned long MAX_HEARTBEAT_AGE_USECS = 10 * USECS_PER_SECOND; +#endif // Set the heartbeat on launch DeadlockWatchdogThread() { From 5230d3a7055e50518ccec8e368311194554de756 Mon Sep 17 00:00:00 2001 From: PhilipRosedale Date: Wed, 9 Mar 2016 14:45:26 -0800 Subject: [PATCH 84/87] Added header --- examples/fireflies/firefly.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/fireflies/firefly.js b/examples/fireflies/firefly.js index e4b1d3f989..4e4c5d7844 100644 --- a/examples/fireflies/firefly.js +++ b/examples/fireflies/firefly.js @@ -1,4 +1,10 @@ // +// Created by Philip Rosedale on March 7, 2016 +// Copyright 2016 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 +// // A firefly which is animated by passerbys. It's physical, no gravity, periodic forces applied. // If a firefly is found to // From 974189b5464f5468712d7c882bab713042e8e0a4 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 9 Mar 2016 15:10:35 -0800 Subject: [PATCH 85/87] deleted cartridge spawner --- examples/VR-VJ/cartridgesSpawner.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 examples/VR-VJ/cartridgesSpawner.js diff --git a/examples/VR-VJ/cartridgesSpawner.js b/examples/VR-VJ/cartridgesSpawner.js deleted file mode 100644 index e69de29bb2..0000000000 From 7b20fdcc1afad252ecb2fa468613f1045f537a5a Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 9 Mar 2016 15:14:51 -0800 Subject: [PATCH 86/87] add file before delete --- examples/VR-VJ/file | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 examples/VR-VJ/file diff --git a/examples/VR-VJ/file b/examples/VR-VJ/file new file mode 100644 index 0000000000..e69de29bb2 From 05d26be300279d98f468bce0162d5a8b550cf61e Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 9 Mar 2016 15:15:20 -0800 Subject: [PATCH 87/87] delete file --- examples/VR-VJ/file | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 examples/VR-VJ/file diff --git a/examples/VR-VJ/file b/examples/VR-VJ/file deleted file mode 100644 index e69de29bb2..0000000000