From 0fe4803b04dc9e2554d1ef5335ce98e498c05cde Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 12 Dec 2015 16:17:00 -0800 Subject: [PATCH 01/57] start --- examples/lights/box.js | 31 +++++++++ examples/lights/light_modifier.js | 103 ++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 examples/lights/box.js create mode 100644 examples/lights/light_modifier.js diff --git a/examples/lights/box.js b/examples/lights/box.js new file mode 100644 index 0000000000..711f5487b2 --- /dev/null +++ b/examples/lights/box.js @@ -0,0 +1,31 @@ +(function() { + + function Box () { + this.oldColor = {}; + this.oldColorKnown = false; + } + + Box.prototype = { + preload: function(entityID) { + print("preload"); + + this.entityID = entityID; + this.storeOldColor(entityID); + }, + startDistantGrab:function(){ + + }, + continueDistantGrab:function(){ + + }, + releaseGrab:function(){ + + } + setHand:function(){ + + } + + }; + + return new Box(); +}); \ No newline at end of file diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js new file mode 100644 index 0000000000..fd49690088 --- /dev/null +++ b/examples/lights/light_modifier.js @@ -0,0 +1,103 @@ +// given a selected light, instantiate some entities that represent various values you can dynamically adjust +// + +var BOX_SCRIPT_URL = Script.resolvePath('box.js'); + +function entitySlider(color) { + this.color = color; + return this; +} + +var RED = { + r: 255, + g: 0, + b: 0 +}; + +var GREEN = { + r: 0, + g: 255, + b: 0 +}; + +var BLUE = { + r: 0, + g: 0, + b: 255 +}; + +var PURPLE = { + r: 255, + g: 0, + b: 255 +}; + +var WHITE = { + r: 255 + g: 255, + b: 255 +}; + +//what's the ux for adjusting values? start with simple entities, try image overlays etc +entitySlider.prototype = { + createAxis: function() { + var properties = { + type: 'Line', + color: this.color, + collisionsWillMove: false, + ignoreForCollisions: true, + }; + + this.axis = Entities.addEntity(properties); + }, + createBoxIndicator: function() { + var properties = { + type: 'Box', + dimensions: { + x: 0.04, + y: 0.04, + z: 0.04 + }, + color: this.color, + position: position, + script: BOX_SCRIPT_URL + }; + + + + this.boxIndicator = Entities.addEntity(properties); + }, + moveIndicatorAlongAxis: function(direction) { + + } +}; + +//create them for this light +function makeSliders(light) { + if (light.type === 'spotlight') { + var USE_COLOR_SLIDER = true; + var USE_INTENSITY_SLIDER = true; + var USE_CUTOFF_SLIDER = true; + var USE_EXPONENT_SLIDER = true; + } + if (light.type === 'pointlight') { + var USE_COLOR_SLIDER = true; + var USE_INTENSITY_SLIDER = true; + var USE_CUTOFF_SLIDER = false; + var USE_EXPONENT_SLIDER = false; + } + if (USE_COLOR_SLIDER === true) { + var r = new entitySlider(RED); + var g = new entitySlider(GREEN); + var b = new entitySlider(BLUE); + } + if (USE_INTENSITY_SLIDER === true) { + var intensity = new entitySlider(WHITE); + } + if (USE_CUTOFF_SLIDER === true) { + var cutoff = new entitySlider(PURPLE); + } + if (USE_EXPONENT_SLIDER === true) { + var exponent = new entitySlider(PURPLE); + } +}; \ No newline at end of file From 7cace240025b3f950a91cbf072e2dbd664fa3235 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 12 Dec 2015 17:14:43 -0800 Subject: [PATCH 02/57] light editing framework --- examples/lights/box.js | 65 ++++++++++++----- examples/lights/light_modifier.js | 116 +++++++++++++++++++++++++----- 2 files changed, 148 insertions(+), 33 deletions(-) diff --git a/examples/lights/box.js b/examples/lights/box.js index 711f5487b2..3a24ef1568 100644 --- a/examples/lights/box.js +++ b/examples/lights/box.js @@ -1,29 +1,62 @@ (function() { - function Box () { - this.oldColor = {}; - this.oldColorKnown = false; + function Box() { + return this; } Box.prototype = { preload: function(entityID) { - print("preload"); - this.entityID = entityID; - this.storeOldColor(entityID); }, - startDistantGrab:function(){ - + startNearGrab: function() { + this.setInitialProperties(); }, - continueDistantGrab:function(){ - + startDistantGrab: function() { + this.setInitialProperties(); }, - releaseGrab:function(){ - - } - setHand:function(){ - - } + setInitialProperties: function() { + this.initialProperties = Entities.getEntityProperties(this.entityID); + }, + getClampedPosition: function() { + return position; + }, + getClampedRotation: function() { + var rotation = initialProperties.rotation; + return rotation; + }, + continueDistantGrab: function() { + var currentPosition = this.getClampedPosition(); + var distance = Vec3.distance(this.initialProperties.position, currentPosition); + this.sliderValue = scaleValueBasedOnDistanceFromStart(distance); + Entities.editEntity(this.entityID) { + position: currentPosition, + rotation: this.getClampedRotation() + } + }, + releaseGrab: function() { + Entities.editEntity(this.entityID, { + velocity: { + x: 0, + y: 0, + z: 0 + } + }) + this.sendValueToSlider(); + }, + scaleValueBasedOnDistanceFromStart: function(value, min1, max1, min2, max2) { + var min1 = 0; + var max1 = 1; + var min2 = 0; + var max2 = 255; + return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); + }, + sendValueToSlider: function() { + var message = { + lightID: this.entityID, + sliderValue: this.sliderValue + } + Messages.sendMessage('Hifi-Slider-Value-Reciever', JSON.stringify(message)); + }; }; diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index fd49690088..71d3d38c64 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -3,8 +3,10 @@ var BOX_SCRIPT_URL = Script.resolvePath('box.js'); -function entitySlider(color) { +function entitySlider(color, sliderType, verticalOffset) { this.color = color; + this.sliderType = sliderType; + this.verticalOffset = verticalOffset; return this; } @@ -38,6 +40,13 @@ var WHITE = { b: 255 }; +var AXIS_SCALE = 1; +var BOX_DIMENSIONS = { + x: 0.04, + y: 0.04, + z: 0.04 +} + //what's the ux for adjusting values? start with simple entities, try image overlays etc entitySlider.prototype = { createAxis: function() { @@ -53,27 +62,98 @@ entitySlider.prototype = { createBoxIndicator: function() { var properties = { type: 'Box', - dimensions: { - x: 0.04, - y: 0.04, - z: 0.04 - }, + dimensions: BOX_DIMENSIONS, color: this.color, position: position, script: BOX_SCRIPT_URL }; - - this.boxIndicator = Entities.addEntity(properties); }, - moveIndicatorAlongAxis: function(direction) { + handleValueMessages: function(channel, message, sender) { + //easily protect from other people editing your values, but group editing might be fun so lets try that first. + // if (sender !== MyAvatar.sessionUUID) { + // return; + // } + var parsedMessage = JSON.parse(message); + setValueFromMessage(parsedMessage); + }, + setValueFromMessage: function(message) { + var lightProperties = Entities.getEntitiyProperties(message.lightID); + if (this.sliderType === 'color_red') { + Entities.editEntity(message.lightID, { + color: { + red: message.sliderValue, + green: lightProperties.color.g, + blue: lightProperties.color.b + } + }) + } + + if (this.sliderType === 'color_green') { + Entities.editEntity(message.lightID, { + color: { + red: lightProperties.color.r + green: message.sliderValue, + blue: lightProperties.color.b + } + }) + } + + if (this.sliderType === 'color_blue') { + Entities.editEntity(message.lightID, { + color: { + red: lightProperties.color.r, + green: lightProperties.color.g, + blue: message.sliderValue, + } + }) + } + + if (this.sliderType === 'intensity') { + Entities.editEntity(message.lightID, { + intensity: message.sliderValue + }) + } + + if (this.sliderType === 'cutoff') { + Entities.editEntity(message.lightID, { + cutoff: message.sliderValue + }) + } + + if (this.sliderType === 'exponent') { + Entities.editEntity(message.lightID, { + exponent: message.sliderValue + }) + } + }, + subscribeToBoxMessages: function() { + Messages.subscribe('Hifi-Slider-Value-Reciever'); + Messages.messageReceived.connect(this.handleValueMessages); + }, + cleanup: function() { + Entities.deleteEntity(this.boxIndicator); + Entities.deleteEntity(this.axis); + Messages.messageReceived.disconnect(this.handleValueMessages); } }; -//create them for this light +//create them for a given light function makeSliders(light) { + var initialPosition = { + x: 0, + y: 0, + z: 0 + }; + + var perRowOffset = { + x: 0, + y: 0.2, + z: 0 + }; + if (light.type === 'spotlight') { var USE_COLOR_SLIDER = true; var USE_INTENSITY_SLIDER = true; @@ -87,17 +167,19 @@ function makeSliders(light) { var USE_EXPONENT_SLIDER = false; } if (USE_COLOR_SLIDER === true) { - var r = new entitySlider(RED); - var g = new entitySlider(GREEN); - var b = new entitySlider(BLUE); + var r = new entitySlider(RED, 'color_red', Vec3.multiply(1, perRowOffset)); + var g = new entitySlider(GREEN, 'color_green', Vec3.multiply(2, perRowOffset)); + var b = new entitySlider(BLUE, 'color_blue', Vec3.multiply(3, perRowOffset)); } if (USE_INTENSITY_SLIDER === true) { - var intensity = new entitySlider(WHITE); + var intensity = new entitySlider(WHITE, 'intensity', Vec3.multiply(4, perRowOffset)); } if (USE_CUTOFF_SLIDER === true) { - var cutoff = new entitySlider(PURPLE); + var cutoff = new entitySlider(PURPLE, 'cutoff', Vec3.multiply(5, perRowOffset)); } if (USE_EXPONENT_SLIDER === true) { - var exponent = new entitySlider(PURPLE); + var exponent = new entitySlider(PURPLE, 'exponent', Vec3.multiply(6, perRowOffset)); } -}; \ No newline at end of file +}; + +makeSliders(light) \ No newline at end of file From 231bcdb8f0fbf0eb8b608f3f89e9f64ed6098f54 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 12 Dec 2015 17:22:57 -0800 Subject: [PATCH 03/57] name some things better and cleanup --- examples/lights/box.js | 4 +- examples/lights/light_modifier.js | 74 +++++++++++++++---------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/examples/lights/box.js b/examples/lights/box.js index 3a24ef1568..27bffe6e33 100644 --- a/examples/lights/box.js +++ b/examples/lights/box.js @@ -28,6 +28,7 @@ var currentPosition = this.getClampedPosition(); var distance = Vec3.distance(this.initialProperties.position, currentPosition); this.sliderValue = scaleValueBasedOnDistanceFromStart(distance); + Entities.editEntity(this.entityID) { position: currentPosition, rotation: this.getClampedRotation() @@ -41,6 +42,7 @@ z: 0 } }) + this.sendValueToSlider(); }, scaleValueBasedOnDistanceFromStart: function(value, min1, max1, min2, max2) { @@ -52,7 +54,7 @@ }, sendValueToSlider: function() { var message = { - lightID: this.entityID, + boxID: this.entityID, sliderValue: this.sliderValue } Messages.sendMessage('Hifi-Slider-Value-Reciever', JSON.stringify(message)); diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index 71d3d38c64..9c841eeb24 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -3,10 +3,11 @@ var BOX_SCRIPT_URL = Script.resolvePath('box.js'); -function entitySlider(color, sliderType, verticalOffset) { +function entitySlider(light, color, sliderType, row) { + this.light = light; this.color = color; this.sliderType = sliderType; - this.verticalOffset = verticalOffset; + this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET);; return this; } @@ -42,20 +43,27 @@ var WHITE = { var AXIS_SCALE = 1; var BOX_DIMENSIONS = { - x: 0.04, - y: 0.04, - z: 0.04 -} + x: 0.05, + y: 0.05, + z: 0.05 +}; +var PER_ROW_OFFSET = { + x: 0, + y: 0.2, + z: 0 +}; //what's the ux for adjusting values? start with simple entities, try image overlays etc entitySlider.prototype = { createAxis: function() { - var properties = { - type: 'Line', - color: this.color, - collisionsWillMove: false, - ignoreForCollisions: true, - }; + var position = + var properties = { + type: 'Line', + color: this.color, + collisionsWillMove: false, + ignoreForCollisions: true, + position: position, + }; this.axis = Entities.addEntity(properties); }, @@ -79,54 +87,54 @@ entitySlider.prototype = { setValueFromMessage(parsedMessage); }, setValueFromMessage: function(message) { - var lightProperties = Entities.getEntitiyProperties(message.lightID); + var lightProperties = Entities.getEntityProperties(this.lightID); if (this.sliderType === 'color_red') { - Entities.editEntity(message.lightID, { + Entities.editEntity(this.lightID, { color: { red: message.sliderValue, green: lightProperties.color.g, blue: lightProperties.color.b } - }) + }); } if (this.sliderType === 'color_green') { - Entities.editEntity(message.lightID, { + Entities.editEntity(this.lightID, { color: { red: lightProperties.color.r green: message.sliderValue, blue: lightProperties.color.b } - }) + }); } if (this.sliderType === 'color_blue') { - Entities.editEntity(message.lightID, { + Entities.editEntity(this.lightID, { color: { red: lightProperties.color.r, green: lightProperties.color.g, blue: message.sliderValue, } - }) + }); } if (this.sliderType === 'intensity') { - Entities.editEntity(message.lightID, { + Entities.editEntity(this.lightID, { intensity: message.sliderValue - }) + }); } if (this.sliderType === 'cutoff') { - Entities.editEntity(message.lightID, { + Entities.editEntity(this.lightID, { cutoff: message.sliderValue - }) + }); } if (this.sliderType === 'exponent') { - Entities.editEntity(message.lightID, { + Entities.editEntity(this.lightID, { exponent: message.sliderValue - }) + }); } }, subscribeToBoxMessages: function() { @@ -142,17 +150,6 @@ entitySlider.prototype = { //create them for a given light function makeSliders(light) { - var initialPosition = { - x: 0, - y: 0, - z: 0 - }; - - var perRowOffset = { - x: 0, - y: 0.2, - z: 0 - }; if (light.type === 'spotlight') { var USE_COLOR_SLIDER = true; @@ -167,7 +164,7 @@ function makeSliders(light) { var USE_EXPONENT_SLIDER = false; } if (USE_COLOR_SLIDER === true) { - var r = new entitySlider(RED, 'color_red', Vec3.multiply(1, perRowOffset)); + var r = new entitySlider(RED, 'color_red', 1); var g = new entitySlider(GREEN, 'color_green', Vec3.multiply(2, perRowOffset)); var b = new entitySlider(BLUE, 'color_blue', Vec3.multiply(3, perRowOffset)); } @@ -182,4 +179,5 @@ function makeSliders(light) { } }; -makeSliders(light) \ No newline at end of file + +makeSliders(light); \ No newline at end of file From 77969e14810ab20d689dff5e65c3bcd6591b65d9 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 12 Dec 2015 17:31:49 -0800 Subject: [PATCH 04/57] breaktime --- examples/lights/light_modifier.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index 9c841eeb24..d6c964bf55 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -179,5 +179,4 @@ function makeSliders(light) { } }; - makeSliders(light); \ No newline at end of file From 1698e903c94ef65de1366e30de692beafc3352c9 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 14 Dec 2015 11:25:30 -0800 Subject: [PATCH 05/57] midday --- examples/lights/box.js | 6 +- examples/lights/light_modifier.js | 114 ++++++++++++++++++++++++------ 2 files changed, 96 insertions(+), 24 deletions(-) diff --git a/examples/lights/box.js b/examples/lights/box.js index 27bffe6e33..ac3cac7ab3 100644 --- a/examples/lights/box.js +++ b/examples/lights/box.js @@ -18,7 +18,11 @@ this.initialProperties = Entities.getEntityProperties(this.entityID); }, getClampedPosition: function() { - return position; + dPosition = Vec3.subtract(MyAvatar.position, previousPosition); + //convert to localFrame + dPosition = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), dPosition); + + return dPosition; }, getClampedRotation: function() { var rotation = initialProperties.rotation; diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index d6c964bf55..6ae702bf7f 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -3,14 +3,6 @@ var BOX_SCRIPT_URL = Script.resolvePath('box.js'); -function entitySlider(light, color, sliderType, row) { - this.light = light; - this.color = color; - this.sliderType = sliderType; - this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET);; - return this; -} - var RED = { r: 255, g: 0, @@ -42,6 +34,7 @@ var WHITE = { }; var AXIS_SCALE = 1; + var BOX_DIMENSIONS = { x: 0.05, y: 0.05, @@ -53,17 +46,54 @@ var PER_ROW_OFFSET = { z: 0 }; +function entitySlider(light, color, sliderType, row) { + this.light = light; + this.lightID = light.id; + this.initialProperties = light.initialProperties; + this.color = color; + this.sliderType = sliderType; + this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); + + var formattedMessage = { + 'color_red': this.initialProperties.color.r, + 'color_green': this.initialProperties.color.g, + 'color_blue': this.initialProperties.color.b, + 'intensity': this.initialProperties.intensity, + 'exponent': this.initialProperties.exponent, + 'cutoff': this.initialProperties.cutoff, + } + + this.setValueFromMessage(formattedMessage); + this.setInitialSliderPositions(); + + return this; +} + //what's the ux for adjusting values? start with simple entities, try image overlays etc entitySlider.prototype = { createAxis: function() { - var position = - var properties = { - type: 'Line', - color: this.color, - collisionsWillMove: false, - ignoreForCollisions: true, - position: position, - }; + //start of line + var position; + //1 meter along orientationAxis + var endOfAxis; + var properties = { + type: 'Line', + color: this.color, + collisionsWillMove: false, + ignoreForCollisions: true, + dimensions: { + x: 3, + y: 3, + z: 3 + }, + position: position, + linePoints: [{ + x: 0, + y: 0, + z: 0 + }, endOfAxis], + lineWidth: 5, + }; this.axis = Entities.addEntity(properties); }, @@ -79,6 +109,9 @@ entitySlider.prototype = { this.boxIndicator = Entities.addEntity(properties); }, handleValueMessages: function(channel, message, sender) { + if (channel !== 'Hifi-Slider-Value-Reciever') { + return; + } //easily protect from other people editing your values, but group editing might be fun so lets try that first. // if (sender !== MyAvatar.sessionUUID) { // return; @@ -141,6 +174,15 @@ entitySlider.prototype = { Messages.subscribe('Hifi-Slider-Value-Reciever'); Messages.messageReceived.connect(this.handleValueMessages); }, + setInitialSliderPositions:function(){ + + var distanceRed = (this.initialProperties.color.r / 255) * AXIS_SCALE; + var distanceGreen = (this.initialProperties.color.g / 255) * AXIS_SCALE; + var distanceBlue = (this.initialProperties.color.b / 255) * AXIS_SCALE; + var distanceIntensity = (this.initialProperties.intensity / 255) * AXIS_SCALE; + var distanceCutoff = (this.initialProperties.cutoff / 360) * AXIS_SCALE; + var distanceExponent = (this.initialProperties.exponent / 255) * AXIS_SCALE; + }, cleanup: function() { Entities.deleteEntity(this.boxIndicator); Entities.deleteEntity(this.axis); @@ -150,7 +192,6 @@ entitySlider.prototype = { //create them for a given light function makeSliders(light) { - if (light.type === 'spotlight') { var USE_COLOR_SLIDER = true; var USE_INTENSITY_SLIDER = true; @@ -165,18 +206,45 @@ function makeSliders(light) { } if (USE_COLOR_SLIDER === true) { var r = new entitySlider(RED, 'color_red', 1); - var g = new entitySlider(GREEN, 'color_green', Vec3.multiply(2, perRowOffset)); - var b = new entitySlider(BLUE, 'color_blue', Vec3.multiply(3, perRowOffset)); + var g = new entitySlider(GREEN, 'color_green', 2); + var b = new entitySlider(BLUE, 'color_blue', 3); } if (USE_INTENSITY_SLIDER === true) { - var intensity = new entitySlider(WHITE, 'intensity', Vec3.multiply(4, perRowOffset)); + var intensity = new entitySlider(WHITE, 'intensity', 4); } if (USE_CUTOFF_SLIDER === true) { - var cutoff = new entitySlider(PURPLE, 'cutoff', Vec3.multiply(5, perRowOffset)); + var cutoff = new entitySlider(PURPLE, 'cutoff', 5); } if (USE_EXPONENT_SLIDER === true) { - var exponent = new entitySlider(PURPLE, 'exponent', Vec3.multiply(6, perRowOffset)); + var exponent = new entitySlider(PURPLE, 'exponent', 6); } }; -makeSliders(light); \ No newline at end of file +function subScribeToNewLights() { + Messages.subscribe('Hifi-Light-Mod-Receiver'); + Messages.messageReceived.connect(handleLightModMessages); +} + +function handleLightModMessages(channel, message, sender) { + if (channel !== 'Hifi-Light-Mod-Receiver') { + return; + } + if (sender !== MyAvatar.sessionUUID) { + return; + } + var parsedMessage = JSON.parse(message); + var light = message.light; + makeSliders(light); +} + +subScribeToNewLights(); + + // diffuseColor: { red: 255, green: 255, blue: 255 }, + // ambientColor: { red: 255, green: 255, blue: 255 }, + // specularColor: { red: 255, green: 255, blue: 255 }, + + // constantAttenuation: 1, + // linearAttenuation: 0, + // quadraticAttenuation: 0, + // exponent: 0, + // cutoff: 180, // in degrees \ No newline at end of file From 18458a843147f55b4163cac6af1e5dd6b37c2468 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 14 Dec 2015 12:04:44 -0800 Subject: [PATCH 06/57] test scene --- examples/lights/testScene.js | 104 +++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 examples/lights/testScene.js diff --git a/examples/lights/testScene.js b/examples/lights/testScene.js new file mode 100644 index 0000000000..eeb5f4ffd7 --- /dev/null +++ b/examples/lights/testScene.js @@ -0,0 +1,104 @@ + // 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(SPAWN_RANGE * 3, Quat.getFront(avatarRot))); + + var ground = Entities.addEntity({ + 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() { + var lightProperties = { + name: 'Hifi-Spotlight' + type: "Light", + isSpotlight: true, + dimensions: { + x: 2, + y: 2, + z: 20 + }, + parentID: box, + color: { + red: 255, + green: 255, + blue: 255 + }, + intensity: 2, + exponent: 0.3, + cutoff: 20, + lifetime: LIFETIME, + 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 blockProperties = { + name: 'Hifi-Spotlight-Block', + type: 'Box', + dimensions: { + x: 1, + y: 1, + z: 1 + }, + collisionsWillMove: true, + shapeType: 'Box', + color: { + red: 0, + green: 0 + blue: 255 + }, + position: basePosition + } + + block = Entities.addEntity(block); + } + + 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(ground); + Entities.deleteEntity(light); + } + + createBlock(); + createLight(); \ No newline at end of file From ea0ffa589930f3528ea347e33709f865e6e645c4 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 14 Dec 2015 16:39:25 -0800 Subject: [PATCH 07/57] support changing values for lights via message --- examples/lights/box.js | 18 ++- examples/lights/light_modifier.js | 197 ++++++++++++++++++++++-------- examples/lights/testScene.js | 38 ++++-- 3 files changed, 183 insertions(+), 70 deletions(-) diff --git a/examples/lights/box.js b/examples/lights/box.js index ac3cac7ab3..a8e708b344 100644 --- a/examples/lights/box.js +++ b/examples/lights/box.js @@ -1,5 +1,11 @@ (function() { + var AXIS_SCALE = 1; + var COLOR_MAX = 255; + var INTENSITY_MAX = 10; + var CUTOFF_MAX = 360; + var EXPONENT_MAX = 1; + function Box() { return this; } @@ -7,6 +13,8 @@ Box.prototype = { preload: function(entityID) { this.entityID = entityID; + var userData = Entities.getEntityProperties(this.entityID, "userData"); + this.userData = JSON.parse(userData); }, startNearGrab: function() { this.setInitialProperties(); @@ -31,7 +39,8 @@ continueDistantGrab: function() { var currentPosition = this.getClampedPosition(); var distance = Vec3.distance(this.initialProperties.position, currentPosition); - this.sliderValue = scaleValueBasedOnDistanceFromStart(distance); + if () + this.sliderValue = scaleValueBasedOnDistanceFromStart(distance); Entities.editEntity(this.entityID) { position: currentPosition, @@ -49,16 +58,17 @@ this.sendValueToSlider(); }, - scaleValueBasedOnDistanceFromStart: function(value, min1, max1, min2, max2) { + scaleValueBasedOnDistanceFromStart: function(value, max2) { var min1 = 0; var max1 = 1; var min2 = 0; - var max2 = 255; + var max2 = max2; return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); }, sendValueToSlider: function() { var message = { - boxID: this.entityID, + lightID:userData.lightID, + sliderType:userData.sliderType, sliderValue: this.sliderValue } Messages.sendMessage('Hifi-Slider-Value-Reciever', JSON.stringify(message)); diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index 6ae702bf7f..f1c27b4e4b 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -28,7 +28,7 @@ var PURPLE = { }; var WHITE = { - r: 255 + r: 255, g: 255, b: 255 }; @@ -48,24 +48,48 @@ var PER_ROW_OFFSET = { function entitySlider(light, color, sliderType, row) { this.light = light; - this.lightID = light.id; + this.lightID = light.id.replace(/[{}]/g, ""); this.initialProperties = light.initialProperties; this.color = color; this.sliderType = sliderType; this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); - var formattedMessage = { - 'color_red': this.initialProperties.color.r, - 'color_green': this.initialProperties.color.g, - 'color_blue': this.initialProperties.color.b, - 'intensity': this.initialProperties.intensity, - 'exponent': this.initialProperties.exponent, - 'cutoff': this.initialProperties.cutoff, + var message = { + lightID: this.lightID, + sliderType: this.sliderType, + sliderValue: null + }; + + if (this.sliderType === 'color_red') { + message.sliderValue = this.initialProperties.color.red + this.setValueFromMessage(message); + } + if (this.sliderType === 'color_green') { + message.sliderValue = this.initialProperties.color.green + this.setValueFromMessage(message); + } + if (this.sliderType === 'color_blue') { + message.sliderValue = this.initialProperties.color.blue + this.setValueFromMessage(message); } - this.setValueFromMessage(formattedMessage); - this.setInitialSliderPositions(); + if (this.sliderType === 'intensity') { + message.sliderValue = this.initialProperties.intensity + this.setValueFromMessage(message); + } + if (this.sliderType === 'exponent') { + message.sliderValue = this.initialProperties.exponent + this.setValueFromMessage(message); + } + + if (this.sliderType === 'cutoff') { + message.sliderValue = this.initialProperties.cutoff + this.setValueFromMessage(message); + } + + // this.setInitialSliderPositions(); + this.subscribeToBoxMessages(); return this; } @@ -103,31 +127,44 @@ entitySlider.prototype = { dimensions: BOX_DIMENSIONS, color: this.color, position: position, - script: BOX_SCRIPT_URL + script: BOX_SCRIPT_URL, + userData: JSON.stringify({ + lightModifierKey: { + lightID: this.lightID, + sliderType: this.sliderType + } + }) }; this.boxIndicator = Entities.addEntity(properties); }, - handleValueMessages: function(channel, message, sender) { - if (channel !== 'Hifi-Slider-Value-Reciever') { + setValueFromMessage: function(message) { + print('VALUE MESSAGE::'+JSON.stringify(message)) + print('LIGHT ID::'+this.lightID); + + //message is not for our light + if (message.lightID !== this.lightID) { + print('not our light') return; } - //easily protect from other people editing your values, but group editing might be fun so lets try that first. - // if (sender !== MyAvatar.sessionUUID) { - // return; - // } - var parsedMessage = JSON.parse(message); - setValueFromMessage(parsedMessage); - }, - setValueFromMessage: function(message) { + + //message is not our type + if (message.sliderType !== this.sliderType) { + print('not our slider type') + return + } + + print('SHOULD SET SOME VALUE:::' + message.sliderType); + var lightProperties = Entities.getEntityProperties(this.lightID); + // print('LIGHT PROPERTIES::'+JSON.stringify(lightProperties)); if (this.sliderType === 'color_red') { Entities.editEntity(this.lightID, { color: { red: message.sliderValue, - green: lightProperties.color.g, - blue: lightProperties.color.b + green: lightProperties.color.green, + blue: lightProperties.color.blue } }); } @@ -135,9 +172,9 @@ entitySlider.prototype = { if (this.sliderType === 'color_green') { Entities.editEntity(this.lightID, { color: { - red: lightProperties.color.r + red: lightProperties.color.red, green: message.sliderValue, - blue: lightProperties.color.b + blue: lightProperties.color.blue } }); } @@ -145,14 +182,15 @@ entitySlider.prototype = { if (this.sliderType === 'color_blue') { Entities.editEntity(this.lightID, { color: { - red: lightProperties.color.r, - green: lightProperties.color.g, + red: lightProperties.color.red, + green: lightProperties.color.green, blue: message.sliderValue, } }); } if (this.sliderType === 'intensity') { + print('CHANGING INTENSITY TO::' + message.sliderValue) Entities.editEntity(this.lightID, { intensity: message.sliderValue }); @@ -171,17 +209,22 @@ entitySlider.prototype = { } }, subscribeToBoxMessages: function() { + print('subscribing to box messages'); Messages.subscribe('Hifi-Slider-Value-Reciever'); - Messages.messageReceived.connect(this.handleValueMessages); + Messages.messageReceived.connect(handleValueMessages); }, - setInitialSliderPositions:function(){ + setInitialSliderPositions: function() { + var COLOR_MAX = 255; + var INTENSITY_MAX = 10; + var CUTOFF_MAX = 360; + var EXPONENT_MAX = 1; - var distanceRed = (this.initialProperties.color.r / 255) * AXIS_SCALE; - var distanceGreen = (this.initialProperties.color.g / 255) * AXIS_SCALE; - var distanceBlue = (this.initialProperties.color.b / 255) * AXIS_SCALE; - var distanceIntensity = (this.initialProperties.intensity / 255) * AXIS_SCALE; - var distanceCutoff = (this.initialProperties.cutoff / 360) * AXIS_SCALE; - var distanceExponent = (this.initialProperties.exponent / 255) * AXIS_SCALE; + var distanceRed = (this.initialProperties.color.red / COLOR_MAX) * AXIS_SCALE; + var distanceGreen = (this.initialProperties.color.green / COLOR_MAX) * AXIS_SCALE; + var distanceBlue = (this.initialProperties.color.blue / COLOR_MAX) * AXIS_SCALE; + var distanceIntensity = (this.initialProperties.intensity / INTENSITY_MAX) * AXIS_SCALE; + var distanceCutoff = (this.initialProperties.cutoff / CUTOFF_MAX) * AXIS_SCALE; + var distanceExponent = (this.initialProperties.exponent / EXPONENT_MAX) * AXIS_SCALE; }, cleanup: function() { Entities.deleteEntity(this.boxIndicator); @@ -190,8 +233,18 @@ entitySlider.prototype = { } }; -//create them for a given light +var sliders = []; +var slidersRef = { + 'color_red': null, + 'color_green': null, + 'color_blue': null, + intensity: null, + cutoff: null, + exponent: null +} + function makeSliders(light) { + print('light in makesliders:::' + light) if (light.type === 'spotlight') { var USE_COLOR_SLIDER = true; var USE_INTENSITY_SLIDER = true; @@ -205,22 +258,31 @@ function makeSliders(light) { var USE_EXPONENT_SLIDER = false; } if (USE_COLOR_SLIDER === true) { - var r = new entitySlider(RED, 'color_red', 1); - var g = new entitySlider(GREEN, 'color_green', 2); - var b = new entitySlider(BLUE, 'color_blue', 3); + slidersRef.color_red = new entitySlider(light, RED, 'color_red', 1); + slidersRef.color_green = new entitySlider(light, GREEN, 'color_green', 2); + slidersRef.color_blue = new entitySlider(light, BLUE, 'color_blue', 3); + + sliders.push(slidersRef.color_red); + sliders.push(slidersRef.color_green); + sliders.push(slidersRef.color_blue); + } if (USE_INTENSITY_SLIDER === true) { - var intensity = new entitySlider(WHITE, 'intensity', 4); + slidersRef.intensity = new entitySlider(light, WHITE, 'intensity', 4); + sliders.push(slidersRef.intensity); } if (USE_CUTOFF_SLIDER === true) { - var cutoff = new entitySlider(PURPLE, 'cutoff', 5); + slidersRef.cutoff = new entitySlider(light, PURPLE, 'cutoff', 5); + sliders.push(slidersRef.cutoff); } if (USE_EXPONENT_SLIDER === true) { - var exponent = new entitySlider(PURPLE, 'exponent', 6); + slidersRef.exponent = new entitySlider(light, PURPLE, 'exponent', 6); + sliders.push(slidersRef.exponent); } }; function subScribeToNewLights() { + print('subscribing to light messages') Messages.subscribe('Hifi-Light-Mod-Receiver'); Messages.messageReceived.connect(handleLightModMessages); } @@ -233,18 +295,47 @@ function handleLightModMessages(channel, message, sender) { return; } var parsedMessage = JSON.parse(message); - var light = message.light; - makeSliders(light); + + print('MESSAGE LIGHT:::' + message) + makeSliders(parsedMessage.light); } +function handleValueMessages(channel, message, sender) { + + + if (channel !== 'Hifi-Slider-Value-Reciever') { + return; + } + print('HANDLE VALUE MESSAGE') + //easily protect from other people editing your values, but group editing might be fun so lets try that first. + // if (sender !== MyAvatar.sessionUUID) { + // return; + // } + var parsedMessage = JSON.parse(message); + + slidersRef[parsedMessage.sliderType].setValueFromMessage(parsedMessage) + + // this.setValueFromMessage(parsedMessage); +} + +function cleanup() { + while (sliders.length > 0) { + var slider = sliders.pop(); + slider.cleanup(); + } + Messages.messageReceived.disconnect(handleLightModMessages); + delete sliders +} + +Script.scriptEnding.connect(cleanup); subScribeToNewLights(); - // diffuseColor: { red: 255, green: 255, blue: 255 }, - // ambientColor: { red: 255, green: 255, blue: 255 }, - // specularColor: { red: 255, green: 255, blue: 255 }, +// diffuseColor: { red: 255, green: 255, blue: 255 }, +// ambientColor: { red: 255, green: 255, blue: 255 }, +// specularColor: { red: 255, green: 255, blue: 255 }, - // constantAttenuation: 1, - // linearAttenuation: 0, - // quadraticAttenuation: 0, - // exponent: 0, - // cutoff: 180, // in degrees \ No newline at end of file +// constantAttenuation: 1, +// linearAttenuation: 0, +// quadraticAttenuation: 0, +// exponent: 0, +// cutoff: 180, // in degrees \ No newline at end of file diff --git a/examples/lights/testScene.js b/examples/lights/testScene.js index eeb5f4ffd7..4cc0058bea 100644 --- a/examples/lights/testScene.js +++ b/examples/lights/testScene.js @@ -12,7 +12,7 @@ var basePosition, avatarRot; avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); - basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(SPAWN_RANGE * 3, Quat.getFront(avatarRot))); + basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(-3, Quat.getUp(avatarRot))); var ground = Entities.addEntity({ type: "Model", @@ -28,11 +28,14 @@ var light, block; - basePosition.y += 2; + // 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' + name: 'Hifi-Spotlight', type: "Light", isSpotlight: true, dimensions: { @@ -40,33 +43,40 @@ y: 2, z: 20 }, - parentID: box, + parentID: block, color: { red: 255, - green: 255, + green: 0, blue: 255 }, intensity: 2, exponent: 0.3, cutoff: 20, - lifetime: LIFETIME, + lifetime: -1, position: lightTransform.p, - rotation: lightTransform.q, - } + rotation: lightTransform.q + }; + light = Entities.addEntity(lightProperties); var message = { light: { id: light, type: 'spotlight', - initialProperties:lightProperties + 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', @@ -76,16 +86,15 @@ z: 1 }, collisionsWillMove: true, - shapeType: 'Box', color: { red: 0, - green: 0 + green: 0, blue: 255 }, - position: basePosition + position: position } - block = Entities.addEntity(block); + block = Entities.addEntity(blockProperties); } function evalLightWorldTransform(modelPos, modelRot) { @@ -96,9 +105,12 @@ } function cleanup() { + Entities.deleteEntity(block); Entities.deleteEntity(ground); Entities.deleteEntity(light); } + Script.scriptEnding.connect(cleanup); + createBlock(); createLight(); \ No newline at end of file From 8bdced85763a6b8643d8f1b0bf63fa921b4747cd Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 14 Dec 2015 16:51:12 -0800 Subject: [PATCH 08/57] more work --- examples/lights/box.js | 22 +++++++++++++++++----- examples/lights/light_modifier.js | 26 +++++++++++++++----------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/examples/lights/box.js b/examples/lights/box.js index a8e708b344..e43ae22a49 100644 --- a/examples/lights/box.js +++ b/examples/lights/box.js @@ -26,7 +26,8 @@ this.initialProperties = Entities.getEntityProperties(this.entityID); }, getClampedPosition: function() { - dPosition = Vec3.subtract(MyAvatar.position, previousPosition); + + dPosition = Vec3.subtract(MyAvatar.position, this.previousPosition); //convert to localFrame dPosition = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), dPosition); @@ -39,8 +40,19 @@ continueDistantGrab: function() { var currentPosition = this.getClampedPosition(); var distance = Vec3.distance(this.initialProperties.position, currentPosition); - if () - this.sliderValue = scaleValueBasedOnDistanceFromStart(distance); + + if (userData.sliderType === 'color_red' || userData.sliderType === 'color_green' || userData.sliderType === 'color_blue') { + this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, COLOR_MAX); + } + if (userData.sliderType === 'intensity') { + this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, INTENSITY_MAX); + } + if (userData.sliderType === 'cutoff') { + this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, CUTOFF_MAX); + } + if (userData.sliderType === 'exponent') { + this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX); + } Entities.editEntity(this.entityID) { position: currentPosition, @@ -67,8 +79,8 @@ }, sendValueToSlider: function() { var message = { - lightID:userData.lightID, - sliderType:userData.sliderType, + lightID: userData.lightID, + sliderType: userData.sliderType, sliderValue: this.sliderValue } Messages.sendMessage('Hifi-Slider-Value-Reciever', JSON.stringify(message)); diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index f1c27b4e4b..983ea5bcb9 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -1,6 +1,8 @@ // given a selected light, instantiate some entities that represent various values you can dynamically adjust // + + var BOX_SCRIPT_URL = Script.resolvePath('box.js'); var RED = { @@ -54,6 +56,9 @@ function entitySlider(light, color, sliderType, row) { this.sliderType = sliderType; this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); + this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); + this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(this.avatarRot))); + var message = { lightID: this.lightID, sliderType: this.sliderType, @@ -97,8 +102,14 @@ function entitySlider(light, color, sliderType, row) { entitySlider.prototype = { createAxis: function() { //start of line - var position; - //1 meter along orientationAxis + var position = Vec3.sum(this.basePosition, this.verticalOffset); + + //line starts on left and goes to right + //set the end of the line to the right + var rightVector = Quat.getRight(this.avatarRot); + var extension = Vec3.multiply(AXIS_SCALE, rightVector); + var endOfAxis = Vec3.sum(position, extension); + var endOfAxis; var properties = { type: 'Line', @@ -139,8 +150,6 @@ entitySlider.prototype = { this.boxIndicator = Entities.addEntity(properties); }, setValueFromMessage: function(message) { - print('VALUE MESSAGE::'+JSON.stringify(message)) - print('LIGHT ID::'+this.lightID); //message is not for our light if (message.lightID !== this.lightID) { @@ -154,10 +163,9 @@ entitySlider.prototype = { return } - print('SHOULD SET SOME VALUE:::' + message.sliderType); + print('should set:::' + this.sliderType); var lightProperties = Entities.getEntityProperties(this.lightID); - // print('LIGHT PROPERTIES::'+JSON.stringify(lightProperties)); if (this.sliderType === 'color_red') { Entities.editEntity(this.lightID, { @@ -190,7 +198,6 @@ entitySlider.prototype = { } if (this.sliderType === 'intensity') { - print('CHANGING INTENSITY TO::' + message.sliderValue) Entities.editEntity(this.lightID, { intensity: message.sliderValue }); @@ -209,7 +216,6 @@ entitySlider.prototype = { } }, subscribeToBoxMessages: function() { - print('subscribing to box messages'); Messages.subscribe('Hifi-Slider-Value-Reciever'); Messages.messageReceived.connect(handleValueMessages); }, @@ -296,17 +302,15 @@ function handleLightModMessages(channel, message, sender) { } var parsedMessage = JSON.parse(message); - print('MESSAGE LIGHT:::' + message) makeSliders(parsedMessage.light); } function handleValueMessages(channel, message, sender) { - + if (channel !== 'Hifi-Slider-Value-Reciever') { return; } - print('HANDLE VALUE MESSAGE') //easily protect from other people editing your values, but group editing might be fun so lets try that first. // if (sender !== MyAvatar.sessionUUID) { // return; From 112dd4209b3efa8032c8b5918429c3b633d2a85f Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 14 Dec 2015 17:27:01 -0800 Subject: [PATCH 09/57] prep for incoming --- examples/lights/box.js | 2 +- examples/lights/light_modifier.js | 49 ++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/examples/lights/box.js b/examples/lights/box.js index e43ae22a49..806d6be389 100644 --- a/examples/lights/box.js +++ b/examples/lights/box.js @@ -72,7 +72,7 @@ }, scaleValueBasedOnDistanceFromStart: function(value, max2) { var min1 = 0; - var max1 = 1; + var max1 = AXIS_SCALE; var min2 = 0; var max2 = max2; return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index 983ea5bcb9..ac29b65f74 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -93,8 +93,10 @@ function entitySlider(light, color, sliderType, row) { this.setValueFromMessage(message); } - // this.setInitialSliderPositions(); + this.setInitialSliderPositions(); this.subscribeToBoxMessages(); + this.createAxis(); + this.createBoxIndicator(); return this; } @@ -133,11 +135,37 @@ entitySlider.prototype = { this.axis = Entities.addEntity(properties); }, createBoxIndicator: function() { + var position = Vec3.sum(this.basePosition, this.verticalOffset); + + //line starts on left and goes to right + //set the end of the line to the right + var rightVector = Quat.getRight(this.avatarRot); + var initialDistance; + if (this.sliderType === 'color_red') { + initialDistance = this.distanceRed; + } + if (this.sliderType === 'color_green') { + initialDistance = this.distanceGreen; + } + if (this.sliderType === 'color_blue') { + initialDistance = this.distanceBlue; + } + if (this.sliderType === 'intensity') { + initialDistance = this.distanceRed; + } + if (this.sliderType === 'cutoff') { + initialDistance = this.distanceCutoff; + } + if (this.sliderType === 'exponent') { + initialDistance = this.distanceExponent; + } + var extension = Vec3.multiply(initialDistance, rightVector); + var endOfAxis = Vec3.sum(position, extension); var properties = { type: 'Box', dimensions: BOX_DIMENSIONS, color: this.color, - position: position, + position: endOfAxis, script: BOX_SCRIPT_URL, userData: JSON.stringify({ lightModifierKey: { @@ -225,12 +253,12 @@ entitySlider.prototype = { var CUTOFF_MAX = 360; var EXPONENT_MAX = 1; - var distanceRed = (this.initialProperties.color.red / COLOR_MAX) * AXIS_SCALE; - var distanceGreen = (this.initialProperties.color.green / COLOR_MAX) * AXIS_SCALE; - var distanceBlue = (this.initialProperties.color.blue / COLOR_MAX) * AXIS_SCALE; - var distanceIntensity = (this.initialProperties.intensity / INTENSITY_MAX) * AXIS_SCALE; - var distanceCutoff = (this.initialProperties.cutoff / CUTOFF_MAX) * AXIS_SCALE; - var distanceExponent = (this.initialProperties.exponent / EXPONENT_MAX) * AXIS_SCALE; + this.distanceRed = (this.initialProperties.color.red / 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.distanceIntensity = (this.initialProperties.intensity / INTENSITY_MAX) * AXIS_SCALE; + this.distanceCutoff = (this.initialProperties.cutoff / CUTOFF_MAX) * AXIS_SCALE; + this.distanceExponent = (this.initialProperties.exponent / EXPONENT_MAX) * AXIS_SCALE; }, cleanup: function() { Entities.deleteEntity(this.boxIndicator); @@ -307,7 +335,6 @@ function handleLightModMessages(channel, message, sender) { function handleValueMessages(channel, message, sender) { - if (channel !== 'Hifi-Slider-Value-Reciever') { return; } @@ -318,8 +345,6 @@ function handleValueMessages(channel, message, sender) { var parsedMessage = JSON.parse(message); slidersRef[parsedMessage.sliderType].setValueFromMessage(parsedMessage) - - // this.setValueFromMessage(parsedMessage); } function cleanup() { @@ -334,6 +359,8 @@ function cleanup() { Script.scriptEnding.connect(cleanup); subScribeToNewLights(); + +//other light properties // diffuseColor: { red: 255, green: 255, blue: 255 }, // ambientColor: { red: 255, green: 255, blue: 255 }, // specularColor: { red: 255, green: 255, blue: 255 }, From 109aa89619b10fc108c2980a47933d4596a95631 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 14 Dec 2015 18:42:00 -0800 Subject: [PATCH 10/57] end of day --- examples/lights/box.js | 22 +++++++++++----------- examples/lights/light_modifier.js | 3 +++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/lights/box.js b/examples/lights/box.js index 806d6be389..b1f9252073 100644 --- a/examples/lights/box.js +++ b/examples/lights/box.js @@ -13,8 +13,9 @@ Box.prototype = { preload: function(entityID) { this.entityID = entityID; - var userData = Entities.getEntityProperties(this.entityID, "userData"); - this.userData = JSON.parse(userData); + var entityProperties = Entities.getEntityProperties(this.entityID, "userData"); + var parsedUserData = JSON.parse(entityProperties.userData); + var userData = parsedUserData.lightModifierKey; }, startNearGrab: function() { this.setInitialProperties(); @@ -26,10 +27,10 @@ this.initialProperties = Entities.getEntityProperties(this.entityID); }, getClampedPosition: function() { - - dPosition = Vec3.subtract(MyAvatar.position, this.previousPosition); + var dPosition; + // dPosition = Vec3.subtract(MyAvatar.position, this.previousPosition); //convert to localFrame - dPosition = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), dPosition); + // dPosition = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), dPosition); return dPosition; }, @@ -52,12 +53,12 @@ } if (userData.sliderType === 'exponent') { this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX); - } + }; - Entities.editEntity(this.entityID) { + Entities.editEntity(this.entityID, { position: currentPosition, - rotation: this.getClampedRotation() - } + // rotation: this.getClampedRotation() + }); }, releaseGrab: function() { Entities.editEntity(this.entityID, { @@ -84,8 +85,7 @@ sliderValue: this.sliderValue } Messages.sendMessage('Hifi-Slider-Value-Reciever', JSON.stringify(message)); - }; - + } }; return new Box(); diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index ac29b65f74..2e11c5e22e 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -115,6 +115,7 @@ entitySlider.prototype = { var endOfAxis; var properties = { type: 'Line', + name: 'Hifi-Slider-Axis::'+this.sliderType, color: this.color, collisionsWillMove: false, ignoreForCollisions: true, @@ -135,6 +136,7 @@ entitySlider.prototype = { this.axis = Entities.addEntity(properties); }, createBoxIndicator: function() { + print('BOX COLOR IS:::'+JSON.stringify(this.color)); var position = Vec3.sum(this.basePosition, this.verticalOffset); //line starts on left and goes to right @@ -163,6 +165,7 @@ entitySlider.prototype = { var endOfAxis = Vec3.sum(position, extension); var properties = { type: 'Box', + name: 'Hifi-Slider::'+this.sliderType, dimensions: BOX_DIMENSIONS, color: this.color, position: endOfAxis, From d4f55ed6d2da961544888a74b22fb45777cbbf8a Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 15 Dec 2015 15:55:03 -0800 Subject: [PATCH 11/57] working lsiders --- examples/controllers/handControllerGrab.js | 56 ++++++++++++++++- examples/lights/box.js | 73 +++++++++++++--------- examples/lights/light_modifier.js | 61 ++++++++++-------- examples/lights/testScene.js | 1 + 4 files changed, 135 insertions(+), 56 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 07894b46d1..d9e75c8836 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -816,6 +816,19 @@ function MyController(hand) { 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 if (MOVE_WITH_HEAD) { var objDistance = Vec3.length(objectToAvatar); @@ -826,8 +839,21 @@ function MyController(hand) { this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change); } + var clampedVector; + var targetPosition; + if (constraintData.axisBasePosition !== false) { + clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition, constraintData.axisBasePosition, constraintData.endOfAxis); + targetPosition = clampedVector; + } else { + targetPosition = { + x: this.currentObjectPosition.x, + y: this.currentObjectPosition.y, + z: this.currentObjectPosition.z + } + } + Entities.updateAction(this.grabbedEntity, this.actionID, { - targetPosition: this.currentObjectPosition, + targetPosition: targetPosition, linearTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, targetRotation: this.currentObjectRotation, angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, @@ -836,6 +862,34 @@ function MyController(hand) { this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); }; + this.projectVectorAlongAxis = function(position, axisStart, axisEnd) { + + var aPrime = Vec3.subtract(position, axisStart); + + var bPrime = Vec3.subtract(axisEnd, axisStart); + + var bPrimeMagnitude = Vec3.length(bPrime); + + var dotProduct = Vec3.dot(aPrime, bPrime); + + var scalar = dotProduct / bPrimeMagnitude; + + print('SCALAR:::'+scalar); + + if(scalar<0){ + scalar = 0; + } + + if(scalar>1){ + scalar = 1; + } + + var projection = Vec3.sum(axisStart, Vec3.multiply(scalar, Vec3.normalize(bPrime))); + + return projection + + }, + this.nearGrabbing = function() { var now = Date.now(); var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); diff --git a/examples/lights/box.js b/examples/lights/box.js index b1f9252073..3bcebc64d3 100644 --- a/examples/lights/box.js +++ b/examples/lights/box.js @@ -14,51 +14,64 @@ preload: function(entityID) { this.entityID = entityID; var entityProperties = Entities.getEntityProperties(this.entityID, "userData"); + print('USER DATA:::' + entityProperties.userData) var parsedUserData = JSON.parse(entityProperties.userData); - var 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() { this.setInitialProperties(); }, startDistantGrab: function() { + // Entities.editEntity(this.entityID, { + // parentID: MyAvatar.sessionUUID, + // parentJointIndex: MyAvatar.getJointIndex("LeftHand") + // }); this.setInitialProperties(); }, setInitialProperties: function() { this.initialProperties = Entities.getEntityProperties(this.entityID); }, - getClampedPosition: function() { - var dPosition; - // dPosition = Vec3.subtract(MyAvatar.position, this.previousPosition); - //convert to localFrame - // dPosition = Vec3.multiplyQbyV(Quat.inverse(MyAvatar.orientation), dPosition); + clampPosition: function() { + + 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; - return dPosition; - }, - getClampedRotation: function() { - var rotation = initialProperties.rotation; - return rotation; }, continueDistantGrab: function() { - var currentPosition = this.getClampedPosition(); - var distance = Vec3.distance(this.initialProperties.position, currentPosition); + // this.clampPosition(); + print('distant grab') + var currentPosition = Entities.getEntityProperties(this.entityID, "position").position; - if (userData.sliderType === 'color_red' || userData.sliderType === 'color_green' || userData.sliderType === 'color_blue') { - this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, COLOR_MAX); + var distance = Vec3.distance(this.axisBasePosition, this.currentProjection); + + if (this.userData.sliderType === 'color_red' || this.userData.sliderType === 'color_green' || this.userData.sliderType === 'color_blue') { + this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, COLOR_MAX); } - if (userData.sliderType === 'intensity') { - this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, INTENSITY_MAX); + if (this.userData.sliderType === 'intensity') { + this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, INTENSITY_MAX); } - if (userData.sliderType === 'cutoff') { - this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, CUTOFF_MAX); + if (this.userData.sliderType === 'cutoff') { + this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, CUTOFF_MAX); } - if (userData.sliderType === 'exponent') { - this.sliderValue = scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX); + if (this.userData.sliderType === 'exponent') { + this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX); }; - Entities.editEntity(this.entityID, { - position: currentPosition, - // rotation: this.getClampedRotation() - }); + }, releaseGrab: function() { Entities.editEntity(this.entityID, { @@ -66,7 +79,8 @@ x: 0, y: 0, z: 0 - } + }, + parentID: null }) this.sendValueToSlider(); @@ -79,10 +93,11 @@ return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); }, sendValueToSlider: function() { + var _t = this; var message = { - lightID: userData.lightID, - sliderType: userData.sliderType, - sliderValue: this.sliderValue + lightID: _t.userData.lightID, + sliderType: _t.userData.sliderType, + sliderValue: _t.sliderValue } Messages.sendMessage('Hifi-Slider-Value-Reciever', JSON.stringify(message)); } diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index 2e11c5e22e..f54af5b54f 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -3,36 +3,36 @@ -var BOX_SCRIPT_URL = Script.resolvePath('box.js'); +var BOX_SCRIPT_URL = Script.resolvePath('box.js?'+Math.random(0,100)); var RED = { - r: 255, - g: 0, - b: 0 + red: 255, + green: 0, + blue: 0 }; var GREEN = { - r: 0, - g: 255, - b: 0 + red: 0, + green: 255, + blue: 0 }; var BLUE = { - r: 0, - g: 0, - b: 255 + red: 0, + green: 0, + blue: 255 }; var PURPLE = { - r: 255, - g: 0, - b: 255 + red: 255, + green: 0, + blue: 255 }; var WHITE = { - r: 255, - g: 255, - b: 255 + red: 255, + green: 255, + blue: 255 }; var AXIS_SCALE = 1; @@ -44,7 +44,7 @@ var BOX_DIMENSIONS = { }; var PER_ROW_OFFSET = { x: 0, - y: 0.2, + y: -0.2, z: 0 }; @@ -55,6 +55,7 @@ function entitySlider(light, color, sliderType, row) { this.color = color; this.sliderType = sliderType; 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.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(this.avatarRot))); @@ -111,11 +112,11 @@ entitySlider.prototype = { var rightVector = Quat.getRight(this.avatarRot); var extension = Vec3.multiply(AXIS_SCALE, rightVector); var endOfAxis = Vec3.sum(position, extension); - - var endOfAxis; + this.endOfAxis = endOfAxis; + print('endOfAxis:::' + JSON.stringify(endOfAxis)) var properties = { type: 'Line', - name: 'Hifi-Slider-Axis::'+this.sliderType, + name: 'Hifi-Slider-Axis::' + this.sliderType, color: this.color, collisionsWillMove: false, ignoreForCollisions: true, @@ -129,14 +130,14 @@ entitySlider.prototype = { x: 0, y: 0, z: 0 - }, endOfAxis], + }, extension], lineWidth: 5, }; this.axis = Entities.addEntity(properties); }, createBoxIndicator: function() { - print('BOX COLOR IS:::'+JSON.stringify(this.color)); + print('BOX COLOR IS:::' + JSON.stringify(this.color)); var position = Vec3.sum(this.basePosition, this.verticalOffset); //line starts on left and goes to right @@ -162,18 +163,26 @@ entitySlider.prototype = { initialDistance = this.distanceExponent; } var extension = Vec3.multiply(initialDistance, rightVector); - var endOfAxis = Vec3.sum(position, extension); + var sliderPosition = Vec3.sum(position, extension); var properties = { type: 'Box', - name: 'Hifi-Slider::'+this.sliderType, + name: 'Hifi-Slider::' + this.sliderType, dimensions: BOX_DIMENSIONS, + collisionsWillMove: true, color: this.color, - position: endOfAxis, + position: sliderPosition, script: BOX_SCRIPT_URL, userData: JSON.stringify({ lightModifierKey: { lightID: this.lightID, - sliderType: this.sliderType + sliderType: this.sliderType, + axisBasePosition: position, + endOfAxis: this.endOfAxis, + }, + constraintKey: { + constrain: { + y: position.y + } } }) }; diff --git a/examples/lights/testScene.js b/examples/lights/testScene.js index 4cc0058bea..0e0a226c0b 100644 --- a/examples/lights/testScene.js +++ b/examples/lights/testScene.js @@ -15,6 +15,7 @@ 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: { From 9a2d9997e90c99edd49ce1b7452511c80e1bccb5 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 15 Dec 2015 18:20:12 -0800 Subject: [PATCH 12/57] prep for feedback --- examples/controllers/handControllerGrab.js | 234 ++++++++++--------- examples/lights/light_loader.js | 8 + examples/lights/light_modifier.js | 113 ++++----- examples/lights/light_modifier_test_scene.js | 128 ++++++++++ examples/lights/{box.js => slider.js} | 49 ++-- examples/lights/testScene.js | 117 ---------- 6 files changed, 331 insertions(+), 318 deletions(-) create mode 100644 examples/lights/light_loader.js create mode 100644 examples/lights/light_modifier_test_scene.js rename examples/lights/{box.js => slider.js} (67%) delete mode 100644 examples/lights/testScene.js diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index d9e75c8836..c452519522 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -218,6 +218,7 @@ function getSpatialOffsetPosition(hand, spatialKey) { } var yFlip = Quat.angleAxis(180, Vec3.UNIT_Y); + function getSpatialOffsetRotation(hand, spatialKey) { var rotation = Quat.IDENTITY; @@ -261,9 +262,9 @@ function MyController(hand) { this.triggerValue = 0; // rolling average of trigger value this.rawTriggerValue = 0; this.rawBumperValue = 0; - + this.overlayLine = null; - + this.ignoreIK = false; this.offsetPosition = Vec3.ZERO; this.offsetRotation = Quat.IDENTITY; @@ -816,33 +817,36 @@ function MyController(hand) { 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 if (MOVE_WITH_HEAD) { var objDistance = Vec3.length(objectToAvatar); - var before = Vec3.multiplyQbyV(this.currentCameraOrientation, { x: 0.0, y: 0.0, z: objDistance }); - var after = Vec3.multiplyQbyV(Camera.orientation, { x: 0.0, y: 0.0, z: objDistance }); + var before = Vec3.multiplyQbyV(this.currentCameraOrientation, { + 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); this.currentCameraOrientation = Camera.orientation; this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change); } + var defaultConstraintData = { + axisStart: false, + axisEnd: false, + } + + var constraintData = getEntityCustomData('lightModifierKey', this.grabbedEntity, defaultConstraintData); var clampedVector; var targetPosition; - if (constraintData.axisBasePosition !== false) { - clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition, constraintData.axisBasePosition, constraintData.endOfAxis); + if (constraintData.startAxis !== false) { + clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition, constraintData.axisStart, constraintData.axisEnd); targetPosition = clampedVector; } else { targetPosition = { @@ -859,121 +863,121 @@ function MyController(hand) { angularTimeScale: DISTANCE_HOLDING_ACTION_TIMEFRAME, ttl: ACTION_TTL }); + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); + }; 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){ - scalar = 0; - } + if (scalar > 1) { + scalar = 1; + } - if(scalar>1){ - scalar = 1; - } + var projection = Vec3.sum(axisStart, Vec3.multiply(scalar, Vec3.normalize(bPrime))); - 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() { - var now = Date.now(); - var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, this.grabbedEntity, DEFAULT_GRABBABLE_DATA); + if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { + this.setState(STATE_RELEASE); + Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); + return; + } - if (this.state == STATE_NEAR_GRABBING && this.triggerSmoothedReleased()) { - this.setState(STATE_RELEASE); - Entities.callEntityMethod(this.grabbedEntity, "releaseGrab"); - return; - } + this.lineOff(); + this.overlayLineOff(); - this.lineOff(); - this.overlayLineOff(); + var grabbedProperties = Entities.getEntityProperties(this.grabbedEntity, GRABBABLE_PROPERTIES); + 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); - this.activateEntity(this.grabbedEntity, grabbedProperties); - if (grabbedProperties.collisionsWillMove && NEAR_GRABBING_KINEMATIC) { - Entities.editEntity(this.grabbedEntity, { - collisionsWillMove: false + 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 }); - } - - 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); + if (this.actionID === NULL_ACTION_ID) { + this.actionID = null; } else { - // equipping - Entities.callEntityMethod(this.grabbedEntity, "startEquip", [JSON.stringify(this.hand)]); - this.startHandGrasp(); + this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); + if (this.state == STATE_NEAR_GRABBING) { + 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) { - Entities.callEntityMethod(this.grabbedEntity, "setRightHand"); - } else { - Entities.callEntityMethod(this.grabbedEntity, "setLeftHand"); - } + this.currentHandControllerTipPosition = + (this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition; - Entities.callEntityMethod(this.grabbedEntity, "setHand", [this.hand]); - - Entities.callEntityMethod(this.grabbedEntity, "startNearGrab"); - - } - - this.currentHandControllerTipPosition = - (this.hand === RIGHT_HAND) ? MyAvatar.rightHandTipPosition : MyAvatar.leftHandTipPosition; - - this.currentObjectTime = Date.now(); - }; + this.currentObjectTime = Date.now(); + }; this.continueNearGrabbing = function() { if (this.state == STATE_CONTINUE_NEAR_GRABBING && this.triggerSmoothedReleased()) { @@ -1358,10 +1362,10 @@ Controller.enableMapping(MAPPING_NAME); var handToDisable = 'none'; function update() { - if (handToDisable !== LEFT_HAND && handToDisable!=='both') { + if (handToDisable !== LEFT_HAND && handToDisable !== 'both') { leftController.update(); } - if (handToDisable !== RIGHT_HAND && handToDisable!=='both') { + if (handToDisable !== RIGHT_HAND && handToDisable !== 'both') { rightController.update(); } } @@ -1369,7 +1373,7 @@ function update() { Messages.subscribe('Hifi-Hand-Disabler'); handleHandDisablerMessages = function(channel, message, sender) { - + if (sender === MyAvatar.sessionUUID) { if (message === 'left') { handToDisable = LEFT_HAND; @@ -1377,11 +1381,11 @@ handleHandDisablerMessages = function(channel, message, sender) { if (message === 'right') { handToDisable = RIGHT_HAND; } - if(message==='both'){ - handToDisable='both'; + if (message === 'both') { + handToDisable = 'both'; } - if(message==='none'){ - handToDisable='none'; + if (message === 'none') { + handToDisable = 'none'; } } @@ -1396,4 +1400,4 @@ function cleanup() { } Script.scriptEnding.connect(cleanup); -Script.update.connect(update); +Script.update.connect(update); \ No newline at end of file diff --git a/examples/lights/light_loader.js b/examples/lights/light_loader.js new file mode 100644 index 0000000000..8edaa20f57 --- /dev/null +++ b/examples/lights/light_loader.js @@ -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) \ No newline at end of file diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index f54af5b54f..cbb4e3ff10 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -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 BOX_SCRIPT_URL = Script.resolvePath('box.js?'+Math.random(0,100)); +var SLIDER_SCRIPT_URL = Script.resolvePath('slider.js?' + Math.random(0, 100)); var RED = { red: 255, @@ -35,13 +48,12 @@ var WHITE = { blue: 255 }; -var AXIS_SCALE = 1; - -var BOX_DIMENSIONS = { - x: 0.05, - y: 0.05, - z: 0.05 +var SLIDER_DIMENSIONS = { + x: 0.075, + y: 0.075, + z: 0.075 }; + var PER_ROW_OFFSET = { x: 0, y: -0.2, @@ -55,10 +67,8 @@ function entitySlider(light, color, sliderType, row) { this.color = color; this.sliderType = sliderType; 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.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 = { lightID: this.lightID, @@ -95,9 +105,8 @@ function entitySlider(light, color, sliderType, row) { } this.setInitialSliderPositions(); - this.subscribeToBoxMessages(); this.createAxis(); - this.createBoxIndicator(); + this.createSliderIndicator(); return this; } @@ -113,7 +122,6 @@ entitySlider.prototype = { var extension = Vec3.multiply(AXIS_SCALE, rightVector); var endOfAxis = Vec3.sum(position, extension); this.endOfAxis = endOfAxis; - print('endOfAxis:::' + JSON.stringify(endOfAxis)) var properties = { type: 'Line', name: 'Hifi-Slider-Axis::' + this.sliderType, @@ -136,10 +144,8 @@ entitySlider.prototype = { this.axis = Entities.addEntity(properties); }, - createBoxIndicator: function() { - print('BOX COLOR IS:::' + JSON.stringify(this.color)); + createSliderIndicator: function() { var position = Vec3.sum(this.basePosition, this.verticalOffset); - //line starts on left and goes to right //set the end of the line to the right var rightVector = Quat.getRight(this.avatarRot); @@ -154,7 +160,7 @@ entitySlider.prototype = { initialDistance = this.distanceBlue; } if (this.sliderType === 'intensity') { - initialDistance = this.distanceRed; + initialDistance = this.distanceIntensity; } if (this.sliderType === 'cutoff') { initialDistance = this.distanceCutoff; @@ -165,30 +171,26 @@ entitySlider.prototype = { var extension = Vec3.multiply(initialDistance, rightVector); var sliderPosition = Vec3.sum(position, extension); var properties = { - type: 'Box', + type: 'Sphere', name: 'Hifi-Slider::' + this.sliderType, - dimensions: BOX_DIMENSIONS, + dimensions: SLIDER_DIMENSIONS, collisionsWillMove: true, color: this.color, position: sliderPosition, - script: BOX_SCRIPT_URL, + script: SLIDER_SCRIPT_URL, userData: JSON.stringify({ lightModifierKey: { lightID: this.lightID, sliderType: this.sliderType, - axisBasePosition: position, - endOfAxis: this.endOfAxis, - }, - constraintKey: { - constrain: { - y: position.y - } + axisStart: position, + axisEnd: this.endOfAxis, } }) }; - this.boxIndicator = Entities.addEntity(properties); + this.sliderIndicator = Entities.addEntity(properties); }, + setValueFromMessage: function(message) { //message is not for our light @@ -203,8 +205,6 @@ entitySlider.prototype = { return } - print('should set:::' + this.sliderType); - var lightProperties = Entities.getEntityProperties(this.lightID); 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() { - 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.distanceGreen = (this.initialProperties.color.green / COLOR_MAX) * AXIS_SCALE; this.distanceBlue = (this.initialProperties.color.blue / COLOR_MAX) * AXIS_SCALE; this.distanceIntensity = (this.initialProperties.intensity / INTENSITY_MAX) * AXIS_SCALE; this.distanceCutoff = (this.initialProperties.cutoff / CUTOFF_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 = []; @@ -288,9 +275,9 @@ var slidersRef = { cutoff: null, exponent: null } +var light = null; function makeSliders(light) { - print('light in makesliders:::' + light) if (light.type === 'spotlight') { var USE_COLOR_SLIDER = true; var USE_INTENSITY_SLIDER = true; @@ -325,14 +312,19 @@ function makeSliders(light) { slidersRef.exponent = new entitySlider(light, PURPLE, 'exponent', 6); sliders.push(slidersRef.exponent); } + subscribeToSliderMessages(); }; function subScribeToNewLights() { - print('subscribing to light messages') Messages.subscribe('Hifi-Light-Mod-Receiver'); Messages.messageReceived.connect(handleLightModMessages); } +function subscribeToSliderMessages() { + Messages.subscribe('Hifi-Slider-Value-Reciever'); + Messages.messageReceived.connect(handleValueMessages); +} + function handleLightModMessages(channel, message, sender) { if (channel !== 'Hifi-Light-Mod-Receiver') { return; @@ -343,6 +335,7 @@ function handleLightModMessages(channel, message, sender) { var parsedMessage = JSON.parse(message); makeSliders(parsedMessage.light); + light = parsedMessage.light.id } function handleValueMessages(channel, message, sender) { @@ -356,27 +349,39 @@ function handleValueMessages(channel, message, sender) { // } var parsedMessage = JSON.parse(message); - slidersRef[parsedMessage.sliderType].setValueFromMessage(parsedMessage) + slidersRef[parsedMessage.sliderType].setValueFromMessage(parsedMessage); } function cleanup() { - while (sliders.length > 0) { - var slider = sliders.pop(); - slider.cleanup(); + var i; + for (i = 0; i < sliders.length; i++) { + Entities.deleteEntity(sliders[i].axis); + Entities.deleteEntity(sliders[i].sliderIndicator); } + Messages.messageReceived.disconnect(handleLightModMessages); - delete sliders + Messages.messageReceived.disconnect(handleValueMessages); + Entities.deletingEntity.disconnect(deleteEntity); + } Script.scriptEnding.connect(cleanup); subScribeToNewLights(); +function deleteEntity(entityID) { + if (entityID === light) { + // cleanup(); + } +} + + +Entities.deletingEntity.connect(deleteEntity); + //other light properties // diffuseColor: { red: 255, green: 255, blue: 255 }, // ambientColor: { red: 255, green: 255, blue: 255 }, // specularColor: { red: 255, green: 255, blue: 255 }, - // constantAttenuation: 1, // linearAttenuation: 0, // quadraticAttenuation: 0, diff --git a/examples/lights/light_modifier_test_scene.js b/examples/lights/light_modifier_test_scene.js new file mode 100644 index 0000000000..d997816957 --- /dev/null +++ b/examples/lights/light_modifier_test_scene.js @@ -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(); \ No newline at end of file diff --git a/examples/lights/box.js b/examples/lights/slider.js similarity index 67% rename from examples/lights/box.js rename to examples/lights/slider.js index 3bcebc64d3..ab90019b9f 100644 --- a/examples/lights/box.js +++ b/examples/lights/slider.js @@ -2,61 +2,40 @@ var AXIS_SCALE = 1; var COLOR_MAX = 255; - var INTENSITY_MAX = 10; + var INTENSITY_MAX = 0.05; var CUTOFF_MAX = 360; var EXPONENT_MAX = 1; - function Box() { + function Slider() { return this; } - Box.prototype = { + Slider.prototype = { preload: function(entityID) { this.entityID = entityID; var entityProperties = Entities.getEntityProperties(this.entityID, "userData"); - print('USER DATA:::' + entityProperties.userData) var parsedUserData = JSON.parse(entityProperties.userData); this.userData = parsedUserData.lightModifierKey; - this.bPrime = Vec3.subtract(this.userData.endOfAxis, this.userData.axisBasePosition); - this.bPrimeMagnitude = Vec3.length(this.bPrime); - }, startNearGrab: function() { this.setInitialProperties(); }, startDistantGrab: function() { - // Entities.editEntity(this.entityID, { - // parentID: MyAvatar.sessionUUID, - // parentJointIndex: MyAvatar.getJointIndex("LeftHand") - // }); this.setInitialProperties(); }, setInitialProperties: function() { this.initialProperties = Entities.getEntityProperties(this.entityID); }, - clampPosition: function() { - - 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; - + continueNearGrab: function() { + // this.continueDistantGrab(); }, continueDistantGrab: function() { - // this.clampPosition(); - print('distant grab') + this.setSliderValueBasedOnDistance(); + }, + setSliderValueBasedOnDistance: function() { 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') { this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, COLOR_MAX); @@ -71,6 +50,8 @@ this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX); }; + print('SLIDER VALUE:::' + this.sliderValue) + this.sendValueToSlider(); }, releaseGrab: function() { @@ -80,7 +61,11 @@ y: 0, z: 0 }, - parentID: null + angularVelocity: { + x: 0, + y: 0, + z: 0 + } }) this.sendValueToSlider(); @@ -103,5 +88,5 @@ } }; - return new Box(); + return new Slider(); }); \ No newline at end of file diff --git a/examples/lights/testScene.js b/examples/lights/testScene.js deleted file mode 100644 index 0e0a226c0b..0000000000 --- a/examples/lights/testScene.js +++ /dev/null @@ -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(); \ No newline at end of file From adf6cf8aa3f3d41ad79013ae8d2ee724de3b738c Mon Sep 17 00:00:00 2001 From: James Pollack Date: Wed, 16 Dec 2015 00:58:00 -0800 Subject: [PATCH 13/57] vary colors --- examples/lights/light_modifier.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index cbb4e3ff10..ed11b9c618 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -48,6 +48,12 @@ var WHITE = { blue: 255 }; +var ORANGE={ + red:255, + green:0, + blue:128 +} + var SLIDER_DIMENSIONS = { x: 0.075, y: 0.075, @@ -309,7 +315,7 @@ function makeSliders(light) { sliders.push(slidersRef.cutoff); } if (USE_EXPONENT_SLIDER === true) { - slidersRef.exponent = new entitySlider(light, PURPLE, 'exponent', 6); + slidersRef.exponent = new entitySlider(light, ORANGE, 'exponent', 6); sliders.push(slidersRef.exponent); } subscribeToSliderMessages(); From 5a9549a2d951442bdc0b3fbf269f7984d126599b Mon Sep 17 00:00:00 2001 From: James Pollack Date: Wed, 16 Dec 2015 01:21:22 -0800 Subject: [PATCH 14/57] headers --- examples/lights/light_modifier.js | 2 +- examples/lights/light_modifier_test_scene.js | 2 +- examples/lights/slider.js | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/lights/light_modifier.js b/examples/lights/light_modifier.js index ed11b9c618..132934f5d2 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/light_modifier.js @@ -1,7 +1,7 @@ // // light_modifier.js // -// Created byJames Pollack @imgntn on 10/19/2015 +// Created byJames Pollack @imgntn on 12/15/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. diff --git a/examples/lights/light_modifier_test_scene.js b/examples/lights/light_modifier_test_scene.js index d997816957..e70812cb45 100644 --- a/examples/lights/light_modifier_test_scene.js +++ b/examples/lights/light_modifier_test_scene.js @@ -1,7 +1,7 @@ // // light_modifier_test_scene.js // -// Created byJames Pollack @imgntn on 10/19/2015 +// Created byJames Pollack @imgntn on 12/15/2015 // Copyright 2015 High Fidelity, Inc. // // Given a selected light, instantiate some entities that represent various values you can dynamically adjust. diff --git a/examples/lights/slider.js b/examples/lights/slider.js index ab90019b9f..ab59b6eed1 100644 --- a/examples/lights/slider.js +++ b/examples/lights/slider.js @@ -1,3 +1,13 @@ +// +// slider.js +// +// Created byJames Pollack @imgntn on 12/15/2015 +// Copyright 2015 High Fidelity, Inc. +// +// Entity script that sends a scaled value to a light based on its distance from the start of its constraint axis. +// +// 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 AXIS_SCALE = 1; From 28a5dba2d32a0a2a96ff161fff58a4647a07f07e Mon Sep 17 00:00:00 2001 From: James Pollack Date: Wed, 16 Dec 2015 01:31:24 -0800 Subject: [PATCH 15/57] rename files --- examples/lights/lightLoader.js | 20 +++++++++++++++++++ .../{light_modifier.js => lightModifier.js} | 8 ++++---- ...est_scene.js => lightModifierTestScene.js} | 5 ++--- examples/lights/light_loader.js | 8 -------- examples/lights/slider.js | 5 +++-- 5 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 examples/lights/lightLoader.js rename examples/lights/{light_modifier.js => lightModifier.js} (98%) rename examples/lights/{light_modifier_test_scene.js => lightModifierTestScene.js} (95%) delete mode 100644 examples/lights/light_loader.js diff --git a/examples/lights/lightLoader.js b/examples/lights/lightLoader.js new file mode 100644 index 0000000000..e4022e7bc1 --- /dev/null +++ b/examples/lights/lightLoader.js @@ -0,0 +1,20 @@ +// +// lightLoader.js +// +// Created by James Pollack @imgntn on 12/15/2015 +// Copyright 2015 High Fidelity, Inc. +// +// Loads a test scene showing sliders that you can grab and move to change entity properties. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var grabScript = Script.resolvePath('../controllers/handControllerGrab.js'); +Script.load(grabScript); +var lightModifier = Script.resolvePath('lightModifier.js'); +Script.load(lightModifier); +Script.setTimeout(function() { + var lightModifierTestScene = Script.resolvePath('lightModifierTestScene.js'); + Script.load(lightModifierTestScene); +}, 750) \ No newline at end of file diff --git a/examples/lights/light_modifier.js b/examples/lights/lightModifier.js similarity index 98% rename from examples/lights/light_modifier.js rename to examples/lights/lightModifier.js index 132934f5d2..ffd1469a4a 100644 --- a/examples/lights/light_modifier.js +++ b/examples/lights/lightModifier.js @@ -1,7 +1,7 @@ // -// light_modifier.js +// lightModifier.js // -// Created byJames Pollack @imgntn on 12/15/2015 +// Created by James Pollack @imgntn on 12/15/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. @@ -201,13 +201,13 @@ entitySlider.prototype = { //message is not for our light if (message.lightID !== this.lightID) { - print('not our light') + // print('not our light') return; } //message is not our type if (message.sliderType !== this.sliderType) { - print('not our slider type') + // print('not our slider type') return } diff --git a/examples/lights/light_modifier_test_scene.js b/examples/lights/lightModifierTestScene.js similarity index 95% rename from examples/lights/light_modifier_test_scene.js rename to examples/lights/lightModifierTestScene.js index e70812cb45..214d900130 100644 --- a/examples/lights/light_modifier_test_scene.js +++ b/examples/lights/lightModifierTestScene.js @@ -1,7 +1,7 @@ // -// light_modifier_test_scene.js +// lightModifierTestScene.js // -// Created byJames Pollack @imgntn on 12/15/2015 +// Created by James Pollack @imgntn on 12/15/2015 // Copyright 2015 High Fidelity, Inc. // // Given a selected light, instantiate some entities that represent various values you can dynamically adjust. @@ -116,7 +116,6 @@ function evalLightWorldTransform(modelPos, modelRot) { } function cleanup() { - print('CLEANUP TEST SCENE SCRIPT') Entities.deleteEntity(block); Entities.deleteEntity(ground); Entities.deleteEntity(light); diff --git a/examples/lights/light_loader.js b/examples/lights/light_loader.js deleted file mode 100644 index 8edaa20f57..0000000000 --- a/examples/lights/light_loader.js +++ /dev/null @@ -1,8 +0,0 @@ -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) \ No newline at end of file diff --git a/examples/lights/slider.js b/examples/lights/slider.js index ab59b6eed1..c17704b0db 100644 --- a/examples/lights/slider.js +++ b/examples/lights/slider.js @@ -1,13 +1,14 @@ // // slider.js // -// Created byJames Pollack @imgntn on 12/15/2015 +// Created by James Pollack @imgntn on 12/15/2015 // Copyright 2015 High Fidelity, Inc. // // Entity script that sends a scaled value to a light based on its distance from the start of its constraint axis. // // 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 AXIS_SCALE = 1; @@ -60,7 +61,7 @@ this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX); }; - print('SLIDER VALUE:::' + this.sliderValue) + //print('SLIDER VALUE:::' + this.sliderValue) this.sendValueToSlider(); }, From b0bcbb03f2bee5fa5c299c9f20774fd0d7ddea04 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 16 Dec 2015 11:57:54 -0800 Subject: [PATCH 16/57] remove floor and move sliders up a bit --- examples/lights/lightModifier.js | 84 +++++++++++++++++++++-- examples/lights/lightModifierTestScene.js | 46 ++++--------- examples/lights/slider.js | 3 +- 3 files changed, 92 insertions(+), 41 deletions(-) diff --git a/examples/lights/lightModifier.js b/examples/lights/lightModifier.js index ffd1469a4a..0a584b127c 100644 --- a/examples/lights/lightModifier.js +++ b/examples/lights/lightModifier.js @@ -10,6 +10,19 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // + +// Script.include('../libraries/lightOverlayManager.js'); +// var lightOverlayManager = new LightOverlayManager(); +// lightOverlayManager.setVisible(true); + + // var pickRay = Camera.computePickRay(event.x, event.y); + // var lightResult = lightOverlayManager.findRayIntersection(pickRay) + + +var DEFAULT_PARENT_ID = '{00000000-0000-0000-0000-000000000000}' +var SHOULD_STAY_WITH_AVATAR = false; +var VERTICAL_SLIDERS = false; + var AXIS_SCALE = 1; var COLOR_MAX = 255; var INTENSITY_MAX = 0.05; @@ -48,10 +61,10 @@ var WHITE = { blue: 255 }; -var ORANGE={ - red:255, - green:0, - blue:128 +var ORANGE = { + red: 255, + green: 0, + blue: 128 } var SLIDER_DIMENSIONS = { @@ -75,6 +88,7 @@ function entitySlider(light, color, sliderType, row) { this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(this.avatarRot))); + this.basePosition.y +=1; var message = { lightID: this.lightID, @@ -190,6 +204,10 @@ entitySlider.prototype = { sliderType: this.sliderType, axisStart: position, axisEnd: this.endOfAxis, + }, + releaseVelocityKey: { + disableReleaseVelocity: true, + customReleaseVelocity: false } }) }; @@ -201,13 +219,13 @@ entitySlider.prototype = { //message is not for our light if (message.lightID !== this.lightID) { - // print('not our light') + // print('not our light') return; } //message is not our type if (message.sliderType !== this.sliderType) { - // print('not our slider type') + // print('not our slider type') return } @@ -381,8 +399,62 @@ function deleteEntity(entityID) { } + Entities.deletingEntity.connect(deleteEntity); +// search for lights to make grabbable + +// var USE_DEBOUNCE = true; +// var sinceLastUpdate = 0; + +// function searchForLightsToVisualize() { + +// var deltaTime = interval(); + +// if (USE_DEBOUNCE === true) { +// sinceLastUpdate = sinceLastUpdate + deltaTime; + +// if (sinceLastUpdate > 60) { +// sinceLastUpdate = 0; +// } else { +// return; +// } +// } + +// print('SEARCHING FOR LIGHTS'); + +// var entitites = Entities.findEntities(MyAvatar.position, 50); +// for (i = 0; i < entities.length; i++) { +// var entityProperties = Entities.getEntityProperties(entities[i], ['type', 'parentID']) +// var parentID = entityProperties.parentID; +// var type = entityProperties.type; + +// if (type !== 'Light') { +// return; +// } + +// if (type === "Light" && parentID !== DEFAULT_PARENT_ID && parentID !== null) { +// var light = entities[i]; +// //do something with the light. +// } + +// } + +// } + +// function interval() { +// var lastTime = new Date().getTime(); + +// return function getInterval() { +// var newTime = new Date().getTime(); +// var delta = newTime - lastTime; +// lastTime = newTime; +// return delta; +// }; +// } + + + //other light properties // diffuseColor: { red: 255, green: 255, blue: 255 }, diff --git a/examples/lights/lightModifierTestScene.js b/examples/lights/lightModifierTestScene.js index 214d900130..5748f0d4ed 100644 --- a/examples/lights/lightModifierTestScene.js +++ b/examples/lights/lightModifierTestScene.js @@ -9,39 +9,10 @@ // 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' -}); +basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(0, Quat.getUp(avatarRot))); var light, block; @@ -87,7 +58,7 @@ function createLight() { function createBlock() { var position = basePosition; - position.y += 5; + position.y += 3; var blockProperties = { name: 'Hifi-Spotlight-Block', type: 'Box', @@ -103,12 +74,22 @@ function createBlock() { blue: 255 }, position: position - } + }; block = Entities.addEntity(blockProperties); } function evalLightWorldTransform(modelPos, modelRot) { + var MODEL_LIGHT_POSITION = { + x: 0, + y: -0.3, + z: 0 + }; + var MODEL_LIGHT_ROTATION = Quat.angleAxis(-90, { + x: 1, + y: 0, + z: 0 + }); return { p: Vec3.sum(modelPos, Vec3.multiplyQbyV(modelRot, MODEL_LIGHT_POSITION)), q: Quat.multiply(modelRot, MODEL_LIGHT_ROTATION) @@ -117,7 +98,6 @@ function evalLightWorldTransform(modelPos, modelRot) { function cleanup() { Entities.deleteEntity(block); - Entities.deleteEntity(ground); Entities.deleteEntity(light); } diff --git a/examples/lights/slider.js b/examples/lights/slider.js index c17704b0db..dc02e0bdba 100644 --- a/examples/lights/slider.js +++ b/examples/lights/slider.js @@ -9,6 +9,7 @@ // 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 AXIS_SCALE = 1; @@ -61,9 +62,7 @@ this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX); }; - //print('SLIDER VALUE:::' + this.sliderValue) this.sendValueToSlider(); - }, releaseGrab: function() { Entities.editEntity(this.entityID, { From 6cd86e8a6bf2371079416dfa3b5c387eddc05696 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 16 Dec 2015 12:23:10 -0800 Subject: [PATCH 17/57] midday --- examples/lights/lightModifier.js | 68 +++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/examples/lights/lightModifier.js b/examples/lights/lightModifier.js index 0a584b127c..e928679f08 100644 --- a/examples/lights/lightModifier.js +++ b/examples/lights/lightModifier.js @@ -11,17 +11,20 @@ // +//some experimental options +var ONLY_I_CAN_EDIT = false; +var SLIDERS_SHOULD_STAY_WITH_AVATAR = false; +var VERTICAL_SLIDERS = false; + // Script.include('../libraries/lightOverlayManager.js'); // var lightOverlayManager = new LightOverlayManager(); // lightOverlayManager.setVisible(true); - // var pickRay = Camera.computePickRay(event.x, event.y); - // var lightResult = lightOverlayManager.findRayIntersection(pickRay) - +// var pickRay = Camera.computePickRay(event.x, event.y); +// var lightResult = lightOverlayManager.findRayIntersection(pickRay) var DEFAULT_PARENT_ID = '{00000000-0000-0000-0000-000000000000}' -var SHOULD_STAY_WITH_AVATAR = false; -var VERTICAL_SLIDERS = false; + var AXIS_SCALE = 1; var COLOR_MAX = 255; @@ -88,7 +91,7 @@ function entitySlider(light, color, sliderType, row) { this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(this.avatarRot))); - this.basePosition.y +=1; + this.basePosition.y += 1; var message = { lightID: this.lightID, @@ -134,14 +137,23 @@ function entitySlider(light, color, sliderType, row) { entitySlider.prototype = { createAxis: function() { //start of line - var position = Vec3.sum(this.basePosition, this.verticalOffset); + var position; + var extension; - //line starts on left and goes to right - //set the end of the line to the right - var rightVector = Quat.getRight(this.avatarRot); - var extension = Vec3.multiply(AXIS_SCALE, rightVector); - var endOfAxis = Vec3.sum(position, extension); - this.endOfAxis = endOfAxis; + if (VERTICAL_SLIDERS == true) { + position = Vec3.sum(this.basePosition, Vec3.multiply(row, (Vec3.multiply(0.2, Quat.getRight(this.avatarRot))))); + //line starts on bottom and goes up + var upVector = Quat.getUp(this.avatarRot); + extension = Vec3.multiply(AXIS_SCALE, upVector); + } else { + position = Vec3.sum(this.basePosition, this.verticalOffset); + //line starts on left and goes to right + //set the end of the line to the right + var rightVector = Quat.getRight(this.avatarRot); + extension = Vec3.multiply(AXIS_SCALE, rightVector); + } + + this.endOfAxis = Vec3.sum(position, extension); var properties = { type: 'Line', name: 'Hifi-Slider-Axis::' + this.sliderType, @@ -165,10 +177,18 @@ entitySlider.prototype = { this.axis = Entities.addEntity(properties); }, createSliderIndicator: function() { - var position = Vec3.sum(this.basePosition, this.verticalOffset); - //line starts on left and goes to right - //set the end of the line to the right - var rightVector = Quat.getRight(this.avatarRot); + var extensionVector; + var position; + if (VERTICAL_SLIDERS == true) { + position = Vec3.sum(this.basePosition, Vec3.multiply(row, (Vec3.multiply(0.2, Quat.getRight(this.avatarRot))))); + extensionVector = Quat.getUp(this.avatarRot); + + } else { + position = Vec3.sum(this.basePosition, this.verticalOffset); + extensionVector = Quat.getRight(this.avatarRot); + + } + var initialDistance; if (this.sliderType === 'color_red') { initialDistance = this.distanceRed; @@ -188,11 +208,13 @@ entitySlider.prototype = { if (this.sliderType === 'exponent') { initialDistance = this.distanceExponent; } - var extension = Vec3.multiply(initialDistance, rightVector); + + var extension = Vec3.multiply(initialDistance, extensionVector); var sliderPosition = Vec3.sum(position, extension); + var properties = { type: 'Sphere', - name: 'Hifi-Slider::' + this.sliderType, + name: 'Hifi-Slider-' + this.sliderType, dimensions: SLIDER_DIMENSIONS, collisionsWillMove: true, color: this.color, @@ -367,10 +389,9 @@ function handleValueMessages(channel, message, sender) { if (channel !== 'Hifi-Slider-Value-Reciever') { return; } - //easily protect from other people editing your values, but group editing might be fun so lets try that first. - // if (sender !== MyAvatar.sessionUUID) { - // return; - // } + if (ONLY_I_CAN_EDIT === true && sender !== MyAvatar.sessionUUID) { + return; + } var parsedMessage = JSON.parse(message); slidersRef[parsedMessage.sliderType].setValueFromMessage(parsedMessage); @@ -455,7 +476,6 @@ Entities.deletingEntity.connect(deleteEntity); - //other light properties // diffuseColor: { red: 255, green: 255, blue: 255 }, // ambientColor: { red: 255, green: 255, blue: 255 }, From e37d68449bb3b344936bc5ad0845098c878cc57f Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 16 Dec 2015 13:57:40 -0800 Subject: [PATCH 18/57] rename folder --- examples/controllers/handControllerGrab.js | 4 ++-- examples/{lights => light_modifier}/lightLoader.js | 0 examples/{lights => light_modifier}/lightModifier.js | 0 examples/{lights => light_modifier}/lightModifierTestScene.js | 0 examples/{lights => light_modifier}/slider.js | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename examples/{lights => light_modifier}/lightLoader.js (100%) rename examples/{lights => light_modifier}/lightModifier.js (100%) rename examples/{lights => light_modifier}/lightModifierTestScene.js (100%) rename examples/{lights => light_modifier}/slider.js (100%) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index c452519522..e7d1b5f84b 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -944,7 +944,7 @@ function MyController(hand) { relativeRotation: this.offsetRotation, ttl: ACTION_TTL, kinematic: NEAR_GRABBING_KINEMATIC, - kinematicSetVelocity: true, + kinematicSetVelocity: false, ignoreIK: this.ignoreIK }); if (this.actionID === NULL_ACTION_ID) { @@ -1029,7 +1029,7 @@ function MyController(hand) { relativeRotation: this.offsetRotation, ttl: ACTION_TTL, kinematic: NEAR_GRABBING_KINEMATIC, - kinematicSetVelocity: true, + kinematicSetVelocity: false, ignoreIK: this.ignoreIK }); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); diff --git a/examples/lights/lightLoader.js b/examples/light_modifier/lightLoader.js similarity index 100% rename from examples/lights/lightLoader.js rename to examples/light_modifier/lightLoader.js diff --git a/examples/lights/lightModifier.js b/examples/light_modifier/lightModifier.js similarity index 100% rename from examples/lights/lightModifier.js rename to examples/light_modifier/lightModifier.js diff --git a/examples/lights/lightModifierTestScene.js b/examples/light_modifier/lightModifierTestScene.js similarity index 100% rename from examples/lights/lightModifierTestScene.js rename to examples/light_modifier/lightModifierTestScene.js diff --git a/examples/lights/slider.js b/examples/light_modifier/slider.js similarity index 100% rename from examples/lights/slider.js rename to examples/light_modifier/slider.js From 40e6e4b13389fb57d5ef627113beda458eabcf76 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 16 Dec 2015 14:01:50 -0800 Subject: [PATCH 19/57] add readme --- examples/light_modifier/README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/light_modifier/README.md diff --git a/examples/light_modifier/README.md b/examples/light_modifier/README.md new file mode 100644 index 0000000000..d978c73b5b --- /dev/null +++ b/examples/light_modifier/README.md @@ -0,0 +1,24 @@ +This PR demonstrates one way in-world editing of objects might work. We start with a spotlight. When you distant grab the sliders, you can move them along their axis to change their values. You may also rotate / move the block to which the spotlight is attached. + +To test: https://rawgit.com/imgntn/hifi/light_mod/examples/lights/lightLoader.js +To reset, I recommend stopping all scripts then re-loading lightLoader.js + +When you run the lightLoader.js script, 4 scripts will be loaded: +- handControllerGrab.js (custom) +- lightModifier.js (listens for message to create sliders for a given light) +- lightModifierTestScene.js (creates a light and parents it to a block, then sends a message ^^) +- slider.js (attached to each slider entity) + + + +Current sliders are (top to bottom): +red +green +blue +intensity +cutoff +exponent + +To-Do: Determine how to enter / exit edit mode , support near grab, add other input types (checkbox, etc), prevent velocity drift on slider release,button to hide entity + +![capture](https://cloud.githubusercontent.com/assets/843228/11830366/2f2dfe70-a359-11e5-84f0-33a380ebeac7.PNG) From e0b8c6b48b46e1f380a5940a16c6dcb702ae3c89 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 16 Dec 2015 14:24:31 -0800 Subject: [PATCH 20/57] show light volumes --- examples/light_modifier/lightModifier.js | 32 +++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index e928679f08..b33b6fc0f1 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -10,22 +10,37 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - //some experimental options var ONLY_I_CAN_EDIT = false; var SLIDERS_SHOULD_STAY_WITH_AVATAR = false; var VERTICAL_SLIDERS = false; +var SHOW_OVERLAYS = true; +var SHOW_LIGHT_VOLUME = true; -// Script.include('../libraries/lightOverlayManager.js'); -// var lightOverlayManager = new LightOverlayManager(); -// lightOverlayManager.setVisible(true); +//variables for managing overlays +var selectionDisplay; +var selectionManager; +var lightOverlayManager; +if (SHOW_OVERLAYS === true) { + Script.include('../libraries/entitySelectionTool.js'); + + selectionDisplay = SelectionDisplay; + selectionManager = SelectionManager; + Script.include('../libraries/lightOverlayManager.js'); + lightOverlayManager = new LightOverlayManager(); + selectionManager.addEventListener(function() { + selectionDisplay.updateHandles(); + lightOverlayManager.updatePositions(); + }); + + lightOverlayManager.setVisible(true); +} // var pickRay = Camera.computePickRay(event.x, event.y); // var lightResult = lightOverlayManager.findRayIntersection(pickRay) var DEFAULT_PARENT_ID = '{00000000-0000-0000-0000-000000000000}' - var AXIS_SCALE = 1; var COLOR_MAX = 255; var INTENSITY_MAX = 0.05; @@ -323,7 +338,9 @@ var slidersRef = { } var light = null; -function makeSliders(light) { +function makeSliders(light) { // selectionManager.setSelections([entityID]); + + if (light.type === 'spotlight') { var USE_COLOR_SLIDER = true; var USE_INTENSITY_SLIDER = true; @@ -382,6 +399,9 @@ function handleLightModMessages(channel, message, sender) { makeSliders(parsedMessage.light); light = parsedMessage.light.id + if (SHOW_LIGHT_VOLUME === true) { + selectionManager.setSelections([parsedMessage.light.id]); + } } function handleValueMessages(channel, message, sender) { From 40a096ca8d9c2e1166387531b154da2d263c3759 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 16 Dec 2015 14:34:01 -0800 Subject: [PATCH 21/57] kinematic grab things --- examples/controllers/handControllerGrab.js | 25 ++++++++++++++++--- examples/light_modifier/lightModifier.js | 3 +-- .../light_modifier/lightModifierTestScene.js | 8 +++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index e7d1b5f84b..ce519880af 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -944,7 +944,7 @@ function MyController(hand) { relativeRotation: this.offsetRotation, ttl: ACTION_TTL, kinematic: NEAR_GRABBING_KINEMATIC, - kinematicSetVelocity: false, + kinematicSetVelocity: true, ignoreIK: this.ignoreIK }); if (this.actionID === NULL_ACTION_ID) { @@ -1029,7 +1029,7 @@ function MyController(hand) { relativeRotation: this.offsetRotation, ttl: ACTION_TTL, kinematic: NEAR_GRABBING_KINEMATIC, - kinematicSetVelocity: false, + kinematicSetVelocity: true, ignoreIK: this.ignoreIK }); this.actionTimeout = now + (ACTION_TTL * MSEC_PER_SEC); @@ -1243,7 +1243,26 @@ function MyController(hand) { this.overlayLineOff(); if (this.grabbedEntity !== null) { if (this.actionID !== null) { - Entities.deleteAction(this.grabbedEntity, this.actionID); + //add velocity whatnot + var defaultReleaseVelocityData = { + disableReleaseVelocity: false + }; + + var releaseVelocityData = getEntityCustomData('releaseVelocityKey', this.grabbedEntity, defaultReleaseVelocityData); + if (releaseVelocityData.disableReleaseVelocity === true) { + Entities.updateAction(this.grabbedEntity, this.actionID, { + ttl: 1, + kinematic: false, + kinematicSetVelocity: false, + + }); + // Entities.deleteAction(this.grabbedEntity, this.actionID); + + } else { + //don't make adjustments + Entities.deleteAction(this.grabbedEntity, this.actionID); + + } } } diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index b33b6fc0f1..b79c00da92 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -243,8 +243,7 @@ entitySlider.prototype = { axisEnd: this.endOfAxis, }, releaseVelocityKey: { - disableReleaseVelocity: true, - customReleaseVelocity: false + disableReleaseVelocity: true } }) }; diff --git a/examples/light_modifier/lightModifierTestScene.js b/examples/light_modifier/lightModifierTestScene.js index 5748f0d4ed..e939353b8c 100644 --- a/examples/light_modifier/lightModifierTestScene.js +++ b/examples/light_modifier/lightModifierTestScene.js @@ -73,7 +73,13 @@ function createBlock() { green: 0, blue: 255 }, - position: position + position: position, + userData: JSON.stringify({ + + releaseVelocityKey: { + disableReleaseVelocity: true + } + }) }; block = Entities.addEntity(blockProperties); From f1ec28e169896581a1eb5788d9e89453d6c93378 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 16 Dec 2015 14:55:01 -0800 Subject: [PATCH 22/57] visualize volumes --- examples/libraries/lightOverlayManager.js | 19 +++++++++++++------ examples/light_modifier/lightModifier.js | 2 ++ .../light_modifier/lightModifierTestScene.js | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/examples/libraries/lightOverlayManager.js b/examples/libraries/lightOverlayManager.js index 0942fae723..2d3618096b 100644 --- a/examples/libraries/lightOverlayManager.js +++ b/examples/libraries/lightOverlayManager.js @@ -53,7 +53,9 @@ LightOverlayManager = function() { if (visible != isVisible) { visible = isVisible; for (var id in entityOverlays) { - Overlays.editOverlay(entityOverlays[id], { visible: visible }); + Overlays.editOverlay(entityOverlays[id], { + visible: visible + }); } } }; @@ -61,8 +63,7 @@ LightOverlayManager = function() { // Allocate or get an unused overlay function getOverlay() { if (unusedOverlays.length == 0) { - var overlay = Overlays.addOverlay("image3d", { - }); + var overlay = Overlays.addOverlay("image3d", {}); allOverlays.push(overlay); } else { var overlay = unusedOverlays.pop(); @@ -72,7 +73,9 @@ LightOverlayManager = function() { function releaseOverlay(overlay) { unusedOverlays.push(overlay); - Overlays.editOverlay(overlay, { visible: false }); + Overlays.editOverlay(overlay, { + visible: false + }); } function addEntity(entityID) { @@ -88,7 +91,11 @@ LightOverlayManager = function() { visible: visible, alpha: 0.9, scale: 0.5, - color: { red: 255, green: 255, blue: 255 } + color: { + red: 255, + green: 255, + blue: 255 + } }); } } @@ -123,4 +130,4 @@ LightOverlayManager = function() { Overlays.deleteOverlay(allOverlays[i]); } }); -}; +}; \ No newline at end of file diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index b79c00da92..4d5a326cae 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -36,6 +36,7 @@ if (SHOW_OVERLAYS === true) { lightOverlayManager.setVisible(true); } +// var entityResult = Entities.findRayIntersection(pickRay, true); // want precision picking // var pickRay = Camera.computePickRay(event.x, event.y); // var lightResult = lightOverlayManager.findRayIntersection(pickRay) @@ -427,6 +428,7 @@ function cleanup() { Messages.messageReceived.disconnect(handleValueMessages); Entities.deletingEntity.disconnect(deleteEntity); + lightOverlayManager.setVisible(false); } Script.scriptEnding.connect(cleanup); diff --git a/examples/light_modifier/lightModifierTestScene.js b/examples/light_modifier/lightModifierTestScene.js index e939353b8c..84fb779469 100644 --- a/examples/light_modifier/lightModifierTestScene.js +++ b/examples/light_modifier/lightModifierTestScene.js @@ -26,7 +26,7 @@ function createLight() { dimensions: { x: 2, y: 2, - z: 20 + z: 8 }, parentID: block, color: { From f55994b99317472a9b39e4ddeee619700899b96f Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 16 Dec 2015 15:07:31 -0800 Subject: [PATCH 23/57] cleanup --- examples/light_modifier/lightModifier.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 4d5a326cae..7cd442e9ed 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -23,19 +23,27 @@ var selectionManager; var lightOverlayManager; if (SHOW_OVERLAYS === true) { + + Script.include('../libraries/gridTool.js'); Script.include('../libraries/entitySelectionTool.js'); + Script.include('../libraries/lightOverlayManager.js'); + + var grid = Grid(); + gridTool = GridTool({ + horizontalGrid: grid + }); + gridTool.setVisible(false); selectionDisplay = SelectionDisplay; selectionManager = SelectionManager; - Script.include('../libraries/lightOverlayManager.js'); lightOverlayManager = new LightOverlayManager(); selectionManager.addEventListener(function() { selectionDisplay.updateHandles(); lightOverlayManager.updatePositions(); }); - lightOverlayManager.setVisible(true); } + // var entityResult = Entities.findRayIntersection(pickRay, true); // want precision picking // var pickRay = Camera.computePickRay(event.x, event.y); // var lightResult = lightOverlayManager.findRayIntersection(pickRay) From cd911b31d29413a56ae1d54e215e70b4ef895ea5 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 17 Dec 2015 10:26:54 -0800 Subject: [PATCH 24/57] dont accidentally constrain all objects --- examples/controllers/handControllerGrab.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index ce519880af..9efbff7c58 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -845,7 +845,8 @@ function MyController(hand) { var constraintData = getEntityCustomData('lightModifierKey', this.grabbedEntity, defaultConstraintData); var clampedVector; var targetPosition; - if (constraintData.startAxis !== false) { + if (constraintData.axisStart !== false) { + print('CONSTRAINING OBJECT') clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition, constraintData.axisStart, constraintData.axisEnd); targetPosition = clampedVector; } else { From 5cc5a2ab33aa2df0edfb622849d17b220c3c1a00 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 17 Dec 2015 10:58:14 -0800 Subject: [PATCH 25/57] working non kinematic release --- examples/controllers/handControllerGrab.js | 71 ++++++++++++------- examples/light_modifier/lightLoader.js | 6 +- examples/light_modifier/lightModifier.js | 8 +-- .../light_modifier/lightModifierTestScene.js | 3 +- 4 files changed, 54 insertions(+), 34 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 9efbff7c58..f21df807b4 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -817,26 +817,35 @@ function MyController(hand) { Entities.callEntityMethod(this.grabbedEntity, "continueDistantGrab"); + var defaultMoveWithHeadData = { + disableMoveWithHead: false + }; + var handControllerData = getEntityCustomData('handControllerKey', this.grabbedEntity, defaultMoveWithHeadData); - // mix in head motion - if (MOVE_WITH_HEAD) { - var objDistance = Vec3.length(objectToAvatar); - var before = Vec3.multiplyQbyV(this.currentCameraOrientation, { - 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); - this.currentCameraOrientation = Camera.orientation; - this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change); + if (handControllerData.disableMoveWithHead !== true) { + // mix in head motion + if (MOVE_WITH_HEAD) { + var objDistance = Vec3.length(objectToAvatar); + var before = Vec3.multiplyQbyV(this.currentCameraOrientation, { + 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); + this.currentCameraOrientation = Camera.orientation; + this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change); + } + } else { + print('should not head move!'); } + var defaultConstraintData = { axisStart: false, axisEnd: false, @@ -846,7 +855,6 @@ function MyController(hand) { var clampedVector; var targetPosition; if (constraintData.axisStart !== false) { - print('CONSTRAINING OBJECT') clampedVector = this.projectVectorAlongAxis(this.currentObjectPosition, constraintData.axisStart, constraintData.axisEnd); targetPosition = clampedVector; } else { @@ -1249,15 +1257,29 @@ function MyController(hand) { disableReleaseVelocity: false }; - var releaseVelocityData = getEntityCustomData('releaseVelocityKey', this.grabbedEntity, defaultReleaseVelocityData); + var releaseVelocityData = getEntityCustomData('handControllerKey', this.grabbedEntity, defaultReleaseVelocityData); if (releaseVelocityData.disableReleaseVelocity === true) { - Entities.updateAction(this.grabbedEntity, this.actionID, { - ttl: 1, - kinematic: false, - kinematicSetVelocity: false, + print('SHOULD NOT BE KINEMATIC AT RELEASE') + // Entities.updateAction(this.grabbedEntity, this.actionID, { + // ttl: 1, + // kinematic: false, + // kinematicSetVelocity: false, + // }); + Entities.deleteAction(this.grabbedEntity, this.actionID); - }); - // Entities.deleteAction(this.grabbedEntity, this.actionID); + Entities.editEntity(this.grabbedEntity,{ + velocity:{ + x:0, + y:0, + z:0 + }, + angularVelocity:{ + x:0, + y:0, + z:0 + } + }) + Entities.deleteAction(this.grabbedEntity, this.actionID); } else { //don't make adjustments @@ -1266,7 +1288,6 @@ function MyController(hand) { } } } - this.deactivateEntity(this.grabbedEntity); this.grabbedEntity = null; diff --git a/examples/light_modifier/lightLoader.js b/examples/light_modifier/lightLoader.js index e4022e7bc1..83618f85c2 100644 --- a/examples/light_modifier/lightLoader.js +++ b/examples/light_modifier/lightLoader.js @@ -10,11 +10,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var grabScript = Script.resolvePath('../controllers/handControllerGrab.js'); +var grabScript = Script.resolvePath('../controllers/handControllerGrab.js?' + Math.random(0 - 100)); Script.load(grabScript); -var lightModifier = Script.resolvePath('lightModifier.js'); +var lightModifier = Script.resolvePath('lightModifier.js?' + Math.random(0 - 100)); Script.load(lightModifier); Script.setTimeout(function() { - var lightModifierTestScene = Script.resolvePath('lightModifierTestScene.js'); + var lightModifierTestScene = Script.resolvePath('lightModifierTestScene.js?' + Math.random(0 - 100)); Script.load(lightModifierTestScene); }, 750) \ No newline at end of file diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 7cd442e9ed..8eae5cc2a4 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -251,15 +251,15 @@ entitySlider.prototype = { axisStart: position, axisEnd: this.endOfAxis, }, - releaseVelocityKey: { - disableReleaseVelocity: true + handControllerKey: { + disableReleaseVelocity: true, + disableMoveWithHead: true } - }) + }), }; this.sliderIndicator = Entities.addEntity(properties); }, - setValueFromMessage: function(message) { //message is not for our light diff --git a/examples/light_modifier/lightModifierTestScene.js b/examples/light_modifier/lightModifierTestScene.js index 84fb779469..761eb4786d 100644 --- a/examples/light_modifier/lightModifierTestScene.js +++ b/examples/light_modifier/lightModifierTestScene.js @@ -75,8 +75,7 @@ function createBlock() { }, position: position, userData: JSON.stringify({ - - releaseVelocityKey: { + handControllerKey: { disableReleaseVelocity: true } }) From 8e2128c69226e629291db183bf1fc77317826ee7 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 17 Dec 2015 11:59:21 -0800 Subject: [PATCH 26/57] update light volume when you move light parent --- examples/controllers/handControllerGrab.js | 29 +- examples/libraries/entitySelectionTool.js | 3101 +++++++++++++---- examples/light_modifier/lightModifier.js | 2 +- .../light_modifier/lightModifierTestScene.js | 2 + examples/light_modifier/lightParent.js | 42 + 5 files changed, 2387 insertions(+), 789 deletions(-) create mode 100644 examples/light_modifier/lightParent.js diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index f21df807b4..f53a66444f 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -1256,27 +1256,21 @@ function MyController(hand) { var defaultReleaseVelocityData = { disableReleaseVelocity: false }; - + //sometimes we want things to stay right where they are when we let go. var releaseVelocityData = getEntityCustomData('handControllerKey', this.grabbedEntity, defaultReleaseVelocityData); if (releaseVelocityData.disableReleaseVelocity === true) { - print('SHOULD NOT BE KINEMATIC AT RELEASE') - // Entities.updateAction(this.grabbedEntity, this.actionID, { - // ttl: 1, - // kinematic: false, - // kinematicSetVelocity: false, - // }); - Entities.deleteAction(this.grabbedEntity, this.actionID); + Entities.deleteAction(this.grabbedEntity, this.actionID); - Entities.editEntity(this.grabbedEntity,{ - velocity:{ - x:0, - y:0, - z:0 + Entities.editEntity(this.grabbedEntity, { + velocity: { + x: 0, + y: 0, + z: 0 }, - angularVelocity:{ - x:0, - y:0, - z:0 + angularVelocity: { + x: 0, + y: 0, + z: 0 } }) Entities.deleteAction(this.grabbedEntity, this.actionID); @@ -1288,6 +1282,7 @@ function MyController(hand) { } } } + this.deactivateEntity(this.grabbedEntity); this.grabbedEntity = null; diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 6edbe6844b..9b213760c2 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -16,23 +16,73 @@ HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; SPACE_LOCAL = "local"; SPACE_WORLD = "world"; + SelectionManager = (function() { var that = {}; + + function subscribeToUpdateMessages() { + Messages.subscribe('entityToolUpdates'); + Messages.messageReceived.connect(handleEntitySelectionToolUpdates); + } + + function handleEntitySelectionToolUpdates(channel, message, sender) { + if (channel !== 'entityToolUpdates') { + return; + } + if (sender !== MyAvatar.sessionUUID) { + return; + } + + if (message === 'callUpdate') { + that._update(); + } + } + + subscribeToUpdateMessages(); + that.savedProperties = {}; that.selections = []; var listeners = []; that.localRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - that.localPosition = { x: 0, y: 0, z: 0 }; - that.localDimensions = { x: 0, y: 0, z: 0 }; - that.localRegistrationPoint = { x: 0.5, y: 0.5, z: 0.5 }; + that.localPosition = { + x: 0, + y: 0, + z: 0 + }; + that.localDimensions = { + x: 0, + y: 0, + z: 0 + }; + that.localRegistrationPoint = { + x: 0.5, + y: 0.5, + z: 0.5 + }; that.worldRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - that.worldPosition = { x: 0, y: 0, z: 0 }; - that.worldDimensions = { x: 0, y: 0, z: 0 }; - that.worldRegistrationPoint = { x: 0.5, y: 0.5, z: 0.5 }; - that.centerPosition = { x: 0, y: 0, z: 0 }; + that.worldPosition = { + x: 0, + y: 0, + z: 0 + }; + that.worldDimensions = { + x: 0, + y: 0, + z: 0 + }; + that.worldRegistrationPoint = { + x: 0.5, + y: 0.5, + z: 0.5 + }; + that.centerPosition = { + x: 0, + y: 0, + z: 0 + }; that.saveProperties = function() { that.savedProperties = {}; @@ -177,9 +227,9 @@ function getRelativeCenterPosition(dimensions, registrationPoint) { } } -SelectionDisplay = (function () { +SelectionDisplay = (function() { var that = {}; - + var MINIMUM_DIMENSION = 0.001; var GRABBER_DISTANCE_TO_SIZE_RATIO = 0.0075; @@ -194,14 +244,18 @@ SelectionDisplay = (function () { var ROTATE_ARROW_WEST_SOUTH_URL = HIFI_PUBLIC_BUCKET + "images/rotate-arrow-west-south.svg"; var showExtendedStretchHandles = false; - + var spaceMode = SPACE_LOCAL; var mode = "UNKNOWN"; var overlayNames = new Array(); var lastCameraPosition = Camera.getPosition(); var lastCameraOrientation = Camera.getOrientation(); - var handleHoverColor = { red: 224, green: 67, blue: 36 }; + var handleHoverColor = { + red: 224, + green: 67, + blue: 36 + }; var handleHoverAlpha = 1.0; var rotateOverlayTargetSize = 10000; // really big target @@ -221,19 +275,27 @@ SelectionDisplay = (function () { var pitchNormal; var rollNormal; var rotationNormal; - + var originalRotation; var originalPitch; var originalYaw; var originalRoll; - - var handleColor = { red: 255, green: 255, blue: 255 }; + + var handleColor = { + red: 255, + green: 255, + blue: 255 + }; var handleAlpha = 0.7; - var highlightedHandleColor = { red: 183, green: 64, blue: 44 }; + var highlightedHandleColor = { + red: 183, + green: 64, + blue: 44 + }; var highlightedHandleAlpha = 0.9; - + var previousHandle = false; var previousHandleColor; var previousHandleAlpha; @@ -242,115 +304,182 @@ SelectionDisplay = (function () { var grabberSizeEdge = 0.015; var grabberSizeFace = 0.025; var grabberAlpha = 1; - var grabberColorCorner = { red: 120, green: 120, blue: 120 }; - var grabberColorEdge = { red: 0, green: 0, blue: 0 }; - var grabberColorFace = { red: 120, green: 120, blue: 120 }; + var grabberColorCorner = { + red: 120, + green: 120, + blue: 120 + }; + var grabberColorEdge = { + red: 0, + green: 0, + blue: 0 + }; + var grabberColorFace = { + red: 120, + green: 120, + blue: 120 + }; var grabberLineWidth = 0.5; var grabberSolid = true; - var grabberMoveUpPosition = { x: 0, y: 0, z: 0 }; + var grabberMoveUpPosition = { + x: 0, + y: 0, + z: 0 + }; - var lightOverlayColor = { red: 255, green: 153, blue: 0 }; + var lightOverlayColor = { + red: 255, + green: 153, + blue: 0 + }; var grabberPropertiesCorner = { - position: { x:0, y: 0, z: 0}, - size: grabberSizeCorner, - color: grabberColorCorner, - alpha: 1, - solid: grabberSolid, - visible: false, - dashed: false, - lineWidth: grabberLineWidth, - drawInFront: true, - borderSize: 1.4, - }; + position: { + x: 0, + y: 0, + z: 0 + }, + size: grabberSizeCorner, + color: grabberColorCorner, + alpha: 1, + solid: grabberSolid, + visible: false, + dashed: false, + lineWidth: grabberLineWidth, + drawInFront: true, + borderSize: 1.4, + }; var grabberPropertiesEdge = { - position: { x:0, y: 0, z: 0}, - size: grabberSizeEdge, - color: grabberColorEdge, - alpha: 1, - solid: grabberSolid, - visible: false, - dashed: false, - lineWidth: grabberLineWidth, - drawInFront: true, - borderSize: 1.4, - }; + position: { + x: 0, + y: 0, + z: 0 + }, + size: grabberSizeEdge, + color: grabberColorEdge, + alpha: 1, + solid: grabberSolid, + visible: false, + dashed: false, + lineWidth: grabberLineWidth, + drawInFront: true, + borderSize: 1.4, + }; var grabberPropertiesFace = { - position: { x:0, y: 0, z: 0}, - size: grabberSizeFace, - color: grabberColorFace, - alpha: 1, - solid: grabberSolid, - visible: false, - dashed: false, - lineWidth: grabberLineWidth, - drawInFront: true, - borderSize: 1.4, - }; - + position: { + x: 0, + y: 0, + z: 0 + }, + size: grabberSizeFace, + color: grabberColorFace, + alpha: 1, + solid: grabberSolid, + visible: false, + dashed: false, + lineWidth: grabberLineWidth, + drawInFront: true, + borderSize: 1.4, + }; + var spotLightLineProperties = { color: lightOverlayColor, lineWidth: 1.5, }; - + var highlightBox = Overlays.addOverlay("cube", { - position: { x:0, y: 0, z: 0}, - size: 1, - color: { red: 90, green: 90, blue: 90}, - alpha: 1, - solid: false, - visible: false, - dashed: true, - lineWidth: 2.0, - ignoreRayIntersection: true, // this never ray intersects - drawInFront: true - }); + position: { + x: 0, + y: 0, + z: 0 + }, + size: 1, + color: { + red: 90, + green: 90, + blue: 90 + }, + alpha: 1, + solid: false, + visible: false, + dashed: true, + lineWidth: 2.0, + ignoreRayIntersection: true, // this never ray intersects + drawInFront: true + }); var selectionBox = Overlays.addOverlay("cube", { - position: { x:0, y: 0, z: 0}, - size: 1, - color: { red: 255, green: 0, blue: 0}, - alpha: 1, - solid: false, - visible: false, - dashed: false, - lineWidth: 1.0, - }); + position: { + x: 0, + y: 0, + z: 0 + }, + size: 1, + color: { + red: 255, + green: 0, + blue: 0 + }, + alpha: 1, + solid: false, + visible: false, + dashed: false, + lineWidth: 1.0, + }); var selectionBoxes = []; var rotationDegreesDisplay = Overlays.addOverlay("text3d", { - position: { x:0, y: 0, z: 0}, - text: "", - color: { red: 0, green: 0, blue: 0}, - backgroundColor: { red: 255, green: 255, blue: 255 }, - alpha: 0.7, - backgroundAlpha: 0.7, - visible: false, - isFacingAvatar: true, - drawInFront: true, - ignoreRayIntersection: true, - dimensions: { x: 0, y: 0 }, - lineHeight: 0.0, - topMargin: 0, - rightMargin: 0, - bottomMargin: 0, - leftMargin: 0, - }); + position: { + x: 0, + y: 0, + z: 0 + }, + text: "", + color: { + red: 0, + green: 0, + blue: 0 + }, + backgroundColor: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 0.7, + backgroundAlpha: 0.7, + visible: false, + isFacingAvatar: true, + drawInFront: true, + ignoreRayIntersection: true, + dimensions: { + x: 0, + y: 0 + }, + lineHeight: 0.0, + topMargin: 0, + rightMargin: 0, + bottomMargin: 0, + leftMargin: 0, + }); var grabberMoveUp = Overlays.addOverlay("image3d", { - url: HIFI_PUBLIC_BUCKET + "images/up-arrow.svg", - position: { x:0, y: 0, z: 0}, - color: handleColor, - alpha: handleAlpha, - visible: false, - size: 0.1, - scale: 0.1, - isFacingAvatar: true, - drawInFront: true, - }); + url: HIFI_PUBLIC_BUCKET + "images/up-arrow.svg", + position: { + x: 0, + y: 0, + z: 0 + }, + color: handleColor, + alpha: handleAlpha, + visible: false, + size: 0.1, + scale: 0.1, + isFacingAvatar: true, + drawInFront: true, + }); // var normalLine = Overlays.addOverlay("line3d", { // visible: true, @@ -360,7 +489,7 @@ SelectionDisplay = (function () { // color: { red: 255, green: 255, blue: 0 }, // ignoreRayIntersection: true, // }); - + var grabberLBN = Overlays.addOverlay("cube", grabberPropertiesCorner); var grabberRBN = Overlays.addOverlay("cube", grabberPropertiesCorner); var grabberLBF = Overlays.addOverlay("cube", grabberPropertiesCorner); @@ -481,171 +610,324 @@ SelectionDisplay = (function () { ]; - var baseOverlayAngles = { x: 0, y: 0, z: 0 }; + var baseOverlayAngles = { + x: 0, + y: 0, + z: 0 + }; var baseOverlayRotation = Quat.fromVec3Degrees(baseOverlayAngles); var baseOfEntityProjectionOverlay = Overlays.addOverlay("rectangle3d", { - position: { x: 1, y: 0, z: 0}, - color: { red: 51, green: 152, blue: 203 }, - alpha: 0.5, - solid: true, - visible: false, - width: 300, height: 200, - rotation: baseOverlayRotation, - ignoreRayIntersection: true, // always ignore this - }); + position: { + x: 1, + y: 0, + z: 0 + }, + color: { + red: 51, + green: 152, + blue: 203 + }, + alpha: 0.5, + solid: true, + visible: false, + width: 300, + height: 200, + rotation: baseOverlayRotation, + ignoreRayIntersection: true, // always ignore this + }); - var yawOverlayAngles = { x: 90, y: 0, z: 0 }; + var yawOverlayAngles = { + x: 90, + y: 0, + z: 0 + }; var yawOverlayRotation = Quat.fromVec3Degrees(yawOverlayAngles); - var pitchOverlayAngles = { x: 0, y: 90, z: 0 }; + var pitchOverlayAngles = { + x: 0, + y: 90, + z: 0 + }; var pitchOverlayRotation = Quat.fromVec3Degrees(pitchOverlayAngles); - var rollOverlayAngles = { x: 0, y: 180, z: 0 }; + var rollOverlayAngles = { + x: 0, + y: 180, + z: 0 + }; var rollOverlayRotation = Quat.fromVec3Degrees(rollOverlayAngles); var xRailOverlay = Overlays.addOverlay("line3d", { - visible: false, - lineWidth: 1.0, - start: { x: 0, y: 0, z: 0 }, - end: { x: 0, y: 0, z: 0 }, - color: { red: 255, green: 0, blue: 0 }, - ignoreRayIntersection: true, // always ignore this - visible: false, - }); + visible: false, + lineWidth: 1.0, + start: { + x: 0, + y: 0, + z: 0 + }, + end: { + x: 0, + y: 0, + z: 0 + }, + color: { + red: 255, + green: 0, + blue: 0 + }, + ignoreRayIntersection: true, // always ignore this + visible: false, + }); var yRailOverlay = Overlays.addOverlay("line3d", { - visible: false, - lineWidth: 1.0, - start: { x: 0, y: 0, z: 0 }, - end: { x: 0, y: 0, z: 0 }, - color: { red: 0, green: 255, blue: 0 }, - ignoreRayIntersection: true, // always ignore this - visible: false, - }); + visible: false, + lineWidth: 1.0, + start: { + x: 0, + y: 0, + z: 0 + }, + end: { + x: 0, + y: 0, + z: 0 + }, + color: { + red: 0, + green: 255, + blue: 0 + }, + ignoreRayIntersection: true, // always ignore this + visible: false, + }); var zRailOverlay = Overlays.addOverlay("line3d", { - visible: false, - lineWidth: 1.0, - start: { x: 0, y: 0, z: 0 }, - end: { x: 0, y: 0, z: 0 }, - color: { red: 0, green: 0, blue: 255 }, - ignoreRayIntersection: true, // always ignore this - visible: false, - }); + visible: false, + lineWidth: 1.0, + start: { + x: 0, + y: 0, + z: 0 + }, + end: { + x: 0, + y: 0, + z: 0 + }, + color: { + red: 0, + green: 0, + blue: 255 + }, + ignoreRayIntersection: true, // always ignore this + visible: false, + }); var rotateZeroOverlay = Overlays.addOverlay("line3d", { - visible: false, - lineWidth: 2.0, - start: { x: 0, y: 0, z: 0 }, - end: { x: 0, y: 0, z: 0 }, - color: { red: 255, green: 0, blue: 0 }, - ignoreRayIntersection: true, // always ignore this - }); + visible: false, + lineWidth: 2.0, + start: { + x: 0, + y: 0, + z: 0 + }, + end: { + x: 0, + y: 0, + z: 0 + }, + color: { + red: 255, + green: 0, + blue: 0 + }, + ignoreRayIntersection: true, // always ignore this + }); var rotateCurrentOverlay = Overlays.addOverlay("line3d", { - visible: false, - lineWidth: 2.0, - start: { x: 0, y: 0, z: 0 }, - end: { x: 0, y: 0, z: 0 }, - color: { red: 0, green: 0, blue: 255 }, - ignoreRayIntersection: true, // always ignore this - }); + visible: false, + lineWidth: 2.0, + start: { + x: 0, + y: 0, + z: 0 + }, + end: { + x: 0, + y: 0, + z: 0 + }, + color: { + red: 0, + green: 0, + blue: 255 + }, + ignoreRayIntersection: true, // always ignore this + }); var rotateOverlayTarget = Overlays.addOverlay("circle3d", { - position: { x:0, y: 0, z: 0}, - size: rotateOverlayTargetSize, - color: { red: 0, green: 0, blue: 0 }, - alpha: 0.0, - solid: true, - visible: false, - rotation: yawOverlayRotation, - }); + position: { + x: 0, + y: 0, + z: 0 + }, + size: rotateOverlayTargetSize, + color: { + red: 0, + green: 0, + blue: 0 + }, + alpha: 0.0, + solid: true, + visible: false, + rotation: yawOverlayRotation, + }); var rotateOverlayInner = Overlays.addOverlay("circle3d", { - position: { x:0, y: 0, z: 0}, - size: 1, - color: { red: 51, green: 152, blue: 203 }, - alpha: 0.2, - solid: true, - visible: false, - rotation: yawOverlayRotation, - hasTickMarks: true, - majorTickMarksAngle: innerSnapAngle, - minorTickMarksAngle: 0, - majorTickMarksLength: -0.25, - minorTickMarksLength: 0, - majorTickMarksColor: { red: 0, green: 0, blue: 0 }, - minorTickMarksColor: { red: 0, green: 0, blue: 0 }, - ignoreRayIntersection: true, // always ignore this - }); + position: { + x: 0, + y: 0, + z: 0 + }, + size: 1, + color: { + red: 51, + green: 152, + blue: 203 + }, + alpha: 0.2, + solid: true, + visible: false, + rotation: yawOverlayRotation, + hasTickMarks: true, + majorTickMarksAngle: innerSnapAngle, + minorTickMarksAngle: 0, + majorTickMarksLength: -0.25, + minorTickMarksLength: 0, + majorTickMarksColor: { + red: 0, + green: 0, + blue: 0 + }, + minorTickMarksColor: { + red: 0, + green: 0, + blue: 0 + }, + ignoreRayIntersection: true, // always ignore this + }); var rotateOverlayOuter = Overlays.addOverlay("circle3d", { - position: { x:0, y: 0, z: 0}, - size: 1, - color: { red: 51, green: 152, blue: 203 }, - alpha: 0.2, - solid: true, - visible: false, - rotation: yawOverlayRotation, + position: { + x: 0, + y: 0, + z: 0 + }, + size: 1, + color: { + red: 51, + green: 152, + blue: 203 + }, + alpha: 0.2, + solid: true, + visible: false, + rotation: yawOverlayRotation, - hasTickMarks: true, - majorTickMarksAngle: 45.0, - minorTickMarksAngle: 5, - majorTickMarksLength: 0.25, - minorTickMarksLength: 0.1, - majorTickMarksColor: { red: 0, green: 0, blue: 0 }, - minorTickMarksColor: { red: 0, green: 0, blue: 0 }, - ignoreRayIntersection: true, // always ignore this - }); + hasTickMarks: true, + majorTickMarksAngle: 45.0, + minorTickMarksAngle: 5, + majorTickMarksLength: 0.25, + minorTickMarksLength: 0.1, + majorTickMarksColor: { + red: 0, + green: 0, + blue: 0 + }, + minorTickMarksColor: { + red: 0, + green: 0, + blue: 0 + }, + ignoreRayIntersection: true, // always ignore this + }); var rotateOverlayCurrent = Overlays.addOverlay("circle3d", { - position: { x:0, y: 0, z: 0}, - size: 1, - color: { red: 224, green: 67, blue: 36}, - alpha: 0.8, - solid: true, - visible: false, - rotation: yawOverlayRotation, - ignoreRayIntersection: true, // always ignore this - hasTickMarks: true, - majorTickMarksColor: { red: 0, green: 0, blue: 0 }, - minorTickMarksColor: { red: 0, green: 0, blue: 0 }, - }); + position: { + x: 0, + y: 0, + z: 0 + }, + size: 1, + color: { + red: 224, + green: 67, + blue: 36 + }, + alpha: 0.8, + solid: true, + visible: false, + rotation: yawOverlayRotation, + ignoreRayIntersection: true, // always ignore this + hasTickMarks: true, + majorTickMarksColor: { + red: 0, + green: 0, + blue: 0 + }, + minorTickMarksColor: { + red: 0, + green: 0, + blue: 0 + }, + }); var yawHandle = Overlays.addOverlay("image3d", { - url: ROTATE_ARROW_WEST_NORTH_URL, - position: { x:0, y: 0, z: 0}, - color: handleColor, - alpha: handleAlpha, - visible: false, - size: 0.1, - scale: 0.1, - isFacingAvatar: false, - drawInFront: true, - }); + url: ROTATE_ARROW_WEST_NORTH_URL, + position: { + x: 0, + y: 0, + z: 0 + }, + color: handleColor, + alpha: handleAlpha, + visible: false, + size: 0.1, + scale: 0.1, + isFacingAvatar: false, + drawInFront: true, + }); var pitchHandle = Overlays.addOverlay("image3d", { - url: ROTATE_ARROW_WEST_NORTH_URL, - position: { x:0, y: 0, z: 0}, - color: handleColor, - alpha: handleAlpha, - visible: false, - size: 0.1, - scale: 0.1, - isFacingAvatar: false, - drawInFront: true, - }); + url: ROTATE_ARROW_WEST_NORTH_URL, + position: { + x: 0, + y: 0, + z: 0 + }, + color: handleColor, + alpha: handleAlpha, + visible: false, + size: 0.1, + scale: 0.1, + isFacingAvatar: false, + drawInFront: true, + }); var rollHandle = Overlays.addOverlay("image3d", { - url: ROTATE_ARROW_WEST_NORTH_URL, - position: { x:0, y: 0, z: 0}, - color: handleColor, - alpha: handleAlpha, - visible: false, - size: 0.1, - scale: 0.1, - isFacingAvatar: false, - drawInFront: true, - }); + url: ROTATE_ARROW_WEST_NORTH_URL, + position: { + x: 0, + y: 0, + z: 0 + }, + color: handleColor, + alpha: handleAlpha, + visible: false, + size: 0.1, + scale: 0.1, + isFacingAvatar: false, + drawInFront: true, + }); var allOverlays = [ highlightBox, @@ -703,7 +985,7 @@ SelectionDisplay = (function () { overlayNames[grabberEdgeNL] = "grabberEdgeNL"; overlayNames[grabberEdgeFR] = "grabberEdgeFR"; overlayNames[grabberEdgeFL] = "grabberEdgeFL"; - + overlayNames[yawHandle] = "yawHandle"; overlayNames[pitchHandle] = "pitchHandle"; overlayNames[rollHandle] = "rollHandle"; @@ -718,6 +1000,7 @@ SelectionDisplay = (function () { var activeTool = null; var grabberTools = {}; + function addGrabberTool(overlay, tool) { grabberTools[overlay] = { mode: tool.mode, @@ -727,8 +1010,8 @@ SelectionDisplay = (function () { } } - - that.cleanup = function () { + + that.cleanup = function() { for (var i = 0; i < allOverlays.length; i++) { Overlays.deleteOverlay(allOverlays[i]); } @@ -741,19 +1024,21 @@ SelectionDisplay = (function () { var properties = Entities.getEntityProperties(entityID); Overlays.editOverlay(highlightBox, { visible: true, - position: properties.boundingBox.center, + position: properties.boundingBox.center, dimensions: properties.dimensions, rotation: properties.rotation }); }; that.unhighlightSelectable = function(entityID) { - Overlays.editOverlay(highlightBox,{ visible: false}); + Overlays.editOverlay(highlightBox, { + visible: false + }); }; that.select = function(entityID, event) { var properties = Entities.getEntityProperties(SelectionManager.selections[0]); - + lastCameraPosition = Camera.getPosition(); lastCameraOrientation = Camera.getOrientation(); @@ -766,12 +1051,16 @@ SelectionDisplay = (function () { print(" event.y:" + event.y); Vec3.print(" current position:", properties.position); } - - + + } - Entities.editEntity(entityID, { localRenderAlpha: 0.1 }); - Overlays.editOverlay(highlightBox, { visible: false }); + Entities.editEntity(entityID, { + localRenderAlpha: 0.1 + }); + Overlays.editOverlay(highlightBox, { + visible: false + }); that.updateHandles(); } @@ -789,7 +1078,7 @@ SelectionDisplay = (function () { } var rotateHandleOffset = 0.05; - + var top, far, left, bottom, near, right, boundsCenter, objectCenter, BLN, BRN, BLF, TLN, TRN, TLF, TRF; var dimensions, rotation; @@ -828,136 +1117,320 @@ SelectionDisplay = (function () { * ------------------------------*/ - + var cameraPosition = Camera.getPosition(); if (cameraPosition.x > objectCenter.x) { // must be BRF or BRN if (cameraPosition.z < objectCenter.z) { - yawHandleRotation = Quat.fromVec3Degrees({ x: 270, y: 90, z: 0 }); - pitchHandleRotation = Quat.fromVec3Degrees({ x: 0, y: 90, z: 0 }); - rollHandleRotation = Quat.fromVec3Degrees({ x: 0, y: 0, z: 0 }); + yawHandleRotation = Quat.fromVec3Degrees({ + x: 270, + y: 90, + z: 0 + }); + pitchHandleRotation = Quat.fromVec3Degrees({ + x: 0, + y: 90, + z: 0 + }); + rollHandleRotation = Quat.fromVec3Degrees({ + x: 0, + y: 0, + z: 0 + }); - yawNormal = { x: 0, y: 1, z: 0 }; - pitchNormal = { x: 1, y: 0, z: 0 }; - rollNormal = { x: 0, y: 0, z: 1 }; + yawNormal = { + x: 0, + y: 1, + z: 0 + }; + pitchNormal = { + x: 1, + y: 0, + z: 0 + }; + rollNormal = { + x: 0, + y: 0, + z: 1 + }; - yawCorner = { x: left + rotateHandleOffset, - y: bottom - rotateHandleOffset, - z: near - rotateHandleOffset }; + yawCorner = { + x: left + rotateHandleOffset, + y: bottom - rotateHandleOffset, + z: near - rotateHandleOffset + }; - pitchCorner = { x: right - rotateHandleOffset, - y: top + rotateHandleOffset, - z: near - rotateHandleOffset}; + pitchCorner = { + x: right - rotateHandleOffset, + y: top + rotateHandleOffset, + z: near - rotateHandleOffset + }; - rollCorner = { x: left + rotateHandleOffset, - y: top + rotateHandleOffset, - z: far + rotateHandleOffset }; + rollCorner = { + x: left + rotateHandleOffset, + y: top + rotateHandleOffset, + z: far + rotateHandleOffset + }; - yawCenter = { x: boundsCenter.x, y: bottom, z: boundsCenter.z }; - pitchCenter = { x: right, y: boundsCenter.y, z: boundsCenter.z}; - rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far }; - + yawCenter = { + x: boundsCenter.x, + y: bottom, + z: boundsCenter.z + }; + pitchCenter = { + x: right, + y: boundsCenter.y, + z: boundsCenter.z + }; + rollCenter = { + x: boundsCenter.x, + y: boundsCenter.y, + z: far + }; + + + Overlays.editOverlay(pitchHandle, { + url: ROTATE_ARROW_WEST_SOUTH_URL + }); + Overlays.editOverlay(rollHandle, { + url: ROTATE_ARROW_WEST_SOUTH_URL + }); - Overlays.editOverlay(pitchHandle, { url: ROTATE_ARROW_WEST_SOUTH_URL }); - Overlays.editOverlay(rollHandle, { url: ROTATE_ARROW_WEST_SOUTH_URL }); - } else { - - yawHandleRotation = Quat.fromVec3Degrees({ x: 270, y: 0, z: 0 }); - pitchHandleRotation = Quat.fromVec3Degrees({ x: 180, y: 270, z: 0 }); - rollHandleRotation = Quat.fromVec3Degrees({ x: 0, y: 0, z: 90 }); - yawNormal = { x: 0, y: 1, z: 0 }; - pitchNormal = { x: 1, y: 0, z: 0 }; - rollNormal = { x: 0, y: 0, z: 1 }; + yawHandleRotation = Quat.fromVec3Degrees({ + x: 270, + y: 0, + z: 0 + }); + pitchHandleRotation = Quat.fromVec3Degrees({ + x: 180, + y: 270, + z: 0 + }); + rollHandleRotation = Quat.fromVec3Degrees({ + x: 0, + y: 0, + z: 90 + }); + + yawNormal = { + x: 0, + y: 1, + z: 0 + }; + pitchNormal = { + x: 1, + y: 0, + z: 0 + }; + rollNormal = { + x: 0, + y: 0, + z: 1 + }; - yawCorner = { x: left + rotateHandleOffset, - y: bottom - rotateHandleOffset, - z: far + rotateHandleOffset }; + yawCorner = { + x: left + rotateHandleOffset, + y: bottom - rotateHandleOffset, + z: far + rotateHandleOffset + }; - pitchCorner = { x: right - rotateHandleOffset, - y: top + rotateHandleOffset, - z: far + rotateHandleOffset }; + pitchCorner = { + x: right - rotateHandleOffset, + y: top + rotateHandleOffset, + z: far + rotateHandleOffset + }; - rollCorner = { x: left + rotateHandleOffset, - y: top + rotateHandleOffset, - z: near - rotateHandleOffset}; + rollCorner = { + x: left + rotateHandleOffset, + y: top + rotateHandleOffset, + z: near - rotateHandleOffset + }; - yawCenter = { x: boundsCenter.x, y: bottom, z: boundsCenter.z }; - pitchCenter = { x: right, y: boundsCenter.y, z: boundsCenter.z }; - rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near}; + yawCenter = { + x: boundsCenter.x, + y: bottom, + z: boundsCenter.z + }; + pitchCenter = { + x: right, + y: boundsCenter.y, + z: boundsCenter.z + }; + rollCenter = { + x: boundsCenter.x, + y: boundsCenter.y, + z: near + }; - Overlays.editOverlay(pitchHandle, { url: ROTATE_ARROW_WEST_NORTH_URL }); - Overlays.editOverlay(rollHandle, { url: ROTATE_ARROW_WEST_NORTH_URL }); + Overlays.editOverlay(pitchHandle, { + url: ROTATE_ARROW_WEST_NORTH_URL + }); + Overlays.editOverlay(rollHandle, { + url: ROTATE_ARROW_WEST_NORTH_URL + }); } } else { - + // must be BLF or BLN if (cameraPosition.z < objectCenter.z) { - - yawHandleRotation = Quat.fromVec3Degrees({ x: 270, y: 180, z: 0 }); - pitchHandleRotation = Quat.fromVec3Degrees({ x: 90, y: 0, z: 90 }); - rollHandleRotation = Quat.fromVec3Degrees({ x: 0, y: 0, z: 180 }); - yawNormal = { x: 0, y: 1, z: 0 }; - pitchNormal = { x: 1, y: 0, z: 0 }; - rollNormal = { x: 0, y: 0, z: 1 }; + yawHandleRotation = Quat.fromVec3Degrees({ + x: 270, + y: 180, + z: 0 + }); + pitchHandleRotation = Quat.fromVec3Degrees({ + x: 90, + y: 0, + z: 90 + }); + rollHandleRotation = Quat.fromVec3Degrees({ + x: 0, + y: 0, + z: 180 + }); - yawCorner = { x: right - rotateHandleOffset, - y: bottom - rotateHandleOffset, - z: near - rotateHandleOffset }; + yawNormal = { + x: 0, + y: 1, + z: 0 + }; + pitchNormal = { + x: 1, + y: 0, + z: 0 + }; + rollNormal = { + x: 0, + y: 0, + z: 1 + }; - pitchCorner = { x: left + rotateHandleOffset, - y: top + rotateHandleOffset, - z: near - rotateHandleOffset }; + yawCorner = { + x: right - rotateHandleOffset, + y: bottom - rotateHandleOffset, + z: near - rotateHandleOffset + }; - rollCorner = { x: right - rotateHandleOffset, - y: top + rotateHandleOffset, - z: far + rotateHandleOffset}; + pitchCorner = { + x: left + rotateHandleOffset, + y: top + rotateHandleOffset, + z: near - rotateHandleOffset + }; - yawCenter = { x: boundsCenter.x, y: bottom, z: boundsCenter.z }; - pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z }; - rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: far}; + rollCorner = { + x: right - rotateHandleOffset, + y: top + rotateHandleOffset, + z: far + rotateHandleOffset + }; - Overlays.editOverlay(pitchHandle, { url: ROTATE_ARROW_WEST_NORTH_URL }); - Overlays.editOverlay(rollHandle, { url: ROTATE_ARROW_WEST_NORTH_URL }); + yawCenter = { + x: boundsCenter.x, + y: bottom, + z: boundsCenter.z + }; + pitchCenter = { + x: left, + y: boundsCenter.y, + z: boundsCenter.z + }; + rollCenter = { + x: boundsCenter.x, + y: boundsCenter.y, + z: far + }; + + Overlays.editOverlay(pitchHandle, { + url: ROTATE_ARROW_WEST_NORTH_URL + }); + Overlays.editOverlay(rollHandle, { + url: ROTATE_ARROW_WEST_NORTH_URL + }); } else { - - yawHandleRotation = Quat.fromVec3Degrees({ x: 270, y: 270, z: 0 }); - pitchHandleRotation = Quat.fromVec3Degrees({ x: 180, y: 270, z: 0 }); - rollHandleRotation = Quat.fromVec3Degrees({ x: 0, y: 0, z: 180 }); - yawNormal = { x: 0, y: 1, z: 0 }; - rollNormal = { x: 0, y: 0, z: 1 }; - pitchNormal = { x: 1, y: 0, z: 0 }; + yawHandleRotation = Quat.fromVec3Degrees({ + x: 270, + y: 270, + z: 0 + }); + pitchHandleRotation = Quat.fromVec3Degrees({ + x: 180, + y: 270, + z: 0 + }); + rollHandleRotation = Quat.fromVec3Degrees({ + x: 0, + y: 0, + z: 180 + }); - yawCorner = { x: right - rotateHandleOffset, - y: bottom - rotateHandleOffset, - z: far + rotateHandleOffset }; + yawNormal = { + x: 0, + y: 1, + z: 0 + }; + rollNormal = { + x: 0, + y: 0, + z: 1 + }; + pitchNormal = { + x: 1, + y: 0, + z: 0 + }; - rollCorner = { x: right - rotateHandleOffset, - y: top + rotateHandleOffset, - z: near - rotateHandleOffset }; + yawCorner = { + x: right - rotateHandleOffset, + y: bottom - rotateHandleOffset, + z: far + rotateHandleOffset + }; - pitchCorner = { x: left + rotateHandleOffset, - y: top + rotateHandleOffset, - z: far + rotateHandleOffset}; + rollCorner = { + x: right - rotateHandleOffset, + y: top + rotateHandleOffset, + z: near - rotateHandleOffset + }; - yawCenter = { x: boundsCenter.x, y: bottom, z: boundsCenter.z }; - rollCenter = { x: boundsCenter.x, y: boundsCenter.y, z: near }; - pitchCenter = { x: left, y: boundsCenter.y, z: boundsCenter.z}; + pitchCorner = { + x: left + rotateHandleOffset, + y: top + rotateHandleOffset, + z: far + rotateHandleOffset + }; - Overlays.editOverlay(pitchHandle, { url: ROTATE_ARROW_WEST_NORTH_URL }); - Overlays.editOverlay(rollHandle, { url: ROTATE_ARROW_WEST_NORTH_URL }); + yawCenter = { + x: boundsCenter.x, + y: bottom, + z: boundsCenter.z + }; + rollCenter = { + x: boundsCenter.x, + y: boundsCenter.y, + z: near + }; + pitchCenter = { + x: left, + y: boundsCenter.y, + z: boundsCenter.z + }; + + Overlays.editOverlay(pitchHandle, { + url: ROTATE_ARROW_WEST_NORTH_URL + }); + Overlays.editOverlay(rollHandle, { + url: ROTATE_ARROW_WEST_NORTH_URL + }); } } - + var rotateHandlesVisible = true; var rotationOverlaysVisible = false; var translateHandlesVisible = true; @@ -984,20 +1457,38 @@ SelectionDisplay = (function () { rotateHandlesVisible = false; translateHandlesVisible = false; } - + var rotation = selectionManager.worldRotation; var dimensions = selectionManager.worldDimensions; var position = selectionManager.worldPosition; - - Overlays.editOverlay(rotateOverlayTarget, { visible: rotationOverlaysVisible }); - Overlays.editOverlay(rotateZeroOverlay, { visible: rotationOverlaysVisible }); - Overlays.editOverlay(rotateCurrentOverlay, { visible: rotationOverlaysVisible }); + + Overlays.editOverlay(rotateOverlayTarget, { + visible: rotationOverlaysVisible + }); + Overlays.editOverlay(rotateZeroOverlay, { + visible: rotationOverlaysVisible + }); + Overlays.editOverlay(rotateCurrentOverlay, { + visible: rotationOverlaysVisible + }); // TODO: we have not implemented the rotating handle/controls yet... so for now, these handles are hidden - Overlays.editOverlay(yawHandle, { visible: rotateHandlesVisible, position: yawCorner, rotation: yawHandleRotation}); - Overlays.editOverlay(pitchHandle, { visible: rotateHandlesVisible, position: pitchCorner, rotation: pitchHandleRotation}); - Overlays.editOverlay(rollHandle, { visible: rotateHandlesVisible, position: rollCorner, rotation: rollHandleRotation}); + Overlays.editOverlay(yawHandle, { + visible: rotateHandlesVisible, + position: yawCorner, + rotation: yawHandleRotation + }); + Overlays.editOverlay(pitchHandle, { + visible: rotateHandlesVisible, + position: pitchCorner, + rotation: pitchHandleRotation + }); + Overlays.editOverlay(rollHandle, { + visible: rotateHandlesVisible, + position: rollCorner, + rotation: rollHandleRotation + }); }; that.setSpaceMode = function(newSpaceMode) { @@ -1016,8 +1507,7 @@ SelectionDisplay = (function () { that.updateHandles(); }; - that.unselectAll = function () { - }; + that.unselectAll = function() {}; that.updateHandles = function() { if (SelectionManager.selections.length == 0) { @@ -1061,34 +1551,138 @@ SelectionDisplay = (function () { var worldTop = SelectionManager.worldDimensions.y / 2; - var LBN = { x: left, y: bottom, z: near }; - var RBN = { x: right, y: bottom, z: near }; - var LBF = { x: left, y: bottom, z: far }; - var RBF = { x: right, y: bottom, z: far }; - var LTN = { x: left, y: top, z: near }; - var RTN = { x: right, y: top, z: near }; - var LTF = { x: left, y: top, z: far }; - var RTF = { x: right, y: top, z: far }; + var LBN = { + x: left, + y: bottom, + z: near + }; + var RBN = { + x: right, + y: bottom, + z: near + }; + var LBF = { + x: left, + y: bottom, + z: far + }; + var RBF = { + x: right, + y: bottom, + z: far + }; + var LTN = { + x: left, + y: top, + z: near + }; + var RTN = { + x: right, + y: top, + z: near + }; + var LTF = { + x: left, + y: top, + z: far + }; + var RTF = { + x: right, + y: top, + z: far + }; - var TOP = { x: center.x, y: top, z: center.z }; - var BOTTOM = { x: center.x, y: bottom, z: center.z }; - var LEFT = { x: left, y: center.y, z: center.z }; - var RIGHT = { x: right, y: center.y, z: center.z }; - var NEAR = { x: center.x, y: center.y, z: near }; - var FAR = { x: center.x, y: center.y, z: far }; + var TOP = { + x: center.x, + y: top, + z: center.z + }; + var BOTTOM = { + x: center.x, + y: bottom, + z: center.z + }; + var LEFT = { + x: left, + y: center.y, + z: center.z + }; + var RIGHT = { + x: right, + y: center.y, + z: center.z + }; + var NEAR = { + x: center.x, + y: center.y, + z: near + }; + var FAR = { + x: center.x, + y: center.y, + z: far + }; - var EdgeTR = { x: right, y: top, z: center.z }; - var EdgeTL = { x: left, y: top, z: center.z }; - var EdgeTF = { x: center.x, y: top, z: front }; - var EdgeTN = { x: center.x, y: top, z: near }; - var EdgeBR = { x: right, y: bottom, z: center.z }; - var EdgeBL = { x: left, y: bottom, z: center.z }; - var EdgeBF = { x: center.x, y: bottom, z: front }; - var EdgeBN = { x: center.x, y: bottom, z: near }; - var EdgeNR = { x: right, y: center.y, z: near }; - var EdgeNL = { x: left, y: center.y, z: near }; - var EdgeFR = { x: right, y: center.y, z: front }; - var EdgeFL = { x: left, y: center.y, z: front }; + var EdgeTR = { + x: right, + y: top, + z: center.z + }; + var EdgeTL = { + x: left, + y: top, + z: center.z + }; + var EdgeTF = { + x: center.x, + y: top, + z: front + }; + var EdgeTN = { + x: center.x, + y: top, + z: near + }; + var EdgeBR = { + x: right, + y: bottom, + z: center.z + }; + var EdgeBL = { + x: left, + y: bottom, + z: center.z + }; + var EdgeBF = { + x: center.x, + y: bottom, + z: front + }; + var EdgeBN = { + x: center.x, + y: bottom, + z: near + }; + var EdgeNR = { + x: right, + y: center.y, + z: near + }; + var EdgeNL = { + x: left, + y: center.y, + z: near + }; + var EdgeFR = { + x: right, + y: center.y, + z: front + }; + var EdgeFL = { + x: left, + y: center.y, + z: front + }; LBN = Vec3.multiplyQbyV(rotation, LBN); RBN = Vec3.multiplyQbyV(rotation, RBN); @@ -1151,7 +1745,7 @@ SelectionDisplay = (function () { var stretchHandlesVisible = spaceMode == SPACE_LOCAL; var extendedStretchHandlesVisible = stretchHandlesVisible && showExtendedStretchHandles; - if (selectionManager.selections.length == 1 ) { + if (selectionManager.selections.length == 1) { var properties = Entities.getEntityProperties(selectionManager.selections[0]); if (properties.type == "Light" && properties.isSpotlight == true) { var stretchHandlesVisible = false; @@ -1190,7 +1784,11 @@ SelectionDisplay = (function () { }); Overlays.editOverlay(grabberSpotLightCircle, { position: NEAR, - dimensions: { x: distance, y: distance, z: 1 }, + dimensions: { + x: distance, + y: distance, + z: 1 + }, lineWidth: 1.5, rotation: rotation, visible: true, @@ -1217,15 +1815,33 @@ SelectionDisplay = (function () { visible: true, }); - Overlays.editOverlay(grabberPointLightCircleX, { visible: false }); - Overlays.editOverlay(grabberPointLightCircleY, { visible: false }); - Overlays.editOverlay(grabberPointLightCircleZ, { visible: false }); - Overlays.editOverlay(grabberPointLightT, { visible: false }); - Overlays.editOverlay(grabberPointLightB, { visible: false }); - Overlays.editOverlay(grabberPointLightL, { visible: false }); - Overlays.editOverlay(grabberPointLightR, { visible: false }); - Overlays.editOverlay(grabberPointLightF, { visible: false }); - Overlays.editOverlay(grabberPointLightN, { visible: false }); + Overlays.editOverlay(grabberPointLightCircleX, { + visible: false + }); + Overlays.editOverlay(grabberPointLightCircleY, { + visible: false + }); + Overlays.editOverlay(grabberPointLightCircleZ, { + visible: false + }); + Overlays.editOverlay(grabberPointLightT, { + visible: false + }); + Overlays.editOverlay(grabberPointLightB, { + visible: false + }); + Overlays.editOverlay(grabberPointLightL, { + visible: false + }); + Overlays.editOverlay(grabberPointLightR, { + visible: false + }); + Overlays.editOverlay(grabberPointLightF, { + visible: false + }); + Overlays.editOverlay(grabberPointLightN, { + visible: false + }); } else if (properties.type == "Light" && properties.isSpotlight == false) { var stretchHandlesVisible = false; var extendedStretchHandlesVisible = false; @@ -1262,75 +1878,203 @@ SelectionDisplay = (function () { Overlays.editOverlay(grabberPointLightCircleX, { position: position, rotation: Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(0, 90, 0)), - dimensions: { x: properties.dimensions.z / 2.0, y: properties.dimensions.z / 2.0, z: 1 }, + dimensions: { + x: properties.dimensions.z / 2.0, + y: properties.dimensions.z / 2.0, + z: 1 + }, visible: true, }); Overlays.editOverlay(grabberPointLightCircleY, { position: position, rotation: Quat.multiply(rotation, Quat.fromPitchYawRollDegrees(90, 0, 0)), - dimensions: { x: properties.dimensions.z / 2.0, y: properties.dimensions.z / 2.0, z: 1 }, + dimensions: { + x: properties.dimensions.z / 2.0, + y: properties.dimensions.z / 2.0, + z: 1 + }, visible: true, }); Overlays.editOverlay(grabberPointLightCircleZ, { position: position, rotation: rotation, - dimensions: { x: properties.dimensions.z / 2.0, y: properties.dimensions.z / 2.0, z: 1 }, + dimensions: { + x: properties.dimensions.z / 2.0, + y: properties.dimensions.z / 2.0, + z: 1 + }, visible: true, }); - Overlays.editOverlay(grabberSpotLightRadius, { visible: false }); - Overlays.editOverlay(grabberSpotLightL, { visible: false }); - Overlays.editOverlay(grabberSpotLightR, { visible: false }); - Overlays.editOverlay(grabberSpotLightT, { visible: false }); - Overlays.editOverlay(grabberSpotLightB, { visible: false }); - Overlays.editOverlay(grabberSpotLightCircle, { visible: false }); - Overlays.editOverlay(grabberSpotLightLineL, { visible: false }); - Overlays.editOverlay(grabberSpotLightLineR, { visible: false }); - Overlays.editOverlay(grabberSpotLightLineT, { visible: false }); - Overlays.editOverlay(grabberSpotLightLineB, { visible: false }); + Overlays.editOverlay(grabberSpotLightRadius, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightL, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightR, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightT, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightB, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightCircle, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightLineL, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightLineR, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightLineT, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightLineB, { + visible: false + }); } else { - Overlays.editOverlay(grabberSpotLightCenter, { visible: false }); - Overlays.editOverlay(grabberSpotLightRadius, { visible: false }); - Overlays.editOverlay(grabberSpotLightL, { visible: false }); - Overlays.editOverlay(grabberSpotLightR, { visible: false }); - Overlays.editOverlay(grabberSpotLightT, { visible: false }); - Overlays.editOverlay(grabberSpotLightB, { visible: false }); - Overlays.editOverlay(grabberSpotLightCircle, { visible: false }); - Overlays.editOverlay(grabberSpotLightLineL, { visible: false }); - Overlays.editOverlay(grabberSpotLightLineR, { visible: false }); - Overlays.editOverlay(grabberSpotLightLineT, { visible: false }); - Overlays.editOverlay(grabberSpotLightLineB, { visible: false }); + Overlays.editOverlay(grabberSpotLightCenter, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightRadius, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightL, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightR, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightT, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightB, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightCircle, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightLineL, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightLineR, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightLineT, { + visible: false + }); + Overlays.editOverlay(grabberSpotLightLineB, { + visible: false + }); - Overlays.editOverlay(grabberPointLightCircleX, { visible: false }); - Overlays.editOverlay(grabberPointLightCircleY, { visible: false }); - Overlays.editOverlay(grabberPointLightCircleZ, { visible: false }); - Overlays.editOverlay(grabberPointLightT, { visible: false }); - Overlays.editOverlay(grabberPointLightB, { visible: false }); - Overlays.editOverlay(grabberPointLightL, { visible: false }); - Overlays.editOverlay(grabberPointLightR, { visible: false }); - Overlays.editOverlay(grabberPointLightF, { visible: false }); - Overlays.editOverlay(grabberPointLightN, { visible: false }); + Overlays.editOverlay(grabberPointLightCircleX, { + visible: false + }); + Overlays.editOverlay(grabberPointLightCircleY, { + visible: false + }); + Overlays.editOverlay(grabberPointLightCircleZ, { + visible: false + }); + Overlays.editOverlay(grabberPointLightT, { + visible: false + }); + Overlays.editOverlay(grabberPointLightB, { + visible: false + }); + Overlays.editOverlay(grabberPointLightL, { + visible: false + }); + Overlays.editOverlay(grabberPointLightR, { + visible: false + }); + Overlays.editOverlay(grabberPointLightF, { + visible: false + }); + Overlays.editOverlay(grabberPointLightN, { + visible: false + }); } } - Overlays.editOverlay(grabberLBN, { visible: stretchHandlesVisible, rotation: rotation, position: LBN }); - Overlays.editOverlay(grabberRBN, { visible: stretchHandlesVisible, rotation: rotation, position: RBN }); - Overlays.editOverlay(grabberLBF, { visible: stretchHandlesVisible, rotation: rotation, position: LBF }); - Overlays.editOverlay(grabberRBF, { visible: stretchHandlesVisible, rotation: rotation, position: RBF }); + Overlays.editOverlay(grabberLBN, { + visible: stretchHandlesVisible, + rotation: rotation, + position: LBN + }); + Overlays.editOverlay(grabberRBN, { + visible: stretchHandlesVisible, + rotation: rotation, + position: RBN + }); + Overlays.editOverlay(grabberLBF, { + visible: stretchHandlesVisible, + rotation: rotation, + position: LBF + }); + Overlays.editOverlay(grabberRBF, { + visible: stretchHandlesVisible, + rotation: rotation, + position: RBF + }); - Overlays.editOverlay(grabberLTN, { visible: extendedStretchHandlesVisible, rotation: rotation, position: LTN }); - Overlays.editOverlay(grabberRTN, { visible: extendedStretchHandlesVisible, rotation: rotation, position: RTN }); - Overlays.editOverlay(grabberLTF, { visible: extendedStretchHandlesVisible, rotation: rotation, position: LTF }); - Overlays.editOverlay(grabberRTF, { visible: extendedStretchHandlesVisible, rotation: rotation, position: RTF }); + Overlays.editOverlay(grabberLTN, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: LTN + }); + Overlays.editOverlay(grabberRTN, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: RTN + }); + Overlays.editOverlay(grabberLTF, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: LTF + }); + Overlays.editOverlay(grabberRTF, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: RTF + }); - Overlays.editOverlay(grabberTOP, { visible: stretchHandlesVisible, rotation: rotation, position: TOP }); - Overlays.editOverlay(grabberBOTTOM, { visible: stretchHandlesVisible, rotation: rotation, position: BOTTOM }); - Overlays.editOverlay(grabberLEFT, { visible: extendedStretchHandlesVisible, rotation: rotation, position: LEFT }); - Overlays.editOverlay(grabberRIGHT, { visible: extendedStretchHandlesVisible, rotation: rotation, position: RIGHT }); - Overlays.editOverlay(grabberNEAR, { visible: extendedStretchHandlesVisible, rotation: rotation, position: NEAR }); - Overlays.editOverlay(grabberFAR, { visible: extendedStretchHandlesVisible, rotation: rotation, position: FAR }); + Overlays.editOverlay(grabberTOP, { + visible: stretchHandlesVisible, + rotation: rotation, + position: TOP + }); + Overlays.editOverlay(grabberBOTTOM, { + visible: stretchHandlesVisible, + rotation: rotation, + position: BOTTOM + }); + Overlays.editOverlay(grabberLEFT, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: LEFT + }); + Overlays.editOverlay(grabberRIGHT, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: RIGHT + }); + Overlays.editOverlay(grabberNEAR, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: NEAR + }); + Overlays.editOverlay(grabberFAR, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: FAR + }); var boxPosition = Vec3.multiplyQbyV(rotation, center); boxPosition = Vec3.sum(position, boxPosition); @@ -1346,9 +2090,17 @@ SelectionDisplay = (function () { for (var i = 0; i < overlaysNeeded; i++) { selectionBoxes.push( Overlays.addOverlay("cube", { - position: { x: 0, y: 0, z: 0 }, + position: { + x: 0, + y: 0, + z: 0 + }, size: 1, - color: { red: 255, green: 153, blue: 0 }, + color: { + red: 255, + green: 153, + blue: 0 + }, alpha: 1, solid: false, visible: false, @@ -1366,7 +2118,11 @@ SelectionDisplay = (function () { // Adjust overlay position to take registrationPoint into account // centeredRP = registrationPoint with range [-0.5, 0.5] - var centeredRP = Vec3.subtract(properties.registrationPoint, { x: 0.5, y: 0.5, z: 0.5 }); + var centeredRP = Vec3.subtract(properties.registrationPoint, { + x: 0.5, + y: 0.5, + z: 0.5 + }); var offset = vec3Mult(properties.dimensions, centeredRP); offset = Vec3.multiply(-1, offset); offset = Vec3.multiplyQbyV(properties.rotation, offset); @@ -1382,25 +2138,81 @@ SelectionDisplay = (function () { } // Hide any remaining selection boxes for (; i < selectionBoxes.length; i++) { - Overlays.editOverlay(selectionBoxes[i], { visible: false }); + Overlays.editOverlay(selectionBoxes[i], { + visible: false + }); } - Overlays.editOverlay(grabberEdgeTR, { visible: extendedStretchHandlesVisible, rotation: rotation, position: EdgeTR }); - Overlays.editOverlay(grabberEdgeTL, { visible: extendedStretchHandlesVisible, rotation: rotation, position: EdgeTL }); - Overlays.editOverlay(grabberEdgeTF, { visible: extendedStretchHandlesVisible, rotation: rotation, position: EdgeTF }); - Overlays.editOverlay(grabberEdgeTN, { visible: extendedStretchHandlesVisible, rotation: rotation, position: EdgeTN }); - Overlays.editOverlay(grabberEdgeBR, { visible: stretchHandlesVisible, rotation: rotation, position: EdgeBR }); - Overlays.editOverlay(grabberEdgeBL, { visible: stretchHandlesVisible, rotation: rotation, position: EdgeBL }); - Overlays.editOverlay(grabberEdgeBF, { visible: stretchHandlesVisible, rotation: rotation, position: EdgeBF }); - Overlays.editOverlay(grabberEdgeBN, { visible: stretchHandlesVisible, rotation: rotation, position: EdgeBN }); - Overlays.editOverlay(grabberEdgeNR, { visible: extendedStretchHandlesVisible, rotation: rotation, position: EdgeNR }); - Overlays.editOverlay(grabberEdgeNL, { visible: extendedStretchHandlesVisible, rotation: rotation, position: EdgeNL }); - Overlays.editOverlay(grabberEdgeFR, { visible: extendedStretchHandlesVisible, rotation: rotation, position: EdgeFR }); - Overlays.editOverlay(grabberEdgeFL, { visible: extendedStretchHandlesVisible, rotation: rotation, position: EdgeFL }); + Overlays.editOverlay(grabberEdgeTR, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: EdgeTR + }); + Overlays.editOverlay(grabberEdgeTL, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: EdgeTL + }); + Overlays.editOverlay(grabberEdgeTF, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: EdgeTF + }); + Overlays.editOverlay(grabberEdgeTN, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: EdgeTN + }); + Overlays.editOverlay(grabberEdgeBR, { + visible: stretchHandlesVisible, + rotation: rotation, + position: EdgeBR + }); + Overlays.editOverlay(grabberEdgeBL, { + visible: stretchHandlesVisible, + rotation: rotation, + position: EdgeBL + }); + Overlays.editOverlay(grabberEdgeBF, { + visible: stretchHandlesVisible, + rotation: rotation, + position: EdgeBF + }); + Overlays.editOverlay(grabberEdgeBN, { + visible: stretchHandlesVisible, + rotation: rotation, + position: EdgeBN + }); + Overlays.editOverlay(grabberEdgeNR, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: EdgeNR + }); + Overlays.editOverlay(grabberEdgeNL, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: EdgeNL + }); + Overlays.editOverlay(grabberEdgeFR, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: EdgeFR + }); + Overlays.editOverlay(grabberEdgeFL, { + visible: extendedStretchHandlesVisible, + rotation: rotation, + position: EdgeFL + }); var grabberMoveUpOffset = 0.1; - grabberMoveUpPosition = { x: position.x, y: position.y + worldTop + grabberMoveUpOffset, z: position.z } - Overlays.editOverlay(grabberMoveUp, { visible: activeTool == null || mode == "TRANSLATE_UP_DOWN" }); + grabberMoveUpPosition = { + x: position.x, + y: position.y + worldTop + grabberMoveUpOffset, + z: position.z + } + Overlays.editOverlay(grabberMoveUp, { + visible: activeTool == null || mode == "TRANSLATE_UP_DOWN" + }); Overlays.editOverlay(baseOfEntityProjectionOverlay, { visible: mode != "ROTATE_YAW" && mode != "ROTATE_PITCH" && mode != "ROTATE_ROLL", @@ -1423,16 +2235,19 @@ SelectionDisplay = (function () { that.setOverlaysVisible = function(isVisible) { var length = allOverlays.length; for (var i = 0; i < length; i++) { - Overlays.editOverlay(allOverlays[i], { visible: isVisible }); + Overlays.editOverlay(allOverlays[i], { + visible: isVisible + }); } length = selectionBoxes.length; for (var i = 0; i < length; i++) { - Overlays.editOverlay(selectionBoxes[i], { visible: isVisible }); + Overlays.editOverlay(selectionBoxes[i], { + visible: isVisible + }); } }; - that.unselect = function (entityID) { - }; + that.unselect = function(entityID) {}; var initialXZPick = null; var isConstrained = false; @@ -1447,7 +2262,11 @@ SelectionDisplay = (function () { var dimensions = SelectionManager.worldDimensions; var pickRay = Camera.computePickRay(event.x, event.y); - initialXZPick = rayPlaneIntersection(pickRay, startPosition, { x: 0, y: 1, z: 0 }); + initialXZPick = rayPlaneIntersection(pickRay, startPosition, { + x: 0, + y: 1, + z: 0 + }); // Duplicate entities if alt is pressed. This will make a // copy of the selected entities and move the _original_ entities, not @@ -1473,13 +2292,21 @@ SelectionDisplay = (function () { onEnd: function(event, reason) { pushCommandForSelections(duplicatedEntityIDs); - Overlays.editOverlay(xRailOverlay, { visible: false }); - Overlays.editOverlay(zRailOverlay, { visible: false }); + Overlays.editOverlay(xRailOverlay, { + visible: false + }); + Overlays.editOverlay(zRailOverlay, { + visible: false + }); }, onMove: function(event) { pickRay = Camera.computePickRay(event.x, event.y); - var pick = rayPlaneIntersection(pickRay, SelectionManager.worldPosition, { x: 0, y: 1, z: 0 }); + var pick = rayPlaneIntersection(pickRay, SelectionManager.worldPosition, { + x: 0, + y: 1, + z: 0 + }); var vector = Vec3.subtract(pick, initialXZPick); // If shifted, constrain to one axis @@ -1490,19 +2317,49 @@ SelectionDisplay = (function () { vector.x = 0; } if (!isConstrained) { - Overlays.editOverlay(xRailOverlay, { visible: true }); - var xStart = Vec3.sum(startPosition, { x: -10000, y: 0, z: 0 }); - var xEnd = Vec3.sum(startPosition, { x: 10000, y: 0, z: 0 }); - var zStart = Vec3.sum(startPosition, { x: 0, y: 0, z: -10000 }); - var zEnd = Vec3.sum(startPosition, { x: 0, y: 0, z: 10000 }); - Overlays.editOverlay(xRailOverlay, { start: xStart, end: xEnd, visible: true }); - Overlays.editOverlay(zRailOverlay, { start: zStart, end: zEnd, visible: true }); + Overlays.editOverlay(xRailOverlay, { + visible: true + }); + var xStart = Vec3.sum(startPosition, { + x: -10000, + y: 0, + z: 0 + }); + var xEnd = Vec3.sum(startPosition, { + x: 10000, + y: 0, + z: 0 + }); + var zStart = Vec3.sum(startPosition, { + x: 0, + y: 0, + z: -10000 + }); + var zEnd = Vec3.sum(startPosition, { + x: 0, + y: 0, + z: 10000 + }); + Overlays.editOverlay(xRailOverlay, { + start: xStart, + end: xEnd, + visible: true + }); + Overlays.editOverlay(zRailOverlay, { + start: zStart, + end: zEnd, + visible: true + }); isConstrained = true; } } else { if (isConstrained) { - Overlays.editOverlay(xRailOverlay, { visible: false }); - Overlays.editOverlay(zRailOverlay, { visible: false }); + Overlays.editOverlay(xRailOverlay, { + visible: false + }); + Overlays.editOverlay(zRailOverlay, { + visible: false + }); isConstrained = false; } } @@ -1510,14 +2367,18 @@ SelectionDisplay = (function () { constrainMajorOnly = event.isControl; var cornerPosition = Vec3.sum(startPosition, Vec3.multiply(-0.5, selectionManager.worldDimensions)); vector = Vec3.subtract( - grid.snapToGrid(Vec3.sum(cornerPosition, vector), constrainMajorOnly), - cornerPosition); + grid.snapToGrid(Vec3.sum(cornerPosition, vector), constrainMajorOnly), + cornerPosition); var wantDebug = false; for (var i = 0; i < SelectionManager.selections.length; i++) { var properties = SelectionManager.savedProperties[SelectionManager.selections[i]]; - var newPosition = Vec3.sum(properties.position, { x: vector.x, y: 0, z: vector.z }); + var newPosition = Vec3.sum(properties.position, { + x: vector.x, + y: 0, + z: vector.z + }); Entities.editEntity(SelectionManager.selections[i], { position: newPosition, }); @@ -1533,7 +2394,7 @@ SelectionDisplay = (function () { SelectionManager._update(); } }; - + var lastXYPick = null var upDownPickNormal = null; addGrabberTool(grabberMoveUp, { @@ -1579,11 +2440,11 @@ SelectionDisplay = (function () { var vector = Vec3.subtract(newIntersection, lastXYPick); vector = grid.snapToGrid(vector); - + // we only care about the Y axis vector.x = 0; vector.z = 0; - + var wantDebug = false; if (wantDebug) { print("translateUpDown... "); @@ -1609,12 +2470,16 @@ SelectionDisplay = (function () { }); var vec3Mult = function(v1, v2) { - return { x: v1.x * v2.x, y: v1.y * v2.y, z: v1.z * v2.z }; - } - // stretchMode - name of mode - // direction - direction to stretch in - // pivot - point to use as a pivot - // offset - the position of the overlay tool relative to the selections center position + return { + x: v1.x * v2.x, + y: v1.y * v2.y, + z: v1.z * v2.z + }; + } + // stretchMode - name of mode + // direction - direction to stretch in + // pivot - point to use as a pivot + // offset - the position of the overlay tool relative to the selections center position var makeStretchTool = function(stretchMode, direction, pivot, offset, customOnMove) { var signs = { x: direction.x < 0 ? -1 : (direction.x > 0 ? 1 : 0), @@ -1659,7 +2524,11 @@ SelectionDisplay = (function () { } // Modify range of registrationPoint to be [-0.5, 0.5] - var centeredRP = Vec3.subtract(registrationPoint, { x: 0.5, y: 0.5, z: 0.5 }); + var centeredRP = Vec3.subtract(registrationPoint, { + x: 0.5, + y: 0.5, + z: 0.5 + }); // Scale pivot to be in the same range as registrationPoint var scaledPivot = Vec3.multiply(0.5, pivot) @@ -1675,9 +2544,17 @@ SelectionDisplay = (function () { pickRayPosition = Vec3.sum(initialPosition, Vec3.multiplyQbyV(rotation, scaledOffsetWorld)); if (numDimensions == 1 && mask.x) { - var start = Vec3.multiplyQbyV(rotation, { x: -10000, y: 0, z: 0 }); + var start = Vec3.multiplyQbyV(rotation, { + x: -10000, + y: 0, + z: 0 + }); start = Vec3.sum(start, properties.position); - var end = Vec3.multiplyQbyV(rotation, { x: 10000, y: 0, z: 0 }); + var end = Vec3.multiplyQbyV(rotation, { + x: 10000, + y: 0, + z: 0 + }); end = Vec3.sum(end, properties.position); Overlays.editOverlay(xRailOverlay, { start: start, @@ -1686,9 +2563,17 @@ SelectionDisplay = (function () { }); } if (numDimensions == 1 && mask.y) { - var start = Vec3.multiplyQbyV(rotation, { x: 0, y: -10000, z: 0 }); + var start = Vec3.multiplyQbyV(rotation, { + x: 0, + y: -10000, + z: 0 + }); start = Vec3.sum(start, properties.position); - var end = Vec3.multiplyQbyV(rotation, { x: 0, y: 10000, z: 0 }); + var end = Vec3.multiplyQbyV(rotation, { + x: 0, + y: 10000, + z: 0 + }); end = Vec3.sum(end, properties.position); Overlays.editOverlay(yRailOverlay, { start: start, @@ -1697,9 +2582,17 @@ SelectionDisplay = (function () { }); } if (numDimensions == 1 && mask.z) { - var start = Vec3.multiplyQbyV(rotation, { x: 0, y: 0, z: -10000 }); + var start = Vec3.multiplyQbyV(rotation, { + x: 0, + y: 0, + z: -10000 + }); start = Vec3.sum(start, properties.position); - var end = Vec3.multiplyQbyV(rotation, { x: 0, y: 0, z: 10000 }); + var end = Vec3.multiplyQbyV(rotation, { + x: 0, + y: 0, + z: 10000 + }); end = Vec3.sum(end, properties.position); Overlays.editOverlay(zRailOverlay, { start: start, @@ -1709,26 +2602,50 @@ SelectionDisplay = (function () { } if (numDimensions == 1) { if (mask.x == 1) { - planeNormal = { x: 0, y: 1, z: 0 }; + planeNormal = { + x: 0, + y: 1, + z: 0 + }; } else if (mask.y == 1) { - planeNormal = { x: 1, y: 0, z: 0 }; + planeNormal = { + x: 1, + y: 0, + z: 0 + }; } else { - planeNormal = { x: 0, y: 1, z: 0 }; + planeNormal = { + x: 0, + y: 1, + z: 0 + }; } } else if (numDimensions == 2) { if (mask.x == 0) { - planeNormal = { x: 1, y: 0, z: 0 }; + planeNormal = { + x: 1, + y: 0, + z: 0 + }; } else if (mask.y == 0) { - planeNormal = { x: 0, y: 1, z: 0 }; + planeNormal = { + x: 0, + y: 1, + z: 0 + }; } else { - planeNormal = { x: 0, y: 0, z: z }; + planeNormal = { + x: 0, + y: 0, + z: z + }; } } planeNormal = Vec3.multiplyQbyV(rotation, planeNormal); var pickRay = Camera.computePickRay(event.x, event.y); lastPick = rayPlaneIntersection(pickRay, - pickRayPosition, - planeNormal); + pickRayPosition, + planeNormal); // Overlays.editOverlay(normalLine, { // start: initialPosition, @@ -1739,9 +2656,15 @@ SelectionDisplay = (function () { }; var onEnd = function(event, reason) { - Overlays.editOverlay(xRailOverlay, { visible: false }); - Overlays.editOverlay(yRailOverlay, { visible: false }); - Overlays.editOverlay(zRailOverlay, { visible: false }); + Overlays.editOverlay(xRailOverlay, { + visible: false + }); + Overlays.editOverlay(yRailOverlay, { + visible: false + }); + Overlays.editOverlay(zRailOverlay, { + visible: false + }); pushCommandForSelections(); }; @@ -1762,8 +2685,8 @@ SelectionDisplay = (function () { var pickRay = Camera.computePickRay(event.x, event.y); newPick = rayPlaneIntersection(pickRay, - pickRayPosition, - planeNormal); + pickRayPosition, + planeNormal); var vector = Vec3.subtract(newPick, lastPick); vector = Vec3.multiplyQbyV(Quat.inverse(rotation), vector); @@ -1798,14 +2721,14 @@ SelectionDisplay = (function () { } else { newDimensions = Vec3.sum(initialDimensions, changeInDimensions); } - + newDimensions.x = Math.max(newDimensions.x, MINIMUM_DIMENSION); newDimensions.y = Math.max(newDimensions.y, MINIMUM_DIMENSION); newDimensions.z = Math.max(newDimensions.z, MINIMUM_DIMENSION); - + var changeInPosition = Vec3.multiplyQbyV(rotation, vec3Mult(deltaPivot, changeInDimensions)); var newPosition = Vec3.sum(initialPosition, changeInPosition); - + for (var i = 0; i < SelectionManager.selections.length; i++) { Entities.editEntity(SelectionManager.selections[i], { position: newPosition, @@ -1882,7 +2805,11 @@ SelectionDisplay = (function () { size = props.dimensions.z + change.z; } - var newDimensions = { x: size, y: size, z: size }; + var newDimensions = { + x: size, + y: size, + z: size + }; Entities.editEntity(selectionManager.selections[0], { dimensions: newDimensions, @@ -1891,47 +2818,411 @@ SelectionDisplay = (function () { SelectionManager._update(); } - addStretchTool(grabberNEAR, "STRETCH_NEAR", { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }); - addStretchTool(grabberFAR, "STRETCH_FAR", { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: 1 }); - addStretchTool(grabberTOP, "STRETCH_TOP", { x: 0, y: -1, z: 0 }, { x: 0, y: -1, z: 0 }, { x: 0, y: 1, z: 0 }); - addStretchTool(grabberBOTTOM, "STRETCH_BOTTOM", { x: 0, y: 1, z: 0 }, { x: 0, y: 1, z: 0 }, { x: 0, y: -1, z: 0 }); - addStretchTool(grabberRIGHT, "STRETCH_RIGHT", { x: -1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }); - addStretchTool(grabberLEFT, "STRETCH_LEFT", { x: 1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }); + addStretchTool(grabberNEAR, "STRETCH_NEAR", { + x: 0, + y: 0, + z: 1 + }, { + x: 0, + y: 0, + z: 1 + }, { + x: 0, + y: 0, + z: -1 + }); + addStretchTool(grabberFAR, "STRETCH_FAR", { + x: 0, + y: 0, + z: -1 + }, { + x: 0, + y: 0, + z: -1 + }, { + x: 0, + y: 0, + z: 1 + }); + addStretchTool(grabberTOP, "STRETCH_TOP", { + x: 0, + y: -1, + z: 0 + }, { + x: 0, + y: -1, + z: 0 + }, { + x: 0, + y: 1, + z: 0 + }); + addStretchTool(grabberBOTTOM, "STRETCH_BOTTOM", { + x: 0, + y: 1, + z: 0 + }, { + x: 0, + y: 1, + z: 0 + }, { + x: 0, + y: -1, + z: 0 + }); + addStretchTool(grabberRIGHT, "STRETCH_RIGHT", { + x: -1, + y: 0, + z: 0 + }, { + x: -1, + y: 0, + z: 0 + }, { + x: 1, + y: 0, + z: 0 + }); + addStretchTool(grabberLEFT, "STRETCH_LEFT", { + x: 1, + y: 0, + z: 0 + }, { + x: 1, + y: 0, + z: 0 + }, { + x: -1, + y: 0, + z: 0 + }); - addStretchTool(grabberSpotLightRadius, "STRETCH_RADIUS", { x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }); - addStretchTool(grabberSpotLightT, "STRETCH_CUTOFF_T", { x: 0, y: 0, z: 0 }, { x: 0, y: -1, z: 0 }, { x: 0, y: 1, z: 0 }, cutoffStretchFunc); - addStretchTool(grabberSpotLightB, "STRETCH_CUTOFF_B", { x: 0, y: 0, z: 0 }, { x: 0, y: 1, z: 0 }, { x: 0, y: -1, z: 0 }, cutoffStretchFunc); - addStretchTool(grabberSpotLightL, "STRETCH_CUTOFF_L", { x: 0, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, cutoffStretchFunc); - addStretchTool(grabberSpotLightR, "STRETCH_CUTOFF_R", { x: 0, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }, cutoffStretchFunc); + addStretchTool(grabberSpotLightRadius, "STRETCH_RADIUS", { + x: 0, + y: 0, + z: 0 + }, { + x: 0, + y: 0, + z: 1 + }, { + x: 0, + y: 0, + z: -1 + }); + addStretchTool(grabberSpotLightT, "STRETCH_CUTOFF_T", { + x: 0, + y: 0, + z: 0 + }, { + x: 0, + y: -1, + z: 0 + }, { + x: 0, + y: 1, + z: 0 + }, cutoffStretchFunc); + addStretchTool(grabberSpotLightB, "STRETCH_CUTOFF_B", { + x: 0, + y: 0, + z: 0 + }, { + x: 0, + y: 1, + z: 0 + }, { + x: 0, + y: -1, + z: 0 + }, cutoffStretchFunc); + addStretchTool(grabberSpotLightL, "STRETCH_CUTOFF_L", { + x: 0, + y: 0, + z: 0 + }, { + x: 1, + y: 0, + z: 0 + }, { + x: -1, + y: 0, + z: 0 + }, cutoffStretchFunc); + addStretchTool(grabberSpotLightR, "STRETCH_CUTOFF_R", { + x: 0, + y: 0, + z: 0 + }, { + x: -1, + y: 0, + z: 0 + }, { + x: 1, + y: 0, + z: 0 + }, cutoffStretchFunc); - addStretchTool(grabberPointLightT, "STRETCH_RADIUS_T", { x: 0, y: 0, z: 0 }, { x: 0, y: -1, z: 0 }, { x: 0, y: 0, z: 1 }, radiusStretchFunc); - addStretchTool(grabberPointLightB, "STRETCH_RADIUS_B", { x: 0, y: 0, z: 0 }, { x: 0, y: 1, z: 0 }, { x: 0, y: 0, z: 1 }, radiusStretchFunc); - addStretchTool(grabberPointLightL, "STRETCH_RADIUS_L", { x: 0, y: 0, z: 0 }, { x: 1, y: 0, z: 0 }, { x: 0, y: 0, z: 1 }, radiusStretchFunc); - addStretchTool(grabberPointLightR, "STRETCH_RADIUS_R", { x: 0, y: 0, z: 0 }, { x: -1, y: 0, z: 0 }, { x: 0, y: 0, z: 1 }, radiusStretchFunc); - addStretchTool(grabberPointLightF, "STRETCH_RADIUS_F", { x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: -1 }, { x: 0, y: 0, z: 1 }, radiusStretchFunc); - addStretchTool(grabberPointLightN, "STRETCH_RADIUS_N", { x: 0, y: 0, z: 0 }, { x: 0, y: 0, z: 1 }, { x: 0, y: 0, z: -1 }, radiusStretchFunc); + addStretchTool(grabberPointLightT, "STRETCH_RADIUS_T", { + x: 0, + y: 0, + z: 0 + }, { + x: 0, + y: -1, + z: 0 + }, { + x: 0, + y: 0, + z: 1 + }, radiusStretchFunc); + addStretchTool(grabberPointLightB, "STRETCH_RADIUS_B", { + x: 0, + y: 0, + z: 0 + }, { + x: 0, + y: 1, + z: 0 + }, { + x: 0, + y: 0, + z: 1 + }, radiusStretchFunc); + addStretchTool(grabberPointLightL, "STRETCH_RADIUS_L", { + x: 0, + y: 0, + z: 0 + }, { + x: 1, + y: 0, + z: 0 + }, { + x: 0, + y: 0, + z: 1 + }, radiusStretchFunc); + addStretchTool(grabberPointLightR, "STRETCH_RADIUS_R", { + x: 0, + y: 0, + z: 0 + }, { + x: -1, + y: 0, + z: 0 + }, { + x: 0, + y: 0, + z: 1 + }, radiusStretchFunc); + addStretchTool(grabberPointLightF, "STRETCH_RADIUS_F", { + x: 0, + y: 0, + z: 0 + }, { + x: 0, + y: 0, + z: -1 + }, { + x: 0, + y: 0, + z: 1 + }, radiusStretchFunc); + addStretchTool(grabberPointLightN, "STRETCH_RADIUS_N", { + x: 0, + y: 0, + z: 0 + }, { + x: 0, + y: 0, + z: 1 + }, { + x: 0, + y: 0, + z: -1 + }, radiusStretchFunc); - addStretchTool(grabberLBN, "STRETCH_LBN", null, {x: 1, y: 0, z: 1}, { x: -1, y: -1, z: -1 }); - addStretchTool(grabberRBN, "STRETCH_RBN", null, {x: -1, y: 0, z: 1}, { x: 1, y: -1, z: -1 }); - addStretchTool(grabberLBF, "STRETCH_LBF", null, {x: 1, y: 0, z: -1}, { x: -1, y: -1, z: 1 }); - addStretchTool(grabberRBF, "STRETCH_RBF", null, {x: -1, y: 0, z: -1}, { x: 1, y: -1, z: 1 }); - addStretchTool(grabberLTN, "STRETCH_LTN", null, {x: 1, y: 0, z: 1}, { x: -1, y: 1, z: -1 }); - addStretchTool(grabberRTN, "STRETCH_RTN", null, {x: -1, y: 0, z: 1}, { x: 1, y: 1, z: -1 }); - addStretchTool(grabberLTF, "STRETCH_LTF", null, {x: 1, y: 0, z: -1}, { x: -1, y: 1, z: 1 }); - addStretchTool(grabberRTF, "STRETCH_RTF", null, {x: -1, y: 0, z: -1}, { x: 1, y: 1, z: 1 }); + addStretchTool(grabberLBN, "STRETCH_LBN", null, { + x: 1, + y: 0, + z: 1 + }, { + x: -1, + y: -1, + z: -1 + }); + addStretchTool(grabberRBN, "STRETCH_RBN", null, { + x: -1, + y: 0, + z: 1 + }, { + x: 1, + y: -1, + z: -1 + }); + addStretchTool(grabberLBF, "STRETCH_LBF", null, { + x: 1, + y: 0, + z: -1 + }, { + x: -1, + y: -1, + z: 1 + }); + addStretchTool(grabberRBF, "STRETCH_RBF", null, { + x: -1, + y: 0, + z: -1 + }, { + x: 1, + y: -1, + z: 1 + }); + addStretchTool(grabberLTN, "STRETCH_LTN", null, { + x: 1, + y: 0, + z: 1 + }, { + x: -1, + y: 1, + z: -1 + }); + addStretchTool(grabberRTN, "STRETCH_RTN", null, { + x: -1, + y: 0, + z: 1 + }, { + x: 1, + y: 1, + z: -1 + }); + addStretchTool(grabberLTF, "STRETCH_LTF", null, { + x: 1, + y: 0, + z: -1 + }, { + x: -1, + y: 1, + z: 1 + }); + addStretchTool(grabberRTF, "STRETCH_RTF", null, { + x: -1, + y: 0, + z: -1 + }, { + x: 1, + y: 1, + z: 1 + }); - addStretchTool(grabberEdgeTR, "STRETCH_EdgeTR", null, {x: 1, y: 1, z: 0}, { x: 1, y: 1, z: 0 }); - addStretchTool(grabberEdgeTL, "STRETCH_EdgeTL", null, {x: -1, y: 1, z: 0}, { x: -1, y: 1, z: 0 }); - addStretchTool(grabberEdgeTF, "STRETCH_EdgeTF", null, {x: 0, y: 1, z: -1}, { x: 0, y: 1, z: -1 }); - addStretchTool(grabberEdgeTN, "STRETCH_EdgeTN", null, {x: 0, y: 1, z: 1}, { x: 0, y: 1, z: 1 }); - addStretchTool(grabberEdgeBR, "STRETCH_EdgeBR", null, {x: -1, y: 0, z: 0}, { x: 1, y: -1, z: 0 }); - addStretchTool(grabberEdgeBL, "STRETCH_EdgeBL", null, {x: 1, y: 0, z: 0}, { x: -1, y: -1, z: 0 }); - addStretchTool(grabberEdgeBF, "STRETCH_EdgeBF", null, {x: 0, y: 0, z: -1}, { x: 0, y: -1, z: -1 }); - addStretchTool(grabberEdgeBN, "STRETCH_EdgeBN", null, {x: 0, y: 0, z: 1}, { x: 0, y: -1, z: 1 }); - addStretchTool(grabberEdgeNR, "STRETCH_EdgeNR", null, {x: -1, y: 0, z: 1}, { x: 1, y: 0, z: -1 }); - addStretchTool(grabberEdgeNL, "STRETCH_EdgeNL", null, {x: 1, y: 0, z: 1}, { x: -1, y: 0, z: -1 }); - addStretchTool(grabberEdgeFR, "STRETCH_EdgeFR", null, {x: -1, y: 0, z: -1}, { x: 1, y: 0, z: 1 }); - addStretchTool(grabberEdgeFL, "STRETCH_EdgeFL", null, {x: 1, y: 0, z: -1}, { x: -1, y: 0, z: 1 }); + addStretchTool(grabberEdgeTR, "STRETCH_EdgeTR", null, { + x: 1, + y: 1, + z: 0 + }, { + x: 1, + y: 1, + z: 0 + }); + addStretchTool(grabberEdgeTL, "STRETCH_EdgeTL", null, { + x: -1, + y: 1, + z: 0 + }, { + x: -1, + y: 1, + z: 0 + }); + addStretchTool(grabberEdgeTF, "STRETCH_EdgeTF", null, { + x: 0, + y: 1, + z: -1 + }, { + x: 0, + y: 1, + z: -1 + }); + addStretchTool(grabberEdgeTN, "STRETCH_EdgeTN", null, { + x: 0, + y: 1, + z: 1 + }, { + x: 0, + y: 1, + z: 1 + }); + addStretchTool(grabberEdgeBR, "STRETCH_EdgeBR", null, { + x: -1, + y: 0, + z: 0 + }, { + x: 1, + y: -1, + z: 0 + }); + addStretchTool(grabberEdgeBL, "STRETCH_EdgeBL", null, { + x: 1, + y: 0, + z: 0 + }, { + x: -1, + y: -1, + z: 0 + }); + addStretchTool(grabberEdgeBF, "STRETCH_EdgeBF", null, { + x: 0, + y: 0, + z: -1 + }, { + x: 0, + y: -1, + z: -1 + }); + addStretchTool(grabberEdgeBN, "STRETCH_EdgeBN", null, { + x: 0, + y: 0, + z: 1 + }, { + x: 0, + y: -1, + z: 1 + }); + addStretchTool(grabberEdgeNR, "STRETCH_EdgeNR", null, { + x: -1, + y: 0, + z: 1 + }, { + x: 1, + y: 0, + z: -1 + }); + addStretchTool(grabberEdgeNL, "STRETCH_EdgeNL", null, { + x: 1, + y: 0, + z: 1 + }, { + x: -1, + y: 0, + z: -1 + }); + addStretchTool(grabberEdgeFR, "STRETCH_EdgeFR", null, { + x: -1, + y: 0, + z: -1 + }, { + x: 1, + y: 0, + z: 1 + }); + addStretchTool(grabberEdgeFL, "STRETCH_EdgeFL", null, { + x: 1, + y: 0, + z: -1 + }, { + x: -1, + y: 0, + z: 1 + }); function updateRotationDegreesOverlay(angleFromZero, handleRotation, centerPosition) { var angle = angleFromZero * (Math.PI / 180); @@ -1967,34 +3258,31 @@ SelectionDisplay = (function () { outerRadius = diagonal * 1.15; var innerAlpha = 0.2; var outerAlpha = 0.2; - Overlays.editOverlay(rotateOverlayInner, - { - visible: true, - size: innerRadius, - innerRadius: 0.9, - startAt: 0, - endAt: 360, - alpha: innerAlpha - }); + Overlays.editOverlay(rotateOverlayInner, { + visible: true, + size: innerRadius, + innerRadius: 0.9, + startAt: 0, + endAt: 360, + alpha: innerAlpha + }); - Overlays.editOverlay(rotateOverlayOuter, - { - visible: true, - size: outerRadius, - innerRadius: 0.9, - startAt: 0, - endAt: 360, - alpha: outerAlpha, - }); + Overlays.editOverlay(rotateOverlayOuter, { + visible: true, + size: outerRadius, + innerRadius: 0.9, + startAt: 0, + endAt: 360, + alpha: outerAlpha, + }); - Overlays.editOverlay(rotateOverlayCurrent, - { - visible: true, - size: outerRadius, - startAt: 0, - endAt: 0, - innerRadius: 0.9, - }); + Overlays.editOverlay(rotateOverlayCurrent, { + visible: true, + size: outerRadius, + startAt: 0, + endAt: 0, + innerRadius: 0.9, + }); Overlays.editOverlay(rotationDegreesDisplay, { visible: true, @@ -2003,19 +3291,35 @@ SelectionDisplay = (function () { updateRotationDegreesOverlay(0, yawHandleRotation, yawCenter); }, onEnd: function(event, reason) { - Overlays.editOverlay(rotateOverlayInner, { visible: false }); - Overlays.editOverlay(rotateOverlayOuter, { visible: false }); - Overlays.editOverlay(rotateOverlayCurrent, { visible: false }); - Overlays.editOverlay(rotationDegreesDisplay, { visible: false }); + Overlays.editOverlay(rotateOverlayInner, { + visible: false + }); + Overlays.editOverlay(rotateOverlayOuter, { + visible: false + }); + Overlays.editOverlay(rotateOverlayCurrent, { + visible: false + }); + Overlays.editOverlay(rotationDegreesDisplay, { + visible: false + }); pushCommandForSelections(); }, onMove: function(event) { var pickRay = Camera.computePickRay(event.x, event.y); - Overlays.editOverlay(selectionBox, { ignoreRayIntersection: true, visible: false}); - Overlays.editOverlay(baseOfEntityProjectionOverlay, { ignoreRayIntersection: true, visible: false }); - Overlays.editOverlay(rotateOverlayTarget, { ignoreRayIntersection: false }); - + Overlays.editOverlay(selectionBox, { + ignoreRayIntersection: true, + visible: false + }); + Overlays.editOverlay(baseOfEntityProjectionOverlay, { + ignoreRayIntersection: true, + visible: false + }); + Overlays.editOverlay(rotateOverlayTarget, { + ignoreRayIntersection: false + }); + var result = Overlays.findRayIntersection(pickRay); if (result.intersects) { @@ -2028,7 +3332,11 @@ SelectionDisplay = (function () { var snapToInner = distanceFromCenter < innerRadius; var snapAngle = snapToInner ? innerSnapAngle : 1.0; angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle; - var yawChange = Quat.fromVec3Degrees({ x: 0, y: angleFromZero, z: 0 }); + var yawChange = Quat.fromVec3Degrees({ + x: 0, + y: angleFromZero, + z: 0 + }); // Entities should only reposition if we are rotating multiple selections around // the selections center point. Otherwise, the rotation will be around the entities @@ -2066,19 +3374,43 @@ SelectionDisplay = (function () { endAtRemainder = startAtCurrent; } if (snapToInner) { - Overlays.editOverlay(rotateOverlayOuter, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(rotateOverlayInner, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: innerRadius, - majorTickMarksAngle: innerSnapAngle, minorTickMarksAngle: 0, - majorTickMarksLength: -0.25, minorTickMarksLength: 0, }); + Overlays.editOverlay(rotateOverlayOuter, { + startAt: 0, + endAt: 360 + }); + Overlays.editOverlay(rotateOverlayInner, { + startAt: startAtRemainder, + endAt: endAtRemainder + }); + Overlays.editOverlay(rotateOverlayCurrent, { + startAt: startAtCurrent, + endAt: endAtCurrent, + size: innerRadius, + majorTickMarksAngle: innerSnapAngle, + minorTickMarksAngle: 0, + majorTickMarksLength: -0.25, + minorTickMarksLength: 0, + }); } else { - Overlays.editOverlay(rotateOverlayInner, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(rotateOverlayOuter, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius, - majorTickMarksAngle: 45.0, minorTickMarksAngle: 5, - majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, }); + Overlays.editOverlay(rotateOverlayInner, { + startAt: 0, + endAt: 360 + }); + Overlays.editOverlay(rotateOverlayOuter, { + startAt: startAtRemainder, + endAt: endAtRemainder + }); + Overlays.editOverlay(rotateOverlayCurrent, { + startAt: startAtCurrent, + endAt: endAtCurrent, + size: outerRadius, + majorTickMarksAngle: 45.0, + minorTickMarksAngle: 5, + majorTickMarksLength: 0.25, + minorTickMarksLength: 0.1, + }); } - + } } }); @@ -2096,34 +3428,31 @@ SelectionDisplay = (function () { outerRadius = diagonal * 1.15; var innerAlpha = 0.2; var outerAlpha = 0.2; - Overlays.editOverlay(rotateOverlayInner, - { - visible: true, - size: innerRadius, - innerRadius: 0.9, - startAt: 0, - endAt: 360, - alpha: innerAlpha - }); + Overlays.editOverlay(rotateOverlayInner, { + visible: true, + size: innerRadius, + innerRadius: 0.9, + startAt: 0, + endAt: 360, + alpha: innerAlpha + }); - Overlays.editOverlay(rotateOverlayOuter, - { - visible: true, - size: outerRadius, - innerRadius: 0.9, - startAt: 0, - endAt: 360, - alpha: outerAlpha, - }); + Overlays.editOverlay(rotateOverlayOuter, { + visible: true, + size: outerRadius, + innerRadius: 0.9, + startAt: 0, + endAt: 360, + alpha: outerAlpha, + }); - Overlays.editOverlay(rotateOverlayCurrent, - { - visible: true, - size: outerRadius, - startAt: 0, - endAt: 0, - innerRadius: 0.9, - }); + Overlays.editOverlay(rotateOverlayCurrent, { + visible: true, + size: outerRadius, + startAt: 0, + endAt: 0, + innerRadius: 0.9, + }); Overlays.editOverlay(rotationDegreesDisplay, { visible: true, @@ -2132,18 +3461,34 @@ SelectionDisplay = (function () { updateRotationDegreesOverlay(0, pitchHandleRotation, pitchCenter); }, onEnd: function(event, reason) { - Overlays.editOverlay(rotateOverlayInner, { visible: false }); - Overlays.editOverlay(rotateOverlayOuter, { visible: false }); - Overlays.editOverlay(rotateOverlayCurrent, { visible: false }); - Overlays.editOverlay(rotationDegreesDisplay, { visible: false }); + Overlays.editOverlay(rotateOverlayInner, { + visible: false + }); + Overlays.editOverlay(rotateOverlayOuter, { + visible: false + }); + Overlays.editOverlay(rotateOverlayCurrent, { + visible: false + }); + Overlays.editOverlay(rotationDegreesDisplay, { + visible: false + }); pushCommandForSelections(); }, onMove: function(event) { var pickRay = Camera.computePickRay(event.x, event.y); - Overlays.editOverlay(selectionBox, { ignoreRayIntersection: true, visible: false}); - Overlays.editOverlay(baseOfEntityProjectionOverlay, { ignoreRayIntersection: true, visible: false }); - Overlays.editOverlay(rotateOverlayTarget, { ignoreRayIntersection: false }); + Overlays.editOverlay(selectionBox, { + ignoreRayIntersection: true, + visible: false + }); + Overlays.editOverlay(baseOfEntityProjectionOverlay, { + ignoreRayIntersection: true, + visible: false + }); + Overlays.editOverlay(rotateOverlayTarget, { + ignoreRayIntersection: false + }); var result = Overlays.findRayIntersection(pickRay); if (result.intersects) { @@ -2158,8 +3503,12 @@ SelectionDisplay = (function () { var snapToInner = distanceFromCenter < innerRadius; var snapAngle = snapToInner ? innerSnapAngle : 1.0; angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle; - - var pitchChange = Quat.fromVec3Degrees({ x: angleFromZero, y: 0, z: 0 }); + + var pitchChange = Quat.fromVec3Degrees({ + x: angleFromZero, + y: 0, + z: 0 + }); for (var i = 0; i < SelectionManager.selections.length; i++) { var entityID = SelectionManager.selections[i]; @@ -2188,17 +3537,41 @@ SelectionDisplay = (function () { endAtRemainder = startAtCurrent; } if (snapToInner) { - Overlays.editOverlay(rotateOverlayOuter, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(rotateOverlayInner, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: innerRadius, - majorTickMarksAngle: innerSnapAngle, minorTickMarksAngle: 0, - majorTickMarksLength: -0.25, minorTickMarksLength: 0, }); + Overlays.editOverlay(rotateOverlayOuter, { + startAt: 0, + endAt: 360 + }); + Overlays.editOverlay(rotateOverlayInner, { + startAt: startAtRemainder, + endAt: endAtRemainder + }); + Overlays.editOverlay(rotateOverlayCurrent, { + startAt: startAtCurrent, + endAt: endAtCurrent, + size: innerRadius, + majorTickMarksAngle: innerSnapAngle, + minorTickMarksAngle: 0, + majorTickMarksLength: -0.25, + minorTickMarksLength: 0, + }); } else { - Overlays.editOverlay(rotateOverlayInner, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(rotateOverlayOuter, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius, - majorTickMarksAngle: 45.0, minorTickMarksAngle: 5, - majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, }); + Overlays.editOverlay(rotateOverlayInner, { + startAt: 0, + endAt: 360 + }); + Overlays.editOverlay(rotateOverlayOuter, { + startAt: startAtRemainder, + endAt: endAtRemainder + }); + Overlays.editOverlay(rotateOverlayCurrent, { + startAt: startAtCurrent, + endAt: endAtCurrent, + size: outerRadius, + majorTickMarksAngle: 45.0, + minorTickMarksAngle: 5, + majorTickMarksLength: 0.25, + minorTickMarksLength: 0.1, + }); } } } @@ -2217,34 +3590,31 @@ SelectionDisplay = (function () { outerRadius = diagonal * 1.15; var innerAlpha = 0.2; var outerAlpha = 0.2; - Overlays.editOverlay(rotateOverlayInner, - { - visible: true, - size: innerRadius, - innerRadius: 0.9, - startAt: 0, - endAt: 360, - alpha: innerAlpha - }); + Overlays.editOverlay(rotateOverlayInner, { + visible: true, + size: innerRadius, + innerRadius: 0.9, + startAt: 0, + endAt: 360, + alpha: innerAlpha + }); - Overlays.editOverlay(rotateOverlayOuter, - { - visible: true, - size: outerRadius, - innerRadius: 0.9, - startAt: 0, - endAt: 360, - alpha: outerAlpha, - }); + Overlays.editOverlay(rotateOverlayOuter, { + visible: true, + size: outerRadius, + innerRadius: 0.9, + startAt: 0, + endAt: 360, + alpha: outerAlpha, + }); - Overlays.editOverlay(rotateOverlayCurrent, - { - visible: true, - size: outerRadius, - startAt: 0, - endAt: 0, - innerRadius: 0.9, - }); + Overlays.editOverlay(rotateOverlayCurrent, { + visible: true, + size: outerRadius, + startAt: 0, + endAt: 0, + innerRadius: 0.9, + }); Overlays.editOverlay(rotationDegreesDisplay, { visible: true, @@ -2253,18 +3623,34 @@ SelectionDisplay = (function () { updateRotationDegreesOverlay(0, rollHandleRotation, rollCenter); }, onEnd: function(event, reason) { - Overlays.editOverlay(rotateOverlayInner, { visible: false }); - Overlays.editOverlay(rotateOverlayOuter, { visible: false }); - Overlays.editOverlay(rotateOverlayCurrent, { visible: false }); - Overlays.editOverlay(rotationDegreesDisplay, { visible: false }); + Overlays.editOverlay(rotateOverlayInner, { + visible: false + }); + Overlays.editOverlay(rotateOverlayOuter, { + visible: false + }); + Overlays.editOverlay(rotateOverlayCurrent, { + visible: false + }); + Overlays.editOverlay(rotationDegreesDisplay, { + visible: false + }); pushCommandForSelections(); }, onMove: function(event) { var pickRay = Camera.computePickRay(event.x, event.y); - Overlays.editOverlay(selectionBox, { ignoreRayIntersection: true, visible: false}); - Overlays.editOverlay(baseOfEntityProjectionOverlay, { ignoreRayIntersection: true, visible: false }); - Overlays.editOverlay(rotateOverlayTarget, { ignoreRayIntersection: false }); + Overlays.editOverlay(selectionBox, { + ignoreRayIntersection: true, + visible: false + }); + Overlays.editOverlay(baseOfEntityProjectionOverlay, { + ignoreRayIntersection: true, + visible: false + }); + Overlays.editOverlay(rotateOverlayTarget, { + ignoreRayIntersection: false + }); var result = Overlays.findRayIntersection(pickRay); if (result.intersects) { @@ -2280,7 +3666,11 @@ SelectionDisplay = (function () { var snapAngle = snapToInner ? innerSnapAngle : 1.0; angleFromZero = Math.floor(angleFromZero / snapAngle) * snapAngle; - var rollChange = Quat.fromVec3Degrees({ x: 0, y: 0, z: angleFromZero }); + var rollChange = Quat.fromVec3Degrees({ + x: 0, + y: 0, + z: angleFromZero + }); for (var i = 0; i < SelectionManager.selections.length; i++) { var entityID = SelectionManager.selections[i]; var properties = Entities.getEntityProperties(entityID); @@ -2308,17 +3698,41 @@ SelectionDisplay = (function () { endAtRemainder = startAtCurrent; } if (snapToInner) { - Overlays.editOverlay(rotateOverlayOuter, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(rotateOverlayInner, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: innerRadius, - majorTickMarksAngle: innerSnapAngle, minorTickMarksAngle: 0, - majorTickMarksLength: -0.25, minorTickMarksLength: 0, }); + Overlays.editOverlay(rotateOverlayOuter, { + startAt: 0, + endAt: 360 + }); + Overlays.editOverlay(rotateOverlayInner, { + startAt: startAtRemainder, + endAt: endAtRemainder + }); + Overlays.editOverlay(rotateOverlayCurrent, { + startAt: startAtCurrent, + endAt: endAtCurrent, + size: innerRadius, + majorTickMarksAngle: innerSnapAngle, + minorTickMarksAngle: 0, + majorTickMarksLength: -0.25, + minorTickMarksLength: 0, + }); } else { - Overlays.editOverlay(rotateOverlayInner, { startAt: 0, endAt: 360 }); - Overlays.editOverlay(rotateOverlayOuter, { startAt: startAtRemainder, endAt: endAtRemainder }); - Overlays.editOverlay(rotateOverlayCurrent, { startAt: startAtCurrent, endAt: endAtCurrent, size: outerRadius, - majorTickMarksAngle: 45.0, minorTickMarksAngle: 5, - majorTickMarksLength: 0.25, minorTickMarksLength: 0.1, }); + Overlays.editOverlay(rotateOverlayInner, { + startAt: 0, + endAt: 360 + }); + Overlays.editOverlay(rotateOverlayOuter, { + startAt: startAtRemainder, + endAt: endAtRemainder + }); + Overlays.editOverlay(rotateOverlayCurrent, { + startAt: startAtCurrent, + endAt: endAtCurrent, + size: outerRadius, + majorTickMarksAngle: 45.0, + minorTickMarksAngle: 5, + majorTickMarksLength: 0.25, + minorTickMarksLength: 0.1, + }); } } } @@ -2329,10 +3743,10 @@ SelectionDisplay = (function () { // FIXME - this cause problems with editing in the entity properties window //SelectionManager._update(); - + if (!Vec3.equal(Camera.getPosition(), lastCameraPosition) || !Quat.equal(Camera.getOrientation(), lastCameraOrientation)) { - + that.updateRotationHandles(); } } @@ -2347,12 +3761,20 @@ SelectionDisplay = (function () { var somethingClicked = false; var pickRay = Camera.computePickRay(event.x, event.y); - + // before we do a ray test for grabbers, disable the ray intersection for our selection box - Overlays.editOverlay(selectionBox, { ignoreRayIntersection: true }); - Overlays.editOverlay(yawHandle, { ignoreRayIntersection: true }); - Overlays.editOverlay(pitchHandle, { ignoreRayIntersection: true }); - Overlays.editOverlay(rollHandle, { ignoreRayIntersection: true }); + Overlays.editOverlay(selectionBox, { + ignoreRayIntersection: true + }); + Overlays.editOverlay(yawHandle, { + ignoreRayIntersection: true + }); + Overlays.editOverlay(pitchHandle, { + ignoreRayIntersection: true + }); + Overlays.editOverlay(rollHandle, { + ignoreRayIntersection: true + }); var result = Overlays.findRayIntersection(pickRay); if (result.intersects) { @@ -2377,14 +3799,16 @@ SelectionDisplay = (function () { activeTool.onBegin(event); } } else { - switch(result.overlayID) { + switch (result.overlayID) { case grabberMoveUp: mode = "TRANSLATE_UP_DOWN"; somethingClicked = true; // in translate mode, we hide our stretch handles... for (var i = 0; i < stretchHandles.length; i++) { - Overlays.editOverlay(stretchHandles[i], { visible: false }); + Overlays.editOverlay(stretchHandles[i], { + visible: false + }); } break; @@ -2397,8 +3821,8 @@ SelectionDisplay = (function () { break; case grabberFAR: - case grabberEdgeTF: // TODO: maybe this should be TOP+FAR stretching? - case grabberEdgeBF: // TODO: maybe this should be BOTTOM+FAR stretching? + case grabberEdgeTF: // TODO: maybe this should be TOP+FAR stretching? + case grabberEdgeBF: // TODO: maybe this should be BOTTOM+FAR stretching? mode = "STRETCH_FAR"; somethingClicked = true; break; @@ -2411,14 +3835,14 @@ SelectionDisplay = (function () { somethingClicked = true; break; case grabberRIGHT: - case grabberEdgeTR: // TODO: maybe this should be TOP+RIGHT stretching? - case grabberEdgeBR: // TODO: maybe this should be BOTTOM+RIGHT stretching? + case grabberEdgeTR: // TODO: maybe this should be TOP+RIGHT stretching? + case grabberEdgeBR: // TODO: maybe this should be BOTTOM+RIGHT stretching? mode = "STRETCH_RIGHT"; somethingClicked = true; break; case grabberLEFT: - case grabberEdgeTL: // TODO: maybe this should be TOP+LEFT stretching? - case grabberEdgeBL: // TODO: maybe this should be BOTTOM+LEFT stretching? + case grabberEdgeTL: // TODO: maybe this should be TOP+LEFT stretching? + case grabberEdgeBL: // TODO: maybe this should be BOTTOM+LEFT stretching? mode = "STRETCH_LEFT"; somethingClicked = true; break; @@ -2429,29 +3853,43 @@ SelectionDisplay = (function () { } } } - + // if one of the items above was clicked, then we know we are in translate or stretch mode, and we // should hide our rotate handles... if (somethingClicked) { - Overlays.editOverlay(yawHandle, { visible: false }); - Overlays.editOverlay(pitchHandle, { visible: false }); - Overlays.editOverlay(rollHandle, { visible: false }); - + Overlays.editOverlay(yawHandle, { + visible: false + }); + Overlays.editOverlay(pitchHandle, { + visible: false + }); + Overlays.editOverlay(rollHandle, { + visible: false + }); + if (mode != "TRANSLATE_UP_DOWN") { - Overlays.editOverlay(grabberMoveUp, { visible: false }); + Overlays.editOverlay(grabberMoveUp, { + visible: false + }); } } - + if (!somethingClicked) { - + print("rotate handle case..."); - + // After testing our stretch handles, then check out rotate handles - Overlays.editOverlay(yawHandle, { ignoreRayIntersection: false }); - Overlays.editOverlay(pitchHandle, { ignoreRayIntersection: false }); - Overlays.editOverlay(rollHandle, { ignoreRayIntersection: false }); + Overlays.editOverlay(yawHandle, { + ignoreRayIntersection: false + }); + Overlays.editOverlay(pitchHandle, { + ignoreRayIntersection: false + }); + Overlays.editOverlay(rollHandle, { + ignoreRayIntersection: false + }); var result = Overlays.findRayIntersection(pickRay); - + var overlayOrientation; var overlayCenter; @@ -2460,12 +3898,12 @@ SelectionDisplay = (function () { var pitch = angles.x; var yaw = angles.y; var roll = angles.z; - + originalRotation = properties.rotation; originalPitch = pitch; originalYaw = yaw; originalRoll = roll; - + if (result.intersects) { var tool = grabberTools[result.overlayID]; if (tool) { @@ -2476,7 +3914,7 @@ SelectionDisplay = (function () { activeTool.onBegin(event); } } - switch(result.overlayID) { + switch (result.overlayID) { case yawHandle: mode = "ROTATE_YAW"; somethingClicked = true; @@ -2514,59 +3952,147 @@ SelectionDisplay = (function () { print(" somethingClicked:" + somethingClicked); print(" mode:" + mode); - + if (somethingClicked) { - - Overlays.editOverlay(rotateOverlayTarget, { visible: true, rotation: overlayOrientation, position: overlayCenter }); - Overlays.editOverlay(rotateOverlayInner, { visible: true, rotation: overlayOrientation, position: overlayCenter }); - Overlays.editOverlay(rotateOverlayOuter, { visible: true, rotation: overlayOrientation, position: overlayCenter, startAt: 0, endAt: 360 }); - Overlays.editOverlay(rotateOverlayCurrent, { visible: true, rotation: overlayOrientation, position: overlayCenter, startAt: 0, endAt: 0 }); - Overlays.editOverlay(yawHandle, { visible: false }); - Overlays.editOverlay(pitchHandle, { visible: false }); - Overlays.editOverlay(rollHandle, { visible: false }); + + Overlays.editOverlay(rotateOverlayTarget, { + visible: true, + rotation: overlayOrientation, + position: overlayCenter + }); + Overlays.editOverlay(rotateOverlayInner, { + visible: true, + rotation: overlayOrientation, + position: overlayCenter + }); + Overlays.editOverlay(rotateOverlayOuter, { + visible: true, + rotation: overlayOrientation, + position: overlayCenter, + startAt: 0, + endAt: 360 + }); + Overlays.editOverlay(rotateOverlayCurrent, { + visible: true, + rotation: overlayOrientation, + position: overlayCenter, + startAt: 0, + endAt: 0 + }); + Overlays.editOverlay(yawHandle, { + visible: false + }); + Overlays.editOverlay(pitchHandle, { + visible: false + }); + Overlays.editOverlay(rollHandle, { + visible: false + }); - Overlays.editOverlay(yawHandle, { visible: false }); - Overlays.editOverlay(pitchHandle, { visible: false }); - Overlays.editOverlay(rollHandle, { visible: false }); - Overlays.editOverlay(grabberMoveUp, { visible: false }); - Overlays.editOverlay(grabberLBN, { visible: false }); - Overlays.editOverlay(grabberLBF, { visible: false }); - Overlays.editOverlay(grabberRBN, { visible: false }); - Overlays.editOverlay(grabberRBF, { visible: false }); - Overlays.editOverlay(grabberLTN, { visible: false }); - Overlays.editOverlay(grabberLTF, { visible: false }); - Overlays.editOverlay(grabberRTN, { visible: false }); - Overlays.editOverlay(grabberRTF, { visible: false }); + Overlays.editOverlay(yawHandle, { + visible: false + }); + Overlays.editOverlay(pitchHandle, { + visible: false + }); + Overlays.editOverlay(rollHandle, { + visible: false + }); + Overlays.editOverlay(grabberMoveUp, { + visible: false + }); + Overlays.editOverlay(grabberLBN, { + visible: false + }); + Overlays.editOverlay(grabberLBF, { + visible: false + }); + Overlays.editOverlay(grabberRBN, { + visible: false + }); + Overlays.editOverlay(grabberRBF, { + visible: false + }); + Overlays.editOverlay(grabberLTN, { + visible: false + }); + Overlays.editOverlay(grabberLTF, { + visible: false + }); + Overlays.editOverlay(grabberRTN, { + visible: false + }); + Overlays.editOverlay(grabberRTF, { + visible: false + }); - Overlays.editOverlay(grabberTOP, { visible: false }); - Overlays.editOverlay(grabberBOTTOM, { visible: false }); - Overlays.editOverlay(grabberLEFT, { visible: false }); - Overlays.editOverlay(grabberRIGHT, { visible: false }); - Overlays.editOverlay(grabberNEAR, { visible: false }); - Overlays.editOverlay(grabberFAR, { visible: false }); + Overlays.editOverlay(grabberTOP, { + visible: false + }); + Overlays.editOverlay(grabberBOTTOM, { + visible: false + }); + Overlays.editOverlay(grabberLEFT, { + visible: false + }); + Overlays.editOverlay(grabberRIGHT, { + visible: false + }); + Overlays.editOverlay(grabberNEAR, { + visible: false + }); + Overlays.editOverlay(grabberFAR, { + visible: false + }); - Overlays.editOverlay(grabberEdgeTR, { visible: false }); - Overlays.editOverlay(grabberEdgeTL, { visible: false }); - Overlays.editOverlay(grabberEdgeTF, { visible: false }); - Overlays.editOverlay(grabberEdgeTN, { visible: false }); - Overlays.editOverlay(grabberEdgeBR, { visible: false }); - Overlays.editOverlay(grabberEdgeBL, { visible: false }); - Overlays.editOverlay(grabberEdgeBF, { visible: false }); - Overlays.editOverlay(grabberEdgeBN, { visible: false }); - Overlays.editOverlay(grabberEdgeNR, { visible: false }); - Overlays.editOverlay(grabberEdgeNL, { visible: false }); - Overlays.editOverlay(grabberEdgeFR, { visible: false }); - Overlays.editOverlay(grabberEdgeFL, { visible: false }); + Overlays.editOverlay(grabberEdgeTR, { + visible: false + }); + Overlays.editOverlay(grabberEdgeTL, { + visible: false + }); + Overlays.editOverlay(grabberEdgeTF, { + visible: false + }); + Overlays.editOverlay(grabberEdgeTN, { + visible: false + }); + Overlays.editOverlay(grabberEdgeBR, { + visible: false + }); + Overlays.editOverlay(grabberEdgeBL, { + visible: false + }); + Overlays.editOverlay(grabberEdgeBF, { + visible: false + }); + Overlays.editOverlay(grabberEdgeBN, { + visible: false + }); + Overlays.editOverlay(grabberEdgeNR, { + visible: false + }); + Overlays.editOverlay(grabberEdgeNL, { + visible: false + }); + Overlays.editOverlay(grabberEdgeFR, { + visible: false + }); + Overlays.editOverlay(grabberEdgeFL, { + visible: false + }); } } if (!somethingClicked) { - Overlays.editOverlay(selectionBox, { ignoreRayIntersection: false }); + Overlays.editOverlay(selectionBox, { + ignoreRayIntersection: false + }); var result = Overlays.findRayIntersection(pickRay); if (result.intersects) { - switch(result.overlayID) { + switch (result.overlayID) { case selectionBox: activeTool = translateXZTool; mode = translateXZTool.mode; @@ -2584,17 +4110,25 @@ SelectionDisplay = (function () { if (somethingClicked) { pickRay = Camera.computePickRay(event.x, event.y); if (wantDebug) { - print("mousePressEvent()...... " + overlayNames[result.overlayID]); + print("mousePressEvent()...... " + overlayNames[result.overlayID]); } } // reset everything as intersectable... // TODO: we could optimize this since some of these were already flipped back - Overlays.editOverlay(selectionBox, { ignoreRayIntersection: false }); - Overlays.editOverlay(yawHandle, { ignoreRayIntersection: false }); - Overlays.editOverlay(pitchHandle, { ignoreRayIntersection: false }); - Overlays.editOverlay(rollHandle, { ignoreRayIntersection: false }); - + Overlays.editOverlay(selectionBox, { + ignoreRayIntersection: false + }); + Overlays.editOverlay(yawHandle, { + ignoreRayIntersection: false + }); + Overlays.editOverlay(pitchHandle, { + ignoreRayIntersection: false + }); + Overlays.editOverlay(rollHandle, { + ignoreRayIntersection: false + }); + return somethingClicked; }; @@ -2613,7 +4147,7 @@ SelectionDisplay = (function () { var highlightNeeded = false; if (result.intersects) { - switch(result.overlayID) { + switch (result.overlayID) { case yawHandle: case pitchHandle: case rollHandle: @@ -2621,7 +4155,7 @@ SelectionDisplay = (function () { pickedAlpha = handleAlpha; highlightNeeded = true; break; - + case grabberMoveUp: pickedColor = handleColor; pickedAlpha = handleAlpha; @@ -2682,30 +4216,42 @@ SelectionDisplay = (function () { default: if (previousHandle) { - Overlays.editOverlay(previousHandle, { color: previousHandleColor, alpha: previousHandleAlpha }); + Overlays.editOverlay(previousHandle, { + color: previousHandleColor, + alpha: previousHandleAlpha + }); previousHandle = false; } break; } - + if (highlightNeeded) { if (previousHandle) { - Overlays.editOverlay(previousHandle, { color: previousHandleColor, alpha: previousHandleAlpha }); + Overlays.editOverlay(previousHandle, { + color: previousHandleColor, + alpha: previousHandleAlpha + }); previousHandle = false; } - Overlays.editOverlay(result.overlayID, { color: highlightedHandleColor, alpha: highlightedHandleAlpha }); + Overlays.editOverlay(result.overlayID, { + color: highlightedHandleColor, + alpha: highlightedHandleAlpha + }); previousHandle = result.overlayID; previousHandleColor = pickedColor; previousHandleAlpha = pickedAlpha; } - + } else { if (previousHandle) { - Overlays.editOverlay(previousHandle, { color: previousHandleColor, alpha: previousHandleAlpha }); + Overlays.editOverlay(previousHandle, { + color: previousHandleColor, + alpha: previousHandleAlpha + }); previousHandle = false; } } - + return false; }; @@ -2728,7 +4274,11 @@ SelectionDisplay = (function () { Overlays.editOverlay(rollHandle, { scale: handleSize, }); - var pos = Vec3.sum(grabberMoveUpPosition, { x: 0, y: Vec3.length(diff) * GRABBER_DISTANCE_TO_SIZE_RATIO * 3, z: 0 }); + var pos = Vec3.sum(grabberMoveUpPosition, { + x: 0, + y: Vec3.length(diff) * GRABBER_DISTANCE_TO_SIZE_RATIO * 3, + z: 0 + }); Overlays.editOverlay(grabberMoveUp, { position: pos, scale: handleSize / 2, @@ -2745,34 +4295,43 @@ SelectionDisplay = (function () { activeTool = null; // hide our rotation overlays..., and show our handles if (mode == "ROTATE_YAW" || mode == "ROTATE_PITCH" || mode == "ROTATE_ROLL") { - Overlays.editOverlay(rotateOverlayTarget, { visible: false }); - Overlays.editOverlay(rotateOverlayInner, { visible: false }); - Overlays.editOverlay(rotateOverlayOuter, { visible: false }); - Overlays.editOverlay(rotateOverlayCurrent, { visible: false }); + Overlays.editOverlay(rotateOverlayTarget, { + visible: false + }); + Overlays.editOverlay(rotateOverlayInner, { + visible: false + }); + Overlays.editOverlay(rotateOverlayOuter, { + visible: false + }); + Overlays.editOverlay(rotateOverlayCurrent, { + visible: false + }); showHandles = true; } if (mode != "UNKNOWN") { showHandles = true; } - + mode = "UNKNOWN"; - + // if something is selected, then reset the "original" properties for any potential next click+move operation if (SelectionManager.hasSelection()) { if (showHandles) { that.select(SelectionManager.selections[0], event); } } - + }; // NOTE: mousePressEvent and mouseMoveEvent from the main script should call us., so we don't hook these: // Controller.mousePressEvent.connect(that.mousePressEvent); // Controller.mouseMoveEvent.connect(that.mouseMoveEvent); Controller.mouseReleaseEvent.connect(that.mouseReleaseEvent); - + + + return that; -}()); - +}()); \ No newline at end of file diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 8eae5cc2a4..8f71f161a2 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -25,7 +25,7 @@ var lightOverlayManager; if (SHOW_OVERLAYS === true) { Script.include('../libraries/gridTool.js'); - Script.include('../libraries/entitySelectionTool.js'); + Script.include('../libraries/entitySelectionTool.js?'+Math.random(0-100)); Script.include('../libraries/lightOverlayManager.js'); var grid = Grid(); diff --git a/examples/light_modifier/lightModifierTestScene.js b/examples/light_modifier/lightModifierTestScene.js index 761eb4786d..8381b9d434 100644 --- a/examples/light_modifier/lightModifierTestScene.js +++ b/examples/light_modifier/lightModifierTestScene.js @@ -10,6 +10,7 @@ // 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)); var basePosition, avatarRot; avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(0, Quat.getUp(avatarRot))); @@ -74,6 +75,7 @@ function createBlock() { blue: 255 }, position: position, + script:PARENT_SCRIPT_URL, userData: JSON.stringify({ handControllerKey: { disableReleaseVelocity: true diff --git a/examples/light_modifier/lightParent.js b/examples/light_modifier/lightParent.js new file mode 100644 index 0000000000..2d7cfe8042 --- /dev/null +++ b/examples/light_modifier/lightParent.js @@ -0,0 +1,42 @@ + // + // slider.js + // + // Created by James Pollack @imgntn on 12/15/2015 + // Copyright 2015 High Fidelity, Inc. + // + // Entity script that sends a scaled value to a light based on its distance from the start of its constraint axis. + // + // Distributed under the Apache License, Version 2.0. + // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + // + + (function() { + + function LightParent() { + return this; + } + + LightParent.prototype = { + preload: function(entityID) { + print('LIGHT PARENT SCRIPT GO') + this.entityID = entityID; + var entityProperties = Entities.getEntityProperties(this.entityID, "userData"); + this.initialProperties = entityProperties + this.userData = JSON.parse(entityProperties.userData); + }, + startNearGrab: function() {}, + startDistantGrab: function() { + + }, + continueNearGrab: function() { + this.continueDistantGrab(); + }, + continueDistantGrab: function() { + print('distant grab, should send message!') + Messages.sendMessage('entityToolUpdates', 'callUpdate'); + }, + + }; + + return new LightParent(); + }); \ No newline at end of file From a25feb5578adfb989824aa6d2e723564a317c6bf Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 17 Dec 2015 16:58:38 -0800 Subject: [PATCH 27/57] switching branches --- examples/controllers/handControllerGrab.js | 2 +- examples/libraries/entitySelectionTool.js | 1 - examples/light_modifier/lightModifier.js | 179 ++++++++++++------ .../light_modifier/lightModifierTestScene.js | 13 +- examples/light_modifier/lightParent.js | 2 - 5 files changed, 131 insertions(+), 66 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index f53a66444f..0f927f39c8 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -517,7 +517,7 @@ function MyController(hand) { } var intersection = Entities.findRayIntersection(pickRayBacked, true); - + Messages.sendMessage('Hifi-Light-Overlay-Ray-Check', JSON.stringify(pickRayBacked)); if (intersection.intersects) { // the ray is intersecting something we can move. var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection); diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 9b213760c2..94ffb48a71 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -20,7 +20,6 @@ SPACE_WORLD = "world"; SelectionManager = (function() { var that = {}; - function subscribeToUpdateMessages() { Messages.subscribe('entityToolUpdates'); Messages.messageReceived.connect(handleEntitySelectionToolUpdates); diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 8f71f161a2..26fb7b7f36 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -22,10 +22,13 @@ var selectionDisplay; var selectionManager; var lightOverlayManager; +//for when we make a block parent for the light +var PARENT_SCRIPT_URL = Script.resolvePath('lightParent.js?' + Math.random(0 - 100)); + if (SHOW_OVERLAYS === true) { Script.include('../libraries/gridTool.js'); - Script.include('../libraries/entitySelectionTool.js?'+Math.random(0-100)); + Script.include('../libraries/entitySelectionTool.js?' + Math.random(0 - 100)); Script.include('../libraries/lightOverlayManager.js'); var grid = Grid(); @@ -90,8 +93,8 @@ var WHITE = { var ORANGE = { red: 255, - green: 0, - blue: 128 + green: 165, + blue: 0 } var SLIDER_DIMENSIONS = { @@ -100,6 +103,18 @@ var SLIDER_DIMENSIONS = { z: 0.075 }; +var CLOSE_BUTTON_DIMENSIONS ={ + x:0.1, + y:0.1, + z:0.1 +} + +var LIGHT_MODEL_DIMENSIONS={ + x:0.04, + y:0.04, + z:0.09 +} + var PER_ROW_OFFSET = { x: 0, y: -0.2, @@ -348,7 +363,6 @@ var light = null; function makeSliders(light) { // selectionManager.setSelections([entityID]); - if (light.type === 'spotlight') { var USE_COLOR_SLIDER = true; var USE_INTENSITY_SLIDER = true; @@ -383,9 +397,25 @@ function makeSliders(light) { // selectionManager.setSelections([entityID]); slidersRef.exponent = new entitySlider(light, ORANGE, 'exponent', 6); sliders.push(slidersRef.exponent); } + + var closeButtonPosition; + + createCloseButton(closeButtonPosition); subscribeToSliderMessages(); }; +function createCloseButton(position){ + var buttonProperties = { + type:'Model', + modelURL:CLOSE_BUTTON_MODEL_URL, + dimensions:CLOSE_BUTTON_DIMENSIONS, + position:position, + rotation:Quat.fromPitchYawRollDegrees(90,0,0); + } + + var button = Entities.addEntity(buttonProperties); +} + function subScribeToNewLights() { Messages.subscribe('Hifi-Light-Mod-Receiver'); Messages.messageReceived.connect(handleLightModMessages); @@ -396,6 +426,12 @@ function subscribeToSliderMessages() { Messages.messageReceived.connect(handleValueMessages); } +function subscribeToLightOverlayRayCheckMessages() { + Messages.subscribe('Hifi-Light-Overlay-Ray-Check'); + Messages.messageReceived.connect(handleLightOverlayRayCheckMessages); +} + + function handleLightModMessages(channel, message, sender) { if (channel !== 'Hifi-Light-Mod-Receiver') { return; @@ -425,6 +461,86 @@ function handleValueMessages(channel, message, sender) { slidersRef[parsedMessage.sliderType].setValueFromMessage(parsedMessage); } +var currentLight; + +function handleLightOverlayRayCheckMessages(channel, message, sender) { + if (channel !== 'Hifi-Light-Overlay-Ray-Check') { + return; + } + if (ONLY_I_CAN_EDIT === true && sender !== MyAvatar.sessionUUID) { + return; + } + + print('RAY CHECK GOT MESSAGE::' + message); + var pickRay = JSON.parse(message); + + var doesIntersect = lightOverlayManager.findRayIntersection(pickRay); + print('DOES INTERSECT A LIGHT WE HAVE???' + doesIntersect.intersects); + if (doesIntersect.intersects === true) { + print('FULL MESSAGE:::' + JSON.stringify(doesIntersect)) + + var lightID = doesIntersect.entityID; + if (currentLight === lightID) { + print('ALREADY HAVE A BLOCK, EXIT') + return; + } + print('LIGHT ID::' + lightID); + currentLight = lightID; + var lightProperties = Entities.getEntityProperties(lightID); + var block = createBlock(lightProperties.position); + + var light = { + id: lightID, + type: 'spotlight', + initialProperties: lightProperties + } + + makeSliders(light); + print('AFTER MAKE SLIDERS') + if (SHOW_LIGHT_VOLUME === true) { + selectionManager.setSelections([lightID]); + print('SET SELECTIOIO MANAGER TO::: '+ lightID); + print('hasSelection???' + selectionManager.hasSelection()) + } + print('BLOCK IS:::' + block); + Entities.editEntity(lightID, { + parentID: block + }); + + + } +} +function createBlock(position) { + print('CREATE BLOCK') + + 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, + script: PARENT_SCRIPT_URL, + userData: JSON.stringify({ + handControllerKey: { + disableReleaseVelocity: true + } + }) + }; + + var block = Entities.addEntity(blockProperties); + + return block +} + function cleanup() { var i; for (i = 0; i < sliders.length; i++) { @@ -440,7 +556,6 @@ function cleanup() { } Script.scriptEnding.connect(cleanup); -subScribeToNewLights(); function deleteEntity(entityID) { if (entityID === light) { @@ -448,60 +563,10 @@ function deleteEntity(entityID) { } } - - Entities.deletingEntity.connect(deleteEntity); -// search for lights to make grabbable - -// var USE_DEBOUNCE = true; -// var sinceLastUpdate = 0; - -// function searchForLightsToVisualize() { - -// var deltaTime = interval(); - -// if (USE_DEBOUNCE === true) { -// sinceLastUpdate = sinceLastUpdate + deltaTime; - -// if (sinceLastUpdate > 60) { -// sinceLastUpdate = 0; -// } else { -// return; -// } -// } - -// print('SEARCHING FOR LIGHTS'); - -// var entitites = Entities.findEntities(MyAvatar.position, 50); -// for (i = 0; i < entities.length; i++) { -// var entityProperties = Entities.getEntityProperties(entities[i], ['type', 'parentID']) -// var parentID = entityProperties.parentID; -// var type = entityProperties.type; - -// if (type !== 'Light') { -// return; -// } - -// if (type === "Light" && parentID !== DEFAULT_PARENT_ID && parentID !== null) { -// var light = entities[i]; -// //do something with the light. -// } - -// } - -// } - -// function interval() { -// var lastTime = new Date().getTime(); - -// return function getInterval() { -// var newTime = new Date().getTime(); -// var delta = newTime - lastTime; -// lastTime = newTime; -// return delta; -// }; -// } +subscribeToLightOverlayRayCheckMessages(); +subScribeToNewLights(); diff --git a/examples/light_modifier/lightModifierTestScene.js b/examples/light_modifier/lightModifierTestScene.js index 8381b9d434..4b78484a31 100644 --- a/examples/light_modifier/lightModifierTestScene.js +++ b/examples/light_modifier/lightModifierTestScene.js @@ -19,7 +19,10 @@ var light, block; function createLight() { var blockProperties = Entities.getEntityProperties(block, ["position", "rotation"]); - var lightTransform = evalLightWorldTransform(blockProperties.position, blockProperties.rotation); + var position = basePosition; + position.y += 3; + var lightTransform = evalLightWorldTransform(position,avatarRot); + // var lightTransform = evalLightWorldTransform(blockProperties.position, blockProperties.rotation); var lightProperties = { name: 'Hifi-Spotlight', type: "Light", @@ -29,7 +32,7 @@ function createLight() { y: 2, z: 8 }, - parentID: block, + // parentID: block, color: { red: 255, green: 0, @@ -53,7 +56,7 @@ function createLight() { } }; - Messages.sendMessage('Hifi-Light-Mod-Receiver', JSON.stringify(message)); +// Messages.sendMessage('Hifi-Light-Mod-Receiver', JSON.stringify(message)); } @@ -104,11 +107,11 @@ function evalLightWorldTransform(modelPos, modelRot) { } function cleanup() { - Entities.deleteEntity(block); + //Entities.deleteEntity(block); Entities.deleteEntity(light); } Script.scriptEnding.connect(cleanup); -createBlock(); +//createBlock(); createLight(); \ No newline at end of file diff --git a/examples/light_modifier/lightParent.js b/examples/light_modifier/lightParent.js index 2d7cfe8042..0d91b93f93 100644 --- a/examples/light_modifier/lightParent.js +++ b/examples/light_modifier/lightParent.js @@ -18,7 +18,6 @@ LightParent.prototype = { preload: function(entityID) { - print('LIGHT PARENT SCRIPT GO') this.entityID = entityID; var entityProperties = Entities.getEntityProperties(this.entityID, "userData"); this.initialProperties = entityProperties @@ -32,7 +31,6 @@ this.continueDistantGrab(); }, continueDistantGrab: function() { - print('distant grab, should send message!') Messages.sendMessage('entityToolUpdates', 'callUpdate'); }, From 7a542a678b709d5a68ce0f75cb9a9c874c94c480 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 17 Dec 2015 17:17:04 -0800 Subject: [PATCH 28/57] prep for close button --- examples/light_modifier/closeButton.js | 41 +++++++++++++ examples/light_modifier/lightModifier.js | 76 +++++++++++++++++------- examples/light_modifier/lightParent.js | 22 +++---- 3 files changed, 106 insertions(+), 33 deletions(-) create mode 100644 examples/light_modifier/closeButton.js diff --git a/examples/light_modifier/closeButton.js b/examples/light_modifier/closeButton.js new file mode 100644 index 0000000000..045882fd33 --- /dev/null +++ b/examples/light_modifier/closeButton.js @@ -0,0 +1,41 @@ +// +// closeButton.js +// +// Created by James Pollack @imgntn on 12/15/2015 +// Copyright 2015 High Fidelity, Inc. +// +// Entity script that closes sliders when interacted with. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + + function CloseButton() { + return this; + } + + CloseButton.prototype = { + preload: function(entityID) { + this.entityID = entityID; + var entityProperties = Entities.getEntityProperties(this.entityID, "userData"); + this.initialProperties = entityProperties + this.userData = JSON.parse(entityProperties.userData); + }, + startNearGrab: function() { + + }, + startDistantGrab: function() { + + }, + continueNearGrab: function() { + this.continueDistantGrab(); + }, + continueDistantGrab: function() { + }, + + }; + + return new CloseButton(); +}); \ No newline at end of file diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 26fb7b7f36..29d66ca821 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -60,6 +60,8 @@ var CUTOFF_MAX = 360; var EXPONENT_MAX = 1; var SLIDER_SCRIPT_URL = Script.resolvePath('slider.js?' + Math.random(0, 100)); +var CLOSE_BUTTON_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/red_x.fbx'; +var CLOSE_BUTTON_SCRIPT_URL = Script.resolvePath('closeButton.js?' + Math.random(0, 100)); var RED = { red: 255, @@ -103,16 +105,16 @@ var SLIDER_DIMENSIONS = { z: 0.075 }; -var CLOSE_BUTTON_DIMENSIONS ={ - x:0.1, - y:0.1, - z:0.1 +var CLOSE_BUTTON_DIMENSIONS = { + x: 0.1, + y: 0.1, + z: 0.1 } -var LIGHT_MODEL_DIMENSIONS={ - x:0.04, - y:0.04, - z:0.09 +var LIGHT_MODEL_DIMENSIONS = { + x: 0.04, + y: 0.04, + z: 0.09 } var PER_ROW_OFFSET = { @@ -361,7 +363,7 @@ var slidersRef = { } var light = null; -function makeSliders(light) { // selectionManager.setSelections([entityID]); +function makeSliders(light) { if (light.type === 'spotlight') { var USE_COLOR_SLIDER = true; @@ -398,22 +400,50 @@ function makeSliders(light) { // selectionManager.setSelections([entityID]); sliders.push(slidersRef.exponent); } - var closeButtonPosition; + createCloseButton(7); - createCloseButton(closeButtonPosition); subscribeToSliderMessages(); }; -function createCloseButton(position){ +var closeButtons = []; + +function createCloseButton(row) { + var basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(this.avatarRot))); + var verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); + var downPosition = Vec3.sum(basePosition, verticalOffset); + var avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); + var rightVector = Quat.getRight(avatarRot); + var extension = Vec3.multiply(AXIS_SCALE, rightVector); + var position = Vec3.sum(downPosition, extension); + var buttonProperties = { - type:'Model', - modelURL:CLOSE_BUTTON_MODEL_URL, - dimensions:CLOSE_BUTTON_DIMENSIONS, - position:position, - rotation:Quat.fromPitchYawRollDegrees(90,0,0); + type: 'Model', + modelURL: CLOSE_BUTTON_MODEL_URL, + dimensions: CLOSE_BUTTON_DIMENSIONS, + position: position, + rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), + collisionsWillMove: false + //need to add wantsTrigger stuff so we can interact with it with our beamz } var button = Entities.addEntity(buttonProperties); + + closeButtons.push(button); + + Script.update.connect(rotateCloseButtons); +} + +function rotateCloseButtons() { + closeButtons.forEach(function(button) { + Entities.editEntity(button, { + angularVelocity: { + x: 0, + y: 0.25, + z: 0 + } + }) + + }) } function subScribeToNewLights() { @@ -471,7 +501,6 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { return; } - print('RAY CHECK GOT MESSAGE::' + message); var pickRay = JSON.parse(message); var doesIntersect = lightOverlayManager.findRayIntersection(pickRay); @@ -484,7 +513,7 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { print('ALREADY HAVE A BLOCK, EXIT') return; } - print('LIGHT ID::' + lightID); + currentLight = lightID; var lightProperties = Entities.getEntityProperties(lightID); var block = createBlock(lightProperties.position); @@ -496,13 +525,13 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { } makeSliders(light); - print('AFTER MAKE SLIDERS') + if (SHOW_LIGHT_VOLUME === true) { selectionManager.setSelections([lightID]); - print('SET SELECTIOIO MANAGER TO::: '+ lightID); + print('SET SELECTIOIO MANAGER TO::: ' + lightID); print('hasSelection???' + selectionManager.hasSelection()) } - print('BLOCK IS:::' + block); + Entities.editEntity(lightID, { parentID: block }); @@ -510,6 +539,7 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { } } + function createBlock(position) { print('CREATE BLOCK') @@ -553,6 +583,8 @@ function cleanup() { Entities.deletingEntity.disconnect(deleteEntity); lightOverlayManager.setVisible(false); + Script.update.disconnect(rotateCloseButtons); + } Script.scriptEnding.connect(cleanup); diff --git a/examples/light_modifier/lightParent.js b/examples/light_modifier/lightParent.js index 0d91b93f93..2b53c05d0a 100644 --- a/examples/light_modifier/lightParent.js +++ b/examples/light_modifier/lightParent.js @@ -1,14 +1,14 @@ - // - // slider.js - // - // Created by James Pollack @imgntn on 12/15/2015 - // Copyright 2015 High Fidelity, Inc. - // - // Entity script that sends a scaled value to a light based on its distance from the start of its constraint axis. - // - // Distributed under the Apache License, Version 2.0. - // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - // +// +// lightParent.js +// +// Created by James Pollack @imgntn on 12/15/2015 +// Copyright 2015 High Fidelity, Inc. +// +// Entity script that tells the light parent to update the selection tool when we move it. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// (function() { From f84a441c7daeb09c54acef636791986df0353609 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 17 Dec 2015 18:33:17 -0800 Subject: [PATCH 29/57] close button --- examples/light_modifier/lightModifier.js | 44 ++++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 29d66ca821..d82afc09bb 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -60,6 +60,7 @@ var CUTOFF_MAX = 360; var EXPONENT_MAX = 1; var SLIDER_SCRIPT_URL = Script.resolvePath('slider.js?' + Math.random(0, 100)); +var LIGHT_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/source4_good.fbx'; var CLOSE_BUTTON_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/red_x.fbx'; var CLOSE_BUTTON_SCRIPT_URL = Script.resolvePath('closeButton.js?' + Math.random(0, 100)); @@ -112,9 +113,9 @@ var CLOSE_BUTTON_DIMENSIONS = { } var LIGHT_MODEL_DIMENSIONS = { - x: 0.04, - y: 0.04, - z: 0.09 + x: 0.68, + y: 0.68, + z: 1.54 } var PER_ROW_OFFSET = { @@ -408,15 +409,16 @@ function makeSliders(light) { var closeButtons = []; function createCloseButton(row) { - var basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(this.avatarRot))); + var avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); + var basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(avatarRot))); var verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); var downPosition = Vec3.sum(basePosition, verticalOffset); - var avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); var rightVector = Quat.getRight(avatarRot); var extension = Vec3.multiply(AXIS_SCALE, rightVector); var position = Vec3.sum(downPosition, extension); var buttonProperties = { + name:'Hifi-Close-Button', type: 'Model', modelURL: CLOSE_BUTTON_MODEL_URL, dimensions: CLOSE_BUTTON_DIMENSIONS, @@ -492,6 +494,7 @@ function handleValueMessages(channel, message, sender) { } var currentLight; +var block; function handleLightOverlayRayCheckMessages(channel, message, sender) { if (channel !== 'Hifi-Light-Overlay-Ray-Check') { @@ -516,7 +519,8 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { currentLight = lightID; var lightProperties = Entities.getEntityProperties(lightID); - var block = createBlock(lightProperties.position); + block = createBlock(lightProperties.position); + // block = createLightModel(lightProperties.position); var light = { id: lightID, @@ -540,6 +544,30 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { } } +function createLightModel(position) { + print('CREATE MODEL') + var blockProperties = { + name: 'Hifi-Spotlight-Model', + type: 'Model', + shapeType: 'box', + modelURL: LIGHT_MODEL_URL, + dimensions: LIGHT_MODEL_DIMENSIONS, + collisionsWillMove: true, + position: position, + rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), + script: PARENT_SCRIPT_URL, + userData: JSON.stringify({ + handControllerKey: { + disableReleaseVelocity: true + } + }) + }; + + var block = Entities.addEntity(blockProperties); + + return block +} + function createBlock(position) { print('CREATE BLOCK') @@ -551,12 +579,12 @@ function createBlock(position) { y: 1, z: 1 }, - collisionsWillMove: true, color: { red: 0, green: 0, blue: 255 }, + collisionsWillMove: true, position: position, script: PARENT_SCRIPT_URL, userData: JSON.stringify({ @@ -578,11 +606,13 @@ function cleanup() { Entities.deleteEntity(sliders[i].sliderIndicator); } + Entities.deleteEntity(block); Messages.messageReceived.disconnect(handleLightModMessages); Messages.messageReceived.disconnect(handleValueMessages); Entities.deletingEntity.disconnect(deleteEntity); lightOverlayManager.setVisible(false); + selectionManager.clearSelections(); Script.update.disconnect(rotateCloseButtons); } From 387c30d83fa1abe3fa2a97ed512918ac7ad073ea Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 18 Dec 2015 15:04:13 -0800 Subject: [PATCH 30/57] close button --- examples/controllers/handControllerGrab.js | 2 +- examples/light_modifier/README.md | 6 +- examples/light_modifier/lightModifier.js | 58 +++++++++++-------- .../light_modifier/lightModifierTestScene.js | 2 +- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 0f927f39c8..1b256f67c0 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -842,7 +842,7 @@ function MyController(hand) { this.currentObjectPosition = Vec3.sum(this.currentObjectPosition, change); } } else { - print('should not head move!'); + // print('should not head move!'); } diff --git a/examples/light_modifier/README.md b/examples/light_modifier/README.md index d978c73b5b..3bd456d525 100644 --- a/examples/light_modifier/README.md +++ b/examples/light_modifier/README.md @@ -3,11 +3,15 @@ This PR demonstrates one way in-world editing of objects might work. We start w To test: https://rawgit.com/imgntn/hifi/light_mod/examples/lights/lightLoader.js To reset, I recommend stopping all scripts then re-loading lightLoader.js -When you run the lightLoader.js script, 4 scripts will be loaded: +When you run the lightLoader.js script, several scripts will be loaded: - handControllerGrab.js (custom) - lightModifier.js (listens for message to create sliders for a given light) - lightModifierTestScene.js (creates a light and parents it to a block, then sends a message ^^) - slider.js (attached to each slider entity) +- lightParent.js (attached to the entity to which a light is parented, so you can move it around) +- closeButton.js (for closing the ui) +- ../libraries/lightOverlayManager.js (custom) +- ../libraries/entitySelectionTool.js diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index d82afc09bb..76c1cdc873 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -60,7 +60,7 @@ var CUTOFF_MAX = 360; var EXPONENT_MAX = 1; var SLIDER_SCRIPT_URL = Script.resolvePath('slider.js?' + Math.random(0, 100)); -var LIGHT_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/source4_good.fbx'; +var LIGHT_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/source4_rotated.fbx'; var CLOSE_BUTTON_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/red_x.fbx'; var CLOSE_BUTTON_SCRIPT_URL = Script.resolvePath('closeButton.js?' + Math.random(0, 100)); @@ -108,14 +108,14 @@ var SLIDER_DIMENSIONS = { var CLOSE_BUTTON_DIMENSIONS = { x: 0.1, - y: 0.1, + y: 0.025, z: 0.1 } var LIGHT_MODEL_DIMENSIONS = { - x: 0.68, - y: 0.68, - z: 1.54 + x: 0.58, + y: 1.21, + z: 0.57 } var PER_ROW_OFFSET = { @@ -262,6 +262,7 @@ entitySlider.prototype = { color: this.color, position: sliderPosition, script: SLIDER_SCRIPT_URL, + ignoreForCollisions:true, userData: JSON.stringify({ lightModifierKey: { lightID: this.lightID, @@ -401,29 +402,34 @@ function makeSliders(light) { sliders.push(slidersRef.exponent); } - createCloseButton(7); + createCloseButton(slidersRef.exponent.endOfAxis); subscribeToSliderMessages(); }; var closeButtons = []; -function createCloseButton(row) { - var avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); - var basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(avatarRot))); - var verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); - var downPosition = Vec3.sum(basePosition, verticalOffset); - var rightVector = Quat.getRight(avatarRot); - var extension = Vec3.multiply(AXIS_SCALE, rightVector); - var position = Vec3.sum(downPosition, extension); +function createCloseButton(endOfAxis) { + // var avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); + // var basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(avatarRot))); + // var verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); + // var verticalOffset = lastRowVerticalOffset; + // var downPosition = Vec3.sum(basePosition, verticalOffset); + // var rightVector = Quat.getRight(avatarRot); + // var extension = Vec3.multiply(AXIS_SCALE, rightVector); + // var position = Vec3.sum(downPosition, extension); var buttonProperties = { name:'Hifi-Close-Button', type: 'Model', modelURL: CLOSE_BUTTON_MODEL_URL, dimensions: CLOSE_BUTTON_DIMENSIONS, - position: position, - rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), + position: Vec3.sum(endOfAxis,{ + x:0, + y:-0.15, + z:0 + }), + rotation: Quat.fromPitchYawRollDegrees(0, 45, 90), collisionsWillMove: false //need to add wantsTrigger stuff so we can interact with it with our beamz } @@ -440,7 +446,7 @@ function rotateCloseButtons() { Entities.editEntity(button, { angularVelocity: { x: 0, - y: 0.25, + y: 0.5, z: 0 } }) @@ -519,8 +525,8 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { currentLight = lightID; var lightProperties = Entities.getEntityProperties(lightID); - block = createBlock(lightProperties.position); - // block = createLightModel(lightProperties.position); + // block = createBlock(lightProperties.position); + block = createLightModel(lightProperties.position); var light = { id: lightID, @@ -532,12 +538,11 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { if (SHOW_LIGHT_VOLUME === true) { selectionManager.setSelections([lightID]); - print('SET SELECTIOIO MANAGER TO::: ' + lightID); - print('hasSelection???' + selectionManager.hasSelection()) } Entities.editEntity(lightID, { - parentID: block + parentID: block, + parentJointIndex:-1 }); @@ -551,10 +556,11 @@ function createLightModel(position) { type: 'Model', shapeType: 'box', modelURL: LIGHT_MODEL_URL, + // modelURL:"http://hifi-content.s3.amazonaws.com/james/light_modifier/box4.fbx", dimensions: LIGHT_MODEL_DIMENSIONS, collisionsWillMove: true, position: position, - rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), + // rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), script: PARENT_SCRIPT_URL, userData: JSON.stringify({ handControllerKey: { @@ -576,7 +582,7 @@ function createBlock(position) { type: 'Box', dimensions: { x: 1, - y: 1, + y: 4, z: 1 }, color: { @@ -606,6 +612,10 @@ function cleanup() { Entities.deleteEntity(sliders[i].sliderIndicator); } + while(closeButtons.length>0){ + Entities.deleteEntity(closeButtons.pop()); + } + Entities.deleteEntity(block); Messages.messageReceived.disconnect(handleLightModMessages); Messages.messageReceived.disconnect(handleValueMessages); diff --git a/examples/light_modifier/lightModifierTestScene.js b/examples/light_modifier/lightModifierTestScene.js index 4b78484a31..8df83b09bf 100644 --- a/examples/light_modifier/lightModifierTestScene.js +++ b/examples/light_modifier/lightModifierTestScene.js @@ -20,7 +20,7 @@ var light, block; function createLight() { var blockProperties = Entities.getEntityProperties(block, ["position", "rotation"]); var position = basePosition; - position.y += 3; + position.y += 2; var lightTransform = evalLightWorldTransform(position,avatarRot); // var lightTransform = evalLightWorldTransform(blockProperties.position, blockProperties.rotation); var lightProperties = { From 0e530900d4a40bbe7c741db2812bb1ca4160637e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 18 Dec 2015 16:22:20 -0800 Subject: [PATCH 31/57] sequential editing --- examples/light_modifier/closeButton.js | 12 +- examples/light_modifier/lightModifier.js | 161 +++++++++++------------ 2 files changed, 81 insertions(+), 92 deletions(-) diff --git a/examples/light_modifier/closeButton.js b/examples/light_modifier/closeButton.js index 045882fd33..7b2869cc8e 100644 --- a/examples/light_modifier/closeButton.js +++ b/examples/light_modifier/closeButton.js @@ -24,16 +24,12 @@ this.userData = JSON.parse(entityProperties.userData); }, startNearGrab: function() { - - }, - startDistantGrab: function() { }, - continueNearGrab: function() { - this.continueDistantGrab(); - }, - continueDistantGrab: function() { - }, + startFarTrigger: function() { + print('START FAR TRIGGER ON CLOSE BUTTON!!!') + Messages.sendMessage('Hifi-Light-Modifier-Cleanup', 'callCleanup') + } }; diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 76c1cdc873..5aa367dbbc 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -262,7 +262,7 @@ entitySlider.prototype = { color: this.color, position: sliderPosition, script: SLIDER_SCRIPT_URL, - ignoreForCollisions:true, + ignoreForCollisions: true, userData: JSON.stringify({ lightModifierKey: { lightID: this.lightID, @@ -407,30 +407,52 @@ function makeSliders(light) { subscribeToSliderMessages(); }; + +function createLightModel(position) { + var blockProperties = { + name: 'Hifi-Spotlight-Model', + type: 'Model', + shapeType: 'box', + modelURL: LIGHT_MODEL_URL, + dimensions: LIGHT_MODEL_DIMENSIONS, + collisionsWillMove: true, + position: position, + script: PARENT_SCRIPT_URL, + userData: JSON.stringify({ + handControllerKey: { + disableReleaseVelocity: true + } + }) + }; + + var block = Entities.addEntity(blockProperties); + + return block +} + var closeButtons = []; function createCloseButton(endOfAxis) { - // var avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); - // var basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(avatarRot))); - // var verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); - // var verticalOffset = lastRowVerticalOffset; - // var downPosition = Vec3.sum(basePosition, verticalOffset); - // var rightVector = Quat.getRight(avatarRot); - // var extension = Vec3.multiply(AXIS_SCALE, rightVector); - // var position = Vec3.sum(downPosition, extension); var buttonProperties = { - name:'Hifi-Close-Button', + name: 'Hifi-Close-Button', type: 'Model', modelURL: CLOSE_BUTTON_MODEL_URL, dimensions: CLOSE_BUTTON_DIMENSIONS, - position: Vec3.sum(endOfAxis,{ - x:0, - y:-0.15, - z:0 + position: Vec3.sum(endOfAxis, { + x: 0, + y: -0.15, + z: 0 }), rotation: Quat.fromPitchYawRollDegrees(0, 45, 90), - collisionsWillMove: false + collisionsWillMove: false, + ignoreForCollisions: true, + script: CLOSE_BUTTON_SCRIPT_URL, + userData: JSON.stringify({ + grabbableKey: { + wantsTrigger: true + } + }) //need to add wantsTrigger stuff so we can interact with it with our beamz } @@ -469,6 +491,11 @@ function subscribeToLightOverlayRayCheckMessages() { Messages.messageReceived.connect(handleLightOverlayRayCheckMessages); } +function subscribeToCleanupMessages() { + Messages.subscribe('Hifi-Light-Modifier-Cleanup'); + Messages.messageReceived.connect(handleCleanupMessages); +} + function handleLightModMessages(channel, message, sender) { if (channel !== 'Hifi-Light-Mod-Receiver') { @@ -513,9 +540,9 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { var pickRay = JSON.parse(message); var doesIntersect = lightOverlayManager.findRayIntersection(pickRay); - print('DOES INTERSECT A LIGHT WE HAVE???' + doesIntersect.intersects); + // print('DOES INTERSECT A LIGHT WE HAVE???' + doesIntersect.intersects); if (doesIntersect.intersects === true) { - print('FULL MESSAGE:::' + JSON.stringify(doesIntersect)) + // print('FULL MESSAGE:::' + JSON.stringify(doesIntersect)) var lightID = doesIntersect.entityID; if (currentLight === lightID) { @@ -525,7 +552,6 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { currentLight = lightID; var lightProperties = Entities.getEntityProperties(lightID); - // block = createBlock(lightProperties.position); block = createLightModel(lightProperties.position); var light = { @@ -542,103 +568,70 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { Entities.editEntity(lightID, { parentID: block, - parentJointIndex:-1 + parentJointIndex: -1 }); - } } -function createLightModel(position) { - print('CREATE MODEL') - var blockProperties = { - name: 'Hifi-Spotlight-Model', - type: 'Model', - shapeType: 'box', - modelURL: LIGHT_MODEL_URL, - // modelURL:"http://hifi-content.s3.amazonaws.com/james/light_modifier/box4.fbx", - dimensions: LIGHT_MODEL_DIMENSIONS, - collisionsWillMove: true, - position: position, - // rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), - script: PARENT_SCRIPT_URL, - userData: JSON.stringify({ - handControllerKey: { - disableReleaseVelocity: true - } - }) - }; +function handleCleanupMessages(channel, message, sender) { - var block = Entities.addEntity(blockProperties); - - return block + if (channel !== 'Hifi-Light-Modifier-Cleanup') { + return; + } + if (ONLY_I_CAN_EDIT === true && sender !== MyAvatar.sessionUUID) { + return; + } + if (message === 'callCleanup') { + print('GOT CLEANUP CALL!!!'); + cleanup(true); + } } -function createBlock(position) { - print('CREATE BLOCK') - - var blockProperties = { - name: 'Hifi-Spotlight-Block', - type: 'Box', - dimensions: { - x: 1, - y: 4, - z: 1 - }, - color: { - red: 0, - green: 0, - blue: 255 - }, - collisionsWillMove: true, - position: position, - script: PARENT_SCRIPT_URL, - userData: JSON.stringify({ - handControllerKey: { - disableReleaseVelocity: true - } - }) - }; - - var block = Entities.addEntity(blockProperties); - - return block -} - -function cleanup() { +function cleanup(fromMessage) { var i; for (i = 0; i < sliders.length; i++) { Entities.deleteEntity(sliders[i].axis); Entities.deleteEntity(sliders[i].sliderIndicator); } - while(closeButtons.length>0){ + while (closeButtons.length > 0) { Entities.deleteEntity(closeButtons.pop()); } - Entities.deleteEntity(block); + //if the light was already parented to something we will want to restore that. or come up with groups or something clever. + Entities.editEntity(currentLight, { + parentID: null, + }); + + if(fromMessage!==true){ Messages.messageReceived.disconnect(handleLightModMessages); Messages.messageReceived.disconnect(handleValueMessages); - Entities.deletingEntity.disconnect(deleteEntity); - + Messages.messageReceived.disconnect(handleLightOverlayRayCheckMessages); lightOverlayManager.setVisible(false); + } + + selectionManager.clearSelections(); Script.update.disconnect(rotateCloseButtons); + print('DELETE LIGHT MODEL::: ' + block); + Entities.deleteEntity(block); + currentLight = null; + + } Script.scriptEnding.connect(cleanup); -function deleteEntity(entityID) { - if (entityID === light) { - // cleanup(); - } -} +Script.scriptEnding.connect(function() { + lightOverlayManager.setVisible(false); +}) -Entities.deletingEntity.connect(deleteEntity); subscribeToLightOverlayRayCheckMessages(); subScribeToNewLights(); +subscribeToCleanupMessages(); From e405311cc8018fc870cf3291a2082174cec89ec1 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 18 Dec 2015 16:35:06 -0800 Subject: [PATCH 32/57] cleanup --- examples/light_modifier/closeButton.js | 1 - examples/light_modifier/lightModifier.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/examples/light_modifier/closeButton.js b/examples/light_modifier/closeButton.js index 7b2869cc8e..72fcfbc382 100644 --- a/examples/light_modifier/closeButton.js +++ b/examples/light_modifier/closeButton.js @@ -27,7 +27,6 @@ }, startFarTrigger: function() { - print('START FAR TRIGGER ON CLOSE BUTTON!!!') Messages.sendMessage('Hifi-Light-Modifier-Cleanup', 'callCleanup') } diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 5aa367dbbc..d813216be5 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -583,7 +583,6 @@ function handleCleanupMessages(channel, message, sender) { return; } if (message === 'callCleanup') { - print('GOT CLEANUP CALL!!!'); cleanup(true); } } @@ -615,7 +614,6 @@ function cleanup(fromMessage) { selectionManager.clearSelections(); Script.update.disconnect(rotateCloseButtons); - print('DELETE LIGHT MODEL::: ' + block); Entities.deleteEntity(block); currentLight = null; From f83476599090eef8ae08488283ebe898e5d0e0da Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 18 Dec 2015 16:39:21 -0800 Subject: [PATCH 33/57] readme --- examples/light_modifier/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/light_modifier/README.md b/examples/light_modifier/README.md index 3bd456d525..73c2199ec9 100644 --- a/examples/light_modifier/README.md +++ b/examples/light_modifier/README.md @@ -1,5 +1,7 @@ This PR demonstrates one way in-world editing of objects might work. We start with a spotlight. When you distant grab the sliders, you can move them along their axis to change their values. You may also rotate / move the block to which the spotlight is attached. +Enter edit mode by running your distance beam through a light overlay. Exit using the red X. + To test: https://rawgit.com/imgntn/hifi/light_mod/examples/lights/lightLoader.js To reset, I recommend stopping all scripts then re-loading lightLoader.js @@ -23,6 +25,4 @@ intensity cutoff exponent -To-Do: Determine how to enter / exit edit mode , support near grab, add other input types (checkbox, etc), prevent velocity drift on slider release,button to hide entity - -![capture](https://cloud.githubusercontent.com/assets/843228/11830366/2f2dfe70-a359-11e5-84f0-33a380ebeac7.PNG) +![capture](https://cloud.githubusercontent.com/assets/843228/11910139/afaaf1ae-a5a5-11e5-8b66-0eb3fc6976df.PNG) From 4afdd0242bfaf907b4dbdf4a6c707e1ca2aebd24 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 18 Dec 2015 16:44:20 -0800 Subject: [PATCH 34/57] cleanup --- .../light_modifier/lightModifierTestScene.js | 52 ++----------------- 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/examples/light_modifier/lightModifierTestScene.js b/examples/light_modifier/lightModifierTestScene.js index 8df83b09bf..58956850f2 100644 --- a/examples/light_modifier/lightModifierTestScene.js +++ b/examples/light_modifier/lightModifierTestScene.js @@ -10,19 +10,17 @@ // 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)); +var PARENT_SCRIPT_URL = Script.resolvePath('lightParent.js?' + Math.random(0 - 100)); var basePosition, avatarRot; avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(0, Quat.getUp(avatarRot))); -var light, block; +var light; function createLight() { - var blockProperties = Entities.getEntityProperties(block, ["position", "rotation"]); - var position = basePosition; + var position = basePosition; position.y += 2; - var lightTransform = evalLightWorldTransform(position,avatarRot); - // var lightTransform = evalLightWorldTransform(blockProperties.position, blockProperties.rotation); + var lightTransform = evalLightWorldTransform(position, avatarRot); var lightProperties = { name: 'Hifi-Spotlight', type: "Light", @@ -32,7 +30,6 @@ function createLight() { y: 2, z: 8 }, - // parentID: block, color: { red: 255, green: 0, @@ -48,45 +45,6 @@ function createLight() { 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 += 3; - 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, - script:PARENT_SCRIPT_URL, - userData: JSON.stringify({ - handControllerKey: { - disableReleaseVelocity: true - } - }) - }; - - block = Entities.addEntity(blockProperties); } function evalLightWorldTransform(modelPos, modelRot) { @@ -107,11 +65,9 @@ function evalLightWorldTransform(modelPos, modelRot) { } function cleanup() { - //Entities.deleteEntity(block); Entities.deleteEntity(light); } Script.scriptEnding.connect(cleanup); -//createBlock(); createLight(); \ No newline at end of file From b0da1773c246f4d619824355c336c2dac1c2869e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Fri, 18 Dec 2015 16:53:41 -0800 Subject: [PATCH 35/57] have right rotation on sequential edits --- examples/light_modifier/lightModifier.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index d813216be5..0d07f2c011 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -60,7 +60,7 @@ var CUTOFF_MAX = 360; var EXPONENT_MAX = 1; var SLIDER_SCRIPT_URL = Script.resolvePath('slider.js?' + Math.random(0, 100)); -var LIGHT_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/source4_rotated.fbx'; +var LIGHT_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/source4_very_good.fbx'; var CLOSE_BUTTON_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/red_x.fbx'; var CLOSE_BUTTON_SCRIPT_URL = Script.resolvePath('closeButton.js?' + Math.random(0, 100)); @@ -408,7 +408,7 @@ function makeSliders(light) { }; -function createLightModel(position) { +function createLightModel(position,rotation) { var blockProperties = { name: 'Hifi-Spotlight-Model', type: 'Model', @@ -417,6 +417,7 @@ function createLightModel(position) { dimensions: LIGHT_MODEL_DIMENSIONS, collisionsWillMove: true, position: position, + rotation:rotation, script: PARENT_SCRIPT_URL, userData: JSON.stringify({ handControllerKey: { @@ -552,7 +553,7 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { currentLight = lightID; var lightProperties = Entities.getEntityProperties(lightID); - block = createLightModel(lightProperties.position); + block = createLightModel(lightProperties.position,lightProperties.rotation); var light = { id: lightID, From eb03dcd8215aa92737b10ae5371eb181795ebe92 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 19 Dec 2015 12:47:44 -0800 Subject: [PATCH 36/57] keep parent of lights that already have parents --- examples/light_modifier/lightModifier.js | 36 +++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 0d07f2c011..e82897e049 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -47,10 +47,6 @@ if (SHOW_OVERLAYS === true) { lightOverlayManager.setVisible(true); } -// var entityResult = Entities.findRayIntersection(pickRay, true); // want precision picking -// var pickRay = Camera.computePickRay(event.x, event.y); -// var lightResult = lightOverlayManager.findRayIntersection(pickRay) - var DEFAULT_PARENT_ID = '{00000000-0000-0000-0000-000000000000}' var AXIS_SCALE = 1; @@ -408,7 +404,7 @@ function makeSliders(light) { }; -function createLightModel(position,rotation) { +function createLightModel(position, rotation) { var blockProperties = { name: 'Hifi-Spotlight-Model', type: 'Model', @@ -417,7 +413,7 @@ function createLightModel(position,rotation) { dimensions: LIGHT_MODEL_DIMENSIONS, collisionsWillMove: true, position: position, - rotation:rotation, + rotation: rotation, script: PARENT_SCRIPT_URL, userData: JSON.stringify({ handControllerKey: { @@ -529,6 +525,7 @@ function handleValueMessages(channel, message, sender) { var currentLight; var block; +var hasParent = false; function handleLightOverlayRayCheckMessages(channel, message, sender) { if (channel !== 'Hifi-Light-Overlay-Ray-Check') { @@ -553,7 +550,16 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { currentLight = lightID; var lightProperties = Entities.getEntityProperties(lightID); - block = createLightModel(lightProperties.position,lightProperties.rotation); + if (lightProperties.parentID !== DEFAULT_PARENT_ID) { + //this light has a parent already. so lets call our block the parent and then make sure not to delete it at the end; + hasParent = true; + block = lightProperties.parentID; + if (lightProperties.parentJointIndex !== -1) { + //should make sure to retain the parent too. but i don't actually know what the + } + } else { + block = createLightModel(lightProperties.position, lightProperties.rotation); + } var light = { id: lightID, @@ -604,18 +610,20 @@ function cleanup(fromMessage) { parentID: null, }); - if(fromMessage!==true){ - Messages.messageReceived.disconnect(handleLightModMessages); - Messages.messageReceived.disconnect(handleValueMessages); - Messages.messageReceived.disconnect(handleLightOverlayRayCheckMessages); - lightOverlayManager.setVisible(false); + if (fromMessage !== true) { + Messages.messageReceived.disconnect(handleLightModMessages); + Messages.messageReceived.disconnect(handleValueMessages); + Messages.messageReceived.disconnect(handleLightOverlayRayCheckMessages); + lightOverlayManager.setVisible(false); } selectionManager.clearSelections(); Script.update.disconnect(rotateCloseButtons); - - Entities.deleteEntity(block); + if (hasParent === false) { + Entities.deleteEntity(block); + } + hasParent = false; currentLight = null; From 378d50d8a3174086ae451e3a048ff3aa96e7ac62 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 19 Dec 2015 12:49:42 -0800 Subject: [PATCH 37/57] update overlays when cutoff slider is used --- examples/light_modifier/slider.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/light_modifier/slider.js b/examples/light_modifier/slider.js index dc02e0bdba..6c67d35204 100644 --- a/examples/light_modifier/slider.js +++ b/examples/light_modifier/slider.js @@ -95,6 +95,9 @@ sliderValue: _t.sliderValue } Messages.sendMessage('Hifi-Slider-Value-Reciever', JSON.stringify(message)); + if (_t.userData.sliderType === 'cutoff') { + Messages.sendMessage('entityToolUpdates', 'callUpdate'); + } } }; From 05467bd5e1a356afca087c151f0c77f29aa5e238 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 19 Dec 2015 18:19:00 -0800 Subject: [PATCH 38/57] create panel entity and parent panel to it --- examples/light_modifier/lightModifier.js | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index e82897e049..14053c7974 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -363,6 +363,10 @@ var light = null; function makeSliders(light) { + if (USE_PARENTED_PANEL === true) { + createPanelEntity(MyAvatar.position); + } + if (light.type === 'spotlight') { var USE_COLOR_SLIDER = true; var USE_INTENSITY_SLIDER = true; @@ -398,12 +402,55 @@ function makeSliders(light) { sliders.push(slidersRef.exponent); } + + createCloseButton(slidersRef.exponent.endOfAxis); subscribeToSliderMessages(); + + if (USE_PARENTED_PANEL === true) { + parentEntitiesToPanel(); + } }; +function parentEntitiesToPanel(panel) { + slidersRef.forEach(function(slider) { + Entities.editEntity(slider.axis, { + parentID: panel + }) + Entities.editEntity(slider.sliderIndicator, { + parentID: panel + }) + }) + + closeButtons.forEach(function(button) { + Entities.editEntity(slider.sliderIndicator, { + parentID: panel + }) + }) +} + +function createPanelEntity(position) { + + var panelProperties = { + name: 'Hifi-Slider-Panel', + type: 'Box', + dimensions: { + x: 0.1, + y: 0.1, + z: 0.1 + }, + visible: false, + collisionsWillMove: false, + ignoreForCollisions: true + } + + var panel = Entities.addEntity(panelProperties); + return panel +} + + function createLightModel(position, rotation) { var blockProperties = { name: 'Hifi-Spotlight-Model', From 9f0d254739df2a9a158c01a138a85717dcad0812 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 19 Dec 2015 19:11:17 -0800 Subject: [PATCH 39/57] panel entity, readme --- examples/light_modifier/README.md | 16 ++++++------- examples/light_modifier/lightModifier.js | 29 ++++++++++++++++-------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/examples/light_modifier/README.md b/examples/light_modifier/README.md index 73c2199ec9..b12ff7550b 100644 --- a/examples/light_modifier/README.md +++ b/examples/light_modifier/README.md @@ -1,6 +1,8 @@ -This PR demonstrates one way in-world editing of objects might work. We start with a spotlight. When you distant grab the sliders, you can move them along their axis to change their values. You may also rotate / move the block to which the spotlight is attached. +This PR demonstrates one way in-world editing of objects might work. -Enter edit mode by running your distance beam through a light overlay. Exit using the red X. +Running this script will show light overlay icons in-world. Enter edit mode by running your distance beam through a light overlay. Exit using the red X. + +When you distant grab the sliders, you can move them along their axis to change their values. You may also rotate / move the block to which the spotlight is attached. To test: https://rawgit.com/imgntn/hifi/light_mod/examples/lights/lightLoader.js To reset, I recommend stopping all scripts then re-loading lightLoader.js @@ -8,14 +10,12 @@ To reset, I recommend stopping all scripts then re-loading lightLoader.js When you run the lightLoader.js script, several scripts will be loaded: - handControllerGrab.js (custom) - lightModifier.js (listens for message to create sliders for a given light) -- lightModifierTestScene.js (creates a light and parents it to a block, then sends a message ^^) +- lightModifierTestScene.js (creates a light) - slider.js (attached to each slider entity) -- lightParent.js (attached to the entity to which a light is parented, so you can move it around) +- lightParent.js (attached to a 3d model of a light, to which a light is parented, so you can move it around. or keep the current parent if a light already has a parent) - closeButton.js (for closing the ui) -- ../libraries/lightOverlayManager.js (custom) -- ../libraries/entitySelectionTool.js - - +- ../libraries/lightOverlayManager.js (shows 2d overlays for lights in the world) +- ../libraries/entitySelectionTool.js (visualizes volume of the lights) Current sliders are (top to bottom): red diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 14053c7974..30f004c922 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -16,13 +16,14 @@ var SLIDERS_SHOULD_STAY_WITH_AVATAR = false; var VERTICAL_SLIDERS = false; var SHOW_OVERLAYS = true; var SHOW_LIGHT_VOLUME = true; +var USE_PARENTED_PANEL = false; //variables for managing overlays var selectionDisplay; var selectionManager; var lightOverlayManager; -//for when we make a block parent for the light +//for when we make a 3d model of a light a parent for the light var PARENT_SCRIPT_URL = Script.resolvePath('lightParent.js?' + Math.random(0 - 100)); if (SHOW_OVERLAYS === true) { @@ -362,9 +363,9 @@ var slidersRef = { var light = null; function makeSliders(light) { - + var panel; if (USE_PARENTED_PANEL === true) { - createPanelEntity(MyAvatar.position); + panel = createPanelEntity(MyAvatar.position); } if (light.type === 'spotlight') { @@ -409,10 +410,21 @@ function makeSliders(light) { subscribeToSliderMessages(); if (USE_PARENTED_PANEL === true) { - parentEntitiesToPanel(); + parentEntitiesToPanel(panel); + } + + if () { + parentPanelToAvatar(panel) } }; +function parentPanelToAvatar(panel) { + Entities.editEntity(panel, { + parentID: MyAvatar.sessionUUID, + //actually figure out which one to parent it to -- probably a spine or something. + parentJointIndex: 1, + }) +} function parentEntitiesToPanel(panel) { slidersRef.forEach(function(slider) { @@ -493,11 +505,10 @@ function createCloseButton(endOfAxis) { ignoreForCollisions: true, script: CLOSE_BUTTON_SCRIPT_URL, userData: JSON.stringify({ - grabbableKey: { - wantsTrigger: true - } - }) - //need to add wantsTrigger stuff so we can interact with it with our beamz + grabbableKey: { + wantsTrigger: true + } + }) } var button = Entities.addEntity(buttonProperties); From daa262af7d33d18866d304a5c3b9d1c5e33aeb55 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 19 Dec 2015 19:14:19 -0800 Subject: [PATCH 40/57] readme --- examples/light_modifier/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/light_modifier/README.md b/examples/light_modifier/README.md index b12ff7550b..4a2690cd91 100644 --- a/examples/light_modifier/README.md +++ b/examples/light_modifier/README.md @@ -8,7 +8,7 @@ To test: https://rawgit.com/imgntn/hifi/light_mod/examples/lights/lightLoader.js To reset, I recommend stopping all scripts then re-loading lightLoader.js When you run the lightLoader.js script, several scripts will be loaded: -- handControllerGrab.js (custom) +- handControllerGrab.js (will not impart velocity when you move the parent or a slider, will not move sliders with head movement,will constrain movement for a slider to a given axis start and end) - lightModifier.js (listens for message to create sliders for a given light) - lightModifierTestScene.js (creates a light) - slider.js (attached to each slider entity) From 485bb4ee3f3948f505fdffda30bc67bafa1c3428 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sat, 19 Dec 2015 19:14:56 -0800 Subject: [PATCH 41/57] slider should stay with avatr --- examples/light_modifier/lightModifier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 30f004c922..02d764e7e2 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -413,7 +413,7 @@ function makeSliders(light) { parentEntitiesToPanel(panel); } - if () { + if (SLIDERS_SHOULD_STAY_WITH_AVATAR) { parentPanelToAvatar(panel) } }; From da57e29096069c06f841aa4e6d6fdbed27989e71 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Sun, 20 Dec 2015 16:40:41 -0800 Subject: [PATCH 42/57] start options, cleanup --- examples/light_modifier/README.md | 2 +- examples/light_modifier/slider.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/light_modifier/README.md b/examples/light_modifier/README.md index 4a2690cd91..1358fbe917 100644 --- a/examples/light_modifier/README.md +++ b/examples/light_modifier/README.md @@ -9,7 +9,7 @@ To reset, I recommend stopping all scripts then re-loading lightLoader.js When you run the lightLoader.js script, several scripts will be loaded: - handControllerGrab.js (will not impart velocity when you move the parent or a slider, will not move sliders with head movement,will constrain movement for a slider to a given axis start and end) -- lightModifier.js (listens for message to create sliders for a given light) +- lightModifier.js (listens for message to create sliders for a given light. will start with slider set to the light's initial properties) - lightModifierTestScene.js (creates a light) - slider.js (attached to each slider entity) - lightParent.js (attached to a 3d model of a light, to which a light is parented, so you can move it around. or keep the current parent if a light already has a parent) diff --git a/examples/light_modifier/slider.js b/examples/light_modifier/slider.js index 6c67d35204..e1dfea4e87 100644 --- a/examples/light_modifier/slider.js +++ b/examples/light_modifier/slider.js @@ -50,16 +50,16 @@ var distance = Vec3.distance(this.userData.axisStart, currentPosition); 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, 0, COLOR_MAX); } if (this.userData.sliderType === 'intensity') { - this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, INTENSITY_MAX); + this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, 0, INTENSITY_MAX); } if (this.userData.sliderType === 'cutoff') { - this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, CUTOFF_MAX); + this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, 0, CUTOFF_MAX); } if (this.userData.sliderType === 'exponent') { - this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, EXPONENT_MAX); + this.sliderValue = this.scaleValueBasedOnDistanceFromStart(distance, 0, EXPONENT_MAX); }; this.sendValueToSlider(); @@ -80,10 +80,10 @@ this.sendValueToSlider(); }, - scaleValueBasedOnDistanceFromStart: function(value, max2) { + scaleValueBasedOnDistanceFromStart: function(value, min2, max2) { var min1 = 0; var max1 = AXIS_SCALE; - var min2 = 0; + var min2 = min2; var max2 = max2; return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); }, From b59b8db5c935884238d6c5f269cbc922ccbf2322 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 21 Dec 2015 12:09:18 -0800 Subject: [PATCH 43/57] set defaults --- examples/light_modifier/lightModifier.js | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 02d764e7e2..e8a9f39903 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -120,6 +120,17 @@ var PER_ROW_OFFSET = { y: -0.2, z: 0 }; +var sliders = []; +var slidersRef = { + 'color_red': null, + 'color_green': null, + 'color_blue': null, + intensity: null, + cutoff: null, + exponent: null +}; +var light = null; + function entitySlider(light, color, sliderType, row) { this.light = light; @@ -351,17 +362,6 @@ entitySlider.prototype = { }; -var sliders = []; -var slidersRef = { - 'color_red': null, - 'color_green': null, - 'color_blue': null, - intensity: null, - cutoff: null, - exponent: null -} -var light = null; - function makeSliders(light) { var panel; if (USE_PARENTED_PANEL === true) { @@ -403,8 +403,6 @@ function makeSliders(light) { sliders.push(slidersRef.exponent); } - - createCloseButton(slidersRef.exponent.endOfAxis); subscribeToSliderMessages(); @@ -413,12 +411,13 @@ function makeSliders(light) { parentEntitiesToPanel(panel); } - if (SLIDERS_SHOULD_STAY_WITH_AVATAR) { - parentPanelToAvatar(panel) + if (SLIDERS_SHOULD_STAY_WITH_AVATAR === true) { + parentPanelToAvatar(panel); } }; function parentPanelToAvatar(panel) { + //this is going to need some more work re: the sliders actually being grabbable. probably something to do with updating axis movement Entities.editEntity(panel, { parentID: MyAvatar.sessionUUID, //actually figure out which one to parent it to -- probably a spine or something. @@ -427,7 +426,8 @@ function parentPanelToAvatar(panel) { } function parentEntitiesToPanel(panel) { - slidersRef.forEach(function(slider) { + + sliders.forEach(function(slider) { Entities.editEntity(slider.axis, { parentID: panel }) @@ -437,14 +437,14 @@ function parentEntitiesToPanel(panel) { }) closeButtons.forEach(function(button) { - Entities.editEntity(slider.sliderIndicator, { + Entities.editEntity(button, { parentID: panel }) }) } function createPanelEntity(position) { - + print('CREATING PANEL at ' + JSON.stringify(position)); var panelProperties = { name: 'Hifi-Slider-Panel', type: 'Box', From 56d654987c1f0fe91731f5671900e927814f124b Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 22 Dec 2015 11:48:56 -0800 Subject: [PATCH 44/57] changing branches --- examples/light_modifier/lightModifier.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index e8a9f39903..48efe89a6e 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -8,7 +8,9 @@ // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// +// + +// todo: text labels for property names, panel plane for visibility //some experimental options var ONLY_I_CAN_EDIT = false; @@ -16,7 +18,7 @@ var SLIDERS_SHOULD_STAY_WITH_AVATAR = false; var VERTICAL_SLIDERS = false; var SHOW_OVERLAYS = true; var SHOW_LIGHT_VOLUME = true; -var USE_PARENTED_PANEL = false; +var USE_PARENTED_PANEL = true; //variables for managing overlays var selectionDisplay; @@ -225,6 +227,9 @@ entitySlider.prototype = { }; this.axis = Entities.addEntity(properties); + }, + createLabel:function(){ + }, createSliderIndicator: function() { var extensionVector; @@ -652,6 +657,12 @@ function handleCleanupMessages(channel, message, sender) { } } +function updateSliderAxis(){ + sliders.forEach(function(slider){ + + }) +} + function cleanup(fromMessage) { var i; for (i = 0; i < sliders.length; i++) { From c39f26ad72c340fb09a5e4e4e91c45ca7f9dd1c5 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 22 Dec 2015 16:31:49 -0800 Subject: [PATCH 45/57] new features --- examples/light_modifier/lightModifier.js | 113 ++++++++++++++++++++--- 1 file changed, 98 insertions(+), 15 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 48efe89a6e..4e0507b69f 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -19,6 +19,8 @@ var VERTICAL_SLIDERS = false; var SHOW_OVERLAYS = true; var SHOW_LIGHT_VOLUME = true; var USE_PARENTED_PANEL = true; +var VISIBLE_PANEL = true; +var USE_LABELS = true; //variables for managing overlays var selectionDisplay; @@ -62,6 +64,7 @@ var SLIDER_SCRIPT_URL = Script.resolvePath('slider.js?' + Math.random(0, 100)); var LIGHT_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/source4_very_good.fbx'; var CLOSE_BUTTON_MODEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/red_x.fbx'; var CLOSE_BUTTON_SCRIPT_URL = Script.resolvePath('closeButton.js?' + Math.random(0, 100)); +var TRANSPARENT_PANEL_URL = 'http://hifi-content.s3.amazonaws.com/james/light_modifier/transparent_box_alpha_15.fbx'; var RED = { red: 255, @@ -134,12 +137,13 @@ var slidersRef = { var light = null; -function entitySlider(light, color, sliderType, row) { +function entitySlider(light, color, sliderType, displayText, row) { this.light = light; this.lightID = light.id.replace(/[{}]/g, ""); this.initialProperties = light.initialProperties; this.color = color; this.sliderType = sliderType; + this.displayText = displayText; this.verticalOffset = Vec3.multiply(row, PER_ROW_OFFSET); this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(this.avatarRot))); @@ -182,6 +186,9 @@ function entitySlider(light, color, sliderType, row) { this.setInitialSliderPositions(); this.createAxis(); this.createSliderIndicator(); + if (USE_LABELS === true) { + this.createLabel() + } return this; } @@ -205,6 +212,8 @@ entitySlider.prototype = { extension = Vec3.multiply(AXIS_SCALE, rightVector); } + + this.axisStart = position; this.endOfAxis = Vec3.sum(position, extension); var properties = { type: 'Line', @@ -228,8 +237,35 @@ entitySlider.prototype = { this.axis = Entities.addEntity(properties); }, - createLabel:function(){ - + createLabel: function() { + var LABEL_WIDTH = 0.25 + var leftVector = Vec.multiply(-1, Quat.getRight(this.avatarRot)); + var extension = Vec3.multiply(LABEL_WIDTH, leftVector); + var position = Vec3.sum(this.axisStart, extension); + var labelProperties = { + name: 'Hifi-Slider-Label-' + this.sliderType, + type: 'Text', + dimensions: { + x: LABEL_WIDTH, + y: 0.2, + z: 0.1 + }, + textColor: { + red: 255, + green: 255, + blue: 255 + }, + text: this.displayText, + lineHeight: 0.14, + backgroundColor: { + red: 0, + green: 0, + blue: 0 + }, + + } + + this.label = Entities.addEntity(labelProperties); }, createSliderIndicator: function() { var extensionVector; @@ -367,8 +403,12 @@ entitySlider.prototype = { }; + +var panel; +var visiblePanel; + function makeSliders(light) { - var panel; + if (USE_PARENTED_PANEL === true) { panel = createPanelEntity(MyAvatar.position); } @@ -386,9 +426,9 @@ function makeSliders(light) { var USE_EXPONENT_SLIDER = false; } if (USE_COLOR_SLIDER === true) { - slidersRef.color_red = new entitySlider(light, RED, 'color_red', 1); - slidersRef.color_green = new entitySlider(light, GREEN, 'color_green', 2); - slidersRef.color_blue = new entitySlider(light, BLUE, 'color_blue', 3); + slidersRef.color_red = new entitySlider(light, RED, 'color_red', 'Red', 1); + slidersRef.color_green = new entitySlider(light, GREEN, 'color_green', 'Green', 2); + slidersRef.color_blue = new entitySlider(light, BLUE, 'color_blue', 'Blue', 3); sliders.push(slidersRef.color_red); sliders.push(slidersRef.color_green); @@ -396,15 +436,15 @@ function makeSliders(light) { } if (USE_INTENSITY_SLIDER === true) { - slidersRef.intensity = new entitySlider(light, WHITE, 'intensity', 4); + slidersRef.intensity = new entitySlider(light, WHITE, 'intensity', 'Intensity', 4); sliders.push(slidersRef.intensity); } if (USE_CUTOFF_SLIDER === true) { - slidersRef.cutoff = new entitySlider(light, PURPLE, 'cutoff', 5); + slidersRef.cutoff = new entitySlider(light, PURPLE, 'cutoff', 'Cutoff', 5); sliders.push(slidersRef.cutoff); } if (USE_EXPONENT_SLIDER === true) { - slidersRef.exponent = new entitySlider(light, ORANGE, 'exponent', 6); + slidersRef.exponent = new entitySlider(light, ORANGE, 'exponent', 'Exponent', 6); sliders.push(slidersRef.exponent); } @@ -419,6 +459,10 @@ function makeSliders(light) { if (SLIDERS_SHOULD_STAY_WITH_AVATAR === true) { parentPanelToAvatar(panel); } + + if (VISIBLE_PANEL === true) { + visiblePanel = createVisiblePanel(); + } }; function parentPanelToAvatar(panel) { @@ -430,6 +474,9 @@ function parentPanelToAvatar(panel) { }) } + +function updateAxisWhe + function parentEntitiesToPanel(panel) { sliders.forEach(function(slider) { @@ -467,6 +514,29 @@ function createPanelEntity(position) { return panel } +function createVisiblePanel(position) { + print('CREATING VISIBLE PANEL at ' + JSON.stringify(position)); + + var totalOffset = Vec3.multiply(sliders.length, PER_ROW_OFFSET); + var panelProperties = { + name: 'Hifi-Visible-Transparent-Panel', + type: 'Model', + modelURL: TRANSPARENT_PANEL_URL, + dimensions: { + x: 1, + y: 1.4, + z: 0.1 + }, + visible: true, + collisionsWillMove: false, + ignoreForCollisions: true, + position: position + } + + var panel = Entities.addEntity(panelProperties); + return panel +} + function createLightModel(position, rotation) { var blockProperties = { @@ -588,6 +658,7 @@ function handleValueMessages(channel, message, sender) { var currentLight; var block; +var oldParent = null; var hasParent = false; function handleLightOverlayRayCheckMessages(channel, message, sender) { @@ -615,6 +686,7 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { var lightProperties = Entities.getEntityProperties(lightID); if (lightProperties.parentID !== DEFAULT_PARENT_ID) { //this light has a parent already. so lets call our block the parent and then make sure not to delete it at the end; + oldParent = lightProperties.parentID; hasParent = true; block = lightProperties.parentID; if (lightProperties.parentJointIndex !== -1) { @@ -657,8 +729,8 @@ function handleCleanupMessages(channel, message, sender) { } } -function updateSliderAxis(){ - sliders.forEach(function(slider){ +function updateSliderAxis() { + sliders.forEach(function(slider) { }) } @@ -675,9 +747,16 @@ function cleanup(fromMessage) { } //if the light was already parented to something we will want to restore that. or come up with groups or something clever. - Entities.editEntity(currentLight, { - parentID: null, - }); + if (oldParent !== null) { + Entities.editEntity(currentLight, { + parentID: oldParent, + }); + } else { + Entities.editEntity(currentLight, { + parentID: null, + }); + } + if (fromMessage !== true) { Messages.messageReceived.disconnect(handleLightModMessages); @@ -687,11 +766,15 @@ function cleanup(fromMessage) { } + Entities.deleteEntity(panel); + Entities.deleteEntity(visiblePanel); + selectionManager.clearSelections(); Script.update.disconnect(rotateCloseButtons); if (hasParent === false) { Entities.deleteEntity(block); } + oldParent = null; hasParent = false; currentLight = null; From aa0d1f0c29a0ae6e14b0bac03307ed218cd84b6e Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 22 Dec 2015 17:15:23 -0800 Subject: [PATCH 46/57] temp --- examples/light_modifier/lightModifier.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 4e0507b69f..a347aeadb0 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -10,8 +10,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -// todo: text labels for property names, panel plane for visibility - //some experimental options var ONLY_I_CAN_EDIT = false; var SLIDERS_SHOULD_STAY_WITH_AVATAR = false; @@ -514,23 +512,23 @@ function createPanelEntity(position) { return panel } -function createVisiblePanel(position) { +function createVisiblePanel() { print('CREATING VISIBLE PANEL at ' + JSON.stringify(position)); - var totalOffset = Vec3.multiply(sliders.length, PER_ROW_OFFSET); + var totalOffset = -PER_ROW_OFFSET.y * sliders.length; var panelProperties = { name: 'Hifi-Visible-Transparent-Panel', type: 'Model', modelURL: TRANSPARENT_PANEL_URL, dimensions: { x: 1, - y: 1.4, + y: totalOffset, z: 0.1 }, visible: true, collisionsWillMove: false, ignoreForCollisions: true, - position: position + position: this.basePosition } var panel = Entities.addEntity(panelProperties); From 65d5e3f60a3a919fd0d0ee00357ce4e2f0e62e3f Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 23 Dec 2015 14:11:42 -0800 Subject: [PATCH 47/57] add labels and transparent panel, but panel blocks pick so disable --- examples/light_modifier/lightModifier.js | 83 ++++++++++++++++++++---- 1 file changed, 69 insertions(+), 14 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index a347aeadb0..dc9332405e 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -17,8 +17,10 @@ var VERTICAL_SLIDERS = false; var SHOW_OVERLAYS = true; var SHOW_LIGHT_VOLUME = true; var USE_PARENTED_PANEL = true; -var VISIBLE_PANEL = true; +var VISIBLE_PANEL = false; var USE_LABELS = true; +var LEFT_LABELS = false; +var RIGHT_LABELS = true; //variables for managing overlays var selectionDisplay; @@ -134,6 +136,8 @@ var slidersRef = { }; var light = null; +var basePosition; +var avatarRotation; function entitySlider(light, color, sliderType, displayText, row) { this.light = light; @@ -146,6 +150,8 @@ function entitySlider(light, color, sliderType, displayText, row) { this.avatarRot = Quat.fromPitchYawRollDegrees(0, MyAvatar.bodyYaw, 0.0); this.basePosition = Vec3.sum(MyAvatar.position, Vec3.multiply(1.5, Quat.getFront(this.avatarRot))); this.basePosition.y += 1; + basePosition=this.basePosition; + avatarRot = this.avatarRot; var message = { lightID: this.lightID, @@ -213,6 +219,8 @@ entitySlider.prototype = { this.axisStart = position; this.endOfAxis = Vec3.sum(position, extension); + this.createEndOfAxisEntity(); + var properties = { type: 'Line', name: 'Hifi-Slider-Axis::' + this.sliderType, @@ -235,16 +243,59 @@ entitySlider.prototype = { this.axis = Entities.addEntity(properties); }, + createEndOfAxisEntity: function() { + //we use this to track the end of the axis while parented to a panel + var properties = { + name: 'Hifi-End-Of-Axis', + type: 'Box', + collisionsWillMove: false, + ignoreForCollisions: true, + dimensions: { + x: 0.01, + y: 0.01, + z: 0.01 + }, + color: { + red: 255, + green: 255, + blue: 255 + }, + position: this.endOfAxis, + parentID:this.axis, + visible: false + } + + this.endOfAxisEntity = Entities.addEntity(this.endOfAxis); + }, createLabel: function() { + var LABEL_WIDTH = 0.25 - var leftVector = Vec.multiply(-1, Quat.getRight(this.avatarRot)); - var extension = Vec3.multiply(LABEL_WIDTH, leftVector); - var position = Vec3.sum(this.axisStart, extension); + var PER_LETTER_SPACING = 0.1; + var textWidth = this.displayText.length * PER_LETTER_SPACING; + + var position; + if (LEFT_LABELS === true) { + var leftVector = Vec3.multiply(-1, Quat.getRight(this.avatarRot)); + + var extension = Vec3.multiply(textWidth, leftVector); + + position = Vec3.sum(this.axisStart, extension); + } + + if (RIGHT_LABELS === true) { + var rightVector = Quat.getRight(this.avatarRot); + + var extension = Vec3.multiply(textWidth / 1.75, rightVector); + + position = Vec3.sum(this.endOfAxis, extension); + } + + var labelProperties = { name: 'Hifi-Slider-Label-' + this.sliderType, type: 'Text', dimensions: { - x: LABEL_WIDTH, + x: textWidth, y: 0.2, z: 0.1 }, @@ -260,10 +311,12 @@ entitySlider.prototype = { green: 0, blue: 0 }, - + position: position, + rotation:this.avatarRot, } - + print('BEFORE CREATE LABEL' + JSON.stringify(labelProperties)) this.label = Entities.addEntity(labelProperties); + print('AFTER CREATE LABEL') }, createSliderIndicator: function() { var extensionVector; @@ -473,8 +526,6 @@ function parentPanelToAvatar(panel) { } -function updateAxisWhe - function parentEntitiesToPanel(panel) { sliders.forEach(function(slider) { @@ -513,22 +564,25 @@ function createPanelEntity(position) { } function createVisiblePanel() { - print('CREATING VISIBLE PANEL at ' + JSON.stringify(position)); - var totalOffset = -PER_ROW_OFFSET.y * sliders.length; + + var moveRight =Vec3.sum(basePosition,Vec3.multiply(AXIS_SCALE/2,Quat.getRight(avatarRot))); + + var moveDown = Vec3.sum(moveRight,Vec3.multiply((sliders.length+1)/2,PER_ROW_OFFSET)) var panelProperties = { name: 'Hifi-Visible-Transparent-Panel', type: 'Model', modelURL: TRANSPARENT_PANEL_URL, dimensions: { - x: 1, + x: AXIS_SCALE+0.1, y: totalOffset, - z: 0.1 + z: SLIDER_DIMENSIONS.z/4 }, visible: true, collisionsWillMove: false, ignoreForCollisions: true, - position: this.basePosition + position: moveDown, + rotation:avatarRot } var panel = Entities.addEntity(panelProperties); @@ -738,6 +792,7 @@ function cleanup(fromMessage) { for (i = 0; i < sliders.length; i++) { Entities.deleteEntity(sliders[i].axis); Entities.deleteEntity(sliders[i].sliderIndicator); + Entities.deleteEntity(sliders[i].label); } while (closeButtons.length > 0) { From d4fd59edc0299101599959f7e7732535808f1b41 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 13:49:00 -0800 Subject: [PATCH 48/57] send blacklist messages --- examples/light_modifier/lightModifier.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index dc9332405e..3ead989d6d 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -17,7 +17,7 @@ var VERTICAL_SLIDERS = false; var SHOW_OVERLAYS = true; var SHOW_LIGHT_VOLUME = true; var USE_PARENTED_PANEL = true; -var VISIBLE_PANEL = false; +var VISIBLE_PANEL = true; var USE_LABELS = true; var LEFT_LABELS = false; var RIGHT_LABELS = true; @@ -586,6 +586,8 @@ function createVisiblePanel() { } var panel = Entities.addEntity(panelProperties); + var data = {action:'add', id:panel}; + Messages.sendMessage ('Hifi-Hand-RayPick-Blacklist',JSON.stringify(data)) return panel } @@ -821,7 +823,12 @@ function cleanup(fromMessage) { Entities.deleteEntity(panel); Entities.deleteEntity(visiblePanel); - + var data = { + action: 'remove', + id: visiblePanel + }; + Messages.sendMessage('Hifi-Hand-RayPick-Blacklist', JSON.stringify(data)) + selectionManager.clearSelections(); Script.update.disconnect(rotateCloseButtons); if (hasParent === false) { From bea18e91aa08ac3ef6fb6fb07f5db5ea88e5c05c Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 28 Dec 2015 15:09:49 -0800 Subject: [PATCH 49/57] Guard against empty polyline index out of range --- .../entities-renderer/src/RenderablePolyLineEntityItem.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index cfdcc87121..7b3bbc4c02 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -141,6 +141,11 @@ void RenderablePolyLineEntityItem::updateVertices() { _vertices << v1 << v2; } + // Guard against an empty polyline + if (finalIndex < 0) { + return; + } + // For last point we can assume binormals are the same since it represents the last two vertices of quad point = _points.at(finalIndex); v1 = point + binormal; From 5786789a665f4e271084131f1a0124b47ada99f0 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 15:12:29 -0800 Subject: [PATCH 50/57] cleanup cleanup --- examples/light_modifier/lightModifier.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 08271fa7a8..eff373d3d7 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -636,7 +636,7 @@ function createCloseButton(axisStart) { modelURL: CLOSE_BUTTON_MODEL_URL, dimensions: CLOSE_BUTTON_DIMENSIONS, position: Vec3.sum(position, VERTICAL_OFFFSET), - rotation: Quat.multiply(avatarRot,Quat.fromPitchYawRollDegrees(90, 0, 45)), + rotation: Quat.multiply(avatarRot, Quat.fromPitchYawRollDegrees(90, 0, 45)), //rotation: Quat.fromPitchYawRollDegrees(0, 0, 90), collisionsWillMove: false, ignoreForCollisions: true, @@ -652,8 +652,8 @@ function createCloseButton(axisStart) { closeButtons.push(button); - if(ROTATE_CLOSE_BUTTON===true){ - Script.update.connect(rotateCloseButtons); + if (ROTATE_CLOSE_BUTTON === true) { + Script.update.connect(rotateCloseButtons); } } @@ -742,7 +742,7 @@ function handleLightOverlayRayCheckMessages(channel, message, sender) { var lightID = doesIntersect.entityID; if (currentLight === lightID) { - // print('ALREADY HAVE A BLOCK, EXIT') + // print('ALREADY HAVE A BLOCK, EXIT') return; } @@ -833,17 +833,17 @@ function cleanup(fromMessage) { Entities.deleteEntity(panel); Entities.deleteEntity(visiblePanel); - var data = { - action: 'remove', - id: visiblePanel - }; - Messages.sendMessage('Hifi-Hand-RayPick-Blacklist', JSON.stringify(data)) selectionManager.clearSelections(); - Script.update.disconnect(rotateCloseButtons); + + if (ROTATE_CLOSE_BUTTON === true) { + Script.update.disconnect(rotateCloseButtons); + } + if (hasParent === false) { Entities.deleteEntity(block); } + oldParent = null; hasParent = false; currentLight = null; From 9f342ba8ce14661a130ed2635a31e5130057d8e7 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 15:14:59 -0800 Subject: [PATCH 51/57] readme --- examples/light_modifier/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/light_modifier/README.md b/examples/light_modifier/README.md index 1358fbe917..f23f22148a 100644 --- a/examples/light_modifier/README.md +++ b/examples/light_modifier/README.md @@ -8,11 +8,12 @@ To test: https://rawgit.com/imgntn/hifi/light_mod/examples/lights/lightLoader.js To reset, I recommend stopping all scripts then re-loading lightLoader.js When you run the lightLoader.js script, several scripts will be loaded: -- handControllerGrab.js (will not impart velocity when you move the parent or a slider, will not move sliders with head movement,will constrain movement for a slider to a given axis start and end) +- handControllerGrab.js (will not impart velocity when you move the parent or a slider, will not move sliders with head movement,will constrain movement for a slider to a given axis start and end, will support blacklisting of entities for raypicking during search for objects) - lightModifier.js (listens for message to create sliders for a given light. will start with slider set to the light's initial properties) - lightModifierTestScene.js (creates a light) - slider.js (attached to each slider entity) - lightParent.js (attached to a 3d model of a light, to which a light is parented, so you can move it around. or keep the current parent if a light already has a parent) +- visiblePanel.js (the transparent panel) - closeButton.js (for closing the ui) - ../libraries/lightOverlayManager.js (shows 2d overlays for lights in the world) - ../libraries/entitySelectionTool.js (visualizes volume of the lights) From c266a093e026cf4d60cd3a98f64ffc76474e587b Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 15:17:00 -0800 Subject: [PATCH 52/57] clear sliders at cleanup --- examples/light_modifier/lightModifier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index eff373d3d7..52d9342464 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -847,7 +847,7 @@ function cleanup(fromMessage) { oldParent = null; hasParent = false; currentLight = null; - + sliders = []; } From 2ec712a5db30b2c847fb8da5e02f8770f99ceece Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 28 Dec 2015 15:27:17 -0800 Subject: [PATCH 53/57] disable near grabbing on sliders --- examples/controllers/handControllerGrab.js | 35 +++++++++++++++++----- examples/light_modifier/lightModifier.js | 3 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 50fdf3353c..9652132c08 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -788,14 +788,19 @@ function MyController(hand) { } else { intersection = Entities.findRayIntersection(pickRayBacked, true); } - + if (intersection.intersects) { - + // the ray is intersecting something we can move. var intersectionDistance = Vec3.distance(pickRay.origin, intersection.intersection); var grabbableData = getEntityCustomData(GRABBABLE_DATA_KEY, intersection.entityID, DEFAULT_GRABBABLE_DATA); + var defaultDisableNearGrabData = { + disableNearGrab: false + }; + //sometimes we want things to stay right where they are when we let go. + var disableNearGrabData = getEntityCustomData('handControllerKey', intersection.entityID, defaultDisableNearGrabData); if (intersection.properties.name == "Grab Debug Entity") { continue; @@ -817,7 +822,11 @@ function MyController(hand) { } else if (!intersection.properties.locked) { this.grabbedEntity = intersection.entityID; if (this.state == STATE_SEARCHING) { - this.setState(STATE_NEAR_GRABBING); + if (disableNearGrabData.disableNearGrab !== true) { + this.setState(STATE_NEAR_GRABBING); + } else { + //disable near grab on this thing + } } else { // equipping if (typeof grabbableData.spatialKey !== 'undefined') { // TODO @@ -940,7 +949,18 @@ function MyController(hand) { this.setState(STATE_NEAR_TRIGGER); return; } else if (!props.locked && props.collisionsWillMove) { - this.setState(this.state == STATE_SEARCHING ? STATE_NEAR_GRABBING : STATE_EQUIP) + var defaultDisableNearGrabData = { + disableNearGrab: false + }; + //sometimes we want things to stay right where they are when we let go. + var disableNearGrabData = getEntityCustomData('handControllerKey', this.grabbedEntity, defaultDisableNearGrabData); + if (disableNearGrabData.disableNearGrab === true) { + //do nothing because near grab is disabled for this object + } else { + this.setState(this.state == STATE_SEARCHING ? STATE_NEAR_GRABBING : STATE_EQUIP) + + } + return; } } @@ -1753,15 +1773,14 @@ handleHandMessages = function(channel, message, sender) { } catch (e) {} - } - else if (channel === 'Hifi-Hand-RayPick-Blacklist') { + } else if (channel === 'Hifi-Hand-RayPick-Blacklist') { try { var data = JSON.parse(message); var action = data.action; var id = data.id; var index = blacklist.indexOf(id); - - if (action === 'add' && index ===-1) { + + if (action === 'add' && index === -1) { blacklist.push(id); } if (action === 'remove') { diff --git a/examples/light_modifier/lightModifier.js b/examples/light_modifier/lightModifier.js index 52d9342464..b50bbe9478 100644 --- a/examples/light_modifier/lightModifier.js +++ b/examples/light_modifier/lightModifier.js @@ -374,7 +374,8 @@ entitySlider.prototype = { }, handControllerKey: { disableReleaseVelocity: true, - disableMoveWithHead: true + disableMoveWithHead: true, + disableNearGrab:true } }), }; From 12fa22300491a5b3f26d22a60eb7cd10a9c8dfac Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 28 Dec 2015 16:23:19 -0800 Subject: [PATCH 54/57] Render SKY_DOME when SKY_MAP tex is loading --- interface/src/Application.cpp | 146 +++++++++--------- libraries/model/src/model/Skybox.cpp | 11 +- .../src/procedural/ProceduralSkybox.cpp | 9 +- 3 files changed, 87 insertions(+), 79 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d383ee3339..e81aa7ec52 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3486,78 +3486,86 @@ namespace render { // Background rendering decision auto skyStage = DependencyManager::get()->getSkyStage(); - if (skyStage->getBackgroundMode() == model::SunSkyStage::NO_BACKGROUND) { + auto backgroundMode = skyStage->getBackgroundMode(); + + if (backgroundMode == model::SunSkyStage::NO_BACKGROUND) { // this line intentionally left blank - } else if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_DOME) { - if (Menu::getInstance()->isOptionChecked(MenuOption::Stars)) { - PerformanceTimer perfTimer("stars"); - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "Application::payloadRender() ... stars..."); - // should be the first rendering pass - w/o depth buffer / lighting - - // compute starfield alpha based on distance from atmosphere - float alpha = 1.0f; - bool hasStars = true; - - if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) { - // TODO: handle this correctly for zones - const EnvironmentData& closestData = background->_environment->getClosestData(args->_viewFrustum->getPosition()); // was theCamera instead of _viewFrustum - - if (closestData.getHasStars()) { - const float APPROXIMATE_DISTANCE_FROM_HORIZON = 0.1f; - const float DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON = 0.2f; - - glm::vec3 sunDirection = (args->_viewFrustum->getPosition()/*getAvatarPosition()*/ - closestData.getSunLocation()) - / closestData.getAtmosphereOuterRadius(); - float height = glm::distance(args->_viewFrustum->getPosition()/*theCamera.getPosition()*/, closestData.getAtmosphereCenter()); - if (height < closestData.getAtmosphereInnerRadius()) { - // If we're inside the atmosphere, then determine if our keyLight is below the horizon - alpha = 0.0f; - - if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) { - float directionY = glm::clamp(sunDirection.y, - -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) - + APPROXIMATE_DISTANCE_FROM_HORIZON; - alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON); - } - - - } else if (height < closestData.getAtmosphereOuterRadius()) { - alpha = (height - closestData.getAtmosphereInnerRadius()) / - (closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius()); - - if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) { - float directionY = glm::clamp(sunDirection.y, - -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) - + APPROXIMATE_DISTANCE_FROM_HORIZON; - alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON); - } - } - } else { - hasStars = false; - } + } else { + if (backgroundMode == model::SunSkyStage::SKY_BOX) { + auto skybox = skyStage->getSkybox(); + if (skybox && skybox->getCubemap() && skybox->getCubemap()->isDefined()) { + PerformanceTimer perfTimer("skybox"); + skybox->render(batch, *(args->_viewFrustum)); + } else { + // If no skybox texture is available, render the SKY_DOME while it loads + backgroundMode = model::SunSkyStage::SKY_DOME; } - - // finally render the starfield - if (hasStars) { - background->_stars.render(args, alpha); - } - - // draw the sky dome - if (/*!selfAvatarOnly &&*/ Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) { - PerformanceTimer perfTimer("atmosphere"); - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "Application::displaySide() ... atmosphere..."); - - background->_environment->renderAtmospheres(batch, *(args->_viewFrustum)); - } - } - } else if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) { - PerformanceTimer perfTimer("skybox"); - auto skybox = skyStage->getSkybox(); - if (skybox) { - skybox->render(batch, *(args->_viewFrustum)); + if (backgroundMode == model::SunSkyStage::SKY_DOME) { + if (Menu::getInstance()->isOptionChecked(MenuOption::Stars)) { + PerformanceTimer perfTimer("stars"); + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), + "Application::payloadRender() ... stars..."); + // should be the first rendering pass - w/o depth buffer / lighting + + // compute starfield alpha based on distance from atmosphere + float alpha = 1.0f; + bool hasStars = true; + + if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) { + // TODO: handle this correctly for zones + const EnvironmentData& closestData = background->_environment->getClosestData(args->_viewFrustum->getPosition()); // was theCamera instead of _viewFrustum + + if (closestData.getHasStars()) { + const float APPROXIMATE_DISTANCE_FROM_HORIZON = 0.1f; + const float DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON = 0.2f; + + glm::vec3 sunDirection = (args->_viewFrustum->getPosition()/*getAvatarPosition()*/ - closestData.getSunLocation()) + / closestData.getAtmosphereOuterRadius(); + float height = glm::distance(args->_viewFrustum->getPosition()/*theCamera.getPosition()*/, closestData.getAtmosphereCenter()); + if (height < closestData.getAtmosphereInnerRadius()) { + // If we're inside the atmosphere, then determine if our keyLight is below the horizon + alpha = 0.0f; + + if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) { + float directionY = glm::clamp(sunDirection.y, + -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) + + APPROXIMATE_DISTANCE_FROM_HORIZON; + alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON); + } + + + } else if (height < closestData.getAtmosphereOuterRadius()) { + alpha = (height - closestData.getAtmosphereInnerRadius()) / + (closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius()); + + if (sunDirection.y > -APPROXIMATE_DISTANCE_FROM_HORIZON) { + float directionY = glm::clamp(sunDirection.y, + -APPROXIMATE_DISTANCE_FROM_HORIZON, APPROXIMATE_DISTANCE_FROM_HORIZON) + + APPROXIMATE_DISTANCE_FROM_HORIZON; + alpha = (directionY / DOUBLE_APPROXIMATE_DISTANCE_FROM_HORIZON); + } + } + } else { + hasStars = false; + } + } + + // finally render the starfield + if (hasStars) { + background->_stars.render(args, alpha); + } + + // draw the sky dome + if (/*!selfAvatarOnly &&*/ Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) { + PerformanceTimer perfTimer("atmosphere"); + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), + "Application::displaySide() ... atmosphere..."); + + background->_environment->renderAtmospheres(batch, *(args->_viewFrustum)); + } + + } } } } diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 8c37359638..476ac2fa08 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -96,7 +96,12 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky } }); + // Render + gpu::TexturePointer skymap = skybox.getCubemap(); + // FIXME: skymap->isDefined may not be threadsafe + assert(skymap && skymap->isDefined()); + glm::mat4 projMat; viewFrustum.evalProjectionMatrix(projMat); @@ -106,11 +111,6 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.setViewTransform(viewTransform); batch.setModelTransform(Transform()); // only for Mac - gpu::TexturePointer skymap; - if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) { - skymap = skybox.getCubemap(); - } - batch.setPipeline(thePipeline); batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, skybox._dataBuffer); batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, skymap); @@ -118,6 +118,5 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.draw(gpu::TRIANGLE_STRIP, 4); batch.setResourceTexture(SKYBOX_SKYMAP_SLOT, nullptr); - } diff --git a/libraries/procedural/src/procedural/ProceduralSkybox.cpp b/libraries/procedural/src/procedural/ProceduralSkybox.cpp index ce6f29c3d5..167d49cbaf 100644 --- a/libraries/procedural/src/procedural/ProceduralSkybox.cpp +++ b/libraries/procedural/src/procedural/ProceduralSkybox.cpp @@ -48,6 +48,10 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, } if (skybox._procedural && skybox._procedural->_enabled && skybox._procedural->ready()) { + gpu::TexturePointer skymap = skybox.getCubemap(); + // FIXME: skymap->isDefined may not be threadsafe + assert(skymap && skymap->isDefined()); + glm::mat4 projMat; viewFrustum.evalProjectionMatrix(projMat); @@ -56,10 +60,7 @@ void ProceduralSkybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, batch.setProjectionTransform(projMat); batch.setViewTransform(viewTransform); batch.setModelTransform(Transform()); // only for Mac - - if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) { - batch.setResourceTexture(0, skybox.getCubemap()); - } + batch.setResourceTexture(0, skybox.getCubemap()); skybox._procedural->prepare(batch, glm::vec3(0), glm::vec3(1)); batch.draw(gpu::TRIANGLE_STRIP, 4); From 1a84b5c0f0c68a2f4f729bf80026b901691d4823 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Dec 2015 18:13:34 -0800 Subject: [PATCH 55/57] Fixing issue with muzzle flash and hit point being out of sync for pistol --- examples/toybox/pistol/pistol.js | 206 +++++++++++++++++-------------- 1 file changed, 115 insertions(+), 91 deletions(-) diff --git a/examples/toybox/pistol/pistol.js b/examples/toybox/pistol/pistol.js index 8ef26b94c1..df249a0aaf 100644 --- a/examples/toybox/pistol/pistol.js +++ b/examples/toybox/pistol/pistol.js @@ -44,6 +44,7 @@ this.showLaser = false; + }; Pistol.prototype = { @@ -58,20 +59,36 @@ if (!this.equipped) { return; } - this.toggleWithTriggerPressure(); + this.updateProps(); if (this.showLaser) { this.updateLaser(); } + this.toggleWithTriggerPressure(); + + + }, + + updateProps: function() { + var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']); + this.position = gunProps.position; + this.rotation = gunProps.rotation; + this.firingDirection = Quat.getFront(this.rotation); + var upVec = Quat.getUp(this.rotation); + this.barrelPoint = Vec3.sum(this.position, Vec3.multiply(upVec, this.laserOffsets.y)); + this.laserTip = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.laserLength)); + this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z)) + var pickRay = { + origin: this.barrelPoint, + direction: this.firingDirection + }; }, toggleWithTriggerPressure: function() { this.triggerValue = Controller.getValue(TRIGGER_CONTROLS[this.hand]); if (this.triggerValue < RELOAD_THRESHOLD) { - // print('RELOAD'); this.canShoot = true; } if (this.canShoot === true && this.triggerValue === 1) { - // print('SHOOT'); this.fire(); this.canShoot = false; } @@ -91,17 +108,10 @@ }, updateLaser: function() { - var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']); - var position = gunProps.position; - var rotation = gunProps.rotation; - this.firingDirection = Quat.getFront(rotation); - var upVec = Quat.getUp(rotation); - this.barrelPoint = Vec3.sum(position, Vec3.multiply(upVec, this.laserOffsets.y)); - var laserTip = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.laserLength)); - this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z)) + Overlays.editOverlay(this.laser, { start: this.barrelPoint, - end: laserTip, + end: this.laserTip, alpha: 1 }); }, @@ -114,19 +124,6 @@ }); }, - preload: function(entityID) { - this.entityID = entityID; - // this.initControllerMapping(); - this.laser = Overlays.addOverlay("line3d", { - start: ZERO_VECTOR, - end: ZERO_VECTOR, - color: COLORS.RED, - alpha: 1, - visible: true, - lineWidth: 2 - }); - }, - triggerPress: function(hand, value) { if (this.hand === hand && value === 1) { //We are pulling trigger on the hand we have the gun in, so fire @@ -135,17 +132,18 @@ }, fire: function() { - var pickRay = { - origin: this.barrelPoint, - direction: this.firingDirection - }; + Audio.playSound(this.fireSound, { position: this.barrelPoint, volume: this.fireVolume }); + var pickRay = { + origin: this.barrelPoint, + direction: this.firingDirection + }; this.createGunFireEffect(this.barrelPoint) - var intersection = Entities.findRayIntersectionBlocking(pickRay, true); + var intersection = Entities.findRayIntersection(pickRay, true); if (intersection.intersects) { this.createEntityHitEffect(intersection.intersection); if (Math.random() < this.playRichochetSoundChance) { @@ -170,11 +168,11 @@ }, createEntityHitEffect: function(position) { - var flash = Entities.addEntity({ + var sparks = Entities.addEntity({ type: "ParticleEffect", position: position, lifetime: 4, - "name": "Flash Emitter", + "name": "Sparks Emitter", "color": { red: 228, green: 128, @@ -228,7 +226,7 @@ }); Script.setTimeout(function() { - Entities.editEntity(flash, { + Entities.editEntity(sparks, { isEmitting: false }); }, 100); @@ -282,70 +280,96 @@ }); }, 100); - var flash = Entities.addEntity({ - type: "ParticleEffect", - position: position, - lifetime: 4, - "name": "Muzzle Flash", - "color": { - red: 228, - green: 128, - blue: 12 - }, - "maxParticles": 1000, - "lifespan": 0.1, - "emitRate": 1000, - "emitSpeed": 0.5, - "speedSpread": 0, - "emitOrientation": { - "x": -0.4, - "y": 1, - "z": -0.2, - "w": 0.7071068286895752 - }, - "emitDimensions": { - "x": 0, - "y": 0, - "z": 0 - }, - "polarStart": 0, - "polarFinish": Math.PI, - "azimuthStart": -3.1415927410125732, - "azimuthFinish": 2, - "emitAcceleration": { - "x": 0, - "y": 0, - "z": 0 - }, - "accelerationSpread": { - "x": 0, - "y": 0, - "z": 0 - }, - "particleRadius": 0.05, - "radiusSpread": 0.01, - "radiusStart": 0.05, - "radiusFinish": 0.05, - "colorSpread": { - red: 100, - green: 100, - blue: 20 - }, - "alpha": 1, - "alphaSpread": 0, - "alphaStart": 0, - "alphaFinish": 0, - "additiveBlending": true, - "textures": "http://ericrius1.github.io/PartiArt/assets/star.png" + Entities.editEntity(this.flash, { + isEmitting: true }); - Script.setTimeout(function() { - Entities.editEntity(flash, { + Entities.editEntity(_this.flash, { isEmitting: false }); }, 100) - } + }, + + preload: function(entityID) { + this.entityID = entityID; + this.laser = Overlays.addOverlay("line3d", { + start: ZERO_VECTOR, + end: ZERO_VECTOR, + color: COLORS.RED, + alpha: 1, + visible: true, + lineWidth: 2 + }); + + var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']); + var position = gunProps.position; + var rotation = gunProps.rotation; + this.firingDirection = Quat.getFront(rotation); + var upVec = Quat.getUp(rotation); + this.barrelPoint = Vec3.sum(position, Vec3.multiply(upVec, this.laserOffsets.y)); + this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z)) + + // this.flash = Entities.addEntity({ + // type: "ParticleEffect", + // parentID: this.entityID, + // position: this.barrelPoint, + // "name": "Muzzle Flash", + // // isEmitting: false, + // "color": { + // red: 228, + // green: 128, + // blue: 12 + // }, + // "maxParticles": 1000, + // "lifespan": 0.1, + // "emitRate": 1000, + // "emitSpeed": 0.5, + // "speedSpread": 0, + // "emitOrientation": { + // "x": -0.4, + // "y": 1, + // "z": -0.2, + // "w": 0.7071068286895752 + // }, + // "emitDimensions": { + // "x": 0, + // "y": 0, + // "z": 0 + // }, + // "polarStart": 0, + // "polarFinish": Math.PI, + // "azimuthStart": -3.1415927410125732, + // "azimuthFinish": 2, + // "emitAcceleration": { + // "x": 0, + // "y": 0, + // "z": 0 + // }, + // "accelerationSpread": { + // "x": 0, + // "y": 0, + // "z": 0 + // }, + // "particleRadius": 0.05, + // "radiusSpread": 0.01, + // "radiusStart": 0.05, + // "radiusFinish": 0.05, + // "colorSpread": { + // red: 100, + // green: 100, + // blue: 20 + // }, + // "alpha": 1, + // "alphaSpread": 0, + // "alphaStart": 0, + // "alphaFinish": 0, + // "additiveBlending": true, + // "textures": "http://ericrius1.github.io/PartiArt/assets/star.png" + // }); + + }, + }; From 4cc94b44ba0f8ed1320f6dcb35e1cc67ca362292 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 29 Dec 2015 18:30:07 -0800 Subject: [PATCH 56/57] muzzle is in sync --- examples/toybox/pistol/pistol.js | 140 +++++++++++++++---------------- 1 file changed, 69 insertions(+), 71 deletions(-) diff --git a/examples/toybox/pistol/pistol.js b/examples/toybox/pistol/pistol.js index df249a0aaf..372c704219 100644 --- a/examples/toybox/pistol/pistol.js +++ b/examples/toybox/pistol/pistol.js @@ -29,20 +29,12 @@ this.equipped = false; this.forceMultiplier = 1; this.laserLength = 100; - this.laserOffsets = { - y: .095 - }; - this.firingOffsets = { - z: 0.16 - } + this.fireSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/GUN-SHOT2.raw"); this.ricochetSound = SoundCache.getSound("https://s3.amazonaws.com/hifi-public/sounds/Guns/Ricochet.L.wav"); this.playRichochetSoundChance = 0.1; this.fireVolume = 0.2; this.bulletForce = 10; - - - this.showLaser = false; }; @@ -143,7 +135,7 @@ direction: this.firingDirection }; this.createGunFireEffect(this.barrelPoint) - var intersection = Entities.findRayIntersection(pickRay, true); + var intersection = Entities.findRayIntersectionBlocking(pickRay, true); if (intersection.intersects) { this.createEntityHitEffect(intersection.intersection); if (Math.random() < this.playRichochetSoundChance) { @@ -301,76 +293,82 @@ visible: true, lineWidth: 2 }); - + this.laserOffsets = { + y: .095 + }; + this.firingOffsets = { + z: 0.16 + } var gunProps = Entities.getEntityProperties(this.entityID, ['position', 'rotation']); var position = gunProps.position; - var rotation = gunProps.rotation; + var rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); this.firingDirection = Quat.getFront(rotation); var upVec = Quat.getUp(rotation); this.barrelPoint = Vec3.sum(position, Vec3.multiply(upVec, this.laserOffsets.y)); this.barrelPoint = Vec3.sum(this.barrelPoint, Vec3.multiply(this.firingDirection, this.firingOffsets.z)) - // this.flash = Entities.addEntity({ - // type: "ParticleEffect", - // parentID: this.entityID, - // position: this.barrelPoint, - // "name": "Muzzle Flash", - // // isEmitting: false, - // "color": { - // red: 228, - // green: 128, - // blue: 12 - // }, - // "maxParticles": 1000, - // "lifespan": 0.1, - // "emitRate": 1000, - // "emitSpeed": 0.5, - // "speedSpread": 0, - // "emitOrientation": { - // "x": -0.4, - // "y": 1, - // "z": -0.2, - // "w": 0.7071068286895752 - // }, - // "emitDimensions": { - // "x": 0, - // "y": 0, - // "z": 0 - // }, - // "polarStart": 0, - // "polarFinish": Math.PI, - // "azimuthStart": -3.1415927410125732, - // "azimuthFinish": 2, - // "emitAcceleration": { - // "x": 0, - // "y": 0, - // "z": 0 - // }, - // "accelerationSpread": { - // "x": 0, - // "y": 0, - // "z": 0 - // }, - // "particleRadius": 0.05, - // "radiusSpread": 0.01, - // "radiusStart": 0.05, - // "radiusFinish": 0.05, - // "colorSpread": { - // red: 100, - // green: 100, - // blue: 20 - // }, - // "alpha": 1, - // "alphaSpread": 0, - // "alphaStart": 0, - // "alphaFinish": 0, - // "additiveBlending": true, - // "textures": "http://ericrius1.github.io/PartiArt/assets/star.png" - // }); + this.flash = Entities.addEntity({ + type: "ParticleEffect", + position: this.barrelPoint, + "name": "Muzzle Flash", + isEmitting: false, + "color": { + red: 228, + green: 128, + blue: 12 + }, + "maxParticles": 1000, + "lifespan": 0.1, + "emitRate": 1000, + "emitSpeed": 0.5, + "speedSpread": 0, + "emitOrientation": { + "x": -0.4, + "y": 1, + "z": -0.2, + "w": 0.7071068286895752 + }, + "emitDimensions": { + "x": 0, + "y": 0, + "z": 0 + }, + "polarStart": 0, + "polarFinish": Math.PI, + "azimuthStart": -3.1415927410125732, + "azimuthFinish": 2, + "emitAcceleration": { + "x": 0, + "y": 0, + "z": 0 + }, + "accelerationSpread": { + "x": 0, + "y": 0, + "z": 0 + }, + "particleRadius": 0.05, + "radiusSpread": 0.01, + "radiusStart": 0.05, + "radiusFinish": 0.05, + "colorSpread": { + red: 100, + green: 100, + blue: 20 + }, + "alpha": 1, + "alphaSpread": 0, + "alphaStart": 0, + "alphaFinish": 0, + "additiveBlending": true, + "textures": "http://ericrius1.github.io/PartiArt/assets/star.png" + }); + + Script.setTimeout(function() { + Entities.editEntity(_this.flash, {parentID: _this.entityID}); + }, 500) }, - - }; // entity scripts always need to return a newly constructed object of our type From 5caa6cbdbf99b1531d757976b539c6606b497b9b Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Tue, 29 Dec 2015 18:38:57 -0800 Subject: [PATCH 57/57] Update pistol.js leading zeroes --- examples/toybox/pistol/pistol.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/toybox/pistol/pistol.js b/examples/toybox/pistol/pistol.js index 372c704219..7fb05d992f 100644 --- a/examples/toybox/pistol/pistol.js +++ b/examples/toybox/pistol/pistol.js @@ -251,11 +251,11 @@ "z": 0 }, "accelerationSpread": { - "x": .2, + "x": 0.2, "y": 0, - "z": .2 + "z": 0.2 }, - "radiusSpread": .04, + "radiusSpread": 0.04, "particleRadius": 0.07, "radiusStart": 0.07, "radiusFinish": 0.07, @@ -294,7 +294,7 @@ lineWidth: 2 }); this.laserOffsets = { - y: .095 + y: 0.095 }; this.firingOffsets = { z: 0.16 @@ -373,4 +373,4 @@ // entity scripts always need to return a newly constructed object of our type return new Pistol(); -}); \ No newline at end of file +});