Async importers.

This commit is contained in:
Viktor Kovacs 2021-04-15 14:52:16 +02:00
parent a99730a95f
commit 9f9851a2ec
18 changed files with 1770 additions and 1583 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -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)

View File

@ -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)
{
}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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);
});
});
});

View File

@ -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 ();
});
});
});

View File

@ -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 ();
}
});

View File

@ -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 ();
}
});
}
});
});

File diff suppressed because it is too large Load Diff

View File

@ -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 ();
});
});
});

View File

@ -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 ();
});
});
});

View File

@ -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 ();
});
});
});

View File

@ -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;
}
}