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