From ceba5769e0e7c001620181ad170a4938f3919ebe Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 4 Aug 2017 18:07:42 +1200 Subject: [PATCH] Apply color to entities when click them --- scripts/vr-edit/modules/selection.js | 10 ++++++++++ scripts/vr-edit/vr-edit.js | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/vr-edit/modules/selection.js b/scripts/vr-edit/modules/selection.js index 89e5221f81..7234553a9d 100644 --- a/scripts/vr-edit/modules/selection.js +++ b/scripts/vr-edit/modules/selection.js @@ -327,6 +327,15 @@ Selection = function (side) { rootEntityID = selection[0].id; } + function applyColor(color) { + // Entities without a color property simply ignore the edit. + for (i = 0, length = selection.length; i < length; i += 1) { + Entities.editEntity(selection[i].id, { + color: color + }); + } + } + function clear() { selection = []; selectedEntityID = null; @@ -361,6 +370,7 @@ Selection = function (side) { finishHandleScaling: finishHandleScaling, finishEditing: finishEditing, cloneEntities: cloneEntities, + applyColor: applyColor, deleteEntities: deleteEntities, clear: clear, destroy: destroy diff --git a/scripts/vr-edit/vr-edit.js b/scripts/vr-edit/vr-edit.js index 7af8be3fb6..72232d6101 100644 --- a/scripts/vr-edit/vr-edit.js +++ b/scripts/vr-edit/vr-edit.js @@ -29,6 +29,7 @@ TOOL_COLOR = 4, TOOL_DELETE = 5, toolSelected = TOOL_NONE, + colorToolColor = { red: 128, green: 128, blue: 128 }, // Primary objects Inputs, @@ -854,8 +855,7 @@ } else if (toolSelected === TOOL_GROUP) { setState(EDITOR_GROUPING); } else if (toolSelected === TOOL_COLOR) { - // TODO - print("$$$$$$$ apply color"); + selection.applyColor(colorToolColor); } else if (toolSelected === TOOL_DELETE) { setState(EDITOR_HIGHLIGHTING); selection.deleteEntities(); @@ -912,8 +912,7 @@ } else if (toolSelected === TOOL_GROUP) { setState(EDITOR_GROUPING); } else if (toolSelected === TOOL_COLOR) { - // TODO - print("$$$$$$$ apply color"); + selection.applyColor(colorToolColor); } else if (toolSelected === TOOL_DELETE) { selection.deleteEntities(); setState(EDITOR_SEARCHING); @@ -1278,6 +1277,7 @@ break; case "setColor": ui.setToolColor(parameter); + colorToolColor = parameter; break; default: debug("ERROR: Unexpected command in onUICommand()!");