From 8e1f24cdc503aa6b81a7ebfb89ca2add939cc2ff Mon Sep 17 00:00:00 2001 From: kovacsv Date: Sun, 13 Jan 2019 12:23:01 +0100 Subject: [PATCH] Add isolate mesh functionality. --- website/include/importerapp.js | 68 +++++++++++++++++++++++++------ website/include/importermenu.js | 8 +++- website/include/importerviewer.js | 8 +--- 3 files changed, 63 insertions(+), 21 deletions(-) diff --git a/website/include/importerapp.js b/website/include/importerapp.js index 4e9b875..ff3b9a2 100644 --- a/website/include/importerapp.js +++ b/website/include/importerapp.js @@ -47,7 +47,7 @@ ImporterApp.prototype.Init = function () var myThis = this; var top = document.getElementById ('top'); this.importerButtons = new ImporterButtons (top); - this.importerButtons.AddLogo ('Online 3D Viewer v 0.6.1', function () { myThis.ShowAboutDialog (); }); + this.importerButtons.AddLogo ('Online 3D Viewer v 0.6.2', function () { myThis.ShowAboutDialog (); }); this.importerButtons.AddButton ('images/openfile.png', 'Open File', function () { myThis.OpenFile (); }); this.importerButtons.AddButton ('images/fitinwindow.png', 'Fit In Window', function () { myThis.FitInWindow (); }); this.importerButtons.AddToggleButton ('images/fixup.png', 'images/fixupgray.png', 'Enable/Disable Fixed Up Vector', function () { myThis.SetFixUp (); }); @@ -170,13 +170,6 @@ ImporterApp.prototype.Resize = function () ImporterApp.prototype.JsonLoaded = function (progressBar) { - var jsonData = this.viewer.GetJsonData (); - this.meshVisibility = {}; - var i; - for (i = 0; i < jsonData.meshes.length; i++) { - this.meshVisibility[i] = true; - } - this.Generate (progressBar); }; @@ -266,6 +259,7 @@ ImporterApp.prototype.GenerateMenu = function () }); } + var visibleImage = null; var meshMenuItem = meshesGroup.AddSubItem (mesh.name, { id : 'meshmenuitem-' + meshIndex.toString (), openCloseButton : { @@ -310,16 +304,21 @@ ImporterApp.prototype.GenerateMenu = function () title : 'Show/Hide Mesh', onCreate : function (image) { image.attr ('src', 'images/visible.png'); + visibleImage = image; }, onClick : function (image, meshIndex) { - var visible = importerApp.ShowHideMesh (meshIndex); - image.attr ('src', visible ? 'images/visible.png' : 'images/hidden.png'); + importerApp.ShowHideMesh (meshIndex); + }, + onCtrlClick : function (image, meshIndex) { + importerApp.IsolateMesh (meshIndex); }, userData : meshIndex } ] }); + meshMenuItem.isVisible = true; + meshMenuItem.visibleImage = visibleImage; return meshMenuItem; } @@ -468,9 +467,50 @@ ImporterApp.prototype.SetView = function (viewType) ImporterApp.prototype.ShowHideMesh = function (meshIndex) { - this.meshVisibility[meshIndex] = !this.meshVisibility[meshIndex]; - this.viewer.ShowMesh (meshIndex, this.meshVisibility[meshIndex]); - return this.meshVisibility[meshIndex]; + var meshMenuItem = this.meshMenuItems[meshIndex]; + this.ShowHideMeshInternal (meshIndex, !meshMenuItem.isVisible); + this.viewer.Draw (); +}; + +ImporterApp.prototype.IsolateMesh = function (meshIndex) +{ + var i, meshMenuItem; + + var onlyThisVisible = true; + if (!this.meshMenuItems[meshIndex].isVisible) { + onlyThisVisible = false; + } else { + for (i = 0; i < this.meshMenuItems.length; i++) { + meshMenuItem = this.meshMenuItems[i]; + if (meshMenuItem.isVisible && i !== meshIndex) { + onlyThisVisible = false; + break; + } + } + } + + var i; + for (i = 0; i < this.meshMenuItems.length; i++) { + if (onlyThisVisible) { + this.ShowHideMeshInternal (i, true); + } else { + if (i == meshIndex) { + this.ShowHideMeshInternal (i, true); + } else { + this.ShowHideMeshInternal (i, false); + } + } + } + + this.viewer.Draw (); +}; + +ImporterApp.prototype.ShowHideMeshInternal = function (meshIndex, isVisible) +{ + var meshMenuItem = this.meshMenuItems[meshIndex]; + meshMenuItem.isVisible = isVisible; + meshMenuItem.visibleImage.attr ('src', meshMenuItem.isVisible ? 'images/visible.png' : 'images/hidden.png'); + this.viewer.ShowMesh (meshIndex, meshMenuItem.isVisible); }; ImporterApp.prototype.ProcessFiles = function (fileList, isUrl) @@ -571,6 +611,8 @@ ImporterApp.prototype.HighlightMesh = function (meshIndex) } } } + + this.viewer.Draw (); }; ImporterApp.prototype.OnCanvasClick = function (x, y) diff --git a/website/include/importermenu.js b/website/include/importermenu.js index 4558cc2..6d6b29d 100644 --- a/website/include/importermenu.js +++ b/website/include/importermenu.js @@ -102,10 +102,14 @@ ImporterMenuItem.prototype.AddUserButton = function (userButton) if (IsSet (userButton.onCreate)) { userButton.onCreate (userImage, userButton.userData); } - if (IsSet (userButton.onClick)) { + if (IsSet (userButton.onClick) || IsSet (userButton.onCtrlClick)) { userImage.click (function (event) { event.stopPropagation (); - userButton.onClick (userImage, userButton.userData); + if (event.ctrlKey && IsSet (userButton.onCtrlClick)) { + userButton.onCtrlClick (userImage, userButton.userData); + } else if (IsSet (userButton.onClick)) { + userButton.onClick (userImage, userButton.userData); + } }); } }; diff --git a/website/include/importerviewer.js b/website/include/importerviewer.js index e7a7471..b0b6032 100644 --- a/website/include/importerviewer.js +++ b/website/include/importerviewer.js @@ -85,24 +85,21 @@ ImporterViewer.prototype.GetMeshesUnderPosition = function (x, y) ImporterViewer.prototype.ShowMesh = function (index, show) { - var myThis = this; this.viewer.scene.traverse (function (current) { if (current instanceof THREE.Mesh) { if (current.originalJsonIndex == index) { if (show) { - myThis.viewer.ShowMesh (current); + current.visible = true; } else { - myThis.viewer.HideMesh (current); + current.visible = false; } } } }); - this.viewer.Draw (); }; ImporterViewer.prototype.HighlightMesh = function (index, highlight) { - var myThis = this; this.viewer.scene.traverse (function (current) { if (current instanceof THREE.Mesh) { if (current.originalJsonIndex == index) { @@ -114,7 +111,6 @@ ImporterViewer.prototype.HighlightMesh = function (index, highlight) } } }); - this.viewer.Draw (); }; ImporterViewer.prototype.FitInWindow = function ()