From b854c450f4f0cf88f84af6a1ec09ab5d0c973d26 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 28 Feb 2014 11:25:07 -0800 Subject: [PATCH] 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__) */