mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 23:14:34 +02:00
flowers are growing when watered
This commit is contained in:
parent
af2816b8db
commit
17dec9446a
3 changed files with 57 additions and 15 deletions
|
@ -17,27 +17,71 @@
|
||||||
var _this;
|
var _this;
|
||||||
GrowingPlant = function() {
|
GrowingPlant = function() {
|
||||||
_this = this;
|
_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 = {
|
GrowingPlant.prototype = {
|
||||||
|
|
||||||
|
|
||||||
grow: function() {
|
continueWatering: function(entityID, data) {
|
||||||
print(" I AM BEING GROWN RIGHT NOW")
|
// 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) {
|
preload: function(entityID) {
|
||||||
_this.entityID = 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() {
|
unload: function() {
|
||||||
|
_this.flowers.forEach(function(flower) {
|
||||||
|
Entities.deleteEntity(flower.id);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -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_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 plantDimensions = {x: 0.52, y: 0.2600, z: 0.52};
|
||||||
var plantPosition = Vec3.sum(bowlPosition, {x: 0, y: plantDimensions.y/2, z: 0});
|
var plantPosition = Vec3.sum(bowlPosition, {x: 0, y: plantDimensions.y/2, z: 0});
|
||||||
var plant = Entities.addEntity({
|
var plant = Entities.addEntity({
|
||||||
|
@ -42,8 +42,8 @@ var plant = Entities.addEntity({
|
||||||
parentID: bowl
|
parentID: bowl
|
||||||
});
|
});
|
||||||
|
|
||||||
var WATER_CAN_MODEL_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/models/waterCan.fbx";
|
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());
|
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 waterCanPosition = Vec3.sum(plantPosition, Vec3.multiply(0.6, Quat.getRight(orientation)));
|
||||||
var waterCanRotation = orientation;
|
var waterCanRotation = orientation;
|
||||||
var waterCan = Entities.addEntity({
|
var waterCan = Entities.addEntity({
|
||||||
|
|
|
@ -59,7 +59,6 @@
|
||||||
});
|
});
|
||||||
_this.waterPouring = false;
|
_this.waterPouring = false;
|
||||||
}
|
}
|
||||||
// print("PITCH " + pitch);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
castRay: function() {
|
castRay: function() {
|
||||||
|
@ -78,10 +77,9 @@
|
||||||
var intersection = Entities.findRayIntersection(pickRay, true, _this.growableEntities);
|
var intersection = Entities.findRayIntersection(pickRay, true, _this.growableEntities);
|
||||||
|
|
||||||
if (intersection.intersects) {
|
if (intersection.intersects) {
|
||||||
//We've intersected with a growable object, now
|
//We've intersected with a waterable object
|
||||||
print(intersection.properties.name)
|
var data = JSON.stringify({position: intersection.intersection, surfaceNormal: intersection.surfaceNormal});
|
||||||
print("intersection with growable object");
|
Entities.callEntityMethod(intersection.entityID, 'continueWatering', [data]);
|
||||||
Entities.callEntityMethod(intersection.entityID, 'grow');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue