Adding in light triggering logic

This commit is contained in:
ericrius1 2015-09-21 15:45:54 -07:00
parent 13d7834902
commit 8678e07c21
4 changed files with 195 additions and 29 deletions

View file

@ -1,11 +1,11 @@
//
// detectGrabExample.js
// examples/entityScripts
// doll.js
// examples/toybox/entityScripts
//
// Created by Brad Hefta-Gaub on 9/3/15.
// Created by Eric Levin on 9/21/15.
// Copyright 2015 High Fidelity, Inc.
//
// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script
// This entity script breathes movement and sound- one might even say life- into a doll.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html

View file

@ -0,0 +1,97 @@
//
// detectGrabExample.js
// examples/entityScripts
//
// Created by Eric Levin on 9/21/15.
// Copyright 2015 High Fidelity, Inc.
//
// This is an example of an entity script which when assigned to an entity, will detect when the entity is being grabbed by the hydraGrab script
//
// 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;
// this is the "constructor" for the entity as a JS object we don't do much here, but we do want to remember
// our this object, so we can access it in cases where we're called without a this (like in the case of various global signals)
LightSwitch = function() {
_this = this;
this.lightStateKey = "lightStateKey";
this.resetKey = "resetMe";
};
LightSwitch.prototype = {
startNearGrab: function() {
print("TOGGLE LIGHT")
// var position = Entities.getEntityProperties(this.entityID, "position").position;
// Audio.playSound(clickSound, {
// position: position,
// volume: 0.05
// });
},
createLights: function() {
print("CREATE LIGHTS *******************")
this.sconceLight1 = Entities.addEntity({
type: "Light",
position: {
x: 543.62,
y: 496.24,
z: 511.23
},
name: "Sconce 1 Light",
dimensions: {
x: 2.545,
y: 2.545,
z: 2.545
},
cutoff: 90,
color: {
red: 217,
green: 146,
blue: 24
}
});
setEntityCustomData(this.resetKey, this.sconceLight1, {
resetMe: true
});
},
// clickReleaseOnEntity: function(entityId, mouseEvent) {
// print("CLIIICK ON MOUSE")
// if (!mouseEvent.isLeftButton) {
// return;
// }
// },
// preload() will be called when the entity has become visible (or known) to the interface
// it gives us a chance to set our local JavaScript object up. In this case it means:
preload: function(entityID) {
this.entityID = entityID;
var defaultLightData= {
on: false
};
this.lightState = getEntityCustomData(this.lightStateKey, this.entityID, defaultLightData);
//If light is off, then we create two new lights- at the position of the sconces
if (this.lightState.on === false) {
this.createLights();
}
},
};
// entity scripts always need to return a newly constructed object of our type
return new LightSwitch();
})

View file

@ -47,6 +47,8 @@ function createAllToys() {
});
createDice();
createLightSwitch();
}
function deleteAllToys() {
@ -61,32 +63,84 @@ function deleteAllToys() {
})
}
function createLightSwitch() {
var modelURL = "http://hifi-public.s3.amazonaws.com/ryan/dimmer.obj";
var scriptURL = Script.resolvePath("entityScripts/lightSwitch.js?v1");
var lightSwitch = Entities.addEntity({
type: "Model",
modelURL: modelURL,
name: "Light Switch Hall",
collisionsWillMove: true,
script: scriptURL,
position: {
x: 543.27764892578125,
y: 495.67999267578125,
z: 511.00564575195312
},
rotation: {
w: 0.63280689716339111,
x: 0.63280689716339111,
y: -0.31551080942153931,
z: 0.31548023223876953
},
dimensions: {
x: 0.10546875,
y: 0.032372996211051941,
z: 0.16242524981498718
}
});
setEntityCustomData(resetKey, lightSwitch, {
resetMe: true
});
}
function createDice() {
var diceProps = {
type: "Model",
modelURL: "http://s3.amazonaws.com/hifi-public/models/props/Dice/goldDie.fbx",
collisionSoundURL: "http://s3.amazonaws.com/hifi-public/sounds/dice/diceCollide.wav",
name: "dice",
position: {x: 541.1, y: 496, z: 509.21 },
dimensions: {x: 0.09, y: 0.09, z: 0.09},
gravity: {x: 0, y: -3.5, z: 0},
velocity: {x: 0, y: -.01, z: 0},
position: {
x: 541.1,
y: 496,
z: 509.21
},
dimensions: {
x: 0.09,
y: 0.09,
z: 0.09
},
gravity: {
x: 0,
y: -3.5,
z: 0
},
velocity: {
x: 0,
y: -.01,
z: 0
},
shapeType: "box",
collisionsWillMove: true
}
var dice1 = Entities.addEntity(diceProps);
diceProps.position = {x: 540.99, y: 496, z: 509.08};
diceProps.position = {
x: 540.99,
y: 496,
z: 509.08
};
var dice2 = Entities.addEntity(diceProps);
setEntityCustomData(resetKey, dice1, {
setEntityCustomData(resetKey, dice1, {
resetMe: true
});
setEntityCustomData(resetKey, dice2, {
setEntityCustomData(resetKey, dice2, {
resetMe: true
});
});
}
function createWand(position) {
@ -248,26 +302,41 @@ function createSprayCan(position) {
function createBlocks(position) {
var baseURL = HIFI_PUBLIC_BUCKET + "models/content/planky/"
var modelURLs = ['planky_blue.fbx', 'planky_green.fbx', 'planky_natural.fbx', "planky_red.fbx", "planky_yellow.fbx"];
var blockTypes = [
{
var blockTypes = [{
url: "planky_blue.fbx",
dimensions: {x: 0.05, y: 0.05, z: 0.25}
},
{
dimensions: {
x: 0.05,
y: 0.05,
z: 0.25
}
}, {
url: "planky_green.fbx",
dimensions: {x: 0.1, y: 0.1, z: 0.25}
},
{
dimensions: {
x: 0.1,
y: 0.1,
z: 0.25
}
}, {
url: "planky_natural.fbx",
dimensions: {x: 0.05, y: 0.05, z: 0.05}
},
{
dimensions: {
x: 0.05,
y: 0.05,
z: 0.05
}
}, {
url: "planky_yellow.fbx",
dimensions: {x: 0.03, y: 0.05, z: 0.25}
},
{
dimensions: {
x: 0.03,
y: 0.05,
z: 0.25
}
}, {
url: "planky_red.fbx",
dimensions: {x: 0.1, y: 0.05, z: 0.25}
dimensions: {
x: 0.1,
y: 0.05,
z: 0.25
}
},
@ -275,13 +344,13 @@ function createBlocks(position) {
var NUM_BLOCKS_PER_COLOR = 4;
for (var i = 0; i < blockTypes.length; i++) {
for(j = 0; j < NUM_BLOCKS_PER_COLOR; j++) {
for (j = 0; j < NUM_BLOCKS_PER_COLOR; j++) {
var modelURL = baseURL + blockTypes[i].url;
var entity = Entities.addEntity({
type: "Model",
modelURL: modelURL,
position: Vec3.sum(position, {
x: j/10,
x: j / 10,
y: i / 10,
z: 0
}),