From fb3cdbe83c09248d1cec1b4a972a5322e5c4d2f4 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Fri, 24 Sep 2021 08:16:18 +0200 Subject: [PATCH] Pass original file name and extension to importers. --- source/import/importer.js | 7 ++----- source/import/importerbase.js | 5 ++++- test/tests/exporter_test.js | 8 ++++---- test/tests/importer_test.js | 1 - test/utils/testfiles.js | 2 +- website/o3dv/js/navigator.js | 9 +++++---- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/source/import/importer.js b/source/import/importer.js index 128f753..2456c0a 100644 --- a/source/import/importer.js +++ b/source/import/importer.js @@ -139,7 +139,7 @@ OV.Importer = class return fileBuffer; }); - importer.Import (mainFile.file.content, mainFile.file.extension, { + importer.Import (mainFile.file.name, mainFile.file.extension, mainFile.file.content, { getDefaultMaterial : () => { let material = new OV.Material (OV.MaterialType.Phong); material.color = settings.defaultColor; @@ -152,12 +152,9 @@ OV.Importer = class return buffers.GetTextureBuffer (filePath); }, onSuccess : () => { - this.model = importer.GetModel (); - this.model.SetName (mainFile.file.name); - let result = new OV.ImportResult (); result.mainFile = mainFile.file.name; - result.model = this.model; + result.model = importer.GetModel (); result.usedFiles = this.usedFiles; result.missingFiles = this.missingFiles; result.upVector = importer.GetUpDirection (); diff --git a/source/import/importerbase.js b/source/import/importerbase.js index 4fe116c..c2026fd 100644 --- a/source/import/importerbase.js +++ b/source/import/importerbase.js @@ -5,10 +5,11 @@ OV.ImporterBase = class } - Import (content, extension, callbacks) + Import (name, extension, content, callbacks) { this.Clear (); + this.name = name; this.extension = extension; this.callbacks = callbacks; this.model = new OV.Model (); @@ -22,6 +23,7 @@ OV.ImporterBase = class Clear () { + this.name = null; this.extension = null; this.callbacks = null; this.model = null; @@ -46,6 +48,7 @@ OV.ImporterBase = class } OV.FinalizeModel (this.model, this.callbacks.getDefaultMaterial); + callbacks.onSuccess (); callbacks.onComplete (); } diff --git a/test/tests/exporter_test.js b/test/tests/exporter_test.js index 23f7e59..73dfa03 100644 --- a/test/tests/exporter_test.js +++ b/test/tests/exporter_test.js @@ -212,7 +212,7 @@ describe ('Exporter', function () { let contentBuffer = stlFile.GetBufferContent (); let importer = new OV.ImporterStl (); - importer.Import (contentBuffer, 'stl', { + importer.Import (stlFile.GetName (), 'stl', contentBuffer, { getDefaultMaterial () { return new OV.Material (OV.MaterialType.Phong); }, @@ -306,7 +306,7 @@ describe ('Exporter', function () { let contentBuffer = plyFile.GetBufferContent (); let importer = new OV.ImporterPly (); - importer.Import (contentBuffer, 'ply', { + importer.Import (plyFile.GetName (), 'ply', contentBuffer, { getDefaultMaterial () { return new OV.Material (OV.MaterialType.Phong); }, @@ -336,7 +336,7 @@ describe ('Exporter', function () { let contentBuffer = gltfFile.GetBufferContent (); let importer = new OV.ImporterGltf (); - importer.Import (contentBuffer, 'gltf', { + importer.Import (gltfFile.GetName (), 'gltf', contentBuffer, { getDefaultMaterial () { return new OV.Material (OV.MaterialType.Phong); }, @@ -374,7 +374,7 @@ describe ('Exporter', function () { let contentBuffer = glbFile.GetBufferContent (); let importer = new OV.ImporterGltf (); - importer.Import (contentBuffer, 'glb', { + importer.Import (glbFile.GetName (), 'glb', contentBuffer, { getDefaultMaterial () { return new OV.Material (OV.MaterialType.Phong); }, diff --git a/test/tests/importer_test.js b/test/tests/importer_test.js index ccf224e..b668433 100644 --- a/test/tests/importer_test.js +++ b/test/tests/importer_test.js @@ -312,7 +312,6 @@ describe ('Importer Test', function () { ImportFiles (files, { success : function (importer, importResult) { assert (!OV.IsModelEmpty (importResult.model)); - console.log (importResult.usedFiles); assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']); assert.deepStrictEqual (importResult.missingFiles, []); done (); diff --git a/test/utils/testfiles.js b/test/utils/testfiles.js index ac8c259..5709025 100644 --- a/test/utils/testfiles.js +++ b/test/utils/testfiles.js @@ -52,7 +52,7 @@ module.exports = let fileContent = testUtils.GetArrayBufferFileContent (folder, filePath); return fileContent; }); - importer.Import (content, extension, { + importer.Import (fileName, extension, content, { getDefaultMaterial : function () { var material = new OV.Material (OV.MaterialType.Phong); return material; diff --git a/website/o3dv/js/navigator.js b/website/o3dv/js/navigator.js index a99c81c..db89d54 100644 --- a/website/o3dv/js/navigator.js +++ b/website/o3dv/js/navigator.js @@ -141,11 +141,12 @@ OV.Navigator = class FillTree (importResult) { - this.titleDiv.html (importResult.mainFile).attr ('title', importResult.mainFile); + const model = importResult.model; + const mainFile = importResult.mainFile; + const usedFiles = importResult.usedFiles; + const missingFiles = importResult.missingFiles; - let model = importResult.model; - let usedFiles = importResult.usedFiles; - let missingFiles = importResult.missingFiles; + this.titleDiv.html (mainFile).attr ('title', mainFile); let filesItem = new OV.TreeViewGroupItem ('Files', 'files'); this.treeView.AddItem (filesItem);