From 671a0cac852255be26bf073e5377cee803e85c39 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Tue, 4 Jan 2022 20:32:53 +0100 Subject: [PATCH] Add the possibility to rotate the model during export #196 --- source/geometry/matrix.js | 6 +++++ website/o3dv/js/exportdialog.js | 46 ++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/source/geometry/matrix.js b/source/geometry/matrix.js index 096a6f5..2b872d8 100644 --- a/source/geometry/matrix.js +++ b/source/geometry/matrix.js @@ -91,6 +91,12 @@ OV.Matrix = class return this; } + CreateRotationAxisAngle (axis, angle) + { + let quaternion = OV.QuaternionFromAxisAngle (axis, angle); + return this.CreateRotation (quaternion.x, quaternion.y, quaternion.z, quaternion.w); + } + CreateScale (x, y, z) { this.matrix = [ diff --git a/website/o3dv/js/exportdialog.js b/website/o3dv/js/exportdialog.js index 16db581..7508fee 100644 --- a/website/o3dv/js/exportdialog.js +++ b/website/o3dv/js/exportdialog.js @@ -25,6 +25,20 @@ OV.ExporterUI = class { } + + AddCheckbox (parentDiv, id, name, isChecked) + { + let line = OV.AddDiv (parentDiv, 'ov_dialog_row'); + return OV.AddCheckbox (line, id, name, isChecked); + } + + AddSelect (parametersDiv, name, values, defaultIndex) + { + let parameterRow = OV.AddDiv (parametersDiv, 'ov_dialog_row'); + OV.AddDiv (parameterRow, 'ov_dialog_row_name', name); + let parameterValueDiv = OV.AddDiv (parameterRow, 'ov_dialog_row_value'); + return OV.AddSelect (parameterValueDiv, values, defaultIndex); + } }; OV.ModelExporterUI = class extends OV.ExporterUI @@ -34,7 +48,8 @@ OV.ModelExporterUI = class extends OV.ExporterUI super (name); this.format = format; this.extension = extension; - this.visibleOnlyCheckbox = null; + this.visibleOnlySelect = null; + this.rotationSelect = null; } GetType () @@ -44,24 +59,27 @@ OV.ModelExporterUI = class extends OV.ExporterUI GenerateParametersUI (parametersDiv) { - function AddCheckbox (parentDiv, id, name, isChecked) - { - let line = OV.AddDiv (parentDiv, 'ov_dialog_row'); - return OV.AddCheckbox (line, id, name, isChecked); - } - - this.visibleOnlyCheckbox = AddCheckbox (parametersDiv, 'export_visible_only', 'Export visible meshes only', true); + this.visibleOnlySelect = this.AddSelect (parametersDiv, 'Scope', ['Entire Model', 'Visible Only'], 1); + this.rotationSelect = this.AddSelect (parametersDiv, 'Rotation', ['No Rotation', '-90 Degrees', '90 Degrees'], 0); } ExportModel (model, callbacks) { let settings = new OV.ExporterSettings (); - if (this.visibleOnlyCheckbox.checked) { + if (this.visibleOnlySelect.selectedIndex === 1) { settings.isMeshVisible = (meshInstanceId) => { return callbacks.isMeshVisible (meshInstanceId); }; } + if (this.rotationSelect.selectedIndex === 1) { + let matrix = new OV.Matrix ().CreateRotationAxisAngle (new OV.Coord3D (1.0, 0.0, 0.0), -Math.PI / 2.0); + settings.transformation.SetMatrix (matrix); + } else if (this.rotationSelect.selectedIndex === 2) { + let matrix = new OV.Matrix ().CreateRotationAxisAngle (new OV.Coord3D (1.0, 0.0, 0.0), Math.PI / 2.0); + settings.transformation.SetMatrix (matrix); + } + let exporterModel = new OV.ExporterModel (model, settings); if (exporterModel.MeshInstanceCount () === 0) { let errorDialog = OV.ShowMessageDialog ( @@ -131,16 +149,8 @@ OV.ImageExporterUI = class extends OV.ExporterUI GenerateParametersUI (parametersDiv) { - function AddParameterSelect (parametersDiv, name, values, defaultIndex) - { - let parameterRow = OV.AddDiv (parametersDiv, 'ov_dialog_row'); - OV.AddDiv (parameterRow, 'ov_dialog_row_name', name); - let parameterValueDiv = OV.AddDiv (parameterRow, 'ov_dialog_row_value'); - return OV.AddSelect (parameterValueDiv, values, defaultIndex); - } - let sizeNames = this.sizes.map (size => size.name); - this.sizeSelect = AddParameterSelect (parametersDiv, 'Image size', sizeNames, 1); + this.sizeSelect = this.AddSelect (parametersDiv, 'Image size', sizeNames, 1); } ExportImage (viewer)