From f09dd81a145b8231b5792a1514ef016821c610d1 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Thu, 11 Feb 2016 19:06:11 -0800 Subject: [PATCH] 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); }