mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 04:07:11 +02:00
remove voxel related scripts
This commit is contained in:
parent
67595ea571
commit
48285b21c4
23 changed files with 17 additions and 4303 deletions
|
@ -145,13 +145,9 @@ function sendCommand(id, action) {
|
|||
return;
|
||||
}
|
||||
|
||||
Voxels.setVoxel(controlVoxelPosition.x + id * controlVoxelSize,
|
||||
controlVoxelPosition.y,
|
||||
controlVoxelPosition.z,
|
||||
controlVoxelSize,
|
||||
COLORS[action].red,
|
||||
COLORS[action].green,
|
||||
COLORS[action].blue);
|
||||
// TODO: Fix this to use some mechanism other than voxels
|
||||
//Voxels.setVoxel(controlVoxelPosition.x + id * controlVoxelSize, controlVoxelPosition.y, controlVoxelPosition.z,
|
||||
// controlVoxelSize, COLORS[action].red, COLORS[action].green, COLORS[action].blue);
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
|
|
|
@ -82,10 +82,9 @@ function getAction(controlVoxel) {
|
|||
if (controlVoxel.red === COLORS[i].red &&
|
||||
controlVoxel.green === COLORS[i].green &&
|
||||
controlVoxel.blue === COLORS[i].blue) {
|
||||
Voxels.eraseVoxel(controlVoxelPosition.x,
|
||||
controlVoxelPosition.y,
|
||||
controlVoxelPosition.z,
|
||||
controlVoxelSize);
|
||||
|
||||
// TODO: Fix this to use some mechanism other than voxels
|
||||
//Voxels.eraseVoxel(controlVoxelPosition.x, controlVoxelPosition.y, controlVoxelPosition.z, controlVoxelSize);
|
||||
return parseInt(i);
|
||||
}
|
||||
}
|
||||
|
@ -101,10 +100,9 @@ function update(event) {
|
|||
return;
|
||||
}
|
||||
|
||||
var controlVoxel = Voxels.getVoxelAt(controlVoxelPosition.x,
|
||||
controlVoxelPosition.y,
|
||||
controlVoxelPosition.z,
|
||||
controlVoxelSize);
|
||||
// TODO: Fix this to use some mechanism other than voxels
|
||||
// Voxels.getVoxelAt(controlVoxelPosition.x, controlVoxelPosition.y, controlVoxelPosition.z, controlVoxelSize);
|
||||
var controlVoxel = false;
|
||||
var action = getAction(controlVoxel);
|
||||
|
||||
switch(action) {
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
//
|
||||
// addVoxelOnMouseClickExample.js
|
||||
// examples
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 2/6/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This is an example script that demonstrates use of the Camera and Voxels class to implement
|
||||
// clicking on a voxel and adding a new voxel on the clicked on face
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
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);
|
||||
if (intersection.intersects) {
|
||||
|
||||
// Note: due to the current C++ "click on voxel" behavior, these values may be the animated color for the voxel
|
||||
print("clicked on voxel.red/green/blue=" + intersection.voxel.red + ", "
|
||||
+ intersection.voxel.green + ", " + intersection.voxel.blue);
|
||||
print("clicked on voxel.x/y/z/s=" + intersection.voxel.x + ", "
|
||||
+ intersection.voxel.y + ", " + intersection.voxel.z+ ": " + intersection.voxel.s);
|
||||
print("clicked on face=" + intersection.face);
|
||||
print("clicked on distance=" + intersection.distance);
|
||||
|
||||
var newVoxel = {
|
||||
x: intersection.voxel.x,
|
||||
y: intersection.voxel.y,
|
||||
z: intersection.voxel.z,
|
||||
s: intersection.voxel.s,
|
||||
red: 255,
|
||||
green: 0,
|
||||
blue: 255 };
|
||||
|
||||
if (intersection.face == "MIN_X_FACE") {
|
||||
newVoxel.x -= newVoxel.s;
|
||||
} else if (intersection.face == "MAX_X_FACE") {
|
||||
newVoxel.x += newVoxel.s;
|
||||
} else if (intersection.face == "MIN_Y_FACE") {
|
||||
newVoxel.y -= newVoxel.s;
|
||||
} else if (intersection.face == "MAX_Y_FACE") {
|
||||
newVoxel.y += newVoxel.s;
|
||||
} else if (intersection.face == "MIN_Z_FACE") {
|
||||
newVoxel.z -= newVoxel.s;
|
||||
} else if (intersection.face == "MAX_Z_FACE") {
|
||||
newVoxel.z += newVoxel.s;
|
||||
}
|
||||
|
||||
print("Voxels.setVoxel("+newVoxel.x + ", "
|
||||
+ newVoxel.y + ", " + newVoxel.z + ", " + newVoxel.s + ", "
|
||||
+ newVoxel.red + ", " + newVoxel.green + ", " + newVoxel.blue + ")" );
|
||||
|
||||
Voxels.setVoxel(newVoxel.x, newVoxel.y, newVoxel.z, newVoxel.s, newVoxel.red, newVoxel.green, newVoxel.blue);
|
||||
}
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
|
||||
function scriptEnding() {
|
||||
}
|
||||
Script.scriptEnding.connect(scriptEnding);
|
|
@ -1,162 +0,0 @@
|
|||
//
|
||||
// clipboardExample.js
|
||||
// examples
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 1/28/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This is an example script that demonstrates use of the Clipboard class
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var selectedVoxel = { x: 0, y: 0, z: 0, s: 0 };
|
||||
var selectedSize = 4;
|
||||
|
||||
function setupMenus() {
|
||||
// hook up menus
|
||||
Menu.menuItemEvent.connect(menuItemEvent);
|
||||
|
||||
// delete the standard application menu item
|
||||
Menu.removeMenuItem("Edit", "Cut");
|
||||
Menu.removeMenuItem("Edit", "Copy");
|
||||
Menu.removeMenuItem("Edit", "Paste");
|
||||
Menu.removeMenuItem("Edit", "Delete");
|
||||
Menu.removeMenuItem("Edit", "Nudge");
|
||||
Menu.removeMenuItem("Edit", "Replace from File");
|
||||
Menu.removeMenuItem("File", "Export Voxels");
|
||||
Menu.removeMenuItem("File", "Import Voxels");
|
||||
|
||||
// delete the standard application menu item
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Cut", shortcutKey: "CTRL+X", afterItem: "Voxels" });
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Copy", shortcutKey: "CTRL+C", afterItem: "Cut" });
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Paste", shortcutKey: "CTRL+V", afterItem: "Copy" });
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Nudge", shortcutKey: "CTRL+N", afterItem: "Paste" });
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Replace from File", shortcutKey: "CTRL+R", afterItem: "Nudge" });
|
||||
Menu.addMenuItem({ menuName: "Edit", menuItemName: "Delete", shortcutKeyEvent: { text: "backspace" }, afterItem: "Nudge" });
|
||||
Menu.addMenuItem({ menuName: "File", menuItemName: "Export Voxels", shortcutKey: "CTRL+E", afterItem: "Voxels" });
|
||||
Menu.addMenuItem({ menuName: "File", menuItemName: "Import Voxels", shortcutKey: "CTRL+I", afterItem: "Export Voxels" });
|
||||
}
|
||||
|
||||
function menuItemEvent(menuItem) {
|
||||
var debug = true;
|
||||
if (debug) {
|
||||
print("menuItemEvent " + menuItem);
|
||||
}
|
||||
|
||||
// Note: this sample uses Alt+ as the key codes for these clipboard items
|
||||
if (menuItem == "Copy") {
|
||||
print("copying...");
|
||||
Clipboard.copyVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
||||
}
|
||||
if (menuItem == "Cut") {
|
||||
print("cutting...");
|
||||
Clipboard.cutVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
||||
}
|
||||
if (menuItem == "Paste") {
|
||||
print("pasting...");
|
||||
Clipboard.pasteVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s);
|
||||
}
|
||||
if (menuItem == "Delete") {
|
||||
print("deleting...");
|
||||
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();
|
||||
}
|
||||
if (menuItem == "Nudge") {
|
||||
print("nudge");
|
||||
Clipboard.nudgeVoxel(selectedVoxel.x, selectedVoxel.y, selectedVoxel.z, selectedVoxel.s, { x: -1, y: 0, z: 0 });
|
||||
}
|
||||
if (menuItem == "Replace from File") {
|
||||
var filename = Window.browse("Select file to load replacement", "", "Voxel Files (*.png *.svo *.schematic)");
|
||||
if (filename) {
|
||||
Clipboard.importVoxel(filename, selectedVoxel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var selectCube = Overlays.addOverlay("cube", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
size: selectedSize,
|
||||
color: { red: 255, green: 255, blue: 0},
|
||||
alpha: 1,
|
||||
solid: false,
|
||||
visible: false,
|
||||
lineWidth: 4
|
||||
});
|
||||
|
||||
|
||||
function mouseMoveEvent(event) {
|
||||
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
|
||||
var debug = false;
|
||||
if (debug) {
|
||||
print("mouseMoveEvent event.x,y=" + event.x + ", " + event.y);
|
||||
print("called Camera.computePickRay()");
|
||||
print("computePickRay origin=" + pickRay.origin.x + ", " + pickRay.origin.y + ", " + pickRay.origin.z);
|
||||
print("computePickRay direction=" + pickRay.direction.x + ", " + pickRay.direction.y + ", " + pickRay.direction.z);
|
||||
}
|
||||
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
|
||||
if (intersection.intersects) {
|
||||
if (debug) {
|
||||
print("intersection voxel.red/green/blue=" + intersection.voxel.red + ", "
|
||||
+ intersection.voxel.green + ", " + intersection.voxel.blue);
|
||||
print("intersection voxel.x/y/z/s=" + intersection.voxel.x + ", "
|
||||
+ intersection.voxel.y + ", " + intersection.voxel.z+ ": " + intersection.voxel.s);
|
||||
print("intersection face=" + intersection.face);
|
||||
print("intersection distance=" + intersection.distance);
|
||||
print("intersection intersection.x/y/z=" + intersection.intersection.x + ", "
|
||||
+ intersection.intersection.y + ", " + intersection.intersection.z);
|
||||
}
|
||||
|
||||
|
||||
|
||||
var x = Math.floor(intersection.voxel.x / selectedSize) * selectedSize;
|
||||
var y = Math.floor(intersection.voxel.y / selectedSize) * selectedSize;
|
||||
var z = Math.floor(intersection.voxel.z / selectedSize) * selectedSize;
|
||||
selectedVoxel = { x: x, y: y, z: z, s: selectedSize };
|
||||
Overlays.editOverlay(selectCube, { position: selectedVoxel, size: selectedSize, visible: true } );
|
||||
} else {
|
||||
Overlays.editOverlay(selectCube, { visible: false } );
|
||||
selectedVoxel = { x: 0, y: 0, z: 0, s: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||
|
||||
function wheelEvent(event) {
|
||||
var debug = false;
|
||||
if (debug) {
|
||||
print("wheelEvent");
|
||||
print(" event.x,y=" + event.x + ", " + event.y);
|
||||
print(" event.delta=" + event.delta);
|
||||
print(" event.orientation=" + event.orientation);
|
||||
print(" event.isLeftButton=" + event.isLeftButton);
|
||||
print(" event.isRightButton=" + event.isRightButton);
|
||||
print(" event.isMiddleButton=" + event.isMiddleButton);
|
||||
print(" event.isShifted=" + event.isShifted);
|
||||
print(" event.isControl=" + event.isControl);
|
||||
print(" event.isMeta=" + event.isMeta);
|
||||
print(" event.isAlt=" + event.isAlt);
|
||||
}
|
||||
}
|
||||
|
||||
Controller.wheelEvent.connect(wheelEvent);
|
||||
|
||||
function scriptEnding() {
|
||||
Overlays.deleteOverlay(selectCube);
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
setupMenus();
|
|
@ -1720,7 +1720,7 @@ var ModelImporter = function (opts) {
|
|||
this.mouseMoveEvent = function (event) {
|
||||
if (self._importing) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
var intersection = false; //Voxels.findRayIntersection(pickRay);
|
||||
|
||||
var distance = 2;// * self._scale;
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,648 +0,0 @@
|
|||
//
|
||||
// fallingSand.js
|
||||
// examples
|
||||
//
|
||||
// Created by Ben Arnold on 7/14/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This sample script allows the user to place sand voxels that will undergo
|
||||
// cellular automata physics.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
Script.include("libraries/globals.js");
|
||||
|
||||
var zFightingSizeAdjust = 0.002; // used to adjust preview voxels to prevent z fighting
|
||||
var previewLineWidth = 2.0;
|
||||
|
||||
var voxelSize = 1;
|
||||
var windowDimensions = Controller.getViewportDimensions();
|
||||
var toolIconUrl = HIFI_PUBLIC_BUCKET + "images/tools/";
|
||||
|
||||
var MAX_VOXEL_SCALE_POWER = 5;
|
||||
var MIN_VOXEL_SCALE_POWER = -8;
|
||||
var MAX_VOXEL_SCALE = Math.pow(2.0, MAX_VOXEL_SCALE_POWER);
|
||||
var MIN_VOXEL_SCALE = Math.pow(2.0, MIN_VOXEL_SCALE_POWER);
|
||||
|
||||
|
||||
var linePreviewTop = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 0, blue: 255},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
var linePreviewBottom = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 0, blue: 255},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
var linePreviewLeft = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 0, blue: 255},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
var linePreviewRight = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 0, blue: 255},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
|
||||
var UIColor = { red: 119, green: 103, blue: 53};
|
||||
var activeUIColor = { red: 234, green: 206, blue: 106};
|
||||
|
||||
var toolHeight = 50;
|
||||
var toolWidth = 50;
|
||||
|
||||
var editToolsOn = true;
|
||||
|
||||
var voxelToolSelected = false;
|
||||
|
||||
var scaleSelectorWidth = 144;
|
||||
var scaleSelectorHeight = 37;
|
||||
|
||||
var scaleSelectorX = windowDimensions.x / 5.0;
|
||||
var scaleSelectorY = windowDimensions.y - scaleSelectorHeight;
|
||||
|
||||
var voxelTool = Overlays.addOverlay("image", {
|
||||
x: scaleSelectorX + scaleSelectorWidth + 1, y: windowDimensions.y - toolHeight, width: toolWidth, height: toolHeight,
|
||||
subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
|
||||
imageURL: toolIconUrl + "voxel-tool.svg",
|
||||
visible: editToolsOn,
|
||||
color: UIColor,
|
||||
alpha: 0.9
|
||||
});
|
||||
|
||||
var copyScale = true;
|
||||
function ScaleSelector() {
|
||||
this.x = scaleSelectorX;
|
||||
this.y = scaleSelectorY;
|
||||
this.width = scaleSelectorWidth;
|
||||
this.height = scaleSelectorHeight;
|
||||
|
||||
this.displayPower = false;
|
||||
this.scale = 1.0;
|
||||
this.power = 0;
|
||||
|
||||
this.FIRST_PART = this.width * 40.0 / 100.0;
|
||||
this.SECOND_PART = this.width * 37.0 / 100.0;
|
||||
|
||||
this.buttonsOverlay = Overlays.addOverlay("image", {
|
||||
x: this.x, y: this.y,
|
||||
width: this.width, height: this.height,
|
||||
//subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
|
||||
imageURL: toolIconUrl + "voxel-size-selector.svg",
|
||||
alpha: 0.9,
|
||||
visible: editToolsOn,
|
||||
color: activeUIColor
|
||||
});
|
||||
this.textOverlay = Overlays.addOverlay("text", {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
width: this.SECOND_PART, height: this.height,
|
||||
topMargin: 13,
|
||||
text: this.scale.toString(),
|
||||
backgroundAlpha: 0.0,
|
||||
visible: editToolsOn,
|
||||
color: activeUIColor
|
||||
});
|
||||
this.powerOverlay = Overlays.addOverlay("text", {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
width: this.SECOND_PART, height: this.height,
|
||||
leftMargin: 28,
|
||||
text: this.power.toString(),
|
||||
backgroundAlpha: 0.0,
|
||||
visible: false,
|
||||
color: activeUIColor
|
||||
});
|
||||
this.setScale = function(scale) {
|
||||
if (scale > MAX_VOXEL_SCALE) {
|
||||
scale = MAX_VOXEL_SCALE;
|
||||
}
|
||||
if (scale < MIN_VOXEL_SCALE) {
|
||||
scale = MIN_VOXEL_SCALE;
|
||||
}
|
||||
|
||||
this.scale = scale;
|
||||
this.power = Math.floor(Math.log(scale) / Math.log(2));
|
||||
this.update();
|
||||
}
|
||||
|
||||
this.show = function(doShow) {
|
||||
Overlays.editOverlay(this.buttonsOverlay, {visible: doShow});
|
||||
Overlays.editOverlay(this.textOverlay, {visible: doShow});
|
||||
Overlays.editOverlay(this.powerOverlay, {visible: doShow && this.displayPower});
|
||||
}
|
||||
|
||||
this.move = function() {
|
||||
this.x = swatchesX + swatchesWidth;
|
||||
this.y = swatchesY;
|
||||
|
||||
Overlays.editOverlay(this.buttonsOverlay, {
|
||||
x: this.x, y: this.y,
|
||||
});
|
||||
Overlays.editOverlay(this.textOverlay, {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
});
|
||||
Overlays.editOverlay(this.powerOverlay, {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.switchDisplay = function() {
|
||||
this.displayPower = !this.displayPower;
|
||||
|
||||
if (this.displayPower) {
|
||||
Overlays.editOverlay(this.textOverlay, {
|
||||
leftMargin: 18,
|
||||
text: "2"
|
||||
});
|
||||
Overlays.editOverlay(this.powerOverlay, {
|
||||
text: this.power.toString(),
|
||||
visible: editToolsOn
|
||||
});
|
||||
} else {
|
||||
Overlays.editOverlay(this.textOverlay, {
|
||||
leftMargin: 13,
|
||||
text: this.scale.toString()
|
||||
});
|
||||
Overlays.editOverlay(this.powerOverlay, {
|
||||
visible: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.update = function() {
|
||||
if (this.displayPower) {
|
||||
Overlays.editOverlay(this.powerOverlay, {text: this.power.toString()});
|
||||
} else {
|
||||
Overlays.editOverlay(this.textOverlay, {text: this.scale.toString()});
|
||||
}
|
||||
}
|
||||
|
||||
this.incrementScale = function() {
|
||||
copyScale = false;
|
||||
if (this.power < MAX_VOXEL_SCALE_POWER) {
|
||||
++this.power;
|
||||
this.scale *= 2.0;
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
|
||||
this.decrementScale = function() {
|
||||
copyScale = false;
|
||||
if (MIN_VOXEL_SCALE_POWER < this.power) {
|
||||
--this.power;
|
||||
this.scale /= 2.0;
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
|
||||
this.clicked = function(x, y) {
|
||||
if (this.x < x && x < this.x + this.width &&
|
||||
this.y < y && y < this.y + this.height) {
|
||||
|
||||
if (x < this.x + this.FIRST_PART) {
|
||||
this.decrementScale();
|
||||
} else if (x < this.x + this.FIRST_PART + this.SECOND_PART) {
|
||||
this.switchDisplay();
|
||||
} else {
|
||||
this.incrementScale();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
this.cleanup = function() {
|
||||
Overlays.deleteOverlay(this.buttonsOverlay);
|
||||
Overlays.deleteOverlay(this.textOverlay);
|
||||
Overlays.deleteOverlay(this.powerOverlay);
|
||||
}
|
||||
|
||||
}
|
||||
var scaleSelector = new ScaleSelector();
|
||||
|
||||
function calculateVoxelFromIntersection(intersection, operation) {
|
||||
|
||||
var resultVoxel;
|
||||
|
||||
var x;
|
||||
var y;
|
||||
var z;
|
||||
|
||||
// if our "target voxel size" is larger than the voxel we intersected with, then we need to find the closest
|
||||
// ancestor voxel of our target size that contains our intersected voxel.
|
||||
if (voxelSize > intersection.voxel.s) {
|
||||
x = Math.floor(intersection.voxel.x / voxelSize) * voxelSize;
|
||||
y = Math.floor(intersection.voxel.y / voxelSize) * voxelSize;
|
||||
z = Math.floor(intersection.voxel.z / voxelSize) * voxelSize;
|
||||
} else {
|
||||
// otherwise, calculate the enclosed voxel of size voxelSize that the intersection point falls inside of.
|
||||
// if you have a voxelSize that's smaller than the voxel you're intersecting, this calculation will result
|
||||
// in the subvoxel that the intersection point falls in, if the target voxelSize matches the intersecting
|
||||
// voxel this still works and results in returning the intersecting voxel which is what we want
|
||||
var adjustToCenter = Vec3.multiply(Voxels.getFaceVector(intersection.face), (voxelSize * -0.5));
|
||||
|
||||
var centerOfIntersectingVoxel = Vec3.sum(intersection.intersection, adjustToCenter);
|
||||
x = Math.floor(centerOfIntersectingVoxel.x / voxelSize) * voxelSize;
|
||||
y = Math.floor(centerOfIntersectingVoxel.y / voxelSize) * voxelSize;
|
||||
z = Math.floor(centerOfIntersectingVoxel.z / voxelSize) * voxelSize;
|
||||
}
|
||||
resultVoxel = { x: x, y: y, z: z, s: voxelSize };
|
||||
var highlightAt = { x: x, y: y, z: z, s: voxelSize };
|
||||
|
||||
|
||||
|
||||
// we only do the "add to the face we're pointing at" adjustment, if the operation is an add
|
||||
// operation, and the target voxel size is equal to or smaller than the intersecting voxel.
|
||||
var wantAddAdjust = (operation == "add" && (voxelSize <= intersection.voxel.s));
|
||||
|
||||
// now we also want to calculate the "edge square" for the face for this voxel
|
||||
if (intersection.face == "MIN_X_FACE") {
|
||||
|
||||
highlightAt.x = x - zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.x -= voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomRight = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
resultVoxel.topLeft = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.topRight = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
|
||||
} else if (intersection.face == "MAX_X_FACE") {
|
||||
|
||||
highlightAt.x = x + voxelSize + zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.x += resultVoxel.s;
|
||||
}
|
||||
|
||||
resultVoxel.bottomRight = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
resultVoxel.topRight = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.topLeft = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
|
||||
} else if (intersection.face == "MIN_Y_FACE") {
|
||||
|
||||
highlightAt.y = y - zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.y -= voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.topRight = {x: highlightAt.x + zFightingSizeAdjust , y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.topLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + zFightingSizeAdjust , y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust , y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
|
||||
} else if (intersection.face == "MAX_Y_FACE") {
|
||||
|
||||
highlightAt.y = y + voxelSize + zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.y += voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust};
|
||||
resultVoxel.topRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust};
|
||||
resultVoxel.topLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust};
|
||||
|
||||
} else if (intersection.face == "MIN_Z_FACE") {
|
||||
|
||||
highlightAt.z = z - zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.z -= voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z};
|
||||
resultVoxel.topRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.topLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z};
|
||||
|
||||
} else if (intersection.face == "MAX_Z_FACE") {
|
||||
|
||||
highlightAt.z = z + voxelSize + zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.z += voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z};
|
||||
resultVoxel.topLeft = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.topRight = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z};
|
||||
|
||||
}
|
||||
return resultVoxel;
|
||||
}
|
||||
|
||||
var trackLastMouseX = 0;
|
||||
var trackLastMouseY = 0;
|
||||
|
||||
function showPreviewLines() {
|
||||
|
||||
var pickRay = Camera.computePickRay(trackLastMouseX, trackLastMouseY);
|
||||
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
|
||||
if (intersection.intersects) {
|
||||
var resultVoxel = calculateVoxelFromIntersection(intersection, "");
|
||||
Overlays.editOverlay(linePreviewTop, { position: resultVoxel.topLeft, end: resultVoxel.topRight, visible: true });
|
||||
Overlays.editOverlay(linePreviewBottom, { position: resultVoxel.bottomLeft, end: resultVoxel.bottomRight, visible: true });
|
||||
Overlays.editOverlay(linePreviewLeft, { position: resultVoxel.topLeft, end: resultVoxel.bottomLeft, visible: true });
|
||||
Overlays.editOverlay(linePreviewRight, { position: resultVoxel.topRight, end: resultVoxel.bottomRight, visible: true });
|
||||
} else {
|
||||
Overlays.editOverlay(linePreviewTop, { visible: false });
|
||||
Overlays.editOverlay(linePreviewBottom, { visible: false });
|
||||
Overlays.editOverlay(linePreviewLeft, { visible: false });
|
||||
Overlays.editOverlay(linePreviewRight, { visible: false });
|
||||
}
|
||||
}
|
||||
|
||||
function mouseMoveEvent(event) {
|
||||
trackLastMouseX = event.x;
|
||||
trackLastMouseY = event.y;
|
||||
if (!voxelToolSelected) {
|
||||
return;
|
||||
}
|
||||
showPreviewLines();
|
||||
}
|
||||
|
||||
var BRUSH_RADIUS = 2;
|
||||
|
||||
function mousePressEvent(event) {
|
||||
var mouseX = event.x;
|
||||
var mouseY = event.y;
|
||||
|
||||
var clickedOnSomething = false;
|
||||
// Check if we clicked an overlay
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: mouseX, y: mouseY});
|
||||
|
||||
if (clickedOverlay == voxelTool) {
|
||||
voxelToolSelected = !voxelToolSelected;
|
||||
|
||||
if (voxelToolSelected == true) {
|
||||
Overlays.editOverlay(voxelTool, {
|
||||
color: activeUIColor
|
||||
});
|
||||
} else {
|
||||
Overlays.editOverlay(voxelTool, {
|
||||
color: UIColor
|
||||
});
|
||||
}
|
||||
|
||||
clickedOnSomething = true;
|
||||
} else if (scaleSelector.clicked(event.x, event.y)) {
|
||||
clickedOnSomething = true;
|
||||
voxelSize = scaleSelector.scale;
|
||||
}
|
||||
|
||||
// Return if we clicked on the UI or the voxel tool is disabled
|
||||
if (clickedOnSomething || !voxelToolSelected) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute the picking ray for the click
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
var resultVoxel = calculateVoxelFromIntersection(intersection, "add");
|
||||
|
||||
|
||||
//Add a clump of sand voxels
|
||||
makeSphere(resultVoxel.x, resultVoxel.y, resultVoxel.z, voxelSize * BRUSH_RADIUS, voxelSize);
|
||||
}
|
||||
|
||||
var sandArray = [];
|
||||
var numSand = 0;
|
||||
|
||||
|
||||
//These arrays are used to buffer add/remove operations so they can be batched together
|
||||
var addArray = [];
|
||||
var addArraySize = 0;
|
||||
var removeArray = [];
|
||||
var removeArraySize = 0;
|
||||
|
||||
//The colors must be different
|
||||
var activeSandColor = { r: 234, g: 206, b: 106};
|
||||
var inactiveSandColor = { r: 233, g: 206, b: 106};
|
||||
|
||||
//This is used as an optimization, so that we
|
||||
//will check our 6 neighbors at most once.
|
||||
var adjacentVoxels = [];
|
||||
var numAdjacentVoxels = 0;
|
||||
//Stores a list of voxels we need to activate
|
||||
var activateMap = {};
|
||||
|
||||
var UPDATES_PER_SECOND = 12.0; // frames per second
|
||||
var frameIndex = 0.0;
|
||||
var oldFrameIndex = 0;
|
||||
|
||||
function update(deltaTime) {
|
||||
frameIndex += deltaTime * UPDATES_PER_SECOND;
|
||||
if (Math.floor(frameIndex) == oldFrameIndex) {
|
||||
return;
|
||||
}
|
||||
oldFrameIndex++;
|
||||
|
||||
//Clear the activate map each frame
|
||||
activateMap = {};
|
||||
|
||||
//Update all sand in our sandArray
|
||||
var i = 0;
|
||||
while (i < numSand) {
|
||||
//Update the sand voxel and if it doesn't move, deactivate it
|
||||
if (updateSand(i) == false) {
|
||||
deactivateSand(i);
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < removeArraySize; i++) {
|
||||
var voxel = removeArray[i];
|
||||
Voxels.eraseVoxel(voxel.x, voxel.y, voxel.z, voxel.s);
|
||||
}
|
||||
removeArraySize = 0;
|
||||
|
||||
//Add all voxels that have moved
|
||||
for (var i = 0; i < addArraySize; i++) {
|
||||
var voxel = addArray[i];
|
||||
Voxels.setVoxel(voxel.x, voxel.y, voxel.z, voxel.s, voxel.r, voxel.g, voxel.b);
|
||||
}
|
||||
addArraySize = 0;
|
||||
|
||||
for (var key in activateMap) {
|
||||
var voxel = activateMap[key];
|
||||
Voxels.setVoxel(voxel.x, voxel.y, voxel.z, voxel.s, activeSandColor.r, activeSandColor.g, activeSandColor.b);
|
||||
sandArray[numSand++] = { x: voxel.x, y: voxel.y, z: voxel.z, s: voxel.s, r: activeSandColor.r, g: activeSandColor.g, b: activeSandColor.b };
|
||||
}
|
||||
}
|
||||
|
||||
//Adds a sphere of sand at the center cx,cy,cz
|
||||
function makeSphere(cx, cy, cz, r, voxelSize) {
|
||||
|
||||
var r2 = r * r;
|
||||
var distance2;
|
||||
var dx;
|
||||
var dy;
|
||||
var dz;
|
||||
|
||||
for (var x = cx - r; x <= cx + r; x += voxelSize) {
|
||||
for (var y = cy - r; y <= cy + r; y += voxelSize) {
|
||||
for (var z = cz - r; z <= cz + r; z += voxelSize) {
|
||||
dx = Math.abs(x - cx);
|
||||
dy = Math.abs(y - cy);
|
||||
dz = Math.abs(z - cz);
|
||||
distance2 = dx * dx + dy * dy + dz * dz;
|
||||
if (distance2 <= r2 && isVoxelEmpty(x, y, z, voxelSize)) {
|
||||
Voxels.setVoxel(x, y, z, voxelSize, activeSandColor.r, activeSandColor.g, activeSandColor.b);
|
||||
sandArray[numSand++] = { x: x, y: y, z: z, s: voxelSize, r: activeSandColor.r, g: activeSandColor.g, b: activeSandColor.b };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check if a given voxel is empty
|
||||
function isVoxelEmpty(x, y, z, s, isAdjacent) {
|
||||
var halfSize = s / 2;
|
||||
var point = {x: x + halfSize, y: y + halfSize, z: z + halfSize };
|
||||
|
||||
var adjacent = Voxels.getVoxelEnclosingPointBlocking(point);
|
||||
//If color is all 0, we assume its air.
|
||||
|
||||
if (adjacent.red == 0 && adjacent.green == 0 && adjacent.blue == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isAdjacent) {
|
||||
adjacentVoxels[numAdjacentVoxels++] = adjacent;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Moves voxel to x,y,z if the space is empty
|
||||
function tryMoveVoxel(voxel, x, y, z) {
|
||||
//If the adjacent voxel is empty, we will move to it.
|
||||
if (isVoxelEmpty(x, y, z, voxel.s, false)) {
|
||||
var hsize = voxel.s / 2;
|
||||
for (var i = 0; i < 5; i++) {
|
||||
var point = {x: voxel.x + directionVecs[i].x * voxel.s + hsize, y: voxel.y + directionVecs[i].y * voxel.s + hsize, z: voxel.z + directionVecs[i].z * voxel.s + hsize };
|
||||
adjacentVoxels[numAdjacentVoxels++] = Voxels.getVoxelEnclosingPointBlocking(point);
|
||||
}
|
||||
moveVoxel(voxel, x, y, z);
|
||||
|
||||
//Get all adjacent voxels for activation
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Moves voxel to x,y,z
|
||||
function moveVoxel(voxel, x, y, z) {
|
||||
activateNeighbors();
|
||||
removeArray[removeArraySize++] = {x: voxel.x, y: voxel.y, z: voxel.z, s: voxel.s};
|
||||
addArray[addArraySize++] = {x: x, y: y, z: z, s: voxel.s, r: activeSandColor.r, g: activeSandColor.g, b: activeSandColor.b};
|
||||
voxel.x = x;
|
||||
voxel.y = y;
|
||||
voxel.z = z;
|
||||
}
|
||||
|
||||
var LEFT = 0;
|
||||
var BACK = 1;
|
||||
var RIGHT = 2;
|
||||
var FRONT = 3;
|
||||
var TOP = 4;
|
||||
|
||||
//These indicate the different directions to neighbor voxels, so we can iterate them
|
||||
var directionVecs = [];
|
||||
directionVecs[LEFT] = {x: -1, y: 0, z: 0}; //Left
|
||||
directionVecs[BACK] = {x: 0, y: 0, z: -1}; //Back
|
||||
directionVecs[RIGHT] = {x: 1, y: 0, z: 0}; //Right
|
||||
directionVecs[FRONT] = {x: 0, y: 0, z: 1}; //Front
|
||||
directionVecs[TOP] = {x: 0, y: 1, z: 0}; //Top
|
||||
|
||||
function updateSand(i) {
|
||||
var voxel = sandArray[i];
|
||||
var size = voxel.s;
|
||||
var hsize = size / 2;
|
||||
numAdjacentVoxels = 0;
|
||||
|
||||
//Down
|
||||
if (tryMoveVoxel(voxel, voxel.x, voxel.y - size, voxel.z)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Left, back, right, front
|
||||
for (var i = 0; i < 4; i++) {
|
||||
if (isVoxelEmpty(voxel.x + directionVecs[i].x * size, voxel.y + directionVecs[i].y * size, voxel.z + directionVecs[i].z * size, size, true)
|
||||
&& isVoxelEmpty(voxel.x + directionVecs[i].x * size, (voxel.y - size) + directionVecs[i].y * size, voxel.z + directionVecs[i].z * size, size, false)) {
|
||||
//get the rest of the adjacent voxels
|
||||
for (var j = i + 1; j < 5; j++) {
|
||||
var point = {x: voxel.x + directionVecs[j].x * size + hsize, y: voxel.y + directionVecs[j].y * size + hsize, z: voxel.z + directionVecs[j].z * size + hsize };
|
||||
adjacentVoxels[numAdjacentVoxels++] = Voxels.getVoxelEnclosingPointBlocking(point);
|
||||
}
|
||||
moveVoxel(voxel, voxel.x + directionVecs[i].x * size, voxel.y + directionVecs[i].y * size, voxel.z + directionVecs[i].z * size);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function activateNeighbors() {
|
||||
for (var i = 0; i < numAdjacentVoxels; i++) {
|
||||
var voxel = adjacentVoxels[i];
|
||||
//Check if this neighbor is inactive, if so, activate it
|
||||
if (voxel.red == inactiveSandColor.r && voxel.green == inactiveSandColor.g && voxel.blue == inactiveSandColor.b) {
|
||||
activateMap[voxel.x.toString() + "," + voxel.y.toString() + ',' + voxel.z.toString()] = voxel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Deactivates a sand voxel to save processing power
|
||||
function deactivateSand(i) {
|
||||
var voxel = sandArray[i];
|
||||
addArray[addArraySize++] = {x: voxel.x, y: voxel.y, z: voxel.z, s: voxel.s, r: inactiveSandColor.r, g: inactiveSandColor.g, b: inactiveSandColor.b};
|
||||
sandArray[i] = sandArray[numSand-1];
|
||||
numSand--;
|
||||
}
|
||||
|
||||
//Cleanup
|
||||
function scriptEnding() {
|
||||
for (var i = 0; i < numSand; i++) {
|
||||
var voxel = sandArray[i];
|
||||
Voxels.eraseVoxel(voxel.x, voxel.y, voxel.z, voxel.s);
|
||||
}
|
||||
Overlays.deleteOverlay(linePreviewTop);
|
||||
Overlays.deleteOverlay(linePreviewBottom);
|
||||
Overlays.deleteOverlay(linePreviewLeft);
|
||||
Overlays.deleteOverlay(linePreviewRight);
|
||||
scaleSelector.cleanup();
|
||||
Overlays.deleteOverlay(voxelTool);
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||
|
||||
Script.update.connect(update);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
Voxels.setMaxPacketSize(1); //this is needed or a bug occurs :(
|
||||
Voxels.setPacketsPerSecond(10000);
|
|
@ -46,7 +46,7 @@ function vInterpolate(a, b, fraction) {
|
|||
}
|
||||
|
||||
var position = { x: 5.0, y: 0.6, z: 5.0 };
|
||||
Voxels.setVoxel(position.x, 0, position.z, 0.5, 0, 0, 255);
|
||||
//Voxels.setVoxel(position.x, 0, position.z, 0.5, 0, 0, 255);
|
||||
|
||||
var totalEntities = 0;
|
||||
function makeFountain(deltaTime) {
|
||||
|
|
|
@ -1,140 +0,0 @@
|
|||
//
|
||||
// gameoflife.js
|
||||
// examples
|
||||
//
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// The following is an example of Conway's Game of Life (http://en.wikipedia.org/wiki/Conway's_Game_of_Life)
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var NUMBER_OF_CELLS_EACH_DIMENSION = 64;
|
||||
var NUMBER_OF_CELLS = NUMBER_OF_CELLS_EACH_DIMENSION * NUMBER_OF_CELLS_EACH_DIMENSION;
|
||||
|
||||
var currentCells = [];
|
||||
var nextCells = [];
|
||||
|
||||
var METER_LENGTH = 1;
|
||||
var cellScale = (NUMBER_OF_CELLS_EACH_DIMENSION * METER_LENGTH) / NUMBER_OF_CELLS_EACH_DIMENSION;
|
||||
|
||||
// randomly populate the cell start values
|
||||
for (var i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) {
|
||||
// create the array to hold this row
|
||||
currentCells[i] = [];
|
||||
|
||||
// create the array to hold this row in the nextCells array
|
||||
nextCells[i] = [];
|
||||
|
||||
for (var j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) {
|
||||
currentCells[i][j] = Math.floor(Math.random() * 2);
|
||||
|
||||
// put the same value in the nextCells array for first board draw
|
||||
nextCells[i][j] = currentCells[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
function isNeighbourAlive(i, j) {
|
||||
if (i < 0 || i >= NUMBER_OF_CELLS_EACH_DIMENSION
|
||||
|| i < 0 || j >= NUMBER_OF_CELLS_EACH_DIMENSION) {
|
||||
return 0;
|
||||
} else {
|
||||
return currentCells[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
function updateCells() {
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
|
||||
for (i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) {
|
||||
for (j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) {
|
||||
// figure out the number of live neighbours for the i-j cell
|
||||
var liveNeighbours =
|
||||
isNeighbourAlive(i + 1, j - 1) + isNeighbourAlive(i + 1, j) + isNeighbourAlive(i + 1, j + 1) +
|
||||
isNeighbourAlive(i, j - 1) + isNeighbourAlive(i, j + 1) +
|
||||
isNeighbourAlive(i - 1, j - 1) + isNeighbourAlive(i - 1, j) + isNeighbourAlive(i - 1, j + 1);
|
||||
|
||||
if (currentCells[i][j]) {
|
||||
// live cell
|
||||
|
||||
if (liveNeighbours < 2) {
|
||||
// rule #1 - under-population - this cell will die
|
||||
// mark it zero to mark the change
|
||||
nextCells[i][j] = 0;
|
||||
} else if (liveNeighbours < 4) {
|
||||
// rule #2 - this cell lives
|
||||
// mark it -1 to mark no change
|
||||
nextCells[i][j] = -1;
|
||||
} else {
|
||||
// rule #3 - overcrowding - this cell dies
|
||||
// mark it zero to mark the change
|
||||
nextCells[i][j] = 0;
|
||||
}
|
||||
} else {
|
||||
// dead cell
|
||||
if (liveNeighbours == 3) {
|
||||
// rule #4 - reproduction - this cell revives
|
||||
// mark it one to mark the change
|
||||
nextCells[i][j] = 1;
|
||||
} else {
|
||||
// this cell stays dead
|
||||
// mark it -1 for no change
|
||||
nextCells[i][j] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Math.random() < 0.001) {
|
||||
// Random mutation to keep things interesting in there.
|
||||
nextCells[i][j] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) {
|
||||
for (j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) {
|
||||
if (nextCells[i][j] != -1) {
|
||||
// there has been a change to this cell, change the value in the currentCells array
|
||||
currentCells[i][j] = nextCells[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendNextCells() {
|
||||
for (var i = 0; i < NUMBER_OF_CELLS_EACH_DIMENSION; i++) {
|
||||
for (var j = 0; j < NUMBER_OF_CELLS_EACH_DIMENSION; j++) {
|
||||
if (nextCells[i][j] != -1) {
|
||||
// there has been a change to the state of this cell, send it
|
||||
|
||||
// find the x and y position for this voxel, z = 0
|
||||
var x = j * cellScale;
|
||||
var y = i * cellScale;
|
||||
|
||||
// queue a packet to add a voxel for the new cell
|
||||
var color = (nextCells[i][j] == 1) ? 255 : 1;
|
||||
Voxels.setVoxel(x, y, 0, cellScale, color, color, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sentFirstBoard = false;
|
||||
|
||||
function step(deltaTime) {
|
||||
if (sentFirstBoard) {
|
||||
// we've already sent the first full board, perform a step in time
|
||||
updateCells();
|
||||
} else {
|
||||
// this will be our first board send
|
||||
sentFirstBoard = true;
|
||||
}
|
||||
|
||||
sendNextCells();
|
||||
}
|
||||
|
||||
print("here");
|
||||
Script.update.connect(step);
|
||||
Voxels.setPacketsPerSecond(200);
|
||||
print("now here");
|
|
@ -116,7 +116,7 @@ function updateWarp() {
|
|||
direction: { x: 0, y: -1, z: 0 }
|
||||
};
|
||||
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
var intersection = Entities.findRayIntersection(pickRay);
|
||||
|
||||
if (intersection.intersects && intersection.distance < WARP_PICK_MAX_DISTANCE) {
|
||||
// Warp 1 meter above the object - this is an approximation
|
||||
|
|
|
@ -155,45 +155,6 @@ function shootTarget() {
|
|||
Audio.playSound(targetLaunchSound, audioOptions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function entityCollisionWithVoxel(entity, voxel, collision) {
|
||||
|
||||
print("entityCollisionWithVoxel....");
|
||||
|
||||
var VOXEL_SIZE = 0.5;
|
||||
// Don't make this big. I mean it.
|
||||
var CRATER_RADIUS = 5;
|
||||
var entityProperties = Entities.getEntityProperties(entity);
|
||||
var position = entityProperties.position;
|
||||
Entities.deleteEntity(entity);
|
||||
|
||||
audioOptions.position = collision.contactPoint;
|
||||
Audio.playSound(impactSound, audioOptions);
|
||||
|
||||
// Make a crater
|
||||
var center = collision.contactPoint;
|
||||
var RADIUS = CRATER_RADIUS * VOXEL_SIZE;
|
||||
var RADIUS2 = RADIUS * RADIUS;
|
||||
var distance2;
|
||||
var dx;
|
||||
var dy;
|
||||
var dz;
|
||||
for (var x = center.x - RADIUS; x <= center.x + RADIUS; x += VOXEL_SIZE) {
|
||||
for (var y = center.y - RADIUS; y <= center.y + RADIUS; y += VOXEL_SIZE) {
|
||||
for (var z = center.z - RADIUS; z <= center.z + RADIUS; z += VOXEL_SIZE) {
|
||||
dx = Math.abs(x - center.x);
|
||||
dy = Math.abs(y - center.y);
|
||||
dz = Math.abs(z - center.z);
|
||||
distance2 = dx * dx + dy * dy + dz * dz;
|
||||
if (distance2 <= RADIUS2) {
|
||||
Voxels.eraseVoxel(x, y, z, VOXEL_SIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function entityCollisionWithEntity(entity1, entity2, collision) {
|
||||
score++;
|
||||
if (showScore) {
|
||||
|
@ -355,7 +316,6 @@ function scriptEnding() {
|
|||
MyAvatar.detachOne(gunModel);
|
||||
}
|
||||
|
||||
Entities.entityCollisionWithVoxel.connect(entityCollisionWithVoxel);
|
||||
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
Script.update.connect(update);
|
||||
|
|
|
@ -1,834 +0,0 @@
|
|||
//
|
||||
// growPlants.js
|
||||
// examples
|
||||
//
|
||||
// Created by Benjamin Arnold on May 29, 2014
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This sample script allows the user to grow different types of plants on the voxels
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
Script.include("libraries/globals.js");
|
||||
|
||||
var zFightingSizeAdjust = 0.002; // used to adjust preview voxels to prevent z fighting
|
||||
var previewLineWidth = 2.0;
|
||||
|
||||
var voxelSize = 1;
|
||||
var windowDimensions = Controller.getViewportDimensions();
|
||||
var toolIconUrl = HIFI_PUBLIC_BUCKET + "images/tools/";
|
||||
|
||||
var MAX_VOXEL_SCALE_POWER = 5;
|
||||
var MIN_VOXEL_SCALE_POWER = -8;
|
||||
var MAX_VOXEL_SCALE = Math.pow(2.0, MAX_VOXEL_SCALE_POWER);
|
||||
var MIN_VOXEL_SCALE = Math.pow(2.0, MIN_VOXEL_SCALE_POWER);
|
||||
|
||||
|
||||
var linePreviewTop = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 255, blue: 0},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
var linePreviewBottom = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 255, blue: 0},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
var linePreviewLeft = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 255, blue: 0},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
var linePreviewRight = Overlays.addOverlay("line3d", {
|
||||
position: { x: 0, y: 0, z: 0},
|
||||
end: { x: 0, y: 0, z: 0},
|
||||
color: { red: 0, green: 255, blue: 0},
|
||||
alpha: 1,
|
||||
visible: false,
|
||||
lineWidth: previewLineWidth
|
||||
});
|
||||
|
||||
|
||||
var UIColor = { red: 0, green: 160, blue: 0};
|
||||
var activeUIColor = { red: 0, green: 255, blue: 0};
|
||||
|
||||
var toolHeight = 50;
|
||||
var toolWidth = 50;
|
||||
|
||||
var editToolsOn = true;
|
||||
|
||||
var voxelToolSelected = false;
|
||||
|
||||
var scaleSelectorWidth = 144;
|
||||
var scaleSelectorHeight = 37;
|
||||
|
||||
var scaleSelectorX = windowDimensions.x / 5.0;
|
||||
var scaleSelectorY = windowDimensions.y - scaleSelectorHeight;
|
||||
|
||||
var voxelTool = Overlays.addOverlay("image", {
|
||||
x: scaleSelectorX + scaleSelectorWidth + 1, y: windowDimensions.y - toolHeight, width: toolWidth, height: toolHeight,
|
||||
subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
|
||||
imageURL: toolIconUrl + "voxel-tool.svg",
|
||||
visible: editToolsOn,
|
||||
color: UIColor,
|
||||
alpha: 0.9
|
||||
});
|
||||
|
||||
var copyScale = true;
|
||||
function ScaleSelector() {
|
||||
this.x = scaleSelectorX;
|
||||
this.y = scaleSelectorY;
|
||||
this.width = scaleSelectorWidth;
|
||||
this.height = scaleSelectorHeight;
|
||||
|
||||
this.displayPower = false;
|
||||
this.scale = 1.0;
|
||||
this.power = 0;
|
||||
|
||||
this.FIRST_PART = this.width * 40.0 / 100.0;
|
||||
this.SECOND_PART = this.width * 37.0 / 100.0;
|
||||
|
||||
this.buttonsOverlay = Overlays.addOverlay("image", {
|
||||
x: this.x, y: this.y,
|
||||
width: this.width, height: this.height,
|
||||
//subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
|
||||
imageURL: toolIconUrl + "voxel-size-selector.svg",
|
||||
alpha: 0.9,
|
||||
visible: editToolsOn,
|
||||
color: activeUIColor
|
||||
});
|
||||
this.textOverlay = Overlays.addOverlay("text", {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
width: this.SECOND_PART, height: this.height,
|
||||
topMargin: 13,
|
||||
text: this.scale.toString(),
|
||||
backgroundAlpha: 0.0,
|
||||
visible: editToolsOn,
|
||||
color: activeUIColor
|
||||
});
|
||||
this.powerOverlay = Overlays.addOverlay("text", {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
width: this.SECOND_PART, height: this.height,
|
||||
leftMargin: 28,
|
||||
text: this.power.toString(),
|
||||
backgroundAlpha: 0.0,
|
||||
visible: false,
|
||||
color: activeUIColor
|
||||
});
|
||||
this.setScale = function(scale) {
|
||||
if (scale > MAX_VOXEL_SCALE) {
|
||||
scale = MAX_VOXEL_SCALE;
|
||||
}
|
||||
if (scale < MIN_VOXEL_SCALE) {
|
||||
scale = MIN_VOXEL_SCALE;
|
||||
}
|
||||
|
||||
this.scale = scale;
|
||||
this.power = Math.floor(Math.log(scale) / Math.log(2));
|
||||
this.update();
|
||||
}
|
||||
|
||||
this.show = function(doShow) {
|
||||
Overlays.editOverlay(this.buttonsOverlay, {visible: doShow});
|
||||
Overlays.editOverlay(this.textOverlay, {visible: doShow});
|
||||
Overlays.editOverlay(this.powerOverlay, {visible: doShow && this.displayPower});
|
||||
}
|
||||
|
||||
this.move = function() {
|
||||
this.x = swatchesX + swatchesWidth;
|
||||
this.y = swatchesY;
|
||||
|
||||
Overlays.editOverlay(this.buttonsOverlay, {
|
||||
x: this.x, y: this.y,
|
||||
});
|
||||
Overlays.editOverlay(this.textOverlay, {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
});
|
||||
Overlays.editOverlay(this.powerOverlay, {
|
||||
x: this.x + this.FIRST_PART, y: this.y,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.switchDisplay = function() {
|
||||
this.displayPower = !this.displayPower;
|
||||
|
||||
if (this.displayPower) {
|
||||
Overlays.editOverlay(this.textOverlay, {
|
||||
leftMargin: 18,
|
||||
text: "2"
|
||||
});
|
||||
Overlays.editOverlay(this.powerOverlay, {
|
||||
text: this.power.toString(),
|
||||
visible: editToolsOn
|
||||
});
|
||||
} else {
|
||||
Overlays.editOverlay(this.textOverlay, {
|
||||
leftMargin: 13,
|
||||
text: this.scale.toString()
|
||||
});
|
||||
Overlays.editOverlay(this.powerOverlay, {
|
||||
visible: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.update = function() {
|
||||
if (this.displayPower) {
|
||||
Overlays.editOverlay(this.powerOverlay, {text: this.power.toString()});
|
||||
} else {
|
||||
Overlays.editOverlay(this.textOverlay, {text: this.scale.toString()});
|
||||
}
|
||||
}
|
||||
|
||||
this.incrementScale = function() {
|
||||
copyScale = false;
|
||||
if (this.power < MAX_VOXEL_SCALE_POWER) {
|
||||
++this.power;
|
||||
this.scale *= 2.0;
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
|
||||
this.decrementScale = function() {
|
||||
copyScale = false;
|
||||
if (MIN_VOXEL_SCALE_POWER < this.power) {
|
||||
--this.power;
|
||||
this.scale /= 2.0;
|
||||
this.update();
|
||||
}
|
||||
}
|
||||
|
||||
this.clicked = function(x, y) {
|
||||
if (this.x < x && x < this.x + this.width &&
|
||||
this.y < y && y < this.y + this.height) {
|
||||
|
||||
if (x < this.x + this.FIRST_PART) {
|
||||
this.decrementScale();
|
||||
} else if (x < this.x + this.FIRST_PART + this.SECOND_PART) {
|
||||
this.switchDisplay();
|
||||
} else {
|
||||
this.incrementScale();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
this.cleanup = function() {
|
||||
Overlays.deleteOverlay(this.buttonsOverlay);
|
||||
Overlays.deleteOverlay(this.textOverlay);
|
||||
Overlays.deleteOverlay(this.powerOverlay);
|
||||
}
|
||||
|
||||
}
|
||||
var scaleSelector = new ScaleSelector();
|
||||
|
||||
|
||||
function calculateVoxelFromIntersection(intersection, operation) {
|
||||
|
||||
var resultVoxel;
|
||||
|
||||
var x;
|
||||
var y;
|
||||
var z;
|
||||
|
||||
// if our "target voxel size" is larger than the voxel we intersected with, then we need to find the closest
|
||||
// ancestor voxel of our target size that contains our intersected voxel.
|
||||
if (voxelSize > intersection.voxel.s) {
|
||||
x = Math.floor(intersection.voxel.x / voxelSize) * voxelSize;
|
||||
y = Math.floor(intersection.voxel.y / voxelSize) * voxelSize;
|
||||
z = Math.floor(intersection.voxel.z / voxelSize) * voxelSize;
|
||||
} else {
|
||||
// otherwise, calculate the enclosed voxel of size voxelSize that the intersection point falls inside of.
|
||||
// if you have a voxelSize that's smaller than the voxel you're intersecting, this calculation will result
|
||||
// in the subvoxel that the intersection point falls in, if the target voxelSize matches the intersecting
|
||||
// voxel this still works and results in returning the intersecting voxel which is what we want
|
||||
var adjustToCenter = Vec3.multiply(Voxels.getFaceVector(intersection.face), (voxelSize * -0.5));
|
||||
|
||||
var centerOfIntersectingVoxel = Vec3.sum(intersection.intersection, adjustToCenter);
|
||||
x = Math.floor(centerOfIntersectingVoxel.x / voxelSize) * voxelSize;
|
||||
y = Math.floor(centerOfIntersectingVoxel.y / voxelSize) * voxelSize;
|
||||
z = Math.floor(centerOfIntersectingVoxel.z / voxelSize) * voxelSize;
|
||||
}
|
||||
resultVoxel = { x: x, y: y, z: z, s: voxelSize };
|
||||
var highlightAt = { x: x, y: y, z: z, s: voxelSize };
|
||||
|
||||
|
||||
|
||||
// we only do the "add to the face we're pointing at" adjustment, if the operation is an add
|
||||
// operation, and the target voxel size is equal to or smaller than the intersecting voxel.
|
||||
var wantAddAdjust = (operation == "add" && (voxelSize <= intersection.voxel.s));
|
||||
|
||||
// now we also want to calculate the "edge square" for the face for this voxel
|
||||
if (intersection.face == "MIN_X_FACE") {
|
||||
|
||||
highlightAt.x = x - zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.x -= voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomRight = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
resultVoxel.topLeft = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.topRight = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
|
||||
} else if (intersection.face == "MAX_X_FACE") {
|
||||
|
||||
highlightAt.x = x + voxelSize + zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.x += resultVoxel.s;
|
||||
}
|
||||
|
||||
resultVoxel.bottomRight = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
resultVoxel.topRight = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.topLeft = {x: highlightAt.x, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
|
||||
} else if (intersection.face == "MIN_Y_FACE") {
|
||||
|
||||
highlightAt.y = y - zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.y -= voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.topRight = {x: highlightAt.x + zFightingSizeAdjust , y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.topLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + zFightingSizeAdjust , y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust , y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust };
|
||||
|
||||
} else if (intersection.face == "MAX_Y_FACE") {
|
||||
|
||||
highlightAt.y = y + voxelSize + zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.y += voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + zFightingSizeAdjust};
|
||||
resultVoxel.topRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust};
|
||||
resultVoxel.topLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y, z: highlightAt.z + voxelSize - zFightingSizeAdjust};
|
||||
|
||||
} else if (intersection.face == "MIN_Z_FACE") {
|
||||
|
||||
highlightAt.z = z - zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.z -= voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z};
|
||||
resultVoxel.topRight = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.topLeft = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z};
|
||||
|
||||
} else if (intersection.face == "MAX_Z_FACE") {
|
||||
|
||||
highlightAt.z = z + voxelSize + zFightingSizeAdjust;
|
||||
if (wantAddAdjust) {
|
||||
resultVoxel.z += voxelSize;
|
||||
}
|
||||
|
||||
resultVoxel.bottomLeft = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.bottomRight = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + zFightingSizeAdjust, z: highlightAt.z};
|
||||
resultVoxel.topLeft = {x: highlightAt.x + zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z };
|
||||
resultVoxel.topRight = {x: highlightAt.x + voxelSize - zFightingSizeAdjust, y: highlightAt.y + voxelSize - zFightingSizeAdjust, z: highlightAt.z};
|
||||
|
||||
}
|
||||
return resultVoxel;
|
||||
}
|
||||
|
||||
var trackLastMouseX = 0;
|
||||
var trackLastMouseY = 0;
|
||||
|
||||
function showPreviewLines() {
|
||||
|
||||
var pickRay = Camera.computePickRay(trackLastMouseX, trackLastMouseY);
|
||||
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
|
||||
if (intersection.intersects) {
|
||||
var resultVoxel = calculateVoxelFromIntersection(intersection, "");
|
||||
Overlays.editOverlay(linePreviewTop, { position: resultVoxel.topLeft, end: resultVoxel.topRight, visible: true });
|
||||
Overlays.editOverlay(linePreviewBottom, { position: resultVoxel.bottomLeft, end: resultVoxel.bottomRight, visible: true });
|
||||
Overlays.editOverlay(linePreviewLeft, { position: resultVoxel.topLeft, end: resultVoxel.bottomLeft, visible: true });
|
||||
Overlays.editOverlay(linePreviewRight, { position: resultVoxel.topRight, end: resultVoxel.bottomRight, visible: true });
|
||||
} else {
|
||||
Overlays.editOverlay(linePreviewTop, { visible: false });
|
||||
Overlays.editOverlay(linePreviewBottom, { visible: false });
|
||||
Overlays.editOverlay(linePreviewLeft, { visible: false });
|
||||
Overlays.editOverlay(linePreviewRight, { visible: false });
|
||||
}
|
||||
}
|
||||
|
||||
function mouseMoveEvent(event) {
|
||||
trackLastMouseX = event.x;
|
||||
trackLastMouseY = event.y;
|
||||
if (!voxelToolSelected) {
|
||||
return;
|
||||
}
|
||||
showPreviewLines();
|
||||
}
|
||||
|
||||
|
||||
// Array of possible trees, right now there is only one
|
||||
var treeTypes = [];
|
||||
|
||||
treeTypes.push({
|
||||
name: "Tall Green",
|
||||
// Voxel Colors
|
||||
wood: { r: 133, g: 81, b: 53 },
|
||||
leaves: { r: 22, g: 83, b: 31 },
|
||||
|
||||
// How tall the tree is
|
||||
height: { min: 20, max: 60 },
|
||||
middleHeight: 0.3,
|
||||
|
||||
// Chance of making a branch
|
||||
branchChance: { min: 0.01, max: 0.1 },
|
||||
branchLength: { min: 30, max: 60 },
|
||||
branchThickness: { min: 2, max: 7},
|
||||
|
||||
// The width of the core, affects width and shape
|
||||
coreWidth: { min: 1, max: 4 },
|
||||
|
||||
//TODO: Make this quadratic splines instead of linear
|
||||
bottomThickness: { min: 2, max: 8 },
|
||||
middleThickness: { min: 1, max: 4 },
|
||||
topThickness: { min: 3, max: 6 },
|
||||
|
||||
//Modifies leaves at top
|
||||
leafCapSizeOffset: 0
|
||||
});
|
||||
|
||||
// Applies noise to color
|
||||
var colorNoiseRange = 0.2;
|
||||
|
||||
|
||||
// Useful constants
|
||||
var LEFT = 0;
|
||||
var BACK = 1;
|
||||
var RIGHT = 2;
|
||||
var FRONT = 3;
|
||||
var UP = 4;
|
||||
|
||||
// Interpolates between min and max of treevar based on b
|
||||
function interpolate(treeVar, b) {
|
||||
return (treeVar.min + (treeVar.max - treeVar.min) * b);
|
||||
}
|
||||
|
||||
function makeBranch(x, y, z, step, length, dir, thickness, wood, leaves) {
|
||||
var moveDir;
|
||||
|
||||
var currentThickness;
|
||||
//thickness attenuates to thickness - 3
|
||||
var finalThickness = thickness - 3;
|
||||
if (finalThickness < 1) {
|
||||
finalThickness = 1;
|
||||
}
|
||||
//Iterative branch generation
|
||||
while (true) {
|
||||
|
||||
//If we are at the end, place a ball of leaves
|
||||
if (step == 0) {
|
||||
makeSphere(x, y, z, 2 + finalThickness, leaves);
|
||||
return;
|
||||
}
|
||||
//thickness attenuation
|
||||
currentThickness = Math.round((finalThickness + (thickness - finalThickness) * (step/length))) - 1;
|
||||
|
||||
|
||||
// If the branch is thick, grow a vertical slice
|
||||
if (currentThickness > 0) {
|
||||
for (var i = -currentThickness; i <= currentThickness; i++) {
|
||||
var len = currentThickness - Math.abs(i);
|
||||
switch (dir) {
|
||||
case 0: //left
|
||||
case 2: //right
|
||||
growInDirection(x, y + i * voxelSize, z, len, len, BACK, wood, false, true);
|
||||
growInDirection(x, y + i * voxelSize, z, len, len, FRONT, wood, false, false)
|
||||
break;
|
||||
case 1: //back
|
||||
case 3: //front
|
||||
growInDirection(x, y + i * voxelSize, z, len, len, LEFT, wood, false, true);
|
||||
growInDirection(x, y + i * voxelSize, z, len, len, RIGHT, wood, false, false)
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//Otherwise place a single voxel
|
||||
var colorNoise = (colorNoiseRange * Math.random() - colorNoiseRange * 0.5) + 1.0;
|
||||
Voxels.setVoxel(x, y, z, voxelSize, wood.r * colorNoise, wood.g * colorNoise, wood.b * colorNoise);
|
||||
}
|
||||
|
||||
// determines random change in direction for branch
|
||||
var r = Math.floor(Math.random() * 9);
|
||||
|
||||
|
||||
if (r >= 6){
|
||||
moveDir = dir; //in same direction
|
||||
} else if (r >= 4) {
|
||||
moveDir = UP; //up
|
||||
}
|
||||
else if (dir == LEFT){
|
||||
if (r >= 2){
|
||||
moveDir = FRONT;
|
||||
}
|
||||
else{
|
||||
moveDir = BACK;
|
||||
}
|
||||
}
|
||||
else if (dir == BACK){
|
||||
if (r >= 2){
|
||||
moveDir = LEFT;
|
||||
}
|
||||
else{
|
||||
moveDir = RIGHT;
|
||||
}
|
||||
}
|
||||
else if (dir == RIGHT){
|
||||
if (r >= 2){
|
||||
moveDir = BACK;
|
||||
}
|
||||
else{
|
||||
moveDir = FRONT;
|
||||
}
|
||||
}
|
||||
else if (dir == FRONT){
|
||||
if (r >= 2){
|
||||
moveDir = RIGHT;
|
||||
}
|
||||
else{
|
||||
moveDir = LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
//Move the branch by moveDir
|
||||
switch (moveDir) {
|
||||
case 0: //left
|
||||
x = x - voxelSize;
|
||||
break;
|
||||
case 1: //back
|
||||
z = z - voxelSize;
|
||||
break;
|
||||
case 2: //right
|
||||
x = x + voxelSize;
|
||||
break;
|
||||
case 3: //front
|
||||
z = z + voxelSize;
|
||||
break;
|
||||
case 4: //up
|
||||
y = y + voxelSize;
|
||||
break;
|
||||
}
|
||||
|
||||
step--;
|
||||
}
|
||||
}
|
||||
|
||||
// Places a sphere of voxels
|
||||
function makeSphere(x, y, z, radius, color) {
|
||||
if (radius <= 0) {
|
||||
return;
|
||||
}
|
||||
var width = radius * 2 + 1;
|
||||
var distance;
|
||||
|
||||
for (var i = -radius; i <= radius; i++){
|
||||
for (var j = -radius; j <= radius; j++){
|
||||
for (var k = -radius; k <= radius; k++){
|
||||
distance = Math.sqrt(i * i + j * j + k * k);
|
||||
if (distance <= radius){
|
||||
var colorNoise = (colorNoiseRange * Math.random() - colorNoiseRange * 0.5) + 1.0;
|
||||
Voxels.setVoxel(x + i * voxelSize, y + j * voxelSize, z + k * voxelSize, voxelSize, color.r * colorNoise, color.g * colorNoise, color.b * colorNoise);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function growInDirection(x, y, z, step, length, dir, color, isSideBranching, addVoxel) {
|
||||
|
||||
|
||||
if (addVoxel == true) {
|
||||
var colorNoise = (colorNoiseRange * Math.random() - colorNoiseRange * 0.5) + 1.0;
|
||||
Voxels.setVoxel(x, y, z, voxelSize, color.r * colorNoise, color.g * colorNoise, color.b * colorNoise);
|
||||
}
|
||||
|
||||
// If this is a main vein, it will branch outward perpendicular to its motion
|
||||
if (isSideBranching == true){
|
||||
var step2;
|
||||
if (step >= length - 1){
|
||||
step2 = length;
|
||||
}
|
||||
else{
|
||||
step2 = step + 1;
|
||||
}
|
||||
growInDirection(x, y, z, step, length, BACK, color, false, false);
|
||||
growInDirection(x, y, z, step, length, FRONT, color, false, false);
|
||||
}
|
||||
|
||||
if (step < 1) return;
|
||||
|
||||
// Recursively move in the direction
|
||||
if (dir == LEFT) { //left
|
||||
growInDirection(x - voxelSize, y, z, step - 1, length, dir, color, isSideBranching, true);
|
||||
}
|
||||
else if (dir == BACK) { //back
|
||||
growInDirection(x, y, z - voxelSize, step - 1, length, dir, color, isSideBranching, true);
|
||||
}
|
||||
else if (dir == RIGHT) { //right
|
||||
growInDirection(x + voxelSize, y, z, step - 1, length, dir, color, isSideBranching, true);
|
||||
}
|
||||
else if (dir == FRONT) {//front
|
||||
growInDirection(x, y, z + voxelSize, step - 1, length, dir, color, isSideBranching, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Grows the thickness of the tree
|
||||
function growHorizontalSlice(x, y, z, thickness, color, side) {
|
||||
// The side variable determines which directions we should grow in
|
||||
// it is an optimization that prevents us from visiting voxels multiple
|
||||
// times for trees with a coreWidth > 1
|
||||
|
||||
// side:
|
||||
// 8 == all directions
|
||||
// 0 1 2
|
||||
// 3 -1 4
|
||||
// 5 6 7
|
||||
|
||||
Voxels.setVoxel(x, y, z, voxelSize, color.r, color.g, color.b);
|
||||
|
||||
//We are done if there is no thickness
|
||||
if (thickness == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (side) {
|
||||
case 0:
|
||||
growInDirection(x, y, z, thickness, thickness, LEFT, color, true, false);
|
||||
break;
|
||||
case 1:
|
||||
growInDirection(x, y, z, thickness, thickness, BACK, color, false, false);
|
||||
break;
|
||||
case 2:
|
||||
growInDirection(x, y, z, thickness, thickness, RIGHT, color, true, false);
|
||||
break;
|
||||
case 3:
|
||||
growInDirection(x, y, z, thickness, thickness, LEFT, color, false, false);
|
||||
break;
|
||||
case 4:
|
||||
growInDirection(x, y, z, thickness, thickness, BACK, color, false, false);
|
||||
break;
|
||||
case 5:
|
||||
growInDirection(x, y, z, thickness, thickness, RIGHT, color, true, false);
|
||||
break;
|
||||
case 6:
|
||||
growInDirection(x, y, z, thickness, thickness, FRONT, color, false, false);
|
||||
break;
|
||||
case 7:
|
||||
growInDirection(x, y, z, thickness, thickness, RIGHT, color, true, false);
|
||||
break;
|
||||
case 8:
|
||||
if (thickness > 1){
|
||||
growInDirection(x, y, z, thickness, thickness, LEFT, color, true, false);
|
||||
growInDirection(x, y, z, thickness, thickness, RIGHT, color, true, false)
|
||||
} else if (thickness == 1){
|
||||
Voxels.setVoxel(x - voxelSize, y, z, voxelSize, color.r, color.g, color.b);
|
||||
Voxels.setVoxel(x + voxelSize, y, z, voxelSize, color.r, color.g, color.b);
|
||||
Voxels.setVoxel(x, y, z - voxelSize, voxelSize, color.r, color.g, color.b);
|
||||
Voxels.setVoxel(x, y, z + voxelSize, voxelSize, color.r, color.g, color.b);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function computeSide(x, z, coreWidth) {
|
||||
// side:
|
||||
// 8 == all directions
|
||||
// 0 1 2
|
||||
// 3 -1 4
|
||||
// 5 6 7
|
||||
|
||||
// if the core is only a single block, we can grow out in all directions
|
||||
if (coreWidth == 1){
|
||||
return 8;
|
||||
}
|
||||
|
||||
// Back face
|
||||
if (z == 0) {
|
||||
if (x == 0) {
|
||||
return 0;
|
||||
} else if (x == coreWidth - 1) {
|
||||
return 2;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Front face
|
||||
if (z == (coreWidth - 1)) {
|
||||
if (x == 0) {
|
||||
return 5;
|
||||
} else if (x == (coreWidth - 1)) {
|
||||
return 7;
|
||||
} else {
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
// Left face
|
||||
if (x == 0) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Right face
|
||||
if (x == (coreWidth - 1)) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
//Interior
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
function growTree(x, y, z, tree) {
|
||||
|
||||
// The size of the tree, from 0-1
|
||||
var treeSize = Math.random();
|
||||
|
||||
// Get tree properties by interpolating with the treeSize
|
||||
var height = interpolate(tree.height, treeSize);
|
||||
var baseHeight = Math.ceil(tree.middleHeight * height);
|
||||
var bottomThickness = interpolate(tree.bottomThickness, treeSize);
|
||||
var middleThickness = interpolate(tree.middleThickness, treeSize);
|
||||
var topThickness = interpolate(tree.topThickness, treeSize);
|
||||
var coreWidth = Math.ceil(interpolate(tree.coreWidth, treeSize));
|
||||
|
||||
var thickness;
|
||||
var side;
|
||||
|
||||
//Loop upwards through each slice of the tree
|
||||
for (var i = 0; i < height; i++){
|
||||
|
||||
//Branch properties are based on current height as well as the overall tree size
|
||||
var branchChance = interpolate(tree.branchChance, i / height);
|
||||
var branchLength = Math.ceil(interpolate(tree.branchLength, (i / height) * treeSize));
|
||||
var branchThickness = Math.round(interpolate(tree.branchThickness, (i / height) * treeSize));
|
||||
|
||||
// Get the "thickness" of the tree by doing linear interpolation between the middle thickness
|
||||
// and the top and bottom thickness.
|
||||
if (i <= baseHeight && baseHeight != 0){
|
||||
thickness = (i / (baseHeight) * (middleThickness - bottomThickness) + bottomThickness);
|
||||
} else {
|
||||
var denom = ((height - baseHeight)) * (topThickness - middleThickness) + middleThickness;
|
||||
if (denom != 0) {
|
||||
thickness = (i - baseHeight) / denom;
|
||||
} else {
|
||||
thickness = 0;
|
||||
}
|
||||
}
|
||||
// The core of the tree is a vertical rectangular prism through the middle of the tree
|
||||
|
||||
//Loop through the "core", which helps shape the trunk
|
||||
var startX = x - Math.floor(coreWidth / 2) * voxelSize;
|
||||
var startZ = z - Math.floor(coreWidth / 2) * voxelSize;
|
||||
for (var j = 0; j < coreWidth; j++) {
|
||||
for (var k = 0; k < coreWidth; k++) {
|
||||
//determine which side of the tree we are on
|
||||
side = computeSide(j, k, coreWidth);
|
||||
//grow a horizontal slice of the tree
|
||||
growHorizontalSlice(startX + j * voxelSize, y + i * voxelSize, startZ + k * voxelSize, Math.floor(thickness), tree.wood, side);
|
||||
|
||||
// Branches
|
||||
if (side != -1) {
|
||||
var r = Math.random();
|
||||
if (r <= branchChance){
|
||||
var dir = Math.floor((Math.random() * 4));
|
||||
makeBranch(startX + j * voxelSize, y + i * voxelSize, startZ + k * voxelSize, branchLength, branchLength, dir, branchThickness, tree.wood, tree.leaves);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
makeSphere(x, y + height * voxelSize, z, topThickness + coreWidth + tree.leafCapSizeOffset, tree.leaves);
|
||||
}
|
||||
|
||||
function mousePressEvent(event) {
|
||||
var mouseX = event.x;
|
||||
var mouseY = event.y;
|
||||
|
||||
var clickedOnSomething = false;
|
||||
// Check if we clicked an overlay
|
||||
var clickedOverlay = Overlays.getOverlayAtPoint({x: mouseX, y: mouseY});
|
||||
|
||||
if (clickedOverlay == voxelTool) {
|
||||
voxelToolSelected = !voxelToolSelected;
|
||||
|
||||
if (voxelToolSelected == true) {
|
||||
Overlays.editOverlay(voxelTool, {
|
||||
color: activeUIColor
|
||||
});
|
||||
} else {
|
||||
Overlays.editOverlay(voxelTool, {
|
||||
color: UIColor
|
||||
});
|
||||
}
|
||||
|
||||
clickedOnSomething = true;
|
||||
} else if (scaleSelector.clicked(event.x, event.y)) {
|
||||
clickedOnSomething = true;
|
||||
voxelSize = scaleSelector.scale;
|
||||
}
|
||||
|
||||
// Return if we clicked on the UI or the voxel tool is disabled
|
||||
if (clickedOnSomething || !voxelToolSelected) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute the picking ray for the click
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
var resultVoxel = calculateVoxelFromIntersection(intersection, "add");
|
||||
|
||||
// Currently not in use, could randomly select a tree
|
||||
var treeIndex = Math.floor(Math.random() * treeTypes.length);
|
||||
|
||||
// Grow the first tree type
|
||||
growTree(resultVoxel.x, resultVoxel.y, resultVoxel.z, treeTypes[0]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function scriptEnding() {
|
||||
Overlays.deleteOverlay(linePreviewTop);
|
||||
Overlays.deleteOverlay(linePreviewBottom);
|
||||
Overlays.deleteOverlay(linePreviewLeft);
|
||||
Overlays.deleteOverlay(linePreviewRight);
|
||||
scaleSelector.cleanup();
|
||||
Overlays.deleteOverlay(voxelTool);
|
||||
}
|
||||
|
||||
Controller.mousePressEvent.connect(mousePressEvent);
|
||||
Controller.mouseMoveEvent.connect(mouseMoveEvent);
|
||||
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
Voxels.setPacketsPerSecond(10000);
|
|
@ -156,19 +156,6 @@ function shootTarget() {
|
|||
|
||||
|
||||
|
||||
function entityCollisionWithVoxel(entity, voxel, collision) {
|
||||
var HOLE_SIZE = 0.125;
|
||||
var entityProperties = Entities.getEntityProperties(entity);
|
||||
var position = entityProperties.position;
|
||||
Entities.deleteEntity(entity);
|
||||
// Make a hole in this voxel
|
||||
//Vec3.print("voxel penetration", collision.penetration);
|
||||
//Vec3.print("voxel contactPoint", collision.contactPoint);
|
||||
Voxels.eraseVoxel(collision.contactPoint.x, collision.contactPoint.y, collision.contactPoint.z, HOLE_SIZE);
|
||||
audioOptions.position = collision.contactPoint;
|
||||
Audio.playSound(impactSound, audioOptions);
|
||||
}
|
||||
|
||||
function entityCollisionWithEntity(entity1, entity2, collision) {
|
||||
score++;
|
||||
if (showScore) {
|
||||
|
@ -329,7 +316,6 @@ function scriptEnding() {
|
|||
MyAvatar.detachOne(gunModel);
|
||||
}
|
||||
|
||||
Entities.entityCollisionWithVoxel.connect(entityCollisionWithVoxel);
|
||||
Entities.entityCollisionWithEntity.connect(entityCollisionWithEntity);
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
Script.update.connect(update);
|
||||
|
|
|
@ -221,13 +221,11 @@ function mousePressEvent(event) {
|
|||
|
||||
// Compute trajectories related values
|
||||
var pickRay = Camera.computePickRay(mouseLastX, mouseLastY);
|
||||
var voxelIntersection = Voxels.findRayIntersection(pickRay);
|
||||
var modelIntersection = Entities.findRayIntersection(pickRay);
|
||||
|
||||
position = Camera.getPosition();
|
||||
|
||||
var avatarTarget = MyAvatar.getTargetAvatarPosition();
|
||||
var voxelTarget = voxelIntersection.intersection;
|
||||
|
||||
|
||||
var distance = -1;
|
||||
|
@ -246,13 +244,6 @@ function mousePressEvent(event) {
|
|||
string = "Inspecting avatar";
|
||||
}
|
||||
|
||||
if ((distance == -1 || Vec3.length(Vec3.subtract(voxelTarget, position)) < distance) &&
|
||||
(voxelTarget.x != 0 || voxelTarget.y != 0 || voxelTarget.z != 0)) {
|
||||
distance = Vec3.length(Vec3.subtract(voxelTarget, position));
|
||||
center = voxelTarget;
|
||||
string = "Inspecting voxel";
|
||||
}
|
||||
|
||||
if (distance == -1) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ ModelImporter = function (opts) {
|
|||
this.mouseMoveEvent = function (event) {
|
||||
if (self._importing) {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
var intersection = Entities.findRayIntersection(pickRay);
|
||||
|
||||
var distance = 2;// * self._scale;
|
||||
|
||||
|
|
|
@ -181,7 +181,9 @@ spatialInformation = (function() {
|
|||
|
||||
// use the blocking version of findRayIntersection to avoid errors
|
||||
var pickRay = {origin: MyAvatar.position, direction: {x:0, y:-1, z:0}};
|
||||
return Voxels.findRayIntersectionBlocking(pickRay).distance - motion.calibration.hipsToFeet;;
|
||||
|
||||
// TODO: change this to use entities?
|
||||
return false; // Voxels.findRayIntersectionBlocking(pickRay).distance - motion.calibration.hipsToFeet;;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ function mousePressEvent(event) {
|
|||
cancelLookAt();
|
||||
} else {
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
var intersection = Entities.findRayIntersection(pickRay);
|
||||
if (intersection.intersects) {
|
||||
|
||||
// remember the old mode we were in
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
//
|
||||
// movingVoxel.js
|
||||
// examples
|
||||
//
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This sample script creates a voxel moving back and forth in a line
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var position = { x: 0, y: 0, z: 0 };
|
||||
var oldPosition = { x: 0, y: 0, z:0 };
|
||||
var size = 0.25;
|
||||
var direction = 1.0;
|
||||
var range = 2.0;
|
||||
var color = { r: 100, g: 50, b: 150 };
|
||||
var colorEdge = { r:255, g:250, b:175 };
|
||||
var frame = 0;
|
||||
var thisColor = color;
|
||||
|
||||
function moveVoxel(deltaTime) {
|
||||
frame++;
|
||||
if (frame % 3 == 0) {
|
||||
// Get a new position
|
||||
position.x += direction * size;
|
||||
if (position.x < 0) {
|
||||
direction *= -1.0;
|
||||
position.x = 0;
|
||||
thisColor = colorEdge;
|
||||
}
|
||||
if (position.x > range) {
|
||||
direction *= -1.0;
|
||||
position.x = range;
|
||||
thisColor = colorEdge;
|
||||
}
|
||||
// Create a new voxel
|
||||
Voxels.setVoxel(position.x, position.y, position.z, size, thisColor.r, thisColor.g, thisColor.b);
|
||||
// delete old voxel
|
||||
Voxels.eraseVoxel(oldPosition.x, oldPosition.y, oldPosition.z, size);
|
||||
// Copy old location to new
|
||||
oldPosition.x = position.x;
|
||||
oldPosition.y = position.y;
|
||||
oldPosition.z = position.z;
|
||||
thisColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
Voxels.setPacketsPerSecond(300);
|
||||
// Connect a call back that happens every frame
|
||||
Script.update.connect(moveVoxel);
|
|
@ -18,30 +18,6 @@ function mouseMoveEvent(event) {
|
|||
print("computePickRay origin=" + pickRay.origin.x + ", " + pickRay.origin.y + ", " + pickRay.origin.z);
|
||||
print("computePickRay direction=" + pickRay.direction.x + ", " + pickRay.direction.y + ", " + pickRay.direction.z);
|
||||
var pickRay = Camera.computePickRay(event.x, event.y);
|
||||
var intersection = Voxels.findRayIntersection(pickRay);
|
||||
if (!intersection.accurate) {
|
||||
print(">>> NOTE: intersection not accurate. will try calling Voxels.findRayIntersectionBlocking()");
|
||||
intersection = Voxels.findRayIntersectionBlocking(pickRay);
|
||||
print(">>> AFTER BLOCKING CALL intersection.accurate=" + intersection.accurate);
|
||||
}
|
||||
|
||||
if (intersection.intersects) {
|
||||
print("intersection voxel.red/green/blue=" + intersection.voxel.red + ", "
|
||||
+ intersection.voxel.green + ", " + intersection.voxel.blue);
|
||||
print("intersection voxel.x/y/z/s=" + intersection.voxel.x + ", "
|
||||
+ intersection.voxel.y + ", " + intersection.voxel.z+ ": " + intersection.voxel.s);
|
||||
print("intersection face=" + intersection.face);
|
||||
print("intersection distance=" + intersection.distance);
|
||||
print("intersection intersection.x/y/z=" + intersection.intersection.x + ", "
|
||||
+ intersection.intersection.y + ", " + intersection.intersection.z);
|
||||
|
||||
// also test the getVoxelAt() api which should find and return same voxel
|
||||
|
||||
var voxelAt = Voxels.getVoxelAt(intersection.voxel.x, intersection.voxel.y, intersection.voxel.z, intersection.voxel.s);
|
||||
print("voxelAt.x/y/z/s=" + voxelAt.x + ", " + voxelAt.y + ", " + voxelAt.z + ": " + voxelAt.s);
|
||||
print("voxelAt.red/green/blue=" + voxelAt.red + ", " + voxelAt.green + ", " + voxelAt.blue);
|
||||
}
|
||||
|
||||
intersection = Entities.findRayIntersection(pickRay);
|
||||
if (!intersection.accurate) {
|
||||
print(">>> NOTE: intersection not accurate. will try calling Entities.findRayIntersectionBlocking()");
|
||||
|
|
|
@ -1,176 +0,0 @@
|
|||
//
|
||||
// ribbon.js
|
||||
// examples
|
||||
//
|
||||
// Created by Andrzej Kapolka on 2/24/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
function vectorMultiply(vector, scalar) {
|
||||
return [ vector[0] * scalar, vector[1] * scalar, vector[2] * scalar ];
|
||||
}
|
||||
|
||||
function vectorAdd(firstVector, secondVector) {
|
||||
return [ firstVector[0] + secondVector[0], firstVector[1] + secondVector[1], firstVector[2] + secondVector[2] ];
|
||||
}
|
||||
|
||||
function vectorSubtract(firstVector, secondVector) {
|
||||
return [ firstVector[0] - secondVector[0], firstVector[1] - secondVector[1], firstVector[2] - secondVector[2] ];
|
||||
}
|
||||
|
||||
function vectorCross(firstVector, secondVector) {
|
||||
return [ firstVector[1] * secondVector[2] - firstVector[2] * secondVector[1],
|
||||
firstVector[2] * secondVector[0] - firstVector[0] * secondVector[2],
|
||||
firstVector[0] * secondVector[1] - firstVector[1] * secondVector[0] ];
|
||||
}
|
||||
|
||||
function vectorLength(vector) {
|
||||
return Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2]);
|
||||
}
|
||||
|
||||
function vectorNormalize(vector) {
|
||||
return vectorMultiply(vector, 1.0 / vectorLength(vector));
|
||||
}
|
||||
|
||||
function vectorClone(vector) {
|
||||
return [ vector[0], vector[1], vector[2] ];
|
||||
}
|
||||
|
||||
function mix(first, second, amount) {
|
||||
return first + (second - first) * amount;
|
||||
}
|
||||
|
||||
function vectorMix(firstVector, secondVector, amount) {
|
||||
return vectorAdd(firstVector, vectorMultiply(vectorSubtract(secondVector, firstVector), amount));
|
||||
}
|
||||
|
||||
function randomVector(minVector, maxVector) {
|
||||
return [ mix(minVector[0], maxVector[0], Math.random()), mix(minVector[1], maxVector[1], Math.random()),
|
||||
mix(minVector[2], maxVector[2], Math.random()) ];
|
||||
}
|
||||
|
||||
function applyToLine(start, end, granularity, fn) {
|
||||
// determine the number of steps from the maximum length
|
||||
var steps = Math.max(
|
||||
Math.abs(Math.floor(start[0] / granularity) - Math.floor(end[0] / granularity)),
|
||||
Math.abs(Math.floor(start[1] / granularity) - Math.floor(end[1] / granularity)),
|
||||
Math.abs(Math.floor(start[2] / granularity) - Math.floor(end[2] / granularity)));
|
||||
var position = vectorClone(start);
|
||||
var increment = vectorMultiply(vectorSubtract(end, start), 1.0 / steps);
|
||||
for (var i = 0; i <= steps; i++) {
|
||||
fn(granularity * Math.floor(position[0] / granularity),
|
||||
granularity * Math.floor(position[1] / granularity),
|
||||
granularity * Math.floor(position[2] / granularity),
|
||||
granularity);
|
||||
position = vectorAdd(position, increment);
|
||||
}
|
||||
}
|
||||
|
||||
function drawLine(start, end, color, granularity) {
|
||||
applyToLine(start, end, granularity, function(x, y, z, scale) {
|
||||
Voxels.setVoxel(x, y, z, scale, color[0], color[1], color[2]);
|
||||
});
|
||||
}
|
||||
|
||||
function eraseLine(start, end, granularity) {
|
||||
applyToLine(start, end, granularity, function(x, y, z, scale) {
|
||||
Voxels.eraseVoxel(x, y, z, scale);
|
||||
});
|
||||
}
|
||||
|
||||
function getHueColor(hue) {
|
||||
// see http://en.wikipedia.org/wiki/HSL_and_HSV
|
||||
var hPrime = hue / 60.0;
|
||||
var x = Math.floor(255.0 * (1.0 - Math.abs(hPrime % 2.0 - 1.0)));
|
||||
if (hPrime < 1) {
|
||||
return [255, x, 0];
|
||||
|
||||
} else if (hPrime < 2) {
|
||||
return [x, 255, 0];
|
||||
|
||||
} else if (hPrime < 3) {
|
||||
return [0, 255, x];
|
||||
|
||||
} else if (hPrime < 4) {
|
||||
return [0, x, 255];
|
||||
|
||||
} else if (hPrime < 5) {
|
||||
return [x, 0, 255];
|
||||
|
||||
} else { // hPrime < 6
|
||||
return [255, 0, x];
|
||||
}
|
||||
}
|
||||
|
||||
var UNIT_MIN = [-1.0, -1.0, -1.0];
|
||||
var UNIT_MAX = [1.0, 1.0, 1.0];
|
||||
|
||||
var EPSILON = 0.00001;
|
||||
|
||||
var BOUNDS_MIN = [5.0, 0.0, 5.0];
|
||||
var BOUNDS_MAX = [15.0, 10.0, 15.0];
|
||||
|
||||
var GRANULARITY = 1.0 / 16.0;
|
||||
|
||||
var WIDTH = 0.5;
|
||||
|
||||
var HISTORY_LENGTH = 300;
|
||||
|
||||
var stateHistory = [];
|
||||
var position;
|
||||
var velocity;
|
||||
var hueAngle = 0;
|
||||
var smoothedOffset;
|
||||
|
||||
function step(deltaTime) {
|
||||
if (stateHistory.length === 0) {
|
||||
// start at a random position within the bounds, with a random velocity
|
||||
position = randomVector(BOUNDS_MIN, BOUNDS_MAX);
|
||||
do {
|
||||
velocity = randomVector(UNIT_MIN, UNIT_MAX);
|
||||
} while (vectorLength(velocity) < EPSILON);
|
||||
velocity = vectorMultiply(velocity, GRANULARITY * 0.5 / vectorLength(velocity));
|
||||
smoothedOffset = [0.0, 0.0, 0.0];
|
||||
}
|
||||
|
||||
var right = vectorCross(velocity, [0.0, 1.0, 0.0]);
|
||||
if (vectorLength(right) < EPSILON) {
|
||||
right = [1.0, 0.0, 0.0];
|
||||
} else {
|
||||
right = vectorNormalize(right);
|
||||
}
|
||||
var up = vectorNormalize(vectorCross(right, velocity));
|
||||
var ANGULAR_SPEED = 2.0;
|
||||
var radians = hueAngle * Math.PI * ANGULAR_SPEED / 180.0;
|
||||
var offset = vectorAdd(vectorMultiply(right, WIDTH * Math.cos(radians)), vectorMultiply(up, WIDTH * Math.sin(radians)));
|
||||
var OFFSET_SMOOTHING = 0.9;
|
||||
smoothedOffset = vectorMix(offset, smoothedOffset, OFFSET_SMOOTHING);
|
||||
|
||||
var state = { start: vectorAdd(position, smoothedOffset), end: vectorSubtract(position, smoothedOffset) };
|
||||
drawLine(state.start, state.end, getHueColor(hueAngle), GRANULARITY);
|
||||
stateHistory.push(state);
|
||||
if (stateHistory.length > HISTORY_LENGTH) {
|
||||
var last = stateHistory.shift();
|
||||
eraseLine(last.start, last.end, GRANULARITY);
|
||||
}
|
||||
|
||||
// update position, check against bounds
|
||||
position = vectorAdd(position, velocity);
|
||||
for (var i = 0; i < 3; i++) {
|
||||
if (position[i] < BOUNDS_MIN[i]) {
|
||||
velocity[i] = -velocity[i];
|
||||
position[i] += 2.0 * (BOUNDS_MIN[i] - position[i]);
|
||||
|
||||
} else if (position[i] > BOUNDS_MAX[i]) {
|
||||
velocity[i] = -velocity[i];
|
||||
position[i] += 2.0 * (BOUNDS_MAX[i] - position[i]);
|
||||
}
|
||||
}
|
||||
var MAX_HUE_ANGLE = 360;
|
||||
hueAngle = (hueAngle + 1) % MAX_HUE_ANGLE;
|
||||
}
|
||||
|
||||
Script.update.connect(step);
|
|
@ -1,272 +0,0 @@
|
|||
// rockPaperScissorsCells.js
|
||||
// examples
|
||||
//
|
||||
// Created by Ben Arnold on 7/16/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This sample script creates a voxel wall that simulates the Rock Paper Scissors cellular
|
||||
// automata. http://www.gamedev.net/blog/844/entry-2249737-another-cellular-automaton-video/
|
||||
// If multiple instances of this script are run, they will combine into a larger wall.
|
||||
// NOTE: You must run each instance one at a time. If they all start at once there are race conditions.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var NUMBER_OF_CELLS_EACH_DIMENSION = 48;
|
||||
var NUMBER_OF_CELLS_REGION_EACH_DIMESION = 16;
|
||||
var REGIONS_EACH_DIMENSION = NUMBER_OF_CELLS_EACH_DIMENSION / NUMBER_OF_CELLS_REGION_EACH_DIMESION;
|
||||
|
||||
var isLocal = false;
|
||||
|
||||
var currentCells = [];
|
||||
var nextCells = [];
|
||||
|
||||
var cornerPosition = {x: 100, y: 0, z: 0 }
|
||||
var position = {x: 0, y: 0, z: 0 };
|
||||
|
||||
var METER_LENGTH = 1;
|
||||
var cellScale = (NUMBER_OF_CELLS_EACH_DIMENSION * METER_LENGTH) / NUMBER_OF_CELLS_EACH_DIMENSION;
|
||||
|
||||
var viewerPosition = {x: cornerPosition.x + (NUMBER_OF_CELLS_EACH_DIMENSION / 2) * cellScale, y: cornerPosition.y + (NUMBER_OF_CELLS_EACH_DIMENSION / 2) * cellScale, z: cornerPosition.z };
|
||||
|
||||
viewerPosition.z += 50;
|
||||
var yaw = 0;
|
||||
var orientation = Quat.fromPitchYawRollDegrees(0, yaw, 0);
|
||||
|
||||
//Feel free to add new cell types here. It can be more than three.
|
||||
var cellTypes = [];
|
||||
cellTypes[0] = { r: 255, g: 0, b: 0 };
|
||||
cellTypes[1] = { r: 0, g: 255, b: 0 };
|
||||
cellTypes[2] = { r: 0, g:0, b: 255 };
|
||||
cellTypes[3] = { r: 0, g: 255, b: 255 };
|
||||
|
||||
|
||||
//Check for free region for AC
|
||||
var regionMarkerX = -1;
|
||||
var regionMarkerY = -1;
|
||||
var regionMarkerI = -1;
|
||||
var regionMarkerJ = -1;
|
||||
|
||||
var regionMarkerColor = {r: 254, g: 0, b: 253};
|
||||
|
||||
function setRegionToColor(startX, startY, width, height, color) {
|
||||
for (var i = startY; i < startY + height; i++) {
|
||||
for (var j = startX; j < startX + width; j++) {
|
||||
|
||||
currentCells[i][j] = { changed: true, type: color };
|
||||
|
||||
// put the same value in the nextCells array for first board draw
|
||||
nextCells[i][j] = { changed: true, type: color };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
for (var i = 0; i < REGIONS_EACH_DIMENSION; i++) {
|
||||
for (var j = 0; j < REGIONS_EACH_DIMENSION; j++) {
|
||||
var x = cornerPosition.x + (j) * cellScale;
|
||||
var y = cornerPosition.y + (i + NUMBER_OF_CELLS_EACH_DIMENSION) * cellScale;
|
||||
var z = cornerPosition.z;
|
||||
var voxel = Voxels.getVoxelAt(x, y, z, cellScale);
|
||||
if (voxel.x != x || voxel.y != y || voxel.z != z || voxel.s != cellScale ||
|
||||
voxel.red != regionMarkerColor.r || voxel.green != regionMarkerColor.g || voxel.blue != regionMarkerColor.b) {
|
||||
regionMarkerX = x;
|
||||
regionMarkerY = y;
|
||||
regionMarkerI = i;
|
||||
regionMarkerJ = j;
|
||||
i = REGIONS_EACH_DIMENSION; //force quit loop
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Didnt find an open spot, end script
|
||||
if (regionMarkerX == -1) {
|
||||
Script.stop();
|
||||
}
|
||||
|
||||
position.x = cornerPosition.x + regionMarkerJ * NUMBER_OF_CELLS_REGION_EACH_DIMESION;
|
||||
position.y = cornerPosition.y + regionMarkerI * NUMBER_OF_CELLS_REGION_EACH_DIMESION;
|
||||
position.z = cornerPosition.z;
|
||||
|
||||
Voxels.setVoxel(regionMarkerX, regionMarkerY, cornerPosition.z, cellScale, regionMarkerColor.r, regionMarkerColor.g, regionMarkerColor.b);
|
||||
|
||||
for (var i = 0; i < NUMBER_OF_CELLS_REGION_EACH_DIMESION; i++) {
|
||||
// create the array to hold this row
|
||||
currentCells[i] = [];
|
||||
|
||||
// create the array to hold this row in the nextCells array
|
||||
nextCells[i] = [];
|
||||
}
|
||||
|
||||
var width = NUMBER_OF_CELLS_REGION_EACH_DIMESION / 2;
|
||||
setRegionToColor(0, 0, width, width, 0);
|
||||
setRegionToColor(0, width, width, width, 1);
|
||||
setRegionToColor(width, width, width, width, 2);
|
||||
setRegionToColor(width, 0, width, width, 3);
|
||||
}
|
||||
|
||||
function updateCells() {
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
var cell;
|
||||
var y = 0;
|
||||
var x = 0;
|
||||
|
||||
for (i = 0; i < NUMBER_OF_CELLS_REGION_EACH_DIMESION; i++) {
|
||||
for (j = 0; j < NUMBER_OF_CELLS_REGION_EACH_DIMESION; j++) {
|
||||
|
||||
cell = currentCells[i][j];
|
||||
|
||||
var r = Math.floor(Math.random() * 8);
|
||||
|
||||
switch (r){
|
||||
case 0:
|
||||
y = i - 1;
|
||||
x = j - 1;
|
||||
break;
|
||||
case 1:
|
||||
y = i;
|
||||
x = j-1;
|
||||
break;
|
||||
case 2:
|
||||
y = i + 1;
|
||||
x = j - 1;
|
||||
break;
|
||||
case 3:
|
||||
y = i + 1;
|
||||
x = j;
|
||||
break;
|
||||
case 4:
|
||||
y = i + 1;
|
||||
x = j + 1;
|
||||
break;
|
||||
case 5:
|
||||
y = i;
|
||||
x = j + 1;
|
||||
break;
|
||||
case 6:
|
||||
y = i - 1;
|
||||
x = j + 1;
|
||||
break;
|
||||
case 7:
|
||||
y = i - 1;
|
||||
x = j;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
//check the voxel grid instead of local array when on the edge
|
||||
if (x == -1 || x == NUMBER_OF_CELLS_REGION_EACH_DIMESION ||
|
||||
y == -1 || y == NUMBER_OF_CELLS_REGION_EACH_DIMESION) {
|
||||
|
||||
var voxel = Voxels.getVoxelAt(position.x + x * cellScale, position.y + y * cellScale, position.z, cellScale);
|
||||
var predatorCellType = ((cell.type + 1) % cellTypes.length);
|
||||
var predatorCellColor = cellTypes[predatorCellType];
|
||||
if (voxel.red == predatorCellColor.r && voxel.green == predatorCellColor.g && voxel.blue == predatorCellColor.b) {
|
||||
nextCells[i][j].type = predatorCellType;
|
||||
nextCells[i][j].changed = true;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (currentCells[y][x].type == ((cell.type + 1) % cellTypes.length)) {
|
||||
nextCells[i][j].type = currentCells[y][x].type;
|
||||
nextCells[i][j].changed = true;
|
||||
} else {
|
||||
//indicate no update
|
||||
nextCells[i][j].changed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < NUMBER_OF_CELLS_REGION_EACH_DIMESION; i++) {
|
||||
for (j = 0; j < NUMBER_OF_CELLS_REGION_EACH_DIMESION; j++) {
|
||||
if (nextCells[i][j].changed == true) {
|
||||
// there has been a change to this cell, change the value in the currentCells array
|
||||
currentCells[i][j].type = nextCells[i][j].type;
|
||||
currentCells[i][j].changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sendNextCells() {
|
||||
for (var i = 0; i < NUMBER_OF_CELLS_REGION_EACH_DIMESION; i++) {
|
||||
for (var j = 0; j < NUMBER_OF_CELLS_REGION_EACH_DIMESION; j++) {
|
||||
if (nextCells[i][j].changed == true) {
|
||||
// there has been a change to the state of this cell, send it
|
||||
|
||||
// find the x and y position for this voxel, z = 0
|
||||
var x = j * cellScale;
|
||||
var y = i * cellScale;
|
||||
var type = nextCells[i][j].type;
|
||||
|
||||
// queue a packet to add a voxel for the new cell
|
||||
Voxels.setVoxel(position.x + x, position.y + y, position.z, cellScale, cellTypes[type].r, cellTypes[type].g, cellTypes[type].b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sentFirstBoard = false;
|
||||
var voxelViewerInit = false;
|
||||
|
||||
var UPDATES_PER_SECOND = 6.0;
|
||||
var frameIndex = 1.0;
|
||||
var oldFrameIndex = 0;
|
||||
|
||||
var framesToWait = UPDATES_PER_SECOND;
|
||||
|
||||
function step(deltaTime) {
|
||||
|
||||
if (isLocal == false) {
|
||||
if (voxelViewerInit == false) {
|
||||
VoxelViewer.setPosition(viewerPosition);
|
||||
VoxelViewer.setOrientation(orientation);
|
||||
voxelViewerInit = true;
|
||||
}
|
||||
VoxelViewer.queryOctree();
|
||||
}
|
||||
|
||||
frameIndex += deltaTime * UPDATES_PER_SECOND;
|
||||
if (Math.floor(frameIndex) == oldFrameIndex) {
|
||||
return;
|
||||
}
|
||||
oldFrameIndex++;
|
||||
|
||||
if (frameIndex <= framesToWait) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sentFirstBoard) {
|
||||
// we've already sent the first full board, perform a step in time
|
||||
updateCells();
|
||||
} else {
|
||||
// this will be our first board send
|
||||
sentFirstBoard = true;
|
||||
init();
|
||||
}
|
||||
|
||||
if (isLocal == false) {
|
||||
VoxelViewer.queryOctree();
|
||||
}
|
||||
sendNextCells();
|
||||
}
|
||||
|
||||
function scriptEnding() {
|
||||
Voxels.eraseVoxel(regionMarkerX, regionMarkerY, position.z, cellScale);
|
||||
}
|
||||
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
Script.update.connect(step);
|
||||
Voxels.setPacketsPerSecond(2000);
|
||||
|
||||
// test for local...
|
||||
Menu.isOptionChecked("Voxels");
|
||||
isLocal = true; // will only get here on local client
|
|
@ -1,226 +0,0 @@
|
|||
|
||||
|
||||
|
||||
var wallX = 8000;
|
||||
var wallY = 8000;
|
||||
var wallZ = 8000;//location
|
||||
|
||||
|
||||
var VOXELSIZE=12;//size of each voxel
|
||||
|
||||
var FACTOR = 0.75;
|
||||
|
||||
var loud=1.0;
|
||||
var maxLoud=500;
|
||||
var minLoud=200;//range of loudness
|
||||
|
||||
|
||||
|
||||
var maxB={color:225,direction:0,speed:1};
|
||||
var minB={color:50,direction:1,speed:1};
|
||||
var maxG={color:200,direction:0,speed:1};
|
||||
var minG={color:30,direction:1,speed:1};
|
||||
var maxR={color:255,direction:0,speed:1};
|
||||
var minR={color:150,direction:1,speed:1};//color objects
|
||||
var addVoxArray=[];
|
||||
var removeVoxArray=[];
|
||||
var numAddVox=0;
|
||||
var numRemoveVox=0;//array for voxels removed and added
|
||||
|
||||
|
||||
var height;
|
||||
var wallWidth=34;
|
||||
var wallHeight=25;
|
||||
var maxHeight=wallHeight;
|
||||
var minHeight=0;//properties of wall
|
||||
|
||||
|
||||
var heightSamplesArray=[];
|
||||
var sampleIndex=0;//declare new array of heights
|
||||
|
||||
var direction=1;
|
||||
|
||||
|
||||
|
||||
|
||||
//initiate and fill array of heights
|
||||
for(var k=0;k<wallWidth;k++)
|
||||
{
|
||||
heightSamplesArray[k]=0;
|
||||
}
|
||||
|
||||
|
||||
//send objects to function changeColor
|
||||
function scratch()
|
||||
{
|
||||
|
||||
|
||||
changeColor(maxB);
|
||||
changeColor(minB);
|
||||
changeColor(maxG);
|
||||
changeColor(minG);
|
||||
changeColor(maxR);
|
||||
changeColor(minR);
|
||||
|
||||
//calculates loudness
|
||||
var audioAverageLoudness = MyAvatar.audioAverageLoudness * FACTOR;
|
||||
|
||||
|
||||
loud = Math.log(audioAverageLoudness) / 5.0 * 255.0;
|
||||
|
||||
print("loud="+ loud);
|
||||
|
||||
|
||||
var scalingfactor=(loud-minLoud)/(maxLoud-minLoud);
|
||||
if(scalingfactor<0)
|
||||
{
|
||||
scalingfactor=0;
|
||||
}
|
||||
if(scalingfactor>1)
|
||||
{
|
||||
scalingfactor=1;
|
||||
}
|
||||
|
||||
//creates diff shades for diff levels of volume
|
||||
|
||||
var green=(maxG.color-minG.color)*scalingfactor+minG.color;
|
||||
var blue=(maxB.color-minB.color)*scalingfactor+minB.color;
|
||||
var red=(maxR.color-minR.color)*scalingfactor+minR.color;
|
||||
height=(maxHeight-minHeight)*scalingfactor+minHeight;
|
||||
|
||||
|
||||
//sets height at position sampleIndex
|
||||
heightSamplesArray[sampleIndex]=height;
|
||||
|
||||
|
||||
|
||||
|
||||
if(loud==Number.NEGATIVE_INFINITY)
|
||||
{
|
||||
green=minG.color;
|
||||
blue=minB.color;
|
||||
red=minR.color;
|
||||
|
||||
}
|
||||
|
||||
|
||||
var k=sampleIndex;
|
||||
|
||||
//add&remove voxels
|
||||
|
||||
for(var i=wallWidth-1;i>=0;i--)
|
||||
{
|
||||
|
||||
for(var j=0;j<wallHeight;j++)
|
||||
|
||||
{
|
||||
if(j<=heightSamplesArray[k])
|
||||
{
|
||||
addVoxArray[numAddVox]={x:wallX+i*VOXELSIZE, y:wallY+j*VOXELSIZE, z:wallZ};
|
||||
|
||||
numAddVox++;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
removeVoxArray[numRemoveVox]={x:wallX+i*VOXELSIZE, y:wallY+j*VOXELSIZE, z:wallZ};
|
||||
|
||||
numRemoveVox++;
|
||||
}
|
||||
|
||||
}
|
||||
k--;
|
||||
if(k<0)
|
||||
{
|
||||
k=wallWidth-1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(var k=0;k<numAddVox;k++)
|
||||
{
|
||||
Voxels.setVoxel(addVoxArray[k].x,addVoxArray[k].y,addVoxArray[k].z,VOXELSIZE, red, green, blue);
|
||||
}
|
||||
|
||||
for(var k=0;k<numRemoveVox;k++)
|
||||
{
|
||||
Voxels.eraseVoxel(removeVoxArray[k].x,removeVoxArray[k].y,removeVoxArray[k].z,VOXELSIZE);
|
||||
}
|
||||
|
||||
numAddVox=0;
|
||||
numRemoveVox=0;
|
||||
|
||||
sampleIndex++;
|
||||
if(sampleIndex>=wallWidth)
|
||||
{
|
||||
sampleIndex=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//color properties (shade, direction, speed)
|
||||
|
||||
function changeColor(color)
|
||||
{
|
||||
|
||||
if (color.direction==1)
|
||||
{
|
||||
if(color.color<255)
|
||||
{
|
||||
color.color+=(color.speed);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
color.direction=0;
|
||||
}
|
||||
|
||||
}
|
||||
else if(color.direction==0)
|
||||
{
|
||||
if(color.color>0)
|
||||
{
|
||||
color.color-=(color.speed);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
color.direction=1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Script.update.connect(scratch);
|
||||
Voxels.setPacketsPerSecond(20000);
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
|
||||
|
||||
|
||||
var wallX = 700;
|
||||
var wallY = 700;
|
||||
var wallZ = 700;//location
|
||||
|
||||
var VOXELSIZE=8;
|
||||
var red=225;
|
||||
var blue=0;
|
||||
var green=0;//color brightness
|
||||
var currentStep=0;//counting number of steps
|
||||
var direction=1;//left to right color change
|
||||
var height=8;
|
||||
var width=8;
|
||||
|
||||
|
||||
var currentStep=0;
|
||||
|
||||
|
||||
|
||||
|
||||
function step()
|
||||
{
|
||||
|
||||
|
||||
|
||||
currentStep++;
|
||||
|
||||
if(currentStep>6000)//how long it will run
|
||||
Script.stop();
|
||||
|
||||
|
||||
for(var i=0;i<width;i++)
|
||||
{
|
||||
for(var j=0;j<height;j++)
|
||||
{
|
||||
|
||||
Voxels.setVoxel(wallX+i*VOXELSIZE, wallY+j*VOXELSIZE, wallZ, VOXELSIZE, red,green,blue);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (direction==1)
|
||||
{
|
||||
if(blue<255)
|
||||
{
|
||||
blue++;
|
||||
red--;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
direction=0;
|
||||
}
|
||||
|
||||
}
|
||||
else if(direction==0)
|
||||
{
|
||||
if(blue>0)
|
||||
{
|
||||
blue--;
|
||||
red++;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
direction=1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Script.update.connect(step);
|
||||
Voxels.setPacketsPerSecond(20000);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue