From 5ffff958fe12914a0ffe4c860219a5879be32d86 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 1 Mar 2014 11:47:37 -0800 Subject: [PATCH 01/32] cleanup names and fix some warnings --- CMakeLists.txt | 2 +- {SvoViewer => svo-viewer}/CMakeLists.txt | 10 ++-- .../external/freeglut/Copying.txt | 0 .../external/freeglut/bin/freeglut.dll | Bin .../external/freeglut/bin/x64/freeglut.dll | Bin .../external/freeglut/include/GL/freeglut.h | 0 .../freeglut/include/GL/freeglut_ext.h | 0 .../freeglut/include/GL/freeglut_std.h | 0 .../external/freeglut/include/GL/glut.h | 0 .../external/freeglut/lib/freeglut.lib | Bin .../external/freeglut/lib/x64/freeglut.lib | Bin .../external/glew/LICENSE.txt | 0 .../glew/bin/Release MX/Win32/glew32mx.dll | Bin .../glew/bin/Release MX/x64/glew32mx.dll | Bin .../glew/bin/Release/Win32/glew32.dll | Bin .../glew/bin/Release/Win32/glewinfo.exe | Bin .../glew/bin/Release/Win32/visualinfo.exe | Bin .../external/glew/bin/Release/x64/glew32.dll | Bin .../glew/bin/Release/x64/glewinfo.exe | Bin .../glew/bin/Release/x64/visualinfo.exe | Bin .../external/glew/include/GL/glew.h | 0 .../external/glew/include/GL/glxew.h | 0 .../external/glew/include/GL/wglew.h | 0 .../glew/lib/Release MX/Win32/glew32mx.lib | Bin .../glew/lib/Release MX/Win32/glew32mxs.lib | Bin .../glew/lib/Release MX/x64/glew32mx.lib | Bin .../glew/lib/Release MX/x64/glew32mxs.lib | Bin .../glew/lib/Release/Win32/glew32.lib | Bin .../glew/lib/Release/Win32/glew32s.lib | Bin .../external/glew/lib/Release/x64/glew32.lib | Bin .../external/glew/lib/Release/x64/glew32s.lib | Bin .../src/AABoundingVolume.h | 0 {SvoViewer => svo-viewer}/src/Camera.cpp | 2 +- {SvoViewer => svo-viewer}/src/Camera.h | 0 {SvoViewer => svo-viewer}/src/GLCanvas.cpp | 2 +- {SvoViewer => svo-viewer}/src/GLCanvas.h | 0 {SvoViewer => svo-viewer}/src/Render.cpp | 12 ++-- {SvoViewer => svo-viewer}/src/Render.h | 0 {SvoViewer => svo-viewer}/src/Render2.cpp | 6 +- {SvoViewer => svo-viewer}/src/SvoViewer.ico | Bin {SvoViewer => svo-viewer}/src/SvoViewer.rc | 0 .../src/TextRenderer.cpp | 3 +- {SvoViewer => svo-viewer}/src/TextRenderer.h | 3 +- {SvoViewer => svo-viewer}/src/globals.cpp | 0 {SvoViewer => svo-viewer}/src/globals.h | 2 +- {SvoViewer => svo-viewer}/src/main.cpp | 2 +- {SvoViewer => svo-viewer}/src/svoviewer.cpp | 53 ++++++++---------- {SvoViewer => svo-viewer}/src/svoviewer.h | 2 +- {SvoViewer => svo-viewer}/src/svoviewer.qrc | 0 {SvoViewer => svo-viewer}/src/svoviewer.ui | 0 {SvoViewer => svo-viewer}/src/windowshacks.h | 0 .../svo-viewer-config.h.in | 0 .../svo-viewer-version.h.in | 0 .../svo-viewer.icns | Bin 54 files changed, 48 insertions(+), 51 deletions(-) rename {SvoViewer => svo-viewer}/CMakeLists.txt (95%) rename {SvoViewer => svo-viewer}/external/freeglut/Copying.txt (100%) rename {SvoViewer => svo-viewer}/external/freeglut/bin/freeglut.dll (100%) rename {SvoViewer => svo-viewer}/external/freeglut/bin/x64/freeglut.dll (100%) rename {SvoViewer => svo-viewer}/external/freeglut/include/GL/freeglut.h (100%) rename {SvoViewer => svo-viewer}/external/freeglut/include/GL/freeglut_ext.h (100%) rename {SvoViewer => svo-viewer}/external/freeglut/include/GL/freeglut_std.h (100%) rename {SvoViewer => svo-viewer}/external/freeglut/include/GL/glut.h (100%) rename {SvoViewer => svo-viewer}/external/freeglut/lib/freeglut.lib (100%) rename {SvoViewer => svo-viewer}/external/freeglut/lib/x64/freeglut.lib (100%) rename {SvoViewer => svo-viewer}/external/glew/LICENSE.txt (100%) rename {SvoViewer => svo-viewer}/external/glew/bin/Release MX/Win32/glew32mx.dll (100%) rename {SvoViewer => svo-viewer}/external/glew/bin/Release MX/x64/glew32mx.dll (100%) rename {SvoViewer => svo-viewer}/external/glew/bin/Release/Win32/glew32.dll (100%) rename {SvoViewer => svo-viewer}/external/glew/bin/Release/Win32/glewinfo.exe (100%) rename {SvoViewer => svo-viewer}/external/glew/bin/Release/Win32/visualinfo.exe (100%) rename {SvoViewer => svo-viewer}/external/glew/bin/Release/x64/glew32.dll (100%) rename {SvoViewer => svo-viewer}/external/glew/bin/Release/x64/glewinfo.exe (100%) rename {SvoViewer => svo-viewer}/external/glew/bin/Release/x64/visualinfo.exe (100%) rename {SvoViewer => svo-viewer}/external/glew/include/GL/glew.h (100%) rename {SvoViewer => svo-viewer}/external/glew/include/GL/glxew.h (100%) rename {SvoViewer => svo-viewer}/external/glew/include/GL/wglew.h (100%) rename {SvoViewer => svo-viewer}/external/glew/lib/Release MX/Win32/glew32mx.lib (100%) rename {SvoViewer => svo-viewer}/external/glew/lib/Release MX/Win32/glew32mxs.lib (100%) rename {SvoViewer => svo-viewer}/external/glew/lib/Release MX/x64/glew32mx.lib (100%) rename {SvoViewer => svo-viewer}/external/glew/lib/Release MX/x64/glew32mxs.lib (100%) rename {SvoViewer => svo-viewer}/external/glew/lib/Release/Win32/glew32.lib (100%) rename {SvoViewer => svo-viewer}/external/glew/lib/Release/Win32/glew32s.lib (100%) rename {SvoViewer => svo-viewer}/external/glew/lib/Release/x64/glew32.lib (100%) rename {SvoViewer => svo-viewer}/external/glew/lib/Release/x64/glew32s.lib (100%) rename {SvoViewer => svo-viewer}/src/AABoundingVolume.h (100%) rename {SvoViewer => svo-viewer}/src/Camera.cpp (99%) rename {SvoViewer => svo-viewer}/src/Camera.h (100%) rename {SvoViewer => svo-viewer}/src/GLCanvas.cpp (98%) rename {SvoViewer => svo-viewer}/src/GLCanvas.h (100%) rename {SvoViewer => svo-viewer}/src/Render.cpp (96%) rename {SvoViewer => svo-viewer}/src/Render.h (100%) rename {SvoViewer => svo-viewer}/src/Render2.cpp (96%) rename {SvoViewer => svo-viewer}/src/SvoViewer.ico (100%) rename {SvoViewer => svo-viewer}/src/SvoViewer.rc (100%) rename {SvoViewer => svo-viewer}/src/TextRenderer.cpp (99%) rename {SvoViewer => svo-viewer}/src/TextRenderer.h (98%) rename {SvoViewer => svo-viewer}/src/globals.cpp (100%) rename {SvoViewer => svo-viewer}/src/globals.h (91%) rename {SvoViewer => svo-viewer}/src/main.cpp (83%) rename {SvoViewer => svo-viewer}/src/svoviewer.cpp (93%) rename {SvoViewer => svo-viewer}/src/svoviewer.h (96%) rename {SvoViewer => svo-viewer}/src/svoviewer.qrc (100%) rename {SvoViewer => svo-viewer}/src/svoviewer.ui (100%) rename {SvoViewer => svo-viewer}/src/windowshacks.h (100%) rename SvoViewer/SvoViewerConfig.h.in => svo-viewer/svo-viewer-config.h.in (100%) rename SvoViewer/SvoViewerVersion.h.in => svo-viewer/svo-viewer-version.h.in (100%) rename SvoViewer/SvoViewer.icns => svo-viewer/svo-viewer.icns (100%) 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/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 96% rename from SvoViewer/src/Render.cpp rename to svo-viewer/src/Render.cpp index cb6ddd25c9..69502a9b42 100755 --- a/SvoViewer/src/Render.cpp +++ b/svo-viewer/src/Render.cpp @@ -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() @@ -324,11 +324,11 @@ void SvoViewer::InitializeVoxelRenderSystem() glShaderSource(_geometryShader, 1, &simpleGeomShaderSrc, &simpleGeomShaderLen); glShaderSource(_pixelShader, 1, &simpleFragShaderSrc, &simpleFragShaderLen); +// TODO: this was Matt's original windows code, it doesn't compile on mac, due to type mismatches +#ifdef WIN32 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); glGetShaderInfoLog(_vertexShader, 1000, &shaderLogLength, shaderLog); if (shaderLog[0] != 0) qDebug("Shaderlog v :\n %s\n", shaderLog); @@ -621,7 +621,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 +632,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; 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 96% rename from SvoViewer/src/Render2.cpp rename to svo-viewer/src/Render2.cpp index 7765aa288b..91e41f3e85 100755 --- a/SvoViewer/src/Render2.cpp +++ b/svo-viewer/src/Render2.cpp @@ -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; @@ -328,7 +328,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..50b1cfdfd1 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,25 @@ 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), _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 +89,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 +210,8 @@ void SvoViewer::init() { void SvoViewer::initializeGL() { - int argc = 0; #ifdef WIN32 + int argc = 0; glutInit(&argc, 0); #endif init(); @@ -585,13 +584,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 +634,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 +655,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 From a2648b062e5f9651636c6888c707fe67a97db785 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 1 Mar 2014 12:35:08 -0800 Subject: [PATCH 02/32] fixed more warnings --- svo-viewer/src/Render.cpp | 24 ++++++++++++++---------- svo-viewer/src/Render2.cpp | 15 ++++++++++++--- svo-viewer/src/svoviewer.cpp | 1 + 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/svo-viewer/src/Render.cpp b/svo-viewer/src/Render.cpp index 69502a9b42..e8596c8818 100755 --- a/svo-viewer/src/Render.cpp +++ b/svo-viewer/src/Render.cpp @@ -324,21 +324,18 @@ void SvoViewer::InitializeVoxelRenderSystem() glShaderSource(_geometryShader, 1, &simpleGeomShaderSrc, &simpleGeomShaderLen); glShaderSource(_pixelShader, 1, &simpleFragShaderSrc, &simpleFragShaderLen); -// TODO: this was Matt's original windows code, it doesn't compile on mac, due to type mismatches -#ifdef WIN32 GLchar shaderLog[1000]; GLsizei shaderLogLength; - GLint compiled; - glCompileShaderARB(_vertexShader); + //GLint compiled; + glCompileShaderARB((void*)_vertexShader); glGetShaderInfoLog(_vertexShader, 1000, &shaderLogLength, shaderLog); if (shaderLog[0] != 0) qDebug("Shaderlog v :\n %s\n", shaderLog); - glCompileShaderARB(_geometryShader); + glCompileShaderARB((void*)_geometryShader); glGetShaderInfoLog(_geometryShader, 1000, &shaderLogLength, shaderLog); if (shaderLog[0] != 0) qDebug("Shaderlog g :\n %s\n", shaderLog); - glCompileShaderARB(_pixelShader); + glCompileShaderARB((void*)_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); @@ -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/svo-viewer/src/Render2.cpp b/svo-viewer/src/Render2.cpp index 91e41f3e85..7538c80d0a 100755 --- a/svo-viewer/src/Render2.cpp +++ b/svo-viewer/src/Render2.cpp @@ -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++) { diff --git a/svo-viewer/src/svoviewer.cpp b/svo-viewer/src/svoviewer.cpp index 50b1cfdfd1..d20910f4bc 100755 --- a/svo-viewer/src/svoviewer.cpp +++ b/svo-viewer/src/svoviewer.cpp @@ -53,6 +53,7 @@ SvoViewer::SvoViewer(int& argc, char** argv, QWidget *parent) _pixelShader(0), _geometryShader(0), _pointVertices(NULL), + _pointColors(NULL), _pointVerticesCount(0), _numSegments(0), _useBoundingVolumes(true), From c8feaa7b806ae2fb7388b0895090f82a9b6221f4 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 1 Mar 2014 12:47:45 -0800 Subject: [PATCH 03/32] one more attempt to get this to work --- svo-viewer/src/Render.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/svo-viewer/src/Render.cpp b/svo-viewer/src/Render.cpp index e8596c8818..fd564ee2fd 100755 --- a/svo-viewer/src/Render.cpp +++ b/svo-viewer/src/Render.cpp @@ -327,13 +327,13 @@ void SvoViewer::InitializeVoxelRenderSystem() GLchar shaderLog[1000]; GLsizei shaderLogLength; //GLint compiled; - glCompileShaderARB((void*)_vertexShader); + glCompileShaderARB((GLhandleARB)_vertexShader); glGetShaderInfoLog(_vertexShader, 1000, &shaderLogLength, shaderLog); if (shaderLog[0] != 0) qDebug("Shaderlog v :\n %s\n", shaderLog); - glCompileShaderARB((void*)_geometryShader); + glCompileShaderARB((GLhandleARB)_geometryShader); glGetShaderInfoLog(_geometryShader, 1000, &shaderLogLength, shaderLog); if (shaderLog[0] != 0) qDebug("Shaderlog g :\n %s\n", shaderLog); - glCompileShaderARB((void*)_pixelShader); + glCompileShaderARB((GLhandleARB)_pixelShader); glGetShaderInfoLog(_pixelShader, 51000, &shaderLogLength, shaderLog); if (shaderLog[0] != 0) qDebug("Shaderlog p :\n %s\n", shaderLog); From c5197b390e5a30892d032ff9ace05c5ad632e3f3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 12:13:00 -0800 Subject: [PATCH 04/32] removed a bunch of cruft from VoxelSystem --- interface/src/Application.cpp | 122 +--- interface/src/Application.h | 13 +- interface/src/Menu.cpp | 77 --- interface/src/Menu.h | 15 - interface/src/VoxelSystem.cpp | 764 +---------------------- interface/src/VoxelSystem.h | 28 - libraries/octree/src/Octree.h | 1 - libraries/octree/src/OctreeRenderer.cpp | 24 +- libraries/octree/src/OctreeRenderer.h | 3 + libraries/octree/src/ViewFrustum.cpp | 1 - libraries/voxels/src/VoxelPacketData.cpp | 16 - libraries/voxels/src/VoxelPacketData.h | 35 -- libraries/voxels/src/VoxelTree.h | 10 +- 13 files changed, 40 insertions(+), 1069 deletions(-) delete mode 100644 libraries/voxels/src/VoxelPacketData.cpp delete mode 100644 libraries/voxels/src/VoxelPacketData.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 97705b9832..28db3d8791 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -742,9 +742,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(); @@ -2518,15 +2516,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 +2957,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) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 4e91876dfb..0f201b20aa 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -34,12 +34,16 @@ #include "BandwidthMeter.h" #include "BuckyBalls.h" #include "Camera.h" +#include "ControllerScriptingInterface.h" #include "DatagramProcessor.h" #include "Environment.h" +#include "ExperimentalVoxelTreeRenderer.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 +72,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" @@ -261,12 +262,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(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 4d19acf248..87cff96284 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -282,11 +282,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 +297,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 +311,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, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 3d8aa24cbd..2ccb7c4260 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,15 +271,12 @@ 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"; diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 24d1e73ee2..449efa2b58 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" @@ -206,31 +204,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". @@ -618,7 +601,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" @@ -886,15 +869,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() { @@ -1830,79 +1804,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; @@ -1935,135 +1836,6 @@ VoxelTreeElement* VoxelSystem::getVoxelEnclosing(const glm::vec3& point) { 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: @@ -2197,57 +1969,6 @@ void VoxelSystem::removeOutOfView() { } } -// 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: @@ -2598,209 +2319,6 @@ bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3 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()"); @@ -2851,268 +2369,6 @@ void VoxelSystem::recurseTreeWithOperation(RecurseOctreeOperation operation, voi _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..cdb27bca3f 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -14,7 +14,6 @@ #include -#include #include #include #include @@ -106,9 +105,6 @@ public: void recurseTreeWithOperation(RecurseOctreeOperation operation, void* extraData=NULL); - CoverageMapV2 myCoverageMapV2; - CoverageMap myCoverageMap; - virtual void elementDeleted(OctreeElement* element); virtual void elementUpdated(OctreeElement* element); @@ -122,19 +118,8 @@ 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(); @@ -178,19 +163,7 @@ 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 +172,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/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index e0c7f414f8..8e7f9b0b23 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; 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.h b/libraries/voxels/src/VoxelTree.h index b5f28811fc..fc85e0184a 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -9,17 +9,11 @@ #ifndef __hifi__VoxelTree__ #define __hifi__VoxelTree__ -#include -#include -#include #include -#include -#include -#include #include "VoxelTreeElement.h" -#include "VoxelPacketData.h" -#include "VoxelSceneStats.h" +//#include "VoxelPacketData.h" +//#include "VoxelSceneStats.h" #include "VoxelEditPacketSender.h" class ReadCodeColorBufferToTreeArgs; From b66c346f202fb254d551bc8da7bc941722d6f42d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 12:19:50 -0800 Subject: [PATCH 05/32] more cruft removal --- interface/src/VoxelSystem.cpp | 5 ----- interface/src/VoxelSystem.h | 1 - libraries/voxels/src/SceneUtils.cpp | 12 ------------ libraries/voxels/src/VoxelTree.cpp | 13 ------------- libraries/voxels/src/VoxelTree.h | 14 -------------- 5 files changed, 45 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 449efa2b58..6155ebdcd4 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -2347,11 +2347,6 @@ void VoxelSystem::createVoxel(float x, float y, float z, float s, 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(); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index cdb27bca3f..113c341ecc 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -97,7 +97,6 @@ public: 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); diff --git a/libraries/voxels/src/SceneUtils.cpp b/libraries/voxels/src/SceneUtils.cpp index 431f4bd042..2cbe73c74e 100644 --- a/libraries/voxels/src/SceneUtils.cpp +++ b/libraries/voxels/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/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 08ec2cfc3c..272668a19e 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -56,19 +56,6 @@ void VoxelTree::createVoxel(float x, float y, float z, float s, 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; diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index fc85e0184a..388b71bfca 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -12,8 +12,6 @@ #include #include "VoxelTreeElement.h" -//#include "VoxelPacketData.h" -//#include "VoxelSceneStats.h" #include "VoxelEditPacketSender.h" class ReadCodeColorBufferToTreeArgs; @@ -32,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); @@ -51,15 +46,6 @@ public: 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 void recurseNodeForNudge(VoxelTreeElement* element, RecurseOctreeOperation operation, void* extraData); From 5b72f01b9919ce9725849b38aabb45ebac0048ff Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 12:33:52 -0800 Subject: [PATCH 06/32] more cruft removal getting rid of false color in VoxelTreeElement --- SvoViewer/src/Render.cpp | 14 +++---- SvoViewer/src/Render2.cpp | 6 +-- interface/src/VoxelSystem.cpp | 23 ++---------- libraries/voxels/src/VoxelTreeElement.cpp | 45 ++++------------------- libraries/voxels/src/VoxelTreeElement.h | 11 ++---- voxel-edit/src/main.cpp | 6 +-- 6 files changed, 26 insertions(+), 79 deletions(-) diff --git a/SvoViewer/src/Render.cpp b/SvoViewer/src/Render.cpp index cb6ddd25c9..396bfad0b1 100755 --- a/SvoViewer/src/Render.cpp +++ b/SvoViewer/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! } @@ -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)); @@ -582,9 +582,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++; diff --git a/SvoViewer/src/Render2.cpp b/SvoViewer/src/Render2.cpp index 7765aa288b..976dc1ee36 100755 --- a/SvoViewer/src/Render2.cpp +++ b/SvoViewer/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++; diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 6155ebdcd4..f91e6eb1ff 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -2117,15 +2117,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; @@ -2158,20 +2152,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++; } 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/voxel-edit/src/main.cpp b/voxel-edit/src/main.cpp index e2529a4599..b1dde051ae 100644 --- a/voxel-edit/src/main.cpp +++ b/voxel-edit/src/main.cpp @@ -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); From 124a63e6ccd90c8739ca8fbc8764da2bccc13c2d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 12:41:17 -0800 Subject: [PATCH 07/32] remove use of getTrueColor() which is going away --- svo-viewer/src/Render.cpp | 14 +++++++------- svo-viewer/src/Render2.cpp | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/svo-viewer/src/Render.cpp b/svo-viewer/src/Render.cpp index fd564ee2fd..f2d500db51 100755 --- a/svo-viewer/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! } @@ -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)); @@ -579,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++; diff --git a/svo-viewer/src/Render2.cpp b/svo-viewer/src/Render2.cpp index 7538c80d0a..1f909603f9 100755 --- a/svo-viewer/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++; From 6c6b65c60057af7ce68b50ed6920aa0d7ab97d40 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 13:22:15 -0800 Subject: [PATCH 08/32] moved SceneUtils out of voxels library into voxel-edit --- animation-server/src/AnimationServer.cpp | 1 - voxel-edit/src/SceneUtils.cpp | 58 ++++++++++++++++++++++++ voxel-edit/src/SceneUtils.h | 19 ++++++++ voxel-edit/src/main.cpp | 4 +- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 voxel-edit/src/SceneUtils.cpp create mode 100644 voxel-edit/src/SceneUtils.h 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/voxel-edit/src/SceneUtils.cpp b/voxel-edit/src/SceneUtils.cpp new file mode 100644 index 0000000000..2cbe73c74e --- /dev/null +++ b/voxel-edit/src/SceneUtils.cpp @@ -0,0 +1,58 @@ +// +// SceneUtils.cpp +// hifi +// +// Created by Brad Hefta-Gaub on 5/7/2013. +// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. +// + +#include + +#include + +#include "SceneUtils.h" + +void addCornersAndAxisLines(VoxelTree* tree) { + // We want our corner voxels to be about 1/2 meter high, and our TREE_SCALE is in meters, so... + float voxelSize = 0.5f / TREE_SCALE; + + // Now some more examples... a little more complex + printf("creating corner points...\n"); + tree->createVoxel(0 , 0 , 0 , voxelSize, 255, 255 ,255); + tree->createVoxel(1.0 - voxelSize, 0 , 0 , voxelSize, 255, 0 ,0 ); + tree->createVoxel(0 , 1.0 - voxelSize, 0 , voxelSize, 0 , 255 ,0 ); + tree->createVoxel(0 , 0 , 1.0 - voxelSize, voxelSize, 0 , 0 ,255); + tree->createVoxel(1.0 - voxelSize, 0 , 1.0 - voxelSize, voxelSize, 255, 0 ,255); + tree->createVoxel(0 , 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 0 , 255 ,255); + 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"); +} + +void addSurfaceScene(VoxelTree * tree) { + printf("adding surface scene...\n"); + float voxelSize = 1.f / (8 * TREE_SCALE); + + // color 1= blue, color 2=green + unsigned char r1, g1, b1, r2, g2, b2, red, green, blue; + r1 = r2 = b2 = g1 = 0; + b1 = g2 = 255; + + for (float x = 0.0; x < 1.0; x += voxelSize) { + for (float z = 0.0; z < 1.0; z += voxelSize) { + + glm::vec2 position = glm::vec2(x, z); + float perlin = glm::perlin(position) + .25f * glm::perlin(position * 4.f) + .125f * glm::perlin(position * 16.f); + float gradient = (1.0f + perlin)/ 2.0f; + red = (unsigned char)std::min(255, std::max(0, (int)(r1 + ((r2 - r1) * gradient)))); + green = (unsigned char)std::min(255, std::max(0, (int)(g1 + ((g2 - g1) * gradient)))); + blue = (unsigned char)std::min(255, std::max(0, (int)(b1 + ((b2 - b1) * gradient)))); + + int height = (4 * gradient)+1; // make it at least 4 thick, so we get some averaging + for (int i = 0; i < height; i++) { + tree->createVoxel(x, ((i+1) * voxelSize) , z, voxelSize, red, green, blue); + } + } + } + printf("DONE adding surface scene...\n"); +} diff --git a/voxel-edit/src/SceneUtils.h b/voxel-edit/src/SceneUtils.h new file mode 100644 index 0000000000..6f52a14f05 --- /dev/null +++ b/voxel-edit/src/SceneUtils.h @@ -0,0 +1,19 @@ +// +// SceneUtils.h +// hifi +// +// Created by Brad Hefta-Gaub on 5/7/2013. +// +// + +#ifndef __hifi__SceneUtil__ +#define __hifi__SceneUtil__ + +#include "VoxelTree.h" +#include + +void addCornersAndAxisLines(VoxelTree* tree); +void addSurfaceScene(VoxelTree * tree); + + +#endif /* defined(__hifi__SceneUtil__) */ diff --git a/voxel-edit/src/main.cpp b/voxel-edit/src/main.cpp index b1dde051ae..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 From de0baddef6120b2f8264a5e0cb751bc8b427ad78 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 13:42:33 -0800 Subject: [PATCH 09/32] remove scene utils from voxels --- libraries/voxels/src/SceneUtils.cpp | 58 ----------------------------- libraries/voxels/src/SceneUtils.h | 19 ---------- 2 files changed, 77 deletions(-) delete mode 100644 libraries/voxels/src/SceneUtils.cpp delete mode 100644 libraries/voxels/src/SceneUtils.h diff --git a/libraries/voxels/src/SceneUtils.cpp b/libraries/voxels/src/SceneUtils.cpp deleted file mode 100644 index 2cbe73c74e..0000000000 --- a/libraries/voxels/src/SceneUtils.cpp +++ /dev/null @@ -1,58 +0,0 @@ -// -// SceneUtils.cpp -// hifi -// -// Created by Brad Hefta-Gaub on 5/7/2013. -// Copyright (c) 2013 HighFidelity, Inc. All rights reserved. -// - -#include - -#include - -#include "SceneUtils.h" - -void addCornersAndAxisLines(VoxelTree* tree) { - // We want our corner voxels to be about 1/2 meter high, and our TREE_SCALE is in meters, so... - float voxelSize = 0.5f / TREE_SCALE; - - // Now some more examples... a little more complex - printf("creating corner points...\n"); - tree->createVoxel(0 , 0 , 0 , voxelSize, 255, 255 ,255); - tree->createVoxel(1.0 - voxelSize, 0 , 0 , voxelSize, 255, 0 ,0 ); - tree->createVoxel(0 , 1.0 - voxelSize, 0 , voxelSize, 0 , 255 ,0 ); - tree->createVoxel(0 , 0 , 1.0 - voxelSize, voxelSize, 0 , 0 ,255); - tree->createVoxel(1.0 - voxelSize, 0 , 1.0 - voxelSize, voxelSize, 255, 0 ,255); - tree->createVoxel(0 , 1.0 - voxelSize, 1.0 - voxelSize, voxelSize, 0 , 255 ,255); - 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"); -} - -void addSurfaceScene(VoxelTree * tree) { - printf("adding surface scene...\n"); - float voxelSize = 1.f / (8 * TREE_SCALE); - - // color 1= blue, color 2=green - unsigned char r1, g1, b1, r2, g2, b2, red, green, blue; - r1 = r2 = b2 = g1 = 0; - b1 = g2 = 255; - - for (float x = 0.0; x < 1.0; x += voxelSize) { - for (float z = 0.0; z < 1.0; z += voxelSize) { - - glm::vec2 position = glm::vec2(x, z); - float perlin = glm::perlin(position) + .25f * glm::perlin(position * 4.f) + .125f * glm::perlin(position * 16.f); - float gradient = (1.0f + perlin)/ 2.0f; - red = (unsigned char)std::min(255, std::max(0, (int)(r1 + ((r2 - r1) * gradient)))); - green = (unsigned char)std::min(255, std::max(0, (int)(g1 + ((g2 - g1) * gradient)))); - blue = (unsigned char)std::min(255, std::max(0, (int)(b1 + ((b2 - b1) * gradient)))); - - int height = (4 * gradient)+1; // make it at least 4 thick, so we get some averaging - for (int i = 0; i < height; i++) { - tree->createVoxel(x, ((i+1) * voxelSize) , z, voxelSize, red, green, blue); - } - } - } - printf("DONE adding surface scene...\n"); -} diff --git a/libraries/voxels/src/SceneUtils.h b/libraries/voxels/src/SceneUtils.h deleted file mode 100644 index 6f52a14f05..0000000000 --- a/libraries/voxels/src/SceneUtils.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// SceneUtils.h -// hifi -// -// Created by Brad Hefta-Gaub on 5/7/2013. -// -// - -#ifndef __hifi__SceneUtil__ -#define __hifi__SceneUtil__ - -#include "VoxelTree.h" -#include - -void addCornersAndAxisLines(VoxelTree* tree); -void addSurfaceScene(VoxelTree * tree); - - -#endif /* defined(__hifi__SceneUtil__) */ From f09521f67c2698d932db5fd45b2c3af51db6a870 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 13:50:46 -0800 Subject: [PATCH 10/32] oops --- interface/src/Application.h | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index 0f201b20aa..ed6e8be166 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -37,7 +37,6 @@ #include "ControllerScriptingInterface.h" #include "DatagramProcessor.h" #include "Environment.h" -#include "ExperimentalVoxelTreeRenderer.h" #include "FileLogger.h" #include "GLCanvas.h" #include "Menu.h" From ded7328959b5f34dbe441108eb1db64a32c26ba6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 15:17:49 -0800 Subject: [PATCH 11/32] clean up application access to deleteVoxelAt()/createVoxel()/getVoxelAt() to access VoxelTree directly --- interface/src/Application.cpp | 16 +++++------ interface/src/VoxelSystem.cpp | 28 ------------------- interface/src/VoxelSystem.h | 5 ---- libraries/octree/src/Octree.cpp | 2 ++ libraries/voxels/src/VoxelTree.cpp | 9 ++---- .../voxels/src/VoxelsScriptingInterface.cpp | 6 ---- 6 files changed, 13 insertions(+), 53 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 28db3d8791..74d8afec54 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1288,7 +1288,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); } @@ -1310,8 +1310,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); } @@ -1370,7 +1369,8 @@ 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); @@ -1415,7 +1415,7 @@ 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); } @@ -1438,7 +1438,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 @@ -1458,7 +1458,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); } @@ -3206,7 +3206,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/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index f91e6eb1ff..8b43491a46 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -2302,34 +2302,6 @@ bool VoxelSystem::findCapsulePenetration(const glm::vec3& start, const glm::vec3 return result; } -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::copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destination, bool rebaseToRoot) { _tree->copySubTreeIntoNewTree(startNode, destination->_tree, rebaseToRoot); destination->setupNewVoxelsForDrawing(); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 113c341ecc..7fa6746330 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -93,11 +93,6 @@ public: 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 copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destinationTree, bool rebaseToRoot); void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelTree* destinationTree, bool rebaseToRoot); void copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelTreeElement* destinationNode); diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 051d4f5ca2..e63424d92b 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 } diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 272668a19e..8ba3f34081 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -47,12 +47,9 @@ 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; } diff --git a/libraries/voxels/src/VoxelsScriptingInterface.cpp b/libraries/voxels/src/VoxelsScriptingInterface.cpp index db61460d69..be7c9664a0 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(); } } From 9bd29bdd92d7422805e47655ad32642a3cd97fb7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 15:34:36 -0800 Subject: [PATCH 12/32] removed findSpherePenetration() and findCapsulePenetration() from VoxelSystem, use VoxelTree --- interface/src/Application.h | 1 + interface/src/VoxelSystem.cpp | 22 -------------- interface/src/VoxelSystem.h | 3 -- interface/src/avatar/MyAvatar.cpp | 2 +- libraries/octree/src/Octree.cpp | 48 +++++++++++++++++++------------ 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index ed6e8be166..91ccdaa02e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.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; } diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 8b43491a46..7110dde688 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -2280,28 +2280,6 @@ bool VoxelSystem::findRayIntersection(const glm::vec3& origin, const glm::vec3& 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; -} - void VoxelSystem::copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destination, bool rebaseToRoot) { _tree->copySubTreeIntoNewTree(startNode, destination->_tree, rebaseToRoot); destination->setupNewVoxelsForDrawing(); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 7fa6746330..17c6dc8bff 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -90,9 +90,6 @@ public: 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 copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destinationTree, bool rebaseToRoot); void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelTree* destinationTree, bool rebaseToRoot); void copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelTreeElement* destinationNode); 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/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index e63424d92b..49f1bc9c3a 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -628,18 +628,23 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) { bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) { - SphereArgs args = { - center / (float)(TREE_SCALE), - radius / (float)(TREE_SCALE), - penetration, - false, - NULL }; - penetration = glm::vec3(0.0f, 0.0f, 0.0f); - recurseTreeWithOperation(findSpherePenetrationOp, &args); - if (penetratedObject) { - *penetratedObject = args.penetratedObject; + bool result = false; // assume no penetration + if (tryLockForRead()) { + SphereArgs args = { + center / (float)(TREE_SCALE), + radius / (float)(TREE_SCALE), + penetration, + false, + NULL }; + penetration = glm::vec3(0.0f, 0.0f, 0.0f); + recurseTreeWithOperation(findSpherePenetrationOp, &args); + if (penetratedObject) { + *penetratedObject = args.penetratedObject; + } + unlock(); + result = args.found; } - return args.found; + return result; } class CapsuleArgs { @@ -673,14 +678,19 @@ bool findCapsulePenetrationOp(OctreeElement* node, void* extraData) { } bool Octree::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) { - CapsuleArgs args = { - start / (float)(TREE_SCALE), - end / (float)(TREE_SCALE), - radius / (float)(TREE_SCALE), - penetration }; - penetration = glm::vec3(0.0f, 0.0f, 0.0f); - recurseTreeWithOperation(findCapsulePenetrationOp, &args); - return args.found; + bool result = false; // assume no penetration + if (tryLockForRead()) { + CapsuleArgs args = { + start / (float)(TREE_SCALE), + end / (float)(TREE_SCALE), + radius / (float)(TREE_SCALE), + penetration }; + penetration = glm::vec3(0.0f, 0.0f, 0.0f); + recurseTreeWithOperation(findCapsulePenetrationOp, &args); + result = args.found; + unlock(); + } + return result; } int Octree::encodeTreeBitstream(OctreeElement* node, From f0e73d2f981f316d1af60debc7a8ec9bd45df539 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 15:46:33 -0800 Subject: [PATCH 13/32] removed VoxelSystem::findRayIntersection() use tree directly --- interface/src/Application.cpp | 2 +- interface/src/VoxelSystem.cpp | 24 ------------------------ interface/src/VoxelSystem.h | 3 --- libraries/voxels/src/VoxelTree.cpp | 25 +++++++++++++++++++++++++ libraries/voxels/src/VoxelTree.h | 4 +++- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 74d8afec54..a9ef383e56 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1740,7 +1740,7 @@ void Application::updateHoverVoxels(float deltaTime, float& distance, BoxFace& f if (!_mousePressed) { PerformanceWarning warn(showWarnings, "Application::updateHoverVoxels() _voxels.findRayIntersection()"); - _isHoverVoxel = _voxels.findRayIntersection(_mouseRayOrigin, _mouseRayDirection, _hoverVoxel, distance, face); + _isHoverVoxel = getVoxelTree()->findRayIntersectionDetail(_mouseRayOrigin, _mouseRayDirection, _hoverVoxel, distance, face); } } diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 7110dde688..c39f50c61f 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -2256,30 +2256,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; -} - void VoxelSystem::copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destination, bool rebaseToRoot) { _tree->copySubTreeIntoNewTree(startNode, destination->_tree, rebaseToRoot); destination->setupNewVoxelsForDrawing(); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 17c6dc8bff..409fc9e740 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -87,9 +87,6 @@ public: bool hasViewChanged(); bool isViewChanging(); - bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - VoxelDetail& detail, float& distance, BoxFace& face); - void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelSystem* destinationTree, bool rebaseToRoot); void copySubTreeIntoNewTree(VoxelTreeElement* startNode, VoxelTree* destinationTree, bool rebaseToRoot); void copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelTreeElement* destinationNode); diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 8ba3f34081..4fd3490c45 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -562,3 +562,28 @@ int VoxelTree::processEditPacketData(PacketType packetType, const unsigned char* } } + +bool VoxelTree::findRayIntersectionDetail(const glm::vec3& origin, const glm::vec3& direction, + VoxelDetail& detail, float& distance, BoxFace& face) { + + bool result = false; // assume no intersection + if (tryLockForRead()) { + OctreeElement* element; + result = 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]; + } + unlock(); + } + return result; +} + + + diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 388b71bfca..5f56b88d6f 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -44,7 +44,9 @@ 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); + + bool findRayIntersectionDetail(const glm::vec3& origin, const glm::vec3& direction, + VoxelDetail& detail, float& distance, BoxFace& face); private: // helper functions for nudgeSubTree From 5f6a60e78647f509713ac313bd84de4b933691e9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 16:40:27 -0800 Subject: [PATCH 14/32] removed more VoxelSystem wrappers, call VoxelTree directly --- interface/src/Application.cpp | 5 +++-- interface/src/VoxelSystem.cpp | 17 ----------------- interface/src/VoxelSystem.h | 6 ------ 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a9ef383e56..544b4ea535 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1373,7 +1373,7 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) { 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,7 +1417,8 @@ void Application::copyVoxels(const VoxelDetail& sourceVoxel) { // then copy onto it if there is something to copy 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(); } } diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index c39f50c61f..ea73f91f26 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -2256,23 +2256,6 @@ bool VoxelSystem::hideOutOfViewOperation(OctreeElement* element, void* extraData } -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); -} - 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 409fc9e740..fb7878154e 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -87,12 +87,6 @@ public: bool hasViewChanged(); bool isViewChanging(); - 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); - virtual void elementDeleted(OctreeElement* element); virtual void elementUpdated(OctreeElement* element); From 63bebc9afcc6bb34743d01ff7d9b0e74c8a158f9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 16:44:25 -0800 Subject: [PATCH 15/32] removed dead code --- interface/src/VoxelSystem.cpp | 103 ---------------------------------- interface/src/VoxelSystem.h | 2 - 2 files changed, 105 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index ea73f91f26..28fb34d089 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -675,8 +675,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; @@ -1836,94 +1834,10 @@ VoxelTreeElement* VoxelSystem::getVoxelEnclosing(const glm::vec3& point) { return voxelAndPoint.voxel; } -// 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 @@ -1952,23 +1866,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 hideOutOfViewArgs { public: diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index fb7878154e..e956393c87 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -81,7 +81,6 @@ public: void killLocalVoxels(); - virtual void removeOutOfView(); virtual void hideOutOfView(bool forceFullFrustum = false); void inspectForOcclusions(); bool hasViewChanged(); @@ -145,7 +144,6 @@ private: // Operation functions for tree recursion methods static int _nodeCount; - static bool removeOutOfViewOperation(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); From 176270f6395645098eec3b59a2135491b63ac2d1 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 16:51:40 -0800 Subject: [PATCH 16/32] more VoxelSystem vs VoxelTree cleanup --- interface/src/VoxelImporter.cpp | 6 +++--- interface/src/VoxelSystem.cpp | 28 ---------------------------- interface/src/VoxelSystem.h | 5 ----- libraries/octree/src/Octree.h | 3 --- 4 files changed, 3 insertions(+), 39 deletions(-) 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 28fb34d089..499b0d7212 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -524,34 +524,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); diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index e956393c87..f0d78d82c2 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -67,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; } diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index 8e7f9b0b23..807de85607 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -235,9 +235,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(); } From d9dcc886ce0c75e0b969b4944dac6a6e7b1c5ee6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 16:57:19 -0800 Subject: [PATCH 17/32] removed some dead code --- interface/src/VoxelSystem.cpp | 5 ----- interface/src/VoxelSystem.h | 6 ------ 2 files changed, 11 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 499b0d7212..6e7c24777f 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -1806,11 +1806,6 @@ VoxelTreeElement* VoxelSystem::getVoxelEnclosing(const glm::vec3& point) { return voxelAndPoint.voxel; } -void VoxelSystem::cancelImport() { - _tree->cancelImport(); -} - - bool VoxelSystem::isViewChanging() { bool result = false; // assume the best diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index f0d78d82c2..09b0be6d43 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -86,10 +86,6 @@ public: 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); @@ -101,8 +97,6 @@ public slots: void cullSharedFaces(); void showCulledSharedFaces(); - void cancelImport(); - void setDisableFastVoxelPipeline(bool disableFastVoxelPipeline); void setUseVoxelShader(bool useVoxelShader); void setVoxelsAsPoints(bool voxelsAsPoints); From 633f358319f5cc0ec5c680ed9c5decfaed0c149d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 17:03:57 -0800 Subject: [PATCH 18/32] removed some dead code --- interface/src/VoxelSystem.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 09b0be6d43..512ff1c065 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -109,18 +109,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 From cb4219b775483cadab4a23b112fc56ead6eb93f4 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 19:23:00 -0800 Subject: [PATCH 19/32] remove HoverVoxel --- interface/src/Application.cpp | 25 ------------------------- interface/src/Application.h | 4 ---- 2 files changed, 29 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 544b4ea535..76295fe702 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -139,7 +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), @@ -1029,11 +1028,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 } @@ -1701,9 +1695,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 : @@ -1734,17 +1725,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 = getVoxelTree()->findRayIntersectionDetail(_mouseRayOrigin, _mouseRayDirection, _hoverVoxel, distance, face); - } -} - void Application::updateHandAndTouch(float deltaTime) { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::updateHandAndTouch()"); @@ -1893,11 +1873,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 diff --git a/interface/src/Application.h b/interface/src/Application.h index 91ccdaa02e..ee8c1148fc 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -292,7 +292,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); @@ -429,9 +428,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; From 855e351f397598ececd4d9d960525c91762548df Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 19:37:40 -0800 Subject: [PATCH 20/32] remove some ray pick helper code that was only used by hover voxel, main ray pick still exists --- libraries/voxels/src/VoxelTree.cpp | 26 -------------------------- libraries/voxels/src/VoxelTree.h | 3 --- 2 files changed, 29 deletions(-) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 4fd3490c45..ea784b2e16 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -561,29 +561,3 @@ int VoxelTree::processEditPacketData(PacketType packetType, const unsigned char* return 0; } } - - -bool VoxelTree::findRayIntersectionDetail(const glm::vec3& origin, const glm::vec3& direction, - VoxelDetail& detail, float& distance, BoxFace& face) { - - bool result = false; // assume no intersection - if (tryLockForRead()) { - OctreeElement* element; - result = 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]; - } - unlock(); - } - return result; -} - - - diff --git a/libraries/voxels/src/VoxelTree.h b/libraries/voxels/src/VoxelTree.h index 5f56b88d6f..2079ab91b2 100644 --- a/libraries/voxels/src/VoxelTree.h +++ b/libraries/voxels/src/VoxelTree.h @@ -45,9 +45,6 @@ public: virtual int processEditPacketData(PacketType packetType, const unsigned char* packetData, int packetLength, const unsigned char* editData, int maxLength, const SharedNodePointer& node); - bool findRayIntersectionDetail(const glm::vec3& origin, const glm::vec3& direction, - VoxelDetail& detail, float& distance, BoxFace& face); - private: // helper functions for nudgeSubTree void recurseNodeForNudge(VoxelTreeElement* element, RecurseOctreeOperation operation, void* extraData); From f245aa6ac55b7e759eb55b9004b14bccadf125fb Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 20:12:52 -0800 Subject: [PATCH 21/32] remove more cruft from VoxelSystem, move getElementEnclosingPoint() to Octree class where it belongs --- interface/src/VoxelSystem.cpp | 32 ---------- interface/src/VoxelSystem.h | 2 - interface/src/avatar/Hand.cpp | 18 +++--- libraries/octree/src/Octree.cpp | 104 ++++++++++++++++++++++++-------- libraries/octree/src/Octree.h | 9 ++- 5 files changed, 95 insertions(+), 70 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 6e7c24777f..0f90d51332 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -1774,38 +1774,6 @@ void VoxelSystem::forceRedrawEntireTree() { 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; -} - bool VoxelSystem::isViewChanging() { bool result = false; // assume the best diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index 512ff1c065..b49891f8d9 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -84,8 +84,6 @@ public: virtual void elementDeleted(OctreeElement* element); virtual void elementUpdated(OctreeElement* element); - VoxelTreeElement* getVoxelEnclosing(const glm::vec3& point); - public slots: void nodeAdded(SharedNodePointer node); void nodeKilled(SharedNodePointer node); diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 51f919130b..e04760526a 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -87,23 +87,25 @@ void Hand::simulate(float deltaTime, bool isMine) { // Voxel Drumming with fingertips if enabled if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelDrumming)) { - VoxelTreeElement* fingerNode = Application::getInstance()->getVoxels()->getVoxelEnclosing( + OctreeElement* fingerElement = Application::getInstance()->getVoxelTree()->getElementEnclosingPoint( glm::vec3(fingerTipPosition / (float)TREE_SCALE)); - if (fingerNode) { + VoxelTreeElement* fingerVoxel = static_cast(fingerElement); + if (fingerVoxel) { if (!palm.getIsCollidingWithVoxel()) { // Collision has just started palm.setIsCollidingWithVoxel(true); - handleVoxelCollision(&palm, fingerTipPosition, fingerNode, deltaTime); + handleVoxelCollision(&palm, fingerTipPosition, fingerVoxel, deltaTime); + // Set highlight voxel VoxelDetail voxel; - glm::vec3 pos = fingerNode->getCorner(); + glm::vec3 pos = fingerVoxel->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]; + voxel.s = fingerVoxel->getScale(); + voxel.red = fingerVoxel->getColor()[0]; + voxel.green = fingerVoxel->getColor()[1]; + voxel.blue = fingerVoxel->getColor()[2]; Application::getInstance()->setHighlightVoxel(voxel); Application::getInstance()->setIsHighlightVoxel(true); } diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 49f1bc9c3a..446eb25a50 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -588,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; } @@ -626,25 +633,27 @@ bool findSpherePenetrationOp(OctreeElement* element, void* extraData) { } bool Octree::findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, - void** penetratedObject) { + void** penetratedObject, bool tryLock) { - bool result = false; // assume no penetration - if (tryLockForRead()) { - SphereArgs args = { - center / (float)(TREE_SCALE), - radius / (float)(TREE_SCALE), - penetration, - false, - NULL }; - penetration = glm::vec3(0.0f, 0.0f, 0.0f); + SphereArgs args = { + center / (float)(TREE_SCALE), + radius / (float)(TREE_SCALE), + penetration, + false, + NULL }; + penetration = glm::vec3(0.0f, 0.0f, 0.0f); + + if (!tryLock) { + lockForRead(); + } + if (tryLock && tryLockForRead()) { recurseTreeWithOperation(findSpherePenetrationOp, &args); if (penetratedObject) { *penetratedObject = args.penetratedObject; } unlock(); - result = args.found; } - return result; + return args.found; } class CapsuleArgs { @@ -677,22 +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 result = false; // assume no penetration - if (tryLockForRead()) { - CapsuleArgs args = { - start / (float)(TREE_SCALE), - end / (float)(TREE_SCALE), - radius / (float)(TREE_SCALE), - penetration }; - penetration = glm::vec3(0.0f, 0.0f, 0.0f); +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, + false }; + penetration = glm::vec3(0.0f, 0.0f, 0.0f); + + if (!tryLock) { + lockForRead(); + } + if (tryLock && tryLockForRead()) { recurseTreeWithOperation(findCapsulePenetrationOp, &args); - result = args.found; unlock(); } - return result; + 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 807de85607..9db83d47b1 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -222,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); From bde39d9832fbbde304a469993cc2ef882b2c44d0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 20:28:20 -0800 Subject: [PATCH 22/32] expose getVoxelEnclosingPoint() to JS, and clean up JS version of findRayIntersection() --- .../voxels/src/VoxelsScriptingInterface.cpp | 46 +++++++++++++------ .../voxels/src/VoxelsScriptingInterface.h | 5 ++ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/libraries/voxels/src/VoxelsScriptingInterface.cpp b/libraries/voxels/src/VoxelsScriptingInterface.cpp index be7c9664a0..3dade9f399 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.cpp +++ b/libraries/voxels/src/VoxelsScriptingInterface.cpp @@ -84,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; @@ -121,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); + 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); From 6ddc6132fd1c46aa8998e32f8c4fc5abf4ae7d67 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 21:53:36 -0800 Subject: [PATCH 23/32] removed unneeded class def --- libraries/audio/src/AudioInjector.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/audio/src/AudioInjector.h b/libraries/audio/src/AudioInjector.h index 1e09a2c3c2..fdc81a72a4 100644 --- a/libraries/audio/src/AudioInjector.h +++ b/libraries/audio/src/AudioInjector.h @@ -19,7 +19,6 @@ #include "Sound.h" class AbstractAudioInterface; -class AudioScriptingInterface; class AudioInjector : public QObject { Q_OBJECT From 3479f72ec90bf1ccbe26c9a372297c30bfd02e6b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 2 Mar 2014 21:55:05 -0800 Subject: [PATCH 24/32] removed _ballColor from Hand since it was never actually used --- interface/src/avatar/Hand.cpp | 9 --------- interface/src/avatar/Hand.h | 2 -- 2 files changed, 11 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index e04760526a..60e41ec7ad 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -29,7 +29,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 +36,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() { @@ -351,7 +343,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; From 2c7d9d7a069402835d4d85ef8ff9291402d45b0f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Mar 2014 00:35:46 -0800 Subject: [PATCH 25/32] removed unneeded class declaration --- libraries/audio/src/AudioInjector.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/audio/src/AudioInjector.h b/libraries/audio/src/AudioInjector.h index fdc81a72a4..beff33a9ef 100644 --- a/libraries/audio/src/AudioInjector.h +++ b/libraries/audio/src/AudioInjector.h @@ -18,8 +18,6 @@ #include "AudioInjectorOptions.h" #include "Sound.h" -class AbstractAudioInterface; - class AudioInjector : public QObject { Q_OBJECT public: From d8d61c736170b19c7454c32440e791c6ca62ba07 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Mar 2014 01:06:48 -0800 Subject: [PATCH 26/32] move hydra finger painting from c++ to js --- examples/editVoxels.js | 49 +++++++++++++++++++++++++++++++++++ interface/src/VoxelSystem.cpp | 6 ----- interface/src/avatar/Hand.cpp | 21 --------------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/examples/editVoxels.js b/examples/editVoxels.js index ed63c12eb9..bf0e455b29 100644 --- a/examples/editVoxels.js +++ b/examples/editVoxels.js @@ -1277,12 +1277,61 @@ 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 palmPosition = Controller.getSpatialControlPosition(palmController); + + var fingerTipController = palmController + 1; + var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController); + + var BUTTON_COUNT = 6; + var BUTTON_BASE = palm * BUTTON_COUNT; + var BUTTON_0 = BUTTON_BASE + 0; // the skinny button between 1 and 2 + var BUTTON_1 = BUTTON_BASE + 1; + var BUTTON_2 = BUTTON_BASE + 2; + var BUTTON_3 = BUTTON_BASE + 3; + var BUTTON_4 = BUTTON_BASE + 4; + var BUTTON_FWD = BUTTON_BASE + 5; + 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/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 0f90d51332..e60165647f 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -82,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; @@ -1185,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(); } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 60e41ec7ad..ed065fb2a5 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; @@ -57,26 +56,6 @@ void Hand::simulate(float deltaTime, bool isMine) { 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)) { OctreeElement* fingerElement = Application::getInstance()->getVoxelTree()->getElementEnclosingPoint( From 011bc4f6cbd55251eb7ec81bc8aa37e4d5179d2a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Mar 2014 01:11:03 -0800 Subject: [PATCH 27/32] slightly less code to get it done --- examples/editVoxels.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/examples/editVoxels.js b/examples/editVoxels.js index bf0e455b29..cfea508912 100644 --- a/examples/editVoxels.js +++ b/examples/editVoxels.js @@ -1284,19 +1284,13 @@ function checkControllers() { var controllersPerPalm = 2; // palm and finger for (var palm = 0; palm < 2; palm++) { var palmController = palm * controllersPerPalm; - var palmPosition = Controller.getSpatialControlPosition(palmController); - var fingerTipController = palmController + 1; var fingerTipPosition = Controller.getSpatialControlPosition(fingerTipController); var BUTTON_COUNT = 6; var BUTTON_BASE = palm * BUTTON_COUNT; - var BUTTON_0 = BUTTON_BASE + 0; // the skinny button between 1 and 2 var BUTTON_1 = BUTTON_BASE + 1; var BUTTON_2 = BUTTON_BASE + 2; - var BUTTON_3 = BUTTON_BASE + 3; - var BUTTON_4 = BUTTON_BASE + 4; - var BUTTON_FWD = BUTTON_BASE + 5; var FINGERTIP_VOXEL_SIZE = 0.05; if (Controller.isButtonPressed(BUTTON_1)) { From 59eefa314c27cd093eb91b56c603a86d3fcd822a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Mar 2014 03:17:16 -0800 Subject: [PATCH 28/32] add support for Audio.startDrumSound() to allow drum sound procedural audio in JS --- libraries/audio/src/AudioInjector.cpp | 2 - .../audio/src/AudioScriptingInterface.cpp | 24 +++++++++- libraries/audio/src/AudioScriptingInterface.h | 2 + libraries/audio/src/Sound.cpp | 45 +++++++++++++++++++ libraries/audio/src/Sound.h | 3 +- 5 files changed, 72 insertions(+), 4 deletions(-) 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/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; } From 372561195ab3a1cb83893070fdfce6b841f2e97c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Mar 2014 04:00:06 -0800 Subject: [PATCH 29/32] remove voxel drumming from C++ --- interface/src/Menu.cpp | 1 - interface/src/Menu.h | 1 - interface/src/avatar/Hand.cpp | 37 ------------------- .../voxels/src/VoxelsScriptingInterface.cpp | 2 +- 4 files changed, 1 insertion(+), 40 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 87cff96284..cb69e8d2eb 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); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 2ccb7c4260..7b4cca3b33 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -280,7 +280,6 @@ namespace MenuOption { 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/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index ed065fb2a5..29e46fc816 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -52,43 +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(); - - // Voxel Drumming with fingertips if enabled - if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelDrumming)) { - OctreeElement* fingerElement = Application::getInstance()->getVoxelTree()->getElementEnclosingPoint( - glm::vec3(fingerTipPosition / (float)TREE_SCALE)); - VoxelTreeElement* fingerVoxel = static_cast(fingerElement); - if (fingerVoxel) { - if (!palm.getIsCollidingWithVoxel()) { - // Collision has just started - palm.setIsCollidingWithVoxel(true); - handleVoxelCollision(&palm, fingerTipPosition, fingerVoxel, deltaTime); - - // Set highlight voxel - VoxelDetail voxel; - glm::vec3 pos = fingerVoxel->getCorner(); - voxel.x = pos.x; - voxel.y = pos.y; - voxel.z = pos.z; - voxel.s = fingerVoxel->getScale(); - voxel.red = fingerVoxel->getColor()[0]; - voxel.green = fingerVoxel->getColor()[1]; - voxel.blue = fingerVoxel->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()); } } diff --git a/libraries/voxels/src/VoxelsScriptingInterface.cpp b/libraries/voxels/src/VoxelsScriptingInterface.cpp index 3dade9f399..2aecb2d457 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.cpp +++ b/libraries/voxels/src/VoxelsScriptingInterface.cpp @@ -121,7 +121,7 @@ glm::vec3 VoxelsScriptingInterface::getFaceVector(const QString& face) { 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); + OctreeElement* element = _tree->getElementEnclosingPoint(point / (float)TREE_SCALE); if (element) { VoxelTreeElement* voxel = static_cast(element); result.x = voxel->getCorner().x; From 85b40f2d13d5f3d5a1cd31ae817e500ef27277d7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Mar 2014 04:05:44 -0800 Subject: [PATCH 30/32] fix crash in Menu.isOptionChecked() if menu item doesn't exist --- interface/src/Menu.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index cb69e8d2eb..dc87cefb05 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -576,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) { From 37472c201ce1f7eb893cbb01fc39fe98b4eb35da Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Mar 2014 04:06:47 -0800 Subject: [PATCH 31/32] added voxelDrumming as JS --- examples/voxelDrumming.js | 167 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 examples/voxelDrumming.js 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); From 9d5e33d75d525a8e76e9d5a393dccfa66d126b15 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 3 Mar 2014 04:09:33 -0800 Subject: [PATCH 32/32] removed unused highlight voxel --- interface/src/Application.cpp | 20 -------------------- interface/src/Application.h | 8 -------- 2 files changed, 28 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 76295fe702..f33c7aea32 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -139,7 +139,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _touchAvgY(0.0f), _isTouchPressed(false), _mousePressed(false), - _isHighlightVoxel(false), _chatEntryOn(false), _audio(&_audioScope, STARTUP_JITTER_SAMPLES), _enableProcessVoxelsThread(true), @@ -1611,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); @@ -2377,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); diff --git a/interface/src/Application.h b/interface/src/Application.h index ee8c1148fc..78826b4fd0 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -215,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: @@ -307,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); @@ -428,9 +423,6 @@ private: bool _mousePressed; // true if mouse has been pressed (clear when finished) - VoxelDetail _highlightVoxel; - bool _isHighlightVoxel; - ChatEntry _chatEntry; // chat entry field bool _chatEntryOn; // Whether to show the chat entry