mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:41:10 +02:00
commit
79b1465cb0
7 changed files with 279 additions and 33 deletions
|
@ -26,6 +26,10 @@ var PIXELS_PER_EXTRUDE_VOXEL = 16;
|
||||||
var WHEEL_PIXELS_PER_SCALE_CHANGE = 100;
|
var WHEEL_PIXELS_PER_SCALE_CHANGE = 100;
|
||||||
var MAX_VOXEL_SCALE = 1.0;
|
var MAX_VOXEL_SCALE = 1.0;
|
||||||
var MIN_VOXEL_SCALE = 1.0 / Math.pow(2.0, 8.0);
|
var MIN_VOXEL_SCALE = 1.0 / Math.pow(2.0, 8.0);
|
||||||
|
var WHITE_COLOR = { red: 255, green: 255, blue: 255 };
|
||||||
|
|
||||||
|
var MAX_PASTE_VOXEL_SCALE = 256;
|
||||||
|
var MIN_PASTE_VOXEL_SCALE = .256;
|
||||||
|
|
||||||
var zFightingSizeAdjust = 0.002; // used to adjust preview voxels to prevent z fighting
|
var zFightingSizeAdjust = 0.002; // used to adjust preview voxels to prevent z fighting
|
||||||
var previewLineWidth = 1.5;
|
var previewLineWidth = 1.5;
|
||||||
|
@ -199,6 +203,8 @@ var voxelToolAt = 0;
|
||||||
var recolorToolAt = 1;
|
var recolorToolAt = 1;
|
||||||
var eyedropperToolAt = 2;
|
var eyedropperToolAt = 2;
|
||||||
|
|
||||||
|
var pasteModeColor = { red: 132, green: 61, blue: 255 };
|
||||||
|
|
||||||
var voxelTool = Overlays.addOverlay("image", {
|
var voxelTool = Overlays.addOverlay("image", {
|
||||||
x: 0, y: 0, width: toolWidth, height: toolHeight,
|
x: 0, y: 0, width: toolWidth, height: toolHeight,
|
||||||
subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
|
subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
|
||||||
|
@ -262,7 +268,7 @@ var thumb = Overlays.addOverlay("image", {
|
||||||
visible: false
|
visible: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var pointerVoxelScale = 0; // this is the voxel scale used for click to add or delete
|
var pointerVoxelScale = Math.floor(MAX_VOXEL_SCALE + MIN_VOXEL_SCALE) / 2; // this is the voxel scale used for click to add or delete
|
||||||
var pointerVoxelScaleSet = false; // if voxel scale has not yet been set, we use the intersection size
|
var pointerVoxelScaleSet = false; // if voxel scale has not yet been set, we use the intersection size
|
||||||
|
|
||||||
var pointerVoxelScaleSteps = 8; // the number of slider position steps
|
var pointerVoxelScaleSteps = 8; // the number of slider position steps
|
||||||
|
@ -271,6 +277,106 @@ var pointerVoxelScaleMin = Math.pow(2, (1-pointerVoxelScaleOriginStep));
|
||||||
var pointerVoxelScaleMax = Math.pow(2, (pointerVoxelScaleSteps-pointerVoxelScaleOriginStep));
|
var pointerVoxelScaleMax = Math.pow(2, (pointerVoxelScaleSteps-pointerVoxelScaleOriginStep));
|
||||||
var thumbDeltaPerStep = thumbExtents / (pointerVoxelScaleSteps - 1);
|
var thumbDeltaPerStep = thumbExtents / (pointerVoxelScaleSteps - 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////// IMPORT MODULE ///////////////////////////////
|
||||||
|
// Move the following code to a separate file when include will be available.
|
||||||
|
var importTree;
|
||||||
|
var importPreview;
|
||||||
|
var importBoundaries;
|
||||||
|
var isImporting;
|
||||||
|
var importPosition;
|
||||||
|
var importScale;
|
||||||
|
|
||||||
|
function initImport() {
|
||||||
|
importPreview = Overlays.addOverlay("localvoxels", {
|
||||||
|
name: "import",
|
||||||
|
position: { x: 0, y: 0, z: 0},
|
||||||
|
scale: 1,
|
||||||
|
visible: false
|
||||||
|
});
|
||||||
|
importBoundaries = Overlays.addOverlay("cube", {
|
||||||
|
position: { x: 0, y: 0, z: 0 },
|
||||||
|
scale: 1,
|
||||||
|
color: { red: 128, blue: 128, green: 128 },
|
||||||
|
solid: false,
|
||||||
|
visible: false
|
||||||
|
})
|
||||||
|
isImporting = false;
|
||||||
|
importPosition = { x: 0, y: 0, z: 0 };
|
||||||
|
importScale = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function importVoxels() {
|
||||||
|
if (Clipboard.importVoxels()) {
|
||||||
|
isImporting = true;
|
||||||
|
if (importScale <= 0) {
|
||||||
|
importScale = 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
isImporting = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isImporting;
|
||||||
|
}
|
||||||
|
|
||||||
|
function moveImport(position) {
|
||||||
|
if (0 < position.x && 0 < position.y && 0 < position.z) {
|
||||||
|
importPosition = position;
|
||||||
|
Overlays.editOverlay(importPreview, {
|
||||||
|
position: { x: importPosition.x, y: importPosition.y, z: importPosition.z }
|
||||||
|
});
|
||||||
|
Overlays.editOverlay(importBoundaries, {
|
||||||
|
position: { x: importPosition.x, y: importPosition.y, z: importPosition.z }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function rescaleImport(scale) {
|
||||||
|
if (0 < scale) {
|
||||||
|
importScale = scale;
|
||||||
|
Overlays.editOverlay(importPreview, {
|
||||||
|
scale: importScale
|
||||||
|
});
|
||||||
|
Overlays.editOverlay(importBoundaries, {
|
||||||
|
scale: importScale
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showImport(doShow) {
|
||||||
|
Overlays.editOverlay(importPreview, {
|
||||||
|
visible: doShow
|
||||||
|
});
|
||||||
|
Overlays.editOverlay(importBoundaries, {
|
||||||
|
visible: doShow
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function placeImport() {
|
||||||
|
if (isImporting) {
|
||||||
|
Clipboard.pasteVoxel(importPosition.x, importPosition.y, importPosition.z, importScale);
|
||||||
|
isImporting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelImport() {
|
||||||
|
if (isImporting) {
|
||||||
|
isImporting = false;
|
||||||
|
showImport(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleanupImport() {
|
||||||
|
Overlays.deleteOverlay(importPreview);
|
||||||
|
Overlays.deleteOverlay(importBoundaries);
|
||||||
|
isImporting = false;
|
||||||
|
importPostion = { x: 0, y: 0, z: 0 };
|
||||||
|
importScale = 0;
|
||||||
|
}
|
||||||
|
/////////////////////////////////// END IMPORT MODULE /////////////////////////////
|
||||||
|
initImport();
|
||||||
|
|
||||||
if (editToolsOn) {
|
if (editToolsOn) {
|
||||||
moveTools();
|
moveTools();
|
||||||
}
|
}
|
||||||
|
@ -295,6 +401,13 @@ function calcScaleFromThumb(newThumbX) {
|
||||||
thumbAt = newThumbX - minThumbX;
|
thumbAt = newThumbX - minThumbX;
|
||||||
thumbStep = Math.floor((thumbAt/ thumbExtents) * (pointerVoxelScaleSteps-1)) + 1;
|
thumbStep = Math.floor((thumbAt/ thumbExtents) * (pointerVoxelScaleSteps-1)) + 1;
|
||||||
pointerVoxelScale = Math.pow(2, (thumbStep-pointerVoxelScaleOriginStep));
|
pointerVoxelScale = Math.pow(2, (thumbStep-pointerVoxelScaleOriginStep));
|
||||||
|
|
||||||
|
// if importing, rescale import ...
|
||||||
|
if (isImporting) {
|
||||||
|
var importScale = (pointerVoxelScale / MAX_VOXEL_SCALE) * MAX_PASTE_VOXEL_SCALE;
|
||||||
|
rescaleImport(importScale);
|
||||||
|
}
|
||||||
|
|
||||||
// now reset the display accordingly...
|
// now reset the display accordingly...
|
||||||
calcThumbFromScale(pointerVoxelScale);
|
calcThumbFromScale(pointerVoxelScale);
|
||||||
|
|
||||||
|
@ -308,7 +421,23 @@ function setAudioPosition() {
|
||||||
audioOptions.position = Vec3.sum(camera, forwardVector);
|
audioOptions.position = Vec3.sum(camera, forwardVector);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNewVoxelPosition() {
|
function getNewPasteVoxel(pickRay) {
|
||||||
|
|
||||||
|
var voxelSize = MIN_PASTE_VOXEL_SCALE + (MAX_PASTE_VOXEL_SCALE - MIN_PASTE_VOXEL_SCALE) * pointerVoxelScale - 1;
|
||||||
|
var origin = { x: pickRay.direction.x, y: pickRay.direction.y, z: pickRay.direction.z };
|
||||||
|
|
||||||
|
origin.x += pickRay.origin.x;
|
||||||
|
origin.y += pickRay.origin.y;
|
||||||
|
origin.z += pickRay.origin.z;
|
||||||
|
|
||||||
|
origin.x -= voxelSize / 2;
|
||||||
|
origin.y -= voxelSize / 2;
|
||||||
|
origin.z += voxelSize / 2;
|
||||||
|
|
||||||
|
return {origin: origin, voxelSize: voxelSize};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNewVoxelPosition() {
|
||||||
var camera = Camera.getPosition();
|
var camera = Camera.getPosition();
|
||||||
var forwardVector = Quat.getFront(MyAvatar.orientation);
|
var forwardVector = Quat.getFront(MyAvatar.orientation);
|
||||||
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, NEW_VOXEL_DISTANCE_FROM_CAMERA));
|
var newPosition = Vec3.sum(camera, Vec3.multiply(forwardVector, NEW_VOXEL_DISTANCE_FROM_CAMERA));
|
||||||
|
@ -337,6 +466,7 @@ var trackAsOrbitOrPan = false;
|
||||||
var voxelToolSelected = true;
|
var voxelToolSelected = true;
|
||||||
var recolorToolSelected = false;
|
var recolorToolSelected = false;
|
||||||
var eyedropperToolSelected = false;
|
var eyedropperToolSelected = false;
|
||||||
|
var pasteMode = false;
|
||||||
|
|
||||||
function playRandomAddSound(audioOptions) {
|
function playRandomAddSound(audioOptions) {
|
||||||
if (Math.random() < 0.33) {
|
if (Math.random() < 0.33) {
|
||||||
|
@ -523,6 +653,38 @@ function showPreviewVoxel() {
|
||||||
function showPreviewLines() {
|
function showPreviewLines() {
|
||||||
|
|
||||||
var pickRay = Camera.computePickRay(trackLastMouseX, trackLastMouseY);
|
var pickRay = Camera.computePickRay(trackLastMouseX, trackLastMouseY);
|
||||||
|
|
||||||
|
if (pasteMode) { // free voxel pasting
|
||||||
|
|
||||||
|
Overlays.editOverlay(voxelPreview, { visible: false });
|
||||||
|
Overlays.editOverlay(linePreviewLeft, { visible: false });
|
||||||
|
|
||||||
|
var pasteVoxel = getNewPasteVoxel(pickRay);
|
||||||
|
|
||||||
|
// X axis
|
||||||
|
Overlays.editOverlay(linePreviewBottom, {
|
||||||
|
position: pasteVoxel.origin,
|
||||||
|
end: {x: pasteVoxel.origin.x + pasteVoxel.voxelSize, y: pasteVoxel.origin.y, z: pasteVoxel.origin.z },
|
||||||
|
visible: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Y axis
|
||||||
|
Overlays.editOverlay(linePreviewRight, {
|
||||||
|
position: pasteVoxel.origin,
|
||||||
|
end: {x: pasteVoxel.origin.x, y: pasteVoxel.origin.y + pasteVoxel.voxelSize, z: pasteVoxel.origin.z },
|
||||||
|
visible: true
|
||||||
|
});
|
||||||
|
|
||||||
|
// Z axis
|
||||||
|
Overlays.editOverlay(linePreviewTop, {
|
||||||
|
position: pasteVoxel.origin,
|
||||||
|
end: {x: pasteVoxel.origin.x, y: pasteVoxel.origin.y, z: pasteVoxel.origin.z - pasteVoxel.voxelSize },
|
||||||
|
visible: true
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var intersection = Voxels.findRayIntersection(pickRay);
|
var intersection = Voxels.findRayIntersection(pickRay);
|
||||||
|
|
||||||
if (intersection.intersects) {
|
if (intersection.intersects) {
|
||||||
|
@ -617,6 +779,8 @@ function trackKeyReleaseEvent(event) {
|
||||||
if (editToolsOn) {
|
if (editToolsOn) {
|
||||||
if (event.text == "ESC") {
|
if (event.text == "ESC") {
|
||||||
pointerVoxelScaleSet = false;
|
pointerVoxelScaleSet = false;
|
||||||
|
pasteMode = false;
|
||||||
|
moveTools();
|
||||||
}
|
}
|
||||||
if (event.text == "-") {
|
if (event.text == "-") {
|
||||||
thumbX -= thumbDeltaPerStep;
|
thumbX -= thumbDeltaPerStep;
|
||||||
|
@ -821,6 +985,23 @@ function mousePressEvent(event) {
|
||||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||||
var intersection = Voxels.findRayIntersection(pickRay);
|
var intersection = Voxels.findRayIntersection(pickRay);
|
||||||
audioOptions.position = Vec3.sum(pickRay.origin, pickRay.direction);
|
audioOptions.position = Vec3.sum(pickRay.origin, pickRay.direction);
|
||||||
|
|
||||||
|
if (isImporting) {
|
||||||
|
print("placing import...");
|
||||||
|
placeImport();
|
||||||
|
showImport(false);
|
||||||
|
moveTools();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pasteMode) {
|
||||||
|
var pasteVoxel = getNewPasteVoxel(pickRay);
|
||||||
|
Clipboard.pasteVoxel(pasteVoxel.origin.x, pasteVoxel.origin.y, pasteVoxel.origin.z, pasteVoxel.voxelSize);
|
||||||
|
pasteMode = false;
|
||||||
|
moveTools();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (intersection.intersects) {
|
if (intersection.intersects) {
|
||||||
// if the user hasn't updated the
|
// if the user hasn't updated the
|
||||||
if (!pointerVoxelScaleSet) {
|
if (!pointerVoxelScaleSet) {
|
||||||
|
@ -967,25 +1148,42 @@ function cleanupMenus() {
|
||||||
function menuItemEvent(menuItem) {
|
function menuItemEvent(menuItem) {
|
||||||
|
|
||||||
// handle clipboard items
|
// handle clipboard items
|
||||||
if (selectToolSelected) {
|
if (editToolsOn) {
|
||||||
|
|
||||||
var pickRay = Camera.computePickRay(trackLastMouseX, trackLastMouseY);
|
var pickRay = Camera.computePickRay(trackLastMouseX, trackLastMouseY);
|
||||||
var intersection = Voxels.findRayIntersection(pickRay);
|
var intersection = Voxels.findRayIntersection(pickRay);
|
||||||
selectedVoxel = calculateVoxelFromIntersection(intersection,"select");
|
selectedVoxel = calculateVoxelFromIntersection(intersection,"select");
|
||||||
if (menuItem == "Copy") {
|
if (menuItem == "Copy") {
|
||||||
print("copying...");
|
print("copying...");
|
||||||
Clipboard.copyVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
Clipboard.copyVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
||||||
|
pasteMode = true;
|
||||||
|
moveTools();
|
||||||
}
|
}
|
||||||
if (menuItem == "Cut") {
|
if (menuItem == "Cut") {
|
||||||
print("cutting...");
|
print("cutting...");
|
||||||
Clipboard.cutVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
Clipboard.cutVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
||||||
|
pasteMode = true;
|
||||||
|
moveTools();
|
||||||
}
|
}
|
||||||
if (menuItem == "Paste") {
|
if (menuItem == "Paste") {
|
||||||
print("pasting...");
|
if (isImporting) {
|
||||||
Clipboard.pasteVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
print("placing import...");
|
||||||
|
placeImport();
|
||||||
|
showImport(false);
|
||||||
|
} else {
|
||||||
|
print("pasting...");
|
||||||
|
Clipboard.pasteVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
||||||
|
}
|
||||||
|
pasteMode = false;
|
||||||
|
moveTools();
|
||||||
}
|
}
|
||||||
if (menuItem == "Delete") {
|
if (menuItem == "Delete") {
|
||||||
print("deleting...");
|
print("deleting...");
|
||||||
Clipboard.deleteVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
if (isImporting) {
|
||||||
|
cancelImport();
|
||||||
|
} else {
|
||||||
|
Clipboard.deleteVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menuItem == "Export Voxels") {
|
if (menuItem == "Export Voxels") {
|
||||||
|
@ -993,8 +1191,11 @@ function menuItemEvent(menuItem) {
|
||||||
Clipboard.exportVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
Clipboard.exportVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
||||||
}
|
}
|
||||||
if (menuItem == "Import Voxels") {
|
if (menuItem == "Import Voxels") {
|
||||||
print("import");
|
print("importing...");
|
||||||
Clipboard.importVoxels();
|
if (importVoxels()) {
|
||||||
|
showImport(true);
|
||||||
|
}
|
||||||
|
moveTools();
|
||||||
}
|
}
|
||||||
if (menuItem == "Nudge") {
|
if (menuItem == "Nudge") {
|
||||||
print("nudge");
|
print("nudge");
|
||||||
|
@ -1149,19 +1350,23 @@ function moveTools() {
|
||||||
recolorToolOffset = 1,
|
recolorToolOffset = 1,
|
||||||
eyedropperToolOffset = 1;
|
eyedropperToolOffset = 1;
|
||||||
|
|
||||||
if (trackAsRecolor || recolorToolSelected) {
|
var voxelToolColor = WHITE_COLOR;
|
||||||
|
|
||||||
|
if (recolorToolSelected) {
|
||||||
recolorToolOffset = 2;
|
recolorToolOffset = 2;
|
||||||
} else if (trackAsEyedropper || eyedropperToolSelected) {
|
} else if (eyedropperToolSelected) {
|
||||||
eyedropperToolOffset = 2;
|
eyedropperToolOffset = 2;
|
||||||
} else if (trackAsOrbitOrPan) {
|
|
||||||
// nothing gets selected in this case...
|
|
||||||
} else {
|
} else {
|
||||||
|
if (pasteMode) {
|
||||||
|
voxelToolColor = pasteModeColor;
|
||||||
|
}
|
||||||
voxelToolOffset = 2;
|
voxelToolOffset = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Overlays.editOverlay(voxelTool, {
|
Overlays.editOverlay(voxelTool, {
|
||||||
subImage: { x: 0, y: toolHeight * voxelToolOffset, width: toolWidth, height: toolHeight },
|
subImage: { x: 0, y: toolHeight * voxelToolOffset, width: toolWidth, height: toolHeight },
|
||||||
x: toolsX, y: toolsY + ((toolHeight + toolVerticalSpacing) * voxelToolAt), width: toolWidth, height: toolHeight,
|
x: toolsX, y: toolsY + ((toolHeight + toolVerticalSpacing) * voxelToolAt), width: toolWidth, height: toolHeight,
|
||||||
|
color: voxelToolColor,
|
||||||
visible: editToolsOn
|
visible: editToolsOn
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1323,14 +1528,27 @@ function checkControllers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function update(deltaTime) {
|
function update(deltaTime) {
|
||||||
var newWindowDimensions = Controller.getViewportDimensions();
|
|
||||||
if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) {
|
|
||||||
windowDimensions = newWindowDimensions;
|
|
||||||
moveTools();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (editToolsOn) {
|
if (editToolsOn) {
|
||||||
|
var newWindowDimensions = Controller.getViewportDimensions();
|
||||||
|
if (newWindowDimensions.x != windowDimensions.x || newWindowDimensions.y != windowDimensions.y) {
|
||||||
|
windowDimensions = newWindowDimensions;
|
||||||
|
moveTools();
|
||||||
|
}
|
||||||
|
|
||||||
checkControllers();
|
checkControllers();
|
||||||
|
|
||||||
|
// Move Import Preview
|
||||||
|
if (isImporting) {
|
||||||
|
var position = MyAvatar.position;
|
||||||
|
var forwardVector = Quat.getFront(MyAvatar.orientation);
|
||||||
|
var targetPosition = Vec3.sum(position, Vec3.multiply(forwardVector, importScale));
|
||||||
|
var newPosition = {
|
||||||
|
x: Math.floor(targetPosition.x / importScale) * importScale,
|
||||||
|
y: Math.floor(targetPosition.y / importScale) * importScale,
|
||||||
|
z: Math.floor(targetPosition.z / importScale) * importScale
|
||||||
|
}
|
||||||
|
moveImport(newPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1356,6 +1574,11 @@ function wheelEvent(event) {
|
||||||
calcThumbFromScale(pointerVoxelScale);
|
calcThumbFromScale(pointerVoxelScale);
|
||||||
trackMouseEvent(event);
|
trackMouseEvent(event);
|
||||||
wheelPixelsMoved = 0;
|
wheelPixelsMoved = 0;
|
||||||
|
|
||||||
|
if (isImporting) {
|
||||||
|
var importScale = (pointerVoxelScale / MAX_VOXEL_SCALE) * MAX_PASTE_VOXEL_SCALE;
|
||||||
|
rescaleImport(importScale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1388,6 +1611,7 @@ function scriptEnding() {
|
||||||
Overlays.deleteOverlay(thumb);
|
Overlays.deleteOverlay(thumb);
|
||||||
Controller.releaseKeyEvents({ text: "+" });
|
Controller.releaseKeyEvents({ text: "+" });
|
||||||
Controller.releaseKeyEvents({ text: "-" });
|
Controller.releaseKeyEvents({ text: "-" });
|
||||||
|
cleanupImport();
|
||||||
cleanupMenus();
|
cleanupMenus();
|
||||||
}
|
}
|
||||||
Script.scriptEnding.connect(scriptEnding);
|
Script.scriptEnding.connect(scriptEnding);
|
||||||
|
|
|
@ -140,12 +140,13 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
_fps(120.0f),
|
_fps(120.0f),
|
||||||
_justStarted(true),
|
_justStarted(true),
|
||||||
_voxelImporter(NULL),
|
_voxelImporter(NULL),
|
||||||
|
_importSucceded(false),
|
||||||
|
_sharedVoxelSystem(TREE_SCALE, DEFAULT_MAX_VOXELS_PER_SYSTEM, &_clipboard),
|
||||||
_wantToKillLocalVoxels(false),
|
_wantToKillLocalVoxels(false),
|
||||||
_viewFrustum(),
|
_viewFrustum(),
|
||||||
_lastQueriedViewFrustum(),
|
_lastQueriedViewFrustum(),
|
||||||
_lastQueriedTime(usecTimestampNow()),
|
_lastQueriedTime(usecTimestampNow()),
|
||||||
_audioScope(256, 200, true),
|
_audioScope(256, 200, true),
|
||||||
_myAvatar(),
|
|
||||||
_mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)),
|
_mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)),
|
||||||
_mouseX(0),
|
_mouseX(0),
|
||||||
_mouseY(0),
|
_mouseY(0),
|
||||||
|
@ -1368,6 +1369,8 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::importVoxels() {
|
void Application::importVoxels() {
|
||||||
|
_importSucceded = false;
|
||||||
|
|
||||||
if (!_voxelImporter) {
|
if (!_voxelImporter) {
|
||||||
_voxelImporter = new VoxelImporter(_window);
|
_voxelImporter = new VoxelImporter(_window);
|
||||||
_voxelImporter->loadSettings(_settings);
|
_voxelImporter->loadSettings(_settings);
|
||||||
|
@ -1375,6 +1378,7 @@ void Application::importVoxels() {
|
||||||
|
|
||||||
if (!_voxelImporter->exec()) {
|
if (!_voxelImporter->exec()) {
|
||||||
qDebug() << "[DEBUG] Import succeeded." << endl;
|
qDebug() << "[DEBUG] Import succeeded." << endl;
|
||||||
|
_importSucceded = true;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "[DEBUG] Import failed." << endl;
|
qDebug() << "[DEBUG] Import failed." << endl;
|
||||||
if (_sharedVoxelSystem.getTree() == _voxelImporter->getVoxelTree()) {
|
if (_sharedVoxelSystem.getTree() == _voxelImporter->getVoxelTree()) {
|
||||||
|
@ -1385,6 +1389,8 @@ void Application::importVoxels() {
|
||||||
|
|
||||||
// restore the main window's active state
|
// restore the main window's active state
|
||||||
_window->activateWindow();
|
_window->activateWindow();
|
||||||
|
|
||||||
|
emit importDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::cutVoxels(const VoxelDetail& sourceVoxel) {
|
void Application::cutVoxels(const VoxelDetail& sourceVoxel) {
|
||||||
|
@ -1476,10 +1482,9 @@ void Application::init() {
|
||||||
|
|
||||||
// Cleanup of the original shared tree
|
// Cleanup of the original shared tree
|
||||||
_sharedVoxelSystem.init();
|
_sharedVoxelSystem.init();
|
||||||
VoxelTree* tmpTree = _sharedVoxelSystem.getTree();
|
|
||||||
_sharedVoxelSystem.changeTree(&_clipboard);
|
_voxelImporter = new VoxelImporter(_window);
|
||||||
delete tmpTree;
|
|
||||||
|
|
||||||
_environment.init();
|
_environment.init();
|
||||||
|
|
||||||
_glowEffect.init();
|
_glowEffect.init();
|
||||||
|
|
|
@ -156,6 +156,7 @@ public:
|
||||||
VoxelTree* getVoxelTree() { return _voxels.getTree(); }
|
VoxelTree* getVoxelTree() { return _voxels.getTree(); }
|
||||||
ParticleTreeRenderer* getParticles() { return &_particles; }
|
ParticleTreeRenderer* getParticles() { return &_particles; }
|
||||||
MetavoxelSystem* getMetavoxels() { return &_metavoxels; }
|
MetavoxelSystem* getMetavoxels() { return &_metavoxels; }
|
||||||
|
bool getImportSucceded() { return _importSucceded; }
|
||||||
VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; }
|
VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; }
|
||||||
VoxelTree* getClipboard() { return &_clipboard; }
|
VoxelTree* getClipboard() { return &_clipboard; }
|
||||||
Environment* getEnvironment() { return &_environment; }
|
Environment* getEnvironment() { return &_environment; }
|
||||||
|
@ -224,6 +225,9 @@ signals:
|
||||||
/// Fired when we're rendering in-world interface elements; allows external parties to hook in.
|
/// Fired when we're rendering in-world interface elements; allows external parties to hook in.
|
||||||
void renderingInWorldInterface();
|
void renderingInWorldInterface();
|
||||||
|
|
||||||
|
/// Fired when the import window is closed
|
||||||
|
void importDone();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void domainChanged(const QString& domainHostname);
|
void domainChanged(const QString& domainHostname);
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
|
@ -350,13 +354,13 @@ private:
|
||||||
glm::vec3 _gravity;
|
glm::vec3 _gravity;
|
||||||
|
|
||||||
// Frame Rate Measurement
|
// Frame Rate Measurement
|
||||||
|
|
||||||
int _frameCount;
|
int _frameCount;
|
||||||
float _fps;
|
float _fps;
|
||||||
timeval _applicationStartupTime;
|
timeval _applicationStartupTime;
|
||||||
timeval _timerStart, _timerEnd;
|
timeval _timerStart, _timerEnd;
|
||||||
timeval _lastTimeUpdated;
|
timeval _lastTimeUpdated;
|
||||||
bool _justStarted;
|
bool _justStarted;
|
||||||
|
|
||||||
Stars _stars;
|
Stars _stars;
|
||||||
|
|
||||||
BuckyBalls _buckyBalls;
|
BuckyBalls _buckyBalls;
|
||||||
|
@ -364,6 +368,7 @@ private:
|
||||||
VoxelSystem _voxels;
|
VoxelSystem _voxels;
|
||||||
VoxelTree _clipboard; // if I copy/paste
|
VoxelTree _clipboard; // if I copy/paste
|
||||||
VoxelImporter* _voxelImporter;
|
VoxelImporter* _voxelImporter;
|
||||||
|
bool _importSucceded;
|
||||||
VoxelSystem _sharedVoxelSystem;
|
VoxelSystem _sharedVoxelSystem;
|
||||||
ViewFrustum _sharedVoxelSystemViewFrustum;
|
ViewFrustum _sharedVoxelSystemViewFrustum;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "ClipboardScriptingInterface.h"
|
#include "ClipboardScriptingInterface.h"
|
||||||
|
|
||||||
ClipboardScriptingInterface::ClipboardScriptingInterface() {
|
ClipboardScriptingInterface::ClipboardScriptingInterface() {
|
||||||
|
connect(this, SIGNAL(readyToImport()), Application::getInstance(), SLOT(importVoxels()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClipboardScriptingInterface::cutVoxel(const VoxelDetail& sourceVoxel) {
|
void ClipboardScriptingInterface::cutVoxel(const VoxelDetail& sourceVoxel) {
|
||||||
|
@ -70,12 +71,17 @@ void ClipboardScriptingInterface::exportVoxel(float x, float y, float z, float s
|
||||||
z / (float)TREE_SCALE,
|
z / (float)TREE_SCALE,
|
||||||
s / (float)TREE_SCALE };
|
s / (float)TREE_SCALE };
|
||||||
|
|
||||||
QMetaObject::invokeMethod(Application::getInstance(), "exportVoxels",
|
Application::getInstance()->exportVoxels(sourceVoxel);
|
||||||
Q_ARG(const VoxelDetail&, sourceVoxel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClipboardScriptingInterface::importVoxels() {
|
bool ClipboardScriptingInterface::importVoxels() {
|
||||||
QMetaObject::invokeMethod(Application::getInstance(), "importVoxels");
|
qDebug() << "[DEBUG] Importing ... ";
|
||||||
|
QEventLoop loop;
|
||||||
|
connect(Application::getInstance(), SIGNAL(importDone()), &loop, SLOT(quit()));
|
||||||
|
emit readyToImport();
|
||||||
|
loop.exec();
|
||||||
|
|
||||||
|
return Application::getInstance()->getImportSucceded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClipboardScriptingInterface::nudgeVoxel(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec) {
|
void ClipboardScriptingInterface::nudgeVoxel(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec) {
|
||||||
|
|
|
@ -18,6 +18,9 @@ class ClipboardScriptingInterface : public QObject {
|
||||||
public:
|
public:
|
||||||
ClipboardScriptingInterface();
|
ClipboardScriptingInterface();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void readyToImport();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void cutVoxel(const VoxelDetail& sourceVoxel);
|
void cutVoxel(const VoxelDetail& sourceVoxel);
|
||||||
void cutVoxel(float x, float y, float z, float s);
|
void cutVoxel(float x, float y, float z, float s);
|
||||||
|
@ -34,7 +37,7 @@ public slots:
|
||||||
void exportVoxel(const VoxelDetail& sourceVoxel);
|
void exportVoxel(const VoxelDetail& sourceVoxel);
|
||||||
void exportVoxel(float x, float y, float z, float s);
|
void exportVoxel(float x, float y, float z, float s);
|
||||||
|
|
||||||
void importVoxels();
|
bool importVoxels();
|
||||||
|
|
||||||
void nudgeVoxel(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec);
|
void nudgeVoxel(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec);
|
||||||
void nudgeVoxel(float x, float y, float z, float s, const glm::vec3& nudgeVec);
|
void nudgeVoxel(float x, float y, float z, float s, const glm::vec3& nudgeVec);
|
||||||
|
|
|
@ -1177,8 +1177,6 @@ void VoxelSystem::init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VoxelSystem::changeTree(VoxelTree* newTree) {
|
void VoxelSystem::changeTree(VoxelTree* newTree) {
|
||||||
disconnect(_tree, 0, this, 0);
|
|
||||||
|
|
||||||
_tree = newTree;
|
_tree = newTree;
|
||||||
|
|
||||||
_tree->setDirtyBit();
|
_tree->setDirtyBit();
|
||||||
|
|
|
@ -40,10 +40,12 @@ void LocalVoxelsOverlay::update(float deltatime) {
|
||||||
_voxelSystem->init();
|
_voxelSystem->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_voxelCount != _tree->getOctreeElementsCount()) {
|
_tree->lockForRead();
|
||||||
|
if (_visible && _voxelCount != _tree->getOctreeElementsCount()) {
|
||||||
_voxelCount = _tree->getOctreeElementsCount();
|
_voxelCount = _tree->getOctreeElementsCount();
|
||||||
_voxelSystem->forceRedrawEntireTree();
|
_voxelSystem->forceRedrawEntireTree();
|
||||||
}
|
}
|
||||||
|
_tree->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalVoxelsOverlay::render() {
|
void LocalVoxelsOverlay::render() {
|
||||||
|
@ -59,8 +61,11 @@ void LocalVoxelsOverlay::render() {
|
||||||
void LocalVoxelsOverlay::setProperties(const QScriptValue &properties) {
|
void LocalVoxelsOverlay::setProperties(const QScriptValue &properties) {
|
||||||
Volume3DOverlay::setProperties(properties);
|
Volume3DOverlay::setProperties(properties);
|
||||||
|
|
||||||
|
if (properties.property("scale").isValid()) {
|
||||||
|
setSize(properties.property("scale").toVariant().toFloat());
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue treeName = properties.property("name");
|
QScriptValue treeName = properties.property("name");
|
||||||
// if "end" property was not there, check to see if they included aliases: endPoint, or p2
|
|
||||||
if (treeName.isValid()) {
|
if (treeName.isValid()) {
|
||||||
if ((_treeName = treeName.toString()) == DOMAIN_TREE_NAME) {
|
if ((_treeName = treeName.toString()) == DOMAIN_TREE_NAME) {
|
||||||
qDebug() << "addOverlay(): Can't create overlay from domain tree";
|
qDebug() << "addOverlay(): Can't create overlay from domain tree";
|
||||||
|
|
Loading…
Reference in a new issue