From 80337d240922a2565f82022782b951723ed075aa Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 25 Feb 2014 16:12:05 -0800 Subject: [PATCH 01/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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/23] 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 f5aaad1f33626a0204170c68675cdebe1b2662bf Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 4 Mar 2014 10:05:43 -0800 Subject: [PATCH 21/23] 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 22/23] 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 23/23] 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. */