From 4166c3224f331a2036921e6c49f6d39121de88b7 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 19 May 2015 16:24:13 -0700 Subject: [PATCH 01/80] link polyvox library in with entities --- CMakeLists.txt | 1 + cmake/externals/polyvox/CMakeLists.txt | 34 ++++++++++++++++++ cmake/modules/FindPolyVox.cmake | 50 ++++++++++++++++++++++++++ libraries/entities/CMakeLists.txt | 6 +++- 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 cmake/externals/polyvox/CMakeLists.txt create mode 100644 cmake/modules/FindPolyVox.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 347341efa0..b27f8862de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -179,6 +179,7 @@ option(GET_TBB "Get Threading Building Blocks library automatically as external option(GET_LIBOVR "Get LibOVR library automatically as external project" 1) option(USE_NSIGHT "Attempt to find the nSight libraries" 1) option(GET_VHACD "Get V-HACD library automatically as external project" 1) +option(GET_POLYVOX "Get polyvox library automatically as external project" 1) if (WIN32) option(GET_GLEW "Get GLEW library automatically as external project" 1) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt new file mode 100644 index 0000000000..5c1ea4f378 --- /dev/null +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -0,0 +1,34 @@ +set(EXTERNAL_NAME polyvox) + +include(ExternalProject) +ExternalProject_Add( + ${EXTERNAL_NAME} + # URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master.zip + URL http://headache.hungry.com/~seth/hifi/polyvox-master.zip + URL_MD5 bbf8040b1e3f338cd51bdcccd0945978 + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= + BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_BUILD 1 +) + +ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) + +string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) +set(${EXTERNAL_NAME_UPPER}_CORE_INCLUDE_DIRS ${INSTALL_DIR}/include/PolyVoxCore CACHE FILEPATH + "Path to polyvox core include directory") +set(${EXTERNAL_NAME_UPPER}_UTIL_INCLUDE_DIRS ${INSTALL_DIR}/include/PolyVoxUtil CACHE FILEPATH + "Path to polyvox util include directory") + + +if (WIN32) + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox util library") +elseif (APPLE) + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox util library") +else () + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxUtil.so CACHE FILEPATH "polyvox util library") +endif () diff --git a/cmake/modules/FindPolyVox.cmake b/cmake/modules/FindPolyVox.cmake new file mode 100644 index 0000000000..1ddab877dd --- /dev/null +++ b/cmake/modules/FindPolyVox.cmake @@ -0,0 +1,50 @@ +# +# FindPolyvox.cmake +# +# Try to find the libpolyvox resampling library +# +# You can provide a LIBPOLYVOX_ROOT_DIR which contains lib and include directories +# +# Once done this will define +# +# POLYVOX_FOUND - system found libpolyvox +# POLYVOX_INCLUDE_DIRS - the libpolyvox include directory +# POLYVOX_LIBRARIES - link to this to use libpolyvox +# +# Created on 1/22/2015 by Stephen Birarda +# Copyright 2015 High Fidelity, Inc. +# +# Distributed under the Apache License, Version 2.0. +# See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +# + +include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") +hifi_library_search_hints("polyvox") + +find_path(POLYVOX_CORE_INCLUDE_DIRS PolyVoxCore/SimpleVolume.h PATH_SUFFIXES include/PolyVoxCore HINTS ${POLYVOX_SEARCH_DIRS}) +find_path(POLYVOX_UTIL_INCLUDE_DIRS PolyVoxUtil/Serialization.h PATH_SUFFIXES include/PolyVoxUtil HINTS ${POLYVOX_SEARCH_DIRS}) + +find_library(POLYVOX_CORE_LIBRARY NAMES PolyVoxCore PATH_SUFFIXES lib HINTS ${POLYVOX_SEARCH_DIRS}) +find_library(POLYVOX_UTIL_LIBRARY NAMES PolyVoxUtil PATH_SUFFIXES lib HINTS ${POLYVOX_SEARCH_DIRS}) + + +if (WIN32) + find_path(POLYVOX_DLL_PATH polyvox.dll PATH_SUFFIXES bin HINTS ${POLYVOX_SEARCH_DIRS}) +endif() + +set(POLYVOX_REQUIREMENTS POLYVOX_CORE_INCLUDE_DIRS POLYVOX_UTIL_INCLUDE_DIRS POLYVOX_CORE_LIBRARY POLYVOX_UTIL_LIBRARY) +if (WIN32) + list(APPEND POLYVOX_REQUIREMENTS POLYVOX_DLL_PATH) +endif () + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Polyvox DEFAULT_MSG ${POLYVOX_REQUIREMENTS}) + +if (WIN32) + add_paths_to_fixup_libs(${POLYVOX_DLL_PATH}) +endif () + +set(POLYVOX_INCLUDE_DIRS ${POLYVOX_CORE_INCLUDE_DIRS} ${POLYVOX_UTIL_INCLUDE_DIRS}) +set(POLYVOX_LIBRARIES ${POLYVOX_CORE_LIBRARY} ${POLYVOX_UTIL_LIBRARY}) + +mark_as_advanced(POLYVOX_INCLUDE_DIRS POLYVOX_LIBRARIES POLYVOX_SEARCH_DIRS) diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index d21906fa3f..c78166b050 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -7,10 +7,14 @@ add_dependency_external_projects(glm) find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) -add_dependency_external_projects(bullet) +add_dependency_external_projects(bullet polyvox) find_package(Bullet REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) +find_package(PolyVox REQUIRED) +target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${POLYVOX_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${POLYVOX_LIBRARIES}) + link_hifi_libraries(avatars shared octree gpu model fbx networking animation environment) From 4b263cf5c895a34f3f24998f9861059056a69566 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 19 May 2015 21:40:05 -0700 Subject: [PATCH 02/80] derieve PolyVox Entity from Model Entity --- .../src/EntityTreeRenderer.cpp | 2 + .../src/RenderableModelEntityItem.cpp | 7 +- .../src/RenderableModelEntityItem.h | 4 +- .../src/RenderablePolyVoxEntityItem.cpp | 108 ++++++++++++++++++ .../src/RenderablePolyVoxEntityItem.h | 32 ++++++ libraries/entities/CMakeLists.txt | 2 +- libraries/entities/src/EntityItemProperties.h | 1 + libraries/entities/src/EntityTypes.cpp | 2 + libraries/entities/src/EntityTypes.h | 3 +- libraries/entities/src/ModelEntityItem.h | 2 +- libraries/shared/src/ShapeInfo.h | 3 +- 11 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp create mode 100644 libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index bacd6eb56e..99dc43b7db 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -39,6 +39,7 @@ #include "RenderableWebEntityItem.h" #include "RenderableZoneEntityItem.h" #include "RenderableLineEntityItem.h" +#include "RenderablePolyVoxEntityItem.h" #include "EntitiesRendererLogging.h" EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterface* viewState, @@ -65,6 +66,7 @@ EntityTreeRenderer::EntityTreeRenderer(bool wantScripts, AbstractViewStateInterf REGISTER_ENTITY_TYPE_WITH_FACTORY(ParticleEffect, RenderableParticleEffectEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Zone, RenderableZoneEntityItem::factory) REGISTER_ENTITY_TYPE_WITH_FACTORY(Line, RenderableLineEntityItem::factory) + REGISTER_ENTITY_TYPE_WITH_FACTORY(PolyVox, RenderablePolyVoxEntityItem::factory) _currentHoverOverEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID _currentClickingOnEntityID = EntityItemID::createInvalidEntityID(); // makes it the unknown ID diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 43112d7d73..50bd0c9d5c 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -110,7 +110,7 @@ void RenderableModelEntityItem::remapTextures() { void RenderableModelEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RMEIrender"); - assert(getType() == EntityTypes::Model); + assert(getType() == EntityTypes::Model || getType() == EntityTypes::PolyVox); bool drawAsModel = hasModel(); @@ -199,6 +199,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { RenderableDebugableEntityItem::render(this, args); } +// virtual Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) { Model* result = NULL; @@ -207,11 +208,11 @@ Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) { _myRenderer = renderer; } assert(_myRenderer == renderer); // you should only ever render on one renderer - + if (QThread::currentThread() != _myRenderer->thread()) { return _model; } - + _needsModelReload = false; // this is the reload // if we have a URL, then we will want to end up returning a model... diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index efd60faedc..74182b4753 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -49,7 +49,7 @@ public: bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const; - Model* getModel(EntityTreeRenderer* renderer); + virtual Model* getModel(EntityTreeRenderer* renderer); bool needsToCallUpdate() const; @@ -60,7 +60,7 @@ public: virtual bool contains(const glm::vec3& point) const; -private: +protected: void remapTextures(); Model* _model; diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp new file mode 100644 index 0000000000..936a833ec8 --- /dev/null +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -0,0 +1,108 @@ +// +// RenderablePolyVoxEntityItem.cpp +// libraries/entities-renderer/src/ +// +// Created by Seth Alves on 5/19/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include + +#include +#include + +#include +#include +#include +#include + +#include "EntityTreeRenderer.h" +#include "RenderablePolyVoxEntityItem.h" + +EntityItem* RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + return new RenderablePolyVoxEntityItem(entityID, properties); +} + + +void createSphereInVolume(PolyVox::SimpleVolume& volData, float fRadius) { + // This vector hold the position of the center of the volume + PolyVox::Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2); + + // This three-level for loop iterates over every voxel in the volume + for (int z = 0; z < volData.getDepth(); z++) { + for (int y = 0; y < volData.getHeight(); y++) { + for (int x = 0; x < volData.getWidth(); x++) { + // Store our current position as a vector... + PolyVox::Vector3DFloat v3dCurrentPos(x,y,z); + // And compute how far the current position is from the center of the volume + float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length(); + + uint8_t uVoxelValue = 0; + + // If the current voxel is less than 'radius' units from the center then we make it solid. + if(fDistToCenter <= fRadius) { + // Our new voxel value + uVoxelValue = 255; + } + + // Wrte the voxel value into the volume + volData.setVoxelAt(x, y, z, uVoxelValue); + } + } + } +} + + +// virtual +Model* RenderablePolyVoxEntityItem::getModel(EntityTreeRenderer* renderer) { + PolyVox::SimpleVolume volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0), + PolyVox::Vector3DInt32(63, 63, 63))); + createSphereInVolume(volData, 15); + + // A mesh object to hold the result of surface extraction + PolyVox::SurfaceMesh mesh; + + //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. + PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor + (&volData, volData.getEnclosingRegion(), &mesh); + // MarchingCubesSurfaceExtractor> surfaceExtractor(&volData, + // volData.getEnclosingRegion(), + // &mesh); + + //Execute the surface extractor. + surfaceExtractor.execute(); + + const std::vector& vecIndices = mesh.getIndices(); + const std::vector& vecVertices = mesh.getVertices(); + + qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------"; + qDebug() << "---- vecIndices.size() =" << vecIndices.size(); + qDebug() << "---- vecVertices.size() =" << vecVertices.size(); + + + // [DEBUG] [05/19 20:46:38] ---- vecIndices.size() = 101556 + // [DEBUG] [05/19 20:46:38] ---- vecVertices.size() = 67704 + + + Model* result = NULL; + // make sure our renderer is setup + if (!_myRenderer) { + _myRenderer = renderer; + } + assert(_myRenderer == renderer); // you should only ever render on one renderer + + result = _model = _myRenderer->allocateModel(getModelURL(), getCompoundShapeURL()); + assert(_model); + + _needsInitialSimulation = true; + + + + + return result; +} diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h new file mode 100644 index 0000000000..24359accf0 --- /dev/null +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -0,0 +1,32 @@ +// +// RenderablePolyVoxEntityItem.h +// libraries/entities-renderer/src/ +// +// Created by Seth Alves on 5/19/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_RenderablePolyVoxEntityItem_h +#define hifi_RenderablePolyVoxEntityItem_h + +#include + +#include "RenderableModelEntityItem.h" +#include "RenderableDebugableEntityItem.h" + +class RenderablePolyVoxEntityItem : public RenderableModelEntityItem { +public: + static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + + RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + RenderableModelEntityItem(entityItemID, properties) { } + + virtual bool hasModel() const { return true; } + virtual Model* getModel(EntityTreeRenderer* renderer); +}; + + +#endif // hifi_RenderablePolyVoxEntityItem_h diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index c78166b050..c4334edb3a 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -14,7 +14,7 @@ target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) find_package(PolyVox REQUIRED) -target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${POLYVOX_INCLUDE_DIRS}) +target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${POLYVOX_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${POLYVOX_LIBRARIES}) link_hifi_libraries(avatars shared octree gpu model fbx networking animation environment) diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 530013bbb6..dabd47e24e 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -54,6 +54,7 @@ class EntityItemProperties { friend class ZoneEntityItem; // TODO: consider removing this friend relationship and use public methods friend class WebEntityItem; // TODO: consider removing this friend relationship and use public methods friend class LineEntityItem; // TODO: consider removing this friend relationship and use public methods + friend class PolyVoxEntityItem; // TODO: consider removing this friend relationship and use public methods public: EntityItemProperties(); virtual ~EntityItemProperties(); diff --git a/libraries/entities/src/EntityTypes.cpp b/libraries/entities/src/EntityTypes.cpp index 794a77b194..ee62b93604 100644 --- a/libraries/entities/src/EntityTypes.cpp +++ b/libraries/entities/src/EntityTypes.cpp @@ -27,6 +27,7 @@ #include "WebEntityItem.h" #include "ZoneEntityItem.h" #include "LineEntityItem.h" +#include "PolyVoxEntityItem.h" QMap EntityTypes::_typeToNameMap; QMap EntityTypes::_nameToTypeMap; @@ -45,6 +46,7 @@ REGISTER_ENTITY_TYPE(Text) REGISTER_ENTITY_TYPE(ParticleEffect) REGISTER_ENTITY_TYPE(Zone) REGISTER_ENTITY_TYPE(Line) +REGISTER_ENTITY_TYPE(PolyVox) const QString& EntityTypes::getEntityTypeName(EntityType entityType) { QMap::iterator matchedTypeName = _typeToNameMap.find(entityType); diff --git a/libraries/entities/src/EntityTypes.h b/libraries/entities/src/EntityTypes.h index b3de3dfc8e..e02d25400d 100644 --- a/libraries/entities/src/EntityTypes.h +++ b/libraries/entities/src/EntityTypes.h @@ -39,7 +39,8 @@ public: Zone, Web, Line, - LAST = Line + PolyVox, + LAST = PolyVox } EntityType; static const QString& getEntityTypeName(EntityType entityType); diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index d4a4efda04..abfa38250c 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -56,7 +56,7 @@ public: const rgbColor& getColor() const { return _color; } xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; } - bool hasModel() const { return !_modelURL.isEmpty(); } + virtual bool hasModel() const { return !_modelURL.isEmpty(); } virtual bool hasCompoundShapeURL() const { return !_compoundShapeURL.isEmpty(); } static const QString DEFAULT_MODEL_URL; diff --git a/libraries/shared/src/ShapeInfo.h b/libraries/shared/src/ShapeInfo.h index e10cf1a149..5148640d2e 100644 --- a/libraries/shared/src/ShapeInfo.h +++ b/libraries/shared/src/ShapeInfo.h @@ -32,7 +32,8 @@ enum ShapeType { SHAPE_TYPE_CYLINDER_X, SHAPE_TYPE_CYLINDER_Y, SHAPE_TYPE_CYLINDER_Z, - SHAPE_TYPE_LINE + SHAPE_TYPE_LINE, + SHAPE_TYPE_POLYVOX }; class ShapeInfo { From f2c1c43da3d8c86df2f9cffc5ee93b4f76343dd1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 20 May 2015 08:44:41 -0700 Subject: [PATCH 03/80] polyvox code runs, no rendering yet --- .../src/RenderableModelEntityItem.cpp | 2 +- .../src/RenderableModelEntityItem.h | 2 +- .../src/RenderablePolyVoxEntityItem.cpp | 78 ++++++++++++- .../src/RenderablePolyVoxEntityItem.h | 17 ++- libraries/entities/src/PolyVoxEntityItem.cpp | 108 ++++++++++++++++++ libraries/entities/src/PolyVoxEntityItem.h | 68 +++++++++++ 6 files changed, 264 insertions(+), 11 deletions(-) create mode 100644 libraries/entities/src/PolyVoxEntityItem.cpp create mode 100644 libraries/entities/src/PolyVoxEntityItem.h diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 50bd0c9d5c..f7e70b2b56 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -110,7 +110,7 @@ void RenderableModelEntityItem::remapTextures() { void RenderableModelEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RMEIrender"); - assert(getType() == EntityTypes::Model || getType() == EntityTypes::PolyVox); + assert(getType() == EntityTypes::Model); bool drawAsModel = hasModel(); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 74182b4753..8f55e67d09 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -60,7 +60,7 @@ public: virtual bool contains(const glm::vec3& point) const; -protected: +private: void remapTextures(); Model* _model; diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 936a833ec8..a4df131cc3 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -58,7 +59,75 @@ void createSphereInVolume(PolyVox::SimpleVolume& volData, float fRadius } -// virtual + +void RenderablePolyVoxEntityItem::render(RenderArgs* args) { + PerformanceTimer perfTimer("PolyVoxrender"); + assert(getType() == EntityTypes::PolyVox); + + bool drawAsModel = hasModel(); + + glm::vec3 position = getPosition(); + glm::vec3 dimensions = getDimensions(); + + bool didDraw = false; + if (drawAsModel) { + glPushMatrix(); + { + float alpha = getLocalRenderAlpha(); + + if (!_model || _needsModelReload) { + // TODO: this getModel() appears to be about 3% of model render time. We should optimize + PerformanceTimer perfTimer("getModel"); + EntityTreeRenderer* renderer = static_cast(args->_renderer); + getModel(renderer); + } + + if (_model) { + glm::quat rotation = getRotation(); + bool movingOrAnimating = isMoving(); + if ((movingOrAnimating || _needsInitialSimulation) && _model->isActive()) { + _model->setScaleToFit(true, dimensions); + _model->setSnapModelToRegistrationPoint(true, getRegistrationPoint()); + _model->setRotation(rotation); + _model->setTranslation(position); + + // make sure to simulate so everything gets set up correctly for rendering + { + PerformanceTimer perfTimer("_model->simulate"); + _model->simulate(0.0f); + } + _needsInitialSimulation = false; + } + + if (_model->isActive()) { + // TODO: this is the majority of model render time. And rendering of a cube model vs the basic Box render + // is significantly more expensive. Is there a way to call this that doesn't cost us as much? + PerformanceTimer perfTimer("model->render"); + // filter out if not needed to render + if (args && (args->_renderMode == RenderArgs::SHADOW_RENDER_MODE)) { + if (movingOrAnimating) { + _model->renderInScene(alpha, args); + didDraw = true; + } + } else { + _model->renderInScene(alpha, args); + didDraw = true; + } + } + } + } + glPopMatrix(); + } + + if (!didDraw) { + glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); + RenderableDebugableEntityItem::renderBoundingBox(this, args, 0.0f, greenColor); + } + + RenderableDebugableEntityItem::render(this, args); +} + + Model* RenderablePolyVoxEntityItem::getModel(EntityTreeRenderer* renderer) { PolyVox::SimpleVolume volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0), PolyVox::Vector3DInt32(63, 63, 63))); @@ -96,13 +165,10 @@ Model* RenderablePolyVoxEntityItem::getModel(EntityTreeRenderer* renderer) { } assert(_myRenderer == renderer); // you should only ever render on one renderer - result = _model = _myRenderer->allocateModel(getModelURL(), getCompoundShapeURL()); - assert(_model); + // result = _model = _myRenderer->allocateModel("", ""); + // assert(_model); _needsInitialSimulation = true; - - - return result; } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 24359accf0..7c3a42ca4a 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -14,18 +14,29 @@ #include -#include "RenderableModelEntityItem.h" +#include "PolyVoxEntityItem.h" #include "RenderableDebugableEntityItem.h" -class RenderablePolyVoxEntityItem : public RenderableModelEntityItem { +class RenderablePolyVoxEntityItem : public PolyVoxEntityItem { public: static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : - RenderableModelEntityItem(entityItemID, properties) { } + PolyVoxEntityItem(entityItemID, properties) { } + void render(RenderArgs* args); virtual bool hasModel() const { return true; } virtual Model* getModel(EntityTreeRenderer* renderer); + +private: + Model* _model = nullptr; + bool _needsInitialSimulation = true; + bool _needsModelReload = true; + EntityTreeRenderer* _myRenderer = nullptr; + // QString _currentTextures; + // QStringList _originalTextures; + // bool _originalTexturesRead; + // QVector> _points; }; diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp new file mode 100644 index 0000000000..145a4ec728 --- /dev/null +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -0,0 +1,108 @@ +// +// PolyVoxEntityItem.cpp +// libraries/entities/src +// +// Created by Seth Alves on 5/11/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#include + +#include + +#include "PolyVoxEntityItem.h" +#include "EntityTree.h" +#include "EntitiesLogging.h" +#include "EntityTreeElement.h" + + +EntityItem* PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + EntityItem* result = new PolyVoxEntityItem(entityID, properties); + return result; +} + +PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : + EntityItem(entityItemID) +{ + _type = EntityTypes::PolyVox; + _created = properties.getCreated(); + setProperties(properties); +} + +EntityItemProperties PolyVoxEntityItem::getProperties() const { + EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class + + properties._color = getXColor(); + properties._colorChanged = false; + + properties._glowLevel = getGlowLevel(); + properties._glowLevelChanged = false; + + return properties; +} + +bool PolyVoxEntityItem::setProperties(const EntityItemProperties& properties) { + bool somethingChanged = false; + somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class + + SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); + + if (somethingChanged) { + bool wantDebug = false; + if (wantDebug) { + uint64_t now = usecTimestampNow(); + int elapsed = now - getLastEdited(); + qCDebug(entities) << "PolyVoxEntityItem::setProperties() AFTER update... edited AGO=" << elapsed << + "now=" << now << " getLastEdited()=" << getLastEdited(); + } + setLastEdited(properties._lastEdited); + } + return somethingChanged; +} + +int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { + + int bytesRead = 0; + const unsigned char* dataAt = data; + + READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); + + return bytesRead; +} + + +// TODO: eventually only include properties changed since the params.lastViewFrustumSent time +EntityPropertyFlags PolyVoxEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { + EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); + requestedProperties += PROP_COLOR; + return requestedProperties; +} + +void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { + + bool successPropertyFits = true; + + APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); +} + +void PolyVoxEntityItem::debugDump() const { + quint64 now = usecTimestampNow(); + qCDebug(entities) << " POLYVOX EntityItem id:" << getEntityItemID() << "---------------------------------------------"; + qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; + qCDebug(entities) << " position:" << debugTreeVector(_position); + qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); + qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); +} + diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h new file mode 100644 index 0000000000..5ddbd9ba7a --- /dev/null +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -0,0 +1,68 @@ +// +// PolyVoxEntityItem.h +// libraries/entities/src +// +// Created by Seth Alves on 5/11/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_PolyVoxEntityItem_h +#define hifi_PolyVoxEntityItem_h + +#include "EntityItem.h" + +class PolyVoxEntityItem : public EntityItem { + public: + static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + + PolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); + + ALLOW_INSTANTIATION // This class can be instantiated + + // methods for getting/setting all properties of an entity + virtual EntityItemProperties getProperties() const; + virtual bool setProperties(const EntityItemProperties& properties); + + // TODO: eventually only include properties changed since the params.lastViewFrustumSent time + virtual EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const; + + virtual void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const; + + virtual int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData); + + const rgbColor& getColor() const { return _color; } + xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; } + + void setColor(const rgbColor& value) { memcpy(_color, value, sizeof(_color)); } + void setColor(const xColor& value) { + _color[RED_INDEX] = value.red; + _color[GREEN_INDEX] = value.green; + _color[BLUE_INDEX] = value.blue; + } + + virtual ShapeType getShapeType() const { return SHAPE_TYPE_POLYVOX; } + + // never have a ray intersection pick a PolyVoxEntityItem. + virtual bool supportsDetailedRayIntersection() const { return true; } + virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, + void** intersectedObject, bool precisionPicking) const { return false; } + + virtual void debugDump() const; + + protected: + rgbColor _color; +}; + +#endif // hifi_PolyVoxEntityItem_h From 138077ede91427bd8e1f3e4ab6d062829f9efa0c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 20 May 2015 18:22:07 -0700 Subject: [PATCH 04/80] hook up mesh renderer --- .../src/RenderablePolyVoxEntityItem.cpp | 148 ++++++++---------- .../src/RenderablePolyVoxEntityItem.h | 15 +- libraries/model/src/model/Geometry.cpp | 12 +- libraries/model/src/model/Geometry.h | 4 +- 4 files changed, 76 insertions(+), 103 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index a4df131cc3..600028c894 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -22,6 +22,8 @@ #include #include +#include "model/Geometry.h" +#include "gpu/GLBackend.h" #include "EntityTreeRenderer.h" #include "RenderablePolyVoxEntityItem.h" @@ -59,116 +61,88 @@ void createSphereInVolume(PolyVox::SimpleVolume& volData, float fRadius } - -void RenderablePolyVoxEntityItem::render(RenderArgs* args) { - PerformanceTimer perfTimer("PolyVoxrender"); - assert(getType() == EntityTypes::PolyVox); - - bool drawAsModel = hasModel(); - - glm::vec3 position = getPosition(); - glm::vec3 dimensions = getDimensions(); - - bool didDraw = false; - if (drawAsModel) { - glPushMatrix(); - { - float alpha = getLocalRenderAlpha(); - - if (!_model || _needsModelReload) { - // TODO: this getModel() appears to be about 3% of model render time. We should optimize - PerformanceTimer perfTimer("getModel"); - EntityTreeRenderer* renderer = static_cast(args->_renderer); - getModel(renderer); - } - - if (_model) { - glm::quat rotation = getRotation(); - bool movingOrAnimating = isMoving(); - if ((movingOrAnimating || _needsInitialSimulation) && _model->isActive()) { - _model->setScaleToFit(true, dimensions); - _model->setSnapModelToRegistrationPoint(true, getRegistrationPoint()); - _model->setRotation(rotation); - _model->setTranslation(position); - - // make sure to simulate so everything gets set up correctly for rendering - { - PerformanceTimer perfTimer("_model->simulate"); - _model->simulate(0.0f); - } - _needsInitialSimulation = false; - } - - if (_model->isActive()) { - // TODO: this is the majority of model render time. And rendering of a cube model vs the basic Box render - // is significantly more expensive. Is there a way to call this that doesn't cost us as much? - PerformanceTimer perfTimer("model->render"); - // filter out if not needed to render - if (args && (args->_renderMode == RenderArgs::SHADOW_RENDER_MODE)) { - if (movingOrAnimating) { - _model->renderInScene(alpha, args); - didDraw = true; - } - } else { - _model->renderInScene(alpha, args); - didDraw = true; - } - } - } - } - glPopMatrix(); - } - - if (!didDraw) { - glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); - RenderableDebugableEntityItem::renderBoundingBox(this, args, 0.0f, greenColor); - } - - RenderableDebugableEntityItem::render(this, args); -} - - -Model* RenderablePolyVoxEntityItem::getModel(EntityTreeRenderer* renderer) { +void RenderablePolyVoxEntityItem::getModel() { PolyVox::SimpleVolume volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0), PolyVox::Vector3DInt32(63, 63, 63))); createSphereInVolume(volData, 15); // A mesh object to hold the result of surface extraction - PolyVox::SurfaceMesh mesh; + PolyVox::SurfaceMesh polyVoxMesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor - (&volData, volData.getEnclosingRegion(), &mesh); + (&volData, volData.getEnclosingRegion(), &polyVoxMesh); // MarchingCubesSurfaceExtractor> surfaceExtractor(&volData, // volData.getEnclosingRegion(), - // &mesh); + // &polyVoxMesh); //Execute the surface extractor. surfaceExtractor.execute(); - const std::vector& vecIndices = mesh.getIndices(); - const std::vector& vecVertices = mesh.getVertices(); + const std::vector& vecIndices = polyVoxMesh.getIndices(); + const std::vector& vecVertices = polyVoxMesh.getVertices(); qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------"; qDebug() << "---- vecIndices.size() =" << vecIndices.size(); qDebug() << "---- vecVertices.size() =" << vecVertices.size(); - - // [DEBUG] [05/19 20:46:38] ---- vecIndices.size() = 101556 // [DEBUG] [05/19 20:46:38] ---- vecVertices.size() = 67704 + model::Mesh* mesh = new model::Mesh(); + model::MeshPointer meshPtr(mesh); - Model* result = NULL; - // make sure our renderer is setup - if (!_myRenderer) { - _myRenderer = renderer; - } - assert(_myRenderer == renderer); // you should only ever render on one renderer + auto indexBuffer = gpu::BufferPointer (new gpu::Buffer(vecIndices.size() * sizeof(uint32_t), + (gpu::Byte*)vecIndices.data())); + auto vertexBuffer = gpu::BufferPointer(new gpu::Buffer(vecVertices.size() * sizeof(PolyVox::PositionMaterialNormal), + (gpu::Byte*)vecVertices.data())); - // result = _model = _myRenderer->allocateModel("", ""); - // assert(_model); + mesh->setIndexBuffer(gpu::BufferView(indexBuffer, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW))); + mesh->setVertexBuffer(gpu::BufferView(vertexBuffer, + 0, + vertexBuffer->getSize() - sizeof(float) * 3, + sizeof(float) * 6, // MAGIC NUMBER! + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); + mesh->addAttribute(gpu::Stream::NORMAL, + gpu::BufferView(vertexBuffer, + sizeof(float) * 3, // MAGIC NUMBER! + vertexBuffer->getSize() - sizeof(float) * 3, + sizeof(float) * 6, // MAGIC NUMBER! + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); - _needsInitialSimulation = true; - return result; + _modelGeometry.setMesh(meshPtr); + _needsModelReload = false; +} + + + +void RenderablePolyVoxEntityItem::render(RenderArgs* args) { + PerformanceTimer perfTimer("RenderablePolyVoxEntityItem::render"); + assert(getType() == EntityTypes::PolyVox); + + if (_needsModelReload) { + getModel(); + } + + glm::vec3 position = getPosition(); + // glm::vec3 dimensions = getDimensions(); + glm::quat rotation = getRotation(); + glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); + glPushMatrix(); + glTranslatef(position.x, position.y, position.z); + glm::vec3 axis = glm::axis(rotation); + glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + + // DependencyManager::get()->renderLine(p1, p2, lineColor, lineColor); + + gpu::Batch batch; + + batch.setInputFormat(_modelGeometry.getMesh()->getVertexFormat()); + batch.setIndexBuffer(gpu::UINT32, _modelGeometry.getMesh()->getIndexBuffer()._buffer, 0); + batch.setInputStream(0, _modelGeometry.getMesh()->makeBufferStream()); + batch.drawIndexed(gpu::TRIANGLES, _modelGeometry.getMesh()->getNumIndices(), 0); + gpu::GLBackend::renderBatch(batch); + + glPopMatrix(); + RenderableDebugableEntityItem::render(this, args); } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 7c3a42ca4a..6e98f2f21e 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -26,17 +26,16 @@ public: void render(RenderArgs* args); virtual bool hasModel() const { return true; } - virtual Model* getModel(EntityTreeRenderer* renderer); + void getModel(); private: - Model* _model = nullptr; - bool _needsInitialSimulation = true; + // Model* _model = nullptr; + // bool _needsInitialSimulation = true; + // bool _needsModelReload = true; + // EntityTreeRenderer* _myRenderer = nullptr; + + model::Geometry _modelGeometry; bool _needsModelReload = true; - EntityTreeRenderer* _myRenderer = nullptr; - // QString _currentTextures; - // QStringList _originalTextures; - // bool _originalTexturesRead; - // QVector> _points; }; diff --git a/libraries/model/src/model/Geometry.cpp b/libraries/model/src/model/Geometry.cpp index 156f593421..ed0201763a 100755 --- a/libraries/model/src/model/Geometry.cpp +++ b/libraries/model/src/model/Geometry.cpp @@ -43,18 +43,18 @@ void Mesh::addAttribute(Slot slot, const BufferView& buffer) { } void Mesh::evalVertexFormat() { - VertexFormat vf; + auto vf = new VertexFormat(); int channelNum = 0; if (hasVertexData()) { - vf.setAttribute(gpu::Stream::POSITION, channelNum, _vertexBuffer._element, 0); + vf->setAttribute(gpu::Stream::POSITION, channelNum, _vertexBuffer._element, 0); channelNum++; } for (auto attrib : _attributeBuffers) { - vf.setAttribute(attrib.first, channelNum, attrib.second._element, 0); + vf->setAttribute(attrib.first, channelNum, attrib.second._element, 0); channelNum++; } - _vertexFormat = vf; + _vertexFormat.reset(vf); } void Mesh::setIndexBuffer(const BufferView& buffer) { @@ -112,12 +112,12 @@ const gpu::BufferStream Mesh::makeBufferStream() const { int channelNum = 0; if (hasVertexData()) { - stream.addBuffer(_vertexBuffer._buffer, _vertexBuffer._offset, _vertexFormat.getChannelStride(channelNum)); + stream.addBuffer(_vertexBuffer._buffer, _vertexBuffer._offset, _vertexFormat->getChannelStride(channelNum)); channelNum++; } for (auto attrib : _attributeBuffers) { BufferView& view = attrib.second; - stream.addBuffer(view._buffer, view._offset, _vertexFormat.getChannelStride(channelNum)); + stream.addBuffer(view._buffer, view._offset, _vertexFormat->getChannelStride(channelNum)); channelNum++; } diff --git a/libraries/model/src/model/Geometry.h b/libraries/model/src/model/Geometry.h index 31c06e6eca..0416018e62 100755 --- a/libraries/model/src/model/Geometry.h +++ b/libraries/model/src/model/Geometry.h @@ -54,7 +54,7 @@ public: void addAttribute(Slot slot, const BufferView& buffer); // Stream format - const VertexFormat& getVertexFormat() const { return _vertexFormat; } + const gpu::Stream::FormatPointer getVertexFormat() const { return _vertexFormat; } // Index Buffer void setIndexBuffer(const BufferView& buffer); @@ -114,7 +114,7 @@ public: protected: - VertexFormat _vertexFormat; + gpu::Stream::FormatPointer _vertexFormat; BufferView _vertexBuffer; BufferViewMap _attributeBuffers; From de6422683a2f7a12ee3ca87c5489f82292e9ada0 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 20 May 2015 21:21:39 -0700 Subject: [PATCH 05/80] cleanups, trying to figure out why this doesn't draw --- .../src/RenderablePolyVoxEntityItem.cpp | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 600028c894..a9251cd961 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -79,8 +79,33 @@ void RenderablePolyVoxEntityItem::getModel() { //Execute the surface extractor. surfaceExtractor.execute(); + + model::Mesh* mesh = new model::Mesh(); + model::MeshPointer meshPtr(mesh); + + const std::vector& vecIndices = polyVoxMesh.getIndices(); + auto indexBuffer = new gpu::Buffer(vecIndices.size() * sizeof(uint32_t), (gpu::Byte*)vecIndices.data()); + auto indexBufferPtr = gpu::BufferPointer(indexBuffer); + mesh->setIndexBuffer(gpu::BufferView(indexBufferPtr, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW))); + + const std::vector& vecVertices = polyVoxMesh.getVertices(); + auto vertexBuffer = new gpu::Buffer(vecVertices.size() * sizeof(PolyVox::PositionMaterialNormal), + (gpu::Byte*)vecVertices.data()); + auto vertexBufferPtr = gpu::BufferPointer(vertexBuffer); + mesh->setVertexBuffer(gpu::BufferView(vertexBufferPtr, + 0, + vertexBufferPtr->getSize() - sizeof(float) * 3, + sizeof(float) * 7, + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); + mesh->addAttribute(gpu::Stream::NORMAL, + gpu::BufferView(vertexBufferPtr, + sizeof(float) * 3, + vertexBufferPtr->getSize() - sizeof(float) * 3, + sizeof(float) * 7, + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); + qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------"; qDebug() << "---- vecIndices.size() =" << vecIndices.size(); @@ -88,27 +113,6 @@ void RenderablePolyVoxEntityItem::getModel() { // [DEBUG] [05/19 20:46:38] ---- vecIndices.size() = 101556 // [DEBUG] [05/19 20:46:38] ---- vecVertices.size() = 67704 - model::Mesh* mesh = new model::Mesh(); - model::MeshPointer meshPtr(mesh); - - auto indexBuffer = gpu::BufferPointer (new gpu::Buffer(vecIndices.size() * sizeof(uint32_t), - (gpu::Byte*)vecIndices.data())); - auto vertexBuffer = gpu::BufferPointer(new gpu::Buffer(vecVertices.size() * sizeof(PolyVox::PositionMaterialNormal), - (gpu::Byte*)vecVertices.data())); - - mesh->setIndexBuffer(gpu::BufferView(indexBuffer, gpu::Element(gpu::SCALAR, gpu::UINT32, gpu::RAW))); - mesh->setVertexBuffer(gpu::BufferView(vertexBuffer, - 0, - vertexBuffer->getSize() - sizeof(float) * 3, - sizeof(float) * 6, // MAGIC NUMBER! - gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); - mesh->addAttribute(gpu::Stream::NORMAL, - gpu::BufferView(vertexBuffer, - sizeof(float) * 3, // MAGIC NUMBER! - vertexBuffer->getSize() - sizeof(float) * 3, - sizeof(float) * 6, // MAGIC NUMBER! - gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); - _modelGeometry.setMesh(meshPtr); _needsModelReload = false; @@ -127,20 +131,18 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { glm::vec3 position = getPosition(); // glm::vec3 dimensions = getDimensions(); glm::quat rotation = getRotation(); - glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha()); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - // DependencyManager::get()->renderLine(p1, p2, lineColor, lineColor); - gpu::Batch batch; - batch.setInputFormat(_modelGeometry.getMesh()->getVertexFormat()); - batch.setIndexBuffer(gpu::UINT32, _modelGeometry.getMesh()->getIndexBuffer()._buffer, 0); - batch.setInputStream(0, _modelGeometry.getMesh()->makeBufferStream()); - batch.drawIndexed(gpu::TRIANGLES, _modelGeometry.getMesh()->getNumIndices(), 0); + auto mesh = _modelGeometry.getMesh(); + batch.setInputFormat(mesh->getVertexFormat()); + batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0); + batch.setInputStream(0, mesh->makeBufferStream()); + batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0); gpu::GLBackend::renderBatch(batch); glPopMatrix(); From fe188f9a4390efa41844fc4644f4bcad40d32d71 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 10:42:14 -0700 Subject: [PATCH 06/80] something draws, now --- .../entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 8 +++++++- libraries/entities/src/PolyVoxEntityItem.cpp | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index a9251cd961..0d710a5188 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -97,13 +97,15 @@ void RenderablePolyVoxEntityItem::getModel() { mesh->setVertexBuffer(gpu::BufferView(vertexBufferPtr, 0, vertexBufferPtr->getSize() - sizeof(float) * 3, - sizeof(float) * 7, + sizeof(float) * 3, + // sizeof(PolyVox::PositionMaterialNormal), gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); mesh->addAttribute(gpu::Stream::NORMAL, gpu::BufferView(vertexBufferPtr, sizeof(float) * 3, vertexBufferPtr->getSize() - sizeof(float) * 3, sizeof(float) * 7, + // sizeof(PolyVox::PositionMaterialNormal), gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); @@ -138,6 +140,10 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { gpu::Batch batch; + // XXX why do I need these? + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_NORMAL_ARRAY); + auto mesh = _modelGeometry.getMesh(); batch.setInputFormat(mesh->getVertexFormat()); batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0); diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index 145a4ec728..f094d83af1 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -21,6 +21,7 @@ EntityItem* PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { + qDebug() << "XXXXXXXXXXXX XXXXXXXXXXXX making PolyVoxEntityItem entity"; EntityItem* result = new PolyVoxEntityItem(entityID, properties); return result; } @@ -28,6 +29,8 @@ EntityItem* PolyVoxEntityItem::factory(const EntityItemID& entityID, const Entit PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID) { + qDebug() << "XXXXXXXXXXXX XXXXXXXXXXXX making PolyVoxEntityItem entity"; + _type = EntityTypes::PolyVox; _created = properties.getCreated(); setProperties(properties); From c02b87ad1c6c646ca9c0a2b8aab729413371a9a2 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 11:09:44 -0700 Subject: [PATCH 07/80] update polyvox --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 5c1ea4f378..f0c9c298b8 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -5,7 +5,7 @@ ExternalProject_Add( ${EXTERNAL_NAME} # URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master.zip URL http://headache.hungry.com/~seth/hifi/polyvox-master.zip - URL_MD5 bbf8040b1e3f338cd51bdcccd0945978 + URL_MD5 82bc1407b3607cc434e1849d1da4e93b CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From b74262f2cecd0dddef896fc0360eab3c5fe78e28 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 11:53:56 -0700 Subject: [PATCH 08/80] update polyvox --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index f0c9c298b8..4a26b17c63 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -5,7 +5,7 @@ ExternalProject_Add( ${EXTERNAL_NAME} # URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master.zip URL http://headache.hungry.com/~seth/hifi/polyvox-master.zip - URL_MD5 82bc1407b3607cc434e1849d1da4e93b + URL_MD5 ceabe53ccb0726524e1d0427c517f3b5 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 8e768871011c8a5cd3d3c62da6025f1f1e8315b1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 11:55:13 -0700 Subject: [PATCH 09/80] working on windows build of polyvox --- cmake/externals/polyvox/CMakeLists.txt | 24 ++++++++++++------ cmake/modules/FindPolyVox.cmake | 34 ++++++++++++++------------ 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index f0c9c298b8..b05bc26cef 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -16,19 +16,27 @@ ExternalProject_Add( ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) -set(${EXTERNAL_NAME_UPPER}_CORE_INCLUDE_DIRS ${INSTALL_DIR}/include/PolyVoxCore CACHE FILEPATH - "Path to polyvox core include directory") -set(${EXTERNAL_NAME_UPPER}_UTIL_INCLUDE_DIRS ${INSTALL_DIR}/include/PolyVoxUtil CACHE FILEPATH - "Path to polyvox util include directory") + +if (WIN32) + set(${EXTERNAL_NAME_UPPER}_CORE_INCLUDE_DIRS ${INSTALL_DIR}/PolyVoxCore/include CACHE FILEPATH + "Path to polyvox core include directory") + set(${EXTERNAL_NAME_UPPER}_UTIL_INCLUDE_DIRS ${INSTALL_DIR}/PolyVoxUtil/include CACHE FILEPATH + "Path to polyvox util include directory") +else () + set(${EXTERNAL_NAME_UPPER}_CORE_INCLUDE_DIRS ${INSTALL_DIR}/include/PolyVoxCore CACHE FILEPATH + "Path to polyvox core include directory") + set(${EXTERNAL_NAME_UPPER}_UTIL_INCLUDE_DIRS ${INSTALL_DIR}/include/PolyVoxUtil CACHE FILEPATH + "Path to polyvox util include directory") +endif () if (WIN32) - set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox core library") - set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox util library") + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/PolyVoxCore/lib/PolyVoxCore.lib CACHE FILEPATH "polyvox core library") +# set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/PolyVoxUtil/lib/PolyVoxUtil.lib CACHE FILEPATH "polyvox util library") elseif (APPLE) set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox core library") - set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox util library") +# set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox util library") else () set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") - set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxUtil.so CACHE FILEPATH "polyvox util library") +# set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxUtil.so CACHE FILEPATH "polyvox util library") endif () diff --git a/cmake/modules/FindPolyVox.cmake b/cmake/modules/FindPolyVox.cmake index 1ddab877dd..60a639e87c 100644 --- a/cmake/modules/FindPolyVox.cmake +++ b/cmake/modules/FindPolyVox.cmake @@ -21,30 +21,34 @@ include("${MACRO_DIR}/HifiLibrarySearchHints.cmake") hifi_library_search_hints("polyvox") -find_path(POLYVOX_CORE_INCLUDE_DIRS PolyVoxCore/SimpleVolume.h PATH_SUFFIXES include/PolyVoxCore HINTS ${POLYVOX_SEARCH_DIRS}) -find_path(POLYVOX_UTIL_INCLUDE_DIRS PolyVoxUtil/Serialization.h PATH_SUFFIXES include/PolyVoxUtil HINTS ${POLYVOX_SEARCH_DIRS}) +find_path(POLYVOX_CORE_INCLUDE_DIRS PolyVoxCore/SimpleVolume.h PATH_SUFFIXES include include/PolyVoxCore HINTS ${POLYVOX_SEARCH_DIRS}) +# find_path(POLYVOX_UTIL_INCLUDE_DIRS PolyVoxUtil/Serialization.h PATH_SUFFIXES include include/PolyVoxUtil HINTS ${POLYVOX_SEARCH_DIRS}) find_library(POLYVOX_CORE_LIBRARY NAMES PolyVoxCore PATH_SUFFIXES lib HINTS ${POLYVOX_SEARCH_DIRS}) -find_library(POLYVOX_UTIL_LIBRARY NAMES PolyVoxUtil PATH_SUFFIXES lib HINTS ${POLYVOX_SEARCH_DIRS}) +# find_library(POLYVOX_UTIL_LIBRARY NAMES PolyVoxUtil PATH_SUFFIXES lib HINTS ${POLYVOX_SEARCH_DIRS}) -if (WIN32) - find_path(POLYVOX_DLL_PATH polyvox.dll PATH_SUFFIXES bin HINTS ${POLYVOX_SEARCH_DIRS}) -endif() +# if (WIN32) +# find_path(POLYVOX_DLL_PATH polyvox.dll PATH_SUFFIXES bin HINTS ${POLYVOX_SEARCH_DIRS}) +# endif() -set(POLYVOX_REQUIREMENTS POLYVOX_CORE_INCLUDE_DIRS POLYVOX_UTIL_INCLUDE_DIRS POLYVOX_CORE_LIBRARY POLYVOX_UTIL_LIBRARY) -if (WIN32) - list(APPEND POLYVOX_REQUIREMENTS POLYVOX_DLL_PATH) -endif () +# set(POLYVOX_REQUIREMENTS POLYVOX_CORE_INCLUDE_DIRS POLYVOX_UTIL_INCLUDE_DIRS POLYVOX_CORE_LIBRARY POLYVOX_UTIL_LIBRARY) +set(POLYVOX_REQUIREMENTS POLYVOX_CORE_INCLUDE_DIRS POLYVOX_CORE_LIBRARY) +# if (WIN32) +# list(APPEND POLYVOX_REQUIREMENTS POLYVOX_DLL_PATH) +# endif () include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Polyvox DEFAULT_MSG ${POLYVOX_REQUIREMENTS}) -if (WIN32) - add_paths_to_fixup_libs(${POLYVOX_DLL_PATH}) -endif () +# if (WIN32) +# add_paths_to_fixup_libs(${POLYVOX_DLL_PATH}) +# endif () -set(POLYVOX_INCLUDE_DIRS ${POLYVOX_CORE_INCLUDE_DIRS} ${POLYVOX_UTIL_INCLUDE_DIRS}) -set(POLYVOX_LIBRARIES ${POLYVOX_CORE_LIBRARY} ${POLYVOX_UTIL_LIBRARY}) +# set(POLYVOX_INCLUDE_DIRS ${POLYVOX_CORE_INCLUDE_DIRS} ${POLYVOX_UTIL_INCLUDE_DIRS}) +# set(POLYVOX_LIBRARIES ${POLYVOX_CORE_LIBRARY} ${POLYVOX_UTIL_LIBRARY}) + +set(POLYVOX_INCLUDE_DIRS ${POLYVOX_CORE_INCLUDE_DIRS}) +set(POLYVOX_LIBRARIES ${POLYVOX_CORE_LIBRARY}) mark_as_advanced(POLYVOX_INCLUDE_DIRS POLYVOX_LIBRARIES POLYVOX_SEARCH_DIRS) From 0c1ad258f3cbc75d1bc106bc8f29e9896e05bc36 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 11:57:37 -0700 Subject: [PATCH 10/80] update polyvox --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 4a26b17c63..84678c8ccf 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -5,7 +5,7 @@ ExternalProject_Add( ${EXTERNAL_NAME} # URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master.zip URL http://headache.hungry.com/~seth/hifi/polyvox-master.zip - URL_MD5 ceabe53ccb0726524e1d0427c517f3b5 + URL_MD5 b62e8d8711a4f462377d45e2dd1a22c0 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From fd19c634491409c5ef62c3d14ff3e09515cdd46d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 14:26:40 -0700 Subject: [PATCH 11/80] fix bug in mesh --- .../src/RenderablePolyVoxEntityItem.cpp | 27 +++++++++++++------ libraries/model/src/model/Geometry.h | 2 +- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 0d710a5188..9decd37cb2 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -97,24 +97,35 @@ void RenderablePolyVoxEntityItem::getModel() { mesh->setVertexBuffer(gpu::BufferView(vertexBufferPtr, 0, vertexBufferPtr->getSize() - sizeof(float) * 3, - sizeof(float) * 3, - // sizeof(PolyVox::PositionMaterialNormal), - gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); + sizeof(PolyVox::PositionMaterialNormal), + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW) + )); mesh->addAttribute(gpu::Stream::NORMAL, gpu::BufferView(vertexBufferPtr, sizeof(float) * 3, vertexBufferPtr->getSize() - sizeof(float) * 3, - sizeof(float) * 7, - // sizeof(PolyVox::PositionMaterialNormal), - gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); + sizeof(PolyVox::PositionMaterialNormal), + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW) + )); qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------"; qDebug() << "---- vecIndices.size() =" << vecIndices.size(); + qDebug() << "---- sizeof(vecIndices[0]) =" << sizeof(vecIndices[0]); qDebug() << "---- vecVertices.size() =" << vecVertices.size(); - // [DEBUG] [05/19 20:46:38] ---- vecIndices.size() = 101556 - // [DEBUG] [05/19 20:46:38] ---- vecVertices.size() = 67704 + qDebug() << "---- sizeof(vecVertices[0]) =" << sizeof(vecVertices[0]); + qDebug() << "---- sizeof(uint32_t) =" << sizeof(uint32_t); + qDebug() << "---- sizeof(float) =" << sizeof(float); + qDebug() << "---- sizeof(PolyVox::PositionMaterialNormal) =" << sizeof(PolyVox::PositionMaterialNormal); + // -------------XXXXXXXXXXXXXXXXXXXX------------------- + // ---- vecIndices.size() = 25524 + // ---- sizeof(vecIndices[0]) = 4 + // ---- vecVertices.size() = 17016 + // ---- sizeof(vecVertices[0]) = 28 + // ---- sizeof(uint32_t) = 4 + // ---- sizeof(float) = 4 + // ---- sizeof(PolyVox::PositionMaterialNormal) = 28 _modelGeometry.setMesh(meshPtr); _needsModelReload = false; diff --git a/libraries/model/src/model/Geometry.h b/libraries/model/src/model/Geometry.h index 0416018e62..95f1c3bce7 100755 --- a/libraries/model/src/model/Geometry.h +++ b/libraries/model/src/model/Geometry.h @@ -47,7 +47,7 @@ public: void setVertexBuffer(const BufferView& buffer); const BufferView& getVertexBuffer() const { return _vertexBuffer; } uint getNumVertices() const { return _vertexBuffer.getNumElements(); } - bool hasVertexData() const { return !_vertexBuffer._buffer; } + bool hasVertexData() const { return _vertexBuffer._buffer.get() != nullptr; } // Attribute Buffers int getNumAttributes() const { return _attributeBuffers.size(); } From bbb61a77d96b0cdea0833cdcdceec66387fb2f0c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 14:47:23 -0700 Subject: [PATCH 12/80] dodge stride bug in mesh code --- .../src/RenderablePolyVoxEntityItem.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 9decd37cb2..252a76e946 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -151,14 +151,15 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { gpu::Batch batch; - // XXX why do I need these? - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - auto mesh = _modelGeometry.getMesh(); batch.setInputFormat(mesh->getVertexFormat()); - batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0); - batch.setInputStream(0, mesh->makeBufferStream()); + + batch.setInputBuffer(gpu::Stream::POSITION, mesh->getVertexBuffer()); + batch.setInputBuffer(gpu::Stream::NORMAL, mesh->getVertexBuffer()._buffer, sizeof(float) * 3, mesh->getVertexBuffer()._stride); + + //batch.setInputStream(0, mesh->makeBufferStream()); + + batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0); batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0); gpu::GLBackend::renderBatch(batch); From 85171f033e7f2f37d41c176f8b2b5906803316c5 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 16:30:16 -0700 Subject: [PATCH 13/80] fallout from no-swap-id merge --- examples/edit.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/edit.js b/examples/edit.js index 95c4df50c4..7983a49575 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -762,7 +762,7 @@ function mouseClickEvent(event) { selectionManager.addEntity(foundEntity, true); } - print("Model selected: " + foundEntity.id); + print("Model selected: " + foundEntity); selectionDisplay.select(selectedEntityID, event); if (Menu.isOptionChecked(MENU_AUTO_FOCUS_ON_SELECT)) { @@ -1201,7 +1201,7 @@ PropertiesTool = function(opts) { var selections = []; for (var i = 0; i < selectionManager.selections.length; i++) { var entity = {}; - entity.id = selectionManager.selections[i].id; + entity.id = selectionManager.selections[i]; entity.properties = Entities.getEntityProperties(selectionManager.selections[i]); entity.properties.rotation = Quat.safeEulerAngles(entity.properties.rotation); selections.push(entity); @@ -1251,7 +1251,7 @@ PropertiesTool = function(opts) { var dY = grid.getOrigin().y - (selectionManager.worldPosition.y - selectionManager.worldDimensions.y / 2), var diff = { x: 0, y: dY, z: 0 }; for (var i = 0; i < selectionManager.selections.length; i++) { - var properties = selectionManager.savedProperties[selectionManager.selections[i].id]; + var properties = selectionManager.savedProperties[selectionManager.selections[i]]; var newPosition = Vec3.sum(properties.position, diff); Entities.editEntity(selectionManager.selections[i], { position: newPosition, @@ -1264,7 +1264,7 @@ PropertiesTool = function(opts) { if (selectionManager.hasSelection()) { selectionManager.saveProperties(); for (var i = 0; i < selectionManager.selections.length; i++) { - var properties = selectionManager.savedProperties[selectionManager.selections[i].id]; + var properties = selectionManager.savedProperties[selectionManager.selections[i]]; var bottomY = properties.boundingBox.center.y - properties.boundingBox.dimensions.y / 2; var dY = grid.getOrigin().y - bottomY; var diff = { x: 0, y: dY, z: 0 }; @@ -1280,7 +1280,7 @@ PropertiesTool = function(opts) { if (selectionManager.hasSelection()) { selectionManager.saveProperties(); for (var i = 0; i < selectionManager.selections.length; i++) { - var properties = selectionManager.savedProperties[selectionManager.selections[i].id]; + var properties = selectionManager.savedProperties[selectionManager.selections[i]]; var naturalDimensions = properties.naturalDimensions; // If any of the natural dimensions are not 0, resize @@ -1302,7 +1302,7 @@ PropertiesTool = function(opts) { if (selectionManager.hasSelection()) { selectionManager.saveProperties(); for (var i = 0; i < selectionManager.selections.length; i++) { - var properties = selectionManager.savedProperties[selectionManager.selections[i].id]; + var properties = selectionManager.savedProperties[selectionManager.selections[i]]; Entities.editEntity(selectionManager.selections[i], { dimensions: Vec3.multiply(multiplier, properties.dimensions), }); @@ -1314,7 +1314,7 @@ PropertiesTool = function(opts) { if (selectionManager.hasSelection()) { selectionManager.saveProperties(); for (var i = 0; i < selectionManager.selections.length; i++) { - var properties = selectionManager.savedProperties[selectionManager.selections[i].id]; + var properties = selectionManager.savedProperties[selectionManager.selections[i]]; if (properties.type == "Zone") { var centerOfZone = properties.boundingBox.center; var atmosphereCenter = { x: centerOfZone.x, From 2cb73b5430185f6b47accdde6aff2e6df3fdecfc Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 16:31:01 -0700 Subject: [PATCH 14/80] added a volex-volume size member variable. drawing transform still isn't quite right --- .../src/RenderableModelEntityItem.h | 2 +- .../src/RenderablePolyVoxEntityItem.cpp | 86 ++++++++++++++----- .../src/RenderablePolyVoxEntityItem.h | 10 +-- libraries/entities/src/PolyVoxEntityItem.h | 3 + 4 files changed, 72 insertions(+), 29 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 8f55e67d09..886ae78a83 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -65,7 +65,7 @@ private: Model* _model; bool _needsInitialSimulation; - bool _needsModelReload; + bool _needsModelReload = true; EntityTreeRenderer* _myRenderer; QString _currentTextures; QStringList _originalTextures; diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 252a76e946..78033ad81a 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -31,6 +31,24 @@ EntityItem* RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, c return new RenderablePolyVoxEntityItem(entityID, properties); } +RenderablePolyVoxEntityItem::~RenderablePolyVoxEntityItem() { + delete _volData; +} + +void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { + PolyVoxEntityItem::setVoxelVolumeSize(voxelVolumeSize); + + if (_volData) { + delete _volData; + } + + PolyVox::Vector3DInt32 lowCorner(0, 0, 0); + PolyVox::Vector3DInt32 highCorner(_voxelVolumeSize[0] - 1, // -1 because these corners are inclusive + _voxelVolumeSize[1] - 1, + _voxelVolumeSize[2] - 1); + + _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); +} void createSphereInVolume(PolyVox::SimpleVolume& volData, float fRadius) { // This vector hold the position of the center of the volume @@ -60,30 +78,46 @@ void createSphereInVolume(PolyVox::SimpleVolume& volData, float fRadius } } - void RenderablePolyVoxEntityItem::getModel() { - PolyVox::SimpleVolume volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0), - PolyVox::Vector3DInt32(63, 63, 63))); - createSphereInVolume(volData, 15); + if (!_volData) { + // this will cause the allocation of _volData + setVoxelVolumeSize(_voxelVolumeSize); + } + + // PolyVox::SimpleVolume volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0), + // PolyVox::Vector3DInt32(63, 63, 63))); + createSphereInVolume(*_volData, 15); // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor - (&volData, volData.getEnclosingRegion(), &polyVoxMesh); - // MarchingCubesSurfaceExtractor> surfaceExtractor(&volData, - // volData.getEnclosingRegion(), + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + // MarchingCubesSurfaceExtractor> surfaceExtractor(_volData, + // _volData->getEnclosingRegion(), // &polyVoxMesh); //Execute the surface extractor. surfaceExtractor.execute(); + // find dimensions + // AABox box; + // const std::vector& vertices = polyVoxMesh.getVertices(); + // foreach (const PolyVox::PositionMaterialNormal vertexMaterialNormal, vertices) { + // const PolyVox::Vector3DFloat& vertex = vertexMaterialNormal.position; + // glm::vec3 v(vertex.getX(), vertex.getY(), vertex.getZ()); + // box += v; + // } + // glm::vec3 dimensions = box.getDimensions(); + // setDimensions(dimensions); + + + // convert PolyVox mesh to a Sam mesh model::Mesh* mesh = new model::Mesh(); model::MeshPointer meshPtr(mesh); - const std::vector& vecIndices = polyVoxMesh.getIndices(); auto indexBuffer = new gpu::Buffer(vecIndices.size() * sizeof(uint32_t), (gpu::Byte*)vecIndices.data()); auto indexBufferPtr = gpu::BufferPointer(indexBuffer); @@ -98,15 +132,13 @@ void RenderablePolyVoxEntityItem::getModel() { 0, vertexBufferPtr->getSize() - sizeof(float) * 3, sizeof(PolyVox::PositionMaterialNormal), - gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW) - )); + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); mesh->addAttribute(gpu::Stream::NORMAL, gpu::BufferView(vertexBufferPtr, sizeof(float) * 3, vertexBufferPtr->getSize() - sizeof(float) * 3, sizeof(PolyVox::PositionMaterialNormal), - gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW) - )); + gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------"; @@ -142,27 +174,35 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { } glm::vec3 position = getPosition(); - // glm::vec3 dimensions = getDimensions(); + glm::vec3 dimensions = getDimensions(); + glm::vec3 scale = dimensions / _voxelVolumeSize; + glm::vec3 center = getCenter(); glm::quat rotation = getRotation(); glPushMatrix(); + // glm::vec3 positionToCenter = center - position; + // glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); + // glm::vec3 axis = glm::axis(rotation); + // glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + // glScalef(dimensions.x, dimensions.y, dimensions.z); + glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - - gpu::Batch batch; + glm::vec3 positionToCenter = center - position; + glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); + glScalef(scale.x, scale.y, scale.z); auto mesh = _modelGeometry.getMesh(); + gpu::Batch batch; batch.setInputFormat(mesh->getVertexFormat()); - - batch.setInputBuffer(gpu::Stream::POSITION, mesh->getVertexBuffer()); - batch.setInputBuffer(gpu::Stream::NORMAL, mesh->getVertexBuffer()._buffer, sizeof(float) * 3, mesh->getVertexBuffer()._stride); - - //batch.setInputStream(0, mesh->makeBufferStream()); - - batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0); + batch.setInputBuffer(gpu::Stream::POSITION, mesh->getVertexBuffer()); + batch.setInputBuffer(gpu::Stream::NORMAL, + mesh->getVertexBuffer()._buffer, + sizeof(float) * 3, + mesh->getVertexBuffer()._stride); + batch.setIndexBuffer(gpu::UINT32, mesh->getIndexBuffer()._buffer, 0); batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0); gpu::GLBackend::renderBatch(batch); - glPopMatrix(); RenderableDebugableEntityItem::render(this, args); } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 6e98f2f21e..e7b16a7739 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -24,16 +24,16 @@ public: RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : PolyVoxEntityItem(entityItemID, properties) { } + virtual ~RenderablePolyVoxEntityItem(); + void render(RenderArgs* args); virtual bool hasModel() const { return true; } void getModel(); -private: - // Model* _model = nullptr; - // bool _needsInitialSimulation = true; - // bool _needsModelReload = true; - // EntityTreeRenderer* _myRenderer = nullptr; + virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize); +private: + PolyVox::SimpleVolume* _volData = nullptr; model::Geometry _modelGeometry; bool _needsModelReload = true; }; diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 5ddbd9ba7a..bc13e0c613 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -61,8 +61,11 @@ class PolyVoxEntityItem : public EntityItem { virtual void debugDump() const; + virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { _voxelVolumeSize = voxelVolumeSize; } + protected: rgbColor _color; + glm::vec3 _voxelVolumeSize = glm::vec3(64, 64, 64); }; #endif // hifi_PolyVoxEntityItem_h From 478cb401354120a0b2f141dfb279fe21060dc76b Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 16:46:27 -0700 Subject: [PATCH 15/80] draws in the right place, now --- .../entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 8 ++------ libraries/entities/src/PolyVoxEntityItem.h | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 78033ad81a..0636c8aeec 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -179,16 +179,12 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { glm::vec3 center = getCenter(); glm::quat rotation = getRotation(); glPushMatrix(); - // glm::vec3 positionToCenter = center - position; - // glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); - // glm::vec3 axis = glm::axis(rotation); - // glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - // glScalef(dimensions.x, dimensions.y, dimensions.z); - glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glm::vec3 positionToCenter = center - position; + // make the voxel volume be centered on the entity's position + positionToCenter -= _dimensions * glm::vec3(0.5f,0.5f,0.5f); glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(scale.x, scale.y, scale.z); diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index bc13e0c613..35071b4d88 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -21,9 +21,9 @@ class PolyVoxEntityItem : public EntityItem { PolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); ALLOW_INSTANTIATION // This class can be instantiated - - // methods for getting/setting all properties of an entity - virtual EntityItemProperties getProperties() const; + + // methods for getting/setting all properties of an entity + virtual EntityItemProperties getProperties() const; virtual bool setProperties(const EntityItemProperties& properties); // TODO: eventually only include properties changed since the params.lastViewFrustumSent time From 8b2d570f3fc0c104489ff2aae86b6560bb697b9f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 17:04:57 -0700 Subject: [PATCH 16/80] clearSphereInVolume --- .../src/RenderablePolyVoxEntityItem.cpp | 56 +++++++++++++------ .../src/RenderablePolyVoxEntityItem.h | 2 + 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 0636c8aeec..84882c1935 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -50,29 +50,48 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); } -void createSphereInVolume(PolyVox::SimpleVolume& volData, float fRadius) { - // This vector hold the position of the center of the volume - PolyVox::Vector3DFloat v3dVolCenter(volData.getWidth() / 2, volData.getHeight() / 2, volData.getDepth() / 2); - +void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 center, float radius) { // This three-level for loop iterates over every voxel in the volume - for (int z = 0; z < volData.getDepth(); z++) { - for (int y = 0; y < volData.getHeight(); y++) { - for (int x = 0; x < volData.getWidth(); x++) { + for (int z = 0; z < _volData->getDepth(); z++) { + for (int y = 0; y < _volData->getHeight(); y++) { + for (int x = 0; x < _volData->getWidth(); x++) { // Store our current position as a vector... - PolyVox::Vector3DFloat v3dCurrentPos(x,y,z); + glm::vec3 pos(x, y, z); // And compute how far the current position is from the center of the volume - float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length(); - - uint8_t uVoxelValue = 0; - + float fDistToCenter = glm::distance(pos, center); + uint8_t uVoxelValue = _volData->getVoxelAt(x, y, z); // If the current voxel is less than 'radius' units from the center then we make it solid. - if(fDistToCenter <= fRadius) { + if (fDistToCenter <= radius) { // Our new voxel value uVoxelValue = 255; } // Wrte the voxel value into the volume - volData.setVoxelAt(x, y, z, uVoxelValue); + _volData->setVoxelAt(x, y, z, uVoxelValue); + } + } + } +} + + +void RenderablePolyVoxEntityItem::clearSphereInVolume(glm::vec3 center, float radius) { + // This three-level for loop iterates over every voxel in the volume + for (int z = 0; z < _volData->getDepth(); z++) { + for (int y = 0; y < _volData->getHeight(); y++) { + for (int x = 0; x < _volData->getWidth(); x++) { + // Store our current position as a vector... + glm::vec3 pos(x, y, z); + // And compute how far the current position is from the center of the volume + float fDistToCenter = glm::distance(pos, center); + uint8_t uVoxelValue = _volData->getVoxelAt(x, y, z); + // If the current voxel is less than 'radius' units from the center then we make it solid. + if (fDistToCenter <= radius) { + // Our new voxel value + uVoxelValue = 0; + } + + // Wrte the voxel value into the volume + _volData->setVoxelAt(x, y, z, uVoxelValue); } } } @@ -84,9 +103,12 @@ void RenderablePolyVoxEntityItem::getModel() { setVoxelVolumeSize(_voxelVolumeSize); } - // PolyVox::SimpleVolume volData(PolyVox::Region(PolyVox::Vector3DInt32(0,0,0), - // PolyVox::Vector3DInt32(63, 63, 63))); - createSphereInVolume(*_volData, 15); + glm::vec3 center(_volData->getDepth() / 2.0f, + _volData->getHeight() / 2.0f, + _volData->getWidth() / 2.0f); + createSphereInVolume(center, 15); + createSphereInVolume(center + glm::vec3(8.0f, 0.0f, 0.0f), 15); + clearSphereInVolume(center + glm::vec3(4.0f, 0.0f, 4.0f), 15); // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index e7b16a7739..b39825e203 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -31,6 +31,8 @@ public: void getModel(); virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize); + void createSphereInVolume(glm::vec3 center, float radius); + void clearSphereInVolume(glm::vec3 center, float radius); private: PolyVox::SimpleVolume* _volData = nullptr; From a882fc7fb1b0e55b7e74caf88a29fa6af9db0773 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 18:07:46 -0700 Subject: [PATCH 17/80] pull out common parts of the two sphere-in-volumes --- .../src/RenderablePolyVoxEntityItem.cpp | 51 +++++-------------- .../src/RenderablePolyVoxEntityItem.h | 4 +- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 84882c1935..fe04d30ce3 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -50,7 +50,8 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); } -void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 center, float radius) { + +void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) { // This three-level for loop iterates over every voxel in the volume for (int z = 0; z < _volData->getDepth(); z++) { for (int y = 0; y < _volData->getHeight(); y++) { @@ -63,7 +64,7 @@ void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 center, float r // If the current voxel is less than 'radius' units from the center then we make it solid. if (fDistToCenter <= radius) { // Our new voxel value - uVoxelValue = 255; + uVoxelValue = toValue; } // Wrte the voxel value into the volume @@ -73,28 +74,13 @@ void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 center, float r } } +void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 center, float radius) { + setSphereInVolume(center, radius, 255); +} -void RenderablePolyVoxEntityItem::clearSphereInVolume(glm::vec3 center, float radius) { - // This three-level for loop iterates over every voxel in the volume - for (int z = 0; z < _volData->getDepth(); z++) { - for (int y = 0; y < _volData->getHeight(); y++) { - for (int x = 0; x < _volData->getWidth(); x++) { - // Store our current position as a vector... - glm::vec3 pos(x, y, z); - // And compute how far the current position is from the center of the volume - float fDistToCenter = glm::distance(pos, center); - uint8_t uVoxelValue = _volData->getVoxelAt(x, y, z); - // If the current voxel is less than 'radius' units from the center then we make it solid. - if (fDistToCenter <= radius) { - // Our new voxel value - uVoxelValue = 0; - } - // Wrte the voxel value into the volume - _volData->setVoxelAt(x, y, z, uVoxelValue); - } - } - } +void RenderablePolyVoxEntityItem::eraseSphereInVolume(glm::vec3 center, float radius) { + setSphereInVolume(center, radius, 0); } void RenderablePolyVoxEntityItem::getModel() { @@ -108,34 +94,21 @@ void RenderablePolyVoxEntityItem::getModel() { _volData->getWidth() / 2.0f); createSphereInVolume(center, 15); createSphereInVolume(center + glm::vec3(8.0f, 0.0f, 0.0f), 15); - clearSphereInVolume(center + glm::vec3(4.0f, 0.0f, 4.0f), 15); + eraseSphereInVolume(center + glm::vec3(4.0f, 0.0f, 4.0f), 15); // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. - PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor + // PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor + // (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - // MarchingCubesSurfaceExtractor> surfaceExtractor(_volData, - // _volData->getEnclosingRegion(), - // &polyVoxMesh); //Execute the surface extractor. surfaceExtractor.execute(); - // find dimensions - // AABox box; - // const std::vector& vertices = polyVoxMesh.getVertices(); - // foreach (const PolyVox::PositionMaterialNormal vertexMaterialNormal, vertices) { - // const PolyVox::Vector3DFloat& vertex = vertexMaterialNormal.position; - // glm::vec3 v(vertex.getX(), vertex.getY(), vertex.getZ()); - // box += v; - // } - // glm::vec3 dimensions = box.getDimensions(); - // setDimensions(dimensions); - - // convert PolyVox mesh to a Sam mesh model::Mesh* mesh = new model::Mesh(); model::MeshPointer meshPtr(mesh); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index b39825e203..7fbf4e980c 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -31,8 +31,10 @@ public: void getModel(); virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize); + + void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue); void createSphereInVolume(glm::vec3 center, float radius); - void clearSphereInVolume(glm::vec3 center, float radius); + void eraseSphereInVolume(glm::vec3 center, float radius); private: PolyVox::SimpleVolume* _volData = nullptr; From f85cc89946ee3ad492ec7dec8c721b228da8a286 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 18:17:07 -0700 Subject: [PATCH 18/80] clean up diff --- libraries/entities-renderer/src/RenderableModelEntityItem.h | 4 ++-- libraries/entities/src/ModelEntityItem.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index 886ae78a83..efd60faedc 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -49,7 +49,7 @@ public: bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const; - virtual Model* getModel(EntityTreeRenderer* renderer); + Model* getModel(EntityTreeRenderer* renderer); bool needsToCallUpdate() const; @@ -65,7 +65,7 @@ private: Model* _model; bool _needsInitialSimulation; - bool _needsModelReload = true; + bool _needsModelReload; EntityTreeRenderer* _myRenderer; QString _currentTextures; QStringList _originalTextures; diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index abfa38250c..d4a4efda04 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -56,7 +56,7 @@ public: const rgbColor& getColor() const { return _color; } xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; } - virtual bool hasModel() const { return !_modelURL.isEmpty(); } + bool hasModel() const { return !_modelURL.isEmpty(); } virtual bool hasCompoundShapeURL() const { return !_compoundShapeURL.isEmpty(); } static const QString DEFAULT_MODEL_URL; From 1100c832eb3877160d2f9f37f5f37f7ed3577ab7 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 21 May 2015 18:18:04 -0700 Subject: [PATCH 19/80] clean up diff --- .../entities-renderer/src/RenderableModelEntityItem.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index f7e70b2b56..43112d7d73 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -199,7 +199,6 @@ void RenderableModelEntityItem::render(RenderArgs* args) { RenderableDebugableEntityItem::render(this, args); } -// virtual Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) { Model* result = NULL; @@ -208,11 +207,11 @@ Model* RenderableModelEntityItem::getModel(EntityTreeRenderer* renderer) { _myRenderer = renderer; } assert(_myRenderer == renderer); // you should only ever render on one renderer - + if (QThread::currentThread() != _myRenderer->thread()) { return _model; } - + _needsModelReload = false; // this is the reload // if we have a URL, then we will want to end up returning a model... From 380fed7aeec69a3b7001b4d8a9658e3ed3373ef1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 22 May 2015 10:37:48 -0700 Subject: [PATCH 20/80] metersToVoxelCoordinates and voxelCoordinatesToMeters --- .../src/RenderablePolyVoxEntityItem.cpp | 25 ++++++++++++++++--- .../src/RenderablePolyVoxEntityItem.h | 3 +++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index fe04d30ce3..e6f0a32e75 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -50,6 +50,23 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); } +glm::vec3 RenderablePolyVoxEntityItem::metersToVoxelCoordinates(glm::vec3 metersOffCenter) { + // convert a vector from the center of the entity with units of meters to a vector with units + // of index-into-volData. + glm::vec3 dimensions = getDimensions(); + glm::vec3 scale = dimensions / _voxelVolumeSize; // meters / voxel-units + glm::vec3 voxelCoords = metersOffCenter / scale; + // the voxel volume is entirely in positive space, but the voxel space is centered at the entity's coords, so: + return voxelCoords + _voxelVolumeSize / 2.0f; +} + +glm::vec3 RenderablePolyVoxEntityItem::voxelCoordinatesToMeters(glm::vec3 voxelCoords) { + // convert a vector is voxel-space to an offset from the entity-center in meters + glm::vec3 dimensions = getDimensions(); + glm::vec3 scale = dimensions / _voxelVolumeSize; // meters / voxel-units + glm::vec3 centeredCoords = voxelCoords - _voxelVolumeSize / 2.0f; + return centeredCoords * scale; +} void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) { // This three-level for loop iterates over every voxel in the volume @@ -100,10 +117,10 @@ void RenderablePolyVoxEntityItem::getModel() { PolyVox::SurfaceMesh polyVoxMesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. - // PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor - // (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + // PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + // (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); //Execute the surface extractor. surfaceExtractor.execute(); @@ -178,7 +195,7 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glm::vec3 positionToCenter = center - position; - // make the voxel volume be centered on the entity's position + // make the rendered voxel volume be centered on the entity's position positionToCenter -= _dimensions * glm::vec3(0.5f,0.5f,0.5f); glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(scale.x, scale.y, scale.z); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 7fbf4e980c..0c0cf82dad 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -32,6 +32,9 @@ public: virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize); + glm::vec3 metersToVoxelCoordinates(glm::vec3 metersOffCenter); + glm::vec3 voxelCoordinatesToMeters(glm::vec3 voxelCoords); + void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue); void createSphereInVolume(glm::vec3 center, float radius); void eraseSphereInVolume(glm::vec3 center, float radius); From e7025180410722b0a8eb0c2290fe3f79b3311b93 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 22 May 2015 16:11:29 -0700 Subject: [PATCH 21/80] adjust logic around timestamps used by entity-server to know if something was sent. adjust which physics variables are adjusted by a non-sim-owner packet --- .../src/octree/OctreeQueryNode.cpp | 3 +-- .../src/octree/OctreeQueryNode.h | 6 ++++- .../src/octree/OctreeSendThread.cpp | 16 ++++++++++---- libraries/entities/src/EntityItem.cpp | 22 ++++++++++++------- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/assignment-client/src/octree/OctreeQueryNode.cpp b/assignment-client/src/octree/OctreeQueryNode.cpp index 35f8fb9973..56d5e041a9 100644 --- a/assignment-client/src/octree/OctreeQueryNode.cpp +++ b/assignment-client/src/octree/OctreeQueryNode.cpp @@ -325,8 +325,7 @@ void OctreeQueryNode::updateLastKnownViewFrustum() { } // save that we know the view has been sent. - quint64 now = usecTimestampNow(); - setLastTimeBagEmpty(now); // is this what we want? poor names + setLastTimeBagEmpty(); } diff --git a/assignment-client/src/octree/OctreeQueryNode.h b/assignment-client/src/octree/OctreeQueryNode.h index ea0f3240aa..ff59fb7685 100644 --- a/assignment-client/src/octree/OctreeQueryNode.h +++ b/assignment-client/src/octree/OctreeQueryNode.h @@ -77,7 +77,7 @@ public: bool moveShouldDump() const; quint64 getLastTimeBagEmpty() const { return _lastTimeBagEmpty; } - void setLastTimeBagEmpty(quint64 lastTimeBagEmpty) { _lastTimeBagEmpty = lastTimeBagEmpty; } + void setLastTimeBagEmpty() { _lastTimeBagEmpty = _sceneSendStartTime; } bool getCurrentPacketIsColor() const { return _currentPacketIsColor; } bool getCurrentPacketIsCompressed() const { return _currentPacketIsCompressed; } @@ -98,6 +98,8 @@ public: void setLastRootTimestamp(quint64 timestamp) { _lastRootTimestamp = timestamp; } unsigned int getlastOctreePacketLength() const { return _lastOctreePacketLength; } int getDuplicatePacketCount() const { return _duplicatePacketCount; } + + void sceneStart(quint64 sceneSendStartTime) { _sceneSendStartTime = sceneSendStartTime; } void nodeKilled(); void forceNodeShutdown(); @@ -158,6 +160,8 @@ private: SentPacketHistory _sentPacketHistory; QQueue _nackedSequenceNumbers; + + quint64 _sceneSendStartTime = 0; }; #endif // hifi_OctreeQueryNode_h diff --git a/assignment-client/src/octree/OctreeSendThread.cpp b/assignment-client/src/octree/OctreeSendThread.cpp index 2014c56476..d664fb5c8f 100644 --- a/assignment-client/src/octree/OctreeSendThread.cpp +++ b/assignment-client/src/octree/OctreeSendThread.cpp @@ -343,8 +343,7 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus if (!viewFrustumChanged && !nodeData->getWantDelta()) { // only set our last sent time if we weren't resetting due to frustum change - quint64 now = usecTimestampNow(); - nodeData->setLastTimeBagEmpty(now); + nodeData->setLastTimeBagEmpty(); } // track completed scenes and send out the stats packet accordingly @@ -368,9 +367,11 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus // TODO: add these to stats page //::startSceneSleepTime = _usleepTime; - + + nodeData->sceneStart(usecTimestampNow() - CHANGE_FUDGE); // start tracking our stats - nodeData->stats.sceneStarted(isFullScene, viewFrustumChanged, _myServer->getOctree()->getRoot(), _myServer->getJurisdiction()); + nodeData->stats.sceneStarted(isFullScene, viewFrustumChanged, + _myServer->getOctree()->getRoot(), _myServer->getJurisdiction()); // This is the start of "resending" the scene. bool dontRestartSceneOnMove = false; // this is experimental @@ -561,6 +562,13 @@ int OctreeSendThread::packetDistributor(OctreeQueryNode* nodeData, bool viewFrus } + if (somethingToSend) { + qDebug() << "Hit PPS Limit, packetsSentThisInterval =" << packetsSentThisInterval + << " maxPacketsPerInterval = " << maxPacketsPerInterval + << " clientMaxPacketsPerInterval = " << clientMaxPacketsPerInterval; + } + + // Here's where we can/should allow the server to send other data... // send the environment packet // TODO: should we turn this into a while loop to better handle sending multiple special packets diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index e8210c7e79..ee728160f6 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -321,10 +321,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // if this bitstream indicates that this node is the simulation owner, ignore any physics-related updates. glm::vec3 savePosition = _position; glm::quat saveRotation = _rotation; - // glm::vec3 saveVelocity = _velocity; - // glm::vec3 saveAngularVelocity = _angularVelocity; - // glm::vec3 saveGravity = _gravity; - // glm::vec3 saveAcceleration = _acceleration; + glm::vec3 saveVelocity = _velocity; + glm::vec3 saveAngularVelocity = _angularVelocity; + glm::vec3 saveGravity = _gravity; + glm::vec3 saveAcceleration = _acceleration; + uint32_t saveFlags = _dirtyFlags; // Header bytes @@ -626,10 +627,15 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // this node, so our version has to be newer than what the packet contained. _position = savePosition; _rotation = saveRotation; - // _velocity = saveVelocity; - // _angularVelocity = saveAngularVelocity; - // _gravity = saveGravity; - // _acceleration = saveAcceleration; + _velocity = saveVelocity; + _angularVelocity = saveAngularVelocity; + _gravity = saveGravity; + _acceleration = saveAcceleration; + _dirtyFlags &= ~(saveFlags & (EntityItem::DIRTY_POSITION | + EntityItem::DIRTY_ROTATION | + EntityItem::DIRTY_LINEAR_VELOCITY | + EntityItem::DIRTY_ANGULAR_VELOCITY | + EntityItem::DIRTY_PHYSICS_ACTIVATION)); } return bytesRead; From 6c67d14fbc90be5907906baafaaecea5237b1876 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 22 May 2015 16:21:09 -0700 Subject: [PATCH 22/80] experimenting with physics --- libraries/entities/src/EntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index ee728160f6..1c68947eef 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -613,7 +613,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // we want to extrapolate the motion forward to compensate for packet travel time, but // we don't want the side effect of flag setting. - simulateKinematicMotion(skipTimeForward, false); + // simulateKinematicMotion(skipTimeForward, false); } _lastSimulated = now; } From 727f457f91e627695a1eb0ea9fcbf71258d2bb28 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Mon, 25 May 2015 21:01:20 -0700 Subject: [PATCH 23/80] hook up RenderablePolyVoxEntityItem::findDetailedRayIntersection to polyvox library's version --- .../src/RenderablePolyVoxEntityItem.cpp | 132 ++++++++++++++---- .../src/RenderablePolyVoxEntityItem.h | 22 ++- libraries/entities/src/EntityItem.cpp | 2 +- 3 files changed, 125 insertions(+), 31 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index e6f0a32e75..967c8950ad 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -10,6 +10,7 @@ // #include +#include #include @@ -21,6 +22,8 @@ #include #include #include +#include +#include #include "model/Geometry.h" #include "gpu/GLBackend.h" @@ -50,22 +53,19 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); } -glm::vec3 RenderablePolyVoxEntityItem::metersToVoxelCoordinates(glm::vec3 metersOffCenter) { - // convert a vector from the center of the entity with units of meters to a vector with units - // of index-into-volData. - glm::vec3 dimensions = getDimensions(); - glm::vec3 scale = dimensions / _voxelVolumeSize; // meters / voxel-units - glm::vec3 voxelCoords = metersOffCenter / scale; - // the voxel volume is entirely in positive space, but the voxel space is centered at the entity's coords, so: - return voxelCoords + _voxelVolumeSize / 2.0f; +glm::mat4 RenderablePolyVoxEntityItem::voxelToWorldMatrix() const { + glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units + glm::mat4 scaled = glm::scale(glm::mat4(), scale); + glm::mat4 centerToCorner = glm::translate(scaled, _voxelVolumeSize / -2.0f); + glm::mat4 rotation = glm::mat4_cast(_rotation); + glm::mat4 translation = glm::translate(getCenter()); + return translation * rotation * centerToCorner; } -glm::vec3 RenderablePolyVoxEntityItem::voxelCoordinatesToMeters(glm::vec3 voxelCoords) { - // convert a vector is voxel-space to an offset from the entity-center in meters - glm::vec3 dimensions = getDimensions(); - glm::vec3 scale = dimensions / _voxelVolumeSize; // meters / voxel-units - glm::vec3 centeredCoords = voxelCoords - _voxelVolumeSize / 2.0f; - return centeredCoords * scale; +glm::mat4 RenderablePolyVoxEntityItem::worldToVoxelMatrix() const { + glm::mat4 worldToModelMatrix = glm::inverse(voxelToWorldMatrix()); + return worldToModelMatrix; + } void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) { @@ -91,13 +91,29 @@ void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radi } } -void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 center, float radius) { - setSphereInVolume(center, radius, 255); +void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 centerVoxelCoords, float radiusVoxelCoords) { + setSphereInVolume(centerVoxelCoords, radiusVoxelCoords, 255); } +void RenderablePolyVoxEntityItem::eraseSphereInVolume(glm::vec3 centerVoxelCoords, float radiusVoxelCoords) { + setSphereInVolume(centerVoxelCoords, radiusVoxelCoords, 0); +} -void RenderablePolyVoxEntityItem::eraseSphereInVolume(glm::vec3 center, float radius) { - setSphereInVolume(center, radius, 0); +void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords, uint8_t toValue) { + // glm::vec3 centerVoxelCoords = worldToVoxelCoordinates(centerWorldCoords); + glm::vec4 centerVoxelCoords = worldToVoxelMatrix() * glm::vec4(centerWorldCoords, 1.0f); + glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units + float scaleY = scale[0]; + float radiusVoxelCoords = radiusWorldCoords / scaleY; + setSphereInVolume(glm::vec3(centerVoxelCoords), radiusVoxelCoords, toValue); +} + +void RenderablePolyVoxEntityItem::createSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords) { + setSphere(centerWorldCoords, radiusWorldCoords, 255); +} + +void RenderablePolyVoxEntityItem::eraseSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords) { + setSphere(centerWorldCoords, radiusWorldCoords, 0); } void RenderablePolyVoxEntityItem::getModel() { @@ -106,12 +122,19 @@ void RenderablePolyVoxEntityItem::getModel() { setVoxelVolumeSize(_voxelVolumeSize); } - glm::vec3 center(_volData->getDepth() / 2.0f, - _volData->getHeight() / 2.0f, - _volData->getWidth() / 2.0f); - createSphereInVolume(center, 15); - createSphereInVolume(center + glm::vec3(8.0f, 0.0f, 0.0f), 15); - eraseSphereInVolume(center + glm::vec3(4.0f, 0.0f, 4.0f), 15); + // glm::vec3 center(_volData->getDepth() / 2.0f, + // _volData->getHeight() / 2.0f, + // _volData->getWidth() / 2.0f); + // createSphereInVolume(center, 15); + // createSphereInVolume(center + glm::vec3(8.0f, 0.0f, 0.0f), 15); + // eraseSphereInVolume(center + glm::vec3(4.0f, 0.0f, 4.0f), 15); + + + glm::vec3 center = getCenter(); + createSphere(center, 4); + createSphere(center + glm::vec3(6.0f, 0.0f, 0.0f), 2); + // eraseSphere(center + glm::vec3(0.5f, 0.0f, 4.0f), 0.8); + // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; @@ -153,7 +176,7 @@ void RenderablePolyVoxEntityItem::getModel() { gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); - qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------"; + qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------" << usecTimestampNow(); qDebug() << "---- vecIndices.size() =" << vecIndices.size(); qDebug() << "---- sizeof(vecIndices[0]) =" << sizeof(vecIndices[0]); qDebug() << "---- vecVertices.size() =" << vecVertices.size(); @@ -175,8 +198,6 @@ void RenderablePolyVoxEntityItem::getModel() { _needsModelReload = false; } - - void RenderablePolyVoxEntityItem::render(RenderArgs* args) { PerformanceTimer perfTimer("RenderablePolyVoxEntityItem::render"); assert(getType() == EntityTypes::PolyVox); @@ -214,3 +235,60 @@ void RenderablePolyVoxEntityItem::render(RenderArgs* args) { glPopMatrix(); RenderableDebugableEntityItem::render(this, args); } + +class RaycastFunctor +{ +public: + RaycastFunctor() : _result(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)) { } + bool operator()(PolyVox::SimpleVolume::Sampler& sampler) + { + if (sampler.getVoxel() == 0) { + return true; // keep raycasting + } + PolyVox::Vector3DInt32 positionIndex = sampler.getPosition(); + _result = glm::vec4(positionIndex.getX(), positionIndex.getY(), positionIndex.getZ(), 1.0f); + return false; + } + glm::vec4 _result; +}; + +bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& origin, + const glm::vec3& direction, + bool& keepSearching, + OctreeElement*& element, + float& distance, BoxFace& face, + void** intersectedObject, + bool precisionPicking) const +{ + if (_needsModelReload || !precisionPicking) { + // just intersect with bounding box + return true; + } + + glm::mat4 wtvMatrix = worldToVoxelMatrix(); + glm::vec3 far = origin + direction; + glm::vec4 originInVoxel = wtvMatrix * glm::vec4(origin, 1.0f); + glm::vec4 farInVoxel = wtvMatrix * glm::vec4(far, 1.0f); + glm::vec4 directionInVoxel = farInVoxel - originInVoxel; + + PolyVox::Vector3DFloat start(originInVoxel[0], originInVoxel[1], originInVoxel[2]); + PolyVox::Vector3DFloat pvDirection(directionInVoxel[0], directionInVoxel[1], directionInVoxel[2]); + pvDirection.normalise(); + // pvDirection *= 1000.0f; // Casts ray of length 1000 + pvDirection *= 64.0f; // Casts ray of length 1000 + + PolyVox::RaycastResult raycastResult; + RaycastFunctor callback; + raycastResult = PolyVox::raycastWithDirection(_volData, start, pvDirection, callback); + + if (raycastResult == PolyVox::RaycastResults::Completed) // the ray completed its path -- nothing was hit. + return false; + + glm::vec4 intersectedWorldPosition = voxelToWorldMatrix() * callback._result; + + distance = glm::distance(glm::vec3(intersectedWorldPosition), origin); + + face = BoxFace::MIN_X_FACE; // XXX + + return true; +} diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 0c0cf82dad..4d414b4b7b 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -26,14 +26,30 @@ public: virtual ~RenderablePolyVoxEntityItem(); + virtual void somethingChangedNotification() { + // This gets called from EnityItem::readEntityDataFromBuffer every time a packet describing + // this entity comes from the entity-server. It gets called even if nothing has actually changed + // (see the comment in EntityItem.cpp). If that gets fixed, this could be used to know if we + // need to redo the voxel data. + // _needsModelReload = true; + } + + void render(RenderArgs* args); - virtual bool hasModel() const { return true; } + virtual bool supportsDetailedRayIntersection() const { return true; } + virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, + bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, + void** intersectedObject, bool precisionPicking) const; + void getModel(); virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize); + glm::mat4 voxelToWorldMatrix() const; + glm::mat4 worldToVoxelMatrix() const; - glm::vec3 metersToVoxelCoordinates(glm::vec3 metersOffCenter); - glm::vec3 voxelCoordinatesToMeters(glm::vec3 voxelCoords); + void setSphere(glm::vec3 center, float radius, uint8_t toValue); + void createSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords); + void eraseSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords); void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue); void createSphereInVolume(glm::vec3 center, float radius); diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 1c68947eef..ee728160f6 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -613,7 +613,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // we want to extrapolate the motion forward to compensate for packet travel time, but // we don't want the side effect of flag setting. - // simulateKinematicMotion(skipTimeForward, false); + simulateKinematicMotion(skipTimeForward, false); } _lastSimulated = now; } From a251ae7f500f65ccc599496a4608c2285517f902 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 09:06:51 -0700 Subject: [PATCH 24/80] far is a reserved word --- .../entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 967c8950ad..ff4cbdd3c1 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -266,9 +266,9 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o } glm::mat4 wtvMatrix = worldToVoxelMatrix(); - glm::vec3 far = origin + direction; + glm::vec3 farPoint = origin + direction; glm::vec4 originInVoxel = wtvMatrix * glm::vec4(origin, 1.0f); - glm::vec4 farInVoxel = wtvMatrix * glm::vec4(far, 1.0f); + glm::vec4 farInVoxel = wtvMatrix * glm::vec4(farPoint, 1.0f); glm::vec4 directionInVoxel = farInVoxel - originInVoxel; PolyVox::Vector3DFloat start(originInVoxel[0], originInVoxel[1], originInVoxel[2]); From 59f68f56256206257ca234953deab7ba139d87ec Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 09:52:18 -0700 Subject: [PATCH 25/80] added voxel-data compression code to see what the sizes are like --- .../src/RenderablePolyVoxEntityItem.cpp | 24 +++++++++++++++++++ .../src/RenderablePolyVoxEntityItem.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index ff4cbdd3c1..c998e2dbc6 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -9,6 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + + #include #include @@ -89,6 +92,7 @@ void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radi } } } + compressVolumeData(); } void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 centerVoxelCoords, float radiusVoxelCoords) { @@ -292,3 +296,23 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o return true; } + + +void RenderablePolyVoxEntityItem::compressVolumeData() { + int rawSize = _volData->getDepth() * _volData->getHeight() * _volData->getWidth(); + QByteArray uncompressedData = QByteArray(rawSize, '\0'); + + for (int z = 0; z < _volData->getDepth(); z++) { + for (int y = 0; y < _volData->getHeight(); y++) { + for (int x = 0; x < _volData->getWidth(); x++) { + uint8_t uVoxelValue = _volData->getVoxelAt(x, y, z); + int uncompressedIndex = z * _volData->getHeight() * _volData->getWidth() + y * _volData->getWidth() + x; + uncompressedData[uncompressedIndex] = uVoxelValue; + } + } + } + + QByteArray compressedData = qCompress(uncompressedData, 9); + qDebug() << "-----------------------------------------------------------------------------"; + qDebug() << "raw-size =" << rawSize << " compressed-size =" << compressedData.size(); +} diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 4d414b4b7b..1bbdc2e20a 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -56,6 +56,8 @@ public: void eraseSphereInVolume(glm::vec3 center, float radius); private: + void compressVolumeData(); + PolyVox::SimpleVolume* _volData = nullptr; model::Geometry _modelGeometry; bool _needsModelReload = true; From ed6fdcfb31d008dd23ac68aa04e10c88f5dbb4d6 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 13:18:25 -0700 Subject: [PATCH 26/80] add QByteArray data uppacking --- libraries/octree/src/OctreePacketData.cpp | 9 +++++++++ libraries/octree/src/OctreePacketData.h | 1 + 2 files changed, 10 insertions(+) diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 8bc27b872f..ce8a6fbd0e 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -573,3 +573,12 @@ int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, xColor result.blue = dataBytes[BLUE_INDEX]; return sizeof(rgbColor); } + +int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, QByteArray& result) { + uint16_t length; + memcpy(&length, dataBytes, sizeof(length)); + dataBytes += sizeof(length); + QByteArray value((const char*)dataBytes, length); + result = value; + return sizeof(length) + length; +} diff --git a/libraries/octree/src/OctreePacketData.h b/libraries/octree/src/OctreePacketData.h index 28ea9aa681..2bad0e96d9 100644 --- a/libraries/octree/src/OctreePacketData.h +++ b/libraries/octree/src/OctreePacketData.h @@ -240,6 +240,7 @@ public: static int uppackDataFromBytes(const unsigned char* dataBytes, QString& result); static int uppackDataFromBytes(const unsigned char* dataBytes, QUuid& result); static int uppackDataFromBytes(const unsigned char* dataBytes, xColor& result); + static int uppackDataFromBytes(const unsigned char* dataBytes, QByteArray& result); private: /// appends raw bytes, might fail if byte would cause packet to be too large From 988ecf9d5503fd184d4e6c652da990fcdb2b397a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 13:18:52 -0700 Subject: [PATCH 27/80] send PolyVox voxel dimensions and compressed data over the wire --- .../src/RenderablePolyVoxEntityItem.cpp | 10 ------ .../entities/src/EntityItemProperties.cpp | 4 +++ libraries/entities/src/EntityItemProperties.h | 4 +++ libraries/entities/src/EntityPropertyFlags.h | 3 ++ libraries/entities/src/PolyVoxEntityItem.cpp | 32 +++++++++++++------ libraries/entities/src/PolyVoxEntityItem.h | 12 +++++-- 6 files changed, 44 insertions(+), 21 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index c998e2dbc6..29d8c6ebf3 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -126,19 +126,9 @@ void RenderablePolyVoxEntityItem::getModel() { setVoxelVolumeSize(_voxelVolumeSize); } - // glm::vec3 center(_volData->getDepth() / 2.0f, - // _volData->getHeight() / 2.0f, - // _volData->getWidth() / 2.0f); - // createSphereInVolume(center, 15); - // createSphereInVolume(center + glm::vec3(8.0f, 0.0f, 0.0f), 15); - // eraseSphereInVolume(center + glm::vec3(4.0f, 0.0f, 4.0f), 15); - - glm::vec3 center = getCenter(); createSphere(center, 4); createSphere(center + glm::vec3(6.0f, 0.0f, 0.0f), 2); - // eraseSphere(center + glm::vec3(0.5f, 0.0f, 4.0f), 0.8); - // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 905fa7d104..07df72656b 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -26,6 +26,7 @@ #include "ParticleEffectEntityItem.h" #include "TextEntityItem.h" #include "ZoneEntityItem.h" +#include "PolyVoxEntityItem.h" AtmospherePropertyGroup EntityItemProperties::_staticAtmosphere; SkyboxPropertyGroup EntityItemProperties::_staticSkybox; @@ -90,6 +91,9 @@ CONSTRUCT_PROPERTY(keyLightDirection, ZoneEntityItem::DEFAULT_KEYLIGHT_DIRECTION CONSTRUCT_PROPERTY(name, ENTITY_ITEM_DEFAULT_NAME), CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(sourceUrl, ""), +CONSTRUCT_PROPERTY(voxelVolumeSize, PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE), +CONSTRUCT_PROPERTY(voxelData, PolyVoxEntityItem::DEFAULT_VOXEL_DATA), + _id(UNKNOWN_ENTITY_ID), _idSet(false), diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 827a48f632..72b4e4ad0b 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -142,6 +142,8 @@ public: DEFINE_PROPERTY_GROUP(Atmosphere, atmosphere, AtmospherePropertyGroup); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_REF(PROP_SOURCE_URL, SourceUrl, sourceUrl, QString); + DEFINE_PROPERTY_REF(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3); + DEFINE_PROPERTY_REF(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray); static QString getBackgroundModeString(BackgroundMode mode); @@ -282,6 +284,8 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, ParticleRadius, particleRadius, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, MarketplaceID, marketplaceID, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, BackgroundMode, backgroundMode, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelVolumeSize, voxelVolumeSize, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelData, voxelData, ""); properties.getStage().debugDump(); properties.getAtmosphere().debugDump(); diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index 8a5d96e8d2..eb5cb1a0ae 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -110,6 +110,9 @@ enum EntityPropertyList { PROP_RESTITUTION, PROP_FRICTION, + PROP_VOXEL_VOLUME_SIZE, + PROP_VOXEL_DATA, + //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties ABOVE this line PROP_AFTER_LAST_ITEM, diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index f094d83af1..71f1c2fb65 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -10,6 +10,7 @@ // +#include #include #include @@ -20,17 +21,19 @@ #include "EntityTreeElement.h" +const glm::vec3 PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE = glm::vec3(32, 32, 32); +const QByteArray PolyVoxEntityItem::DEFAULT_VOXEL_DATA(qCompress(QByteArray(0), 9)); + EntityItem* PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - qDebug() << "XXXXXXXXXXXX XXXXXXXXXXXX making PolyVoxEntityItem entity"; EntityItem* result = new PolyVoxEntityItem(entityID, properties); return result; } PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : - EntityItem(entityItemID) + EntityItem(entityItemID), + _voxelVolumeSize(PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE), + _voxelData(PolyVoxEntityItem::DEFAULT_VOXEL_DATA) { - qDebug() << "XXXXXXXXXXXX XXXXXXXXXXXX making PolyVoxEntityItem entity"; - _type = EntityTypes::PolyVox; _created = properties.getCreated(); setProperties(properties); @@ -39,11 +42,14 @@ PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const Ent EntityItemProperties PolyVoxEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - properties._color = getXColor(); - properties._colorChanged = false; + // properties._color = getXColor(); + // properties._colorChanged = false; + // properties._glowLevel = getGlowLevel(); + // properties._glowLevelChanged = false; - properties._glowLevel = getGlowLevel(); - properties._glowLevelChanged = false; + COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelVolumeSize, getVoxelVolumeSize); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelData, getVoxelData); return properties; } @@ -52,7 +58,9 @@ bool PolyVoxEntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = false; somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class - SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setXColor); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelVolumeSize, setVoxelVolumeSize); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelData, setVoxelData); if (somethingChanged) { bool wantDebug = false; @@ -75,6 +83,8 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat const unsigned char* dataAt = data; READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); + READ_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); + READ_ENTITY_PROPERTY(PROP_VOXEL_DATA, QByteArray, setVoxelData); return bytesRead; } @@ -84,6 +94,8 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat EntityPropertyFlags PolyVoxEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); requestedProperties += PROP_COLOR; + requestedProperties += PROP_VOXEL_VOLUME_SIZE; + requestedProperties += PROP_VOXEL_DATA; return requestedProperties; } @@ -98,6 +110,8 @@ void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeB bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, getVoxelVolumeSize()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, getVoxelData()); } void PolyVoxEntityItem::debugDump() const { diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 35071b4d88..387bb86225 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -45,7 +45,7 @@ class PolyVoxEntityItem : public EntityItem { xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; } void setColor(const rgbColor& value) { memcpy(_color, value, sizeof(_color)); } - void setColor(const xColor& value) { + void setXColor(const xColor& value) { _color[RED_INDEX] = value.red; _color[GREEN_INDEX] = value.green; _color[BLUE_INDEX] = value.blue; @@ -62,10 +62,18 @@ class PolyVoxEntityItem : public EntityItem { virtual void debugDump() const; virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { _voxelVolumeSize = voxelVolumeSize; } + virtual const glm::vec3& getVoxelVolumeSize() const { return _voxelVolumeSize; } + + virtual void setVoxelData(QByteArray voxelData) { _voxelData = voxelData; } + virtual const QByteArray& getVoxelData() const { return _voxelData; } + + static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; + static const QByteArray DEFAULT_VOXEL_DATA; protected: rgbColor _color; - glm::vec3 _voxelVolumeSize = glm::vec3(64, 64, 64); + glm::vec3 _voxelVolumeSize; // this is always 3 bytes + QByteArray _voxelData; }; #endif // hifi_PolyVoxEntityItem_h From 1ec384ab4df02790a770369469a2b2465c727fff Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 13:43:22 -0700 Subject: [PATCH 28/80] allow QByteArray data to be sent with a length. Use appendRawData in places that used to append raw byte-arrays --- libraries/entities/src/EntityItem.cpp | 10 +++++----- libraries/entities/src/EntityItemProperties.cpp | 10 +++++----- libraries/octree/src/OctreePacketData.cpp | 13 ++++++++++++- libraries/octree/src/OctreePacketData.h | 1 + 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index ee728160f6..8cc373e5cc 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -183,9 +183,9 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet QByteArray encodedPropertyFlags; int propertyCount = 0; - successIDFits = packetData->appendValue(encodedID); + successIDFits = packetData->appendRawData(encodedID); if (successIDFits) { - successTypeFits = packetData->appendValue(encodedType); + successTypeFits = packetData->appendRawData(encodedType); } if (successTypeFits) { successCreatedFits = packetData->appendValue(_created); @@ -194,17 +194,17 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet successLastEditedFits = packetData->appendValue(lastEdited); } if (successLastEditedFits) { - successLastUpdatedFits = packetData->appendValue(encodedUpdateDelta); + successLastUpdatedFits = packetData->appendRawData(encodedUpdateDelta); } if (successLastUpdatedFits) { - successLastSimulatedFits = packetData->appendValue(encodedSimulatedDelta); + successLastSimulatedFits = packetData->appendRawData(encodedSimulatedDelta); } if (successLastSimulatedFits) { propertyFlagsOffset = packetData->getUncompressedByteOffset(); encodedPropertyFlags = propertyFlags; oldPropertyFlagsLength = encodedPropertyFlags.length(); - successPropertyFlagsFits = packetData->appendValue(encodedPropertyFlags); + successPropertyFlagsFits = packetData->appendRawData(encodedPropertyFlags); } bool headerFits = successIDFits && successTypeFits && successCreatedFits && successLastEditedFits diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 07df72656b..59944b92fc 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -623,23 +623,23 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem quint64 lastEdited = properties.getLastEdited(); bool successLastEditedFits = packetData->appendValue(lastEdited); - bool successIDFits = packetData->appendValue(encodedID); + bool successIDFits = packetData->appendRawData(encodedID); if (successIDFits) { - successIDFits = packetData->appendValue(encodedToken); + successIDFits = packetData->appendRawData(encodedToken); } - bool successTypeFits = packetData->appendValue(encodedType); + bool successTypeFits = packetData->appendRawData(encodedType); // NOTE: We intentionally do not send "created" times in edit messages. This is because: // 1) if the edit is to an existing entity, the created time can not be changed // 2) if the edit is to a new entity, the created time is the last edited time // TODO: Should we get rid of this in this in edit packets, since this has to always be 0? - bool successLastUpdatedFits = packetData->appendValue(encodedUpdateDelta); + bool successLastUpdatedFits = packetData->appendRawData(encodedUpdateDelta); int propertyFlagsOffset = packetData->getUncompressedByteOffset(); QByteArray encodedPropertyFlags = propertyFlags; int oldPropertyFlagsLength = encodedPropertyFlags.length(); - bool successPropertyFlagsFits = packetData->appendValue(encodedPropertyFlags); + bool successPropertyFlagsFits = packetData->appendRawData(encodedPropertyFlags); int propertyCount = 0; bool headerFits = successIDFits && successTypeFits && successLastEditedFits diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index ce8a6fbd0e..ed30c619ca 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -426,7 +426,12 @@ bool OctreePacketData::appendValue(const QUuid& uuid) { } bool OctreePacketData::appendValue(const QByteArray& bytes) { - bool success = appendRawData((const unsigned char*)bytes.constData(), bytes.size()); + // TODO: make this a ByteCountCoded leading byte + uint16_t length = bytes.size(); + bool success = appendValue(length); + if (success) { + success = appendRawData((const unsigned char*)bytes.constData(), bytes.size()); + } return success; } @@ -451,6 +456,12 @@ bool OctreePacketData::appendRawData(const unsigned char* data, int length) { return success; } + +bool OctreePacketData::appendRawData(QByteArray data) { + return appendRawData((unsigned char *)data.data(), data.size()); +} + + quint64 OctreePacketData::_compressContentTime = 0; quint64 OctreePacketData::_compressContentCalls = 0; diff --git a/libraries/octree/src/OctreePacketData.h b/libraries/octree/src/OctreePacketData.h index 2bad0e96d9..28d6ff7d20 100644 --- a/libraries/octree/src/OctreePacketData.h +++ b/libraries/octree/src/OctreePacketData.h @@ -183,6 +183,7 @@ public: /// appends raw bytes, might fail if byte would cause packet to be too large bool appendRawData(const unsigned char* data, int length); + bool appendRawData(QByteArray data); /// returns a byte offset from beginning of the uncompressed stream based on offset from end. /// Positive offsetFromEnd returns that many bytes before the end of uncompressed stream From 728e6d121b040e59f2c7411390d4ae54d9cbf671 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 14:12:01 -0700 Subject: [PATCH 29/80] changes sam made to get normals to work on a mesh --- .../src/RenderablePolyVoxEntityItem.cpp | 11 +++-- libraries/gpu/src/gpu/Resource.h | 48 +++++++++++-------- libraries/model/src/model/Geometry.cpp | 9 ++++ libraries/model/src/model/Geometry.h | 1 + .../src/DeferredLightingEffect.cpp | 8 ++-- 5 files changed, 50 insertions(+), 27 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index c998e2dbc6..2b731c2a27 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -144,10 +144,10 @@ void RenderablePolyVoxEntityItem::getModel() { PolyVox::SurfaceMesh polyVoxMesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. - PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor - (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - // PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + // PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor // (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); //Execute the surface extractor. surfaceExtractor.execute(); @@ -179,6 +179,11 @@ void RenderablePolyVoxEntityItem::getModel() { sizeof(PolyVox::PositionMaterialNormal), gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); + auto normalAttrib = mesh->getAttributeBuffer(gpu::Stream::NORMAL); + for (auto normal = normalAttrib.begin(); normal != normalAttrib.end(); normal++) { + (*normal) = -(*normal); + } + qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------" << usecTimestampNow(); qDebug() << "---- vecIndices.size() =" << vecIndices.size(); diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 7f3f850339..c7763e108b 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -228,13 +228,14 @@ public: { public: - Iterator(T* ptr = NULL) { _ptr = ptr; } + Iterator(T* ptr = NULL, int stride = sizeof(T)): _ptr(ptr), _stride(stride) { } Iterator(const Iterator& iterator) = default; ~Iterator() {} Iterator& operator=(const Iterator& iterator) = default; Iterator& operator=(T* ptr) { _ptr = ptr; + // stride is left unchanged return (*this); } @@ -249,43 +250,49 @@ public: bool operator==(const Iterator& iterator) const { return (_ptr == iterator.getConstPtr()); } bool operator!=(const Iterator& iterator) const { return (_ptr != iterator.getConstPtr()); } + void movePtr(const Index& movement) { + auto byteptr = ((Byte*)_ptr); + byteptr += _stride * movement; + _ptr = (T*)byteptr; + } + Iterator& operator+=(const Index& movement) { - _ptr += movement; + movePtr(movement); return (*this); } Iterator& operator-=(const Index& movement) { - _ptr -= movement; + movePtr(-movement); return (*this); } Iterator& operator++() { - ++_ptr; + movePtr(1); return (*this); } Iterator& operator--() { - --_ptr; - return (*this); + movePtr(-1); + return (*this); } Iterator operator++(Index) { auto temp(*this); - ++_ptr; - return temp; + movePtr(1); + return temp; } Iterator operator--(Index) { auto temp(*this); - --_ptr; - return temp; + movePtr(-1); + return temp; } Iterator operator+(const Index& movement) { auto oldPtr = _ptr; - _ptr += movement; + movePtr(movement); auto temp(*this); _ptr = oldPtr; return temp; } Iterator operator-(const Index& movement) { auto oldPtr = _ptr; - _ptr -= movement; - auto temp(*this); + movePtr(-movement); + auto temp(*this); _ptr = oldPtr; return temp; } @@ -302,16 +309,17 @@ public: protected: T* _ptr; + int _stride = sizeof(T); }; - template Iterator begin() { return Iterator(&edit(0)); } - template Iterator end() { return Iterator(&edit(getNum())); } - template Iterator cbegin() const { return Iterator(&get(0)); } - template Iterator cend() const { return Iterator(&get(getNum())); } + template Iterator begin() { return Iterator(&edit(0), _stride); } + template Iterator end() { return Iterator(&edit(getNum()), _stride); } + template Iterator cbegin() const { return Iterator(&get(0), _stride); } + template Iterator cend() const { return Iterator(&get(getNum()), _stride); } // the number of elements of the specified type fitting in the view size template Index getNum() const { - return Index(_size / sizeof(T)); + return Index(_size / _stride); } template const T& get() const { @@ -347,7 +355,7 @@ public: } template const T& get(const Index index) const { - Resource::Size elementOffset = index * sizeof(T) + _offset; + Resource::Size elementOffset = index * _stride + _offset; #if _DEBUG if (!_buffer) { qDebug() << "Accessing null gpu::buffer!"; @@ -363,7 +371,7 @@ public: } template T& edit(const Index index) const { - Resource::Size elementOffset = index * sizeof(T) + _offset; + Resource::Size elementOffset = index * _stride + _offset; #if _DEBUG if (!_buffer) { qDebug() << "Accessing null gpu::buffer!"; diff --git a/libraries/model/src/model/Geometry.cpp b/libraries/model/src/model/Geometry.cpp index ed0201763a..7f0abbd9b9 100755 --- a/libraries/model/src/model/Geometry.cpp +++ b/libraries/model/src/model/Geometry.cpp @@ -42,6 +42,15 @@ void Mesh::addAttribute(Slot slot, const BufferView& buffer) { evalVertexFormat(); } +const BufferView Mesh::getAttributeBuffer(int attrib) const { + auto attribBuffer = _attributeBuffers.find(attrib); + if (attribBuffer != _attributeBuffers.end()) { + return attribBuffer->second; + } else { + return BufferView(); + } +} + void Mesh::evalVertexFormat() { auto vf = new VertexFormat(); int channelNum = 0; diff --git a/libraries/model/src/model/Geometry.h b/libraries/model/src/model/Geometry.h index 95f1c3bce7..736047e886 100755 --- a/libraries/model/src/model/Geometry.h +++ b/libraries/model/src/model/Geometry.h @@ -52,6 +52,7 @@ public: // Attribute Buffers int getNumAttributes() const { return _attributeBuffers.size(); } void addAttribute(Slot slot, const BufferView& buffer); + const BufferView getAttributeBuffer(int attrib) const; // Stream format const gpu::Stream::FormatPointer getVertexFormat() const { return _vertexFormat; } diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 54e5388ec8..795b2a4389 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -93,16 +93,16 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { } void DeferredLightingEffect::bindSimpleProgram() { - DependencyManager::get()->setPrimaryDrawBuffers(true, true, true); + // DependencyManager::get()->setPrimaryDrawBuffers(true, true, true); _simpleProgram.bind(); _simpleProgram.setUniformValue(_glowIntensityLocation, DependencyManager::get()->getIntensity()); - glDisable(GL_BLEND); + // glDisable(GL_BLEND); } void DeferredLightingEffect::releaseSimpleProgram() { - glEnable(GL_BLEND); + // glEnable(GL_BLEND); _simpleProgram.release(); - DependencyManager::get()->setPrimaryDrawBuffers(true, false, false); + // DependencyManager::get()->setPrimaryDrawBuffers(true, false, false); } void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color) { From cdef502e2e07d43caeb8b0e2494e8fa28841a667 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 14:26:05 -0700 Subject: [PATCH 30/80] expose setVoxelSphere to js --- .../src/RenderablePolyVoxEntityItem.cpp | 34 +++---------------- .../src/RenderablePolyVoxEntityItem.h | 10 +++--- .../entities/src/EntityScriptingInterface.cpp | 17 ++++++++++ .../entities/src/EntityScriptingInterface.h | 2 ++ libraries/entities/src/PolyVoxEntityItem.h | 6 ++++ 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 29d8c6ebf3..c3bad8a5e4 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -80,29 +80,16 @@ void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radi glm::vec3 pos(x, y, z); // And compute how far the current position is from the center of the volume float fDistToCenter = glm::distance(pos, center); - uint8_t uVoxelValue = _volData->getVoxelAt(x, y, z); // If the current voxel is less than 'radius' units from the center then we make it solid. if (fDistToCenter <= radius) { - // Our new voxel value - uVoxelValue = toValue; + _volData->setVoxelAt(x, y, z, toValue); } - - // Wrte the voxel value into the volume - _volData->setVoxelAt(x, y, z, uVoxelValue); } } } compressVolumeData(); } -void RenderablePolyVoxEntityItem::createSphereInVolume(glm::vec3 centerVoxelCoords, float radiusVoxelCoords) { - setSphereInVolume(centerVoxelCoords, radiusVoxelCoords, 255); -} - -void RenderablePolyVoxEntityItem::eraseSphereInVolume(glm::vec3 centerVoxelCoords, float radiusVoxelCoords) { - setSphereInVolume(centerVoxelCoords, radiusVoxelCoords, 0); -} - void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords, uint8_t toValue) { // glm::vec3 centerVoxelCoords = worldToVoxelCoordinates(centerWorldCoords); glm::vec4 centerVoxelCoords = worldToVoxelMatrix() * glm::vec4(centerWorldCoords, 1.0f); @@ -112,37 +99,24 @@ void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float r setSphereInVolume(glm::vec3(centerVoxelCoords), radiusVoxelCoords, toValue); } -void RenderablePolyVoxEntityItem::createSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords) { - setSphere(centerWorldCoords, radiusWorldCoords, 255); -} - -void RenderablePolyVoxEntityItem::eraseSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords) { - setSphere(centerWorldCoords, radiusWorldCoords, 0); -} - void RenderablePolyVoxEntityItem::getModel() { if (!_volData) { // this will cause the allocation of _volData setVoxelVolumeSize(_voxelVolumeSize); } - glm::vec3 center = getCenter(); - createSphere(center, 4); - createSphere(center + glm::vec3(6.0f, 0.0f, 0.0f), 2); - // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. - PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor - (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - // PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + // PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor // (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); //Execute the surface extractor. surfaceExtractor.execute(); - // convert PolyVox mesh to a Sam mesh model::Mesh* mesh = new model::Mesh(); model::MeshPointer meshPtr(mesh); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 1bbdc2e20a..633d02386e 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -47,13 +47,11 @@ public: glm::mat4 voxelToWorldMatrix() const; glm::mat4 worldToVoxelMatrix() const; - void setSphere(glm::vec3 center, float radius, uint8_t toValue); - void createSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords); - void eraseSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords); + // coords are in voxel-volume space + virtual void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue); - void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue); - void createSphereInVolume(glm::vec3 center, float radius); - void eraseSphereInVolume(glm::vec3 center, float radius); + // coords are in world-space + virtual void setSphere(glm::vec3 center, float radius, uint8_t toValue); private: void compressVolumeData(); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 351bbc3643..b4f532cab9 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -17,6 +17,7 @@ #include "ModelEntityItem.h" #include "ZoneEntityItem.h" #include "EntitiesLogging.h" +#include "PolyVoxEntityItem.h" EntityScriptingInterface::EntityScriptingInterface() : @@ -380,3 +381,19 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra vec3FromScriptValue(intersection, value.intersection); } } + + +bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) const { + EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(entityID)); + if (!entity) { + return false; + } + EntityTypes::EntityType entityType = entity->getType(); + if (entityType != EntityTypes::PolyVox) { + return false; + } + + PolyVoxEntityItem* polyVoxEntity = static_cast(entity); + polyVoxEntity->setSphere(center, radius, value); + return true; +} diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index f1876a836b..b2292b75eb 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -117,6 +117,8 @@ public slots: Q_INVOKABLE void setSendPhysicsUpdates(bool value); Q_INVOKABLE bool getSendPhysicsUpdates() const; + Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) const; + Q_INVOKABLE void dumpTree() const; signals: diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 387bb86225..2039f44a34 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -70,6 +70,12 @@ class PolyVoxEntityItem : public EntityItem { static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; static const QByteArray DEFAULT_VOXEL_DATA; + // coords are in voxel-volume space + virtual void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) {} + + // coords are in world-space + virtual void setSphere(glm::vec3 center, float radius, uint8_t toValue) {} + protected: rgbColor _color; glm::vec3 _voxelVolumeSize; // this is always 3 bytes From 66760afadbf5b6d5249824320a68ee742ee5c9c3 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 14:27:22 -0700 Subject: [PATCH 31/80] quiet compiler --- libraries/model/src/model/Skybox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index a3f4220362..a34a3be3fd 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -107,7 +107,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky } else { // skybox has no cubemap, just clear the color buffer auto color = skybox.getColor(); - batch.clearFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(skybox.getColor(),1.0f), 0.f, 0); + batch.clearFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(color, 1.0f), 0.f, 0); } } From 55028f6cb0e04964daf911eea8b8130867be913f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 16:34:35 -0700 Subject: [PATCH 32/80] voxel data sent over wire and saved to json --- examples/voxels.js | 41 +++++++++++++ interface/src/Application.cpp | 2 + .../src/RenderablePolyVoxEntityItem.cpp | 61 +++++++++++++++---- .../src/RenderablePolyVoxEntityItem.h | 3 + .../entities/src/EntityItemProperties.cpp | 31 ++++++++-- libraries/entities/src/EntityItemProperties.h | 7 ++- .../entities/src/EntityItemPropertiesMacros.h | 36 +++++++++++ .../entities/src/EntityScriptingInterface.cpp | 22 ++++++- .../entities/src/EntityScriptingInterface.h | 2 +- 9 files changed, 181 insertions(+), 24 deletions(-) create mode 100644 examples/voxels.js diff --git a/examples/voxels.js b/examples/voxels.js new file mode 100644 index 0000000000..365f45ae0d --- /dev/null +++ b/examples/voxels.js @@ -0,0 +1,41 @@ + +var altHeld = false; + + +function mousePressEvent(event) { + if (!event.isLeftButton) { + return; + } + + var pickRay = Camera.computePickRay(event.x, event.y); + var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking + // var props = Entities.getEntityProperties(intersection.entityID); + if (intersection.intersects) { + var ids = Entities.findEntities(intersection.intersection, 10); + for (var i = 0; i < ids.length; i++) { + var id = ids[i]; + if (altHeld) { + Entities.setVoxelSphere(id, intersection.intersection, 2.0, 0); + } else { + Entities.setVoxelSphere(id, intersection.intersection, 2.0, 255); + } + } + } +} + + +function keyPressEvent(event) { + if (event.text == "ALT") { + altHeld = true; + } +} + + +function keyReleaseEvent(event) { + if (event.text == "ALT") { + altHeld = false; + } +} + + +Controller.mousePressEvent.connect(mousePressEvent); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 300b55917b..16fa8677f2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1948,7 +1948,9 @@ FaceTracker* Application::getSelectedFaceTracker() { } void Application::setActiveFaceTracker() { +#if defined(HAVE_FACESHIFT) || defined(HAVE_DDE) bool isMuted = Menu::getInstance()->isOptionChecked(MenuOption::MuteFaceTracking); +#endif #ifdef HAVE_FACESHIFT auto faceshiftTracker = DependencyManager::get(); faceshiftTracker->setIsMuted(isMuted); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 8a9fd27626..2b69f6e451 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -42,6 +42,13 @@ RenderablePolyVoxEntityItem::~RenderablePolyVoxEntityItem() { } void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { + + if (_volData && voxelVolumeSize == _voxelVolumeSize) { + return; + } + + qDebug() << "RESETTING VOXEL SIZE"; + PolyVoxEntityItem::setVoxelVolumeSize(voxelVolumeSize); if (_volData) { @@ -56,6 +63,13 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) _volData = new PolyVox::SimpleVolume(PolyVox::Region(lowCorner, highCorner)); } + +void RenderablePolyVoxEntityItem::setVoxelData(QByteArray voxelData) { + PolyVoxEntityItem::setVoxelData(voxelData); + decompressVolumeData(); +} + + glm::mat4 RenderablePolyVoxEntityItem::voxelToWorldMatrix() const { glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units glm::mat4 scaled = glm::scale(glm::mat4(), scale); @@ -88,6 +102,7 @@ void RenderablePolyVoxEntityItem::setSphereInVolume(glm::vec3 center, float radi } } compressVolumeData(); + _needsModelReload = true; } void RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float radiusWorldCoords, uint8_t toValue) { @@ -143,20 +158,20 @@ void RenderablePolyVoxEntityItem::getModel() { sizeof(PolyVox::PositionMaterialNormal), gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::RAW))); - auto normalAttrib = mesh->getAttributeBuffer(gpu::Stream::NORMAL); - for (auto normal = normalAttrib.begin(); normal != normalAttrib.end(); normal++) { - (*normal) = -(*normal); - } + // auto normalAttrib = mesh->getAttributeBuffer(gpu::Stream::NORMAL); + // for (auto normal = normalAttrib.begin(); normal != normalAttrib.end(); normal++) { + // (*normal) = -(*normal); + // } - qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------" << usecTimestampNow(); + // qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------" << usecTimestampNow(); qDebug() << "---- vecIndices.size() =" << vecIndices.size(); - qDebug() << "---- sizeof(vecIndices[0]) =" << sizeof(vecIndices[0]); + // qDebug() << "---- sizeof(vecIndices[0]) =" << sizeof(vecIndices[0]); qDebug() << "---- vecVertices.size() =" << vecVertices.size(); - qDebug() << "---- sizeof(vecVertices[0]) =" << sizeof(vecVertices[0]); - qDebug() << "---- sizeof(uint32_t) =" << sizeof(uint32_t); - qDebug() << "---- sizeof(float) =" << sizeof(float); - qDebug() << "---- sizeof(PolyVox::PositionMaterialNormal) =" << sizeof(PolyVox::PositionMaterialNormal); + // qDebug() << "---- sizeof(vecVertices[0]) =" << sizeof(vecVertices[0]); + // qDebug() << "---- sizeof(uint32_t) =" << sizeof(uint32_t); + // qDebug() << "---- sizeof(float) =" << sizeof(float); + // qDebug() << "---- sizeof(PolyVox::PositionMaterialNormal) =" << sizeof(PolyVox::PositionMaterialNormal); // -------------XXXXXXXXXXXXXXXXXXXX------------------- // ---- vecIndices.size() = 25524 @@ -281,7 +296,27 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { } } - QByteArray compressedData = qCompress(uncompressedData, 9); - qDebug() << "-----------------------------------------------------------------------------"; - qDebug() << "raw-size =" << rawSize << " compressed-size =" << compressedData.size(); + _voxelData = qCompress(uncompressedData, 9); + qDebug() << "-------------- compresss ------------------------------------------------------------"; + qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); +} + + +void RenderablePolyVoxEntityItem::decompressVolumeData() { + int rawSize = _volData->getDepth() * _volData->getHeight() * _volData->getWidth(); + QByteArray uncompressedData = QByteArray(rawSize, '\0'); + + uncompressedData = qUncompress(_voxelData); + + for (int z = 0; z < _volData->getDepth(); z++) { + for (int y = 0; y < _volData->getHeight(); y++) { + for (int x = 0; x < _volData->getWidth(); x++) { + int uncompressedIndex = z * _volData->getHeight() * _volData->getWidth() + y * _volData->getWidth() + x; + _volData->setVoxelAt(x, y, z, uncompressedData[uncompressedIndex]); + } + } + } + + qDebug() << "--------------- decompress -----------------------------------------------------------"; + qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 633d02386e..981d59c506 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -43,6 +43,8 @@ public: void getModel(); + virtual void setVoxelData(QByteArray voxelData); + virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize); glm::mat4 voxelToWorldMatrix() const; glm::mat4 worldToVoxelMatrix() const; @@ -55,6 +57,7 @@ public: private: void compressVolumeData(); + void decompressVolumeData(); PolyVox::SimpleVolume* _volData = nullptr; model::Geometry _modelGeometry; diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 59944b92fc..fed8242e07 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -88,11 +88,11 @@ CONSTRUCT_PROPERTY(keyLightColor, ZoneEntityItem::DEFAULT_KEYLIGHT_COLOR), CONSTRUCT_PROPERTY(keyLightIntensity, ZoneEntityItem::DEFAULT_KEYLIGHT_INTENSITY), CONSTRUCT_PROPERTY(keyLightAmbientIntensity, ZoneEntityItem::DEFAULT_KEYLIGHT_AMBIENT_INTENSITY), CONSTRUCT_PROPERTY(keyLightDirection, ZoneEntityItem::DEFAULT_KEYLIGHT_DIRECTION), +CONSTRUCT_PROPERTY(voxelVolumeSize, PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE), +CONSTRUCT_PROPERTY(voxelData, PolyVoxEntityItem::DEFAULT_VOXEL_DATA), CONSTRUCT_PROPERTY(name, ENTITY_ITEM_DEFAULT_NAME), CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(sourceUrl, ""), -CONSTRUCT_PROPERTY(voxelVolumeSize, PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE), -CONSTRUCT_PROPERTY(voxelData, PolyVoxEntityItem::DEFAULT_VOXEL_DATA), _id(UNKNOWN_ENTITY_ID), @@ -340,6 +340,8 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_KEYLIGHT_DIRECTION, keyLightDirection); CHECK_PROPERTY_CHANGE(PROP_BACKGROUND_MODE, backgroundMode); CHECK_PROPERTY_CHANGE(PROP_SOURCE_URL, sourceUrl); + CHECK_PROPERTY_CHANGE(PROP_VOXEL_VOLUME_SIZE, voxelVolumeSize); + CHECK_PROPERTY_CHANGE(PROP_VOXEL_DATA, voxelData); changedProperties += _stage.getChangedProperties(); changedProperties += _atmosphere.getChangedProperties(); @@ -422,6 +424,9 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(keyLightDirection); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(backgroundMode, getBackgroundModeAsString()); COPY_PROPERTY_TO_QSCRIPTVALUE(sourceUrl); + + COPY_PROPERTY_TO_QSCRIPTVALUE(voxelVolumeSize); + COPY_PROPERTY_TO_QSCRIPTVALUE(voxelData); // Sitting properties support if (!skipDefaults) { @@ -527,7 +532,10 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE(keyLightDirection, glmVec3, setKeyLightDirection); COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(backgroundMode, BackgroundMode); COPY_PROPERTY_FROM_QSCRIPTVALUE(sourceUrl, QString, setSourceUrl); - + + COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelVolumeSize, glmVec3, setVoxelVolumeSize); + COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelData, QByteArray, setVoxelData); + _stage.copyFromScriptValue(object, _defaultSettings); _atmosphere.copyFromScriptValue(object, _defaultSettings); _skybox.copyFromScriptValue(object, _defaultSettings); @@ -744,6 +752,12 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem _staticSkybox.setProperties(properties); _staticSkybox.appentToEditPacket(packetData, requestedProperties, propertyFlags, propertiesDidntFit, propertyCount, appendState ); } + + if (properties.getType() == EntityTypes::PolyVox) { + APPEND_ENTITY_PROPERTY(PROP_COLOR, properties.getColor()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, properties.getVoxelVolumeSize()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, properties.getVoxelData()); + } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); APPEND_ENTITY_PROPERTY(PROP_NAME, properties.getName()); @@ -978,11 +992,17 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int properties.getAtmosphere().decodeFromEditPacket(propertyFlags, dataAt , processedBytes); properties.getSkybox().decodeFromEditPacket(propertyFlags, dataAt , processedBytes); } + + if (properties.getType() == EntityTypes::PolyVox) { + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR, xColor, setColor); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_DATA, QByteArray, setVoxelData); + } READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MARKETPLACE_ID, QString, setMarketplaceID); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_NAME, QString, setName); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLLISION_SOUND_URL, QString, setCollisionSoundURL); - + return valid; } @@ -1083,6 +1103,9 @@ void EntityItemProperties::markAllChanged() { _skybox.markAllChanged(); _sourceUrlChanged = true; + + _voxelVolumeSizeChanged = true; + _voxelDataChanged = true; } /// The maximum bounding cube for the entity, independent of it's rotation. diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 72b4e4ad0b..5acf3a71e1 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -136,14 +136,14 @@ public: DEFINE_PROPERTY(PROP_KEYLIGHT_INTENSITY, KeyLightIntensity, keyLightIntensity, float); DEFINE_PROPERTY(PROP_KEYLIGHT_AMBIENT_INTENSITY, KeyLightAmbientIntensity, keyLightAmbientIntensity, float); DEFINE_PROPERTY_REF(PROP_KEYLIGHT_DIRECTION, KeyLightDirection, keyLightDirection, glm::vec3); + DEFINE_PROPERTY_REF(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3); + DEFINE_PROPERTY_REF(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray); DEFINE_PROPERTY_REF(PROP_NAME, Name, name, QString); DEFINE_PROPERTY_REF_ENUM(PROP_BACKGROUND_MODE, BackgroundMode, backgroundMode, BackgroundMode); DEFINE_PROPERTY_GROUP(Stage, stage, StagePropertyGroup); DEFINE_PROPERTY_GROUP(Atmosphere, atmosphere, AtmospherePropertyGroup); DEFINE_PROPERTY_GROUP(Skybox, skybox, SkyboxPropertyGroup); DEFINE_PROPERTY_REF(PROP_SOURCE_URL, SourceUrl, sourceUrl, QString); - DEFINE_PROPERTY_REF(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3); - DEFINE_PROPERTY_REF(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray); static QString getBackgroundModeString(BackgroundMode mode); @@ -192,6 +192,8 @@ public: QString getSimulatorIDAsString() const { return _simulatorID.toString().mid(1,36).toUpper(); } + void setVoxelDataDirty() { _voxelDataChanged = true; } + private: QUuid _id; bool _idSet; @@ -222,7 +224,6 @@ void EntityItemPropertiesFromScriptValue(const QScriptValue &object, EntityItemP inline void EntityItemProperties::setPosition(const glm::vec3& value) { _position = glm::clamp(value, 0.0f, (float)TREE_SCALE); _positionChanged = true; } - inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { debug << "EntityItemProperties[" << "\n"; diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index 8c4f329cc9..ee9fa69fa3 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -91,10 +91,26 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, float v) { return QScri inline QScriptValue convertScriptValue(QScriptEngine* e, int v) { return QScriptValue(v); } inline QScriptValue convertScriptValue(QScriptEngine* e, quint32 v) { return QScriptValue(v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const QString& v) { return QScriptValue(v); } + inline QScriptValue convertScriptValue(QScriptEngine* e, const xColor& v) { return xColorToScriptValue(e, v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const glm::quat& v) { return quatToScriptValue(e, v); } inline QScriptValue convertScriptValue(QScriptEngine* e, const QScriptValue& v) { return v; } +inline QScriptValue convertScriptValue(QScriptEngine* e, const QByteArray& v) { + // return QScriptValue(QLatin1String(v.data())); + + // QScriptValue array = e->newArray(v.size()); + // for (int i = 0; i < v.size(); ++i) { + // array.setProperty(i, QScriptValue(e, (unsigned int) v[i])); + // } + // return array; + + QByteArray b64 = v.toBase64(); + return QScriptValue(QString(b64)); +} + + + #define COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(G,g,P,p) \ if (!skipDefaults || defaultEntityProperties.get##G().get##P() != get##P()) { \ QScriptValue groupProperties = properties.property(#g); \ @@ -129,6 +145,26 @@ inline int int_convertFromScriptValue(const QScriptValue& v, bool& isValid) { re inline bool bool_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toBool(); } inline QString QString_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toString().trimmed(); } inline QUuid QUuid_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; return v.toVariant().toUuid(); } + + +inline QByteArray QByteArray_convertFromScriptValue(const QScriptValue& v, bool& isValid) { + isValid = true; + // return v.toVariant().toByteArray(); + + // QByteArray byteArray; + // uint len = v.property("length").toUInt32(); + // byteArray.resize(len); + // for (uint i = 0; i < len; ++i) + // byteArray[i] = v.property(i).toUInt32(); + // return byteArray; + + QString b64 = v.toVariant().toString().trimmed(); + + return QByteArray::fromBase64(b64.toUtf8()); +} + + + inline glmVec3 glmVec3_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = false; /// assume it can't be converted QScriptValue x = v.property("x"); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index b4f532cab9..1d77626163 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -383,17 +383,33 @@ void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, Ra } -bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) const { - EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(entityID)); - if (!entity) { +bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) { + if (!_entityTree) { return false; } + + EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(entityID)); + if (!entity) { + qCDebug(entities) << "EntityScriptingInterface::setVoxelSphere no entity with ID" << entityID; + return false; + } + EntityTypes::EntityType entityType = entity->getType(); if (entityType != EntityTypes::PolyVox) { return false; } PolyVoxEntityItem* polyVoxEntity = static_cast(entity); + _entityTree->lockForWrite(); polyVoxEntity->setSphere(center, radius, value); + _entityTree->unlock(); + + _entityTree->lockForRead(); + EntityItemProperties properties = entity->getProperties(); + _entityTree->unlock(); + + properties.setVoxelDataDirty(); + queueEntityMessage(PacketTypeEntityEdit, entityID, properties); + return true; } diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index b2292b75eb..e53a8c4677 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -117,7 +117,7 @@ public slots: Q_INVOKABLE void setSendPhysicsUpdates(bool value); Q_INVOKABLE bool getSendPhysicsUpdates() const; - Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value) const; + Q_INVOKABLE bool setVoxelSphere(QUuid entityID, const glm::vec3& center, float radius, int value); Q_INVOKABLE void dumpTree() const; From 0ecd60a48994440d7e7a4cb439530b403fe86998 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 16:45:29 -0700 Subject: [PATCH 33/80] update voxel mesh when new data arrives from the wire --- .../entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 2b69f6e451..4090de45e4 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -65,6 +65,9 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) void RenderablePolyVoxEntityItem::setVoxelData(QByteArray voxelData) { + if (voxelData == _voxelData) { + return; + } PolyVoxEntityItem::setVoxelData(voxelData); decompressVolumeData(); } @@ -317,6 +320,8 @@ void RenderablePolyVoxEntityItem::decompressVolumeData() { } } + _needsModelReload = true; + qDebug() << "--------------- decompress -----------------------------------------------------------"; qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); } From 517d4372fab21220d6c4c036d3d8e9b514a9b6fd Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 16:53:11 -0700 Subject: [PATCH 34/80] debugging --- .../entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 1 + libraries/entities/src/PolyVoxEntityItem.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 4090de45e4..cd7098b0c2 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -65,6 +65,7 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) void RenderablePolyVoxEntityItem::setVoxelData(QByteArray voxelData) { + qDebug() << "%%%%%%%%%%% RenderablePolyVoxEntityItem::setVoxelData" << voxelData.size() << _voxelData.size(); if (voxelData == _voxelData) { return; } diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 2039f44a34..fdab472e1b 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -64,7 +64,10 @@ class PolyVoxEntityItem : public EntityItem { virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { _voxelVolumeSize = voxelVolumeSize; } virtual const glm::vec3& getVoxelVolumeSize() const { return _voxelVolumeSize; } - virtual void setVoxelData(QByteArray voxelData) { _voxelData = voxelData; } + virtual void setVoxelData(QByteArray voxelData) { + qDebug() << "%%%%%%%%%%% PolyVoxEntityItem::setVoxelData" << voxelData.size() << _voxelData.size(); + _voxelData = voxelData; + } virtual const QByteArray& getVoxelData() const { return _voxelData; } static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; From cd2b6473ba07b36bc4936b4dcc748be1eb903567 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 18:21:45 -0700 Subject: [PATCH 35/80] debugging --- libraries/entities/src/EntityScriptingInterface.cpp | 6 +++++- libraries/entities/src/PolyVoxEntityItem.cpp | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 1d77626163..6541c66865 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -409,7 +409,11 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c _entityTree->unlock(); properties.setVoxelDataDirty(); - queueEntityMessage(PacketTypeEntityEdit, entityID, properties); + entity->setLastBroadcast(usecTimestampNow()); + // modifiedProperties.setType(entity->getType()); + // bidForSimulationOwnership(modifiedProperties); + + queueEntityMessage(PacketTypeEntityEdit, entityID, properties); return true; } diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index 71f1c2fb65..b61ce79236 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -82,6 +82,8 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat int bytesRead = 0; const unsigned char* dataAt = data; + qDebug() << "PolyVoxEntityItem::readEntitySubclassDataFromBuffer"; + READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); READ_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); READ_ENTITY_PROPERTY(PROP_VOXEL_DATA, QByteArray, setVoxelData); From ebae87136fbd8847a9d4abf4997f41c11153c787 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 20:57:58 -0700 Subject: [PATCH 36/80] debugging --- libraries/entities/src/EntityItem.cpp | 13 ++++++-- .../entities/src/EntityItemProperties.cpp | 2 +- .../entities/src/EntityScriptingInterface.cpp | 1 + libraries/entities/src/PolyVoxEntityItem.cpp | 30 ++++++++++++------- libraries/octree/src/OctreePacketData.cpp | 1 + 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 8cc373e5cc..94ad553c70 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -432,6 +432,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // If this is from the same sever packet, then check against any local changes since we got // the most recent packet from this server time if (_lastEdited > _lastEditedFromRemote) { + qDebug() << "_lastEdited > _lastEditedFromRemote"; ignoreServerPacket = true; } } else { @@ -439,6 +440,14 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // If we've changed our local tree more recently than the new data from this packet // then we will not be changing our values, instead we just read and skip the data if (_lastEdited > lastEditedFromBufferAdjusted) { + qDebug() << "_lastEdited > lastEditedFromBufferAdjusted"; + qDebug() << "_lastEdited =" << _lastEdited; + qDebug() << "lastEditedFromBuffer - clockSkew =" << lastEditedFromBuffer - clockSkew; + qDebug() << "lastEditedFromBufferAdjusted =" << lastEditedFromBufferAdjusted; + qDebug() << "lastEditedFromBuffer =" << lastEditedFromBuffer; + qDebug() << "clockSkew =" << clockSkew; + qDebug() << "now = " << now; + ignoreServerPacket = true; } } @@ -660,12 +669,12 @@ void EntityItem::adjustEditPacketForClockSkew(unsigned char* editPacketBuffer, s memcpy(&lastEditedInLocalTime, dataAt, sizeof(lastEditedInLocalTime)); quint64 lastEditedInServerTime = lastEditedInLocalTime + clockSkew; memcpy(dataAt, &lastEditedInServerTime, sizeof(lastEditedInServerTime)); - #ifdef WANT_DEBUG + //#ifdef WANT_DEBUG qCDebug(entities, "EntityItem::adjustEditPacketForClockSkew()..."); qCDebug(entities) << " lastEditedInLocalTime: " << lastEditedInLocalTime; qCDebug(entities) << " clockSkew: " << clockSkew; qCDebug(entities) << " lastEditedInServerTime: " << lastEditedInServerTime; - #endif + //#endif } float EntityItem::computeMass() const { diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index fed8242e07..a9747ffe3a 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -539,7 +539,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { _stage.copyFromScriptValue(object, _defaultSettings); _atmosphere.copyFromScriptValue(object, _defaultSettings); _skybox.copyFromScriptValue(object, _defaultSettings); - _lastEdited = usecTimestampNow(); + _lastEdited = usecTimestampNow(); // ??? } QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties) { diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 6541c66865..0abc01fbd9 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -402,6 +402,7 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c PolyVoxEntityItem* polyVoxEntity = static_cast(entity); _entityTree->lockForWrite(); polyVoxEntity->setSphere(center, radius, value); + // entity->setLastEdited(usecTimestampNow()); _entityTree->unlock(); _entityTree->lockForRead(); diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index b61ce79236..bf99ecd408 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -62,8 +62,11 @@ bool PolyVoxEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelVolumeSize, setVoxelVolumeSize); SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelData, setVoxelData); + qDebug() << "PolyVoxEntityItem::setProperties somethingChanged =" << somethingChanged + << "prop has voxel-data =" << properties.getChangedProperties().getHasProperty(PROP_VOXEL_DATA); + if (somethingChanged) { - bool wantDebug = false; + bool wantDebug = true; if (wantDebug) { uint64_t now = usecTimestampNow(); int elapsed = now - getLastEdited(); @@ -76,18 +79,23 @@ bool PolyVoxEntityItem::setProperties(const EntityItemProperties& properties) { } int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, - ReadBitstreamToTreeParams& args, - EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { + ReadBitstreamToTreeParams& args, + EntityPropertyFlags& propertyFlags, bool overwriteLocalData) { int bytesRead = 0; const unsigned char* dataAt = data; - qDebug() << "PolyVoxEntityItem::readEntitySubclassDataFromBuffer"; + qDebug() << "PolyVoxEntityItem::readEntitySubclassDataFromBuffer" + << "propertyFlags.getHasProperty(PROP_VOXEL_DATA) =" << propertyFlags.getHasProperty(PROP_VOXEL_DATA) + << "overwriteLocalData =" << overwriteLocalData; + READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); READ_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); READ_ENTITY_PROPERTY(PROP_VOXEL_DATA, QByteArray, setVoxelData); + + return bytesRead; } @@ -102,18 +110,20 @@ EntityPropertyFlags PolyVoxEntityItem::getEntityProperties(EncodeBitstreamParams } void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params, - EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, - EntityPropertyFlags& requestedProperties, - EntityPropertyFlags& propertyFlags, - EntityPropertyFlags& propertiesDidntFit, - int& propertyCount, - OctreeElement::AppendState& appendState) const { + EntityTreeElementExtraEncodeData* modelTreeElementExtraEncodeData, + EntityPropertyFlags& requestedProperties, + EntityPropertyFlags& propertyFlags, + EntityPropertyFlags& propertiesDidntFit, + int& propertyCount, + OctreeElement::AppendState& appendState) const { bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, getVoxelVolumeSize()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, getVoxelData()); + + qDebug() << "PolyVoxEntityItem::appendSubclassData successPropertyFits =" << successPropertyFits; } void PolyVoxEntityItem::debugDump() const { diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index ed30c619ca..416cdffe32 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -591,5 +591,6 @@ int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, QByteA dataBytes += sizeof(length); QByteArray value((const char*)dataBytes, length); result = value; + qDebug() << "OctreePacketData::uppackDataFromBytes uppacked " << length; return sizeof(length) + length; } From 5acc018bdaba0609a6d5663ad60219adf8e063c7 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 20:58:23 -0700 Subject: [PATCH 37/80] debugging --- libraries/entities/src/EntityItem.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 94ad553c70..4f7db64a95 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -667,6 +667,7 @@ void EntityItem::adjustEditPacketForClockSkew(unsigned char* editPacketBuffer, s // lastEdited quint64 lastEditedInLocalTime; memcpy(&lastEditedInLocalTime, dataAt, sizeof(lastEditedInLocalTime)); + assert(lastEditedInLocalTime > 0); quint64 lastEditedInServerTime = lastEditedInLocalTime + clockSkew; memcpy(dataAt, &lastEditedInServerTime, sizeof(lastEditedInServerTime)); //#ifdef WANT_DEBUG From 6b5020285b7faacf0f6b36d6ec4ca3f42ef71879 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 21:32:33 -0700 Subject: [PATCH 38/80] set last-edited in properties when changing voxel data --- libraries/entities/src/EntityEditPacketSender.cpp | 4 ++-- libraries/entities/src/EntityScriptingInterface.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index 8d03ca0fcb..2704717e5c 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -37,11 +37,11 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI int sizeOut = 0; if (EntityItemProperties::encodeEntityEditPacket(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) { - #ifdef WANT_DEBUG + //#ifdef WANT_DEBUG qCDebug(entities) << "calling queueOctreeEditMessage()..."; qCDebug(entities) << " id:" << modelID; qCDebug(entities) << " properties:" << properties; - #endif + //#endif queueOctreeEditMessage(type, bufferOut, sizeOut); } } diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 0abc01fbd9..c06bcf1448 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -399,10 +399,13 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c return false; } + auto now = usecTimestampNow(); + PolyVoxEntityItem* polyVoxEntity = static_cast(entity); _entityTree->lockForWrite(); polyVoxEntity->setSphere(center, radius, value); - // entity->setLastEdited(usecTimestampNow()); + entity->setLastEdited(now); + entity->setLastBroadcast(now); _entityTree->unlock(); _entityTree->lockForRead(); @@ -410,10 +413,7 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c _entityTree->unlock(); properties.setVoxelDataDirty(); - - entity->setLastBroadcast(usecTimestampNow()); - // modifiedProperties.setType(entity->getType()); - // bidForSimulationOwnership(modifiedProperties); + properties.setLastEdited(now); queueEntityMessage(PacketTypeEntityEdit, entityID, properties); return true; From 6930008f745acbfae314d89d50ca016ec423375c Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 26 May 2015 21:40:50 -0700 Subject: [PATCH 39/80] remove debugging spew --- .../src/RenderablePolyVoxEntityItem.cpp | 23 +++---------------- .../entities/src/EntityEditPacketSender.cpp | 4 ++-- libraries/entities/src/EntityItem.cpp | 9 -------- libraries/entities/src/PolyVoxEntityItem.cpp | 15 +----------- libraries/entities/src/PolyVoxEntityItem.h | 5 +--- libraries/octree/src/OctreePacketData.cpp | 1 - 6 files changed, 7 insertions(+), 50 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index cd7098b0c2..725b093e81 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -47,7 +47,7 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) return; } - qDebug() << "RESETTING VOXEL SIZE"; + qDebug() << "resetting voxel-space size"; PolyVoxEntityItem::setVoxelVolumeSize(voxelVolumeSize); @@ -65,7 +65,6 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) void RenderablePolyVoxEntityItem::setVoxelData(QByteArray voxelData) { - qDebug() << "%%%%%%%%%%% RenderablePolyVoxEntityItem::setVoxelData" << voxelData.size() << _voxelData.size(); if (voxelData == _voxelData) { return; } @@ -167,24 +166,8 @@ void RenderablePolyVoxEntityItem::getModel() { // (*normal) = -(*normal); // } - - // qDebug() << "-------------XXXXXXXXXXXXXXXXXXXX-------------------" << usecTimestampNow(); qDebug() << "---- vecIndices.size() =" << vecIndices.size(); - // qDebug() << "---- sizeof(vecIndices[0]) =" << sizeof(vecIndices[0]); qDebug() << "---- vecVertices.size() =" << vecVertices.size(); - // qDebug() << "---- sizeof(vecVertices[0]) =" << sizeof(vecVertices[0]); - // qDebug() << "---- sizeof(uint32_t) =" << sizeof(uint32_t); - // qDebug() << "---- sizeof(float) =" << sizeof(float); - // qDebug() << "---- sizeof(PolyVox::PositionMaterialNormal) =" << sizeof(PolyVox::PositionMaterialNormal); - - // -------------XXXXXXXXXXXXXXXXXXXX------------------- - // ---- vecIndices.size() = 25524 - // ---- sizeof(vecIndices[0]) = 4 - // ---- vecVertices.size() = 17016 - // ---- sizeof(vecVertices[0]) = 28 - // ---- sizeof(uint32_t) = 4 - // ---- sizeof(float) = 4 - // ---- sizeof(PolyVox::PositionMaterialNormal) = 28 _modelGeometry.setMesh(meshPtr); _needsModelReload = false; @@ -301,7 +284,7 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { } _voxelData = qCompress(uncompressedData, 9); - qDebug() << "-------------- compresss ------------------------------------------------------------"; + qDebug() << "-------------- voxel compresss ------------------------------------------------------------"; qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); } @@ -323,6 +306,6 @@ void RenderablePolyVoxEntityItem::decompressVolumeData() { _needsModelReload = true; - qDebug() << "--------------- decompress -----------------------------------------------------------"; + qDebug() << "--------------- voxel decompress -----------------------------------------------------------"; qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); } diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index 2704717e5c..8d03ca0fcb 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -37,11 +37,11 @@ void EntityEditPacketSender::queueEditEntityMessage(PacketType type, EntityItemI int sizeOut = 0; if (EntityItemProperties::encodeEntityEditPacket(type, modelID, properties, &bufferOut[0], _maxPacketSize, sizeOut)) { - //#ifdef WANT_DEBUG + #ifdef WANT_DEBUG qCDebug(entities) << "calling queueOctreeEditMessage()..."; qCDebug(entities) << " id:" << modelID; qCDebug(entities) << " properties:" << properties; - //#endif + #endif queueOctreeEditMessage(type, bufferOut, sizeOut); } } diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 4f7db64a95..38bc744e63 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -432,7 +432,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // If this is from the same sever packet, then check against any local changes since we got // the most recent packet from this server time if (_lastEdited > _lastEditedFromRemote) { - qDebug() << "_lastEdited > _lastEditedFromRemote"; ignoreServerPacket = true; } } else { @@ -440,14 +439,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // If we've changed our local tree more recently than the new data from this packet // then we will not be changing our values, instead we just read and skip the data if (_lastEdited > lastEditedFromBufferAdjusted) { - qDebug() << "_lastEdited > lastEditedFromBufferAdjusted"; - qDebug() << "_lastEdited =" << _lastEdited; - qDebug() << "lastEditedFromBuffer - clockSkew =" << lastEditedFromBuffer - clockSkew; - qDebug() << "lastEditedFromBufferAdjusted =" << lastEditedFromBufferAdjusted; - qDebug() << "lastEditedFromBuffer =" << lastEditedFromBuffer; - qDebug() << "clockSkew =" << clockSkew; - qDebug() << "now = " << now; - ignoreServerPacket = true; } } diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index bf99ecd408..19d741a83b 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -62,11 +62,8 @@ bool PolyVoxEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelVolumeSize, setVoxelVolumeSize); SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelData, setVoxelData); - qDebug() << "PolyVoxEntityItem::setProperties somethingChanged =" << somethingChanged - << "prop has voxel-data =" << properties.getChangedProperties().getHasProperty(PROP_VOXEL_DATA); - if (somethingChanged) { - bool wantDebug = true; + bool wantDebug = false; if (wantDebug) { uint64_t now = usecTimestampNow(); int elapsed = now - getLastEdited(); @@ -85,17 +82,10 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat int bytesRead = 0; const unsigned char* dataAt = data; - qDebug() << "PolyVoxEntityItem::readEntitySubclassDataFromBuffer" - << "propertyFlags.getHasProperty(PROP_VOXEL_DATA) =" << propertyFlags.getHasProperty(PROP_VOXEL_DATA) - << "overwriteLocalData =" << overwriteLocalData; - - READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); READ_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); READ_ENTITY_PROPERTY(PROP_VOXEL_DATA, QByteArray, setVoxelData); - - return bytesRead; } @@ -116,14 +106,11 @@ void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeB EntityPropertyFlags& propertiesDidntFit, int& propertyCount, OctreeElement::AppendState& appendState) const { - bool successPropertyFits = true; APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, getVoxelVolumeSize()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, getVoxelData()); - - qDebug() << "PolyVoxEntityItem::appendSubclassData successPropertyFits =" << successPropertyFits; } void PolyVoxEntityItem::debugDump() const { diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index fdab472e1b..2039f44a34 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -64,10 +64,7 @@ class PolyVoxEntityItem : public EntityItem { virtual void setVoxelVolumeSize(glm::vec3 voxelVolumeSize) { _voxelVolumeSize = voxelVolumeSize; } virtual const glm::vec3& getVoxelVolumeSize() const { return _voxelVolumeSize; } - virtual void setVoxelData(QByteArray voxelData) { - qDebug() << "%%%%%%%%%%% PolyVoxEntityItem::setVoxelData" << voxelData.size() << _voxelData.size(); - _voxelData = voxelData; - } + virtual void setVoxelData(QByteArray voxelData) { _voxelData = voxelData; } virtual const QByteArray& getVoxelData() const { return _voxelData; } static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index 416cdffe32..ed30c619ca 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -591,6 +591,5 @@ int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, QByteA dataBytes += sizeof(length); QByteArray value((const char*)dataBytes, length); result = value; - qDebug() << "OctreePacketData::uppackDataFromBytes uppacked " << length; return sizeof(length) + length; } From 0f81445cee94d3365abed748a997f75c186eca6d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 07:04:44 -0700 Subject: [PATCH 40/80] flag for polyvox to select minecraft vs walking-cubes. uppack to unpack --- examples/voxels.js | 16 +++++----- .../src/RenderablePolyVoxEntityItem.cpp | 17 ++++++----- .../entities/src/EntityItemProperties.cpp | 7 +++++ libraries/entities/src/EntityItemProperties.h | 2 ++ .../entities/src/EntityItemPropertiesMacros.h | 4 +-- libraries/entities/src/EntityPropertyFlags.h | 1 + libraries/entities/src/PolyVoxEntityItem.cpp | 9 +++++- libraries/entities/src/PolyVoxEntityItem.h | 5 ++++ libraries/octree/src/OctreePacketData.cpp | 8 ++--- libraries/octree/src/OctreePacketData.h | 30 +++++++++---------- 10 files changed, 61 insertions(+), 38 deletions(-) diff --git a/examples/voxels.js b/examples/voxels.js index 365f45ae0d..632ed77e15 100644 --- a/examples/voxels.js +++ b/examples/voxels.js @@ -1,5 +1,5 @@ -var altHeld = false; +var controlHeld = false; function mousePressEvent(event) { @@ -14,10 +14,10 @@ function mousePressEvent(event) { var ids = Entities.findEntities(intersection.intersection, 10); for (var i = 0; i < ids.length; i++) { var id = ids[i]; - if (altHeld) { - Entities.setVoxelSphere(id, intersection.intersection, 2.0, 0); + if (controlHeld) { + Entities.setVoxelSphere(id, intersection.intersection, 1.2, 0); } else { - Entities.setVoxelSphere(id, intersection.intersection, 2.0, 255); + Entities.setVoxelSphere(id, intersection.intersection, 1.2, 255); } } } @@ -25,15 +25,15 @@ function mousePressEvent(event) { function keyPressEvent(event) { - if (event.text == "ALT") { - altHeld = true; + if (event.text == "CONTROL") { + controlHeld = true; } } function keyReleaseEvent(event) { - if (event.text == "ALT") { - altHeld = false; + if (event.text == "CONTROL") { + controlHeld = false; } } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 725b093e81..e8684a88dc 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -126,14 +126,15 @@ void RenderablePolyVoxEntityItem::getModel() { // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; - //Create a surface extractor. Comment out one of the following two lines to decide which type gets created. - // PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor - // (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor - (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - - //Execute the surface extractor. - surfaceExtractor.execute(); + if (_voxelSurfaceStyle == 0) { + PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + surfaceExtractor.execute(); + } else { + PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + surfaceExtractor.execute(); + } // convert PolyVox mesh to a Sam mesh model::Mesh* mesh = new model::Mesh(); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index a9747ffe3a..7bda9d3ef5 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -90,6 +90,7 @@ CONSTRUCT_PROPERTY(keyLightAmbientIntensity, ZoneEntityItem::DEFAULT_KEYLIGHT_AM CONSTRUCT_PROPERTY(keyLightDirection, ZoneEntityItem::DEFAULT_KEYLIGHT_DIRECTION), CONSTRUCT_PROPERTY(voxelVolumeSize, PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE), CONSTRUCT_PROPERTY(voxelData, PolyVoxEntityItem::DEFAULT_VOXEL_DATA), +CONSTRUCT_PROPERTY(voxelSurfaceStyle, PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE), CONSTRUCT_PROPERTY(name, ENTITY_ITEM_DEFAULT_NAME), CONSTRUCT_PROPERTY(backgroundMode, BACKGROUND_MODE_INHERIT), CONSTRUCT_PROPERTY(sourceUrl, ""), @@ -342,6 +343,7 @@ EntityPropertyFlags EntityItemProperties::getChangedProperties() const { CHECK_PROPERTY_CHANGE(PROP_SOURCE_URL, sourceUrl); CHECK_PROPERTY_CHANGE(PROP_VOXEL_VOLUME_SIZE, voxelVolumeSize); CHECK_PROPERTY_CHANGE(PROP_VOXEL_DATA, voxelData); + CHECK_PROPERTY_CHANGE(PROP_VOXEL_SURFACE_STYLE, voxelSurfaceStyle); changedProperties += _stage.getChangedProperties(); changedProperties += _atmosphere.getChangedProperties(); @@ -427,6 +429,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool COPY_PROPERTY_TO_QSCRIPTVALUE(voxelVolumeSize); COPY_PROPERTY_TO_QSCRIPTVALUE(voxelData); + COPY_PROPERTY_TO_QSCRIPTVALUE(voxelSurfaceStyle); // Sitting properties support if (!skipDefaults) { @@ -535,6 +538,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelVolumeSize, glmVec3, setVoxelVolumeSize); COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelData, QByteArray, setVoxelData); + COPY_PROPERTY_FROM_QSCRIPTVALUE(voxelSurfaceStyle, uint16_t, setVoxelSurfaceStyle); _stage.copyFromScriptValue(object, _defaultSettings); _atmosphere.copyFromScriptValue(object, _defaultSettings); @@ -757,6 +761,7 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem APPEND_ENTITY_PROPERTY(PROP_COLOR, properties.getColor()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, properties.getVoxelVolumeSize()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, properties.getVoxelData()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, properties.getVoxelSurfaceStyle()); } APPEND_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, properties.getMarketplaceID()); @@ -997,6 +1002,7 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR, xColor, setColor); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_DATA, QByteArray, setVoxelData); + READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_SURFACE_STYLE, uint16_t, setVoxelSurfaceStyle); } READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_MARKETPLACE_ID, QString, setMarketplaceID); @@ -1106,6 +1112,7 @@ void EntityItemProperties::markAllChanged() { _voxelVolumeSizeChanged = true; _voxelDataChanged = true; + _voxelSurfaceStyleChanged = true; } /// The maximum bounding cube for the entity, independent of it's rotation. diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 5acf3a71e1..26c26bd474 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -138,6 +138,7 @@ public: DEFINE_PROPERTY_REF(PROP_KEYLIGHT_DIRECTION, KeyLightDirection, keyLightDirection, glm::vec3); DEFINE_PROPERTY_REF(PROP_VOXEL_VOLUME_SIZE, VoxelVolumeSize, voxelVolumeSize, glm::vec3); DEFINE_PROPERTY_REF(PROP_VOXEL_DATA, VoxelData, voxelData, QByteArray); + DEFINE_PROPERTY_REF(PROP_VOXEL_SURFACE_STYLE, VoxelSurfaceStyle, voxelSurfaceStyle, uint16_t); DEFINE_PROPERTY_REF(PROP_NAME, Name, name, QString); DEFINE_PROPERTY_REF_ENUM(PROP_BACKGROUND_MODE, BackgroundMode, backgroundMode, BackgroundMode); DEFINE_PROPERTY_GROUP(Stage, stage, StagePropertyGroup); @@ -287,6 +288,7 @@ inline QDebug operator<<(QDebug debug, const EntityItemProperties& properties) { DEBUG_PROPERTY_IF_CHANGED(debug, properties, BackgroundMode, backgroundMode, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelVolumeSize, voxelVolumeSize, ""); DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelData, voxelData, ""); + DEBUG_PROPERTY_IF_CHANGED(debug, properties, VoxelSurfaceStyle, voxelSurfaceStyle, ""); properties.getStage().debugDump(); properties.getAtmosphere().debugDump(); diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index ee9fa69fa3..0fab1d7d06 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -32,7 +32,7 @@ #define READ_ENTITY_PROPERTY(P,T,S) \ if (propertyFlags.getHasProperty(P)) { \ T fromBuffer; \ - int bytes = OctreePacketData::uppackDataFromBytes(dataAt, fromBuffer); \ + int bytes = OctreePacketData::unpackDataFromBytes(dataAt, fromBuffer); \ dataAt += bytes; \ bytesRead += bytes; \ if (overwriteLocalData) { \ @@ -49,7 +49,7 @@ #define READ_ENTITY_PROPERTY_TO_PROPERTIES(P,T,O) \ if (propertyFlags.getHasProperty(P)) { \ T fromBuffer; \ - int bytes = OctreePacketData::uppackDataFromBytes(dataAt, fromBuffer); \ + int bytes = OctreePacketData::unpackDataFromBytes(dataAt, fromBuffer); \ dataAt += bytes; \ processedBytes += bytes; \ properties.O(fromBuffer); \ diff --git a/libraries/entities/src/EntityPropertyFlags.h b/libraries/entities/src/EntityPropertyFlags.h index eb5cb1a0ae..bcb1ec0886 100644 --- a/libraries/entities/src/EntityPropertyFlags.h +++ b/libraries/entities/src/EntityPropertyFlags.h @@ -112,6 +112,7 @@ enum EntityPropertyList { PROP_VOXEL_VOLUME_SIZE, PROP_VOXEL_DATA, + PROP_VOXEL_SURFACE_STYLE, //////////////////////////////////////////////////////////////////////////////////////////////////// // ATTENTION: add new properties ABOVE this line diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index 19d741a83b..74569de9e1 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -23,6 +23,7 @@ const glm::vec3 PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE = glm::vec3(32, 32, 32); const QByteArray PolyVoxEntityItem::DEFAULT_VOXEL_DATA(qCompress(QByteArray(0), 9)); +const int PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE = 0; EntityItem* PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItem* result = new PolyVoxEntityItem(entityID, properties); @@ -32,7 +33,8 @@ EntityItem* PolyVoxEntityItem::factory(const EntityItemID& entityID, const Entit PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : EntityItem(entityItemID), _voxelVolumeSize(PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE), - _voxelData(PolyVoxEntityItem::DEFAULT_VOXEL_DATA) + _voxelData(PolyVoxEntityItem::DEFAULT_VOXEL_DATA), + _voxelSurfaceStyle(PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE) { _type = EntityTypes::PolyVox; _created = properties.getCreated(); @@ -50,6 +52,7 @@ EntityItemProperties PolyVoxEntityItem::getProperties() const { COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor); COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelVolumeSize, getVoxelVolumeSize); COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelData, getVoxelData); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelSurfaceStyle, getVoxelSurfaceStyle); return properties; } @@ -61,6 +64,7 @@ bool PolyVoxEntityItem::setProperties(const EntityItemProperties& properties) { SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setXColor); SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelVolumeSize, setVoxelVolumeSize); SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelData, setVoxelData); + SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelSurfaceStyle, setVoxelSurfaceStyle); if (somethingChanged) { bool wantDebug = false; @@ -85,6 +89,7 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); READ_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); READ_ENTITY_PROPERTY(PROP_VOXEL_DATA, QByteArray, setVoxelData); + READ_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, uint16_t, setVoxelSurfaceStyle); return bytesRead; } @@ -96,6 +101,7 @@ EntityPropertyFlags PolyVoxEntityItem::getEntityProperties(EncodeBitstreamParams requestedProperties += PROP_COLOR; requestedProperties += PROP_VOXEL_VOLUME_SIZE; requestedProperties += PROP_VOXEL_DATA; + requestedProperties += PROP_VOXEL_SURFACE_STYLE; return requestedProperties; } @@ -111,6 +117,7 @@ void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeB APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, getVoxelVolumeSize()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, getVoxelData()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, getVoxelSurfaceStyle()); } void PolyVoxEntityItem::debugDump() const { diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 2039f44a34..e4e486337b 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -67,8 +67,12 @@ class PolyVoxEntityItem : public EntityItem { virtual void setVoxelData(QByteArray voxelData) { _voxelData = voxelData; } virtual const QByteArray& getVoxelData() const { return _voxelData; } + virtual void setVoxelSurfaceStyle(uint16_t voxelSurfaceStyle) { _voxelSurfaceStyle = voxelSurfaceStyle; } + virtual uint16_t getVoxelSurfaceStyle() const { return _voxelSurfaceStyle; } + static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; static const QByteArray DEFAULT_VOXEL_DATA; + static const int DEFAULT_VOXEL_SURFACE_STYLE; // coords are in voxel-volume space virtual void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) {} @@ -80,6 +84,7 @@ class PolyVoxEntityItem : public EntityItem { rgbColor _color; glm::vec3 _voxelVolumeSize; // this is always 3 bytes QByteArray _voxelData; + uint16_t _voxelSurfaceStyle; }; #endif // hifi_PolyVoxEntityItem_h diff --git a/libraries/octree/src/OctreePacketData.cpp b/libraries/octree/src/OctreePacketData.cpp index ed30c619ca..19fc278088 100644 --- a/libraries/octree/src/OctreePacketData.cpp +++ b/libraries/octree/src/OctreePacketData.cpp @@ -556,7 +556,7 @@ void OctreePacketData::debugContent() { printf("\n"); } -int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, QString& result) { +int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QString& result) { uint16_t length; memcpy(&length, dataBytes, sizeof(length)); dataBytes += sizeof(length); @@ -565,7 +565,7 @@ int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, QStrin return sizeof(length) + length; } -int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, QUuid& result) { +int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QUuid& result) { uint16_t length; memcpy(&length, dataBytes, sizeof(length)); dataBytes += sizeof(length); @@ -578,14 +578,14 @@ int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, QUuid& return sizeof(length) + length; } -int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, xColor& result) { +int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, xColor& result) { result.red = dataBytes[RED_INDEX]; result.green = dataBytes[GREEN_INDEX]; result.blue = dataBytes[BLUE_INDEX]; return sizeof(rgbColor); } -int OctreePacketData::uppackDataFromBytes(const unsigned char* dataBytes, QByteArray& result) { +int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QByteArray& result) { uint16_t length; memcpy(&length, dataBytes, sizeof(length)); dataBytes += sizeof(length); diff --git a/libraries/octree/src/OctreePacketData.h b/libraries/octree/src/OctreePacketData.h index 28d6ff7d20..5becb26ca2 100644 --- a/libraries/octree/src/OctreePacketData.h +++ b/libraries/octree/src/OctreePacketData.h @@ -227,21 +227,21 @@ public: static quint64 getTotalBytesOfBitMasks() { return _totalBytesOfBitMasks; } /// total bytes of bitmasks static quint64 getTotalBytesOfColor() { return _totalBytesOfColor; } /// total bytes of color - static int uppackDataFromBytes(const unsigned char* dataBytes, float& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, glm::vec3& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, bool& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, quint64& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, uint32_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, uint16_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, uint8_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, rgbColor& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, glm::quat& result) { int bytes = unpackOrientationQuatFromBytes(dataBytes, result); return bytes; } - static int uppackDataFromBytes(const unsigned char* dataBytes, ShapeType& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, BackgroundMode& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } - static int uppackDataFromBytes(const unsigned char* dataBytes, QString& result); - static int uppackDataFromBytes(const unsigned char* dataBytes, QUuid& result); - static int uppackDataFromBytes(const unsigned char* dataBytes, xColor& result); - static int uppackDataFromBytes(const unsigned char* dataBytes, QByteArray& result); + static int unpackDataFromBytes(const unsigned char* dataBytes, float& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, glm::vec3& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, bool& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, quint64& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, uint32_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, uint16_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, uint8_t& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, rgbColor& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, glm::quat& result) { int bytes = unpackOrientationQuatFromBytes(dataBytes, result); return bytes; } + static int unpackDataFromBytes(const unsigned char* dataBytes, ShapeType& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, BackgroundMode& result) { memcpy(&result, dataBytes, sizeof(result)); return sizeof(result); } + static int unpackDataFromBytes(const unsigned char* dataBytes, QString& result); + static int unpackDataFromBytes(const unsigned char* dataBytes, QUuid& result); + static int unpackDataFromBytes(const unsigned char* dataBytes, xColor& result); + static int unpackDataFromBytes(const unsigned char* dataBytes, QByteArray& result); private: /// appends raw bytes, might fail if byte would cause packet to be too large From df795cf2960459eeada033632f579514cb7a653b Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 08:54:15 -0700 Subject: [PATCH 41/80] adapting to entitypointer merge --- libraries/entities/src/EntityScriptingInterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 0271766d38..320780dc80 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -389,7 +389,7 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c return false; } - EntityItem* entity = const_cast(_entityTree->findEntityByEntityItemID(entityID)); + EntityItemPointer entity = static_cast(_entityTree->findEntityByEntityItemID(entityID)); if (!entity) { qCDebug(entities) << "EntityScriptingInterface::setVoxelSphere no entity with ID" << entityID; return false; @@ -402,7 +402,7 @@ bool EntityScriptingInterface::setVoxelSphere(QUuid entityID, const glm::vec3& c auto now = usecTimestampNow(); - PolyVoxEntityItem* polyVoxEntity = static_cast(entity); + PolyVoxEntityItem* polyVoxEntity = static_cast(entity.get()); _entityTree->lockForWrite(); polyVoxEntity->setSphere(center, radius, value); entity->setLastEdited(now); From c1f75506aea59626002f9fd3e0ccdd77602cbb24 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 08:57:22 -0700 Subject: [PATCH 42/80] adapting to entitypointer merge --- libraries/entities/src/PolyVoxEntityItem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index e4e486337b..d658ad365a 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -16,7 +16,7 @@ class PolyVoxEntityItem : public EntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); PolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties); From b02e452b19de84de66ab10a886b11a692e4427d3 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 08:58:03 -0700 Subject: [PATCH 43/80] adapting to entitypointer merge --- libraries/entities/src/PolyVoxEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index 74569de9e1..4b8be31fe0 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -25,7 +25,7 @@ const glm::vec3 PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE = glm::vec3(32, 32, const QByteArray PolyVoxEntityItem::DEFAULT_VOXEL_DATA(qCompress(QByteArray(0), 9)); const int PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE = 0; -EntityItem* PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItemPointer PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { EntityItem* result = new PolyVoxEntityItem(entityID, properties); return result; } From f310da9cd3627dee116b620d1275a934c827baa1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 08:59:44 -0700 Subject: [PATCH 44/80] adapting to entitypointer merge --- .../entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 2 +- libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h | 2 +- libraries/entities/src/PolyVoxEntityItem.cpp | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index e8684a88dc..ec2c8e32a3 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -33,7 +33,7 @@ #include "EntityTreeRenderer.h" #include "RenderablePolyVoxEntityItem.h" -EntityItem* RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { +EntityItemPointer RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return new RenderablePolyVoxEntityItem(entityID, properties); } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 981d59c506..b04b32996b 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -19,7 +19,7 @@ class RenderablePolyVoxEntityItem : public PolyVoxEntityItem { public: - static EntityItem* factory(const EntityItemID& entityID, const EntityItemProperties& properties); + static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties); RenderablePolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : PolyVoxEntityItem(entityItemID, properties) { } diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index 4b8be31fe0..a170d67241 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -26,8 +26,7 @@ const QByteArray PolyVoxEntityItem::DEFAULT_VOXEL_DATA(qCompress(QByteArray(0), const int PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE = 0; EntityItemPointer PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - EntityItem* result = new PolyVoxEntityItem(entityID, properties); - return result; + return EntityItemPointer(new PolyVoxEntityItem(entityID, properties)); } PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const EntityItemProperties& properties) : From 1749ec83dbcc071e1537884b9521b369ffb435f1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 09:00:59 -0700 Subject: [PATCH 45/80] adapting to entitypointer merge --- libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index ec2c8e32a3..6d06263cea 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -34,7 +34,7 @@ #include "RenderablePolyVoxEntityItem.h" EntityItemPointer RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { - return new RenderablePolyVoxEntityItem(entityID, properties); + return EntityItemPointer(new RenderablePolyVoxEntityItem(entityID, properties)); } RenderablePolyVoxEntityItem::~RenderablePolyVoxEntityItem() { From 3af916e27eecd60e52af19b256d1fea3d1439dff Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 09:32:10 -0700 Subject: [PATCH 46/80] use enum for polyvox surface style --- .../src/RenderablePolyVoxEntityItem.cpp | 21 ++++++++++++------- libraries/entities/src/EntityItem.cpp | 4 ++-- libraries/entities/src/PolyVoxEntityItem.cpp | 5 +++-- libraries/entities/src/PolyVoxEntityItem.h | 16 ++++++++++---- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 6d06263cea..647e2fb280 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -126,14 +126,19 @@ void RenderablePolyVoxEntityItem::getModel() { // A mesh object to hold the result of surface extraction PolyVox::SurfaceMesh polyVoxMesh; - if (_voxelSurfaceStyle == 0) { - PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor - (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - surfaceExtractor.execute(); - } else { - PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor - (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); - surfaceExtractor.execute(); + switch (_voxelSurfaceStyle) { + case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: { + PolyVox::MarchingCubesSurfaceExtractor> surfaceExtractor + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + surfaceExtractor.execute(); + break; + } + case PolyVoxEntityItem::SURFACE_CUBIC: { + PolyVox::CubicSurfaceExtractorWithNormals> surfaceExtractor + (_volData, _volData->getEnclosingRegion(), &polyVoxMesh); + surfaceExtractor.execute(); + break; + } } // convert PolyVox mesh to a Sam mesh diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 38bc744e63..275b22b4a7 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -661,12 +661,12 @@ void EntityItem::adjustEditPacketForClockSkew(unsigned char* editPacketBuffer, s assert(lastEditedInLocalTime > 0); quint64 lastEditedInServerTime = lastEditedInLocalTime + clockSkew; memcpy(dataAt, &lastEditedInServerTime, sizeof(lastEditedInServerTime)); - //#ifdef WANT_DEBUG + #ifdef WANT_DEBUG qCDebug(entities, "EntityItem::adjustEditPacketForClockSkew()..."); qCDebug(entities) << " lastEditedInLocalTime: " << lastEditedInLocalTime; qCDebug(entities) << " clockSkew: " << clockSkew; qCDebug(entities) << " lastEditedInServerTime: " << lastEditedInServerTime; - //#endif + #endif } float EntityItem::computeMass() const { diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index a170d67241..5ba74dbff5 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -23,7 +23,8 @@ const glm::vec3 PolyVoxEntityItem::DEFAULT_VOXEL_VOLUME_SIZE = glm::vec3(32, 32, 32); const QByteArray PolyVoxEntityItem::DEFAULT_VOXEL_DATA(qCompress(QByteArray(0), 9)); -const int PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE = 0; +const PolyVoxEntityItem::PolyVoxSurfaceStyle PolyVoxEntityItem::DEFAULT_VOXEL_SURFACE_STYLE = + PolyVoxEntityItem::SURFACE_MARCHING_CUBES; EntityItemPointer PolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return EntityItemPointer(new PolyVoxEntityItem(entityID, properties)); @@ -116,7 +117,7 @@ void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeB APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, getVoxelVolumeSize()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, getVoxelData()); - APPEND_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, getVoxelSurfaceStyle()); + APPEND_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, (uint16_t) getVoxelSurfaceStyle()); } void PolyVoxEntityItem::debugDump() const { diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index d658ad365a..53675e6efa 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -67,12 +67,20 @@ class PolyVoxEntityItem : public EntityItem { virtual void setVoxelData(QByteArray voxelData) { _voxelData = voxelData; } virtual const QByteArray& getVoxelData() const { return _voxelData; } - virtual void setVoxelSurfaceStyle(uint16_t voxelSurfaceStyle) { _voxelSurfaceStyle = voxelSurfaceStyle; } - virtual uint16_t getVoxelSurfaceStyle() const { return _voxelSurfaceStyle; } + enum PolyVoxSurfaceStyle { + SURFACE_MARCHING_CUBES, + SURFACE_CUBIC + }; + + virtual void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { _voxelSurfaceStyle = voxelSurfaceStyle; } + virtual void setVoxelSurfaceStyle(uint16_t voxelSurfaceStyle) { + _voxelSurfaceStyle = (PolyVoxSurfaceStyle) voxelSurfaceStyle; + } + virtual PolyVoxSurfaceStyle getVoxelSurfaceStyle() const { return _voxelSurfaceStyle; } static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; static const QByteArray DEFAULT_VOXEL_DATA; - static const int DEFAULT_VOXEL_SURFACE_STYLE; + static const PolyVoxSurfaceStyle DEFAULT_VOXEL_SURFACE_STYLE; // coords are in voxel-volume space virtual void setSphereInVolume(glm::vec3 center, float radius, uint8_t toValue) {} @@ -84,7 +92,7 @@ class PolyVoxEntityItem : public EntityItem { rgbColor _color; glm::vec3 _voxelVolumeSize; // this is always 3 bytes QByteArray _voxelData; - uint16_t _voxelSurfaceStyle; + PolyVoxSurfaceStyle _voxelSurfaceStyle; }; #endif // hifi_PolyVoxEntityItem_h From 429cc631f39858a7119d0fd9f899044c7c44fd79 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 09:48:32 -0700 Subject: [PATCH 47/80] limit size of polyvox data property to below MTU --- examples/voxels.js | 2 ++ .../src/RenderablePolyVoxEntityItem.cpp | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/voxels.js b/examples/voxels.js index 632ed77e15..e274f1c4cc 100644 --- a/examples/voxels.js +++ b/examples/voxels.js @@ -39,3 +39,5 @@ function keyReleaseEvent(event) { Controller.mousePressEvent.connect(mousePressEvent); +Controller.keyPressEvent.connect(keyPressEvent); +Controller.keyReleaseEvent.connect(keyReleaseEvent); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 647e2fb280..81d4834015 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -289,8 +289,12 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { } } - _voxelData = qCompress(uncompressedData, 9); - qDebug() << "-------------- voxel compresss ------------------------------------------------------------"; + QByteArray newVoxelData = qCompress(uncompressedData, 9); + // HACK -- until we have a way to allow for properties larger than MTU, don't update. + if (newVoxelData.length() < 1300) { + _voxelData = newVoxelData; + } + qDebug() << "-------------- voxel compresss --------------"; qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); } @@ -312,6 +316,6 @@ void RenderablePolyVoxEntityItem::decompressVolumeData() { _needsModelReload = true; - qDebug() << "--------------- voxel decompress -----------------------------------------------------------"; + qDebug() << "--------------- voxel decompress ---------------"; qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); } From 14c68519f3dc2a1daa1c4d35612293085694be21 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 09:59:18 -0700 Subject: [PATCH 48/80] limit size of polyvox data property to below MTU --- .../src/RenderablePolyVoxEntityItem.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 81d4834015..2e769399ce 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -291,11 +291,15 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { QByteArray newVoxelData = qCompress(uncompressedData, 9); // HACK -- until we have a way to allow for properties larger than MTU, don't update. - if (newVoxelData.length() < 1300) { + if (newVoxelData.length() < 1200) { _voxelData = newVoxelData; + qDebug() << "-------------- voxel compresss --------------"; + qDebug() << "raw-size =" << rawSize << " compressed-size =" << newVoxelData.size(); + } else { + qDebug() << "voxel data too large, reverting change."; + // revert + decompressVolumeData(); } - qDebug() << "-------------- voxel compresss --------------"; - qDebug() << "raw-size =" << rawSize << " compressed-size =" << _voxelData.size(); } From 5e66a079c438b23a16e17713078967f4679808e3 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 10:38:15 -0700 Subject: [PATCH 49/80] make this build on older gcc --- libraries/gpu/src/gpu/Resource.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index c7763e108b..846a416191 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -309,7 +309,7 @@ public: protected: T* _ptr; - int _stride = sizeof(T); + int _stride; }; template Iterator begin() { return Iterator(&edit(0), _stride); } From 7c4b89d91749208f951e36266d3a3acdf2b1e13a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 11:56:57 -0700 Subject: [PATCH 50/80] get polyvox to build on osx --- ...hange.cmake => OSXInstallNameChange.cmake} | 27 +++++++++---------- cmake/externals/polyvox/CMakeLists.txt | 24 ++++++++++++++--- cmake/externals/tbb/CMakeLists.txt | 6 +++-- 3 files changed, 36 insertions(+), 21 deletions(-) rename cmake/externals/{tbb/OSXTBBInstallNameChange.cmake => OSXInstallNameChange.cmake} (53%) diff --git a/cmake/externals/tbb/OSXTBBInstallNameChange.cmake b/cmake/externals/OSXInstallNameChange.cmake similarity index 53% rename from cmake/externals/tbb/OSXTBBInstallNameChange.cmake rename to cmake/externals/OSXInstallNameChange.cmake index 0fa377959b..4922f2f8a5 100644 --- a/cmake/externals/tbb/OSXTBBInstallNameChange.cmake +++ b/cmake/externals/OSXInstallNameChange.cmake @@ -1,6 +1,6 @@ # -# OSXTBBInstallNameChange.cmake -# cmake/externals/tbb +# OSXInstallNameChange.cmake +# cmake/macros # # Copyright 2015 High Fidelity, Inc. # Created by Stephen Birarda on February 20, 2014 @@ -10,36 +10,33 @@ # # first find the so files in the source dir -set(_TBB_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib) -file(GLOB_RECURSE _TBB_LIBRARIES "${_TBB_LIBRARY_DIR}/*.dylib") +message("INSTALL_NAME_LIBRARY_DIR ${INSTALL_NAME_LIBRARY_DIR}") -# raise an error if we found none -if (NOT _TBB_LIBRARIES) - message(FATAL_ERROR "Did not find any TBB libraries") +file(GLOB_RECURSE _LIBRARIES "${INSTALL_NAME_LIBRARY_DIR}/*.dylib") + +if (NOT _LIBRARIES) + message(FATAL_ERROR "OSXInstallNameChange -- no libraries found: ${INSTALL_NAME_LIBRARY_DIR}") endif () # find the install_name_tool command find_program(INSTALL_NAME_TOOL_COMMAND NAMES install_name_tool DOC "Path to the install_name_tool command") -# find the lipo command -find_program(LIPO_COMMAND NAMES lipo DOC "Path to the lipo command") - # enumerate the libraries -foreach(_TBB_LIBRARY ${_TBB_LIBRARIES}) - get_filename_component(_TBB_LIBRARY_FILENAME ${_TBB_LIBRARY} NAME) +foreach(_LIBRARY ${_LIBRARIES}) + get_filename_component(_LIBRARY_FILENAME ${_LIBRARY} NAME) - set(_INSTALL_NAME_ARGS ${INSTALL_NAME_TOOL_COMMAND} -id ${_TBB_LIBRARY} ${_TBB_LIBRARY_FILENAME}) + set(_INSTALL_NAME_ARGS ${INSTALL_NAME_TOOL_COMMAND} -id ${_LIBRARY} ${_LIBRARY_FILENAME}) message(STATUS "${INSTALL_NAME_COMMAND} ${_INSTALL_NAME_ARGS}") execute_process( COMMAND ${INSTALL_NAME_COMMAND} ${_INSTALL_NAME_ARGS} - WORKING_DIRECTORY ${_TBB_LIBRARY_DIR} + WORKING_DIRECTORY ${INSTALL_NAME_LIBRARY_DIR} ERROR_VARIABLE _INSTALL_NAME_ERROR ) if (_INSTALL_NAME_ERROR) - message(FATAL_ERROR "There was an error changing install name for ${_TBB_LIBRARY_FILENAME} - ${_INSTALL_NAME_ERROR}") + message(FATAL_ERROR "There was an error changing install name for ${_LIBRARY_FILENAME} - ${_INSTALL_NAME_ERROR}") endif () endforeach() diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 7e719887e2..1089692b37 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,8 +4,8 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} # URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master.zip - URL http://headache.hungry.com/~seth/hifi/polyvox-master.zip - URL_MD5 b62e8d8711a4f462377d45e2dd1a22c0 + URL http://headache.hungry.com/~seth/hifi/polyvox-master-2015-5-27.zip + URL_MD5 f1241daae74ff69b7e31961edaff1555 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 @@ -13,8 +13,24 @@ ExternalProject_Add( LOG_BUILD 1 ) + ExternalProject_Get_Property(${EXTERNAL_NAME} INSTALL_DIR) +if (APPLE) + set(INSTALL_NAME_LIBRARY_DIR ${INSTALL_DIR}/lib) + message(STATUS "in polyvox INSTALL_NAME_LIBRARY_DIR ${INSTALL_NAME_LIBRARY_DIR}") + ExternalProject_Add_Step( + ${EXTERNAL_NAME} + change-install-name + COMMENT "Calling install_name_tool on libraries to fix install name for dylib linking" + COMMAND ${CMAKE_COMMAND} -DINSTALL_NAME_LIBRARY_DIR=${INSTALL_NAME_LIBRARY_DIR} -P ${EXTERNAL_PROJECT_DIR}/OSXInstallNameChange.cmake + DEPENDEES install + WORKING_DIRECTORY + LOG 1 + ) +endif () + + string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) if (WIN32) @@ -34,8 +50,8 @@ if (WIN32) set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/PolyVoxCore/lib/PolyVoxCore.lib CACHE FILEPATH "polyvox core library") # set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/PolyVoxUtil/lib/PolyVoxUtil.lib CACHE FILEPATH "polyvox util library") elseif (APPLE) - set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox core library") -# set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/polyvox.lib CACHE FILEPATH "polyvox util library") +set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxCore.dylib CACHE FILEPATH "polyvox core library") +# set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxUtil.dylib CACHE FILEPATH "polyvox util library") else () set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") # set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxUtil.so CACHE FILEPATH "polyvox util library") diff --git a/cmake/externals/tbb/CMakeLists.txt b/cmake/externals/tbb/CMakeLists.txt index b9b2b65010..7af91ad3d9 100644 --- a/cmake/externals/tbb/CMakeLists.txt +++ b/cmake/externals/tbb/CMakeLists.txt @@ -57,6 +57,8 @@ ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) +message("HERE in tbb") + if (APPLE) set(_TBB_LIB_DIR "${SOURCE_DIR}/lib") set(_LIB_PREFIX "lib") @@ -66,7 +68,7 @@ if (APPLE) ${EXTERNAL_NAME} change-install-name COMMENT "Calling install_name_tool on TBB libraries to fix install name for dylib linking" - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/OSXTBBInstallNameChange.cmake + COMMAND ${CMAKE_COMMAND} -DINSTALL_NAME_LIBRARY_DIR=${_TBB_LIB_DIR} -P ${EXTERNAL_PROJECT_DIR}/OSXInstallNameChange.cmake DEPENDEES install WORKING_DIRECTORY LOG 1 @@ -115,4 +117,4 @@ endif () if (DEFINED ${EXTERNAL_NAME_UPPER}_LIBRARY_RELEASE) set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIRS ${SOURCE_DIR}/include CACHE TYPE "List of tbb include directories") -endif () \ No newline at end of file +endif () From 1109444c3de3d116d3bd3b7ca64cb01102d8681a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 14:57:12 -0700 Subject: [PATCH 51/80] attempt to make sure the ray that picks against polyvox entities is long enough --- cmake/externals/tbb/CMakeLists.txt | 2 -- .../src/RenderablePolyVoxEntityItem.cpp | 13 +++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmake/externals/tbb/CMakeLists.txt b/cmake/externals/tbb/CMakeLists.txt index 7af91ad3d9..8f327bd69f 100644 --- a/cmake/externals/tbb/CMakeLists.txt +++ b/cmake/externals/tbb/CMakeLists.txt @@ -57,8 +57,6 @@ ExternalProject_Get_Property(${EXTERNAL_NAME} SOURCE_DIR) string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) -message("HERE in tbb") - if (APPLE) set(_TBB_LIB_DIR "${SOURCE_DIR}/lib") set(_LIB_PREFIX "lib") diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 2e769399ce..933b7ad1ef 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -33,6 +33,7 @@ #include "EntityTreeRenderer.h" #include "RenderablePolyVoxEntityItem.h" + EntityItemPointer RenderablePolyVoxEntityItem::factory(const EntityItemID& entityID, const EntityItemProperties& properties) { return EntityItemPointer(new RenderablePolyVoxEntityItem(entityID, properties)); } @@ -255,8 +256,13 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o PolyVox::Vector3DFloat start(originInVoxel[0], originInVoxel[1], originInVoxel[2]); PolyVox::Vector3DFloat pvDirection(directionInVoxel[0], directionInVoxel[1], directionInVoxel[2]); pvDirection.normalise(); - // pvDirection *= 1000.0f; // Casts ray of length 1000 - pvDirection *= 64.0f; // Casts ray of length 1000 + + // the PolyVox ray intersection code requires a near and far point. + glm::vec3 scale = _dimensions / _voxelVolumeSize; // meters / voxel-units + float distanceToEntity = glm::distance(origin, _position); + float largestDimension = glm::max(_dimensions[0], _dimensions[1], _dimensions[2]); + // set ray cast length to long enough to cover all of the voxel space + pvDirection *= (distanceToEntity + largestDimension) / glm::min(scale[0], scale[1], scale[2]); PolyVox::RaycastResult raycastResult; RaycastFunctor callback; @@ -275,6 +281,8 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o } +// compress the data in _volData and save the results. The compressed form is used during +// saves to disk and for transmission over the wire void RenderablePolyVoxEntityItem::compressVolumeData() { int rawSize = _volData->getDepth() * _volData->getHeight() * _volData->getWidth(); QByteArray uncompressedData = QByteArray(rawSize, '\0'); @@ -303,6 +311,7 @@ void RenderablePolyVoxEntityItem::compressVolumeData() { } +// take compressed data and decompreess it into _volData. void RenderablePolyVoxEntityItem::decompressVolumeData() { int rawSize = _volData->getDepth() * _volData->getHeight() * _volData->getWidth(); QByteArray uncompressedData = QByteArray(rawSize, '\0'); From c933c42b182eab0024f785ac1b5776f5b6885bb1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 15:02:20 -0700 Subject: [PATCH 52/80] move polyvox external source to s3 --- cmake/externals/polyvox/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 1089692b37..2c05ddbb72 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -3,8 +3,7 @@ set(EXTERNAL_NAME polyvox) include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} - # URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master.zip - URL http://headache.hungry.com/~seth/hifi/polyvox-master-2015-5-27.zip + URL https://s3.amazonaws.com/hifi-public/dependencies/polyvox-master-2015-5-27.zip URL_MD5 f1241daae74ff69b7e31961edaff1555 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build From ded79609de77de6024df6d3e2d58bd9537283d60 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 15:10:27 -0700 Subject: [PATCH 53/80] back out unrelated change --- libraries/entities/src/EntityItem.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 275b22b4a7..d5a99bf263 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -321,11 +321,10 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // if this bitstream indicates that this node is the simulation owner, ignore any physics-related updates. glm::vec3 savePosition = _position; glm::quat saveRotation = _rotation; - glm::vec3 saveVelocity = _velocity; - glm::vec3 saveAngularVelocity = _angularVelocity; - glm::vec3 saveGravity = _gravity; - glm::vec3 saveAcceleration = _acceleration; - uint32_t saveFlags = _dirtyFlags; + // glm::vec3 saveVelocity = _velocity; + // glm::vec3 saveAngularVelocity = _angularVelocity; + // glm::vec3 saveGravity = _gravity; + // glm::vec3 saveAcceleration = _acceleration; // Header bytes @@ -627,15 +626,10 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // this node, so our version has to be newer than what the packet contained. _position = savePosition; _rotation = saveRotation; - _velocity = saveVelocity; - _angularVelocity = saveAngularVelocity; - _gravity = saveGravity; - _acceleration = saveAcceleration; - _dirtyFlags &= ~(saveFlags & (EntityItem::DIRTY_POSITION | - EntityItem::DIRTY_ROTATION | - EntityItem::DIRTY_LINEAR_VELOCITY | - EntityItem::DIRTY_ANGULAR_VELOCITY | - EntityItem::DIRTY_PHYSICS_ACTIVATION)); + // _velocity = saveVelocity; + // _angularVelocity = saveAngularVelocity; + // _gravity = saveGravity; + // _acceleration = saveAcceleration; } return bytesRead; From 5cc038e1c65d540982d2a27e598b480fe111b45f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 15:12:26 -0700 Subject: [PATCH 54/80] polyvox no longer has a color --- libraries/entities/src/EntityItemProperties.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 7bda9d3ef5..856c1a1cb4 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -543,7 +543,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) { _stage.copyFromScriptValue(object, _defaultSettings); _atmosphere.copyFromScriptValue(object, _defaultSettings); _skybox.copyFromScriptValue(object, _defaultSettings); - _lastEdited = usecTimestampNow(); // ??? + _lastEdited = usecTimestampNow(); } QScriptValue EntityItemPropertiesToScriptValue(QScriptEngine* engine, const EntityItemProperties& properties) { @@ -758,7 +758,6 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType command, EntityItem } if (properties.getType() == EntityTypes::PolyVox) { - APPEND_ENTITY_PROPERTY(PROP_COLOR, properties.getColor()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, properties.getVoxelVolumeSize()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, properties.getVoxelData()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, properties.getVoxelSurfaceStyle()); @@ -999,7 +998,6 @@ bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int } if (properties.getType() == EntityTypes::PolyVox) { - READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_COLOR, xColor, setColor); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_DATA, QByteArray, setVoxelData); READ_ENTITY_PROPERTY_TO_PROPERTIES(PROP_VOXEL_SURFACE_STYLE, uint16_t, setVoxelSurfaceStyle); From 8cb5717b86c11b841cd40bea0035eee1667ce0fc Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 15:16:15 -0700 Subject: [PATCH 55/80] formatting, cleanups --- .../entities/src/EntityItemPropertiesMacros.h | 18 ------------- libraries/gpu/src/gpu/Resource.h | 26 +++++++++---------- libraries/model/src/model/Geometry.h | 2 +- 3 files changed, 14 insertions(+), 32 deletions(-) diff --git a/libraries/entities/src/EntityItemPropertiesMacros.h b/libraries/entities/src/EntityItemPropertiesMacros.h index 0fab1d7d06..33abc59e4d 100644 --- a/libraries/entities/src/EntityItemPropertiesMacros.h +++ b/libraries/entities/src/EntityItemPropertiesMacros.h @@ -97,14 +97,6 @@ inline QScriptValue convertScriptValue(QScriptEngine* e, const glm::quat& v) { r inline QScriptValue convertScriptValue(QScriptEngine* e, const QScriptValue& v) { return v; } inline QScriptValue convertScriptValue(QScriptEngine* e, const QByteArray& v) { - // return QScriptValue(QLatin1String(v.data())); - - // QScriptValue array = e->newArray(v.size()); - // for (int i = 0; i < v.size(); ++i) { - // array.setProperty(i, QScriptValue(e, (unsigned int) v[i])); - // } - // return array; - QByteArray b64 = v.toBase64(); return QScriptValue(QString(b64)); } @@ -149,17 +141,7 @@ inline QUuid QUuid_convertFromScriptValue(const QScriptValue& v, bool& isValid) inline QByteArray QByteArray_convertFromScriptValue(const QScriptValue& v, bool& isValid) { isValid = true; - // return v.toVariant().toByteArray(); - - // QByteArray byteArray; - // uint len = v.property("length").toUInt32(); - // byteArray.resize(len); - // for (uint i = 0; i < len; ++i) - // byteArray[i] = v.property(i).toUInt32(); - // return byteArray; - QString b64 = v.toVariant().toString().trimmed(); - return QByteArray::fromBase64(b64.toUtf8()); } diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 846a416191..21202f9354 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -235,7 +235,7 @@ public: Iterator& operator=(const Iterator& iterator) = default; Iterator& operator=(T* ptr) { _ptr = ptr; - // stride is left unchanged + // stride is left unchanged return (*this); } @@ -257,42 +257,42 @@ public: } Iterator& operator+=(const Index& movement) { - movePtr(movement); + movePtr(movement); return (*this); } Iterator& operator-=(const Index& movement) { - movePtr(-movement); + movePtr(-movement); return (*this); } Iterator& operator++() { - movePtr(1); + movePtr(1); return (*this); } Iterator& operator--() { - movePtr(-1); - return (*this); + movePtr(-1); + return (*this); } Iterator operator++(Index) { auto temp(*this); - movePtr(1); - return temp; + movePtr(1); + return temp; } Iterator operator--(Index) { auto temp(*this); - movePtr(-1); - return temp; + movePtr(-1); + return temp; } Iterator operator+(const Index& movement) { auto oldPtr = _ptr; - movePtr(movement); + movePtr(movement); auto temp(*this); _ptr = oldPtr; return temp; } Iterator operator-(const Index& movement) { auto oldPtr = _ptr; - movePtr(-movement); - auto temp(*this); + movePtr(-movement); + auto temp(*this); _ptr = oldPtr; return temp; } diff --git a/libraries/model/src/model/Geometry.h b/libraries/model/src/model/Geometry.h index 736047e886..ddefaf4e96 100755 --- a/libraries/model/src/model/Geometry.h +++ b/libraries/model/src/model/Geometry.h @@ -52,7 +52,7 @@ public: // Attribute Buffers int getNumAttributes() const { return _attributeBuffers.size(); } void addAttribute(Slot slot, const BufferView& buffer); - const BufferView getAttributeBuffer(int attrib) const; + const BufferView getAttributeBuffer(int attrib) const; // Stream format const gpu::Stream::FormatPointer getVertexFormat() const { return _vertexFormat; } From 8db8277bf837e9e4e42cee5a866042b2af745410 Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Wed, 27 May 2015 15:20:49 -0700 Subject: [PATCH 56/80] tiles and block no longer delete on script end, now user can delete all the stuff with a button click instead. Also blocks now spawn with random angular velocity for spinning fun --- examples/blockWorld.js | 201 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) diff --git a/examples/blockWorld.js b/examples/blockWorld.js index e69de29bb2..53809612ed 100644 --- a/examples/blockWorld.js +++ b/examples/blockWorld.js @@ -0,0 +1,201 @@ +// blockWorld.js +// examples +// +// Created by Eric Levin on May 26, 2015 +// Copyright 2015 High Fidelity, Inc. +// +// Creates a floor of tiles and then drops planky blocks at random points above the tile floor +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var TILE_SIZE = 7 +var GENERATE_INTERVAL = 50; +var NUM_ROWS = 10; +var angVelRange = 4; + +var floorTiles = []; +var blocks = []; +var blockSpawner; + +HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; + + +var floorPos = Vec3.sum(MyAvatar.position, { + x: 0, + y: -2, + z: 0 +}); +var x = floorPos.x; + +var currentRowIndex = 0; +var currentColumnIndex = 0; + +var DROP_HEIGHT = floorPos.y + 5; +var BLOCK_GRAVITY = { + x: 0, + y: -9, + z: 0 +}; +var BLOCK_SIZE = { + x: 0.2, + y: 0.1, + z: 0.8 +}; + +var bounds = { + xMin: floorPos.x, + xMax: floorPos.x + (TILE_SIZE * NUM_ROWS) - TILE_SIZE, + zMin: floorPos.z, + zMax: floorPos.z + (TILE_SIZE * NUM_ROWS) - TILE_SIZE +}; + +var screenSize = Controller.getViewportDimensions(); + +var BUTTON_SIZE = 32; +var PADDING = 3; + +var offButton = Overlays.addOverlay("image", { + x: screenSize.x / 2 - BUTTON_SIZE * 2 + PADDING, + y: screenSize.y - (BUTTON_SIZE + PADDING), + width: BUTTON_SIZE, + height: BUTTON_SIZE, + imageURL: HIFI_PUBLIC_BUCKET + "images/close.png", + color: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1 +}); + +var deleteButton = Overlays.addOverlay("image", { + x: screenSize.x / 2 - BUTTON_SIZE, + y: screenSize.y - (BUTTON_SIZE + PADDING), + width: BUTTON_SIZE, + height: BUTTON_SIZE, + imageURL: HIFI_PUBLIC_BUCKET + "images/delete.png", + color: { + red: 255, + green: 255, + blue: 255 + }, + alpha: 1 +}); + + +function generateFloor() { + for (var z = floorPos.z; currentColumnIndex < NUM_ROWS; z += TILE_SIZE, currentColumnIndex++) { + floorTiles.push(Entities.addEntity({ + type: 'Box', + position: { + x: x, + y: floorPos.y, + z: z + }, + dimensions: { + x: TILE_SIZE, + y: 2, + z: TILE_SIZE + }, + color: { + red: randFloat(70, 120), + green: randFloat(70, 71), + blue: randFloat(70, 80) + }, + // collisionsWillMove: true + })); + } + + currentRowIndex++; + if (currentRowIndex < NUM_ROWS) { + currentColumnIndex = 0; + x += TILE_SIZE; + Script.setTimeout(generateFloor, GENERATE_INTERVAL); + } else { + //Once we're done generating floor, drop planky blocks at random points on floor + blockSpawner = Script.setInterval(function() { + dropBlock(); + }, GENERATE_INTERVAL) + } +} + +function dropBlock() { + var dropPos = floorPos; + dropPos.y = DROP_HEIGHT; + dropPos.x = randFloat(bounds.xMin, bounds.xMax); + dropPos.z = randFloat(bounds.zMin, bounds.zMax); + blocks.push(Entities.addEntity({ + type: "Model", + modelURL: 'http://s3.amazonaws.com/hifi-public/marketplace/hificontent/Games/blocks/block.fbx', + shapeType: 'box', + position: dropPos, + dimensions: BLOCK_SIZE, + collisionsWillMove: true, + gravity: { + x: 0, + y: -9, + z: 0 + }, + velocity: { + x: 0, + y: .1, + z: 0 + }, + angularVelocity: { + x: randFloat(-angVelRange, angVelRange), + y: randFloat(-angVelRange, angVelRange), + z: randFloat(-angVelRange, angVelRange), + } + })); +} + +function mousePressEvent(event) { + var clickedOverlay = Overlays.getOverlayAtPoint({ + x: event.x, + y: event.y + }); + if (clickedOverlay == offButton) { + Script.clearInterval(blockSpawner); + } + if(clickedOverlay == deleteButton){ + destroyStuff(); + } +} + +generateFloor(); + +function cleanup() { + // for (var i = 0; i < floorTiles.length; i++) { + // Entities.deleteEntity(floorTiles[i]); + // } + // for (var i = 0; i < blocks.length; i++) { + // Entities.deleteEntity(blocks[i]); + // } + Overlays.deleteOverlay(offButton); + Overlays.deleteOverlay(deleteButton) + Script.clearInterval(blockSpawner); +} + +function destroyStuff() { + for (var i = 0; i < floorTiles.length; i++) { + Entities.deleteEntity(floorTiles[i]); + } + for (var i = 0; i < blocks.length; i++) { + Entities.deleteEntity(blocks[i]); + } + Script.clearInterval(blockSpawner); + +} + +function randFloat(low, high) { + return Math.floor(low + Math.random() * (high - low)); +} + +function map(value, min1, max1, min2, max2) { + return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); +} + +Script.scriptEnding.connect(cleanup); +Controller.mousePressEvent.connect(mousePressEvent); \ No newline at end of file From c3c701f80753e05acaf77732cdbd8e8f9b3cab72 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 15:23:01 -0700 Subject: [PATCH 57/80] polyvox no longer has a color --- libraries/entities/src/PolyVoxEntityItem.cpp | 13 ------------- libraries/gpu/src/gpu/Resource.h | 4 ++-- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index 5ba74dbff5..da54f62337 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -43,13 +43,6 @@ PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID, const Ent EntityItemProperties PolyVoxEntityItem::getProperties() const { EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class - - // properties._color = getXColor(); - // properties._colorChanged = false; - // properties._glowLevel = getGlowLevel(); - // properties._glowLevelChanged = false; - - COPY_ENTITY_PROPERTY_TO_PROPERTIES(color, getXColor); COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelVolumeSize, getVoxelVolumeSize); COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelData, getVoxelData); COPY_ENTITY_PROPERTY_TO_PROPERTIES(voxelSurfaceStyle, getVoxelSurfaceStyle); @@ -60,8 +53,6 @@ EntityItemProperties PolyVoxEntityItem::getProperties() const { bool PolyVoxEntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = false; somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class - - SET_ENTITY_PROPERTY_FROM_PROPERTIES(color, setXColor); SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelVolumeSize, setVoxelVolumeSize); SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelData, setVoxelData); SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelSurfaceStyle, setVoxelSurfaceStyle); @@ -86,7 +77,6 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat int bytesRead = 0; const unsigned char* dataAt = data; - READ_ENTITY_PROPERTY(PROP_COLOR, rgbColor, setColor); READ_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, glm::vec3, setVoxelVolumeSize); READ_ENTITY_PROPERTY(PROP_VOXEL_DATA, QByteArray, setVoxelData); READ_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, uint16_t, setVoxelSurfaceStyle); @@ -98,7 +88,6 @@ int PolyVoxEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* dat // TODO: eventually only include properties changed since the params.lastViewFrustumSent time EntityPropertyFlags PolyVoxEntityItem::getEntityProperties(EncodeBitstreamParams& params) const { EntityPropertyFlags requestedProperties = EntityItem::getEntityProperties(params); - requestedProperties += PROP_COLOR; requestedProperties += PROP_VOXEL_VOLUME_SIZE; requestedProperties += PROP_VOXEL_DATA; requestedProperties += PROP_VOXEL_SURFACE_STYLE; @@ -114,7 +103,6 @@ void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeB OctreeElement::AppendState& appendState) const { bool successPropertyFits = true; - APPEND_ENTITY_PROPERTY(PROP_COLOR, getColor()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_VOLUME_SIZE, getVoxelVolumeSize()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_DATA, getVoxelData()); APPEND_ENTITY_PROPERTY(PROP_VOXEL_SURFACE_STYLE, (uint16_t) getVoxelSurfaceStyle()); @@ -123,7 +111,6 @@ void PolyVoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeB void PolyVoxEntityItem::debugDump() const { quint64 now = usecTimestampNow(); qCDebug(entities) << " POLYVOX EntityItem id:" << getEntityItemID() << "---------------------------------------------"; - qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2]; qCDebug(entities) << " position:" << debugTreeVector(_position); qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 21202f9354..87b6f82b89 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -319,7 +319,7 @@ public: // the number of elements of the specified type fitting in the view size template Index getNum() const { - return Index(_size / _stride); + return Index(_size / _stride); } template const T& get() const { @@ -371,7 +371,7 @@ public: } template T& edit(const Index index) const { - Resource::Size elementOffset = index * _stride + _offset; + Resource::Size elementOffset = index * _stride + _offset; #if _DEBUG if (!_buffer) { qDebug() << "Accessing null gpu::buffer!"; From 25df7771322d6ed7afbe9a80f011350846d11db6 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 16:15:58 -0700 Subject: [PATCH 58/80] fix polyfox url --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 2c05ddbb72..eeabb35c21 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -3,7 +3,7 @@ set(EXTERNAL_NAME polyvox) include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} - URL https://s3.amazonaws.com/hifi-public/dependencies/polyvox-master-2015-5-27.zip + URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip URL_MD5 f1241daae74ff69b7e31961edaff1555 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build From 05cd7fb8c49dea81527f1f065c6fc9fab1be9eb7 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 18:39:13 -0700 Subject: [PATCH 59/80] update polyvox external source --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index eeabb35c21..dc9494b07b 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 f1241daae74ff69b7e31961edaff1555 + URL_MD5 fa4de29655f8a23ad8c7cbdb9cd1b39b CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From aff82a90cef224d2a549a07272e9578a2c75f91f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 19:16:50 -0700 Subject: [PATCH 60/80] try, try again --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index dc9494b07b..05acd2bae6 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 fa4de29655f8a23ad8c7cbdb9cd1b39b + URL_MD5 20f294773ff4b3f81402ead0a4a19d71 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 00296faa5186b19f3819c88f146a30cdd31ac6cc Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 20:00:37 -0700 Subject: [PATCH 61/80] trying to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 05acd2bae6..4ad5b012f1 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 20f294773ff4b3f81402ead0a4a19d71 + URL_MD5 051098f5f7dcad555a3febf9a0ec0a2c CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 6711c64cc6ab9efec4aa9960e27b821405517f61 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 20:20:37 -0700 Subject: [PATCH 62/80] trying to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 4ad5b012f1..ed781d96b5 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 051098f5f7dcad555a3febf9a0ec0a2c + URL_MD5 b6944ed34efacce4978187e57803e331 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From f4b7a410066a35d11d75d334fe67eb16b0744254 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 20:46:50 -0700 Subject: [PATCH 63/80] trying to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index ed781d96b5..2011c4c3ea 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 b6944ed34efacce4978187e57803e331 + URL_MD5 771cfa6c983941e51d5f5cfd79c192a3 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 5e79b03faf2aa83e0b8619be121b646bc857fa9f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 20:55:16 -0700 Subject: [PATCH 64/80] trying to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 2011c4c3ea..82a2219561 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 771cfa6c983941e51d5f5cfd79c192a3 + URL_MD5 c1946dbb18bef945856a8ed1029725b2 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 5b62714ba4a39f931de6af0e4e022429e4375bd0 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 21:09:48 -0700 Subject: [PATCH 65/80] trying again to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 82a2219561..037035af33 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 c1946dbb18bef945856a8ed1029725b2 + URL_MD5 a2fd9c02eba9e2eed47080dac365ef91 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 1026da18b2ebf933ac8d2248783e1889a358cd05 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 21:32:20 -0700 Subject: [PATCH 66/80] trying again to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 037035af33..b07b36cbb4 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 a2fd9c02eba9e2eed47080dac365ef91 + URL_MD5 ff28b42960b576342a89f637af076f48 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 6a1ea820e76d4c1fada2b46d42ff1566a8ed0d39 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 21:50:35 -0700 Subject: [PATCH 67/80] trying again to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index b07b36cbb4..256a7750ac 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 ff28b42960b576342a89f637af076f48 + URL_MD5 afc347069d3f46c4d4f4ec7f0f2bfe5c CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From b024bd0ff2e8735b5b91ca720746b4b34908ce70 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 27 May 2015 22:00:20 -0700 Subject: [PATCH 68/80] trying again to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 256a7750ac..f1788e0058 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 afc347069d3f46c4d4f4ec7f0f2bfe5c + URL_MD5 b96a5bfa41ddc4895fce1e968bb59955 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From e5bec4251255cccd29c38170bcc77287f256546a Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Wed, 27 May 2015 23:36:00 -0700 Subject: [PATCH 69/80] Fix mouse emulation picking and pointer positioning for the hydra --- interface/src/ui/ApplicationOverlay.cpp | 75 ++++++++++--------------- interface/src/ui/ApplicationOverlay.h | 2 +- 2 files changed, 32 insertions(+), 45 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index c65de2afb0..8a64630266 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -356,7 +356,7 @@ void ApplicationOverlay::displayOverlayTextureHmd(Camera& whichCamera) { }); if (!Application::getInstance()->isMouseHidden()) { - renderPointersOculus(myAvatar->getDefaultEyePosition()); + renderPointersOculus(); } glDepthMask(GL_TRUE); glDisable(GL_TEXTURE_2D); @@ -486,49 +486,40 @@ void ApplicationOverlay::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origi direction = glm::normalize(intersectionWithUi - origin); } +glm::vec2 getPolarCoordinates(const PalmData& palm) { + MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); + auto avatarOrientation = myAvatar->getOrientation(); + auto eyePos = myAvatar->getDefaultEyePosition(); + glm::vec3 tip = myAvatar->getLaserPointerTipPosition(&palm); + // Direction of the tip relative to the eye + glm::vec3 tipDirection = tip - eyePos; + // orient into avatar space + tipDirection = glm::inverse(avatarOrientation) * tipDirection; + // Normalize for trig functions + tipDirection = glm::normalize(tipDirection); + // Convert to polar coordinates + glm::vec2 polar(glm::atan(tipDirection.x, -tipDirection.z), glm::asin(tipDirection.y)); + return polar; +} + //Caculate the click location using one of the sixense controllers. Scale is not applied QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { - MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); - - glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm); - glm::vec3 eyePos = myAvatar->getHead()->getEyePosition(); - glm::quat invOrientation = glm::inverse(myAvatar->getOrientation()); - //direction of ray goes towards camera - glm::vec3 dir = invOrientation * glm::normalize(qApp->getCamera()->getPosition() - tip); - glm::vec3 tipPos = invOrientation * (tip - eyePos); - QPoint rv; auto canvasSize = qApp->getCanvasSize(); if (qApp->isHMDMode()) { float t; - - //We back the ray up by dir to ensure that it will not start inside the UI. - glm::vec3 adjustedPos = tipPos - dir; - //Find intersection of crosshair ray. - if (raySphereIntersect(dir, adjustedPos, _oculusUIRadius * myAvatar->getScale(), &t)){ - glm::vec3 collisionPos = adjustedPos + dir * t; - //Normalize it in case its not a radius of 1 - collisionPos = glm::normalize(collisionPos); - //If we hit the back hemisphere, mark it as not a collision - if (collisionPos.z > 0) { - rv.setX(INT_MAX); - rv.setY(INT_MAX); - } else { - - float u = asin(collisionPos.x) / (_textureFov)+0.5f; - float v = 1.0 - (asin(collisionPos.y) / (_textureFov)+0.5f); - - rv.setX(u * canvasSize.x); - rv.setY(v * canvasSize.y); - } - } else { - //if they did not click on the overlay, just set the coords to INT_MAX - rv.setX(INT_MAX); - rv.setY(INT_MAX); - } + glm::vec2 polar = getPolarCoordinates(*palm); + glm::vec2 point = sphericalToScreen(-polar); + rv.rx() = point.x; + rv.ry() = point.y; } else { + MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); glm::dmat4 projection; qApp->getProjectionMatrix(&projection); + glm::quat invOrientation = glm::inverse(myAvatar->getOrientation()); + glm::vec3 eyePos = myAvatar->getDefaultEyePosition(); + glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm); + glm::vec3 tipPos = invOrientation * (tip - eyePos); glm::vec4 clipSpacePos = glm::vec4(projection * glm::dvec4(tipPos, 1.0)); glm::vec3 ndcSpacePos; @@ -729,7 +720,7 @@ void ApplicationOverlay::renderControllerPointers() { } } -void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { +void ApplicationOverlay::renderPointersOculus() { glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(_crosshairTexture)); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_MODELVIEW); @@ -737,16 +728,12 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { //Controller Pointers MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); for (int i = 0; i < (int)myAvatar->getHand()->getNumPalms(); i++) { - PalmData& palm = myAvatar->getHand()->getPalms()[i]; if (palm.isActive()) { - glm::vec3 tip = myAvatar->getLaserPointerTipPosition(&palm); - glm::vec3 tipDirection = glm::normalize(glm::inverse(myAvatar->getOrientation()) * (tip - eyePos)); - float pitch = -glm::asin(tipDirection.y); - float yawSign = glm::sign(-tipDirection.x); - float yaw = glm::acos(-tipDirection.z) * - ((yawSign == 0.0f) ? 1.0f : yawSign); - glm::quat orientation = glm::quat(glm::vec3(pitch, yaw, 0.0f)); + glm::vec2 polar = getPolarCoordinates(palm); + // Convert to quaternion + glm::quat orientation = glm::quat(glm::vec3(polar.y, -polar.x, 0.0f)); + // Render reticle at location renderReticle(orientation, _alpha); } } diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 34beb98682..864bd95b4e 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -102,7 +102,7 @@ private: void renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder); void renderControllerPointers(); - void renderPointersOculus(const glm::vec3& eyePos); + void renderPointersOculus(); void renderAudioMeter(); void renderCameraToggle(); From 24bb17f7b2115255e5a99f6de06cdb6b484df3e1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 28 May 2015 06:36:31 -0700 Subject: [PATCH 70/80] trying again to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index f1788e0058..bfaebb91f8 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 b96a5bfa41ddc4895fce1e968bb59955 + URL_MD5 10f46ac4c6a6c099a654b7863ec03659 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From aefd34f8d686d301d9d667c543725064cc3cebdf Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 28 May 2015 06:43:31 -0700 Subject: [PATCH 71/80] trying again to get polyvox to build on osx --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index bfaebb91f8..76302f9b4a 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-5-27.zip - URL_MD5 10f46ac4c6a6c099a654b7863ec03659 + URL_MD5 e3dd09a24df4db29ba370e3bea753388 CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 03062fccd3b8f004bdf7c773e6d075547bbc955a Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 28 May 2015 10:17:47 -0700 Subject: [PATCH 72/80] remove whiteboard by default in pointer.js --- examples/pointer.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/examples/pointer.js b/examples/pointer.js index eebe4ec5be..32698209a4 100644 --- a/examples/pointer.js +++ b/examples/pointer.js @@ -67,20 +67,6 @@ var pointerButton = Overlays.addOverlay("image", { var center = Vec3.sum(MyAvatar.position, Vec3.multiply(2.0, Quat.getFront(Camera.getOrientation()))); center.y += 0.5; -var whiteBoard = Entities.addEntity({ - type: "Box", - position: center, - dimensions: { - x: 1, - y: 1, - z: .001 - }, - color: { - red: 255, - green: 255, - blue: 255 - } -}); function calculateNearLinePosition(targetPosition) { var handPosition = MyAvatar.getRightPalmPosition(); @@ -243,7 +229,6 @@ function keyReleaseEvent(event) { } function cleanup() { - Entities.deleteEntity(whiteBoard); for (var i = 0; i < strokes.length; i++) { Entities.deleteEntity(strokes[i]); } From e46c24ea58cae7e7b4556b9e83dd8b689e135e4a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 28 May 2015 10:27:59 -0700 Subject: [PATCH 73/80] code review --- .../entities-renderer/src/RenderablePolyVoxEntityItem.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 933b7ad1ef..977a6511c8 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -268,8 +268,10 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o RaycastFunctor callback; raycastResult = PolyVox::raycastWithDirection(_volData, start, pvDirection, callback); - if (raycastResult == PolyVox::RaycastResults::Completed) // the ray completed its path -- nothing was hit. + if (raycastResult == PolyVox::RaycastResults::Completed) { + // the ray completed its path -- nothing was hit. return false; + } glm::vec4 intersectedWorldPosition = voxelToWorldMatrix() * callback._result; From 7547ef6ea436e32e2ce145cad098bbb62a7b192e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 28 May 2015 10:29:07 -0700 Subject: [PATCH 74/80] code review --- libraries/entities/src/PolyVoxEntityItem.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index da54f62337..a46fdb2682 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -51,8 +51,7 @@ EntityItemProperties PolyVoxEntityItem::getProperties() const { } bool PolyVoxEntityItem::setProperties(const EntityItemProperties& properties) { - bool somethingChanged = false; - somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class + bool somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelVolumeSize, setVoxelVolumeSize); SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelData, setVoxelData); SET_ENTITY_PROPERTY_FROM_PROPERTIES(voxelSurfaceStyle, setVoxelSurfaceStyle); From ab86b1d90a570cd87ff62fb8d48883135adc8e55 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 28 May 2015 10:29:23 -0700 Subject: [PATCH 75/80] code review --- libraries/gpu/src/gpu/Resource.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 87b6f82b89..42897e9947 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -250,11 +250,11 @@ public: bool operator==(const Iterator& iterator) const { return (_ptr == iterator.getConstPtr()); } bool operator!=(const Iterator& iterator) const { return (_ptr != iterator.getConstPtr()); } - void movePtr(const Index& movement) { - auto byteptr = ((Byte*)_ptr); - byteptr += _stride * movement; - _ptr = (T*)byteptr; - } + void movePtr(const Index& movement) { + auto byteptr = ((Byte*)_ptr); + byteptr += _stride * movement; + _ptr = (T*)byteptr; + } Iterator& operator+=(const Index& movement) { movePtr(movement); @@ -313,9 +313,9 @@ public: }; template Iterator begin() { return Iterator(&edit(0), _stride); } - template Iterator end() { return Iterator(&edit(getNum()), _stride); } - template Iterator cbegin() const { return Iterator(&get(0), _stride); } - template Iterator cend() const { return Iterator(&get(getNum()), _stride); } + template Iterator end() { return Iterator(&edit(getNum()), _stride); } + template Iterator cbegin() const { return Iterator(&get(0), _stride); } + template Iterator cend() const { return Iterator(&get(getNum()), _stride); } // the number of elements of the specified type fitting in the view size template Index getNum() const { From b7e3461e1a7119333856f44f05c08d137b8d1948 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 28 May 2015 12:21:38 -0700 Subject: [PATCH 76/80] restore _created magic --- libraries/entities/src/EntityItem.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index e0297fe7d4..64196d1c35 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -957,9 +957,6 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { #endif setLastEdited(now); somethingChangedNotification(); // notify derived classes that something has changed - if (_created == UNKNOWN_CREATED_TIME) { - _created = now; - } if (getDirtyFlags() & (EntityItem::DIRTY_TRANSFORM | EntityItem::DIRTY_VELOCITIES)) { // anything that sets the transform or velocity must update _lastSimulated which is used // for kinematic extrapolation (e.g. we want to extrapolate forward from this moment @@ -968,6 +965,16 @@ bool EntityItem::setProperties(const EntityItemProperties& properties) { } } + // timestamps + quint64 timestamp = properties.getCreated(); + if (_created == UNKNOWN_CREATED_TIME && timestamp != UNKNOWN_CREATED_TIME) { + quint64 now = usecTimestampNow(); + if (timestamp > now) { + timestamp = now; + } + _created = timestamp; + } + return somethingChanged; } From b90d35c0c0ed59d722d9f81b07f6d77674a34ac4 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 28 May 2015 12:22:17 -0700 Subject: [PATCH 77/80] restore code to fix box entites not rendering boxes wouldn't render when in an otherwise empty domain --- libraries/render-utils/src/DeferredLightingEffect.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 795b2a4389..54e5388ec8 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -93,16 +93,16 @@ void DeferredLightingEffect::init(AbstractViewStateInterface* viewState) { } void DeferredLightingEffect::bindSimpleProgram() { - // DependencyManager::get()->setPrimaryDrawBuffers(true, true, true); + DependencyManager::get()->setPrimaryDrawBuffers(true, true, true); _simpleProgram.bind(); _simpleProgram.setUniformValue(_glowIntensityLocation, DependencyManager::get()->getIntensity()); - // glDisable(GL_BLEND); + glDisable(GL_BLEND); } void DeferredLightingEffect::releaseSimpleProgram() { - // glEnable(GL_BLEND); + glEnable(GL_BLEND); _simpleProgram.release(); - // DependencyManager::get()->setPrimaryDrawBuffers(true, false, false); + DependencyManager::get()->setPrimaryDrawBuffers(true, false, false); } void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color) { From 0c6de897f55c7c61d86420bad227cdf08baf2a6f Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 28 May 2015 12:26:29 -0700 Subject: [PATCH 78/80] replace tab with spaces --- tests/physics/src/MeshMassPropertiesTests.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/physics/src/MeshMassPropertiesTests.h b/tests/physics/src/MeshMassPropertiesTests.h index ab352bfce2..07cd774d34 100644 --- a/tests/physics/src/MeshMassPropertiesTests.h +++ b/tests/physics/src/MeshMassPropertiesTests.h @@ -15,7 +15,7 @@ namespace MeshMassPropertiesTests{ void testParallelAxisTheorem(); void testTetrahedron(); void testOpenTetrahedonMesh(); - void testClosedTetrahedronMesh(); + void testClosedTetrahedronMesh(); void testBoxAsMesh(); void runAllTests(); } From 131827a82b7a04e4e77354d9cc2ea36fe49acb96 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 28 May 2015 14:27:49 -0700 Subject: [PATCH 79/80] libraries/entities doesn't need polyvox, only libraries/entities-renderer --- libraries/entities-renderer/CMakeLists.txt | 6 +++++- libraries/entities/CMakeLists.txt | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index 6c7fa04a21..029d742b09 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -3,7 +3,7 @@ set(TARGET_NAME entities-renderer) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Widgets OpenGL Network Script) -add_dependency_external_projects(glm) +add_dependency_external_projects(glm polyvox) find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) @@ -12,4 +12,8 @@ find_package(Bullet REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) +find_package(PolyVox REQUIRED) +target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${POLYVOX_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${POLYVOX_LIBRARIES}) + link_hifi_libraries(shared gpu script-engine render-utils) diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index c4334edb3a..d21906fa3f 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -7,14 +7,10 @@ add_dependency_external_projects(glm) find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) -add_dependency_external_projects(bullet polyvox) +add_dependency_external_projects(bullet) find_package(Bullet REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) -find_package(PolyVox REQUIRED) -target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${POLYVOX_INCLUDE_DIRS}) -target_link_libraries(${TARGET_NAME} ${POLYVOX_LIBRARIES}) - link_hifi_libraries(avatars shared octree gpu model fbx networking animation environment) From 94edb72b47a497aad1f73b0b04d574c3a2bcab07 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 28 May 2015 14:30:06 -0700 Subject: [PATCH 80/80] oops --- libraries/entities-renderer/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index 029d742b09..a94bfb5f97 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -3,7 +3,7 @@ set(TARGET_NAME entities-renderer) # use setup_hifi_library macro to setup our project and link appropriate Qt modules setup_hifi_library(Widgets OpenGL Network Script) -add_dependency_external_projects(glm polyvox) +add_dependency_external_projects(glm) find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) @@ -12,6 +12,7 @@ find_package(Bullet REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) +add_dependency_external_projects(polyvox) find_package(PolyVox REQUIRED) target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${POLYVOX_INCLUDE_DIRS}) target_link_libraries(${TARGET_NAME} ${POLYVOX_LIBRARIES})