diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 2df3cb1ab9..fe035e3c51 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -8,15 +8,11 @@ set(MACRO_DIR "${ROOT_DIR}/cmake/macros") # setup for find modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/") -find_package(Qt5Network REQUIRED) -find_package(Qt5Script REQUIRED) -find_package(Qt5Widgets REQUIRED) +find_package(Qt5 COMPONENTS Network Script Widgets) include("${MACRO_DIR}/SetupHifiProject.cmake") setup_hifi_project(${TARGET_NAME} TRUE) -qt5_use_modules(${TARGET_NAME} Network Script Widgets) - # include glm include("${MACRO_DIR}/IncludeGLM.cmake") include_glm(${TARGET_NAME} "${ROOT_DIR}") @@ -40,3 +36,5 @@ endif (UNIX) IF (WIN32) target_link_libraries(${TARGET_NAME} Winmm Ws2_32) ENDIF(WIN32) + +target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script) diff --git a/domain-server/CMakeLists.txt b/domain-server/CMakeLists.txt index a4624dbbf7..eeaa4dc150 100644 --- a/domain-server/CMakeLists.txt +++ b/domain-server/CMakeLists.txt @@ -18,8 +18,6 @@ include(${MACRO_DIR}/SetupHifiProject.cmake) setup_hifi_project(${TARGET_NAME} TRUE) -qt5_use_modules(${TARGET_NAME} Network) - # remove and then copy the files for the webserver add_custom_command(TARGET ${TARGET_NAME} POST_BUILD COMMAND "${CMAKE_COMMAND}" -E remove_directory @@ -36,4 +34,6 @@ link_hifi_library(embedded-webserver ${TARGET_NAME} "${ROOT_DIR}") IF (WIN32) target_link_libraries(${TARGET_NAME} Winmm Ws2_32) -ENDIF(WIN32) \ No newline at end of file +ENDIF(WIN32) + +target_link_libraries(${TARGET_NAME} Qt5::Network) \ No newline at end of file diff --git a/examples/bot.js b/examples/bot.js index 8d70cc8656..5fd4785b76 100644 --- a/examples/bot.js +++ b/examples/bot.js @@ -18,6 +18,10 @@ function getRandomInt (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } +function printVector(string, vector) { + print(string + " " + vector.x + ", " + vector.y + ", " + vector.z); +} + var CHANCE_OF_MOVING = 0.005; var CHANCE_OF_SOUND = 0.005; var CHANCE_OF_HEAD_TURNING = 0.05; @@ -31,6 +35,7 @@ var X_MIN = 0.0; var X_MAX = 5.0; var Z_MIN = 0.0; var Z_MAX = 5.0; +var Y_PELVIS = 2.5; var MOVE_RANGE_SMALL = 0.5; var MOVE_RANGE_BIG = Math.max(X_MAX - X_MIN, Z_MAX - Z_MIN) / 2.0; @@ -41,7 +46,7 @@ var TURN_RATE = 0.15; var PITCH_RATE = 0.20; var PITCH_RANGE = 30.0; -var firstPosition = { x: getRandomFloat(X_MIN, X_MAX), y: 0, z: getRandomFloat(Z_MIN, Z_MAX) }; +var firstPosition = { x: getRandomFloat(X_MIN, X_MAX), y: Y_PELVIS, z: getRandomFloat(Z_MIN, Z_MAX) }; var targetPosition = { x: 0, y: 0, z: 0 }; var targetDirection = { x: 0, y: 0, z: 0, w: 0 }; var currentDirection = { x: 0, y: 0, z: 0, w: 0 }; @@ -72,9 +77,6 @@ function playRandomSound(position) { } } -// change the avatar's position to the random one -Avatar.position = firstPosition; - // pick an integer between 1 and 20 for the face model for this bot botNumber = getRandomInt(1, 100); @@ -103,6 +105,10 @@ Avatar.billboardURL = "https://s3-us-west-1.amazonaws.com/highfidelity-public/me Agent.isAvatar = true; +// change the avatar's position to the random one +Avatar.position = firstPosition; +printVector("New bot, position = ", Avatar.position); + function updateBehavior(deltaTime) { if (Math.random() < CHANCE_OF_SOUND) { playRandomSound(Avatar.position); @@ -132,6 +138,7 @@ function updateBehavior(deltaTime) { } targetPosition.x = clamp(targetPosition.x, X_MIN, X_MAX); targetPosition.z = clamp(targetPosition.z, Z_MIN, Z_MAX); + targetPosition.y = Y_PELVIS; isMoving = true; } else { diff --git a/examples/gun.js b/examples/gun.js index 2e9bf5655c..617ec1bbc4 100644 --- a/examples/gun.js +++ b/examples/gun.js @@ -57,12 +57,12 @@ function shootBullet(position, velocity) { damping: 0 }); // Play firing sounds - audioOptions.position = position; + audioOptions.position = position; Audio.playSound(fireSound, audioOptions); } function particleCollisionWithVoxel(particle, voxel) { - var HOLE_SIZE = 0.25; + var HOLE_SIZE = 0.125; var particleProperties = Particles.getParticleProperties(particle); var position = particleProperties.position; Particles.deleteParticle(particle); diff --git a/examples/localVoxelsExample.js b/examples/localVoxelsExample.js new file mode 100644 index 0000000000..7d9007f590 --- /dev/null +++ b/examples/localVoxelsExample.js @@ -0,0 +1,54 @@ + +var TREE_SCALE = 16384; +var tree = LocalVoxels("tree"); +tree.setVoxel(0, 0, 0, + 0.5 * TREE_SCALE, + 255, 0, 0); +tree.setVoxel(0.5 * TREE_SCALE, + 0.5 * TREE_SCALE, + 0.5 * TREE_SCALE, + 0.5 * TREE_SCALE, + 0, 255, 0); + +var copy = LocalVoxels("copy"); +tree.pasteFrom(0, 0, 0, TREE_SCALE, "copy"); +tree.pasteFrom(0, 0, 0, TREE_SCALE, "clipboard"); + +var overlay1 = Overlays.addOverlay("localvoxels", { + position: {x: 1, y: 1, z: 1}, + size: 1, + name: "tree" + }); +var overlay2 = Overlays.addOverlay("localvoxels", { + position: {x: 1, y: 2, z: 1}, + size: 1, + name: "tree" + }); +var overlay3 = Overlays.addOverlay("localvoxels", { + position: {x: 1, y: 3, z: 1}, + size: 1, + name: "tree" + }); +var overlay4 = Overlays.addOverlay("localvoxels", { + position: {x: 1, y: 4, z: 1}, + size: 1, + name: "copy" + }); + +var clipboard = Overlays.addOverlay("localvoxels", { + position: {x: 1, y: 5, z: 1}, + size: 1, + name: "clipboard" + }); + + + +// When our script shuts down, we should clean up all of our overlays +function scriptEnding() { + Overlays.deleteOverlay(overlay1); + Overlays.deleteOverlay(overlay2); + Overlays.deleteOverlay(overlay3); + Overlays.deleteOverlay(overlay4); + Overlays.deleteOverlay(clipboard); +} +Script.scriptEnding.connect(scriptEnding); \ No newline at end of file diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 646ad3c167..b1268e331e 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -75,15 +75,7 @@ foreach(EXTERNAL_SOURCE_SUBDIR ${EXTERNAL_SOURCE_SUBDIRS}) set(INTERFACE_SRCS ${INTERFACE_SRCS} "${SUBDIR_SRCS}") endforeach(EXTERNAL_SOURCE_SUBDIR) -find_package(Qt5Core REQUIRED) -find_package(Qt5Gui REQUIRED) -find_package(Qt5Multimedia REQUIRED) -find_package(Qt5Network REQUIRED) -find_package(Qt5OpenGL REQUIRED) -find_package(Qt5Svg REQUIRED) -find_package(Qt5WebKit REQUIRED) -find_package(Qt5WebKitWidgets REQUIRED) -find_package(Qt5Xml REQUIRED) +find_package(Qt5 COMPONENTS Core Gui Multimedia Network OpenGL Script Svg WebKit WebKitWidgets Xml UiTools) # grab the ui files in resources/ui file (GLOB_RECURSE QT_UI_FILES ui/*.ui) @@ -180,8 +172,6 @@ if (LIBOVR_FOUND AND NOT DISABLE_LIBOVR) target_link_libraries(${TARGET_NAME} "${LIBOVR_LIBRARIES}") endif (LIBOVR_FOUND AND NOT DISABLE_LIBOVR) -qt5_use_modules(${TARGET_NAME} Core Gui Multimedia Network OpenGL Script Svg WebKit WebKitWidgets Xml UiTools) - # include headers for interface and InterfaceConfig. include_directories( "${PROJECT_SOURCE_DIR}/src" @@ -200,6 +190,8 @@ target_link_libraries( ${TARGET_NAME} "${FACESHIFT_LIBRARIES}" "${ZLIB_LIBRARIES}" + Qt5::Core Qt5::Gui Qt5::Multimedia Qt5::Network Qt5::OpenGL + Qt5::Script Qt5::Svg Qt5::WebKit Qt5::WebKitWidgets Qt5::Xml Qt5::UiTools ) if (APPLE) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b21d660452..c6c6882012 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include "Application.h" #include "ClipboardScriptingInterface.h" @@ -311,7 +312,10 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : checkVersion(); _overlays.init(_glWidget); // do this before scripts load - + + LocalVoxelsList::getInstance()->addPersistantTree(DOMAIN_TREE_NAME, _voxels.getTree()); + LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard); + // do this as late as possible so that all required subsystems are inialized loadScripts(); } @@ -398,6 +402,12 @@ void Application::initializeGL() { // initialize glut for shape drawing; Qt apparently initializes it on OS X #ifndef __APPLE__ + static bool isInitialized = false; + if (isInitialized) { + return; + } else { + isInitialized = true; + } int argc = 0; glutInit(&argc, 0); #endif @@ -1424,6 +1434,7 @@ void Application::pasteVoxelsToOctalCode(const unsigned char* octalCodeDestinati args.newBaseOctCode = octalCodeDestination; _sharedVoxelSystem.getTree()->recurseTreeWithOperation(sendVoxelsOperation, &args); + // Switch back to clipboard if it was an import if (_sharedVoxelSystem.getTree() != &_clipboard) { _sharedVoxelSystem.killLocalVoxels(); _sharedVoxelSystem.changeTree(&_clipboard); @@ -1885,6 +1896,8 @@ void Application::update(float deltaTime) { _particles.update(); // update the particles... _particleCollisionSystem.update(); // collide the particles... + _overlays.update(deltaTime); + // let external parties know we're updating emit simulating(deltaTime); } @@ -3466,7 +3479,6 @@ void Application::cleanupScriptMenuItem(const QString& scriptMenuName) { } void Application::loadScript(const QString& fileNameString) { - _activeScripts.append(fileNameString); QByteArray fileNameAscii = fileNameString.toLocal8Bit(); const char* fileName = fileNameAscii.data(); @@ -3476,6 +3488,7 @@ void Application::loadScript(const QString& fileNameString) { return; } qDebug("Loading file %s...", fileName); + _activeScripts.append(fileNameString); // get file length.... unsigned long fileLength = file.tellg(); diff --git a/interface/src/ClipboardScriptingInterface.cpp b/interface/src/ClipboardScriptingInterface.cpp index c669b465ad..d9a8f04d90 100644 --- a/interface/src/ClipboardScriptingInterface.cpp +++ b/interface/src/ClipboardScriptingInterface.cpp @@ -90,5 +90,4 @@ void ClipboardScriptingInterface::nudgeVoxel(float x, float y, float z, float s, s / (float)TREE_SCALE }; Application::getInstance()->nudgeVoxelsByVector(sourceVoxel, nudgeVecInTreeSpace); -} - +} \ No newline at end of file diff --git a/interface/src/VoxelImporter.cpp b/interface/src/VoxelImporter.cpp index 2daafedcbb..9d8b8ad811 100644 --- a/interface/src/VoxelImporter.cpp +++ b/interface/src/VoxelImporter.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -31,6 +32,8 @@ VoxelImporter::VoxelImporter(QWidget* parent) : _task(NULL), _didImport(false) { + LocalVoxelsList::getInstance()->addPersistantTree(IMPORT_TREE_NAME, &_voxelTree); + connect(&_voxelTree, SIGNAL(importProgress(int)), &_importDialog, SLOT(setProgressBarValue(int))); connect(&_importDialog, SIGNAL(canceled()), this, SLOT(cancel())); connect(&_importDialog, SIGNAL(accepted()), this, SLOT(import())); diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index e60165647f..1d5a238622 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -53,7 +53,7 @@ GLubyte identityIndicesRight[] = { 1, 2, 6, 1, 6, 5 }; GLubyte identityIndicesFront[] = { 0, 2, 1, 0, 3, 2 }; GLubyte identityIndicesBack[] = { 4, 5, 6, 4, 6, 7 }; -VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) +VoxelSystem::VoxelSystem(float treeScale, int maxVoxels, VoxelTree* tree) : NodeData(), _treeScale(treeScale), _maxVoxels(maxVoxels), @@ -69,7 +69,7 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) _voxelsInReadArrays = _voxelsInWriteArrays = _voxelsUpdated = 0; _writeRenderFullVBO = true; _readRenderFullVBO = true; - _tree = new VoxelTree(); + _tree = (tree) ? tree : new VoxelTree(); _tree->getRoot()->setVoxelSystem(this); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index b49891f8d9..49b47c6f25 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -44,7 +44,7 @@ class VoxelSystem : public NodeData, public OctreeElementDeleteHook, public Octr friend class VoxelHideShowThread; public: - VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = DEFAULT_MAX_VOXELS_PER_SYSTEM); + VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = DEFAULT_MAX_VOXELS_PER_SYSTEM, VoxelTree* tree = NULL); ~VoxelSystem(); void setDataSourceUUID(const QUuid& dataSourceUUID) { _dataSourceUUID = dataSourceUUID; } @@ -52,8 +52,8 @@ public: int parseData(const QByteArray& packet); + bool isInitialized() { return _initialized; } virtual void init(); - void simulate(float deltaTime) { } void render(); void changeTree(VoxelTree* newTree); diff --git a/interface/src/renderer/TextureCache.cpp b/interface/src/renderer/TextureCache.cpp index dcaf059714..d5d3b42155 100644 --- a/interface/src/renderer/TextureCache.cpp +++ b/interface/src/renderer/TextureCache.cpp @@ -41,15 +41,12 @@ TextureCache::~TextureCache() { glDeleteTextures(1, &id); } if (_primaryFramebufferObject) { - delete _primaryFramebufferObject; glDeleteTextures(1, &_primaryDepthTextureID); } - if (_secondaryFramebufferObject) { - delete _secondaryFramebufferObject; - } - if (_tertiaryFramebufferObject) { - delete _tertiaryFramebufferObject; - } + + delete _primaryFramebufferObject; + delete _secondaryFramebufferObject; + delete _tertiaryFramebufferObject; } GLuint TextureCache::getPermutationNormalTextureID() { diff --git a/interface/src/ui/ClipboardOverlay.cpp b/interface/src/ui/ClipboardOverlay.cpp deleted file mode 100644 index 7eee318ec9..0000000000 --- a/interface/src/ui/ClipboardOverlay.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// -// ClipboardOverlay.cpp -// hifi -// -// Created by Clément Brisset on 2/20/14. -// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. -// - -// include this before QGLWidget, which includes an earlier version of OpenGL -#include "InterfaceConfig.h" - -#include -#include - -#include "ClipboardOverlay.h" -#include "../Application.h" - -static int lastVoxelCount = 0; - -ClipboardOverlay::ClipboardOverlay() { -} - -ClipboardOverlay::~ClipboardOverlay() { -} - -void ClipboardOverlay::render() { - if (!_visible) { - return; // do nothing if we're not visible - } - - VoxelSystem* voxelSystem = Application::getInstance()->getSharedVoxelSystem(); - VoxelTree* clipboard = Application::getInstance()->getClipboard(); - if (voxelSystem->getTree() != clipboard) { - voxelSystem->changeTree(clipboard); - } - - glPushMatrix(); - glTranslatef(_position.x, _position.y, _position.z); - glScalef(_size, _size, _size); - - // We only force the redraw when the clipboard content has changed - if (lastVoxelCount != clipboard->getOctreeElementsCount()) { - voxelSystem->forceRedrawEntireTree(); - lastVoxelCount = clipboard->getOctreeElementsCount(); - } - - voxelSystem->render(); - - glPopMatrix(); -} \ No newline at end of file diff --git a/interface/src/ui/ClipboardOverlay.h b/interface/src/ui/ClipboardOverlay.h deleted file mode 100644 index 49daa73c20..0000000000 --- a/interface/src/ui/ClipboardOverlay.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// ClipboardOverlay.h -// hifi -// -// Created by Clément Brisset on 2/20/14. -// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. -// - -#ifndef __interface__ClipboardOverlay__ -#define __interface__ClipboardOverlay__ - -#include "Volume3DOverlay.h" - -class ClipboardOverlay : public Volume3DOverlay { - Q_OBJECT - -public: - ClipboardOverlay(); - ~ClipboardOverlay(); - - virtual void render(); -}; - - -#endif /* defined(__interface__ClipboardOverlay__) */ diff --git a/interface/src/ui/LocalVoxelsOverlay.cpp b/interface/src/ui/LocalVoxelsOverlay.cpp new file mode 100644 index 0000000000..01a885dedc --- /dev/null +++ b/interface/src/ui/LocalVoxelsOverlay.cpp @@ -0,0 +1,84 @@ +// +// LocalVoxelsOverlay.cpp +// hifi +// +// Created by Clément Brisset on 2/28/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// +// +// include this before QGLWidget, which includes an earlier version of OpenGL +#include "InterfaceConfig.h" + +#include +#include + +#include +#include + +#include "LocalVoxelsOverlay.h" + +QMap LocalVoxelsOverlay::_voxelSystemMap; + +LocalVoxelsOverlay::LocalVoxelsOverlay() : + Volume3DOverlay(), + _voxelCount(0) +{ +} + +LocalVoxelsOverlay::~LocalVoxelsOverlay() { + _voxelSystem->changeTree(new VoxelTree()); + _voxelSystem.clear(); + if (_voxelSystemMap.value(_treeName).isNull()) { + _voxelSystemMap.remove(_treeName); + } + _tree.clear(); + LocalVoxelsList::getInstance()->remove(_treeName); +} + +void LocalVoxelsOverlay::update(float deltatime) { + if (!_voxelSystem->isInitialized()) { + _voxelSystem->init(); + } + + if (_voxelCount != _tree->getOctreeElementsCount()) { + _voxelCount = _tree->getOctreeElementsCount(); + _voxelSystem->forceRedrawEntireTree(); + } +} + +void LocalVoxelsOverlay::render() { + if (_visible && _size > 0 && _voxelSystem && _voxelSystem->isInitialized()) { + glPushMatrix(); { + glTranslatef(_position.x, _position.y, _position.z); + glScalef(_size, _size, _size); + _voxelSystem->render(); + } glPopMatrix(); + } +} + +void LocalVoxelsOverlay::setProperties(const QScriptValue &properties) { + Volume3DOverlay::setProperties(properties); + + QScriptValue treeName = properties.property("name"); + // if "end" property was not there, check to see if they included aliases: endPoint, or p2 + if (treeName.isValid()) { + if ((_treeName = treeName.toString()) == DOMAIN_TREE_NAME) { + qDebug() << "addOverlay(): Can't create overlay from domain tree"; + return; + } + _tree = LocalVoxelsList::getInstance()->getTree(_treeName); + if (_tree.isNull()) { + qDebug() << "addOverlay(): Invalid tree name"; + return; + } + + _voxelSystem = _voxelSystemMap[_treeName]; + if (_voxelSystem.isNull()) { + _voxelSystem = StrongVoxelSystemPointer(new VoxelSystem(1, + DEFAULT_MAX_VOXELS_PER_SYSTEM, + _tree.data())); + _voxelSystemMap.insert(_treeName, _voxelSystem); + } + } +} + diff --git a/interface/src/ui/LocalVoxelsOverlay.h b/interface/src/ui/LocalVoxelsOverlay.h new file mode 100644 index 0000000000..c5582a54eb --- /dev/null +++ b/interface/src/ui/LocalVoxelsOverlay.h @@ -0,0 +1,50 @@ +// +// LocalVoxelsOverlay.h +// hifi +// +// Created by Clément Brisset on 2/28/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// +// Scriptable interface for LocalVoxels +// + +#ifndef __hifi__LocalVoxelsOverlay__ +#define __hifi__LocalVoxelsOverlay__ + +// include this before QGLWidget, which includes an earlier version of OpenGL +#include "InterfaceConfig.h" + +#include +#include +#include +#include +#include + +#include + +#include "Volume3DOverlay.h" + +typedef QSharedPointer StrongVoxelSystemPointer; +typedef QWeakPointer WeakVoxelSystemPointer; + +class LocalVoxelsOverlay : public Volume3DOverlay { + Q_OBJECT +public: + LocalVoxelsOverlay(); + ~LocalVoxelsOverlay(); + + virtual void update(float deltatime); + virtual void render(); + + virtual void setProperties(const QScriptValue& properties); + +private: + static QMap _voxelSystemMap; // treeName/voxelSystem + + QString _treeName; + StrongVoxelTreePointer _tree; // so that the tree doesn't get freed + int _voxelCount; + StrongVoxelSystemPointer _voxelSystem; +}; + +#endif /* defined(__hifi__LocalVoxelsOverlay__) */ diff --git a/interface/src/ui/Overlay.h b/interface/src/ui/Overlay.h index df898ec741..ad1084e889 100644 --- a/interface/src/ui/Overlay.h +++ b/interface/src/ui/Overlay.h @@ -28,6 +28,7 @@ public: Overlay(); ~Overlay(); void init(QGLWidget* parent); + virtual void update(float deltatime) {} virtual void render() = 0; // getters diff --git a/interface/src/ui/Overlays.cpp b/interface/src/ui/Overlays.cpp index 84944332f1..0c9415fa73 100644 --- a/interface/src/ui/Overlays.cpp +++ b/interface/src/ui/Overlays.cpp @@ -12,20 +12,41 @@ #include "Overlays.h" #include "Sphere3DOverlay.h" #include "TextOverlay.h" -#include "ClipboardOverlay.h" +#include "LocalVoxelsOverlay.h" -unsigned int Overlays::_nextOverlayID = 1; - -Overlays::Overlays() { +Overlays::Overlays() : _nextOverlayID(1) { } Overlays::~Overlays() { + QMap::iterator it; + for (it = _overlays2D.begin(); it != _overlays2D.end(); ++it) { + delete _overlays2D.take(it.key()); + } + for (it = _overlays3D.begin(); it != _overlays3D.end(); ++it) { + delete _overlays3D.take(it.key()); + } + while (!_overlaysToDelete.isEmpty()) { + delete _overlaysToDelete.takeLast(); + } } void Overlays::init(QGLWidget* parent) { _parent = parent; } +void Overlays::update(float deltatime) { + foreach (Overlay* thisOverlay, _overlays2D) { + thisOverlay->update(deltatime); + } + foreach (Overlay* thisOverlay, _overlays3D) { + thisOverlay->update(deltatime); + } + while (!_overlaysToDelete.isEmpty()) { + delete _overlaysToDelete.takeLast(); + } + +} + void Overlays::render2D() { foreach(Overlay* thisOverlay, _overlays2D) { thisOverlay->render(); @@ -73,8 +94,8 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope thisOverlay->setProperties(properties); created = true; is3D = true; - } else if (type == "clipboard") { - thisOverlay = new ClipboardOverlay(); + } else if (type == "localvoxels") { + thisOverlay = new LocalVoxelsOverlay(); thisOverlay->init(_parent); thisOverlay->setProperties(properties); created = true; @@ -111,11 +132,16 @@ bool Overlays::editOverlay(unsigned int id, const QScriptValue& properties) { // TODO: make multi-threaded safe void Overlays::deleteOverlay(unsigned int id) { + Overlay* overlayToDelete; if (_overlays2D.contains(id)) { - _overlays2D.erase(_overlays2D.find(id)); + overlayToDelete = _overlays2D.take(id); } else if (_overlays3D.contains(id)) { - _overlays3D.erase(_overlays3D.find(id)); + overlayToDelete = _overlays3D.take(id); + } else { + return; } + + _overlaysToDelete.push_back(overlayToDelete); } unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) { diff --git a/interface/src/ui/Overlays.h b/interface/src/ui/Overlays.h index cfd84fd44b..c28f3ab83b 100644 --- a/interface/src/ui/Overlays.h +++ b/interface/src/ui/Overlays.h @@ -18,6 +18,7 @@ public: Overlays(); ~Overlays(); void init(QGLWidget* parent); + void update(float deltatime); void render3D(); void render2D(); @@ -38,7 +39,8 @@ public slots: private: QMap _overlays2D; QMap _overlays3D; - static unsigned int _nextOverlayID; + QList _overlaysToDelete; + unsigned int _nextOverlayID; QGLWidget* _parent; }; diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index bcafb32dc6..316f1dca58 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -13,8 +13,6 @@ find_package(Qt5Script REQUIRED) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) -qt5_use_modules(${TARGET_NAME} Script) - include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") @@ -24,3 +22,5 @@ link_hifi_library(shared ${TARGET_NAME} "${ROOT_DIR}") # link in the hifi voxels library link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") + +target_link_libraries(${TARGET_NAME} Qt5::Script) \ No newline at end of file diff --git a/libraries/embedded-webserver/CMakeLists.txt b/libraries/embedded-webserver/CMakeLists.txt index 1ab454bf0a..06dd2d750d 100644 --- a/libraries/embedded-webserver/CMakeLists.txt +++ b/libraries/embedded-webserver/CMakeLists.txt @@ -13,4 +13,4 @@ find_package(Qt5Network REQUIRED) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) -qt5_use_modules(${TARGET_NAME} Network) \ No newline at end of file +target_link_libraries(${TARGET_NAME} Qt5::Network) \ No newline at end of file diff --git a/libraries/metavoxels/CMakeLists.txt b/libraries/metavoxels/CMakeLists.txt index 617609f1fa..bab03058a0 100644 --- a/libraries/metavoxels/CMakeLists.txt +++ b/libraries/metavoxels/CMakeLists.txt @@ -8,8 +8,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cm set(TARGET_NAME metavoxels) -find_package(Qt5Network REQUIRED) -find_package(Qt5Widgets REQUIRED) +find_package(Qt5 COMPONENTS Network Script Widgets) include(${MACRO_DIR}/AutoMTC.cmake) auto_mtc(${TARGET_NAME} "${ROOT_DIR}") @@ -17,8 +16,8 @@ auto_mtc(${TARGET_NAME} "${ROOT_DIR}") include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME} "${AUTOMTC_SRC}") -qt5_use_modules(${TARGET_NAME} Network Script Widgets) - include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") +target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script) + diff --git a/libraries/metavoxels/src/Bitstream.h b/libraries/metavoxels/src/Bitstream.h index c06c4c3b5f..b5db4782b7 100644 --- a/libraries/metavoxels/src/Bitstream.h +++ b/libraries/metavoxels/src/Bitstream.h @@ -450,6 +450,13 @@ public: bool operator==(const X& first, const X& second); \ bool operator!=(const X& first, const X& second); \ static const int* _TypePtr##X = &X::Type; +#elif __GNUC__ +#define DECLARE_STREAMABLE_METATYPE(X) Q_DECLARE_METATYPE(X) \ + Bitstream& operator<<(Bitstream& out, const X& obj); \ + Bitstream& operator>>(Bitstream& in, X& obj); \ + bool operator==(const X& first, const X& second); \ + bool operator!=(const X& first, const X& second); \ + __attribute__((unused)) static const int* _TypePtr##X = &X::Type; #else #define STRINGIFY(x) #x #define DECLARE_STREAMABLE_METATYPE(X) Q_DECLARE_METATYPE(X) \ diff --git a/libraries/octree/CMakeLists.txt b/libraries/octree/CMakeLists.txt index ac59ca454e..8b8f37bae7 100644 --- a/libraries/octree/CMakeLists.txt +++ b/libraries/octree/CMakeLists.txt @@ -13,8 +13,6 @@ find_package(Qt5Widgets REQUIRED) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) -qt5_use_modules(${TARGET_NAME} Widgets) - include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") @@ -24,4 +22,5 @@ link_hifi_library(shared ${TARGET_NAME} "${ROOT_DIR}") # link ZLIB find_package(ZLIB) include_directories("${ZLIB_INCLUDE_DIRS}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}") + +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 05760ef675..4515deb6b5 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -590,16 +590,26 @@ bool findRayIntersectionOp(OctreeElement* node, void* extraData) { } bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElement*& node, float& distance, BoxFace& face, bool tryLock) { + OctreeElement*& node, float& distance, BoxFace& face, Octree::lockType lockType) { RayArgs args = { origin / (float)(TREE_SCALE), direction, node, distance, face }; - if (!tryLock) { + bool gotLock = false; + if (lockType == Octree::Lock) { lockForRead(); + gotLock = true; + } else if (lockType == Octree::TryLock) { + gotLock = tryLockForRead(); + if (!gotLock) { + return args.found; // if we wanted to tryLock, and we couldn't then just bail... + } } - if (tryLock && tryLockForRead()) { - recurseTreeWithOperation(findRayIntersectionOp, &args); + + recurseTreeWithOperation(findRayIntersectionOp, &args); + + if (gotLock) { unlock(); } + return args.found; } @@ -635,7 +645,7 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) { } bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, - void** penetratedObject, bool tryLock) { + void** penetratedObject, Octree::lockType lockType) { SphereArgs args = { center / (float)(TREE_SCALE), @@ -644,17 +654,27 @@ bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::v false, NULL }; penetration = glm::vec3(0.0f, 0.0f, 0.0f); - - if (!tryLock) { + + bool gotLock = false; + if (lockType == Octree::Lock) { lockForRead(); - } - if (tryLock && tryLockForRead()) { - recurseTreeWithOperation(findSpherePenetrationOp, &args); - if (penetratedObject) { - *penetratedObject = args.penetratedObject; + gotLock = true; + } else if (lockType == Octree::TryLock) { + gotLock = tryLockForRead(); + if (!gotLock) { + return args.found; // if we wanted to tryLock, and we couldn't then just bail... } + } + + recurseTreeWithOperation(findSpherePenetrationOp, &args); + if (penetratedObject) { + *penetratedObject = args.penetratedObject; + } + + if (gotLock) { unlock(); } + return args.found; } @@ -689,7 +709,7 @@ bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) { } bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, - glm::vec3& penetration, bool tryLock) { + glm::vec3& penetration, Octree::lockType lockType) { CapsuleArgs args = { start / (float)(TREE_SCALE), @@ -699,11 +719,20 @@ bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end false }; penetration = glm::vec3(0.0f, 0.0f, 0.0f); - if (!tryLock) { + bool gotLock = false; + if (lockType == Octree::Lock) { lockForRead(); + gotLock = true; + } else if (lockType == Octree::TryLock) { + gotLock = tryLockForRead(); + if (!gotLock) { + return args.found; // if we wanted to tryLock, and we couldn't then just bail... + } } - if (tryLock && tryLockForRead()) { - recurseTreeWithOperation(findCapsulePenetrationOp, &args); + + recurseTreeWithOperation(findCapsulePenetrationOp, &args); + + if (gotLock) { unlock(); } return args.found; @@ -732,18 +761,28 @@ bool getElementEnclosingOperation(OctreeElement* element, void* extraData) { return true; // keep looking } -OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, bool tryLock) { +OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, Octree::lockType lockType) { GetElementEnclosingArgs args; args.point = point; args.element = NULL; - if (!tryLock) { + bool gotLock = false; + if (lockType == Octree::Lock) { lockForRead(); + gotLock = true; + } else if (lockType == Octree::TryLock) { + gotLock = tryLockForRead(); + if (!gotLock) { + return args.element; // if we wanted to tryLock, and we couldn't then just bail... + } } - if (tryLock && tryLockForRead()) { - recurseTreeWithOperation(getElementEnclosingOperation, (void*)&args); + + recurseTreeWithOperation(getElementEnclosingOperation, (void*)&args); + + if (gotLock) { unlock(); } + return args.element; } diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index 21a6929034..4c237b5f56 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -221,16 +221,29 @@ public: void clearDirtyBit() { _isDirty = false; } void setDirtyBit() { _isDirty = true; } + // Octree does not currently handle its own locking, caller must use these to lock/unlock + void lockForRead() { _lock.lockForRead(); } + bool tryLockForRead() { return _lock.tryLockForRead(); } + void lockForWrite() { _lock.lockForWrite(); } + bool tryLockForWrite() { return _lock.tryLockForWrite(); } + void unlock() { _lock.unlock(); } + // output hints from the encode process + typedef enum { + Lock, + TryLock, + NoLock + } lockType; + bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElement*& node, float& distance, BoxFace& face, bool tryLock = true); + OctreeElement*& node, float& distance, BoxFace& face, Octree::lockType lockType = Octree::TryLock); bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, - void** penetratedObject = NULL, bool tryLock = true); + void** penetratedObject = NULL, Octree::lockType lockType = Octree::TryLock); bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, - glm::vec3& penetration, bool tryLock = true); + glm::vec3& penetration, Octree::lockType lockType = Octree::TryLock); - OctreeElement* getElementEnclosingPoint(const glm::vec3& point, bool tryLock = true); + OctreeElement* getElementEnclosingPoint(const glm::vec3& point, Octree::lockType lockType = Octree::TryLock); // Note: this assumes the fileFormat is the HIO individual voxels code files void loadOctreeFile(const char* fileName, bool wantColorRandomizer); @@ -238,13 +251,7 @@ public: // these will read/write files that match the wireformat, excluding the 'V' leading void writeToSVOFile(const char* filename, OctreeElement* node = NULL); bool readFromSVOFile(const char* filename); - - // Octree does not currently handle its own locking, caller must use these to lock/unlock - void lockForRead() { _lock.lockForRead(); } - bool tryLockForRead() { return _lock.tryLockForRead(); } - void lockForWrite() { _lock.lockForWrite(); } - bool tryLockForWrite() { return _lock.tryLockForWrite(); } - void unlock() { _lock.unlock(); } + unsigned long getOctreeElementsCount(); diff --git a/libraries/particles/CMakeLists.txt b/libraries/particles/CMakeLists.txt index f7d0088c1b..8f475647bd 100644 --- a/libraries/particles/CMakeLists.txt +++ b/libraries/particles/CMakeLists.txt @@ -13,8 +13,6 @@ find_package(Qt5Widgets REQUIRED) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) -qt5_use_modules(${TARGET_NAME} Widgets) - include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") @@ -25,4 +23,5 @@ link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") # link ZLIB find_package(ZLIB) include_directories("${ZLIB_INCLUDE_DIRS}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}") + +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index 2d272a8f1f..b36b6a3a04 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -58,7 +58,7 @@ bool ParticleCollisionSystem::updateOperation(OctreeElement* element, void* extr void ParticleCollisionSystem::update() { // update all particles - if (_particles->tryLockForWrite()) { + if (_particles->tryLockForRead()) { _particles->recurseTreeWithOperation(updateOperation, this); _particles->unlock(); } @@ -117,7 +117,7 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particleA) const float COLLISION_FREQUENCY = 0.5f; glm::vec3 penetration; Particle* particleB; - if (_particles->findSpherePenetration(center, radius, penetration, (void**)&particleB)) { + if (_particles->findSpherePenetration(center, radius, penetration, (void**)&particleB, Octree::NoLock)) { // NOTE: 'penetration' is the depth that 'particleA' overlaps 'particleB'. // That is, it points from A into B. diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index d2a838e543..d91814bcec 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -13,8 +13,6 @@ find_package(Qt5Widgets REQUIRED) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) -qt5_use_modules(${TARGET_NAME} Widgets) - include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") @@ -27,4 +25,5 @@ link_hifi_library(particles ${TARGET_NAME} "${ROOT_DIR}") # link ZLIB find_package(ZLIB) include_directories("${ZLIB_INCLUDE_DIRS}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}") + +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) diff --git a/libraries/script-engine/src/LocalVoxels.cpp b/libraries/script-engine/src/LocalVoxels.cpp new file mode 100644 index 0000000000..075dfb9e9a --- /dev/null +++ b/libraries/script-engine/src/LocalVoxels.cpp @@ -0,0 +1,153 @@ +// +// LocalVoxels.cpp +// hifi +// +// Created by Clément Brisset on 2/24/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#include "LocalVoxels.h" + +LocalVoxels::LocalVoxels(QString name) : + QObject(NULL), + _name(name), + _tree(new VoxelTree(true)) +{ + LocalVoxelsList::getInstance()->insert(_name, _tree); +} + +LocalVoxels::~LocalVoxels() { + _tree.clear(); + LocalVoxelsList::getInstance()->remove(_name); +} + +VoxelDetail LocalVoxels::getVoxelAt(float x, float y, float z, float scale) { + // setup a VoxelDetail struct with the data + VoxelDetail result = {0,0,0,0,0,0,0}; + if (_tree) { + _tree->lockForRead(); + + VoxelTreeElement* voxel = static_cast(_tree->getOctreeElementAt(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE)); + _tree->unlock(); + if (voxel) { + // Note: these need to be in voxel space because the VoxelDetail -> js converter will upscale + result.x = voxel->getCorner().x; + result.y = voxel->getCorner().y; + result.z = voxel->getCorner().z; + result.s = voxel->getScale(); + result.red = voxel->getColor()[RED_INDEX]; + result.green = voxel->getColor()[GREEN_INDEX]; + result.blue = voxel->getColor()[BLUE_INDEX]; + } + } + return result; +} + +void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale, + uchar red, uchar green, uchar blue) { + if (_name == DOMAIN_TREE_NAME) { + qDebug() << "LocalVoxels::setVoxelNonDestructive(): Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + if (_tree ) { + _tree->createVoxel(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE, + red, green, blue, false); + } +} + +void LocalVoxels::setVoxel(float x, float y, float z, float scale, + uchar red, uchar green, uchar blue) { + if (_name == DOMAIN_TREE_NAME) { + qDebug() << "LocalVoxels::setVoxel(): Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + if (_tree ) { + _tree->createVoxel(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE, + red, green, blue, true); + } +} + +void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) { + if (_name == DOMAIN_TREE_NAME) { + qDebug() << "LocalVoxels::eraseVoxel(): Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + if (_tree ) { + _tree->deleteVoxelAt(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE); + } +} + +void LocalVoxels::copyTo(float x, float y, float z, float scale, const QString destination) { + if (destination == DOMAIN_TREE_NAME) { + qDebug() << "LocalVoxels::copyTo(): Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + StrongVoxelTreePointer destinationTree = LocalVoxelsList::getInstance()->getTree(destination); + VoxelTreeElement* destinationNode = destinationTree->getVoxelAt(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE); + destinationTree->copyFromTreeIntoSubTree(_tree.data(), destinationNode); +} + +void LocalVoxels::pasteFrom(float x, float y, float z, float scale, const QString source) { + if (_name == DOMAIN_TREE_NAME) { + qDebug() << "LocalVoxels::pasteFrom(): Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + StrongVoxelTreePointer sourceTree = LocalVoxelsList::getInstance()->getTree(source); + VoxelTreeElement* sourceNode = _tree->getVoxelAt(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE); + _tree->copySubTreeIntoNewTree(sourceNode, sourceTree.data(), true); +} + +RayToVoxelIntersectionResult LocalVoxels::findRayIntersection(const PickRay& ray) { + RayToVoxelIntersectionResult result; + if (_tree) { + OctreeElement* element; + result.intersects = _tree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face); + if (result.intersects) { + VoxelTreeElement* voxel = (VoxelTreeElement*)element; + result.voxel.x = voxel->getCorner().x; + result.voxel.y = voxel->getCorner().y; + result.voxel.z = voxel->getCorner().z; + result.voxel.s = voxel->getScale(); + result.voxel.red = voxel->getColor()[0]; + result.voxel.green = voxel->getColor()[1]; + result.voxel.blue = voxel->getColor()[2]; + result.intersection = ray.origin + (ray.direction * result.distance); + } + } + return result; +} + +glm::vec3 LocalVoxels::getFaceVector(const QString& face) { + if (face == "MIN_X_FACE") { + return glm::vec3(-1, 0, 0); + } else if (face == "MAX_X_FACE") { + return glm::vec3(1, 0, 0); + } else if (face == "MIN_Y_FACE") { + return glm::vec3(0, -1, 0); + } else if (face == "MAX_Y_FACE") { + return glm::vec3(0, 1, 0); + } else if (face == "MIN_Z_FACE") { + return glm::vec3(0, 0, -1); + } else if (face == "MAX_Z_FACE") { + return glm::vec3(0, 0, 1); + } + return glm::vec3(0, 0, 0); //error case +} diff --git a/libraries/script-engine/src/LocalVoxels.h b/libraries/script-engine/src/LocalVoxels.h new file mode 100644 index 0000000000..c64379ab27 --- /dev/null +++ b/libraries/script-engine/src/LocalVoxels.h @@ -0,0 +1,90 @@ +// +// LocalVoxels.h +// hifi +// +// Created by Clément Brisset on 2/24/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#ifndef __hifi__LocalVoxels__ +#define __hifi__LocalVoxels__ + +#include + +#include +#include + + +/// object allowing JS scripters to use their own local trees +class LocalVoxels : public QObject { + Q_OBJECT + +public: + LocalVoxels(QString name); + ~LocalVoxels(); + + /// checks the local voxel tree for a voxel at the specified location and scale + /// \param x the x-coordinate of the voxel (in meter units) + /// \param y the y-coordinate of the voxel (in meter units) + /// \param z the z-coordinate of the voxel (in meter units) + /// \param scale the scale of the voxel (in meter units) + Q_INVOKABLE VoxelDetail getVoxelAt(float x, float y, float z, float scale); + + /// creates a non destructive voxel in the local tree + /// \param x the x-coordinate of the voxel (in meter units) + /// \param y the y-coordinate of the voxel (in meter units) + /// \param z the z-coordinate of the voxel (in meter units) + /// \param scale the scale of the voxel (in meter units) + /// \param red the R value for RGB color of voxel + /// \param green the G value for RGB color of voxel + /// \param blue the B value for RGB color of voxel + Q_INVOKABLE void setVoxelNonDestructive(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); + + /// creates a voxel in the local tree + /// \param x the x-coordinate of the voxel (in meter units) + /// \param y the y-coordinate of the voxel (in meter units) + /// \param z the z-coordinate of the voxel (in meter units) + /// \param scale the scale of the voxel (in meter units) + /// \param red the R value for RGB color of voxel + /// \param green the G value for RGB color of voxel + /// \param blue the B value for RGB color of voxel + Q_INVOKABLE void setVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue); + + /// erase the voxel and its children at the given coordinate + /// \param x the x-coordinate of the voxel (in meter units) + /// \param y the y-coordinate of the voxel (in meter units) + /// \param z the z-coordinate of the voxel (in meter units) + /// \param scale the scale of the voxel (in meter units) + Q_INVOKABLE void eraseVoxel(float x, float y, float z, float scale); + + /// copy the given subtree onto destination's root node + /// \param x the x-coordinate of the subtree (in meter units) + /// \param y the y-coordinate of the subtree (in meter units) + /// \param z the z-coordinate of the subtree (in meter units) + /// \param scale the scale of the subtree (in meter units) + /// \param destination LocalVoxels' destination tree + Q_INVOKABLE void copyTo(float x, float y, float z, float scale, const QString destination); + + ///copy source in the given subtree + /// \param x the x-coordinate of the subtree (in meter units) + /// \param y the y-coordinate of the subtree (in meter units) + /// \param z the z-coordinate of the subtree (in meter units) + /// \param scale the scale of the subtree (in meter units) + /// \param source LocalVoxels' source tree + Q_INVOKABLE void pasteFrom(float x, float y, float z, float scale, const QString source); + + /// If the scripting context has visible voxels, this will determine a ray intersection + Q_INVOKABLE RayToVoxelIntersectionResult findRayIntersection(const PickRay& ray); + + /// returns a voxel space axis aligned vector for the face, useful in doing voxel math + Q_INVOKABLE glm::vec3 getFaceVector(const QString& face); + +private: + QString _name; + StrongVoxelTreePointer _tree; +}; + + + + +#endif /* defined(__hifi__LocalVoxels__) */ diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index c63d2e9162..59ce841969 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -25,6 +25,7 @@ #include #include "MenuItemProperties.h" +#include "LocalVoxels.h" #include "ScriptEngine.h" const unsigned int VISUAL_DATA_CALLBACK_USECS = (1.0 / 60.0) * 1000 * 1000; @@ -118,6 +119,7 @@ bool ScriptEngine::setScriptContents(const QString& scriptContents) { } Q_SCRIPT_DECLARE_QMETAOBJECT(AudioInjectorOptions, QObject*) +Q_SCRIPT_DECLARE_QMETAOBJECT(LocalVoxels, QString) void ScriptEngine::init() { if (_isInitialized) { @@ -146,6 +148,9 @@ void ScriptEngine::init() { QScriptValue injectionOptionValue = _engine.scriptValueFromQMetaObject(); _engine.globalObject().setProperty("AudioInjectionOptions", injectionOptionValue); + + QScriptValue localVoxelsValue = _engine.scriptValueFromQMetaObject(); + _engine.globalObject().setProperty("LocalVoxels", localVoxelsValue); registerGlobalObject("Script", this); registerGlobalObject("Audio", &_audioScriptingInterface); diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index 1f23dca926..021d8b33bf 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -6,14 +6,11 @@ set(MACRO_DIR "${ROOT_DIR}/cmake/macros") set(TARGET_NAME shared) project(${TARGET_NAME}) -find_package(Qt5Network REQUIRED) -find_package(Qt5Widgets REQUIRED) +find_package(Qt5 COMPONENTS Network Widgets) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) -qt5_use_modules(${TARGET_NAME} Network Widgets) - # include GLM include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") @@ -31,3 +28,5 @@ if (UNIX AND NOT APPLE) find_package(Threads REQUIRED) target_link_libraries(${TARGET_NAME} "${CMAKE_THREAD_LIBS_INIT}") endif (UNIX AND NOT APPLE) + +target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets) \ No newline at end of file diff --git a/libraries/shared/src/Node.cpp b/libraries/shared/src/Node.cpp index 889f3e2ed0..dadf39f790 100644 --- a/libraries/shared/src/Node.cpp +++ b/libraries/shared/src/Node.cpp @@ -62,10 +62,7 @@ Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const } Node::~Node() { - if (_linkedData) { - delete _linkedData; - } - + delete _linkedData; delete _bytesReceivedMovingAverage; } diff --git a/libraries/voxels/CMakeLists.txt b/libraries/voxels/CMakeLists.txt index 279168ded8..515c6b6f94 100644 --- a/libraries/voxels/CMakeLists.txt +++ b/libraries/voxels/CMakeLists.txt @@ -8,14 +8,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cm set(TARGET_NAME voxels) -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Script REQUIRED) +find_package(Qt5 COMPONENTS Widgets Script) include(${MACRO_DIR}/SetupHifiLibrary.cmake) setup_hifi_library(${TARGET_NAME}) -qt5_use_modules(${TARGET_NAME} Widgets Script) - include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") @@ -26,4 +23,5 @@ link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") # link ZLIB find_package(ZLIB) include_directories("${ZLIB_INCLUDE_DIRS}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}") + +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets Qt5::Script) diff --git a/libraries/voxels/src/LocalVoxelsList.cpp b/libraries/voxels/src/LocalVoxelsList.cpp new file mode 100644 index 0000000000..e8f5a09d6d --- /dev/null +++ b/libraries/voxels/src/LocalVoxelsList.cpp @@ -0,0 +1,64 @@ +// +// LocalVoxelsList.cpp +// hifi +// +// Created by Clément Brisset on 2/24/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#include "LocalVoxelsList.h" + +static void doNothing(VoxelTree* t) { + // do nothing +} + +LocalVoxelsList* LocalVoxelsList::_instance = NULL; + +LocalVoxelsList* LocalVoxelsList::getInstance() { + if (!_instance) { + _instance = new LocalVoxelsList(); + } + + return _instance; +} + +LocalVoxelsList::LocalVoxelsList() { +} + +LocalVoxelsList::~LocalVoxelsList() { + _instance = NULL; +} + +StrongVoxelTreePointer LocalVoxelsList::getTree(QString treeName) { + return _trees.value(treeName); +} + +void LocalVoxelsList::addPersistantTree(QString treeName, VoxelTree* tree) { + StrongVoxelTreePointer treePtr(tree, doNothing); + _persistantTrees.push_back(treePtr); + _trees.insert(treeName, treePtr); + qDebug() << "[DEBUG] LocalVoxelsList : added persistant tree (" << treeName << ")"; +} + +void LocalVoxelsList::insert(QString treeName, StrongVoxelTreePointer& tree) { + // If the key don't already exist or the value is null + if (!_trees.contains(treeName) || !_trees.value(treeName)) { + _trees.insert(treeName, tree); + qDebug() << "[DEBUG] LocalVoxelsList : added local tree (" << treeName << ")"; + } else { + // if not we replace the tree created by the user with the existing one + tree = _trees.value(treeName); + qDebug() << "[DEBUG] LocalVoxelsList : local tree already exist (" << treeName << ")"; + } +} + +void LocalVoxelsList::remove(QString treeName) { + // if the tree is not used anymore (no strong pointer) + if (!_trees.value(treeName)) { + // then remove it from the list + qDebug() << "[DEBUG] LocalVoxelsList : removed unused tree (" << treeName << ")"; + _trees.remove(treeName); + } else { + qDebug() << "[DEBUG] LocalVoxelsList : tree still in use (" << treeName << ")"; + } +} \ No newline at end of file diff --git a/libraries/voxels/src/LocalVoxelsList.h b/libraries/voxels/src/LocalVoxelsList.h new file mode 100644 index 0000000000..e4b4decf8e --- /dev/null +++ b/libraries/voxels/src/LocalVoxelsList.h @@ -0,0 +1,59 @@ +// +// LocalVoxelsList.h +// hifi +// +// Created by Clément Brisset on 2/24/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// + +#ifndef __hifi__LocalVoxelsList__ +#define __hifi__LocalVoxelsList__ + +#include +#include +#include +#include + +#include "VoxelTree.h" + +typedef QSharedPointer StrongVoxelTreePointer; +typedef QWeakPointer WeakVoxelTreePointer; + +static const QString DOMAIN_TREE_NAME = "domain"; +static const QString CLIPBOARD_TREE_NAME = "clipboard"; +static const QString IMPORT_TREE_NAME = "import"; + +/// Handles the the storage and cleanup of local named trees used by JS +class LocalVoxelsList { +public: + static LocalVoxelsList* getInstance(); + ~LocalVoxelsList(); + + /// Lookup up a tree in the QHash and return a strong pointer to it. + /// \param treeName name of the tree to look up + StrongVoxelTreePointer getTree(QString treeName); + + /// Add a that will stay in the list until destruction of the instance and won't be destroyed then either. + /// \param treeName name to give to the tree in the list + /// \param tree standard pointer to the tree + void addPersistantTree(QString treeName, VoxelTree* tree); + + /// insert a local tree in the list + /// \param treeName name to give to the tree in the list + /// \param tree strong pointer to the tree + void insert(QString treeName, StrongVoxelTreePointer& tree); + + /// remove a tree from the list if it's not being used anymore + /// \param treeName name of the tree to remove + void remove(QString treeName); + +private: + static LocalVoxelsList* _instance; + LocalVoxelsList(); + + QHash _trees; + + QList _persistantTrees; +}; + +#endif /* defined(__hifi__LocalVoxelsList__) */ diff --git a/svo-viewer/CMakeLists.txt b/svo-viewer/CMakeLists.txt index c76cc4209b..8eceb0ea43 100644 --- a/svo-viewer/CMakeLists.txt +++ b/svo-viewer/CMakeLists.txt @@ -61,15 +61,7 @@ foreach(EXTERNAL_SOURCE_SUBDIR ${EXTERNAL_SOURCE_SUBDIRS}) set(APPLICATION_SRCS ${APPLICATION_SRCS} "${SUBDIR_SRCS}") endforeach(EXTERNAL_SOURCE_SUBDIR) -find_package(Qt5Core REQUIRED) -find_package(Qt5Gui REQUIRED) -find_package(Qt5Multimedia REQUIRED) -find_package(Qt5Network REQUIRED) -find_package(Qt5OpenGL REQUIRED) -find_package(Qt5Svg REQUIRED) -find_package(Qt5WebKit REQUIRED) -find_package(Qt5WebKitWidgets REQUIRED) -find_package(Qt5Xml REQUIRED) +find_package(Qt5 COMPONENTS Core Gui Multimedia Network OpenGL Script Svg WebKit WebKitWidgets Xml UiTools) # grab the ui files in resources/ui file (GLOB_RECURSE QT_UI_FILES ui/*.ui) @@ -122,8 +114,6 @@ link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") find_package(GLM REQUIRED) find_package(ZLIB) -qt5_use_modules(${TARGET_NAME} Core Gui Multimedia Network OpenGL Script Svg WebKit WebKitWidgets Xml UiTools) - # include headers for interface include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/includes") @@ -131,7 +121,9 @@ include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/includes" # use system flag so warnings are supressed include_directories(SYSTEM "${GLM_INCLUDE_DIRS}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}") +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" + Qt5::Core Qt5::Gui Qt5::Multimedia Qt5::Network Qt5::OpenGL + Qt5::Script Qt5::Svg Qt5::WebKit Qt5::WebKitWidgets Qt5::Xml Qt5::UiTools) if (APPLE) # link in required OS X frameworks and include the right GL headers diff --git a/svo-viewer/src/Render2.cpp b/svo-viewer/src/Render2.cpp index 06410cfe4e..56ce3e04ae 100755 --- a/svo-viewer/src/Render2.cpp +++ b/svo-viewer/src/Render2.cpp @@ -267,7 +267,10 @@ void SvoViewer::InitializeVoxelOpt2RenderSystem() delete [] _readVertexStructs; //delete [] _readIndicesArray; delete [] faceCenters; - for (int k = 0; k < NUM_CUBE_FACES; k++) if (_segmentIdxBuffers[i].idxBuff[k]) delete [] _segmentIdxBuffers[i].idxBuff[k]; + + for (int k = 0; k < NUM_CUBE_FACES; k++) { + delete[] _segmentIdxBuffers[i].idxBuff[k]; + } } _voxelOptRenderInitialized = true; diff --git a/tests/metavoxels/CMakeLists.txt b/tests/metavoxels/CMakeLists.txt index 39730ab015..4654d8c353 100644 --- a/tests/metavoxels/CMakeLists.txt +++ b/tests/metavoxels/CMakeLists.txt @@ -8,9 +8,7 @@ set(MACRO_DIR "${ROOT_DIR}/cmake/macros") # setup for find modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules/") -find_package(Qt5Network REQUIRED) -find_package(Qt5Script REQUIRED) -find_package(Qt5Widgets REQUIRED) +find_package(Qt5 COMPONENTS Network Script Widgets) include(${MACRO_DIR}/AutoMTC.cmake) auto_mtc(${TARGET_NAME} "${ROOT_DIR}") @@ -18,8 +16,6 @@ auto_mtc(${TARGET_NAME} "${ROOT_DIR}") include(${MACRO_DIR}/SetupHifiProject.cmake) setup_hifi_project(${TARGET_NAME} TRUE "${AUTOMTC_SRC}") -qt5_use_modules(${TARGET_NAME} Network Script Widgets) - #include glm include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") @@ -33,3 +29,5 @@ IF (WIN32) target_link_libraries(${TARGET_NAME} Winmm Ws2_32) ENDIF(WIN32) +target_link_libraries(${TARGET_NAME} Qt5::Network Qt5::Widgets Qt5::Script) + diff --git a/voxel-edit/CMakeLists.txt b/voxel-edit/CMakeLists.txt index d394cea518..126775b152 100644 --- a/voxel-edit/CMakeLists.txt +++ b/voxel-edit/CMakeLists.txt @@ -12,12 +12,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} "${ROOT_DIR}") +find_package(Qt5Script REQUIRED) + include(${MACRO_DIR}/SetupHifiProject.cmake) setup_hifi_project(${TARGET_NAME} TRUE) -find_package(Qt5Script REQUIRED) -qt5_use_modules(${TARGET_NAME} Script) - # link in the shared library include(${MACRO_DIR}/LinkHifiLibrary.cmake) link_hifi_library(shared ${TARGET_NAME} "${ROOT_DIR}") @@ -31,3 +30,5 @@ link_hifi_library(voxels ${TARGET_NAME} "${ROOT_DIR}") IF (WIN32) target_link_libraries(${TARGET_NAME} Winmm Ws2_32) ENDIF(WIN32) + +target_link_libraries(${TARGET_NAME} Qt5::Script) \ No newline at end of file