From d361c75b506d6194a004b238219c79bba8364632 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 26 Feb 2014 14:16:22 -0800 Subject: [PATCH] more work on seeing voxels --- examples/seeingVoxelsExample.js | 29 +++++++--- libraries/octree/src/OctreeHeadlessViewer.cpp | 58 +------------------ libraries/octree/src/OctreeHeadlessViewer.h | 2 + 3 files changed, 25 insertions(+), 64 deletions(-) diff --git a/examples/seeingVoxelsExample.js b/examples/seeingVoxelsExample.js index 46e06d201d..98445990a8 100644 --- a/examples/seeingVoxelsExample.js +++ b/examples/seeingVoxelsExample.js @@ -14,23 +14,29 @@ var yaw = 45; var yawMax = 70; var yawMin = 20; -var isLocal = true; +var isLocal = false; // set up our VoxelViewer with a position and orientation var orientation = Quat.fromPitchYawRoll(0, yaw, 0); -if (isLocal) { - MyAvatar.position = {x: 10, y: 0, z: 10}; - MyAvatar.orientation = orientation; -} else { - VoxelViewer.setPosition({x: 10, y: 0, z: 10}); - VoxelViewer.setOrientation(orientation); - VoxelViewer.queryOctree(); - Agent.isAvatar = true; +function init() { + if (isLocal) { + MyAvatar.position = {x: 10, y: 0, z: 10}; + MyAvatar.orientation = orientation; + } else { + VoxelViewer.setPosition({x: 10, y: 0, z: 10}); + VoxelViewer.setOrientation(orientation); + VoxelViewer.queryOctree(); + Agent.isAvatar = true; + } } function keepLooking() { //print("count =" + count); + + if (count == 0) { + init(); + } count++; if (count % 10 == 0) { yaw += yawDirection; @@ -46,6 +52,7 @@ function keepLooking() { } else { VoxelViewer.setOrientation(orientation); VoxelViewer.queryOctree(); + print("VoxelViewer.getOctreeElementsCount()=" + VoxelViewer.getOctreeElementsCount()); } } @@ -61,3 +68,7 @@ Script.willSendVisualDataCallback.connect(keepLooking); // register our scriptEnding callback Script.scriptEnding.connect(scriptEnding); + +// test for local... +Menu.isOptionChecked("Voxels"); +isLocal = true; // will only get here on local client diff --git a/libraries/octree/src/OctreeHeadlessViewer.cpp b/libraries/octree/src/OctreeHeadlessViewer.cpp index 55a0729742..4ab85e7de8 100644 --- a/libraries/octree/src/OctreeHeadlessViewer.cpp +++ b/libraries/octree/src/OctreeHeadlessViewer.cpp @@ -226,65 +226,13 @@ void OctreeHeadlessViewer::queryOctree() { int OctreeHeadlessViewer::parseOctreeStats(const QByteArray& packet, const SharedNodePointer& sourceNode) { - // But, also identify the sender, and keep track of the contained jurisdiction root for this server - // parse the incoming stats datas stick it in a temporary object for now, while we - // determine which server it belongs to OctreeSceneStats temp; int statsMessageLength = temp.unpackFromMessage(reinterpret_cast(packet.data()), packet.size()); + + // TODO: actually do something with these stats, like expose them to JS... + return statsMessageLength; - -#if 0 // CURRENTLY NOT YET IMPLEMENTED - - // quick fix for crash... why would voxelServer be NULL? - if (sourceNode) { - QUuid nodeUUID = sendingNode->getUUID(); - - // now that we know the node ID, let's add these stats to the stats for that node... - _voxelSceneStatsLock.lockForWrite(); - if (_octreeServerSceneStats.find(nodeUUID) != _octreeServerSceneStats.end()) { - _octreeServerSceneStats[nodeUUID].unpackFromMessage(reinterpret_cast(packet.data()), - packet.size()); - } else { - _octreeServerSceneStats[nodeUUID] = temp; - } - _voxelSceneStatsLock.unlock(); - - VoxelPositionSize rootDetails; - voxelDetailsForCode(temp.getJurisdictionRoot(), rootDetails); - - // see if this is the first we've heard of this node... - NodeToJurisdictionMap* jurisdiction = NULL; - if (sendingNode->getType() == NodeType::VoxelServer) { - jurisdiction = &_voxelServerJurisdictions; - } else { - jurisdiction = &_particleServerJurisdictions; - } - - - if (jurisdiction->find(nodeUUID) == jurisdiction->end()) { - printf("stats from new server... v[%f, %f, %f, %f]\n", - rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s); - - // Add the jurisditionDetails object to the list of "fade outs" - if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnVoxelServerChanges)) { - VoxelFade fade(VoxelFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE); - fade.voxelDetails = rootDetails; - const float slightly_smaller = 0.99f; - fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller; - _voxelFades.push_back(fade); - } - } - // store jurisdiction details for later use - // This is bit of fiddling is because JurisdictionMap assumes it is the owner of the values used to construct it - // but VoxelSceneStats thinks it's just returning a reference to it's contents. So we need to make a copy of the - // details from the VoxelSceneStats to construct the JurisdictionMap - JurisdictionMap jurisdictionMap; - jurisdictionMap.copyContents(temp.getJurisdictionRoot(), temp.getJurisdictionEndNodes()); - (*jurisdiction)[nodeUUID] = jurisdictionMap; - } - return statsMessageLength; -#endif } void OctreeHeadlessViewer::trackIncomingOctreePacket(const QByteArray& packet, diff --git a/libraries/octree/src/OctreeHeadlessViewer.h b/libraries/octree/src/OctreeHeadlessViewer.h index c058809acd..fc32dbc682 100644 --- a/libraries/octree/src/OctreeHeadlessViewer.h +++ b/libraries/octree/src/OctreeHeadlessViewer.h @@ -59,6 +59,8 @@ public slots: int getBoundaryLevelAdjust() const { return _boundaryLevelAdjust; } int getMaxPacketsPerSecond() const { return _maxPacketsPerSecond; } + unsigned getOctreeElementsCount() const { return _tree->getOctreeElementsCount(); } + private: ViewFrustum _viewFrustum; JurisdictionListener* _jurisdictionListener;