Added stuff to localVoxelsExample.js

This commit is contained in:
Atlante45 2014-03-03 17:52:49 -08:00
parent f1ce034c35
commit 357d71e637
2 changed files with 43 additions and 8 deletions

View file

@ -1,7 +1,18 @@
var TREE_SCALE = 16384;
var tree = LocalVoxels("tree");
tree.setVoxel(0, 0, 0, 0.5, 255, 0, 0);
tree.setVoxel(0.5, 0.5, 0.5, 0.5, 0, 255, 0);
tree.setVoxel(0, 0, 0,
0.5 * TREE_SCALE,
255, 0, 0);
tree.setVoxel(0.5 * TREE_SCALE,
0.5 * TREE_SCALE,
0.5 * TREE_SCALE,
0.5 * TREE_SCALE,
0, 255, 0);
var copy = LocalVoxels("copy");
tree.pasteFrom(0, 0, 0, TREE_SCALE, "copy");
tree.pasteFrom(0, 0, 0, TREE_SCALE, "clipboard");
var overlay1 = Overlays.addOverlay("localvoxels", {
position: {x: 1, y: 1, z: 1},
@ -21,7 +32,13 @@ var overlay3 = Overlays.addOverlay("localvoxels", {
var overlay4 = Overlays.addOverlay("localvoxels", {
position: {x: 1, y: 4, z: 1},
size: 1,
name: "tree"
name: "copy"
});
var clipboard = Overlays.addOverlay("localvoxels", {
position: {x: 1, y: 5, z: 1},
size: 1,
name: "clipboard"
});
@ -31,5 +48,6 @@ function scriptEnding() {
Overlays.deleteOverlay(overlay2);
Overlays.deleteOverlay(overlay3);
Overlays.deleteOverlay(overlay4);
Overlays.deleteOverlay(clipboard);
}
Script.scriptEnding.connect(scriptEnding);

View file

@ -54,7 +54,11 @@ void LocalVoxels::setVoxelNonDestructive(float x, float y, float z, float scale,
}
if (_tree ) {
if (_tree->tryLockForWrite()) {
_tree->createVoxel(x, y, z, scale, red, green, blue, false);
_tree->createVoxel(x / (float)TREE_SCALE,
y / (float)TREE_SCALE,
z / (float)TREE_SCALE,
scale / (float)TREE_SCALE,
red, green, blue, false);
_tree->unlock();
}
}
@ -68,7 +72,11 @@ void LocalVoxels::setVoxel(float x, float y, float z, float scale,
}
if (_tree ) {
if (_tree->tryLockForWrite()) {
_tree->createVoxel(x, y, z, scale, red, green, blue, true);
_tree->createVoxel(x / (float)TREE_SCALE,
y / (float)TREE_SCALE,
z / (float)TREE_SCALE,
scale / (float)TREE_SCALE,
red, green, blue, true);
_tree->unlock();
}
}
@ -81,7 +89,10 @@ void LocalVoxels::eraseVoxel(float x, float y, float z, float scale) {
}
if (_tree ) {
if (_tree->tryLockForWrite()) {
_tree->deleteVoxelAt(x, y, z, scale);
_tree->deleteVoxelAt(x / (float)TREE_SCALE,
y / (float)TREE_SCALE,
z / (float)TREE_SCALE,
scale / (float)TREE_SCALE);
_tree->unlock();
}
}
@ -93,7 +104,10 @@ void LocalVoxels::copyTo(float x, float y, float z, float scale, const QString d
return;
}
StrongVoxelTreePointer destinationTree = LocalVoxelsList::getInstance()->getTree(destination);
VoxelTreeElement* destinationNode = destinationTree->getVoxelAt(x, y, z, scale);
VoxelTreeElement* destinationNode = destinationTree->getVoxelAt(x / (float)TREE_SCALE,
y / (float)TREE_SCALE,
z / (float)TREE_SCALE,
scale / (float)TREE_SCALE);
destinationTree->copyFromTreeIntoSubTree(_tree.data(), destinationNode);
}
@ -103,7 +117,10 @@ void LocalVoxels::pasteFrom(float x, float y, float z, float scale, const QStrin
return;
}
StrongVoxelTreePointer sourceTree = LocalVoxelsList::getInstance()->getTree(source);
VoxelTreeElement* sourceNode = _tree->getVoxelAt(x, y, z, scale);
VoxelTreeElement* sourceNode = _tree->getVoxelAt(x / (float)TREE_SCALE,
y / (float)TREE_SCALE,
z / (float)TREE_SCALE,
scale / (float)TREE_SCALE);
_tree->copySubTreeIntoNewTree(sourceNode, sourceTree.data(), true);
}