| @@ -414,19 +414,41 @@ bool RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float r · 413 unmodified lines |
| 414 | 414 | glm::ivec3 lowI = glm::clamp(low, glm::vec3(0.0f), _voxelVolumeSize); |
| 415 | 415 | glm::ivec3 highI = glm::clamp(high, glm::vec3(0.0f), _voxelVolumeSize); |
| 416 | 416 | |
| 417 | + // This three-level for loop iterates over every voxel in the volume that might be in the sphere |
| 418 | + // withWriteLock([&] { |
| 419 | + // for (int z = lowI.z; z < highI.z; z++) { |
| 420 | + // for (int y = lowI.y; y < highI.y; y++) { |
| 421 | + // for (int x = lowI.x; x < highI.x; x++) { |
| 422 | + // // Store our current position as a vector... |
| 423 | + // glm::vec4 pos(x + 0.5f, y + 0.5f, z + 0.5f, 1.0); // consider voxels cenetered on their coordinates |
| 424 | + // // convert to world coordinates |
| 425 | + // glm::vec3 worldPos = glm::vec3(vtwMatrix * pos); |
| 426 | + // // compute how far the current position is from the center of the volume |
| 427 | + // float fDistToCenter = glm::distance(worldPos, centerWorldCoords); |
| 428 | + // // If the current voxel is less than 'radius' units from the center then we set its value |
| 429 | + // if (fDistToCenter <= radiusWorldCoords) { |
| 430 | + // result |= setVoxelInternal(x, y, z, toValue); |
| 431 | + // } |
| 432 | + // } |
| 433 | + // } |
| 434 | + // } |
| 435 | + // }); |
| 436 | + |
| 437 | + |
| 438 | + glm::vec3 radials(radiusWorldCoords / voxelSize.x, |
| 439 | + radiusWorldCoords / voxelSize.y, |
| 440 | + radiusWorldCoords / voxelSize.z); |
| 441 | + float minRadial = glm::min(radials.x, radials.y); |
| 442 | + minRadial = glm::min(minRadial, radials.z); |
| 443 | + |
| 417 | 444 | // This three-level for loop iterates over every voxel in the volume that might be in the sphere |
| 418 | 445 | withWriteLock([&] { |
| 419 | 446 | for (int z = lowI.z; z < highI.z; z++) { |
| 420 | 447 | for (int y = lowI.y; y < highI.y; y++) { |
| 421 | 448 | for (int x = lowI.x; x < highI.x; x++) { |
| 422 | | − // Store our current position as a vector... |
| 423 | | − glm::vec4 pos(x + 0.5f, y + 0.5f, z + 0.5f, 1.0); // consider voxels cenetered on their coordinates |
| 424 | | − // convert to world coordinates |
| 425 | | − glm::vec3 worldPos = glm::vec3(vtwMatrix * pos); |
| 426 | | − // compute how far the current position is from the center of the volume |
| 427 | | − float fDistToCenter = glm::distance(worldPos, centerWorldCoords); |
| 428 | | − // If the current voxel is less than 'radius' units from the center then we set its value |
| 429 | | − if (fDistToCenter <= radiusWorldCoords) { |
| 449 | + AABox voxelBox(glm::vec3(x - 0.5f, y - 0.5f, z - 0.5f), glm::vec3(1.0f, 1.0f, 1.0f)); |
| 450 | + // if (voxelBox.touchesSphere(centerInVoxelCoords, minRadial)) { |
| 451 | + if (voxelBox.touchesAAEllipsoid(centerInVoxelCoords, radials)) { |
| 430 | 452 | result |= setVoxelInternal(x, y, z, toValue); |
| 431 | 453 | } |
| 432 | 454 | } |
| @@ -434,6 +456,7 @@ bool RenderablePolyVoxEntityItem::setSphere(glm::vec3 centerWorldCoords, float r · 1 unmodified line |
| 434 | 456 | } |
| 435 | 457 | }); |
| 436 | 458 | |
| 459 | + |
| 437 | 460 | if (result) { |
| 438 | 461 | compressVolumeDataAndSendEditPacket(); |
| 439 | 462 | } |