overte/examples/light_modifier/lightModifierTestScene.js

117 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-12-15 18:20:12 -08:00
//
2015-12-16 01:31:24 -08:00
// lightModifierTestScene.js
2015-12-15 18:20:12 -08:00
//
2015-12-16 01:31:24 -08:00
// Created by James Pollack @imgntn on 12/15/2015
2015-12-15 18:20:12 -08:00
// Copyright 2015 High Fidelity, Inc.
//
// Given a selected light, instantiate some entities that represent various values you can dynamically adjust.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var PARENT_SCRIPT_URL = Script.resolvePath('lightParent.js?'+Math.random(0-100));
2015-12-15 18:20:12 -08:00
var basePosition, avatarRot;
avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0);
2015-12-16 11:57:54 -08:00
basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(0, Quat.getUp(avatarRot)));
2015-12-15 18:20:12 -08:00
var light, block;
function createLight() {
var blockProperties = Entities.getEntityProperties(block, ["position", "rotation"]);
2015-12-17 16:58:38 -08:00
var position = basePosition;
position.y += 3;
var lightTransform = evalLightWorldTransform(position,avatarRot);
// var lightTransform = evalLightWorldTransform(blockProperties.position, blockProperties.rotation);
2015-12-15 18:20:12 -08:00
var lightProperties = {
name: 'Hifi-Spotlight',
type: "Light",
isSpotlight: true,
dimensions: {
x: 2,
y: 2,
2015-12-16 14:55:01 -08:00
z: 8
2015-12-15 18:20:12 -08:00
},
2015-12-17 16:58:38 -08:00
// parentID: block,
2015-12-15 18:20:12 -08:00
color: {
red: 255,
green: 0,
blue: 255
},
intensity: 0.035,
exponent: 1,
cutoff: 30,
lifetime: -1,
position: lightTransform.p,
rotation: lightTransform.q
};
light = Entities.addEntity(lightProperties);
var message = {
light: {
id: light,
type: 'spotlight',
initialProperties: lightProperties
}
};
2015-12-17 16:58:38 -08:00
// Messages.sendMessage('Hifi-Light-Mod-Receiver', JSON.stringify(message));
2015-12-15 18:20:12 -08:00
}
function createBlock() {
var position = basePosition;
2015-12-16 11:57:54 -08:00
position.y += 3;
2015-12-15 18:20:12 -08:00
var blockProperties = {
name: 'Hifi-Spotlight-Block',
type: 'Box',
dimensions: {
x: 1,
y: 1,
z: 1
},
collisionsWillMove: true,
color: {
red: 0,
green: 0,
blue: 255
},
2015-12-16 14:34:01 -08:00
position: position,
script:PARENT_SCRIPT_URL,
2015-12-16 14:34:01 -08:00
userData: JSON.stringify({
2015-12-17 10:58:14 -08:00
handControllerKey: {
2015-12-16 14:34:01 -08:00
disableReleaseVelocity: true
}
})
2015-12-16 11:57:54 -08:00
};
2015-12-15 18:20:12 -08:00
block = Entities.addEntity(blockProperties);
}
function evalLightWorldTransform(modelPos, modelRot) {
2015-12-16 11:57:54 -08:00
var MODEL_LIGHT_POSITION = {
x: 0,
y: -0.3,
z: 0
};
var MODEL_LIGHT_ROTATION = Quat.angleAxis(-90, {
x: 1,
y: 0,
z: 0
});
2015-12-15 18:20:12 -08:00
return {
p: Vec3.sum(modelPos, Vec3.multiplyQbyV(modelRot, MODEL_LIGHT_POSITION)),
q: Quat.multiply(modelRot, MODEL_LIGHT_ROTATION)
};
}
function cleanup() {
2015-12-17 16:58:38 -08:00
//Entities.deleteEntity(block);
2015-12-15 18:20:12 -08:00
Entities.deleteEntity(light);
}
Script.scriptEnding.connect(cleanup);
2015-12-17 16:58:38 -08:00
//createBlock();
2015-12-15 18:20:12 -08:00
createLight();