mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-23 14:14:28 +02:00
merge with upstream/master
This commit is contained in:
commit
c110fcbfad
76 changed files with 2117 additions and 890 deletions
|
@ -40,7 +40,7 @@ if (WIN32)
|
||||||
elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
||||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
|
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
|
||||||
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas")
|
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-strict-aliasing")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-strict-aliasing -ggdb")
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
if (NOT MSVC12)
|
if (NOT MSVC12)
|
||||||
|
|
|
@ -208,7 +208,7 @@ void Agent::run() {
|
||||||
|
|
||||||
_scriptEngine.init(); // must be done before we set up the viewers
|
_scriptEngine.init(); // must be done before we set up the viewers
|
||||||
|
|
||||||
_scriptEngine.registerGlobalObject("SoundCache", &SoundCache::getInstance());
|
_scriptEngine.registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
|
||||||
|
|
||||||
_scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer);
|
_scriptEngine.registerGlobalObject("EntityViewer", &_entityViewer);
|
||||||
_entityViewer.setJurisdictionListener(_scriptEngine.getEntityScriptingInterface()->getJurisdictionListener());
|
_entityViewer.setJurisdictionListener(_scriptEngine.getEntityScriptingInterface()->getJurisdictionListener());
|
||||||
|
|
|
@ -136,7 +136,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) :
|
||||||
|
|
||||||
// Create Singleton objects on main thread
|
// Create Singleton objects on main thread
|
||||||
NetworkAccessManager::getInstance();
|
NetworkAccessManager::getInstance();
|
||||||
SoundCache::getInstance();
|
auto soundCache = DependencyManager::get<SoundCache>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignmentClient::sendAssignmentRequest() {
|
void AssignmentClient::sendAssignmentRequest() {
|
||||||
|
|
|
@ -147,3 +147,14 @@ void EntityServer::pruneDeletedEntities() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectionObject) {
|
||||||
|
bool wantEditLogging = false;
|
||||||
|
readOptionBool(QString("wantEditLogging"), settingsSectionObject, wantEditLogging);
|
||||||
|
qDebug("wantEditLogging=%s", debug::valueOf(wantEditLogging));
|
||||||
|
|
||||||
|
|
||||||
|
EntityTree* tree = static_cast<EntityTree*>(_tree);
|
||||||
|
tree->setWantEditLogging(wantEditLogging);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent);
|
virtual int sendSpecialPacket(const SharedNodePointer& node, OctreeQueryNode* queryNode, int& packetsSent);
|
||||||
|
|
||||||
virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode);
|
virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode);
|
||||||
|
virtual void readAdditionalConfiguration(const QJsonObject& settingsSectionObject);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void pruneDeletedEntities();
|
void pruneDeletedEntities();
|
||||||
|
|
|
@ -409,6 +409,13 @@
|
||||||
"default": "",
|
"default": "",
|
||||||
"advanced": true
|
"advanced": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "wantEditLogging",
|
||||||
|
"type": "checkbox",
|
||||||
|
"help": "Logging of all edits to entities",
|
||||||
|
"default": true,
|
||||||
|
"advanced": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "verboseDebug",
|
"name": "verboseDebug",
|
||||||
"type": "checkbox",
|
"type": "checkbox",
|
||||||
|
|
248
examples/controllers/oculus/goTo.js
Normal file
248
examples/controllers/oculus/goTo.js
Normal file
|
@ -0,0 +1,248 @@
|
||||||
|
//
|
||||||
|
// goTo.js
|
||||||
|
// examples
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 12/28/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Control a virtual keyboard using your favorite HMD.
|
||||||
|
// Usage: Enable VR-mode and go to First person mode,
|
||||||
|
// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard.
|
||||||
|
//
|
||||||
|
// Enter a location URL using your HMD. Press Enter to pop-up the virtual keyboard and location input.
|
||||||
|
// Press Space on the keyboard or the X button on your gamepad to press a key that you have selected.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
Script.include("../../libraries/globals.js");
|
||||||
|
Script.include("../../libraries/virtualKeyboard.js");
|
||||||
|
|
||||||
|
const MAX_SHOW_INSTRUCTION_TIMES = 2;
|
||||||
|
const INSTRUCTIONS_SETTING = "GoToInstructionsShowCounter"
|
||||||
|
|
||||||
|
var windowDimensions = Controller.getViewportDimensions();
|
||||||
|
|
||||||
|
function Instructions(imageURL, originalWidth, originalHeight) {
|
||||||
|
var tthis = this;
|
||||||
|
this.originalSize = {w: originalWidth, h: originalHeight};
|
||||||
|
this.visible = false;
|
||||||
|
this.overlay = Overlays.addOverlay("image", {
|
||||||
|
imageURL: imageURL,
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
width: originalWidth,
|
||||||
|
height: originalHeight,
|
||||||
|
alpha: 1,
|
||||||
|
visible: this.visible
|
||||||
|
});
|
||||||
|
|
||||||
|
this.show = function() {
|
||||||
|
var timesShown = Settings.getValue(INSTRUCTIONS_SETTING);
|
||||||
|
timesShown = timesShown === "" ? 0 : parseInt(timesShown);
|
||||||
|
print(timesShown);
|
||||||
|
if (timesShown < MAX_SHOW_INSTRUCTION_TIMES) {
|
||||||
|
Settings.setValue(INSTRUCTIONS_SETTING, timesShown + 1);
|
||||||
|
tthis.visible = true;
|
||||||
|
tthis.rescale();
|
||||||
|
Overlays.editOverlay(tthis.overlay, {visible: tthis.visible});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tthis.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.remove = function() {
|
||||||
|
Overlays.deleteOverlay(tthis.overlay);
|
||||||
|
tthis.visible = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.rescale = function() {
|
||||||
|
var scale = Math.min(windowDimensions.x / tthis.originalSize.w, windowDimensions.y / tthis.originalSize.h);
|
||||||
|
var newWidth = tthis.originalSize.w * scale;
|
||||||
|
var newHeight = tthis.originalSize.h * scale;
|
||||||
|
Overlays.editOverlay(tthis.overlay, {
|
||||||
|
x: (windowDimensions.x / 2) - (newWidth / 2),
|
||||||
|
y: (windowDimensions.y / 2) - (newHeight / 2),
|
||||||
|
width: newWidth,
|
||||||
|
height: newHeight
|
||||||
|
});
|
||||||
|
};
|
||||||
|
this.rescale();
|
||||||
|
};
|
||||||
|
|
||||||
|
var theInstruction = new Instructions(HIFI_PUBLIC_BUCKET + "images/tutorial-goTo.svg", 457, 284.1);
|
||||||
|
|
||||||
|
var firstControllerPlugged = false;
|
||||||
|
|
||||||
|
|
||||||
|
var cursor = new Cursor({visible: false});
|
||||||
|
var keyboard = new Keyboard({visible: false});
|
||||||
|
var textFontSize = 9;
|
||||||
|
var text = null;
|
||||||
|
var locationURL = "";
|
||||||
|
|
||||||
|
function appendChar(char) {
|
||||||
|
locationURL += char;
|
||||||
|
updateTextOverlay();
|
||||||
|
Overlays.editOverlay(text, {text: locationURL});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteChar() {
|
||||||
|
if (locationURL.length > 0) {
|
||||||
|
locationURL = locationURL.substring(0, locationURL.length - 1);
|
||||||
|
updateTextOverlay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTextOverlay() {
|
||||||
|
var maxLineWidth = Overlays.textSize(text, locationURL).width;
|
||||||
|
var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90;
|
||||||
|
var maxFontSize = 140;
|
||||||
|
textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize;
|
||||||
|
var topMargin = (250 - textFontSize) / 4;
|
||||||
|
Overlays.editOverlay(text, {text: locationURL, font: {size: textFontSize}, topMargin: topMargin, visible: keyboard.visible});
|
||||||
|
maxLineWidth = Overlays.textSize(text, locationURL).width;
|
||||||
|
Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2});
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboard.onKeyPress = function(event) {
|
||||||
|
if (event.event == 'keypress') {
|
||||||
|
appendChar(event.char);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
keyboard.onKeyRelease = function(event) {
|
||||||
|
// you can cancel a key by releasing its focusing before releasing it
|
||||||
|
if (event.focus) {
|
||||||
|
if (event.event == 'delete') {
|
||||||
|
deleteChar();
|
||||||
|
} else if (event.event == 'submit' || event.event == 'enter') {
|
||||||
|
print("going to hifi://" + locationURL);
|
||||||
|
location = "hifi://" + locationURL;
|
||||||
|
locationURL = "";
|
||||||
|
keyboard.hide();
|
||||||
|
cursor.hide();
|
||||||
|
updateTextOverlay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
keyboard.onFullyLoaded = function() {
|
||||||
|
print("Virtual-keyboard fully loaded.");
|
||||||
|
var dimensions = Controller.getViewportDimensions();
|
||||||
|
text = Overlays.addOverlay("text", {
|
||||||
|
x: 0,
|
||||||
|
y: dimensions.y - keyboard.height() - 260,
|
||||||
|
width: dimensions.x,
|
||||||
|
height: 250,
|
||||||
|
backgroundColor: { red: 255, green: 255, blue: 255},
|
||||||
|
color: { red: 0, green: 0, blue: 0},
|
||||||
|
topMargin: 5,
|
||||||
|
leftMargin: 0,
|
||||||
|
font: {size: textFontSize},
|
||||||
|
text: "",
|
||||||
|
alpha: 0.8,
|
||||||
|
visible: keyboard.visible
|
||||||
|
});
|
||||||
|
updateTextOverlay();
|
||||||
|
// the cursor is being loaded after the keyboard, else it will be on the background of the keyboard
|
||||||
|
cursor.initialize();
|
||||||
|
cursor.updateVisibility(keyboard.visible);
|
||||||
|
cursor.onUpdate = function(position) {
|
||||||
|
keyboard.setFocusPosition(position.x, position.y);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
function keyPressEvent(event) {
|
||||||
|
if (theInstruction.visible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key === SPACEBAR_CHARCODE) {
|
||||||
|
keyboard.pressFocussedKey();
|
||||||
|
} else if (event.key === ENTER_CHARCODE || event.key === RETURN_CHARCODE) {
|
||||||
|
keyboard.toggle();
|
||||||
|
if (cursor !== undefined) {
|
||||||
|
cursor.updateVisibility(keyboard.visible);
|
||||||
|
}
|
||||||
|
Overlays.editOverlay(text, {visible: keyboard.visible});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyReleaseEvent(event) {
|
||||||
|
if (theInstruction.visible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.key === SPACEBAR_CHARCODE) {
|
||||||
|
keyboard.releaseKeys();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scriptEnding() {
|
||||||
|
keyboard.remove();
|
||||||
|
cursor.remove();
|
||||||
|
Overlays.deleteOverlay(text);
|
||||||
|
Overlays.deleteOverlay(textSizeMeasureOverlay);
|
||||||
|
Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE});
|
||||||
|
Controller.releaseKeyEvents({key: RETURN_CHARCODE});
|
||||||
|
Controller.releaseKeyEvents({key: ENTER_CHARCODE});
|
||||||
|
theInstruction.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportButtonValue(button, newValue, oldValue) {
|
||||||
|
if (theInstruction.visible) {
|
||||||
|
if (button == Joysticks.BUTTON_FACE_BOTTOM && newValue) {
|
||||||
|
theInstruction.remove();
|
||||||
|
}
|
||||||
|
} else if (button == Joysticks.BUTTON_FACE_BOTTOM) {
|
||||||
|
if (newValue) {
|
||||||
|
keyboard.pressFocussedKey();
|
||||||
|
} else {
|
||||||
|
keyboard.releaseKeys();
|
||||||
|
}
|
||||||
|
} else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) {
|
||||||
|
deleteChar();
|
||||||
|
} else if (button == Joysticks.BUTTON_FACE_LEFT && newValue) {
|
||||||
|
keyboard.hide();
|
||||||
|
if (cursor !== undefined) {
|
||||||
|
cursor.hide();
|
||||||
|
}
|
||||||
|
Overlays.editOverlay(text, {visible: false});
|
||||||
|
} else if (button == Joysticks.BUTTON_RIGHT_SHOULDER && newValue) {
|
||||||
|
if (keyboard.visible) {
|
||||||
|
print("going to hifi://" + locationURL);
|
||||||
|
location = "hifi://" + locationURL;
|
||||||
|
locationURL = "";
|
||||||
|
keyboard.hide();
|
||||||
|
cursor.hide();
|
||||||
|
updateTextOverlay();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
keyboard.show();
|
||||||
|
if (cursor !== undefined) {
|
||||||
|
cursor.show();
|
||||||
|
}
|
||||||
|
Overlays.editOverlay(text, {visible: true});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addJoystick(gamepad) {
|
||||||
|
gamepad.buttonStateChanged.connect(reportButtonValue);
|
||||||
|
if (!firstControllerPlugged) {
|
||||||
|
firstControllerPlugged = true;
|
||||||
|
theInstruction.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var allJoysticks = Joysticks.getAllJoysticks();
|
||||||
|
for (var i = 0; i < allJoysticks.length; i++) {
|
||||||
|
addJoystick(allJoysticks[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Joysticks.joystickAdded.connect(addJoystick);
|
||||||
|
Controller.captureKeyEvents({key: RETURN_CHARCODE});
|
||||||
|
Controller.captureKeyEvents({key: ENTER_CHARCODE});
|
||||||
|
Controller.captureKeyEvents({key: SPACEBAR_CHARCODE});
|
||||||
|
Controller.keyPressEvent.connect(keyPressEvent);
|
||||||
|
Controller.keyReleaseEvent.connect(keyReleaseEvent);
|
||||||
|
Script.scriptEnding.connect(scriptEnding);
|
183
examples/controllers/oculus/virtualKeyboardTextEntityExample.js
Normal file
183
examples/controllers/oculus/virtualKeyboardTextEntityExample.js
Normal file
|
@ -0,0 +1,183 @@
|
||||||
|
//
|
||||||
|
// virtualKeyboardTextEntityExample.js
|
||||||
|
// examples
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 12/28/14.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Control a virtual keyboard using your favorite HMD.
|
||||||
|
// Usage: Enable VR-mode and go to First person mode,
|
||||||
|
// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard.
|
||||||
|
//
|
||||||
|
// leased some code from newEditEntities.js for Text Entity example
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
Script.include("../../libraries/globals.js");
|
||||||
|
Script.include("../../libraries/virtualKeyboard.js");
|
||||||
|
|
||||||
|
const SPAWN_DISTANCE = 1;
|
||||||
|
const DEFAULT_TEXT_DIMENSION_Z = 0.02;
|
||||||
|
|
||||||
|
const TEXT_MARGIN_TOP = 0.15;
|
||||||
|
const TEXT_MARGIN_LEFT = 0.15;
|
||||||
|
const TEXT_MARGIN_RIGHT = 0.17;
|
||||||
|
const TEXT_MARGIN_BOTTOM = 0.17;
|
||||||
|
|
||||||
|
var windowDimensions = Controller.getViewportDimensions();
|
||||||
|
var cursor = new Cursor();
|
||||||
|
var keyboard = new Keyboard();
|
||||||
|
var textFontSize = 9;
|
||||||
|
var text = null;
|
||||||
|
var textText = "";
|
||||||
|
var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false});
|
||||||
|
|
||||||
|
function appendChar(char) {
|
||||||
|
textText += char;
|
||||||
|
updateTextOverlay();
|
||||||
|
Overlays.editOverlay(text, {text: textText});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteChar() {
|
||||||
|
if (textText.length > 0) {
|
||||||
|
textText = textText.substring(0, textText.length - 1);
|
||||||
|
updateTextOverlay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateTextOverlay() {
|
||||||
|
var textLines = textText.split("\n");
|
||||||
|
var suggestedFontSize = (windowDimensions.x / Overlays.textSize(text, textText).width) * textFontSize * 0.90;
|
||||||
|
var maxFontSize = 170 / textLines.length;
|
||||||
|
textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize;
|
||||||
|
var topMargin = (250 - (textFontSize * textLines.length)) / 4;
|
||||||
|
Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin});
|
||||||
|
Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - Overlays.textSize(text, textLines).width) / 2});
|
||||||
|
}
|
||||||
|
|
||||||
|
keyboard.onKeyPress = function(event) {
|
||||||
|
if (event.event == 'keypress') {
|
||||||
|
appendChar(event.char);
|
||||||
|
} else if (event.event == 'enter') {
|
||||||
|
appendChar("\n");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
keyboard.onKeyRelease = function(event) {
|
||||||
|
print("Key release event test");
|
||||||
|
// you can cancel a key by releasing its focusing before releasing it
|
||||||
|
if (event.focus) {
|
||||||
|
if (event.event == 'delete') {
|
||||||
|
deleteChar();
|
||||||
|
} else if (event.event == 'submit') {
|
||||||
|
print(textText);
|
||||||
|
|
||||||
|
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
||||||
|
|
||||||
|
var textLines = textText.split("\n");
|
||||||
|
var maxLineWidth = Overlays.textSize(textSizeMeasureOverlay, textText).width;
|
||||||
|
var usernameLine = "--" + GlobalServices.myUsername;
|
||||||
|
var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width;
|
||||||
|
if (maxLineWidth < usernameWidth) {
|
||||||
|
maxLineWidth = usernameWidth;
|
||||||
|
} else {
|
||||||
|
var spaceableWidth = maxLineWidth - usernameWidth;
|
||||||
|
//TODO: WORKAROUND WARNING BELOW Fix this when spaces are not trimmed out of the textsize calculation anymore
|
||||||
|
var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, "| |").width
|
||||||
|
- Overlays.textSize(textSizeMeasureOverlay, "||").width;
|
||||||
|
var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth);
|
||||||
|
for (var i = 0; i < numberOfSpaces; i++) {
|
||||||
|
usernameLine = " " + usernameLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT;
|
||||||
|
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
||||||
|
Entities.addEntity({
|
||||||
|
type: "Text",
|
||||||
|
rotation: MyAvatar.orientation,
|
||||||
|
position: position,
|
||||||
|
dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z },
|
||||||
|
backgroundColor: { red: 0, green: 0, blue: 0 },
|
||||||
|
textColor: { red: 255, green: 255, blue: 255 },
|
||||||
|
text: textText + "\n" + usernameLine,
|
||||||
|
lineHeight: 0.1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
textText = "";
|
||||||
|
updateTextOverlay();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
keyboard.onFullyLoaded = function() {
|
||||||
|
print("Virtual-keyboard fully loaded.");
|
||||||
|
var dimensions = Controller.getViewportDimensions();
|
||||||
|
text = Overlays.addOverlay("text", {
|
||||||
|
x: 0,
|
||||||
|
y: dimensions.y - keyboard.height() - 260,
|
||||||
|
width: dimensions.x,
|
||||||
|
height: 250,
|
||||||
|
backgroundColor: { red: 255, green: 255, blue: 255},
|
||||||
|
color: { red: 0, green: 0, blue: 0},
|
||||||
|
topMargin: 5,
|
||||||
|
leftMargin: 0,
|
||||||
|
font: {size: textFontSize},
|
||||||
|
text: "",
|
||||||
|
alpha: 0.8
|
||||||
|
});
|
||||||
|
updateTextOverlay();
|
||||||
|
// the cursor is being loaded after the keyboard, else it will be on the background of the keyboard
|
||||||
|
cursor.initialize();
|
||||||
|
cursor.onUpdate = function(position) {
|
||||||
|
keyboard.setFocusPosition(position.x, position.y);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
function keyPressEvent(event) {
|
||||||
|
if (event.key === SPACEBAR_CHARCODE) {
|
||||||
|
keyboard.pressFocussedKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyReleaseEvent(event) {
|
||||||
|
if (event.key === SPACEBAR_CHARCODE) {
|
||||||
|
keyboard.releaseKeys();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scriptEnding() {
|
||||||
|
keyboard.remove();
|
||||||
|
cursor.remove();
|
||||||
|
Overlays.deleteOverlay(text);
|
||||||
|
Overlays.deleteOverlay(textSizeMeasureOverlay);
|
||||||
|
Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE});
|
||||||
|
}
|
||||||
|
|
||||||
|
function reportButtonValue(button, newValue, oldValue) {
|
||||||
|
if (button == Joysticks.BUTTON_FACE_BOTTOM) {
|
||||||
|
if (newValue) {
|
||||||
|
keyboard.pressFocussedKey();
|
||||||
|
} else {
|
||||||
|
keyboard.releaseKeys();
|
||||||
|
}
|
||||||
|
} else if (button == Joysticks.BUTTON_FACE_RIGHT && newValue) {
|
||||||
|
deleteChar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addJoystick(gamepad) {
|
||||||
|
gamepad.buttonStateChanged.connect(reportButtonValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
var allJoysticks = Joysticks.getAllJoysticks();
|
||||||
|
for (var i = 0; i < allJoysticks.length; i++) {
|
||||||
|
addJoystick(allJoysticks[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Joysticks.joystickAdded.connect(addJoystick);
|
||||||
|
Controller.captureKeyEvents({key: SPACEBAR_CHARCODE});
|
||||||
|
Controller.keyPressEvent.connect(keyPressEvent);
|
||||||
|
Controller.keyReleaseEvent.connect(keyReleaseEvent);
|
||||||
|
Script.scriptEnding.connect(scriptEnding);
|
|
@ -127,7 +127,7 @@ var toolBar = (function () {
|
||||||
height: toolHeight,
|
height: toolHeight,
|
||||||
alpha: 0.9,
|
alpha: 0.9,
|
||||||
visible: true
|
visible: true
|
||||||
}, true, false);
|
});
|
||||||
|
|
||||||
browseModelsButton = toolBar.addTool({
|
browseModelsButton = toolBar.addTool({
|
||||||
imageURL: toolIconUrl + "list-icon.svg",
|
imageURL: toolIconUrl + "list-icon.svg",
|
||||||
|
@ -190,6 +190,7 @@ var toolBar = (function () {
|
||||||
cameraManager.enable();
|
cameraManager.enable();
|
||||||
entityListTool.setVisible(true);
|
entityListTool.setVisible(true);
|
||||||
gridTool.setVisible(true);
|
gridTool.setVisible(true);
|
||||||
|
grid.setEnabled(true);
|
||||||
propertiesTool.setVisible(true);
|
propertiesTool.setVisible(true);
|
||||||
Window.setFocus();
|
Window.setFocus();
|
||||||
}
|
}
|
||||||
|
@ -261,6 +262,8 @@ var toolBar = (function () {
|
||||||
toolBar.move(toolsX, toolsY);
|
toolBar.move(toolsX, toolsY);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var newModelButtonDown = false;
|
||||||
|
var browseModelsButtonDown = false;
|
||||||
that.mousePressEvent = function (event) {
|
that.mousePressEvent = function (event) {
|
||||||
var clickedOverlay,
|
var clickedOverlay,
|
||||||
url,
|
url,
|
||||||
|
@ -273,19 +276,14 @@ var toolBar = (function () {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle these two buttons in the mouseRelease event handler so that we don't suppress a mouseRelease event from
|
||||||
|
// occurring when showing a modal dialog.
|
||||||
if (newModelButton === toolBar.clicked(clickedOverlay)) {
|
if (newModelButton === toolBar.clicked(clickedOverlay)) {
|
||||||
url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]);
|
newModelButtonDown = true;
|
||||||
if (url !== null && url !== "") {
|
|
||||||
addModel(url);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (browseModelsButton === toolBar.clicked(clickedOverlay)) {
|
if (browseModelsButton === toolBar.clicked(clickedOverlay)) {
|
||||||
url = Window.s3Browse(".*(fbx|FBX)");
|
browseModelsButtonDown = true;
|
||||||
if (url !== null && url !== "") {
|
|
||||||
addModel(url);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,6 +345,7 @@ var toolBar = (function () {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (newTextButton === toolBar.clicked(clickedOverlay)) {
|
if (newTextButton === toolBar.clicked(clickedOverlay)) {
|
||||||
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
||||||
|
|
||||||
|
@ -366,10 +365,37 @@ var toolBar = (function () {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.mouseReleaseEvent = function(event) {
|
||||||
|
var handled = false;
|
||||||
|
if (newModelButtonDown) {
|
||||||
|
var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||||
|
if (newModelButton === toolBar.clicked(clickedOverlay)) {
|
||||||
|
url = Window.prompt("Model URL", modelURLs[Math.floor(Math.random() * modelURLs.length)]);
|
||||||
|
if (url !== null && url !== "") {
|
||||||
|
addModel(url);
|
||||||
|
}
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
} else if (browseModelsButtonDown) {
|
||||||
|
var clickedOverlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y });
|
||||||
|
if (browseModelsButton === toolBar.clicked(clickedOverlay)) {
|
||||||
|
url = Window.s3Browse(".*(fbx|FBX)");
|
||||||
|
if (url !== null && url !== "") {
|
||||||
|
addModel(url);
|
||||||
|
}
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newModelButtonDown = false;
|
||||||
|
browseModelsButtonDown = false;
|
||||||
|
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
|
||||||
that.cleanup = function () {
|
that.cleanup = function () {
|
||||||
toolBar.cleanup();
|
toolBar.cleanup();
|
||||||
};
|
};
|
||||||
|
@ -532,8 +558,13 @@ function highlightEntityUnderCursor(position, accurateRay) {
|
||||||
|
|
||||||
|
|
||||||
function mouseReleaseEvent(event) {
|
function mouseReleaseEvent(event) {
|
||||||
|
if (toolBar.mouseReleaseEvent(event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (placingEntityID) {
|
if (placingEntityID) {
|
||||||
|
if (isActive) {
|
||||||
selectionManager.setSelections([placingEntityID]);
|
selectionManager.setSelections([placingEntityID]);
|
||||||
|
}
|
||||||
placingEntityID = null;
|
placingEntityID = null;
|
||||||
}
|
}
|
||||||
if (isActive && selectionManager.hasSelection()) {
|
if (isActive && selectionManager.hasSelection()) {
|
||||||
|
@ -956,10 +987,19 @@ PropertiesTool = function(opts) {
|
||||||
selectionManager.saveProperties();
|
selectionManager.saveProperties();
|
||||||
for (var i = 0; i < selectionManager.selections.length; i++) {
|
for (var i = 0; i < selectionManager.selections.length; i++) {
|
||||||
var properties = selectionManager.savedProperties[selectionManager.selections[i].id];
|
var properties = selectionManager.savedProperties[selectionManager.selections[i].id];
|
||||||
|
var naturalDimensions = properties.naturalDimensions;
|
||||||
|
|
||||||
|
// If any of the natural dimensions are not 0, resize
|
||||||
|
if (properties.type == "Model" && naturalDimensions.x == 0
|
||||||
|
&& naturalDimensions.y == 0 && naturalDimensions.z == 0) {
|
||||||
|
Window.alert("Cannot reset entity to its natural dimensions: Model URL"
|
||||||
|
+ " is invalid or the model has not yet been loaded.");
|
||||||
|
} else {
|
||||||
Entities.editEntity(selectionManager.selections[i], {
|
Entities.editEntity(selectionManager.selections[i], {
|
||||||
dimensions: properties.naturalDimensions,
|
dimensions: properties.naturalDimensions,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
pushCommandForSelections();
|
pushCommandForSelections();
|
||||||
selectionManager._update();
|
selectionManager._update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
print("BUTTERFLIES START");
|
||||||
|
|
||||||
|
|
||||||
var numButterflies = 25;
|
var numButterflies = 25;
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,7 +112,7 @@ function updateButterflies(deltaTime) {
|
||||||
var properties = Entities.getEntityProperties(butterflies[i]);
|
var properties = Entities.getEntityProperties(butterflies[i]);
|
||||||
if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) {
|
if (Vec3.length(Vec3.subtract(properties.position, flockPosition)) > range) {
|
||||||
Entities.editEntity(butterflies[i], { position: flockPosition } );
|
Entities.editEntity(butterflies[i], { position: flockPosition } );
|
||||||
} else if (properties.velocity.y < 0.0) {
|
} else if (properties.velocity.y <= 0.0) {
|
||||||
// If falling, Create a new direction and impulse
|
// If falling, Create a new direction and impulse
|
||||||
var HORIZ_SCALE = 0.50;
|
var HORIZ_SCALE = 0.50;
|
||||||
var VERT_SCALE = 0.50;
|
var VERT_SCALE = 0.50;
|
||||||
|
@ -139,3 +142,5 @@ Script.scriptEnding.connect(function() {
|
||||||
Entities.deleteEntity(butterflies[i]);
|
Entities.deleteEntity(butterflies[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
print("BUTTERFLIES END");
|
||||||
|
|
|
@ -30,8 +30,8 @@
|
||||||
elPosY.value = origin.y.toFixed(2);
|
elPosY.value = origin.y.toFixed(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.minorGridSpacing !== undefined) {
|
if (data.minorGridWidth !== undefined) {
|
||||||
elMinorSpacing.value = data.minorGridSpacing;
|
elMinorSpacing.value = data.minorGridWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.majorGridEvery !== undefined) {
|
if (data.majorGridEvery !== undefined) {
|
||||||
|
@ -57,7 +57,7 @@
|
||||||
origin: {
|
origin: {
|
||||||
y: elPosY.value,
|
y: elPosY.value,
|
||||||
},
|
},
|
||||||
minorGridSpacing: elMinorSpacing.value,
|
minorGridWidth: elMinorSpacing.value,
|
||||||
majorGridEvery: elMajorSpacing.value,
|
majorGridEvery: elMajorSpacing.value,
|
||||||
gridColor: gridColor,
|
gridColor: gridColor,
|
||||||
colorIndex: gridColorIndex,
|
colorIndex: gridColorIndex,
|
||||||
|
|
|
@ -9,179 +9,50 @@
|
||||||
// Usage: Enable VR-mode and go to First person mode,
|
// Usage: Enable VR-mode and go to First person mode,
|
||||||
// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard.
|
// look at the key that you would like to press, and press the spacebar on your "REAL" keyboard.
|
||||||
//
|
//
|
||||||
// leased some code from newEditEntities.js for Text Entity example
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
|
// experimental 3dmode
|
||||||
|
THREE_D_MODE = false;
|
||||||
|
|
||||||
const KBD_UPPERCASE_DEFAULT = 0;
|
KBD_UPPERCASE_DEFAULT = 0;
|
||||||
const KBD_LOWERCASE_DEFAULT = 1;
|
KBD_LOWERCASE_DEFAULT = 1;
|
||||||
const KBD_UPPERCASE_HOVER = 2;
|
KBD_UPPERCASE_HOVER = 2;
|
||||||
const KBD_LOWERCASE_HOVER = 3;
|
KBD_LOWERCASE_HOVER = 3;
|
||||||
const KBD_BACKGROUND = 4;
|
KBD_BACKGROUND = 4;
|
||||||
|
|
||||||
const KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg";
|
KEYBOARD_URL = HIFI_PUBLIC_BUCKET + "images/keyboard.svg";
|
||||||
const CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg";
|
CURSOR_URL = HIFI_PUBLIC_BUCKET + "images/cursor.svg";
|
||||||
|
|
||||||
const SPACEBAR_CHARCODE = 32;
|
RETURN_CHARCODE = 0x01000004;
|
||||||
|
ENTER_CHARCODE = 0x01000005;
|
||||||
|
SPACEBAR_CHARCODE = 32;
|
||||||
|
|
||||||
const KEYBOARD_WIDTH = 1174.7;
|
KEYBOARD_WIDTH = 1174.7;
|
||||||
const KEYBOARD_HEIGHT = 434.1;
|
KEYBOARD_HEIGHT = 434.1;
|
||||||
|
|
||||||
const CURSOR_WIDTH = 33.9;
|
CURSOR_WIDTH = 33.9;
|
||||||
const CURSOR_HEIGHT = 33.9;
|
CURSOR_HEIGHT = 33.9;
|
||||||
|
|
||||||
|
KEYBOARD_SCALE_MULTIPLIER = 0.50;
|
||||||
|
|
||||||
// VIEW_ANGLE can be adjusted to your likings, the smaller the faster movement.
|
// VIEW_ANGLE can be adjusted to your likings, the smaller the faster movement.
|
||||||
// Try setting it to 60 if it goes too fast for you.
|
// Try setting it to 60 if it goes too fast for you.
|
||||||
const VIEW_ANGLE = 40.0;
|
const VIEW_ANGLE = 40.0;
|
||||||
const VIEW_ANGLE_BY_TWO = VIEW_ANGLE / 2;
|
const VIEW_ANGLE_BY_TWO = VIEW_ANGLE / 2;
|
||||||
|
|
||||||
const SPAWN_DISTANCE = 1;
|
|
||||||
const DEFAULT_TEXT_DIMENSION_Z = 0.02;
|
|
||||||
|
|
||||||
const BOUND_X = 0;
|
const BOUND_X = 0;
|
||||||
const BOUND_Y = 1;
|
const BOUND_Y = 1;
|
||||||
const BOUND_W = 2;
|
const BOUND_W = 2;
|
||||||
const BOUND_H = 3;
|
const BOUND_H = 3;
|
||||||
|
|
||||||
const KEY_STATE_LOWER = 0;
|
KEY_STATE_LOWER = 0;
|
||||||
const KEY_STATE_UPPER = 1;
|
KEY_STATE_UPPER = 1;
|
||||||
|
|
||||||
const TEXT_MARGIN_TOP = 0.15;
|
|
||||||
const TEXT_MARGIN_LEFT = 0.15;
|
|
||||||
const TEXT_MARGIN_RIGHT = 0.17;
|
|
||||||
const TEXT_MARGIN_BOTTOM = 0.17;
|
|
||||||
|
|
||||||
var windowDimensions = Controller.getViewportDimensions();
|
var windowDimensions = Controller.getViewportDimensions();
|
||||||
var cursor = null;
|
|
||||||
var keyboard = new Keyboard();
|
|
||||||
var textFontSize = 9;
|
|
||||||
var text = null;
|
|
||||||
var textText = "";
|
|
||||||
var textSizeMeasureOverlay = Overlays.addOverlay("text3d", {visible: false});
|
|
||||||
|
|
||||||
function appendChar(char) {
|
KeyboardKey = (function(keyboard, keyProperties) {
|
||||||
textText += char;
|
|
||||||
updateTextOverlay();
|
|
||||||
Overlays.editOverlay(text, {text: textText});
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteChar() {
|
|
||||||
if (textText.length > 0) {
|
|
||||||
textText = textText.substring(0, textText.length - 1);
|
|
||||||
updateTextOverlay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateTextOverlay() {
|
|
||||||
var textLines = textText.split("\n");
|
|
||||||
var maxLineWidth = 0;
|
|
||||||
for (textLine in textLines) {
|
|
||||||
var lineWidth = Overlays.textSize(text, textLines[textLine]).width;
|
|
||||||
if (lineWidth > maxLineWidth) {
|
|
||||||
maxLineWidth = lineWidth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var suggestedFontSize = (windowDimensions.x / maxLineWidth) * textFontSize * 0.90;
|
|
||||||
var maxFontSize = 190 / textLines.length;
|
|
||||||
textFontSize = (suggestedFontSize > maxFontSize) ? maxFontSize : suggestedFontSize;
|
|
||||||
var topMargin = (250 - (textFontSize * textLines.length)) / 4;
|
|
||||||
Overlays.editOverlay(text, {text: textText, font: {size: textFontSize}, topMargin: topMargin});
|
|
||||||
var maxLineWidth = 0;
|
|
||||||
for (textLine in textLines) {
|
|
||||||
var lineWidth = Overlays.textSize(text, textLines[textLine]).width;
|
|
||||||
if (lineWidth > maxLineWidth) {
|
|
||||||
maxLineWidth = lineWidth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Overlays.editOverlay(text, {leftMargin: (windowDimensions.x - maxLineWidth) / 2});
|
|
||||||
}
|
|
||||||
|
|
||||||
keyboard.onKeyPress = function(event) {
|
|
||||||
if (event.event == 'keypress') {
|
|
||||||
appendChar(event.char);
|
|
||||||
} else if (event.event == 'enter') {
|
|
||||||
appendChar("\n");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
keyboard.onKeyRelease = function(event) {
|
|
||||||
print("Key release event test");
|
|
||||||
// you can cancel a key by releasing its focusing before releasing it
|
|
||||||
if (event.focus) {
|
|
||||||
if (event.event == 'delete') {
|
|
||||||
deleteChar();
|
|
||||||
} else if (event.event == 'submit') {
|
|
||||||
print(textText);
|
|
||||||
|
|
||||||
var position = Vec3.sum(MyAvatar.position, Vec3.multiply(Quat.getFront(MyAvatar.orientation), SPAWN_DISTANCE));
|
|
||||||
|
|
||||||
var textLines = textText.split("\n");
|
|
||||||
var maxLineWidth = 0;
|
|
||||||
for (textLine in textLines) {
|
|
||||||
var lineWidth = Overlays.textSize(textSizeMeasureOverlay, textLines[textLine]).width;
|
|
||||||
if (lineWidth > maxLineWidth) {
|
|
||||||
maxLineWidth = lineWidth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var usernameLine = "--" + GlobalServices.myUsername;
|
|
||||||
var usernameWidth = Overlays.textSize(textSizeMeasureOverlay, usernameLine).width;
|
|
||||||
if (maxLineWidth < usernameWidth) {
|
|
||||||
maxLineWidth = usernameWidth;
|
|
||||||
} else {
|
|
||||||
var spaceableWidth = maxLineWidth - usernameWidth;
|
|
||||||
var spaceWidth = Overlays.textSize(textSizeMeasureOverlay, " ").width;
|
|
||||||
var numberOfSpaces = Math.floor(spaceableWidth / spaceWidth);
|
|
||||||
for (var i = 0; i < numberOfSpaces; i++) {
|
|
||||||
usernameLine = " " + usernameLine;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var dimension_x = maxLineWidth + TEXT_MARGIN_RIGHT + TEXT_MARGIN_LEFT;
|
|
||||||
if (position.x > 0 && position.y > 0 && position.z > 0) {
|
|
||||||
Entities.addEntity({
|
|
||||||
type: "Text",
|
|
||||||
rotation: MyAvatar.orientation,
|
|
||||||
position: position,
|
|
||||||
dimensions: { x: dimension_x, y: (textLines.length + 1) * 0.14 + TEXT_MARGIN_TOP + TEXT_MARGIN_BOTTOM, z: DEFAULT_TEXT_DIMENSION_Z },
|
|
||||||
backgroundColor: { red: 0, green: 0, blue: 0 },
|
|
||||||
textColor: { red: 255, green: 255, blue: 255 },
|
|
||||||
text: textText + "\n" + usernameLine
|
|
||||||
});
|
|
||||||
}
|
|
||||||
textText = "";
|
|
||||||
updateTextOverlay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
keyboard.onFullyLoaded = function() {
|
|
||||||
print("Virtual-keyboard fully loaded.");
|
|
||||||
var dimensions = Controller.getViewportDimensions();
|
|
||||||
text = Overlays.addOverlay("text", {
|
|
||||||
x: 0,
|
|
||||||
y: dimensions.y - keyboard.height() - 260,
|
|
||||||
width: dimensions.x,
|
|
||||||
height: 250,
|
|
||||||
backgroundColor: { red: 255, green: 255, blue: 255},
|
|
||||||
color: { red: 0, green: 0, blue: 0},
|
|
||||||
topMargin: 5,
|
|
||||||
leftMargin: 0,
|
|
||||||
font: {size: textFontSize},
|
|
||||||
text: "",
|
|
||||||
alpha: 0.8
|
|
||||||
});
|
|
||||||
updateTextOverlay();
|
|
||||||
// the cursor is being loaded after the keyboard, else it will be on the background of the keyboard
|
|
||||||
cursor = new Cursor();
|
|
||||||
cursor.onUpdate = function(position) {
|
|
||||||
keyboard.setFocusPosition(position.x, position.y);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
function KeyboardKey(keyboard, keyProperties) {
|
|
||||||
var tthis = this;
|
var tthis = this;
|
||||||
this._focus = false;
|
this._focus = false;
|
||||||
this._beingPressed = false;
|
this._beingPressed = false;
|
||||||
|
@ -247,6 +118,11 @@ function KeyboardKey(keyboard, keyProperties) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this.updateVisibility = function() {
|
||||||
|
for (var i = 0; i < tthis.bounds.length; i++) {
|
||||||
|
Overlays.editOverlay(tthis.overlays[i], {visible: tthis.keyboard.visible});
|
||||||
|
}
|
||||||
|
};
|
||||||
this.rescale = function() {
|
this.rescale = function() {
|
||||||
for (var i = 0; i < tthis.bounds.length; i++) {
|
for (var i = 0; i < tthis.bounds.length; i++) {
|
||||||
Overlays.editOverlay(tthis.overlays[i], {
|
Overlays.editOverlay(tthis.overlays[i], {
|
||||||
|
@ -271,24 +147,48 @@ function KeyboardKey(keyboard, keyProperties) {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
for (var i = 0; i < this.bounds.length; i++) {
|
for (var i = 0; i < this.bounds.length; i++) {
|
||||||
var newOverlay = Overlays.cloneOverlay(this.keyboard.background);
|
if (THREE_D_MODE) {
|
||||||
Overlays.editOverlay(newOverlay, {
|
this.overlays.push(Overlays.addOverlay("billboard", {
|
||||||
|
scale: 1,
|
||||||
|
rotation: MyAvatar.rotation,
|
||||||
|
isFacingAvatar: false,
|
||||||
|
url: KEYBOARD_URL,
|
||||||
|
alpha: 1,
|
||||||
|
position: {
|
||||||
|
x: MyAvatar.position.x,// + this.bounds[i][BOUND_X] * 0.01,// /*+ this.keyboard.getX()*/ + this.bounds[i][BOUND_X] * keyboard.scale,
|
||||||
|
y: MyAvatar.position.y,// - this.bounds[i][BOUND_Y] * 0.01,// /*+ this.keyboard.getY()*/ + this.bounds[i][BOUND_Y] * keyboard.scale,
|
||||||
|
z: MyAvatar.position.z
|
||||||
|
},
|
||||||
|
width: this.bounds[i][BOUND_W] * keyboard.scale,
|
||||||
|
height: this.bounds[i][BOUND_H] * keyboard.scale,
|
||||||
|
subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]},
|
||||||
|
alpha: 1,
|
||||||
|
visible: tthis.keyboard.visible
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
this.overlays.push(Overlays.addOverlay("image", {
|
||||||
|
imageURL: KEYBOARD_URL,
|
||||||
x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale,
|
x: this.keyboard.getX() + this.bounds[i][BOUND_X] * keyboard.scale,
|
||||||
y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale,
|
y: this.keyboard.getY() + this.bounds[i][BOUND_Y] * keyboard.scale,
|
||||||
width: this.bounds[i][BOUND_W] * keyboard.scale,
|
width: this.bounds[i][BOUND_W] * keyboard.scale,
|
||||||
height: this.bounds[i][BOUND_H] * keyboard.scale,
|
height: this.bounds[i][BOUND_H] * keyboard.scale,
|
||||||
subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]},
|
subImage: {width: this.bounds[i][BOUND_W], height: this.bounds[i][BOUND_H], x: this.bounds[i][BOUND_X], y: (KEYBOARD_HEIGHT * this.keyState) + this.bounds[i][BOUND_Y]},
|
||||||
alpha: 1
|
alpha: 1,
|
||||||
});
|
visible: tthis.keyboard.visible
|
||||||
this.overlays.push(newOverlay);
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function Keyboard() {
|
Keyboard = (function(params) {
|
||||||
|
if (params === undefined) {
|
||||||
|
params = {};
|
||||||
|
}
|
||||||
var tthis = this;
|
var tthis = this;
|
||||||
this.focussed_key = -1;
|
this.focussed_key = -1;
|
||||||
this.scale = windowDimensions.x / KEYBOARD_WIDTH;
|
this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER;
|
||||||
this.shift = false;
|
this.shift = false;
|
||||||
|
this.visible = params.visible != undefined ? params.visible : true;
|
||||||
this.width = function() {
|
this.width = function() {
|
||||||
return KEYBOARD_WIDTH * tthis.scale;
|
return KEYBOARD_WIDTH * tthis.scale;
|
||||||
};
|
};
|
||||||
|
@ -301,6 +201,20 @@ function Keyboard() {
|
||||||
this.getY = function() {
|
this.getY = function() {
|
||||||
return windowDimensions.y - this.height();
|
return windowDimensions.y - this.height();
|
||||||
};
|
};
|
||||||
|
if (THREE_D_MODE) {
|
||||||
|
this.background = Overlays.addOverlay("billboard", {
|
||||||
|
scale: 1,
|
||||||
|
position: MyAvatar.position,
|
||||||
|
rotation: MyAvatar.rotation,
|
||||||
|
width: this.width(),
|
||||||
|
height: this.height(),
|
||||||
|
subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND},
|
||||||
|
isFacingAvatar: false,
|
||||||
|
url: KEYBOARD_URL,
|
||||||
|
alpha: 1,
|
||||||
|
visible: this.visible
|
||||||
|
});
|
||||||
|
} else {
|
||||||
this.background = Overlays.addOverlay("image", {
|
this.background = Overlays.addOverlay("image", {
|
||||||
x: this.getX(),
|
x: this.getX(),
|
||||||
y: this.getY(),
|
y: this.getY(),
|
||||||
|
@ -308,10 +222,12 @@ function Keyboard() {
|
||||||
height: this.height(),
|
height: this.height(),
|
||||||
subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND},
|
subImage: {width: KEYBOARD_WIDTH, height: KEYBOARD_HEIGHT, y: KEYBOARD_HEIGHT * KBD_BACKGROUND},
|
||||||
imageURL: KEYBOARD_URL,
|
imageURL: KEYBOARD_URL,
|
||||||
alpha: 1
|
alpha: 1,
|
||||||
|
visible: this.visible
|
||||||
});
|
});
|
||||||
|
}
|
||||||
this.rescale = function() {
|
this.rescale = function() {
|
||||||
this.scale = windowDimensions.x / KEYBOARD_WIDTH;
|
this.scale = (windowDimensions.x / KEYBOARD_WIDTH) * KEYBOARD_SCALE_MULTIPLIER;
|
||||||
Overlays.editOverlay(tthis.background, {
|
Overlays.editOverlay(tthis.background, {
|
||||||
x: this.getX(),
|
x: this.getX(),
|
||||||
y: this.getY(),
|
y: this.getY(),
|
||||||
|
@ -349,6 +265,9 @@ function Keyboard() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.pressFocussedKey = function() {
|
this.pressFocussedKey = function() {
|
||||||
|
if (!tthis.visible) {
|
||||||
|
return tthis;
|
||||||
|
}
|
||||||
if (tthis.focussed_key != -1) {
|
if (tthis.focussed_key != -1) {
|
||||||
if (tthis.keys[tthis.focussed_key].event == 'shift') {
|
if (tthis.keys[tthis.focussed_key].event == 'shift') {
|
||||||
tthis.toggleShift();
|
tthis.toggleShift();
|
||||||
|
@ -402,6 +321,32 @@ function Keyboard() {
|
||||||
for (var i = 0; i < this.keys.length; i++) {
|
for (var i = 0; i < this.keys.length; i++) {
|
||||||
this.keys[i].remove();
|
this.keys[i].remove();
|
||||||
}
|
}
|
||||||
|
// resets the cursor and magnifier
|
||||||
|
this.updateVisibility(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.show = function() {
|
||||||
|
tthis.updateVisibility(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.hide = function() {
|
||||||
|
tthis.updateVisibility(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.toggle = function() {
|
||||||
|
tthis.updateVisibility(!tthis.visible);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.updateVisibility = function(visible) {
|
||||||
|
tthis.visible = visible;
|
||||||
|
if (HMD.magnifier == visible) {
|
||||||
|
HMD.toggleMagnifier();
|
||||||
|
}
|
||||||
|
Window.cursorVisible = !visible;
|
||||||
|
Overlays.editOverlay(tthis.background, { visible: tthis.visible });
|
||||||
|
for (var i = 0; i < this.keys.length; i++) {
|
||||||
|
this.keys[i].updateVisibility();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onKeyPress = null;
|
this.onKeyPress = null;
|
||||||
|
@ -502,23 +447,27 @@ function Keyboard() {
|
||||||
|
|
||||||
{bounds: [[899, 355, 263, 67]], event: 'submit'}
|
{bounds: [[899, 355, 263, 67]], event: 'submit'}
|
||||||
];
|
];
|
||||||
|
for (var i = 0; i < keyProperties.length; i++) {
|
||||||
|
this.keys.push(new KeyboardKey(this, keyProperties[i]));
|
||||||
|
}
|
||||||
this.keyboardTextureLoaded = function() {
|
this.keyboardTextureLoaded = function() {
|
||||||
if (Overlays.isLoaded(tthis.background)) {
|
if (Overlays.isLoaded(tthis.background)) {
|
||||||
Script.clearInterval(tthis.keyboardTextureLoaded_timer);
|
Script.clearInterval(tthis.keyboardTextureLoaded_timer);
|
||||||
for (var i = 0; i < keyProperties.length; i++) {
|
|
||||||
tthis.keys.push(new KeyboardKey(tthis, keyProperties[i]));
|
|
||||||
}
|
|
||||||
if (keyboard.onFullyLoaded != null) {
|
if (keyboard.onFullyLoaded != null) {
|
||||||
tthis.onFullyLoaded();
|
tthis.onFullyLoaded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.keyboardTextureLoaded_timer = Script.setInterval(this.keyboardTextureLoaded, 250);
|
this.keyboardTextureLoaded_timer = Script.setInterval(this.keyboardTextureLoaded, 250);
|
||||||
}
|
});
|
||||||
|
|
||||||
function Cursor() {
|
Cursor = (function(params) {
|
||||||
|
if (params === undefined) {
|
||||||
|
params = {};
|
||||||
|
}
|
||||||
var tthis = this;
|
var tthis = this;
|
||||||
|
this.initialize = function() {
|
||||||
|
this.visible = params.visible != undefined ? params.visible : true;
|
||||||
this.x = windowDimensions.x / 2;
|
this.x = windowDimensions.x / 2;
|
||||||
this.y = windowDimensions.y / 2;
|
this.y = windowDimensions.y / 2;
|
||||||
this.overlay = Overlays.addOverlay("image", {
|
this.overlay = Overlays.addOverlay("image", {
|
||||||
|
@ -527,7 +476,8 @@ function Cursor() {
|
||||||
width: CURSOR_WIDTH,
|
width: CURSOR_WIDTH,
|
||||||
height: CURSOR_HEIGHT,
|
height: CURSOR_HEIGHT,
|
||||||
imageURL: CURSOR_URL,
|
imageURL: CURSOR_URL,
|
||||||
alpha: 1
|
alpha: 1,
|
||||||
|
visible: this.visible
|
||||||
});
|
});
|
||||||
this.remove = function() {
|
this.remove = function() {
|
||||||
Overlays.deleteOverlay(this.overlay);
|
Overlays.deleteOverlay(this.overlay);
|
||||||
|
@ -541,6 +491,19 @@ function Cursor() {
|
||||||
this.getY = function() {
|
this.getY = function() {
|
||||||
return tthis.y;
|
return tthis.y;
|
||||||
};
|
};
|
||||||
|
this.show = function() {
|
||||||
|
tthis.updateVisibility(true);
|
||||||
|
};
|
||||||
|
this.hide = function() {
|
||||||
|
tthis.updateVisibility(false);
|
||||||
|
};
|
||||||
|
this.toggle = function() {
|
||||||
|
tthis.updateVisibility(!tthis.visible);
|
||||||
|
};
|
||||||
|
this.updateVisibility = function(visible) {
|
||||||
|
tthis.visible = visible;
|
||||||
|
Overlays.editOverlay(this.overlay, { visible: tthis.visible });
|
||||||
|
};
|
||||||
this.onUpdate = null;
|
this.onUpdate = null;
|
||||||
this.update = function() {
|
this.update = function() {
|
||||||
var newWindowDimensions = Controller.getViewportDimensions();
|
var newWindowDimensions = Controller.getViewportDimensions();
|
||||||
|
@ -553,14 +516,16 @@ function Cursor() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var editobject = {};
|
var editobject = {};
|
||||||
if (MyAvatar.getHeadFinalYaw() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalYaw() >= -1 * VIEW_ANGLE_BY_TWO) {
|
var hudLookatPosition = HMD.getHUDLookAtPosition2D();
|
||||||
angle = ((-1 * MyAvatar.getHeadFinalYaw()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE;
|
if (hudLookatPosition === null) {
|
||||||
tthis.x = angle * windowDimensions.x;
|
return;
|
||||||
|
}
|
||||||
|
if (tthis.x !== hudLookatPosition.x) {
|
||||||
|
tthis.x = hudLookatPosition.x;
|
||||||
editobject.x = tthis.x - (CURSOR_WIDTH / 2);
|
editobject.x = tthis.x - (CURSOR_WIDTH / 2);
|
||||||
}
|
}
|
||||||
if (MyAvatar.getHeadFinalPitch() <= VIEW_ANGLE_BY_TWO && MyAvatar.getHeadFinalPitch() >= -1 * VIEW_ANGLE_BY_TWO) {
|
if (tthis.y !== hudLookatPosition.y) {
|
||||||
angle = ((-1 * MyAvatar.getHeadFinalPitch()) + VIEW_ANGLE_BY_TWO) / VIEW_ANGLE;
|
tthis.y = hudLookatPosition.y;
|
||||||
tthis.y = angle * windowDimensions.y;
|
|
||||||
editobject.y = tthis.y - (CURSOR_HEIGHT / 2);
|
editobject.y = tthis.y - (CURSOR_HEIGHT / 2);
|
||||||
}
|
}
|
||||||
if (Object.keys(editobject).length > 0) {
|
if (Object.keys(editobject).length > 0) {
|
||||||
|
@ -571,28 +536,5 @@ function Cursor() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Script.update.connect(this.update);
|
Script.update.connect(this.update);
|
||||||
}
|
};
|
||||||
|
});
|
||||||
function keyPressEvent(event) {
|
|
||||||
if (event.key === SPACEBAR_CHARCODE) {
|
|
||||||
keyboard.pressFocussedKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function keyReleaseEvent(event) {
|
|
||||||
if (event.key === SPACEBAR_CHARCODE) {
|
|
||||||
keyboard.releaseKeys();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function scriptEnding() {
|
|
||||||
keyboard.remove();
|
|
||||||
cursor.remove();
|
|
||||||
Overlays.deleteOverlay(text);
|
|
||||||
Overlays.deleteOverlay(textSizeMeasureOverlay);
|
|
||||||
Controller.releaseKeyEvents({key: SPACEBAR_CHARCODE});
|
|
||||||
}
|
|
||||||
Controller.captureKeyEvents({key: SPACEBAR_CHARCODE});
|
|
||||||
Controller.keyPressEvent.connect(keyPressEvent);
|
|
||||||
Controller.keyReleaseEvent.connect(keyReleaseEvent);
|
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
|
|
@ -9,8 +9,6 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <QtCore/QThread>
|
|
||||||
|
|
||||||
#include <AccountManager.h>
|
#include <AccountManager.h>
|
||||||
#include <AddressManager.h>
|
#include <AddressManager.h>
|
||||||
#include <HifiSockAddr.h>
|
#include <HifiSockAddr.h>
|
||||||
|
|
|
@ -16,13 +16,14 @@
|
||||||
|
|
||||||
#include <HifiSockAddr.h>
|
#include <HifiSockAddr.h>
|
||||||
|
|
||||||
class QThread;
|
|
||||||
|
|
||||||
class Client : public QObject {
|
class Client : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Client(QObject* parent = 0);
|
Client(QObject* parent = 0);
|
||||||
|
|
||||||
|
virtual void cleanupBeforeQuit() = 0;
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void setupNetworking();
|
void setupNetworking();
|
||||||
virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket);
|
virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket);
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -86,6 +86,13 @@ GVRInterface::GVRInterface(int argc, char* argv[]) :
|
||||||
QTimer* idleTimer = new QTimer(this);
|
QTimer* idleTimer = new QTimer(this);
|
||||||
connect(idleTimer, &QTimer::timeout, this, &GVRInterface::idle);
|
connect(idleTimer, &QTimer::timeout, this, &GVRInterface::idle);
|
||||||
idleTimer->start(0);
|
idleTimer->start(0);
|
||||||
|
|
||||||
|
// call our quit handler before we go down
|
||||||
|
connect(this, &QCoreApplication::aboutToQuit, this, &GVRInterface::handleApplicationQuit);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GVRInterface::handleApplicationQuit() {
|
||||||
|
_client->cleanupBeforeQuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GVRInterface::idle() {
|
void GVRInterface::idle() {
|
||||||
|
|
|
@ -53,6 +53,7 @@ private slots:
|
||||||
void handleApplicationStateChange(Qt::ApplicationState state);
|
void handleApplicationStateChange(Qt::ApplicationState state);
|
||||||
void idle();
|
void idle();
|
||||||
private:
|
private:
|
||||||
|
void handleApplicationQuit();
|
||||||
|
|
||||||
void enterVRMode();
|
void enterVRMode();
|
||||||
void leaveVRMode();
|
void leaveVRMode();
|
||||||
|
|
|
@ -37,7 +37,7 @@ RenderingClient::RenderingClient(QObject *parent, const QString& launchURLString
|
||||||
DependencyManager::set<AvatarHashMap>();
|
DependencyManager::set<AvatarHashMap>();
|
||||||
|
|
||||||
// get our audio client setup on its own thread
|
// get our audio client setup on its own thread
|
||||||
QThread* audioThread = new QThread(this);
|
QThread* audioThread = new QThread();
|
||||||
auto audioClient = DependencyManager::set<AudioClient>();
|
auto audioClient = DependencyManager::set<AudioClient>();
|
||||||
|
|
||||||
audioClient->setPositionGetter(getPositionForAudio);
|
audioClient->setPositionGetter(getPositionForAudio);
|
||||||
|
@ -45,6 +45,8 @@ RenderingClient::RenderingClient(QObject *parent, const QString& launchURLString
|
||||||
|
|
||||||
audioClient->moveToThread(audioThread);
|
audioClient->moveToThread(audioThread);
|
||||||
connect(audioThread, &QThread::started, audioClient.data(), &AudioClient::start);
|
connect(audioThread, &QThread::started, audioClient.data(), &AudioClient::start);
|
||||||
|
connect(audioClient.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
|
||||||
|
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
|
||||||
|
|
||||||
audioThread->start();
|
audioThread->start();
|
||||||
|
|
||||||
|
@ -68,15 +70,13 @@ void RenderingClient::sendAvatarPacket() {
|
||||||
_fakeAvatar.sendIdentityPacket();
|
_fakeAvatar.sendIdentityPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderingClient::~RenderingClient() {
|
void RenderingClient::cleanupBeforeQuit() {
|
||||||
auto audioClient = DependencyManager::get<AudioClient>();
|
|
||||||
|
|
||||||
// stop the audio client
|
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
|
||||||
QMetaObject::invokeMethod(audioClient.data(), "stop", Qt::BlockingQueuedConnection);
|
"stop", Qt::BlockingQueuedConnection);
|
||||||
|
|
||||||
// ask the audio thread to quit and wait until it is done
|
// destroy the AudioClient so it and its thread will safely go down
|
||||||
audioClient->thread()->quit();
|
DependencyManager::destroy<AudioClient>();
|
||||||
audioClient->thread()->wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderingClient::processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket) {
|
void RenderingClient::processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket) {
|
||||||
|
|
|
@ -26,7 +26,6 @@ class RenderingClient : public Client {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
RenderingClient(QObject* parent = 0, const QString& launchURLString = QString());
|
RenderingClient(QObject* parent = 0, const QString& launchURLString = QString());
|
||||||
~RenderingClient();
|
|
||||||
|
|
||||||
const glm::vec3& getPosition() const { return _position; }
|
const glm::vec3& getPosition() const { return _position; }
|
||||||
const glm::quat& getOrientation() const { return _orientation; }
|
const glm::quat& getOrientation() const { return _orientation; }
|
||||||
|
@ -35,6 +34,8 @@ public:
|
||||||
static glm::vec3 getPositionForAudio() { return _instance->getPosition(); }
|
static glm::vec3 getPositionForAudio() { return _instance->getPosition(); }
|
||||||
static glm::quat getOrientationForAudio() { return _instance->getOrientation(); }
|
static glm::quat getOrientationForAudio() { return _instance->getOrientation(); }
|
||||||
|
|
||||||
|
virtual void cleanupBeforeQuit();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void goToLocation(const glm::vec3& newPosition,
|
void goToLocation(const glm::vec3& newPosition,
|
||||||
bool hasOrientationChange, const glm::quat& newOrientation,
|
bool hasOrientationChange, const glm::quat& newOrientation,
|
||||||
|
|
|
@ -65,6 +65,7 @@
|
||||||
#include <HFBackEvent.h>
|
#include <HFBackEvent.h>
|
||||||
#include <LogHandler.h>
|
#include <LogHandler.h>
|
||||||
#include <MainWindow.h>
|
#include <MainWindow.h>
|
||||||
|
#include <ModelEntityItem.h>
|
||||||
#include <NetworkAccessManager.h>
|
#include <NetworkAccessManager.h>
|
||||||
#include <OctalCode.h>
|
#include <OctalCode.h>
|
||||||
#include <OctreeSceneStats.h>
|
#include <OctreeSceneStats.h>
|
||||||
|
@ -110,6 +111,7 @@
|
||||||
#include "scripting/AccountScriptingInterface.h"
|
#include "scripting/AccountScriptingInterface.h"
|
||||||
#include "scripting/AudioDeviceScriptingInterface.h"
|
#include "scripting/AudioDeviceScriptingInterface.h"
|
||||||
#include "scripting/ClipboardScriptingInterface.h"
|
#include "scripting/ClipboardScriptingInterface.h"
|
||||||
|
#include "scripting/HMDScriptingInterface.h"
|
||||||
#include "scripting/JoystickScriptingInterface.h"
|
#include "scripting/JoystickScriptingInterface.h"
|
||||||
#include "scripting/GlobalServicesScriptingInterface.h"
|
#include "scripting/GlobalServicesScriptingInterface.h"
|
||||||
#include "scripting/LocationScriptingInterface.h"
|
#include "scripting/LocationScriptingInterface.h"
|
||||||
|
@ -211,6 +213,8 @@ bool setupEssentials(int& argc, char** argv) {
|
||||||
auto addressManager = DependencyManager::set<AddressManager>();
|
auto addressManager = DependencyManager::set<AddressManager>();
|
||||||
auto nodeList = DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
|
auto nodeList = DependencyManager::set<NodeList>(NodeType::Agent, listenPort);
|
||||||
auto geometryCache = DependencyManager::set<GeometryCache>();
|
auto geometryCache = DependencyManager::set<GeometryCache>();
|
||||||
|
auto scriptCache = DependencyManager::set<ScriptCache>();
|
||||||
|
auto soundCache = DependencyManager::set<SoundCache>();
|
||||||
auto glowEffect = DependencyManager::set<GlowEffect>();
|
auto glowEffect = DependencyManager::set<GlowEffect>();
|
||||||
auto faceshift = DependencyManager::set<Faceshift>();
|
auto faceshift = DependencyManager::set<Faceshift>();
|
||||||
auto audio = DependencyManager::set<AudioClient>();
|
auto audio = DependencyManager::set<AudioClient>();
|
||||||
|
@ -328,7 +332,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), &_datagramProcessor, SLOT(processDatagrams()));
|
connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), &_datagramProcessor, SLOT(processDatagrams()));
|
||||||
|
|
||||||
// put the audio processing on a separate thread
|
// put the audio processing on a separate thread
|
||||||
QThread* audioThread = new QThread(this);
|
QThread* audioThread = new QThread();
|
||||||
audioThread->setObjectName("Audio Thread");
|
audioThread->setObjectName("Audio Thread");
|
||||||
|
|
||||||
auto audioIO = DependencyManager::get<AudioClient>();
|
auto audioIO = DependencyManager::get<AudioClient>();
|
||||||
|
@ -338,7 +342,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
|
|
||||||
audioIO->moveToThread(audioThread);
|
audioIO->moveToThread(audioThread);
|
||||||
connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
|
connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
|
||||||
connect(audioIO.data(), SIGNAL(muteToggled()), this, SLOT(audioMuteToggled()));
|
connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
|
||||||
|
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
|
||||||
|
connect(audioIO.data(), &AudioClient::muteToggled, this, &Application::audioMuteToggled);
|
||||||
|
|
||||||
audioThread->start();
|
audioThread->start();
|
||||||
|
|
||||||
|
@ -516,40 +522,47 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
|
|
||||||
void Application::aboutToQuit() {
|
void Application::aboutToQuit() {
|
||||||
_aboutToQuit = true;
|
_aboutToQuit = true;
|
||||||
|
|
||||||
|
cleanupBeforeQuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application() {
|
void Application::cleanupBeforeQuit() {
|
||||||
|
// make sure we don't call the idle timer any more
|
||||||
|
delete idleTimer;
|
||||||
|
|
||||||
|
// save state
|
||||||
QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection);
|
QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection);
|
||||||
_settingsThread.quit();
|
_settingsThread.quit();
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
|
||||||
_entities.getTree()->setSimulation(NULL);
|
|
||||||
qInstallMessageHandler(NULL);
|
|
||||||
|
|
||||||
_window->saveGeometry();
|
_window->saveGeometry();
|
||||||
|
|
||||||
int DELAY_TIME = 1000;
|
// TODO: now that this is in cleanupBeforeQuit do we really need it to stop and force
|
||||||
UserActivityLogger::getInstance().close(DELAY_TIME);
|
// an event loop to send the packet?
|
||||||
|
UserActivityLogger::getInstance().close();
|
||||||
// make sure we don't call the idle timer any more
|
|
||||||
delete idleTimer;
|
|
||||||
|
|
||||||
// let the avatar mixer know we're out
|
// let the avatar mixer know we're out
|
||||||
MyAvatar::sendKillAvatar();
|
MyAvatar::sendKillAvatar();
|
||||||
|
|
||||||
|
// stop the AudioClient
|
||||||
|
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
|
||||||
|
"stop", Qt::BlockingQueuedConnection);
|
||||||
|
|
||||||
|
// destroy the AudioClient so it and its thread have a chance to go down safely
|
||||||
|
DependencyManager::destroy<AudioClient>();
|
||||||
|
}
|
||||||
|
|
||||||
|
Application::~Application() {
|
||||||
|
EntityTree* tree = _entities.getTree();
|
||||||
|
tree->lockForWrite();
|
||||||
|
_entities.getTree()->setSimulation(NULL);
|
||||||
|
tree->unlock();
|
||||||
|
|
||||||
|
qInstallMessageHandler(NULL);
|
||||||
|
|
||||||
// ask the datagram processing thread to quit and wait until it is done
|
// ask the datagram processing thread to quit and wait until it is done
|
||||||
_nodeThread->quit();
|
_nodeThread->quit();
|
||||||
_nodeThread->wait();
|
_nodeThread->wait();
|
||||||
|
|
||||||
auto audioIO = DependencyManager::get<AudioClient>();
|
|
||||||
|
|
||||||
// stop the audio process
|
|
||||||
QMetaObject::invokeMethod(audioIO.data(), "stop", Qt::BlockingQueuedConnection);
|
|
||||||
|
|
||||||
// ask the audio thread to quit and wait until it is done
|
|
||||||
audioIO->thread()->quit();
|
|
||||||
audioIO->thread()->wait();
|
|
||||||
|
|
||||||
_octreeProcessor.terminate();
|
_octreeProcessor.terminate();
|
||||||
_entityEditSender.terminate();
|
_entityEditSender.terminate();
|
||||||
|
|
||||||
|
@ -557,12 +570,17 @@ Application::~Application() {
|
||||||
|
|
||||||
_myAvatar = NULL;
|
_myAvatar = NULL;
|
||||||
|
|
||||||
|
ModelEntityItem::cleanupLoadedAnimations() ;
|
||||||
|
|
||||||
DependencyManager::destroy<GLCanvas>();
|
DependencyManager::destroy<GLCanvas>();
|
||||||
|
|
||||||
|
qDebug() << "start destroying ResourceCaches Application::~Application() line:" << __LINE__;
|
||||||
DependencyManager::destroy<AnimationCache>();
|
DependencyManager::destroy<AnimationCache>();
|
||||||
DependencyManager::destroy<TextureCache>();
|
DependencyManager::destroy<TextureCache>();
|
||||||
DependencyManager::destroy<GeometryCache>();
|
DependencyManager::destroy<GeometryCache>();
|
||||||
DependencyManager::destroy<ScriptCache>();
|
DependencyManager::destroy<ScriptCache>();
|
||||||
DependencyManager::destroy<SoundCache>();
|
DependencyManager::destroy<SoundCache>();
|
||||||
|
qDebug() << "done destroying ResourceCaches Application::~Application() line:" << __LINE__;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::initializeGL() {
|
void Application::initializeGL() {
|
||||||
|
@ -2599,6 +2617,9 @@ const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f };
|
||||||
const GLfloat WORLD_DIFFUSE_COLOR[] = { 0.6f, 0.525f, 0.525f };
|
const GLfloat WORLD_DIFFUSE_COLOR[] = { 0.6f, 0.525f, 0.525f };
|
||||||
const GLfloat WORLD_SPECULAR_COLOR[] = { 0.94f, 0.94f, 0.737f, 1.0f };
|
const GLfloat WORLD_SPECULAR_COLOR[] = { 0.94f, 0.94f, 0.737f, 1.0f };
|
||||||
|
|
||||||
|
const glm::vec3 GLOBAL_LIGHT_COLOR = { 0.6f, 0.525f, 0.525f };
|
||||||
|
const float GLOBAL_LIGHT_INTENSITY = 1.0f;
|
||||||
|
|
||||||
void Application::setupWorldLight() {
|
void Application::setupWorldLight() {
|
||||||
|
|
||||||
// Setup 3D lights (after the camera transform, so that they are positioned in world space)
|
// Setup 3D lights (after the camera transform, so that they are positioned in world space)
|
||||||
|
@ -2613,6 +2634,7 @@ void Application::setupWorldLight() {
|
||||||
glLightfv(GL_LIGHT0, GL_SPECULAR, WORLD_SPECULAR_COLOR);
|
glLightfv(GL_LIGHT0, GL_SPECULAR, WORLD_SPECULAR_COLOR);
|
||||||
glMaterialfv(GL_FRONT, GL_SPECULAR, WORLD_SPECULAR_COLOR);
|
glMaterialfv(GL_FRONT, GL_SPECULAR, WORLD_SPECULAR_COLOR);
|
||||||
glMateriali(GL_FRONT, GL_SHININESS, 96);
|
glMateriali(GL_FRONT, GL_SHININESS, 96);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) {
|
bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) {
|
||||||
|
@ -2819,7 +2841,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs
|
||||||
|
|
||||||
{
|
{
|
||||||
DependencyManager::get<DeferredLightingEffect>()->setAmbientLightMode(getRenderAmbientLight());
|
DependencyManager::get<DeferredLightingEffect>()->setAmbientLightMode(getRenderAmbientLight());
|
||||||
|
DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(-getSunDirection(), GLOBAL_LIGHT_COLOR, GLOBAL_LIGHT_INTENSITY);
|
||||||
PROFILE_RANGE("DeferredLighting");
|
PROFILE_RANGE("DeferredLighting");
|
||||||
PerformanceTimer perfTimer("lighting");
|
PerformanceTimer perfTimer("lighting");
|
||||||
DependencyManager::get<DeferredLightingEffect>()->render();
|
DependencyManager::get<DeferredLightingEffect>()->render();
|
||||||
|
@ -3457,7 +3479,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance());
|
||||||
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
|
||||||
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
||||||
scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance());
|
scriptEngine->registerGlobalObject("SoundCache", DependencyManager::get<SoundCache>().data());
|
||||||
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance());
|
||||||
scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);
|
scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels);
|
||||||
|
|
||||||
|
@ -3471,6 +3493,10 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
|
|
||||||
scriptEngine->registerGlobalObject("UndoStack", &_undoStackScriptingInterface);
|
scriptEngine->registerGlobalObject("UndoStack", &_undoStackScriptingInterface);
|
||||||
|
|
||||||
|
QScriptValue hmdInterface = scriptEngine->registerGlobalObject("HMD", &HMDScriptingInterface::getInstance());
|
||||||
|
scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition2D", HMDScriptingInterface::getHUDLookAtPosition2D, 0);
|
||||||
|
scriptEngine->registerFunction(hmdInterface, "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0);
|
||||||
|
|
||||||
#ifdef HAVE_RTMIDI
|
#ifdef HAVE_RTMIDI
|
||||||
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
|
scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -411,6 +411,8 @@ private:
|
||||||
void initDisplay();
|
void initDisplay();
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
void cleanupBeforeQuit();
|
||||||
|
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
|
|
||||||
// Various helper functions called during update()
|
// Various helper functions called during update()
|
||||||
|
|
|
@ -129,12 +129,12 @@ void DatagramProcessor::processDatagrams() {
|
||||||
|
|
||||||
if (incomingType == PacketTypeMuteEnvironment) {
|
if (incomingType == PacketTypeMuteEnvironment) {
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
float radius, distance;
|
float radius;
|
||||||
|
|
||||||
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
||||||
memcpy(&position, incomingPacket.constData() + headerSize, sizeof(glm::vec3));
|
memcpy(&position, incomingPacket.constData() + headerSize, sizeof(glm::vec3));
|
||||||
memcpy(&radius, incomingPacket.constData() + headerSize + sizeof(glm::vec3), sizeof(float));
|
memcpy(&radius, incomingPacket.constData() + headerSize + sizeof(glm::vec3), sizeof(float));
|
||||||
distance = glm::distance(DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition(),
|
float distance = glm::distance(DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition(),
|
||||||
position);
|
position);
|
||||||
|
|
||||||
mute = mute && (distance < radius);
|
mute = mute && (distance < radius);
|
||||||
|
|
56
interface/src/scripting/HMDScriptingInterface.cpp
Normal file
56
interface/src/scripting/HMDScriptingInterface.cpp
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
//
|
||||||
|
// HMDScriptingInterface.cpp
|
||||||
|
// interface/src/scripting
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 1/12/15.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "HMDScriptingInterface.h"
|
||||||
|
|
||||||
|
#include <avatar/AvatarManager.h>
|
||||||
|
|
||||||
|
HMDScriptingInterface& HMDScriptingInterface::getInstance() {
|
||||||
|
static HMDScriptingInterface sharedInstance;
|
||||||
|
return sharedInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HMDScriptingInterface::getHUDLookAtPosition3D(glm::vec3& result) const {
|
||||||
|
Camera* camera = Application::getInstance()->getCamera();
|
||||||
|
glm::vec3 position = camera->getPosition();
|
||||||
|
glm::quat orientation = camera->getOrientation();
|
||||||
|
|
||||||
|
glm::vec3 direction = orientation * glm::vec3(0.0f, 0.0f, -1.0f);
|
||||||
|
|
||||||
|
ApplicationOverlay& applicationOverlay = Application::getInstance()->getApplicationOverlay();
|
||||||
|
|
||||||
|
return applicationOverlay.calculateRayUICollisionPoint(position, direction, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue HMDScriptingInterface::getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine) {
|
||||||
|
|
||||||
|
glm::vec3 hudIntersection;
|
||||||
|
|
||||||
|
if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(hudIntersection)) {
|
||||||
|
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
|
glm::vec3 sphereCenter = myAvatar->getDefaultEyePosition();
|
||||||
|
glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * (hudIntersection - sphereCenter);
|
||||||
|
glm::quat rotation = ::rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), direction);
|
||||||
|
glm::vec3 eulers = ::safeEulerAngles(rotation);
|
||||||
|
return qScriptValueFromValue<glm::vec2>(engine, Application::getInstance()->getApplicationOverlay()
|
||||||
|
.sphericalToOverlay(glm::vec2(eulers.y, -eulers.x)));
|
||||||
|
}
|
||||||
|
return QScriptValue::NullValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QScriptValue HMDScriptingInterface::getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine) {
|
||||||
|
glm::vec3 result;
|
||||||
|
HMDScriptingInterface* hmdInterface = &HMDScriptingInterface::getInstance();
|
||||||
|
if ((&HMDScriptingInterface::getInstance())->getHUDLookAtPosition3D(result)) {
|
||||||
|
return qScriptValueFromValue<glm::vec3>(engine, result);
|
||||||
|
}
|
||||||
|
return QScriptValue::NullValue;
|
||||||
|
}
|
42
interface/src/scripting/HMDScriptingInterface.h
Normal file
42
interface/src/scripting/HMDScriptingInterface.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// HMDScriptingInterface.h
|
||||||
|
// interface/src/scripting
|
||||||
|
//
|
||||||
|
// Created by Thijs Wenker on 1/12/15.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef hifi_HMDScriptingInterface_h
|
||||||
|
#define hifi_HMDScriptingInterface_h
|
||||||
|
|
||||||
|
#include <GLMHelpers.h>
|
||||||
|
|
||||||
|
#include "Application.h"
|
||||||
|
#include "devices/OculusManager.h"
|
||||||
|
|
||||||
|
class HMDScriptingInterface : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool magnifier READ getMagnifier)
|
||||||
|
Q_PROPERTY(bool active READ isHMDMode)
|
||||||
|
public:
|
||||||
|
static HMDScriptingInterface& getInstance();
|
||||||
|
|
||||||
|
static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine);
|
||||||
|
static QScriptValue getHUDLookAtPosition3D(QScriptContext* context, QScriptEngine* engine);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void toggleMagnifier() { Application::getInstance()->getApplicationOverlay().toggleMagnifier(); };
|
||||||
|
|
||||||
|
private:
|
||||||
|
HMDScriptingInterface() {};
|
||||||
|
bool getMagnifier() const { return Application::getInstance()->getApplicationOverlay().hasMagnifier(); };
|
||||||
|
bool isHMDMode() const { return Application::getInstance()->isHMDMode(); }
|
||||||
|
|
||||||
|
bool getHUDLookAtPosition3D(glm::vec3& result) const;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_HMDScriptingInterface_h
|
|
@ -139,6 +139,7 @@ ApplicationOverlay::ApplicationOverlay() :
|
||||||
_alpha(1.0f),
|
_alpha(1.0f),
|
||||||
_oculusUIRadius(1.0f),
|
_oculusUIRadius(1.0f),
|
||||||
_crosshairTexture(0),
|
_crosshairTexture(0),
|
||||||
|
_magnifier(true),
|
||||||
_previousBorderWidth(-1),
|
_previousBorderWidth(-1),
|
||||||
_previousBorderHeight(-1),
|
_previousBorderHeight(-1),
|
||||||
_previousMagnifierBottomLeft(),
|
_previousMagnifierBottomLeft(),
|
||||||
|
@ -559,7 +560,7 @@ void ApplicationOverlay::renderPointers() {
|
||||||
|
|
||||||
_reticlePosition[MOUSE] = position;
|
_reticlePosition[MOUSE] = position;
|
||||||
_reticleActive[MOUSE] = true;
|
_reticleActive[MOUSE] = true;
|
||||||
_magActive[MOUSE] = true;
|
_magActive[MOUSE] = _magnifier;
|
||||||
_reticleActive[LEFT_CONTROLLER] = false;
|
_reticleActive[LEFT_CONTROLLER] = false;
|
||||||
_reticleActive[RIGHT_CONTROLLER] = false;
|
_reticleActive[RIGHT_CONTROLLER] = false;
|
||||||
} else if (qApp->getLastMouseMoveWasSimulated() && Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
|
} else if (qApp->getLastMouseMoveWasSimulated() && Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
|
||||||
|
@ -718,6 +719,9 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) {
|
||||||
|
|
||||||
//Renders a small magnification of the currently bound texture at the coordinates
|
//Renders a small magnification of the currently bound texture at the coordinates
|
||||||
void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) {
|
void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) {
|
||||||
|
if (!_magnifier) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto glCanvas = DependencyManager::get<GLCanvas>();
|
auto glCanvas = DependencyManager::get<GLCanvas>();
|
||||||
|
|
||||||
const int widgetWidth = glCanvas->width();
|
const int widgetWidth = glCanvas->width();
|
||||||
|
@ -788,13 +792,12 @@ void ApplicationOverlay::renderAudioMeter() {
|
||||||
|
|
||||||
// Audio VU Meter and Mute Icon
|
// Audio VU Meter and Mute Icon
|
||||||
const int MUTE_ICON_SIZE = 24;
|
const int MUTE_ICON_SIZE = 24;
|
||||||
const int AUDIO_METER_INSET = 2;
|
|
||||||
const int MUTE_ICON_PADDING = 10;
|
const int MUTE_ICON_PADDING = 10;
|
||||||
const int AUDIO_METER_WIDTH = MIRROR_VIEW_WIDTH - MUTE_ICON_SIZE - AUDIO_METER_INSET - MUTE_ICON_PADDING;
|
const int AUDIO_METER_WIDTH = MIRROR_VIEW_WIDTH - MUTE_ICON_SIZE - MUTE_ICON_PADDING;
|
||||||
const int AUDIO_METER_SCALE_WIDTH = AUDIO_METER_WIDTH - 2 * AUDIO_METER_INSET;
|
const int AUDIO_METER_SCALE_WIDTH = AUDIO_METER_WIDTH - 2 ;
|
||||||
const int AUDIO_METER_HEIGHT = 8;
|
const int AUDIO_METER_HEIGHT = 8;
|
||||||
const int AUDIO_METER_GAP = 5;
|
const int AUDIO_METER_GAP = 5;
|
||||||
const int AUDIO_METER_X = MIRROR_VIEW_LEFT_PADDING + MUTE_ICON_SIZE + AUDIO_METER_INSET + AUDIO_METER_GAP;
|
const int AUDIO_METER_X = MIRROR_VIEW_LEFT_PADDING + MUTE_ICON_SIZE + AUDIO_METER_GAP;
|
||||||
|
|
||||||
int audioMeterY;
|
int audioMeterY;
|
||||||
bool smallMirrorVisible = Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && !OculusManager::isConnected();
|
bool smallMirrorVisible = Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && !OculusManager::isConnected();
|
||||||
|
@ -847,7 +850,7 @@ void ApplicationOverlay::renderAudioMeter() {
|
||||||
|
|
||||||
// Draw audio meter background Quad
|
// Draw audio meter background Quad
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT,
|
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT,
|
||||||
glm::vec4(0, 0, 0, 1));
|
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||||
|
|
||||||
if (audioLevel > AUDIO_RED_START) {
|
if (audioLevel > AUDIO_RED_START) {
|
||||||
glm::vec4 quadColor;
|
glm::vec4 quadColor;
|
||||||
|
@ -857,10 +860,10 @@ void ApplicationOverlay::renderAudioMeter() {
|
||||||
quadColor = glm::vec4(1, 1, 1, 1);
|
quadColor = glm::vec4(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
// Draw Red Quad
|
// Draw Red Quad
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START,
|
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_RED_START,
|
||||||
audioMeterY + AUDIO_METER_INSET,
|
audioMeterY,
|
||||||
audioLevel - AUDIO_RED_START,
|
audioLevel - AUDIO_RED_START,
|
||||||
AUDIO_METER_HEIGHT - AUDIO_METER_INSET, quadColor,
|
AUDIO_METER_HEIGHT, quadColor,
|
||||||
_audioRedQuad);
|
_audioRedQuad);
|
||||||
|
|
||||||
audioLevel = AUDIO_RED_START;
|
audioLevel = AUDIO_RED_START;
|
||||||
|
@ -874,15 +877,16 @@ void ApplicationOverlay::renderAudioMeter() {
|
||||||
quadColor = glm::vec4(1, 1, 1, 1);
|
quadColor = glm::vec4(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
// Draw Green Quad
|
// Draw Green Quad
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START,
|
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_GREEN_START,
|
||||||
audioMeterY + AUDIO_METER_INSET,
|
audioMeterY,
|
||||||
audioLevel - AUDIO_GREEN_START,
|
audioLevel - AUDIO_GREEN_START,
|
||||||
AUDIO_METER_HEIGHT - AUDIO_METER_INSET, quadColor,
|
AUDIO_METER_HEIGHT, quadColor,
|
||||||
_audioGreenQuad);
|
_audioGreenQuad);
|
||||||
|
|
||||||
audioLevel = AUDIO_GREEN_START;
|
audioLevel = AUDIO_GREEN_START;
|
||||||
}
|
}
|
||||||
// Draw Blue Quad
|
|
||||||
|
if (audioLevel >= 0) {
|
||||||
glm::vec4 quadColor;
|
glm::vec4 quadColor;
|
||||||
if (!isClipping) {
|
if (!isClipping) {
|
||||||
quadColor = AUDIO_METER_BLUE;
|
quadColor = AUDIO_METER_BLUE;
|
||||||
|
@ -890,10 +894,11 @@ void ApplicationOverlay::renderAudioMeter() {
|
||||||
quadColor = glm::vec4(1, 1, 1, 1);
|
quadColor = glm::vec4(1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
// Draw Blue (low level) quad
|
// Draw Blue (low level) quad
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET,
|
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X,
|
||||||
audioMeterY + AUDIO_METER_INSET,
|
audioMeterY,
|
||||||
audioLevel, AUDIO_METER_HEIGHT - AUDIO_METER_INSET, quadColor,
|
audioLevel, AUDIO_METER_HEIGHT, quadColor,
|
||||||
_audioBlueQuad);
|
_audioBlueQuad);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationOverlay::renderStatsAndLogs() {
|
void ApplicationOverlay::renderStatsAndLogs() {
|
||||||
|
|
|
@ -37,6 +37,9 @@ public:
|
||||||
QPoint getPalmClickLocation(const PalmData *palm) const;
|
QPoint getPalmClickLocation(const PalmData *palm) const;
|
||||||
bool calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const;
|
bool calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const;
|
||||||
|
|
||||||
|
bool hasMagnifier() const { return _magnifier; }
|
||||||
|
void toggleMagnifier() { _magnifier = !_magnifier; }
|
||||||
|
|
||||||
float getOculusUIAngularSize() const { return _oculusUIAngularSize; }
|
float getOculusUIAngularSize() const { return _oculusUIAngularSize; }
|
||||||
void setOculusUIAngularSize(float oculusUIAngularSize) { _oculusUIAngularSize = oculusUIAngularSize; }
|
void setOculusUIAngularSize(float oculusUIAngularSize) { _oculusUIAngularSize = oculusUIAngularSize; }
|
||||||
|
|
||||||
|
@ -109,6 +112,7 @@ private:
|
||||||
bool _magActive[NUMBER_OF_RETICLES];
|
bool _magActive[NUMBER_OF_RETICLES];
|
||||||
float _magSizeMult[NUMBER_OF_RETICLES];
|
float _magSizeMult[NUMBER_OF_RETICLES];
|
||||||
quint64 _lastMouseMove;
|
quint64 _lastMouseMove;
|
||||||
|
bool _magnifier;
|
||||||
|
|
||||||
float _alpha;
|
float _alpha;
|
||||||
float _oculusUIRadius;
|
float _oculusUIRadius;
|
||||||
|
|
|
@ -59,8 +59,8 @@ CachesSizeDialog::CachesSizeDialog(QWidget* parent) :
|
||||||
void CachesSizeDialog::confirmClicked(bool checked) {
|
void CachesSizeDialog::confirmClicked(bool checked) {
|
||||||
DependencyManager::get<AnimationCache>()->setUnusedResourceCacheSize(_animations->value() * BYTES_PER_MEGABYTES);
|
DependencyManager::get<AnimationCache>()->setUnusedResourceCacheSize(_animations->value() * BYTES_PER_MEGABYTES);
|
||||||
DependencyManager::get<GeometryCache>()->setUnusedResourceCacheSize(_geometries->value() * BYTES_PER_MEGABYTES);
|
DependencyManager::get<GeometryCache>()->setUnusedResourceCacheSize(_geometries->value() * BYTES_PER_MEGABYTES);
|
||||||
ScriptCache::getInstance()->setUnusedResourceCacheSize(_scripts->value() * BYTES_PER_MEGABYTES);
|
DependencyManager::get<ScriptCache>()->setUnusedResourceCacheSize(_scripts->value() * BYTES_PER_MEGABYTES);
|
||||||
SoundCache::getInstance().setUnusedResourceCacheSize(_sounds->value() * BYTES_PER_MEGABYTES);
|
DependencyManager::get<SoundCache>()->setUnusedResourceCacheSize(_sounds->value() * BYTES_PER_MEGABYTES);
|
||||||
DependencyManager::get<TextureCache>()->setUnusedResourceCacheSize(_textures->value() * BYTES_PER_MEGABYTES);
|
DependencyManager::get<TextureCache>()->setUnusedResourceCacheSize(_textures->value() * BYTES_PER_MEGABYTES);
|
||||||
|
|
||||||
QDialog::close();
|
QDialog::close();
|
||||||
|
@ -69,8 +69,8 @@ void CachesSizeDialog::confirmClicked(bool checked) {
|
||||||
void CachesSizeDialog::resetClicked(bool checked) {
|
void CachesSizeDialog::resetClicked(bool checked) {
|
||||||
_animations->setValue(DependencyManager::get<AnimationCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
_animations->setValue(DependencyManager::get<AnimationCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
||||||
_geometries->setValue(DependencyManager::get<GeometryCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
_geometries->setValue(DependencyManager::get<GeometryCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
||||||
_scripts->setValue(ScriptCache::getInstance()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
_scripts->setValue(DependencyManager::get<ScriptCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
||||||
_sounds->setValue(SoundCache::getInstance().getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
_sounds->setValue(DependencyManager::get<SoundCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
||||||
_textures->setValue(DependencyManager::get<TextureCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
_textures->setValue(DependencyManager::get<TextureCache>()->getUnusedResourceCacheSize() / BYTES_PER_MEGABYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,9 @@ LoginDialog::LoginDialog(QWidget* parent) :
|
||||||
this, &LoginDialog::handleLoginClicked);
|
this, &LoginDialog::handleLoginClicked);
|
||||||
connect(_ui->closeButton, &QPushButton::clicked,
|
connect(_ui->closeButton, &QPushButton::clicked,
|
||||||
this, &LoginDialog::close);
|
this, &LoginDialog::close);
|
||||||
|
|
||||||
|
// Initialize toggle connection
|
||||||
|
toggleQAction();
|
||||||
};
|
};
|
||||||
|
|
||||||
LoginDialog::~LoginDialog() {
|
LoginDialog::~LoginDialog() {
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
#include "Line3DOverlay.h"
|
#include "Line3DOverlay.h"
|
||||||
|
|
||||||
|
|
||||||
Line3DOverlay::Line3DOverlay() {
|
Line3DOverlay::Line3DOverlay() :
|
||||||
|
_geometryCacheID(DependencyManager::get<GeometryCache>()->allocateID())
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Line3DOverlay::Line3DOverlay(const Line3DOverlay* line3DOverlay) :
|
Line3DOverlay::Line3DOverlay(const Line3DOverlay* line3DOverlay) :
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
|
|
||||||
#include "Rectangle3DOverlay.h"
|
#include "Rectangle3DOverlay.h"
|
||||||
|
|
||||||
Rectangle3DOverlay::Rectangle3DOverlay() {
|
Rectangle3DOverlay::Rectangle3DOverlay() :
|
||||||
|
_geometryCacheID(DependencyManager::get<GeometryCache>()->allocateID())
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle3DOverlay::Rectangle3DOverlay(const Rectangle3DOverlay* rectangle3DOverlay) :
|
Rectangle3DOverlay::Rectangle3DOverlay(const Rectangle3DOverlay* rectangle3DOverlay) :
|
||||||
|
|
|
@ -141,6 +141,8 @@ AudioClient::AudioClient() :
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioClient::~AudioClient() {
|
AudioClient::~AudioClient() {
|
||||||
|
stop();
|
||||||
|
|
||||||
if (_gverbLocal) {
|
if (_gverbLocal) {
|
||||||
gverb_free(_gverbLocal);
|
gverb_free(_gverbLocal);
|
||||||
}
|
}
|
||||||
|
@ -494,7 +496,6 @@ void AudioClient::start() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioClient::stop() {
|
void AudioClient::stop() {
|
||||||
|
|
||||||
_inputFrameBuffer.finalize();
|
_inputFrameBuffer.finalize();
|
||||||
_inputGain.finalize();
|
_inputGain.finalize();
|
||||||
_sourceGain.finalize();
|
_sourceGain.finalize();
|
||||||
|
@ -892,13 +893,14 @@ void AudioClient::processReceivedSamples(const QByteArray& inputBuffer, QByteArr
|
||||||
|
|
||||||
void AudioClient::sendMuteEnvironmentPacket() {
|
void AudioClient::sendMuteEnvironmentPacket() {
|
||||||
QByteArray mutePacket = byteArrayWithPopulatedHeader(PacketTypeMuteEnvironment);
|
QByteArray mutePacket = byteArrayWithPopulatedHeader(PacketTypeMuteEnvironment);
|
||||||
QDataStream mutePacketStream(&mutePacket, QIODevice::Append);
|
int headerSize = mutePacket.size();
|
||||||
|
|
||||||
const float MUTE_RADIUS = 50;
|
const float MUTE_RADIUS = 50;
|
||||||
|
|
||||||
glm::vec3 currentSourcePosition = _positionGetter();
|
glm::vec3 currentSourcePosition = _positionGetter();
|
||||||
mutePacketStream.writeBytes(reinterpret_cast<const char *>(¤tSourcePosition), sizeof(glm::vec3));
|
mutePacket.resize(mutePacket.size() + sizeof(glm::vec3) + sizeof(float));
|
||||||
mutePacketStream.writeBytes(reinterpret_cast<const char *>(&MUTE_RADIUS), sizeof(float));
|
memcpy(mutePacket.data() + headerSize, ¤tSourcePosition, sizeof(glm::vec3));
|
||||||
|
memcpy(mutePacket.data() + headerSize + sizeof(glm::vec3), &MUTE_RADIUS, sizeof(float));
|
||||||
|
|
||||||
// grab our audio mixer from the NodeList, if it exists
|
// grab our audio mixer from the NodeList, if it exists
|
||||||
auto nodelist = DependencyManager::get<NodeList>();
|
auto nodelist = DependencyManager::get<NodeList>();
|
||||||
|
|
|
@ -186,6 +186,10 @@ protected:
|
||||||
AudioClient();
|
AudioClient();
|
||||||
~AudioClient();
|
~AudioClient();
|
||||||
|
|
||||||
|
virtual void customDeleter() {
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void outputFormatChanged();
|
void outputFormatChanged();
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,6 @@
|
||||||
|
|
||||||
static int soundPointerMetaTypeId = qRegisterMetaType<SharedSoundPointer>();
|
static int soundPointerMetaTypeId = qRegisterMetaType<SharedSoundPointer>();
|
||||||
|
|
||||||
SoundCache& SoundCache::getInstance() {
|
|
||||||
static SoundCache staticInstance;
|
|
||||||
return staticInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
SoundCache::SoundCache(QObject* parent) :
|
SoundCache::SoundCache(QObject* parent) :
|
||||||
ResourceCache(parent)
|
ResourceCache(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
|
|
||||||
/// Scriptable interface for sound loading.
|
/// Scriptable interface for sound loading.
|
||||||
class SoundCache : public ResourceCache {
|
class SoundCache : public ResourceCache, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
SINGLETON_DEPENDENCY
|
||||||
static SoundCache& getInstance();
|
|
||||||
|
|
||||||
|
public:
|
||||||
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
|
Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -194,6 +194,7 @@ public:
|
||||||
bool containsBoundsProperties() const { return (_positionChanged || _dimensionsChanged); }
|
bool containsBoundsProperties() const { return (_positionChanged || _dimensionsChanged); }
|
||||||
bool containsPositionChange() const { return _positionChanged; }
|
bool containsPositionChange() const { return _positionChanged; }
|
||||||
bool containsDimensionsChange() const { return _dimensionsChanged; }
|
bool containsDimensionsChange() const { return _dimensionsChanged; }
|
||||||
|
bool containsAnimationSettingsChange() const { return _animationSettingsChanged; }
|
||||||
|
|
||||||
float getGlowLevel() const { return _glowLevel; }
|
float getGlowLevel() const { return _glowLevel; }
|
||||||
float getLocalRenderAlpha() const { return _localRenderAlpha; }
|
float getLocalRenderAlpha() const { return _localRenderAlpha; }
|
||||||
|
@ -256,12 +257,57 @@ inline void EntityItemProperties::setPosition(const glm::vec3& value)
|
||||||
|
|
||||||
|
|
||||||
inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) {
|
inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) {
|
||||||
debug << "EntityItemProperties[" << "\n"
|
debug << "EntityItemProperties[" << "\n";
|
||||||
<< " position:" << properties.getPosition() << "in meters" << "\n"
|
|
||||||
<< " velocity:" << properties.getVelocity() << "in meters" << "\n"
|
// TODO: figure out why position and animationSettings don't seem to like the macro approach
|
||||||
<< " last edited:" << properties.getLastEdited() << "\n"
|
if (properties.containsPositionChange()) {
|
||||||
<< " edited ago:" << properties.getEditedAgo() << "\n"
|
debug << " position:" << properties.getPosition() << "in meters" << "\n";
|
||||||
<< "]";
|
}
|
||||||
|
if (properties.containsAnimationSettingsChange()) {
|
||||||
|
debug << " animationSettings:" << properties.getAnimationSettings() << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Dimensions, dimensions, "in meters");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Velocity, velocity, "in meters");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Visible, visible, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Rotation, rotation, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Density, density, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Gravity, gravity, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Damping, damping, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Lifetime, lifetime, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Script, script, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Color, color, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ModelURL, modelURL, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationURL, animationURL, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationFPS, animationFPS, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationFrameIndex, animationFrameIndex, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AnimationIsPlaying, animationIsPlaying, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, RegistrationPoint, registrationPoint, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AngularVelocity, angularVelocity, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AngularDamping, angularDamping, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, IgnoreForCollisions, ignoreForCollisions, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, CollisionsWillMove, collisionsWillMove, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, IsSpotlight, isSpotlight, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, DiffuseColor, diffuseColor, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, AmbientColor, ambientColor, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, SpecularColor, specularColor, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ConstantAttenuation, constantAttenuation, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, LinearAttenuation, linearAttenuation, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, QuadraticAttenuation, quadraticAttenuation, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Exponent, exponent, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Cutoff, cutoff, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Locked, locked, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Textures, textures, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, UserData, userData, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, Text, text, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, LineHeight, lineHeight, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, TextColor, textColor, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, BackgroundColor, backgroundColor, "");
|
||||||
|
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ShapeType, shapeType, "");
|
||||||
|
|
||||||
|
debug << " last edited:" << properties.getLastEdited() << "\n";
|
||||||
|
debug << " edited ago:" << properties.getEditedAgo() << "\n";
|
||||||
|
debug << "]";
|
||||||
|
|
||||||
return debug;
|
return debug;
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,6 +321,10 @@
|
||||||
T _##n; \
|
T _##n; \
|
||||||
bool _##n##Changed;
|
bool _##n##Changed;
|
||||||
|
|
||||||
|
#define DEBUG_PROPERTY_IF_CHANGED(D, P, N, n, x) \
|
||||||
|
if (P.n##Changed()) { \
|
||||||
|
D << " " << #n << ":" << P.get##N() << x << "\n"; \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_EntityItemPropertiesMacros_h
|
#endif // hifi_EntityItemPropertiesMacros_h
|
||||||
|
|
|
@ -592,6 +592,10 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char
|
||||||
|
|
||||||
// if the EntityItem exists, then update it
|
// if the EntityItem exists, then update it
|
||||||
if (existingEntity) {
|
if (existingEntity) {
|
||||||
|
if (wantEditLogging()) {
|
||||||
|
qDebug() << "User [" << senderNode->getUUID() << "] editing entity. ID:" << entityItemID;
|
||||||
|
qDebug() << " properties:" << properties;
|
||||||
|
}
|
||||||
updateEntity(entityItemID, properties, senderNode->getCanAdjustLocks());
|
updateEntity(entityItemID, properties, senderNode->getCanAdjustLocks());
|
||||||
existingEntity->markAsChangedOnServer();
|
existingEntity->markAsChangedOnServer();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -152,6 +152,9 @@ public:
|
||||||
|
|
||||||
void setSimulation(EntitySimulation* simulation);
|
void setSimulation(EntitySimulation* simulation);
|
||||||
|
|
||||||
|
bool wantEditLogging() const { return _wantEditLogging; }
|
||||||
|
void setWantEditLogging(bool value) { _wantEditLogging = value; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void deletingEntity(const EntityItemID& entityID);
|
void deletingEntity(const EntityItemID& entityID);
|
||||||
void addingEntity(const EntityItemID& entityID);
|
void addingEntity(const EntityItemID& entityID);
|
||||||
|
@ -180,6 +183,8 @@ private:
|
||||||
QHash<EntityItemID, EntityTreeElement*> _entityToElementMap;
|
QHash<EntityItemID, EntityTreeElement*> _entityToElementMap;
|
||||||
|
|
||||||
EntitySimulation* _simulation;
|
EntitySimulation* _simulation;
|
||||||
|
|
||||||
|
bool _wantEditLogging = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_EntityTree_h
|
#endif // hifi_EntityTree_h
|
||||||
|
|
|
@ -163,16 +163,6 @@ void ModelEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit
|
||||||
|
|
||||||
QMap<QString, AnimationPointer> ModelEntityItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s)
|
QMap<QString, AnimationPointer> ModelEntityItem::_loadedAnimations; // TODO: improve cleanup by leveraging the AnimationPointer(s)
|
||||||
|
|
||||||
// This class/instance will cleanup the animations once unloaded.
|
|
||||||
class EntityAnimationsBookkeeper {
|
|
||||||
public:
|
|
||||||
~EntityAnimationsBookkeeper() {
|
|
||||||
ModelEntityItem::cleanupLoadedAnimations();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
EntityAnimationsBookkeeper modelAnimationsBookkeeperInstance;
|
|
||||||
|
|
||||||
void ModelEntityItem::cleanupLoadedAnimations() {
|
void ModelEntityItem::cleanupLoadedAnimations() {
|
||||||
foreach(AnimationPointer animation, _loadedAnimations) {
|
foreach(AnimationPointer animation, _loadedAnimations) {
|
||||||
animation.clear();
|
animation.clear();
|
||||||
|
|
|
@ -1127,7 +1127,7 @@ FBXTexture getTexture(const QString& textureID,
|
||||||
texture.transform.setTranslation(p.translation);
|
texture.transform.setTranslation(p.translation);
|
||||||
texture.transform.setRotation(glm::quat(glm::radians(p.rotation)));
|
texture.transform.setRotation(glm::quat(glm::radians(p.rotation)));
|
||||||
texture.transform.setScale(p.scaling);
|
texture.transform.setScale(p.scaling);
|
||||||
if ((p.UVSet != "map1") || (p.UVSet != "UVSet0")) {
|
if ((p.UVSet != "map1") && (p.UVSet != "UVSet0")) {
|
||||||
texture.texcoordSet = 1;
|
texture.texcoordSet = 1;
|
||||||
}
|
}
|
||||||
texture.texcoordSetName = p.UVSet;
|
texture.texcoordSetName = p.UVSet;
|
||||||
|
@ -1556,6 +1556,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping,
|
||||||
if (property.name == propertyName) {
|
if (property.name == propertyName) {
|
||||||
QString v = property.properties.at(0).toString();
|
QString v = property.properties.at(0).toString();
|
||||||
if (property.properties.at(0) == "UVSet") {
|
if (property.properties.at(0) == "UVSet") {
|
||||||
|
std::string uvName = property.properties.at(index).toString().toStdString();
|
||||||
tex.assign(tex.UVSet, property.properties.at(index).toString());
|
tex.assign(tex.UVSet, property.properties.at(index).toString());
|
||||||
} else if (property.properties.at(0) == "CurrentTextureBlendMode") {
|
} else if (property.properties.at(0) == "CurrentTextureBlendMode") {
|
||||||
tex.assign<uint8_t>(tex.currentTextureBlendMode, property.properties.at(index).value<int>());
|
tex.assign<uint8_t>(tex.currentTextureBlendMode, property.properties.at(index).value<int>());
|
||||||
|
|
|
@ -85,8 +85,11 @@ bool Texture::Storage::allocateMip(uint16 level) {
|
||||||
bool Texture::Storage::assignMipData(uint16 level, const Element& format, Size size, const Byte* bytes) {
|
bool Texture::Storage::assignMipData(uint16 level, const Element& format, Size size, const Byte* bytes) {
|
||||||
// Ok we should be able to do that...
|
// Ok we should be able to do that...
|
||||||
allocateMip(level);
|
allocateMip(level);
|
||||||
_mips[level]->_format = format;
|
auto mip = _mips[level];
|
||||||
Size allocated = _mips[level]->_sysmem.setData(size, bytes);
|
mip->_format = format;
|
||||||
|
Size allocated = mip->_sysmem.setData(size, bytes);
|
||||||
|
mip->_isGPULoaded = false;
|
||||||
|
|
||||||
return allocated == size;
|
return allocated == size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -465,9 +465,9 @@ void Bitstream::writeRawDelta(const QScriptValue& value, const QScriptValue& ref
|
||||||
} else if (reference.isArray()) {
|
} else if (reference.isArray()) {
|
||||||
if (value.isArray()) {
|
if (value.isArray()) {
|
||||||
*this << false;
|
*this << false;
|
||||||
int length = value.property(ScriptCache::getInstance()->getLengthString()).toInt32();
|
int length = value.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
|
||||||
*this << length;
|
*this << length;
|
||||||
int referenceLength = reference.property(ScriptCache::getInstance()->getLengthString()).toInt32();
|
int referenceLength = reference.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
if (i < referenceLength) {
|
if (i < referenceLength) {
|
||||||
writeDelta(value.property(i), reference.property(i));
|
writeDelta(value.property(i), reference.property(i));
|
||||||
|
@ -555,7 +555,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
|
||||||
} else {
|
} else {
|
||||||
QVariant variant;
|
QVariant variant;
|
||||||
readRawDelta(variant, reference.toVariant());
|
readRawDelta(variant, reference.toVariant());
|
||||||
value = ScriptCache::getInstance()->getEngine()->newVariant(variant);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newVariant(variant);
|
||||||
}
|
}
|
||||||
} else if (reference.isQObject()) {
|
} else if (reference.isQObject()) {
|
||||||
bool typeChanged;
|
bool typeChanged;
|
||||||
|
@ -566,7 +566,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
|
||||||
} else {
|
} else {
|
||||||
QObject* object;
|
QObject* object;
|
||||||
readRawDelta(object, reference.toQObject());
|
readRawDelta(object, reference.toQObject());
|
||||||
value = ScriptCache::getInstance()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
|
||||||
}
|
}
|
||||||
} else if (reference.isQMetaObject()) {
|
} else if (reference.isQMetaObject()) {
|
||||||
bool typeChanged;
|
bool typeChanged;
|
||||||
|
@ -577,7 +577,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
|
||||||
} else {
|
} else {
|
||||||
const QMetaObject* metaObject;
|
const QMetaObject* metaObject;
|
||||||
*this >> metaObject;
|
*this >> metaObject;
|
||||||
value = ScriptCache::getInstance()->getEngine()->newQMetaObject(metaObject);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newQMetaObject(metaObject);
|
||||||
}
|
}
|
||||||
} else if (reference.isDate()) {
|
} else if (reference.isDate()) {
|
||||||
bool typeChanged;
|
bool typeChanged;
|
||||||
|
@ -588,7 +588,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
|
||||||
} else {
|
} else {
|
||||||
QDateTime dateTime;
|
QDateTime dateTime;
|
||||||
*this >> dateTime;
|
*this >> dateTime;
|
||||||
value = ScriptCache::getInstance()->getEngine()->newDate(dateTime);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newDate(dateTime);
|
||||||
}
|
}
|
||||||
} else if (reference.isRegExp()) {
|
} else if (reference.isRegExp()) {
|
||||||
bool typeChanged;
|
bool typeChanged;
|
||||||
|
@ -599,7 +599,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
|
||||||
} else {
|
} else {
|
||||||
QRegExp regExp;
|
QRegExp regExp;
|
||||||
*this >> regExp;
|
*this >> regExp;
|
||||||
value = ScriptCache::getInstance()->getEngine()->newRegExp(regExp);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newRegExp(regExp);
|
||||||
}
|
}
|
||||||
} else if (reference.isArray()) {
|
} else if (reference.isArray()) {
|
||||||
bool typeChanged;
|
bool typeChanged;
|
||||||
|
@ -610,8 +610,8 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
|
||||||
} else {
|
} else {
|
||||||
int length;
|
int length;
|
||||||
*this >> length;
|
*this >> length;
|
||||||
value = ScriptCache::getInstance()->getEngine()->newArray(length);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(length);
|
||||||
int referenceLength = reference.property(ScriptCache::getInstance()->getLengthString()).toInt32();
|
int referenceLength = reference.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
QScriptValue element;
|
QScriptValue element;
|
||||||
if (i < referenceLength) {
|
if (i < referenceLength) {
|
||||||
|
@ -630,7 +630,7 @@ void Bitstream::readRawDelta(QScriptValue& value, const QScriptValue& reference)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// start by shallow-copying the reference
|
// start by shallow-copying the reference
|
||||||
value = ScriptCache::getInstance()->getEngine()->newObject();
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
|
||||||
for (QScriptValueIterator it(reference); it.hasNext(); ) {
|
for (QScriptValueIterator it(reference); it.hasNext(); ) {
|
||||||
it.next();
|
it.next();
|
||||||
value.setProperty(it.scriptName(), it.value());
|
value.setProperty(it.scriptName(), it.value());
|
||||||
|
@ -1036,7 +1036,7 @@ Bitstream& Bitstream::operator<<(const QScriptValue& value) {
|
||||||
|
|
||||||
} else if (value.isArray()) {
|
} else if (value.isArray()) {
|
||||||
writeScriptValueType(*this, ARRAY_SCRIPT_VALUE);
|
writeScriptValueType(*this, ARRAY_SCRIPT_VALUE);
|
||||||
int length = value.property(ScriptCache::getInstance()->getLengthString()).toInt32();
|
int length = value.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
|
||||||
*this << length;
|
*this << length;
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
*this << value.property(i);
|
*this << value.property(i);
|
||||||
|
@ -1087,37 +1087,37 @@ Bitstream& Bitstream::operator>>(QScriptValue& value) {
|
||||||
case VARIANT_SCRIPT_VALUE: {
|
case VARIANT_SCRIPT_VALUE: {
|
||||||
QVariant variantValue;
|
QVariant variantValue;
|
||||||
*this >> variantValue;
|
*this >> variantValue;
|
||||||
value = ScriptCache::getInstance()->getEngine()->newVariant(variantValue);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newVariant(variantValue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QOBJECT_SCRIPT_VALUE: {
|
case QOBJECT_SCRIPT_VALUE: {
|
||||||
QObject* object;
|
QObject* object;
|
||||||
*this >> object;
|
*this >> object;
|
||||||
ScriptCache::getInstance()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
|
DependencyManager::get<ScriptCache>()->getEngine()->newQObject(object, QScriptEngine::ScriptOwnership);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QMETAOBJECT_SCRIPT_VALUE: {
|
case QMETAOBJECT_SCRIPT_VALUE: {
|
||||||
const QMetaObject* metaObject;
|
const QMetaObject* metaObject;
|
||||||
*this >> metaObject;
|
*this >> metaObject;
|
||||||
ScriptCache::getInstance()->getEngine()->newQMetaObject(metaObject);
|
DependencyManager::get<ScriptCache>()->getEngine()->newQMetaObject(metaObject);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DATE_SCRIPT_VALUE: {
|
case DATE_SCRIPT_VALUE: {
|
||||||
QDateTime dateTime;
|
QDateTime dateTime;
|
||||||
*this >> dateTime;
|
*this >> dateTime;
|
||||||
value = ScriptCache::getInstance()->getEngine()->newDate(dateTime);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newDate(dateTime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case REGEXP_SCRIPT_VALUE: {
|
case REGEXP_SCRIPT_VALUE: {
|
||||||
QRegExp regExp;
|
QRegExp regExp;
|
||||||
*this >> regExp;
|
*this >> regExp;
|
||||||
value = ScriptCache::getInstance()->getEngine()->newRegExp(regExp);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newRegExp(regExp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ARRAY_SCRIPT_VALUE: {
|
case ARRAY_SCRIPT_VALUE: {
|
||||||
int length;
|
int length;
|
||||||
*this >> length;
|
*this >> length;
|
||||||
value = ScriptCache::getInstance()->getEngine()->newArray(length);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(length);
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
QScriptValue element;
|
QScriptValue element;
|
||||||
*this >> element;
|
*this >> element;
|
||||||
|
@ -1126,7 +1126,7 @@ Bitstream& Bitstream::operator>>(QScriptValue& value) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case OBJECT_SCRIPT_VALUE: {
|
case OBJECT_SCRIPT_VALUE: {
|
||||||
value = ScriptCache::getInstance()->getEngine()->newObject();
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
|
||||||
forever {
|
forever {
|
||||||
QScriptString name;
|
QScriptString name;
|
||||||
*this >> name;
|
*this >> name;
|
||||||
|
@ -1477,7 +1477,7 @@ Bitstream& Bitstream::operator>(QScriptString& string) {
|
||||||
QString rawString;
|
QString rawString;
|
||||||
*this >> rawString;
|
*this >> rawString;
|
||||||
string = (rawString == INVALID_STRING) ? QScriptString() :
|
string = (rawString == INVALID_STRING) ? QScriptString() :
|
||||||
ScriptCache::getInstance()->getEngine()->toStringHandle(rawString);
|
DependencyManager::get<ScriptCache>()->getEngine()->toStringHandle(rawString);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1828,7 +1828,7 @@ QJsonValue JSONWriter::getData(const QScriptValue& value) {
|
||||||
} else if (value.isArray()) {
|
} else if (value.isArray()) {
|
||||||
object.insert("type", QString("ARRAY"));
|
object.insert("type", QString("ARRAY"));
|
||||||
QJsonArray array;
|
QJsonArray array;
|
||||||
int length = value.property(ScriptCache::getInstance()->getLengthString()).toInt32();
|
int length = value.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
array.append(getData(value.property(i)));
|
array.append(getData(value.property(i)));
|
||||||
}
|
}
|
||||||
|
@ -2209,31 +2209,31 @@ void JSONReader::putData(const QJsonValue& data, QScriptValue& value) {
|
||||||
} else if (type == "VARIANT") {
|
} else if (type == "VARIANT") {
|
||||||
QVariant variant;
|
QVariant variant;
|
||||||
putData(object.value("value"), variant);
|
putData(object.value("value"), variant);
|
||||||
value = ScriptCache::getInstance()->getEngine()->newVariant(variant);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newVariant(variant);
|
||||||
|
|
||||||
} else if (type == "QOBJECT") {
|
} else if (type == "QOBJECT") {
|
||||||
QObject* qObject;
|
QObject* qObject;
|
||||||
putData(object.value("value"), qObject);
|
putData(object.value("value"), qObject);
|
||||||
value = ScriptCache::getInstance()->getEngine()->newQObject(qObject, QScriptEngine::ScriptOwnership);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newQObject(qObject, QScriptEngine::ScriptOwnership);
|
||||||
|
|
||||||
} else if (type == "QMETAOBJECT") {
|
} else if (type == "QMETAOBJECT") {
|
||||||
const QMetaObject* metaObject;
|
const QMetaObject* metaObject;
|
||||||
putData(object.value("value"), metaObject);
|
putData(object.value("value"), metaObject);
|
||||||
value = ScriptCache::getInstance()->getEngine()->newQMetaObject(metaObject);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newQMetaObject(metaObject);
|
||||||
|
|
||||||
} else if (type == "DATE") {
|
} else if (type == "DATE") {
|
||||||
QDateTime dateTime;
|
QDateTime dateTime;
|
||||||
putData(object.value("value"), dateTime);
|
putData(object.value("value"), dateTime);
|
||||||
value = ScriptCache::getInstance()->getEngine()->newDate(dateTime);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newDate(dateTime);
|
||||||
|
|
||||||
} else if (type == "REGEXP") {
|
} else if (type == "REGEXP") {
|
||||||
QRegExp regExp;
|
QRegExp regExp;
|
||||||
putData(object.value("value"), regExp);
|
putData(object.value("value"), regExp);
|
||||||
value = ScriptCache::getInstance()->getEngine()->newRegExp(regExp);
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newRegExp(regExp);
|
||||||
|
|
||||||
} else if (type == "ARRAY") {
|
} else if (type == "ARRAY") {
|
||||||
QJsonArray array = object.value("value").toArray();
|
QJsonArray array = object.value("value").toArray();
|
||||||
value = ScriptCache::getInstance()->getEngine()->newArray(array.size());
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(array.size());
|
||||||
for (int i = 0; i < array.size(); i++) {
|
for (int i = 0; i < array.size(); i++) {
|
||||||
QScriptValue element;
|
QScriptValue element;
|
||||||
putData(array.at(i), element);
|
putData(array.at(i), element);
|
||||||
|
@ -2241,7 +2241,7 @@ void JSONReader::putData(const QJsonValue& data, QScriptValue& value) {
|
||||||
}
|
}
|
||||||
} else if (type == "OBJECT") {
|
} else if (type == "OBJECT") {
|
||||||
QJsonObject jsonObject = object.value("value").toObject();
|
QJsonObject jsonObject = object.value("value").toObject();
|
||||||
value = ScriptCache::getInstance()->getEngine()->newObject();
|
value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
|
||||||
for (QJsonObject::const_iterator it = jsonObject.constBegin(); it != jsonObject.constEnd(); it++) {
|
for (QJsonObject::const_iterator it = jsonObject.constBegin(); it != jsonObject.constEnd(); it++) {
|
||||||
QScriptValue element;
|
QScriptValue element;
|
||||||
putData(it.value(), element);
|
putData(it.value(), element);
|
||||||
|
|
|
@ -663,7 +663,7 @@ void ParameterizedURLEditor::updateURL() {
|
||||||
QByteArray valuePropertyName = widget->property("valuePropertyName").toByteArray();
|
QByteArray valuePropertyName = widget->property("valuePropertyName").toByteArray();
|
||||||
const QMetaObject* widgetMetaObject = widget->metaObject();
|
const QMetaObject* widgetMetaObject = widget->metaObject();
|
||||||
QMetaProperty widgetProperty = widgetMetaObject->property(widgetMetaObject->indexOfProperty(valuePropertyName));
|
QMetaProperty widgetProperty = widgetMetaObject->property(widgetMetaObject->indexOfProperty(valuePropertyName));
|
||||||
parameters.insert(ScriptCache::getInstance()->getEngine()->toStringHandle(
|
parameters.insert(DependencyManager::get<ScriptCache>()->getEngine()->toStringHandle(
|
||||||
widget->property("parameterName").toString()), widgetProperty.read(widget));
|
widget->property("parameterName").toString()), widgetProperty.read(widget));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -677,7 +677,7 @@ void ParameterizedURLEditor::updateParameters() {
|
||||||
if (_program) {
|
if (_program) {
|
||||||
_program->disconnect(this);
|
_program->disconnect(this);
|
||||||
}
|
}
|
||||||
_program = ScriptCache::getInstance()->getProgram(_url.getURL());
|
_program = DependencyManager::get<ScriptCache>()->getProgram(_url.getURL());
|
||||||
if (_program->isLoaded()) {
|
if (_program->isLoaded()) {
|
||||||
continueUpdatingParameters();
|
continueUpdatingParameters();
|
||||||
} else {
|
} else {
|
||||||
|
@ -698,7 +698,7 @@ void ParameterizedURLEditor::continueUpdatingParameters() {
|
||||||
}
|
}
|
||||||
delete form;
|
delete form;
|
||||||
}
|
}
|
||||||
QSharedPointer<NetworkValue> value = ScriptCache::getInstance()->getValue(_url.getURL());
|
QSharedPointer<NetworkValue> value = DependencyManager::get<ScriptCache>()->getValue(_url.getURL());
|
||||||
const QList<ParameterInfo>& parameters = static_cast<RootNetworkValue*>(value.data())->getParameterInfo();
|
const QList<ParameterInfo>& parameters = static_cast<RootNetworkValue*>(value.data())->getParameterInfo();
|
||||||
if (parameters.isEmpty()) {
|
if (parameters.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -57,8 +57,8 @@ bool operator==(const QScriptValue& first, const QScriptValue& second) {
|
||||||
if (!second.isArray()) {
|
if (!second.isArray()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int length = first.property(ScriptCache::getInstance()->getLengthString()).toInt32();
|
int length = first.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
|
||||||
if (second.property(ScriptCache::getInstance()->getLengthString()).toInt32() != length) {
|
if (second.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32() != length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
|
@ -103,11 +103,6 @@ bool operator<(const QScriptValue& first, const QScriptValue& second) {
|
||||||
return first.lessThan(second);
|
return first.lessThan(second);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptCache* ScriptCache::getInstance() {
|
|
||||||
static ScriptCache cache;
|
|
||||||
return &cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptCache::ScriptCache() :
|
ScriptCache::ScriptCache() :
|
||||||
_engine(NULL)
|
_engine(NULL)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,13 +25,11 @@ class NetworkProgram;
|
||||||
class NetworkValue;
|
class NetworkValue;
|
||||||
|
|
||||||
/// Maintains a cache of loaded scripts.
|
/// Maintains a cache of loaded scripts.
|
||||||
class ScriptCache : public ResourceCache {
|
class ScriptCache : public ResourceCache, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
SINGLETON_DEPENDENCY
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static ScriptCache* getInstance();
|
|
||||||
|
|
||||||
ScriptCache();
|
ScriptCache();
|
||||||
|
|
||||||
void setEngine(QScriptEngine* engine);
|
void setEngine(QScriptEngine* engine);
|
||||||
|
|
|
@ -23,6 +23,7 @@ typedef gpu::BufferView::Index Index;
|
||||||
typedef gpu::BufferView BufferView;
|
typedef gpu::BufferView BufferView;
|
||||||
typedef AABox Box;
|
typedef AABox Box;
|
||||||
typedef std::vector< Box > Boxes;
|
typedef std::vector< Box > Boxes;
|
||||||
|
typedef glm::vec3 Vec3;
|
||||||
|
|
||||||
class Mesh {
|
class Mesh {
|
||||||
public:
|
public:
|
||||||
|
@ -35,7 +36,7 @@ public:
|
||||||
typedef gpu::Stream::Format VertexFormat;
|
typedef gpu::Stream::Format VertexFormat;
|
||||||
typedef std::map< Slot, BufferView > BufferViewMap;
|
typedef std::map< Slot, BufferView > BufferViewMap;
|
||||||
|
|
||||||
typedef glm::vec3 Vec3;
|
typedef model::Vec3 Vec3;
|
||||||
|
|
||||||
Mesh();
|
Mesh();
|
||||||
Mesh(const Mesh& mesh);
|
Mesh(const Mesh& mesh);
|
||||||
|
|
97
libraries/model/src/model/Light.cpp
Executable file
97
libraries/model/src/model/Light.cpp
Executable file
|
@ -0,0 +1,97 @@
|
||||||
|
//
|
||||||
|
// Light.cpp
|
||||||
|
// libraries/model/src/model
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 1/26/2014.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
#include "Light.h"
|
||||||
|
|
||||||
|
using namespace model;
|
||||||
|
|
||||||
|
Light::Light() :
|
||||||
|
_flags(0),
|
||||||
|
_schemaBuffer(),
|
||||||
|
_transform() {
|
||||||
|
// only if created from nothing shall we create the Buffer to store the properties
|
||||||
|
Schema schema;
|
||||||
|
_schemaBuffer = gpu::BufferView(new gpu::Buffer(sizeof(Schema), (const gpu::Buffer::Byte*) &schema));
|
||||||
|
}
|
||||||
|
|
||||||
|
Light::Light(const Light& light) :
|
||||||
|
_flags(light._flags),
|
||||||
|
_schemaBuffer(light._schemaBuffer),
|
||||||
|
_transform(light._transform) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Light& Light::operator= (const Light& light) {
|
||||||
|
_flags = (light._flags);
|
||||||
|
_schemaBuffer = (light._schemaBuffer);
|
||||||
|
_transform = (light._transform);
|
||||||
|
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Light::~Light() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setPosition(const Vec3& position) {
|
||||||
|
_transform.setTranslation(position);
|
||||||
|
editSchema()._position = Vec4(position, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setOrientation(const glm::quat& orientation) {
|
||||||
|
_transform.setRotation(orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setDirection(const Vec3& direction) {
|
||||||
|
editSchema()._direction = glm::normalize(direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vec3& Light::getDirection() const {
|
||||||
|
return getSchema()._direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setColor(const Color& color) {
|
||||||
|
editSchema()._color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setIntensity(float intensity) {
|
||||||
|
editSchema()._intensity = intensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setMaximumRadius(float radius) {
|
||||||
|
if (radius <= 0.f) {
|
||||||
|
radius = 1.0f;
|
||||||
|
}
|
||||||
|
float CutOffIntensityRatio = 0.05f;
|
||||||
|
float surfaceRadius = radius / (sqrt(1.0f / CutOffIntensityRatio) - 1.f);
|
||||||
|
editSchema()._attenuation = Vec4(surfaceRadius, 1.0f/surfaceRadius, CutOffIntensityRatio, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setSpotAngle(float angle) {
|
||||||
|
if (angle <= 0.f) {
|
||||||
|
angle = 0.0f;
|
||||||
|
}
|
||||||
|
float cosAngle = cos(angle);
|
||||||
|
editSchema()._spot.x = cos(angle);
|
||||||
|
editSchema()._spot.y = sin(angle);
|
||||||
|
editSchema()._spot.z = angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setSpotExponent(float exponent) {
|
||||||
|
if (exponent <= 0.f) {
|
||||||
|
exponent = 1.0f;
|
||||||
|
}
|
||||||
|
editSchema()._spot.w = exponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Light::setShowContour(float show) {
|
||||||
|
if (show <= 0.f) {
|
||||||
|
show = 0.0f;
|
||||||
|
}
|
||||||
|
editSchema()._control.w = show;
|
||||||
|
}
|
294
libraries/model/src/model/Light.h
Executable file
294
libraries/model/src/model/Light.h
Executable file
|
@ -0,0 +1,294 @@
|
||||||
|
//
|
||||||
|
// Light.h
|
||||||
|
// libraries/model/src/model
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 12/10/2014.
|
||||||
|
// Copyright 2014 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
#ifndef hifi_model_Light_h
|
||||||
|
#define hifi_model_Light_h
|
||||||
|
|
||||||
|
#include <bitset>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include "Transform.h"
|
||||||
|
#include "gpu/Resource.h"
|
||||||
|
#include "gpu/Texture.h"
|
||||||
|
|
||||||
|
namespace model {
|
||||||
|
typedef gpu::BufferView UniformBufferView;
|
||||||
|
typedef gpu::TextureView TextureView;
|
||||||
|
typedef glm::vec3 Vec3;
|
||||||
|
typedef glm::vec4 Vec4;
|
||||||
|
typedef glm::quat Quat;
|
||||||
|
|
||||||
|
class SphericalHarmonics {
|
||||||
|
public:
|
||||||
|
glm::vec3 L00 ; float spare0;
|
||||||
|
glm::vec3 L1m1 ; float spare1;
|
||||||
|
glm::vec3 L10 ; float spare2;
|
||||||
|
glm::vec3 L11 ; float spare3;
|
||||||
|
glm::vec3 L2m2 ; float spare4;
|
||||||
|
glm::vec3 L2m1 ; float spare5;
|
||||||
|
glm::vec3 L20 ; float spare6;
|
||||||
|
glm::vec3 L21 ; float spare7;
|
||||||
|
glm::vec3 L22 ; float spare8;
|
||||||
|
|
||||||
|
static const int NUM_COEFFICIENTS = 9;
|
||||||
|
|
||||||
|
enum Preset {
|
||||||
|
OLD_TOWN_SQUARE = 0,
|
||||||
|
GRACE_CATHEDRAL,
|
||||||
|
EUCALYPTUS_GROVE,
|
||||||
|
ST_PETERS_BASILICA,
|
||||||
|
UFFIZI_GALLERY,
|
||||||
|
GALILEOS_TOMB,
|
||||||
|
VINE_STREET_KITCHEN,
|
||||||
|
BREEZEWAY,
|
||||||
|
CAMPUS_SUNSET,
|
||||||
|
FUNSTON_BEACH_SUNSET,
|
||||||
|
|
||||||
|
NUM_PRESET,
|
||||||
|
};
|
||||||
|
|
||||||
|
void assignPreset(int p) {
|
||||||
|
switch (p) {
|
||||||
|
case OLD_TOWN_SQUARE: {
|
||||||
|
L00 = glm::vec3( 0.871297f, 0.875222f, 0.864470f);
|
||||||
|
L1m1 = glm::vec3( 0.175058f, 0.245335f, 0.312891f);
|
||||||
|
L10 = glm::vec3( 0.034675f, 0.036107f, 0.037362f);
|
||||||
|
L11 = glm::vec3(-0.004629f,-0.029448f,-0.048028f);
|
||||||
|
L2m2 = glm::vec3(-0.120535f,-0.121160f,-0.117507f);
|
||||||
|
L2m1 = glm::vec3( 0.003242f, 0.003624f, 0.007511f);
|
||||||
|
L20 = glm::vec3(-0.028667f,-0.024926f,-0.020998f);
|
||||||
|
L21 = glm::vec3(-0.077539f,-0.086325f,-0.091591f);
|
||||||
|
L22 = glm::vec3(-0.161784f,-0.191783f,-0.219152f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GRACE_CATHEDRAL: {
|
||||||
|
L00 = glm::vec3( 0.79f, 0.44f, 0.54f);
|
||||||
|
L1m1 = glm::vec3( 0.39f, 0.35f, 0.60f);
|
||||||
|
L10 = glm::vec3(-0.34f, -0.18f, -0.27f);
|
||||||
|
L11 = glm::vec3(-0.29f, -0.06f, 0.01f);
|
||||||
|
L2m2 = glm::vec3(-0.11f, -0.05f, -0.12f);
|
||||||
|
L2m1 = glm::vec3(-0.26f, -0.22f, -0.47f);
|
||||||
|
L20 = glm::vec3(-0.16f, -0.09f, -0.15f);
|
||||||
|
L21 = glm::vec3( 0.56f, 0.21f, 0.14f);
|
||||||
|
L22 = glm::vec3( 0.21f, -0.05f, -0.30f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case EUCALYPTUS_GROVE: {
|
||||||
|
L00 = glm::vec3( 0.38f, 0.43f, 0.45f);
|
||||||
|
L1m1 = glm::vec3( 0.29f, 0.36f, 0.41f);
|
||||||
|
L10 = glm::vec3( 0.04f, 0.03f, 0.01f);
|
||||||
|
L11 = glm::vec3(-0.10f, -0.10f, -0.09f);
|
||||||
|
L2m2 = glm::vec3(-0.06f, -0.06f, -0.04f);
|
||||||
|
L2m1 = glm::vec3( 0.01f, -0.01f, -0.05f);
|
||||||
|
L20 = glm::vec3(-0.09f, -0.13f, -0.15f);
|
||||||
|
L21 = glm::vec3(-0.06f, -0.05f, -0.04f);
|
||||||
|
L22 = glm::vec3( 0.02f, 0.00f, -0.05f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ST_PETERS_BASILICA: {
|
||||||
|
L00 = glm::vec3( 0.36f, 0.26f, 0.23f);
|
||||||
|
L1m1 = glm::vec3( 0.18f, 0.14f, 0.13f);
|
||||||
|
L10 = glm::vec3(-0.02f, -0.01f, 0.00f);
|
||||||
|
L11 = glm::vec3( 0.03f, 0.02f, -0.00f);
|
||||||
|
L2m2 = glm::vec3( 0.02f, 0.01f, -0.00f);
|
||||||
|
L2m1 = glm::vec3(-0.05f, -0.03f, -0.01f);
|
||||||
|
L20 = glm::vec3(-0.09f, -0.08f, -0.07f);
|
||||||
|
L21 = glm::vec3( 0.01f, 0.00f, 0.00f);
|
||||||
|
L22 = glm::vec3(-0.08f, -0.03f, -0.00f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case UFFIZI_GALLERY: {
|
||||||
|
L00 = glm::vec3( 0.32f, 0.31f, 0.35f);
|
||||||
|
L1m1 = glm::vec3( 0.37f, 0.37f, 0.43f);
|
||||||
|
L10 = glm::vec3( 0.00f, 0.00f, 0.00f);
|
||||||
|
L11 = glm::vec3(-0.01f, -0.01f, -0.01f);
|
||||||
|
L2m2 = glm::vec3(-0.02f, -0.02f, -0.03f);
|
||||||
|
L2m1 = glm::vec3(-0.01f, -0.01f, -0.01f);
|
||||||
|
L20 = glm::vec3(-0.28f, -0.28f, -0.32f);
|
||||||
|
L21 = glm::vec3( 0.00f, 0.00f, 0.00f);
|
||||||
|
L22 = glm::vec3(-0.24f, -0.24f, -0.28f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GALILEOS_TOMB: {
|
||||||
|
L00 = glm::vec3( 1.04f, 0.76f, 0.71f);
|
||||||
|
L1m1 = glm::vec3( 0.44f, 0.34f, 0.34f);
|
||||||
|
L10 = glm::vec3(-0.22f, -0.18f, -0.17f);
|
||||||
|
L11 = glm::vec3( 0.71f, 0.54f, 0.56f);
|
||||||
|
L2m2 = glm::vec3( 0.64f, 0.50f, 0.52f);
|
||||||
|
L2m1 = glm::vec3(-0.12f, -0.09f, -0.08f);
|
||||||
|
L20 = glm::vec3(-0.37f, -0.28f, -0.32f);
|
||||||
|
L21 = glm::vec3(-0.17f, -0.13f, -0.13f);
|
||||||
|
L22 = glm::vec3( 0.55f, 0.42f, 0.42f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case VINE_STREET_KITCHEN: {
|
||||||
|
L00 = glm::vec3( 0.64f, 0.67f, 0.73f);
|
||||||
|
L1m1 = glm::vec3( 0.28f, 0.32f, 0.33f);
|
||||||
|
L10 = glm::vec3( 0.42f, 0.60f, 0.77f);
|
||||||
|
L11 = glm::vec3(-0.05f, -0.04f, -0.02f);
|
||||||
|
L2m2 = glm::vec3(-0.10f, -0.08f, -0.05f);
|
||||||
|
L2m1 = glm::vec3( 0.25f, 0.39f, 0.53f);
|
||||||
|
L20 = glm::vec3( 0.38f, 0.54f, 0.71f);
|
||||||
|
L21 = glm::vec3( 0.06f, 0.01f, -0.02f);
|
||||||
|
L22 = glm::vec3(-0.03f, -0.02f, -0.03f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BREEZEWAY: {
|
||||||
|
L00 = glm::vec3( 0.32f, 0.36f, 0.38f);
|
||||||
|
L1m1 = glm::vec3( 0.37f, 0.41f, 0.45f);
|
||||||
|
L10 = glm::vec3(-0.01f, -0.01f, -0.01f);
|
||||||
|
L11 = glm::vec3(-0.10f, -0.12f, -0.12f);
|
||||||
|
L2m2 = glm::vec3(-0.13f, -0.15f, -0.17f);
|
||||||
|
L2m1 = glm::vec3(-0.01f, -0.02f, 0.02f);
|
||||||
|
L20 = glm::vec3(-0.07f, -0.08f, -0.09f);
|
||||||
|
L21 = glm::vec3( 0.02f, 0.03f, 0.03f);
|
||||||
|
L22 = glm::vec3(-0.29f, -0.32f, -0.36f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CAMPUS_SUNSET: {
|
||||||
|
L00 = glm::vec3( 0.79f, 0.94f, 0.98f);
|
||||||
|
L1m1 = glm::vec3( 0.44f, 0.56f, 0.70f);
|
||||||
|
L10 = glm::vec3(-0.10f, -0.18f, -0.27f);
|
||||||
|
L11 = glm::vec3( 0.45f, 0.38f, 0.20f);
|
||||||
|
L2m2 = glm::vec3( 0.18f, 0.14f, 0.05f);
|
||||||
|
L2m1 = glm::vec3(-0.14f, -0.22f, -0.31f);
|
||||||
|
L20 = glm::vec3(-0.39f, -0.40f, -0.36f);
|
||||||
|
L21 = glm::vec3( 0.09f, 0.07f, 0.04f);
|
||||||
|
L22 = glm::vec3( 0.67f, 0.67f, 0.52f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FUNSTON_BEACH_SUNSET: {
|
||||||
|
L00 = glm::vec3( 0.68f, 0.69f, 0.70f);
|
||||||
|
L1m1 = glm::vec3( 0.32f, 0.37f, 0.44f);
|
||||||
|
L10 = glm::vec3(-0.17f, -0.17f, -0.17f);
|
||||||
|
L11 = glm::vec3(-0.45f, -0.42f, -0.34f);
|
||||||
|
L2m2 = glm::vec3(-0.17f, -0.17f, -0.15f);
|
||||||
|
L2m1 = glm::vec3(-0.08f, -0.09f, -0.10f);
|
||||||
|
L20 = glm::vec3(-0.03f, -0.02f, -0.01f);
|
||||||
|
L21 = glm::vec3( 0.16f, 0.14f, 0.10f);
|
||||||
|
L22 = glm::vec3( 0.37f, 0.31f, 0.20f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Light {
|
||||||
|
public:
|
||||||
|
enum Type {
|
||||||
|
SUN = 0,
|
||||||
|
POINT,
|
||||||
|
SPOT,
|
||||||
|
|
||||||
|
NUM_TYPES,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Vec3 Color;
|
||||||
|
|
||||||
|
enum FlagBit {
|
||||||
|
COLOR_BIT = 0,
|
||||||
|
INTENSITY_BIT,
|
||||||
|
RANGE_BIT,
|
||||||
|
SPOT_BIT,
|
||||||
|
TRANSFORM_BIT,
|
||||||
|
|
||||||
|
NUM_FLAGS,
|
||||||
|
};
|
||||||
|
typedef std::bitset<NUM_FLAGS> Flags;
|
||||||
|
|
||||||
|
Light();
|
||||||
|
Light(const Light& light);
|
||||||
|
Light& operator= (const Light& light);
|
||||||
|
virtual ~Light();
|
||||||
|
|
||||||
|
void setType(Type type) { editSchema()._control.x = float(type); }
|
||||||
|
Type getType() const { return Type((int) getSchema()._control.x); }
|
||||||
|
|
||||||
|
void setPosition(const Vec3& position);
|
||||||
|
const Vec3& getPosition() const { return _transform.getTranslation(); }
|
||||||
|
|
||||||
|
void setDirection(const Vec3& direction);
|
||||||
|
const Vec3& getDirection() const;
|
||||||
|
|
||||||
|
void setOrientation(const Quat& orientation);
|
||||||
|
const glm::quat& getOrientation() const { return _transform.getRotation(); }
|
||||||
|
|
||||||
|
const Color& getColor() const { return getSchema()._color; }
|
||||||
|
void setColor(const Color& color);
|
||||||
|
|
||||||
|
float getIntensity() const { return getSchema()._intensity; }
|
||||||
|
void setIntensity(float intensity);
|
||||||
|
|
||||||
|
bool isRanged() const { return (getType() == POINT) || (getType() == SPOT ); }
|
||||||
|
|
||||||
|
void setMaximumRadius(float radius);
|
||||||
|
float getMaximumRadius() const { return getSchema()._attenuation.w; }
|
||||||
|
|
||||||
|
// Spot properties
|
||||||
|
bool isSpot() const { return getType() == SPOT; }
|
||||||
|
void setSpotAngle(float angle);
|
||||||
|
float getSpotAngle() const { return getSchema()._spot.z; }
|
||||||
|
void setSpotExponent(float exponent);
|
||||||
|
float getSpotExponent() const { return getSchema()._spot.w; }
|
||||||
|
|
||||||
|
// For editing purpose, show the light volume contour.
|
||||||
|
// Set to non 0 to show it, the value is used as the intensity of the contour color
|
||||||
|
void setShowContour(float show);
|
||||||
|
float getShowContour() const { return getSchema()._control.w; }
|
||||||
|
|
||||||
|
// Spherical Harmonics storing the Ambien lighting approximation used for the Sun typed light
|
||||||
|
void setAmbientSphere(const SphericalHarmonics& sphere) { _ambientSphere = sphere; }
|
||||||
|
const SphericalHarmonics& getAmbientSphere() const { return _ambientSphere; }
|
||||||
|
void setAmbientSpherePreset(SphericalHarmonics::Preset preset) { _ambientSphere.assignPreset(preset); }
|
||||||
|
|
||||||
|
// Schema to access the attribute values of the light
|
||||||
|
class Schema {
|
||||||
|
public:
|
||||||
|
Vec4 _position;
|
||||||
|
Vec3 _direction;
|
||||||
|
float _spare0;
|
||||||
|
Color _color;
|
||||||
|
float _intensity;
|
||||||
|
Vec4 _attenuation;
|
||||||
|
Vec4 _spot;
|
||||||
|
Vec4 _shadow;
|
||||||
|
|
||||||
|
Vec4 _control;
|
||||||
|
|
||||||
|
Schema() :
|
||||||
|
_position(0.0f, 0.0f, 0.0f, 1.0f),
|
||||||
|
_direction(0.0f, 0.0f, -1.0f),
|
||||||
|
_spare0(0.f),
|
||||||
|
_color(1.0f),
|
||||||
|
_intensity(1.0f),
|
||||||
|
_attenuation(1.0f, 1.0f, 1.0f, 1.0f),
|
||||||
|
_spot(0.0f, 0.0f, 0.0f, 3.0f),
|
||||||
|
_control(0.0f)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
const UniformBufferView& getSchemaBuffer() const { return _schemaBuffer; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Flags _flags;
|
||||||
|
UniformBufferView _schemaBuffer;
|
||||||
|
Transform _transform;
|
||||||
|
SphericalHarmonics _ambientSphere;
|
||||||
|
|
||||||
|
const Schema& getSchema() const { return _schemaBuffer.get<Schema>(); }
|
||||||
|
Schema& editSchema() { return _schemaBuffer.edit<Schema>(); }
|
||||||
|
};
|
||||||
|
typedef QSharedPointer< Light > LightPointer;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -100,7 +100,6 @@ public:
|
||||||
void setTextureView(MapChannel channel, const TextureView& texture);
|
void setTextureView(MapChannel channel, const TextureView& texture);
|
||||||
const TextureMap& getTextureMap() const { return _textureMap; }
|
const TextureMap& getTextureMap() const { return _textureMap; }
|
||||||
|
|
||||||
const Schema* getSchema() const { return &_schemaBuffer.get<Schema>(); }
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Flags _flags;
|
Flags _flags;
|
||||||
|
|
|
@ -39,6 +39,7 @@ const char SOLO_NODE_TYPES[2] = {
|
||||||
const QUrl DEFAULT_NODE_AUTH_URL = QUrl("https://metaverse.highfidelity.io");
|
const QUrl DEFAULT_NODE_AUTH_URL = QUrl("https://metaverse.highfidelity.io");
|
||||||
|
|
||||||
LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short dtlsListenPort) :
|
LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short dtlsListenPort) :
|
||||||
|
linkedDataCreateCallback(NULL),
|
||||||
_sessionUUID(),
|
_sessionUUID(),
|
||||||
_nodeHash(),
|
_nodeHash(),
|
||||||
_nodeMutex(QReadWriteLock::Recursive),
|
_nodeMutex(QReadWriteLock::Recursive),
|
||||||
|
|
|
@ -86,17 +86,9 @@ void UserActivityLogger::launch(QString applicationVersion) {
|
||||||
logAction(ACTION_NAME, actionDetails);
|
logAction(ACTION_NAME, actionDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserActivityLogger::close(int delayTime) {
|
void UserActivityLogger::close() {
|
||||||
const QString ACTION_NAME = "close";
|
const QString ACTION_NAME = "close";
|
||||||
|
|
||||||
// In order to get the end of the session, we need to give the account manager enough time to send the packet.
|
|
||||||
QEventLoop loop;
|
|
||||||
QTimer timer;
|
|
||||||
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
|
||||||
// Now we can log it
|
|
||||||
logAction(ACTION_NAME, QJsonObject());
|
logAction(ACTION_NAME, QJsonObject());
|
||||||
timer.start(delayTime);
|
|
||||||
loop.exec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserActivityLogger::changedDisplayName(QString displayName) {
|
void UserActivityLogger::changedDisplayName(QString displayName) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ public slots:
|
||||||
void logAction(QString action, QJsonObject details = QJsonObject(), JSONCallbackParameters params = JSONCallbackParameters());
|
void logAction(QString action, QJsonObject details = QJsonObject(), JSONCallbackParameters params = JSONCallbackParameters());
|
||||||
|
|
||||||
void launch(QString applicationVersion);
|
void launch(QString applicationVersion);
|
||||||
void close(int delayTime);
|
void close();
|
||||||
void changedDisplayName(QString displayName);
|
void changedDisplayName(QString displayName);
|
||||||
void changedModel(QString typeOfModel, QString modelURL);
|
void changedModel(QString typeOfModel, QString modelURL);
|
||||||
void changedDomain(QString domainURL);
|
void changedDomain(QString domainURL);
|
||||||
|
|
|
@ -49,14 +49,32 @@ void OctreePersistThread::parseSettings(const QJsonObject& settings) {
|
||||||
qDebug() << "BACKUP RULES:";
|
qDebug() << "BACKUP RULES:";
|
||||||
|
|
||||||
foreach (const QJsonValue& value, backupRules) {
|
foreach (const QJsonValue& value, backupRules) {
|
||||||
|
|
||||||
QJsonObject obj = value.toObject();
|
QJsonObject obj = value.toObject();
|
||||||
|
|
||||||
|
int interval = 0;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
QJsonValue intervalVal = obj["backupInterval"];
|
||||||
|
if (intervalVal.isString()) {
|
||||||
|
interval = intervalVal.toString().toInt();
|
||||||
|
} else {
|
||||||
|
interval = intervalVal.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonValue countVal = obj["maxBackupVersions"];
|
||||||
|
if (countVal.isString()) {
|
||||||
|
count = countVal.toString().toInt();
|
||||||
|
} else {
|
||||||
|
count = countVal.toInt();
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << " Name:" << obj["Name"].toString();
|
qDebug() << " Name:" << obj["Name"].toString();
|
||||||
qDebug() << " format:" << obj["format"].toString();
|
qDebug() << " format:" << obj["format"].toString();
|
||||||
qDebug() << " interval:" << obj["backupInterval"].toInt();
|
qDebug() << " interval:" << interval;
|
||||||
qDebug() << " count:" << obj["maxBackupVersions"].toInt();
|
qDebug() << " count:" << count;
|
||||||
|
|
||||||
BackupRule newRule = { obj["Name"].toString(), obj["backupInterval"].toInt(),
|
BackupRule newRule = { obj["Name"].toString(), interval, obj["format"].toString(), count, 0};
|
||||||
obj["format"].toString(), obj["maxBackupVersions"].toInt(), 0};
|
|
||||||
|
|
||||||
newRule.lastBackup = getMostRecentBackupTimeInUsecs(obj["format"].toString());
|
newRule.lastBackup = getMostRecentBackupTimeInUsecs(obj["format"].toString());
|
||||||
|
|
||||||
|
@ -213,7 +231,9 @@ void OctreePersistThread::persist() {
|
||||||
}
|
}
|
||||||
_tree->unlock();
|
_tree->unlock();
|
||||||
|
|
||||||
|
qDebug() << "persist operation calling backup...";
|
||||||
backup(); // handle backup if requested
|
backup(); // handle backup if requested
|
||||||
|
qDebug() << "persist operation DONE with backup...";
|
||||||
|
|
||||||
|
|
||||||
// create our "lock" file to indicate we're saving.
|
// create our "lock" file to indicate we're saving.
|
||||||
|
@ -319,6 +339,7 @@ bool OctreePersistThread::getMostRecentBackup(const QString& format,
|
||||||
void OctreePersistThread::rollOldBackupVersions(const BackupRule& rule) {
|
void OctreePersistThread::rollOldBackupVersions(const BackupRule& rule) {
|
||||||
|
|
||||||
if (rule.extensionFormat.contains("%N")) {
|
if (rule.extensionFormat.contains("%N")) {
|
||||||
|
if (rule.maxBackupVersions > 0) {
|
||||||
qDebug() << "Rolling old backup versions for rule" << rule.name << "...";
|
qDebug() << "Rolling old backup versions for rule" << rule.name << "...";
|
||||||
for(int n = rule.maxBackupVersions - 1; n > 0; n--) {
|
for(int n = rule.maxBackupVersions - 1; n > 0; n--) {
|
||||||
QString backupExtensionN = rule.extensionFormat;
|
QString backupExtensionN = rule.extensionFormat;
|
||||||
|
@ -342,11 +363,17 @@ void OctreePersistThread::rollOldBackupVersions(const BackupRule& rule) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug() << "Done rolling old backup versions...";
|
qDebug() << "Done rolling old backup versions...";
|
||||||
|
} else {
|
||||||
|
qDebug() << "Rolling backups for rule" << rule.name << "."
|
||||||
|
<< " Max Rolled Backup Versions less than 1 [" << rule.maxBackupVersions << "]."
|
||||||
|
<< " No need to roll backups...";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OctreePersistThread::backup() {
|
void OctreePersistThread::backup() {
|
||||||
|
qDebug() << "backup operation wantBackup:" << _wantBackup;
|
||||||
if (_wantBackup) {
|
if (_wantBackup) {
|
||||||
quint64 now = usecTimestampNow();
|
quint64 now = usecTimestampNow();
|
||||||
|
|
||||||
|
@ -354,10 +381,12 @@ void OctreePersistThread::backup() {
|
||||||
BackupRule& rule = _backupRules[i];
|
BackupRule& rule = _backupRules[i];
|
||||||
|
|
||||||
quint64 sinceLastBackup = now - rule.lastBackup;
|
quint64 sinceLastBackup = now - rule.lastBackup;
|
||||||
|
|
||||||
quint64 SECS_TO_USECS = 1000 * 1000;
|
quint64 SECS_TO_USECS = 1000 * 1000;
|
||||||
quint64 intervalToBackup = rule.interval * SECS_TO_USECS;
|
quint64 intervalToBackup = rule.interval * SECS_TO_USECS;
|
||||||
|
|
||||||
|
qDebug() << "Checking [" << rule.name << "] - Time since last backup [" << sinceLastBackup << "] " <<
|
||||||
|
"compared to backup interval [" << intervalToBackup << "]...";
|
||||||
|
|
||||||
if (sinceLastBackup > intervalToBackup) {
|
if (sinceLastBackup > intervalToBackup) {
|
||||||
qDebug() << "Time since last backup [" << sinceLastBackup << "] for rule [" << rule.name
|
qDebug() << "Time since last backup [" << sinceLastBackup << "] for rule [" << rule.name
|
||||||
<< "] exceeds backup interval [" << intervalToBackup << "] doing backup now...";
|
<< "] exceeds backup interval [" << intervalToBackup << "] doing backup now...";
|
||||||
|
@ -379,15 +408,28 @@ void OctreePersistThread::backup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (rule.maxBackupVersions > 0) {
|
||||||
|
QFile persistFile(_filename);
|
||||||
|
if (persistFile.exists()) {
|
||||||
qDebug() << "backing up persist file " << _filename << "to" << backupFileName << "...";
|
qDebug() << "backing up persist file " << _filename << "to" << backupFileName << "...";
|
||||||
bool result = QFile::copy(_filename, backupFileName);
|
bool result = QFile::copy(_filename, backupFileName);
|
||||||
if (result) {
|
if (result) {
|
||||||
qDebug() << "DONE backing up persist file...";
|
qDebug() << "DONE backing up persist file...";
|
||||||
|
rule.lastBackup = now; // only record successful backup in this case.
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "ERROR in backing up persist file...";
|
qDebug() << "ERROR in backing up persist file...";
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
rule.lastBackup = now;
|
qDebug() << "persist file " << _filename << " does not exist. " <<
|
||||||
|
"nothing to backup for this rule ["<< rule.name << "]...";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "This backup rule" << rule.name
|
||||||
|
<< " has Max Rolled Backup Versions less than 1 [" << rule.maxBackupVersions << "]."
|
||||||
|
<< " There are no backups to be done...";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "Backup not needed for this rule ["<< rule.name << "]...";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
117
libraries/render-utils/src/DeferredGlobalLight.slh
Executable file
117
libraries/render-utils/src/DeferredGlobalLight.slh
Executable file
|
@ -0,0 +1,117 @@
|
||||||
|
<!
|
||||||
|
// DeferredGlobalLight.slh
|
||||||
|
// libraries/render-utils/src
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 2/5/15.
|
||||||
|
// Copyright 2013 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
!>
|
||||||
|
<@if not DEFERRED_GLOBAL_LIGHT_SLH@>
|
||||||
|
<@def DEFERRED_GLOBAL_LIGHT_SLH@>
|
||||||
|
|
||||||
|
<@include DeferredLighting.slh@>
|
||||||
|
|
||||||
|
struct SphericalHarmonics {
|
||||||
|
vec4 L00;
|
||||||
|
vec4 L1m1;
|
||||||
|
vec4 L10;
|
||||||
|
vec4 L11;
|
||||||
|
vec4 L2m2;
|
||||||
|
vec4 L2m1;
|
||||||
|
vec4 L20;
|
||||||
|
vec4 L21;
|
||||||
|
vec4 L22;
|
||||||
|
};
|
||||||
|
|
||||||
|
vec4 evalSphericalLight(SphericalHarmonics sh, vec3 direction ) {
|
||||||
|
|
||||||
|
const float C1 = 0.429043;
|
||||||
|
const float C2 = 0.511664;
|
||||||
|
const float C3 = 0.743125;
|
||||||
|
const float C4 = 0.886227;
|
||||||
|
const float C5 = 0.247708;
|
||||||
|
|
||||||
|
vec4 value = C1 * sh.L22 * (direction.x * direction.x - direction.y * direction.y) +
|
||||||
|
C3 * sh.L20 * direction.z * direction.z +
|
||||||
|
C4 * sh.L00 - C5 * sh.L20 +
|
||||||
|
2.0 * C1 * ( sh.L2m2 * direction.x * direction.y +
|
||||||
|
sh.L21 * direction.x * direction.z +
|
||||||
|
sh.L2m1 * direction.y * direction.z ) +
|
||||||
|
2.0 * C2 * ( sh.L11 * direction.x +
|
||||||
|
sh.L1m1 * direction.y +
|
||||||
|
sh.L10 * direction.z ) ;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Need one SH
|
||||||
|
uniform SphericalHarmonics ambientSphere;
|
||||||
|
|
||||||
|
// Everything about light
|
||||||
|
<@include Light.slh@>
|
||||||
|
|
||||||
|
// The view Matrix
|
||||||
|
uniform mat4 invViewMat;
|
||||||
|
|
||||||
|
vec3 evalAmbienGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss) {
|
||||||
|
|
||||||
|
// Need the light now
|
||||||
|
Light light = getLight();
|
||||||
|
|
||||||
|
vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0));
|
||||||
|
vec4 fragEyeVector = invViewMat * vec4(-position, 0.0);
|
||||||
|
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
||||||
|
|
||||||
|
vec3 color = diffuse.rgb * getLightColor(light) * 0.5;
|
||||||
|
|
||||||
|
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss);
|
||||||
|
|
||||||
|
color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
vec3 evalAmbienSphereGlobalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss) {
|
||||||
|
// Need the light now
|
||||||
|
Light light = getLight();
|
||||||
|
|
||||||
|
vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0));
|
||||||
|
vec4 fragEyeVector = invViewMat * vec4(-position, 0.0);
|
||||||
|
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
||||||
|
|
||||||
|
// TODO: The world space normal doesn;t seem to work properly with the current SH definitions
|
||||||
|
// FoOr now, we use the normal in view space
|
||||||
|
vec3 ambientNormal = normal;
|
||||||
|
|
||||||
|
vec3 color = diffuse.rgb * 0.5 * evalSphericalLight(ambientSphere, ambientNormal).xyz;
|
||||||
|
|
||||||
|
vec4 shading = evalFragShading(fragNormal, -getLightDirection(light), fragEyeDir, specular, gloss);
|
||||||
|
|
||||||
|
color += vec3(diffuse + shading.rgb) * shading.w * shadowAttenuation * getLightColor(light) * getLightIntensity(light);
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) {
|
||||||
|
|
||||||
|
Light light = getLight();
|
||||||
|
float diffuseDot = dot(normal, getLightDirection(light));
|
||||||
|
|
||||||
|
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
||||||
|
// it should be just 0, but we have innacurracy so we need to overshoot
|
||||||
|
const float PERPENDICULAR_THRESHOLD = -0.005;
|
||||||
|
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot);
|
||||||
|
|
||||||
|
// evaluate the shadow test but only relevant for light facing fragments
|
||||||
|
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
||||||
|
|
||||||
|
// diffuse light is the lightmap dimmed by shadow
|
||||||
|
vec3 diffuseLight = lightAttenuation * lightmap;
|
||||||
|
|
||||||
|
// ambient is a tiny percentage of the lightmap and only when in the shadow
|
||||||
|
vec3 ambientLight = (1 - lightAttenuation) * 0.5 * lightmap;
|
||||||
|
|
||||||
|
return diffuse * (ambientLight + diffuseLight);
|
||||||
|
}
|
||||||
|
|
||||||
|
<@endif@>
|
|
@ -11,86 +11,51 @@
|
||||||
<@if not DEFERRED_LIGHTING_SLH@>
|
<@if not DEFERRED_LIGHTING_SLH@>
|
||||||
<@def DEFERRED_LIGHTING_SLH@>
|
<@def DEFERRED_LIGHTING_SLH@>
|
||||||
|
|
||||||
struct SphericalHarmonics {
|
// Frag Shading returns the diffuse amount as W and the specular rgb as xyz
|
||||||
vec4 L00;
|
vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) {
|
||||||
vec4 L1m1;
|
|
||||||
vec4 L10;
|
|
||||||
vec4 L11;
|
|
||||||
vec4 L2m2;
|
|
||||||
vec4 L2m1;
|
|
||||||
vec4 L20;
|
|
||||||
vec4 L21;
|
|
||||||
vec4 L22;
|
|
||||||
};
|
|
||||||
|
|
||||||
vec4 evalSphericalLight(SphericalHarmonics sh, vec3 direction ) {
|
|
||||||
|
|
||||||
const float C1 = 0.429043;
|
|
||||||
const float C2 = 0.511664;
|
|
||||||
const float C3 = 0.743125;
|
|
||||||
const float C4 = 0.886227;
|
|
||||||
const float C5 = 0.247708;
|
|
||||||
|
|
||||||
vec4 value = C1 * sh.L22 * (direction.x * direction.x - direction.y * direction.y) +
|
|
||||||
C3 * sh.L20 * direction.z * direction.z +
|
|
||||||
C4 * sh.L00 - C5 * sh.L20 +
|
|
||||||
2.0 * C1 * ( sh.L2m2 * direction.x * direction.y +
|
|
||||||
sh.L21 * direction.x * direction.z +
|
|
||||||
sh.L2m1 * direction.y * direction.z ) +
|
|
||||||
2.0 * C2 * ( sh.L11 * direction.x +
|
|
||||||
sh.L1m1 * direction.y +
|
|
||||||
sh.L10 * direction.z ) ;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
uniform SphericalHarmonics ambientSphere;
|
|
||||||
|
|
||||||
vec3 evalAmbientColor(vec3 normal, vec3 diffuse, vec3 specular, float gloss) {
|
|
||||||
return diffuse.rgb * gl_FrontLightProduct[0].ambient.rgb;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 evalAmbientSphereColor(vec3 normal, vec3 diffuse, vec3 specular, float gloss) {
|
|
||||||
vec3 ambientLight = 0.5 * evalSphericalLight(ambientSphere, normal).xyz;
|
|
||||||
|
|
||||||
return diffuse.rgb * ambientLight;
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 evalDirectionalColor(float shadowAttenuation, vec3 position, vec3 normal, vec3 diffuse, vec3 specular, float gloss) {
|
|
||||||
// Diffuse Lighting
|
// Diffuse Lighting
|
||||||
float diffuseDot = dot(normal, gl_LightSource[0].position.xyz);
|
float diffuseDot = dot(fragNormal, fragLightDir);
|
||||||
float facingLight = step(0.0, diffuseDot) * shadowAttenuation;
|
float facingLight = step(0.0, diffuseDot);
|
||||||
vec3 diffuseColor = diffuse * (gl_FrontLightProduct[0].diffuse.rgb * (diffuseDot * facingLight));
|
float diffuse = diffuseDot * facingLight;
|
||||||
|
|
||||||
// compute the specular multiplier (sans exponent)
|
// Specular Lighting depends on the half vector and the gloss
|
||||||
float specularPower = facingLight * max(0.0,
|
vec3 halfDir = normalize(fragEyeDir + fragLightDir);
|
||||||
dot(normalize(gl_LightSource[0].position.xyz - normalize(position)), normal));
|
|
||||||
vec3 specularColor = pow(specularPower, gloss * 128.0) * specular;
|
|
||||||
|
|
||||||
// add specular contribution
|
// float specularPower = pow(facingLight * max(0.0, dot(halfDir, fragNormal)), gloss * 128.0);
|
||||||
return vec3(diffuseColor + specularColor);
|
float specularPower = pow(max(0.0, dot(halfDir, fragNormal)), gloss * 128.0);
|
||||||
|
specularPower *= (gloss * 128.0 * 0.125 + 0.25);
|
||||||
|
|
||||||
|
float shlickPower = (1.0 - dot(fragLightDir,halfDir));
|
||||||
|
float shlickPower2 = shlickPower * shlickPower;
|
||||||
|
float shlickPower5 = shlickPower2 * shlickPower2 * shlickPower;
|
||||||
|
vec3 schlick = specular * (1.0 - shlickPower5) + vec3(shlickPower5);
|
||||||
|
vec3 reflect = specularPower * schlick;
|
||||||
|
|
||||||
|
return vec4(reflect, diffuse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec4 evalBlinnShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) {
|
||||||
|
// Diffuse Lighting
|
||||||
|
float diffuseDot = dot(fragNormal, fragLightDir);
|
||||||
|
float facingLight = step(0.0, diffuseDot);
|
||||||
|
float diffuse = diffuseDot * facingLight;
|
||||||
|
|
||||||
vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) {
|
// Specular Lighting depends on the half vector and the gloss
|
||||||
|
vec3 halfDir = normalize(fragEyeDir + fragLightDir);
|
||||||
|
|
||||||
float diffuseDot = dot(normal, gl_LightSource[0].position.xyz);
|
float specularPower = pow(facingLight * max(0.0, dot(halfDir, fragNormal)), gloss * 128.0);
|
||||||
|
vec3 reflect = specularPower * specular;
|
||||||
|
|
||||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
return vec4(reflect, diffuse);
|
||||||
// it should be just 0, but we have innacurracy so we need to overshoot
|
|
||||||
const float PERPENDICULAR_THRESHOLD = -0.005;
|
|
||||||
float facingLight = step(PERPENDICULAR_THRESHOLD, diffuseDot);
|
|
||||||
|
|
||||||
// evaluate the shadow test but only relevant for light facing fragments
|
|
||||||
float lightAttenuation = (1 - facingLight) + facingLight * shadowAttenuation;
|
|
||||||
|
|
||||||
// diffuse light is the lightmap dimmed by shadow
|
|
||||||
vec3 diffuseLight = lightAttenuation * lightmap;
|
|
||||||
|
|
||||||
// ambient is a tiny percentage of the lightmap and only when in the shadow
|
|
||||||
vec3 ambientLight = (1 - lightAttenuation) * 0.5 * lightmap;
|
|
||||||
|
|
||||||
return diffuse * (ambientLight + diffuseLight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec4 evalFragShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, vec3 specular, float gloss) {
|
||||||
|
|
||||||
|
/*if (gl_FragCoord.x > 1000) {
|
||||||
|
return evalBlinnShading(fragNormal, fragLightDir, fragEyeDir, specular, gloss);
|
||||||
|
} else {*/
|
||||||
|
return evalPBRShading(fragNormal, fragLightDir, fragEyeDir, specular, gloss);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
#include "RenderUtil.h"
|
#include "RenderUtil.h"
|
||||||
#include "TextureCache.h"
|
#include "TextureCache.h"
|
||||||
|
|
||||||
|
#include "gpu/Batch.h"
|
||||||
|
#include "gpu/GLBackend.h"
|
||||||
|
|
||||||
#include "simple_vert.h"
|
#include "simple_vert.h"
|
||||||
#include "simple_frag.h"
|
#include "simple_frag.h"
|
||||||
|
|
||||||
|
@ -42,146 +45,6 @@
|
||||||
#include "point_light_frag.h"
|
#include "point_light_frag.h"
|
||||||
#include "spot_light_frag.h"
|
#include "spot_light_frag.h"
|
||||||
|
|
||||||
class SphericalHarmonics {
|
|
||||||
public:
|
|
||||||
glm::vec3 L00 ; float spare0;
|
|
||||||
glm::vec3 L1m1 ; float spare1;
|
|
||||||
glm::vec3 L10 ; float spare2;
|
|
||||||
glm::vec3 L11 ; float spare3;
|
|
||||||
glm::vec3 L2m2 ; float spare4;
|
|
||||||
glm::vec3 L2m1 ; float spare5;
|
|
||||||
glm::vec3 L20 ; float spare6;
|
|
||||||
glm::vec3 L21 ; float spare7;
|
|
||||||
glm::vec3 L22 ; float spare8;
|
|
||||||
|
|
||||||
static const int NUM_COEFFICIENTS = 9;
|
|
||||||
|
|
||||||
void assignPreset(int p) {
|
|
||||||
switch (p) {
|
|
||||||
case DeferredLightingEffect::OLD_TOWN_SQUARE: {
|
|
||||||
L00 = glm::vec3( 0.871297f, 0.875222f, 0.864470f);
|
|
||||||
L1m1 = glm::vec3( 0.175058f, 0.245335f, 0.312891f);
|
|
||||||
L10 = glm::vec3( 0.034675f, 0.036107f, 0.037362f);
|
|
||||||
L11 = glm::vec3(-0.004629f,-0.029448f,-0.048028f);
|
|
||||||
L2m2 = glm::vec3(-0.120535f,-0.121160f,-0.117507f);
|
|
||||||
L2m1 = glm::vec3( 0.003242f, 0.003624f, 0.007511f);
|
|
||||||
L20 = glm::vec3(-0.028667f,-0.024926f,-0.020998f);
|
|
||||||
L21 = glm::vec3(-0.077539f,-0.086325f,-0.091591f);
|
|
||||||
L22 = glm::vec3(-0.161784f,-0.191783f,-0.219152f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DeferredLightingEffect::GRACE_CATHEDRAL: {
|
|
||||||
L00 = glm::vec3( 0.79f, 0.44f, 0.54f);
|
|
||||||
L1m1 = glm::vec3( 0.39f, 0.35f, 0.60f);
|
|
||||||
L10 = glm::vec3(-0.34f, -0.18f, -0.27f);
|
|
||||||
L11 = glm::vec3(-0.29f, -0.06f, 0.01f);
|
|
||||||
L2m2 = glm::vec3(-0.11f, -0.05f, -0.12f);
|
|
||||||
L2m1 = glm::vec3(-0.26f, -0.22f, -0.47f);
|
|
||||||
L20 = glm::vec3(-0.16f, -0.09f, -0.15f);
|
|
||||||
L21 = glm::vec3( 0.56f, 0.21f, 0.14f);
|
|
||||||
L22 = glm::vec3( 0.21f, -0.05f, -0.30f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DeferredLightingEffect::EUCALYPTUS_GROVE: {
|
|
||||||
L00 = glm::vec3( 0.38f, 0.43f, 0.45f);
|
|
||||||
L1m1 = glm::vec3( 0.29f, 0.36f, 0.41f);
|
|
||||||
L10 = glm::vec3( 0.04f, 0.03f, 0.01f);
|
|
||||||
L11 = glm::vec3(-0.10f, -0.10f, -0.09f);
|
|
||||||
L2m2 = glm::vec3(-0.06f, -0.06f, -0.04f);
|
|
||||||
L2m1 = glm::vec3( 0.01f, -0.01f, -0.05f);
|
|
||||||
L20 = glm::vec3(-0.09f, -0.13f, -0.15f);
|
|
||||||
L21 = glm::vec3(-0.06f, -0.05f, -0.04f);
|
|
||||||
L22 = glm::vec3( 0.02f, 0.00f, -0.05f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DeferredLightingEffect::ST_PETERS_BASILICA: {
|
|
||||||
L00 = glm::vec3( 0.36f, 0.26f, 0.23f);
|
|
||||||
L1m1 = glm::vec3( 0.18f, 0.14f, 0.13f);
|
|
||||||
L10 = glm::vec3(-0.02f, -0.01f, 0.00f);
|
|
||||||
L11 = glm::vec3( 0.03f, 0.02f, -0.00f);
|
|
||||||
L2m2 = glm::vec3( 0.02f, 0.01f, -0.00f);
|
|
||||||
L2m1 = glm::vec3(-0.05f, -0.03f, -0.01f);
|
|
||||||
L20 = glm::vec3(-0.09f, -0.08f, -0.07f);
|
|
||||||
L21 = glm::vec3( 0.01f, 0.00f, 0.00f);
|
|
||||||
L22 = glm::vec3(-0.08f, -0.03f, -0.00f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DeferredLightingEffect::UFFIZI_GALLERY: {
|
|
||||||
L00 = glm::vec3( 0.32f, 0.31f, 0.35f);
|
|
||||||
L1m1 = glm::vec3( 0.37f, 0.37f, 0.43f);
|
|
||||||
L10 = glm::vec3( 0.00f, 0.00f, 0.00f);
|
|
||||||
L11 = glm::vec3(-0.01f, -0.01f, -0.01f);
|
|
||||||
L2m2 = glm::vec3(-0.02f, -0.02f, -0.03f);
|
|
||||||
L2m1 = glm::vec3(-0.01f, -0.01f, -0.01f);
|
|
||||||
L20 = glm::vec3(-0.28f, -0.28f, -0.32f);
|
|
||||||
L21 = glm::vec3( 0.00f, 0.00f, 0.00f);
|
|
||||||
L22 = glm::vec3(-0.24f, -0.24f, -0.28f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DeferredLightingEffect::GALILEOS_TOMB: {
|
|
||||||
L00 = glm::vec3( 1.04f, 0.76f, 0.71f);
|
|
||||||
L1m1 = glm::vec3( 0.44f, 0.34f, 0.34f);
|
|
||||||
L10 = glm::vec3(-0.22f, -0.18f, -0.17f);
|
|
||||||
L11 = glm::vec3( 0.71f, 0.54f, 0.56f);
|
|
||||||
L2m2 = glm::vec3( 0.64f, 0.50f, 0.52f);
|
|
||||||
L2m1 = glm::vec3(-0.12f, -0.09f, -0.08f);
|
|
||||||
L20 = glm::vec3(-0.37f, -0.28f, -0.32f);
|
|
||||||
L21 = glm::vec3(-0.17f, -0.13f, -0.13f);
|
|
||||||
L22 = glm::vec3( 0.55f, 0.42f, 0.42f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DeferredLightingEffect::VINE_STREET_KITCHEN: {
|
|
||||||
L00 = glm::vec3( 0.64f, 0.67f, 0.73f);
|
|
||||||
L1m1 = glm::vec3( 0.28f, 0.32f, 0.33f);
|
|
||||||
L10 = glm::vec3( 0.42f, 0.60f, 0.77f);
|
|
||||||
L11 = glm::vec3(-0.05f, -0.04f, -0.02f);
|
|
||||||
L2m2 = glm::vec3(-0.10f, -0.08f, -0.05f);
|
|
||||||
L2m1 = glm::vec3( 0.25f, 0.39f, 0.53f);
|
|
||||||
L20 = glm::vec3( 0.38f, 0.54f, 0.71f);
|
|
||||||
L21 = glm::vec3( 0.06f, 0.01f, -0.02f);
|
|
||||||
L22 = glm::vec3(-0.03f, -0.02f, -0.03f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DeferredLightingEffect::BREEZEWAY: {
|
|
||||||
L00 = glm::vec3( 0.32f, 0.36f, 0.38f);
|
|
||||||
L1m1 = glm::vec3( 0.37f, 0.41f, 0.45f);
|
|
||||||
L10 = glm::vec3(-0.01f, -0.01f, -0.01f);
|
|
||||||
L11 = glm::vec3(-0.10f, -0.12f, -0.12f);
|
|
||||||
L2m2 = glm::vec3(-0.13f, -0.15f, -0.17f);
|
|
||||||
L2m1 = glm::vec3(-0.01f, -0.02f, 0.02f);
|
|
||||||
L20 = glm::vec3(-0.07f, -0.08f, -0.09f);
|
|
||||||
L21 = glm::vec3( 0.02f, 0.03f, 0.03f);
|
|
||||||
L22 = glm::vec3(-0.29f, -0.32f, -0.36f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DeferredLightingEffect::CAMPUS_SUNSET: {
|
|
||||||
L00 = glm::vec3( 0.79f, 0.94f, 0.98f);
|
|
||||||
L1m1 = glm::vec3( 0.44f, 0.56f, 0.70f);
|
|
||||||
L10 = glm::vec3(-0.10f, -0.18f, -0.27f);
|
|
||||||
L11 = glm::vec3( 0.45f, 0.38f, 0.20f);
|
|
||||||
L2m2 = glm::vec3( 0.18f, 0.14f, 0.05f);
|
|
||||||
L2m1 = glm::vec3(-0.14f, -0.22f, -0.31f);
|
|
||||||
L20 = glm::vec3(-0.39f, -0.40f, -0.36f);
|
|
||||||
L21 = glm::vec3( 0.09f, 0.07f, 0.04f);
|
|
||||||
L22 = glm::vec3( 0.67f, 0.67f, 0.52f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case DeferredLightingEffect::FUNSTON_BEACH_SUNSET: {
|
|
||||||
L00 = glm::vec3( 0.68f, 0.69f, 0.70f);
|
|
||||||
L1m1 = glm::vec3( 0.32f, 0.37f, 0.44f);
|
|
||||||
L10 = glm::vec3(-0.17f, -0.17f, -0.17f);
|
|
||||||
L11 = glm::vec3(-0.45f, -0.42f, -0.34f);
|
|
||||||
L2m2 = glm::vec3(-0.17f, -0.17f, -0.15f);
|
|
||||||
L2m1 = glm::vec3(-0.08f, -0.09f, -0.10f);
|
|
||||||
L20 = glm::vec3(-0.03f, -0.02f, -0.01f);
|
|
||||||
L21 = glm::vec3( 0.16f, 0.14f, 0.10f);
|
|
||||||
L22 = glm::vec3( 0.37f, 0.31f, 0.20f);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
||||||
_viewState = viewState;
|
_viewState = viewState;
|
||||||
_simpleProgram.addShaderFromSourceCode(QGLShader::Vertex, simple_vert);
|
_simpleProgram.addShaderFromSourceCode(QGLShader::Vertex, simple_vert);
|
||||||
|
@ -206,6 +69,18 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) {
|
||||||
|
|
||||||
loadLightProgram(point_light_frag, true, _pointLight, _pointLightLocations);
|
loadLightProgram(point_light_frag, true, _pointLight, _pointLightLocations);
|
||||||
loadLightProgram(spot_light_frag, true, _spotLight, _spotLightLocations);
|
loadLightProgram(spot_light_frag, true, _spotLight, _spotLightLocations);
|
||||||
|
|
||||||
|
// Allocate a global light representing the Global Directional light casting shadow (the sun) and the ambient light
|
||||||
|
_globalLights.push_back(0);
|
||||||
|
_allocatedLights.push_back(model::LightPointer(new model::Light()));
|
||||||
|
|
||||||
|
model::LightPointer lp = _allocatedLights[0];
|
||||||
|
|
||||||
|
lp->setDirection(-glm::vec3(1.0f, 1.0f, 1.0f));
|
||||||
|
lp->setColor(glm::vec3(1.0f));
|
||||||
|
lp->setIntensity(1.0f);
|
||||||
|
lp->setType(model::Light::SUN);
|
||||||
|
lp->setAmbientSpherePreset(model::SphericalHarmonics::Preset(_ambientLightMode % model::SphericalHarmonics::NUM_PRESET));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeferredLightingEffect::bindSimpleProgram() {
|
void DeferredLightingEffect::bindSimpleProgram() {
|
||||||
|
@ -260,30 +135,29 @@ void DeferredLightingEffect::addPointLight(const glm::vec3& position, float radi
|
||||||
void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radius, const glm::vec3& ambient,
|
void DeferredLightingEffect::addSpotLight(const glm::vec3& position, float radius, const glm::vec3& ambient,
|
||||||
const glm::vec3& diffuse, const glm::vec3& specular, float constantAttenuation, float linearAttenuation,
|
const glm::vec3& diffuse, const glm::vec3& specular, float constantAttenuation, float linearAttenuation,
|
||||||
float quadraticAttenuation, const glm::vec3& direction, float exponent, float cutoff) {
|
float quadraticAttenuation, const glm::vec3& direction, float exponent, float cutoff) {
|
||||||
|
|
||||||
|
int lightID = _pointLights.size() + _spotLights.size() + _globalLights.size();
|
||||||
|
if (lightID >= _allocatedLights.size()) {
|
||||||
|
_allocatedLights.push_back(model::LightPointer(new model::Light()));
|
||||||
|
}
|
||||||
|
model::LightPointer lp = _allocatedLights[lightID];
|
||||||
|
|
||||||
|
lp->setPosition(position);
|
||||||
|
lp->setMaximumRadius(radius);
|
||||||
|
lp->setColor(diffuse);
|
||||||
|
lp->setIntensity(1.0f);
|
||||||
|
//lp->setShowContour(quadraticAttenuation);
|
||||||
|
|
||||||
if (exponent == 0.0f && cutoff == PI) {
|
if (exponent == 0.0f && cutoff == PI) {
|
||||||
PointLight light;
|
lp->setType(model::Light::POINT);
|
||||||
light.position = glm::vec4(position, 1.0f);
|
_pointLights.push_back(lightID);
|
||||||
light.radius = radius;
|
|
||||||
light.ambient = glm::vec4(ambient, 1.0f);
|
|
||||||
light.diffuse = glm::vec4(diffuse, 1.0f);
|
|
||||||
light.specular = glm::vec4(specular, 1.0f);
|
|
||||||
light.constantAttenuation = constantAttenuation;
|
|
||||||
light.linearAttenuation = linearAttenuation;
|
|
||||||
_pointLights.append(light);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
SpotLight light;
|
lp->setDirection(direction);
|
||||||
light.position = glm::vec4(position, 1.0f);
|
lp->setSpotAngle(cutoff);
|
||||||
light.radius = radius;
|
lp->setSpotExponent(exponent);
|
||||||
light.ambient = glm::vec4(ambient, 1.0f);
|
lp->setType(model::Light::SPOT);
|
||||||
light.diffuse = glm::vec4(diffuse, 1.0f);
|
_spotLights.push_back(lightID);
|
||||||
light.specular = glm::vec4(specular, 1.0f);
|
|
||||||
light.constantAttenuation = constantAttenuation;
|
|
||||||
light.linearAttenuation = linearAttenuation;
|
|
||||||
light.direction = direction;
|
|
||||||
light.exponent = exponent;
|
|
||||||
light.cutoff = cutoff;
|
|
||||||
_spotLights.append(light);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +191,7 @@ void DeferredLightingEffect::render() {
|
||||||
QOpenGLFramebufferObject* freeFBO = DependencyManager::get<GlowEffect>()->getFreeFramebufferObject();
|
QOpenGLFramebufferObject* freeFBO = DependencyManager::get<GlowEffect>()->getFreeFramebufferObject();
|
||||||
freeFBO->bind();
|
freeFBO->bind();
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glEnable(GL_FRAMEBUFFER_SRGB);
|
// glEnable(GL_FRAMEBUFFER_SRGB);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, primaryFBO->texture());
|
glBindTexture(GL_TEXTURE_2D, primaryFBO->texture());
|
||||||
|
|
||||||
|
@ -342,6 +216,10 @@ void DeferredLightingEffect::render() {
|
||||||
float tMin = viewport[VIEWPORT_Y_INDEX] / (float)primaryFBO->height();
|
float tMin = viewport[VIEWPORT_Y_INDEX] / (float)primaryFBO->height();
|
||||||
float tHeight = viewport[VIEWPORT_HEIGHT_INDEX] / (float)primaryFBO->height();
|
float tHeight = viewport[VIEWPORT_HEIGHT_INDEX] / (float)primaryFBO->height();
|
||||||
|
|
||||||
|
// Fetch the ViewMatrix;
|
||||||
|
glm::mat4 invViewMat;
|
||||||
|
_viewState->getViewTransform().getMatrix(invViewMat);
|
||||||
|
|
||||||
ProgramObject* program = &_directionalLight;
|
ProgramObject* program = &_directionalLight;
|
||||||
const LightLocations* locations = &_directionalLightLocations;
|
const LightLocations* locations = &_directionalLightLocations;
|
||||||
bool shadowsEnabled = _viewState->getShadowsEnabled();
|
bool shadowsEnabled = _viewState->getShadowsEnabled();
|
||||||
|
@ -379,19 +257,24 @@ void DeferredLightingEffect::render() {
|
||||||
program->bind();
|
program->bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (locations->ambientSphere >= 0) {
|
{
|
||||||
SphericalHarmonics sh;
|
auto globalLight = _allocatedLights[_globalLights.front()];
|
||||||
if (_ambientLightMode < NUM_PRESET) {
|
|
||||||
sh.assignPreset(_ambientLightMode);
|
|
||||||
} else {
|
|
||||||
sh.assignPreset(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i =0; i <SphericalHarmonics::NUM_COEFFICIENTS; i++) {
|
if (locations->ambientSphere >= 0) {
|
||||||
|
auto sh = globalLight->getAmbientSphere();
|
||||||
|
for (int i =0; i <model::SphericalHarmonics::NUM_COEFFICIENTS; i++) {
|
||||||
program->setUniformValue(locations->ambientSphere + i, *(((QVector4D*) &sh) + i));
|
program->setUniformValue(locations->ambientSphere + i, *(((QVector4D*) &sh) + i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (locations->lightBufferUnit >= 0) {
|
||||||
|
gpu::Batch batch;
|
||||||
|
batch.setUniformBuffer(locations->lightBufferUnit, globalLight->getSchemaBuffer());
|
||||||
|
gpu::GLBackend::renderBatch(batch);
|
||||||
|
}
|
||||||
|
glUniformMatrix4fv(locations->invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat));
|
||||||
|
}
|
||||||
|
|
||||||
float left, right, bottom, top, nearVal, farVal;
|
float left, right, bottom, top, nearVal, farVal;
|
||||||
glm::vec4 nearClipPlane, farClipPlane;
|
glm::vec4 nearClipPlane, farClipPlane;
|
||||||
_viewState->computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
_viewState->computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
|
||||||
|
@ -434,27 +317,27 @@ void DeferredLightingEffect::render() {
|
||||||
|
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
|
||||||
if (!_pointLights.isEmpty()) {
|
if (!_pointLights.empty()) {
|
||||||
_pointLight.bind();
|
_pointLight.bind();
|
||||||
_pointLight.setUniformValue(_pointLightLocations.nearLocation, nearVal);
|
_pointLight.setUniformValue(_pointLightLocations.nearLocation, nearVal);
|
||||||
_pointLight.setUniformValue(_pointLightLocations.depthScale, depthScale);
|
_pointLight.setUniformValue(_pointLightLocations.depthScale, depthScale);
|
||||||
_pointLight.setUniformValue(_pointLightLocations.depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
|
_pointLight.setUniformValue(_pointLightLocations.depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
|
||||||
_pointLight.setUniformValue(_pointLightLocations.depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
|
_pointLight.setUniformValue(_pointLightLocations.depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
|
||||||
|
|
||||||
foreach (const PointLight& light, _pointLights) {
|
for (auto lightID : _pointLights) {
|
||||||
_pointLight.setUniformValue(_pointLightLocations.radius, light.radius);
|
auto light = _allocatedLights[lightID];
|
||||||
glLightfv(GL_LIGHT1, GL_AMBIENT, (const GLfloat*)&light.ambient);
|
|
||||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, (const GLfloat*)&light.diffuse);
|
if (_pointLightLocations.lightBufferUnit >= 0) {
|
||||||
glLightfv(GL_LIGHT1, GL_SPECULAR, (const GLfloat*)&light.specular);
|
gpu::Batch batch;
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, (const GLfloat*)&light.position);
|
batch.setUniformBuffer(_pointLightLocations.lightBufferUnit, light->getSchemaBuffer());
|
||||||
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, (light.constantAttenuation > 0.0f ? light.constantAttenuation : 0.0f));
|
gpu::GLBackend::renderBatch(batch);
|
||||||
glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, (light.linearAttenuation > 0.0f ? light.linearAttenuation : 0.0f));
|
}
|
||||||
glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, (light.quadraticAttenuation > 0.0f ? light.quadraticAttenuation : 0.0f));
|
glUniformMatrix4fv(_pointLightLocations.invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat));
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
float expandedRadius = light.radius * (1.0f + SCALE_EXPANSION);
|
float expandedRadius = light->getMaximumRadius() * (1.0f + SCALE_EXPANSION);
|
||||||
if (glm::distance(eyePoint, glm::vec3(light.position)) < expandedRadius + nearRadius) {
|
if (glm::distance(eyePoint, glm::vec3(light->getPosition())) < expandedRadius + nearRadius) {
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0.0f, 0.0f, -1.0f);
|
glTranslatef(0.0f, 0.0f, -1.0f);
|
||||||
|
|
||||||
|
@ -468,7 +351,7 @@ void DeferredLightingEffect::render() {
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
glTranslatef(light.position.x, light.position.y, light.position.z);
|
glTranslatef(light->getPosition().x, light->getPosition().y, light->getPosition().z);
|
||||||
geometryCache->renderSphere(expandedRadius, 32, 32, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
|
geometryCache->renderSphere(expandedRadius, 32, 32, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,31 +362,28 @@ void DeferredLightingEffect::render() {
|
||||||
_pointLight.release();
|
_pointLight.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_spotLights.isEmpty()) {
|
if (!_spotLights.empty()) {
|
||||||
_spotLight.bind();
|
_spotLight.bind();
|
||||||
_spotLight.setUniformValue(_spotLightLocations.nearLocation, nearVal);
|
_spotLight.setUniformValue(_spotLightLocations.nearLocation, nearVal);
|
||||||
_spotLight.setUniformValue(_spotLightLocations.depthScale, depthScale);
|
_spotLight.setUniformValue(_spotLightLocations.depthScale, depthScale);
|
||||||
_spotLight.setUniformValue(_spotLightLocations.depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
|
_spotLight.setUniformValue(_spotLightLocations.depthTexCoordOffset, depthTexCoordOffsetS, depthTexCoordOffsetT);
|
||||||
_spotLight.setUniformValue(_spotLightLocations.depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
|
_spotLight.setUniformValue(_spotLightLocations.depthTexCoordScale, depthTexCoordScaleS, depthTexCoordScaleT);
|
||||||
|
|
||||||
foreach (const SpotLight& light, _spotLights) {
|
for (auto lightID : _spotLights) {
|
||||||
_spotLight.setUniformValue(_spotLightLocations.radius, light.radius);
|
auto light = _allocatedLights[lightID];
|
||||||
glLightfv(GL_LIGHT1, GL_AMBIENT, (const GLfloat*)&light.ambient);
|
|
||||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, (const GLfloat*)&light.diffuse);
|
if (_spotLightLocations.lightBufferUnit >= 0) {
|
||||||
glLightfv(GL_LIGHT1, GL_SPECULAR, (const GLfloat*)&light.specular);
|
gpu::Batch batch;
|
||||||
glLightfv(GL_LIGHT1, GL_POSITION, (const GLfloat*)&light.position);
|
batch.setUniformBuffer(_spotLightLocations.lightBufferUnit, light->getSchemaBuffer());
|
||||||
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, (light.constantAttenuation > 0.0f ? light.constantAttenuation : 0.0f));
|
gpu::GLBackend::renderBatch(batch);
|
||||||
glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, (light.linearAttenuation > 0.0f ? light.linearAttenuation : 0.0f));
|
}
|
||||||
glLightf(GL_LIGHT1, GL_QUADRATIC_ATTENUATION, (light.quadraticAttenuation > 0.0f ? light.quadraticAttenuation : 0.0f));
|
glUniformMatrix4fv(_spotLightLocations.invViewMat, 1, false, reinterpret_cast< const GLfloat* >(&invViewMat));
|
||||||
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, (const GLfloat*)&light.direction);
|
|
||||||
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, light.exponent);
|
|
||||||
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, glm::degrees(light.cutoff));
|
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
float expandedRadius = light.radius * (1.0f + SCALE_EXPANSION);
|
float expandedRadius = light->getMaximumRadius() * (1.0f + SCALE_EXPANSION);
|
||||||
float edgeRadius = expandedRadius / glm::cos(light.cutoff);
|
float edgeRadius = expandedRadius / glm::cos(light->getSpotAngle());
|
||||||
if (glm::distance(eyePoint, glm::vec3(light.position)) < edgeRadius + nearRadius) {
|
if (glm::distance(eyePoint, glm::vec3(light->getPosition())) < edgeRadius + nearRadius) {
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0.0f, 0.0f, -1.0f);
|
glTranslatef(0.0f, 0.0f, -1.0f);
|
||||||
|
|
||||||
|
@ -517,12 +397,12 @@ void DeferredLightingEffect::render() {
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
glTranslatef(light.position.x, light.position.y, light.position.z);
|
glTranslatef(light->getPosition().x, light->getPosition().y, light->getPosition().z);
|
||||||
glm::quat spotRotation = rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), light.direction);
|
glm::quat spotRotation = rotationBetween(glm::vec3(0.0f, 0.0f, -1.0f), light->getDirection());
|
||||||
glm::vec3 axis = glm::axis(spotRotation);
|
glm::vec3 axis = glm::axis(spotRotation);
|
||||||
glRotatef(glm::degrees(glm::angle(spotRotation)), axis.x, axis.y, axis.z);
|
glRotatef(glm::degrees(glm::angle(spotRotation)), axis.x, axis.y, axis.z);
|
||||||
glTranslatef(0.0f, 0.0f, -light.radius * (1.0f + SCALE_EXPANSION * 0.5f));
|
glTranslatef(0.0f, 0.0f, -light->getMaximumRadius() * (1.0f + SCALE_EXPANSION * 0.5f));
|
||||||
geometryCache->renderCone(expandedRadius * glm::tan(light.cutoff),
|
geometryCache->renderCone(expandedRadius * glm::tan(light->getSpotAngle()),
|
||||||
expandedRadius, 32, 1);
|
expandedRadius, 32, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,7 +425,7 @@ void DeferredLightingEffect::render() {
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
freeFBO->release();
|
freeFBO->release();
|
||||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
// glDisable(GL_FRAMEBUFFER_SRGB);
|
||||||
|
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
@ -607,11 +487,46 @@ void DeferredLightingEffect::loadLightProgram(const char* fragSource, bool limit
|
||||||
locations.depthTexCoordScale = program.uniformLocation("depthTexCoordScale");
|
locations.depthTexCoordScale = program.uniformLocation("depthTexCoordScale");
|
||||||
locations.radius = program.uniformLocation("radius");
|
locations.radius = program.uniformLocation("radius");
|
||||||
locations.ambientSphere = program.uniformLocation("ambientSphere.L00");
|
locations.ambientSphere = program.uniformLocation("ambientSphere.L00");
|
||||||
|
locations.invViewMat = program.uniformLocation("invViewMat");
|
||||||
|
|
||||||
|
GLint loc = -1;
|
||||||
|
#if defined(Q_OS_MAC)
|
||||||
|
loc = program.uniformLocation("lightBuffer");
|
||||||
|
if (loc >= 0) {
|
||||||
|
locations.lightBufferUnit = loc;
|
||||||
|
} else {
|
||||||
|
locations.lightBufferUnit = -1;
|
||||||
|
}
|
||||||
|
#elif defined(Q_OS_WIN)
|
||||||
|
loc = glGetUniformBlockIndex(program.programId(), "lightBuffer");
|
||||||
|
if (loc >= 0) {
|
||||||
|
glUniformBlockBinding(program.programId(), loc, 0);
|
||||||
|
locations.lightBufferUnit = 0;
|
||||||
|
} else {
|
||||||
|
locations.lightBufferUnit = -1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
loc = program.uniformLocation("lightBuffer");
|
||||||
|
if (loc >= 0) {
|
||||||
|
locations.lightBufferUnit = loc;
|
||||||
|
} else {
|
||||||
|
locations.lightBufferUnit = -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
program.release();
|
program.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeferredLightingEffect::setAmbientLightMode(int preset) {
|
void DeferredLightingEffect::setAmbientLightMode(int preset) {
|
||||||
if ((preset >= -1) && (preset < NUM_PRESET)) {
|
if ((preset >= -1) && (preset < model::SphericalHarmonics::NUM_PRESET)) {
|
||||||
_ambientLightMode = preset;
|
_ambientLightMode = preset;
|
||||||
|
auto light = _allocatedLights.front();
|
||||||
|
light->setAmbientSpherePreset(model::SphericalHarmonics::Preset(preset % model::SphericalHarmonics::NUM_PRESET));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeferredLightingEffect::setGlobalLight(const glm::vec3& direction, const glm::vec3& diffuse, float intensity) {
|
||||||
|
auto light = _allocatedLights.front();
|
||||||
|
light->setDirection(direction);
|
||||||
|
light->setColor(diffuse);
|
||||||
|
light->setIntensity(intensity);
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include "ProgramObject.h"
|
#include "ProgramObject.h"
|
||||||
|
|
||||||
|
#include "model/Light.h"
|
||||||
|
|
||||||
class AbstractViewStateInterface;
|
class AbstractViewStateInterface;
|
||||||
class PostLightingRenderable;
|
class PostLightingRenderable;
|
||||||
|
|
||||||
|
@ -71,25 +73,12 @@ public:
|
||||||
void prepare();
|
void prepare();
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
enum AmbientLightPreset {
|
// update global lighting
|
||||||
OLD_TOWN_SQUARE = 0,
|
|
||||||
GRACE_CATHEDRAL,
|
|
||||||
EUCALYPTUS_GROVE,
|
|
||||||
ST_PETERS_BASILICA,
|
|
||||||
UFFIZI_GALLERY,
|
|
||||||
GALILEOS_TOMB,
|
|
||||||
VINE_STREET_KITCHEN,
|
|
||||||
BREEZEWAY,
|
|
||||||
CAMPUS_SUNSET,
|
|
||||||
FUNSTON_BEACH_SUNSET,
|
|
||||||
|
|
||||||
NUM_PRESET,
|
|
||||||
};
|
|
||||||
|
|
||||||
void setAmbientLightMode(int preset);
|
void setAmbientLightMode(int preset);
|
||||||
|
void setGlobalLight(const glm::vec3& direction, const glm::vec3& diffuse, float intensity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeferredLightingEffect() { }
|
DeferredLightingEffect() {}
|
||||||
virtual ~DeferredLightingEffect() { }
|
virtual ~DeferredLightingEffect() { }
|
||||||
|
|
||||||
class LightLocations {
|
class LightLocations {
|
||||||
|
@ -102,6 +91,8 @@ private:
|
||||||
int depthTexCoordScale;
|
int depthTexCoordScale;
|
||||||
int radius;
|
int radius;
|
||||||
int ambientSphere;
|
int ambientSphere;
|
||||||
|
int lightBufferUnit;
|
||||||
|
int invViewMat;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations);
|
static void loadLightProgram(const char* fragSource, bool limited, ProgramObject& program, LightLocations& locations);
|
||||||
|
@ -147,8 +138,12 @@ private:
|
||||||
float cutoff;
|
float cutoff;
|
||||||
};
|
};
|
||||||
|
|
||||||
QVector<PointLight> _pointLights;
|
typedef std::vector< model::LightPointer > Lights;
|
||||||
QVector<SpotLight> _spotLights;
|
|
||||||
|
Lights _allocatedLights;
|
||||||
|
std::vector<int> _globalLights;
|
||||||
|
std::vector<int> _pointLights;
|
||||||
|
std::vector<int> _spotLights;
|
||||||
QVector<PostLightingRenderable*> _postLightingRenderables;
|
QVector<PostLightingRenderable*> _postLightingRenderables;
|
||||||
|
|
||||||
AbstractViewStateInterface* _viewState;
|
AbstractViewStateInterface* _viewState;
|
||||||
|
|
|
@ -1154,7 +1154,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC
|
||||||
|
|
||||||
gpu::Batch batch;
|
gpu::Batch batch;
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
// glEnable(GL_TEXTURE_2D);
|
||||||
//glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific...
|
//glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific...
|
||||||
|
|
||||||
batch.setInputFormat(details.streamFormat);
|
batch.setInputFormat(details.streamFormat);
|
||||||
|
@ -1168,8 +1168,8 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
// glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glDisable(GL_TEXTURE_2D);
|
// glDisable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) {
|
void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) {
|
||||||
|
|
107
libraries/render-utils/src/Light.slh
Executable file
107
libraries/render-utils/src/Light.slh
Executable file
|
@ -0,0 +1,107 @@
|
||||||
|
<!
|
||||||
|
// Light.slh
|
||||||
|
// fragment shader
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 1/25/14.
|
||||||
|
// Copyright 2013 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
!>
|
||||||
|
<@if not LIGHT_SLH@>
|
||||||
|
<@def LIGHT_SLH@>
|
||||||
|
|
||||||
|
struct Light {
|
||||||
|
vec4 _position;
|
||||||
|
vec4 _direction;
|
||||||
|
vec4 _color;
|
||||||
|
vec4 _attenuation;
|
||||||
|
vec4 _spot;
|
||||||
|
|
||||||
|
vec4 _shadow;
|
||||||
|
|
||||||
|
vec4 _control;
|
||||||
|
};
|
||||||
|
|
||||||
|
vec3 getLightPosition(Light l) { return l._position.xyz; }
|
||||||
|
vec3 getLightDirection(Light l) { return l._direction.xyz; } // direction is -Z axis
|
||||||
|
|
||||||
|
vec3 getLightColor(Light l) { return l._color.rgb; }
|
||||||
|
float getLightIntensity(Light l) { return l._color.w; }
|
||||||
|
|
||||||
|
float evalLightAttenuation(Light l, float r) {
|
||||||
|
float d = max(r - l._attenuation.x, 0.0);
|
||||||
|
float denom = d * l._attenuation.y + 1.0;
|
||||||
|
float attenuation = 1.0 / (denom * denom);
|
||||||
|
return max((attenuation - l._attenuation.z)/(1.0 - l._attenuation.z), 0.0);
|
||||||
|
// return clamp(1.0/(l._attenuation.x + l._attenuation.y * r + l._attenuation.z * r * r), 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float getLightSpotAngleCos(Light l) {
|
||||||
|
return l._spot.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 getLightSpotOutsideNormal2(Light l) {
|
||||||
|
return vec2(-l._spot.y, l._spot.x);
|
||||||
|
}
|
||||||
|
|
||||||
|
float evalLightSpotAttenuation(Light l, float cosA) {
|
||||||
|
return pow(cosA, l._spot.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
float getLightSquareRadius(Light l) {
|
||||||
|
return l._attenuation.w * l._attenuation.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
float getLightRadius(Light l) {
|
||||||
|
return l._attenuation.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
float getLightAttenuationCutoff(Light l) {
|
||||||
|
return l._attenuation.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
float getLightShowContour(Light l) {
|
||||||
|
return l._control.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
<@if GLPROFILE == PC_GL@>
|
||||||
|
uniform lightBuffer {
|
||||||
|
Light light;
|
||||||
|
};
|
||||||
|
Light getLight() {
|
||||||
|
return light;
|
||||||
|
}
|
||||||
|
<@elif GLPROFILE == MAC_GL@>
|
||||||
|
uniform vec4 lightBuffer[9];
|
||||||
|
Light getLight() {
|
||||||
|
Light light;
|
||||||
|
light._position = lightBuffer[0];
|
||||||
|
light._direction = lightBuffer[1];
|
||||||
|
light._color = lightBuffer[2];
|
||||||
|
light._attenuation = lightBuffer[3];
|
||||||
|
light._spot = lightBuffer[4];
|
||||||
|
light._shadow = lightBuffer[5];
|
||||||
|
light._control = lightBuffer[6];
|
||||||
|
|
||||||
|
return light;
|
||||||
|
}
|
||||||
|
<@else@>
|
||||||
|
uniform vec4 lightBuffer[9];
|
||||||
|
Light getLight() {
|
||||||
|
Light light;
|
||||||
|
light._position = lightBuffer[0];
|
||||||
|
light._direction = lightBuffer[1];
|
||||||
|
light._color = lightBuffer[2];
|
||||||
|
light._attenuation = lightBuffer[3];
|
||||||
|
light._spot = lightBuffer[4];
|
||||||
|
light._shadow = lightBuffer[5];
|
||||||
|
light._control = lightBuffer[6];
|
||||||
|
|
||||||
|
return light;
|
||||||
|
}
|
||||||
|
<@endif@>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<@endif@>
|
|
@ -511,6 +511,10 @@ TextRenderer::TextRenderer(const char* family, float pointSize, int weight,
|
||||||
bool italic, EffectType effect, int effectThickness,
|
bool italic, EffectType effect, int effectThickness,
|
||||||
const QColor& color) :
|
const QColor& color) :
|
||||||
_effectType(effect), _effectThickness(effectThickness), _pointSize(pointSize), _color(color), _font(loadFont(family)) {
|
_effectType(effect), _effectThickness(effectThickness), _pointSize(pointSize), _color(color), _font(loadFont(family)) {
|
||||||
|
if (!_font) {
|
||||||
|
qWarning() << "Unable to load font with family " << family;
|
||||||
|
_font = loadFont("Courier");
|
||||||
|
}
|
||||||
if (1 != _effectThickness) {
|
if (1 != _effectThickness) {
|
||||||
qWarning() << "Effect thickness not current supported";
|
qWarning() << "Effect thickness not current supported";
|
||||||
}
|
}
|
||||||
|
@ -524,7 +528,10 @@ TextRenderer::~TextRenderer() {
|
||||||
|
|
||||||
glm::vec2 TextRenderer::computeExtent(const QString & str) const {
|
glm::vec2 TextRenderer::computeExtent(const QString & str) const {
|
||||||
float scale = (_pointSize / DEFAULT_POINT_SIZE) * 0.25f;
|
float scale = (_pointSize / DEFAULT_POINT_SIZE) * 0.25f;
|
||||||
|
if (_font) {
|
||||||
return _font->computeExtent(str) * scale;
|
return _font->computeExtent(str) * scale;
|
||||||
|
}
|
||||||
|
return glm::vec2(0.1f,0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float TextRenderer::draw(float x, float y, const QString & str,
|
float TextRenderer::draw(float x, float y, const QString & str,
|
||||||
|
@ -544,7 +551,9 @@ float TextRenderer::draw(float x, float y, const QString & str,
|
||||||
// scale at all.
|
// scale at all.
|
||||||
mv.translate(glm::vec2(x, y)).scale(glm::vec3(scale, -scale, scale));
|
mv.translate(glm::vec2(x, y)).scale(glm::vec3(scale, -scale, scale));
|
||||||
// The font does all the OpenGL work
|
// The font does all the OpenGL work
|
||||||
|
if (_font) {
|
||||||
result = _font->drawString(x, y, str, actualColor, _effectType, bounds / scale);
|
result = _font->drawString(x, y, str, actualColor, _effectType, bounds / scale);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return result.x;
|
return result.x;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,22 +15,23 @@
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
<@include DeferredLighting.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
||||||
|
|
||||||
|
|
||||||
// Light mapped or not ?
|
// Light mapped or not ?
|
||||||
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
|
if ((frag.normalVal.a >= 0.45) && (frag.normalVal.a <= 0.55)) {
|
||||||
gl_FragColor = vec4( evalLightmappedColor(
|
vec3 color = evalLightmappedColor(
|
||||||
1.0,
|
1.0,
|
||||||
frag.normal,
|
frag.normal,
|
||||||
frag.diffuse,
|
frag.diffuse,
|
||||||
frag.specularVal.xyz),
|
frag.specularVal.xyz);
|
||||||
1.0);
|
|
||||||
|
gl_FragColor = vec4(color, 1.0);
|
||||||
} else {
|
} else {
|
||||||
vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
vec3 color = evalAmbienSphereGlobalColor(1.0,
|
||||||
+ evalDirectionalColor(1.0,
|
|
||||||
frag.position.xyz,
|
frag.position.xyz,
|
||||||
frag.normal,
|
frag.normal,
|
||||||
frag.diffuse,
|
frag.diffuse,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
<@include DeferredLighting.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
// Everything about shadow
|
// Everything about shadow
|
||||||
<@include Shadow.slh@>
|
<@include Shadow.slh@>
|
||||||
|
@ -36,8 +36,7 @@ void main(void) {
|
||||||
frag.specularVal.xyz),
|
frag.specularVal.xyz),
|
||||||
1.0);
|
1.0);
|
||||||
} else {
|
} else {
|
||||||
vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
vec3 color = evalAmbienSphereGlobalColor(shadowAttenuation,
|
||||||
+ evalDirectionalColor(shadowAttenuation,
|
|
||||||
frag.position.xyz,
|
frag.position.xyz,
|
||||||
frag.normal,
|
frag.normal,
|
||||||
frag.diffuse,
|
frag.diffuse,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
<@include DeferredLighting.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
// Everything about shadow
|
// Everything about shadow
|
||||||
<@include Shadow.slh@>
|
<@include Shadow.slh@>
|
||||||
|
@ -37,8 +37,7 @@ void main(void) {
|
||||||
frag.specularVal.xyz),
|
frag.specularVal.xyz),
|
||||||
1.0);
|
1.0);
|
||||||
} else {
|
} else {
|
||||||
vec3 color = evalAmbientSphereColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
vec3 color = evalAmbienSphereGlobalColor(shadowAttenuation,
|
||||||
+ evalDirectionalColor(shadowAttenuation,
|
|
||||||
frag.position.xyz,
|
frag.position.xyz,
|
||||||
frag.normal,
|
frag.normal,
|
||||||
frag.diffuse,
|
frag.diffuse,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
<@include DeferredLighting.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
DeferredFragment frag = unpackDeferredFragment(gl_TexCoord[0].st);
|
||||||
|
@ -29,8 +29,7 @@ void main(void) {
|
||||||
frag.specularVal.xyz),
|
frag.specularVal.xyz),
|
||||||
1.0);
|
1.0);
|
||||||
} else {
|
} else {
|
||||||
vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
vec3 color = evalAmbienGlobalColor(1.0,
|
||||||
+ evalDirectionalColor(1.0,
|
|
||||||
frag.position.xyz,
|
frag.position.xyz,
|
||||||
frag.normal,
|
frag.normal,
|
||||||
frag.diffuse,
|
frag.diffuse,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
<@include DeferredLighting.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
// Everything about shadow
|
// Everything about shadow
|
||||||
<@include Shadow.slh@>
|
<@include Shadow.slh@>
|
||||||
|
@ -36,8 +36,7 @@ void main(void) {
|
||||||
frag.specularVal.xyz),
|
frag.specularVal.xyz),
|
||||||
1.0);
|
1.0);
|
||||||
} else {
|
} else {
|
||||||
vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
vec3 color = evalAmbienGlobalColor(shadowAttenuation,
|
||||||
+ evalDirectionalColor(shadowAttenuation,
|
|
||||||
frag.position.xyz,
|
frag.position.xyz,
|
||||||
frag.normal,
|
frag.normal,
|
||||||
frag.diffuse,
|
frag.diffuse,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
<@include DeferredLighting.slh@>
|
<@include DeferredGlobalLight.slh@>
|
||||||
|
|
||||||
// Everything about shadow
|
// Everything about shadow
|
||||||
<@include Shadow.slh@>
|
<@include Shadow.slh@>
|
||||||
|
@ -37,8 +37,7 @@ void main(void) {
|
||||||
frag.specularVal.xyz),
|
frag.specularVal.xyz),
|
||||||
1.0);
|
1.0);
|
||||||
} else {
|
} else {
|
||||||
vec3 color = evalAmbientColor(frag.normal, frag.diffuse, frag.specular, frag.gloss)
|
vec3 color = evalAmbienGlobalColor(shadowAttenuation,
|
||||||
+ evalDirectionalColor(shadowAttenuation,
|
|
||||||
frag.position.xyz,
|
frag.position.xyz,
|
||||||
frag.normal,
|
frag.normal,
|
||||||
frag.diffuse,
|
frag.diffuse,
|
||||||
|
|
|
@ -33,6 +33,7 @@ void main(void) {
|
||||||
|
|
||||||
// and the texture coordinates
|
// and the texture coordinates
|
||||||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||||
|
// interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0)).xy;
|
||||||
interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.0, 1.0)).xy;
|
interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.0, 1.0)).xy;
|
||||||
|
|
||||||
// use standard pipeline transform
|
// use standard pipeline transform
|
||||||
|
|
|
@ -15,41 +15,61 @@
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
// the radius (hard cutoff) of the light effect
|
//Everything about deferred lighting
|
||||||
uniform float radius;
|
<@include DeferredLighting.slh@>
|
||||||
|
|
||||||
|
// Everything about light
|
||||||
|
<@include Light.slh@>
|
||||||
|
|
||||||
|
// The view Matrix
|
||||||
|
uniform mat4 invViewMat;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
// get the depth and exit early if it doesn't pass the test
|
// Grab the fragment data from the uv
|
||||||
vec2 texCoord = gl_TexCoord[0].st / gl_TexCoord[0].q;
|
vec2 texCoord = gl_TexCoord[0].st / gl_TexCoord[0].q;
|
||||||
float depth = texture2D(depthMap, texCoord).r;
|
DeferredFragment frag = unpackDeferredFragment(texCoord);
|
||||||
|
|
||||||
|
// Kill if in front of the light volume
|
||||||
|
float depth = frag.depthVal;
|
||||||
if (depth < gl_FragCoord.z) {
|
if (depth < gl_FragCoord.z) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
// compute the view space position using the depth
|
|
||||||
float z = near / (depth * depthScale - 1.0);
|
|
||||||
vec4 position = vec4((depthTexCoordOffset + texCoord * depthTexCoordScale) * z, z, 1.0);
|
|
||||||
|
|
||||||
// get the normal from the map
|
// Need the light now
|
||||||
vec4 normal = texture2D(normalMap, texCoord);
|
Light light = getLight();
|
||||||
vec4 normalizedNormal = normalize(normal * 2.0 - vec4(1.0, 1.0, 1.0, 2.0));
|
|
||||||
|
|
||||||
// compute the base color based on OpenGL lighting model
|
// Make the Light vector going from fragment to light center in world space
|
||||||
vec4 lightVector = gl_LightSource[1].position - position;
|
vec4 fragPos = invViewMat * frag.position;
|
||||||
float lightDistance = length(lightVector);
|
vec3 fragLightVec = getLightPosition(light) - fragPos.xyz;
|
||||||
lightVector = lightVector / lightDistance;
|
|
||||||
float diffuse = dot(normalizedNormal, lightVector);
|
|
||||||
float facingLight = step(0.0, diffuse);
|
|
||||||
vec4 baseColor = texture2D(diffuseMap, texCoord) * (gl_FrontLightProduct[1].ambient +
|
|
||||||
gl_FrontLightProduct[1].diffuse * (diffuse * facingLight));
|
|
||||||
|
|
||||||
// compute attenuation based on distance, etc.
|
// Kill if too far from the light center
|
||||||
float attenuation = step(lightDistance, radius) / dot(vec3(gl_LightSource[1].constantAttenuation,
|
if (dot(fragLightVec, fragLightVec) > getLightSquareRadius(light)) {
|
||||||
gl_LightSource[1].linearAttenuation, gl_LightSource[1].quadraticAttenuation),
|
discard;
|
||||||
vec3(1.0, lightDistance, lightDistance * lightDistance));
|
}
|
||||||
|
|
||||||
// add base to specular, modulate by attenuation
|
// Allright we re valid in the volume
|
||||||
float specular = facingLight * max(0.0, dot(normalize(lightVector - normalize(vec4(position.xyz, 0.0))),
|
float fragLightDistance = length(fragLightVec);
|
||||||
normalizedNormal));
|
vec3 fragLightDir = fragLightVec / fragLightDistance;
|
||||||
vec4 specularColor = texture2D(specularMap, texCoord);
|
|
||||||
gl_FragColor = vec4((baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb) * attenuation, 0.0);
|
// Eval shading
|
||||||
|
vec3 fragNormal = vec3(invViewMat * vec4(frag.normal, 0.0));
|
||||||
|
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
|
||||||
|
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
||||||
|
vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.specular, frag.gloss);
|
||||||
|
|
||||||
|
// Eval attenuation
|
||||||
|
float radialAttenuation = evalLightAttenuation(light, fragLightDistance);
|
||||||
|
|
||||||
|
// Final Lighting color
|
||||||
|
vec3 fragColor = shading.w * (frag.diffuse + shading.xyz);
|
||||||
|
gl_FragColor = vec4(fragColor * radialAttenuation * getLightColor(light) * getLightIntensity(light), 0.0);
|
||||||
|
|
||||||
|
if (getLightShowContour(light) > 0.0) {
|
||||||
|
// Show edge
|
||||||
|
float edge = abs(2.0 * ((getLightRadius(light) - fragLightDistance) / (0.1)) - 1.0);
|
||||||
|
if (edge < 1) {
|
||||||
|
float edgeCoord = exp2(-8.0*edge*edge);
|
||||||
|
gl_FragColor = vec4(edgeCoord * edgeCoord * getLightShowContour(light) * getLightColor(light), 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,43 +15,73 @@
|
||||||
// Everything about deferred buffer
|
// Everything about deferred buffer
|
||||||
<@include DeferredBuffer.slh@>
|
<@include DeferredBuffer.slh@>
|
||||||
|
|
||||||
// the radius (hard cutoff) of the light effect
|
//Everything about deferred lighting
|
||||||
uniform float radius;
|
<@include DeferredLighting.slh@>
|
||||||
|
|
||||||
|
// Everything about light
|
||||||
|
<@include Light.slh@>
|
||||||
|
|
||||||
|
// The view Matrix
|
||||||
|
uniform mat4 invViewMat;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
// get the depth and exit early if it doesn't pass the test
|
// Grab the fragment data from the uv
|
||||||
vec2 texCoord = gl_TexCoord[0].st / gl_TexCoord[0].q;
|
vec2 texCoord = gl_TexCoord[0].st / gl_TexCoord[0].q;
|
||||||
float depth = texture2D(depthMap, texCoord).r;
|
DeferredFragment frag = unpackDeferredFragment(texCoord);
|
||||||
|
|
||||||
|
// Kill if in front of the light volume
|
||||||
|
float depth = frag.depthVal;
|
||||||
if (depth < gl_FragCoord.z) {
|
if (depth < gl_FragCoord.z) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
// compute the view space position using the depth
|
|
||||||
float z = near / (depth * depthScale - 1.0);
|
|
||||||
vec4 position = vec4((depthTexCoordOffset + texCoord * depthTexCoordScale) * z, z, 1.0);
|
|
||||||
|
|
||||||
// get the normal from the map
|
// Need the light now
|
||||||
vec4 normal = texture2D(normalMap, texCoord);
|
Light light = getLight();
|
||||||
vec4 normalizedNormal = normalize(normal * 2.0 - vec4(1.0, 1.0, 1.0, 2.0));
|
|
||||||
|
|
||||||
// compute the base color based on OpenGL lighting model
|
// Make the Light vector going from fragment to light center in world space
|
||||||
vec4 lightVector = gl_LightSource[1].position - position;
|
vec4 fragPos = invViewMat * frag.position;
|
||||||
float lightDistance = length(lightVector);
|
vec3 fragLightVec = getLightPosition(light) - fragPos.xyz;
|
||||||
lightVector = lightVector / lightDistance;
|
|
||||||
float diffuse = dot(normalizedNormal, lightVector);
|
|
||||||
float facingLight = step(0.0, diffuse);
|
|
||||||
vec4 baseColor = texture2D(diffuseMap, texCoord) * (gl_FrontLightProduct[1].ambient +
|
|
||||||
gl_FrontLightProduct[1].diffuse * (diffuse * facingLight));
|
|
||||||
|
|
||||||
// compute attenuation based on spot angle, distance, etc.
|
// Kill if too far from the light center
|
||||||
float cosSpotAngle = max(-dot(lightVector.xyz, gl_LightSource[1].spotDirection), 0.0);
|
if (dot(fragLightVec, fragLightVec) > getLightSquareRadius(light)) {
|
||||||
float attenuation = step(lightDistance, radius) * step(gl_LightSource[1].spotCosCutoff, cosSpotAngle) *
|
discard;
|
||||||
pow(cosSpotAngle, gl_LightSource[1].spotExponent) / dot(vec3(gl_LightSource[1].constantAttenuation,
|
}
|
||||||
gl_LightSource[1].linearAttenuation, gl_LightSource[1].quadraticAttenuation),
|
|
||||||
vec3(1.0, lightDistance, lightDistance * lightDistance));
|
|
||||||
|
|
||||||
// add base to specular, modulate by attenuation
|
// Allright we re valid in the volume
|
||||||
float specular = facingLight * max(0.0, dot(normalize(lightVector - normalize(vec4(position.xyz, 0.0))),
|
float fragLightDistance = length(fragLightVec);
|
||||||
normalizedNormal));
|
vec3 fragLightDir = fragLightVec / fragLightDistance;
|
||||||
vec4 specularColor = texture2D(specularMap, texCoord);
|
|
||||||
gl_FragColor = vec4((baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb) * attenuation, 0.0);
|
// Kill if not in the spot light (ah ah !)
|
||||||
|
vec3 lightSpotDir = getLightDirection(light);
|
||||||
|
float cosSpotAngle = max(-dot(fragLightDir, lightSpotDir), 0.0);
|
||||||
|
if (cosSpotAngle < getLightSpotAngleCos(light)) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eval shading
|
||||||
|
vec3 fragNormal = vec3(invViewMat * vec4(frag.normal, 0.0));
|
||||||
|
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
|
||||||
|
vec3 fragEyeDir = normalize(fragEyeVector.xyz);
|
||||||
|
vec4 shading = evalFragShading(fragNormal, fragLightDir, fragEyeDir, frag.specular, frag.gloss);
|
||||||
|
|
||||||
|
// Eval attenuation
|
||||||
|
float radialAttenuation = evalLightAttenuation(light, fragLightDistance);
|
||||||
|
float angularAttenuation = evalLightSpotAttenuation(light, cosSpotAngle);
|
||||||
|
|
||||||
|
// Final Lighting color
|
||||||
|
vec3 fragColor = shading.w * (frag.diffuse + shading.xyz);
|
||||||
|
gl_FragColor = vec4(fragColor * angularAttenuation * radialAttenuation * getLightColor(light) * getLightIntensity(light), 0.0);
|
||||||
|
|
||||||
|
if (getLightShowContour(light) > 0.0) {
|
||||||
|
// Show edges
|
||||||
|
float edgeDistR = (getLightRadius(light) - fragLightDistance);
|
||||||
|
float edgeDistS = dot(fragLightDistance * vec2(cosSpotAngle, sqrt(1.0 - cosSpotAngle * cosSpotAngle)), -getLightSpotOutsideNormal2(light));
|
||||||
|
float edgeDist = min(edgeDistR, edgeDistS);
|
||||||
|
float edge = abs(2.0 * (edgeDist / (0.1)) - 1.0);
|
||||||
|
if (edge < 1) {
|
||||||
|
float edgeCoord = exp2(-8.0*edge*edge);
|
||||||
|
gl_FragColor = vec4(edgeCoord * edgeCoord * getLightColor(light), 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,18 +31,15 @@ AudioScriptingInterface::AudioScriptingInterface() :
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptAudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions& injectorOptions) {
|
ScriptAudioInjector* AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions& injectorOptions) {
|
||||||
AudioInjector* injector = NULL;
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "invokedPlaySound", Qt::BlockingQueuedConnection,
|
ScriptAudioInjector* injector = NULL;
|
||||||
Q_RETURN_ARG(AudioInjector*, injector),
|
|
||||||
Q_ARG(Sound*, sound), Q_ARG(const AudioInjectorOptions&, injectorOptions));
|
QMetaObject::invokeMethod(this, "playSound", Qt::BlockingQueuedConnection,
|
||||||
if (injector) {
|
Q_RETURN_ARG(ScriptAudioInjector*, injector),
|
||||||
return new ScriptAudioInjector(injector);
|
Q_ARG(Sound*, sound), Q_ARG(const AudioInjectorOptions&, injectorOptions));
|
||||||
} else {
|
return injector;
|
||||||
return NULL;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioInjector* AudioScriptingInterface::invokedPlaySound(Sound* sound, const AudioInjectorOptions& injectorOptions) {
|
|
||||||
if (sound) {
|
if (sound) {
|
||||||
// stereo option isn't set from script, this comes from sound metadata or filename
|
// stereo option isn't set from script, this comes from sound metadata or filename
|
||||||
AudioInjectorOptions optionsCopy = injectorOptions;
|
AudioInjectorOptions optionsCopy = injectorOptions;
|
||||||
|
@ -65,7 +62,7 @@ AudioInjector* AudioScriptingInterface::invokedPlaySound(Sound* sound, const Aud
|
||||||
|
|
||||||
injectorThread->start();
|
injectorThread->start();
|
||||||
|
|
||||||
return injector;
|
return new ScriptAudioInjector(injector);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "AudioScriptingInterface::playSound called with null Sound object.";
|
qDebug() << "AudioScriptingInterface::playSound called with null Sound object.";
|
||||||
|
|
|
@ -33,9 +33,6 @@ signals:
|
||||||
void mutedByMixer();
|
void mutedByMixer();
|
||||||
void environmentMuted();
|
void environmentMuted();
|
||||||
|
|
||||||
private slots:
|
|
||||||
AudioInjector* invokedPlaySound(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AudioScriptingInterface();
|
AudioScriptingInterface();
|
||||||
AbstractAudioInterface* _localAudioInterface;
|
AbstractAudioInterface* _localAudioInterface;
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
|
|
||||||
QScriptValue injectorToScriptValue(QScriptEngine* engine, ScriptAudioInjector* const& in) {
|
QScriptValue injectorToScriptValue(QScriptEngine* engine, ScriptAudioInjector* const& in) {
|
||||||
// when the script goes down we want to cleanup the injector
|
// when the script goes down we want to cleanup the injector
|
||||||
QObject::connect(engine, &QScriptEngine::destroyed, in, &ScriptAudioInjector::stopInjectorImmediately);
|
|
||||||
|
QObject::connect(engine, &QScriptEngine::destroyed, in, &ScriptAudioInjector::stopInjectorImmediately,
|
||||||
|
Qt::DirectConnection);
|
||||||
|
|
||||||
return engine->newQObject(in, QScriptEngine::ScriptOwnership);
|
return engine->newQObject(in, QScriptEngine::ScriptOwnership);
|
||||||
}
|
}
|
||||||
|
@ -36,5 +38,6 @@ ScriptAudioInjector::~ScriptAudioInjector() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptAudioInjector::stopInjectorImmediately() {
|
void ScriptAudioInjector::stopInjectorImmediately() {
|
||||||
|
qDebug() << "ScriptAudioInjector::stopInjectorImmediately called to stop audio injector immediately.";
|
||||||
_injector->stopAndDeleteLater();
|
_injector->stopAndDeleteLater();
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,8 +272,12 @@ QScriptValue ScriptEngine::registerGlobalObject(const QString& name, QObject* ob
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::registerFunction(const QString& name, QScriptEngine::FunctionSignature fun, int numArguments) {
|
void ScriptEngine::registerFunction(const QString& name, QScriptEngine::FunctionSignature fun, int numArguments) {
|
||||||
|
registerFunction(globalObject(), name, fun, numArguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptEngine::registerFunction(QScriptValue parent, const QString& name, QScriptEngine::FunctionSignature fun, int numArguments) {
|
||||||
QScriptValue scriptFun = newFunction(fun, numArguments);
|
QScriptValue scriptFun = newFunction(fun, numArguments);
|
||||||
globalObject().setProperty(name, scriptFun);
|
parent.setProperty(name, scriptFun);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter,
|
void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter,
|
||||||
|
|
|
@ -58,6 +58,8 @@ public:
|
||||||
void registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter,
|
void registerGetterSetter(const QString& name, QScriptEngine::FunctionSignature getter,
|
||||||
QScriptEngine::FunctionSignature setter, QScriptValue object = QScriptValue::NullValue);
|
QScriptEngine::FunctionSignature setter, QScriptValue object = QScriptValue::NullValue);
|
||||||
void registerFunction(const QString& name, QScriptEngine::FunctionSignature fun, int numArguments = -1);
|
void registerFunction(const QString& name, QScriptEngine::FunctionSignature fun, int numArguments = -1);
|
||||||
|
void registerFunction(QScriptValue parent, const QString& name, QScriptEngine::FunctionSignature fun,
|
||||||
|
int numArguments = -1);
|
||||||
|
|
||||||
Q_INVOKABLE void setIsAvatar(bool isAvatar);
|
Q_INVOKABLE void setIsAvatar(bool isAvatar);
|
||||||
bool isAvatar() const { return _isAvatar; }
|
bool isAvatar() const { return _isAvatar; }
|
||||||
|
|
|
@ -100,6 +100,8 @@ public:
|
||||||
// Left will be inversed before the multiplication
|
// Left will be inversed before the multiplication
|
||||||
static Transform& inverseMult(Transform& result, const Transform& left, const Transform& right);
|
static Transform& inverseMult(Transform& result, const Transform& left, const Transform& right);
|
||||||
|
|
||||||
|
Vec4 transform(const Vec4& pos) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
enum Flag {
|
enum Flag {
|
||||||
|
@ -414,6 +416,13 @@ inline Transform& Transform::inverseMult( Transform& result, const Transform& le
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Transform::Vec4 Transform::transform(const Vec4& pos) const {
|
||||||
|
Mat4 m;
|
||||||
|
getMatrix(m);
|
||||||
|
return m * pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Transform::Mat4& Transform::getCachedMatrix(Transform::Mat4& result) const {
|
inline Transform::Mat4& Transform::getCachedMatrix(Transform::Mat4& result) const {
|
||||||
updateCache();
|
updateCache();
|
||||||
result = (*_matrix);
|
result = (*_matrix);
|
||||||
|
|
|
@ -219,14 +219,14 @@ static QScriptValue createRandomScriptValue(bool complex = false, bool ensureHas
|
||||||
|
|
||||||
case 4: {
|
case 4: {
|
||||||
int length = randIntInRange(2, 6);
|
int length = randIntInRange(2, 6);
|
||||||
QScriptValue value = ScriptCache::getInstance()->getEngine()->newArray(length);
|
QScriptValue value = DependencyManager::get<ScriptCache>()->getEngine()->newArray(length);
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
value.setProperty(i, createRandomScriptValue());
|
value.setProperty(i, createRandomScriptValue());
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
QScriptValue value = ScriptCache::getInstance()->getEngine()->newObject();
|
QScriptValue value = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
|
||||||
if (ensureHashOrder) {
|
if (ensureHashOrder) {
|
||||||
// we can't depend on the iteration order, so if we need it to be the same (as when comparing bytes), we
|
// we can't depend on the iteration order, so if we need it to be the same (as when comparing bytes), we
|
||||||
// can only have one property
|
// can only have one property
|
||||||
|
@ -747,7 +747,7 @@ static SharedObjectPointer mutate(const SharedObjectPointer& state) {
|
||||||
case 3: {
|
case 3: {
|
||||||
SharedObjectPointer newState = state->clone(true);
|
SharedObjectPointer newState = state->clone(true);
|
||||||
QScriptValue oldValue = static_cast<TestSharedObjectA*>(newState.data())->getBizzle();
|
QScriptValue oldValue = static_cast<TestSharedObjectA*>(newState.data())->getBizzle();
|
||||||
QScriptValue newValue = ScriptCache::getInstance()->getEngine()->newObject();
|
QScriptValue newValue = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
|
||||||
for (QScriptValueIterator it(oldValue); it.hasNext(); ) {
|
for (QScriptValueIterator it(oldValue); it.hasNext(); ) {
|
||||||
it.next();
|
it.next();
|
||||||
newValue.setProperty(it.scriptName(), it.value());
|
newValue.setProperty(it.scriptName(), it.value());
|
||||||
|
@ -755,8 +755,8 @@ static SharedObjectPointer mutate(const SharedObjectPointer& state) {
|
||||||
switch (randIntInRange(0, 2)) {
|
switch (randIntInRange(0, 2)) {
|
||||||
case 0: {
|
case 0: {
|
||||||
QScriptValue oldArray = oldValue.property("foo");
|
QScriptValue oldArray = oldValue.property("foo");
|
||||||
int oldLength = oldArray.property(ScriptCache::getInstance()->getLengthString()).toInt32();
|
int oldLength = oldArray.property(DependencyManager::get<ScriptCache>()->getLengthString()).toInt32();
|
||||||
QScriptValue newArray = ScriptCache::getInstance()->getEngine()->newArray(oldLength);
|
QScriptValue newArray = DependencyManager::get<ScriptCache>()->getEngine()->newArray(oldLength);
|
||||||
for (int i = 0; i < oldLength; i++) {
|
for (int i = 0; i < oldLength; i++) {
|
||||||
newArray.setProperty(i, oldArray.property(i));
|
newArray.setProperty(i, oldArray.property(i));
|
||||||
}
|
}
|
||||||
|
@ -1203,8 +1203,8 @@ TestSharedObjectA::TestSharedObjectA(float foo, TestEnum baz, TestFlags bong) :
|
||||||
_bong(bong) {
|
_bong(bong) {
|
||||||
sharedObjectsCreated++;
|
sharedObjectsCreated++;
|
||||||
|
|
||||||
_bizzle = ScriptCache::getInstance()->getEngine()->newObject();
|
_bizzle = DependencyManager::get<ScriptCache>()->getEngine()->newObject();
|
||||||
_bizzle.setProperty("foo", ScriptCache::getInstance()->getEngine()->newArray(4));
|
_bizzle.setProperty("foo", DependencyManager::get<ScriptCache>()->getEngine()->newArray(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
TestSharedObjectA::~TestSharedObjectA() {
|
TestSharedObjectA::~TestSharedObjectA() {
|
||||||
|
|
Loading…
Reference in a new issue