Merge branch 'master' of https://github.com/highfidelity/hifi into add_interface_to_log_user_activity

This commit is contained in:
Atlante45 2014-06-30 14:30:17 -07:00
commit ff8694d5c5
37 changed files with 787 additions and 103 deletions

View file

@ -63,7 +63,7 @@ If `libgnutls28-dev` 3.2.12 or higher is available via your package manager, it
[Homebrew](http://brew.sh/) is an excellent package manager for OS X. It makes install of all hifi dependencies very simple.
brew tap highfidelity/homebrew-formulas
brew install cmake glm zlib gnutls
brew install cmake glm gnutls
brew install highfidelity/formulas/qt5
brew link qt5 --force
brew install highfidelity/formulas/qxmpp

View file

@ -213,8 +213,6 @@ void Agent::run() {
loop.exec();
// let the AvatarData and ResourceCache classes use our QNetworkAccessManager
AvatarData::setNetworkAccessManager(networkManager);
ResourceCache::setNetworkAccessManager(networkManager);

View file

@ -38,6 +38,9 @@
#include <QtCore/QJsonObject>
#include <QtCore/QJsonValue>
#include <QtCore/QTimer>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <Logging.h>
#include <NodeList.h>
@ -478,40 +481,81 @@ void AudioMixer::run() {
nodeList->linkedDataCreateCallback = attachNewBufferToNode;
// check the payload to see if we have any unattenuated zones
const QString UNATTENUATED_ZONE_REGEX_STRING = "--unattenuated-zone ([\\d.,-]+)";
QRegExp unattenuatedZoneMatch(UNATTENUATED_ZONE_REGEX_STRING);
// setup a QNetworkAccessManager to ask the domain-server for our settings
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
if (unattenuatedZoneMatch.indexIn(_payload) != -1) {
QString unattenuatedZoneString = unattenuatedZoneMatch.cap(1);
QStringList zoneStringList = unattenuatedZoneString.split(',');
QUrl settingsJSONURL;
settingsJSONURL.setScheme("http");
settingsJSONURL.setHost(nodeList->getDomainHandler().getHostname());
settingsJSONURL.setPort(DOMAIN_SERVER_HTTP_PORT);
settingsJSONURL.setPath("/settings.json");
settingsJSONURL.setQuery(QString("type=%1").arg(_type));
QNetworkReply *reply = NULL;
int failedAttempts = 0;
const int MAX_SETTINGS_REQUEST_FAILED_ATTEMPTS = 5;
qDebug() << "Requesting settings for assignment from domain-server at" << settingsJSONURL.toString();
while (!reply || reply->error() != QNetworkReply::NoError) {
reply = networkManager->get(QNetworkRequest(settingsJSONURL));
glm::vec3 sourceCorner(zoneStringList[0].toFloat(), zoneStringList[1].toFloat(), zoneStringList[2].toFloat());
glm::vec3 sourceDimensions(zoneStringList[3].toFloat(), zoneStringList[4].toFloat(), zoneStringList[5].toFloat());
glm::vec3 listenerCorner(zoneStringList[6].toFloat(), zoneStringList[7].toFloat(), zoneStringList[8].toFloat());
glm::vec3 listenerDimensions(zoneStringList[9].toFloat(), zoneStringList[10].toFloat(), zoneStringList[11].toFloat());
QEventLoop loop;
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
_sourceUnattenuatedZone = new AABox(sourceCorner, sourceDimensions);
_listenerUnattenuatedZone = new AABox(listenerCorner, listenerDimensions);
loop.exec();
glm::vec3 sourceCenter = _sourceUnattenuatedZone->calcCenter();
glm::vec3 destinationCenter = _listenerUnattenuatedZone->calcCenter();
++failedAttempts;
qDebug() << "There is an unattenuated zone with source center at"
<< QString("%1, %2, %3").arg(sourceCenter.x).arg(sourceCenter.y).arg(sourceCenter.z);
qDebug() << "Buffers inside this zone will not be attenuated inside a box with center at"
<< QString("%1, %2, %3").arg(destinationCenter.x).arg(destinationCenter.y).arg(destinationCenter.z);
if (failedAttempts == MAX_SETTINGS_REQUEST_FAILED_ATTEMPTS) {
qDebug() << "Failed to get settings from domain-server. Bailing on assignment.";
setFinished(true);
return;
}
}
// check the payload to see if we have asked for dynamicJitterBuffer support
const QString DYNAMIC_JITTER_BUFFER_REGEX_STRING = "--dynamicJitterBuffer";
QRegExp dynamicJitterBufferMatch(DYNAMIC_JITTER_BUFFER_REGEX_STRING);
if (dynamicJitterBufferMatch.indexIn(_payload) != -1) {
qDebug() << "Enable dynamic jitter buffers.";
_useDynamicJitterBuffers = true;
} else {
qDebug() << "Dynamic jitter buffers disabled, using old behavior.";
QJsonObject settingsObject = QJsonDocument::fromJson(reply->readAll()).object();
// check the settings object to see if we have anything we can parse out
const QString AUDIO_GROUP_KEY = "audio";
if (settingsObject.contains(AUDIO_GROUP_KEY)) {
QJsonObject audioGroupObject = settingsObject[AUDIO_GROUP_KEY].toObject();
const QString UNATTENUATED_ZONE_KEY = "unattenuated-zone";
QString unattenuatedZoneString = audioGroupObject[UNATTENUATED_ZONE_KEY].toString();
if (!unattenuatedZoneString.isEmpty()) {
QStringList zoneStringList = unattenuatedZoneString.split(',');
glm::vec3 sourceCorner(zoneStringList[0].toFloat(), zoneStringList[1].toFloat(), zoneStringList[2].toFloat());
glm::vec3 sourceDimensions(zoneStringList[3].toFloat(), zoneStringList[4].toFloat(), zoneStringList[5].toFloat());
glm::vec3 listenerCorner(zoneStringList[6].toFloat(), zoneStringList[7].toFloat(), zoneStringList[8].toFloat());
glm::vec3 listenerDimensions(zoneStringList[9].toFloat(), zoneStringList[10].toFloat(), zoneStringList[11].toFloat());
_sourceUnattenuatedZone = new AABox(sourceCorner, sourceDimensions);
_listenerUnattenuatedZone = new AABox(listenerCorner, listenerDimensions);
glm::vec3 sourceCenter = _sourceUnattenuatedZone->calcCenter();
glm::vec3 destinationCenter = _listenerUnattenuatedZone->calcCenter();
qDebug() << "There is an unattenuated zone with source center at"
<< QString("%1, %2, %3").arg(sourceCenter.x).arg(sourceCenter.y).arg(sourceCenter.z);
qDebug() << "Buffers inside this zone will not be attenuated inside a box with center at"
<< QString("%1, %2, %3").arg(destinationCenter.x).arg(destinationCenter.y).arg(destinationCenter.z);
}
// check the payload to see if we have asked for dynamicJitterBuffer support
const QString DYNAMIC_JITTER_BUFFER_JSON_KEY = "dynamic-jitter-buffer";
bool shouldUseDynamicJitterBuffers = audioGroupObject[DYNAMIC_JITTER_BUFFER_JSON_KEY].toBool();
if (shouldUseDynamicJitterBuffers) {
qDebug() << "Enable dynamic jitter buffers.";
_useDynamicJitterBuffers = true;
} else {
qDebug() << "Dynamic jitter buffers disabled, using old behavior.";
}
}
int nextFrame = 0;

View file

@ -1,8 +1,8 @@
#nodes-lead {
#nodes-lead, #settings-lead {
color: #66CCCC;
}
#nodes-lead .lead-line {
#nodes-lead .lead-line, #settings-lead .lead-line {
background-color: #66CCCC;
}

View file

@ -18,7 +18,20 @@
</tr>
</thead>
<tbody>
</tbody>
<script id="nodes-template" type="text/template">
<% _.each(nodes, function(node, node_index){ %>
<tr>
<td><%- node.type %></td>
<td><a href="stats/?uuid=<%- node.uuid %>"><%- node.uuid %></a></td>
<td><%- node.pool %></td>
<td><%- node.public.ip %><span class='port'><%- node.public.port %></span></td>
<td><%- node.local.ip %><span class='port'><%- node.local.port %></span></td>
<td><%- ((Date.now() - node.wake_timestamp) / 1000).toLocaleString() %></td>
<td><%- (typeof node.pending_credits == 'number' ? node.pending_credits.toLocaleString() : 'N/A') %></td>
<td><span class='glyphicon glyphicon-remove' data-uuid="<%- node.uuid %>"></span></td>
</tr>
<% }); %>
</script>
</table>
<div id="queued-lead" class="table-lead"><h3>Queued Assignments</h3><div class="lead-line"></div></div>
@ -31,8 +44,18 @@
</tr>
</thead>
<tbody>
<script id="queued-template" type="text/template">
<% _.each(queued, function(assignment, uuid){ %>
<tr>
<td><%- assignment.type %></td>
<td><%- uuid %></td>
<td><%- assignment.pool %></td>
</tr>
<% }); %>
</script>
</tbody>
</table>
<!--#include file="footer.html"-->
<script src='js/tables.js'></script>
<script src='js/underscore-1.5.0.min.js'></script>
<!--#include file="page-end.html"-->

26
domain-server/resources/web/js/form2js.min.js vendored Executable file
View file

@ -0,0 +1,26 @@
/**
* Copyright (c) 2010 Maxim Vasiliev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author Maxim Vasiliev
* Date: 09.09.2010
* Time: 19:02:33
*/
(function(e,t){if(typeof define==="function"&&define.amd){define(t)}else{e.form2js=t()}})(this,function(){"use strict";function e(e,r,i,s,o,u){u=u?true:false;if(typeof i=="undefined"||i==null)i=true;if(typeof r=="undefined"||r==null)r=".";if(arguments.length<5)o=false;e=typeof e=="string"?document.getElementById(e):e;var a=[],f,l=0;if(e.constructor==Array||typeof NodeList!="undefined"&&e.constructor==NodeList){while(f=e[l++]){a=a.concat(n(f,s,o,u))}}else{a=n(e,s,o,u)}return t(a,i,r)}function t(e,t,n){var r={},i={},s,o,u,a,f,l,c,h,p,d,v,m,g;for(s=0;s<e.length;s++){f=e[s].value;if(t&&(f===""||f===null))continue;m=e[s].name;g=m.split(n);l=[];c=r;h="";for(o=0;o<g.length;o++){v=g[o].split("][");if(v.length>1){for(u=0;u<v.length;u++){if(u==0){v[u]=v[u]+"]"}else if(u==v.length-1){v[u]="["+v[u]}else{v[u]="["+v[u]+"]"}d=v[u].match(/([a-z_]+)?\[([a-z_][a-z0-9_]+?)\]/i);if(d){for(a=1;a<d.length;a++){if(d[a])l.push(d[a])}}else{l.push(v[u])}}}else l=l.concat(v)}for(o=0;o<l.length;o++){v=l[o];if(v.indexOf("[]")>-1&&o==l.length-1){p=v.substr(0,v.indexOf("["));h+=p;if(!c[p])c[p]=[];c[p].push(f)}else if(v.indexOf("[")>-1){p=v.substr(0,v.indexOf("["));d=v.replace(/(^([a-z_]+)?\[)|(\]$)/gi,"");h+="_"+p+"_"+d;if(!i[h])i[h]={};if(p!=""&&!c[p])c[p]=[];if(o==l.length-1){if(p==""){c.push(f);i[h][d]=c[c.length-1]}else{c[p].push(f);i[h][d]=c[p][c[p].length-1]}}else{if(!i[h][d]){if(/^[0-9a-z_]+\[?/i.test(l[o+1]))c[p].push({});else c[p].push([]);i[h][d]=c[p][c[p].length-1]}}c=i[h][d]}else{h+=v;if(o<l.length-1){if(!c[v])c[v]={};c=c[v]}else{c[v]=f}}}}return r}function n(e,t,n,s){var o=i(e,t,n,s);return o.length>0?o:r(e,t,n,s)}function r(e,t,n,r){var s=[],o=e.firstChild;while(o){s=s.concat(i(o,t,n,r));o=o.nextSibling}return s}function i(e,t,n,i){if(e.disabled&&!i)return[];var u,a,f,l=s(e,n);u=t&&t(e);if(u&&u.name){f=[u]}else if(l!=""&&e.nodeName.match(/INPUT|TEXTAREA/i)){a=o(e,i);if(null===a){f=[]}else{f=[{name:l,value:a}]}}else if(l!=""&&e.nodeName.match(/SELECT/i)){a=o(e,i);f=[{name:l.replace(/\[\]$/,""),value:a}]}else{f=r(e,t,n,i)}return f}function s(e,t){if(e.name&&e.name!="")return e.name;else if(t&&e.id&&e.id!="")return e.id;else return""}function o(e,t){if(e.disabled&&!t)return null;switch(e.nodeName){case"INPUT":case"TEXTAREA":switch(e.type.toLowerCase()){case"radio":if(e.checked&&e.value==="false")return false;case"checkbox":if(e.checked&&e.value==="true")return true;if(!e.checked&&e.value==="true")return false;if(e.checked)return e.value;break;case"button":case"reset":case"submit":case"image":return"";break;default:return e.value;break}break;case"SELECT":return u(e);break;default:break}return null}function u(e){var t=e.multiple,n=[],r,i,s;if(!t)return e.value;for(r=e.getElementsByTagName("option"),i=0,s=r.length;i<s;i++){if(r[i].selected)n.push(r[i].value)}return n}return e})

View file

@ -0,0 +1,72 @@
var Settings = {};
$(document).ready(function(){
var source = $('#settings-template').html();
Settings.template = _.template(source);
reloadSettings();
});
function reloadSettings() {
$.getJSON('/settings.json', function(data){
$('#settings').html(Settings.template(data));
});
}
var SETTINGS_ERROR_MESSAGE = "There was a problem saving domain settings. Please try again!";
$('#settings').on('click', 'button', function(e){
// disable any inputs not changed
$("input:not([data-changed])").each(function(){
$(this).prop('disabled', true);
});
// grab a JSON representation of the form via form2js
var formJSON = form2js('settings-form', ".", false, cleanupFormValues, true);
// re-enable all inputs
$("input").each(function(){
$(this).prop('disabled', false);
});
// POST the form JSON to the domain-server settings.json endpoint so the settings are saved
$.ajax('/settings.json', {
data: JSON.stringify(formJSON),
contentType: 'application/json',
type: 'POST'
}).done(function(data){
if (data.status == "success") {
showAlertMessage("Domain settings saved.", true);
} else {
showAlertMessage(SETTINGS_ERROR_MESSAGE, false);
}
reloadSettings();
}).fail(function(){
showAlertMessage(SETTINGS_ERROR_MESSAGE, false);
reloadSettings();
});
return false;
});
$('#settings').on('change', 'input', function(){
// this input was changed, add the changed data attribute to it
$(this).attr('data-changed', true);
});
function cleanupFormValues(node) {
if (node.type && node.type === 'checkbox') {
return { name: node.id, value: node.checked ? true : false };
} else {
return false;
}
}
function showAlertMessage(message, isSuccess) {
var alertBox = $('.alert');
alertBox.attr('class', 'alert');
alertBox.addClass(isSuccess ? 'alert-success' : 'alert-danger');
alertBox.html(message);
alertBox.fadeIn();
}

View file

@ -1,4 +1,8 @@
$(document).ready(function(){
// setup the underscore templates
var nodeTemplate = _.template($('#nodes-template').html());
var queuedTemplate = _.template($('#queued-template').html());
// setup a function to grab the assignments
function getNodesAndAssignments() {
$.getJSON("nodes.json", function(json){
@ -29,40 +33,11 @@ $(document).ready(function(){
}
});
nodesTableBody = "";
$.each(json.nodes, function(index, data) {
nodesTableBody += "<tr>";
nodesTableBody += "<td>" + data.type + "</td>";
nodesTableBody += "<td><a href='stats/?uuid=" + data.uuid + "'>" + data.uuid + "</a></td>";
nodesTableBody += "<td>" + (data.pool ? data.pool : "") + "</td>";
nodesTableBody += "<td>" + data.public.ip + "<span class='port'>:" + data.public.port + "</span></td>";
nodesTableBody += "<td>" + data.local.ip + "<span class='port'>:" + data.local.port + "</span></td>";
var uptimeSeconds = (Date.now() - data.wake_timestamp) / 1000;
nodesTableBody += "<td>" + uptimeSeconds.toLocaleString() + "</td>";
nodesTableBody += "<td>" + (typeof data.pending_credits == 'number' ? data.pending_credits.toLocaleString() : 'N/A') + "</td>";
nodesTableBody += "<td><span class='glyphicon glyphicon-remove' data-uuid=" + data.uuid + "></span></td>";
nodesTableBody += "</tr>";
});
$('#nodes-table tbody').html(nodesTableBody);
$('#nodes-table tbody').html(nodeTemplate(json));
});
$.getJSON("assignments.json", function(json){
queuedTableBody = "";
$.each(json.queued, function (uuid, data) {
queuedTableBody += "<tr>";
queuedTableBody += "<td>" + data.type + "</td>";
queuedTableBody += "<td>" + uuid + "</td>";
queuedTableBody += "<td>" + (data.pool ? data.pool : "") + "</td>";
queuedTableBody += "</tr>";
});
$('#assignments-table tbody').html(queuedTableBody);
$('#assignments-table tbody').html(queuedTemplate(json));
});
}

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,20 @@
{
"audio": {
"label": "Audio",
"assignment-types": [0],
"settings": {
"unattenuated-zone": {
"label": "Unattenuated Zone",
"help": "Boxes for source and listener (corner x, corner y, corner z, size x, size y, size z, corner x, corner y, corner z, size x, size y, size z)",
"placeholder": "no zone",
"default": ""
},
"dynamic-jitter-buffer": {
"type": "checkbox",
"label": "Dynamic Jitter Buffers",
"help": "Dynamically buffer client audio based on perceived jitter in packet receipt timing",
"default": false
}
}
}
}

View file

@ -0,0 +1,46 @@
<!--#include virtual="header.html"-->
<div id="settings-lead" class="table-lead"><h3>Settings</h3><div class="lead-line"></div></div>
<div style="clear: both;"></div>
<div class="alert" style="display:none;"></div>
<form class="form-horizontal" id="settings-form" role="form">
<script id="settings-template" type="text/template">
<% _.each(descriptions, function(group, group_key){ %>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%- group.label %></h3>
</div>
<div class="panel-body">
<% _.each(group.settings, function(setting, setting_key){ %>
<div class="form-group">
<% var setting_id = group_key + "." + setting_key %>
<label for="<%- setting_id %>" class="col-sm-2 control-label"><%- setting.label %></label>
<div class="col-sm-10">
<% if(setting.type) %>
<% if (setting.type === "checkbox") { %>
<% var checked_box = (values[group_key] || {})[setting_key] || setting.default %>
<input type="checkbox" id="<%- setting_id %>" <%- checked_box ? "checked" : "" %>>
<% } else { %>
<input type="text" class="form-control" id="<%- setting_id %>"
placeholder="<%- setting.placeholder %>"
value="<%- (values[group_key] || {})[setting_key] %>">
<% } %>
</div>
<p class="help-block col-sm-offset-2 col-sm-10"><%- setting.help %></p>
</div>
<% }); %>
</div>
</div>
<% }); %>
<button type="submit" class="btn btn-default">Save</button>
</script>
<div id="settings"></div>
</form>
<!--#include virtual="footer.html"-->
<script src='/js/settings.js'></script>
<script src='/js/form2js.min.js'></script>
<script src='/js/underscore-1.5.0.min.js'></script>
<!--#include virtual="page-end.html"-->

View file

@ -41,7 +41,8 @@ DomainServer::DomainServer(int argc, char* argv[]) :
_oauthClientID(),
_hostname(),
_networkReplyUUIDMap(),
_sessionAuthenticationHash()
_sessionAuthenticationHash(),
_settingsManager()
{
setOrganizationName("High Fidelity");
setOrganizationDomain("highfidelity.io");
@ -362,7 +363,7 @@ void DomainServer::createStaticAssignmentsForType(Assignment::Type type, const Q
QString dashes = payloadKey.size() == 1 ? "-" : "--";
payloadStringList << QString("%1%2 %3").arg(dashes).arg(payloadKey).arg(jsonObject[payloadKey].toString());
}
configAssignment->setPayload(payloadStringList.join(' ').toUtf8());
addStaticAssignmentToAssignmentHash(configAssignment);
@ -1162,12 +1163,13 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
}
}
// didn't process the request, let the HTTPManager try and handle
return false;
// didn't process the request, let our DomainServerSettingsManager or HTTPManager handle
return _settingsManager.handleHTTPRequest(connection, url);
}
bool DomainServer::handleHTTPSRequest(HTTPSConnection* connection, const QUrl &url) {
const QString URI_OAUTH = "/oauth";
qDebug() << "HTTPS request received at" << url.toString();
if (url.path() == URI_OAUTH) {
QUrlQuery codeURLQuery(url);

View file

@ -24,6 +24,7 @@
#include <HTTPSConnection.h>
#include <LimitedNodeList.h>
#include "DomainServerSettingsManager.h"
#include "WalletTransaction.h"
#include "PendingAssignedNodeData.h"
@ -110,6 +111,8 @@ private:
QString _hostname;
QMap<QNetworkReply*, QUuid> _networkReplyUUIDMap;
QHash<QUuid, bool> _sessionAuthenticationHash;
DomainServerSettingsManager _settingsManager;
};
#endif // hifi_DomainServer_h

View file

@ -0,0 +1,179 @@
//
// DomainServerSettingsManager.cpp
// domain-server/src
//
// Created by Stephen Birarda on 2014-06-24.
// 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 <QtCore/QCoreApplication>
#include <QtCore/QFile>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonObject>
#include <QtCore/QUrl>
#include <QtCore/QUrlQuery>
#include <Assignment.h>
#include <HTTPConnection.h>
#include "DomainServerSettingsManager.h"
const QString SETTINGS_DESCRIPTION_RELATIVE_PATH = "/resources/web/settings/describe.json";
const QString SETTINGS_CONFIG_FILE_RELATIVE_PATH = "/resources/config.json";
DomainServerSettingsManager::DomainServerSettingsManager() :
_descriptionObject(),
_settingsMap()
{
// load the description object from the settings description
QFile descriptionFile(QCoreApplication::applicationDirPath() + SETTINGS_DESCRIPTION_RELATIVE_PATH);
descriptionFile.open(QIODevice::ReadOnly);
_descriptionObject = QJsonDocument::fromJson(descriptionFile.readAll()).object();
// load the existing config file to get the current values
QFile configFile(QCoreApplication::applicationDirPath() + SETTINGS_CONFIG_FILE_RELATIVE_PATH);
configFile.open(QIODevice::ReadOnly);
_settingsMap = QJsonDocument::fromJson(configFile.readAll()).toVariant().toMap();
}
const QString DESCRIPTION_SETTINGS_KEY = "settings";
const QString SETTING_DEFAULT_KEY = "default";
bool DomainServerSettingsManager::handleHTTPRequest(HTTPConnection* connection, const QUrl &url) {
if (connection->requestOperation() == QNetworkAccessManager::PostOperation && url.path() == "/settings.json") {
// this is a POST operation to change one or more settings
QJsonDocument postedDocument = QJsonDocument::fromJson(connection->requestContent());
QJsonObject postedObject = postedDocument.object();
// we recurse one level deep below each group for the appropriate setting
recurseJSONObjectAndOverwriteSettings(postedObject, _settingsMap, _descriptionObject);
// store whatever the current _settingsMap is to file
persistToFile();
// return success to the caller
QString jsonSuccess = "{\"status\": \"success\"}";
connection->respond(HTTPConnection::StatusCode200, jsonSuccess.toUtf8(), "application/json");
return true;
} else if (connection->requestOperation() == QNetworkAccessManager::GetOperation && url.path() == "/settings.json") {
// this is a GET operation for our settings
// check if there is a query parameter for settings affecting a particular type of assignment
const QString SETTINGS_TYPE_QUERY_KEY = "type";
QUrlQuery settingsQuery(url);
QString typeValue = settingsQuery.queryItemValue(SETTINGS_TYPE_QUERY_KEY);
QJsonObject responseObject;
if (typeValue.isEmpty()) {
// combine the description object and our current settings map
responseObject["descriptions"] = _descriptionObject;
responseObject["values"] = QJsonDocument::fromVariant(_settingsMap).object();
} else {
// convert the string type value to a QJsonValue
QJsonValue queryType = QJsonValue(typeValue.toInt());
const QString AFFECTED_TYPES_JSON_KEY = "assignment-types";
// enumerate the groups in the description object to find which settings to pass
foreach(const QString& group, _descriptionObject.keys()) {
QJsonObject groupObject = _descriptionObject[group].toObject();
QJsonObject groupSettingsObject = groupObject[DESCRIPTION_SETTINGS_KEY].toObject();
QJsonObject groupResponseObject;
foreach(const QString& settingKey, groupSettingsObject.keys()) {
QJsonObject settingObject = groupSettingsObject[settingKey].toObject();
QJsonArray affectedTypesArray = settingObject[AFFECTED_TYPES_JSON_KEY].toArray();
if (affectedTypesArray.isEmpty()) {
affectedTypesArray = groupObject[AFFECTED_TYPES_JSON_KEY].toArray();
}
if (affectedTypesArray.contains(queryType)) {
// this is a setting we should include in the responseObject
// we need to check if the settings map has a value for this setting
QVariant variantValue;
QVariant settingsMapGroupValue = _settingsMap.value(group);
if (!settingsMapGroupValue.isNull()) {
variantValue = settingsMapGroupValue.toMap().value(settingKey);
}
if (variantValue.isNull()) {
// no value for this setting, pass the default
groupResponseObject[settingKey] = settingObject[SETTING_DEFAULT_KEY];
} else {
groupResponseObject[settingKey] = QJsonValue::fromVariant(variantValue);
}
}
}
if (!groupResponseObject.isEmpty()) {
// set this group's object to the constructed object
responseObject[group] = groupResponseObject;
}
}
}
connection->respond(HTTPConnection::StatusCode200, QJsonDocument(responseObject).toJson(), "application/json");
return true;
}
return false;
}
void DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJsonObject& postedObject,
QVariantMap& settingsVariant,
QJsonObject descriptionObject) {
foreach(const QString& key, postedObject.keys()) {
QJsonValue rootValue = postedObject[key];
// we don't continue if this key is not present in our descriptionObject
if (descriptionObject.contains(key)) {
if (rootValue.isString()) {
settingsVariant[key] = rootValue.toString();
} else if (rootValue.isBool()) {
settingsVariant[key] = rootValue.toBool();
} else if (rootValue.isObject()) {
// there's a JSON Object to explore, so attempt to recurse into it
QJsonObject nextDescriptionObject = descriptionObject[key].toObject();
if (nextDescriptionObject.contains(DESCRIPTION_SETTINGS_KEY)) {
if (!settingsVariant.contains(key)) {
// we don't have a map below this key yet, so set it up now
settingsVariant[key] = QVariantMap();
}
recurseJSONObjectAndOverwriteSettings(rootValue.toObject(),
*reinterpret_cast<QVariantMap*>(settingsVariant[key].data()),
nextDescriptionObject[DESCRIPTION_SETTINGS_KEY].toObject());
}
}
}
}
}
QByteArray DomainServerSettingsManager::getJSONSettingsMap() const {
return QJsonDocument::fromVariant(_settingsMap).toJson();
}
void DomainServerSettingsManager::persistToFile() {
QFile settingsFile(QCoreApplication::applicationDirPath() + SETTINGS_CONFIG_FILE_RELATIVE_PATH);
if (settingsFile.open(QIODevice::WriteOnly)) {
settingsFile.write(getJSONSettingsMap());
} else {
qCritical("Could not write to JSON settings file. Unable to persist settings.");
}
}

View file

@ -0,0 +1,35 @@
//
// DomainServerSettingsManager.h
// domain-server/src
//
// Created by Stephen Birarda on 2014-06-24.
// 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_DomainServerSettingsManager_h
#define hifi_DomainServerSettingsManager_h
#include <QtCore/QJsonDocument>
#include <HTTPManager.h>
class DomainServerSettingsManager : public QObject, HTTPRequestHandler {
Q_OBJECT
public:
DomainServerSettingsManager();
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url);
QByteArray getJSONSettingsMap() const;
private:
void recurseJSONObjectAndOverwriteSettings(const QJsonObject& postedObject, QVariantMap& settingsVariant,
QJsonObject descriptionObject);
void persistToFile();
QJsonObject _descriptionObject;
QVariantMap _settingsMap;
};
#endif // hifi_DomainServerSettingsManager_h

View file

@ -16,8 +16,8 @@ var avatarPosition;
var cameraNumber = 0;
var freeCamera = false;
var cameraLocations = [ {x: 7972.2, y: 241.6, z: 7304.1}, {x: 7973.0, y: 241.6, z: 7304.1}, {x: 7975.5, y: 241.6, z: 7304.1}, {x: 7972.3, y: 241.6, z: 7303.3}, {x: 7971.4, y: 241.6, z: 7304.3}, {x: 7973.5, y: 240.6, z: 7302.5} ];
var cameraLookAts = [ {x: 7971.1, y: 241.6, z: 7304.1}, {x: 7972.1, y: 241.6, z: 7304.1}, {x: 7972.1, y: 241.6, z: 7304.1}, {x: 7972.1, y: 241.6, z: 7304.1}, {x: 7972.1, y: 241.6, z: 7304.1}, {x: 7972.1, y: 241., z: 7304.1} ];
var cameraLocations = [ {x: 7971.9, y: 241.3, z: 7304.1}, {x: 7973.0, y: 241.3, z: 7304.1}, {x: 7975.5, y: 241.3, z: 7304.1}, {x: 7972.3, y: 241.3, z: 7303.3}, {x: 7971.0, y: 241.3, z: 7304.3}, {x: 7973.5, y: 240.7, z: 7302.5} ];
var cameraLookAts = [ {x: 7971.1, y: 241.3, z: 7304.1}, {x: 7972.1, y: 241.3, z: 7304.1}, {x: 7972.1, y: 241.3, z: 7304.1}, {x: 7972.1, y: 241.3, z: 7304.1}, {x: 7972.1, y: 241.3, z: 7304.1}, {x: 7971.3, y: 241.3, z: 7304.2} ];
function saveCameraState() {
oldMode = Camera.getMode();
@ -56,6 +56,11 @@ function keyPressEvent(event) {
Camera.setPosition(cameraLocations[choice - 1]);
Camera.keepLookingAt(cameraLookAts[choice - 1]);
}
if (event.text == "ESC") {
cameraNumber = 0;
freeCamera = false;
restoreCameraState();
}
if (event.text == "0") {
// Show camera location in log
var cameraLocation = Camera.getPosition();

View file

@ -752,7 +752,16 @@ function Tooltip() {
text += "ID: " + properties.id + "\n"
text += "model url: " + properties.modelURL + "\n"
text += "animation url: " + properties.animationURL + "\n"
if (properties.sittingPoints.length > 0) {
text += properties.sittingPoints.length + " sitting points: "
for (var i = 0; i < properties.sittingPoints.length; ++i) {
text += properties.sittingPoints[i].name + " "
}
} else {
text += "No sitting points"
}
Overlays.editOverlay(this.textOverlay, { text: text });
}

View file

@ -38,9 +38,15 @@ var standUpButton = Overlays.addOverlay("image", {
var passedTime = 0.0;
var startPosition = null;
var startRotation = null;
var animationLenght = 2.0;
var sitting = false;
var avatarOldPosition = { x: 0, y: 0, z: 0 };
var sitting = false;
var seat = new Object();
var hiddingSeats = false;
// This is the pose we would like to end up
var pose = [
@ -83,7 +89,7 @@ var sittingDownAnimation = function(deltaTime) {
}
}
var standingUpAnimation = function(deltaTime){
var standingUpAnimation = function(deltaTime) {
passedTime += deltaTime;
var factor = 1 - passedTime/animationLenght;
@ -97,6 +103,24 @@ var standingUpAnimation = function(deltaTime){
}
}
var goToSeatAnimation = function(deltaTime) {
passedTime += deltaTime;
var factor = passedTime/animationLenght;
if (passedTime <= animationLenght) {
var targetPosition = Vec3.sum(seat.position, { x: 0.3, y: 0.5, z: 0 });
MyAvatar.position = Vec3.sum(Vec3.multiply(startPosition, 1 - factor), Vec3.multiply(targetPosition, factor));
} else if (passedTime <= 2 * animationLenght) {
Quat.print("MyAvatar: ", MyAvatar.orientation);
Quat.print("Seat: ", seat.rotation);
MyAvatar.orientation = Quat.mix(startRotation, seat.rotation, factor - 1);
} else {
Script.update.disconnect(goToSeatAnimation);
sitDown();
showIndicators(false);
}
}
function sitDown() {
sitting = true;
passedTime = 0.0;
@ -124,15 +148,104 @@ function standUp() {
Overlays.editOverlay(sitDownButton, { visible: true });
}
Controller.mousePressEvent.connect(function(event){
var models = new Object();
function SeatIndicator(modelProperties, seatIndex) {
this.position = Vec3.sum(modelProperties.position,
Vec3.multiply(Vec3.multiplyQbyV(modelProperties.modelRotation,
modelProperties.sittingPoints[seatIndex].position),
modelProperties.radius));
this.orientation = Quat.multiply(modelProperties.modelRotation,
modelProperties.sittingPoints[seatIndex].rotation);
this.scale = MyAvatar.scale / 12;
this.sphere = Overlays.addOverlay("sphere", {
position: this.position,
size: this.scale,
solid: true,
color: { red: 0, green: 0, blue: 255 },
alpha: 0.3,
visible: true
});
this.show = function(doShow) {
Overlays.editOverlay(this.sphere, { visible: doShow });
}
this.update = function() {
Overlays.editOverlay(this.sphere, {
position: this.position,
size: this.scale
});
}
this.cleanup = function() {
Overlays.deleteOverlay(this.sphere);
}
}
Controller.mousePressEvent.connect(function(event) {
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
if (clickedOverlay == sitDownButton) {
sitDown();
} else if (clickedOverlay == standUpButton) {
standUp();
}
} else {
var pickRay = Camera.computePickRay(event.x, event.y);
var clickedOnSeat = false;
for (index in models) {
var model = models[index];
for (var i = 0; i < model.properties.sittingPoints.length; ++i) {
if (raySphereIntersection(pickRay.origin,
pickRay.direction,
model.properties.sittingPoints[i].indicator.position,
model.properties.sittingPoints[i].indicator.scale / 2)) {
clickedOnSeat = true;
seat.position = model.properties.sittingPoints[i].indicator.position;
seat.rotation = model.properties.sittingPoints[i].indicator.orientation;
}
}
}
if (clickedOnSeat) {
passedTime = 0.0;
startPosition = MyAvatar.position;
startRotation = MyAvatar.orientation;
try{ Script.update.disconnect(standingUpAnimation); } catch(e){}
try{ Script.update.disconnect(sittingDownAnimation); } catch(e){}
Script.update.connect(goToSeatAnimation);
}
return;
var intersection = Models.findRayIntersection(pickRay);
if (intersection.accurate && intersection.intersects && false) {
var properties = intersection.modelProperties;
print("Intersecting with model, let's check for seats.");
if (properties.sittingPoints.length > 0) {
print("Available seats, going to the first one: " + properties.sittingPoints[0].name);
seat.position = Vec3.sum(properties.position, Vec3.multiplyQbyV(properties.modelRotation, properties.sittingPoints[0].position));
Vec3.print("Seat position: ", seat.position);
seat.rotation = Quat.multiply(properties.modelRotation, properties.sittingPoints[0].rotation);
Quat.print("Seat rotation: ", seat.rotation);
passedTime = 0.0;
startPosition = MyAvatar.position;
startRotation = MyAvatar.orientation;
try{ Script.update.disconnect(standingUpAnimation); } catch(e){}
try{ Script.update.disconnect(sittingDownAnimation); } catch(e){}
Script.update.connect(goToSeatAnimation);
} else {
print ("Sorry, no seats here.");
}
}
}
})
function update(deltaTime){
@ -143,7 +256,76 @@ function update(deltaTime){
var newY = (windowDimensions.y - buttonHeight) / 2 ;
Overlays.editOverlay( standUpButton, {x: newX, y: newY} );
Overlays.editOverlay( sitDownButton, {x: newX, y: newY} );
}
}
if (MyAvatar.position.x != avatarOldPosition.x &&
MyAvatar.position.y != avatarOldPosition.y &&
MyAvatar.position.z != avatarOldPosition.z) {
avatarOldPosition = MyAvatar.position;
var SEARCH_RADIUS = 5;
var foundModels = Models.findModels(MyAvatar.position, SEARCH_RADIUS);
// Let's remove indicator that got out of radius
for (model in models) {
if (Vec3.distance(models[model].properties.position, MyAvatar.position) > SEARCH_RADIUS) {
removeIndicators(models[model]);
}
}
// Let's add indicators to new seats in radius
for (var i = 0; i < foundModels.length; ++i) {
var model = foundModels[i];
if (typeof(models[model.id]) == "undefined") {
addIndicators(model);
}
}
if (hiddingSeats && passedTime >= animationLenght) {
showIndicators(true);
}
}
}
function addIndicators(modelID) {
modelID.properties = Models.getModelProperties(modelID);
if (modelID.properties.sittingPoints.length > 0) {
for (var i = 0; i < modelID.properties.sittingPoints.length; ++i) {
modelID.properties.sittingPoints[i].indicator = new SeatIndicator(modelID.properties, i);
}
models[modelID.id] = modelID;
} else {
Models.editModel(modelID, { glowLevel: 0.0 });
}
}
function removeIndicators(modelID) {
for (var i = 0; i < modelID.properties.sittingPoints.length; ++i) {
modelID.properties.sittingPoints[i].indicator.cleanup();
}
delete models[modelID.id];
}
function showIndicators(doShow) {
for (model in models) {
var modelID = models[model];
for (var i = 0; i < modelID.properties.sittingPoints.length; ++i) {
modelID.properties.sittingPoints[i].indicator.show(doShow);
}
}
hiddingSeats = !doShow;
}
function raySphereIntersection(origin, direction, center, radius) {
var A = origin;
var B = Vec3.normalize(direction);
var P = center;
var x = Vec3.dot(Vec3.subtract(P, A), B);
var X = Vec3.sum(A, Vec3.multiply(B, x));
var d = Vec3.length(Vec3.subtract(P, X));
return (x > 0 && d <= radius);
}
function keyPressEvent(event) {
@ -161,11 +343,15 @@ Script.update.connect(update);
Controller.keyPressEvent.connect(keyPressEvent);
Script.scriptEnding.connect(function() {
for (var i = 0; i < pose.length; i++){
MyAvatar.clearJointData(pose[i].joint);
}
}
Overlays.deleteOverlay(sitDownButton);
Overlays.deleteOverlay(standUpButton);
for (model in models){
for (var i = 0; i < models[model].properties.sittingPoints.length; ++i) {
models[model].properties.sittingPoints[i].indicator.cleanup();
}
}
});

View file

@ -3656,8 +3656,9 @@ void Application::stopAllScripts(bool restart) {
}
void Application::stopScript(const QString &scriptName) {
if (_scriptEnginesHash.contains(scriptName)) {
_scriptEnginesHash.value(scriptName)->stop();
const QString& scriptURLString = QUrl(scriptName).toString();
if (_scriptEnginesHash.contains(scriptURLString)) {
_scriptEnginesHash.value(scriptURLString)->stop();
qDebug() << "stopping script..." << scriptName;
}
}

View file

@ -108,9 +108,9 @@ Menu::Menu() :
_fastFPSAverage(ONE_SECOND_OF_FRAMES),
_loginAction(NULL),
_preferencesDialog(NULL),
_scriptsLocation(),
_loginDialog(NULL),
_snapshotsLocation()
_snapshotsLocation(),
_scriptsLocation()
{
Application *appInstance = Application::getInstance();

View file

@ -574,8 +574,8 @@ void Avatar::initializeHair() {
for (int link = 0; link < HAIR_LINKS; link++) {
int vertexIndex = strand * HAIR_LINKS + link;
// Clear constraints
for (int link = 0; link < HAIR_MAX_CONSTRAINTS; link++) {
_hairConstraints[vertexIndex * HAIR_MAX_CONSTRAINTS + link] = -1;
for (int link2 = 0; link2 < HAIR_MAX_CONSTRAINTS; link2++) {
_hairConstraints[vertexIndex * HAIR_MAX_CONSTRAINTS + link2] = -1;
}
if (vertexIndex % HAIR_LINKS == 0) {
// start of strand

View file

@ -39,7 +39,6 @@ void SkeletonModel::setJointStates(QVector<JointState> states) {
}
clearShapes();
clearRagdollConstraintsAndPoints();
if (_enableShapes) {
buildShapes();
}
@ -505,8 +504,7 @@ void SkeletonModel::renderRagdoll() {
// virtual
void SkeletonModel::initRagdollPoints() {
assert(_ragdollPoints.size() == 0);
assert(_ragdollConstraints.size() == 0);
clearRagdollConstraintsAndPoints();
// one point for each joint
int numJoints = _jointStates.size();

View file

@ -15,7 +15,7 @@
#include "LocationManager.h"
const QString GET_USER_ADDRESS = "/api/v1/users/%1/address";
const QString GET_PLACE_ADDRESS = "/api/v1/places/%1/address";
const QString GET_PLACE_ADDRESS = "/api/v1/places/%1";
const QString GET_ADDRESSES = "/api/v1/addresses/%1";
const QString POST_PLACE_CREATE = "/api/v1/places/";

View file

@ -376,7 +376,7 @@ void ApplicationOverlay::renderControllerPointers() {
//then disable it.
const int MAX_BUTTON_PRESS_TIME = 250 * MSECS_TO_USECS;
if (usecTimestampNow() - pressedTime[index] < MAX_BUTTON_PRESS_TIME) {
if (usecTimestampNow() < pressedTime[index] + MAX_BUTTON_PRESS_TIME) {
_magActive[index] = !stateWhenPressed[index];
}
}

View file

@ -109,6 +109,8 @@ void OAuthWebViewHandler::displayWebviewForAuthorizationURL(const QUrl& authoriz
connect(_activeWebView->page()->networkAccessManager(), &QNetworkAccessManager::sslErrors,
this, &OAuthWebViewHandler::handleSSLErrors);
connect(_activeWebView->page()->networkAccessManager(), &QNetworkAccessManager::finished,
this, &OAuthWebViewHandler::handleReplyFinished);
connect(_activeWebView.data(), &QWebView::loadFinished, this, &OAuthWebViewHandler::handleLoadFinished);
// connect to the destroyed signal so after the web view closes we can start a timer
@ -132,6 +134,14 @@ void OAuthWebViewHandler::handleLoadFinished(bool success) {
NodeList::getInstance()->setSessionUUID(QUuid(authQuery.queryItemValue(AUTH_STATE_QUERY_KEY)));
_activeWebView->close();
_activeWebView = NULL;
}
}
void OAuthWebViewHandler::handleReplyFinished(QNetworkReply* reply) {
if (_activeWebView && reply->error() != QNetworkReply::NoError) {
qDebug() << "Error loading" << reply->url() << "-" << reply->errorString();
_activeWebView->close();
}
}
@ -148,6 +158,7 @@ void OAuthWebViewHandler::handleURLChanged(const QUrl& url) {
_activeWebView->show();
} else if (url.toString() == DEFAULT_NODE_AUTH_URL.toString() + "/login") {
// this is a login request - we're going to close the webview and signal the AccountManager that we need a login
qDebug() << "data-server replied with login request. Signalling that login is required to proceed with OAuth.";
_activeWebView->close();
AccountManager::getInstance().checkAndSignalForAccessToken();
}

View file

@ -31,6 +31,7 @@ public slots:
private slots:
void handleSSLErrors(QNetworkReply* networkReply, const QList<QSslError>& errorList);
void handleLoadFinished(bool success);
void handleReplyFinished(QNetworkReply* reply);
void handleWebViewDestroyed(QObject* destroyedObject);
void handleURLChanged(const QUrl& url);
private:

View file

@ -28,8 +28,8 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) :
FramelessDialog(parent, 0, POSITION_LEFT),
ui(new Ui::RunningScriptsWidget),
_signalMapper(this),
_scriptsModel(this),
_proxyModel(this) {
_proxyModel(this),
_scriptsModel(this) {
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, false);

View file

@ -902,7 +902,7 @@ padding: 10px;margin-top:10px</string>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<layout class="QHBoxLayout" name="horizontalLayout_111">
<property name="spacing">
<number>0</number>
</property>
@ -937,7 +937,7 @@ padding: 10px;margin-top:10px</string>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_11">
<spacer name="horizontalSpacer_111">
<property name="font">
<font>
<family>Arial</family>

View file

@ -121,7 +121,7 @@ qint64 AudioRingBuffer::writeData(const char* data, qint64 maxSize) {
// make sure we have enough bytes left for this to be the right amount of audio
// otherwise we should not copy that data, and leave the buffer pointers where they are
int samplesToCopy = std::min((quint64)(maxSize / sizeof(int16_t)), (quint64)_sampleCapacity);
quint64 samplesToCopy = std::min((quint64)(maxSize / sizeof(int16_t)), (quint64)_sampleCapacity);
if (_hasStarted && samplesToCopy > _sampleCapacity - samplesAvailable()) {
// this read will cross the next output, so call us starved and reset the buffer

View file

@ -209,7 +209,7 @@ bool PositionalAudioRingBuffer::shouldBeAddedToMix() {
}
return false;
} else if (samplesAvailable() < samplesPerFrame) {
} else if (samplesAvailable() < (unsigned int)samplesPerFrame) {
// if the buffer doesn't have a full frame of samples to take for mixing, it is starved
_isStarved = true;

View file

@ -1897,7 +1897,20 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
}
geometry.attachments.append(attachment);
}
// Add sitting points
QVariantHash sittingPoints = mapping.value("sit").toHash();
for (QVariantHash::const_iterator it = sittingPoints.constBegin(); it != sittingPoints.constEnd(); it++) {
SittingPoint sittingPoint;
sittingPoint.name = it.key();
QVariantList properties = it->toList();
sittingPoint.position = parseVec3(properties.at(0).toString());
sittingPoint.rotation = glm::quat(glm::radians(parseVec3(properties.at(1).toString())));
geometry.sittingPoints.append(sittingPoint);
}
return geometry;
}

View file

@ -182,6 +182,14 @@ public:
glm::vec3 scale;
};
/// A point where an avatar can sit
class SittingPoint {
public:
QString name;
glm::vec3 position; // relative postion
glm::quat rotation; // relative orientation
};
/// A set of meshes extracted from an FBX document.
class FBXGeometry {
public:
@ -209,6 +217,8 @@ public:
glm::vec3 palmDirection;
QVector<SittingPoint> sittingPoints;
glm::vec3 neckPivot;
Extents bindExtents;

View file

@ -886,7 +886,19 @@ QScriptValue ModelItemProperties::copyToScriptValue(QScriptEngine* engine) const
properties.setProperty("shouldDie", _shouldDie);
properties.setProperty("modelURL", _modelURL);
QScriptValue sittingPoints = engine->newObject();
for (int i = 0; i < _sittingPoints.size(); ++i) {
QScriptValue sittingPoint = engine->newObject();
sittingPoint.setProperty("name", _sittingPoints[i].name);
sittingPoint.setProperty("position", vec3toScriptValue(engine, _sittingPoints[i].position));
sittingPoint.setProperty("rotation", quatToScriptValue(engine, _sittingPoints[i].rotation));
sittingPoints.setProperty(i, sittingPoint);
}
sittingPoints.setProperty("length", _sittingPoints.size());
properties.setProperty("sittingPoints", sittingPoints);
QScriptValue modelRotation = quatToScriptValue(engine, _modelRotation);
properties.setProperty("modelRotation", modelRotation);
@ -971,7 +983,7 @@ void ModelItemProperties::copyFromScriptValue(const QScriptValue &object) {
_modelURLChanged = true;
}
}
QScriptValue modelRotation = object.property("modelRotation");
if (modelRotation.isValid()) {
QScriptValue x = modelRotation.property("x");
@ -1125,6 +1137,7 @@ void ModelItemProperties::copyFromModelItem(const ModelItem& modelItem) {
_animationFrameIndex = modelItem.getAnimationFrameIndex();
_animationFPS = modelItem.getAnimationFPS();
_glowLevel = modelItem.getGlowLevel();
_sittingPoints = modelItem.getSittingPoints();
_id = modelItem.getID();
_idSet = true;

View file

@ -23,6 +23,7 @@
#include <CollisionInfo.h>
#include <SharedUtil.h>
#include <OctreePacketData.h>
#include <FBXReader.h>
class ModelItem;
@ -124,7 +125,8 @@ private:
float _animationFrameIndex;
float _animationFPS;
float _glowLevel;
QVector<SittingPoint> _sittingPoints;
uint32_t _id;
bool _idSet;
quint64 _lastEdited;
@ -213,6 +215,7 @@ public:
bool hasAnimation() const { return !_animationURL.isEmpty(); }
const QString& getAnimationURL() const { return _animationURL; }
float getGlowLevel() const { return _glowLevel; }
QVector<SittingPoint> getSittingPoints() const { return _sittingPoints; }
ModelItemID getModelItemID() const { return ModelItemID(getID(), getCreatorTokenID(), getID() != UNKNOWN_MODEL_ID); }
ModelItemProperties getProperties() const;
@ -256,6 +259,7 @@ public:
void setAnimationIsPlaying(bool value) { _animationIsPlaying = value; }
void setAnimationFPS(float value) { _animationFPS = value; }
void setGlowLevel(float glowLevel) { _glowLevel = glowLevel; }
void setSittingPoints(QVector<SittingPoint> sittingPoints) { _sittingPoints = sittingPoints; }
void setProperties(const ModelItemProperties& properties);
@ -302,6 +306,8 @@ protected:
QString _modelURL;
glm::quat _modelRotation;
QVector<SittingPoint> _sittingPoints;
float _glowLevel;
uint32_t _creatorTokenID;

View file

@ -117,7 +117,7 @@ void ModelTree::storeModel(const ModelItem& model, const SharedNodePointer& send
// if we didn't find it in the tree, then store it...
if (!theOperator.wasFound()) {
AACube modelCube = model.getAACube();
ModelTreeElement* element = (ModelTreeElement*)getOrCreateChildElementContaining(model.getAACube());
ModelTreeElement* element = static_cast<ModelTreeElement*>(getOrCreateChildElementContaining(model.getAACube()));
element->storeModel(model);
// In the case where we stored it, we also need to mark the entire "path" down to the model as

View file

@ -330,6 +330,9 @@ bool ModelTreeElement::updateModel(const ModelItemID& modelID, const ModelItemPr
}
if (found) {
thisModel.setProperties(properties);
if (_myTree->getGeometryForModel(thisModel)) {
thisModel.setSittingPoints(_myTree->getGeometryForModel(thisModel)->sittingPoints);
}
markWithChangedTime(); // mark our element as changed..
const bool wantDebug = false;
if (wantDebug) {

View file

@ -160,10 +160,8 @@ ModelItemID ModelsScriptingInterface::findClosestModel(const glm::vec3& center,
QVector<ModelItemID> ModelsScriptingInterface::findModels(const glm::vec3& center, float radius) const {
QVector<ModelItemID> result;
if (_modelTree) {
_modelTree->lockForRead();
QVector<const ModelItem*> models;
_modelTree->findModels(center/(float)TREE_SCALE, radius/(float)TREE_SCALE, models);
_modelTree->unlock();
foreach (const ModelItem* model, models) {
ModelItemID thisModelItemID(model->getID(), UNKNOWN_MODEL_TOKEN, true);