From e5364fd186568c4c6606277e1b5f54d80e0572f0 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 22 Mar 2016 17:33:18 -0700 Subject: [PATCH] update --- .../virtualBaton/batonSimpleEntityScript.js | 71 +++++++++++++------ .../virtualBaton/batonSimpleEntitySpawner.js | 9 +-- examples/libraries/utils.js | 13 +++- 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/examples/entityScripts/virtualBaton/batonSimpleEntityScript.js b/examples/entityScripts/virtualBaton/batonSimpleEntityScript.js index 22eb90cc26..7a0076e9f6 100644 --- a/examples/entityScripts/virtualBaton/batonSimpleEntityScript.js +++ b/examples/entityScripts/virtualBaton/batonSimpleEntityScript.js @@ -1,11 +1,27 @@ (function() { Script.include("../../libraries/virtualBaton.js"); + Script.include("../../libraries/utils.js"); var _this = this; this.startUpdate = function() { - Entities.editEntity(_this.batonDebugModel, {visible: true}); + Entities.editEntity(_this.batonOwnerIndicator, { + visible: true + }); + + // Change color of box + Entities.editEntity(_this.entityID, { + color: randomColor() + }); + + _this.position = Entities.getEntityProperties(_this.entityID, "position").position; + _this.debugLightProperties.position = Vec3.sum(_this.position, {x: 0, y: 1, z: 0}); + _this.debugLightProperties.color = randomColor(); + var debugLight = Entities.addEntity(_this.debugLightProperties); + Script.setTimeout(function() { + Entities.deleteEntity(debugLight); + }, 500); } @@ -13,17 +29,34 @@ if (_this.isBatonOwner === true) { _this.isBatonOwner = false; } - Entities.editEntity(_this.batonDebugModel, {visible: false}); + Entities.editEntity(_this.batonOwnerIndicator, { + visible: false + }); baton.claim(_this.startUpdate, _this.maybeClaim); } this.unload = function() { baton.unload(); + Entities.deleteEntity(_this.batonOwnerIndicator); } + this.preload = function(entityID) { - _this.entityID = entityID - _this.batonDebugModel = Entities.addEntity({ + _this.entityID = entityID; + _this.setupDebugEntities(); + + baton = virtualBaton({ + batonName: "batonSimpleEntityScript:" + _this.entityID + }); + _this.isBatonOwner = false; + _this.maybeClaim(); + + print("EBL Preload!!"); + } + + + this.setupDebugEntities = function() { + _this.batonOwnerIndicator = Entities.addEntity({ type: "Box", color: { red: 200, @@ -43,26 +76,18 @@ parentID: MyAvatar.sessionUUID, visible: false }); - _this.colorsToCycle = [{ - red: 200, - green: 0, - blue: 0 - }, { - red: 0, - green: 200, - blue: 0 - }, { - red: 0, - green: 0, - blue: 200 - }]; - baton = virtualBaton({ - batonName: "batonSimpleEntityScript:" + _this.entityID - }); - _this.isBatonOwner = false; - _this.maybeClaim(); + } - print("EBL Preload!!"); + _this.debugLightProperties = { + type: "Light", + name: "hifi-baton-light", + dimensions: { + x: 10, + y: 10, + z: 10 + }, + falloffRadius: 3, + intensity: 20, } }); \ No newline at end of file diff --git a/examples/entityScripts/virtualBaton/batonSimpleEntitySpawner.js b/examples/entityScripts/virtualBaton/batonSimpleEntitySpawner.js index c596b8c5f2..f74c1ad774 100644 --- a/examples/entityScripts/virtualBaton/batonSimpleEntitySpawner.js +++ b/examples/entityScripts/virtualBaton/batonSimpleEntitySpawner.js @@ -7,13 +7,13 @@ // Math.random ensures no caching of script var SCRIPT_URL = Script.resolvePath("batonSimpleEntityScript.js?v1" + Math.random()); - var myEntity = Entities.addEntity({ + var batonBox = Entities.addEntity({ type: "Box", name: "hifi-baton-entity", color: { red: 200, - green: 10, - blue: 10 + green: 200, + blue: 200 }, position: center, dimensions: { @@ -25,8 +25,9 @@ }); + function cleanup() { - Entities.deleteEntity(myEntity); + Entities.deleteEntity(batonBox); } Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/examples/libraries/utils.js b/examples/libraries/utils.js index f4a431a657..2dca32aa4f 100644 --- a/examples/libraries/utils.js +++ b/examples/libraries/utils.js @@ -28,7 +28,6 @@ colorMix = function(colorA, colorB, mix) { } return result; } - scaleLine = function (start, end, scale) { var v = Vec3.subtract(end, start); var length = Vec3.length(v); @@ -262,12 +261,22 @@ randInt = function(low, high) { return Math.floor(randFloat(low, high)); } + +randomColor = function() { + return { + red: randInt(0, 255), + green: randInt(0, 255), + blue: randInt(0, 255) + } +} + + hexToRgb = function(hex) { var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { red: parseInt(result[1], 16), green: parseInt(result[2], 16), - blue: parseInt(result[3], 16) + blue: parseInt(resulta[3], 16) } : null; }