editVoxels reformat

This commit is contained in:
Atlante45 2014-04-16 17:33:15 -07:00
parent 956fe71d34
commit 1c89d8f3ed

View file

@ -157,50 +157,50 @@ var editToolsOn = true; // starts out off
var previewAsVoxel = false; var previewAsVoxel = false;
var voxelPreview = Overlays.addOverlay("cube", { var voxelPreview = Overlays.addOverlay("cube", {
position: { x: 0, y: 0, z: 0}, position: { x: 0, y: 0, z: 0},
size: 1, size: 1,
color: { red: 255, green: 0, blue: 0}, color: { red: 255, green: 0, blue: 0},
alpha: 1, alpha: 1,
solid: false, solid: false,
visible: false, visible: false,
lineWidth: 4 lineWidth: 4
}); });
var linePreviewTop = Overlays.addOverlay("line3d", { var linePreviewTop = Overlays.addOverlay("line3d", {
position: { x: 0, y: 0, z: 0}, position: { x: 0, y: 0, z: 0},
end: { x: 0, y: 0, z: 0}, end: { x: 0, y: 0, z: 0},
color: { red: 255, green: 255, blue: 255}, color: { red: 255, green: 255, blue: 255},
alpha: 1, alpha: 1,
visible: false, visible: false,
lineWidth: previewLineWidth lineWidth: previewLineWidth
}); });
var linePreviewBottom = Overlays.addOverlay("line3d", { var linePreviewBottom = Overlays.addOverlay("line3d", {
position: { x: 0, y: 0, z: 0}, position: { x: 0, y: 0, z: 0},
end: { x: 0, y: 0, z: 0}, end: { x: 0, y: 0, z: 0},
color: { red: 255, green: 255, blue: 255}, color: { red: 255, green: 255, blue: 255},
alpha: 1, alpha: 1,
visible: false, visible: false,
lineWidth: previewLineWidth lineWidth: previewLineWidth
}); });
var linePreviewLeft = Overlays.addOverlay("line3d", { var linePreviewLeft = Overlays.addOverlay("line3d", {
position: { x: 0, y: 0, z: 0}, position: { x: 0, y: 0, z: 0},
end: { x: 0, y: 0, z: 0}, end: { x: 0, y: 0, z: 0},
color: { red: 255, green: 255, blue: 255}, color: { red: 255, green: 255, blue: 255},
alpha: 1, alpha: 1,
visible: false, visible: false,
lineWidth: previewLineWidth lineWidth: previewLineWidth
}); });
var linePreviewRight = Overlays.addOverlay("line3d", { var linePreviewRight = Overlays.addOverlay("line3d", {
position: { x: 0, y: 0, z: 0}, position: { x: 0, y: 0, z: 0},
end: { x: 0, y: 0, z: 0}, end: { x: 0, y: 0, z: 0},
color: { red: 255, green: 255, blue: 255}, color: { red: 255, green: 255, blue: 255},
alpha: 1, alpha: 1,
visible: false, visible: false,
lineWidth: previewLineWidth lineWidth: previewLineWidth
}); });
// these will be used below // these will be used below
@ -238,16 +238,16 @@ for (s = 0; s < numColors; s++) {
} }
swatches[s] = Overlays.addOverlay("image", { swatches[s] = Overlays.addOverlay("image", {
x: swatchX, x: swatchX,
y: swatchesY, y: swatchesY,
width: swatchWidth + extraWidth, width: swatchWidth + extraWidth,
height: swatchHeight, height: swatchHeight,
subImage: { x: imageFromX, y: imageFromY, width: swatchWidth + extraWidth, height: swatchHeight }, subImage: { x: imageFromX, y: imageFromY, width: swatchWidth + extraWidth, height: swatchHeight },
imageURL: toolIconUrl + "swatches.svg", imageURL: toolIconUrl + "swatches.svg",
color: colors[s], color: colors[s],
alpha: 1, alpha: 1,
visible: editToolsOn visible: editToolsOn
}); });
} }
@ -267,28 +267,28 @@ var eyedropperToolAt = 2;
var pasteModeColor = { red: 132, green: 61, blue: 255 }; var pasteModeColor = { red: 132, green: 61, blue: 255 };
var voxelTool = Overlays.addOverlay("image", { var voxelTool = Overlays.addOverlay("image", {
x: 0, y: 0, width: toolWidth, height: toolHeight, x: 0, y: 0, width: toolWidth, height: toolHeight,
subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight }, subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
imageURL: toolIconUrl + "voxel-tool.svg", imageURL: toolIconUrl + "voxel-tool.svg",
visible: false, visible: false,
alpha: 0.9 alpha: 0.9
}); });
var recolorTool = Overlays.addOverlay("image", { var recolorTool = Overlays.addOverlay("image", {
x: 0, y: 0, width: toolWidth, height: toolHeight, x: 0, y: 0, width: toolWidth, height: toolHeight,
subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight }, subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
imageURL: toolIconUrl + "paint-tool.svg", imageURL: toolIconUrl + "paint-tool.svg",
visible: false, visible: false,
alpha: 0.9 alpha: 0.9
}); });
var eyedropperTool = Overlays.addOverlay("image", { var eyedropperTool = Overlays.addOverlay("image", {
x: 0, y: 0, width: toolWidth, height: toolHeight, x: 0, y: 0, width: toolWidth, height: toolHeight,
subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight }, subImage: { x: 0, y: toolHeight, width: toolWidth, height: toolHeight },
imageURL: toolIconUrl + "eyedropper-tool.svg", imageURL: toolIconUrl + "eyedropper-tool.svg",
visible: false, visible: false,
alpha: 0.9 alpha: 0.9
}); });
// This will create a couple of image overlays that make a "slider", we will demonstrate how to trap mouse messages to // This will create a couple of image overlays that make a "slider", we will demonstrate how to trap mouse messages to
// move the slider // move the slider
@ -301,12 +301,12 @@ var sliderOffsetX = 17;
var sliderX = swatchesX - swatchWidth - sliderOffsetX; var sliderX = swatchesX - swatchWidth - sliderOffsetX;
var sliderY = windowDimensions.y - sliderHeight + 1; var sliderY = windowDimensions.y - sliderHeight + 1;
var slider = Overlays.addOverlay("image", { var slider = Overlays.addOverlay("image", {
// alternate form of expressing bounds // alternate form of expressing bounds
bounds: { x: sliderX, y: sliderY, width: sliderWidth, height: sliderHeight}, bounds: { x: sliderX, y: sliderY, width: sliderWidth, height: sliderHeight},
imageURL: toolIconUrl + "voxel-size-slider-bg.svg", imageURL: toolIconUrl + "voxel-size-slider-bg.svg",
alpha: 1, alpha: 1,
visible: false visible: false
}); });
// The slider is handled in the mouse event callbacks. // The slider is handled in the mouse event callbacks.
var isMovingSlider = false; var isMovingSlider = false;
@ -320,14 +320,14 @@ var thumbX = (minThumbX + maxThumbX) / 2;
var thumbOffsetY = 11; var thumbOffsetY = 11;
var thumbY = sliderY + thumbOffsetY; var thumbY = sliderY + thumbOffsetY;
var thumb = Overlays.addOverlay("image", { var thumb = Overlays.addOverlay("image", {
x: sliderX + thumbX, x: sliderX + thumbX,
y: thumbY, y: thumbY,
width: 17, width: 17,
height: 17, height: 17,
imageURL: toolIconUrl + "voxel-size-slider-handle.svg", imageURL: toolIconUrl + "voxel-size-slider-handle.svg",
alpha: 1, alpha: 1,
visible: false visible: false
}); });
var pointerVoxelScale = Math.floor(MAX_VOXEL_SCALE + MIN_VOXEL_SCALE) / 2; // this is the voxel scale used for click to add or delete var pointerVoxelScale = Math.floor(MAX_VOXEL_SCALE + MIN_VOXEL_SCALE) / 2; // this is the voxel scale used for click to add or delete
var pointerVoxelScaleSet = false; // if voxel scale has not yet been set, we use the intersection size var pointerVoxelScaleSet = false; // if voxel scale has not yet been set, we use the intersection size
@ -533,13 +533,13 @@ function calculateVoxelFromIntersection(intersection, operation) {
var wantDebug = false; var wantDebug = false;
if (wantDebug) { if (wantDebug) {
print(">>>>> calculateVoxelFromIntersection().... intersection voxel.red/green/blue=" + intersection.voxel.red + ", " print(">>>>> calculateVoxelFromIntersection().... intersection voxel.red/green/blue=" + intersection.voxel.red + ", "
+ intersection.voxel.green + ", " + intersection.voxel.blue); + intersection.voxel.green + ", " + intersection.voxel.blue);
print(" intersection voxel.x/y/z/s=" + intersection.voxel.x + ", " print(" intersection voxel.x/y/z/s=" + intersection.voxel.x + ", "
+ intersection.voxel.y + ", " + intersection.voxel.z+ ": " + intersection.voxel.s); + intersection.voxel.y + ", " + intersection.voxel.z+ ": " + intersection.voxel.s);
print(" intersection face=" + intersection.face); print(" intersection face=" + intersection.face);
print(" intersection distance=" + intersection.distance); print(" intersection distance=" + intersection.distance);
print(" intersection intersection.x/y/z=" + intersection.intersection.x + ", " print(" intersection intersection.x/y/z=" + intersection.intersection.x + ", "
+ intersection.intersection.y + ", " + intersection.intersection.z); + intersection.intersection.y + ", " + intersection.intersection.z);
} }
var voxelSize; var voxelSize;
@ -678,12 +678,12 @@ function showPreviewVoxel() {
if (whichColor == -1) { if (whichColor == -1) {
// Copy mode - use clicked voxel color // Copy mode - use clicked voxel color
voxelColor = { red: intersection.voxel.red, voxelColor = { red: intersection.voxel.red,
green: intersection.voxel.green, green: intersection.voxel.green,
blue: intersection.voxel.blue }; blue: intersection.voxel.blue };
} else { } else {
voxelColor = { red: colors[whichColor].red, voxelColor = { red: colors[whichColor].red,
green: colors[whichColor].green, green: colors[whichColor].green,
blue: colors[whichColor].blue }; blue: colors[whichColor].blue };
} }
var guidePosition; var guidePosition;
@ -709,24 +709,24 @@ function showPreviewLines() {
// X axis // X axis
Overlays.editOverlay(linePreviewBottom, { Overlays.editOverlay(linePreviewBottom, {
position: pasteVoxel.origin, position: pasteVoxel.origin,
end: {x: pasteVoxel.origin.x + pasteVoxel.voxelSize, y: pasteVoxel.origin.y, z: pasteVoxel.origin.z }, end: {x: pasteVoxel.origin.x + pasteVoxel.voxelSize, y: pasteVoxel.origin.y, z: pasteVoxel.origin.z },
visible: true visible: true
}); });
// Y axis // Y axis
Overlays.editOverlay(linePreviewRight, { Overlays.editOverlay(linePreviewRight, {
position: pasteVoxel.origin, position: pasteVoxel.origin,
end: {x: pasteVoxel.origin.x, y: pasteVoxel.origin.y + pasteVoxel.voxelSize, z: pasteVoxel.origin.z }, end: {x: pasteVoxel.origin.x, y: pasteVoxel.origin.y + pasteVoxel.voxelSize, z: pasteVoxel.origin.z },
visible: true visible: true
}); });
// Z axis // Z axis
Overlays.editOverlay(linePreviewTop, { Overlays.editOverlay(linePreviewTop, {
position: pasteVoxel.origin, position: pasteVoxel.origin,
end: {x: pasteVoxel.origin.x, y: pasteVoxel.origin.y, z: pasteVoxel.origin.z - pasteVoxel.voxelSize }, end: {x: pasteVoxel.origin.x, y: pasteVoxel.origin.y, z: pasteVoxel.origin.z - pasteVoxel.voxelSize },
visible: true visible: true
}); });
return; return;
} }
@ -878,7 +878,7 @@ function mousePressEvent(event) {
thumbClickOffsetX = event.x - (sliderX + thumbX); // this should be the position of the mouse relative to the thumb thumbClickOffsetX = event.x - (sliderX + thumbX); // this should be the position of the mouse relative to the thumb
clickedOnSomething = true; clickedOnSomething = true;
Overlays.editOverlay(thumb, { imageURL: toolIconUrl + "voxel-size-slider-handle.svg", }); //Overlays.editOverlay(thumb, { imageURL: toolIconUrl + "voxel-size-slider-handle.svg", });
} else if (clickedOverlay == voxelTool) { } else if (clickedOverlay == voxelTool) {
modeSwitchSound.play(0); modeSwitchSound.play(0);
@ -990,19 +990,19 @@ function mousePressEvent(event) {
if (whichColor == -1) { if (whichColor == -1) {
// Copy mode - use clicked voxel color // Copy mode - use clicked voxel color
newColor = { newColor = {
red: intersection.voxel.red, red: intersection.voxel.red,
green: intersection.voxel.green, green: intersection.voxel.green,
blue: intersection.voxel.blue }; blue: intersection.voxel.blue };
} else { } else {
newColor = { newColor = {
red: colors[whichColor].red, red: colors[whichColor].red,
green: colors[whichColor].green, green: colors[whichColor].green,
blue: colors[whichColor].blue }; blue: colors[whichColor].blue };
} }
voxelDetails = calculateVoxelFromIntersection(intersection,"add"); voxelDetails = calculateVoxelFromIntersection(intersection,"add");
Voxels.setVoxel(voxelDetails.x, voxelDetails.y, voxelDetails.z, voxelDetails.s, Voxels.setVoxel(voxelDetails.x, voxelDetails.y, voxelDetails.z, voxelDetails.s,
newColor.red, newColor.green, newColor.blue); newColor.red, newColor.green, newColor.blue);
lastVoxelPosition = { x: voxelDetails.x, y: voxelDetails.y, z: voxelDetails.z }; lastVoxelPosition = { x: voxelDetails.x, y: voxelDetails.y, z: voxelDetails.z };
lastVoxelColor = { red: newColor.red, green: newColor.green, blue: newColor.blue }; lastVoxelColor = { red: newColor.red, green: newColor.green, blue: newColor.blue };
lastVoxelScale = voxelDetails.s; lastVoxelScale = voxelDetails.s;
@ -1036,13 +1036,13 @@ function keyPressEvent(event) {
if (color == -1) color = 0; if (color == -1) color = 0;
var newPosition = getNewVoxelPosition(); var newPosition = getNewVoxelPosition();
var newVoxel = { var newVoxel = {
x: newPosition.x, x: newPosition.x,
y: newPosition.y , y: newPosition.y ,
z: newPosition.z, z: newPosition.z,
s: NEW_VOXEL_SIZE, s: NEW_VOXEL_SIZE,
red: colors[color].red, red: colors[color].red,
green: colors[color].green, green: colors[color].green,
blue: colors[color].blue }; blue: colors[color].blue };
Voxels.eraseVoxel(newVoxel.x, newVoxel.y, newVoxel.z, newVoxel.s); Voxels.eraseVoxel(newVoxel.x, newVoxel.y, newVoxel.z, newVoxel.s);
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);
setAudioPosition(); setAudioPosition();
@ -1173,8 +1173,8 @@ function mouseMoveEvent(event) {
if (!isExtruding) { if (!isExtruding) {
var pickRay = Camera.computePickRay(event.x, event.y); var pickRay = Camera.computePickRay(event.x, event.y);
var lastVoxelDistance = { x: pickRay.origin.x - lastVoxelPosition.x, var lastVoxelDistance = { x: pickRay.origin.x - lastVoxelPosition.x,
y: pickRay.origin.y - lastVoxelPosition.y, y: pickRay.origin.y - lastVoxelPosition.y,
z: pickRay.origin.z - lastVoxelPosition.z }; z: pickRay.origin.z - lastVoxelPosition.z };
var distance = Vec3.length(lastVoxelDistance); var distance = Vec3.length(lastVoxelDistance);
var mouseSpot = { x: pickRay.direction.x * distance, y: pickRay.direction.y * distance, z: pickRay.direction.z * distance }; var mouseSpot = { x: pickRay.direction.x * distance, y: pickRay.direction.y * distance, z: pickRay.direction.z * distance };
mouseSpot.x += pickRay.origin.x; mouseSpot.x += pickRay.origin.x;
@ -1200,7 +1200,7 @@ function mouseMoveEvent(event) {
if (Math.sqrt(dx*dx + dy*dy) > PIXELS_PER_EXTRUDE_VOXEL) { if (Math.sqrt(dx*dx + dy*dy) > PIXELS_PER_EXTRUDE_VOXEL) {
lastVoxelPosition = Vec3.sum(lastVoxelPosition, extrudeDirection); lastVoxelPosition = Vec3.sum(lastVoxelPosition, extrudeDirection);
Voxels.setVoxel(lastVoxelPosition.x, lastVoxelPosition.y, lastVoxelPosition.z, Voxels.setVoxel(lastVoxelPosition.x, lastVoxelPosition.y, lastVoxelPosition.z,
extrudeScale, lastVoxelColor.red, lastVoxelColor.green, lastVoxelColor.blue); extrudeScale, lastVoxelColor.red, lastVoxelColor.green, lastVoxelColor.blue);
mouseX = event.x; mouseX = event.x;
mouseY = event.y; mouseY = event.y;
} }
@ -1254,21 +1254,21 @@ function moveTools() {
} }
Overlays.editOverlay(swatches[s], { Overlays.editOverlay(swatches[s], {
x: swatchX, x: swatchX,
y: swatchesY, y: swatchesY,
subImage: { x: imageFromX, y: imageFromY, width: swatchWidth + extraWidth, height: swatchHeight }, subImage: { x: imageFromX, y: imageFromY, width: swatchWidth + extraWidth, height: swatchHeight },
color: colors[s], color: colors[s],
alpha: 1, alpha: 1,
visible: editToolsOn visible: editToolsOn
}); });
} }
// move the tools // move the tools
toolsY = (windowDimensions.y - toolsHeight) / 2; toolsY = (windowDimensions.y - toolsHeight) / 2;
var voxelToolOffset = 1, var voxelToolOffset = 1,
recolorToolOffset = 1, recolorToolOffset = 1,
eyedropperToolOffset = 1; eyedropperToolOffset = 1;
var voxelToolColor = WHITE_COLOR; var voxelToolColor = WHITE_COLOR;
@ -1284,23 +1284,23 @@ function moveTools() {
} }
Overlays.editOverlay(voxelTool, { Overlays.editOverlay(voxelTool, {
subImage: { x: 0, y: toolHeight * voxelToolOffset, width: toolWidth, height: toolHeight }, subImage: { x: 0, y: toolHeight * voxelToolOffset, width: toolWidth, height: toolHeight },
x: toolsX, y: toolsY + ((toolHeight + toolVerticalSpacing) * voxelToolAt), width: toolWidth, height: toolHeight, x: toolsX, y: toolsY + ((toolHeight + toolVerticalSpacing) * voxelToolAt), width: toolWidth, height: toolHeight,
color: voxelToolColor, color: voxelToolColor,
visible: editToolsOn visible: editToolsOn
}); });
Overlays.editOverlay(recolorTool, { Overlays.editOverlay(recolorTool, {
subImage: { x: 0, y: toolHeight * recolorToolOffset, width: toolWidth, height: toolHeight }, subImage: { x: 0, y: toolHeight * recolorToolOffset, width: toolWidth, height: toolHeight },
x: toolsX, y: toolsY + ((toolHeight + toolVerticalSpacing) * recolorToolAt), width: toolWidth, height: toolHeight, x: toolsX, y: toolsY + ((toolHeight + toolVerticalSpacing) * recolorToolAt), width: toolWidth, height: toolHeight,
visible: editToolsOn visible: editToolsOn
}); });
Overlays.editOverlay(eyedropperTool, { Overlays.editOverlay(eyedropperTool, {
subImage: { x: 0, y: toolHeight * eyedropperToolOffset, width: toolWidth, height: toolHeight }, subImage: { x: 0, y: toolHeight * eyedropperToolOffset, width: toolWidth, height: toolHeight },
x: toolsX, y: toolsY + ((toolHeight + toolVerticalSpacing) * eyedropperToolAt), width: toolWidth, height: toolHeight, x: toolsX, y: toolsY + ((toolHeight + toolVerticalSpacing) * eyedropperToolAt), width: toolWidth, height: toolHeight,
visible: editToolsOn visible: editToolsOn
}); });
sliderX = swatchesX + swatchesWidth - sliderOffsetX; sliderX = swatchesX + swatchesWidth - sliderOffsetX;
sliderY = windowDimensions.y - sliderHeight + 1; sliderY = windowDimensions.y - sliderHeight + 1;
@ -1338,7 +1338,7 @@ function checkControllers() {
Voxels.eraseVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE); Voxels.eraseVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE);
Voxels.setVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE, Voxels.setVoxel(fingerTipPosition.x, fingerTipPosition.y, fingerTipPosition.z, FINGERTIP_VOXEL_SIZE,
newColor.red, newColor.green, newColor.blue); newColor.red, newColor.green, newColor.blue);
lastFingerAddVoxel = fingerTipPosition; lastFingerAddVoxel = fingerTipPosition;
} }
@ -1367,9 +1367,9 @@ function update(deltaTime) {
var forwardVector = Quat.getFront(MyAvatar.orientation); var forwardVector = Quat.getFront(MyAvatar.orientation);
var targetPosition = Vec3.sum(position, Vec3.multiply(forwardVector, importScale)); var targetPosition = Vec3.sum(position, Vec3.multiply(forwardVector, importScale));
var newPosition = { var newPosition = {
x: Math.floor(targetPosition.x / importScale) * importScale, x: Math.floor(targetPosition.x / importScale) * importScale,
y: Math.floor(targetPosition.y / importScale) * importScale, y: Math.floor(targetPosition.y / importScale) * importScale,
z: Math.floor(targetPosition.z / importScale) * importScale z: Math.floor(targetPosition.z / importScale) * importScale
} }
moveImport(newPosition); moveImport(newPosition);
} }