This commit is contained in:
ericrius1 2016-03-22 17:33:18 -07:00
parent 60bb77fd34
commit e5364fd186
3 changed files with 64 additions and 29 deletions

View file

@ -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,
}
});

View file

@ -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);

View file

@ -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;
}