Display bounding box of currently selected groups

This commit is contained in:
David Rowe 2017-09-24 12:06:04 +13:00
parent 959d497079
commit 2afc84cf0b
4 changed files with 107 additions and 22 deletions

View file

@ -71,6 +71,10 @@ Groups = function () {
return rootEntityIDs.indexOf(rootEntityID) !== -1; return rootEntityIDs.indexOf(rootEntityID) !== -1;
} }
function getRootEntityIDs() {
return rootEntityIDs;
}
function groupsCount() { function groupsCount() {
return selections.length; return selections.length;
} }
@ -264,6 +268,7 @@ Groups = function () {
toggle: toggle, toggle: toggle,
selection: selection, selection: selection,
includes: includes, includes: includes,
rootEntityIDs: getRootEntityIDs,
groupsCount: groupsCount, groupsCount: groupsCount,
entitiesCount: entitiesCount, entitiesCount: entitiesCount,
group: group, group: group,

View file

@ -17,11 +17,14 @@ Highlights = function (side) {
var handOverlay, var handOverlay,
entityOverlays = [], entityOverlays = [],
boundingBoxOverlay,
isDisplayingBoundingBox = false,
HIGHLIGHT_COLOR = { red: 240, green: 240, blue: 0 }, HIGHLIGHT_COLOR = { red: 240, green: 240, blue: 0 },
SCALE_COLOR = { red: 0, green: 240, blue: 240 }, SCALE_COLOR = { red: 0, green: 240, blue: 240 },
GROUP_COLOR = { red: 220, green: 60, blue: 220 }, GROUP_COLOR = { red: 220, green: 60, blue: 220 },
HAND_HIGHLIGHT_ALPHA = 0.35, HAND_HIGHLIGHT_ALPHA = 0.35,
ENTITY_HIGHLIGHT_ALPHA = 0.8, ENTITY_HIGHLIGHT_ALPHA = 0.8,
BOUNDING_BOX_ALPHA = 0.8,
HAND_HIGHLIGHT_OFFSET = { x: 0.0, y: 0.11, z: 0.02 }, HAND_HIGHLIGHT_OFFSET = { x: 0.0, y: 0.11, z: 0.02 },
LEFT_HAND = 0; LEFT_HAND = 0;
@ -43,6 +46,14 @@ Highlights = function (side) {
visible: false visible: false
}); });
boundingBoxOverlay = Overlays.addOverlay("cube", {
alpha: BOUNDING_BOX_ALPHA,
solid: false,
drawInFront: true,
ignoreRayIntersection: true,
visible: false
});
function setHandHighlightRadius(radius) { function setHandHighlightRadius(radius) {
var dimension = 2 * radius; var dimension = 2 * radius;
Overlays.editOverlay(handOverlay, { Overlays.editOverlay(handOverlay, {
@ -75,7 +86,7 @@ Highlights = function (side) {
}); });
} }
function display(handIntersected, selection, entityIndex, overlayColor) { function display(handIntersected, selection, entityIndex, boundingBox, overlayColor) {
// Displays highlight for just entityIndex if non-null, otherwise highlights whole selection. // Displays highlight for just entityIndex if non-null, otherwise highlights whole selection.
var i, var i,
length; length;
@ -86,7 +97,8 @@ Highlights = function (side) {
visible: handIntersected visible: handIntersected
}); });
if (entityIndex !== null) { // Display entity overlays.
if (entityIndex !== null) {
// Add/edit entity overlay for just entityIndex. // Add/edit entity overlay for just entityIndex.
maybeAddEntityOverlay(0); maybeAddEntityOverlay(0);
editEntityOverlay(0, selection[entityIndex], overlayColor); editEntityOverlay(0, selection[entityIndex], overlayColor);
@ -103,14 +115,30 @@ Highlights = function (side) {
Overlays.deleteOverlay(entityOverlays[i]); Overlays.deleteOverlay(entityOverlays[i]);
entityOverlays.splice(i, 1); entityOverlays.splice(i, 1);
} }
// Update bounding box overlay.
if (boundingBox !== null) {
Overlays.editOverlay(boundingBoxOverlay, {
position: boundingBox.center,
rotation: boundingBox.orientation,
dimensions: boundingBox.dimensions,
color: overlayColor,
visible: true
});
isDisplayingBoundingBox = true;
} else if (isDisplayingBoundingBox) {
Overlays.editOverlay(boundingBoxOverlay, { visible: false });
isDisplayingBoundingBox = false;
}
} }
function clear() { function clear() {
var i, var i,
length; length;
// Hide hand overlay. // Hide hand and bounding box overlays.
Overlays.editOverlay(handOverlay, { visible: false }); Overlays.editOverlay(handOverlay, { visible: false });
Overlays.editOverlay(boundingBoxOverlay, { visible: false });
// Delete entity overlays. // Delete entity overlays.
for (i = 0, length = entityOverlays.length; i < length; i += 1) { for (i = 0, length = entityOverlays.length; i < length; i += 1) {
@ -122,6 +150,7 @@ Highlights = function (side) {
function destroy() { function destroy() {
clear(); clear();
Overlays.deleteOverlay(handOverlay); Overlays.deleteOverlay(handOverlay);
Overlays.deleteOverlay(boundingBoxOverlay);
} }
return { return {

View file

@ -99,6 +99,12 @@ SelectionManager = function (side) {
traverseEntityTree(rootEntityID, selection, selectionProperties); traverseEntityTree(rootEntityID, selection, selectionProperties);
} }
function append(rootEntityID) {
// Add further entities to the selection.
// Assumes that rootEntityID is not already in the selection.
traverseEntityTree(rootEntityID, selection, selectionProperties);
}
function getIntersectedEntityID() { function getIntersectedEntityID() {
return intersectedEntityID; return intersectedEntityID;
} }
@ -754,6 +760,7 @@ SelectionManager = function (side) {
return { return {
select: select, select: select,
append: append,
selection: getSelection, selection: getSelection,
count: count, count: count,
intersectedEntityID: getIntersectedEntityID, intersectedEntityID: getIntersectedEntityID,

View file

@ -690,6 +690,7 @@
if (toolSelected !== TOOL_SCALE || !otherEditor.isEditing(rootEntityID)) { if (toolSelected !== TOOL_SCALE || !otherEditor.isEditing(rootEntityID)) {
highlights.display(intersection.handIntersected, selection.selection(), highlights.display(intersection.handIntersected, selection.selection(),
toolSelected === TOOL_COLOR || toolSelected === TOOL_PICK_COLOR ? selection.intersectedEntityIndex() : null, toolSelected === TOOL_COLOR || toolSelected === TOOL_PICK_COLOR ? selection.intersectedEntityIndex() : null,
null,
toolSelected === TOOL_SCALE || otherEditor.isEditing(rootEntityID) toolSelected === TOOL_SCALE || otherEditor.isEditing(rootEntityID)
? highlights.SCALE_COLOR : highlights.HIGHLIGHT_COLOR); ? highlights.SCALE_COLOR : highlights.HIGHLIGHT_COLOR);
} }
@ -702,6 +703,7 @@
if (toolSelected !== TOOL_SCALE || !otherEditor.isEditing(rootEntityID)) { if (toolSelected !== TOOL_SCALE || !otherEditor.isEditing(rootEntityID)) {
highlights.display(intersection.handIntersected, selection.selection(), highlights.display(intersection.handIntersected, selection.selection(),
toolSelected === TOOL_COLOR || toolSelected === TOOL_PICK_COLOR ? selection.intersectedEntityIndex() : null, toolSelected === TOOL_COLOR || toolSelected === TOOL_PICK_COLOR ? selection.intersectedEntityIndex() : null,
null,
toolSelected === TOOL_SCALE || otherEditor.isEditing(rootEntityID) toolSelected === TOOL_SCALE || otherEditor.isEditing(rootEntityID)
? highlights.SCALE_COLOR : highlights.HIGHLIGHT_COLOR); ? highlights.SCALE_COLOR : highlights.HIGHLIGHT_COLOR);
if (!intersection.laserIntersected && !isUIVisible) { if (!intersection.laserIntersected && !isUIVisible) {
@ -815,12 +817,13 @@
function enterEditorGrouping() { function enterEditorGrouping() {
if (!grouping.includes(rootEntityID)) { if (!grouping.includes(rootEntityID)) {
highlights.display(false, selection.selection(), null, highlights.GROUP_COLOR); highlights.display(false, selection.selection(), null, null, highlights.GROUP_COLOR);
} }
if (toolSelected === TOOL_GROUP_BOX) { if (toolSelected === TOOL_GROUP_BOX) {
if (!grouping.includes(rootEntityID)) { if (!grouping.includes(rootEntityID)) {
Feedback.play(side, Feedback.SELECT_ENTITY); Feedback.play(side, Feedback.SELECT_ENTITY);
grouping.selectInBox(selection.selection()); grouping.toggle(selection.selection());
grouping.selectInBox();
} else { } else {
Feedback.play(side, Feedback.GENERAL_ERROR); Feedback.play(side, Feedback.GENERAL_ERROR);
} }
@ -1281,13 +1284,14 @@
// Grouping highlights and functions. // Grouping highlights and functions.
var groups, var groups,
isSelectInBox = false,
highlights, highlights,
exludedLeftRootEntityID = null, exludedLeftRootEntityID = null,
exludedrightRootEntityID = null, exludedrightRootEntityID = null,
excludedRootEntityIDs = [], excludedRootEntityIDs = [],
hasHighlights = false, hasHighlights = false,
hasSelectionChanged = false; hasSelectionChanged = false,
isSelectInBox = false,
selectInBoxSelection = null; // Selection of all groups combined in order to calculate bounding box.
if (!this instanceof Grouping) { if (!this instanceof Grouping) {
return new Grouping(); return new Grouping();
@ -1298,6 +1302,14 @@
function toggle(selection) { function toggle(selection) {
groups.toggle(selection); groups.toggle(selection);
if (isSelectInBox) {
// When selecting in a box, toggle() is only called to add entities to the selection.
if (selectInBoxSelection.count() === 0) {
selectInBoxSelection.select(selection[0].id);
} else {
selectInBoxSelection.append(selection[0].id);
}
}
if (groups.groupsCount() === 0) { if (groups.groupsCount() === 0) {
hasHighlights = false; hasHighlights = false;
highlights.clear(); highlights.clear();
@ -1307,31 +1319,54 @@
} }
} }
function updateSelectInBox() { function selectInBox() {
// TODO: Calculate bounding box. // Add any entities or groups of entities wholly within bounding box of current selection.
// Must be wholly within otherwise selection could grow uncontrollably.
var boundingBox;
// TODO: Select further entities per bounding box. if (selectInBoxSelection.count() > 1) {
boundingBox = selectInBoxSelection.boundingBox();
// TODO: Update bounding box overlay. // TODO: Select further entities per bounding box.
hasSelectionChanged = true;
}
} }
function startSelectInBox() { function startSelectInBox() {
// Start automatically selecting entities in bounding box of current selection.
var rootEntityIDs,
i,
length;
isSelectInBox = true; isSelectInBox = true;
// TODO: Create bounding box overlay. // Select entities current groups combined.
selectInBoxSelection = new SelectionManager();
rootEntityIDs = groups.rootEntityIDs();
if (rootEntityIDs.length > 0) {
selectInBoxSelection.select(rootEntityIDs[0]);
for (i = 1, length = rootEntityIDs.length; i < length; i += 1) {
selectInBoxSelection.append(rootEntityIDs[i]);
}
}
updateSelectInBox(); // Add any enclosed entities.
} selectInBox();
function selectInBox(selection) { // Show bounding box overlay plus any newly selected entities.
toggle(selection); hasSelectionChanged = true;
updateSelectInBox();
} }
function stopSelectInBox() { function stopSelectInBox() {
isSelectInBox = false; // Stop automatically selecting entities within bounding box of current selection.
selectInBoxSelection.destroy();
selectInBoxSelection = null;
// TODO: Delete bounding box overlay. // Hide bounding box overlay.
hasSelectionChanged = true;
isSelectInBox = false;
} }
function includes(rootEntityID) { function includes(rootEntityID) {
@ -1355,7 +1390,9 @@
} }
function update(leftRootEntityID, rightRootEntityID) { function update(leftRootEntityID, rightRootEntityID) {
var hasExludedRootEntitiesChanged; // Update highlights displayed, excluding entities highlighted by left or right hands.
var hasExludedRootEntitiesChanged,
boundingBox;
hasExludedRootEntitiesChanged = leftRootEntityID !== exludedLeftRootEntityID hasExludedRootEntitiesChanged = leftRootEntityID !== exludedLeftRootEntityID
|| rightRootEntityID !== exludedrightRootEntityID; || rightRootEntityID !== exludedrightRootEntityID;
@ -1376,12 +1413,15 @@
exludedrightRootEntityID = rightRootEntityID; exludedrightRootEntityID = rightRootEntityID;
} }
highlights.display(false, groups.selection(excludedRootEntityIDs), null, highlights.GROUP_COLOR); boundingBox = isSelectInBox && selectInBoxSelection.count() > 1 ? selectInBoxSelection.boundingBox() : null;
highlights.display(false, groups.selection(excludedRootEntityIDs), null, boundingBox, highlights.GROUP_COLOR);
hasSelectionChanged = false; hasSelectionChanged = false;
} }
function clear() { function clear() {
if (isSelectInBox) {
stopSelectInBox();
}
groups.clear(); groups.clear();
highlights.clear(); highlights.clear();
} }
@ -1395,6 +1435,10 @@
highlights.destroy(); highlights.destroy();
highlights = null; highlights = null;
} }
if (selectInBoxSelection) {
selectInBoxSelection.destroy();
selectInBoxSelection = null;
}
} }
return { return {