diff --git a/source/import/importer.js b/source/import/importer.js index 1cfb89b..3d7ea41 100644 --- a/source/import/importer.js +++ b/source/import/importer.js @@ -34,42 +34,41 @@ OV.ImportResult = class } }; -OV.ImportBuffers = class +OV.ImporterFileAccessor = class { constructor (getBufferCallback) { this.getBufferCallback = getBufferCallback; - this.fileBuffers = {}; - this.textureBuffers = {}; + this.fileBuffers = new Map (); + this.textureBuffers = new Map (); } GetFileBuffer (filePath) { let fileName = OV.GetFileName (filePath); - let buffer = this.fileBuffers[fileName]; - if (buffer === undefined) { - buffer = this.getBufferCallback (fileName); - this.fileBuffers[fileName] = buffer; + if (this.fileBuffers.has (fileName)) { + return this.fileBuffers.get (fileName); } + let buffer = this.getBufferCallback (fileName); + this.fileBuffers.set (fileName, buffer); return buffer; } GetTextureBuffer (filePath) { let fileName = OV.GetFileName (filePath); - let buffer = this.textureBuffers[fileName]; - if (buffer === undefined) { - let textureBuffer = this.getBufferCallback (fileName); - if (textureBuffer !== null) { - buffer = { - url : OV.CreateObjectUrl (textureBuffer), - buffer : textureBuffer - }; - } else { - buffer = null; - } - this.textureBuffers[fileName] = buffer; + if (this.textureBuffers.has (fileName)) { + return this.textureBuffers.get (fileName); } + let buffer = null; + let textureBuffer = this.getBufferCallback (fileName); + if (textureBuffer !== null) { + buffer = { + url : OV.CreateObjectUrl (textureBuffer), + buffer : textureBuffer + }; + } + this.textureBuffers.set (fileName, buffer); return buffer; } }; @@ -176,7 +175,7 @@ OV.Importer = class this.usedFiles.push (mainFile.file.name); let importer = mainFile.importer; - let buffers = new OV.ImportBuffers ((fileName) => { + let fileAccessor = new OV.ImporterFileAccessor ((fileName) => { let fileBuffer = null; let file = this.fileList.FindFileByPath (fileName); if (file === null || file.content === null) { @@ -196,10 +195,10 @@ OV.Importer = class return material; }, getFileBuffer : (filePath) => { - return buffers.GetFileBuffer (filePath); + return fileAccessor.GetFileBuffer (filePath); }, getTextureBuffer : (filePath) => { - return buffers.GetTextureBuffer (filePath); + return fileAccessor.GetTextureBuffer (filePath); }, onSuccess : () => { let result = new OV.ImportResult (); diff --git a/test/utils/testfiles.js b/test/utils/testfiles.js index 5709025..6daa6d0 100644 --- a/test/utils/testfiles.js +++ b/test/utils/testfiles.js @@ -3,43 +3,43 @@ var testUtils = require ('./testutils.js'); module.exports = { ImportObjFile : function (fileName, onReady) - { + { var importer = new OV.ImporterObj (); this.ImportFile (importer, 'obj', fileName, onReady); }, ImportStlFile : function (fileName, onReady) - { + { var importer = new OV.ImporterStl (); this.ImportFile (importer, 'stl', fileName, onReady); }, ImportOffFile : function (fileName, onReady) - { + { var importer = new OV.ImporterOff (); this.ImportFile (importer, 'off', fileName, onReady); }, ImportPlyFile : function (fileName, onReady) - { + { var importer = new OV.ImporterPly (); this.ImportFile (importer, 'ply', fileName, onReady); }, Import3dsFile : function (fileName, onReady) - { + { var importer = new OV.Importer3ds (); this.ImportFile (importer, '3ds', fileName, onReady); }, ImportGltfFile : function (folderName, fileName, onReady) - { + { var importer = new OV.ImporterGltf (); this.ImportFile (importer, 'gltf/' + folderName, fileName, onReady); }, ImportO3dvFile : function (fileName, onReady) - { + { var importer = new OV.ImporterO3dv (); this.ImportFile (importer, 'o3dv', fileName, onReady); }, @@ -48,7 +48,7 @@ module.exports = { let content = testUtils.GetArrayBufferFileContent (folder, fileName); var extension = OV.GetFileExtension (fileName); - let buffers = new OV.ImportBuffers (function (filePath) { + let fileAccessor = new OV.ImporterFileAccessor (function (filePath) { let fileContent = testUtils.GetArrayBufferFileContent (folder, filePath); return fileContent; }); @@ -58,10 +58,10 @@ module.exports = return material; }, getFileBuffer : function (filePath) { - return buffers.GetFileBuffer (filePath); + return fileAccessor.GetFileBuffer (filePath); }, getTextureBuffer : function (filePath) { - return buffers.GetTextureBuffer (filePath); + return fileAccessor.GetTextureBuffer (filePath); }, onSuccess : function () { let model = importer.GetModel (); @@ -71,7 +71,7 @@ module.exports = onReady (model); }, onComplete : function () { - + } }); }