From 0327d11c5a75dc3a3e23b762ff9814eb02b43748 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Tue, 17 May 2022 18:55:47 +0200 Subject: [PATCH] Initial JS files for Edit Tools --- scripts/system/create/edit.js | 9 +- scripts/system/create/editModes/editModes.js | 178 ++++++++++++++++++ scripts/system/create/qml/EditTabView.qml | 2 +- .../system/create/qml/EditToolsTabView.qml | 2 +- .../system/create/qml/NewPolyVoxDialog.qml | 36 ++-- scripts/system/html/gridControls.html | 49 +++++ scripts/system/html/js/gridControls.js | 57 ++++++ scripts/system/html/users.html | 2 +- scripts/system/libraries/gridTool.js | 14 +- 9 files changed, 325 insertions(+), 24 deletions(-) create mode 100644 scripts/system/create/editModes/editModes.js diff --git a/scripts/system/create/edit.js b/scripts/system/create/edit.js index e00d72bc6b..8d206f5586 100644 --- a/scripts/system/create/edit.js +++ b/scripts/system/create/edit.js @@ -12,7 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -/* global Script, SelectionDisplay, LightOverlayManager, CameraManager, Grid, GridTool, EntityListTool, Vec3, SelectionManager, +/* global Script, SelectionDisplay, LightOverlayManager, CameraManager, Grid, GridTool, EditTools, EntityListTool, Vec3, SelectionManager, Overlays, OverlayWebWindow, UserActivityLogger, Settings, Entities, Tablet, Toolbars, Messages, Menu, Camera, progressDialog, tooltip, MyAvatar, Quat, Controller, Clipboard, HMD, UndoStack, OverlaySystemWindow, keyUpEventFromUIWindow:true */ @@ -37,7 +37,8 @@ Script.include([ "entityList/entityList.js", "entitySelectionTool/entitySelectionTool.js", "audioFeedback/audioFeedback.js", - "modules/brokenURLReport.js" + "modules/brokenURLReport.js", + "editModes/editModes.js" ]); var CreateWindow = Script.require('./modules/createWindow.js'); @@ -127,6 +128,10 @@ var gridTool = new GridTool({ }); gridTool.setVisible(false); +var editTools = new EditTools({ + createToolsWindow: createToolsWindow, +}); + var entityShapeVisualizerSessionName = "SHAPE_VISUALIZER_" + Uuid.generate(); var EntityShapeVisualizer = Script.require('./modules/entityShapeVisualizer.js'); diff --git a/scripts/system/create/editModes/editModes.js b/scripts/system/create/editModes/editModes.js new file mode 100644 index 0000000000..d3a6b9d202 --- /dev/null +++ b/scripts/system/create/editModes/editModes.js @@ -0,0 +1,178 @@ +// +// editModes.js +// +// Created by Karol Suprynowicz on 2022.05.15. +// Copyright 2022 Overte e.V. +// +// Partially based on gridTool.js +// Created by Ryan Huffman on 6 Nov 2014 +// Copyright 2014 High Fidelity, Inc. +// Copyright 2020 Vircadia contributors. +// Copyright 2022 Overte e.V. +// +// This script implements a class for managing different edit modes +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +EditTools = function(options) { + var that = {}; + + var createAppMode = "object"; + var voxelEditMode = "single"; + var voxelSphereSize = 0.3; + var voxelEditDynamics = "click"; + var voxelRemove = false; + var voxelPointerMode = "single"; + var voxelBrushLength = 0.5; + var listeners = []; + + var createToolsWindow = options.createToolsWindow; + + that.emitUpdate = function() { + var dataString = JSON.stringify({ + createAppMode : createAppMode, + voxelEditMode : voxelEditMode, + voxelSphereSize : voxelSphereSize, + voxelEditDynamics : voxelEditDynamics, + voxelRemove : voxelRemove, + voxelPointerMode : voxelPointerMode, + voxelBrushLength : voxelBrushLength, + }); + webView.emitScriptEvent(dataString); + createToolsWindow.emitScriptEvent(dataString); + }; + + that.getCreateAppMode = function() { + return createAppMode; + } + + that.setCreateAppMode = function(value) { + createAppMode = value; + that.emitUpdate(); + } + + that.getVoxelEditMode = function() { + return voxelEditMode; + } + + that.setVoxelEditMode = function(value) { + voxelEditMode = value; + that.emitUpdate(); + } + + that.getVoxelSphereSize = function() { + return voxelSphereSize; + } + + that.setVoxelSphereSize = function(value) { + voxelSphereSize = value; + that.emitUpdate(); + } + + that.getVoxelEditDynamics = function() { + return voxelEditDynamics; + } + + that.setVoxelEditDynamics = function(value) { + voxelEditDynamics = value; + that.emitUpdate(); + } + + that.getVoxelRemove = function() { + return voxelRemove; + } + + that.setVoxelRemove = function(value) { + voxelRemove = value; + that.emitUpdate(); + } + + that.getVoxelPointerMode = function() { + return voxelPointerMode; + } + + that.setVoxelPointerMode = function(value) { + voxelPointerMode = value; + that.emitUpdate(); + } + + that.getVoxelBrushLength = function() { + return voxelBrushLength; + } + + that.setVoxelBrushLength = function(value) { + voxelBrushLength = value; + that.emitUpdate(); + } + + that.update = function(data) { + if (data.type !== "update-edit-tools") { + return; + } + + var needsUpdate = false; + + if (data.createAppMode) { + createAppMode = data.createAppMode; + needsUpdate = true; + } + if (data.voxelEditMode) { + voxelEditMode = data.voxelEditMode; + needsUpdate = true; + } + if (data.voxelSphereSize) { + voxelSphereSize = data.voxelSphereSize; + needsUpdate = true; + } + if (data.voxelEditDynamics) { + voxelEditDynamics = data.voxelEditDynamics; + needsUpdate = true; + } + if (data.voxelRemove) { + voxelRemove = data.voxelRemove; + needsUpdate = true; + } + if (data.voxelPointerMode) { + voxelPointerMode = data.voxelPointerMode; + needsUpdate = true; + } + if (data.voxelBrushLength) { + voxelBrushLength = data.voxelBrushLength; + needsUpdate = true; + } + } + + var webEventReceived = function(data) { + try { + data = JSON.parse(data); + } catch (e) { + return; + } + + if (data.type === "init") { + that.emitUpdate(); + } else if (data.type === "update-edit-tools") { + that.update(data); + for (var i = 0; i < listeners.length; i++) { + listeners[i] && listeners[i](data); + } + } + }; + + var webView = null; + webView = Tablet.getTablet("com.highfidelity.interface.tablet.system"); + + webView.webEventReceived.connect(webEventReceived); + createToolsWindow.webEventReceived.addListener(webEventReceived); + + that.addListener = function(callback) { + listeners.push(callback); + }; + + function cleanup() { + } + + return that; +} diff --git a/scripts/system/create/qml/EditTabView.qml b/scripts/system/create/qml/EditTabView.qml index b122370192..96e66c109e 100644 --- a/scripts/system/create/qml/EditTabView.qml +++ b/scripts/system/create/qml/EditTabView.qml @@ -286,7 +286,7 @@ TabBar { } EditTabButton { - title: "GRID" + title: "TOOLS" active: true enabled: true property string originalUrl: "" diff --git a/scripts/system/create/qml/EditToolsTabView.qml b/scripts/system/create/qml/EditToolsTabView.qml index bd4d47ddea..998c3a3aac 100644 --- a/scripts/system/create/qml/EditToolsTabView.qml +++ b/scripts/system/create/qml/EditToolsTabView.qml @@ -276,7 +276,7 @@ TabBar { } EditTabButton { - title: "GRID" + title: "TOOLS" active: true enabled: true property string originalUrl: "" diff --git a/scripts/system/create/qml/NewPolyVoxDialog.qml b/scripts/system/create/qml/NewPolyVoxDialog.qml index bbc9e7281a..fde7d075e0 100644 --- a/scripts/system/create/qml/NewPolyVoxDialog.qml +++ b/scripts/system/create/qml/NewPolyVoxDialog.qml @@ -74,39 +74,39 @@ Rectangle { switch (currentIndex) { // Clear texture entries case 0: - xTextureURL.text = "" - yTextureURL.text = "" - zTextureURL.text = "" + xTextureURL.text = ""; + yTextureURL.text = ""; + zTextureURL.text = ""; break; // Grass + ground case 1: - xTextureURL.text = "qrc:///serverless/Textures/ground_5-2K/2K-ground_5-diffuse.jpg" - yTextureURL.text = "qrc:///serverless/Textures/ground_grass_gen_05.png" - zTextureURL.text = "qrc:///serverless/Textures/ground_5-2K/2K-ground_5-diffuse.jpg" + xTextureURL.text = "qrc:///serverless/Textures/ground_5-2K/2K-ground_5-diffuse.jpg"; + yTextureURL.text = "qrc:///serverless/Textures/ground_grass_gen_05.png"; + zTextureURL.text = "qrc:///serverless/Textures/ground_5-2K/2K-ground_5-diffuse.jpg"; break; // Bricks case 2: - xTextureURL.text = "qrc:///serverless/Textures/2K-wall_stone_2-diffuse_l.jpg" - yTextureURL.text = "qrc:///serverless/Textures/2K-stone_floor_3-diffuse_l.jpg" - zTextureURL.text = "qrc:///serverless/Textures/2K-wall_stone_2-diffuse_l.jpg" + xTextureURL.text = "qrc:///serverless/Textures/2K-wall_stone_2-diffuse_l.jpg"; + yTextureURL.text = "qrc:///serverless/Textures/2K-stone_floor_3-diffuse_l.jpg"; + zTextureURL.text = "qrc:///serverless/Textures/2K-wall_stone_2-diffuse_l.jpg"; break; // Stone case 3: - xTextureURL.text = "qrc:///serverless/Textures/wall_l.png" - yTextureURL.text = "qrc:///serverless/Textures/floor_l.png" - zTextureURL.text = "qrc:///serverless/Textures/wall_l.png" + xTextureURL.text = "qrc:///serverless/Textures/wall_l.png"; + yTextureURL.text = "qrc:///serverless/Textures/floor_l.png"; + zTextureURL.text = "qrc:///serverless/Textures/wall_l.png"; break; // Concrete case 4: - xTextureURL.text = "qrc:///serverless/Textures/concrete_12-2K/2K-concrete_12-diffuse.jpg" - yTextureURL.text = "qrc:///serverless/Textures/concrete_12-2K/2K-concrete_12-diffuse.jpg" - zTextureURL.text = "qrc:///serverless/Textures/concrete_12-2K/2K-concrete_12-diffuse.jpg" + xTextureURL.text = "qrc:///serverless/Textures/concrete_12-2K/2K-concrete_12-diffuse.jpg"; + yTextureURL.text = "qrc:///serverless/Textures/concrete_12-2K/2K-concrete_12-diffuse.jpg"; + zTextureURL.text = "qrc:///serverless/Textures/concrete_12-2K/2K-concrete_12-diffuse.jpg"; break; // Rock case 5: - xTextureURL.text = "qrc:///serverless/Textures/Rock026_2K-JPG/Rock026_2K_Color.jpg" - yTextureURL.text = "qrc:///serverless/Textures/Rock026_2K-JPG/Rock026_2K_Color.jpg" - zTextureURL.text = "qrc:///serverless/Textures/Rock026_2K-JPG/Rock026_2K_Color.jpg" + xTextureURL.text = "qrc:///serverless/Textures/Rock026_2K-JPG/Rock026_2K_Color.jpg"; + yTextureURL.text = "qrc:///serverless/Textures/Rock026_2K-JPG/Rock026_2K_Color.jpg"; + zTextureURL.text = "qrc:///serverless/Textures/Rock026_2K-JPG/Rock026_2K_Color.jpg"; break; } } diff --git a/scripts/system/html/gridControls.html b/scripts/system/html/gridControls.html index 8d6ee34bc0..9c21fbdb0d 100644 --- a/scripts/system/html/gridControls.html +++ b/scripts/system/html/gridControls.html @@ -3,6 +3,7 @@ // // Created by Ryan Huffman on 6 Nov 2014 // Copyright 2014 High Fidelity, Inc. +// Copyright 2022 Overte e.V. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -20,7 +21,55 @@ +
+
+ + +
+
+
+

Voxel edit settings

+
+ + + +
+ +
+
+
+ + + +
+ + +
+
+
+ + + +
+ +
+
+
+

Grid settings

diff --git a/scripts/system/html/js/gridControls.js b/scripts/system/html/js/gridControls.js index e27dac522b..67b1d6bdae 100644 --- a/scripts/system/html/js/gridControls.js +++ b/scripts/system/html/js/gridControls.js @@ -2,12 +2,21 @@ // // Created by Ryan Huffman on 6 Nov 2014 // Copyright 2014 High Fidelity, Inc. +// Copyright 2022 Overte e.V. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html function loaded() { openEventBridge(function() { + elCreateAppMode = document.getElementById("create-app-mode"); + elVoxelEditMode = document.getElementById("voxel-edit-mode"); + elVoxelSphereSize = document.getElementById("voxel-sphere-size"); + elVoxelEditDynamics = document.getElementById("voxel-edit-dynamics"); + elVoxelRemove = document.getElementById("voxel-remove"); + elVoxelPointerMode = document.getElementById("voxel-pointer-mode"); + elVoxelBrushLength = document.getElementById("voxel-brush-length"); + elPosY = document.getElementById("horiz-y"); elMinorSpacing = document.getElementById("minor-spacing"); elMajorSpacing = document.getElementById("major-spacing"); @@ -20,6 +29,34 @@ function loaded() { EventBridge.scriptEventReceived.connect(function(data) { data = JSON.parse(data); + if (data.createAppMode !== undefined) { + elCreateAppMode.value = data.createAppMode; + } + + if (data.voxelEditMode !== undefined) { + elVoxelEditMode.value = data.voxelEditMode; + } + + if (data.voxelSphereSize !== undefined) { + elVoxelSphereSize.value = data.voxelSphereSize; + } + + if (data.voxelEditDynamics !== undefined) { + elVoxelEditDynamics.value = data.voxelEditDynamics; + } + + if (data.voxelRemove !== undefined) { + elVoxelRemove.checked = data.voxelRemove == true; + } + + if (data.voxelPointerMode !== undefined) { + elVoxelPointerMode.value = data.voxelPointerMode; + } + + if (data.voxelBrushLength !== undefined) { + elVoxelBrushLength.value = data.voxelBrushLength; + } + if (data.origin) { var origin = data.origin; elPosY.value = origin.y; @@ -60,8 +97,28 @@ function loaded() { })); } + function emitUpdateEditTools() { + EventBridge.emitWebEvent(JSON.stringify({ + type: "update-edit-tools", + createAppMode: elCreateAppMode.value, + voxelEditMode: elVoxelEditMode.value, + voxelSphereSize: elVoxelSphereSize.value, + voxelEditDynamics: elVoxelEditDynamics.value, + voxelRemove: elVoxelRemove.checked, + voxelPointerMode: elVoxelPointerMode.value, + voxelBrushLength: elVoxelBrushLength.value, + })); + } } + elCreateAppMode.addEventListener("change", emitUpdateEditTools); + elVoxelEditMode.addEventListener("change", emitUpdateEditTools); + elVoxelSphereSize.addEventListener("change", emitUpdateEditTools); + elVoxelEditDynamics.addEventListener("change", emitUpdateEditTools); + elVoxelRemove.addEventListener("change", emitUpdateEditTools); + elVoxelPointerMode.addEventListener("change", emitUpdateEditTools); + elVoxelBrushLength.addEventListener("change", emitUpdateEditTools); + elPosY.addEventListener("change", emitUpdate); elMinorSpacing.addEventListener("change", emitUpdate); elMajorSpacing.addEventListener("change", emitUpdate); diff --git a/scripts/system/html/users.html b/scripts/system/html/users.html index bf483484bc..005750d21f 100644 --- a/scripts/system/html/users.html +++ b/scripts/system/html/users.html @@ -508,4 +508,4 @@ }); - \ No newline at end of file + diff --git a/scripts/system/libraries/gridTool.js b/scripts/system/libraries/gridTool.js index 1dbe1fea4c..4674e5925d 100644 --- a/scripts/system/libraries/gridTool.js +++ b/scripts/system/libraries/gridTool.js @@ -3,6 +3,7 @@ // Created by Ryan Huffman on 6 Nov 2014 // Copyright 2014 High Fidelity, Inc. // Copyright 2020 Vircadia contributors. +// Copyright 2022 Overte e.V. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -196,8 +197,11 @@ Grid = function() { }; that.update = function(data) { + var gridNeedsUpdate = false; + if (data.snapToGrid !== undefined) { snapToGrid = data.snapToGrid; + var gridNeedsUpdate = true; } if (data.origin) { @@ -206,29 +210,37 @@ Grid = function() { pos.y = pos.y === undefined ? origin.y : parseFloat(pos.y); pos.z = pos.z === undefined ? origin.z : parseFloat(pos.z); that.setPosition(pos, true); + var gridNeedsUpdate = true; } if (data.minorGridEvery) { minorGridEvery = data.minorGridEvery; + var gridNeedsUpdate = true; } if (data.majorGridEvery) { majorGridEvery = data.majorGridEvery; + var gridNeedsUpdate = true; } if (data.gridColor) { gridColor = data.gridColor; + var gridNeedsUpdate = true; } if (data.gridSize) { halfSize = data.gridSize; + var gridNeedsUpdate = true; } if (data.visible !== undefined) { that.setVisible(data.visible, true); + var gridNeedsUpdate = true; } - updateGrid(true); + if (gridNeedsUpdate) { + updateGrid(true); + } }; function updateGrid(noUpdate) {