Adding entity script to each color box

This commit is contained in:
ericrius1 2015-10-13 15:00:38 -07:00
parent ad61b89abd
commit a3f948acf8
3 changed files with 58 additions and 4 deletions

View file

@ -0,0 +1,47 @@
//
// colorSelectorEntityScript.js
// examples/toybox/entityScripts
//
// Created by Eric Levin on 9/21/15.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
/*global print, MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, Audio, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */
/*global ColorSelector */
(function() {
var _this;
ColorSelector = function() {
_this = this;
};
ColorSelector.prototype = {
startFarGrabNonColliding: function() {
this.selectColor();
},
clickReleaseOnEntity: function() {
this.selectColor();
},
selectColor: function() {
print("COLOR SELECTED");
},
preload: function(entityID) {
this.entityID = entityID;
var props = Entities.getEntityProperties(this.entityID, ["position, color, userData"]);
this.position = props.position;
this.color = props.color;
this.whiteboard = JSON.parse(this.userData).whiteboard;
},
};
// entity scripts always need to return a newly constructed object of our type
return new ColorSelector();
});

View file

@ -67,7 +67,7 @@
direction: Quat.getUp(this.getHandRotation())
};
this.intersection = Entities.findRayIntersection(pickRay, true, [this.entityID]);
this.intersection = Entities.findRayIntersection(pickRay, true, this.whitelist);
if (this.intersection.intersects) {
var distance = Vec3.distance(handPosition, this.intersection.intersection);
if (distance < MAX_DISTANCE) {
@ -170,6 +170,7 @@
blue: 190
};
this.strokes = [];
this.whitelist = [this.entityID];
},
unload: function() {
@ -180,6 +181,7 @@
};
// entity scripts always need to return a newly constructed object of our type
return new Whiteboard();
});

View file

@ -58,19 +58,24 @@ colorBoxPosition.y += whiteboardDimensions.y / 2;
var colorBoxes = [];
var colorSquareDimensions = {
x: (whiteboardDimensions.x / 2) / (colors.length - 1),
x: (whiteboardDimensions.x / 2) / (colors.length - 1),
y: .1,
z: 0.05
};
var spaceBetweenColorBoxes = Vec3.multiply(direction, colorSquareDimensions.x * 2);
var scriptURL = Script.resolvePath("colorSelectorEntityScript.js");
for (var i = 0; i < colors.length; i++) {
var colorBox = Entities.addEntity({
type: "Box",
position: colorBoxPosition,
dimensions: colorSquareDimensions,
rotation: rotation,
color: colors[i]
color: colors[i],
script: scriptURL,
userData: JSON.stringify({
colorPalette: true,
whiteboard: whiteboard
})
});
colorBoxes.push(colorBox);