From 7fe555d3a59d0b435481335dba4c31eb31ed9e27 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Wed, 10 Feb 2016 15:44:34 -0800 Subject: [PATCH 01/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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 7b69aa375e94587767e319b5b4b5e9a1eedc7ec6 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 7 Mar 2016 18:18:38 -0800 Subject: [PATCH 47/63] 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 48/63] 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 451856ae679ec1fa632d4e546d7efafc2d21af07 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 08:14:57 -0800 Subject: [PATCH 49/63] 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 5299b06e832da5ea3ffb1f5da5bdf0ac03ee1920 Mon Sep 17 00:00:00 2001 From: samcake Date: Tue, 8 Mar 2016 11:26:16 -0800 Subject: [PATCH 50/63] 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 51/63] 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 883d4ba006faefc08b253ed7a651098d2d0ac548 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 8 Mar 2016 13:31:23 -0800 Subject: [PATCH 52/63] 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 bcd8d8fb30fe6f76f8f7427c5630dd19fa2437b0 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 15:46:55 -0800 Subject: [PATCH 53/63] 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 54/63] 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 c928b9e4114d8687d3f17468850bebcfbb40d333 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 8 Mar 2016 16:09:19 -0800 Subject: [PATCH 55/63] 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 56/63] 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 57/63] 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 58/63] 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 59/63] 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 60/63] 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 95f5d82d37405bde429133d9348a680dc7682e1a Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 8 Mar 2016 23:45:51 -0800 Subject: [PATCH 61/63] 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 f82bd441a955e4cfc38378483d70d8de92f01e1d Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 9 Mar 2016 10:34:49 -0800 Subject: [PATCH 62/63] 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 63/63] 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(); });