From 6f4683206936b124d092a4d5ed75e355f4a95a71 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 25 Aug 2015 21:30:38 -0700 Subject: [PATCH] clean up some commented code. attempt to fix ray-casting in non-edged polyvox -- still isn't correct --- examples/voxels.js | 35 +------------- .../src/RenderablePolyVoxEntityItem.cpp | 46 +++++++++++-------- 2 files changed, 29 insertions(+), 52 deletions(-) diff --git a/examples/voxels.js b/examples/voxels.js index 893aa264d8..4c344a7eee 100644 --- a/examples/voxels.js +++ b/examples/voxels.js @@ -1,17 +1,10 @@ var controlHeld = false; var shiftHeld = false; - Script.include([ "libraries/toolBars.js", ]); - -// http://headache.hungry.com/~seth/hifi/voxel-add.svg -// http://headache.hungry.com/~seth/hifi/voxel-add.svg -// http://headache.hungry.com/~seth/hifi/voxel-delete.svg -// http://headache.hungry.com/~seth/hifi/voxel-terrain.svg - var isActive = false; var toolIconUrl = "http://headache.hungry.com/~seth/hifi/"; var toolHeight = 50; @@ -23,7 +16,6 @@ var deletingVoxels = false; offAlpha = 0.5; onAlpha = 0.9; - function floorVector(v) { return {x: Math.floor(v.x), y: Math.floor(v.y), z: Math.floor(v.z)}; } @@ -193,7 +185,7 @@ function addTerrainBlock() { position: baseLocation, dimensions: { x: 16, y: 16, z: 16 }, voxelVolumeSize: {x:16, y:16, z:16}, - voxelSurfaceStyle: 3 + voxelSurfaceStyle: 2 }); Entities.setAllVoxels(polyVoxId, 255); @@ -205,25 +197,6 @@ function addTerrainBlock() { } } - // for (var x = 1; x <= 14; x++) { - // Entities.setVoxel(polyVoxId, {x: x, y: 1, z: 1}, 255); - // Entities.setVoxel(polyVoxId, {x: x, y: 14, z: 1}, 255); - // Entities.setVoxel(polyVoxId, {x: x, y: 1, z: 14}, 255); - // Entities.setVoxel(polyVoxId, {x: x, y: 14, z: 14}, 255); - // } - // for (var y = 2; y <= 13; y++) { - // Entities.setVoxel(polyVoxId, {x: 1, y: y, z: 1}, 255); - // Entities.setVoxel(polyVoxId, {x: 14, y: y, z: 1}, 255); - // Entities.setVoxel(polyVoxId, {x: 1, y: y, z: 14}, 255); - // Entities.setVoxel(polyVoxId, {x: 14, y: y, z: 14}, 255); - // } - // for (var z = 2; z <= 13; z++) { - // Entities.setVoxel(polyVoxId, {x: 1, y: 1, z: z}, 255); - // Entities.setVoxel(polyVoxId, {x: 14, y: 1, z: z}, 255); - // Entities.setVoxel(polyVoxId, {x: 1, y: 14, z: z}, 255); - // Entities.setVoxel(polyVoxId, {x: 14, y: 14, z: z}, 255); - // } - return true; } @@ -252,12 +225,6 @@ function attemptVoxelChange(pickRayDir, intersection) { doDelete = addingVoxels; } - // } else if (shiftHeld) { - // // return Entities.setAllVoxels(intersection.entityID, 255); - // } - - // Entities.setVoxelSphere(id, intersection.intersection, radius, 0) - if (doDelete) { var toErasePosition = Vec3.sum(voxelPosition, Vec3.multiply(pickRayDirInVoxelSpace, 0.1)); return Entities.setVoxel(intersection.entityID, floorVector(toErasePosition), 0); diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index f220518e7e..e986866bce 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -369,6 +369,34 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o return true; } + +PolyVox::RaycastResult RenderablePolyVoxEntityItem::doRayCast(glm::vec4 originInVoxel, + glm::vec4 farInVoxel, + glm::vec4& result) const { + PolyVox::Vector3DFloat startPoint(originInVoxel.x, originInVoxel.y, originInVoxel.z); + PolyVox::Vector3DFloat endPoint(farInVoxel.x, farInVoxel.y, farInVoxel.z); + + _volDataLock.lockForRead(); + RaycastFunctor callback(_volData); + PolyVox::RaycastResult raycastResult = PolyVox::raycastWithEndpoints(_volData, startPoint, endPoint, callback); + _volDataLock.unlock(); + + // result is in voxel-space coordinates. + switch (_voxelSurfaceStyle) { + case PolyVoxEntityItem::SURFACE_MARCHING_CUBES: + case PolyVoxEntityItem::SURFACE_CUBIC: + result = callback._result + glm::vec4(0.5f, 0.5f, 0.5f, 0.0f); + break; + case PolyVoxEntityItem::SURFACE_EDGED_CUBIC: + case PolyVoxEntityItem::SURFACE_EDGED_MARCHING_CUBES: + result = callback._result - glm::vec4(0.5f, 0.5f, 0.5f, 0.0f); + break; + } + + return raycastResult; +} + + // virtual ShapeType RenderablePolyVoxEntityItem::getShapeType() const { return SHAPE_TYPE_COMPOUND; @@ -683,24 +711,6 @@ bool RenderablePolyVoxEntityItem::updateOnCount(int x, int y, int z, uint8_t toV } -PolyVox::RaycastResult RenderablePolyVoxEntityItem::doRayCast(glm::vec4 originInVoxel, - glm::vec4 farInVoxel, - glm::vec4& result) const { - PolyVox::Vector3DFloat startPoint(originInVoxel.x, originInVoxel.y, originInVoxel.z); - PolyVox::Vector3DFloat endPoint(farInVoxel.x, farInVoxel.y, farInVoxel.z); - - _volDataLock.lockForRead(); - RaycastFunctor callback(_volData); - PolyVox::RaycastResult raycastResult = PolyVox::raycastWithEndpoints(_volData, startPoint, endPoint, callback); - _volDataLock.unlock(); - - // result is in voxel-space coordinates. - result = callback._result - glm::vec4(0.5f, 0.5f, 0.5f, 0.0f); - return raycastResult; -} - - - void RenderablePolyVoxEntityItem::decompressVolumeData() { _threadRunning.acquire(); QtConcurrent::run(this, &RenderablePolyVoxEntityItem::decompressVolumeDataAsync);