mirror of
https://github.com/overte-org/overte.git
synced 2025-08-05 15:39:57 +02:00
make voxel editing work, even if the voxel-space is empty
This commit is contained in:
parent
f8617bab2d
commit
f2d8c78a88
1 changed files with 41 additions and 11 deletions
|
@ -2,6 +2,32 @@ var controlHeld = false;
|
||||||
var shiftHeld = false;
|
var shiftHeld = false;
|
||||||
|
|
||||||
|
|
||||||
|
function attemptVoxelChange(intersection) {
|
||||||
|
var ids = Entities.findEntities(intersection.intersection, 10);
|
||||||
|
var success = false;
|
||||||
|
for (var i = 0; i < ids.length; i++) {
|
||||||
|
var id = ids[i];
|
||||||
|
if (controlHeld) {
|
||||||
|
// hold control to erase a sphere
|
||||||
|
if (Entities.setVoxelSphere(id, intersection.intersection, 1.0, 0)) {
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
} else if (shiftHeld) {
|
||||||
|
// hold shift to set all voxels to 255
|
||||||
|
if (Entities.setAllVoxels(id, 255)) {
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// no modifier key means to add a sphere
|
||||||
|
if (Entities.setVoxelSphere(id, intersection.intersection, 1.0, 255)) {
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function mousePressEvent(event) {
|
function mousePressEvent(event) {
|
||||||
if (!event.isLeftButton) {
|
if (!event.isLeftButton) {
|
||||||
return;
|
return;
|
||||||
|
@ -9,20 +35,24 @@ function mousePressEvent(event) {
|
||||||
|
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||||
var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking
|
var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking
|
||||||
// var props = Entities.getEntityProperties(intersection.entityID);
|
|
||||||
|
// we've used a picking ray to decide where to add the new sphere of voxels. If we pick nothing
|
||||||
|
// or if we pick a non-PolyVox entity, we fall through to the next picking attempt.
|
||||||
if (intersection.intersects) {
|
if (intersection.intersects) {
|
||||||
var ids = Entities.findEntities(intersection.intersection, 10);
|
if (attemptVoxelChange(intersection)) {
|
||||||
for (var i = 0; i < ids.length; i++) {
|
print("here0");
|
||||||
var id = ids[i];
|
return;
|
||||||
if (controlHeld) {
|
|
||||||
Entities.setVoxelSphere(id, intersection.intersection, 1.0, 0);
|
|
||||||
} else if (shiftHeld) {
|
|
||||||
Entities.setAllVoxels(id, 255);
|
|
||||||
} else {
|
|
||||||
Entities.setVoxelSphere(id, intersection.intersection, 1.0, 255);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the PolyVox entity is empty, we can't pick against its voxel. try picking against it's
|
||||||
|
// bounding box, instead.
|
||||||
|
intersection = Entities.findRayIntersection(pickRay, false); // bounding box picking
|
||||||
|
if (intersection.intersects) {
|
||||||
|
print("here1");
|
||||||
|
attemptVoxelChange(intersection);
|
||||||
|
}
|
||||||
|
print("here2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue