From 80337d240922a2565f82022782b951723ed075aa Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 25 Feb 2014 16:12:05 -0800 Subject: [PATCH 01/31] Base classe for shared named trees --- libraries/voxels/src/LocalVoxelsList.cpp | 64 ++++++++++++++++++++++++ libraries/voxels/src/LocalVoxelsList.h | 55 ++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 libraries/voxels/src/LocalVoxelsList.cpp create mode 100644 libraries/voxels/src/LocalVoxelsList.h diff --git a/libraries/voxels/src/LocalVoxelsList.cpp b/libraries/voxels/src/LocalVoxelsList.cpp new file mode 100644 index 0000000000..4e378b665c --- /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); + _persistantTree.push_back(treePtr); + _trees.insert(treeName, treePtr); + qDebug() << "[DEBUG] LocalVoxelsList : added persistant tree (" << treeName << ")" << endl; +} + +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 << ")" << endl; + } 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 << ")"<< endl; + } +} + +void LocalVoxelsList::remove(QString treeName) { + // if the tree is not used anymore (no strong pointer) + if (!_trees.value(treeName, StrongVoxelTreePointer(NULL))) { + // then remove it from the list + qDebug() << "[DEBUG] LocalVoxelsList : removed unused tree (" << treeName << ")" << endl; + _trees.remove(treeName); + } else { + qDebug() << "[DEBUG] LocalVoxelsList : tree still in use (" << treeName << ")" << endl; + } +} \ 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..f3de0e54b8 --- /dev/null +++ b/libraries/voxels/src/LocalVoxelsList.h @@ -0,0 +1,55 @@ +// +// 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; + +/// 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 _persistantTree; +}; + +#endif /* defined(__hifi__LocalVoxelsList__) */ From 413031361845009a1d9d641af6ed09c0f5c84c40 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 25 Feb 2014 16:13:26 -0800 Subject: [PATCH 02/31] Added meta object for js LocalVoxels object --- libraries/voxels/src/LocalVoxels.cpp | 90 ++++++++++++++++++++++++++++ libraries/voxels/src/LocalVoxels.h | 76 +++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 libraries/voxels/src/LocalVoxels.cpp create mode 100644 libraries/voxels/src/LocalVoxels.h diff --git a/libraries/voxels/src/LocalVoxels.cpp b/libraries/voxels/src/LocalVoxels.cpp new file mode 100644 index 0000000000..4df3cd5951 --- /dev/null +++ b/libraries/voxels/src/LocalVoxels.cpp @@ -0,0 +1,90 @@ +// +// 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); +} + +void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale, + uchar red, uchar green, uchar blue) {if (_tree ) { + if (_tree->tryLockForWrite()) { + _tree->createVoxel(x, y, z, scale, red, green, blue, false); + _tree->unlock(); + } +} +} + +void LocalVoxels::setVoxel(float x, float y, float z, float scale, + uchar red, uchar green, uchar blue) { + if (_tree ) { + if (_tree->tryLockForWrite()) { + _tree->createVoxel(x, y, z, scale, red, green, blue, true); + _tree->unlock(); + } + } +} + +void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) { + if (_tree ) { + if (_tree->tryLockForWrite()) { + _tree->deleteVoxelAt(x, y, z, scale); + _tree->unlock(); + } + } +} + +RayToVoxelIntersectionResult LocalVoxels::findRayIntersection(const PickRay& ray) { + RayToVoxelIntersectionResult result; + if (_tree) { + if (_tree->tryLockForRead()) { + 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); + } + _tree->unlock(); + } + } + 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/voxels/src/LocalVoxels.h b/libraries/voxels/src/LocalVoxels.h new file mode 100644 index 0000000000..dc81935835 --- /dev/null +++ b/libraries/voxels/src/LocalVoxels.h @@ -0,0 +1,76 @@ +// +// 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 "VoxelTree.h" +#include "LocalVoxelsList.h" + + +/// 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); + + /// 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__) */ From 96d4f38e425e37c14cab2f344d31d08b72ce5c3b Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 25 Feb 2014 16:14:58 -0800 Subject: [PATCH 03/31] Modified the Script engine for Local voxel handling --- libraries/script-engine/src/ScriptEngine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 076f941222..cf33d08c3c 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -122,6 +123,7 @@ bool ScriptEngine::setScriptContents(const QString& scriptContents) { } Q_SCRIPT_DECLARE_QMETAOBJECT(AudioInjectorOptions, QObject*) +Q_SCRIPT_DECLARE_QMETAOBJECT(LocalVoxels, QString) void ScriptEngine::init() { if (_isInitialized) { @@ -150,6 +152,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); From 878259de48519c0a1484a611b64bb88a3da4a9d1 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 25 Feb 2014 16:16:56 -0800 Subject: [PATCH 04/31] Added example file for LocalVoxels use --- examples/localVoxelsExample.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 examples/localVoxelsExample.js diff --git a/examples/localVoxelsExample.js b/examples/localVoxelsExample.js new file mode 100644 index 0000000000..4892f656d5 --- /dev/null +++ b/examples/localVoxelsExample.js @@ -0,0 +1,7 @@ + +function test() { + var tree = LocalVoxels("tree"); + tree.setVoxel(0, 0, 0, 1, 128, 128, 128); +} + +test(); \ No newline at end of file From 0026002ecb19bb8143016092aa6ac3a0439d1360 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 27 Feb 2014 14:38:18 -0800 Subject: [PATCH 05/31] Added domain and clipboard to the local trees --- interface/src/Application.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e8a7d0dcbc..0a9a0c892b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include "Application.h" #include "ClipboardScriptingInterface.h" @@ -309,7 +310,10 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : checkVersion(); _overlays.init(_glWidget); // do this before scripts load - + + LocalVoxelsList::getInstance()->addPersistantTree("domain", _voxels.getTree()); + LocalVoxelsList::getInstance()->addPersistantTree("clipboard", &_clipboard); + // do this as late as possible so that all required subsystems are inialized loadScripts(); } From b07081407a7d4f5c74a31dd6a619c91bbf8f7b81 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 27 Feb 2014 14:47:05 -0800 Subject: [PATCH 06/31] Made commom string name static const --- interface/src/Application.cpp | 4 ++-- libraries/voxels/src/LocalVoxelsList.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0a9a0c892b..ec1e27bf16 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -311,8 +311,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _overlays.init(_glWidget); // do this before scripts load - LocalVoxelsList::getInstance()->addPersistantTree("domain", _voxels.getTree()); - LocalVoxelsList::getInstance()->addPersistantTree("clipboard", &_clipboard); + 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(); diff --git a/libraries/voxels/src/LocalVoxelsList.h b/libraries/voxels/src/LocalVoxelsList.h index f3de0e54b8..af1c7046f9 100644 --- a/libraries/voxels/src/LocalVoxelsList.h +++ b/libraries/voxels/src/LocalVoxelsList.h @@ -19,6 +19,9 @@ typedef QSharedPointer StrongVoxelTreePointer; typedef QWeakPointer WeakVoxelTreePointer; +static const QString DOMAIN_TREE_NAME = "domain"; +static const QString CLIPBOARD_TREE_NAME = "clipboard"; + /// Handles the the storage and cleanup of local named trees used by JS class LocalVoxelsList { public: From 5986fcafaea7c35f7303a5e492c27e6d2781677a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 27 Feb 2014 16:41:58 -0800 Subject: [PATCH 07/31] Added copyTo and pasteFrom to ClipboardScriptingInterface - Supports LocalVoxels --- interface/src/ClipboardScriptingInterface.cpp | 20 +++++++++++++++++++ interface/src/ClipboardScriptingInterface.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/interface/src/ClipboardScriptingInterface.cpp b/interface/src/ClipboardScriptingInterface.cpp index c669b465ad..5c68de5cf7 100644 --- a/interface/src/ClipboardScriptingInterface.cpp +++ b/interface/src/ClipboardScriptingInterface.cpp @@ -5,6 +5,8 @@ // Copyright (c) 2014 High Fidelity, Inc. All rights reserved. // +#include + #include "Application.h" #include "ClipboardScriptingInterface.h" @@ -92,3 +94,21 @@ void ClipboardScriptingInterface::nudgeVoxel(float x, float y, float z, float s, Application::getInstance()->nudgeVoxelsByVector(sourceVoxel, nudgeVecInTreeSpace); } +void ClipboardScriptingInterface::copyTo(float x, float y, float z, float s, + const QString source, const QString destination) { + StrongVoxelTreePointer sourceTree = LocalVoxelsList::getInstance()->getTree(source); + StrongVoxelTreePointer destinationTree = LocalVoxelsList::getInstance()->getTree(destination); + + VoxelTreeElement* destinationNode = destinationTree->getVoxelAt(x, y, z, s); + destinationTree->copyFromTreeIntoSubTree(sourceTree.data(), destinationNode); + +} + +void ClipboardScriptingInterface::pasteFrom(float x, float y, float z, float s, + const QString source, const QString destination) { + StrongVoxelTreePointer sourceTree = LocalVoxelsList::getInstance()->getTree(source); + StrongVoxelTreePointer destinationTree = LocalVoxelsList::getInstance()->getTree(destination); + + VoxelTreeElement* sourceNode = sourceTree->getVoxelAt(x, y, z, s); + destinationTree->copySubTreeIntoNewTree(sourceNode, destinationTree.data(), true); +} \ No newline at end of file diff --git a/interface/src/ClipboardScriptingInterface.h b/interface/src/ClipboardScriptingInterface.h index 99747f56f6..1e18970983 100644 --- a/interface/src/ClipboardScriptingInterface.h +++ b/interface/src/ClipboardScriptingInterface.h @@ -38,6 +38,9 @@ public slots: void nudgeVoxel(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec); void nudgeVoxel(float x, float y, float z, float s, const glm::vec3& nudgeVec); + + void copyTo(float x, float y, float z, float s, const QString source, const QString destination); + void pasteFrom(float x, float y, float z, float s, const QString source, const QString destination); }; #endif // __interface__Clipboard__ From 11e80e0aaa3a2dfef4d68f1852b6df1e4c802966 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 27 Feb 2014 17:52:44 -0800 Subject: [PATCH 08/31] Added getVoxelAt for LocalVoxels + handle the case of the domain tree --- libraries/voxels/src/LocalVoxels.cpp | 42 +++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/libraries/voxels/src/LocalVoxels.cpp b/libraries/voxels/src/LocalVoxels.cpp index 4df3cd5951..7c4ba4e284 100644 --- a/libraries/voxels/src/LocalVoxels.cpp +++ b/libraries/voxels/src/LocalVoxels.cpp @@ -13,6 +13,13 @@ LocalVoxels::LocalVoxels(QString name) : _name(name), _tree(new VoxelTree(true)) { + // Don't allow creation of a local tree pointing to the domain tree. + if (_name == DOMAIN_TREE_NAME) { + qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; + _name.clear(); + _tree.clear(); + } + LocalVoxelsList::getInstance()->insert(_name, _tree); } @@ -21,13 +28,40 @@ LocalVoxels::~LocalVoxels() { LocalVoxelsList::getInstance()->remove(_name); } -void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale, - uchar red, uchar green, uchar blue) {if (_tree ) { - if (_tree->tryLockForWrite()) { - _tree->createVoxel(x, y, z, scale, red, green, blue, false); +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 (_tree ) { + if (_tree->tryLockForWrite()) { + _tree->createVoxel(x, y, z, scale, red, green, blue, false); + _tree->unlock(); + } + } } void LocalVoxels::setVoxel(float x, float y, float z, float scale, From 5b085a72cd9e89bc4482e26c33870cb87feaa9df Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 28 Feb 2014 11:21:32 -0800 Subject: [PATCH 09/31] Added import tree to LocalVoxels --- interface/src/VoxelImporter.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/VoxelImporter.cpp b/interface/src/VoxelImporter.cpp index 3949ee96d2..b39f73f5d0 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())); From 41931ebd571705a516668bf722e1698230fb8969 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 28 Feb 2014 11:22:14 -0800 Subject: [PATCH 10/31] Removed copyTo and pasteFrom from ClipboardScriptingInterface (not useful in the end) --- interface/src/ClipboardScriptingInterface.cpp | 19 ------------------- interface/src/ClipboardScriptingInterface.h | 3 --- 2 files changed, 22 deletions(-) diff --git a/interface/src/ClipboardScriptingInterface.cpp b/interface/src/ClipboardScriptingInterface.cpp index 5c68de5cf7..c99c55db4d 100644 --- a/interface/src/ClipboardScriptingInterface.cpp +++ b/interface/src/ClipboardScriptingInterface.cpp @@ -92,23 +92,4 @@ void ClipboardScriptingInterface::nudgeVoxel(float x, float y, float z, float s, s / (float)TREE_SCALE }; Application::getInstance()->nudgeVoxelsByVector(sourceVoxel, nudgeVecInTreeSpace); -} - -void ClipboardScriptingInterface::copyTo(float x, float y, float z, float s, - const QString source, const QString destination) { - StrongVoxelTreePointer sourceTree = LocalVoxelsList::getInstance()->getTree(source); - StrongVoxelTreePointer destinationTree = LocalVoxelsList::getInstance()->getTree(destination); - - VoxelTreeElement* destinationNode = destinationTree->getVoxelAt(x, y, z, s); - destinationTree->copyFromTreeIntoSubTree(sourceTree.data(), destinationNode); - -} - -void ClipboardScriptingInterface::pasteFrom(float x, float y, float z, float s, - const QString source, const QString destination) { - StrongVoxelTreePointer sourceTree = LocalVoxelsList::getInstance()->getTree(source); - StrongVoxelTreePointer destinationTree = LocalVoxelsList::getInstance()->getTree(destination); - - VoxelTreeElement* sourceNode = sourceTree->getVoxelAt(x, y, z, s); - destinationTree->copySubTreeIntoNewTree(sourceNode, destinationTree.data(), true); } \ No newline at end of file diff --git a/interface/src/ClipboardScriptingInterface.h b/interface/src/ClipboardScriptingInterface.h index 1e18970983..99747f56f6 100644 --- a/interface/src/ClipboardScriptingInterface.h +++ b/interface/src/ClipboardScriptingInterface.h @@ -38,9 +38,6 @@ public slots: void nudgeVoxel(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec); void nudgeVoxel(float x, float y, float z, float s, const glm::vec3& nudgeVec); - - void copyTo(float x, float y, float z, float s, const QString source, const QString destination); - void pasteFrom(float x, float y, float z, float s, const QString source, const QString destination); }; #endif // __interface__Clipboard__ From b854c450f4f0cf88f84af6a1ec09ab5d0c973d26 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 28 Feb 2014 11:25:07 -0800 Subject: [PATCH 11/31] Moved LocalVoxels class --- libraries/script-engine/src/ScriptEngine.cpp | 2 +- libraries/voxels/src/LocalVoxels.cpp | 124 ------------------- libraries/voxels/src/LocalVoxels.h | 76 ------------ 3 files changed, 1 insertion(+), 201 deletions(-) delete mode 100644 libraries/voxels/src/LocalVoxels.cpp delete mode 100644 libraries/voxels/src/LocalVoxels.h diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 37fb996bb6..718e5331dd 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -21,11 +21,11 @@ #include #include #include -#include #include #include "MenuItemProperties.h" +#include "LocalVoxels.h" #include "ScriptEngine.h" const unsigned int VISUAL_DATA_CALLBACK_USECS = (1.0 / 60.0) * 1000 * 1000; diff --git a/libraries/voxels/src/LocalVoxels.cpp b/libraries/voxels/src/LocalVoxels.cpp deleted file mode 100644 index 7c4ba4e284..0000000000 --- a/libraries/voxels/src/LocalVoxels.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// -// 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)) -{ - // Don't allow creation of a local tree pointing to the domain tree. - if (_name == DOMAIN_TREE_NAME) { - qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; - _name.clear(); - _tree.clear(); - } - - 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 (_tree ) { - if (_tree->tryLockForWrite()) { - _tree->createVoxel(x, y, z, scale, red, green, blue, false); - _tree->unlock(); - } - } -} - -void LocalVoxels::setVoxel(float x, float y, float z, float scale, - uchar red, uchar green, uchar blue) { - if (_tree ) { - if (_tree->tryLockForWrite()) { - _tree->createVoxel(x, y, z, scale, red, green, blue, true); - _tree->unlock(); - } - } -} - -void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) { - if (_tree ) { - if (_tree->tryLockForWrite()) { - _tree->deleteVoxelAt(x, y, z, scale); - _tree->unlock(); - } - } -} - -RayToVoxelIntersectionResult LocalVoxels::findRayIntersection(const PickRay& ray) { - RayToVoxelIntersectionResult result; - if (_tree) { - if (_tree->tryLockForRead()) { - 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); - } - _tree->unlock(); - } - } - 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/voxels/src/LocalVoxels.h b/libraries/voxels/src/LocalVoxels.h deleted file mode 100644 index dc81935835..0000000000 --- a/libraries/voxels/src/LocalVoxels.h +++ /dev/null @@ -1,76 +0,0 @@ -// -// 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 "VoxelTree.h" -#include "LocalVoxelsList.h" - - -/// 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); - - /// 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__) */ From 20b921f4f8b6c3ddffecbc87bc41ccc81d1a83c3 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 28 Feb 2014 11:26:17 -0800 Subject: [PATCH 12/31] Fixed typo --- libraries/voxels/src/LocalVoxelsList.cpp | 2 +- libraries/voxels/src/LocalVoxelsList.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/voxels/src/LocalVoxelsList.cpp b/libraries/voxels/src/LocalVoxelsList.cpp index 4e378b665c..16f72483de 100644 --- a/libraries/voxels/src/LocalVoxelsList.cpp +++ b/libraries/voxels/src/LocalVoxelsList.cpp @@ -35,7 +35,7 @@ StrongVoxelTreePointer LocalVoxelsList::getTree(QString treeName) { void LocalVoxelsList::addPersistantTree(QString treeName, VoxelTree* tree) { StrongVoxelTreePointer treePtr(tree, doNothing); - _persistantTree.push_back(treePtr); + _persistantTrees.push_back(treePtr); _trees.insert(treeName, treePtr); qDebug() << "[DEBUG] LocalVoxelsList : added persistant tree (" << treeName << ")" << endl; } diff --git a/libraries/voxels/src/LocalVoxelsList.h b/libraries/voxels/src/LocalVoxelsList.h index af1c7046f9..e4b4decf8e 100644 --- a/libraries/voxels/src/LocalVoxelsList.h +++ b/libraries/voxels/src/LocalVoxelsList.h @@ -21,6 +21,7 @@ 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 { @@ -52,7 +53,7 @@ private: QHash _trees; - QList _persistantTree; + QList _persistantTrees; }; #endif /* defined(__hifi__LocalVoxelsList__) */ From 4a9415faeb438c14128df79e2034d15550f27f99 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 28 Feb 2014 11:31:37 -0800 Subject: [PATCH 13/31] Prevent users from modifying the domain tree with the LocalVoxels interface --- libraries/script-engine/src/LocalVoxels.cpp | 161 ++++++++++++++++++++ libraries/script-engine/src/LocalVoxels.h | 90 +++++++++++ 2 files changed, 251 insertions(+) create mode 100644 libraries/script-engine/src/LocalVoxels.cpp create mode 100644 libraries/script-engine/src/LocalVoxels.h diff --git a/libraries/script-engine/src/LocalVoxels.cpp b/libraries/script-engine/src/LocalVoxels.cpp new file mode 100644 index 0000000000..a92ffd3a5c --- /dev/null +++ b/libraries/script-engine/src/LocalVoxels.cpp @@ -0,0 +1,161 @@ +// +// 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)) +{ + if (_name == DOMAIN_TREE_NAME) { + qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; + } + + 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() << "Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + + if (_tree ) { + if (_tree->tryLockForWrite()) { + _tree->createVoxel(x, y, z, scale, red, green, blue, false); + _tree->unlock(); + } + } +} + +void LocalVoxels::setVoxel(float x, float y, float z, float scale, + uchar red, uchar green, uchar blue) { + if (_name == DOMAIN_TREE_NAME) { + qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + + if (_tree ) { + if (_tree->tryLockForWrite()) { + _tree->createVoxel(x, y, z, scale, red, green, blue, true); + _tree->unlock(); + } + } +} + +void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) { + if (_name == DOMAIN_TREE_NAME) { + qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + + if (_tree ) { + if (_tree->tryLockForWrite()) { + _tree->deleteVoxelAt(x, y, z, scale); + _tree->unlock(); + } + } +} + +void LocalVoxels::copyTo(float x, float y, float z, float scale, const QString destination) { + if (destination == DOMAIN_TREE_NAME) { + qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + + + StrongVoxelTreePointer destinationTree = LocalVoxelsList::getInstance()->getTree(destination); + + VoxelTreeElement* destinationNode = destinationTree->getVoxelAt(x, y, z, 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() << "Please use the \"Voxels\" interface to modify the domain tree."; + return; + } + + StrongVoxelTreePointer sourceTree = LocalVoxelsList::getInstance()->getTree(source); + + VoxelTreeElement* sourceNode = _tree->getVoxelAt(x, y, z, scale); + _tree->copySubTreeIntoNewTree(sourceNode, sourceTree.data(), true); +} + +RayToVoxelIntersectionResult LocalVoxels::findRayIntersection(const PickRay& ray) { + RayToVoxelIntersectionResult result; + if (_tree) { + if (_tree->tryLockForRead()) { + 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); + } + _tree->unlock(); + } + } + 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__) */ From 4bcb43f7dd23b5fdb7b09082e7f820eb00b9298a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 28 Feb 2014 15:10:53 -0800 Subject: [PATCH 14/31] Added an overlay system for local trees --- interface/src/ui/LocalVoxelsOverlay.cpp | 111 ++++++++++++++++++++++++ interface/src/ui/LocalVoxelsOverlay.h | 45 ++++++++++ 2 files changed, 156 insertions(+) create mode 100644 interface/src/ui/LocalVoxelsOverlay.cpp create mode 100644 interface/src/ui/LocalVoxelsOverlay.h diff --git a/interface/src/ui/LocalVoxelsOverlay.cpp b/interface/src/ui/LocalVoxelsOverlay.cpp new file mode 100644 index 0000000000..8a6be8cd82 --- /dev/null +++ b/interface/src/ui/LocalVoxelsOverlay.cpp @@ -0,0 +1,111 @@ +// +// LocalVoxelsOverlay.cpp +// hifi +// +// Created by Clément Brisset on 2/28/14. +// Copyright (c) 2014 High Fidelity, Inc. All rights reserved. +// +// + +#include +#include + +#include "LocalVoxelsOverlay.h" + +struct OverlayElement { + QString treeName; + StrongVoxelTreePointer tree; // so that the tree doesn't get freed + glm::vec3 position; + float scale; + bool wantDisplay; + StrongVoxelSystemPointer voxelSystem; +}; + + +LocalVoxelsOverlay::LocalVoxelsOverlay() { +} + +LocalVoxelsOverlay::~LocalVoxelsOverlay() { +} + +void LocalVoxelsOverlay::render() { + QMap::iterator i; + for (i = _overlayMap.begin(); i != _overlayMap.end(); ++i) { + if (i->wantDisplay && i->scale > 0) { + glPushMatrix(); + glTranslatef(i->position.x, i->position.y, i->position.z); + glScalef(i->scale, i->scale, i->scale); + i->voxelSystem->render(); + glPopMatrix(); + } + } +} + +void LocalVoxelsOverlay::addOverlay(QString overlayName, QString treeName) { + if (treeName == DOMAIN_TREE_NAME) { + qDebug() << "addOverlay(): Can't create overlay from domain tree"; + return; + } + if (_overlayMap.contains(overlayName)) { + qDebug() << "addOverlay(): Overlay name elready in use"; + return; + } + + StrongVoxelTreePointer tree = LocalVoxelsList::getInstance()->getTree(treeName); + if (tree.isNull()) { + qDebug() << "addOverlay(): Invalid tree name"; + return; + } + StrongVoxelSystemPointer voxelSystem = _voxelSystemMap[treeName]; + if (voxelSystem.isNull()) { + voxelSystem = StrongVoxelSystemPointer(new VoxelSystem(TREE_SCALE, + DEFAULT_MAX_VOXELS_PER_SYSTEM, + tree.data())); + _voxelSystemMap.insert(treeName, voxelSystem); + } + + OverlayElement element = { + treeName, + tree, + glm::vec3(0, 0, 0), + 0, + false, + voxelSystem + }; + _overlayMap.insert(overlayName, element); +} + +void LocalVoxelsOverlay::setPosition(QString overlayName, float x, float y, float z) { + if (_overlayMap.contains(overlayName)) { + _overlayMap[overlayName].position = glm::vec3(x, y, z); + } +} + +void LocalVoxelsOverlay::setScale(QString overlayName, float scale) { + if (_overlayMap.contains(overlayName)) { + _overlayMap[overlayName].scale = scale; + } +} + +void LocalVoxelsOverlay::display(QString overlayName, bool wantDisplay) { + if (_overlayMap.contains(overlayName)) { + _overlayMap[overlayName].wantDisplay = wantDisplay; + } +} + +void LocalVoxelsOverlay::removeOverlay(QString overlayName) { + if (_overlayMap.contains(overlayName)) { + QString treeName = _overlayMap.take(overlayName).treeName; + + if (_voxelSystemMap.value(treeName).isNull()) { + _voxelSystemMap.remove(treeName); + } + } +} + + + + + + + diff --git a/interface/src/ui/LocalVoxelsOverlay.h b/interface/src/ui/LocalVoxelsOverlay.h new file mode 100644 index 0000000000..28ce6c909f --- /dev/null +++ b/interface/src/ui/LocalVoxelsOverlay.h @@ -0,0 +1,45 @@ +// +// 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 "Volume3DOverlay.h" + +#include +#include +#include + +struct OverlayElement; +typedef QSharedPointer StrongVoxelSystemPointer; +typedef QWeakPointer WeakVoxelSystemPointer; + +class LocalVoxelsOverlay : public Volume3DOverlay { + Q_OBJECT +public: + LocalVoxelsOverlay(); + ~LocalVoxelsOverlay(); + + virtual void render(); + + void addOverlay(QString overlayName, QString treeName); + void setPosition(QString overlayName, float x, float y, float z); + void setScale(QString overlayName, float scale); + void update(QString overlayName); + void display(QString overlayName, bool wantDisplay); + void removeOverlay(QString overlayName); + + +private: + QMap _overlayMap; // overlayName/overlayElement + QMap _voxelSystemMap; // treeName/voxelSystem +}; + +#endif /* defined(__hifi__LocalVoxelsOverlay__) */ From ea0f414c2389da74fcd3ddee7131bb1d6826883b Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 28 Feb 2014 15:11:38 -0800 Subject: [PATCH 15/31] Added possibility to create a VoxelSystem from an already existing VoxelTree --- interface/src/VoxelSystem.cpp | 4 ++-- interface/src/VoxelSystem.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 24d1e73ee2..454814544c 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -55,7 +55,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), @@ -71,7 +71,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 0e2ae29475..a261d6aa53 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -45,7 +45,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; } From af691e1f752edc4bd81241bcccdb5bdb53b109cb Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 28 Feb 2014 15:14:01 -0800 Subject: [PATCH 16/31] Some comments and debug messages --- interface/src/Application.cpp | 1 + libraries/script-engine/src/LocalVoxels.cpp | 23 +++++---------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0d8ba933cb..75e9065ce0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1434,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); diff --git a/libraries/script-engine/src/LocalVoxels.cpp b/libraries/script-engine/src/LocalVoxels.cpp index a92ffd3a5c..091cdbe5a9 100644 --- a/libraries/script-engine/src/LocalVoxels.cpp +++ b/libraries/script-engine/src/LocalVoxels.cpp @@ -13,10 +13,6 @@ LocalVoxels::LocalVoxels(QString name) : _name(name), _tree(new VoxelTree(true)) { - if (_name == DOMAIN_TREE_NAME) { - qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; - } - LocalVoxelsList::getInstance()->insert(_name, _tree); } @@ -28,7 +24,6 @@ LocalVoxels::~LocalVoxels() { 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(); @@ -54,10 +49,9 @@ VoxelDetail LocalVoxels::getVoxelAt(float x, float y, float z, float scale) { void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) { if (_name == DOMAIN_TREE_NAME) { - qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; + qDebug() << "LocalVoxels::setVoxelNonDestructive(): Please use the \"Voxels\" interface to modify the domain tree."; return; } - if (_tree ) { if (_tree->tryLockForWrite()) { _tree->createVoxel(x, y, z, scale, red, green, blue, false); @@ -69,10 +63,9 @@ void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale, void LocalVoxels::setVoxel(float x, float y, float z, float scale, uchar red, uchar green, uchar blue) { if (_name == DOMAIN_TREE_NAME) { - qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; + qDebug() << "LocalVoxels::setVoxel(): Please use the \"Voxels\" interface to modify the domain tree."; return; } - if (_tree ) { if (_tree->tryLockForWrite()) { _tree->createVoxel(x, y, z, scale, red, green, blue, true); @@ -83,10 +76,9 @@ void LocalVoxels::setVoxel(float x, float y, float z, float scale, void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) { if (_name == DOMAIN_TREE_NAME) { - qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; + qDebug() << "LocalVoxels::eraseVoxel(): Please use the \"Voxels\" interface to modify the domain tree."; return; } - if (_tree ) { if (_tree->tryLockForWrite()) { _tree->deleteVoxelAt(x, y, z, scale); @@ -97,25 +89,20 @@ void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) { void LocalVoxels::copyTo(float x, float y, float z, float scale, const QString destination) { if (destination == DOMAIN_TREE_NAME) { - qDebug() << "Please use the \"Voxels\" interface to modify the domain tree."; + 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, y, z, 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() << "Please use the \"Voxels\" interface to modify the domain tree."; + 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, y, z, scale); _tree->copySubTreeIntoNewTree(sourceNode, sourceTree.data(), true); } From ef9ff0fa7401a38241da2e5043fc502d93914faa Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 3 Mar 2014 16:46:25 -0800 Subject: [PATCH 17/31] Put initialization and deletion of localVoxelSystems on render thread --- examples/localVoxelsExample.js | 38 +++++- interface/src/Application.cpp | 2 + interface/src/VoxelSystem.h | 2 +- interface/src/ui/LocalVoxelsOverlay.cpp | 148 ++++++++++------------- interface/src/ui/LocalVoxelsOverlay.h | 27 +++-- interface/src/ui/Overlay.cpp | 1 + interface/src/ui/Overlay.h | 4 + interface/src/ui/Overlays.cpp | 48 +++++++- interface/src/ui/Overlays.h | 4 +- libraries/voxels/src/LocalVoxelsList.cpp | 12 +- 10 files changed, 170 insertions(+), 116 deletions(-) diff --git a/examples/localVoxelsExample.js b/examples/localVoxelsExample.js index 4892f656d5..dd192d4c82 100644 --- a/examples/localVoxelsExample.js +++ b/examples/localVoxelsExample.js @@ -1,7 +1,35 @@ -function test() { - var tree = LocalVoxels("tree"); - tree.setVoxel(0, 0, 0, 1, 128, 128, 128); +var tree = LocalVoxels("tree"); +tree.setVoxel(0, 0, 0, 0.5, 255, 0, 0); +tree.setVoxel(0.5, 0.5, 0.5, 0.5, 0, 255, 0); + +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: "tree" + }); + + +// 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); } - -test(); \ No newline at end of file +Script.scriptEnding.connect(scriptEnding); \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 75e9065ce0..1fb32e1989 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1920,6 +1920,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); } diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index a261d6aa53..ade4ed9b4e 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -53,8 +53,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/ui/LocalVoxelsOverlay.cpp b/interface/src/ui/LocalVoxelsOverlay.cpp index 8a6be8cd82..b14db72d99 100644 --- a/interface/src/ui/LocalVoxelsOverlay.cpp +++ b/interface/src/ui/LocalVoxelsOverlay.cpp @@ -6,106 +6,80 @@ // 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 #include "LocalVoxelsOverlay.h" -struct OverlayElement { - QString treeName; - StrongVoxelTreePointer tree; // so that the tree doesn't get freed - glm::vec3 position; - float scale; - bool wantDisplay; - StrongVoxelSystemPointer voxelSystem; -}; +QMap LocalVoxelsOverlay::_voxelSystemMap; - -LocalVoxelsOverlay::LocalVoxelsOverlay() { +LocalVoxelsOverlay::LocalVoxelsOverlay() : + Volume3DOverlay(), + _voxelCount(0) +{ + _wantDeleteOnRenderThread = true; } 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() { - QMap::iterator i; - for (i = _overlayMap.begin(); i != _overlayMap.end(); ++i) { - if (i->wantDisplay && i->scale > 0) { - glPushMatrix(); - glTranslatef(i->position.x, i->position.y, i->position.z); - glScalef(i->scale, i->scale, i->scale); - i->voxelSystem->render(); - glPopMatrix(); + 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); } } } -void LocalVoxelsOverlay::addOverlay(QString overlayName, QString treeName) { - if (treeName == DOMAIN_TREE_NAME) { - qDebug() << "addOverlay(): Can't create overlay from domain tree"; - return; - } - if (_overlayMap.contains(overlayName)) { - qDebug() << "addOverlay(): Overlay name elready in use"; - return; - } - - StrongVoxelTreePointer tree = LocalVoxelsList::getInstance()->getTree(treeName); - if (tree.isNull()) { - qDebug() << "addOverlay(): Invalid tree name"; - return; - } - StrongVoxelSystemPointer voxelSystem = _voxelSystemMap[treeName]; - if (voxelSystem.isNull()) { - voxelSystem = StrongVoxelSystemPointer(new VoxelSystem(TREE_SCALE, - DEFAULT_MAX_VOXELS_PER_SYSTEM, - tree.data())); - _voxelSystemMap.insert(treeName, voxelSystem); - } - - OverlayElement element = { - treeName, - tree, - glm::vec3(0, 0, 0), - 0, - false, - voxelSystem - }; - _overlayMap.insert(overlayName, element); -} - -void LocalVoxelsOverlay::setPosition(QString overlayName, float x, float y, float z) { - if (_overlayMap.contains(overlayName)) { - _overlayMap[overlayName].position = glm::vec3(x, y, z); - } -} - -void LocalVoxelsOverlay::setScale(QString overlayName, float scale) { - if (_overlayMap.contains(overlayName)) { - _overlayMap[overlayName].scale = scale; - } -} - -void LocalVoxelsOverlay::display(QString overlayName, bool wantDisplay) { - if (_overlayMap.contains(overlayName)) { - _overlayMap[overlayName].wantDisplay = wantDisplay; - } -} - -void LocalVoxelsOverlay::removeOverlay(QString overlayName) { - if (_overlayMap.contains(overlayName)) { - QString treeName = _overlayMap.take(overlayName).treeName; - - if (_voxelSystemMap.value(treeName).isNull()) { - _voxelSystemMap.remove(treeName); - } - } -} - - - - - - - diff --git a/interface/src/ui/LocalVoxelsOverlay.h b/interface/src/ui/LocalVoxelsOverlay.h index 28ce6c909f..c5582a54eb 100644 --- a/interface/src/ui/LocalVoxelsOverlay.h +++ b/interface/src/ui/LocalVoxelsOverlay.h @@ -11,13 +11,19 @@ #ifndef __hifi__LocalVoxelsOverlay__ #define __hifi__LocalVoxelsOverlay__ -#include "Volume3DOverlay.h" +// include this before QGLWidget, which includes an earlier version of OpenGL +#include "InterfaceConfig.h" +#include +#include #include #include #include -struct OverlayElement; +#include + +#include "Volume3DOverlay.h" + typedef QSharedPointer StrongVoxelSystemPointer; typedef QWeakPointer WeakVoxelSystemPointer; @@ -27,19 +33,18 @@ public: LocalVoxelsOverlay(); ~LocalVoxelsOverlay(); + virtual void update(float deltatime); virtual void render(); - void addOverlay(QString overlayName, QString treeName); - void setPosition(QString overlayName, float x, float y, float z); - void setScale(QString overlayName, float scale); - void update(QString overlayName); - void display(QString overlayName, bool wantDisplay); - void removeOverlay(QString overlayName); - + virtual void setProperties(const QScriptValue& properties); private: - QMap _overlayMap; // overlayName/overlayElement - QMap _voxelSystemMap; // treeName/voxelSystem + 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.cpp b/interface/src/ui/Overlay.cpp index 40da2253f4..61c0ee36c0 100644 --- a/interface/src/ui/Overlay.cpp +++ b/interface/src/ui/Overlay.cpp @@ -18,6 +18,7 @@ Overlay::Overlay() : _parent(NULL), + _wantDeleteOnRenderThread(false), _alpha(DEFAULT_ALPHA), _color(DEFAULT_BACKGROUND_COLOR), _visible(true) diff --git a/interface/src/ui/Overlay.h b/interface/src/ui/Overlay.h index df898ec741..95d4bf7541 100644 --- a/interface/src/ui/Overlay.h +++ b/interface/src/ui/Overlay.h @@ -28,9 +28,11 @@ public: Overlay(); ~Overlay(); void init(QGLWidget* parent); + virtual void update(float deltatime) {} virtual void render() = 0; // getters + bool deleteOnRenderThread() { return _wantDeleteOnRenderThread; } bool getVisible() const { return _visible; } const xColor& getColor() const { return _color; } float getAlpha() const { return _alpha; } @@ -44,6 +46,8 @@ public: protected: QGLWidget* _parent; + bool _wantDeleteOnRenderThread; + float _alpha; xColor _color; bool _visible; // should the overlay be drawn at all diff --git a/interface/src/ui/Overlays.cpp b/interface/src/ui/Overlays.cpp index 84944332f1..a57970b797 100644 --- a/interface/src/ui/Overlays.cpp +++ b/interface/src/ui/Overlays.cpp @@ -13,19 +13,41 @@ #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(); @@ -79,6 +101,12 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope thisOverlay->setProperties(properties); created = true; is3D = true; + } else if (type == "localvoxels") { + thisOverlay = new LocalVoxelsOverlay(); + thisOverlay->init(_parent); + thisOverlay->setProperties(properties); + created = true; + is3D = true; } if (created) { @@ -111,11 +139,21 @@ 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; } + + if (overlayToDelete->deleteOnRenderThread()) { + _overlaysToDelete.push_back(overlayToDelete); + } else { + delete 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/voxels/src/LocalVoxelsList.cpp b/libraries/voxels/src/LocalVoxelsList.cpp index 16f72483de..e8f5a09d6d 100644 --- a/libraries/voxels/src/LocalVoxelsList.cpp +++ b/libraries/voxels/src/LocalVoxelsList.cpp @@ -37,28 +37,28 @@ 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 << ")" << endl; + 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 << ")" << endl; + 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 << ")"<< endl; + 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, StrongVoxelTreePointer(NULL))) { + if (!_trees.value(treeName)) { // then remove it from the list - qDebug() << "[DEBUG] LocalVoxelsList : removed unused tree (" << treeName << ")" << endl; + qDebug() << "[DEBUG] LocalVoxelsList : removed unused tree (" << treeName << ")"; _trees.remove(treeName); } else { - qDebug() << "[DEBUG] LocalVoxelsList : tree still in use (" << treeName << ")" << endl; + qDebug() << "[DEBUG] LocalVoxelsList : tree still in use (" << treeName << ")"; } } \ No newline at end of file From 357d71e6377a0de0428701e39ba5b02474e8a08d Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 3 Mar 2014 17:52:49 -0800 Subject: [PATCH 18/31] Added stuff to localVoxelsExample.js --- examples/localVoxelsExample.js | 24 +++++++++++++++--- libraries/script-engine/src/LocalVoxels.cpp | 27 +++++++++++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/examples/localVoxelsExample.js b/examples/localVoxelsExample.js index dd192d4c82..bc7c555921 100644 --- a/examples/localVoxelsExample.js +++ b/examples/localVoxelsExample.js @@ -1,7 +1,18 @@ +var TREE_SCALE = 16384; var tree = LocalVoxels("tree"); -tree.setVoxel(0, 0, 0, 0.5, 255, 0, 0); -tree.setVoxel(0.5, 0.5, 0.5, 0.5, 0, 255, 0); +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}, @@ -21,7 +32,13 @@ var overlay3 = Overlays.addOverlay("localvoxels", { var overlay4 = Overlays.addOverlay("localvoxels", { position: {x: 1, y: 4, z: 1}, size: 1, - name: "tree" + name: "copy" + }); + +var clipboard = Overlays.addOverlay("localvoxels", { + position: {x: 1, y: 5, z: 1}, + size: 1, + name: "clipboard" }); @@ -31,5 +48,6 @@ function scriptEnding() { 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/libraries/script-engine/src/LocalVoxels.cpp b/libraries/script-engine/src/LocalVoxels.cpp index 091cdbe5a9..3567b6a0db 100644 --- a/libraries/script-engine/src/LocalVoxels.cpp +++ b/libraries/script-engine/src/LocalVoxels.cpp @@ -54,7 +54,11 @@ void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale, } if (_tree ) { if (_tree->tryLockForWrite()) { - _tree->createVoxel(x, y, z, scale, red, green, blue, false); + _tree->createVoxel(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE, + red, green, blue, false); _tree->unlock(); } } @@ -68,7 +72,11 @@ void LocalVoxels::setVoxel(float x, float y, float z, float scale, } if (_tree ) { if (_tree->tryLockForWrite()) { - _tree->createVoxel(x, y, z, scale, red, green, blue, true); + _tree->createVoxel(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE, + red, green, blue, true); _tree->unlock(); } } @@ -81,7 +89,10 @@ void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) { } if (_tree ) { if (_tree->tryLockForWrite()) { - _tree->deleteVoxelAt(x, y, z, scale); + _tree->deleteVoxelAt(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE); _tree->unlock(); } } @@ -93,7 +104,10 @@ void LocalVoxels::copyTo(float x, float y, float z, float scale, const QString d return; } StrongVoxelTreePointer destinationTree = LocalVoxelsList::getInstance()->getTree(destination); - VoxelTreeElement* destinationNode = destinationTree->getVoxelAt(x, y, z, scale); + 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); } @@ -103,7 +117,10 @@ void LocalVoxels::pasteFrom(float x, float y, float z, float scale, const QStrin return; } StrongVoxelTreePointer sourceTree = LocalVoxelsList::getInstance()->getTree(source); - VoxelTreeElement* sourceNode = _tree->getVoxelAt(x, y, z, scale); + 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); } From bb3c8f2a7a7286fdb7c4d8a5c033cf8e3a420605 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 3 Mar 2014 17:54:58 -0800 Subject: [PATCH 19/31] Removed ClipboardOverlay --- interface/src/ui/ClipboardOverlay.cpp | 50 --------------------------- interface/src/ui/ClipboardOverlay.h | 25 -------------- interface/src/ui/Overlays.cpp | 7 ---- 3 files changed, 82 deletions(-) delete mode 100644 interface/src/ui/ClipboardOverlay.cpp delete mode 100644 interface/src/ui/ClipboardOverlay.h 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/Overlays.cpp b/interface/src/ui/Overlays.cpp index a57970b797..684ba88e35 100644 --- a/interface/src/ui/Overlays.cpp +++ b/interface/src/ui/Overlays.cpp @@ -12,7 +12,6 @@ #include "Overlays.h" #include "Sphere3DOverlay.h" #include "TextOverlay.h" -#include "ClipboardOverlay.h" #include "LocalVoxelsOverlay.h" Overlays::Overlays() : _nextOverlayID(1) { @@ -95,12 +94,6 @@ unsigned int Overlays::addOverlay(const QString& type, const QScriptValue& prope thisOverlay->setProperties(properties); created = true; is3D = true; - } else if (type == "clipboard") { - thisOverlay = new ClipboardOverlay(); - thisOverlay->init(_parent); - thisOverlay->setProperties(properties); - created = true; - is3D = true; } else if (type == "localvoxels") { thisOverlay = new LocalVoxelsOverlay(); thisOverlay->init(_parent); From de679b20ad0f288a74456c534e6d1e6b0309cb05 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 3 Mar 2014 18:48:11 -0800 Subject: [PATCH 20/31] Removed deadlock from merge --- examples/localVoxelsExample.js | 1 + libraries/script-engine/src/LocalVoxels.cpp | 58 ++++++++------------- 2 files changed, 24 insertions(+), 35 deletions(-) diff --git a/examples/localVoxelsExample.js b/examples/localVoxelsExample.js index bc7c555921..7d9007f590 100644 --- a/examples/localVoxelsExample.js +++ b/examples/localVoxelsExample.js @@ -42,6 +42,7 @@ var clipboard = Overlays.addOverlay("localvoxels", { }); + // When our script shuts down, we should clean up all of our overlays function scriptEnding() { Overlays.deleteOverlay(overlay1); diff --git a/libraries/script-engine/src/LocalVoxels.cpp b/libraries/script-engine/src/LocalVoxels.cpp index 3567b6a0db..075dfb9e9a 100644 --- a/libraries/script-engine/src/LocalVoxels.cpp +++ b/libraries/script-engine/src/LocalVoxels.cpp @@ -53,14 +53,11 @@ void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale, return; } if (_tree ) { - if (_tree->tryLockForWrite()) { - _tree->createVoxel(x / (float)TREE_SCALE, - y / (float)TREE_SCALE, - z / (float)TREE_SCALE, - scale / (float)TREE_SCALE, - red, green, blue, false); - _tree->unlock(); - } + _tree->createVoxel(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE, + red, green, blue, false); } } @@ -71,14 +68,11 @@ void LocalVoxels::setVoxel(float x, float y, float z, float scale, return; } if (_tree ) { - if (_tree->tryLockForWrite()) { - _tree->createVoxel(x / (float)TREE_SCALE, - y / (float)TREE_SCALE, - z / (float)TREE_SCALE, - scale / (float)TREE_SCALE, - red, green, blue, true); - _tree->unlock(); - } + _tree->createVoxel(x / (float)TREE_SCALE, + y / (float)TREE_SCALE, + z / (float)TREE_SCALE, + scale / (float)TREE_SCALE, + red, green, blue, true); } } @@ -88,13 +82,10 @@ void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) { return; } if (_tree ) { - if (_tree->tryLockForWrite()) { - _tree->deleteVoxelAt(x / (float)TREE_SCALE, + _tree->deleteVoxelAt(x / (float)TREE_SCALE, y / (float)TREE_SCALE, z / (float)TREE_SCALE, scale / (float)TREE_SCALE); - _tree->unlock(); - } } } @@ -127,21 +118,18 @@ void LocalVoxels::pasteFrom(float x, float y, float z, float scale, const QStrin RayToVoxelIntersectionResult LocalVoxels::findRayIntersection(const PickRay& ray) { RayToVoxelIntersectionResult result; if (_tree) { - if (_tree->tryLockForRead()) { - 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); - } - _tree->unlock(); + 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; From 028b816e5bf4b3ed6c190bcd6b27a23735cd5708 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 3 Mar 2014 22:17:55 -0800 Subject: [PATCH 21/31] smaller damage --- examples/gun.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/gun.js b/examples/gun.js index 17587e3810..b50a8f64d8 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); From f5aaad1f33626a0204170c68675cdebe1b2662bf Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Mar 2014 10:05:43 -0800 Subject: [PATCH 22/31] remove if checks in cases where delete handles null --- interface/src/renderer/TextureCache.cpp | 11 ++++------- libraries/shared/src/Node.cpp | 5 +---- svo-viewer/src/Render2.cpp | 5 ++++- 3 files changed, 9 insertions(+), 12 deletions(-) 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/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/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; From 66b05905097f1dca7d15f30d20187094c783428b Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 4 Mar 2014 10:48:53 -0800 Subject: [PATCH 23/31] Review fixes --- interface/src/ClipboardScriptingInterface.cpp | 2 -- interface/src/ui/LocalVoxelsOverlay.cpp | 1 - interface/src/ui/Overlay.cpp | 1 - interface/src/ui/Overlay.h | 3 --- interface/src/ui/Overlays.cpp | 7 +------ 5 files changed, 1 insertion(+), 13 deletions(-) diff --git a/interface/src/ClipboardScriptingInterface.cpp b/interface/src/ClipboardScriptingInterface.cpp index c99c55db4d..d9a8f04d90 100644 --- a/interface/src/ClipboardScriptingInterface.cpp +++ b/interface/src/ClipboardScriptingInterface.cpp @@ -5,8 +5,6 @@ // Copyright (c) 2014 High Fidelity, Inc. All rights reserved. // -#include - #include "Application.h" #include "ClipboardScriptingInterface.h" diff --git a/interface/src/ui/LocalVoxelsOverlay.cpp b/interface/src/ui/LocalVoxelsOverlay.cpp index b14db72d99..01a885dedc 100644 --- a/interface/src/ui/LocalVoxelsOverlay.cpp +++ b/interface/src/ui/LocalVoxelsOverlay.cpp @@ -23,7 +23,6 @@ LocalVoxelsOverlay::LocalVoxelsOverlay() : Volume3DOverlay(), _voxelCount(0) { - _wantDeleteOnRenderThread = true; } LocalVoxelsOverlay::~LocalVoxelsOverlay() { diff --git a/interface/src/ui/Overlay.cpp b/interface/src/ui/Overlay.cpp index 61c0ee36c0..40da2253f4 100644 --- a/interface/src/ui/Overlay.cpp +++ b/interface/src/ui/Overlay.cpp @@ -18,7 +18,6 @@ Overlay::Overlay() : _parent(NULL), - _wantDeleteOnRenderThread(false), _alpha(DEFAULT_ALPHA), _color(DEFAULT_BACKGROUND_COLOR), _visible(true) diff --git a/interface/src/ui/Overlay.h b/interface/src/ui/Overlay.h index 95d4bf7541..ad1084e889 100644 --- a/interface/src/ui/Overlay.h +++ b/interface/src/ui/Overlay.h @@ -32,7 +32,6 @@ public: virtual void render() = 0; // getters - bool deleteOnRenderThread() { return _wantDeleteOnRenderThread; } bool getVisible() const { return _visible; } const xColor& getColor() const { return _color; } float getAlpha() const { return _alpha; } @@ -46,8 +45,6 @@ public: protected: QGLWidget* _parent; - bool _wantDeleteOnRenderThread; - float _alpha; xColor _color; bool _visible; // should the overlay be drawn at all diff --git a/interface/src/ui/Overlays.cpp b/interface/src/ui/Overlays.cpp index 684ba88e35..0c9415fa73 100644 --- a/interface/src/ui/Overlays.cpp +++ b/interface/src/ui/Overlays.cpp @@ -141,12 +141,7 @@ void Overlays::deleteOverlay(unsigned int id) { return; } - if (overlayToDelete->deleteOnRenderThread()) { - _overlaysToDelete.push_back(overlayToDelete); - } else { - delete overlayToDelete; - } - + _overlaysToDelete.push_back(overlayToDelete); } unsigned int Overlays::getOverlayAtPoint(const glm::vec2& point) { From 9767846c91145dc152fd6242ab56181964b82874 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 4 Mar 2014 11:06:23 -0800 Subject: [PATCH 24/31] fix for windows --- interface/src/Application.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 29833a9ddb..75c1d9afd6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -403,6 +403,12 @@ void Application::initializeGL() { #endif #ifdef WIN32 + static bool isInitialized = false; + if (isInitialized) { + return; + } else { + isInitialized = true; + } GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ From 6ff629dcfd5557f364a577527b674cc8e48a46cd Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 4 Mar 2014 11:23:44 -0800 Subject: [PATCH 25/31] Use different unused variable warning suppressor for GCC. --- libraries/metavoxels/src/Bitstream.h | 7 +++++++ 1 file changed, 7 insertions(+) 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) \ From 231dc624ff23e9f75d7c227795fabd8e8698bde4 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Mar 2014 12:41:24 -0800 Subject: [PATCH 26/31] replace deprecated qt5 macros in cmake with target_link_libraries --- assignment-client/CMakeLists.txt | 8 +++----- domain-server/CMakeLists.txt | 6 +++--- interface/CMakeLists.txt | 14 +++----------- libraries/avatars/CMakeLists.txt | 4 ++-- libraries/embedded-webserver/CMakeLists.txt | 2 +- libraries/metavoxels/CMakeLists.txt | 7 +++---- libraries/octree/CMakeLists.txt | 5 ++--- libraries/particles/CMakeLists.txt | 5 ++--- libraries/script-engine/CMakeLists.txt | 5 ++--- libraries/shared/CMakeLists.txt | 7 +++---- libraries/voxels/CMakeLists.txt | 8 +++----- svo-viewer/CMakeLists.txt | 16 ++++------------ tests/metavoxels/CMakeLists.txt | 8 +++----- voxel-edit/CMakeLists.txt | 7 ++++--- 14 files changed, 38 insertions(+), 64 deletions(-) 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/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/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/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/particles/CMakeLists.txt b/libraries/particles/CMakeLists.txt index f7d0088c1b..f83e76cf61 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::Particles) 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/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/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/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/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 From a48185053ee611d204caeafab506c34e86aeafc7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Mar 2014 12:42:08 -0800 Subject: [PATCH 27/31] repair a typo in particles link to widgets lib --- libraries/particles/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/particles/CMakeLists.txt b/libraries/particles/CMakeLists.txt index f83e76cf61..8f475647bd 100644 --- a/libraries/particles/CMakeLists.txt +++ b/libraries/particles/CMakeLists.txt @@ -24,4 +24,4 @@ link_hifi_library(octree ${TARGET_NAME} "${ROOT_DIR}") find_package(ZLIB) include_directories("${ZLIB_INCLUDE_DIRS}") -target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Particles) +target_link_libraries(${TARGET_NAME} "${ZLIB_LIBRARIES}" Qt5::Widgets) From 3c99cf162d0e70bf29ebd299015ef4370921716c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 4 Mar 2014 13:17:19 -0800 Subject: [PATCH 28/31] Fix was at the wrong spot --- interface/src/Application.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 75c1d9afd6..741ec5381a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -398,17 +398,17 @@ void Application::initializeGL() { // initialize glut for shape drawing; Qt apparently initializes it on OS X #ifndef __APPLE__ - int argc = 0; - glutInit(&argc, 0); - #endif - - #ifdef WIN32 static bool isInitialized = false; if (isInitialized) { return; } else { isInitialized = true; } + int argc = 0; + glutInit(&argc, 0); + #endif + + #ifdef WIN32 GLenum err = glewInit(); if (GLEW_OK != err) { /* Problem: glewInit failed, something is seriously wrong. */ From 2c27c6b8c1d6b5ebb4bb072d0d1ae54250e9a8ed Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 4 Mar 2014 15:03:30 -0800 Subject: [PATCH 29/31] adjustable height of bot avatars --- examples/bot.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/bot.js b/examples/bot.js index a3ae7f3263..162dde9dae 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() { if (Math.random() < CHANCE_OF_SOUND) { playRandomSound(Avatar.position); @@ -132,6 +138,7 @@ function updateBehavior() { } 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 { From c90d4a9514be17971344c6872dfe8d6a0c87e09a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Mar 2014 15:07:30 -0800 Subject: [PATCH 30/31] fix failed lock causing particle collisions to not work --- libraries/octree/src/Octree.cpp | 79 ++++++++++++++----- libraries/octree/src/Octree.h | 29 ++++--- .../particles/src/ParticleCollisionSystem.cpp | 4 +- 3 files changed, 79 insertions(+), 33 deletions(-) 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/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. From c031359a5467e98bfaac43c7bbf39ec03cf281bf Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 4 Mar 2014 16:20:17 -0800 Subject: [PATCH 31/31] fix infinite reloading of missing script files --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 98ba3f0dac..c6c6882012 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3479,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(); @@ -3489,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();