Basic voxel editing for desktop mode

This commit is contained in:
ksuprynowicz 2022-05-26 00:25:31 +02:00
parent 4acdf8502d
commit 51b267a18f
4 changed files with 40 additions and 5 deletions

View file

@ -136,6 +136,7 @@ var editTools = new EditTools({
var editVoxels = new EditVoxels(); var editVoxels = new EditVoxels();
editTools.addListener(editVoxels.updateEditSettings); editTools.addListener(editVoxels.updateEditSettings);
editTools.addListener(selectionManager.updateEditSettings);
var entityShapeVisualizerSessionName = "SHAPE_VISUALIZER_" + Uuid.generate(); var entityShapeVisualizerSessionName = "SHAPE_VISUALIZER_" + Uuid.generate();
@ -781,7 +782,7 @@ var toolBar = (function () {
xTextureURL: result.xTextureURL, xTextureURL: result.xTextureURL,
yTextureURL: result.yTextureURL, yTextureURL: result.yTextureURL,
zTextureURL: result.zTextureURL, zTextureURL: result.zTextureURL,
voxelSurfaceStyle: 3, voxelSurfaceStyle: voxelSurfaceStyle,
collisionless: !(result.collisions), collisionless: !(result.collisions),
grab: { grab: {
grabbable: result.grabbable grabbable: result.grabbable
@ -1103,6 +1104,8 @@ var toolBar = (function () {
isActive = active; isActive = active;
activeButton.editProperties({isActive: isActive}); activeButton.editProperties({isActive: isActive});
undoHistory.setEnabled(isActive); undoHistory.setEnabled(isActive);
editVoxels.setActive(active);
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
@ -1456,7 +1459,7 @@ function mouseClickEvent(event) {
var sizeOK = (allowLargeModels || angularSize < MAX_ANGULAR_SIZE) && var sizeOK = (allowLargeModels || angularSize < MAX_ANGULAR_SIZE) &&
(allowSmallModels || angularSize > MIN_ANGULAR_SIZE); (allowSmallModels || angularSize > MIN_ANGULAR_SIZE);
if (0 < x && sizeOK) { if (0 < x && sizeOK && selectionManager.editEnabled) {
selectedEntityID = foundEntity; selectedEntityID = foundEntity;
orientation = MyAvatar.orientation; orientation = MyAvatar.orientation;
intersection = rayPlaneIntersection(pickRay, P, Quat.getForward(orientation)); intersection = rayPlaneIntersection(pickRay, P, Quat.getForward(orientation));

View file

@ -24,7 +24,7 @@ EditTools = function(options) {
var voxelSphereSize = 0.3; var voxelSphereSize = 0.3;
var voxelEditDynamics = "click"; var voxelEditDynamics = "click";
var voxelRemove = false; var voxelRemove = false;
var voxelPointerMode = "single"; var voxelPointerMode = "laser";
var voxelBrushLength = 0.5; var voxelBrushLength = 0.5;
var listeners = []; var listeners = [];

View file

@ -19,6 +19,7 @@ Script.include([
]); ]);
EditVoxels = function() { EditVoxels = function() {
var self = this;
var that = {}; var that = {};
var controlHeld = false; var controlHeld = false;
@ -33,10 +34,15 @@ EditVoxels = function() {
var deletingCubes = false; var deletingCubes = false;
var continuousPaint = false; var continuousPaint = false;
var brushPointer = false; var brushPointer = false;
var isActive = true;
var editSphereRadius = 0.15; var editSphereRadius = 0.15;
var brushLength = 0.5; var brushLength = 0.5;
that.setActive = function(active) {
isActive = (active === true);
}
that.updateEditSettings = function(data) { that.updateEditSettings = function(data) {
if (data.createAppMode) { if (data.createAppMode) {
@ -114,7 +120,7 @@ EditVoxels = function() {
return false; return false;
} }
if (!editEnabled) { if (!editEnabled || !isActive) {
return false; return false;
} }
@ -224,7 +230,9 @@ EditVoxels = function() {
} }
function cleanup() { function cleanup() {
toolBar.cleanup(); Controller.mousePressEvent.disconnect(self.mousePressEvent);
Controller.keyPressEvent.disconnect(self.keyPressEvent);
Controller.keyReleaseEvent.disconnect(self.keyReleaseEvent);
} }
Controller.mousePressEvent.connect(mousePressEvent); Controller.mousePressEvent.connect(mousePressEvent);

View file

@ -187,6 +187,21 @@ SelectionManager = (function() {
that.pointingAtDesktopWindowRight = false; that.pointingAtDesktopWindowRight = false;
that.pointingAtTabletLeft = false; that.pointingAtTabletLeft = false;
that.pointingAtTabletRight = false; that.pointingAtTabletRight = false;
that.editEnabled = true;
that.updateEditSettings = function(data) {
if (data.createAppMode) {
if (data.createAppMode === "object"){
that.editEnabled = true;
} else {
that.editEnabled = false;
if(that.hasSelection()){
that.clearSelections();
}
}
}
}
that.saveProperties = function() { that.saveProperties = function() {
that.savedProperties = {}; that.savedProperties = {};
@ -1303,6 +1318,9 @@ SelectionDisplay = (function() {
} }
function makeClickHandler(hand) { function makeClickHandler(hand) {
return function (clicked) { return function (clicked) {
if (!SelectionManager.editEnabled) {
return;
}
// Don't allow both hands to trigger at the same time // Don't allow both hands to trigger at the same time
if (that.triggered() && hand !== that.triggeredHand) { if (that.triggered() && hand !== that.triggeredHand) {
return; return;
@ -1318,6 +1336,9 @@ SelectionDisplay = (function() {
} }
function makePressHandler(hand) { function makePressHandler(hand) {
return function (value) { return function (value) {
if (!SelectionManager.editEnabled) {
return;
}
if (value >= TRIGGER_ON_VALUE && !that.triggered() && !pointingAtDesktopWindowOrTablet(hand)) { if (value >= TRIGGER_ON_VALUE && !that.triggered() && !pointingAtDesktopWindowOrTablet(hand)) {
that.pressedHand = hand; that.pressedHand = hand;
that.updateHighlight({}); that.updateHighlight({});
@ -1413,6 +1434,9 @@ SelectionDisplay = (function() {
if (wantDebug) { if (wantDebug) {
print("=============== eST::MousePressEvent BEG ======================="); print("=============== eST::MousePressEvent BEG =======================");
} }
if (!SelectionManager.editEnabled) {
return;
}
if (!event.isLeftButton && !that.triggered()) { if (!event.isLeftButton && !that.triggered()) {
// EARLY EXIT-(if another mouse button than left is pressed ignore it) // EARLY EXIT-(if another mouse button than left is pressed ignore it)
return false; return false;