Merge pull request #7405 from sethalves/fix-voxels-js

make voxels.js buttons work, again
This commit is contained in:
Brad Hefta-Gaub 2016-03-21 08:46:29 -07:00
commit 2e7bc5f430

View file

@ -16,8 +16,8 @@ var deletingVoxels = false;
var addingSpheres = false; var addingSpheres = false;
var deletingSpheres = false; var deletingSpheres = false;
var offAlpha = 0.5; var offAlpha = 0.8;
var onAlpha = 0.9; var onAlpha = 1.0;
var editSphereRadius = 4; var editSphereRadius = 4;
function floorVector(v) { function floorVector(v) {
@ -48,52 +48,47 @@ var toolBar = (function () {
height: toolHeight, height: toolHeight,
alpha: onAlpha, alpha: onAlpha,
visible: true, visible: true,
}); }, false);
addVoxelButton = toolBar.addTool({ addVoxelButton = toolBar.addTool({
imageURL: toolIconUrl + "voxel-add.svg", imageURL: toolIconUrl + "voxel-add.svg",
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
width: toolWidth, width: toolWidth,
height: toolHeight, height: toolHeight,
alpha: offAlpha, alpha: offAlpha,
visible: false visible: false
}); }, false);
deleteVoxelButton = toolBar.addTool({ deleteVoxelButton = toolBar.addTool({
imageURL: toolIconUrl + "voxel-delete.svg", imageURL: toolIconUrl + "voxel-delete.svg",
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
width: toolWidth, width: toolWidth,
height: toolHeight, height: toolHeight,
alpha: offAlpha, alpha: offAlpha,
visible: false visible: false
}); }, false);
addSphereButton = toolBar.addTool({ addSphereButton = toolBar.addTool({
imageURL: toolIconUrl + "sphere-add.svg", imageURL: toolIconUrl + "sphere-add.svg",
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
width: toolWidth, width: toolWidth,
height: toolHeight, height: toolHeight,
alpha: offAlpha, alpha: offAlpha,
visible: false visible: false
}); }, false);
deleteSphereButton = toolBar.addTool({ deleteSphereButton = toolBar.addTool({
imageURL: toolIconUrl + "sphere-delete.svg", imageURL: toolIconUrl + "sphere-delete.svg",
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
width: toolWidth, width: toolWidth,
height: toolHeight, height: toolHeight,
alpha: offAlpha, alpha: offAlpha,
visible: false visible: false
}); }, false);
addTerrainButton = toolBar.addTool({ addTerrainButton = toolBar.addTool({
imageURL: toolIconUrl + "voxel-terrain.svg", imageURL: toolIconUrl + "voxel-terrain.svg",
subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT },
width: toolWidth, width: toolWidth,
height: toolHeight, height: toolHeight,
alpha: onAlpha, alpha: onAlpha,
visible: false visible: false
}); }, false);
that.setActive(false); that.setActive(false);
} }
@ -193,7 +188,6 @@ var toolBar = (function () {
that.cleanup = function () { that.cleanup = function () {
toolBar.cleanup(); toolBar.cleanup();
// Overlays.deleteOverlay(activeButton);
}; };
@ -237,7 +231,6 @@ function grabLowestJointY() {
} }
function addTerrainBlock() { function addTerrainBlock() {
var baseLocation = getTerrainAlignedLocation(Vec3.sum(MyAvatar.position, {x:8, y:8, z:8})); var baseLocation = getTerrainAlignedLocation(Vec3.sum(MyAvatar.position, {x:8, y:8, z:8}));
if (baseLocation.y > MyAvatar.position.y) { if (baseLocation.y > MyAvatar.position.y) {
@ -253,10 +246,26 @@ function addTerrainBlock() {
baseLocation = getTerrainAlignedLocation(facingPosition); baseLocation = getTerrainAlignedLocation(facingPosition);
alreadyThere = lookupTerrainForLocation(baseLocation); alreadyThere = lookupTerrainForLocation(baseLocation);
if (alreadyThere) { if (alreadyThere) {
return; return null;
} }
} }
var polyVoxID = addTerrainBlockNearLocation(baseLocation);
if (polyVoxID) {
var AvatarPositionInVoxelCoords = Entities.worldCoordsToVoxelCoords(polyVoxID, MyAvatar.position);
// TODO -- how to find the avatar's feet?
var topY = Math.round(AvatarPositionInVoxelCoords.y) - 4;
Entities.setVoxelsInCuboid(polyVoxID, {x:0, y:0, z:0}, {x:16, y:topY, z:16}, 255);
}
}
function addTerrainBlockNearLocation(baseLocation) {
var alreadyThere = lookupTerrainForLocation(baseLocation);
if (alreadyThere) {
return null;
}
var polyVoxID = Entities.addEntity({ var polyVoxID = Entities.addEntity({
type: "PolyVox", type: "PolyVox",
name: "terrain", name: "terrain",
@ -269,12 +278,6 @@ function addTerrainBlock() {
zTextureURL: "http://headache.hungry.com/~seth/hifi/dirt.jpeg" zTextureURL: "http://headache.hungry.com/~seth/hifi/dirt.jpeg"
}); });
var AvatarPositionInVoxelCoords = Entities.worldCoordsToVoxelCoords(polyVoxID, MyAvatar.position);
// TODO -- how to find the avatar's feet?
var topY = Math.round(AvatarPositionInVoxelCoords.y) - 4;
Entities.setVoxelsInCuboid(polyVoxID, {x:0, y:0, z:0}, {x:16, y:topY, z:16}, 255);
////////// //////////
// stitch together the terrain with x/y/z NeighorID properties // stitch together the terrain with x/y/z NeighorID properties
////////// //////////
@ -330,7 +333,7 @@ function addTerrainBlock() {
properties.zPNeighborID = lookupTerrainForLocation(Vec3.sum(baseLocation, {x:0, y:0, z:16})); properties.zPNeighborID = lookupTerrainForLocation(Vec3.sum(baseLocation, {x:0, y:0, z:16}));
Entities.editEntity(polyVoxID, properties); Entities.editEntity(polyVoxID, properties);
return true; return polyVoxID;
} }
@ -456,9 +459,6 @@ function keyReleaseEvent(event) {
function cleanup() { function cleanup() {
for (var i = 0; i < overlays.length; i++) {
Overlays.deleteOverlay(overlays[i]);
}
toolBar.cleanup(); toolBar.cleanup();
} }