From 9f9851a2ec85e3ed98defa257246e04d72ce259c Mon Sep 17 00:00:00 2001 From: Viktor Kovacs Date: Thu, 15 Apr 2021 14:52:16 +0200 Subject: [PATCH] Async importers. --- source/external/three.model.loader.js | 4 +- source/import/importer.js | 36 +- source/import/importer3ds.js | 3 +- source/import/importerbase.js | 18 +- source/import/importergltf.js | 3 +- source/import/importerobj.js | 3 +- source/import/importeroff.js | 3 +- source/import/importerply.js | 22 +- source/import/importerstl.js | 3 +- test/tests/exporter_test.js | 70 +- test/tests/importer3ds_test.js | 292 +++---- test/tests/importer_test.js | 88 +- test/tests/importergltf_test.js | 730 +++++++++-------- test/tests/importerobj_test.js | 1062 +++++++++++++------------ test/tests/importeroff_test.js | 245 +++--- test/tests/importerply_test.js | 380 ++++----- test/tests/importerstl_test.js | 356 +++++---- test/utils/testfiles.js | 35 +- 18 files changed, 1770 insertions(+), 1583 deletions(-) diff --git a/source/external/three.model.loader.js b/source/external/three.model.loader.js index 62154d4..daa94f5 100644 --- a/source/external/three.model.loader.js +++ b/source/external/three.model.loader.js @@ -57,10 +57,10 @@ OV.ThreeModelLoader = class this.callbacks.onImportStart (); OV.RunTaskAsync (function () { obj.importer.Import (settings, { - success : function (importResult) { + onSuccess : function (importResult) { obj.OnModelImported (importResult); }, - error : function (importError) { + onError : function (importError) { obj.callbacks.onLoadError (importError); obj.inProgress = false; } diff --git a/source/import/importer.js b/source/import/importer.js index 7883d1e..d4681e3 100644 --- a/source/import/importer.js +++ b/source/import/importer.js @@ -287,7 +287,7 @@ OV.Importer = class { let mainFile = this.fileList.GetMainFile (); if (mainFile === null || mainFile.file === null || mainFile.file.content === null) { - callbacks.error (new OV.ImportError (OV.ImportErrorCode.NoImportableFile, null)); + callbacks.onError (new OV.ImportError (OV.ImportErrorCode.NoImportableFile, null)); return; } @@ -297,9 +297,6 @@ OV.Importer = class this.missingFiles = []; this.usedFiles.push (mainFile.file.name); - let result = new OV.ImportResult (); - result.mainFile = mainFile.file.name; - let obj = this; let importer = mainFile.importer; let buffers = new OV.ImportBuffers (function (fileName) { @@ -326,23 +323,24 @@ OV.Importer = class }, getTextureBuffer : function (filePath) { return buffers.GetTextureBuffer (filePath); + }, + onSuccess : function () { + obj.model = importer.GetModel (); + obj.model.SetName (mainFile.file.name); + + let result = new OV.ImportResult (); + result.mainFile = mainFile.file.name; + result.model = obj.model; + result.usedFiles = obj.usedFiles; + result.missingFiles = obj.missingFiles; + result.upVector = importer.GetUpDirection (); + callbacks.onSuccess (result); + }, + onError : function () { + let message = importer.GetMessage (); + callbacks.onError (new OV.ImportError (OV.ImportErrorCode.ImportFailed, message)); } }); - - if (importer.IsError ()) { - let message = importer.GetMessage (); - callbacks.error (new OV.ImportError (OV.ImportErrorCode.ImportFailed, message)); - return; - } - - this.model = importer.GetModel (); - this.model.SetName (mainFile.file.name); - - result.model = this.model; - result.usedFiles = this.usedFiles; - result.missingFiles = this.missingFiles; - result.upVector = importer.GetUpDirection (); - callbacks.success (result); } LoadFiles (fileList, fileSource, onReady) diff --git a/source/import/importer3ds.js b/source/import/importer3ds.js index 2cb9e92..0a7b65f 100644 --- a/source/import/importer3ds.js +++ b/source/import/importer3ds.js @@ -83,9 +83,10 @@ OV.Importer3ds = class extends OV.ImporterBase return OV.Direction.Z; } - ImportContent (fileContent) + ImportContent (fileContent, onFinish) { this.ProcessBinary (fileContent); + onFinish (); } ProcessBinary (fileContent) diff --git a/source/import/importerbase.js b/source/import/importerbase.js index ae9e584..37475ae 100644 --- a/source/import/importerbase.js +++ b/source/import/importerbase.js @@ -17,19 +17,29 @@ OV.ImporterBase = class this.error = false; this.message = null; - this.ResetState (); - this.ImportContent (content); + let obj = this; + obj.ResetState (); + obj.ImportContent (content, function () { + obj.CreateResult (callbacks); + }); + } + + CreateResult (callbacks) + { if (this.error) { + callbacks.onError (); return; } if (OV.IsModelEmpty (this.model)) { this.error = true; + callbacks.onError (); return; } OV.FinalizeModel (this.model, this.callbacks.getDefaultMaterial); - } + callbacks.onSuccess (); + } ResetState () { @@ -51,7 +61,7 @@ OV.ImporterBase = class return OV.Direction.Z; } - ImportContent (content) + ImportContent (content, onFinish) { } diff --git a/source/import/importergltf.js b/source/import/importergltf.js index 57cab21..ab4d07a 100644 --- a/source/import/importergltf.js +++ b/source/import/importergltf.js @@ -380,13 +380,14 @@ OV.ImporterGltf = class extends OV.ImporterBase return OV.Direction.Y; } - ImportContent (fileContent) + ImportContent (fileContent, onFinish) { if (this.extension === 'gltf') { this.ProcessGltf (fileContent); } else if (this.extension === 'glb') { this.ProcessBinaryGltf (fileContent); } + onFinish (); } ProcessGltf (fileContent) diff --git a/source/import/importerobj.js b/source/import/importerobj.js index b2e011f..5dadb7a 100644 --- a/source/import/importerobj.js +++ b/source/import/importerobj.js @@ -50,7 +50,7 @@ OV.ImporterObj = class extends OV.ImporterBase return OV.Direction.Y; } - ImportContent (fileContent) + ImportContent (fileContent, onFinish) { let obj = this; OV.ReadLines (fileContent, function (line) { @@ -58,6 +58,7 @@ OV.ImporterObj = class extends OV.ImporterBase obj.ProcessLine (line); } }); + onFinish (); } ProcessLine (line) diff --git a/source/import/importeroff.js b/source/import/importeroff.js index 12f0319..f0dc2fb 100644 --- a/source/import/importeroff.js +++ b/source/import/importeroff.js @@ -37,7 +37,7 @@ OV.ImporterOff = class extends OV.ImporterBase return OV.Direction.Y; } - ImportContent (fileContent) + ImportContent (fileContent, onFinish) { let obj = this; OV.ReadLines (fileContent, function (line) { @@ -45,6 +45,7 @@ OV.ImporterOff = class extends OV.ImporterBase obj.ProcessLine (line); } }); + onFinish (); } ProcessLine (line) diff --git a/source/import/importerply.js b/source/import/importerply.js index 763e6ae..0a1f7c5 100644 --- a/source/import/importerply.js +++ b/source/import/importerply.js @@ -116,23 +116,23 @@ OV.ImporterPly = class extends OV.ImporterBase return OV.Direction.Y; } - ImportContent (fileContent) + ImportContent (fileContent, onFinish) { let headerString = this.GetHeaderContent (fileContent); let header = this.ReadHeader (headerString); - if (!header.Check ()) { + if (header.Check ()) { + if (header.format === 'ascii') { + let contentString = OV.ArrayBufferToUtf8String (fileContent); + contentString = contentString.substr (headerString.length); + this.ReadAsciiContent (header, contentString); + } else if (header.format === 'binary_little_endian' || header.format === 'binary_big_endian') { + this.ReadBinaryContent (header, fileContent, headerString.length); + } + } else { this.SetError (); this.SetMessage ('Invalid header information.'); - return; - } - - if (header.format === 'ascii') { - let contentString = OV.ArrayBufferToUtf8String (fileContent); - contentString = contentString.substr (headerString.length); - this.ReadAsciiContent (header, contentString); - } else if (header.format === 'binary_little_endian' || header.format === 'binary_big_endian') { - this.ReadBinaryContent (header, fileContent, headerString.length); } + onFinish (); } GetHeaderContent (fileContent) diff --git a/source/import/importerstl.js b/source/import/importerstl.js index 5886551..89241f2 100644 --- a/source/import/importerstl.js +++ b/source/import/importerstl.js @@ -31,7 +31,7 @@ OV.ImporterStl = class extends OV.ImporterBase return OV.Direction.Z; } - ImportContent (fileContent) + ImportContent (fileContent, onFinish) { if (this.IsBinaryStlFile (fileContent)) { this.ProcessBinary (fileContent); @@ -44,6 +44,7 @@ OV.ImporterStl = class extends OV.ImporterBase } }); } + onFinish (); } IsBinaryStlFile (fileContent) diff --git a/test/tests/exporter_test.js b/test/tests/exporter_test.js index 10b4241..62801d4 100644 --- a/test/tests/exporter_test.js +++ b/test/tests/exporter_test.js @@ -179,7 +179,7 @@ describe ('Exporter', function () { ].join ('\n')); }); - it ('Stl Binary Export', function () { + it ('Stl Binary Export', function (done) { let model = CreateTestModel (); let exporter = new OV.Exporter (); @@ -195,11 +195,14 @@ describe ('Exporter', function () { importer.Import (contentBuffer, 'stl', { getDefaultMaterial () { return new OV.Material (); + }, + onSuccess () { + let importedModel = importer.GetModel (); + assert.strictEqual (importedModel.VertexCount (), 12); + assert.strictEqual (importedModel.TriangleCount (), 4); + done (); } }); - let importedModel = importer.GetModel (); - assert.strictEqual (importedModel.VertexCount (), 12); - assert.strictEqual (importedModel.TriangleCount (), 4); }); it ('Off Export', function () { @@ -267,7 +270,7 @@ describe ('Exporter', function () { ].join ('\n')); }); - it ('Ply Binary Export', function () { + it ('Ply Binary Export', function (done) { let model = CreateTestModel (); let exporter = new OV.Exporter (); @@ -283,14 +286,17 @@ describe ('Exporter', function () { importer.Import (contentBuffer, 'ply', { getDefaultMaterial () { return new OV.Material (); + }, + onSuccess () { + let importedModel = importer.GetModel (); + assert.strictEqual (importedModel.VertexCount (), 8); + assert.strictEqual (importedModel.TriangleCount (), 4); + done (); } - }); - let importedModel = importer.GetModel (); - assert.strictEqual (importedModel.VertexCount (), 8); - assert.strictEqual (importedModel.TriangleCount (), 4); + }); }); - it ('Gltf Ascii Export', function () { + it ('Gltf Ascii Export', function (done) { let model = CreateTestModel (); let exporter = new OV.Exporter (); @@ -320,20 +326,22 @@ describe ('Exporter', function () { }, getTextureBuffer (filePath) { return null; + }, + onSuccess () { + let importedModel = importer.GetModel (); + assert (OV.CheckModel (importedModel)); + assert.strictEqual (importedModel.MaterialCount (), 2); + assert.strictEqual (importedModel.MeshCount (), 2); + assert.strictEqual (importedModel.GetMesh (0).GetName (), 'TestMesh1'); + assert.strictEqual (importedModel.GetMesh (1).GetName (), 'TestMesh2'); + assert.strictEqual (importedModel.VertexCount (), 12); + assert.strictEqual (importedModel.TriangleCount (), 4); + done (); } }); - - let importedModel = importer.GetModel (); - assert (OV.CheckModel (importedModel)); - assert.strictEqual (importedModel.MaterialCount (), 2); - assert.strictEqual (importedModel.MeshCount (), 2); - assert.strictEqual (importedModel.GetMesh (0).GetName (), 'TestMesh1'); - assert.strictEqual (importedModel.GetMesh (1).GetName (), 'TestMesh2'); - assert.strictEqual (importedModel.VertexCount (), 12); - assert.strictEqual (importedModel.TriangleCount (), 4); }); - it ('Gltf Binary Export', function () { + it ('Gltf Binary Export', function (done) { let model = CreateTestModel (); let exporter = new OV.Exporter (); @@ -354,16 +362,18 @@ describe ('Exporter', function () { }, getTextureBuffer (filePath) { return null; + }, + onSuccess () { + let importedModel = importer.GetModel (); + assert (OV.CheckModel (importedModel)); + assert.strictEqual (importedModel.MaterialCount (), 2); + assert.strictEqual (importedModel.MeshCount (), 2); + assert.strictEqual (importedModel.GetMesh (0).GetName (), 'TestMesh1'); + assert.strictEqual (importedModel.GetMesh (1).GetName (), 'TestMesh2'); + assert.strictEqual (importedModel.VertexCount (), 12); + assert.strictEqual (importedModel.TriangleCount (), 4); + done (); } - }); - - let importedModel = importer.GetModel (); - assert (OV.CheckModel (importedModel)); - assert.strictEqual (importedModel.MaterialCount (), 2); - assert.strictEqual (importedModel.MeshCount (), 2); - assert.strictEqual (importedModel.GetMesh (0).GetName (), 'TestMesh1'); - assert.strictEqual (importedModel.GetMesh (1).GetName (), 'TestMesh2'); - assert.strictEqual (importedModel.VertexCount (), 12); - assert.strictEqual (importedModel.TriangleCount (), 4); + }); }); }); diff --git a/test/tests/importer3ds_test.js b/test/tests/importer3ds_test.js index 365993d..8d1f5fe 100644 --- a/test/tests/importer3ds_test.js +++ b/test/tests/importer3ds_test.js @@ -3,159 +3,167 @@ var testFiles = require ('../utils/testfiles.js'); var testUtils = require ('../utils/testutils.js'); describe ('3ds Importer', function() { - it ('cube_with_materials.obj', function () { - var model = testFiles.Import3dsFile ('cube_with_materials.3ds'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'tex' }, - { name : 'red' }, - { name : 'green' }, - { name : 'blue' }, - { name : 'white' } - ], - meshes : [ - { - name : 'cube', - vertexCount : 8, - normalCount : 12, - uvCount : 8, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_with_materials.3ds', function (done) { + testFiles.Import3dsFile ('cube_with_materials.3ds', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'tex' }, + { name : 'red' }, + { name : 'green' }, + { name : 'blue' }, + { name : 'white' } + ], + meshes : [ + { + name : 'cube', + vertexCount : 8, + normalCount : 12, + uvCount : 8, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); - it ('cube_with_texture_transformations.3ds', function () { - var model = testFiles.Import3dsFile ('cube_with_texture_transformations.3ds'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'tex' }, - { name : 'red' }, - { name : 'green' }, - { name : 'blue' }, - { name : 'white' } - ], - meshes : [ - { - name : 'cube', - vertexCount : 8, - normalCount : 12, - uvCount : 8, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_with_texture_transformations.3ds', function (done) { + testFiles.Import3dsFile ('cube_with_texture_transformations.3ds', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'tex' }, + { name : 'red' }, + { name : 'green' }, + { name : 'blue' }, + { name : 'white' } + ], + meshes : [ + { + name : 'cube', + vertexCount : 8, + normalCount : 12, + uvCount : 8, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); - it ('cube_two_instances.3ds', function () { - var model = testFiles.Import3dsFile ('cube_two_instances.3ds'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'tex' }, - { name : 'red' }, - { name : 'green' }, - { name : 'blue' }, - { name : 'white' } - ], - meshes : [ - { - name : 'cube', - vertexCount : 8, - normalCount : 12, - uvCount : 8, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] - } - }, - { - name : 'cube', - vertexCount : 8, - normalCount : 12, - uvCount : 8, - triangleCount : 12, - boundingBox : { - min : [2, 0, 0], - max : [3, 1, 1] - } - } - ] + it ('cube_two_instances.3ds', function (done) { + testFiles.Import3dsFile ('cube_two_instances.3ds', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'tex' }, + { name : 'red' }, + { name : 'green' }, + { name : 'blue' }, + { name : 'white' } + ], + meshes : [ + { + name : 'cube', + vertexCount : 8, + normalCount : 12, + uvCount : 8, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } + }, + { + name : 'cube', + vertexCount : 8, + normalCount : 12, + uvCount : 8, + triangleCount : 12, + boundingBox : { + min : [2, 0, 0], + max : [3, 1, 1] + } + } + ] + }); + done (); }); }); - it ('cube_four_instances.3ds', function () { - var model = testFiles.Import3dsFile ('cube_four_instances.3ds'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'tex' }, - { name : 'red' }, - { name : 'green' }, - { name : 'blue' }, - { name : 'white' } - ], - meshes : [ - { - name : 'cube', - vertexCount : 8, - normalCount : 12, - uvCount : 8, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] - } - }, - { - name : 'cube', - vertexCount : 8, - normalCount : 12, - uvCount : 8, - triangleCount : 12, - boundingBox : { - min : [2, 0, 0], - max : [3, 1, 1] - } - }, - { - name : 'cube', - vertexCount : 8, - normalCount : 12, - uvCount : 8, - triangleCount : 12, - boundingBox : { - min : [2, 2, 0], - max : [3, 3, 1] - } - }, - { - name : 'cube', - vertexCount : 8, - normalCount : 12, - uvCount : 8, - triangleCount : 12, - boundingBox : { - min : [0, 2, 0], - max : [1, 3, 1] - } - } - ] + it ('cube_four_instances.3ds', function (done) { + testFiles.Import3dsFile ('cube_four_instances.3ds', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'tex' }, + { name : 'red' }, + { name : 'green' }, + { name : 'blue' }, + { name : 'white' } + ], + meshes : [ + { + name : 'cube', + vertexCount : 8, + normalCount : 12, + uvCount : 8, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } + }, + { + name : 'cube', + vertexCount : 8, + normalCount : 12, + uvCount : 8, + triangleCount : 12, + boundingBox : { + min : [2, 0, 0], + max : [3, 1, 1] + } + }, + { + name : 'cube', + vertexCount : 8, + normalCount : 12, + uvCount : 8, + triangleCount : 12, + boundingBox : { + min : [2, 2, 0], + max : [3, 3, 1] + } + }, + { + name : 'cube', + vertexCount : 8, + normalCount : 12, + uvCount : 8, + triangleCount : 12, + boundingBox : { + min : [0, 2, 0], + max : [1, 3, 1] + } + } + ] + }); + done (); }); }); }); diff --git a/test/tests/importer_test.js b/test/tests/importer_test.js index b7b9cf5..46c6c39 100644 --- a/test/tests/importer_test.js +++ b/test/tests/importer_test.js @@ -6,10 +6,10 @@ function ImportFilesWithImporter (importer, files, callbacks) importer.LoadFilesFromFileObjects (files, function () { let settings = new OV.ImportSettings (); importer.Import (settings, { - success : function (importResult) { + onSuccess : function (importResult) { callbacks.success (importer, importResult); }, - error : function (importError) { + onError : function (importError) { callbacks.error (importer, importError); } }); @@ -23,7 +23,7 @@ function ImportFiles (files, callbacks) } describe ('Importer Test', function () { - it ('Empty File List', function () { + it ('Empty File List', function (done) { let files = []; ImportFiles (files, { success : function (importer, importResult) { @@ -31,11 +31,12 @@ describe ('Importer Test', function () { }, error : function (importer, importError) { assert.strictEqual (importError.code, OV.ImportErrorCode.NoImportableFile); + done (); } }); }); - it ('Not existing file', function () { + it ('Not existing file', function (done) { let files = [ new FileObject ('obj', 'missing.obj') ]; @@ -45,11 +46,12 @@ describe ('Importer Test', function () { }, error : function (importer, importError) { assert.strictEqual (importError.code, OV.ImportErrorCode.NoImportableFile); + done (); } }); }); - it ('Not imprtable file', function () { + it ('Not imprtable file', function (done) { let files = [ new FileObject ('', 'wrong.ext') ]; @@ -59,11 +61,12 @@ describe ('Importer Test', function () { }, error : function (importer, importError) { assert.strictEqual (importError.code, OV.ImportErrorCode.NoImportableFile); + done (); } }); }); - it ('Wrong file', function () { + it ('Wrong file', function (done) { let files = [ new FileObject ('3ds', 'wrong.3ds') ]; @@ -73,11 +76,12 @@ describe ('Importer Test', function () { }, error : function (importer, importError) { assert.strictEqual (importError.code, OV.ImportErrorCode.ImportFailed); + done (); } }); }); - it ('Single file', function () { + it ('Single file', function (done) { let files = [ new FileObject ('obj', 'single_triangle.obj') ]; @@ -86,6 +90,7 @@ describe ('Importer Test', function () { assert (!OV.IsModelEmpty (importResult.model)); assert.deepStrictEqual (importResult.usedFiles, ['single_triangle.obj']); assert.deepStrictEqual (importResult.missingFiles, []); + done (); }, error : function (importer, importError) { assert.fail (); @@ -93,7 +98,7 @@ describe ('Importer Test', function () { }); }); - it ('Multiple files', function () { + it ('Multiple files', function (done) { let files = [ new FileObject ('obj', 'cube_with_materials.obj'), new FileObject ('obj', 'cube_with_materials.mtl'), @@ -105,7 +110,8 @@ describe ('Importer Test', function () { success : function (importer, importResult) { assert (!OV.IsModelEmpty (importResult.model)); assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']); - assert.deepStrictEqual (importResult.missingFiles, []); + assert.deepStrictEqual (importResult.missingFiles, []); + done (); }, error : function (importer, importError) { assert.fail (); @@ -113,7 +119,7 @@ describe ('Importer Test', function () { }); }); - it ('Missing files', function () { + it ('Missing files', function (done) { let files = []; files.push (new FileObject ('obj', 'cube_with_materials.obj')); ImportFiles (files, { @@ -121,36 +127,38 @@ describe ('Importer Test', function () { assert (!OV.IsModelEmpty (importResult.model)); assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj']); assert.deepStrictEqual (importResult.missingFiles, ['cube_with_materials.mtl']); + files.push (new FileObject ('obj', 'cube_with_materials.mtl')); + ImportFiles (files, { + success : function (importer, importResult) { + assert (!OV.IsModelEmpty (importResult.model)); + assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl']); + assert.deepStrictEqual (importResult.missingFiles, ['cube_texture.png']); + files.push (new FileObject ('obj', 'cube_texture.png')); + ImportFiles (files, { + success : function (importer, importResult) { + assert (!OV.IsModelEmpty (importResult.model)); + assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']); + assert.deepStrictEqual (importResult.missingFiles, []); + done (); + }, + error : function (importer, importError) { + assert.fail (); + } + }); + }, + error : function (importer, importError) { + assert.fail (); + } + }); }, error : function (importer, importError) { assert.fail (); } }); - files.push (new FileObject ('obj', 'cube_with_materials.mtl')); - ImportFiles (files, { - success : function (importer, importResult) { - assert (!OV.IsModelEmpty (importResult.model)); - assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl']); - assert.deepStrictEqual (importResult.missingFiles, ['cube_texture.png']); - }, - error : function (importer, importError) { - assert.fail (); - } - }); - files.push (new FileObject ('obj', 'cube_texture.png')); - ImportFiles (files, { - success : function (importer, importResult) { - assert (!OV.IsModelEmpty (importResult.model)); - assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']); - assert.deepStrictEqual (importResult.missingFiles, []); - }, - error : function (importer, importError) { - assert.fail (); - } - }); + }); - it ('Missing texture multiple times', function () { + it ('Missing texture multiple times', function (done) { let files = [ new FileObject ('obj', 'two_materials_same_texture.obj'), new FileObject ('obj', 'two_materials_same_texture.mtl'), @@ -160,6 +168,7 @@ describe ('Importer Test', function () { assert (!OV.IsModelEmpty (importResult.model)); assert.deepStrictEqual (importResult.usedFiles, ['two_materials_same_texture.obj', 'two_materials_same_texture.mtl']); assert.deepStrictEqual (importResult.missingFiles, ['texture.png']); + done (); }, error : function (importer, importError) { assert.fail (); @@ -167,7 +176,7 @@ describe ('Importer Test', function () { }); }); - it ('Append Missing files', function () { + it ('Append Missing files', function (done) { let theImporter = new OV.Importer (); ImportFilesWithImporter (theImporter, [new FileObject ('obj', 'cube_with_materials.obj')], { success : function (importer, importResult) { @@ -184,6 +193,7 @@ describe ('Importer Test', function () { assert (!OV.IsModelEmpty (importResult.model)); assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']); assert.deepStrictEqual (importResult.missingFiles, []); + done (); }, error : function (importer, importError) { assert.fail (); @@ -201,7 +211,7 @@ describe ('Importer Test', function () { }); }); - it ('Reuse importer', function () { + it ('Reuse importer', function (done) { let files1 = [ new FileObject ('obj', 'cube_with_materials.obj'), new FileObject ('obj', 'cube_with_materials.mtl'), @@ -223,6 +233,7 @@ describe ('Importer Test', function () { assert (!OV.IsModelEmpty (importResult.model)); assert.deepStrictEqual (importResult.usedFiles, ['single_triangle.obj']); assert.deepStrictEqual (importResult.missingFiles, []); + done (); }, error : function (importer, importError) { assert.fail (); @@ -235,7 +246,7 @@ describe ('Importer Test', function () { }); }); - it ('Default color', function () { + it ('Default color', function (done) { let files = [ new FileObject ('stl', 'single_triangle.stl') ]; @@ -244,14 +255,15 @@ describe ('Importer Test', function () { let settings = new OV.ImportSettings (); settings.defaultColor = new OV.Color (200, 0, 0); theImporter.Import (settings, { - success : function (importResult) { + onSuccess : function (importResult) { assert (!OV.IsModelEmpty (importResult.model)); assert.deepStrictEqual (importResult.usedFiles, ['single_triangle.stl']); assert.deepStrictEqual (importResult.missingFiles, []); let material = importResult.model.GetMaterial (0); assert.deepStrictEqual (material.diffuse, new OV.Color (200, 0, 0)); + done (); }, - error : function (importError) { + onError : function (importError) { assert.fail (); } }); diff --git a/test/tests/importergltf_test.js b/test/tests/importergltf_test.js index 23eb451..d6a927d 100644 --- a/test/tests/importergltf_test.js +++ b/test/tests/importergltf_test.js @@ -6,348 +6,384 @@ let testUtils = require ('../utils/testutils.js'); //console.log (util.inspect(testUtils.ModelToObjectSimple (model), {showHidden: false, depth: null})) describe ('Gltf Importer', function () { - it ('Triangle', function () { + it ('Triangle', function (done) { let testFileList = [ ['Triangle/glTF', 'Triangle.gltf'], ['Triangle/glTF-Embedded', 'Triangle.gltf'], ['TriangleWithoutIndices/glTF', 'TriangleWithoutIndices.gltf'], ['TriangleWithoutIndices/glTF-Embedded', 'TriangleWithoutIndices.gltf'] ]; + let processed = 0; for (let i = 0; i < testFileList.length; i++) { let testFile = testFileList[i]; - let model = testFiles.ImportGltfFile (testFile[0], testFile[1]); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 3, - normalCount : 1, - uvCount : 0, - triangleCount : 1, - boundingBox : { - min : [0.0, 0.0, 0.0], - max : [1.0, 1.0, 0.0] + testFiles.ImportGltfFile (testFile[0], testFile[1], function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 3, + normalCount : 1, + uvCount : 0, + triangleCount : 1, + boundingBox : { + min : [0.0, 0.0, 0.0], + max : [1.0, 1.0, 0.0] + } } - } - ] - }); + ] + }); + processed += 1; + if (processed == testFileList.length) { + done (); + } + }); } }); - it ('Box', function () { + it ('Box', function (done) { let testFileList = [ ['Box/glTF', 'Box.gltf'], ['Box/glTF-Embedded', 'Box.gltf'], ['Box/glTF-Binary', 'Box.glb'] ]; + let processed = 0; for (let i = 0; i < testFileList.length; i++) { let testFile = testFileList[i]; - let model = testFiles.ImportGltfFile (testFile[0], testFile[1]); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'Red' } - ], - meshes : [ - { - name : 'Mesh', - vertexCount : 24, - normalCount : 24, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [-0.5, -0.5, -0.5], - max : [0.5, 0.5, 0.5] + testFiles.ImportGltfFile (testFile[0], testFile[1], function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'Red' } + ], + meshes : [ + { + name : 'Mesh', + vertexCount : 24, + normalCount : 24, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [-0.5, -0.5, -0.5], + max : [0.5, 0.5, 0.5] + } } - } - ] - }); + ] + }); + processed += 1; + if (processed == testFileList.length) { + done (); + } + }); } }); - it ('BoxInterleaved', function () { + it ('BoxInterleaved', function (done) { let testFileList = [ ['BoxInterleaved/glTF', 'BoxInterleaved.gltf'], ['BoxInterleaved/glTF-Embedded', 'BoxInterleaved.gltf'], ['BoxInterleaved/glTF-Binary', 'BoxInterleaved.glb'] ]; + let processed = 0; for (let i = 0; i < testFileList.length; i++) { let testFile = testFileList[i]; - let model = testFiles.ImportGltfFile (testFile[0], testFile[1]); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'Mesh', - vertexCount : 24, - normalCount : 24, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [-0.5, -0.5, -0.5], - max : [0.5, 0.5, 0.5] + testFiles.ImportGltfFile (testFile[0], testFile[1], function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'Mesh', + vertexCount : 24, + normalCount : 24, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [-0.5, -0.5, -0.5], + max : [0.5, 0.5, 0.5] + } } - } - ] - }); + ] + }); + processed += 1; + if (processed == testFileList.length) { + done (); + } + }); } }); - it ('BoxTextured', function () { + it ('BoxTextured', function (done) { let testFileList = [ ['BoxTextured/glTF', 'BoxTextured.gltf'], ['BoxTextured/glTF-Embedded', 'BoxTextured.gltf'], ['BoxTextured/glTF-Binary', 'BoxTextured.glb'] ]; + let processed = 0; for (let i = 0; i < testFileList.length; i++) { let testFile = testFileList[i]; - let model = testFiles.ImportGltfFile (testFile[0], testFile[1]); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'Texture' } - ], - meshes : [ - { - name : 'Mesh', - vertexCount : 24, - normalCount : 24, - uvCount : 24, - triangleCount : 12, - boundingBox : { - min : [-0.5, -0.5, -0.5], - max : [0.5, 0.5, 0.5] + testFiles.ImportGltfFile (testFile[0], testFile[1], function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'Texture' } + ], + meshes : [ + { + name : 'Mesh', + vertexCount : 24, + normalCount : 24, + uvCount : 24, + triangleCount : 12, + boundingBox : { + min : [-0.5, -0.5, -0.5], + max : [0.5, 0.5, 0.5] + } } - } - ] - }); + ] + }); + processed += 1; + if (processed == testFileList.length) { + done (); + } + }); } }); - it ('SimpleMeshes', function () { + it ('SimpleMeshes', function (done) { let testFileList = [ ['SimpleMeshes/glTF', 'SimpleMeshes.gltf'], ['SimpleMeshes/glTF-Embedded', 'SimpleMeshes.gltf'] ]; + let processed = 0; for (let i = 0; i < testFileList.length; i++) { let testFile = testFileList[i]; - let model = testFiles.ImportGltfFile (testFile[0], testFile[1]); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 3, - normalCount : 3, - uvCount : 0, - triangleCount : 1, - boundingBox : { - min : [0.0, 0.0, 0.0], - max : [1.0, 1.0, 0.0] + testFiles.ImportGltfFile (testFile[0], testFile[1], function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 3, + normalCount : 3, + uvCount : 0, + triangleCount : 1, + boundingBox : { + min : [0.0, 0.0, 0.0], + max : [1.0, 1.0, 0.0] + } + }, + { + name : '', + vertexCount : 3, + normalCount : 3, + uvCount : 0, + triangleCount : 1, + boundingBox : { + min : [1.0, 0.0, 0.0], + max : [2.0, 1.0, 0.0] + } } - }, - { - name : '', - vertexCount : 3, - normalCount : 3, - uvCount : 0, - triangleCount : 1, - boundingBox : { - min : [1.0, 0.0, 0.0], - max : [2.0, 1.0, 0.0] - } - } - ] - }); + ] + }); + processed += 1; + if (processed == testFileList.length) { + done (); + } + }); } }); - it ('OrientationTest', function () { + it ('OrientationTest', function (done) { let testFileList = [ ['OrientationTest/glTF', 'OrientationTest.gltf'], ['OrientationTest/glTF-Embedded', 'OrientationTest.gltf'], ['OrientationTest/glTF-Binary', 'OrientationTest.glb'], ]; + let processed = 0; for (let i = 0; i < testFileList.length; i++) { let testFile = testFileList[i]; - let model = testFiles.ImportGltfFile (testFile[0], testFile[1]); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'BaseMaterial' }, - { name : 'MatX1' }, - { name : 'MatX2' }, - { name : 'MatY1' }, - { name : 'MatY2' }, - { name : 'MatZ1' }, - { name : 'MatZ2' } - ], - meshes : [ - { - name: 'ArrowMeshZ2', - vertexCount: 78, - normalCount: 78, - uvCount: 0, - triangleCount: 38, - boundingBox : { - min: [ -0.6921195564310951, -1.0785199551363698, -5.330651201963446 ], - max: [ 1.0439303242310798, 2.868914373727357, -4.66934876823423 ] + testFiles.ImportGltfFile (testFile[0], testFile[1], function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'BaseMaterial' }, + { name : 'MatX1' }, + { name : 'MatX2' }, + { name : 'MatY1' }, + { name : 'MatY2' }, + { name : 'MatZ1' }, + { name : 'MatZ2' } + ], + meshes : [ + { + name: 'ArrowMeshZ2', + vertexCount: 78, + normalCount: 78, + uvCount: 0, + triangleCount: 38, + boundingBox : { + min: [ -0.6921195564310951, -1.0785199551363698, -5.330651201963446 ], + max: [ 1.0439303242310798, 2.868914373727357, -4.66934876823423 ] + } + }, + { + name: 'TargetMeshZ2', + vertexCount: 50, + normalCount: 50, + uvCount: 0, + triangleCount: 26, + boundingBox : { + min: [ 0.8097413778305054, 2.8717148303985596, -5.33065128326416 ], + max: [ 1.4936277866363525, 3.9211390018463135, -4.66934871673584 ] + } + }, + { + name: 'TargetMeshY2', + vertexCount: 50, + normalCount: 50, + uvCount: 0, + triangleCount: 26, + boundingBox : { + min: [ -1.1686336994171143, -5.330650806427002, 2.93727445602417 ], + max: [ -0.46912679076194763, -4.66934871673584, 3.9916374683380127 ] + } + }, + { + name: 'ArrowMeshY2', + vertexCount: 78, + normalCount: 78, + uvCount: 0, + triangleCount: 38, + boundingBox : { + min: [ -0.9557393651589479, -5.330651177643153, -1.06505742884149 ], + max: [ 0.6167901044859734, -4.6693486435429055, 2.934442924096579 ] + } + }, + { + name: 'ArrowMeshX2', + vertexCount: 78, + normalCount: 78, + uvCount: 0, + triangleCount: 38, + boundingBox : { + min: [ -5.330651171390089, -1.0326269494863676, -0.6059335185163844 ], + max: [ -4.669348828609911, 2.9885841671721116, 0.8202131194767724 ] + } + }, + { + name: 'TargetMeshX2', + vertexCount: 54, + normalCount: 54, + uvCount: 0, + triangleCount: 26, + boundingBox : { + min: [ -5.33065128326416, 2.991360902786255, -0.012430161237716675 ], + max: [ -4.66934871673584, 4.039160251617432, 0.6999828815460205 ] + } + }, + { + name: 'TargetMeshZ1', + vertexCount: 52, + normalCount: 52, + uvCount: 0, + triangleCount: 26, + boundingBox : { + min: [ -1.3648574352264404, 2.9005930423736572, 4.66934871673584 ], + max: [ -0.6740907430648804, 3.9529545307159424, 5.33065128326416 ] + } + }, + { + name: 'ArrowMeshZ1', + vertexCount: 74, + normalCount: 74, + uvCount: 0, + triangleCount: 38, + boundingBox : { + min: [ -1.009571011381568, -1.074115497823536, 4.669348895549774 ], + max: [ 0.6625885973069405, 2.8977772707193465, 5.330651104450226 ] + } + }, + { + name: 'TargetMeshX1', + vertexCount: 54, + normalCount: 54, + uvCount: 0, + triangleCount: 26, + boundingBox : { + min: [ 4.66934871673584, 2.4595587253570557, -2.553251266479492 ], + max: [ 5.33065128326416, 3.432579517364502, -1.7226401567459106 ] + } + }, + { + name: 'ArrowMeshX1', + vertexCount: 78, + normalCount: 78, + uvCount: 0, + triangleCount: 38, + boundingBox : { + min: [ 4.669348835945129, -1.0589144181932033, -1.7207290818192755 ], + max: [ 5.330651164054871, 2.4574561383341145, 0.9159925616542917 ] + } + }, + { + name: 'TargetMeshY1', + vertexCount: 52, + normalCount: 52, + uvCount: 0, + triangleCount: 26, + boundingBox : { + min: [ 2.8218495845794678, 4.669349193572998, -1.6833229064941406 ], + max: [ 3.864471435546875, 5.33065128326416, -1.0113166570663452 ] + } + }, + { + name: 'ArrowMeshY1', + vertexCount: 78, + normalCount: 78, + uvCount: 0, + triangleCount: 38, + boundingBox : { + min: [ -1.0826615032554154, 4.669348806142807, -1.093071740019906 ], + max: [ 2.8190779754834807, 5.3306513130664825, 0.7348238365226794 ] + } + }, + { + name: 'BaseCubeMesh', + vertexCount: 272, + normalCount: 272, + uvCount: 0, + triangleCount: 140, + boundingBox : { + min: [ -5.000001907348633, -5, -5.000001907348633 ], + max: [ 5.000002384185791, 5, 5.000002861022949 ] + } } - }, - { - name: 'TargetMeshZ2', - vertexCount: 50, - normalCount: 50, - uvCount: 0, - triangleCount: 26, - boundingBox : { - min: [ 0.8097413778305054, 2.8717148303985596, -5.33065128326416 ], - max: [ 1.4936277866363525, 3.9211390018463135, -4.66934871673584 ] - } - }, - { - name: 'TargetMeshY2', - vertexCount: 50, - normalCount: 50, - uvCount: 0, - triangleCount: 26, - boundingBox : { - min: [ -1.1686336994171143, -5.330650806427002, 2.93727445602417 ], - max: [ -0.46912679076194763, -4.66934871673584, 3.9916374683380127 ] - } - }, - { - name: 'ArrowMeshY2', - vertexCount: 78, - normalCount: 78, - uvCount: 0, - triangleCount: 38, - boundingBox : { - min: [ -0.9557393651589479, -5.330651177643153, -1.06505742884149 ], - max: [ 0.6167901044859734, -4.6693486435429055, 2.934442924096579 ] - } - }, - { - name: 'ArrowMeshX2', - vertexCount: 78, - normalCount: 78, - uvCount: 0, - triangleCount: 38, - boundingBox : { - min: [ -5.330651171390089, -1.0326269494863676, -0.6059335185163844 ], - max: [ -4.669348828609911, 2.9885841671721116, 0.8202131194767724 ] - } - }, - { - name: 'TargetMeshX2', - vertexCount: 54, - normalCount: 54, - uvCount: 0, - triangleCount: 26, - boundingBox : { - min: [ -5.33065128326416, 2.991360902786255, -0.012430161237716675 ], - max: [ -4.66934871673584, 4.039160251617432, 0.6999828815460205 ] - } - }, - { - name: 'TargetMeshZ1', - vertexCount: 52, - normalCount: 52, - uvCount: 0, - triangleCount: 26, - boundingBox : { - min: [ -1.3648574352264404, 2.9005930423736572, 4.66934871673584 ], - max: [ -0.6740907430648804, 3.9529545307159424, 5.33065128326416 ] - } - }, - { - name: 'ArrowMeshZ1', - vertexCount: 74, - normalCount: 74, - uvCount: 0, - triangleCount: 38, - boundingBox : { - min: [ -1.009571011381568, -1.074115497823536, 4.669348895549774 ], - max: [ 0.6625885973069405, 2.8977772707193465, 5.330651104450226 ] - } - }, - { - name: 'TargetMeshX1', - vertexCount: 54, - normalCount: 54, - uvCount: 0, - triangleCount: 26, - boundingBox : { - min: [ 4.66934871673584, 2.4595587253570557, -2.553251266479492 ], - max: [ 5.33065128326416, 3.432579517364502, -1.7226401567459106 ] - } - }, - { - name: 'ArrowMeshX1', - vertexCount: 78, - normalCount: 78, - uvCount: 0, - triangleCount: 38, - boundingBox : { - min: [ 4.669348835945129, -1.0589144181932033, -1.7207290818192755 ], - max: [ 5.330651164054871, 2.4574561383341145, 0.9159925616542917 ] - } - }, - { - name: 'TargetMeshY1', - vertexCount: 52, - normalCount: 52, - uvCount: 0, - triangleCount: 26, - boundingBox : { - min: [ 2.8218495845794678, 4.669349193572998, -1.6833229064941406 ], - max: [ 3.864471435546875, 5.33065128326416, -1.0113166570663452 ] - } - }, - { - name: 'ArrowMeshY1', - vertexCount: 78, - normalCount: 78, - uvCount: 0, - triangleCount: 38, - boundingBox : { - min: [ -1.0826615032554154, 4.669348806142807, -1.093071740019906 ], - max: [ 2.8190779754834807, 5.3306513130664825, 0.7348238365226794 ] - } - }, - { - name: 'BaseCubeMesh', - vertexCount: 272, - normalCount: 272, - uvCount: 0, - triangleCount: 140, - boundingBox : { - min: [ -5.000001907348633, -5, -5.000001907348633 ], - max: [ 5.000002384185791, 5, 5.000002861022949 ] - } - } - ] - }); + ] + }); + processed += 1; + if (processed == testFileList.length) { + done (); + } + }); } }); - it ('MeshPrimitives_4Vertex', function () { + it ('MeshPrimitives_4Vertex', function (done) { let testFileList = [ ['Mesh_PrimitiveMode', 'Mesh_PrimitiveMode_04.gltf'], ['Mesh_PrimitiveMode', 'Mesh_PrimitiveMode_05.gltf'], @@ -355,90 +391,108 @@ describe ('Gltf Importer', function () { ['Mesh_PrimitiveMode', 'Mesh_PrimitiveMode_12.gltf'], ['Mesh_PrimitiveMode', 'Mesh_PrimitiveMode_13.gltf'] ]; + let processed = 0; for (let i = 0; i < testFileList.length; i++) { let testFile = testFileList[i]; - let model = testFiles.ImportGltfFile (testFile[0], testFile[1]); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 4, - normalCount : 2, - uvCount : 0, - triangleCount : 2, - boundingBox : { - min : [-0.5, -0.5, 0.0], - max : [0.5, 0.5, 0.0] + testFiles.ImportGltfFile (testFile[0], testFile[1], function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 4, + normalCount : 2, + uvCount : 0, + triangleCount : 2, + boundingBox : { + min : [-0.5, -0.5, 0.0], + max : [0.5, 0.5, 0.0] + } } - } - ] - }); + ] + }); + processed += 1; + if (processed == testFileList.length) { + done (); + } + }); } }); - it ('MeshPrimitives_6Vertex', function () { + it ('MeshPrimitives_6Vertex', function (done) { let testFileList = [ ['Mesh_PrimitiveMode', 'Mesh_PrimitiveMode_06.gltf'] ]; + let processed = 0; for (let i = 0; i < testFileList.length; i++) { let testFile = testFileList[i]; - let model = testFiles.ImportGltfFile (testFile[0], testFile[1]); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 6, - normalCount : 2, - uvCount : 0, - triangleCount : 2, - boundingBox : { - min : [-0.5, -0.5, 0.0], - max : [0.5, 0.5, 0.0] + testFiles.ImportGltfFile (testFile[0], testFile[1], function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 6, + normalCount : 2, + uvCount : 0, + triangleCount : 2, + boundingBox : { + min : [-0.5, -0.5, 0.0], + max : [0.5, 0.5, 0.0] + } } - } - ] - }); + ] + }); + processed += 1; + if (processed == testFileList.length) { + done (); + } + }); } }); - it ('SimpleSparseAccessor', function () { + it ('SimpleSparseAccessor', function (done) { let testFileList = [ ['SimpleSparseAccessor/glTF', 'SimpleSparseAccessor.gltf'], ['SimpleSparseAccessor/glTF-Embedded', 'SimpleSparseAccessor.gltf'] ]; + let processed = 0; for (let i = 0; i < testFileList.length; i++) { let testFile = testFileList[i]; - let model = testFiles.ImportGltfFile (testFile[0], testFile[1]); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 14, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [0.0, 0.0, 0.0], - max : [6.0, 4.0, 0.0] + testFiles.ImportGltfFile (testFile[0], testFile[1], function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 14, + normalCount : 12, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [0.0, 0.0, 0.0], + max : [6.0, 4.0, 0.0] + } } - } - ] - }); + ] + }); + processed += 1; + if (processed == testFileList.length) { + done (); + } + }); } }); }); diff --git a/test/tests/importerobj_test.js b/test/tests/importerobj_test.js index c1df2df..6458ac9 100644 --- a/test/tests/importerobj_test.js +++ b/test/tests/importerobj_test.js @@ -2,580 +2,622 @@ var assert = require ('assert'); var testFiles = require ('../utils/testfiles.js'); var testUtils = require ('../utils/testutils.js'); -describe ('Obj Importer', function() { - it ('single_triangle.obj', function () { - var model = testFiles.ImportObjFile ('single_triangle.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] +describe ('Obj Importer', function () { + it ('single_triangle.obj', function (done) { + testFiles.ImportObjFile ('single_triangle.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('two_triangles.obj', function () { - var model = testFiles.ImportObjFile ('two_triangles.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - }, - { - vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('two_triangles.obj', function (done) { + testFiles.ImportObjFile ('two_triangles.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + }, + { + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_rectangle.obj', function () { - var model = testFiles.ImportObjFile ('single_rectangle.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - }, - { - vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_rectangle.obj', function (done) { + testFiles.ImportObjFile ('single_rectangle.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + }, + { + vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_triangle_with_comments.obj', function () { - var model = testFiles.ImportObjFile ('single_triangle_with_comments.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MyMeshName', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_triangle_with_comments.obj', function (done) { + testFiles.ImportObjFile ('single_triangle_with_comments.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MyMeshName', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_triangle_negative_indices.obj', function () { - var model = testFiles.ImportObjFile ('single_triangle_negative_indices.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_triangle_negative_indices.obj', function (done) { + testFiles.ImportObjFile ('single_triangle_negative_indices.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_triangle_with_normals_and_uvs.obj', function () { - var model = testFiles.ImportObjFile ('single_triangle_with_normals_and_uvs.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [0, 0, 1, 0, 1, 1], - mat : 0 - } - ] - } - ] + it ('single_triangle_with_normals_and_uvs.obj', function (done) { + testFiles.ImportObjFile ('single_triangle_with_normals_and_uvs.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [0, 0, 1, 0, 1, 1], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_triangle_in_mesh.obj', function () { - var model = testFiles.ImportObjFile ('single_triangle_in_mesh.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MeshName', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_triangle_in_mesh.obj', function (done) { + testFiles.ImportObjFile ('single_triangle_in_mesh.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MeshName', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('two_triangles_in_meshes.obj', function () { - var model = testFiles.ImportObjFile ('two_triangles_in_meshes.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MeshName1', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - }, - { - name : 'MeshName2', - triangles : [ - { - vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('two_triangles_in_meshes.obj', function (done) { + testFiles.ImportObjFile ('two_triangles_in_meshes.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MeshName1', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + }, + { + name : 'MeshName2', + triangles : [ + { + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('empty_meshes.obj', function () { - var model = testFiles.ImportObjFile ('empty_meshes.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MeshName1', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - }, - { - name : 'MeshName2', - triangles : [ - { - vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('empty_meshes.obj', function (done) { + testFiles.ImportObjFile ('empty_meshes.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MeshName1', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + }, + { + name : 'MeshName2', + triangles : [ + { + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_triangle_with_material.obj', function () { - var model = testFiles.ImportObjFile ('single_triangle_with_material.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : 'MaterialName1' }, - { name : 'MaterialName2' } - ], - meshes : [ - { - name : 'MeshName', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_triangle_with_material.obj', function (done) { + testFiles.ImportObjFile ('single_triangle_with_material.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : 'MaterialName1' }, + { name : 'MaterialName2' } + ], + meshes : [ + { + name : 'MeshName', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('two_triangles_with_material.obj', function () { - var model = testFiles.ImportObjFile ('two_triangles_with_material.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : 'MaterialName1' }, - { name : 'MaterialName2' } - ], - meshes : [ - { - name : 'MeshName', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - }, - { - vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 1 - } - ] - } - ] + it ('two_triangles_with_material.obj', function (done) { + testFiles.ImportObjFile ('two_triangles_with_material.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : 'MaterialName1' }, + { name : 'MaterialName2' } + ], + meshes : [ + { + name : 'MeshName', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + }, + { + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 1 + } + ] + } + ] + }); + done (); }); }); - it ('two_meshes_same_vertices.obj', function () { - var model = testFiles.ImportObjFile ('two_meshes_same_vertices.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MeshName1', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - }, - { - name : 'MeshName2', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 0, 0, 1], - normals : [0, -1, 0, 0, -1, 0, 0, -1, 0], - uvs : [], - mat : 0 - } - ] - } - ] + it ('two_meshes_same_vertices.obj', function (done) { + testFiles.ImportObjFile ('two_meshes_same_vertices.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MeshName1', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + }, + { + name : 'MeshName2', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 0, 0, 1], + normals : [0, -1, 0, 0, -1, 0, 0, -1, 0], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('two_meshes_with_same_name.obj', function () { - var model = testFiles.ImportObjFile ('two_meshes_with_same_name.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MeshName', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - }, - { - vertices : [0, 0, 0, 1, 0, 0, 0, 0, 1], - normals : [0, -1, 0, 0, -1, 0, 0, -1, 0], - uvs : [], - mat : 0 - } - ] - } - ] + it ('two_meshes_with_same_name.obj', function (done) { + testFiles.ImportObjFile ('two_meshes_with_same_name.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MeshName', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + }, + { + vertices : [0, 0, 0, 1, 0, 0, 0, 0, 1], + normals : [0, -1, 0, 0, -1, 0, 0, -1, 0], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('rectangle_with_texture.obj', function () { - var model = testFiles.ImportObjFile ('rectangle_with_texture.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : 'Material' } - ], - meshes : [ - { - name : 'Mesh', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [0, 0, 1, 0, 1, 1], - mat : 0 - }, - { - vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [0, 0, 1, 1, 0, 1], - mat : 0 - } - ] - } - ] + it ('rectangle_with_texture.obj', function (done) { + testFiles.ImportObjFile ('rectangle_with_texture.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : 'Material' } + ], + meshes : [ + { + name : 'Mesh', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [0, 0, 1, 0, 1, 1], + mat : 0 + }, + { + vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [0, 0, 1, 1, 0, 1], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('two_materials_same_texture.obj', function () { - var model = testFiles.ImportObjFile ('two_materials_same_texture.obj'); - assert.strictEqual (model.GetMaterial (0).diffuseMap.url, model.GetMaterial (1).diffuseMap.url); - assert.strictEqual (model.GetMaterial (0).diffuseMap.buffer.byteLength, model.GetMaterial (1).diffuseMap.buffer.byteLength); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : 'Material1' }, - { name : 'Material2' } - ], - meshes : [ - { - name : 'Mesh', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [0, 0, 1, 0, 1, 1], - mat : 0 - }, - { - vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [0, 0, 1, 1, 0, 1], - mat : 1 - } - ] - } - ] + it ('two_materials_same_texture.obj', function (done) { + testFiles.ImportObjFile ('two_materials_same_texture.obj', function (model) { + assert.strictEqual (model.GetMaterial (0).diffuseMap.url, model.GetMaterial (1).diffuseMap.url); + assert.strictEqual (model.GetMaterial (0).diffuseMap.buffer.byteLength, model.GetMaterial (1).diffuseMap.buffer.byteLength); + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : 'Material1' }, + { name : 'Material2' } + ], + meshes : [ + { + name : 'Mesh', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [0, 0, 1, 0, 1, 1], + mat : 0 + }, + { + vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [0, 0, 1, 1, 0, 1], + mat : 1 + } + ] + } + ] + }); + done (); }); }); - it ('cube_with_materials.obj', function () { - var model = testFiles.ImportObjFile ('cube_with_materials.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'Red' }, - { name : 'Green' }, - { name : 'Blue' }, - { name : 'White' }, - { name : 'Texture' } - ], - meshes : [ - { - name : 'Cube', - vertexCount : 8, - normalCount : 6, - uvCount : 4, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_with_materials.obj', function (done) { + testFiles.ImportObjFile ('cube_with_materials.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'Red' }, + { name : 'Green' }, + { name : 'Blue' }, + { name : 'White' }, + { name : 'Texture' } + ], + meshes : [ + { + name : 'Cube', + vertexCount : 8, + normalCount : 6, + uvCount : 4, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); - it ('cube_rgb.obj', function () { - var model = testFiles.ImportObjFile ('cube_rgb.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'Red' }, - { name : 'Green' }, - { name : 'Blue' }, - { name : 'White' } - ], - meshes : [ - { - name : 'Cube', - vertexCount : 8, - normalCount : 6, - uvCount : 4, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_rgb.obj', function (done) { + testFiles.ImportObjFile ('cube_rgb.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'Red' }, + { name : 'Green' }, + { name : 'Blue' }, + { name : 'White' } + ], + meshes : [ + { + name : 'Cube', + vertexCount : 8, + normalCount : 6, + uvCount : 4, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); - it ('cube_with_materials_comments.obj', function () { - var model = testFiles.ImportObjFile ('cube_with_materials_comments.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'Red' }, - { name : 'Green' }, - { name : 'Blue' }, - { name : 'White' }, - { name : 'Texture' } - ], - meshes : [ - { - name : 'Cube', - vertexCount : 8, - normalCount : 6, - uvCount : 4, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_with_materials_comments.obj', function (done) { + testFiles.ImportObjFile ('cube_with_materials_comments.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'Red' }, + { name : 'Green' }, + { name : 'Blue' }, + { name : 'White' }, + { name : 'Texture' } + ], + meshes : [ + { + name : 'Cube', + vertexCount : 8, + normalCount : 6, + uvCount : 4, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); - it ('cube with white spaces.obj', function () { - var model = testFiles.ImportObjFile ('cube with white spaces.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'Red Color' }, - { name : 'Green Color' }, - { name : 'Blue Color' }, - { name : 'White Color' }, - { name : 'Texture Color' } - ], - meshes : [ - { - name : 'Cube Mesh', - vertexCount : 8, - normalCount : 6, - uvCount : 4, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube with white spaces.obj', function (done) { + testFiles.ImportObjFile ('cube with white spaces.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'Red Color' }, + { name : 'Green Color' }, + { name : 'Blue Color' }, + { name : 'White Color' }, + { name : 'Texture Color' } + ], + meshes : [ + { + name : 'Cube Mesh', + vertexCount : 8, + normalCount : 6, + uvCount : 4, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); - it ('icosahedron.obj', function () { - var model = testFiles.ImportObjFile ('icosahedron.obj'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : 'Blue' } - ], - meshes : [ - { - name : 'Icosahedron', - vertexCount : 12, - normalCount : 20, - uvCount : 0, - triangleCount : 20, - boundingBox : { - min : [-0.85065080835204, -0.85065080835204, -0.85065080835204], - max : [0.85065080835204, 0.85065080835204, 0.85065080835204] + it ('icosahedron.obj', function (done) { + testFiles.ImportObjFile ('icosahedron.obj', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : 'Blue' } + ], + meshes : [ + { + name : 'Icosahedron', + vertexCount : 12, + normalCount : 20, + uvCount : 0, + triangleCount : 20, + boundingBox : { + min : [-0.85065080835204, -0.85065080835204, -0.85065080835204], + max : [0.85065080835204, 0.85065080835204, 0.85065080835204] + } } - } - ] + ] + }); + done (); }); }); - it ('hundred_cubes.obj', function () { - var model = testFiles.ImportObjFile ('hundred_cubes.obj'); - assert (OV.CheckModel (model)); - assert.strictEqual (model.MaterialCount (), 3); - assert.strictEqual (model.MeshCount (), 100); + it ('hundred_cubes.obj', function (done) { + testFiles.ImportObjFile ('hundred_cubes.obj', function (model) { + assert (OV.CheckModel (model)); + assert.strictEqual (model.MaterialCount (), 3); + assert.strictEqual (model.MeshCount (), 100); + done (); + }); }); }); diff --git a/test/tests/importeroff_test.js b/test/tests/importeroff_test.js index b05be9e..d44b443 100644 --- a/test/tests/importeroff_test.js +++ b/test/tests/importeroff_test.js @@ -2,136 +2,147 @@ var assert = require ('assert'); var testFiles = require ('../utils/testfiles.js'); var testUtils = require ('../utils/testutils.js'); -describe ('Off Importer', function() { - it ('single_triangle.off', function () { - var model = testFiles.ImportOffFile ('single_triangle.off'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] +describe ('Off Importer', function () { + it ('single_triangle.off', function (done) { + testFiles.ImportOffFile ('single_triangle.off', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('two_triangles.off', function () { - var model = testFiles.ImportOffFile ('two_triangles.off'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - }, - { - vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('two_triangles.off', function (done) { + testFiles.ImportOffFile ('two_triangles.off', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + }, + { + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_rectangle.off', function () { - var model = testFiles.ImportOffFile ('single_rectangle.off'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - }, - { - vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_rectangle.off', function (done) { + testFiles.ImportOffFile ('single_rectangle.off', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + }, + { + vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_triangle_with_comments.off', function () { - var model = testFiles.ImportOffFile ('single_triangle_with_comments.off'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_triangle_with_comments.off', function (done) { + testFiles.ImportOffFile ('single_triangle_with_comments.off', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); + }); - it ('cube.off', function () { - var model = testFiles.ImportOffFile ('cube.off'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 8, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube.off', function (done) { + testFiles.ImportOffFile ('cube.off', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 8, + normalCount : 12, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); }); diff --git a/test/tests/importerply_test.js b/test/tests/importerply_test.js index c9a8b8e..acad183 100644 --- a/test/tests/importerply_test.js +++ b/test/tests/importerply_test.js @@ -3,210 +3,226 @@ var testFiles = require ('../utils/testfiles.js'); var testUtils = require ('../utils/testutils.js'); describe ('Ply Importer', function() { - it ('single_triangle.ply', function () { - var model = testFiles.ImportPlyFile ('single_triangle.ply'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_triangle.ply', function (done) { + var model = testFiles.ImportPlyFile ('single_triangle.ply', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('two_triangles.ply', function () { - var model = testFiles.ImportPlyFile ('two_triangles.ply'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - }, - { - vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('two_triangles.ply', function (done) { + var model = testFiles.ImportPlyFile ('two_triangles.ply', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + }, + { + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_rectangle.ply', function () { - var model = testFiles.ImportPlyFile ('single_rectangle.ply'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - }, - { - vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_rectangle.ply', function (done) { + var model = testFiles.ImportPlyFile ('single_rectangle.ply', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + }, + { + vertices : [0, 0, 0, 1, 1, 0, 0, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_triangle_with_comments.ply', function () { - var model = testFiles.ImportPlyFile ('single_triangle_with_comments.ply'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 + it ('single_triangle_with_comments.ply', function (done) { + var model = testFiles.ImportPlyFile ('single_triangle_with_comments.ply', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); + }); + }); + + it ('cube.ply', function (done) { + var model = testFiles.ImportPlyFile ('cube.ply', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 8, + normalCount : 12, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] } - ] - } - ] + } + ] + }); + done (); }); }); - it ('cube.ply', function () { - var model = testFiles.ImportPlyFile ('cube.ply'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 8, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_meshlab_ascii.ply', function (done) { + var model = testFiles.ImportPlyFile ('cube_meshlab_ascii.ply', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 8, + normalCount : 12, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] - }); - }); - - it ('cube_meshlab_ascii.ply', function () { - var model = testFiles.ImportPlyFile ('cube_meshlab_ascii.ply'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 8, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] - } - } - ] + ] + }); + done (); }); }); - it ('cube_meshlab_binary.ply', function () { - var model = testFiles.ImportPlyFile ('cube_meshlab_binary.ply'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 8, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_meshlab_binary.ply', function (done) { + var model = testFiles.ImportPlyFile ('cube_meshlab_binary.ply', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 8, + normalCount : 12, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); - it ('cube_rgb_binary.ply', function () { - var model = testFiles.ImportPlyFile ('cube_rgb_binary.ply'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '#cc0000ff' }, - { name : '#00cc00ff' }, - { name : '#0000ccff' }, - { name : '#cccccc7f' } - ], - meshes : [ - { - name : '', - vertexCount : 8, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_rgb_binary.ply', function (done) { + var model = testFiles.ImportPlyFile ('cube_rgb_binary.ply', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '#cc0000ff' }, + { name : '#00cc00ff' }, + { name : '#0000ccff' }, + { name : '#cccccc7f' } + ], + meshes : [ + { + name : '', + vertexCount : 8, + normalCount : 12, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); }); diff --git a/test/tests/importerstl_test.js b/test/tests/importerstl_test.js index d7f7d5c..f21ca41 100644 --- a/test/tests/importerstl_test.js +++ b/test/tests/importerstl_test.js @@ -3,202 +3,218 @@ var testFiles = require ('../utils/testfiles.js'); var testUtils = require ('../utils/testutils.js'); describe ('Stl Importer', function() { - it ('single_triangle.stl', function () { - var model = testFiles.ImportStlFile ('single_triangle.stl'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MeshName', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_triangle.stl', function (done) { + testFiles.ImportStlFile ('single_triangle.stl', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MeshName', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_triangle_with_comments.stl', function () { - var model = testFiles.ImportStlFile ('single_triangle_with_comments.stl'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MeshName', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_triangle_with_comments.stl', function (done) { + testFiles.ImportStlFile ('single_triangle_with_comments.stl', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MeshName', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('single_triangle_no_normal.stl', function () { - var model = testFiles.ImportStlFile ('single_triangle_no_normal.stl'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MeshName', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('single_triangle_no_normal.stl', function (done) { + testFiles.ImportStlFile ('single_triangle_no_normal.stl', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MeshName', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('two_triangles.stl', function () { - var model = testFiles.ImportStlFile ('two_triangles.stl'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObject (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'MeshName', - triangles : [ - { - vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - }, - { - vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], - normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], - uvs : [], - mat : 0 - } - ] - } - ] + it ('two_triangles.stl', function (done) { + testFiles.ImportStlFile ('two_triangles.stl', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObject (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'MeshName', + triangles : [ + { + vertices : [0, 0, 0, 1, 0, 0, 1, 1, 0], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + }, + { + vertices : [0, 0, 1, 1, 0, 1, 1, 1, 1], + normals : [0, 0, 1, 0, 0, 1, 0, 0, 1], + uvs : [], + mat : 0 + } + ] + } + ] + }); + done (); }); }); - it ('stl_ascii.stl', function () { - var model = testFiles.ImportStlFile ('stl_ascii.stl'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'Untitled-5427e5af', - vertexCount : 1716, - normalCount : 572, - uvCount : 0, - triangleCount : 572, - boundingBox : { - min : [0, -1.10792799192095, 0], - max : [4.94407346265022, 3.31831671830375, 1.2] + it ('stl_ascii.stl', function (done) { + testFiles.ImportStlFile ('stl_ascii.stl', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'Untitled-5427e5af', + vertexCount : 1716, + normalCount : 572, + uvCount : 0, + triangleCount : 572, + boundingBox : { + min : [0, -1.10792799192095, 0], + max : [4.94407346265022, 3.31831671830375, 1.2] + } } - } - ] + ] + }); + done (); }); }); - it ('stl_binary.stl', function () { - var model = testFiles.ImportStlFile ('stl_binary.stl'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 2184, - normalCount : 728, - uvCount : 0, - triangleCount : 728, - boundingBox : { - min : [0, -1.1079280376434326, 0], - max : [5.70156717300415, 3.318316698074341, 1.2000000476837158] + it ('stl_binary.stl', function (done) { + testFiles.ImportStlFile ('stl_binary.stl', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 2184, + normalCount : 728, + uvCount : 0, + triangleCount : 728, + boundingBox : { + min : [0, -1.1079280376434326, 0], + max : [5.70156717300415, 3.318316698074341, 1.2000000476837158] + } } - } - ] + ] + }); + done (); }); }); - it ('cube_meshlab_ascii.stl', function () { - var model = testFiles.ImportStlFile ('cube_meshlab_ascii.stl'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : 'STL generated by MeshLab', - vertexCount : 36, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_meshlab_ascii.stl', function (done) { + testFiles.ImportStlFile ('cube_meshlab_ascii.stl', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : 'STL generated by MeshLab', + vertexCount : 36, + normalCount : 12, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); - it ('cube_meshlab_binary.stl', function () { - var model = testFiles.ImportStlFile ('cube_meshlab_binary.stl'); - assert (OV.CheckModel (model)); - assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { - name : '', - materials : [ - { name : '' } - ], - meshes : [ - { - name : '', - vertexCount : 36, - normalCount : 12, - uvCount : 0, - triangleCount : 12, - boundingBox : { - min : [0, 0, 0], - max : [1, 1, 1] + it ('cube_meshlab_binary.stl', function (done) { + testFiles.ImportStlFile ('cube_meshlab_binary.stl', function (model) { + assert (OV.CheckModel (model)); + assert.deepStrictEqual (testUtils.ModelToObjectSimple (model), { + name : '', + materials : [ + { name : '' } + ], + meshes : [ + { + name : '', + vertexCount : 36, + normalCount : 12, + uvCount : 0, + triangleCount : 12, + boundingBox : { + min : [0, 0, 0], + max : [1, 1, 1] + } } - } - ] + ] + }); + done (); }); }); }); diff --git a/test/utils/testfiles.js b/test/utils/testfiles.js index 4b87c90..fc4d519 100644 --- a/test/utils/testfiles.js +++ b/test/utils/testfiles.js @@ -2,37 +2,37 @@ var testUtils = require ('./testutils.js'); module.exports = { - ImportObjFile : function (fileName) + ImportObjFile : function (fileName, onReady) { var importer = new OV.ImporterObj (); - return this.ImportFile (importer, OV.FileFormat.Text, 'obj', fileName); + this.ImportFile (importer, OV.FileFormat.Text, 'obj', fileName, onReady); }, - ImportStlFile : function (fileName) + ImportStlFile : function (fileName, onReady) { var importer = new OV.ImporterStl (); - return this.ImportFile (importer, OV.FileFormat.Binary, 'stl', fileName); + this.ImportFile (importer, OV.FileFormat.Binary, 'stl', fileName, onReady); }, - ImportOffFile : function (fileName) + ImportOffFile : function (fileName, onReady) { var importer = new OV.ImporterOff (); - return this.ImportFile (importer, OV.FileFormat.Text, 'off', fileName); + this.ImportFile (importer, OV.FileFormat.Text, 'off', fileName, onReady); }, - ImportPlyFile : function (fileName) + ImportPlyFile : function (fileName, onReady) { var importer = new OV.ImporterPly (); - return this.ImportFile (importer, OV.FileFormat.Binary, 'ply', fileName); + this.ImportFile (importer, OV.FileFormat.Binary, 'ply', fileName, onReady); }, - Import3dsFile : function (fileName) + Import3dsFile : function (fileName, onReady) { var importer = new OV.Importer3ds (); - return this.ImportFile (importer, OV.FileFormat.Binary, '3ds', fileName); + this.ImportFile (importer, OV.FileFormat.Binary, '3ds', fileName, onReady); }, - ImportGltfFile : function (folderName, fileName) + ImportGltfFile : function (folderName, fileName, onReady) { let extension = OV.GetFileExtension (fileName); let format = OV.FileFormat.Text; @@ -40,10 +40,10 @@ module.exports = format = OV.FileFormat.Binary; } var importer = new OV.ImporterGltf (); - return this.ImportFile (importer, format, 'gltf/' + folderName, fileName); + this.ImportFile (importer, format, 'gltf/' + folderName, fileName, onReady); }, - ImportFile : function (importer, format, folder, fileName) + ImportFile : function (importer, format, folder, fileName, onReady) { var content = null; if (format == OV.FileFormat.Text) { @@ -77,9 +77,14 @@ module.exports = }, getTextureBuffer : function (filePath) { return buffers.GetTextureBuffer (filePath); + }, + onSuccess : function () { + let model = importer.GetModel (); + onReady (model); + }, + onError : function () { + onReady (model); } }); - let model = importer.GetModel (); - return model; } }