mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:13:05 +02:00
More work on editVoxel.js
This commit is contained in:
parent
ca0cd2d9d0
commit
dcaef45f2e
9 changed files with 273 additions and 138 deletions
|
@ -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
|
// 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
|
// 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", {
|
var voxelPreview = Overlays.addOverlay("cube", {
|
||||||
position: { x: 0, y: 0, z: 0},
|
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 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 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) {
|
if (editToolsOn) {
|
||||||
moveTools();
|
moveTools();
|
||||||
}
|
}
|
||||||
|
@ -301,6 +383,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);
|
||||||
|
|
||||||
|
@ -879,6 +968,15 @@ function mousePressEvent(event) {
|
||||||
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);
|
||||||
|
pasteMode = false;
|
||||||
|
moveTools();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (pasteMode) {
|
if (pasteMode) {
|
||||||
var pasteVoxel = getNewPasteVoxel(pickRay);
|
var pasteVoxel = getNewPasteVoxel(pickRay);
|
||||||
Clipboard.pasteVoxel(pasteVoxel.origin.x, pasteVoxel.origin.y, pasteVoxel.origin.z, pasteVoxel.voxelSize);
|
Clipboard.pasteVoxel(pasteVoxel.origin.x, pasteVoxel.origin.y, pasteVoxel.origin.z, pasteVoxel.voxelSize);
|
||||||
|
@ -1051,14 +1149,24 @@ function menuItemEvent(menuItem) {
|
||||||
moveTools();
|
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;
|
pasteMode = false;
|
||||||
moveTools();
|
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") {
|
||||||
|
@ -1066,9 +1174,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()) {
|
||||||
pasteMode = true;
|
showImport(true);
|
||||||
|
pasteMode = true;
|
||||||
|
}
|
||||||
moveTools();
|
moveTools();
|
||||||
}
|
}
|
||||||
if (menuItem == "Nudge") {
|
if (menuItem == "Nudge") {
|
||||||
|
@ -1435,6 +1545,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1467,6 +1582,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,9 +140,9 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
_fps(120.0f),
|
_fps(120.0f),
|
||||||
_justStarted(true),
|
_justStarted(true),
|
||||||
_voxelImporter(NULL),
|
_voxelImporter(NULL),
|
||||||
|
_sharedVoxelSystem(TREE_SCALE, DEFAULT_MAX_VOXELS_PER_SYSTEM, &_clipboard),
|
||||||
_wantToKillLocalVoxels(false),
|
_wantToKillLocalVoxels(false),
|
||||||
_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),
|
||||||
|
@ -1387,6 +1387,8 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::importVoxels() {
|
void Application::importVoxels() {
|
||||||
|
int result = 1;
|
||||||
|
|
||||||
if (!_voxelImporter) {
|
if (!_voxelImporter) {
|
||||||
_voxelImporter = new VoxelImporter(_window);
|
_voxelImporter = new VoxelImporter(_window);
|
||||||
_voxelImporter->loadSettings(_settings);
|
_voxelImporter->loadSettings(_settings);
|
||||||
|
@ -1394,6 +1396,7 @@ void Application::importVoxels() {
|
||||||
|
|
||||||
if (!_voxelImporter->exec()) {
|
if (!_voxelImporter->exec()) {
|
||||||
qDebug() << "[DEBUG] Import succeeded." << endl;
|
qDebug() << "[DEBUG] Import succeeded." << endl;
|
||||||
|
result = 0;
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "[DEBUG] Import failed." << endl;
|
qDebug() << "[DEBUG] Import failed." << endl;
|
||||||
if (_sharedVoxelSystem.getTree() == _voxelImporter->getVoxelTree()) {
|
if (_sharedVoxelSystem.getTree() == _voxelImporter->getVoxelTree()) {
|
||||||
|
@ -1404,6 +1407,8 @@ void Application::importVoxels() {
|
||||||
|
|
||||||
// restore the main window's active state
|
// restore the main window's active state
|
||||||
_window->activateWindow();
|
_window->activateWindow();
|
||||||
|
|
||||||
|
emit importDone(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::cutVoxels(const VoxelDetail& sourceVoxel) {
|
void Application::cutVoxels(const VoxelDetail& sourceVoxel) {
|
||||||
|
@ -1495,9 +1500,8 @@ 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();
|
||||||
|
|
||||||
|
|
|
@ -225,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 with a return code.
|
||||||
|
void importDone(int);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void domainChanged(const QString& domainHostname);
|
void domainChanged(const QString& domainHostname);
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
|
@ -351,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;
|
||||||
|
|
|
@ -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(int)), &loop, SLOT(quit()));
|
||||||
|
emit readyToImport();
|
||||||
|
int returnCode = loop.exec();
|
||||||
|
|
||||||
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,9 +40,11 @@ void LocalVoxelsOverlay::update(float deltatime) {
|
||||||
_voxelSystem->init();
|
_voxelSystem->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_voxelCount != _tree->getOctreeElementsCount()) {
|
if (_visible && _voxelCount != _tree->getOctreeElementsCount()) {
|
||||||
_voxelCount = _tree->getOctreeElementsCount();
|
_voxelCount = _tree->getOctreeElementsCount();
|
||||||
|
_tree->lockForWrite();
|
||||||
_voxelSystem->forceRedrawEntireTree();
|
_voxelSystem->forceRedrawEntireTree();
|
||||||
|
_tree->unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@ void Volume3DOverlay::setProperties(const QScriptValue& properties) {
|
||||||
if (properties.property("size").isValid()) {
|
if (properties.property("size").isValid()) {
|
||||||
setSize(properties.property("size").toVariant().toFloat());
|
setSize(properties.property("size").toVariant().toFloat());
|
||||||
}
|
}
|
||||||
|
if (properties.property("scale").isValid()) {
|
||||||
|
setSize(properties.property("scale").toVariant().toFloat());
|
||||||
|
}
|
||||||
|
|
||||||
if (properties.property("isSolid").isValid()) {
|
if (properties.property("isSolid").isValid()) {
|
||||||
setIsSolid(properties.property("isSolid").toVariant().toBool());
|
setIsSolid(properties.property("isSolid").toVariant().toBool());
|
||||||
|
|
Loading…
Reference in a new issue