diff --git a/CMakeLists.txt b/CMakeLists.txt index d12cf1e45d..2560c6498f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,4 +39,4 @@ add_subdirectory(domain-server) add_subdirectory(interface) add_subdirectory(tests) add_subdirectory(voxel-edit) -add_subdirectory(SvoViewer) +add_subdirectory(svo-viewer) diff --git a/animation-server/src/AnimationServer.cpp b/animation-server/src/AnimationServer.cpp index a2ca454741..a013eaaf5c 100644 --- a/animation-server/src/AnimationServer.cpp +++ b/animation-server/src/AnimationServer.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/editVoxels.js b/examples/editVoxels.js index ed63c12eb9..cfea508912 100644 --- a/examples/editVoxels.js +++ b/examples/editVoxels.js @@ -1277,12 +1277,55 @@ function touchEndEvent(event) { } } +var lastFingerAddVoxel = { x: -1, y: -1, z: -1}; // off of the build-able area +var lastFingerDeleteVoxel = { x: -1, y: -1, z: -1}; // off of the build-able area + +function checkControllers() { + var controllersPerPalm = 2; // palm and finger + for (var palm = 0; palm < 2; palm++) { + var palmController = palm * controllersPerPalm; + var fingerTipController = palmController + 1; + var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController); + + var BUTTON_COUNT = 6; + var BUTTON_BASE = palm * BUTTON_COUNT; + var BUTTON_1 = BUTTON_BASE + 1; + var BUTTON_2 = BUTTON_BASE + 2; + var FINGERTIP_VOXEL_SIZE = 0.05; + + if (Controller.isButtonPressed(BUTTON_1)) { + if (Vec3.length(Vec3.subtract(fingerTipPosition,lastFingerAddVoxel)) > (FINGERTIP_VOXEL_SIZE / 2)) { + if (whichColor == -1) { + newColor = { red: colors[0].red, green: colors[0].green, blue: colors[0].blue }; + } else { + newColor = { red: colors[whichColor].red, green: colors[whichColor].green, blue: colors[whichColor].blue }; + } + + Voxels.eraseVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE); + Voxels.setVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE, + newColor.red, newColor.green, newColor.blue); + + lastFingerAddVoxel = fingerTipPosition; + } + } else if (Controller.isButtonPressed(BUTTON_2)) { + if (Vec3.length(Vec3.subtract(fingerTipPosition,lastFingerDeleteVoxel)) > (FINGERTIP_VOXEL_SIZE / 2)) { + Voxels.eraseVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE); + lastFingerDeleteVoxel = fingerTipPosition; + } + } + } +} + function update() { var newWindowDimensions = Controller.getViewportDimensions(); if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) { windowDimensions = newWindowDimensions; moveTools(); } + + if (editToolsOn) { + checkControllers(); + } } function wheelEvent(event) { diff --git a/examples/voxelDrumming.js b/examples/voxelDrumming.js new file mode 100644 index 0000000000..a2acb05958 --- /dev/null +++ b/examples/voxelDrumming.js @@ -0,0 +1,167 @@ +// +// voxelDrumming.js +// hifi +// +// Created by Brad Hefta-Gaub on 2/14/14. +// Copyright (c) 2014 HighFidelity, Inc. All rights reserved. +// +// This is an example script that demonstrates use of the Overlays, Controller, and Audio classes +// +// It adds Hydra controller "fingertip on voxels" drumming +// + +Menu.addMenuItem({ + menuName: "Developer > Hand Options", + menuItemName: "Voxel Drumming", + isCheckable: true, + isChecked: false + }); + +var collisionCenter = new Array(); +collisionCenter[0] = { x: 0, y: 0, z: 0}; +collisionCenter[1] = { x: 0, y: 0, z: 0}; + +var collisionAge = new Array(); +collisionAge[0] = 0; +collisionAge[1] = 0; + +var collisionDuration = new Array(); +collisionDuration[0] = 0; +collisionDuration[1] = 0; + +var isColliding = new Array(); +isColliding[0] = false; +isColliding[1] = false; + +var highlightVoxel = Overlays.addOverlay("cube", + { + position: { x: 0, y: 0, z: 0}, + size: 0, + color: { red: 0, green: 0, blue: 0 }, + visible: false, + lineWidth: 3, + solid: false + }); + +var collisionBubble = new Array(); +collisionBubble[0] = Overlays.addOverlay("sphere", + { + position: { x: 0, y: 0, z: 0}, + size: 0, + color: { red: 0, green: 0, blue: 0 }, + alpha: 0.5, + visible: false + }); +collisionBubble[1] = Overlays.addOverlay("sphere", + { + position: { x: 0, y: 0, z: 0}, + size: 0, + color: { red: 0, green: 0, blue: 0 }, + alpha: 0.5, + visible: false + }); + +var audioOptions = new AudioInjectionOptions();
 +audioOptions.position = { x: MyAvatar.position.x, y: MyAvatar.position.y + 1, z: MyAvatar.position.z }; +audioOptions.volume = 1; + + +function clamp(valueToClamp, minValue, maxValue) { + return Math.max(minValue, Math.min(maxValue, valueToClamp)); +} + +function produceCollisionSound(palm, voxelDetail) { + // Collision between finger and a voxel plays sound + + var palmVelocity = Controller.getSpatialControlVelocity(palm * 2); + var speed = Vec3.length(palmVelocity); + var fingerTipPosition = Controller.getSpatialControlPosition(palm * 2 + 1); + + var deltaTime = 1/60; //close enough + var LOWEST_FREQUENCY = 100.0; + var HERTZ_PER_RGB = 3.0; + var DECAY_PER_SAMPLE = 0.0005; + var DURATION_MAX = 2.0; + var MIN_VOLUME = 0.1; + var volume = MIN_VOLUME + clamp(speed, 0.0, (1.0 - MIN_VOLUME)); + var duration = volume; + + collisionCenter[palm] = fingerTipPosition; + collisionAge[palm] = deltaTime; + collisionDuration[palm] = duration; + + var voxelBrightness = voxelDetail.red + voxelDetail.green + voxelDetail.blue; + var frequency = LOWEST_FREQUENCY + (voxelBrightness * HERTZ_PER_RGB); + + audioOptions.position = fingerTipPosition; + Audio.startDrumSound(volume, frequency, DURATION_MAX, DECAY_PER_SAMPLE, audioOptions); +} + +function update() { + var deltaTime = 1/60; //close enough + + // Voxel Drumming with fingertips if enabled + if (Menu.isOptionChecked("Voxel Drumming")) { + + for (var palm = 0; palm < 2; palm++) { + var fingerTipPosition = Controller.getSpatialControlPosition(palm * 2 + 1); + + var voxel = Voxels.getVoxelEnclosingPoint(fingerTipPosition); + if (voxel.s > 0) { + if (!isColliding[palm]) { + // Collision has just started + isColliding[palm] = true; + produceCollisionSound(palm, voxel); + + // Set highlight voxel + Overlays.editOverlay(highlightVoxel, + { + position: { x: voxel.x, y: voxel.y, z: voxel.z}, + size: voxel.s + 0.002, + color: { red: voxel.red + 128, green: voxel.green + 128, blue: voxel.blue + 128 }, + visible: true + }); + } + } else { + if (isColliding[palm]) { + // Collision has just ended + isColliding[palm] = false; + Overlays.editOverlay(highlightVoxel, { visible: false }); + } + } + + if (collisionAge[palm] > 0) { + collisionAge[palm] += deltaTime; + } + + // If hand/voxel collision has happened, render a little expanding sphere + if (collisionAge[palm] > 0) { + var opacity = clamp(1 - (collisionAge[palm] / collisionDuration[palm]), 0, 1); + var size = collisionAge[palm] * 0.25; + + Overlays.editOverlay(collisionBubble[palm], + { + position: { x: collisionCenter[palm].x, y: collisionCenter[palm].y, z: collisionCenter[palm].z}, + size: size, + color: { red: 255, green: 0, blue: 0 }, + alpha: 0.5 * opacity, + visible: true + }); + + if (collisionAge[palm] > collisionDuration[palm]) { + collisionAge[palm] = 0; + Overlays.editOverlay(collisionBubble[palm], { visible: false }); + } + } + } // palm loop + } // menu item check +} +Script.willSendVisualDataCallback.connect(update); + +function scriptEnding() { + Overlays.deleteOverlay(highlightVoxel); + Overlays.deleteOverlay(collisionBubble[0]); + Overlays.deleteOverlay(collisionBubble[1]); + Menu.removeMenuItem("Developer > Hand Options","Voxel Drumming"); +} +Script.scriptEnding.connect(scriptEnding); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 97705b9832..f33c7aea32 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -139,8 +139,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _touchAvgY(0.0f), _isTouchPressed(false), _mousePressed(false), - _isHoverVoxel(false), - _isHighlightVoxel(false), _chatEntryOn(false), _audio(&_audioScope, STARTUP_JITTER_SAMPLES), _enableProcessVoxelsThread(true), @@ -742,9 +740,7 @@ void Application::keyPressEvent(QKeyEvent* event) { break; case Qt::Key_S: - if (isShifted && !isMeta) { - _voxels.collectStatsForTreesAndVBOs(); - } else if (isShifted && isMeta) { + if (isShifted && isMeta) { Menu::getInstance()->triggerOption(MenuOption::SuppressShortTimings); } else if (!isShifted && isMeta) { takeSnapshot(); @@ -1031,11 +1027,6 @@ void Application::mousePressEvent(QMouseEvent* event) { return; } - if (!_isHoverVoxel || _myAvatar->getLookAtTargetAvatar()) { - // disable for now - // _pieMenu.mousePressEvent(_mouseX, _mouseY); - } - } else if (event->button() == Qt::RightButton) { // right click items here } @@ -1290,7 +1281,7 @@ void Application::removeVoxel(glm::vec3 position, _voxelEditSender.sendVoxelEditMessage(PacketTypeVoxelErase, voxel); // delete it locally to see the effect immediately (and in case no voxel server is present) - _voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); + _voxels.getTree()->deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); } @@ -1312,8 +1303,7 @@ void Application::makeVoxel(glm::vec3 position, _voxelEditSender.sendVoxelEditMessage(message, voxel); // create the voxel locally so it appears immediately - - _voxels.createVoxel(voxel.x, voxel.y, voxel.z, voxel.s, + _voxels.getTree()->createVoxel(voxel.x, voxel.y, voxel.z, voxel.s, voxel.red, voxel.green, voxel.blue, isDestructive); } @@ -1372,10 +1362,11 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) { tr("Sparse Voxel Octree Files (*.svo)")); QByteArray fileNameAscii = fileNameString.toLocal8Bit(); const char* fileName = fileNameAscii.data(); - VoxelTreeElement* selectedNode = _voxels.getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); + + VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); if (selectedNode) { VoxelTree exportTree; - _voxels.copySubTreeIntoNewTree(selectedNode, &exportTree, true); + getVoxelTree()->copySubTreeIntoNewTree(selectedNode, &exportTree, true); exportTree.writeToSVOFile(fileName); } @@ -1417,9 +1408,10 @@ void Application::copyVoxels(const VoxelDetail& sourceVoxel) { } // then copy onto it if there is something to copy - VoxelTreeElement* selectedNode = _voxels.getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); + VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); if (selectedNode) { - _voxels.copySubTreeIntoNewTree(selectedNode, &_sharedVoxelSystem, true); + getVoxelTree()->copySubTreeIntoNewTree(selectedNode, _sharedVoxelSystem.getTree(), true); + _sharedVoxelSystem.forceRedrawEntireTree(); } } @@ -1440,7 +1432,7 @@ void Application::pasteVoxelsToOctalCode(const unsigned char* octalCodeDestinati void Application::pasteVoxels(const VoxelDetail& sourceVoxel) { unsigned char* calculatedOctCode = NULL; - VoxelTreeElement* selectedNode = _voxels.getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); + VoxelTreeElement* selectedNode = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); // we only need the selected voxel to get the newBaseOctCode, which we can actually calculate from the // voxel size/position details. If we don't have an actual selectedNode then use the mouseVoxel to create a @@ -1460,7 +1452,7 @@ void Application::pasteVoxels(const VoxelDetail& sourceVoxel) { } void Application::nudgeVoxelsByVector(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec) { - VoxelTreeElement* nodeToNudge = _voxels.getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); + VoxelTreeElement* nodeToNudge = _voxels.getTree()->getVoxelAt(sourceVoxel.x, sourceVoxel.y, sourceVoxel.z, sourceVoxel.s); if (nodeToNudge) { _voxels.getTree()->nudgeSubTree(nodeToNudge, nudgeVec, _voxelEditSender); } @@ -1618,20 +1610,6 @@ bool Application::isLookingAtMyAvatar(Avatar* avatar) { return false; } -void Application::renderHighlightVoxel(VoxelDetail voxel) { - glDisable(GL_LIGHTING); - glPushMatrix(); - glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE); - const float EDGE_EXPAND = 1.02f; - glColor3ub(voxel.red + 128, voxel.green + 128, voxel.blue + 128); - glTranslatef(voxel.x + voxel.s * 0.5f, - voxel.y + voxel.s * 0.5f, - voxel.z + voxel.s * 0.5f); - glLineWidth(2.0f); - glutWireCube(voxel.s * EDGE_EXPAND); - glPopMatrix(); -} - void Application::updateMouseRay() { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); @@ -1702,9 +1680,6 @@ void Application::updateMyAvatarLookAtPosition() { if (_myAvatar->getLookAtTargetAvatar()) { distance = glm::distance(_mouseRayOrigin, static_cast(_myAvatar->getLookAtTargetAvatar())->getHead()->calculateAverageEyePosition()); - - } else if (_isHoverVoxel) { - distance = glm::distance(_mouseRayOrigin, getMouseVoxelWorldCoordinates(_hoverVoxel)); } const float FIXED_MIN_EYE_DISTANCE = 0.3f; float minEyeDistance = FIXED_MIN_EYE_DISTANCE + (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON ? 0.0f : @@ -1735,17 +1710,6 @@ void Application::updateMyAvatarLookAtPosition() { _myAvatar->getHead()->setLookAtPosition(lookAtSpot); } -void Application::updateHoverVoxels(float deltaTime, float& distance, BoxFace& face) { - - bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); - PerformanceWarning warn(showWarnings, "Application::updateHoverVoxels()"); - - if (!_mousePressed) { - PerformanceWarning warn(showWarnings, "Application::updateHoverVoxels() _voxels.findRayIntersection()"); - _isHoverVoxel = _voxels.findRayIntersection(_mouseRayOrigin, _mouseRayDirection, _hoverVoxel, distance, face); - } -} - void Application::updateHandAndTouch(float deltaTime) { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::updateHandAndTouch()"); @@ -1894,11 +1858,6 @@ void Application::update(float deltaTime) { _myAvatar->updateLookAtTargetAvatar(); updateMyAvatarLookAtPosition(); - // Find the voxel we are hovering over, and respond if clicked - float distance; - BoxFace face; - - updateHoverVoxels(deltaTime, distance, face); // clicking on voxels and making sounds updateHandAndTouch(deltaTime); // Update state for touch sensors updateLeap(deltaTime); // Leap finger-sensing device updateSixense(deltaTime); // Razer Hydra controllers @@ -2403,11 +2362,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { // restore default, white specular glMaterialfv(GL_FRONT, GL_SPECULAR, WHITE_SPECULAR_COLOR); - - // Render the highlighted voxel - if (_isHighlightVoxel) { - renderHighlightVoxel(_highlightVoxel); - } } bool forceRenderMyHead = (whichCamera.getInterpolatedMode() == CAMERA_MODE_MIRROR); @@ -2518,15 +2472,6 @@ void Application::displayOverlay() { } } - // testing rendering coverage map - if (Menu::getInstance()->isOptionChecked(MenuOption::CoverageMapV2)) { - renderCoverageMapV2(); - } - - if (Menu::getInstance()->isOptionChecked(MenuOption::CoverageMap)) { - renderCoverageMap(); - } - // Show chat entry field if (_chatEntryOn) { _chatEntry.render(_glWidget->width(), _glWidget->height()); @@ -2968,115 +2913,6 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { return screenPoint; } -// render the coverage map on screen -void Application::renderCoverageMapV2() { - glDisable(GL_LIGHTING); - glLineWidth(2.0); - glBegin(GL_LINES); - glColor3f(0,1,1); - - renderCoverageMapsV2Recursively(&_voxels.myCoverageMapV2); - - glEnd(); - glEnable(GL_LIGHTING); -} - -void Application::renderCoverageMapsV2Recursively(CoverageMapV2* map) { - // render ourselves... - if (map->isCovered()) { - BoundingBox box = map->getBoundingBox(); - - glm::vec2 firstPoint = getScaledScreenPoint(box.getVertex(0)); - glm::vec2 lastPoint(firstPoint); - - for (int i = 1; i < box.getVertexCount(); i++) { - glm::vec2 thisPoint = getScaledScreenPoint(box.getVertex(i)); - - glVertex2f(lastPoint.x, lastPoint.y); - glVertex2f(thisPoint.x, thisPoint.y); - lastPoint = thisPoint; - } - - glVertex2f(lastPoint.x, lastPoint.y); - glVertex2f(firstPoint.x, firstPoint.y); - } else { - // iterate our children and call render on them. - for (int i = 0; i < CoverageMapV2::NUMBER_OF_CHILDREN; i++) { - CoverageMapV2* childMap = map->getChild(i); - if (childMap) { - renderCoverageMapsV2Recursively(childMap); - } - } - } -} - -// render the coverage map on screen -void Application::renderCoverageMap() { - - glDisable(GL_LIGHTING); - glLineWidth(2.0); - glBegin(GL_LINES); - glColor3f(0,0,1); - - renderCoverageMapsRecursively(&_voxels.myCoverageMap); - - glEnd(); - glEnable(GL_LIGHTING); -} - -void Application::renderCoverageMapsRecursively(CoverageMap* map) { - for (int i = 0; i < map->getPolygonCount(); i++) { - - OctreeProjectedPolygon* polygon = map->getPolygon(i); - - if (polygon->getProjectionType() == (PROJECTION_RIGHT | PROJECTION_NEAR | PROJECTION_BOTTOM)) { - glColor3f(.5,0,0); // dark red - } else if (polygon->getProjectionType() == (PROJECTION_NEAR | PROJECTION_RIGHT)) { - glColor3f(.5,.5,0); // dark yellow - } else if (polygon->getProjectionType() == (PROJECTION_NEAR | PROJECTION_LEFT)) { - glColor3f(.5,.5,.5); // gray - } else if (polygon->getProjectionType() == (PROJECTION_NEAR | PROJECTION_LEFT | PROJECTION_BOTTOM)) { - glColor3f(.5,0,.5); // dark magenta - } else if (polygon->getProjectionType() == (PROJECTION_NEAR | PROJECTION_BOTTOM)) { - glColor3f(.75,0,0); // red - } else if (polygon->getProjectionType() == (PROJECTION_NEAR | PROJECTION_TOP)) { - glColor3f(1,0,1); // magenta - } else if (polygon->getProjectionType() == (PROJECTION_NEAR | PROJECTION_LEFT | PROJECTION_TOP)) { - glColor3f(0,0,1); // Blue - } else if (polygon->getProjectionType() == (PROJECTION_NEAR | PROJECTION_RIGHT | PROJECTION_TOP)) { - glColor3f(0,1,0); // green - } else if (polygon->getProjectionType() == (PROJECTION_NEAR)) { - glColor3f(1,1,0); // yellow - } else if (polygon->getProjectionType() == (PROJECTION_FAR | PROJECTION_RIGHT | PROJECTION_BOTTOM)) { - glColor3f(0,.5,.5); // dark cyan - } else { - glColor3f(1,0,0); - } - - glm::vec2 firstPoint = getScaledScreenPoint(polygon->getVertex(0)); - glm::vec2 lastPoint(firstPoint); - - for (int i = 1; i < polygon->getVertexCount(); i++) { - glm::vec2 thisPoint = getScaledScreenPoint(polygon->getVertex(i)); - - glVertex2f(lastPoint.x, lastPoint.y); - glVertex2f(thisPoint.x, thisPoint.y); - lastPoint = thisPoint; - } - - glVertex2f(lastPoint.x, lastPoint.y); - glVertex2f(firstPoint.x, firstPoint.y); - } - - // iterate our children and call render on them. - for (int i = 0; i < CoverageMapV2::NUMBER_OF_CHILDREN; i++) { - CoverageMap* childMap = map->getChild(i); - if (childMap) { - renderCoverageMapsRecursively(childMap); - } - } -} - void Application::renderRearViewMirror(const QRect& region, bool billboard) { bool eyeRelativeCamera = false; if (billboard) { @@ -3326,7 +3162,7 @@ void Application::deleteVoxelAt(const VoxelDetail& voxel) { _voxelEditSender.sendVoxelEditMessage(PacketTypeVoxelErase, voxel); // delete it locally to see the effect immediately (and in case no voxel server is present) - _voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); + _voxels.getTree()->deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); } } diff --git a/interface/src/Application.h b/interface/src/Application.h index 4e91876dfb..78826b4fd0 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -34,12 +34,15 @@ #include "BandwidthMeter.h" #include "BuckyBalls.h" #include "Camera.h" +#include "ControllerScriptingInterface.h" #include "DatagramProcessor.h" #include "Environment.h" +#include "FileLogger.h" #include "GLCanvas.h" #include "Menu.h" #include "MetavoxelSystem.h" #include "PacketHeaders.h" +#include "ParticleTreeRenderer.h" #include "PieMenu.h" #include "Stars.h" #include "ViewFrustum.h" @@ -68,9 +71,6 @@ #include "ui/LodToolsDialog.h" #include "ui/LogDialog.h" #include "ui/UpdateDialog.h" -#include "FileLogger.h" -#include "ParticleTreeRenderer.h" -#include "ControllerScriptingInterface.h" #include "ui/Overlays.h" @@ -154,6 +154,7 @@ public: Camera* getCamera() { return &_myCamera; } ViewFrustum* getViewFrustum() { return &_viewFrustum; } VoxelSystem* getVoxels() { return &_voxels; } + VoxelTree* getVoxelTree() { return _voxels.getTree(); } ParticleTreeRenderer* getParticles() { return &_particles; } MetavoxelSystem* getMetavoxels() { return &_metavoxels; } VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; } @@ -214,10 +215,6 @@ public: NodeToJurisdictionMap& getParticleServerJurisdictions() { return _particleServerJurisdictions; } void pasteVoxelsToOctalCode(const unsigned char* octalCodeDestination); - /// set a voxel which is to be rendered with a highlight - void setHighlightVoxel(const VoxelDetail& highlightVoxel) { _highlightVoxel = highlightVoxel; } - void setIsHighlightVoxel(bool isHighlightVoxel) { _isHighlightVoxel = isHighlightVoxel; } - void skipVersion(QString latestVersion); signals: @@ -261,12 +258,6 @@ private slots: void setEnable3DTVMode(bool enable3DTVMode); void cameraMenuChanged(); - void renderCoverageMap(); - void renderCoverageMapsRecursively(CoverageMap* map); - - void renderCoverageMapV2(); - void renderCoverageMapsV2Recursively(CoverageMapV2* map); - glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint); void closeMirrorView(); @@ -297,7 +288,6 @@ private: void updateFaceshift(); void updateVisage(); void updateMyAvatarLookAtPosition(); - void updateHoverVoxels(float deltaTime, float& distance, BoxFace& face); void updateHandAndTouch(float deltaTime); void updateLeap(float deltaTime); void updateSixense(float deltaTime); @@ -313,7 +303,6 @@ private: bool isLookingAtMyAvatar(Avatar* avatar); void renderLookatIndicator(glm::vec3 pointOfInterest); - void renderHighlightVoxel(VoxelDetail voxel); void updateMyAvatar(float deltaTime); void queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions); @@ -434,12 +423,6 @@ private: bool _mousePressed; // true if mouse has been pressed (clear when finished) - VoxelDetail _hoverVoxel; // Stuff about the voxel I am hovering or clicking - bool _isHoverVoxel; - - VoxelDetail _highlightVoxel; - bool _isHighlightVoxel; - ChatEntry _chatEntry; // chat entry field bool _chatEntryOn; // Whether to show the chat entry diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 4d19acf248..dc87cefb05 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -272,7 +272,6 @@ Menu::Menu() : SLOT(setFilter(bool))); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHands, 0, true); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHandTargets, 0, false); - addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::VoxelDrumming, 0, false); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::PlaySlaps, 0, false); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::HandsCollideWithSelf, 0, false); @@ -282,11 +281,6 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::TestPing, 0, true); addCheckableActionToQMenuAndActionHash(timingMenu, MenuOption::FrameTimer); addActionToQMenuAndActionHash(timingMenu, MenuOption::RunTimingTests, 0, this, SLOT(runTests())); - addActionToQMenuAndActionHash(timingMenu, - MenuOption::TreeStats, - Qt::SHIFT | Qt::Key_S, - appInstance->getVoxels(), - SLOT(collectStatsForTreesAndVBOs())); QMenu* frustumMenu = developerMenu->addMenu("View Frustum Debugging Tools"); addCheckableActionToQMenuAndActionHash(frustumMenu, MenuOption::DisplayFrustum, Qt::SHIFT | Qt::Key_F); @@ -302,62 +296,6 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(renderDebugMenu, MenuOption::PipelineWarnings, Qt::CTRL | Qt::SHIFT | Qt::Key_P); addCheckableActionToQMenuAndActionHash(renderDebugMenu, MenuOption::SuppressShortTimings, Qt::CTRL | Qt::SHIFT | Qt::Key_S); - addCheckableActionToQMenuAndActionHash(renderDebugMenu, MenuOption::AutomaticallyAuditTree); - - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::ShowAllLocalVoxels, - Qt::CTRL | Qt::Key_A, - appInstance->getVoxels(), - SLOT(showAllLocalVoxels())); - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::KillLocalVoxels, - Qt::CTRL | Qt::Key_K, - appInstance, SLOT(doKillLocalVoxels())); - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::RandomizeVoxelColors, - Qt::CTRL | Qt::Key_R, - appInstance->getVoxels(), - SLOT(randomizeVoxelColors())); - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::FalseColorRandomly, - 0, - appInstance->getVoxels(), - SLOT(falseColorizeRandom())); - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::FalseColorEveryOtherVoxel, - 0, - appInstance->getVoxels(), - SLOT(falseColorizeRandomEveryOther())); - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::FalseColorByDistance, - 0, - appInstance->getVoxels(), - SLOT(falseColorizeDistanceFromView())); - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::FalseColorOutOfView, - 0, - appInstance->getVoxels(), - SLOT(falseColorizeInView())); - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::FalseColorBySource, - 0, - appInstance->getVoxels(), - SLOT(falseColorizeBySource())); - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::ShowTrueColors, - Qt::CTRL | Qt::Key_T, - appInstance->getVoxels(), - SLOT(trueColorize())); - addCheckableActionToQMenuAndActionHash(renderDebugMenu, MenuOption::CullSharedFaces, Qt::CTRL | Qt::SHIFT | Qt::Key_C, @@ -372,22 +310,6 @@ Menu::Menu() : appInstance->getVoxels(), SLOT(showCulledSharedFaces())); - addDisabledActionAndSeparator(renderDebugMenu, "Coverage Maps"); - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::FalseColorOccluded, - 0, - appInstance->getVoxels(), - SLOT(falseColorizeOccluded())); - - addActionToQMenuAndActionHash(renderDebugMenu, - MenuOption::FalseColorOccludedV2, - 0, - appInstance->getVoxels(), - SLOT(falseColorizeOccludedV2())); - - addCheckableActionToQMenuAndActionHash(renderDebugMenu, MenuOption::CoverageMap, Qt::SHIFT | Qt::CTRL | Qt::Key_O); - addCheckableActionToQMenuAndActionHash(renderDebugMenu, MenuOption::CoverageMapV2, Qt::SHIFT | Qt::CTRL | Qt::Key_P); - QMenu* audioDebugMenu = developerMenu->addMenu("Audio Debugging Tools"); addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioNoiseReduction, 0, @@ -654,7 +576,11 @@ void Menu::setIsOptionChecked(const QString& menuOption, bool isChecked) { } bool Menu::isOptionChecked(const QString& menuOption) { - return _actionHash.value(menuOption)->isChecked(); + QAction* menu = _actionHash.value(menuOption); + if (menu) { + return menu->isChecked(); + } + return false; } void Menu::triggerOption(const QString& menuOption) { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 3d8aa24cbd..7b4cca3b33 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -203,7 +203,6 @@ namespace MenuOption { const QString Avatars = "Avatars"; const QString Atmosphere = "Atmosphere"; const QString DisableAutoAdjustLOD = "Disable Automatically Adjusting LOD"; - const QString AutomaticallyAuditTree = "Automatically Audit Tree Stats"; const QString Bandwidth = "Bandwidth Display"; const QString BandwidthDetails = "Bandwidth Details"; const QString BuckyBalls = "Bucky Balls"; @@ -213,8 +212,6 @@ namespace MenuOption { const QString CollideWithParticles = "Collide With Particles"; const QString CollideWithVoxels = "Collide With Voxels"; const QString CollideWithEnvironment = "Collide With World Boundaries"; - const QString CoverageMap = "Render Coverage Map"; - const QString CoverageMapV2 = "Render Coverage Map V2"; const QString CullSharedFaces = "Cull Shared Voxel Faces"; const QString DecreaseAvatarSize = "Decrease Avatar Size"; const QString DecreaseVoxelSize = "Decrease Voxel Size"; @@ -231,13 +228,6 @@ namespace MenuOption { const QString HeadMouse = "Head Mouse"; const QString HandsCollideWithSelf = "Collide With Self"; const QString FaceshiftTCP = "Faceshift (TCP)"; - const QString FalseColorByDistance = "FALSE Color By Distance"; - const QString FalseColorBySource = "FALSE Color By Source"; - const QString FalseColorEveryOtherVoxel = "FALSE Color Every Other Randomly"; - const QString FalseColorOccluded = "FALSE Color Occluded Voxels"; - const QString FalseColorOccludedV2 = "FALSE Color Occluded V2 Voxels"; - const QString FalseColorOutOfView = "FALSE Color Voxel Out of View"; - const QString FalseColorRandomly = "FALSE Color Voxels Randomly"; const QString FirstPerson = "First Person"; const QString FrameTimer = "Show Timer"; const QString FrustumRenderMode = "Render Mode"; @@ -249,7 +239,6 @@ namespace MenuOption { const QString GoTo = "Go To..."; const QString IncreaseAvatarSize = "Increase Avatar Size"; const QString IncreaseVoxelSize = "Increase Voxel Size"; - const QString KillLocalVoxels = "Kill Local Voxels"; const QString GoHome = "Go Home"; const QString Gravity = "Use Gravity"; const QString LodTools = "LOD Tools"; @@ -274,7 +263,6 @@ namespace MenuOption { const QString PipelineWarnings = "Show Render Pipeline Warnings"; const QString PlaySlaps = "Play Slaps"; const QString Preferences = "Preferences..."; - const QString RandomizeVoxelColors = "Randomize Voxel TRUE Colors"; const QString ReloadAllScripts = "Reload All Scripts"; const QString RenderSkeletonCollisionProxies = "Skeleton Collision Proxies"; const QString RenderHeadCollisionProxies = "Head Collision Proxies"; @@ -283,19 +271,15 @@ namespace MenuOption { const QString SettingsImport = "Import Settings"; const QString Shadows = "Shadows"; const QString SettingsExport = "Export Settings"; - const QString ShowAllLocalVoxels = "Show All Local Voxels"; const QString ShowCulledSharedFaces = "Show Culled Shared Voxel Faces"; - const QString ShowTrueColors = "Show TRUE Colors"; const QString SuppressShortTimings = "Suppress Timings Less than 10ms"; const QString Stars = "Stars"; const QString Stats = "Stats"; const QString StopAllScripts = "Stop All Scripts"; const QString TestPing = "Test Ping"; - const QString TreeStats = "Calculate Tree Stats"; const QString TransmitterDrive = "Transmitter Drive"; const QString Quit = "Quit"; const QString Voxels = "Voxels"; - const QString VoxelDrumming = "Voxel Drumming"; const QString VoxelMode = "Cycle Voxel Mode"; const QString VoxelStats = "Voxel Stats"; const QString VoxelTextures = "Voxel Textures"; diff --git a/interface/src/VoxelImporter.cpp b/interface/src/VoxelImporter.cpp index 3949ee96d2..2daafedcbb 100644 --- a/interface/src/VoxelImporter.cpp +++ b/interface/src/VoxelImporter.cpp @@ -143,11 +143,11 @@ void ImportTask::run() { // Then we call the righ method for the job if (_filename.endsWith(".png", Qt::CaseInsensitive)) { - voxelSystem->readFromSquareARGB32Pixels(_filename.toLocal8Bit().data()); + voxelSystem->getTree()->readFromSquareARGB32Pixels(_filename.toLocal8Bit().data()); } else if (_filename.endsWith(".svo", Qt::CaseInsensitive)) { - voxelSystem->readFromSVOFile(_filename.toLocal8Bit().data()); + voxelSystem->getTree()->readFromSVOFile(_filename.toLocal8Bit().data()); } else if (_filename.endsWith(".schematic", Qt::CaseInsensitive)) { - voxelSystem->readFromSchematicFile(_filename.toLocal8Bit().data()); + voxelSystem->getTree()->readFromSchematicFile(_filename.toLocal8Bit().data()); } else { // We should never get here. qDebug() << "[ERROR] Invalid file extension." << endl; diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 24d1e73ee2..e60165647f 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -18,8 +18,6 @@ #include #include "Application.h" -#include "CoverageMap.h" -#include "CoverageMapV2.h" #include "InterfaceConfig.h" #include "Menu.h" #include "renderer/ProgramObject.h" @@ -84,9 +82,6 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) _viewFrustum = Application::getInstance()->getViewFrustum(); - connect(_tree, SIGNAL(importSize(float,float,float)), SIGNAL(importSize(float,float,float))); - connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int))); - _useVoxelShader = false; _voxelsAsPoints = false; _voxelShaderModeWhenVoxelsAsPointsEnabled = false; @@ -206,31 +201,16 @@ void VoxelSystem::freeBufferIndex(glBufferIndex index) { qDebug() << "freeBufferIndex() called when _voxelsInWriteArrays == 0!"; } - // if the "freed" index was our max index, then just drop the _voxelsInWriteArrays down one... - bool inList = false; + // make the index available for next node that needs to be drawn + _freeIndexLock.lock(); + _freeIndexes.push_back(index); + _freeIndexLock.unlock(); - // make sure the index isn't already in the free list..., this is a debugging measure only done if you've enabled audits - if (Menu::getInstance()->isOptionChecked(MenuOption::AutomaticallyAuditTree)) { - for (unsigned long i = 0; i < _freeIndexes.size(); i++) { - if (_freeIndexes[i] == index) { - printf("freeBufferIndex(glBufferIndex index)... index=%ld already in free list!", index); - inList = true; - break; - } - } - } - if (!inList) { - // make the index available for next node that needs to be drawn - _freeIndexLock.lock(); - _freeIndexes.push_back(index); - _freeIndexLock.unlock(); - - // make the VBO slot "invisible" in case this slot is not used - const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX); - const float voxelScale = 0; - const nodeColor BLACK = {0, 0, 0, 0}; - updateArraysDetails(index, startVertex, voxelScale, BLACK); - } + // make the VBO slot "invisible" in case this slot is not used + const glm::vec3 startVertex(FLT_MAX, FLT_MAX, FLT_MAX); + const float voxelScale = 0; + const nodeColor BLACK = {0, 0, 0, 0}; + updateArraysDetails(index, startVertex, voxelScale, BLACK); } // This will run through the list of _freeIndexes and reset their VBO array values to be "invisible". @@ -541,34 +521,6 @@ void VoxelSystem::initVoxelMemory() { _readArraysLock.unlock(); } -void VoxelSystem::writeToSVOFile(const char* filename, VoxelTreeElement* element) const { - _tree->writeToSVOFile(filename, element); -} - -bool VoxelSystem::readFromSVOFile(const char* filename) { - bool result = _tree->readFromSVOFile(filename); - if (result) { - setupNewVoxelsForDrawing(); - } - return result; -} - -bool VoxelSystem::readFromSquareARGB32Pixels(const char *filename) { - bool result = _tree->readFromSquareARGB32Pixels(filename); - if (result) { - setupNewVoxelsForDrawing(); - } - return result; -} - -bool VoxelSystem::readFromSchematicFile(const char* filename) { - bool result = _tree->readFromSchematicFile(filename); - if (result) { - setupNewVoxelsForDrawing(); - } - return result; -} - int VoxelSystem::parseData(const QByteArray& packet) { bool showTimingDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showTimingDetails, "VoxelSystem::parseData()",showTimingDetails); @@ -618,7 +570,7 @@ int VoxelSystem::parseData(const QByteArray& packet) { // ask the VoxelTree to read the bitstream into the tree ReadBitstreamToTreeParams args(packetIsColored ? WANT_COLOR : NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceUUID()); _tree->lockForWrite(); - VoxelPacketData packetData(packetIsCompressed); + OctreePacketData packetData(packetIsCompressed); packetData.loadFinalizedContent(dataAt, sectionLength); if (Application::getInstance()->getLogger()->extraDebugging()) { qDebug("VoxelSystem::parseData() ... Got Packet Section" @@ -692,8 +644,6 @@ void VoxelSystem::setupNewVoxelsForDrawing() { _abandonedVBOSlots = 0; // reset the count of our abandoned slots, why is this here and not earlier???? } - // since we called treeToArrays, we can assume that our VBO is in sync, and so partial updates to the VBOs are - // ok again, until/unless we call removeOutOfView() _writeRenderFullVBO = false; } else { _voxelsUpdated = 0; @@ -886,15 +836,6 @@ void VoxelSystem::checkForCulling() { // we should consider putting this someplace else... as this might be able to occur less frequently, and save us on // VBO reubuilding. Possibly we should do this only if our actual VBO usage crosses some lower boundary. cleanupRemovedVoxels(); - - quint64 sinceLastAudit = (start - _lastAudit) / 1000; - - if (Menu::getInstance()->isOptionChecked(MenuOption::AutomaticallyAuditTree)) { - if (sinceLastAudit >= std::max((float) _lastViewCullingElapsed, VIEW_CULLING_RATE_IN_MILLISECONDS)) { - _lastAudit = start; - collectStatsForTreesAndVBOs(); - } - } } void VoxelSystem::cleanupRemovedVoxels() { @@ -1241,9 +1182,6 @@ void VoxelSystem::changeTree(VoxelTree* newTree) { _tree->setDirtyBit(); _tree->getRoot()->setVoxelSystem(this); - connect(_tree, SIGNAL(importSize(float,float,float)), SIGNAL(importSize(float,float,float))); - connect(_tree, SIGNAL(importProgress(int)), SIGNAL(importProgress(int))); - setupNewVoxelsForDrawing(); } @@ -1830,329 +1768,6 @@ void VoxelSystem::forceRedrawEntireTree() { setupNewVoxelsForDrawing(); } -bool VoxelSystem::randomColorOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - _nodeCount++; - if (voxel->isColored()) { - nodeColor newColor = { 255, randomColorValue(150), randomColorValue(150), 1 }; - voxel->setColor(newColor); - } - return true; -} - -void VoxelSystem::randomizeVoxelColors() { - _nodeCount = 0; - _tree->recurseTreeWithOperation(randomColorOperation); - qDebug("setting randomized true color for %d nodes", _nodeCount); - _tree->setDirtyBit(); - setupNewVoxelsForDrawing(); -} - -bool VoxelSystem::falseColorizeRandomOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - _nodeCount++; - // always false colorize - voxel->setFalseColor(255, randomColorValue(150), randomColorValue(150)); - return true; // keep going! -} - -void VoxelSystem::falseColorizeRandom() { - _nodeCount = 0; - _tree->recurseTreeWithOperation(falseColorizeRandomOperation); - qDebug("setting randomized false color for %d nodes", _nodeCount); - _tree->setDirtyBit(); - setupNewVoxelsForDrawing(); -} - -bool VoxelSystem::trueColorizeOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - _nodeCount++; - voxel->setFalseColored(false); - return true; -} - -void VoxelSystem::trueColorize() { - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "trueColorize()",true); - _nodeCount = 0; - _tree->recurseTreeWithOperation(trueColorizeOperation); - qDebug("setting true color for %d nodes", _nodeCount); - _tree->setDirtyBit(); - setupNewVoxelsForDrawing(); -} - -// Will false colorize voxels that are not in view -bool VoxelSystem::falseColorizeInViewOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - const ViewFrustum* viewFrustum = (const ViewFrustum*) extraData; - _nodeCount++; - if (voxel->isColored()) { - if (!voxel->isInView(*viewFrustum)) { - // Out of view voxels are colored RED - voxel->setFalseColor(255, 0, 0); - } - } - return true; // keep going! -} - -void VoxelSystem::falseColorizeInView() { - _nodeCount = 0; - _tree->recurseTreeWithOperation(falseColorizeInViewOperation,(void*)_viewFrustum); - qDebug("setting in view false color for %d nodes", _nodeCount); - _tree->setDirtyBit(); - setupNewVoxelsForDrawing(); -} - -class VoxelAndPoint { -public: - VoxelTreeElement* voxel; - glm::vec3 point; -}; - -// Find the smallest colored voxel enclosing a point (if there is one) -bool VoxelSystem::getVoxelEnclosingOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - VoxelAndPoint* args = (VoxelAndPoint*) extraData; - AABox voxelBox = voxel->getAABox(); - if (voxelBox.contains(args->point)) { - if (voxel->isColored() && voxel->isLeaf()) { - // we've reached a solid leaf containing the point, return the node. - args->voxel = voxel; - return false; - } - } else { - // The point is not inside this voxel, so stop recursing. - return false; - } - return true; // keep looking -} - -VoxelTreeElement* VoxelSystem::getVoxelEnclosing(const glm::vec3& point) { - VoxelAndPoint voxelAndPoint; - voxelAndPoint.point = point; - voxelAndPoint.voxel = NULL; - _tree->recurseTreeWithOperation(getVoxelEnclosingOperation, (void*) &voxelAndPoint); - return voxelAndPoint.voxel; -} - - -// helper classes and args for falseColorizeBySource -class groupColor { -public: - unsigned char red, green, blue; - groupColor(unsigned char red, unsigned char green, unsigned char blue) : - red(red), green(green), blue(blue) { } - - groupColor() : - red(0), green(0), blue(0) { } -}; - -class colorizeBySourceArgs { -public: - std::map colors; -}; - -// Will false colorize voxels that are not in view -bool VoxelSystem::falseColorizeBySourceOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - colorizeBySourceArgs* args = (colorizeBySourceArgs*)extraData; - _nodeCount++; - if (voxel->isColored()) { - // pick a color based on the source - we want each source to be obviously different - uint16_t nodeIDKey = voxel->getSourceUUIDKey(); - voxel->setFalseColor(args->colors[nodeIDKey].red, args->colors[nodeIDKey].green, args->colors[nodeIDKey].blue); - } - return true; // keep going! -} - -void VoxelSystem::falseColorizeBySource() { - _nodeCount = 0; - colorizeBySourceArgs args; - const int NUMBER_OF_COLOR_GROUPS = 6; - const unsigned char MIN_COLOR = 128; - int voxelServerCount = 0; - groupColor groupColors[NUMBER_OF_COLOR_GROUPS] = { - groupColor(255, 0, 0), - groupColor( 0, 255, 0), - groupColor( 0, 0, 255), - groupColor(255, 0, 255), - groupColor( 0, 255, 255), - groupColor(255, 255, 255) - }; - - // create a bunch of colors we'll use during colorization - - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { - if (node->getType() == NodeType::VoxelServer) { - uint16_t nodeID = VoxelTreeElement::getSourceNodeUUIDKey(node->getUUID()); - int groupColor = voxelServerCount % NUMBER_OF_COLOR_GROUPS; - args.colors[nodeID] = groupColors[groupColor]; - - if (groupColors[groupColor].red > 0) { - groupColors[groupColor].red = ((groupColors[groupColor].red - MIN_COLOR)/2) + MIN_COLOR; - } - if (groupColors[groupColor].green > 0) { - groupColors[groupColor].green = ((groupColors[groupColor].green - MIN_COLOR)/2) + MIN_COLOR; - } - if (groupColors[groupColor].blue > 0) { - groupColors[groupColor].blue = ((groupColors[groupColor].blue - MIN_COLOR)/2) + MIN_COLOR; - } - - voxelServerCount++; - } - } - - _tree->recurseTreeWithOperation(falseColorizeBySourceOperation, &args); - qDebug("setting false color by source for %d nodes", _nodeCount); - _tree->setDirtyBit(); - setupNewVoxelsForDrawing(); -} - -// Will false colorize voxels based on distance from view -bool VoxelSystem::falseColorizeDistanceFromViewOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - ViewFrustum* viewFrustum = (ViewFrustum*) extraData; - if (voxel->isColored()) { - float distance = voxel->distanceToCamera(*viewFrustum); - _nodeCount++; - float distanceRatio = (_minDistance == _maxDistance) ? 1 : (distance - _minDistance) / (_maxDistance - _minDistance); - - // We want to colorize this in 16 bug chunks of color - const unsigned char maxColor = 255; - const unsigned char colorBands = 16; - const unsigned char gradientOver = 128; - unsigned char colorBand = (colorBands * distanceRatio); - voxel->setFalseColor((colorBand * (gradientOver / colorBands)) + (maxColor - gradientOver), 0, 0); - } - return true; // keep going! -} - -float VoxelSystem::_maxDistance = 0.0; -float VoxelSystem::_minDistance = FLT_MAX; - -// Helper function will get the distance from view range, would be nice if you could just keep track -// of this as voxels are created and/or colored... seems like some transform math could do that so -// we wouldn't need to do two passes of the tree -bool VoxelSystem::getDistanceFromViewRangeOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - ViewFrustum* viewFrustum = (ViewFrustum*) extraData; - // only do this for truly colored voxels... - if (voxel->isColored()) { - float distance = voxel->distanceToCamera(*viewFrustum); - // calculate the range of distances - if (distance > _maxDistance) { - _maxDistance = distance; - } - if (distance < _minDistance) { - _minDistance = distance; - } - _nodeCount++; - } - return true; // keep going! -} - -void VoxelSystem::falseColorizeDistanceFromView() { - _nodeCount = 0; - _maxDistance = 0.0; - _minDistance = FLT_MAX; - _tree->recurseTreeWithOperation(getDistanceFromViewRangeOperation, (void*) _viewFrustum); - qDebug("determining distance range for %d nodes", _nodeCount); - _nodeCount = 0; - _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation, (void*) _viewFrustum); - qDebug("setting in distance false color for %d nodes", _nodeCount); - _tree->setDirtyBit(); - setupNewVoxelsForDrawing(); -} - -// combines the removeOutOfView args into a single class -class removeOutOfViewArgs { -public: - VoxelSystem* thisVoxelSystem; - ViewFrustum thisViewFrustum; - OctreeElementBag dontRecurseBag; - unsigned long nodesScanned; - unsigned long nodesRemoved; - unsigned long nodesInside; - unsigned long nodesIntersect; - unsigned long nodesOutside; - VoxelTreeElement* insideRoot; - VoxelTreeElement* outsideRoot; - - removeOutOfViewArgs(VoxelSystem* voxelSystem, bool widenViewFrustum = true) : - thisVoxelSystem(voxelSystem), - thisViewFrustum(*voxelSystem->getViewFrustum()), - dontRecurseBag(), - nodesScanned(0), - nodesRemoved(0), - nodesInside(0), - nodesIntersect(0), - nodesOutside(0), - insideRoot(NULL), - outsideRoot(NULL) - { - // Widen the FOV for trimming - if (widenViewFrustum) { - float originalFOV = thisViewFrustum.getFieldOfView(); - float wideFOV = originalFOV + VIEW_FRUSTUM_FOV_OVERSEND; - thisViewFrustum.setFieldOfView(wideFOV); - thisViewFrustum.calculate(); - } - } -}; - -void VoxelSystem::cancelImport() { - _tree->cancelImport(); -} - -// "Remove" voxels from the tree that are not in view. We don't actually delete them, -// we remove them from the tree and place them into a holding area for later deletion -bool VoxelSystem::removeOutOfViewOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*) element; - removeOutOfViewArgs* args = (removeOutOfViewArgs*)extraData; - - // If our node was previously added to the don't recurse bag, then return false to - // stop the further recursion. This means that the whole node and it's children are - // known to be in view, so don't recurse them - if (args->dontRecurseBag.contains(voxel)) { - args->dontRecurseBag.remove(voxel); - return false; // stop recursion - } - - VoxelSystem* thisVoxelSystem = args->thisVoxelSystem; - args->nodesScanned++; - // Need to operate on our child nodes, so we can remove them - for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { - VoxelTreeElement* childNode = voxel->getChildAtIndex(i); - if (childNode) { - ViewFrustum::location inFrustum = childNode->inFrustum(args->thisViewFrustum); - switch (inFrustum) { - case ViewFrustum::OUTSIDE: { - args->nodesOutside++; - args->nodesRemoved++; - voxel->removeChildAtIndex(i); - thisVoxelSystem->_removedVoxels.insert(childNode); - // by removing the child, it will not get recursed! - } break; - case ViewFrustum::INSIDE: { - // if the child node is fully INSIDE the view, then there's no need to recurse it - // because we know all it's children will also be in the view, so we want to - // tell the caller to NOT recurse this child - args->nodesInside++; - args->dontRecurseBag.insert(childNode); - } break; - case ViewFrustum::INTERSECT: { - // if the child node INTERSECTs the view, then we don't want to remove it because - // it is at least partially in view. But we DO want to recurse the children because - // some of them may not be in view... nothing specifically to do, just keep iterating - // the children - args->nodesIntersect++; - } break; - } - } - } - return true; // keep going! -} - bool VoxelSystem::isViewChanging() { bool result = false; // assume the best @@ -2180,74 +1795,6 @@ bool VoxelSystem::hasViewChanged() { return result; } -void VoxelSystem::removeOutOfView() { - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "removeOutOfView()"); - removeOutOfViewArgs args(this); - _tree->recurseTreeWithOperation(removeOutOfViewOperation,(void*)&args); - - if (args.nodesRemoved) { - _tree->setDirtyBit(); - } - bool showRemoveDebugDetails = false; - if (showRemoveDebugDetails) { - qDebug("removeOutOfView() scanned=%ld removed=%ld inside=%ld intersect=%ld outside=%ld _removedVoxels.count()=%d", - args.nodesScanned, args.nodesRemoved, args.nodesInside, - args.nodesIntersect, args.nodesOutside, _removedVoxels.count() - ); - } -} - -// combines the removeOutOfView args into a single class -class showAllLocalVoxelsArgs { -public: - VoxelSystem* thisVoxelSystem; - ViewFrustum thisViewFrustum; - unsigned long nodesScanned; - - showAllLocalVoxelsArgs(VoxelSystem* voxelSystem) : - thisVoxelSystem(voxelSystem), - thisViewFrustum(*voxelSystem->getViewFrustum()), - nodesScanned(0) - { - } -}; - -void VoxelSystem::showAllLocalVoxels() { - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "showAllLocalVoxels()"); - showAllLocalVoxelsArgs args(this); - _tree->recurseTreeWithOperation(showAllLocalVoxelsOperation,(void*)&args); - - bool showRemoveDebugDetails = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); - if (showRemoveDebugDetails) { - qDebug("showAllLocalVoxels() scanned=%ld",args.nodesScanned ); - } -} - -bool VoxelSystem::showAllLocalVoxelsOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - showAllLocalVoxelsArgs* args = (showAllLocalVoxelsArgs*)extraData; - - args->nodesScanned++; - - float voxelSizeScale = Menu::getInstance()->getVoxelSizeScale();; - int boundaryLevelAdjust = Menu::getInstance()->getBoundaryLevelAdjust(); - bool shouldRender = voxel->calculateShouldRender(&args->thisViewFrustum, voxelSizeScale, boundaryLevelAdjust); - voxel->setShouldRender(shouldRender); - - if (shouldRender) { - bool falseColorize = false; - if (falseColorize) { - voxel->setFalseColor(0,0,255); // false colorize - } - // These are both needed to force redraw... - voxel->setDirtyBit(); - voxel->markWithChangedTime(); - } - - return true; // keep recursing! -} - - // combines the removeOutOfView args into a single class class hideOutOfViewArgs { public: @@ -2396,15 +1943,9 @@ bool VoxelSystem::hideAllSubTreeOperation(OctreeElement* element, void* extraDat args->nodesOutside++; if (voxel->isKnownBufferIndex()) { args->nodesRemoved++; - bool falseColorize = false; - if (falseColorize) { - voxel->setFalseColor(255,0,0); // false colorize - } else { - VoxelSystem* thisVoxelSystem = args->thisVoxelSystem; - thisVoxelSystem->_voxelsUpdated += thisVoxelSystem->forceRemoveNodeFromArrays(voxel); - thisVoxelSystem->setupNewVoxelsForDrawingSingleNode(); - } - + VoxelSystem* thisVoxelSystem = args->thisVoxelSystem; + thisVoxelSystem->_voxelsUpdated += thisVoxelSystem->forceRemoveNodeFromArrays(voxel); + thisVoxelSystem->setupNewVoxelsForDrawingSingleNode(); } return true; @@ -2437,20 +1978,9 @@ bool VoxelSystem::showAllSubTreeOperation(OctreeElement* element, void* extraDat voxel->setShouldRender(shouldRender); if (shouldRender && !voxel->isKnownBufferIndex()) { - bool falseColorize = false; - if (falseColorize) { - voxel->setFalseColor(0,0,255); // false colorize - } // These are both needed to force redraw... voxel->setDirtyBit(); voxel->markWithChangedTime(); - // and this? -// no, not needed, because markWithChangedTime notifies hooks, which calls elementUpdated, which calls updateNodeInArrays -// { -// VoxelSystem* thisVoxelSystem = args->thisVoxelSystem; -// thisVoxelSystem->_voxelsUpdated += thisVoxelSystem->updateNodeInArrays(voxel, true, true); -// thisVoxelSystem->setupNewVoxelsForDrawingSingleNode(); -// } args->nodesShown++; } @@ -2552,567 +2082,6 @@ bool VoxelSystem::hideOutOfViewOperation(OctreeElement* element, void* extraData } -bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - VoxelDetail& detail, float& distance, BoxFace& face) { - - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "VoxelSystem::findRayIntersection()"); - bool result = false; // assume no intersection - if (_tree->tryLockForRead()) { - OctreeElement* element; - result = _tree->findRayIntersection(origin, direction, element, distance, face); - if (result) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - detail.x = voxel->getCorner().x; - detail.y = voxel->getCorner().y; - detail.z = voxel->getCorner().z; - detail.s = voxel->getScale(); - detail.red = voxel->getColor()[0]; - detail.green = voxel->getColor()[1]; - detail.blue = voxel->getColor()[2]; - } - _tree->unlock(); - } - return result; -} - -bool VoxelSystem::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) { - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "VoxelSystem::findSpherePenetration()"); - bool result = false; // assume no penetration - if (_tree->tryLockForRead()) { - result = _tree->findSpherePenetration(center, radius, penetration); - _tree->unlock(); - } - return result; -} - -bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) { - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "VoxelSystem::findCapsulePenetration()"); - bool result = false; // assume no penetration - if (_tree->tryLockForRead()) { - result = _tree->findCapsulePenetration(start, end, radius, penetration); - _tree->unlock(); - } - return result; -} - -class falseColorizeRandomEveryOtherArgs { -public: - falseColorizeRandomEveryOtherArgs() : totalNodes(0), colorableNodes(0), coloredNodes(0), colorThis(true) {}; - unsigned long totalNodes; - unsigned long colorableNodes; - unsigned long coloredNodes; - bool colorThis; -}; - -bool VoxelSystem::falseColorizeRandomEveryOtherOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - falseColorizeRandomEveryOtherArgs* args = (falseColorizeRandomEveryOtherArgs*)extraData; - args->totalNodes++; - if (voxel->isColored()) { - args->colorableNodes++; - if (args->colorThis) { - args->coloredNodes++; - voxel->setFalseColor(255, randomColorValue(150), randomColorValue(150)); - } - args->colorThis = !args->colorThis; - } - return true; // keep going! -} - -void VoxelSystem::falseColorizeRandomEveryOther() { - falseColorizeRandomEveryOtherArgs args; - _tree->recurseTreeWithOperation(falseColorizeRandomEveryOtherOperation,&args); - qDebug("randomized false color for every other node: total %ld, colorable %ld, colored %ld", - args.totalNodes, args.colorableNodes, args.coloredNodes); - _tree->setDirtyBit(); - setupNewVoxelsForDrawing(); -} - -class collectStatsForTreesAndVBOsArgs { -public: - collectStatsForTreesAndVBOsArgs(int maxVoxels) : - totalNodes(0), - dirtyNodes(0), - shouldRenderNodes(0), - coloredNodes(0), - nodesInVBO(0), - nodesInVBONotShouldRender(0), - nodesInVBOOverExpectedMax(0), - duplicateVBOIndex(0), - leafNodes(0), - culledLeafNodes(0), - nodesInPrimitiveRenderer(0) - { - hasIndexFound = new bool[maxVoxels]; - memset(hasIndexFound, false, maxVoxels * sizeof(bool)); - }; - - ~collectStatsForTreesAndVBOsArgs() { - delete[] hasIndexFound; - } - - unsigned long totalNodes; - unsigned long dirtyNodes; - unsigned long shouldRenderNodes; - unsigned long coloredNodes; - unsigned long nodesInVBO; - unsigned long nodesInVBONotShouldRender; - unsigned long nodesInVBOOverExpectedMax; - unsigned long duplicateVBOIndex; - unsigned long leafNodes; - unsigned long culledLeafNodes; ///< Number of completely culled nodes because of face sharing - unsigned long nodesInPrimitiveRenderer; - - unsigned long expectedMax; - - bool* hasIndexFound; -}; - -bool VoxelSystem::collectStatsForTreesAndVBOsOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - - collectStatsForTreesAndVBOsArgs* args = (collectStatsForTreesAndVBOsArgs*)extraData; - args->totalNodes++; - - if (voxel->isLeaf()) { - args->leafNodes++; - if (voxel->getInteriorOcclusions() == OctreeElement::HalfSpace::All) { - args->culledLeafNodes++; - } - } - - if (voxel->isColored()) { - args->coloredNodes++; - } - - if (voxel->getShouldRender()) { - args->shouldRenderNodes++; - } - - if (voxel->isDirty()) { - args->dirtyNodes++; - } - - unsigned long nodeIndex = 0; - if (voxel->getBufferIndex()) { - args->nodesInPrimitiveRenderer++; - nodeIndex = voxel->getBufferIndex(); - - const bool extraDebugging = false; // enable for extra debugging - if (extraDebugging) { - qDebug("node In Renderer... [%f,%f,%f] %f ... index=%ld, isDirty=%s, shouldRender=%s, culledFaces=0x%02x \n", - voxel->getCorner().x, voxel->getCorner().y, voxel->getCorner().z, voxel->getScale(), - nodeIndex, debug::valueOf(voxel->isDirty()), debug::valueOf(voxel->getShouldRender()), - voxel->getInteriorOcclusions()); - } - } - - if (voxel->isKnownBufferIndex()) { - args->nodesInVBO++; - nodeIndex = voxel->getBufferIndex(); - - const bool extraDebugging = false; // enable for extra debugging - if (extraDebugging) { - qDebug("node In VBO... [%f,%f,%f] %f ... index=%ld, isDirty=%s, shouldRender=%s \n", - voxel->getCorner().x, voxel->getCorner().y, voxel->getCorner().z, voxel->getScale(), - nodeIndex, debug::valueOf(voxel->isDirty()), debug::valueOf(voxel->getShouldRender())); - } - - if (args->hasIndexFound[nodeIndex]) { - args->duplicateVBOIndex++; - qDebug("duplicateVBO found... index=%ld, isDirty=%s, shouldRender=%s", nodeIndex, - debug::valueOf(voxel->isDirty()), debug::valueOf(voxel->getShouldRender())); - } else { - args->hasIndexFound[nodeIndex] = true; - } - if (nodeIndex > args->expectedMax) { - args->nodesInVBOOverExpectedMax++; - } - - // if it's in VBO but not-shouldRender, track that also... - if (!voxel->getShouldRender()) { - args->nodesInVBONotShouldRender++; - } - } - - return true; // keep going! -} - -void VoxelSystem::collectStatsForTreesAndVBOs() { - PerformanceWarning warn(true, "collectStatsForTreesAndVBOs()", true); - - glBufferIndex minDirty = GLBUFFER_INDEX_UNKNOWN; - glBufferIndex maxDirty = 0; - - if (!_usePrimitiveRenderer) { - for (glBufferIndex i = 0; i < _voxelsInWriteArrays; i++) { - if (_writeVoxelDirtyArray[i]) { - minDirty = std::min(minDirty,i); - maxDirty = std::max(maxDirty,i); - } - } - } - - collectStatsForTreesAndVBOsArgs args(_maxVoxels); - args.expectedMax = _voxelsInWriteArrays; - - qDebug("CALCULATING Local Voxel Tree Statistics >>>>>>>>>>>>"); - - _tree->recurseTreeWithOperation(collectStatsForTreesAndVBOsOperation,&args); - - qDebug("Local Voxel Tree Statistics:\n total nodes %ld \n leaves %ld \n dirty %ld \n colored %ld \n shouldRender %ld \n", - args.totalNodes, args.leafNodes, args.dirtyNodes, args.coloredNodes, args.shouldRenderNodes); - - if (!_usePrimitiveRenderer) { - qDebug(" _voxelsDirty=%s \n _voxelsInWriteArrays=%ld \n minDirty=%ld \n maxDirty=%ld", debug::valueOf(_voxelsDirty), - _voxelsInWriteArrays, minDirty, maxDirty); - - qDebug(" inVBO %ld \n nodesInVBOOverExpectedMax %ld \n duplicateVBOIndex %ld \n nodesInVBONotShouldRender %ld", - args.nodesInVBO, args.nodesInVBOOverExpectedMax, args.duplicateVBOIndex, args.nodesInVBONotShouldRender); - - qDebug(" memory usage %ld \n gpu memory usage %ld \n", _memoryUsageRAM, _memoryUsageVBO); - - glBufferIndex minInVBO = GLBUFFER_INDEX_UNKNOWN; - glBufferIndex maxInVBO = 0; - - for (glBufferIndex i = 0; i < _maxVoxels; i++) { - if (args.hasIndexFound[i]) { - minInVBO = std::min(minInVBO,i); - maxInVBO = std::max(maxInVBO,i); - } - } - - qDebug(" minInVBO=%ld \n maxInVBO=%ld \n _voxelsInWriteArrays=%ld \n _voxelsInReadArrays=%ld", - minInVBO, maxInVBO, _voxelsInWriteArrays, _voxelsInReadArrays); - - qDebug(" _freeIndexes.size()=%ld", - _freeIndexes.size()); - } else { - qDebug(" PrimitiveRenderer nodes %ld \n completely culled nodes %ld \n", - args.nodesInPrimitiveRenderer, args.culledLeafNodes); - - qDebug(" memory usage %ld \n gpu memory usage %ld \n", - _renderer->getMemoryUsage(), _renderer->getMemoryUsageGPU()); - } - qDebug("DONE WITH Local Voxel Tree Statistics >>>>>>>>>>>>"); -} - - -void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) { - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "VoxelSystem::deleteVoxelAt()"); - _tree->lockForWrite(); - _tree->deleteVoxelAt(x, y, z, s); - _tree->unlock(); - - // redraw! - setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in? -}; - -VoxelTreeElement* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const { - return _tree->getVoxelAt(x, y, z, s); -}; - -void VoxelSystem::createVoxel(float x, float y, float z, float s, - unsigned char red, unsigned char green, unsigned char blue, bool destructive) { - - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "VoxelSystem::createVoxel()"); - - _tree->lockForWrite(); - _tree->createVoxel(x, y, z, s, red, green, blue, destructive); - _tree->unlock(); - - setupNewVoxelsForDrawing(); -}; - -void VoxelSystem::createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color, bool destructive) { - _tree->createLine(point1, point2, unitSize, color, destructive); - setupNewVoxelsForDrawing(); -}; - -void VoxelSystem::copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destination, bool rebaseToRoot) { - _tree->copySubTreeIntoNewTree(startNode, destination->_tree, rebaseToRoot); - destination->setupNewVoxelsForDrawing(); -} - -void VoxelSystem::copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelTree* destination, bool rebaseToRoot) { - _tree->copySubTreeIntoNewTree(startNode, destination, rebaseToRoot); -} - -void VoxelSystem::copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelTreeElement* destinationNode) { - _tree->copyFromTreeIntoSubTree(sourceTree, destinationNode); -} - -void VoxelSystem::recurseTreeWithOperation(RecurseOctreeOperation operation, void* extraData) { - _tree->recurseTreeWithOperation(operation, extraData); -} - -struct FalseColorizeOccludedArgs { - ViewFrustum* viewFrustum; - CoverageMap* map; - CoverageMapV2* mapV2; - VoxelTree* tree; - long totalVoxels; - long coloredVoxels; - long occludedVoxels; - long notOccludedVoxels; - long outOfView; - long subtreeVoxelsSkipped; - long nonLeaves; - long nonLeavesOutOfView; - long nonLeavesOccluded; -}; - -struct FalseColorizeSubTreeOperationArgs { - unsigned char color[NUMBER_OF_COLORS]; - long voxelsTouched; -}; - -bool VoxelSystem::falseColorizeSubTreeOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - if (voxel->getShouldRender()) { - FalseColorizeSubTreeOperationArgs* args = (FalseColorizeSubTreeOperationArgs*) extraData; - voxel->setFalseColor(args->color[0], args->color[1], args->color[2]); - args->voxelsTouched++; - } - return true; -} - -bool VoxelSystem::falseColorizeOccludedOperation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - - FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData; - args->totalVoxels++; - - // If we are a parent, let's see if we're completely occluded. - if (!voxel->isLeaf()) { - args->nonLeaves++; - - AABox voxelBox = voxel->getAABox(); - voxelBox.scale(TREE_SCALE); - OctreeProjectedPolygon* voxelPolygon = new OctreeProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox)); - - // If we're not all in view, then ignore it, and just return. But keep searching... - if (!voxelPolygon->getAllInView()) { - args->nonLeavesOutOfView++; - delete voxelPolygon; - return true; - } - - CoverageMapStorageResult result = args->map->checkMap(voxelPolygon, false); - if (result == OCCLUDED) { - args->nonLeavesOccluded++; - delete voxelPolygon; - - FalseColorizeSubTreeOperationArgs subArgs; - subArgs.color[0] = 0; - subArgs.color[1] = 255; - subArgs.color[2] = 0; - subArgs.voxelsTouched = 0; - - args->tree->recurseNodeWithOperation(voxel, falseColorizeSubTreeOperation, &subArgs ); - - args->subtreeVoxelsSkipped += (subArgs.voxelsTouched - 1); - args->totalVoxels += (subArgs.voxelsTouched - 1); - - return false; - } - - delete voxelPolygon; - return true; // keep looking... - } - - if (voxel->isLeaf() && voxel->isColored() && voxel->getShouldRender()) { - args->coloredVoxels++; - - AABox voxelBox = voxel->getAABox(); - voxelBox.scale(TREE_SCALE); - OctreeProjectedPolygon* voxelPolygon = new OctreeProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox)); - - // If we're not all in view, then ignore it, and just return. But keep searching... - if (!voxelPolygon->getAllInView()) { - args->outOfView++; - delete voxelPolygon; - return true; - } - - CoverageMapStorageResult result = args->map->checkMap(voxelPolygon, true); - if (result == OCCLUDED) { - voxel->setFalseColor(255, 0, 0); - args->occludedVoxels++; - } else if (result == STORED) { - args->notOccludedVoxels++; - //qDebug("***** falseColorizeOccludedOperation() NODE is STORED *****\n"); - } else if (result == DOESNT_FIT) { - //qDebug("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n"); - } - } - return true; // keep going! -} - -void VoxelSystem::falseColorizeOccluded() { - PerformanceWarning warn(true, "falseColorizeOccluded()",true); - myCoverageMap.erase(); - - FalseColorizeOccludedArgs args; - args.viewFrustum = _viewFrustum; - args.map = &myCoverageMap; - args.totalVoxels = 0; - args.coloredVoxels = 0; - args.occludedVoxels = 0; - args.notOccludedVoxels = 0; - args.outOfView = 0; - args.subtreeVoxelsSkipped = 0; - args.nonLeaves = 0; - args.nonLeavesOutOfView = 0; - args.nonLeavesOccluded = 0; - args.tree = _tree; - - OctreeProjectedPolygon::pointInside_calls = 0; - OctreeProjectedPolygon::occludes_calls = 0; - OctreeProjectedPolygon::intersects_calls = 0; - - glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE); - - _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedOperation, position, (void*)&args); - - qDebug("falseColorizeOccluded()\n position=(%f,%f)\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n pointInside_calls=%ld\n occludes_calls=%ld\n intersects_calls=%ld", - position.x, position.y, - args.totalVoxels, args.coloredVoxels, args.occludedVoxels, - args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, - args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded, - OctreeProjectedPolygon::pointInside_calls, - OctreeProjectedPolygon::occludes_calls, - OctreeProjectedPolygon::intersects_calls - ); - - - //myCoverageMap.erase(); - - _tree->setDirtyBit(); - setupNewVoxelsForDrawing(); -} - -bool VoxelSystem::falseColorizeOccludedV2Operation(OctreeElement* element, void* extraData) { - VoxelTreeElement* voxel = (VoxelTreeElement*)element; - - FalseColorizeOccludedArgs* args = (FalseColorizeOccludedArgs*) extraData; - args->totalVoxels++; - - // If we are a parent, let's see if we're completely occluded. - if (!voxel->isLeaf()) { - args->nonLeaves++; - - AABox voxelBox = voxel->getAABox(); - voxelBox.scale(TREE_SCALE); - OctreeProjectedPolygon* voxelPolygon = new OctreeProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox)); - - // If we're not all in view, then ignore it, and just return. But keep searching... - if (!voxelPolygon->getAllInView()) { - args->nonLeavesOutOfView++; - delete voxelPolygon; - return true; - } - - CoverageMapV2StorageResult result = args->mapV2->checkMap(voxelPolygon, false); - if (result == V2_OCCLUDED) { - args->nonLeavesOccluded++; - delete voxelPolygon; - - FalseColorizeSubTreeOperationArgs subArgs; - subArgs.color[0] = 0; - subArgs.color[1] = 255; - subArgs.color[2] = 0; - subArgs.voxelsTouched = 0; - - args->tree->recurseNodeWithOperation(voxel, falseColorizeSubTreeOperation, &subArgs ); - - args->subtreeVoxelsSkipped += (subArgs.voxelsTouched - 1); - args->totalVoxels += (subArgs.voxelsTouched - 1); - - return false; - } - - delete voxelPolygon; - return true; // keep looking... - } - - if (voxel->isLeaf() && voxel->isColored() && voxel->getShouldRender()) { - args->coloredVoxels++; - - AABox voxelBox = voxel->getAABox(); - voxelBox.scale(TREE_SCALE); - OctreeProjectedPolygon* voxelPolygon = new OctreeProjectedPolygon(args->viewFrustum->getProjectedPolygon(voxelBox)); - - // If we're not all in view, then ignore it, and just return. But keep searching... - if (!voxelPolygon->getAllInView()) { - args->outOfView++; - delete voxelPolygon; - return true; - } - - CoverageMapV2StorageResult result = args->mapV2->checkMap(voxelPolygon, true); - if (result == V2_OCCLUDED) { - voxel->setFalseColor(255, 0, 0); - args->occludedVoxels++; - } else if (result == V2_STORED) { - args->notOccludedVoxels++; - //qDebug("***** falseColorizeOccludedOperation() NODE is STORED *****\n"); - } else if (result == V2_DOESNT_FIT) { - //qDebug("***** falseColorizeOccludedOperation() NODE DOESNT_FIT???? *****\n"); - } - delete voxelPolygon; // V2 maps don't store polygons, so we're always in charge of freeing - } - return true; // keep going! -} - - -void VoxelSystem::falseColorizeOccludedV2() { - PerformanceWarning warn(true, "falseColorizeOccludedV2()",true); - myCoverageMapV2.erase(); - - CoverageMapV2::wantDebugging = true; - - OctreeProjectedPolygon::pointInside_calls = 0; - OctreeProjectedPolygon::occludes_calls = 0; - OctreeProjectedPolygon::intersects_calls = 0; - - FalseColorizeOccludedArgs args; - args.viewFrustum = _viewFrustum; - args.mapV2 = &myCoverageMapV2; - args.totalVoxels = 0; - args.coloredVoxels = 0; - args.occludedVoxels = 0; - args.notOccludedVoxels = 0; - args.outOfView = 0; - args.subtreeVoxelsSkipped = 0; - args.nonLeaves = 0; - args.nonLeavesOutOfView = 0; - args.nonLeavesOccluded = 0; - args.tree = _tree; - - glm::vec3 position = args.viewFrustum->getPosition() * (1.0f/TREE_SCALE); - - _tree->recurseTreeWithOperationDistanceSorted(falseColorizeOccludedV2Operation, position, (void*)&args); - - qDebug("falseColorizeOccludedV2()\n position=(%f,%f)\n total=%ld\n colored=%ld\n occluded=%ld\n notOccluded=%ld\n outOfView=%ld\n subtreeVoxelsSkipped=%ld\n nonLeaves=%ld\n nonLeavesOutOfView=%ld\n nonLeavesOccluded=%ld\n pointInside_calls=%ld\n occludes_calls=%ld\n intersects_calls=%ld\n", - position.x, position.y, - args.totalVoxels, args.coloredVoxels, args.occludedVoxels, - args.notOccludedVoxels, args.outOfView, args.subtreeVoxelsSkipped, - args.nonLeaves, args.nonLeavesOutOfView, args.nonLeavesOccluded, - OctreeProjectedPolygon::pointInside_calls, - OctreeProjectedPolygon::occludes_calls, - OctreeProjectedPolygon::intersects_calls - ); - //myCoverageMapV2.erase(); - _tree->setDirtyBit(); - setupNewVoxelsForDrawing(); -} - void VoxelSystem::nodeAdded(SharedNodePointer node) { if (node->getType() == NodeType::VoxelServer) { qDebug("VoxelSystem... voxel server %s added...", node->getUUID().toString().toLocal8Bit().constData()); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 0e2ae29475..b49891f8d9 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -14,7 +14,6 @@ #include -#include #include #include #include @@ -68,11 +67,6 @@ public: ViewFrustum* getLastCulledViewFrustum() { return &_lastCulledViewFrustum; } - void writeToSVOFile(const char* filename, VoxelTreeElement* element) const; - bool readFromSVOFile(const char* filename); - bool readFromSquareARGB32Pixels(const char* filename); - bool readFromSchematicFile(const char* filename); - void setMaxVoxels(int maxVoxels); long int getMaxVoxels() const { return _maxVoxels; } unsigned long getVoxelMemoryUsageRAM() const { return _memoryUsageRAM; } @@ -82,66 +76,25 @@ public: void killLocalVoxels(); - virtual void removeOutOfView(); virtual void hideOutOfView(bool forceFullFrustum = false); void inspectForOcclusions(); bool hasViewChanged(); bool isViewChanging(); - bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - VoxelDetail& detail, float& distance, BoxFace& face); - - bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration); - bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration); - - void deleteVoxelAt(float x, float y, float z, float s); - VoxelTreeElement* getVoxelAt(float x, float y, float z, float s) const; - void createVoxel(float x, float y, float z, float s, - unsigned char red, unsigned char green, unsigned char blue, bool destructive = false); - void createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color, bool destructive = false); - - void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destinationTree, bool rebaseToRoot); - void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelTree* destinationTree, bool rebaseToRoot); - void copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelTreeElement* destinationNode); - - void recurseTreeWithOperation(RecurseOctreeOperation operation, void* extraData=NULL); - - CoverageMapV2 myCoverageMapV2; - CoverageMap myCoverageMap; - virtual void elementDeleted(OctreeElement* element); virtual void elementUpdated(OctreeElement* element); - VoxelTreeElement* getVoxelEnclosing(const glm::vec3& point); - -signals: - void importSize(float x, float y, float z); - void importProgress(int progress); - public slots: void nodeAdded(SharedNodePointer node); void nodeKilled(SharedNodePointer node); - void collectStatsForTreesAndVBOs(); // Methods that recurse tree - void showAllLocalVoxels(); - void randomizeVoxelColors(); - void falseColorizeRandom(); - void trueColorize(); - void falseColorizeInView(); - void falseColorizeDistanceFromView(); - void falseColorizeRandomEveryOther(); - void falseColorizeOccluded(); - void falseColorizeOccludedV2(); - void falseColorizeBySource(); void forceRedrawEntireTree(); void clearAllNodesBufferIndex(); void cullSharedFaces(); void showCulledSharedFaces(); - void cancelImport(); - void setDisableFastVoxelPipeline(bool disableFastVoxelPipeline); void setUseVoxelShader(bool useVoxelShader); void setVoxelsAsPoints(bool voxelsAsPoints); @@ -154,18 +107,24 @@ protected: void setupNewVoxelsForDrawing(); static const bool DONT_BAIL_EARLY; // by default we will bail early, if you want to force not bailing, then use this void setupNewVoxelsForDrawingSingleNode(bool allowBailEarly = true); + + /// called on the hide/show thread to hide any out of view voxels and show any newly in view voxels. void checkForCulling(); + + /// single pass to remove old VBO data and fill it with correct current view, used when switching LOD or needing to force + /// a full redraw of everything in view void recreateVoxelGeometryInView(); glm::vec3 computeVoxelVertex(const glm::vec3& startVertex, float voxelScale, int index) const; - virtual void updateArraysDetails(glBufferIndex nodeIndex, const glm::vec3& startVertex, float voxelScale, const nodeColor& color); virtual void copyWrittenDataSegmentToReadArrays(glBufferIndex segmentStart, glBufferIndex segmentEnd); virtual void updateVBOSegment(glBufferIndex segmentStart, glBufferIndex segmentEnd); - virtual void applyScaleAndBindProgram(bool texture); - virtual void removeScaleAndReleaseProgram(bool texture); + + + virtual void applyScaleAndBindProgram(bool texture); /// used in render() to apply shadows and textures + virtual void removeScaleAndReleaseProgram(bool texture); /// stop the shaders for shadows and textures private: // disallow copying of VoxelSystem objects @@ -178,19 +137,6 @@ private: // Operation functions for tree recursion methods static int _nodeCount; - static bool randomColorOperation(OctreeElement* element, void* extraData); - static bool falseColorizeRandomOperation(OctreeElement* element, void* extraData); - static bool trueColorizeOperation(OctreeElement* element, void* extraData); - static bool falseColorizeInViewOperation(OctreeElement* element, void* extraData); - static bool falseColorizeDistanceFromViewOperation(OctreeElement* element, void* extraData); - static bool getDistanceFromViewRangeOperation(OctreeElement* element, void* extraData); - static bool removeOutOfViewOperation(OctreeElement* element, void* extraData); - static bool falseColorizeRandomEveryOtherOperation(OctreeElement* element, void* extraData); - static bool collectStatsForTreesAndVBOsOperation(OctreeElement* element, void* extraData); - static bool falseColorizeOccludedOperation(OctreeElement* element, void* extraData); - static bool falseColorizeSubTreeOperation(OctreeElement* element, void* extraData); - static bool falseColorizeOccludedV2Operation(OctreeElement* element, void* extraData); - static bool falseColorizeBySourceOperation(OctreeElement* element, void* extraData); static bool killSourceVoxelsOperation(OctreeElement* element, void* extraData); static bool forceRedrawEntireTreeOperation(OctreeElement* element, void* extraData); static bool clearAllNodesBufferIndexOperation(OctreeElement* element, void* extraData); @@ -199,7 +145,6 @@ private: static bool hideOutOfViewOperation(OctreeElement* element, void* extraData); static bool hideAllSubTreeOperation(OctreeElement* element, void* extraData); static bool showAllSubTreeOperation(OctreeElement* element, void* extraData); - static bool showAllLocalVoxelsOperation(OctreeElement* element, void* extraData); static bool getVoxelEnclosingOperation(OctreeElement* element, void* extraData); static bool recreateVoxelGeometryInViewOperation(OctreeElement* element, void* extraData); diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 51f919130b..29e46fc816 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -20,7 +20,6 @@ using namespace std; const float FINGERTIP_COLLISION_RADIUS = 0.01f; -const float FINGERTIP_VOXEL_SIZE = 0.05f; const float PALM_COLLISION_RADIUS = 0.03f; @@ -29,7 +28,6 @@ Hand::Hand(Avatar* owningAvatar) : _owningAvatar(owningAvatar), _renderAlpha(1.0), - _ballColor(0.0, 0.0, 0.4), _collisionCenter(0,0,0), _collisionAge(0), _collisionDuration(0) @@ -37,13 +35,6 @@ Hand::Hand(Avatar* owningAvatar) : } void Hand::init() { - // Different colors for my hand and others' hands - if (_owningAvatar && _owningAvatar->isMyAvatar()) { - _ballColor = glm::vec3(0.0, 0.4, 0.0); - } - else { - _ballColor = glm::vec3(0.0, 0.0, 0.4); - } } void Hand::reset() { @@ -61,61 +52,6 @@ void Hand::simulate(float deltaTime, bool isMine) { // Iterate hand controllers, take actions as needed for (size_t i = 0; i < getNumPalms(); ++i) { PalmData& palm = getPalms()[i]; - if (palm.isActive()) { - FingerData& finger = palm.getFingers()[0]; // Sixense has only one finger - glm::vec3 fingerTipPosition = finger.getTipPosition(); - - - if (palm.getControllerButtons() & BUTTON_1) { - if (glm::length(fingerTipPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { - // TODO: we need to move this code to JS so it can access the editVoxels.js color palette - QColor paintColor(128,128,128); - Application::getInstance()->makeVoxel(fingerTipPosition, - FINGERTIP_VOXEL_SIZE, - paintColor.red(), - paintColor.green(), - paintColor.blue(), - true); - _lastFingerAddVoxel = fingerTipPosition; - } - } else if (palm.getControllerButtons() & BUTTON_2) { - if (glm::length(fingerTipPosition - _lastFingerDeleteVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { - Application::getInstance()->removeVoxel(fingerTipPosition, FINGERTIP_VOXEL_SIZE); - _lastFingerDeleteVoxel = fingerTipPosition; - } - } - - // Voxel Drumming with fingertips if enabled - if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelDrumming)) { - VoxelTreeElement* fingerNode = Application::getInstance()->getVoxels()->getVoxelEnclosing( - glm::vec3(fingerTipPosition / (float)TREE_SCALE)); - if (fingerNode) { - if (!palm.getIsCollidingWithVoxel()) { - // Collision has just started - palm.setIsCollidingWithVoxel(true); - handleVoxelCollision(&palm, fingerTipPosition, fingerNode, deltaTime); - // Set highlight voxel - VoxelDetail voxel; - glm::vec3 pos = fingerNode->getCorner(); - voxel.x = pos.x; - voxel.y = pos.y; - voxel.z = pos.z; - voxel.s = fingerNode->getScale(); - voxel.red = fingerNode->getColor()[0]; - voxel.green = fingerNode->getColor()[1]; - voxel.blue = fingerNode->getColor()[2]; - Application::getInstance()->setHighlightVoxel(voxel); - Application::getInstance()->setIsHighlightVoxel(true); - } - } else { - if (palm.getIsCollidingWithVoxel()) { - // Collision has just ended - palm.setIsCollidingWithVoxel(false); - Application::getInstance()->setIsHighlightVoxel(false); - } - } - } - } palm.setLastControllerButtons(palm.getControllerButtons()); } } @@ -349,7 +285,6 @@ void Hand::renderLeapHands(bool isMine) { const float alpha = 1.0f; - //const glm::vec3 handColor = _ballColor; const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color glEnable(GL_DEPTH_TEST); diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index 059a83f18a..bf335d1bdd 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -51,7 +51,6 @@ public: void reset(); void simulate(float deltaTime, bool isMine); void render(bool isMine); - void setBallColor (glm::vec3 ballColor ) { _ballColor = ballColor; } // getters const glm::vec3& getLeapFingerTipBallPosition (int ball) const { return _leapFingerTipBalls [ball].position;} @@ -69,7 +68,6 @@ private: Avatar* _owningAvatar; float _renderAlpha; - glm::vec3 _ballColor; std::vector _leapFingerTipBalls; std::vector _leapFingerRootBalls; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 02d14b7a2c..51fcad20ae 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -810,7 +810,7 @@ void MyAvatar::updateCollisionWithVoxels(float deltaTime, float radius) { const float VOXEL_COLLISION_FREQUENCY = 0.5f; glm::vec3 penetration; float pelvisFloatingHeight = getPelvisFloatingHeight(); - if (Application::getInstance()->getVoxels()->findCapsulePenetration( + if (Application::getInstance()->getVoxelTree()->findCapsulePenetration( _position - glm::vec3(0.0f, pelvisFloatingHeight - radius, 0.0f), _position + glm::vec3(0.0f, getSkeletonHeight() - pelvisFloatingHeight + radius, 0.0f), radius, penetration)) { _lastCollisionPosition = _position; diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index 2d4074f125..d15852e11f 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -18,8 +18,6 @@ #include "AudioInjector.h" -int abstractAudioPointerMeta = qRegisterMetaType("AbstractAudioInterface*"); - AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) : _sound(sound), _options(injectorOptions) diff --git a/libraries/audio/src/AudioInjector.h b/libraries/audio/src/AudioInjector.h index 1e09a2c3c2..beff33a9ef 100644 --- a/libraries/audio/src/AudioInjector.h +++ b/libraries/audio/src/AudioInjector.h @@ -18,9 +18,6 @@ #include "AudioInjectorOptions.h" #include "Sound.h" -class AbstractAudioInterface; -class AudioScriptingInterface; - class AudioInjector : public QObject { Q_OBJECT public: diff --git a/libraries/audio/src/AudioScriptingInterface.cpp b/libraries/audio/src/AudioScriptingInterface.cpp index d09a4eef86..1fe2c19922 100644 --- a/libraries/audio/src/AudioScriptingInterface.cpp +++ b/libraries/audio/src/AudioScriptingInterface.cpp @@ -25,4 +25,26 @@ void AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions connect(injectorThread, SIGNAL(finished()), injectorThread, SLOT(deleteLater())); injectorThread->start(); -} \ No newline at end of file +} + +void AudioScriptingInterface::startDrumSound(float volume, float frequency, float duration, float decay, + const AudioInjectorOptions* injectorOptions) { + + Sound* sound = new Sound(volume, frequency, duration, decay); + AudioInjector* injector = new AudioInjector(sound, *injectorOptions); + sound->setParent(injector); + + QThread* injectorThread = new QThread(); + + injector->moveToThread(injectorThread); + + // start injecting when the injector thread starts + connect(injectorThread, SIGNAL(started()), injector, SLOT(injectAudio())); + + // connect the right slots and signals so that the AudioInjector is killed once the injection is complete + connect(injector, SIGNAL(finished()), injector, SLOT(deleteLater())); + connect(injector, SIGNAL(finished()), injectorThread, SLOT(quit())); + connect(injectorThread, SIGNAL(finished()), injectorThread, SLOT(deleteLater())); + + injectorThread->start(); +} diff --git a/libraries/audio/src/AudioScriptingInterface.h b/libraries/audio/src/AudioScriptingInterface.h index bded426cbd..f758923513 100644 --- a/libraries/audio/src/AudioScriptingInterface.h +++ b/libraries/audio/src/AudioScriptingInterface.h @@ -18,6 +18,8 @@ class AudioScriptingInterface : public QObject { Q_OBJECT public slots: static void playSound(Sound* sound, const AudioInjectorOptions* injectorOptions = NULL); + static void startDrumSound(float volume, float frequency, float duration, float decay, + const AudioInjectorOptions* injectorOptions = NULL); }; #endif /* defined(__hifi__AudioScriptingInterface__) */ diff --git a/libraries/audio/src/Sound.cpp b/libraries/audio/src/Sound.cpp index 07eec031b5..83b4d8a79c 100644 --- a/libraries/audio/src/Sound.cpp +++ b/libraries/audio/src/Sound.cpp @@ -9,6 +9,8 @@ #include +#include + #include #include #include @@ -16,8 +18,51 @@ #include #include +#include + +#include "AudioRingBuffer.h" #include "Sound.h" +// procedural audio version of Sound +Sound::Sound(float volume, float frequency, float duration, float decay, QObject* parent) : + QObject(parent) +{ + static char monoAudioData[MAX_PACKET_SIZE]; + static int16_t* monoAudioSamples = (int16_t*)(monoAudioData); + + float t; + const float AUDIO_CALLBACK_MSECS = (float) NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL / (float)SAMPLE_RATE * 1000.0; + const float MAX_VOLUME = 32000.f; + const float MAX_DURATION = 2.f; + const float MIN_AUDIBLE_VOLUME = 0.001f; + const float NOISE_MAGNITUDE = 0.02f; + const int MAX_SAMPLE_VALUE = std::numeric_limits::max(); + const int MIN_SAMPLE_VALUE = std::numeric_limits::min(); + int numSamples = NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; // we add sounds in chunks of this many samples + + int chunkStartingSample = 0; + float waveFrequency = (frequency / SAMPLE_RATE) * PI_TIMES_TWO; + while (volume > 0.f) { + for (int i = 0; i < numSamples; i++) { + t = (float)chunkStartingSample + (float)i; + float sample = sinf(t * waveFrequency); + sample += ((randFloat() - 0.5f) * NOISE_MAGNITUDE); + sample *= volume * MAX_VOLUME; + + monoAudioSamples[i] = glm::clamp((int)sample, MIN_SAMPLE_VALUE, MAX_SAMPLE_VALUE); + volume *= (1.f - decay); + } + // add the monoAudioSamples to our actual output Byte Array + _byteArray.append(monoAudioData, numSamples * sizeof(int16_t)); + chunkStartingSample += numSamples; + duration = glm::clamp(duration - (AUDIO_CALLBACK_MSECS / 1000.f), 0.f, MAX_DURATION); + //qDebug() << "decaying... _duration=" << _duration; + if (duration == 0.f || (volume < MIN_AUDIBLE_VOLUME)) { + volume = 0.f; + } + } +} + Sound::Sound(const QUrl& sampleURL, QObject* parent) : QObject(parent) { diff --git a/libraries/audio/src/Sound.h b/libraries/audio/src/Sound.h index c17bae2582..7956343d46 100644 --- a/libraries/audio/src/Sound.h +++ b/libraries/audio/src/Sound.h @@ -17,7 +17,8 @@ class QNetworkReply; class Sound : public QObject { Q_OBJECT public: - Sound(const QUrl& sampleURL, QObject* parent = 0); + Sound(const QUrl& sampleURL, QObject* parent = NULL); + Sound(float volume, float frequency, float duration, float decay, QObject* parent = NULL); const QByteArray& getByteArray() { return _byteArray; } diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 051d4f5ca2..446eb25a50 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -330,7 +330,9 @@ void Octree::readBitstreamToTree(const unsigned char * bitstream, unsigned long void Octree::deleteOctreeElementAt(float x, float y, float z, float s) { unsigned char* octalCode = pointToOctalCode(x,y,z,s); + lockForWrite(); deleteOctalCodeFromTree(octalCode); + unlock(); delete[] octalCode; // cleanup memory } @@ -586,9 +588,16 @@ bool findRayIntersectionOp(OctreeElement* node, void* extraData) { } bool Octree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElement*& node, float& distance, BoxFace& face) { + OctreeElement*& node, float& distance, BoxFace& face, bool tryLock) { RayArgs args = { origin / (float)(TREE_SCALE), direction, node, distance, face }; - recurseTreeWithOperation(findRayIntersectionOp, &args); + + if (!tryLock) { + lockForRead(); + } + if (tryLock && tryLockForRead()) { + recurseTreeWithOperation(findRayIntersectionOp, &args); + unlock(); + } return args.found; } @@ -624,7 +633,7 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) { } bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, - void** penetratedObject) { + void** penetratedObject, bool tryLock) { SphereArgs args = { center / (float)(TREE_SCALE), @@ -633,9 +642,16 @@ bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::v false, NULL }; penetration = glm::vec3(0.0f, 0.0f, 0.0f); - recurseTreeWithOperation(findSpherePenetrationOp, &args); - if (penetratedObject) { - *penetratedObject = args.penetratedObject; + + if (!tryLock) { + lockForRead(); + } + if (tryLock && tryLockForRead()) { + recurseTreeWithOperation(findSpherePenetrationOp, &args); + if (penetratedObject) { + *penetratedObject = args.penetratedObject; + } + unlock(); } return args.found; } @@ -670,17 +686,67 @@ bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) { return false; } -bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) { +bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, + glm::vec3& penetration, bool tryLock) { + CapsuleArgs args = { start / (float)(TREE_SCALE), end / (float)(TREE_SCALE), radius / (float)(TREE_SCALE), - penetration }; + penetration, + false }; penetration = glm::vec3(0.0f, 0.0f, 0.0f); - recurseTreeWithOperation(findCapsulePenetrationOp, &args); + + if (!tryLock) { + lockForRead(); + } + if (tryLock && tryLockForRead()) { + recurseTreeWithOperation(findCapsulePenetrationOp, &args); + unlock(); + } return args.found; } +class GetElementEnclosingArgs { +public: + OctreeElement* element; + glm::vec3 point; +}; + +// Find the smallest colored voxel enclosing a point (if there is one) +bool getElementEnclosingOperation(OctreeElement* element, void* extraData) { + GetElementEnclosingArgs* args = static_cast(extraData); + AABox elementBox = element->getAABox(); + if (elementBox.contains(args->point)) { + if (element->hasContent() && element->isLeaf()) { + // we've reached a solid leaf containing the point, return the node. + args->element = element; + return false; + } + } else { + // The point is not inside this voxel, so stop recursing. + return false; + } + return true; // keep looking +} + +OctreeElement* Octree::getElementEnclosingPoint(const glm::vec3& point, bool tryLock) { + GetElementEnclosingArgs args; + args.point = point; + args.element = NULL; + + if (!tryLock) { + lockForRead(); + } + if (tryLock && tryLockForRead()) { + recurseTreeWithOperation(getElementEnclosingOperation, (void*)&args); + unlock(); + } + return args.element; +} + + + int Octree::encodeTreeBitstream(OctreeElement* node, OctreePacketData* packetData, OctreeElementBag& bag, EncodeBitstreamParams& params) { diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index e0c7f414f8..9db83d47b1 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -12,7 +12,6 @@ #include #include -//#include "CoverageMap.h" class CoverageMap; class ReadBitstreamToTreeParams; class Octree; @@ -223,12 +222,15 @@ public: void setDirtyBit() { _isDirty = true; } bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElement*& node, float& distance, BoxFace& face); + OctreeElement*& node, float& distance, BoxFace& face, bool tryLock = true); bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, - void** penetratedObject = NULL); + void** penetratedObject = NULL, bool tryLock = true); - bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration); + bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, + glm::vec3& penetration, bool tryLock = true); + + OctreeElement* getElementEnclosingPoint(const glm::vec3& point, bool tryLock = true); // Note: this assumes the fileFormat is the HIO individual voxels code files void loadOctreeFile(const char* fileName, bool wantColorRandomizer); @@ -236,9 +238,6 @@ public: // these will read/write files that match the wireformat, excluding the 'V' leading void writeToSVOFile(const char* filename, OctreeElement* node = NULL); bool readFromSVOFile(const char* filename); - // reads voxels from square image with alpha as a Y-axis - bool readFromSquareARGB32Pixels(const char *filename); - bool readFromSchematicFile(const char* filename); // Octree does not currently handle its own locking, caller must use these to lock/unlock void lockForRead() { lock.lockForRead(); } diff --git a/libraries/octree/src/OctreeRenderer.cpp b/libraries/octree/src/OctreeRenderer.cpp index 06007cb0dc..8fdc2139af 100644 --- a/libraries/octree/src/OctreeRenderer.cpp +++ b/libraries/octree/src/OctreeRenderer.cpp @@ -14,16 +14,32 @@ #include #include "OctreeRenderer.h" -OctreeRenderer::OctreeRenderer() { - _tree = NULL; - _viewFrustum = NULL; +OctreeRenderer::OctreeRenderer() : + _tree(NULL), + _managedTree(false), + _viewFrustum(NULL) +{ } void OctreeRenderer::init() { - _tree = createTree(); + if (!_tree) { + _tree = createTree(); + _managedTree = true; + } } OctreeRenderer::~OctreeRenderer() { + if (_tree && _managedTree) { + delete _tree; + } +} + +void OctreeRenderer::setTree(Octree* newTree) { + if (_tree && _managedTree) { + delete _tree; + _managedTree = false; + } + _tree = newTree; } void OctreeRenderer::processDatagram(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { diff --git a/libraries/octree/src/OctreeRenderer.h b/libraries/octree/src/OctreeRenderer.h index 52b0a3fc2e..2e9762a883 100644 --- a/libraries/octree/src/OctreeRenderer.h +++ b/libraries/octree/src/OctreeRenderer.h @@ -44,6 +44,8 @@ public: virtual PacketType getMyQueryMessageType() const = 0; virtual PacketType getExpectedPacketType() const = 0; virtual void renderElement(OctreeElement* element, RenderArgs* args) = 0; + + virtual void setTree(Octree* newTree); /// process incoming data virtual void processDatagram(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode); @@ -63,6 +65,7 @@ public: void clear(); protected: Octree* _tree; + bool _managedTree; ViewFrustum* _viewFrustum; }; diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index e97e05dcb9..cab186ea6e 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -16,7 +16,6 @@ #include -//#include "CoverageMap.h" #include "GeometryUtil.h" #include "SharedUtil.h" #include "ViewFrustum.h" diff --git a/libraries/voxels/src/VoxelPacketData.cpp b/libraries/voxels/src/VoxelPacketData.cpp deleted file mode 100644 index 0053cff226..0000000000 --- a/libraries/voxels/src/VoxelPacketData.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// -// VoxelPacketData.cpp -// hifi -// -// Created by Brad Hefta-Gaub on 11/19/2013. -// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. -// - -#include -#include "VoxelPacketData.h" - -// currently just an alias for OctreePacketData - -VoxelPacketData::VoxelPacketData(bool enableCompression, int maxFinalizedSize) : - OctreePacketData(enableCompression, maxFinalizedSize) { -}; diff --git a/libraries/voxels/src/VoxelPacketData.h b/libraries/voxels/src/VoxelPacketData.h deleted file mode 100644 index 637a91d0ec..0000000000 --- a/libraries/voxels/src/VoxelPacketData.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// VoxelPacketData.h -// hifi -// -// Created by Brad Hefta-Gaub on 11/19/2013 -// -// TO DO: -// -// * add stats tracking for number of unique colors and consecutive identical colors. -// (as research for color dictionaries and RLE) -// -// * further testing of compression to determine optimal configuration for performance and compression -// -// * improve semantics for "reshuffle" - current approach will work for now and with compression -// but wouldn't work with RLE because the colors in the levels would get reordered and RLE would need -// to be recalculated -// - -#ifndef __hifi__VoxelPacketData__ -#define __hifi__VoxelPacketData__ - -#include - -#include - -#include "VoxelConstants.h" -#include "VoxelTreeElement.h" - -/// Handles packing of the data portion of PacketType_VOXEL_DATA messages. -class VoxelPacketData : public OctreePacketData { -public: - VoxelPacketData(bool enableCompression = false, int maxFinalizedSize = MAX_OCTREE_PACKET_DATA_SIZE); -}; - -#endif /* defined(__hifi__VoxelPacketData__) */ \ No newline at end of file diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 08ec2cfc3c..ea784b2e16 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -47,28 +47,12 @@ void VoxelTree::createVoxel(float x, float y, float z, float s, unsigned char red, unsigned char green, unsigned char blue, bool destructive) { unsigned char* voxelData = pointToVoxel(x,y,z,s,red,green,blue); - - //int length = bytesRequiredForCodeLength(numberOfThreeBitSectionsInCode(voxelData)) + BYTES_PER_COLOR; - //printf("createVoxel()..."); - //outputBufferBits(voxelData,length); - - this->readCodeColorBufferToTree(voxelData, destructive); + lockForWrite(); + readCodeColorBufferToTree(voxelData, destructive); + unlock(); delete[] voxelData; } - -void VoxelTree::createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color, bool destructive) { - glm::vec3 distance = point2 - point1; - glm::vec3 items = distance / unitSize; - int maxItems = std::max(items.x, std::max(items.y, items.z)); - glm::vec3 increment = distance * (1.0f/ maxItems); - glm::vec3 pointAt = point1; - for (int i = 0; i <= maxItems; i++ ) { - pointAt += increment; - createVoxel(pointAt.x, pointAt.y, pointAt.z, unitSize, color[0], color[1], color[2], destructive); - } -} - class NodeChunkArgs { public: VoxelTree* thisVoxelTree; @@ -577,4 +561,3 @@ int VoxelTree::processEditPacketData(PacketType packetType, const unsigned char* return 0; } } - diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index b5f28811fc..2079ab91b2 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -9,17 +9,9 @@ #ifndef __hifi__VoxelTree__ #define __hifi__VoxelTree__ -#include -#include -#include #include -#include -#include -#include #include "VoxelTreeElement.h" -#include "VoxelPacketData.h" -#include "VoxelSceneStats.h" #include "VoxelEditPacketSender.h" class ReadCodeColorBufferToTreeArgs; @@ -38,11 +30,8 @@ public: void createVoxel(float x, float y, float z, float s, unsigned char red, unsigned char green, unsigned char blue, bool destructive = false); - void createLine(glm::vec3 point1, glm::vec3 point2, float unitSize, rgbColor color, bool destructive = false); - void nudgeSubTree(VoxelTreeElement* elementToNudge, const glm::vec3& nudgeAmount, VoxelEditPacketSender& voxelEditSender); - /// reads voxels from square image with alpha as a Y-axis bool readFromSquareARGB32Pixels(const char *filename); @@ -55,16 +44,6 @@ public: virtual bool handlesEditPacketType(PacketType packetType) const; virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, const unsigned char* editData, int maxLength, const SharedNodePointer& node); - void processSetVoxelsBitstream(const unsigned char* bitstream, int bufferSizeBytes); - -/** -signals: - void importSize(float x, float y, float z); - void importProgress(int progress); - -public slots: - void cancelImport(); -**/ private: // helper functions for nudgeSubTree diff --git a/libraries/voxels/src/VoxelTreeElement.cpp b/libraries/voxels/src/VoxelTreeElement.cpp index 3f8af58afd..5609e279d7 100644 --- a/libraries/voxels/src/VoxelTreeElement.cpp +++ b/libraries/voxels/src/VoxelTreeElement.cpp @@ -39,8 +39,7 @@ void VoxelTreeElement::init(unsigned char* octalCode) { setVoxelSystem(NULL); setBufferIndex(GLBUFFER_INDEX_UNKNOWN); _falseColored = false; // assume true color - _currentColor[0] = _currentColor[1] = _currentColor[2] = _currentColor[3] = 0; - _trueColor[0] = _trueColor[1] = _trueColor[2] = _trueColor[3] = 0; + _color[0] = _color[1] = _color[2] = _color[3] = 0; _density = 0.0f; OctreeElement::init(octalCode); _voxelMemoryUsage += sizeof(VoxelTreeElement); @@ -115,39 +114,9 @@ void VoxelTreeElement::setVoxelSystem(VoxelSystem* voxelSystem) { } } - -void VoxelTreeElement::setFalseColor(colorPart red, colorPart green, colorPart blue) { - if (_falseColored != true || _currentColor[0] != red || _currentColor[1] != green || _currentColor[2] != blue) { - _falseColored=true; - _currentColor[0] = red; - _currentColor[1] = green; - _currentColor[2] = blue; - _currentColor[3] = 1; // XXXBHG - False colors are always considered set - _isDirty = true; - markWithChangedTime(); - } -} - -void VoxelTreeElement::setFalseColored(bool isFalseColored) { - if (_falseColored != isFalseColored) { - // if we were false colored, and are no longer false colored, then swap back - if (_falseColored && !isFalseColored) { - memcpy(&_currentColor,&_trueColor,sizeof(nodeColor)); - } - _falseColored = isFalseColored; - _isDirty = true; - _density = 1.0f; // If color set, assume leaf, re-averaging will update density if needed. - markWithChangedTime(); - } -}; - - void VoxelTreeElement::setColor(const nodeColor& color) { - if (_trueColor[0] != color[0] || _trueColor[1] != color[1] || _trueColor[2] != color[2]) { - memcpy(&_trueColor,&color,sizeof(nodeColor)); - if (!_falseColored) { - memcpy(&_currentColor,&color,sizeof(nodeColor)); - } + if (_color[0] != color[0] || _color[1] != color[1] || _color[2] != color[2]) { + memcpy(&_color,&color,sizeof(nodeColor)); _isDirty = true; if (color[3]) { _density = 1.0f; // If color set, assume leaf, re-averaging will update density if needed. @@ -168,7 +137,7 @@ void VoxelTreeElement::calculateAverageFromChildren() { VoxelTreeElement* childAt = getChildAtIndex(i); if (childAt && childAt->isColored()) { for (int j = 0; j < 3; j++) { - colorArray[j] += childAt->getTrueColor()[j]; // color averaging should always be based on true colors + colorArray[j] += childAt->getColor()[j]; // color averaging should always be based on true colors } colorArray[3]++; } @@ -260,9 +229,9 @@ bool VoxelTreeElement::findSpherePenetration(const glm::vec3& center, float radi voxelDetails->y = _box.getCorner().y; voxelDetails->z = _box.getCorner().z; voxelDetails->s = _box.getScale(); - voxelDetails->red = getTrueColor()[RED_INDEX]; - voxelDetails->green = getTrueColor()[GREEN_INDEX]; - voxelDetails->blue = getTrueColor()[BLUE_INDEX]; + voxelDetails->red = getColor()[RED_INDEX]; + voxelDetails->green = getColor()[GREEN_INDEX]; + voxelDetails->blue = getColor()[BLUE_INDEX]; *penetratedObject = (void*)voxelDetails; } diff --git a/libraries/voxels/src/VoxelTreeElement.h b/libraries/voxels/src/VoxelTreeElement.h index 83544bea32..c88fd6d207 100644 --- a/libraries/voxels/src/VoxelTreeElement.h +++ b/libraries/voxels/src/VoxelTreeElement.h @@ -57,14 +57,10 @@ public: virtual bool isRendered() const { return isKnownBufferIndex(); } - bool isColored() const { return _trueColor[3] == 1; } + bool isColored() const { return _color[3] == 1; } - void setFalseColor(colorPart red, colorPart green, colorPart blue); - void setFalseColored(bool isFalseColored); - bool getFalseColored() { return _falseColored; } void setColor(const nodeColor& color); - const nodeColor& getTrueColor() const { return _trueColor; } - const nodeColor& getColor() const { return _currentColor; } + const nodeColor& getColor() const { return _color; } void setDensity(float density) { _density = density; } float getDensity() const { return _density; } @@ -92,8 +88,7 @@ protected: float _density; /// Client and server, If leaf: density = 1, if internal node: 0-1 density of voxels inside, 4 bytes - nodeColor _trueColor; /// Client and server, true color of this voxel, 4 bytes - nodeColor _currentColor; /// Client only, false color of this voxel, 4 bytes + nodeColor _color; /// Client and server, true color of this voxel, 4 bytes private: unsigned char _exteriorOcclusions; ///< Exterior shared partition boundaries that are completely occupied diff --git a/libraries/voxels/src/VoxelsScriptingInterface.cpp b/libraries/voxels/src/VoxelsScriptingInterface.cpp index db61460d69..2aecb2d457 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.cpp +++ b/libraries/voxels/src/VoxelsScriptingInterface.cpp @@ -47,9 +47,7 @@ void VoxelsScriptingInterface::setVoxelNonDestructive(float x, float y, float z, // handle the local tree also... if (_tree) { - _tree->lockForWrite(); _tree->createVoxel(addVoxelDetail.x, addVoxelDetail.y, addVoxelDetail.z, addVoxelDetail.s, red, green, blue, false); - _tree->unlock(); } } @@ -64,9 +62,7 @@ void VoxelsScriptingInterface::setVoxel(float x, float y, float z, float scale, // handle the local tree also... if (_tree) { - _tree->lockForWrite(); _tree->createVoxel(addVoxelDetail.x, addVoxelDetail.y, addVoxelDetail.z, addVoxelDetail.s, red, green, blue, true); - _tree->unlock(); } } @@ -80,9 +76,7 @@ void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale // handle the local tree also... if (_tree) { - _tree->lockForWrite(); _tree->deleteVoxelAt(deleteVoxelDetail.x, deleteVoxelDetail.y, deleteVoxelDetail.z, deleteVoxelDetail.s); - _tree->unlock(); } } @@ -90,21 +84,18 @@ void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale RayToVoxelIntersectionResult VoxelsScriptingInterface::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; @@ -127,3 +118,22 @@ glm::vec3 VoxelsScriptingInterface::getFaceVector(const QString& face) { return glm::vec3(0, 0, 0); //error case } +VoxelDetail VoxelsScriptingInterface::getVoxelEnclosingPoint(const glm::vec3& point) { + VoxelDetail result = { 0.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0 }; + if (_tree) { + OctreeElement* element = _tree->getElementEnclosingPoint(point / (float)TREE_SCALE); + if (element) { + VoxelTreeElement* voxel = static_cast(element); + result.x = voxel->getCorner().x; + result.y = voxel->getCorner().y; + result.z = voxel->getCorner().z; + result.s = voxel->getScale(); + result.red = voxel->getColor()[0]; + result.green = voxel->getColor()[1]; + result.blue = voxel->getColor()[2]; + } + } + return result; +} + + diff --git a/libraries/voxels/src/VoxelsScriptingInterface.h b/libraries/voxels/src/VoxelsScriptingInterface.h index fb0bd6ab03..d07d2a785c 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.h +++ b/libraries/voxels/src/VoxelsScriptingInterface.h @@ -70,6 +70,11 @@ public slots: /// returns a voxel space axis aligned vector for the face, useful in doing voxel math glm::vec3 getFaceVector(const QString& face); + + /// checks the local voxel tree for the smallest voxel enclosing the point + /// \param point the x,y,z coordinates of the point (in meter units) + /// \return VoxelDetail - if no voxel encloses the point then VoxelDetail items will be 0 + VoxelDetail getVoxelEnclosingPoint(const glm::vec3& point); private: void queueVoxelAdd(PacketType addPacketType, VoxelDetail& addVoxelDetails); diff --git a/SvoViewer/CMakeLists.txt b/svo-viewer/CMakeLists.txt similarity index 95% rename from SvoViewer/CMakeLists.txt rename to svo-viewer/CMakeLists.txt index 3cc47678d7..24f07c5a6d 100644 --- a/SvoViewer/CMakeLists.txt +++ b/svo-viewer/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8) set(ROOT_DIR ..) set(MACRO_DIR ${ROOT_DIR}/cmake/macros) -set(TARGET_NAME SvoViewer) +set(TARGET_NAME svo-viewer) project(${TARGET_NAME}) # setup for find modules @@ -42,9 +42,9 @@ endif (WIN32) include(${MACRO_DIR}/IncludeGLM.cmake) include_glm(${TARGET_NAME} ${ROOT_DIR}) -# create the ${TARGET_NAME}Config.h file based on GL_HEADERS above -configure_file(${TARGET_NAME}Config.h.in ${PROJECT_BINARY_DIR}/includes/${TARGET_NAME}Config.h) -configure_file(${TARGET_NAME}Version.h.in ${PROJECT_BINARY_DIR}/includes/${TARGET_NAME}Version.h) +# create the ${TARGET_NAME}-config.h file based on GL_HEADERS above +configure_file(${TARGET_NAME}-config.h.in ${PROJECT_BINARY_DIR}/includes/${TARGET_NAME}-config.h) +configure_file(${TARGET_NAME}-version.h.in ${PROJECT_BINARY_DIR}/includes/${TARGET_NAME}-version.h) # grab the implementation and header files from src dirs file(GLOB APPLICATION_SRCS src/*.c src/*.cpp src/*.h) @@ -81,7 +81,7 @@ if (APPLE) # configure CMake to use a custom Info.plist SET_TARGET_PROPERTIES( ${this_target} PROPERTIES MACOSX_BUNDLE_INFO_PLIST MacOSXBundleInfo.plist.in ) - set(MACOSX_BUNDLE_BUNDLE_NAME SvoViewer) + set(MACOSX_BUNDLE_BUNDLE_NAME svo-viewer) set(MACOSX_BUNDLE_GUI_IDENTIFIER io.highfidelity.${TARGET_NAME}) # set how the icon shows up in the Info.plist file diff --git a/SvoViewer/external/freeglut/Copying.txt b/svo-viewer/external/freeglut/Copying.txt similarity index 100% rename from SvoViewer/external/freeglut/Copying.txt rename to svo-viewer/external/freeglut/Copying.txt diff --git a/SvoViewer/external/freeglut/bin/freeglut.dll b/svo-viewer/external/freeglut/bin/freeglut.dll similarity index 100% rename from SvoViewer/external/freeglut/bin/freeglut.dll rename to svo-viewer/external/freeglut/bin/freeglut.dll diff --git a/SvoViewer/external/freeglut/bin/x64/freeglut.dll b/svo-viewer/external/freeglut/bin/x64/freeglut.dll similarity index 100% rename from SvoViewer/external/freeglut/bin/x64/freeglut.dll rename to svo-viewer/external/freeglut/bin/x64/freeglut.dll diff --git a/SvoViewer/external/freeglut/include/GL/freeglut.h b/svo-viewer/external/freeglut/include/GL/freeglut.h similarity index 100% rename from SvoViewer/external/freeglut/include/GL/freeglut.h rename to svo-viewer/external/freeglut/include/GL/freeglut.h diff --git a/SvoViewer/external/freeglut/include/GL/freeglut_ext.h b/svo-viewer/external/freeglut/include/GL/freeglut_ext.h similarity index 100% rename from SvoViewer/external/freeglut/include/GL/freeglut_ext.h rename to svo-viewer/external/freeglut/include/GL/freeglut_ext.h diff --git a/SvoViewer/external/freeglut/include/GL/freeglut_std.h b/svo-viewer/external/freeglut/include/GL/freeglut_std.h similarity index 100% rename from SvoViewer/external/freeglut/include/GL/freeglut_std.h rename to svo-viewer/external/freeglut/include/GL/freeglut_std.h diff --git a/SvoViewer/external/freeglut/include/GL/glut.h b/svo-viewer/external/freeglut/include/GL/glut.h similarity index 100% rename from SvoViewer/external/freeglut/include/GL/glut.h rename to svo-viewer/external/freeglut/include/GL/glut.h diff --git a/SvoViewer/external/freeglut/lib/freeglut.lib b/svo-viewer/external/freeglut/lib/freeglut.lib similarity index 100% rename from SvoViewer/external/freeglut/lib/freeglut.lib rename to svo-viewer/external/freeglut/lib/freeglut.lib diff --git a/SvoViewer/external/freeglut/lib/x64/freeglut.lib b/svo-viewer/external/freeglut/lib/x64/freeglut.lib similarity index 100% rename from SvoViewer/external/freeglut/lib/x64/freeglut.lib rename to svo-viewer/external/freeglut/lib/x64/freeglut.lib diff --git a/SvoViewer/external/glew/LICENSE.txt b/svo-viewer/external/glew/LICENSE.txt similarity index 100% rename from SvoViewer/external/glew/LICENSE.txt rename to svo-viewer/external/glew/LICENSE.txt diff --git a/SvoViewer/external/glew/bin/Release MX/Win32/glew32mx.dll b/svo-viewer/external/glew/bin/Release MX/Win32/glew32mx.dll similarity index 100% rename from SvoViewer/external/glew/bin/Release MX/Win32/glew32mx.dll rename to svo-viewer/external/glew/bin/Release MX/Win32/glew32mx.dll diff --git a/SvoViewer/external/glew/bin/Release MX/x64/glew32mx.dll b/svo-viewer/external/glew/bin/Release MX/x64/glew32mx.dll similarity index 100% rename from SvoViewer/external/glew/bin/Release MX/x64/glew32mx.dll rename to svo-viewer/external/glew/bin/Release MX/x64/glew32mx.dll diff --git a/SvoViewer/external/glew/bin/Release/Win32/glew32.dll b/svo-viewer/external/glew/bin/Release/Win32/glew32.dll similarity index 100% rename from SvoViewer/external/glew/bin/Release/Win32/glew32.dll rename to svo-viewer/external/glew/bin/Release/Win32/glew32.dll diff --git a/SvoViewer/external/glew/bin/Release/Win32/glewinfo.exe b/svo-viewer/external/glew/bin/Release/Win32/glewinfo.exe similarity index 100% rename from SvoViewer/external/glew/bin/Release/Win32/glewinfo.exe rename to svo-viewer/external/glew/bin/Release/Win32/glewinfo.exe diff --git a/SvoViewer/external/glew/bin/Release/Win32/visualinfo.exe b/svo-viewer/external/glew/bin/Release/Win32/visualinfo.exe similarity index 100% rename from SvoViewer/external/glew/bin/Release/Win32/visualinfo.exe rename to svo-viewer/external/glew/bin/Release/Win32/visualinfo.exe diff --git a/SvoViewer/external/glew/bin/Release/x64/glew32.dll b/svo-viewer/external/glew/bin/Release/x64/glew32.dll similarity index 100% rename from SvoViewer/external/glew/bin/Release/x64/glew32.dll rename to svo-viewer/external/glew/bin/Release/x64/glew32.dll diff --git a/SvoViewer/external/glew/bin/Release/x64/glewinfo.exe b/svo-viewer/external/glew/bin/Release/x64/glewinfo.exe similarity index 100% rename from SvoViewer/external/glew/bin/Release/x64/glewinfo.exe rename to svo-viewer/external/glew/bin/Release/x64/glewinfo.exe diff --git a/SvoViewer/external/glew/bin/Release/x64/visualinfo.exe b/svo-viewer/external/glew/bin/Release/x64/visualinfo.exe similarity index 100% rename from SvoViewer/external/glew/bin/Release/x64/visualinfo.exe rename to svo-viewer/external/glew/bin/Release/x64/visualinfo.exe diff --git a/SvoViewer/external/glew/include/GL/glew.h b/svo-viewer/external/glew/include/GL/glew.h similarity index 100% rename from SvoViewer/external/glew/include/GL/glew.h rename to svo-viewer/external/glew/include/GL/glew.h diff --git a/SvoViewer/external/glew/include/GL/glxew.h b/svo-viewer/external/glew/include/GL/glxew.h similarity index 100% rename from SvoViewer/external/glew/include/GL/glxew.h rename to svo-viewer/external/glew/include/GL/glxew.h diff --git a/SvoViewer/external/glew/include/GL/wglew.h b/svo-viewer/external/glew/include/GL/wglew.h similarity index 100% rename from SvoViewer/external/glew/include/GL/wglew.h rename to svo-viewer/external/glew/include/GL/wglew.h diff --git a/SvoViewer/external/glew/lib/Release MX/Win32/glew32mx.lib b/svo-viewer/external/glew/lib/Release MX/Win32/glew32mx.lib similarity index 100% rename from SvoViewer/external/glew/lib/Release MX/Win32/glew32mx.lib rename to svo-viewer/external/glew/lib/Release MX/Win32/glew32mx.lib diff --git a/SvoViewer/external/glew/lib/Release MX/Win32/glew32mxs.lib b/svo-viewer/external/glew/lib/Release MX/Win32/glew32mxs.lib similarity index 100% rename from SvoViewer/external/glew/lib/Release MX/Win32/glew32mxs.lib rename to svo-viewer/external/glew/lib/Release MX/Win32/glew32mxs.lib diff --git a/SvoViewer/external/glew/lib/Release MX/x64/glew32mx.lib b/svo-viewer/external/glew/lib/Release MX/x64/glew32mx.lib similarity index 100% rename from SvoViewer/external/glew/lib/Release MX/x64/glew32mx.lib rename to svo-viewer/external/glew/lib/Release MX/x64/glew32mx.lib diff --git a/SvoViewer/external/glew/lib/Release MX/x64/glew32mxs.lib b/svo-viewer/external/glew/lib/Release MX/x64/glew32mxs.lib similarity index 100% rename from SvoViewer/external/glew/lib/Release MX/x64/glew32mxs.lib rename to svo-viewer/external/glew/lib/Release MX/x64/glew32mxs.lib diff --git a/SvoViewer/external/glew/lib/Release/Win32/glew32.lib b/svo-viewer/external/glew/lib/Release/Win32/glew32.lib similarity index 100% rename from SvoViewer/external/glew/lib/Release/Win32/glew32.lib rename to svo-viewer/external/glew/lib/Release/Win32/glew32.lib diff --git a/SvoViewer/external/glew/lib/Release/Win32/glew32s.lib b/svo-viewer/external/glew/lib/Release/Win32/glew32s.lib similarity index 100% rename from SvoViewer/external/glew/lib/Release/Win32/glew32s.lib rename to svo-viewer/external/glew/lib/Release/Win32/glew32s.lib diff --git a/SvoViewer/external/glew/lib/Release/x64/glew32.lib b/svo-viewer/external/glew/lib/Release/x64/glew32.lib similarity index 100% rename from SvoViewer/external/glew/lib/Release/x64/glew32.lib rename to svo-viewer/external/glew/lib/Release/x64/glew32.lib diff --git a/SvoViewer/external/glew/lib/Release/x64/glew32s.lib b/svo-viewer/external/glew/lib/Release/x64/glew32s.lib similarity index 100% rename from SvoViewer/external/glew/lib/Release/x64/glew32s.lib rename to svo-viewer/external/glew/lib/Release/x64/glew32s.lib diff --git a/SvoViewer/src/AABoundingVolume.h b/svo-viewer/src/AABoundingVolume.h similarity index 100% rename from SvoViewer/src/AABoundingVolume.h rename to svo-viewer/src/AABoundingVolume.h diff --git a/SvoViewer/src/Camera.cpp b/svo-viewer/src/Camera.cpp similarity index 99% rename from SvoViewer/src/Camera.cpp rename to svo-viewer/src/Camera.cpp index 7cfbf8fc2c..8582c00b5c 100755 --- a/SvoViewer/src/Camera.cpp +++ b/svo-viewer/src/Camera.cpp @@ -4,7 +4,7 @@ // // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. -#include "SvoViewerConfig.h" +#include "svo-viewer-config.h" #include #include diff --git a/SvoViewer/src/Camera.h b/svo-viewer/src/Camera.h similarity index 100% rename from SvoViewer/src/Camera.h rename to svo-viewer/src/Camera.h diff --git a/SvoViewer/src/GLCanvas.cpp b/svo-viewer/src/GLCanvas.cpp similarity index 98% rename from SvoViewer/src/GLCanvas.cpp rename to svo-viewer/src/GLCanvas.cpp index 0bd29e4f00..737d46dbc3 100755 --- a/SvoViewer/src/GLCanvas.cpp +++ b/svo-viewer/src/GLCanvas.cpp @@ -5,7 +5,7 @@ // Copyright (c) 2014 HighFidelity, Inc. All rights reserved. // -#include "SvoViewerConfig.h" +#include "svo-viewer-config.h" #include "svoviewer.h" diff --git a/SvoViewer/src/GLCanvas.h b/svo-viewer/src/GLCanvas.h similarity index 100% rename from SvoViewer/src/GLCanvas.h rename to svo-viewer/src/GLCanvas.h diff --git a/SvoViewer/src/Render.cpp b/svo-viewer/src/Render.cpp similarity index 91% rename from SvoViewer/src/Render.cpp rename to svo-viewer/src/Render.cpp index cb6ddd25c9..f2d500db51 100755 --- a/SvoViewer/src/Render.cpp +++ b/svo-viewer/src/Render.cpp @@ -51,9 +51,9 @@ bool SvoViewer::PointRenderAssemblePerVoxel(OctreeElement* node, void* extraData center *= 100.0; args->buffer[args->count] = center; int cCount = args->count * 3; - args->colorBuffer[cCount] = voxel->getTrueColor()[0]; - args->colorBuffer[cCount+1] = voxel->getTrueColor()[1]; - args->colorBuffer[cCount+2] = voxel->getTrueColor()[2]; + args->colorBuffer[cCount] = voxel->getColor()[0]; + args->colorBuffer[cCount+1] = voxel->getColor()[1]; + args->colorBuffer[cCount+2] = voxel->getColor()[2]; args->count++; return true; // keep going! } @@ -80,7 +80,7 @@ void SvoViewer::InitializePointRenderSystem() _pointVerticesCount = args.count; // create the data store. - int size = _nodeCount * sizeof(glm::vec3); + //int size = _nodeCount * sizeof(glm::vec3); glBindBuffer( GL_ARRAY_BUFFER, _pointVtxBuffer); glBufferData(GL_ARRAY_BUFFER, _nodeCount * 3, args.buffer, GL_STATIC_DRAW); //glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); @@ -92,7 +92,7 @@ void SvoViewer::InitializePointRenderSystem() _renderFlags.ptRenderDirty = false; _ptRenderInitialized = true; float elapsed = (float)(usecTimestampNow() - fstart) / 1000.f; - qDebug("Point render intialization took %f time for %d nodes\n", elapsed, _nodeCount); + qDebug("Point render intialization took %f time for %ld nodes\n", elapsed, _nodeCount); } void SvoViewer::RenderTreeSystemAsPoints() @@ -189,7 +189,7 @@ bool SvoViewer::VoxelRenderAssemblePerVoxel(OctreeElement* node, void* extraData int totalNodesProcessedSinceLastFlush = args->leafCount - args->lastBufferSegmentStart; // ack, one of these components is flags, not alpha int cCount = totalNodesProcessedSinceLastFlush * 4; // Place it relative to the current segment. - unsigned char col[4] = {voxel->getTrueColor()[0], voxel->getTrueColor()[1], voxel->getTrueColor()[2], 1}; + unsigned char col[4] = {voxel->getColor()[0], voxel->getColor()[1], voxel->getColor()[2], 1}; for(int i = 0; i < GLOBAL_NORMALS_VERTICES_PER_VOXEL; i++) memcpy(&args->colorBuffer[cCount+i*4], col, sizeof(col)); @@ -326,19 +326,16 @@ void SvoViewer::InitializeVoxelRenderSystem() GLchar shaderLog[1000]; GLsizei shaderLogLength; - GLint compiled; -// TODO: this was Matt's original windows code, it doesn't compile on mac, due to type mismatches -#ifdef WIN32 - glCompileShaderARB(_vertexShader); + //GLint compiled; + glCompileShaderARB((GLhandleARB)_vertexShader); glGetShaderInfoLog(_vertexShader, 1000, &shaderLogLength, shaderLog); if (shaderLog[0] != 0) qDebug("Shaderlog v :\n %s\n", shaderLog); - glCompileShaderARB(_geometryShader); + glCompileShaderARB((GLhandleARB)_geometryShader); glGetShaderInfoLog(_geometryShader, 1000, &shaderLogLength, shaderLog); if (shaderLog[0] != 0) qDebug("Shaderlog g :\n %s\n", shaderLog); - glCompileShaderARB(_pixelShader); + glCompileShaderARB((GLhandleARB)_pixelShader); glGetShaderInfoLog(_pixelShader, 51000, &shaderLogLength, shaderLog); if (shaderLog[0] != 0) qDebug("Shaderlog p :\n %s\n", shaderLog); -#endif //def WIN32 _linkProgram = glCreateProgram(); glAttachShader(_linkProgram, _vertexShader); @@ -582,9 +579,9 @@ bool SvoViewer::VoxelOptRenderAssemblePerVoxel(OctreeElement* node, void* extraD args->vtxBuffer[args->vtxCount].position *= 100; args->vtxBuffer[args->vtxCount].position.x -= 25; args->vtxBuffer[args->vtxCount].position.y -= 4; - args->vtxBuffer[args->vtxCount].color[0] = voxel->getTrueColor()[0]; - args->vtxBuffer[args->vtxCount].color[1] = voxel->getTrueColor()[1]; - args->vtxBuffer[args->vtxCount].color[2] = voxel->getTrueColor()[2]; + args->vtxBuffer[args->vtxCount].color[0] = voxel->getColor()[0]; + args->vtxBuffer[args->vtxCount].color[1] = voxel->getColor()[1]; + args->vtxBuffer[args->vtxCount].color[2] = voxel->getColor()[2]; args->vtxBuffer[args->vtxCount].color[3] = 1; args->bounds.AddToSet(args->vtxBuffer[args->vtxCount].position); args->vtxCount++; @@ -621,7 +618,7 @@ void SvoViewer::InitializeVoxelOptRenderSystem() // Set up the segments. Find the number of leaves at each subtree. OctreeElement * rootNode = _systemTree.getRoot(); OctreeElement* node0fromRoot = rootNode->getChildAtIndex(0); // ALL the interesting data for our test SVO is in this node! HACK!! - int rootNumChildren = rootNode->getChildCount(); + //int rootNumChildren = rootNode->getChildCount(); for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { OctreeElement* childNode1stOrder = node0fromRoot->getChildAtIndex(i); @@ -632,7 +629,7 @@ void SvoViewer::InitializeVoxelOptRenderSystem() OctreeElement* childNode2ndOrder = childNode1stOrder->getChildAtIndex(j); if (childNode2ndOrder == NULL) continue; - int num2ndOrderChildren = childNode2ndOrder->getChildCount(); + //int num2ndOrderChildren = childNode2ndOrder->getChildCount(); // Figure out how populated this child is. FindNumLeavesData data; data.numLeaves = 0; @@ -713,15 +710,22 @@ void SvoViewer::RenderTreeSystemAsOptVoxels() if (isVisibleBV(&_segmentBoundingVolumes[i], &_myCamera, &_viewFrustum)) // Add aggressive LOD check here. { glBindBuffer(GL_ARRAY_BUFFER, _vboOVerticesIds[i]); - glVertexAttribPointer(ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,position)); + // NOTE: mac compiler doesn't support offsetof() for non-POD types, which apparently glm::vec3 is + //glVertexAttribPointer(ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,position)); + glVertexAttribPointer(ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0); glEnableVertexAttribArray(ATTRIB_POSITION); - glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,color)); + // NOTE: mac compiler doesn't support offsetof() for non-POD types, which apparently glm::vec3 is + //glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,color)); + glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(Vertex), (void*)sizeof(glm::vec3)); glEnableVertexAttribArray(ATTRIB_COLOR); //glVertexPointer(3, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex,position)); glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (void*)offsetof(Vertex,color)); + + // NOTE: mac compiler doesn't support offsetof() for non-POD types, which apparently glm::vec3 is + //glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (void*)offsetof(Vertex,color)); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (void*)sizeof(glm::vec3)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboOIndicesIds[i]); diff --git a/SvoViewer/src/Render.h b/svo-viewer/src/Render.h similarity index 100% rename from SvoViewer/src/Render.h rename to svo-viewer/src/Render.h diff --git a/SvoViewer/src/Render2.cpp b/svo-viewer/src/Render2.cpp similarity index 90% rename from SvoViewer/src/Render2.cpp rename to svo-viewer/src/Render2.cpp index 7765aa288b..1f909603f9 100755 --- a/SvoViewer/src/Render2.cpp +++ b/svo-viewer/src/Render2.cpp @@ -148,9 +148,9 @@ bool SvoViewer::VoxelOpt2RenderAssemblePerVoxel(OctreeElement* node, void* extra args->vtxBuffer[args->vtxCount].position *= 100; args->vtxBuffer[args->vtxCount].position.x -= 25; args->vtxBuffer[args->vtxCount].position.y -= 4; - args->vtxBuffer[args->vtxCount].color[0] = voxel->getTrueColor()[0]; - args->vtxBuffer[args->vtxCount].color[1] = voxel->getTrueColor()[1]; - args->vtxBuffer[args->vtxCount].color[2] = voxel->getTrueColor()[2]; + args->vtxBuffer[args->vtxCount].color[0] = voxel->getColor()[0]; + args->vtxBuffer[args->vtxCount].color[1] = voxel->getColor()[1]; + args->vtxBuffer[args->vtxCount].color[2] = voxel->getColor()[2]; args->vtxBuffer[args->vtxCount].color[3] = 1; cubeVerts[i] = args->vtxBuffer[args->vtxCount].position; args->vtxCount++; @@ -190,7 +190,7 @@ void SvoViewer::InitializeVoxelOpt2RenderSystem() // Set up the segments. Find the number of leaves at each subtree. OctreeElement * rootNode = _systemTree.getRoot(); OctreeElement* node0fromRoot = rootNode->getChildAtIndex(0); // ALL the interesting data for our test SVO is in this node! HACK!! - int rootNumChildren = rootNode->getChildCount(); + //int rootNumChildren = rootNode->getChildCount(); for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { OctreeElement* childNode1stOrder = node0fromRoot->getChildAtIndex(i); @@ -201,7 +201,7 @@ void SvoViewer::InitializeVoxelOpt2RenderSystem() OctreeElement* childNode2ndOrder = childNode1stOrder->getChildAtIndex(j); if (childNode2ndOrder == NULL) continue; - int num2ndOrderChildren = childNode2ndOrder->getChildCount(); + //int num2ndOrderChildren = childNode2ndOrder->getChildCount(); // Figure out how populated this child is. FindNumLeavesData data; data.numLeaves = 0; @@ -296,15 +296,24 @@ void SvoViewer::RenderTreeSystemAsOpt2Voxels() if (_displayOnlyPartition == i || _displayOnlyPartition == NO_PARTITION ) { glBindBuffer(GL_ARRAY_BUFFER, _vboOVerticesIds[i]); - glVertexAttribPointer(ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,position)); + + // NOTE: mac compiler doesn't support offsetof() for non-POD types, which apparently glm::vec3 is + //glVertexAttribPointer(ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,position)); + glVertexAttribPointer(ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0); + glEnableVertexAttribArray(ATTRIB_POSITION); - glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,color)); + // NOTE: mac compiler doesn't support offsetof() for non-POD types, which apparently glm::vec3 is + //glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex,color)); + glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(Vertex), (void*)sizeof(glm::vec3)); glEnableVertexAttribArray(ATTRIB_COLOR); //glVertexPointer(3, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex,position)); glEnableClientState(GL_COLOR_ARRAY); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (void*)offsetof(Vertex,color)); + + // NOTE: mac compiler doesn't support offsetof() for non-POD types, which apparently glm::vec3 is + //glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (void*)offsetof(Vertex,color)); + glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), (void*)sizeof(glm::vec3)); for (int j = 0; j < NUM_CUBE_FACES; j++) { @@ -328,7 +337,7 @@ void SvoViewer::UpdateOpt2BVFaceVisibility() { if (_currentShaderModel != RENDER_OPT_CULLED_POLYS || _voxelOptRenderInitialized != true ) return; - float faceParamVals[NUM_CUBE_FACES]; + //float faceParamVals[NUM_CUBE_FACES]; glm::vec3 pos = _myCamera.getPosition(); for (int i = 0; i < _numSegments; i++) diff --git a/SvoViewer/src/SvoViewer.ico b/svo-viewer/src/SvoViewer.ico similarity index 100% rename from SvoViewer/src/SvoViewer.ico rename to svo-viewer/src/SvoViewer.ico diff --git a/SvoViewer/src/SvoViewer.rc b/svo-viewer/src/SvoViewer.rc similarity index 100% rename from SvoViewer/src/SvoViewer.rc rename to svo-viewer/src/SvoViewer.rc diff --git a/SvoViewer/src/TextRenderer.cpp b/svo-viewer/src/TextRenderer.cpp similarity index 99% rename from SvoViewer/src/TextRenderer.cpp rename to svo-viewer/src/TextRenderer.cpp index 3b2a308ba8..414f2cdd55 100644 --- a/SvoViewer/src/TextRenderer.cpp +++ b/svo-viewer/src/TextRenderer.cpp @@ -5,13 +5,14 @@ // Created by Andrzej Kapolka on 4/24/13. // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +#include "svo-viewer-config.h" + #include #include #include #include #include -#include "SvoViewerConfig.h" #include "TextRenderer.h" // the width/height of the cached glyph textures diff --git a/SvoViewer/src/TextRenderer.h b/svo-viewer/src/TextRenderer.h similarity index 98% rename from SvoViewer/src/TextRenderer.h rename to svo-viewer/src/TextRenderer.h index b5348cd665..1a913dac49 100644 --- a/SvoViewer/src/TextRenderer.h +++ b/svo-viewer/src/TextRenderer.h @@ -9,13 +9,14 @@ #ifndef __interface__TextRenderer__ #define __interface__TextRenderer__ +#include "svo-viewer-config.h" + #include #include #include #include #include -#include "SvoViewerConfig.h" // a special "character" that renders as a solid block const char SOLID_BLOCK_CHAR = 127; diff --git a/SvoViewer/src/globals.cpp b/svo-viewer/src/globals.cpp similarity index 100% rename from SvoViewer/src/globals.cpp rename to svo-viewer/src/globals.cpp diff --git a/SvoViewer/src/globals.h b/svo-viewer/src/globals.h similarity index 91% rename from SvoViewer/src/globals.h rename to svo-viewer/src/globals.h index b20fa3e2a5..2ac08a8973 100755 --- a/SvoViewer/src/globals.h +++ b/svo-viewer/src/globals.h @@ -6,7 +6,7 @@ #pragma once -#include "SvoViewerConfig.h" +#include "svo-viewer-config.h" #include #include diff --git a/SvoViewer/src/main.cpp b/svo-viewer/src/main.cpp similarity index 83% rename from SvoViewer/src/main.cpp rename to svo-viewer/src/main.cpp index e92d98f14b..159171fd53 100755 --- a/SvoViewer/src/main.cpp +++ b/svo-viewer/src/main.cpp @@ -4,7 +4,7 @@ // Copyright (c) 2014 HighFidelity, Inc. All rights reserved. // -#include "SvoViewerConfig.h" +#include "svo-viewer-config.h" #include "svoviewer.h" #include diff --git a/SvoViewer/src/svoviewer.cpp b/svo-viewer/src/svoviewer.cpp similarity index 93% rename from SvoViewer/src/svoviewer.cpp rename to svo-viewer/src/svoviewer.cpp index 310c1f2f00..d20910f4bc 100755 --- a/SvoViewer/src/svoviewer.cpp +++ b/svo-viewer/src/svoviewer.cpp @@ -31,13 +31,17 @@ SvoViewer * _globalSvoViewerObj; // Hack :: var to store global pointer since th SvoViewer::SvoViewer(int& argc, char** argv, QWidget *parent) : QApplication(argc, argv), _window(new QMainWindow(desktop())), - _glWidget(new GLCanvas()), _width(1280), _height(720), _pixelCount(1280*720), - _frameCount(0), + _glWidget(new GLCanvas()), + _nodeCount(0), _leafCount(0), - _nodeCount(0), + _pitch(0), + _yaw(0), + _roll(0), + _displayOnlyPartition(NO_PARTITION), + _frameCount(0), _fps(0.0), _lastTimeFpsUpdated(0), _lastTimeFrameUpdated(0), @@ -48,29 +52,26 @@ SvoViewer::SvoViewer(int& argc, char** argv, QWidget *parent) _vertexShader(0), _pixelShader(0), _geometryShader(0), - _maxVoxels(DEFAULT_MAX_VOXELS_PER_SYSTEM), - _voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE), - _boundaryLevelAdjust(0), - _viewFrustumOffset(DEFAULT_FRUSTUM_OFFSET), - _fieldOfView(DEFAULT_FIELD_OF_VIEW_DEGREES), - _useVoxelTextures(false), _pointVertices(NULL), + _pointColors(NULL), _pointVerticesCount(0), + _numSegments(0), + _useBoundingVolumes(true), + _numElemsDrawn(0), + _totalPossibleElems(0), + _viewFrustumOffset(DEFAULT_FRUSTUM_OFFSET), + _maxVoxels(DEFAULT_MAX_VOXELS_PER_SYSTEM), + _voxelSizeScale(DEFAULT_OCTREE_SIZE_SCALE), + _boundaryLevelAdjust(0), //_vboShaderData(NULL), - _mousePressed(false), - _pitch(0), - _yaw(0), - _roll(0), - _numSegments(0), - _displayOnlyPartition(NO_PARTITION), - _totalPossibleElems(0), - _numElemsDrawn(0), - _useBoundingVolumes(true) + _fieldOfView(DEFAULT_FIELD_OF_VIEW_DEGREES) { gettimeofday(&_applicationStartupTime, NULL); _appStartTickCount = usecTimestampNow(); _globalSvoViewerObj = this; + _mousePressed = false; + _useVoxelTextures = false; //ui.setupUi(this); _window->setWindowTitle("SvoViewer"); @@ -89,7 +90,6 @@ SvoViewer::SvoViewer(int& argc, char** argv, QWidget *parent) QString shaderMode; QStringList argumentList = arguments(); - int argumentIndex = 0; // check if this domain server should use no authentication or a custom hostname for authentication const QString FILE_NAME = "--file"; @@ -211,8 +211,8 @@ void SvoViewer::init() { void SvoViewer::initializeGL() { - int argc = 0; #ifdef WIN32 + int argc = 0; glutInit(&argc, 0); #endif init(); @@ -585,13 +585,9 @@ void SvoViewer::keyReleaseEvent(QKeyEvent* event) {} void SvoViewer::mouseMoveEvent(QMouseEvent* event) { - int deltaX = event->x() - _mouseX; - int deltaY = event->y() - _mouseY; _mouseX = event->x(); _mouseY = event->y(); - - - loadViewFrustum(_myCamera, _viewFrustum); + loadViewFrustum(_myCamera, _viewFrustum); } void SvoViewer::mousePressEvent(QMouseEvent* event) @@ -639,8 +635,8 @@ bool SvoViewer::isVisibleBV(AABoundingVolume * volume, Camera * camera, ViewFrus //if (pos.z >= volume->getBound(2,AABF_HIGH)) return false; // Project all the points into screen space. AA2DBoundingVolume twoDBounds; - float xvals[2] = {9999.0, -1.0}; - float yvals[2] = {9999.0, -1.0}; + //float xvals[2] = {9999.0, -1.0}; + //float yvals[2] = {9999.0, -1.0}; //project all bv points into screen space. GLdouble scr[3]; for (int i = 0; i < 8; i++) @@ -660,8 +656,8 @@ bool SvoViewer::isVisibleBV(AABoundingVolume * volume, Camera * camera, ViewFrus float SvoViewer::visibleAngleSubtended(AABoundingVolume * volume, Camera * camera, ViewFrustum * frustum) { AA2DBoundingVolume twoDBounds; - float xvals[2] = {9999.0, -1.0}; - float yvals[2] = {9999.0, -1.0}; + //float xvals[2] = {9999.0, -1.0}; + //float yvals[2] = {9999.0, -1.0}; //project all bv points into screen space. GLdouble scr[3]; for (int i = 0; i < 8; i++) diff --git a/SvoViewer/src/svoviewer.h b/svo-viewer/src/svoviewer.h similarity index 96% rename from SvoViewer/src/svoviewer.h rename to svo-viewer/src/svoviewer.h index c4aca046fe..abd4879424 100755 --- a/SvoViewer/src/svoviewer.h +++ b/svo-viewer/src/svoviewer.h @@ -11,7 +11,7 @@ #pragma once -#include "SvoViewerConfig.h" +#include "svo-viewer-config.h" #include #include diff --git a/SvoViewer/src/svoviewer.qrc b/svo-viewer/src/svoviewer.qrc similarity index 100% rename from SvoViewer/src/svoviewer.qrc rename to svo-viewer/src/svoviewer.qrc diff --git a/SvoViewer/src/svoviewer.ui b/svo-viewer/src/svoviewer.ui similarity index 100% rename from SvoViewer/src/svoviewer.ui rename to svo-viewer/src/svoviewer.ui diff --git a/SvoViewer/src/windowshacks.h b/svo-viewer/src/windowshacks.h similarity index 100% rename from SvoViewer/src/windowshacks.h rename to svo-viewer/src/windowshacks.h diff --git a/SvoViewer/SvoViewerConfig.h.in b/svo-viewer/svo-viewer-config.h.in similarity index 100% rename from SvoViewer/SvoViewerConfig.h.in rename to svo-viewer/svo-viewer-config.h.in diff --git a/SvoViewer/SvoViewerVersion.h.in b/svo-viewer/svo-viewer-version.h.in similarity index 100% rename from SvoViewer/SvoViewerVersion.h.in rename to svo-viewer/svo-viewer-version.h.in diff --git a/SvoViewer/SvoViewer.icns b/svo-viewer/svo-viewer.icns similarity index 100% rename from SvoViewer/SvoViewer.icns rename to svo-viewer/svo-viewer.icns diff --git a/libraries/voxels/src/SceneUtils.cpp b/voxel-edit/src/SceneUtils.cpp similarity index 79% rename from libraries/voxels/src/SceneUtils.cpp rename to voxel-edit/src/SceneUtils.cpp index 431f4bd042..2cbe73c74e 100644 --- a/libraries/voxels/src/SceneUtils.cpp +++ b/voxel-edit/src/SceneUtils.cpp @@ -27,18 +27,6 @@ void addCornersAndAxisLines(VoxelTree* tree) { tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 0 , voxelSize, 255, 255 ,0 ); tree->createVoxel(1.0 - voxelSize, 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 255, 255 ,255); printf("DONE creating corner points...\n"); - - // Now some more examples... creating some lines using the line primitive - printf("creating voxel lines...\n"); - // We want our line voxels to be about 1/32 meter high, and our TREE_SCALE is in meters, so... - float lineVoxelSize = 1.f / (32 * TREE_SCALE); - rgbColor red = {255, 0, 0}; - rgbColor green = {0, 255, 0}; - rgbColor blue = {0, 0, 255}; - tree->createLine(glm::vec3(0, 0, 0), glm::vec3(0, 0, 1), lineVoxelSize, blue); - tree->createLine(glm::vec3(0, 0, 0), glm::vec3(1, 0, 0), lineVoxelSize, red); - tree->createLine(glm::vec3(0, 0, 0), glm::vec3(0, 1, 0), lineVoxelSize, green); - printf("DONE creating lines...\n"); } void addSurfaceScene(VoxelTree * tree) { diff --git a/libraries/voxels/src/SceneUtils.h b/voxel-edit/src/SceneUtils.h similarity index 100% rename from libraries/voxels/src/SceneUtils.h rename to voxel-edit/src/SceneUtils.h diff --git a/voxel-edit/src/main.cpp b/voxel-edit/src/main.cpp index e2529a4599..35401aa1d0 100644 --- a/voxel-edit/src/main.cpp +++ b/voxel-edit/src/main.cpp @@ -1,4 +1,4 @@ - // +// // main.cpp // Voxel Edit // @@ -8,7 +8,7 @@ #include #include -#include +#include "SceneUtils.h" #include #include #include @@ -163,9 +163,9 @@ bool copyAndFillOperation(OctreeElement* element, void* extraData) { float y = voxel->getCorner().y; float z = voxel->getCorner().z; float s = voxel->getScale(); - unsigned char red = voxel->getTrueColor()[RED_INDEX]; - unsigned char green = voxel->getTrueColor()[GREEN_INDEX]; - unsigned char blue = voxel->getTrueColor()[BLUE_INDEX]; + unsigned char red = voxel->getColor()[RED_INDEX]; + unsigned char green = voxel->getColor()[GREEN_INDEX]; + unsigned char blue = voxel->getColor()[BLUE_INDEX]; bool destructive = true; args->destinationTree->createVoxel(x, y, z, s, red, green, blue, destructive);