mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
prep for feedback
This commit is contained in:
parent
d4f55ed6d2
commit
9a2d9997e9
6 changed files with 331 additions and 318 deletions
|
@ -218,6 +218,7 @@ function getSpatialOffsetPosition(hand, spatialKey) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var yFlip = Quat.angleAxis(180, Vec3.UNIT_Y);
|
var yFlip = Quat.angleAxis(180, Vec3.UNIT_Y);
|
||||||
|
|
||||||
function getSpatialOffsetRotation(hand, spatialKey) {
|
function getSpatialOffsetRotation(hand, spatialKey) {
|
||||||
var rotation = Quat.IDENTITY;
|
var rotation = Quat.IDENTITY;
|
||||||
|
|
||||||
|
@ -261,9 +262,9 @@ function MyController(hand) {
|
||||||
this.triggerValue = 0; // rolling average of trigger value
|
this.triggerValue = 0; // rolling average of trigger value
|
||||||
this.rawTriggerValue = 0;
|
this.rawTriggerValue = 0;
|
||||||
this.rawBumperValue = 0;
|
this.rawBumperValue = 0;
|
||||||
|
|
||||||
this.overlayLine = null;
|
this.overlayLine = null;
|
||||||
|
|
||||||
this.ignoreIK = false;
|
this.ignoreIK = false;
|
||||||
this.offsetPosition = Vec3.ZERO;
|
this.offsetPosition = Vec3.ZERO;
|
||||||
this.offsetRotation = Quat.IDENTITY;
|
this.offsetRotation = Quat.IDENTITY;
|
||||||
|
@ -816,33 +817,36 @@ function MyController(hand) {
|
||||||
|
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "continueDistantGrab");
|
Entities.callEntityMethod(this.grabbedEntity, "continueDistantGrab");
|
||||||
|
|
||||||
var defaultConstrainData = {
|
|
||||||
axisBasePosition:false,
|
|
||||||
endOfAxis: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
var constraintData = getEntityCustomData('lightModifierKey', this.grabbedEntity, defaultConstrainData);
|
|
||||||
|
|
||||||
// var constrainX = constraintData.constrain.x;
|
|
||||||
// var constrainY = constraintData.constrain.y;
|
|
||||||
// var constrainZ = constraintData.constrain.z;
|
|
||||||
|
|
||||||
// print('constrainY'+constrainY);
|
|
||||||
|
|
||||||
// mix in head motion
|
// mix in head motion
|
||||||
if (MOVE_WITH_HEAD) {
|
if (MOVE_WITH_HEAD) {
|
||||||
var objDistance = Vec3.length(objectToAvatar);
|
var objDistance = Vec3.length(objectToAvatar);
|
||||||
var before = Vec3.multiplyQbyV(this.currentCameraOrientation, { x: 0.0, y: 0.0, z: objDistance });
|
var before = Vec3.multiplyQbyV(this.currentCameraOrientation, {
|
||||||
var after = Vec3.multiplyQbyV(Camera.orientation, { x: 0.0, y: 0.0, z: objDistance });
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
z: objDistance
|
||||||
|
});
|
||||||
|
var after = Vec3.multiplyQbyV(Camera.orientation, {
|
||||||
|
x: 0.0,
|
||||||
|
y: 0.0,
|
||||||
|
z: objDistance
|
||||||
|
});
|
||||||
var change = Vec3.subtract(before, after);
|
var change = Vec3.subtract(before, after);
|
||||||
this.currentCameraOrientation = Camera.orientation;
|
this.currentCameraOrientation = Camera.orientation;
|
||||||
this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change);
|
this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var defaultConstraintData = {
|
||||||
|
axisStart: false,
|
||||||
|
axisEnd: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
var constraintData = getEntityCustomData('lightModifierKey', this.grabbedEntity, defaultConstraintData);
|
||||||
var clampedVector;
|
var clampedVector;
|
||||||
var targetPosition;
|
var targetPosition;
|
||||||
if (constraintData.axisBasePosition !== false) {
|
if (constraintData.startAxis !== false) {
|
||||||
clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition, constraintData.axisBasePosition, constraintData.endOfAxis);
|
clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition, constraintData.axisStart, constraintData.axisEnd);
|
||||||
targetPosition = clampedVector;
|
targetPosition = clampedVector;
|
||||||
} else {
|
} else {
|
||||||
targetPosition = {
|
targetPosition = {
|
||||||
|
@ -859,121 +863,121 @@ function MyController(hand) {
|
||||||
angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME,
|
||||||
ttl: ACTION_TTL
|
ttl: ACTION_TTL
|
||||||
});
|
});
|
||||||
|
|
||||||
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
|
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.projectVectorAlongAxis = function(position, axisStart, axisEnd) {
|
this.projectVectorAlongAxis = function(position, axisStart, axisEnd) {
|
||||||
|
|
||||||
var aPrime = Vec3.subtract(position, axisStart);
|
var aPrime = Vec3.subtract(position, axisStart);
|
||||||
|
|
||||||
var bPrime = Vec3.subtract(axisEnd, axisStart);
|
var bPrime = Vec3.subtract(axisEnd, axisStart);
|
||||||
|
|
||||||
var bPrimeMagnitude = Vec3.length(bPrime);
|
var bPrimeMagnitude = Vec3.length(bPrime);
|
||||||
|
|
||||||
var dotProduct = Vec3.dot(aPrime, bPrime);
|
var dotProduct = Vec3.dot(aPrime, bPrime);
|
||||||
|
|
||||||
var scalar = dotProduct / bPrimeMagnitude;
|
var scalar = dotProduct / bPrimeMagnitude;
|
||||||
|
|
||||||
print('SCALAR:::'+scalar);
|
if (scalar < 0) {
|
||||||
|
scalar = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if(scalar<0){
|
if (scalar > 1) {
|
||||||
scalar = 0;
|
scalar = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(scalar>1){
|
var projection = Vec3.sum(axisStart, Vec3.multiply(scalar, Vec3.normalize(bPrime)));
|
||||||
scalar = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var projection = Vec3.sum(axisStart, Vec3.multiply(scalar, Vec3.normalize(bPrime)));
|
return projection
|
||||||
|
|
||||||
return projection
|
},
|
||||||
|
|
||||||
},
|
this.nearGrabbing = function() {
|
||||||
|
var now = Date.now();
|
||||||
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
||||||
|
|
||||||
this.nearGrabbing = function() {
|
if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
|
||||||
var now = Date.now();
|
this.setState(STATE_RELEASE);
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
Entities.callEntityMethod(this.grabbedEntity, "releaseGrab");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
|
this.lineOff();
|
||||||
this.setState(STATE_RELEASE);
|
this.overlayLineOff();
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "releaseGrab");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.lineOff();
|
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES);
|
||||||
this.overlayLineOff();
|
this.activateEntity(this.grabbedEntity, grabbedProperties);
|
||||||
|
if (grabbedProperties.collisionsWillMove && NEAR_GRABBING_KINEMATIC) {
|
||||||
|
Entities.editEntity(this.grabbedEntity, {
|
||||||
|
collisionsWillMove: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES);
|
var handRotation = this.getHandRotation();
|
||||||
this.activateEntity(this.grabbedEntity, grabbedProperties);
|
var handPosition = this.getHandPosition();
|
||||||
if (grabbedProperties.collisionsWillMove && NEAR_GRABBING_KINEMATIC) {
|
|
||||||
Entities.editEntity(this.grabbedEntity, {
|
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
||||||
collisionsWillMove: false
|
|
||||||
|
if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) {
|
||||||
|
// if an object is "equipped" and has a spatialKey, use it.
|
||||||
|
this.ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false;
|
||||||
|
this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey);
|
||||||
|
this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey);
|
||||||
|
} else {
|
||||||
|
this.ignoreIK = false;
|
||||||
|
|
||||||
|
var objectRotation = grabbedProperties.rotation;
|
||||||
|
this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation);
|
||||||
|
|
||||||
|
var currentObjectPosition = grabbedProperties.position;
|
||||||
|
var offset = Vec3.subtract(currentObjectPosition, handPosition);
|
||||||
|
this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.actionID = NULL_ACTION_ID;
|
||||||
|
this.actionID = Entities.addAction("hold", this.grabbedEntity, {
|
||||||
|
hand: this.hand === RIGHT_HAND ? "right" : "left",
|
||||||
|
timeScale: NEAR_GRABBING_ACTION_TIMEFRAME,
|
||||||
|
relativePosition: this.offsetPosition,
|
||||||
|
relativeRotation: this.offsetRotation,
|
||||||
|
ttl: ACTION_TTL,
|
||||||
|
kinematic: NEAR_GRABBING_KINEMATIC,
|
||||||
|
kinematicSetVelocity: true,
|
||||||
|
ignoreIK: this.ignoreIK
|
||||||
});
|
});
|
||||||
}
|
if (this.actionID === NULL_ACTION_ID) {
|
||||||
|
this.actionID = null;
|
||||||
var handRotation = this.getHandRotation();
|
|
||||||
var handPosition = this.getHandPosition();
|
|
||||||
|
|
||||||
var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA);
|
|
||||||
|
|
||||||
if (this.state != STATE_NEAR_GRABBING && grabbableData.spatialKey) {
|
|
||||||
// if an object is "equipped" and has a spatialKey, use it.
|
|
||||||
this.ignoreIK = grabbableData.spatialKey.ignoreIK ? grabbableData.spatialKey.ignoreIK : false;
|
|
||||||
this.offsetPosition = getSpatialOffsetPosition(this.hand, grabbableData.spatialKey);
|
|
||||||
this.offsetRotation = getSpatialOffsetRotation(this.hand, grabbableData.spatialKey);
|
|
||||||
} else {
|
|
||||||
this.ignoreIK = false;
|
|
||||||
|
|
||||||
var objectRotation = grabbedProperties.rotation;
|
|
||||||
this.offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation);
|
|
||||||
|
|
||||||
var currentObjectPosition = grabbedProperties.position;
|
|
||||||
var offset = Vec3.subtract(currentObjectPosition, handPosition);
|
|
||||||
this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.actionID = NULL_ACTION_ID;
|
|
||||||
this.actionID = Entities.addAction("hold", this.grabbedEntity, {
|
|
||||||
hand: this.hand === RIGHT_HAND ? "right" : "left",
|
|
||||||
timeScale: NEAR_GRABBING_ACTION_TIMEFRAME,
|
|
||||||
relativePosition: this.offsetPosition,
|
|
||||||
relativeRotation: this.offsetRotation,
|
|
||||||
ttl: ACTION_TTL,
|
|
||||||
kinematic: NEAR_GRABBING_KINEMATIC,
|
|
||||||
kinematicSetVelocity: true,
|
|
||||||
ignoreIK: this.ignoreIK
|
|
||||||
});
|
|
||||||
if (this.actionID === NULL_ACTION_ID) {
|
|
||||||
this.actionID = null;
|
|
||||||
} else {
|
|
||||||
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
|
|
||||||
if (this.state == STATE_NEAR_GRABBING) {
|
|
||||||
this.setState(STATE_CONTINUE_NEAR_GRABBING);
|
|
||||||
} else {
|
} else {
|
||||||
// equipping
|
this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC);
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "startEquip", [JSON.stringify(this.hand)]);
|
if (this.state == STATE_NEAR_GRABBING) {
|
||||||
this.startHandGrasp();
|
this.setState(STATE_CONTINUE_NEAR_GRABBING);
|
||||||
|
} else {
|
||||||
|
// equipping
|
||||||
|
Entities.callEntityMethod(this.grabbedEntity, "startEquip", [JSON.stringify(this.hand)]);
|
||||||
|
this.startHandGrasp();
|
||||||
|
|
||||||
|
this.setState(STATE_CONTINUE_EQUIP_BD);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hand === RIGHT_HAND) {
|
||||||
|
Entities.callEntityMethod(this.grabbedEntity, "setRightHand");
|
||||||
|
} else {
|
||||||
|
Entities.callEntityMethod(this.grabbedEntity, "setLeftHand");
|
||||||
|
}
|
||||||
|
|
||||||
|
Entities.callEntityMethod(this.grabbedEntity, "setHand", [this.hand]);
|
||||||
|
|
||||||
|
Entities.callEntityMethod(this.grabbedEntity, "startNearGrab");
|
||||||
|
|
||||||
this.setState(STATE_CONTINUE_EQUIP_BD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.hand === RIGHT_HAND) {
|
this.currentHandControllerTipPosition =
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "setRightHand");
|
(this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition;
|
||||||
} else {
|
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "setLeftHand");
|
|
||||||
}
|
|
||||||
|
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "setHand", [this.hand]);
|
this.currentObjectTime = Date.now();
|
||||||
|
};
|
||||||
Entities.callEntityMethod(this.grabbedEntity, "startNearGrab");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.currentHandControllerTipPosition =
|
|
||||||
(this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition;
|
|
||||||
|
|
||||||
this.currentObjectTime = Date.now();
|
|
||||||
};
|
|
||||||
|
|
||||||
this.continueNearGrabbing = function() {
|
this.continueNearGrabbing = function() {
|
||||||
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
|
if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) {
|
||||||
|
@ -1358,10 +1362,10 @@ Controller.enableMapping(MAPPING_NAME);
|
||||||
var handToDisable = 'none';
|
var handToDisable = 'none';
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
if (handToDisable !== LEFT_HAND && handToDisable!=='both') {
|
if (handToDisable !== LEFT_HAND && handToDisable !== 'both') {
|
||||||
leftController.update();
|
leftController.update();
|
||||||
}
|
}
|
||||||
if (handToDisable !== RIGHT_HAND && handToDisable!=='both') {
|
if (handToDisable !== RIGHT_HAND && handToDisable !== 'both') {
|
||||||
rightController.update();
|
rightController.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1369,7 +1373,7 @@ function update() {
|
||||||
Messages.subscribe('Hifi-Hand-Disabler');
|
Messages.subscribe('Hifi-Hand-Disabler');
|
||||||
|
|
||||||
handleHandDisablerMessages = function(channel, message, sender) {
|
handleHandDisablerMessages = function(channel, message, sender) {
|
||||||
|
|
||||||
if (sender === MyAvatar.sessionUUID) {
|
if (sender === MyAvatar.sessionUUID) {
|
||||||
if (message === 'left') {
|
if (message === 'left') {
|
||||||
handToDisable = LEFT_HAND;
|
handToDisable = LEFT_HAND;
|
||||||
|
@ -1377,11 +1381,11 @@ handleHandDisablerMessages = function(channel, message, sender) {
|
||||||
if (message === 'right') {
|
if (message === 'right') {
|
||||||
handToDisable = RIGHT_HAND;
|
handToDisable = RIGHT_HAND;
|
||||||
}
|
}
|
||||||
if(message==='both'){
|
if (message === 'both') {
|
||||||
handToDisable='both';
|
handToDisable = 'both';
|
||||||
}
|
}
|
||||||
if(message==='none'){
|
if (message === 'none') {
|
||||||
handToDisable='none';
|
handToDisable = 'none';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1396,4 +1400,4 @@ function cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
8
examples/lights/light_loader.js
Normal file
8
examples/lights/light_loader.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
var grabScript = Script.resolvePath('../controllers/handControllerGrab.js');
|
||||||
|
Script.load(grabScript);
|
||||||
|
var lightModifier = Script.resolvePath('light_modifier.js');
|
||||||
|
Script.load(lightModifier);
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
var lightModifierTestScene = Script.resolvePath('light_modifier_test_scene.js');
|
||||||
|
Script.load(lightModifierTestScene);
|
||||||
|
}, 750)
|
|
@ -1,9 +1,22 @@
|
||||||
// given a selected light, instantiate some entities that represent various values you can dynamically adjust
|
//
|
||||||
|
// light_modifier.js
|
||||||
|
//
|
||||||
|
// Created byJames Pollack @imgntn on 10/19/2015
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Given a selected light, instantiate some entities that represent various values you can dynamically adjust by grabbing and moving.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
|
var AXIS_SCALE = 1;
|
||||||
|
var COLOR_MAX = 255;
|
||||||
|
var INTENSITY_MAX = 0.05;
|
||||||
|
var CUTOFF_MAX = 360;
|
||||||
|
var EXPONENT_MAX = 1;
|
||||||
|
|
||||||
|
var SLIDER_SCRIPT_URL = Script.resolvePath('slider.js?' + Math.random(0, 100));
|
||||||
var BOX_SCRIPT_URL = Script.resolvePath('box.js?'+Math.random(0,100));
|
|
||||||
|
|
||||||
var RED = {
|
var RED = {
|
||||||
red: 255,
|
red: 255,
|
||||||
|
@ -35,13 +48,12 @@ var WHITE = {
|
||||||
blue: 255
|
blue: 255
|
||||||
};
|
};
|
||||||
|
|
||||||
var AXIS_SCALE = 1;
|
var SLIDER_DIMENSIONS = {
|
||||||
|
x: 0.075,
|
||||||
var BOX_DIMENSIONS = {
|
y: 0.075,
|
||||||
x: 0.05,
|
z: 0.075
|
||||||
y: 0.05,
|
|
||||||
z: 0.05
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var PER_ROW_OFFSET = {
|
var PER_ROW_OFFSET = {
|
||||||
x: 0,
|
x: 0,
|
||||||
y: -0.2,
|
y: -0.2,
|
||||||
|
@ -55,10 +67,8 @@ function entitySlider(light, color, sliderType, row) {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.sliderType = sliderType;
|
this.sliderType = sliderType;
|
||||||
this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET);
|
this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET);
|
||||||
print('slider : ' + this.sliderType + "should have an offset of : " + this.verticalOffset);
|
|
||||||
|
|
||||||
this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0);
|
this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0);
|
||||||
this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(this.avatarRot)));
|
this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(this.avatarRot)));
|
||||||
|
|
||||||
var message = {
|
var message = {
|
||||||
lightID: this.lightID,
|
lightID: this.lightID,
|
||||||
|
@ -95,9 +105,8 @@ function entitySlider(light, color, sliderType, row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setInitialSliderPositions();
|
this.setInitialSliderPositions();
|
||||||
this.subscribeToBoxMessages();
|
|
||||||
this.createAxis();
|
this.createAxis();
|
||||||
this.createBoxIndicator();
|
this.createSliderIndicator();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +122,6 @@ entitySlider.prototype = {
|
||||||
var extension = Vec3.multiply(AXIS_SCALE, rightVector);
|
var extension = Vec3.multiply(AXIS_SCALE, rightVector);
|
||||||
var endOfAxis = Vec3.sum(position, extension);
|
var endOfAxis = Vec3.sum(position, extension);
|
||||||
this.endOfAxis = endOfAxis;
|
this.endOfAxis = endOfAxis;
|
||||||
print('endOfAxis:::' + JSON.stringify(endOfAxis))
|
|
||||||
var properties = {
|
var properties = {
|
||||||
type: 'Line',
|
type: 'Line',
|
||||||
name: 'Hifi-Slider-Axis::' + this.sliderType,
|
name: 'Hifi-Slider-Axis::' + this.sliderType,
|
||||||
|
@ -136,10 +144,8 @@ entitySlider.prototype = {
|
||||||
|
|
||||||
this.axis = Entities.addEntity(properties);
|
this.axis = Entities.addEntity(properties);
|
||||||
},
|
},
|
||||||
createBoxIndicator: function() {
|
createSliderIndicator: function() {
|
||||||
print('BOX COLOR IS:::' + JSON.stringify(this.color));
|
|
||||||
var position = Vec3.sum(this.basePosition, this.verticalOffset);
|
var position = Vec3.sum(this.basePosition, this.verticalOffset);
|
||||||
|
|
||||||
//line starts on left and goes to right
|
//line starts on left and goes to right
|
||||||
//set the end of the line to the right
|
//set the end of the line to the right
|
||||||
var rightVector = Quat.getRight(this.avatarRot);
|
var rightVector = Quat.getRight(this.avatarRot);
|
||||||
|
@ -154,7 +160,7 @@ entitySlider.prototype = {
|
||||||
initialDistance = this.distanceBlue;
|
initialDistance = this.distanceBlue;
|
||||||
}
|
}
|
||||||
if (this.sliderType === 'intensity') {
|
if (this.sliderType === 'intensity') {
|
||||||
initialDistance = this.distanceRed;
|
initialDistance = this.distanceIntensity;
|
||||||
}
|
}
|
||||||
if (this.sliderType === 'cutoff') {
|
if (this.sliderType === 'cutoff') {
|
||||||
initialDistance = this.distanceCutoff;
|
initialDistance = this.distanceCutoff;
|
||||||
|
@ -165,30 +171,26 @@ entitySlider.prototype = {
|
||||||
var extension = Vec3.multiply(initialDistance, rightVector);
|
var extension = Vec3.multiply(initialDistance, rightVector);
|
||||||
var sliderPosition = Vec3.sum(position, extension);
|
var sliderPosition = Vec3.sum(position, extension);
|
||||||
var properties = {
|
var properties = {
|
||||||
type: 'Box',
|
type: 'Sphere',
|
||||||
name: 'Hifi-Slider::' + this.sliderType,
|
name: 'Hifi-Slider::' + this.sliderType,
|
||||||
dimensions: BOX_DIMENSIONS,
|
dimensions: SLIDER_DIMENSIONS,
|
||||||
collisionsWillMove: true,
|
collisionsWillMove: true,
|
||||||
color: this.color,
|
color: this.color,
|
||||||
position: sliderPosition,
|
position: sliderPosition,
|
||||||
script: BOX_SCRIPT_URL,
|
script: SLIDER_SCRIPT_URL,
|
||||||
userData: JSON.stringify({
|
userData: JSON.stringify({
|
||||||
lightModifierKey: {
|
lightModifierKey: {
|
||||||
lightID: this.lightID,
|
lightID: this.lightID,
|
||||||
sliderType: this.sliderType,
|
sliderType: this.sliderType,
|
||||||
axisBasePosition: position,
|
axisStart: position,
|
||||||
endOfAxis: this.endOfAxis,
|
axisEnd: this.endOfAxis,
|
||||||
},
|
|
||||||
constraintKey: {
|
|
||||||
constrain: {
|
|
||||||
y: position.y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
this.boxIndicator = Entities.addEntity(properties);
|
this.sliderIndicator = Entities.addEntity(properties);
|
||||||
},
|
},
|
||||||
|
|
||||||
setValueFromMessage: function(message) {
|
setValueFromMessage: function(message) {
|
||||||
|
|
||||||
//message is not for our light
|
//message is not for our light
|
||||||
|
@ -203,8 +205,6 @@ entitySlider.prototype = {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
print('should set:::' + this.sliderType);
|
|
||||||
|
|
||||||
var lightProperties = Entities.getEntityProperties(this.lightID);
|
var lightProperties = Entities.getEntityProperties(this.lightID);
|
||||||
|
|
||||||
if (this.sliderType === 'color_red') {
|
if (this.sliderType === 'color_red') {
|
||||||
|
@ -255,28 +255,15 @@ entitySlider.prototype = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
subscribeToBoxMessages: function() {
|
|
||||||
Messages.subscribe('Hifi-Slider-Value-Reciever');
|
|
||||||
Messages.messageReceived.connect(handleValueMessages);
|
|
||||||
},
|
|
||||||
setInitialSliderPositions: function() {
|
setInitialSliderPositions: function() {
|
||||||
var COLOR_MAX = 255;
|
|
||||||
var INTENSITY_MAX = 10;
|
|
||||||
var CUTOFF_MAX = 360;
|
|
||||||
var EXPONENT_MAX = 1;
|
|
||||||
|
|
||||||
this.distanceRed = (this.initialProperties.color.red / COLOR_MAX) * AXIS_SCALE;
|
this.distanceRed = (this.initialProperties.color.red / COLOR_MAX) * AXIS_SCALE;
|
||||||
this.distanceGreen = (this.initialProperties.color.green / COLOR_MAX) * AXIS_SCALE;
|
this.distanceGreen = (this.initialProperties.color.green / COLOR_MAX) * AXIS_SCALE;
|
||||||
this.distanceBlue = (this.initialProperties.color.blue / COLOR_MAX) * AXIS_SCALE;
|
this.distanceBlue = (this.initialProperties.color.blue / COLOR_MAX) * AXIS_SCALE;
|
||||||
this.distanceIntensity = (this.initialProperties.intensity / INTENSITY_MAX) * AXIS_SCALE;
|
this.distanceIntensity = (this.initialProperties.intensity / INTENSITY_MAX) * AXIS_SCALE;
|
||||||
this.distanceCutoff = (this.initialProperties.cutoff / CUTOFF_MAX) * AXIS_SCALE;
|
this.distanceCutoff = (this.initialProperties.cutoff / CUTOFF_MAX) * AXIS_SCALE;
|
||||||
this.distanceExponent = (this.initialProperties.exponent / EXPONENT_MAX) * AXIS_SCALE;
|
this.distanceExponent = (this.initialProperties.exponent / EXPONENT_MAX) * AXIS_SCALE;
|
||||||
},
|
|
||||||
cleanup: function() {
|
|
||||||
Entities.deleteEntity(this.boxIndicator);
|
|
||||||
Entities.deleteEntity(this.axis);
|
|
||||||
Messages.messageReceived.disconnect(this.handleValueMessages);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var sliders = [];
|
var sliders = [];
|
||||||
|
@ -288,9 +275,9 @@ var slidersRef = {
|
||||||
cutoff: null,
|
cutoff: null,
|
||||||
exponent: null
|
exponent: null
|
||||||
}
|
}
|
||||||
|
var light = null;
|
||||||
|
|
||||||
function makeSliders(light) {
|
function makeSliders(light) {
|
||||||
print('light in makesliders:::' + light)
|
|
||||||
if (light.type === 'spotlight') {
|
if (light.type === 'spotlight') {
|
||||||
var USE_COLOR_SLIDER = true;
|
var USE_COLOR_SLIDER = true;
|
||||||
var USE_INTENSITY_SLIDER = true;
|
var USE_INTENSITY_SLIDER = true;
|
||||||
|
@ -325,14 +312,19 @@ function makeSliders(light) {
|
||||||
slidersRef.exponent = new entitySlider(light, PURPLE, 'exponent', 6);
|
slidersRef.exponent = new entitySlider(light, PURPLE, 'exponent', 6);
|
||||||
sliders.push(slidersRef.exponent);
|
sliders.push(slidersRef.exponent);
|
||||||
}
|
}
|
||||||
|
subscribeToSliderMessages();
|
||||||
};
|
};
|
||||||
|
|
||||||
function subScribeToNewLights() {
|
function subScribeToNewLights() {
|
||||||
print('subscribing to light messages')
|
|
||||||
Messages.subscribe('Hifi-Light-Mod-Receiver');
|
Messages.subscribe('Hifi-Light-Mod-Receiver');
|
||||||
Messages.messageReceived.connect(handleLightModMessages);
|
Messages.messageReceived.connect(handleLightModMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function subscribeToSliderMessages() {
|
||||||
|
Messages.subscribe('Hifi-Slider-Value-Reciever');
|
||||||
|
Messages.messageReceived.connect(handleValueMessages);
|
||||||
|
}
|
||||||
|
|
||||||
function handleLightModMessages(channel, message, sender) {
|
function handleLightModMessages(channel, message, sender) {
|
||||||
if (channel !== 'Hifi-Light-Mod-Receiver') {
|
if (channel !== 'Hifi-Light-Mod-Receiver') {
|
||||||
return;
|
return;
|
||||||
|
@ -343,6 +335,7 @@ function handleLightModMessages(channel, message, sender) {
|
||||||
var parsedMessage = JSON.parse(message);
|
var parsedMessage = JSON.parse(message);
|
||||||
|
|
||||||
makeSliders(parsedMessage.light);
|
makeSliders(parsedMessage.light);
|
||||||
|
light = parsedMessage.light.id
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleValueMessages(channel, message, sender) {
|
function handleValueMessages(channel, message, sender) {
|
||||||
|
@ -356,27 +349,39 @@ function handleValueMessages(channel, message, sender) {
|
||||||
// }
|
// }
|
||||||
var parsedMessage = JSON.parse(message);
|
var parsedMessage = JSON.parse(message);
|
||||||
|
|
||||||
slidersRef[parsedMessage.sliderType].setValueFromMessage(parsedMessage)
|
slidersRef[parsedMessage.sliderType].setValueFromMessage(parsedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
while (sliders.length > 0) {
|
var i;
|
||||||
var slider = sliders.pop();
|
for (i = 0; i < sliders.length; i++) {
|
||||||
slider.cleanup();
|
Entities.deleteEntity(sliders[i].axis);
|
||||||
|
Entities.deleteEntity(sliders[i].sliderIndicator);
|
||||||
}
|
}
|
||||||
|
|
||||||
Messages.messageReceived.disconnect(handleLightModMessages);
|
Messages.messageReceived.disconnect(handleLightModMessages);
|
||||||
delete sliders
|
Messages.messageReceived.disconnect(handleValueMessages);
|
||||||
|
Entities.deletingEntity.disconnect(deleteEntity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanup);
|
Script.scriptEnding.connect(cleanup);
|
||||||
subScribeToNewLights();
|
subScribeToNewLights();
|
||||||
|
|
||||||
|
function deleteEntity(entityID) {
|
||||||
|
if (entityID === light) {
|
||||||
|
// cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Entities.deletingEntity.connect(deleteEntity);
|
||||||
|
|
||||||
|
|
||||||
//other light properties
|
//other light properties
|
||||||
// diffuseColor: { red: 255, green: 255, blue: 255 },
|
// diffuseColor: { red: 255, green: 255, blue: 255 },
|
||||||
// ambientColor: { red: 255, green: 255, blue: 255 },
|
// ambientColor: { red: 255, green: 255, blue: 255 },
|
||||||
// specularColor: { red: 255, green: 255, blue: 255 },
|
// specularColor: { red: 255, green: 255, blue: 255 },
|
||||||
|
|
||||||
// constantAttenuation: 1,
|
// constantAttenuation: 1,
|
||||||
// linearAttenuation: 0,
|
// linearAttenuation: 0,
|
||||||
// quadraticAttenuation: 0,
|
// quadraticAttenuation: 0,
|
||||||
|
|
128
examples/lights/light_modifier_test_scene.js
Normal file
128
examples/lights/light_modifier_test_scene.js
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
//
|
||||||
|
// light_modifier_test_scene.js
|
||||||
|
//
|
||||||
|
// Created byJames Pollack @imgntn on 10/19/2015
|
||||||
|
// 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 MODEL_LIGHT_POSITION = {
|
||||||
|
x: 0,
|
||||||
|
y: -0.3,
|
||||||
|
z: 0
|
||||||
|
};
|
||||||
|
var MODEL_LIGHT_ROTATION = Quat.angleAxis(-90, {
|
||||||
|
x: 1,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
var basePosition, avatarRot;
|
||||||
|
avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0);
|
||||||
|
basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(-3, Quat.getUp(avatarRot)));
|
||||||
|
|
||||||
|
var ground = Entities.addEntity({
|
||||||
|
name: 'Hifi-Light-Mod-Floor',
|
||||||
|
//type: "Model",
|
||||||
|
type: 'Box',
|
||||||
|
color: {
|
||||||
|
red: 100,
|
||||||
|
green: 100,
|
||||||
|
blue: 100
|
||||||
|
},
|
||||||
|
//modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/woodFloor.fbx",
|
||||||
|
dimensions: {
|
||||||
|
x: 100,
|
||||||
|
y: 2,
|
||||||
|
z: 100
|
||||||
|
},
|
||||||
|
position: basePosition,
|
||||||
|
shapeType: 'box'
|
||||||
|
});
|
||||||
|
|
||||||
|
var light, block;
|
||||||
|
|
||||||
|
function createLight() {
|
||||||
|
var blockProperties = Entities.getEntityProperties(block, ["position", "rotation"]);
|
||||||
|
var lightTransform = evalLightWorldTransform(blockProperties.position, blockProperties.rotation);
|
||||||
|
var lightProperties = {
|
||||||
|
name: 'Hifi-Spotlight',
|
||||||
|
type: "Light",
|
||||||
|
isSpotlight: true,
|
||||||
|
dimensions: {
|
||||||
|
x: 2,
|
||||||
|
y: 2,
|
||||||
|
z: 20
|
||||||
|
},
|
||||||
|
parentID: block,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Messages.sendMessage('Hifi-Light-Mod-Receiver', JSON.stringify(message));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function createBlock() {
|
||||||
|
var position = basePosition;
|
||||||
|
position.y += 5;
|
||||||
|
var blockProperties = {
|
||||||
|
name: 'Hifi-Spotlight-Block',
|
||||||
|
type: 'Box',
|
||||||
|
dimensions: {
|
||||||
|
x: 1,
|
||||||
|
y: 1,
|
||||||
|
z: 1
|
||||||
|
},
|
||||||
|
collisionsWillMove: true,
|
||||||
|
color: {
|
||||||
|
red: 0,
|
||||||
|
green: 0,
|
||||||
|
blue: 255
|
||||||
|
},
|
||||||
|
position: position
|
||||||
|
}
|
||||||
|
|
||||||
|
block = Entities.addEntity(blockProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
function evalLightWorldTransform(modelPos, modelRot) {
|
||||||
|
return {
|
||||||
|
p: Vec3.sum(modelPos, Vec3.multiplyQbyV(modelRot, MODEL_LIGHT_POSITION)),
|
||||||
|
q: Quat.multiply(modelRot, MODEL_LIGHT_ROTATION)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
print('CLEANUP TEST SCENE SCRIPT')
|
||||||
|
Entities.deleteEntity(block);
|
||||||
|
Entities.deleteEntity(ground);
|
||||||
|
Entities.deleteEntity(light);
|
||||||
|
}
|
||||||
|
|
||||||
|
Script.scriptEnding.connect(cleanup);
|
||||||
|
|
||||||
|
createBlock();
|
||||||
|
createLight();
|
|
@ -2,61 +2,40 @@
|
||||||
|
|
||||||
var AXIS_SCALE = 1;
|
var AXIS_SCALE = 1;
|
||||||
var COLOR_MAX = 255;
|
var COLOR_MAX = 255;
|
||||||
var INTENSITY_MAX = 10;
|
var INTENSITY_MAX = 0.05;
|
||||||
var CUTOFF_MAX = 360;
|
var CUTOFF_MAX = 360;
|
||||||
var EXPONENT_MAX = 1;
|
var EXPONENT_MAX = 1;
|
||||||
|
|
||||||
function Box() {
|
function Slider() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Box.prototype = {
|
Slider.prototype = {
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
var entityProperties = Entities.getEntityProperties(this.entityID, "userData");
|
var entityProperties = Entities.getEntityProperties(this.entityID, "userData");
|
||||||
print('USER DATA:::' + entityProperties.userData)
|
|
||||||
var parsedUserData = JSON.parse(entityProperties.userData);
|
var parsedUserData = JSON.parse(entityProperties.userData);
|
||||||
this.userData = parsedUserData.lightModifierKey;
|
this.userData = parsedUserData.lightModifierKey;
|
||||||
this.bPrime = Vec3.subtract(this.userData.endOfAxis, this.userData.axisBasePosition);
|
|
||||||
this.bPrimeMagnitude = Vec3.length(this.bPrime);
|
|
||||||
|
|
||||||
},
|
},
|
||||||
startNearGrab: function() {
|
startNearGrab: function() {
|
||||||
this.setInitialProperties();
|
this.setInitialProperties();
|
||||||
},
|
},
|
||||||
startDistantGrab: function() {
|
startDistantGrab: function() {
|
||||||
// Entities.editEntity(this.entityID, {
|
|
||||||
// parentID: MyAvatar.sessionUUID,
|
|
||||||
// parentJointIndex: MyAvatar.getJointIndex("LeftHand")
|
|
||||||
// });
|
|
||||||
this.setInitialProperties();
|
this.setInitialProperties();
|
||||||
},
|
},
|
||||||
setInitialProperties: function() {
|
setInitialProperties: function() {
|
||||||
this.initialProperties = Entities.getEntityProperties(this.entityID);
|
this.initialProperties = Entities.getEntityProperties(this.entityID);
|
||||||
},
|
},
|
||||||
clampPosition: function() {
|
continueNearGrab: function() {
|
||||||
|
// this.continueDistantGrab();
|
||||||
var currentProperties = Entities.getEntityProperties(this.entityID);
|
|
||||||
|
|
||||||
var aPrime = Vec3.subtract(this.userData.axisBasePosition, currentProperties.position);
|
|
||||||
|
|
||||||
var dotProduct = Vec3.dot(aPrime, this.bPrime);
|
|
||||||
|
|
||||||
var scalar = dotProduct / this.bPrimeMagnitude;
|
|
||||||
|
|
||||||
print('SCALAR:::' + scalar);
|
|
||||||
|
|
||||||
var projection = Vec3.sum(this.userData.axisBasePosition, Vec3.multiply(scalar, Vec3.normalize(this.bPrime)));
|
|
||||||
|
|
||||||
this.currentProjection = projection;
|
|
||||||
|
|
||||||
},
|
},
|
||||||
continueDistantGrab: function() {
|
continueDistantGrab: function() {
|
||||||
// this.clampPosition();
|
this.setSliderValueBasedOnDistance();
|
||||||
print('distant grab')
|
},
|
||||||
|
setSliderValueBasedOnDistance: function() {
|
||||||
var currentPosition = Entities.getEntityProperties(this.entityID, "position").position;
|
var currentPosition = Entities.getEntityProperties(this.entityID, "position").position;
|
||||||
|
|
||||||
var distance = Vec3.distance(this.axisBasePosition, this.currentProjection);
|
var distance = Vec3.distance(this.userData.axisStart, currentPosition);
|
||||||
|
|
||||||
if (this.userData.sliderType === 'color_red' || this.userData.sliderType === 'color_green' || this.userData.sliderType === 'color_blue') {
|
if (this.userData.sliderType === 'color_red' || this.userData.sliderType === 'color_green' || this.userData.sliderType === 'color_blue') {
|
||||||
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, COLOR_MAX);
|
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, COLOR_MAX);
|
||||||
|
@ -71,6 +50,8 @@
|
||||||
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX);
|
this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
print('SLIDER VALUE:::' + this.sliderValue)
|
||||||
|
this.sendValueToSlider();
|
||||||
|
|
||||||
},
|
},
|
||||||
releaseGrab: function() {
|
releaseGrab: function() {
|
||||||
|
@ -80,7 +61,11 @@
|
||||||
y: 0,
|
y: 0,
|
||||||
z: 0
|
z: 0
|
||||||
},
|
},
|
||||||
parentID: null
|
angularVelocity: {
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
z: 0
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.sendValueToSlider();
|
this.sendValueToSlider();
|
||||||
|
@ -103,5 +88,5 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Box();
|
return new Slider();
|
||||||
});
|
});
|
|
@ -1,117 +0,0 @@
|
||||||
// These constants define the Spotlight position and orientation relative to the model
|
|
||||||
var MODEL_LIGHT_POSITION = {
|
|
||||||
x: 0,
|
|
||||||
y: -0.3,
|
|
||||||
z: 0
|
|
||||||
};
|
|
||||||
var MODEL_LIGHT_ROTATION = Quat.angleAxis(-90, {
|
|
||||||
x: 1,
|
|
||||||
y: 0,
|
|
||||||
z: 0
|
|
||||||
});
|
|
||||||
|
|
||||||
var basePosition, avatarRot;
|
|
||||||
avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0);
|
|
||||||
basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(-3, Quat.getUp(avatarRot)));
|
|
||||||
|
|
||||||
var ground = Entities.addEntity({
|
|
||||||
name:'Hifi-Light-Mod-Floor',
|
|
||||||
type: "Model",
|
|
||||||
modelURL: "https://hifi-public.s3.amazonaws.com/eric/models/woodFloor.fbx",
|
|
||||||
dimensions: {
|
|
||||||
x: 100,
|
|
||||||
y: 2,
|
|
||||||
z: 100
|
|
||||||
},
|
|
||||||
position: basePosition,
|
|
||||||
shapeType: 'box'
|
|
||||||
});
|
|
||||||
|
|
||||||
var light, block;
|
|
||||||
|
|
||||||
// basePosition.y += 2;
|
|
||||||
|
|
||||||
function createLight() {
|
|
||||||
print('making light' + block)
|
|
||||||
var blockProperties = Entities.getEntityProperties(block, ["position", "rotation"]);
|
|
||||||
var lightTransform = evalLightWorldTransform(blockProperties.position, blockProperties.rotation);
|
|
||||||
var lightProperties = {
|
|
||||||
name: 'Hifi-Spotlight',
|
|
||||||
type: "Light",
|
|
||||||
isSpotlight: true,
|
|
||||||
dimensions: {
|
|
||||||
x: 2,
|
|
||||||
y: 2,
|
|
||||||
z: 20
|
|
||||||
},
|
|
||||||
parentID: block,
|
|
||||||
color: {
|
|
||||||
red: 255,
|
|
||||||
green: 0,
|
|
||||||
blue: 255
|
|
||||||
},
|
|
||||||
intensity: 2,
|
|
||||||
exponent: 0.3,
|
|
||||||
cutoff: 20,
|
|
||||||
lifetime: -1,
|
|
||||||
position: lightTransform.p,
|
|
||||||
rotation: lightTransform.q
|
|
||||||
};
|
|
||||||
|
|
||||||
light = Entities.addEntity(lightProperties);
|
|
||||||
|
|
||||||
var message = {
|
|
||||||
light: {
|
|
||||||
id: light,
|
|
||||||
type: 'spotlight',
|
|
||||||
initialProperties: lightProperties
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Messages.sendMessage('Hifi-Light-Mod-Receiver', JSON.stringify(message));
|
|
||||||
print('SENT MESSAGE')
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function createBlock() {
|
|
||||||
print('making block');
|
|
||||||
|
|
||||||
var position = basePosition;
|
|
||||||
position.y += 5;
|
|
||||||
var blockProperties = {
|
|
||||||
name: 'Hifi-Spotlight-Block',
|
|
||||||
type: 'Box',
|
|
||||||
dimensions: {
|
|
||||||
x: 1,
|
|
||||||
y: 1,
|
|
||||||
z: 1
|
|
||||||
},
|
|
||||||
collisionsWillMove: true,
|
|
||||||
color: {
|
|
||||||
red: 0,
|
|
||||||
green: 0,
|
|
||||||
blue: 255
|
|
||||||
},
|
|
||||||
position: position
|
|
||||||
}
|
|
||||||
|
|
||||||
block = Entities.addEntity(blockProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
function evalLightWorldTransform(modelPos, modelRot) {
|
|
||||||
return {
|
|
||||||
p: Vec3.sum(modelPos, Vec3.multiplyQbyV(modelRot, MODEL_LIGHT_POSITION)),
|
|
||||||
q: Quat.multiply(modelRot, MODEL_LIGHT_ROTATION)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanup() {
|
|
||||||
Entities.deleteEntity(block);
|
|
||||||
Entities.deleteEntity(ground);
|
|
||||||
Entities.deleteEntity(light);
|
|
||||||
}
|
|
||||||
|
|
||||||
Script.scriptEnding.connect(cleanup);
|
|
||||||
|
|
||||||
createBlock();
|
|
||||||
createLight();
|
|
Loading…
Reference in a new issue