added Voxels.getVoxelAt() to inspect local tree

This commit is contained in:
ZappoMan 2014-02-23 13:18:36 -08:00
parent a8b34ae756
commit 892cc01dd9
3 changed files with 38 additions and 0 deletions

View file

@ -26,6 +26,12 @@ function mouseMoveEvent(event) {
print("intersection distance=" + intersection.distance);
print("intersection intersection.x/y/z=" + intersection.intersection.x + ", "
+ intersection.intersection.y + ", " + intersection.intersection.z);
// also test the getVoxelAt() api which should find and return same voxel
var voxelAt = Voxels.getVoxelAt(intersection.voxel.x, intersection.voxel.y, intersection.voxel.z, intersection.voxel.s);
print("voxelAt.x/y/z/s=" + voxelAt.x + ", " + voxelAt.y + ", " + voxelAt.z + ": " + voxelAt.s);
print("voxelAt.red/green/blue=" + voxelAt.red + ", " + voxelAt.green + ", " + voxelAt.blue);
}
}

View file

@ -12,6 +12,30 @@ void VoxelsScriptingInterface::queueVoxelAdd(PacketType addPacketType, VoxelDeta
getVoxelPacketSender()->queueVoxelEditMessages(addPacketType, 1, &addVoxelDetails);
}
VoxelDetail VoxelsScriptingInterface::getVoxelAt(float x, float y, float z, float scale) {
// setup a VoxelDetail struct with the data
VoxelDetail result = {0,0,0,0,0,0,0};
if (_tree) {
_tree->lockForRead();
VoxelTreeElement* voxel = static_cast<VoxelTreeElement*>(_tree->getOctreeElementAt(x / (float)TREE_SCALE, y / (float)TREE_SCALE,
z / (float)TREE_SCALE, scale / (float)TREE_SCALE));
_tree->unlock();
if (voxel) {
// Note: these need to be in voxel space because the VoxelDetail -> js converter will upscale
result.x = voxel->getCorner().x;
result.y = voxel->getCorner().y;
result.z = voxel->getCorner().z;
result.s = voxel->getScale();
result.red = voxel->getColor()[RED_INDEX];
result.green = voxel->getColor()[GREEN_INDEX];
result.blue = voxel->getColor()[BLUE_INDEX];
}
}
return result;
}
void VoxelsScriptingInterface::setVoxelNonDestructive(float x, float y, float z, float scale,
uchar red, uchar green, uchar blue) {
// setup a VoxelDetail struct with the data

View file

@ -30,6 +30,14 @@ public:
void setVoxelTree(VoxelTree* tree) { _tree = tree; }
public slots:
/// checks the local voxel tree for a voxel at the specified location and scale
/// \param x the x-coordinate of the voxel (in meter units)
/// \param y the y-coordinate of the voxel (in meter units)
/// \param z the z-coordinate of the voxel (in meter units)
/// \param scale the scale of the voxel (in meter units)
VoxelDetail getVoxelAt(float x, float y, float z, float scale);
/// queues the creation of a voxel which will be sent by calling process on the PacketSender
/// \param x the x-coordinate of the voxel (in meter units)
/// \param y the y-coordinate of the voxel (in meter units)