Merge branch 'master' of https://github.com/highfidelity/hifi into sequence-numbers

This commit is contained in:
Stephen Birarda 2015-05-06 10:12:17 -07:00
commit 5b1514a390
47 changed files with 1527 additions and 226 deletions

View file

@ -12,7 +12,6 @@ Script.load("progress.js");
Script.load("edit.js");
Script.load("selectAudioDevice.js");
Script.load("controllers/hydra/hydraMove.js");
Script.load("headMove.js");
Script.load("inspect.js");
Script.load("lobby.js");
Script.load("notifications.js");

View file

@ -13,7 +13,8 @@
//
var isDice = false;
var NUMBER_OF_DICE = 2;
var NUMBER_OF_DICE = 4;
var LIFETIME = 10000; // Dice will live for about 3 hours
var dice = [];
var DIE_SIZE = 0.20;
@ -50,7 +51,7 @@ var diceButton = Overlays.addOverlay("image", {
});
var GRAVITY = -3.5;
var LIFETIME = 300;
// NOTE: angularVelocity is in radians/sec
var MAX_ANGULAR_SPEED = Math.PI;
@ -105,6 +106,7 @@ function mousePressEvent(event) {
var clickedText = false;
var clickedOverlay = Overlays.getOverlayAtPoint({x: event.x, y: event.y});
if (clickedOverlay == offButton) {
deleteDice();
Script.stop();
} else if (clickedOverlay == diceButton) {
var HOW_HARD = 2.0;
@ -116,10 +118,8 @@ function mousePressEvent(event) {
}
function scriptEnding() {
deleteDice();
Overlays.deleteOverlay(offButton);
Overlays.deleteOverlay(diceButton);
}
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);

View file

@ -0,0 +1,69 @@
//
// changingAtmosphereExample.js
// examples
//
// Created by Brad Hefta-Gaub on 4/16/15.
// Copyright 2015 High Fidelity, Inc.
//
// This is an example script that demonstrates creating a zone using the atmosphere features that changes scatter properties
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
var count = 0;
var stopAfter = 10000;
var zoneEntityA = Entities.addEntity({
type: "Zone",
position: { x: 1000, y: 1000, z: 1000},
dimensions: { x: 2000, y: 2000, z: 2000 },
keyLightColor: { red: 255, green: 0, blue: 0 },
stageSunModelEnabled: false,
shapeType: "sphere",
backgroundMode: "atmosphere",
atmosphere: {
center: { x: 1000, y: 0, z: 1000},
innerRadius: 1000.0,
outerRadius: 1025.0,
rayleighScattering: 0.0025, // Meaningful values 0 to ~0.01
mieScattering: 0.0010, // Meaningful values 0 to ~0.01
// First two, Meaningful values 0 to 1 each, blue, purple; third meaningful 0.3 to 1 - affects shape
scatteringWavelengths: { x: 0.650, y: 0.570, z: 0.475 },
hasStars: true
},
stageLatitude: 37.777,
stageLongitude: 122.407,
stageAltitude: 0.03,
stageDay: 183,
stageHour: 5,
stageSunModelEnabled: true
});
// register the call back so it fires before each data send
Script.update.connect(function(deltaTime) {
// stop it...
if (count >= stopAfter) {
print("calling Script.stop()");
Script.stop();
}
count++;
var rayleighScattering = (count / 100000) % 0.01;
var mieScattering = (count / 100000) % 0.01;
var waveX = (count / 2000) % 1;
var waveZ = ((count / 2000) % 0.7) + 0.3;
Entities.editEntity(zoneEntityA, {
atmosphere: {
rayleighScattering: rayleighScattering,
mieScattering: mieScattering,
scatteringWavelengths: { x: waveX, y: waveX, z: waveZ }
},
});
});

View file

@ -0,0 +1,63 @@
//
// zoneAtmosphereExample.js
// examples
//
// Created by Brad Hefta-Gaub on 4/16/15.
// Copyright 2015 High Fidelity, Inc.
//
// This is an example script that demonstrates creating a zone using the atmosphere features
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/";
var count = 0;
var stopAfter = 10000;
var zoneEntityA = Entities.addEntity({
type: "Zone",
position: { x: 1000, y: 1000, z: 1000},
dimensions: { x: 2000, y: 2000, z: 2000 },
keyLightColor: { red: 255, green: 0, blue: 0 },
stageSunModelEnabled: false,
shapeType: "sphere",
backgroundMode: "atmosphere",
atmosphere: {
center: { x: 1000, y: 0, z: 1000},
innerRadius: 1000.0,
outerRadius: 1025.0,
rayleighScattering: 0.0025,
mieScattering: 0.0010,
scatteringWavelengths: { x: 0.650, y: 0.570, z: 0.475 },
hasStars: false
},
stageLatitude: 37.777,
stageLongitude: 122.407,
stageAltitude: 0.03,
stageDay: 60,
stageHour: 0,
stageSunModelEnabled: true
});
// register the call back so it fires before each data send
Script.update.connect(function(deltaTime) {
// stop it...
if (count >= stopAfter) {
print("calling Script.stop()");
Script.stop();
}
count++;
var newHour = (count / 10) % 24;
var newIntensity = ((count / 10) % 24) / 24;
print("newHour:" + newHour);
print("newIntensity:" + newIntensity);
Entities.editEntity(zoneEntityA, {
stageHour: newHour,
keyLightIntensity: newIntensity
});
});

View file

@ -0,0 +1,65 @@
// harmonicOscillator.js
//
// Created by Philip Rosedale on May 5, 2015
// Copyright 2015 High Fidelity, Inc.
//
// An object moves around the edge of a disc while
// changing color. The script is continuously updating
// position, velocity, rotation, and color. The movement
// should appear perfectly smooth to someone else,
// provided their network connection is good.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
var ball, disc;
var time = 0.0;
var range = 1.0;
var speed = 0.5;
var basePosition = Vec3.sum(Camera.getPosition(), Quat.getFront(Camera.getOrientation()));
ball = Entities.addEntity(
{ type: "Box",
position: basePosition,
dimensions: { x: 0.1, y: 0.1, z: 0.1 },
color: { red: 255, green: 0, blue: 255 }
});
disc = Entities.addEntity(
{ type: "Sphere",
position: basePosition,
dimensions: { x: range, y: range / 20.0, z: range },
color: { red: 128, green: 128, blue: 128 }
});
function update(deltaTime) {
time += deltaTime * speed;
if (!ball.isKnownID) {
ball = Entities.identifyEntity(ball);
}
rotation = Quat.angleAxis(time/Math.PI * 180.0, { x: 0, y: 1, z: 0 });
Entities.editEntity(ball,
{
color: { red: 255 * (Math.sin(time)/2.0 + 0.5),
green: 255 - 255 * (Math.sin(time)/2.0 + 0.5),
blue: 0 },
position: { x: basePosition.x + Math.sin(time) / 2.0 * range,
y: basePosition.y,
z: basePosition.z + Math.cos(time) / 2.0 * range },
velocity: { x: Math.cos(time)/2.0 * range,
y: 0.0,
z: -Math.sin(time)/2.0 * range },
rotation: rotation
});
}
function scriptEnding() {
Entities.deleteEntity(ball);
Entities.deleteEntity(disc);
}
Script.scriptEnding.connect(scriptEnding);
Script.update.connect(update);

View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="45px" height="45px" viewBox="0 0 45 45" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<!-- Generator: Sketch 3.3.1 (12005) - http://www.bohemiancoding.com/sketch -->
<title>Slice 1</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="mic-mute" sketch:type="MSLayerGroup" transform="translate(-3.000000, 0.000000)">
<g id="Layer_3" transform="translate(3.420508, 0.842347)" stroke-width="2.10526286" stroke="#000000" fill="#FF0000" sketch:type="MSShapeGroup">
<g id="Layer_2">
<path d="M43.5266358,21.6577606 C43.5266358,33.3277189 33.9360211,43.0001168 22.0267963,43.1052516 C10.2229629,43.1052516 0.63234822,33.5379884 0.63234822,21.6577606 C0.63234822,9.77753268 10.2229629,0.21026952 22.0267963,0.21026952 C33.8306298,0.21026952 43.5266358,9.88266744 43.5266358,21.6577606 L43.5266358,21.6577606 Z" id="path6"></path>
<path d="M7.48278769,5.99268111 L37.7301094,36.1663595" id="line8"></path>
</g>
</g>
<g id="Layer_1" transform="translate(0.752809, 0.984270)" fill="#000000" sketch:type="MSShapeGroup">
<g id="Page-1_2_" transform="translate(1.000000, 0.000000)">
<g id="mic-tool_1_" transform="translate(1.000000, 0.000000)">
<g id="Page-1_3_" transform="translate(1.000000, 0.000000)">
<g id="Group_1_" transform="translate(1.000000, 1.000000)">
<g id="mic_1_" transform="translate(1.000000, 0.000000)">
<path d="M16.6868483,13.1449797 C16.6868483,16.2551904 14.4163295,17.579132 11.6131391,17.579132 C8.81632746,17.579132 6.5454869,16.2555462 6.5454869,13.1449797 C6.5454869,10.031224 8.81600655,5.5 11.6131391,5.5 C14.4163295,5.5 16.6868483,10.0312249 16.6868483,13.1449797 L16.6868483,13.1449797 Z" id="Shape"></path>
<path d="M32.9863177,13.1449797 C32.9863177,16.2551904 30.7158014,17.579132 27.9158039,17.579132 C25.1189922,17.579132 22.8484683,16.2555462 22.8484683,13.1449797 C22.8484683,10.031224 25.1189922,5.5 27.9158039,5.5 C30.7158023,5.5 32.9863177,10.0312249 32.9863177,13.1449797 L32.9863177,13.1449797 Z" id="Shape"></path>
<path d="M19.4246955,22.8995505 C8.59074225,22.8995505 3.97133194,18.0445183 3.97133194,24.0594622 C3.97133194,30.0829058 10.8899328,37.3346368 19.4246955,37.3346368 C27.9594572,37.3346368 34.8809223,30.3131889 34.8809223,24.2961184 C34.8809223,18.2776321 30.5208332,22.8995513 19.4246955,22.8995513 L19.4246955,22.8995505 Z M19.4246955,35.5515526 C17.3227023,35.5515526 15.3309396,35.0148194 13.5175822,34.1790777 C13.7995276,32.7577127 15.4529546,31.6435062 17.5390188,31.6435062 C18.2312941,31.6435062 18.8515667,31.7972603 19.4246955,32.0055779 C19.9978148,31.7969079 20.617776,31.6435062 21.3100529,31.6435062 C23.40822,31.6435062 25.0715291,32.76515 25.3378606,34.2003348 C23.5238656,35.0215518 21.5292319,35.5515534 19.4246955,35.5515534 L19.4246955,35.5515526 Z" id="Shape"></path>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>

After

(image error) Size: 3.5 KiB

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="45px" height="45px" viewBox="0 0 45 45" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<!-- Generator: Sketch 3.3.1 (12005) - http://www.bohemiancoding.com/sketch -->
<title>Slice 1</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="mic-mute" sketch:type="MSLayerGroup" transform="translate(-3.000000, 0.000000)">
<g id="Layer_3" transform="translate(2.420508, 0.842347)" stroke="#000000" stroke-width="2.10526286" fill="#FFFFFF" sketch:type="MSShapeGroup">
<g id="Layer_2" transform="translate(1.000000, 0.000000)">
<path d="M43.5266358,21.6577606 C43.5266358,33.3277189 33.9360211,43.0001168 22.0267963,43.1052516 C10.2229629,43.1052516 0.63234822,33.5379884 0.63234822,21.6577606 C0.63234822,9.77753268 10.2229629,0.21026952 22.0267963,0.21026952 C33.8306298,0.21026952 43.5266358,9.88266744 43.5266358,21.6577606 L43.5266358,21.6577606 Z" id="path6"></path>
</g>
</g>
<g id="Layer_1" transform="translate(0.752809, 0.984270)" fill="#000000" sketch:type="MSShapeGroup">
<g id="Page-1_2_" transform="translate(1.000000, 0.000000)">
<g id="mic-tool_1_" transform="translate(1.000000, 0.000000)">
<g id="Page-1_3_" transform="translate(1.000000, 0.000000)">
<g id="Group_1_" transform="translate(1.000000, 1.000000)">
<g id="mic_1_" transform="translate(1.000000, 0.000000)">
<path d="M16.6868483,13.1449797 C16.6868483,16.2551904 14.4163295,17.579132 11.6131391,17.579132 C8.81632746,17.579132 6.5454869,16.2555462 6.5454869,13.1449797 C6.5454869,10.031224 8.81600655,5.5 11.6131391,5.5 C14.4163295,5.5 16.6868483,10.0312249 16.6868483,13.1449797 L16.6868483,13.1449797 Z" id="Shape"></path>
<path d="M32.9863177,13.1449797 C32.9863177,16.2551904 30.7158014,17.579132 27.9158039,17.579132 C25.1189922,17.579132 22.8484683,16.2555462 22.8484683,13.1449797 C22.8484683,10.031224 25.1189922,5.5 27.9158039,5.5 C30.7158023,5.5 32.9863177,10.0312249 32.9863177,13.1449797 L32.9863177,13.1449797 Z" id="Shape"></path>
<path d="M19.4246955,22.8995505 C8.59074225,22.8995505 3.97133194,18.0445183 3.97133194,24.0594622 C3.97133194,30.0829058 10.8899328,37.3346368 19.4246955,37.3346368 C27.9594572,37.3346368 34.8809223,30.3131889 34.8809223,24.2961184 C34.8809223,18.2776321 30.5208332,22.8995513 19.4246955,22.8995513 L19.4246955,22.8995505 Z M19.4246955,35.5515526 C17.3227023,35.5515526 15.3309396,35.0148194 13.5175822,34.1790777 C13.7995276,32.7577127 15.4529546,31.6435062 17.5390188,31.6435062 C18.2312941,31.6435062 18.8515667,31.7972603 19.4246955,32.0055779 C19.9978148,31.7969079 20.617776,31.6435062 21.3100529,31.6435062 C23.40822,31.6435062 25.0715291,32.76515 25.3378606,34.2003348 C23.5238656,35.0215518 21.5292319,35.5515534 19.4246955,35.5515534 L19.4246955,35.5515526 Z" id="Shape"></path>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>

After

(image error) Size: 3.4 KiB

View file

@ -103,6 +103,7 @@
#include "audio/AudioIOStatsRenderer.h"
#include "audio/AudioScope.h"
#include "devices/CameraToolBox.h"
#include "devices/DdeFaceTracker.h"
#include "devices/Faceshift.h"
#include "devices/Leapmotion.h"
@ -266,6 +267,7 @@ bool setupEssentials(int& argc, char** argv) {
auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();
auto modelBlender = DependencyManager::set<ModelBlender>();
auto audioToolBox = DependencyManager::set<AudioToolBox>();
auto cameraToolBox = DependencyManager::set<CameraToolBox>();
auto avatarManager = DependencyManager::set<AvatarManager>();
auto lodManager = DependencyManager::set<LODManager>();
auto jsConsole = DependencyManager::set<StandAloneJSConsole>();
@ -590,6 +592,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
// The offscreen UI needs to intercept the mouse and keyboard
// events coming from the onscreen window
_glWidget->installEventFilter(DependencyManager::get<OffscreenUi>().data());
// initialize our face trackers after loading the menu settings
auto faceshiftTracker = DependencyManager::get<Faceshift>();
faceshiftTracker->init();
connect(faceshiftTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled);
auto ddeTracker = DependencyManager::get<DdeFaceTracker>();
ddeTracker->init();
connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled);
}
@ -921,6 +931,14 @@ void Application::audioMuteToggled() {
muteAction->setChecked(DependencyManager::get<AudioClient>()->isMuted());
}
void Application::faceTrackerMuteToggled() {
QAction* muteAction = Menu::getInstance()->getActionForOption(MenuOption::MuteFaceTracking);
Q_CHECK_PTR(muteAction);
bool isMuted = getSelectedFaceTracker()->isMuted();
muteAction->setChecked(isMuted);
getSelectedFaceTracker()->setEnabled(!isMuted);
}
void Application::aboutApp() {
InfoView::forcedShow(INFO_HELP_PATH);
}
@ -1011,6 +1029,9 @@ bool Application::event(QEvent* event) {
case QEvent::MouseButtonPress:
mousePressEvent((QMouseEvent*)event);
return true;
case QEvent::MouseButtonDblClick:
mouseDoublePressEvent((QMouseEvent*)event);
return true;
case QEvent::MouseButtonRelease:
mouseReleaseEvent((QMouseEvent*)event);
return true;
@ -1432,7 +1453,12 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
// stop propagation
return;
}
if (DependencyManager::get<CameraToolBox>()->mousePressEvent(getMouseX(), getMouseY())) {
// stop propagation
return;
}
if (_rearMirrorTools->mousePressEvent(getMouseX(), getMouseY())) {
// stop propagation
return;
@ -1450,6 +1476,24 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
}
}
void Application::mouseDoublePressEvent(QMouseEvent* event, unsigned int deviceID) {
// if one of our scripts have asked to capture this event, then stop processing it
if (_controllerScriptingInterface.isMouseCaptured()) {
return;
}
if (activeWindow() == _window) {
if (event->button() == Qt::LeftButton) {
if (mouseOnScreen()) {
if (DependencyManager::get<CameraToolBox>()->mouseDoublePressEvent(getMouseX(), getMouseY())) {
// stop propagation
return;
}
}
}
}
}
void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
if (!_aboutToQuit) {
@ -1845,18 +1889,45 @@ FaceTracker* Application::getActiveFaceTracker() {
(faceshift->isActive() ? static_cast<FaceTracker*>(faceshift.data()) : NULL));
}
void Application::setActiveFaceTracker() {
FaceTracker* Application::getSelectedFaceTracker() {
FaceTracker* faceTracker = NULL;
#ifdef HAVE_FACESHIFT
DependencyManager::get<Faceshift>()->setTCPEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Faceshift));
if (Menu::getInstance()->isOptionChecked(MenuOption::Faceshift)) {
faceTracker = DependencyManager::get<Faceshift>().data();
}
#endif
#ifdef HAVE_DDE
if (Menu::getInstance()->isOptionChecked(MenuOption::UseCamera)) {
faceTracker = DependencyManager::get<DdeFaceTracker>().data();
}
#endif
return faceTracker;
}
void Application::setActiveFaceTracker() {
bool isMuted = Menu::getInstance()->isOptionChecked(MenuOption::MuteFaceTracking);
#ifdef HAVE_FACESHIFT
auto faceshiftTracker = DependencyManager::get<Faceshift>();
faceshiftTracker->setIsMuted(isMuted);
faceshiftTracker->setEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Faceshift) && !isMuted);
#endif
#ifdef HAVE_DDE
bool isUsingDDE = Menu::getInstance()->isOptionChecked(MenuOption::UseCamera);
Menu::getInstance()->getActionForOption(MenuOption::UseAudioForMouth)->setVisible(isUsingDDE);
Menu::getInstance()->getActionForOption(MenuOption::VelocityFilter)->setVisible(isUsingDDE);
DependencyManager::get<DdeFaceTracker>()->setEnabled(isUsingDDE);
auto ddeTracker = DependencyManager::get<DdeFaceTracker>();
ddeTracker->setIsMuted(isMuted);
ddeTracker->setEnabled(isUsingDDE && !isMuted);
#endif
}
void Application::toggleFaceTrackerMute() {
FaceTracker* faceTracker = getSelectedFaceTracker();
if (faceTracker) {
faceTracker->toggleMute();
}
}
bool Application::exportEntities(const QString& filename, const QVector<EntityItemID>& entityIDs) {
QVector<EntityItem*> entities;
@ -2025,10 +2096,6 @@ void Application::init() {
SixenseManager::getInstance().toggleSixense(true);
#endif
// initialize our face trackers after loading the menu settings
DependencyManager::get<Faceshift>()->init();
DependencyManager::get<DdeFaceTracker>()->init();
Leapmotion::init();
RealSense::init();
@ -2166,7 +2233,7 @@ void Application::updateMyAvatarLookAtPosition() {
isLookingAtSomeone = true;
// If I am looking at someone else, look directly at one of their eyes
if (tracker) {
if (tracker && !tracker->isMuted()) {
// If a face tracker is active, look at the eye for the side my gaze is biased toward
if (tracker->getEstimatedEyeYaw() > _myAvatar->getHead()->getFinalYaw()) {
// Look at their right eye
@ -2192,7 +2259,7 @@ void Application::updateMyAvatarLookAtPosition() {
//
// Deflect the eyes a bit to match the detected Gaze from 3D camera if active
//
if (tracker) {
if (tracker && !tracker->isMuted()) {
float eyePitch = tracker->getEstimatedEyePitch();
float eyeYaw = tracker->getEstimatedEyeYaw();
const float GAZE_DEFLECTION_REDUCTION_DURING_EYE_CONTACT = 0.1f;
@ -2247,7 +2314,7 @@ void Application::updateCamera(float deltaTime) {
if (!OculusManager::isConnected() && !TV3DManager::isConnected() &&
Menu::getInstance()->isOptionChecked(MenuOption::OffAxisProjection)) {
FaceTracker* tracker = getActiveFaceTracker();
if (tracker) {
if (tracker && !tracker->isMuted()) {
const float EYE_OFFSET_SCALE = 0.025f;
glm::vec3 position = tracker->getHeadTranslation() * EYE_OFFSET_SCALE;
float xSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? 1.0f : -1.0f;
@ -2311,7 +2378,7 @@ void Application::update(float deltaTime) {
PerformanceTimer perfTimer("devices");
DeviceTracker::updateAll();
FaceTracker* tracker = getActiveFaceTracker();
if (tracker) {
if (tracker && !tracker->isMuted()) {
tracker->update(deltaTime);
}
SixenseManager::getInstance().update(deltaTime);
@ -3087,21 +3154,29 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs
// compute starfield alpha based on distance from atmosphere
float alpha = 1.0f;
bool hasStars = true;
if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
// TODO: handle this correctly for zones
const EnvironmentData& closestData = _environment.getClosestData(theCamera.getPosition());
float height = glm::distance(theCamera.getPosition(),
closestData.getAtmosphereCenter(theCamera.getPosition()));
if (height < closestData.getAtmosphereInnerRadius()) {
alpha = 0.0f;
if (closestData.getHasStars()) {
float height = glm::distance(theCamera.getPosition(), closestData.getAtmosphereCenter());
if (height < closestData.getAtmosphereInnerRadius()) {
alpha = 0.0f;
} else if (height < closestData.getAtmosphereOuterRadius()) {
alpha = (height - closestData.getAtmosphereInnerRadius()) /
(closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius());
} else if (height < closestData.getAtmosphereOuterRadius()) {
alpha = (height - closestData.getAtmosphereInnerRadius()) /
(closestData.getAtmosphereOuterRadius() - closestData.getAtmosphereInnerRadius());
}
} else {
hasStars = false;
}
}
// finally render the starfield
_stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha);
if (hasStars) {
_stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha);
}
}
if (Menu::getInstance()->isOptionChecked(MenuOption::Wireframe)) {
@ -3233,6 +3308,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs
{
PerformanceTimer perfTimer("3dOverlaysFront");
glClear(GL_DEPTH_BUFFER_BIT);
Glower glower; // Sets alpha to 1.0
_overlays.renderWorld(true);
}
activeRenderingThread = nullptr;

View file

@ -169,6 +169,7 @@ public:
void mouseMoveEvent(QMouseEvent* event, unsigned int deviceID = 0);
void mousePressEvent(QMouseEvent* event, unsigned int deviceID = 0);
void mouseDoublePressEvent(QMouseEvent* event, unsigned int deviceID = 0);
void mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID = 0);
void touchBeginEvent(QTouchEvent* event);
@ -218,6 +219,7 @@ public:
bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated; }
FaceTracker* getActiveFaceTracker();
FaceTracker* getSelectedFaceTracker();
QSystemTrayIcon* getTrayIcon() { return _trayIcon; }
ApplicationOverlay& getApplicationOverlay() { return _applicationOverlay; }
@ -282,6 +284,9 @@ public:
virtual int getBoundaryLevelAdjust() const;
virtual PickRay computePickRay(float x, float y);
virtual const glm::vec3& getAvatarPosition() const { return _myAvatar->getPosition(); }
virtual void overrideEnvironmentData(const EnvironmentData& newData) { _environment.override(newData); }
virtual void endOverrideEnvironmentData() { _environment.endOverride(); }
NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; }
@ -393,6 +398,7 @@ public slots:
void resetSensors();
void setActiveFaceTracker();
void toggleFaceTrackerMute();
void aboutApp();
void showEditEntitiesHelp();
@ -434,6 +440,7 @@ private slots:
void runTests();
void audioMuteToggled();
void faceTrackerMuteToggled();
void setCursorVisible(bool visible);

View file

@ -71,15 +71,46 @@ void Environment::resetToDefault() {
void Environment::renderAtmospheres(Camera& camera) {
// get the lock for the duration of the call
QMutexLocker locker(&_mutex);
foreach (const ServerData& serverData, _data) {
// TODO: do something about EnvironmentData
foreach (const EnvironmentData& environmentData, serverData) {
renderAtmosphere(camera, environmentData);
if (_environmentIsOverridden) {
renderAtmosphere(camera, _overrideData);
} else {
foreach (const ServerData& serverData, _data) {
// TODO: do something about EnvironmentData
foreach (const EnvironmentData& environmentData, serverData) {
renderAtmosphere(camera, environmentData);
}
}
}
}
EnvironmentData Environment::getClosestData(const glm::vec3& position) {
if (_environmentIsOverridden) {
return _overrideData;
}
// get the lock for the duration of the call
QMutexLocker locker(&_mutex);
EnvironmentData closest;
float closestDistance = FLT_MAX;
foreach (const ServerData& serverData, _data) {
foreach (const EnvironmentData& environmentData, serverData) {
float distance = glm::distance(position, environmentData.getAtmosphereCenter(position)) -
environmentData.getAtmosphereOuterRadius();
if (distance < closestDistance) {
closest = environmentData;
closestDistance = distance;
}
}
}
return closest;
}
// NOTE: Deprecated - I'm leaving this in for now, but it's not actually used. I made it private
// so that if anyone wants to start using this in the future they will consider how to make it
// work with new physics systems.
glm::vec3 Environment::getGravity (const glm::vec3& position) {
//
// 'Default' gravity pulls you downward in Y when you are near the X/Z plane
@ -115,25 +146,6 @@ glm::vec3 Environment::getGravity (const glm::vec3& position) {
return gravity;
}
const EnvironmentData Environment::getClosestData(const glm::vec3& position) {
// get the lock for the duration of the call
QMutexLocker locker(&_mutex);
EnvironmentData closest;
float closestDistance = FLT_MAX;
foreach (const ServerData& serverData, _data) {
foreach (const EnvironmentData& environmentData, serverData) {
float distance = glm::distance(position, environmentData.getAtmosphereCenter(position)) -
environmentData.getAtmosphereOuterRadius();
if (distance < closestDistance) {
closest = environmentData;
closestDistance = distance;
}
}
}
return closest;
}
bool Environment::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end,
float radius, glm::vec3& penetration) {
// collide with the "floor"
@ -217,14 +229,14 @@ ProgramObject* Environment::createSkyProgram(const char* from, int* locations) {
}
void Environment::renderAtmosphere(Camera& camera, const EnvironmentData& data) {
glm::vec3 center = data.getAtmosphereCenter(camera.getPosition());
glm::vec3 center = data.getAtmosphereCenter();
glPushMatrix();
glTranslatef(center.x, center.y, center.z);
glm::vec3 relativeCameraPos = camera.getPosition() - center;
float height = glm::length(relativeCameraPos);
// use the appropriate shader depending on whether we're inside or outside
ProgramObject* program;
int* locations;

View file

@ -30,15 +30,19 @@ public:
void init();
void resetToDefault();
void renderAtmospheres(Camera& camera);
void override(const EnvironmentData& overrideData) { _overrideData = overrideData; _environmentIsOverridden = true; }
void endOverride() { _environmentIsOverridden = false; }
glm::vec3 getGravity (const glm::vec3& position);
const EnvironmentData getClosestData(const glm::vec3& position);
EnvironmentData getClosestData(const glm::vec3& position);
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration);
int parseData(const HifiSockAddr& senderSockAddr, const QByteArray& packet);
private:
glm::vec3 getGravity (const glm::vec3& position); // NOTE: Deprecated
bool findCapsulePenetration(const glm::vec3& start,
const glm::vec3& end, float radius, glm::vec3& penetration); // NOTE: Deprecated
ProgramObject* createSkyProgram(const char* from, int* locations);
@ -74,6 +78,8 @@ private:
typedef QHash<int, EnvironmentData> ServerData;
QHash<HifiSockAddr, ServerData> _data;
EnvironmentData _overrideData;
bool _environmentIsOverridden = false;
QMutex _mutex;
};

View file

@ -131,6 +131,7 @@ bool GLCanvas::event(QEvent* event) {
case QEvent::MouseMove:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::KeyPress:
case QEvent::KeyRelease:
case QEvent::FocusIn:

View file

@ -394,6 +394,12 @@ Menu::Menu() {
QAction* ddeFiltering = addCheckableActionToQMenuAndActionHash(faceTrackingMenu, MenuOption::VelocityFilter, 0, true);
ddeFiltering->setVisible(false);
#endif
#if defined(HAVE_FACESHIFT) || defined(HAVE_DDE)
faceTrackingMenu->addSeparator();
addCheckableActionToQMenuAndActionHash(faceTrackingMenu, MenuOption::MuteFaceTracking,
0, false,
qApp, SLOT(toggleFaceTrackerMute()));
#endif
auto avatarManager = DependencyManager::get<AvatarManager>();
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::AvatarReceiveStats, 0, false,

View file

@ -211,6 +211,7 @@ namespace MenuOption {
const QString Mirror = "Mirror";
const QString MuteAudio = "Mute Microphone";
const QString MuteEnvironment = "Mute Environment";
const QString MuteFaceTracking = "Mute Face Tracking";
const QString NoFaceTracking = "None";
const QString OctreeStats = "Entity Statistics";
const QString OffAxisProjection = "Off-Axis Projection";

View file

@ -35,7 +35,7 @@ bool AudioToolBox::mousePressEvent(int x, int y) {
return false;
}
void AudioToolBox::render(int x, int y, bool boxed) {
void AudioToolBox::render(int x, int y, int padding, bool boxed) {
glEnable(GL_TEXTURE_2D);
auto glCanvas = Application::getInstance()->getGLWidget();
@ -79,7 +79,7 @@ void AudioToolBox::render(int x, int y, bool boxed) {
float iconColor = 1.0f;
_iconBounds = QRect(x, y, MUTE_ICON_SIZE, MUTE_ICON_SIZE);
_iconBounds = QRect(x + padding, y, MUTE_ICON_SIZE, MUTE_ICON_SIZE);
if (!audioIO->isMuted()) {
glBindTexture(GL_TEXTURE_2D, _micTextureId);
iconColor = 1.0f;

View file

@ -18,7 +18,7 @@
class AudioToolBox : public Dependency {
SINGLETON_DEPENDENCY
public:
void render(int x, int y, bool boxed);
void render(int x, int y, int padding, bool boxed);
bool mousePressEvent(int x, int y);
protected:

View file

@ -90,7 +90,7 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) {
// Only use face trackers when not playing back a recording.
if (!myAvatar->isPlaying()) {
FaceTracker* faceTracker = Application::getInstance()->getActiveFaceTracker();
_isFaceTrackerConnected = faceTracker != NULL;
_isFaceTrackerConnected = faceTracker != NULL && !faceTracker->isMuted();
if (_isFaceTrackerConnected) {
_blendshapeCoefficients = faceTracker->getBlendshapeCoefficients();

View file

@ -243,7 +243,7 @@ void MyAvatar::updateFromTrackers(float deltaTime) {
estimatedPosition /= OCULUS_LEAN_SCALE;
} else {
FaceTracker* tracker = Application::getInstance()->getActiveFaceTracker();
if (tracker) {
if (tracker && !tracker->isMuted()) {
estimatedPosition = tracker->getHeadTranslation();
_trackedHeadPosition = estimatedPosition;
estimatedRotation = glm::degrees(safeEulerAngles(tracker->getHeadRotation()));

View file

@ -0,0 +1,121 @@
//
// CameraToolBox.cpp
// interface/src/devices
//
// Created by David Rowe on 30 Apr 2015.
// 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 "InterfaceConfig.h"
#include <GLCanvas.h>
#include <PathUtils.h>
#include "Application.h"
#include "CameraToolBox.h"
#include "FaceTracker.h"
CameraToolBox::CameraToolBox() :
_iconPulseTimeReference(usecTimestampNow()),
_doubleClickTimer(NULL)
{
}
CameraToolBox::~CameraToolBox() {
if (_doubleClickTimer) {
_doubleClickTimer->stop();
delete _doubleClickTimer;
}
}
bool CameraToolBox::mousePressEvent(int x, int y) {
if (_iconBounds.contains(x, y)) {
if (!_doubleClickTimer) {
// Toggle mute after waiting to check that it's not a double-click.
const int DOUBLE_CLICK_WAIT = 200; // ms
_doubleClickTimer = new QTimer(this);
connect(_doubleClickTimer, SIGNAL(timeout()), this, SLOT(toggleMute()));
_doubleClickTimer->setSingleShot(true);
_doubleClickTimer->setInterval(DOUBLE_CLICK_WAIT);
_doubleClickTimer->start();
}
return true;
}
return false;
}
bool CameraToolBox::mouseDoublePressEvent(int x, int y) {
if (_iconBounds.contains(x, y)) {
if (_doubleClickTimer) {
_doubleClickTimer->stop();
delete _doubleClickTimer;
_doubleClickTimer = NULL;
}
Application::getInstance()->resetSensors();
return true;
}
return false;
}
void CameraToolBox::toggleMute() {
delete _doubleClickTimer;
_doubleClickTimer = NULL;
FaceTracker* faceTracker = Application::getInstance()->getSelectedFaceTracker();
if (faceTracker) {
faceTracker->toggleMute();
}
}
void CameraToolBox::render(int x, int y, bool boxed) {
glEnable(GL_TEXTURE_2D);
auto glCanvas = Application::getInstance()->getGLWidget();
if (_enabledTextureId == 0) {
_enabledTextureId = glCanvas->bindTexture(QImage(PathUtils::resourcesPath() + "images/face.svg"));
}
if (_mutedTextureId == 0) {
_mutedTextureId = glCanvas->bindTexture(QImage(PathUtils::resourcesPath() + "images/face-mute.svg"));
}
const int MUTE_ICON_SIZE = 24;
_iconBounds = QRect(x, y, MUTE_ICON_SIZE, MUTE_ICON_SIZE);
float iconColor = 1.0f;
if (!Menu::getInstance()->isOptionChecked(MenuOption::MuteFaceTracking)) {
glBindTexture(GL_TEXTURE_2D, _enabledTextureId);
} else {
glBindTexture(GL_TEXTURE_2D, _mutedTextureId);
// Make muted icon pulsate
static const float PULSE_MIN = 0.4f;
static const float PULSE_MAX = 1.0f;
static const float PULSE_FREQUENCY = 1.0f; // in Hz
qint64 now = usecTimestampNow();
if (now - _iconPulseTimeReference > (qint64)USECS_PER_SECOND) {
// Prevents t from getting too big, which would diminish glm::cos precision
_iconPulseTimeReference = now - ((now - _iconPulseTimeReference) % USECS_PER_SECOND);
}
float t = (float)(now - _iconPulseTimeReference) / (float)USECS_PER_SECOND;
float pulseFactor = (glm::cos(t * PULSE_FREQUENCY * 2.0f * PI) + 1.0f) / 2.0f;
iconColor = PULSE_MIN + (PULSE_MAX - PULSE_MIN) * pulseFactor;
}
glm::vec4 quadColor(iconColor, iconColor, iconColor, 1.0f);
glm::vec2 topLeft(_iconBounds.left(), _iconBounds.top());
glm::vec2 bottomRight(_iconBounds.right(), _iconBounds.bottom());
glm::vec2 texCoordTopLeft(1,1);
glm::vec2 texCoordBottomRight(0,0);
if (_boxQuadID == GeometryCache::UNKNOWN_ID) {
_boxQuadID = DependencyManager::get<GeometryCache>()->allocateID();
}
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor, _boxQuadID);
glDisable(GL_TEXTURE_2D);
}

View file

@ -0,0 +1,45 @@
//
// CameraToolBox.h
// interface/src/devices
//
// Created by David Rowe on 30 Apr 2015.
// 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_CameraToolBox_h
#define hifi_CameraToolBox_h
#include <QObject>
#include <DependencyManager.h>
#include <GeometryCache.h>
class CameraToolBox : public QObject, public Dependency {
Q_OBJECT
SINGLETON_DEPENDENCY
public:
void render(int x, int y, bool boxed);
bool mousePressEvent(int x, int y);
bool mouseDoublePressEvent(int x, int y);
protected:
CameraToolBox();
~CameraToolBox();
private slots:
void toggleMute();
private:
GLuint _enabledTextureId = 0;
GLuint _mutedTextureId = 0;
int _boxQuadID = GeometryCache::UNKNOWN_ID;
QRect _iconBounds;
qint64 _iconPulseTimeReference = 0;
QTimer* _doubleClickTimer;
};
#endif // hifi_CameraToolBox_h

View file

@ -178,9 +178,7 @@ DdeFaceTracker::DdeFaceTracker(const QHostAddress& host, quint16 serverPort, qui
_filteredBrowUp(0.0f),
_lastEyeBlinks(),
_filteredEyeBlinks(),
_lastEyeCoefficients(),
_isCalculatingFPS(false),
_frameCount(0)
_lastEyeCoefficients()
{
_coefficients.resize(NUM_FACESHIFT_BLENDSHAPES);
@ -203,7 +201,16 @@ DdeFaceTracker::~DdeFaceTracker() {
#pragma warning(default:4351)
#endif
void DdeFaceTracker::init() {
FaceTracker::init();
setEnabled(Menu::getInstance()->isOptionChecked(MenuOption::UseCamera) && !_isMuted);
}
void DdeFaceTracker::setEnabled(bool enabled) {
if (!_isInitialized) {
// Don't enable until have explicitly initialized
return;
}
#ifdef HAVE_DDE
// isOpen() does not work as one might expect on QUdpSocket; don't test isOpen() before closing socket.
_udpSocket.close();
@ -314,7 +321,9 @@ float DdeFaceTracker::getBlendshapeCoefficient(int index) const {
}
void DdeFaceTracker::decodePacket(const QByteArray& buffer) {
if(buffer.size() > MIN_PACKET_SIZE) {
_lastReceiveTimestamp = usecTimestampNow();
if (buffer.size() > MIN_PACKET_SIZE) {
bool isFiltering = Menu::getInstance()->isOptionChecked(MenuOption::VelocityFilter);
Packet packet;
@ -326,7 +335,7 @@ void DdeFaceTracker::decodePacket(const QByteArray& buffer) {
memcpy(&translation, packet.translation, sizeof(packet.translation));
glm::quat rotation;
memcpy(&rotation, &packet.rotation, sizeof(packet.rotation));
if (_reset || (_lastReceiveTimestamp == 0)) {
if (_reset || (_lastMessageReceived == 0)) {
memcpy(&_referenceTranslation, &translation, sizeof(glm::vec3));
memcpy(&_referenceRotation, &rotation, sizeof(glm::quat));
_reset = false;
@ -501,5 +510,4 @@ void DdeFaceTracker::decodePacket(const QByteArray& buffer) {
} else {
qCWarning(interfaceapp) << "DDE Face Tracker: Decode error";
}
_lastReceiveTimestamp = usecTimestampNow();
}

View file

@ -28,6 +28,7 @@ class DdeFaceTracker : public FaceTracker, public Dependency {
SINGLETON_DEPENDENCY
public:
virtual void init();
virtual void reset();
virtual bool isActive() const;
@ -120,9 +121,6 @@ private:
float _lastEyeBlinks[2];
float _filteredEyeBlinks[2];
float _lastEyeCoefficients[2];
bool _isCalculatingFPS;
int _frameCount;
};
#endif // hifi_DdeFaceTracker_h

View file

@ -15,14 +15,14 @@
#include "FaceTracker.h"
#include "InterfaceLogging.h"
#include "Menu.h"
const int FPS_TIMER_DELAY = 2000; // ms
const int FPS_TIMER_DURATION = 2000; // ms
FaceTracker::FaceTracker() :
_isCalculatingFPS(false),
_frameCount(0)
{
void FaceTracker::init() {
_isMuted = Menu::getInstance()->isOptionChecked(MenuOption::MuteFaceTracking);
_isInitialized = true; // FaceTracker can be used now
}
inline float FaceTracker::getBlendshapeCoefficient(int index) const {
@ -101,3 +101,8 @@ void FaceTracker::finishFPSTimer() {
qCDebug(interfaceapp) << "Face tracker FPS =" << (float)_frameCount / ((float)FPS_TIMER_DURATION / 1000.0f);
_isCalculatingFPS = false;
}
void FaceTracker::toggleMute() {
_isMuted = !_isMuted;
emit muteToggled();
}

View file

@ -26,7 +26,7 @@ public:
virtual bool isActive() const { return false; }
virtual bool isTracking() const { return false; }
virtual void init() {}
virtual void init();
virtual void update(float deltaTime);
virtual void reset();
@ -42,11 +42,23 @@ public:
bool isValidBlendshapeIndex(int index) const { return index >= 0 && index < getNumBlendshapes(); }
const QVector<float>& getBlendshapeCoefficients() const;
float getBlendshapeCoefficient(int index) const;
bool isMuted() const { return _isMuted; }
void setIsMuted(bool isMuted) { _isMuted = isMuted; }
void toggleMute();
signals:
void muteToggled();
public slots:
virtual void setEnabled(bool enabled) = 0;
protected:
FaceTracker();
virtual ~FaceTracker() {};
bool _isInitialized = false;
bool _isMuted = true;
glm::vec3 _headTranslation = glm::vec3(0.0f);
glm::quat _headRotation = glm::quat();
float _estimatedEyePitch = 0.0f;
@ -63,8 +75,8 @@ private slots:
void finishFPSTimer();
private:
bool _isCalculatingFPS;
int _frameCount;
bool _isCalculatingFPS = false;
int _frameCount = 0;
};
#endif // hifi_FaceTracker_h

View file

@ -49,7 +49,8 @@ Faceshift::Faceshift() :
#ifdef HAVE_FACESHIFT
void Faceshift::init() {
setTCPEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Faceshift));
FaceTracker::init();
setEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Faceshift) && !_isMuted);
}
void Faceshift::update(float deltaTime) {
@ -92,7 +93,7 @@ void Faceshift::reset() {
bool Faceshift::isActive() const {
const quint64 ACTIVE_TIMEOUT_USECS = 1000000;
return (usecTimestampNow() - _lastTrackingStateReceived) < ACTIVE_TIMEOUT_USECS;
return (usecTimestampNow() - _lastReceiveTimestamp) < ACTIVE_TIMEOUT_USECS;
}
bool Faceshift::isTracking() const {
@ -127,7 +128,11 @@ void Faceshift::updateFakeCoefficients(float leftBlink, float rightBlink, float
coefficients[FUNNEL_BLENDSHAPE] = mouth3;
}
void Faceshift::setTCPEnabled(bool enabled) {
void Faceshift::setEnabled(bool enabled) {
// Don't enable until have explicitly initialized
if (!_isInitialized) {
return;
}
#ifdef HAVE_FACESHIFT
if ((_tcpEnabled = enabled)) {
connectSocket();
@ -196,6 +201,8 @@ void Faceshift::send(const std::string& message) {
void Faceshift::receive(const QByteArray& buffer) {
#ifdef HAVE_FACESHIFT
_lastReceiveTimestamp = usecTimestampNow();
_stream.received(buffer.size(), buffer.constData());
fsMsgPtr msg;
for (fsMsgPtr msg; (msg = _stream.get_message()); ) {
@ -240,11 +247,11 @@ void Faceshift::receive(const QByteArray& buffer) {
const float FRAME_AVERAGING_FACTOR = 0.99f;
quint64 usecsNow = usecTimestampNow();
if (_lastTrackingStateReceived != 0) {
if (_lastMessageReceived != 0) {
_averageFrameTime = FRAME_AVERAGING_FACTOR * _averageFrameTime +
(1.0f - FRAME_AVERAGING_FACTOR) * (float)(usecsNow - _lastTrackingStateReceived) / 1000000.0f;
(1.0f - FRAME_AVERAGING_FACTOR) * (float)(usecsNow - _lastMessageReceived) / 1000000.0f;
}
_lastTrackingStateReceived = usecsNow;
_lastMessageReceived = usecsNow;
}
break;
}

View file

@ -87,7 +87,7 @@ signals:
void connectionStateChanged();
public slots:
void setTCPEnabled(bool enabled);
void setEnabled(bool enabled);
private slots:
void connectSocket();
@ -114,7 +114,8 @@ private:
bool _tcpEnabled = true;
int _tcpRetryCount = 0;
bool _tracking = false;
quint64 _lastTrackingStateReceived = 0;
quint64 _lastReceiveTimestamp = 0;
quint64 _lastMessageReceived = 0;
float _averageFrameTime = STARTING_FACESHIFT_FRAME_TIME;
glm::vec3 _headAngularVelocity = glm::vec3(0.0f);

View file

@ -25,6 +25,7 @@
#include "audio/AudioToolBox.h"
#include "Application.h"
#include "ApplicationOverlay.h"
#include "devices/CameraToolBox.h"
#include "devices/OculusManager.h"
#include "Util.h"
@ -211,6 +212,7 @@ void ApplicationOverlay::renderOverlay() {
glMatrixMode(GL_MODELVIEW);
renderAudioMeter();
renderCameraToggle();
renderStatsAndLogs();
@ -808,18 +810,46 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool
} glPopMatrix();
}
const int AUDIO_METER_GAP = 5;
const int MUTE_ICON_PADDING = 10;
void ApplicationOverlay::renderCameraToggle() {
if (Menu::getInstance()->isOptionChecked(MenuOption::NoFaceTracking)) {
return;
}
int audioMeterY;
bool smallMirrorVisible = Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && !OculusManager::isConnected();
bool boxed = smallMirrorVisible &&
!Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror);
if (boxed) {
audioMeterY = MIRROR_VIEW_HEIGHT + AUDIO_METER_GAP + MUTE_ICON_PADDING;
} else {
audioMeterY = AUDIO_METER_GAP + MUTE_ICON_PADDING;
}
DependencyManager::get<CameraToolBox>()->render(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, audioMeterY, boxed);
}
void ApplicationOverlay::renderAudioMeter() {
auto glCanvas = Application::getInstance()->getGLWidget();
auto audio = DependencyManager::get<AudioClient>();
// Audio VU Meter and Mute Icon
const int MUTE_ICON_SIZE = 24;
const int MUTE_ICON_PADDING = 10;
const int AUDIO_METER_WIDTH = MIRROR_VIEW_WIDTH - MUTE_ICON_SIZE - MUTE_ICON_PADDING;
const int AUDIO_METER_SCALE_WIDTH = AUDIO_METER_WIDTH - 2 ;
const int AUDIO_METER_HEIGHT = 8;
const int AUDIO_METER_GAP = 5;
const int AUDIO_METER_X = MIRROR_VIEW_LEFT_PADDING + MUTE_ICON_SIZE + AUDIO_METER_GAP;
const int INTER_ICON_GAP = 2;
int cameraSpace = 0;
int audioMeterWidth = MIRROR_VIEW_WIDTH - MUTE_ICON_SIZE - MUTE_ICON_PADDING;
int audioMeterScaleWidth = audioMeterWidth - 2;
int audioMeterX = MIRROR_VIEW_LEFT_PADDING + MUTE_ICON_SIZE + AUDIO_METER_GAP;
if (!Menu::getInstance()->isOptionChecked(MenuOption::NoFaceTracking)) {
cameraSpace = MUTE_ICON_SIZE + INTER_ICON_GAP;
audioMeterWidth -= cameraSpace;
audioMeterScaleWidth -= cameraSpace;
audioMeterX += cameraSpace;
}
int audioMeterY;
bool smallMirrorVisible = Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && !OculusManager::isConnected();
@ -834,13 +864,13 @@ void ApplicationOverlay::renderAudioMeter() {
const glm::vec4 AUDIO_METER_BLUE = { 0.0, 0.0, 1.0, 1.0 };
const glm::vec4 AUDIO_METER_GREEN = { 0.0, 1.0, 0.0, 1.0 };
const glm::vec4 AUDIO_METER_RED = { 1.0, 0.0, 0.0, 1.0 };
const float AUDIO_GREEN_START = 0.25 * AUDIO_METER_SCALE_WIDTH;
const float AUDIO_RED_START = 0.80 * AUDIO_METER_SCALE_WIDTH;
const float CLIPPING_INDICATOR_TIME = 1.0f;
const float AUDIO_METER_AVERAGING = 0.5;
const float LOG2 = log(2.0f);
const float METER_LOUDNESS_SCALE = 2.8f / 5.0f;
const float LOG2_LOUDNESS_FLOOR = 11.0f;
float audioGreenStart = 0.25f * audioMeterScaleWidth;
float audioRedStart = 0.8f * audioMeterScaleWidth;
float audioLevel = 0.0f;
float loudness = audio->getLastInputLoudness() + 1.0f;
@ -848,12 +878,12 @@ void ApplicationOverlay::renderAudioMeter() {
float log2loudness = log(_trailingAudioLoudness) / LOG2;
if (log2loudness <= LOG2_LOUDNESS_FLOOR) {
audioLevel = (log2loudness / LOG2_LOUDNESS_FLOOR) * METER_LOUDNESS_SCALE * AUDIO_METER_SCALE_WIDTH;
audioLevel = (log2loudness / LOG2_LOUDNESS_FLOOR) * METER_LOUDNESS_SCALE * audioMeterScaleWidth;
} else {
audioLevel = (log2loudness - (LOG2_LOUDNESS_FLOOR - 1.0f)) * METER_LOUDNESS_SCALE * AUDIO_METER_SCALE_WIDTH;
audioLevel = (log2loudness - (LOG2_LOUDNESS_FLOOR - 1.0f)) * METER_LOUDNESS_SCALE * audioMeterScaleWidth;
}
if (audioLevel > AUDIO_METER_SCALE_WIDTH) {
audioLevel = AUDIO_METER_SCALE_WIDTH;
if (audioLevel > audioMeterScaleWidth) {
audioLevel = audioMeterScaleWidth;
}
bool isClipping = ((audio->getTimeSinceLastClip() > 0.0f) && (audio->getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME));
@ -863,7 +893,7 @@ void ApplicationOverlay::renderAudioMeter() {
renderCollisionOverlay(glCanvas->width(), glCanvas->height(), magnitude, 1.0f);
}
DependencyManager::get<AudioToolBox>()->render(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, audioMeterY, boxed);
DependencyManager::get<AudioToolBox>()->render(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, audioMeterY, cameraSpace, boxed);
DependencyManager::get<AudioScope>()->render(glCanvas->width(), glCanvas->height());
DependencyManager::get<AudioIOStatsRenderer>()->render(WHITE_TEXT, glCanvas->width(), glCanvas->height());
@ -871,10 +901,10 @@ void ApplicationOverlay::renderAudioMeter() {
audioMeterY += AUDIO_METER_HEIGHT;
// Draw audio meter background Quad
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT,
DependencyManager::get<GeometryCache>()->renderQuad(audioMeterX, audioMeterY, audioMeterWidth, AUDIO_METER_HEIGHT,
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
if (audioLevel > AUDIO_RED_START) {
if (audioLevel > audioRedStart) {
glm::vec4 quadColor;
if (!isClipping) {
quadColor = AUDIO_METER_RED;
@ -882,16 +912,16 @@ void ApplicationOverlay::renderAudioMeter() {
quadColor = glm::vec4(1, 1, 1, 1);
}
// Draw Red Quad
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_RED_START,
DependencyManager::get<GeometryCache>()->renderQuad(audioMeterX + audioRedStart,
audioMeterY,
audioLevel - AUDIO_RED_START,
audioLevel - audioRedStart,
AUDIO_METER_HEIGHT, quadColor,
_audioRedQuad);
audioLevel = AUDIO_RED_START;
audioLevel = audioRedStart;
}
if (audioLevel > AUDIO_GREEN_START) {
if (audioLevel > audioGreenStart) {
glm::vec4 quadColor;
if (!isClipping) {
quadColor = AUDIO_METER_GREEN;
@ -899,13 +929,13 @@ void ApplicationOverlay::renderAudioMeter() {
quadColor = glm::vec4(1, 1, 1, 1);
}
// Draw Green Quad
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X + AUDIO_GREEN_START,
DependencyManager::get<GeometryCache>()->renderQuad(audioMeterX + audioGreenStart,
audioMeterY,
audioLevel - AUDIO_GREEN_START,
audioLevel - audioGreenStart,
AUDIO_METER_HEIGHT, quadColor,
_audioGreenQuad);
audioLevel = AUDIO_GREEN_START;
audioLevel = audioGreenStart;
}
if (audioLevel >= 0) {
@ -916,7 +946,7 @@ void ApplicationOverlay::renderAudioMeter() {
quadColor = glm::vec4(1, 1, 1, 1);
}
// Draw Blue (low level) quad
DependencyManager::get<GeometryCache>()->renderQuad(AUDIO_METER_X,
DependencyManager::get<GeometryCache>()->renderQuad(audioMeterX,
audioMeterY,
audioLevel, AUDIO_METER_HEIGHT, quadColor,
_audioBlueQuad);

View file

@ -101,6 +101,7 @@ private:
void renderPointersOculus(const glm::vec3& eyePos);
void renderAudioMeter();
void renderCameraToggle();
void renderStatsAndLogs();
void renderDomainConnectionStatusBorder();

View file

@ -57,7 +57,9 @@ public:
bool isAxis() const { return getType() == ChannelType::AXIS; }
bool isJoint() const { return getType() == ChannelType::JOINT; }
explicit Input() {}
// WORKAROUND: the explicit initializer here avoids a bug in GCC-4.8.2 (but not found in 4.9.2)
// where the default initializer (a C++-11ism) for the union data above is not applied.
explicit Input() : _id(0) {}
explicit Input(uint32 id) : _id(id) {}
explicit Input(uint16 device, uint16 channel, ChannelType type) : _device(device), _channel(channel), _type(uint16(type)) {}
Input(const Input& src) : _id(src._id) {}

View file

@ -427,6 +427,25 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode,
_bestZone->getStageAltitude());
scene->setStageDayTime(_bestZone->getStageHour());
scene->setStageYearTime(_bestZone->getStageDay());
if (_bestZone->getBackgroundMode() == BACKGROUND_MODE_ATMOSPHERE) {
EnvironmentData data = _bestZone->getEnvironmentData();
glm::vec3 keyLightDirection = scene->getKeyLightDirection();
glm::vec3 inverseKeyLightDirection = keyLightDirection * -1.0f;
// NOTE: is this right? It seems like the "sun" should be based on the center of the
// atmosphere, not where the camera is.
glm::vec3 keyLightLocation = _viewState->getAvatarPosition()
+ (inverseKeyLightDirection * data.getAtmosphereOuterRadius());
data.setSunLocation(keyLightLocation);
const float KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO = 20.0f;
float sunBrightness = scene->getKeyLightIntensity() * KEY_LIGHT_INTENSITY_TO_SUN_BRIGHTNESS_RATIO;
data.setSunBrightness(sunBrightness);
_viewState->overrideEnvironmentData(data);
}
} else {
if (_hasPreviousZone) {
scene->setKeyLightColor(_previousKeyLightColor);
@ -440,6 +459,7 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode,
scene->setStageYearTime(_previousStageDay);
_hasPreviousZone = false;
}
_viewState->endOverrideEnvironmentData();
}
// we must call endScene while we still have the tree locked so that no one deletes a model

View file

@ -13,4 +13,4 @@ find_package(Bullet REQUIRED)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
link_hifi_libraries(avatars shared octree gpu model fbx networking animation)
link_hifi_libraries(avatars shared octree gpu model fbx networking animation environment)

View file

@ -0,0 +1,196 @@
//
// AtmospherePropertyGroup.cpp
// libraries/entities/src
//
// Created by Brad Hefta-Gaub on 12/4/13.
// 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
//
#include <OctreePacketData.h>
#include "AtmospherePropertyGroup.h"
#include "EntityItemProperties.h"
#include "EntityItemPropertiesMacros.h"
AtmospherePropertyGroup::AtmospherePropertyGroup() {
_center = glm::vec3(0.0f);
_innerRadius = 0.0f;
_outerRadius = 0.0f;
_mieScattering = 0.0f;
_rayleighScattering = 0.0f;
_scatteringWavelengths = glm::vec3(0.0f);
_hasStars = true;
}
void AtmospherePropertyGroup::copyToScriptValue(QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const {
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_VEC3(Atmosphere, Center, center);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, InnerRadius, innerRadius);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, OuterRadius, outerRadius);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, MieScattering, mieScattering);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, RayleighScattering, rayleighScattering);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_VEC3(Atmosphere, ScatteringWavelengths, scatteringWavelengths);
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(Atmosphere, HasStars, hasStars);
}
void AtmospherePropertyGroup::copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) {
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_VEC3(atmosphere, center, setCenter);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(atmosphere, innerRadius, setInnerRadius);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(atmosphere, outerRadius, setOuterRadius);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(atmosphere, mieScattering, setMieScattering);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(atmosphere, rayleighScattering, setRayleighScattering);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_VEC3(atmosphere, scatteringWavelengths, setScatteringWavelengths);
COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_BOOL(atmosphere, hasStars, setHasStars);
}
void AtmospherePropertyGroup::debugDump() const {
qDebug() << " AtmospherePropertyGroup: ---------------------------------------------";
qDebug() << " Center:" << getCenter() << " has changed:" << centerChanged();
qDebug() << " Inner Radius:" << getInnerRadius() << " has changed:" << innerRadiusChanged();
qDebug() << " Outer Radius:" << getOuterRadius() << " has changed:" << outerRadiusChanged();
qDebug() << " Mie Scattering:" << getMieScattering() << " has changed:" << mieScatteringChanged();
qDebug() << " Rayleigh Scattering:" << getRayleighScattering() << " has changed:" << rayleighScatteringChanged();
qDebug() << " Scattering Wavelengths:" << getScatteringWavelengths() << " has changed:" << scatteringWavelengthsChanged();
qDebug() << " Has Stars:" << getHasStars() << " has changed:" << hasStarsChanged();
}
bool AtmospherePropertyGroup::appentToEditPacket(OctreePacketData* packetData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const {
bool successPropertyFits = true;
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_CENTER, appendValue, getCenter());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_INNER_RADIUS, appendValue, getInnerRadius());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_OUTER_RADIUS, appendValue, getOuterRadius());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_MIE_SCATTERING, appendValue, getMieScattering());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_RAYLEIGH_SCATTERING, appendValue, getRayleighScattering());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_SCATTERING_WAVELENGTHS, appendValue, getScatteringWavelengths());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_HAS_STARS, appendValue, getHasStars());
return true;
}
bool AtmospherePropertyGroup::decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt , int& processedBytes) {
int bytesRead = 0;
bool overwriteLocalData = true;
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_CENTER, glm::vec3, _center);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_INNER_RADIUS, float, _innerRadius);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_OUTER_RADIUS, float, _outerRadius);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_MIE_SCATTERING, float, _mieScattering);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_RAYLEIGH_SCATTERING, float, _rayleighScattering);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_SCATTERING_WAVELENGTHS, glm::vec3, _scatteringWavelengths);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_HAS_STARS, bool, _hasStars);
processedBytes += bytesRead;
return true;
}
void AtmospherePropertyGroup::markAllChanged() {
_centerChanged = true;
_innerRadiusChanged = true;
_outerRadiusChanged = true;
_mieScatteringChanged = true;
_rayleighScatteringChanged = true;
_scatteringWavelengthsChanged = true;
_hasStarsChanged = true;
}
EntityPropertyFlags AtmospherePropertyGroup::getChangedProperties() const {
EntityPropertyFlags changedProperties;
CHECK_PROPERTY_CHANGE(PROP_ATMOSPHERE_CENTER, center);
CHECK_PROPERTY_CHANGE(PROP_ATMOSPHERE_INNER_RADIUS, innerRadius);
CHECK_PROPERTY_CHANGE(PROP_ATMOSPHERE_OUTER_RADIUS, outerRadius);
CHECK_PROPERTY_CHANGE(PROP_ATMOSPHERE_MIE_SCATTERING, mieScattering);
CHECK_PROPERTY_CHANGE(PROP_ATMOSPHERE_RAYLEIGH_SCATTERING, rayleighScattering);
CHECK_PROPERTY_CHANGE(PROP_ATMOSPHERE_SCATTERING_WAVELENGTHS, scatteringWavelengths);
CHECK_PROPERTY_CHANGE(PROP_ATMOSPHERE_HAS_STARS, hasStars);
return changedProperties;
}
void AtmospherePropertyGroup::getProperties(EntityItemProperties& properties) const {
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Atmosphere, Center, getCenter);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Atmosphere, InnerRadius, getInnerRadius);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Atmosphere, OuterRadius, getOuterRadius);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Atmosphere, MieScattering, getMieScattering);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Atmosphere, MieScattering, getMieScattering);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Atmosphere, RayleighScattering, getRayleighScattering);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Atmosphere, ScatteringWavelengths, getScatteringWavelengths);
COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(Atmosphere, HasStars, getHasStars);
}
bool AtmospherePropertyGroup::setProperties(const EntityItemProperties& properties) {
bool somethingChanged = false;
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Atmosphere, Center, center, setCenter);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Atmosphere, InnerRadius, innerRadius, setInnerRadius);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Atmosphere, OuterRadius, outerRadius, setOuterRadius);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Atmosphere, MieScattering, mieScattering, setMieScattering);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Atmosphere, RayleighScattering, rayleighScattering, setRayleighScattering);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Atmosphere, ScatteringWavelengths, scatteringWavelengths, setScatteringWavelengths);
SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(Atmosphere, HasStars, hasStars, setHasStars);
return somethingChanged;
}
EntityPropertyFlags AtmospherePropertyGroup::getEntityProperties(EncodeBitstreamParams& params) const {
EntityPropertyFlags requestedProperties;
requestedProperties += PROP_ATMOSPHERE_CENTER;
requestedProperties += PROP_ATMOSPHERE_INNER_RADIUS;
requestedProperties += PROP_ATMOSPHERE_OUTER_RADIUS;
requestedProperties += PROP_ATMOSPHERE_MIE_SCATTERING;
requestedProperties += PROP_ATMOSPHERE_RAYLEIGH_SCATTERING;
requestedProperties += PROP_ATMOSPHERE_SCATTERING_WAVELENGTHS;
requestedProperties += PROP_ATMOSPHERE_HAS_STARS;
return requestedProperties;
}
void AtmospherePropertyGroup::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const {
bool successPropertyFits = true;
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_CENTER, appendValue, getCenter());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_INNER_RADIUS, appendValue, getInnerRadius());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_OUTER_RADIUS, appendValue, getOuterRadius());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_MIE_SCATTERING, appendValue, getMieScattering());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_RAYLEIGH_SCATTERING, appendValue, getRayleighScattering());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_SCATTERING_WAVELENGTHS, appendValue, getScatteringWavelengths());
APPEND_ENTITY_PROPERTY(PROP_ATMOSPHERE_HAS_STARS, appendValue, getHasStars());
}
int AtmospherePropertyGroup::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) {
int bytesRead = 0;
const unsigned char* dataAt = data;
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_CENTER, glm::vec3, _center);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_INNER_RADIUS, float, _innerRadius);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_OUTER_RADIUS, float, _outerRadius);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_MIE_SCATTERING, float, _mieScattering);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_RAYLEIGH_SCATTERING, float, _rayleighScattering);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_SCATTERING_WAVELENGTHS, glm::vec3, _scatteringWavelengths);
READ_ENTITY_PROPERTY(PROP_ATMOSPHERE_HAS_STARS, bool, _hasStars);
return bytesRead;
}

View file

@ -0,0 +1,102 @@
//
// AtmospherePropertyGroup.h
// libraries/entities/src
//
// Created by Brad Hefta-Gaub on 12/4/13.
// 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
//
#ifndef hifi_AtmospherePropertyGroup_h
#define hifi_AtmospherePropertyGroup_h
#include <QtScript/QScriptEngine>
#include "PropertyGroup.h"
#include "EntityItemPropertiesMacros.h"
class EntityItemProperties;
class EncodeBitstreamParams;
class OctreePacketData;
class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
#include <stdint.h>
#include <glm/glm.hpp>
/*
#include <glm/gtx/extented_min_max.hpp>
#include <QtCore/QObject>
#include <QVector>
#include <QString>
#include <AACube.h>
#include <FBXReader.h> // for SittingPoint
#include <PropertyFlags.h>
#include <OctreeConstants.h>
#include <ShapeInfo.h>
#include "EntityItemID.h"
#include "AtmospherePropertyGroupMacros.h"
#include "EntityTypes.h"
*/
class AtmospherePropertyGroup : public PropertyGroup {
public:
AtmospherePropertyGroup();
virtual ~AtmospherePropertyGroup() {}
// EntityItemProperty related helpers
virtual void copyToScriptValue(QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const;
virtual void copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings);
virtual void debugDump() const;
virtual bool appentToEditPacket(OctreePacketData* packetData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const;
virtual bool decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt , int& processedBytes);
virtual void markAllChanged();
virtual EntityPropertyFlags getChangedProperties() const;
// EntityItem related helpers
// methods for getting/setting all properties of an entity
virtual void getProperties(EntityItemProperties& propertiesOut) const;
/// returns true if something changed
virtual bool setProperties(const EntityItemProperties& properties);
virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const;
virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const;
virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData);
DEFINE_PROPERTY_REF(PROP_ATMOSPHERE_CENTER, Center, center, glm::vec3);
DEFINE_PROPERTY(PROP_ATMOSPHERE_INNER_RADIUS, InnerRadius, innerRadius, float);
DEFINE_PROPERTY(PROP_ATMOSPHERE_OUTER_RADIUS, OuterRadius, outerRadius, float);
DEFINE_PROPERTY(PROP_ATMOSPHERE_MIE_SCATTERING, MieScattering, mieScattering, float);
DEFINE_PROPERTY(PROP_ATMOSPHERE_RAYLEIGH_SCATTERING, RayleighScattering, rayleighScattering, float);
DEFINE_PROPERTY_REF(PROP_ATMOSPHERE_SCATTERING_WAVELENGTHS, ScatteringWavelengths, scatteringWavelengths, glm::vec3);
DEFINE_PROPERTY(PROP_ATMOSPHERE_HAS_STARS, HasStars, hasStars, bool);
};
#endif // hifi_AtmospherePropertyGroup_h

View file

@ -27,6 +27,8 @@
#include "TextEntityItem.h"
#include "ZoneEntityItem.h"
AtmospherePropertyGroup EntityItemProperties::_staticAtmosphere;
EntityPropertyList PROP_LAST_ITEM = (EntityPropertyList)(PROP_AFTER_LAST_ITEM - 1);
EntityItemProperties::EntityItemProperties() :
@ -87,6 +89,7 @@ EntityItemProperties::EntityItemProperties() :
CONSTRUCT_PROPERTY(stageDay, ZoneEntityItem::DEFAULT_STAGE_DAY),
CONSTRUCT_PROPERTY(stageHour, ZoneEntityItem::DEFAULT_STAGE_HOUR),
CONSTRUCT_PROPERTY(name, ENTITY_ITEM_DEFAULT_NAME),
CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT),
_id(UNKNOWN_ENTITY_ID),
_idSet(false),
@ -234,6 +237,43 @@ void EntityItemProperties::setShapeTypeFromString(const QString& shapeName) {
}
}
const char* backgroundModeNames[] = {"inherit", "atmosphere", "texture" };
QHash<QString, BackgroundMode> stringToBackgroundModeLookup;
void addBackgroundMode(BackgroundMode type) {
stringToBackgroundModeLookup[backgroundModeNames[type]] = type;
}
void buildStringToBackgroundModeLookup() {
addBackgroundMode(BACKGROUND_MODE_INHERIT);
addBackgroundMode(BACKGROUND_MODE_ATMOSPHERE);
addBackgroundMode(BACKGROUND_MODE_TEXTURE);
}
QString EntityItemProperties::getBackgroundModeAsString() const {
if (_backgroundMode < sizeof(backgroundModeNames) / sizeof(char *))
return QString(backgroundModeNames[_backgroundMode]);
return QString(backgroundModeNames[BACKGROUND_MODE_INHERIT]);
}
QString EntityItemProperties::getBackgroundModeString(BackgroundMode mode) {
if (mode < sizeof(backgroundModeNames) / sizeof(char *))
return QString(backgroundModeNames[mode]);
return QString(backgroundModeNames[BACKGROUND_MODE_INHERIT]);
}
void EntityItemProperties::setBackgroundModeFromString(const QString& backgroundMode) {
if (stringToBackgroundModeLookup.empty()) {
buildStringToBackgroundModeLookup();
}
auto backgroundModeItr = stringToBackgroundModeLookup.find(backgroundMode.toLower());
if (backgroundModeItr != stringToBackgroundModeLookup.end()) {
_backgroundMode = backgroundModeItr.value();
_backgroundModeChanged = true;
}
}
EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
EntityPropertyFlags changedProperties;
@ -294,6 +334,10 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
CHECK_PROPERTY_CHANGE(PROP_STAGE_DAY, stageDay);
CHECK_PROPERTY_CHANGE(PROP_STAGE_HOUR, stageHour);
CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_MODE, backgroundMode);
changedProperties += _atmosphere.getChangedProperties();
return changedProperties;
}
@ -375,6 +419,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
COPY_PROPERTY_TO_QSCRIPTVALUE(stageAltitude);
COPY_PROPERTY_TO_QSCRIPTVALUE(stageDay);
COPY_PROPERTY_TO_QSCRIPTVALUE(stageHour);
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(backgroundMode, getBackgroundModeAsString());
// Sitting properties support
if (!skipDefaults) {
@ -408,6 +453,8 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool
if (!skipDefaults) {
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_NO_SKIP(originalTextures, textureNamesList); // gettable, but not settable
}
_atmosphere.copyToScriptValue(properties, engine, skipDefaults, defaultEntityProperties);
return properties;
}
@ -477,7 +524,8 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(stageAltitude, setStageAltitude);
COPY_PROPERTY_FROM_QSCRIPTVALUE_INT(stageDay, setStageDay);
COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(stageHour, setStageHour);
COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(backgroundMode, BackgroundMode);
_atmosphere.copyFromScriptValue(object, _defaultSettings);
_lastEdited = usecTimestampNow();
}
@ -682,6 +730,11 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem
APPEND_ENTITY_PROPERTY(PROP_SHAPE_TYPE, appendValue, (uint32_t)properties.getShapeType());
APPEND_ENTITY_PROPERTY(PROP_COMPOUND_SHAPE_URL, appendValue, properties.getCompoundShapeURL());
APPEND_ENTITY_PROPERTY(PROP_BACKGROUND_MODE, appendValue, (uint32_t)properties.getBackgroundMode());
_staticAtmosphere.setProperties(properties);
_staticAtmosphere.appentToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState );
}
APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, appendValue, properties.getMarketplaceID());
@ -931,6 +984,8 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_STAGE_HOUR, float, setStageHour);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_SHAPE_TYPE, ShapeType, setShapeType);
READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_COMPOUND_SHAPE_URL, setCompoundShapeURL);
READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_BACKGROUND_MODE, BackgroundMode, setBackgroundMode);
properties.getAtmosphere().decodeFromEditPacket(propertyFlags, dataAt , processedBytes);
}
READ_ENTITY_PROPERTY_STRING_TO_PROPERTIES(PROP_MARKETPLACE_ID, setMarketplaceID);
@ -1032,6 +1087,10 @@ void EntityItemProperties::markAllChanged() {
_stageAltitudeChanged = true;
_stageDayChanged = true;
_stageHourChanged = true;
_backgroundModeChanged = true;
_atmosphere.markAllChanged();
}
/// The maximum bounding cube for the entity, independent of it's rotation.

View file

@ -29,115 +29,11 @@
#include <OctreeConstants.h>
#include <ShapeInfo.h>
#include "AtmospherePropertyGroup.h"
#include "EntityItemID.h"
#include "EntityItemPropertiesMacros.h"
#include "EntityTypes.h"
enum EntityPropertyList {
PROP_PAGED_PROPERTY,
PROP_CUSTOM_PROPERTIES_INCLUDED,
// these properties are supported by the EntityItem base class
PROP_VISIBLE,
PROP_POSITION,
PROP_RADIUS, // NOTE: PROP_RADIUS is obsolete and only included in old format streams
PROP_DIMENSIONS = PROP_RADIUS,
PROP_ROTATION,
PROP_DENSITY,
PROP_VELOCITY,
PROP_GRAVITY,
PROP_DAMPING,
PROP_LIFETIME,
PROP_SCRIPT,
// these properties are supported by some derived classes
PROP_COLOR,
PROP_MODEL_URL,
PROP_ANIMATION_URL,
PROP_ANIMATION_FPS,
PROP_ANIMATION_FRAME_INDEX,
PROP_ANIMATION_PLAYING,
// these properties are supported by the EntityItem base class
PROP_REGISTRATION_POINT,
PROP_ANGULAR_VELOCITY,
PROP_ANGULAR_DAMPING,
PROP_IGNORE_FOR_COLLISIONS,
PROP_COLLISIONS_WILL_MOVE,
// property used by Light entity
PROP_IS_SPOTLIGHT,
PROP_DIFFUSE_COLOR_UNUSED,
PROP_AMBIENT_COLOR_UNUSED,
PROP_SPECULAR_COLOR_UNUSED,
PROP_INTENSITY, // Previously PROP_CONSTANT_ATTENUATION
PROP_LINEAR_ATTENUATION_UNUSED,
PROP_QUADRATIC_ATTENUATION_UNUSED,
PROP_EXPONENT,
PROP_CUTOFF,
// available to all entities
PROP_LOCKED,
// used by Model entities
PROP_TEXTURES,
PROP_ANIMATION_SETTINGS,
PROP_USER_DATA,
PROP_SHAPE_TYPE,
// used by ParticleEffect entities
PROP_MAX_PARTICLES,
PROP_LIFESPAN,
PROP_EMIT_RATE,
PROP_EMIT_DIRECTION,
PROP_EMIT_STRENGTH,
PROP_LOCAL_GRAVITY,
PROP_PARTICLE_RADIUS,
PROP_COMPOUND_SHAPE_URL,
PROP_MARKETPLACE_ID,
PROP_ACCELERATION,
PROP_SIMULATOR_ID,
PROP_NAME,
////////////////////////////////////////////////////////////////////////////////////////////////////
// ATTENTION: add new properties ABOVE this line
PROP_AFTER_LAST_ITEM,
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// WARNING! Do not add props here unless you intentionally mean to reuse PROP_ indexes
//
// These properties of TextEntity piggy back off of properties of ModelEntities, the type doesn't matter
// since the derived class knows how to interpret it's own properties and knows the types it expects
PROP_TEXT_COLOR = PROP_COLOR,
PROP_TEXT = PROP_MODEL_URL,
PROP_LINE_HEIGHT = PROP_ANIMATION_URL,
PROP_BACKGROUND_COLOR = PROP_ANIMATION_FPS,
PROP_COLLISION_MODEL_URL_OLD_VERSION = PROP_ANIMATION_FPS + 1,
// Aliases/Piggyback properties for Zones. These properties intentionally reuse the enum values for
// other properties which will never overlap with each other. We do this so that we don't have to expand
// the size of the properties bitflags mask
PROP_KEYLIGHT_COLOR = PROP_COLOR,
PROP_KEYLIGHT_INTENSITY = PROP_INTENSITY,
PROP_KEYLIGHT_AMBIENT_INTENSITY = PROP_CUTOFF,
PROP_KEYLIGHT_DIRECTION = PROP_EXPONENT,
PROP_STAGE_SUN_MODEL_ENABLED = PROP_IS_SPOTLIGHT,
PROP_STAGE_LATITUDE = PROP_DIFFUSE_COLOR_UNUSED,
PROP_STAGE_LONGITUDE = PROP_AMBIENT_COLOR_UNUSED,
PROP_STAGE_ALTITUDE = PROP_SPECULAR_COLOR_UNUSED,
PROP_STAGE_DAY = PROP_LINEAR_ATTENUATION_UNUSED,
PROP_STAGE_HOUR = PROP_QUADRATIC_ATTENUATION_UNUSED,
// WARNING!!! DO NOT ADD PROPS_xxx here unless you really really meant to.... Add them UP above
};
typedef PropertyFlags<EntityPropertyList> EntityPropertyFlags;
// this is set at the top of EntityItemProperties.cpp to PROP_AFTER_LAST_ITEM - 1. PROP_AFTER_LAST_ITEM is always
// one greater than the last item property due to the enum's auto-incrementing.
extern EntityPropertyList PROP_LAST_ITEM;
#include "EntityPropertyFlags.h"
const quint64 UNKNOWN_CREATED_TIME = 0;
@ -242,6 +138,10 @@ public:
DEFINE_PROPERTY(PROP_STAGE_DAY, StageDay, stageDay, quint16);
DEFINE_PROPERTY(PROP_STAGE_HOUR, StageHour, stageHour, float);
DEFINE_PROPERTY_REF(PROP_NAME, Name, name, QString);
DEFINE_PROPERTY_GROUP(Atmosphere, atmosphere, AtmospherePropertyGroup);
DEFINE_PROPERTY_REF_ENUM(PROP_BACKGROUND_MODE, BackgroundMode, backgroundMode, BackgroundMode);
static QString getBackgroundModeString(BackgroundMode mode);
public:
@ -376,6 +276,7 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) {
DEBUG_PROPERTY_IF_CHANGED(debug, properties, LocalGravity, localGravity, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, ParticleRadius, particleRadius, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, MarketplaceID, marketplaceID, "");
DEBUG_PROPERTY_IF_CHANGED(debug, properties, BackgroundMode, backgroundMode, "");
debug << " last edited:" << properties.getLastEdited() << "\n";
debug << " edited ago:" << properties.getEditedAgo() << "\n";

View file

@ -51,7 +51,6 @@
} \
}
#define READ_ENTITY_PROPERTY_QUAT(P,M) \
if (propertyFlags.getHasProperty(P)) { \
glm::quat fromBuffer; \
@ -181,15 +180,25 @@
somethingChanged = true; \
}
#define SET_ENTITY_GROUP_PROPERTY_FROM_PROPERTIES(G,P,p,M) \
if (properties.get##G().p##Changed()) { \
M(properties.get##G().get##P()); \
somethingChanged = true; \
}
#define SET_ENTITY_PROPERTY_FROM_PROPERTIES_GETTER(C,G,S) \
if (properties.C()) { \
S(properties.G()); \
somethingChanged = true; \
}
#define COPY_ENTITY_PROPERTY_TO_PROPERTIES(M,G) \
properties._##M = G(); \
properties._##M##Changed = false;
#define COPY_ENTITY_PROPERTY_TO_PROPERTIES(P,M) \
properties._##P = M(); \
properties._##P##Changed = false;
#define COPY_ENTITY_GROUP_PROPERTY_TO_PROPERTIES(G,P,M) \
properties.get##G().set##P(M()); \
properties.get##G().set##P##Changed(false);
#define CHECK_PROPERTY_CHANGE(P,M) \
if (_##M##Changed) { \
@ -197,6 +206,27 @@
}
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE_VEC3(G,P,p) \
if (!skipDefaults || defaultEntityProperties.get##G().get##P() != _##p) { \
QScriptValue groupProperties = properties.property(#G); \
if (!groupProperties.isValid()) { \
groupProperties = engine->newObject(); \
} \
QScriptValue V = vec3toScriptValue(engine, _##p); \
groupProperties.setProperty(#p, V); \
properties.setProperty(#G, groupProperties); \
}
#define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(G,P,p) \
if (!skipDefaults || defaultEntityProperties.get##G().get##P() != _##p) { \
QScriptValue groupProperties = properties.property(#G); \
if (!groupProperties.isValid()) { \
groupProperties = engine->newObject(); \
} \
groupProperties.setProperty(#p, _##p); \
properties.setProperty(#G, groupProperties); \
}
#define COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(P) \
if (!skipDefaults || defaultEntityProperties._##P != _##P) { \
QScriptValue P = vec3toScriptValue(engine, _##P); \
@ -243,6 +273,20 @@
} \
}
#define COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(G, P, S) \
{ \
QScriptValue G = object.property(#G); \
if (G.isValid()) { \
QScriptValue P = G.property(#P); \
if (P.isValid()) { \
float newValue = P.toVariant().toFloat(); \
if (_defaultSettings || newValue != _##P) { \
S(newValue); \
} \
} \
} \
}
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_INT(P, S) \
QScriptValue P = object.property(#P); \
if (P.isValid()) { \
@ -261,6 +305,20 @@
} \
}
#define COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_BOOL(G, P, S) \
{ \
QScriptValue G = object.property(#G); \
if (G.isValid()) { \
QScriptValue P = G.property(#P); \
if (P.isValid()) { \
float newValue = P.toVariant().toBool(); \
if (_defaultSettings || newValue != _##P) { \
S(newValue); \
} \
} \
} \
}
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_STRING(P, S)\
QScriptValue P = object.property(#P); \
if (P.isValid()) { \
@ -299,6 +357,32 @@
} \
} \
}
#define COPY_GROUP_PROPERTY_FROM_QSCRIPTVALUE_VEC3(G, P, S) \
{ \
QScriptValue G = object.property(#G); \
if (G.isValid()) { \
QScriptValue P = G.property(#P); \
if (P.isValid()) { \
QScriptValue x = P.property("x"); \
QScriptValue y = P.property("y"); \
QScriptValue z = P.property("z"); \
if (x.isValid() && y.isValid() && z.isValid()) { \
glm::vec3 newValue; \
newValue.x = x.toVariant().toFloat(); \
newValue.y = y.toVariant().toFloat(); \
newValue.z = z.toVariant().toFloat(); \
bool isValid = !glm::isnan(newValue.x) && \
!glm::isnan(newValue.y) && \
!glm::isnan(newValue.z); \
if (isValid && \
(_defaultSettings || newValue != _##P)) { \
S(newValue); \
} \
} \
} \
} \
}
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_QUAT(P, S) \
QScriptValue P = object.property(#P); \
@ -357,6 +441,14 @@
_##n(V), \
_##n##Changed(false)
#define DEFINE_PROPERTY_GROUP(N, n, T) \
public: \
const T& get##N() const { return _##n; } \
T& get##N() { return _##n; } \
private: \
T _##n; \
static T _static##N;
#define DEFINE_PROPERTY(P, N, n, T) \
public: \
T get##N() const { return _##n; } \
@ -365,7 +457,7 @@
void set##N##Changed(bool value) { _##n##Changed = value; } \
private: \
T _##n; \
bool _##n##Changed;
bool _##n##Changed = false;
#define DEFINE_PROPERTY_REF(P, N, n, T) \
public: \
@ -375,7 +467,7 @@
void set##N##Changed(bool value) { _##n##Changed = value; } \
private: \
T _##n; \
bool _##n##Changed;
bool _##n##Changed = false;
#define DEFINE_PROPERTY_REF_WITH_SETTER(P, N, n, T) \
public: \

View file

@ -0,0 +1,165 @@
//
// EntityPropertyFlags.h
// libraries/entities/src
//
// Created by Brad Hefta-Gaub on 12/4/13.
// 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
//
#ifndef hifi_EntityPropertyFlags_h
#define hifi_EntityPropertyFlags_h
/*
#include <stdint.h>
#include <glm/glm.hpp>
#include <glm/gtx/extented_min_max.hpp>
#include <QtScript/QScriptEngine>
#include <QtCore/QObject>
#include <QVector>
#include <QString>
#include <AACube.h>
#include <FBXReader.h> // for SittingPoint
*/
#include <PropertyFlags.h>
/*
#include <OctreeConstants.h>
#include <ShapeInfo.h>
#include "AtmospherePropertyGroup.h"
#include "EntityItemID.h"
#include "EntityItemPropertiesMacros.h"
#include "EntityTypes.h"
*/
enum EntityPropertyList {
PROP_PAGED_PROPERTY,
PROP_CUSTOM_PROPERTIES_INCLUDED,
// these properties are supported by the EntityItem base class
PROP_VISIBLE,
PROP_POSITION,
PROP_RADIUS, // NOTE: PROP_RADIUS is obsolete and only included in old format streams
PROP_DIMENSIONS = PROP_RADIUS,
PROP_ROTATION,
PROP_DENSITY,
PROP_VELOCITY,
PROP_GRAVITY,
PROP_DAMPING,
PROP_LIFETIME,
PROP_SCRIPT,
// these properties are supported by some derived classes
PROP_COLOR,
// these are used by models only
PROP_MODEL_URL,
PROP_ANIMATION_URL,
PROP_ANIMATION_FPS,
PROP_ANIMATION_FRAME_INDEX,
PROP_ANIMATION_PLAYING,
// these properties are supported by the EntityItem base class
PROP_REGISTRATION_POINT,
PROP_ANGULAR_VELOCITY,
PROP_ANGULAR_DAMPING,
PROP_IGNORE_FOR_COLLISIONS,
PROP_COLLISIONS_WILL_MOVE,
// property used by Light entity
PROP_IS_SPOTLIGHT,
PROP_DIFFUSE_COLOR_UNUSED,
PROP_AMBIENT_COLOR_UNUSED,
PROP_SPECULAR_COLOR_UNUSED,
PROP_INTENSITY, // Previously PROP_CONSTANT_ATTENUATION
PROP_LINEAR_ATTENUATION_UNUSED,
PROP_QUADRATIC_ATTENUATION_UNUSED,
PROP_EXPONENT,
PROP_CUTOFF,
// available to all entities
PROP_LOCKED,
PROP_TEXTURES, // used by Model entities
PROP_ANIMATION_SETTINGS, // used by Model entities
PROP_USER_DATA, // all entities
PROP_SHAPE_TYPE, // used by Model + zones entities
// used by ParticleEffect entities
PROP_MAX_PARTICLES,
PROP_LIFESPAN,
PROP_EMIT_RATE,
PROP_EMIT_DIRECTION,
PROP_EMIT_STRENGTH,
PROP_LOCAL_GRAVITY,
PROP_PARTICLE_RADIUS,
PROP_COMPOUND_SHAPE_URL, // used by Model + zones entities
PROP_MARKETPLACE_ID, // all entities
PROP_ACCELERATION, // all entities
PROP_SIMULATOR_ID, // all entities
PROP_NAME, // all entities
////////////////////////////////////////////////////////////////////////////////////////////////////
// ATTENTION: add new properties ABOVE this line
PROP_AFTER_LAST_ITEM,
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// WARNING! Do not add props here unless you intentionally mean to reuse PROP_ indexes
//
// These properties of TextEntity piggy back off of properties of ModelEntities, the type doesn't matter
// since the derived class knows how to interpret it's own properties and knows the types it expects
PROP_TEXT_COLOR = PROP_COLOR,
PROP_TEXT = PROP_MODEL_URL,
PROP_LINE_HEIGHT = PROP_ANIMATION_URL,
PROP_BACKGROUND_COLOR = PROP_ANIMATION_FPS,
PROP_COLLISION_MODEL_URL_OLD_VERSION = PROP_ANIMATION_FPS + 1,
// Aliases/Piggyback properties for Zones. These properties intentionally reuse the enum values for
// other properties which will never overlap with each other. We do this so that we don't have to expand
// the size of the properties bitflags mask
PROP_KEYLIGHT_COLOR = PROP_COLOR,
PROP_KEYLIGHT_INTENSITY = PROP_INTENSITY,
PROP_KEYLIGHT_AMBIENT_INTENSITY = PROP_CUTOFF,
PROP_KEYLIGHT_DIRECTION = PROP_EXPONENT,
PROP_STAGE_SUN_MODEL_ENABLED = PROP_IS_SPOTLIGHT,
PROP_STAGE_LATITUDE = PROP_DIFFUSE_COLOR_UNUSED,
PROP_STAGE_LONGITUDE = PROP_AMBIENT_COLOR_UNUSED,
PROP_STAGE_ALTITUDE = PROP_SPECULAR_COLOR_UNUSED,
PROP_STAGE_DAY = PROP_LINEAR_ATTENUATION_UNUSED,
PROP_STAGE_HOUR = PROP_QUADRATIC_ATTENUATION_UNUSED,
PROP_ATMOSPHERE_CENTER = PROP_MAX_PARTICLES,
PROP_ATMOSPHERE_INNER_RADIUS = PROP_LIFESPAN,
PROP_ATMOSPHERE_OUTER_RADIUS = PROP_EMIT_RATE,
PROP_ATMOSPHERE_MIE_SCATTERING = PROP_EMIT_DIRECTION,
PROP_ATMOSPHERE_RAYLEIGH_SCATTERING = PROP_EMIT_STRENGTH,
PROP_ATMOSPHERE_SCATTERING_WAVELENGTHS = PROP_LOCAL_GRAVITY,
PROP_ATMOSPHERE_HAS_STARS = PROP_PARTICLE_RADIUS,
PROP_BACKGROUND_MODE = PROP_MODEL_URL,
// WARNING!!! DO NOT ADD PROPS_xxx here unless you really really meant to.... Add them UP above
};
typedef PropertyFlags<EntityPropertyList> EntityPropertyFlags;
// this is set at the top of EntityItemProperties.cpp to PROP_AFTER_LAST_ITEM - 1. PROP_AFTER_LAST_ITEM is always
// one greater than the last item property due to the enum's auto-incrementing.
extern EntityPropertyList PROP_LAST_ITEM;
enum BackgroundMode {
BACKGROUND_MODE_INHERIT,
BACKGROUND_MODE_ATMOSPHERE,
BACKGROUND_MODE_TEXTURE,
};
#endif // hifi_EntityPropertyFlags_h

View file

@ -0,0 +1,100 @@
//
// PropertyGroup.h
// libraries/entities/src
//
// Created by Brad Hefta-Gaub on 12/4/13.
// 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
//
#ifndef hifi_PropertyGroup_h
#define hifi_PropertyGroup_h
#include <QtScript/QScriptEngine>
//#include "EntityItemProperties.h"
#include "EntityPropertyFlags.h"
class EntityItemProperties;
class EncodeBitstreamParams;
class OctreePacketData;
class EntityTreeElementExtraEncodeData;
class ReadBitstreamToTreeParams;
#include <OctreeElement.h>
/*
#include <stdint.h>
#include <glm/glm.hpp>
#include <glm/gtx/extented_min_max.hpp>
#include <QtCore/QObject>
#include <QVector>
#include <QString>
#include <AACube.h>
#include <FBXReader.h> // for SittingPoint
#include <PropertyFlags.h>
#include <OctreeConstants.h>
#include <ShapeInfo.h>
#include "EntityItemID.h"
#include "PropertyGroupMacros.h"
#include "EntityTypes.h"
*/
//typedef PropertyFlags<EntityPropertyList> EntityPropertyFlags;
class PropertyGroup {
public:
PropertyGroup() {}
virtual ~PropertyGroup() {}
// EntityItemProperty related helpers
virtual void copyToScriptValue(QScriptValue& properties, QScriptEngine* engine, bool skipDefaults, EntityItemProperties& defaultEntityProperties) const = 0;
virtual void copyFromScriptValue(const QScriptValue& object, bool& _defaultSettings) = 0;
virtual void debugDump() const { }
virtual bool appentToEditPacket(OctreePacketData* packetData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const = 0;
virtual bool decodeFromEditPacket(EntityPropertyFlags& propertyFlags, const unsigned char*& dataAt , int& processedBytes) = 0;
virtual void markAllChanged() = 0;
virtual EntityPropertyFlags getChangedProperties() const = 0;
// EntityItem related helpers
// methods for getting/setting all properties of an entity
virtual void getProperties(EntityItemProperties& propertiesOut) const = 0;
/// returns true if something changed
virtual bool setProperties(const EntityItemProperties& properties) = 0;
/// Override this in your derived class if you'd like to be informed when something about the state of the entity
/// has changed. This will be called with properties change or when new data is loaded from a stream
virtual void somethingChangedNotification() { }
virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const = 0;
virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeData* entityTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const = 0;
virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) = 0;
};
#endif // hifi_PropertyGroup_h

View file

@ -61,10 +61,32 @@ ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID, const EntityIte
_stageHour = DEFAULT_STAGE_HOUR;
_shapeType = DEFAULT_SHAPE_TYPE;
_compoundShapeURL = DEFAULT_COMPOUND_SHAPE_URL;
_backgroundMode = BACKGROUND_MODE_INHERIT;
setProperties(properties);
}
EnvironmentData ZoneEntityItem::getEnvironmentData() const {
EnvironmentData result;
result.setAtmosphereCenter(_atmospherePropeties.getCenter());
result.setAtmosphereInnerRadius(_atmospherePropeties.getInnerRadius());
result.setAtmosphereOuterRadius(_atmospherePropeties.getOuterRadius());
result.setRayleighScattering(_atmospherePropeties.getRayleighScattering());
result.setMieScattering(_atmospherePropeties.getMieScattering());
result.setScatteringWavelengths(_atmospherePropeties.getScatteringWavelengths());
result.setHasStars(_atmospherePropeties.getHasStars());
// NOTE: The sunLocation and SunBrightness will be overwritten in the EntityTreeRenderer to use the
// keyLight details from the scene interface
//result.setSunLocation(1000, 900, 1000));
//result.setSunBrightness(20.0f);
return result;
}
EntityItemProperties ZoneEntityItem::getProperties() const {
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
@ -81,6 +103,10 @@ EntityItemProperties ZoneEntityItem::getProperties() const {
COPY_ENTITY_PROPERTY_TO_PROPERTIES(shapeType, getShapeType);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(compoundShapeURL, getCompoundShapeURL);
COPY_ENTITY_PROPERTY_TO_PROPERTIES(backgroundMode, getBackgroundMode);
_atmospherePropeties.getProperties(properties);
return properties;
}
@ -100,6 +126,11 @@ bool ZoneEntityItem::setProperties(const EntityItemProperties& properties) {
SET_ENTITY_PROPERTY_FROM_PROPERTIES(stageHour, setStageHour);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(shapeType, updateShapeType);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(compoundShapeURL, setCompoundShapeURL);
SET_ENTITY_PROPERTY_FROM_PROPERTIES(backgroundMode, setBackgroundMode);
bool somethingChangedInAtmosphere = _atmospherePropeties.setProperties(properties);
somethingChanged = somethingChanged || somethingChangedInAtmosphere;
if (somethingChanged) {
bool wantDebug = false;
@ -111,13 +142,13 @@ bool ZoneEntityItem::setProperties(const EntityItemProperties& properties) {
}
setLastEdited(properties._lastEdited);
}
return somethingChanged;
}
int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData) {
int bytesRead = 0;
const unsigned char* dataAt = data;
@ -133,6 +164,9 @@ int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
READ_ENTITY_PROPERTY(PROP_STAGE_HOUR, float, _stageHour);
READ_ENTITY_PROPERTY_SETTER(PROP_SHAPE_TYPE, ShapeType, updateShapeType);
READ_ENTITY_PROPERTY_STRING(PROP_COMPOUND_SHAPE_URL, setCompoundShapeURL);
READ_ENTITY_PROPERTY_SETTER(PROP_BACKGROUND_MODE, BackgroundMode, setBackgroundMode);
bytesRead += _atmospherePropeties.readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args,
propertyFlags, overwriteLocalData);
return bytesRead;
}
@ -154,6 +188,8 @@ EntityPropertyFlags ZoneEntityItem::getEntityProperties(EncodeBitstreamParams& p
requestedProperties += PROP_STAGE_HOUR;
requestedProperties += PROP_SHAPE_TYPE;
requestedProperties += PROP_COMPOUND_SHAPE_URL;
requestedProperties += PROP_BACKGROUND_MODE;
requestedProperties += _atmospherePropeties.getEntityProperties(params);
return requestedProperties;
}
@ -180,6 +216,11 @@ void ZoneEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits
APPEND_ENTITY_PROPERTY(PROP_STAGE_HOUR, appendValue, getStageHour());
APPEND_ENTITY_PROPERTY(PROP_SHAPE_TYPE, appendValue, (uint32_t)getShapeType());
APPEND_ENTITY_PROPERTY(PROP_COMPOUND_SHAPE_URL, appendValue, getCompoundShapeURL());
APPEND_ENTITY_PROPERTY(PROP_BACKGROUND_MODE, appendValue, (uint32_t)getBackgroundMode()); // could this be a uint16??
_atmospherePropeties.appendSubclassData(packetData, params, modelTreeElementExtraEncodeData, requestedProperties,
propertyFlags, propertiesDidntFit, propertyCount, appendState);
}
void ZoneEntityItem::debugDump() const {
@ -198,6 +239,9 @@ void ZoneEntityItem::debugDump() const {
qCDebug(entities) << " _stageAltitude:" << _stageAltitude;
qCDebug(entities) << " _stageDay:" << _stageDay;
qCDebug(entities) << " _stageHour:" << _stageHour;
qCDebug(entities) << " _backgroundMode:" << EntityItemProperties::getBackgroundModeString(_backgroundMode);
_atmospherePropeties.debugDump();
}
ShapeType ZoneEntityItem::getShapeType() const {

View file

@ -12,6 +12,9 @@
#ifndef hifi_ZoneEntityItem_h
#define hifi_ZoneEntityItem_h
#include <EnvironmentData.h>
#include "AtmospherePropertyGroup.h"
#include "EntityItem.h"
class ZoneEntityItem : public EntityItem {
@ -103,6 +106,11 @@ public:
const QString getCompoundShapeURL() const { return _compoundShapeURL; }
virtual void setCompoundShapeURL(const QString& url);
void setBackgroundMode(BackgroundMode value) { _backgroundMode = value; }
BackgroundMode getBackgroundMode() const { return _backgroundMode; }
EnvironmentData getEnvironmentData() const;
virtual bool supportsDetailedRayIntersection() const { return true; }
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,
@ -138,6 +146,9 @@ protected:
ShapeType _shapeType = SHAPE_TYPE_NONE;
QString _compoundShapeURL;
BackgroundMode _backgroundMode = BACKGROUND_MODE_INHERIT;
AtmospherePropertyGroup _atmospherePropeties;
static bool _drawZoneBoundaries;
static bool _zonesArePickable;

View file

@ -27,7 +27,8 @@ EnvironmentData::EnvironmentData(int id) :
_mieScattering(0.0010f),
_scatteringWavelengths(0.650f, 0.570f, 0.475f),
_sunLocation(1000, 900, 1000),
_sunBrightness(20.0f) {
_sunBrightness(20.0f),
_hasStars(true) {
}
glm::vec3 EnvironmentData::getAtmosphereCenter(const glm::vec3& cameraPosition) const {

View file

@ -28,6 +28,9 @@ public:
void setGravity(float gravity) { _gravity = gravity; }
float getGravity() const { return _gravity; }
void setHasStars(bool value) { _hasStars = value; }
bool getHasStars() const { return _hasStars; }
void setAtmosphereCenter(const glm::vec3& center) { _atmosphereCenter = center; }
void setAtmosphereInnerRadius(float radius) { _atmosphereInnerRadius = radius; }
void setAtmosphereOuterRadius(float radius) { _atmosphereOuterRadius = radius; }
@ -73,6 +76,8 @@ private:
glm::vec3 _sunLocation;
float _sunBrightness;
bool _hasStars;
};
#endif // hifi_EnvironmentData_h

View file

@ -72,7 +72,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
return 1;
case PacketTypeEntityAddOrEdit:
case PacketTypeEntityData:
return VERSION_ENTITIES_HAVE_NAMES;
return VERSION_ENTITIES_ZONE_ENTITIES_HAVE_ATMOSPHERE;
case PacketTypeEntityErase:
return 2;
case PacketTypeAudioStreamStats:

View file

@ -161,5 +161,6 @@ const PacketVersion VERSION_ENTITIES_HAVE_UUIDS = 16;
const PacketVersion VERSION_ENTITIES_ZONE_ENTITIES_EXIST = 17;
const PacketVersion VERSION_ENTITIES_ZONE_ENTITIES_HAVE_DYNAMIC_SHAPE = 18;
const PacketVersion VERSION_ENTITIES_HAVE_NAMES = 19;
const PacketVersion VERSION_ENTITIES_ZONE_ENTITIES_HAVE_ATMOSPHERE = 20;
#endif // hifi_PacketHeaders_h

View file

@ -18,6 +18,7 @@ class Transform;
class QThread;
class ViewFrustum;
class PickRay;
class EnvironmentData;
/// Interface provided by Application to other objects that need access to the current view state details
class AbstractViewStateInterface {
@ -32,6 +33,10 @@ public:
/// gets the current view frustum for rendering the view state
virtual ViewFrustum* getCurrentViewFrustum() = 0;
/// overrides environment data
virtual void overrideEnvironmentData(const EnvironmentData& newData) = 0;
virtual void endOverrideEnvironmentData() = 0;
/// gets the shadow view frustum for rendering the view state
virtual ViewFrustum* getShadowViewFrustum() = 0;

View file

@ -3,6 +3,6 @@ set(TARGET_NAME octree-tests)
setup_hifi_project(Script Network)
# link in the shared libraries
link_hifi_libraries(shared octree gpu model fbx networking entities avatars audio animation script-engine physics)
link_hifi_libraries(shared octree gpu model fbx networking environment entities avatars audio animation script-engine physics)
copy_dlls_beside_windows_executable()

View file

@ -162,6 +162,7 @@ public:
Mirror,
MuteAudio,
MuteEnvironment,
MuteFaceTracking,
NoFaceTracking,
NoShadows,
OctreeStats,