mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:18:12 +02:00
Collect grouping data
This commit is contained in:
parent
7e1584a43e
commit
c686cef4a0
3 changed files with 155 additions and 2 deletions
85
scripts/vr-edit/modules/groups.js
Normal file
85
scripts/vr-edit/modules/groups.js
Normal 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 = {};
|
|
@ -31,6 +31,7 @@ Selection = function (side) {
|
||||||
|
|
||||||
function traverseEntityTree(id, result) {
|
function traverseEntityTree(id, result) {
|
||||||
// Recursively traverses tree of entities and their children, gather IDs and properties.
|
// Recursively traverses tree of entities and their children, gather IDs and properties.
|
||||||
|
// The root entity is always the first entry.
|
||||||
var children,
|
var children,
|
||||||
properties,
|
properties,
|
||||||
SELECTION_PROPERTIES = ["position", "registrationPoint", "rotation", "dimensions", "parentID", "localPosition",
|
SELECTION_PROPERTIES = ["position", "registrationPoint", "rotation", "dimensions", "parentID", "localPosition",
|
||||||
|
|
|
@ -37,9 +37,12 @@
|
||||||
editors = [],
|
editors = [],
|
||||||
LEFT_HAND = 0,
|
LEFT_HAND = 0,
|
||||||
RIGHT_HAND = 1,
|
RIGHT_HAND = 1,
|
||||||
|
Grouping,
|
||||||
|
grouping,
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
CreatePalette,
|
CreatePalette,
|
||||||
|
Groups,
|
||||||
Hand,
|
Hand,
|
||||||
Handles,
|
Handles,
|
||||||
Highlights,
|
Highlights,
|
||||||
|
@ -61,6 +64,7 @@
|
||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
Script.include("./modules/createPalette.js");
|
Script.include("./modules/createPalette.js");
|
||||||
|
Script.include("./modules/groups.js");
|
||||||
Script.include("./modules/hand.js");
|
Script.include("./modules/hand.js");
|
||||||
Script.include("./modules/handles.js");
|
Script.include("./modules/handles.js");
|
||||||
Script.include("./modules/highlights.js");
|
Script.include("./modules/highlights.js");
|
||||||
|
@ -713,11 +717,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function enterEditorGrouping() {
|
function enterEditorGrouping() {
|
||||||
// TODO: Add/remove highlightedEntityID to/from groups.
|
highlights.display(intersection.handIntersected, selection.selection(), false);
|
||||||
|
grouping.toggle(selection.selection());
|
||||||
}
|
}
|
||||||
|
|
||||||
function exitEditorGrouping() {
|
function exitEditorGrouping() {
|
||||||
// Nothing to do.
|
highlights.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
STATE_MACHINE = {
|
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() {
|
function update() {
|
||||||
// Main update loop.
|
// Main update loop.
|
||||||
updateTimer = null;
|
updateTimer = null;
|
||||||
|
@ -1085,6 +1141,9 @@
|
||||||
editors[LEFT_HAND].apply();
|
editors[LEFT_HAND].apply();
|
||||||
editors[RIGHT_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);
|
updateTimer = Script.setTimeout(update, UPDATE_LOOP_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1203,6 +1262,9 @@
|
||||||
editors[LEFT_HAND].setReferences(inputs[LEFT_HAND], editors[RIGHT_HAND]);
|
editors[LEFT_HAND].setReferences(inputs[LEFT_HAND], editors[RIGHT_HAND]);
|
||||||
editors[RIGHT_HAND].setReferences(inputs[RIGHT_HAND], editors[LEFT_HAND]);
|
editors[RIGHT_HAND].setReferences(inputs[RIGHT_HAND], editors[LEFT_HAND]);
|
||||||
|
|
||||||
|
// Grouping object.
|
||||||
|
grouping = new Grouping();
|
||||||
|
|
||||||
// Settings changes.
|
// Settings changes.
|
||||||
MyAvatar.dominantHandChanged.connect(onDominantHandChanged);
|
MyAvatar.dominantHandChanged.connect(onDominantHandChanged);
|
||||||
|
|
||||||
|
@ -1230,6 +1292,11 @@
|
||||||
button = null;
|
button = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (grouping) {
|
||||||
|
grouping.destroy();
|
||||||
|
grouping = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (editors[LEFT_HAND]) {
|
if (editors[LEFT_HAND]) {
|
||||||
editors[LEFT_HAND].destroy();
|
editors[LEFT_HAND].destroy();
|
||||||
editors[LEFT_HAND] = null;
|
editors[LEFT_HAND] = null;
|
||||||
|
|
Loading…
Reference in a new issue