From 802f72c732a131c7ae1f4a2376209d22b8ee4247 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 7 Feb 2014 15:06:32 -0800 Subject: [PATCH] more ray picking and intersection work --- interface/src/Application.cpp | 1 + .../voxels/src/VoxelsScriptingInterface.cpp | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 39e1868dd0..13e09eedf3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4101,6 +4101,7 @@ void Application::loadScript(const QString& fileNameString) { // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so // we can use the same ones from the application. scriptEngine->getVoxelsScriptingInterface()->setPacketSender(&_voxelEditSender); + scriptEngine->getVoxelsScriptingInterface()->setVoxelTree(_voxels.getTree()); scriptEngine->getParticlesScriptingInterface()->setPacketSender(&_particleEditSender); scriptEngine->getParticlesScriptingInterface()->setParticleTree(_particles.getTree()); diff --git a/libraries/voxels/src/VoxelsScriptingInterface.cpp b/libraries/voxels/src/VoxelsScriptingInterface.cpp index 34c91c8f60..af5f8ce3c2 100644 --- a/libraries/voxels/src/VoxelsScriptingInterface.cpp +++ b/libraries/voxels/src/VoxelsScriptingInterface.cpp @@ -44,5 +44,22 @@ void VoxelsScriptingInterface::eraseVoxel(float x, float y, float z, float scale RayToVoxelIntersectionResult VoxelsScriptingInterface::findRayIntersection(const PickRay& ray) { RayToVoxelIntersectionResult result; + if (_tree) { + if (_tree->tryLockForRead()) { + OctreeElement* element; + result.intersects = _tree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face); + if (result.intersects) { + VoxelTreeElement* voxel = (VoxelTreeElement*)element; + result.voxel.x = voxel->getCorner().x; + result.voxel.y = voxel->getCorner().y; + result.voxel.z = voxel->getCorner().z; + result.voxel.s = voxel->getScale(); + result.voxel.red = voxel->getColor()[0]; + result.voxel.green = voxel->getColor()[1]; + result.voxel.blue = voxel->getColor()[2]; + } + _tree->unlock(); + } + } return result; }