Collect grouping data

This commit is contained in:
David Rowe 2017-08-02 13:15:53 +12:00
parent 7e1584a43e
commit c686cef4a0
3 changed files with 155 additions and 2 deletions

View file

@ -0,0 +1,85 @@
//
// groups.js
//
// Created by David Rowe on 1 Aug 2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/* global Groups */
Groups = function () {
// Groups and ungroups trees of entities.
"use strict";
var groupRootEntityIDs = [],
groupSelectionDetails = [];
if (!this instanceof Groups) {
return new Groups();
}
function add(selection) {
groupRootEntityIDs.push(selection[0].id);
groupSelectionDetails.push(Object.clone(selection));
}
function remove(selection) {
var index = groupRootEntityIDs.indexOf(selection[0].id);
groupRootEntityIDs.splice(index, 1);
groupSelectionDetails.splice(index, 1);
}
function toggle(selection) {
if (selection.length === 0) {
return;
}
if (groupRootEntityIDs.indexOf(selection[0].id) === -1) {
add(selection);
} else {
remove(selection);
}
}
function getGroups() {
return groupSelectionDetails;
}
function count() {
return groupSelectionDetails.length;
}
function group() {
// TODO
}
function ungroup() {
// TODO
}
function clear() {
groupRootEntityIDs = [];
groupSelectionDetails = [];
}
function destroy() {
clear();
}
return {
toggle: toggle,
groups: getGroups,
count: count,
group: group,
ungroup: ungroup,
clear: clear,
destroy: destroy
};
};
Groups.prototype = {};

View file

@ -31,6 +31,7 @@ Selection = function (side) {
function traverseEntityTree(id, result) {
// Recursively traverses tree of entities and their children, gather IDs and properties.
// The root entity is always the first entry.
var children,
properties,
SELECTION_PROPERTIES = ["position", "registrationPoint", "rotation", "dimensions", "parentID", "localPosition",

View file

@ -37,9 +37,12 @@
editors = [],
LEFT_HAND = 0,
RIGHT_HAND = 1,
Grouping,
grouping,
// Modules
CreatePalette,
Groups,
Hand,
Handles,
Highlights,
@ -61,6 +64,7 @@
// Modules
Script.include("./modules/createPalette.js");
Script.include("./modules/groups.js");
Script.include("./modules/hand.js");
Script.include("./modules/handles.js");
Script.include("./modules/highlights.js");
@ -713,11 +717,12 @@
}
function enterEditorGrouping() {
// TODO: Add/remove highlightedEntityID to/from groups.
highlights.display(intersection.handIntersected, selection.selection(), false);
grouping.toggle(selection.selection());
}
function exitEditorGrouping() {
// Nothing to do.
highlights.clear();
}
STATE_MACHINE = {
@ -1068,6 +1073,57 @@
};
Grouping = function () {
// Grouping highlights and functions.
var groups;
if (!this instanceof Grouping) {
return new Grouping();
}
groups = new Groups();
function toggle(selection) {
groups.toggle(selection);
}
function count() {
return groups.count();
}
function group() {
groups.group();
}
function ungroup() {
groups.ungroup();
}
function update(leftRootEntityID, rightRootEntityID) {
// TODO: Update grouping highlights.
}
function clear() {
groups.clear();
}
function destroy() {
groups.destroy();
}
return {
toggle: toggle,
count: count,
group: group,
ungroup: ungroup,
update: update,
clear: clear,
destroy: destroy
};
};
function update() {
// Main update loop.
updateTimer = null;
@ -1085,6 +1141,9 @@
editors[LEFT_HAND].apply();
editors[RIGHT_HAND].apply();
// Grouping display.
grouping.update(editors[LEFT_HAND].rootEntityID(), editors[RIGHT_HAND].rootEntityID());
updateTimer = Script.setTimeout(update, UPDATE_LOOP_TIMEOUT);
}
@ -1203,6 +1262,9 @@
editors[LEFT_HAND].setReferences(inputs[LEFT_HAND], editors[RIGHT_HAND]);
editors[RIGHT_HAND].setReferences(inputs[RIGHT_HAND], editors[LEFT_HAND]);
// Grouping object.
grouping = new Grouping();
// Settings changes.
MyAvatar.dominantHandChanged.connect(onDominantHandChanged);
@ -1230,6 +1292,11 @@
button = null;
}
if (grouping) {
grouping.destroy();
grouping = null;
}
if (editors[LEFT_HAND]) {
editors[LEFT_HAND].destroy();
editors[LEFT_HAND] = null;