Merge pull request #191 from overte-org/fix/create_app_intersections

Fixed create app entity intersections in VR, increased default voxel resolution
This commit is contained in:
ksuprynowicz 2022-09-18 22:16:11 +02:00 committed by GitHub
commit a89ddf2d26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 17 deletions

View file

@ -22,8 +22,8 @@
// //
Script.include([ Script.include([
"./libraries/utils.js", "../../libraries/utils.js",
"entitySelectionTool/entitySelectionTool.js" "../entitySelectionTool/entitySelectionTool.js"
]); ]);
var selectionManager = SelectionManager; var selectionManager = SelectionManager;
@ -337,6 +337,7 @@ EditVoxels = function() {
var pickRay = generalComputePickRay(event.x, event.y); var pickRay = generalComputePickRay(event.x, event.y);
var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking var intersection = Entities.findRayIntersection(pickRay, true); // accurate picking
var overlaysIntersection = Overlays.findRayIntersection(pickRay, true); // accurate picking
if (wantDebug) { if (wantDebug) {
print("Pick ray: " + JSON.stringify(pickRay)); print("Pick ray: " + JSON.stringify(pickRay));
@ -344,6 +345,17 @@ EditVoxels = function() {
} }
if (intersection.intersects) { if (intersection.intersects) {
if (overlaysIntersection.intersects) {
var overlaysIntersectionDistance = Vec3.distance(overlaysIntersection.intersection, pickRay.origin);
var intersectionDistance = Vec3.distance(intersection.intersection, pickRay.origin);
if (wantDebug) {
print("overlaysIntersectionDistance: " + overlaysIntersectionDistance);
print("intersectionDistance: " + intersectionDistance);
}
if (overlaysIntersectionDistance < intersectionDistance) {
return;
}
}
if (attemptVoxelChangeForEntity(intersection.entityID, pickRay.direction, intersection.intersection)) { if (attemptVoxelChangeForEntity(intersection.entityID, pickRay.direction, intersection.intersection)) {
Script.update.connect(onUpdateHandler); Script.update.connect(onUpdateHandler);
isOnUpdateConnected = true; isOnUpdateConnected = true;
@ -409,16 +421,6 @@ EditVoxels = function() {
return that.triggeredHand !== NO_HAND; return that.triggeredHand !== NO_HAND;
}; };
function pointingAtDesktopWindowOrTablet(hand) {
var pointingAtDesktopWindow = (hand === Controller.Standard.RightHand &&
SelectionManager.pointingAtDesktopWindowRight) ||
(hand === Controller.Standard.LeftHand &&
SelectionManager.pointingAtDesktopWindowLeft);
var pointingAtTablet = (hand === Controller.Standard.RightHand && SelectionManager.pointingAtTabletRight) ||
(hand === Controller.Standard.LeftHand && SelectionManager.pointingAtTabletLeft);
return pointingAtDesktopWindow || pointingAtTablet;
}
function makeClickHandler(hand) { function makeClickHandler(hand) {
return function (clicked) { return function (clicked) {
if (!editEnabled) { if (!editEnabled) {
@ -428,7 +430,7 @@ EditVoxels = function() {
if (triggered() && hand !== that.triggeredHand) { if (triggered() && hand !== that.triggeredHand) {
return; return;
} }
if (!triggered() && clicked && !pointingAtDesktopWindowOrTablet(hand)) { if (!triggered() && clicked) {
that.triggeredHand = hand; that.triggeredHand = hand;
mousePressEvent({}); mousePressEvent({});
} else if (triggered() && !clicked) { } else if (triggered() && !clicked) {
@ -443,7 +445,7 @@ EditVoxels = function() {
if (!editEnabled) { if (!editEnabled) {
return; return;
} }
if (value >= TRIGGER_ON_VALUE && !triggered() && !pointingAtDesktopWindowOrTablet(hand)) { if (value >= TRIGGER_ON_VALUE && !triggered()) {
that.pressedHand = hand; that.pressedHand = hand;
} else { } else {
that.pressedHand = NO_HAND; that.pressedHand = NO_HAND;

View file

@ -130,6 +130,11 @@ SelectionManager = (function() {
audioFeedback.action(); audioFeedback.action();
} }
} else { } else {
var pickRay = SelectionDisplay.controllerComputePickRay();
var intersectObj = SelectionDisplay.testRayIntersect(pickRay, SelectionDisplay.allToolEntities);
if (intersectObj.intersects) {
return;
}
if (hmdMultiSelectMode) { if (hmdMultiSelectMode) {
that.addEntity(messageParsed.entityID, true, that); that.addEntity(messageParsed.entityID, true, that);
} else { } else {
@ -1253,6 +1258,8 @@ SelectionDisplay = (function() {
zRailToolEntity zRailToolEntity
]; ];
that.allToolEntities = allToolEntities;
const nonLayeredToolEntities = [selectionBox, iconSelectionBox]; const nonLayeredToolEntities = [selectionBox, iconSelectionBox];
var maximumHandleInAllToolEntities = handleDuplicator; var maximumHandleInAllToolEntities = handleDuplicator;
@ -1419,6 +1426,8 @@ SelectionDisplay = (function() {
return intersectObj; return intersectObj;
} }
that.testRayIntersect = testRayIntersect;
function isPointInsideBox(point, box) { function isPointInsideBox(point, box) {
var position = Vec3.subtract(point, box.position); var position = Vec3.subtract(point, box.position);
position = Vec3.multiplyQbyV(Quat.inverse(box.rotation), position); position = Vec3.multiplyQbyV(Quat.inverse(box.rotation), position);
@ -1784,6 +1793,8 @@ SelectionDisplay = (function() {
} }
} }
that.controllerComputePickRay = controllerComputePickRay;
function generalComputePickRay(x, y) { function generalComputePickRay(x, y) {
return controllerComputePickRay() || Camera.computePickRay(x, y); return controllerComputePickRay() || Camera.computePickRay(x, y);
} }

View file

@ -302,7 +302,7 @@ Rectangle {
width: 50 width: 50
anchors.left: textVolumeSizeX.right anchors.left: textVolumeSizeX.right
anchors.leftMargin: 3 anchors.leftMargin: 3
text: qsTr("16") text: qsTr("20")
color: "white" color: "white"
font.pixelSize: 12 font.pixelSize: 12
validator: IntValidator{bottom: 8; top: 64;} validator: IntValidator{bottom: 8; top: 64;}
@ -344,7 +344,7 @@ Rectangle {
width: 50 width: 50
anchors.left: textVolumeSizeY.right anchors.left: textVolumeSizeY.right
anchors.leftMargin: 3 anchors.leftMargin: 3
text: qsTr("16") text: qsTr("20")
color: "white" color: "white"
font.pixelSize: 12 font.pixelSize: 12
validator: IntValidator{bottom: 8; top: 64;} validator: IntValidator{bottom: 8; top: 64;}
@ -385,7 +385,7 @@ Rectangle {
width: 50 width: 50
anchors.left: textVolumeSizeZ.right anchors.left: textVolumeSizeZ.right
anchors.leftMargin: 3 anchors.leftMargin: 3
text: qsTr("16") text: qsTr("20")
color: "white" color: "white"
font.pixelSize: 12 font.pixelSize: 12
validator: IntValidator{bottom: 8; top: 64;} validator: IntValidator{bottom: 8; top: 64;}