mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Add drag to add more voxels, turn off hover orbit voxels until in the script as function key
This commit is contained in:
parent
6b0c31e6e9
commit
cfa7f5e6ca
2 changed files with 74 additions and 8 deletions
|
@ -11,18 +11,32 @@
|
|||
// Alt + click = delete this voxel
|
||||
// shift + click = recolor this voxel
|
||||
//
|
||||
// Click and drag to create more new voxels in the same direction
|
||||
//
|
||||
|
||||
function vLength(v) {
|
||||
return Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
|
||||
}
|
||||
|
||||
var key_alt = false;
|
||||
var key_shift = false;
|
||||
var isAdding = false;
|
||||
|
||||
var lastVoxelPosition = { x: 0, y: 0, z: 0 };
|
||||
var lastVoxelColor = { red: 0, green: 0, blue: 0 };
|
||||
var lastVoxelScale = 0;
|
||||
var dragStart = { x: 0, y: 0 };
|
||||
|
||||
// Create a table of the different colors you can choose
|
||||
var colors = new Array();
|
||||
colors[0] = { red: 255, green: 0, blue: 0 };
|
||||
colors[1] = { red: 0, green: 255, blue: 0 };
|
||||
colors[2] = { red: 0, green: 0, blue: 255 };
|
||||
colors[3] = { red: 255, green: 255, blue: 0 };
|
||||
colors[4] = { red: 0, green: 255, blue: 255 };
|
||||
colors[5] = { red: 255, green: 0, blue: 255 };
|
||||
colors[0] = { red: 237, green: 175, blue: 0 };
|
||||
colors[1] = { red: 61, green: 211, blue: 72 };
|
||||
colors[2] = { red: 51, green: 204, blue: 204 };
|
||||
colors[3] = { red: 63, green: 169, blue: 245 };
|
||||
colors[4] = { red: 193, green: 99, blue: 122 };
|
||||
colors[5] = { red: 255, green: 54, blue: 69 };
|
||||
colors[6] = { red: 124, green: 36, blue: 36 };
|
||||
colors[7] = { red: 63, green: 35, blue: 19 };
|
||||
var numColors = 6;
|
||||
var whichColor = 0;
|
||||
|
||||
|
@ -33,7 +47,6 @@ var changeColorSound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelit
|
|||
var audioOptions = new AudioInjectionOptions();
|
||||
|
||||
function mousePressEvent(event) {
|
||||
print("mousePressEvent event.x,y=" + event.x + ", " + event.y);
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
audioOptions.volume = 1.0;
|
||||
|
@ -81,7 +94,13 @@ function mousePressEvent(event) {
|
|||
}
|
||||
|
||||
Voxels.setVoxel(newVoxel.x, newVoxel.y, newVoxel.z, newVoxel.s, newVoxel.red, newVoxel.green, newVoxel.blue);
|
||||
lastVoxelPosition = { x: newVoxel.x, y: newVoxel.y, z: newVoxel.z };
|
||||
lastVoxelColor = { red: newVoxel.red, green: newVoxel.green, blue: newVoxel.blue };
|
||||
lastVoxelScale = newVoxel.s;
|
||||
|
||||
Audio.playSound(addSound, audioOptions);
|
||||
dragStart = { x: event.x, y: event.y };
|
||||
isAdding = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,8 +113,55 @@ function keyReleaseEvent(event) {
|
|||
key_alt = false;
|
||||
key_shift = false;
|
||||
}
|
||||
function mouseMoveEvent(event) {
|
||||
if (isAdding) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var lastVoxelDistance = { x: pickRay.origin.x - lastVoxelPosition.x,
|
||||
y: pickRay.origin.y - lastVoxelPosition.y,
|
||||
z: pickRay.origin.z - lastVoxelPosition.z };
|
||||
var distance = vLength(lastVoxelDistance);
|
||||
var mouseSpot = { x: pickRay.direction.x * distance, y: pickRay.direction.y * distance, z: pickRay.direction.z * distance };
|
||||
mouseSpot.x += pickRay.origin.x;
|
||||
mouseSpot.y += pickRay.origin.y;
|
||||
mouseSpot.z += pickRay.origin.z;
|
||||
var dx = mouseSpot.x - lastVoxelPosition.x;
|
||||
var dy = mouseSpot.y - lastVoxelPosition.y;
|
||||
var dz = mouseSpot.z - lastVoxelPosition.z;
|
||||
if (dx > lastVoxelScale) {
|
||||
lastVoxelPosition.x += lastVoxelScale;
|
||||
Voxels.setVoxel(lastVoxelPosition.x, lastVoxelPosition.y, lastVoxelPosition.z,
|
||||
lastVoxelScale, lastVoxelColor.red, lastVoxelColor.green, lastVoxelColor.blue);
|
||||
} else if (dx < -lastVoxelScale) {
|
||||
lastVoxelPosition.x -= lastVoxelScale;
|
||||
Voxels.setVoxel(lastVoxelPosition.x, lastVoxelPosition.y, lastVoxelPosition.z,
|
||||
lastVoxelScale, lastVoxelColor.red, lastVoxelColor.green, lastVoxelColor.blue);
|
||||
} else if (dy > lastVoxelScale) {
|
||||
lastVoxelPosition.y += lastVoxelScale;
|
||||
Voxels.setVoxel(lastVoxelPosition.x, lastVoxelPosition.y, lastVoxelPosition.z,
|
||||
lastVoxelScale, lastVoxelColor.red, lastVoxelColor.green, lastVoxelColor.blue);
|
||||
} else if (dy < -lastVoxelScale) {
|
||||
lastVoxelPosition.y -= lastVoxelScale;
|
||||
Voxels.setVoxel(lastVoxelPosition.x, lastVoxelPosition.y, lastVoxelPosition.z,
|
||||
lastVoxelScale, lastVoxelColor.red, lastVoxelColor.green, lastVoxelColor.blue);
|
||||
} else if (dz > lastVoxelScale) {
|
||||
lastVoxelPosition.z += lastVoxelScale;
|
||||
Voxels.setVoxel(lastVoxelPosition.x, lastVoxelPosition.y, lastVoxelPosition.z,
|
||||
lastVoxelScale, lastVoxelColor.red, lastVoxelColor.green, lastVoxelColor.blue);
|
||||
} else if (dz < -lastVoxelScale) {
|
||||
lastVoxelPosition.z -= lastVoxelScale;
|
||||
Voxels.setVoxel(lastVoxelPosition.x, lastVoxelPosition.y, lastVoxelPosition.z,
|
||||
lastVoxelScale, lastVoxelColor.red, lastVoxelColor.green, lastVoxelColor.blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function mouseReleaseEvent(event) {
|
||||
isAdding = false;
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
|
||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||
Controller.keyPressEvent.connect(keyPressEvent);
|
||||
Controller.keyReleaseEvent.connect(keyReleaseEvent);
|
||||
|
||||
|
|
|
@ -1198,7 +1198,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) {
|
|||
return;
|
||||
}
|
||||
if (_isHoverVoxel) {
|
||||
_myAvatar->orbit(getMouseVoxelWorldCoordinates(_hoverVoxel), deltaX, deltaY);
|
||||
//_myAvatar->orbit(getMouseVoxelWorldCoordinates(_hoverVoxel), deltaX, deltaY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue