diff --git a/website/include/importerapp.js b/website/include/importerapp.js index ef2982c..1780015 100644 --- a/website/include/importerapp.js +++ b/website/include/importerapp.js @@ -49,7 +49,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.3', function () { myThis.ShowAboutDialog (); }); + this.importerButtons.AddLogo ('Online 3D Viewer v 0.6.4', 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 (); }); @@ -221,11 +221,15 @@ ImporterApp.prototype.GenerateMenu = function () title : 'Show/Hide Information', onOpen : function (contentDiv, material) { contentDiv.empty (); - var materialbuttons = $('
').addClass ('submenubuttons').appendTo (contentDiv); - var highlightButton = $('').addClass ('submenubutton').attr ('src', 'images/highlightmesh.png').attr ('title', 'Highlight Meshes With Material').appendTo (materialbuttons); + var materialButtons = $('
').addClass ('submenubuttons').appendTo (contentDiv); + var highlightButton = $('').addClass ('submenubutton').attr ('src', 'images/highlightmesh.png').attr ('title', 'Highlight Meshes By Material').appendTo (materialButtons); highlightButton.click (function () { importerApp.HighlightMeshesByMaterial (materialIndex); }); + var fitInWindowButton = $('').addClass ('submenubutton').attr ('src', 'images/fitinwindowsmall.png').attr ('title', 'Fit Meshes In Window By Material').appendTo (materialButtons); + fitInWindowButton.click (function () { + importerApp.FitMeshesByMaterialInWindow (materialIndex); + }); var table = new InfoTable (contentDiv); table.AddColorRow ('Ambient', material.ambient); table.AddColorRow ('Diffuse', material.diffuse); @@ -463,6 +467,15 @@ ImporterApp.prototype.FitMeshInWindow = function (meshIndex) this.viewer.FitMeshInWindow (meshIndex); }; +ImporterApp.prototype.FitMeshesByMaterialInWindow = function (materialIndex) +{ + var meshIndices = this.viewer.GetMeshesByMaterial (materialIndex); + if (meshIndices.length === 0) { + return; + } + this.viewer.FitMeshesInWindow (meshIndices); +}; + ImporterApp.prototype.SetFixUp = function () { this.viewer.SetFixUp (); diff --git a/website/include/importerviewer.js b/website/include/importerviewer.js index e67c1c9..bd04aa0 100644 --- a/website/include/importerviewer.js +++ b/website/include/importerviewer.js @@ -146,6 +146,19 @@ ImporterViewer.prototype.FitMeshInWindow = function (index) this.viewer.FitMeshesInWindow (meshes); }; +ImporterViewer.prototype.FitMeshesInWindow = function (meshIndices) +{ + var meshes = []; + this.viewer.scene.traverse (function (current) { + if (current instanceof THREE.Mesh) { + if (meshIndices.indexOf (current.originalJsonMeshIndex) != -1) { + meshes.push (current); + } + } + }); + this.viewer.FitMeshesInWindow (meshes); +}; + ImporterViewer.prototype.AdjustClippingPlanes = function () { if (this.viewer.MeshCount () > 0) { diff --git a/website/testfiles/multimesh3.mtl b/website/testfiles/multimesh3.mtl new file mode 100644 index 0000000..5f71069 --- /dev/null +++ b/website/testfiles/multimesh3.mtl @@ -0,0 +1,6 @@ +newmtl Material0 +Kd 0.784314 0 0 +newmtl Material1 +Kd 0 0.784314 0 +newmtl Material2 +Kd 0 0 0.784314 diff --git a/website/testfiles/multimesh3.obj b/website/testfiles/multimesh3.obj new file mode 100644 index 0000000..778b1ed --- /dev/null +++ b/website/testfiles/multimesh3.obj @@ -0,0 +1,105 @@ +mtllib multimesh3.mtl +g Mesh10 +v -0.5 -0.5 -0.5 +v 0.5 -0.5 -0.5 +v 0.5 -0.5 0.5 +v -0.5 -0.5 0.5 +v -0.5 0.5 -0.5 +v 0.5 0.5 -0.5 +v 0.5 0.5 0.5 +v -0.5 0.5 0.5 +vn 0 -1 0 +vn 0 -1 0 +vn 1 0 0 +vn 1 0 0 +vn 0 1 0 +vn 0 1 0 +vn -1 0 0 +vn -1 0 0 +vn 0 0 -1 +vn 0 0 -1 +vn 0 0 1 +vn 0 0 1 +usemtl Material0 +f 1//1 2//1 3//1 +f 1//2 3//2 4//2 +f 2//3 6//3 7//3 +f 2//4 7//4 3//4 +f 6//5 5//5 8//5 +f 6//6 8//6 7//6 +f 5//7 1//7 4//7 +f 5//8 4//8 8//8 +f 1//9 5//9 6//9 +f 1//10 6//10 2//10 +f 4//11 3//11 7//11 +f 4//12 7//12 8//12 +g Mesh11 +v 1.5 -0.5 -0.5 +v 2.5 -0.5 -0.5 +v 2.5 -0.5 0.5 +v 1.5 -0.5 0.5 +v 1.5 0.5 -0.5 +v 2.5 0.5 -0.5 +v 2.5 0.5 0.5 +v 1.5 0.5 0.5 +vn 0 -1 0 +vn 0 -1 0 +vn 1 0 0 +vn 1 0 0 +vn 0 1 0 +vn 0 1 0 +vn -1 0 0 +vn -1 0 0 +vn 0 0 -1 +vn 0 0 -1 +vn 0 0 1 +vn 0 0 1 +usemtl Material1 +f 9//13 10//13 11//13 +f 9//14 11//14 12//14 +f 10//15 14//15 15//15 +f 10//16 15//16 11//16 +f 14//17 13//17 16//17 +f 14//18 16//18 15//18 +f 13//19 9//19 12//19 +f 13//20 12//20 16//20 +f 9//21 13//21 14//21 +f 9//22 14//22 10//22 +f 12//23 11//23 15//23 +f 12//24 15//24 16//24 +g Mesh12 +v 3.5 -0.5 -0.5 +v 4.5 -0.5 -0.5 +v 4.5 -0.5 0.5 +v 3.5 -0.5 0.5 +v 3.5 0.5 -0.5 +v 4.5 0.5 -0.5 +v 4.5 0.5 0.5 +v 3.5 0.5 0.5 +vn 0 -1 0 +vn 0 -1 0 +vn 1 0 0 +vn 1 0 0 +vn 0 1 0 +vn 0 1 0 +vn -1 0 0 +vn -1 0 0 +vn 0 0 -1 +vn 0 0 -1 +vn 0 0 1 +vn 0 0 1 +usemtl Material0 +f 17//25 18//25 19//25 +usemtl Material1 +f 17//26 19//26 20//26 +usemtl Material2 +f 18//27 22//27 23//27 +f 18//28 23//28 19//28 +f 22//29 21//29 24//29 +f 22//30 24//30 23//30 +f 21//31 17//31 20//31 +f 21//32 20//32 24//32 +f 17//33 21//33 22//33 +f 17//34 22//34 18//34 +f 20//35 19//35 23//35 +f 20//36 23//36 24//36