From cdd4fdb03e263f9a14ed7793d0c44a4f74a109ea Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Mon, 7 Mar 2016 14:04:45 -0800 Subject: [PATCH] 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,