overte/script-archive/light_modifier/lightModifierTestScene.js

73 lines
1.7 KiB
JavaScript
Raw Permalink 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
//
2015-12-18 16:44:20 -08:00
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
2015-12-18 16:44:20 -08:00
var light;
2015-12-15 18:20:12 -08:00
function createLight() {
2015-12-18 16:44:20 -08:00
var position = basePosition;
2015-12-18 15:04:13 -08:00
position.y += 2;
2015-12-18 16:44:20 -08:00
var lightTransform = evalLightWorldTransform(position, avatarRot);
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
},
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);
}
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() {
Entities.deleteEntity(light);
}
Script.scriptEnding.connect(cleanup);
createLight();