More work on editVoxel.js

This commit is contained in:
Clement 2014-03-11 16:01:21 -07:00
parent ca0cd2d9d0
commit dcaef45f2e
9 changed files with 273 additions and 138 deletions

View file

@ -93,7 +93,7 @@ var editToolsOn = true; // starts out off
// previewAsVoxel - by default, we will preview adds/deletes/recolors as just 4 lines on the intersecting face. But if you
// the preview to show a full voxel then set this to true and the voxel will be displayed for voxel editing
var previewAsVoxel = false;
var previewAsVoxel = true;
var voxelPreview = Overlays.addOverlay("cube", {
position: { x: 0, y: 0, z: 0},
@ -277,6 +277,88 @@ var pointerVoxelScaleMin = Math.pow(2, (1-pointerVoxelScaleOriginStep));
var pointerVoxelScaleMax = Math.pow(2, (pointerVoxelScaleSteps-pointerVoxelScaleOriginStep));
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 isImporting;
var importPosition;
var importScale;
function initImport() {
importPreview = Overlays.addOverlay("localvoxels", {
name: "import",
position: { x: 0, y: 0, z: 0},
scale: 0,
visible: false
});
isImporting = false;
importPosition = { x: 0, y: 0, z: 0 };
importScale = 0;
}
function importVoxels() {
if (Clipboard.importVoxels() == 0) {
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 }
});
}
}
function rescaleImport(scale) {
if (0 < scale) {
importScale = scale;
Overlays.editOverlay(importPreview, {
scale: importScale
});
}
}
function showImport(doShow) {
Overlays.editOverlay(importPreview, {
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);
isImporting = false;
importPostion = { x: 0, y: 0, z: 0 };
importScale = 0;
}
/////////////////////////////////// END IMPORT MODULE /////////////////////////////
initImport();
if (editToolsOn) {
moveTools();
}
@ -301,6 +383,13 @@ function calcScaleFromThumb(newThumbX) {
thumbAt = newThumbX - minThumbX;
thumbStep = Math.floor((thumbAt/ thumbExtents) * (pointerVoxelScaleSteps-1)) + 1;
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...
calcThumbFromScale(pointerVoxelScale);
@ -879,6 +968,15 @@ function mousePressEvent(event) {
var intersection = Voxels.findRayIntersection(pickRay);
audioOptions.position = Vec3.sum(pickRay.origin, pickRay.direction);
if (isImporting) {
print("placing import...");
placeImport();
showImport(false);
pasteMode = false;
moveTools();
return;
}
if (pasteMode) {
var pasteVoxel = getNewPasteVoxel(pickRay);
Clipboard.pasteVoxel(pasteVoxel.origin.x, pasteVoxel.origin.y, pasteVoxel.origin.z, pasteVoxel.voxelSize);
@ -1051,24 +1149,36 @@ function menuItemEvent(menuItem) {
moveTools();
}
if (menuItem == "Paste") {
if (isImporting) {
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") {
print("deleting...");
if (isImporting) {
cancelImport();
} else {
Clipboard.deleteVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
}
}
if (menuItem == "Export Voxels") {
print("export");
Clipboard.exportVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
}
if (menuItem == "Import Voxels") {
print("import");
Clipboard.importVoxels();
print("importing...");
if (importVoxels()) {
showImport(true);
pasteMode = true;
}
moveTools();
}
if (menuItem == "Nudge") {
@ -1435,6 +1545,11 @@ function wheelEvent(event) {
calcThumbFromScale(pointerVoxelScale);
trackMouseEvent(event);
wheelPixelsMoved = 0;
if (isImporting) {
var importScale = (pointerVoxelScale / MAX_VOXEL_SCALE) * MAX_PASTE_VOXEL_SCALE;
rescaleImport(importScale);
}
}
}
@ -1467,6 +1582,7 @@ function scriptEnding() {
Overlays.deleteOverlay(thumb);
Controller.releaseKeyEvents({ text: "+" });
Controller.releaseKeyEvents({ text: "-" });
cleanupImport();
cleanupMenus();
}
Script.scriptEnding.connect(scriptEnding);

View file

@ -140,9 +140,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
_fps(120.0f),
_justStarted(true),
_voxelImporter(NULL),
_sharedVoxelSystem(TREE_SCALE, DEFAULT_MAX_VOXELS_PER_SYSTEM, &_clipboard),
_wantToKillLocalVoxels(false),
_audioScope(256, 200, true),
_myAvatar(),
_mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)),
_mouseX(0),
_mouseY(0),
@ -1387,6 +1387,8 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) {
}
void Application::importVoxels() {
int result = 1;
if (!_voxelImporter) {
_voxelImporter = new VoxelImporter(_window);
_voxelImporter->loadSettings(_settings);
@ -1394,6 +1396,7 @@ void Application::importVoxels() {
if (!_voxelImporter->exec()) {
qDebug() << "[DEBUG] Import succeeded." << endl;
result = 0;
} else {
qDebug() << "[DEBUG] Import failed." << endl;
if (_sharedVoxelSystem.getTree() == _voxelImporter->getVoxelTree()) {
@ -1404,6 +1407,8 @@ void Application::importVoxels() {
// restore the main window's active state
_window->activateWindow();
emit importDone(result);
}
void Application::cutVoxels(const VoxelDetail& sourceVoxel) {
@ -1495,9 +1500,8 @@ void Application::init() {
// Cleanup of the original shared tree
_sharedVoxelSystem.init();
VoxelTree* tmpTree = _sharedVoxelSystem.getTree();
_sharedVoxelSystem.changeTree(&_clipboard);
delete tmpTree;
_voxelImporter = new VoxelImporter(_window);
_environment.init();

View file

@ -225,6 +225,9 @@ signals:
/// Fired when we're rendering in-world interface elements; allows external parties to hook in.
void renderingInWorldInterface();
/// Fired when the import window is closed with a return code.
void importDone(int);
public slots:
void domainChanged(const QString& domainHostname);
void updateWindowTitle();
@ -351,13 +354,13 @@ private:
glm::vec3 _gravity;
// Frame Rate Measurement
int _frameCount;
float _fps;
timeval _applicationStartupTime;
timeval _timerStart, _timerEnd;
timeval _lastTimeUpdated;
bool _justStarted;
Stars _stars;
BuckyBalls _buckyBalls;

View file

@ -9,6 +9,7 @@
#include "ClipboardScriptingInterface.h"
ClipboardScriptingInterface::ClipboardScriptingInterface() {
connect(this, SIGNAL(readyToImport()), Application::getInstance(), SLOT(importVoxels()));
}
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,
s / (float)TREE_SCALE };
QMetaObject::invokeMethod(Application::getInstance(), "exportVoxels",
Q_ARG(const VoxelDetail&, sourceVoxel));
Application::getInstance()->exportVoxels(sourceVoxel);
}
void ClipboardScriptingInterface::importVoxels() {
QMetaObject::invokeMethod(Application::getInstance(), "importVoxels");
bool ClipboardScriptingInterface::importVoxels() {
qDebug() << "[DEBUG] Importing ... ";
QEventLoop loop;
connect(Application::getInstance(), SIGNAL(importDone(int)), &loop, SLOT(quit()));
emit readyToImport();
int returnCode = loop.exec();
return returnCode;
}
void ClipboardScriptingInterface::nudgeVoxel(const VoxelDetail& sourceVoxel, const glm::vec3& nudgeVec) {

View file

@ -18,6 +18,9 @@ class ClipboardScriptingInterface : public QObject {
public:
ClipboardScriptingInterface();
signals:
void readyToImport();
public slots:
void cutVoxel(const VoxelDetail& sourceVoxel);
void cutVoxel(float x, float y, float z, float s);
@ -34,7 +37,7 @@ public slots:
void exportVoxel(const VoxelDetail& sourceVoxel);
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(float x, float y, float z, float s, const glm::vec3& nudgeVec);

View file

@ -1177,8 +1177,6 @@ void VoxelSystem::init() {
}
void VoxelSystem::changeTree(VoxelTree* newTree) {
disconnect(_tree, 0, this, 0);
_tree = newTree;
_tree->setDirtyBit();

View file

@ -40,9 +40,11 @@ void LocalVoxelsOverlay::update(float deltatime) {
_voxelSystem->init();
}
if (_voxelCount != _tree->getOctreeElementsCount()) {
if (_visible && _voxelCount != _tree->getOctreeElementsCount()) {
_voxelCount = _tree->getOctreeElementsCount();
_tree->lockForWrite();
_voxelSystem->forceRedrawEntireTree();
_tree->unlock();
}
}

View file

@ -31,6 +31,9 @@ void Volume3DOverlay::setProperties(const QScriptValue& properties) {
if (properties.property("size").isValid()) {
setSize(properties.property("size").toVariant().toFloat());
}
if (properties.property("scale").isValid()) {
setSize(properties.property("scale").toVariant().toFloat());
}
if (properties.property("isSolid").isValid()) {
setIsSolid(properties.property("isSolid").toVariant().toBool());