Rename ImportBuffers to ImporterFileAccessor.

This commit is contained in:
kovacsv 2021-11-19 08:00:32 +01:00
parent 33a8464321
commit 8fa45a8b95
2 changed files with 32 additions and 33 deletions

View File

@ -34,42 +34,41 @@ OV.ImportResult = class
} }
}; };
OV.ImportBuffers = class OV.ImporterFileAccessor = class
{ {
constructor (getBufferCallback) constructor (getBufferCallback)
{ {
this.getBufferCallback = getBufferCallback; this.getBufferCallback = getBufferCallback;
this.fileBuffers = {}; this.fileBuffers = new Map ();
this.textureBuffers = {}; this.textureBuffers = new Map ();
} }
GetFileBuffer (filePath) GetFileBuffer (filePath)
{ {
let fileName = OV.GetFileName (filePath); let fileName = OV.GetFileName (filePath);
let buffer = this.fileBuffers[fileName]; if (this.fileBuffers.has (fileName)) {
if (buffer === undefined) { return this.fileBuffers.get (fileName);
buffer = this.getBufferCallback (fileName);
this.fileBuffers[fileName] = buffer;
} }
let buffer = this.getBufferCallback (fileName);
this.fileBuffers.set (fileName, buffer);
return buffer; return buffer;
} }
GetTextureBuffer (filePath) GetTextureBuffer (filePath)
{ {
let fileName = OV.GetFileName (filePath); let fileName = OV.GetFileName (filePath);
let buffer = this.textureBuffers[fileName]; if (this.textureBuffers.has (fileName)) {
if (buffer === undefined) { return this.textureBuffers.get (fileName);
let textureBuffer = this.getBufferCallback (fileName);
if (textureBuffer !== null) {
buffer = {
url : OV.CreateObjectUrl (textureBuffer),
buffer : textureBuffer
};
} else {
buffer = null;
}
this.textureBuffers[fileName] = buffer;
} }
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; return buffer;
} }
}; };
@ -176,7 +175,7 @@ OV.Importer = class
this.usedFiles.push (mainFile.file.name); this.usedFiles.push (mainFile.file.name);
let importer = mainFile.importer; let importer = mainFile.importer;
let buffers = new OV.ImportBuffers ((fileName) => { let fileAccessor = new OV.ImporterFileAccessor ((fileName) => {
let fileBuffer = null; let fileBuffer = null;
let file = this.fileList.FindFileByPath (fileName); let file = this.fileList.FindFileByPath (fileName);
if (file === null || file.content === null) { if (file === null || file.content === null) {
@ -196,10 +195,10 @@ OV.Importer = class
return material; return material;
}, },
getFileBuffer : (filePath) => { getFileBuffer : (filePath) => {
return buffers.GetFileBuffer (filePath); return fileAccessor.GetFileBuffer (filePath);
}, },
getTextureBuffer : (filePath) => { getTextureBuffer : (filePath) => {
return buffers.GetTextureBuffer (filePath); return fileAccessor.GetTextureBuffer (filePath);
}, },
onSuccess : () => { onSuccess : () => {
let result = new OV.ImportResult (); let result = new OV.ImportResult ();

View File

@ -3,43 +3,43 @@ var testUtils = require ('./testutils.js');
module.exports = module.exports =
{ {
ImportObjFile : function (fileName, onReady) ImportObjFile : function (fileName, onReady)
{ {
var importer = new OV.ImporterObj (); var importer = new OV.ImporterObj ();
this.ImportFile (importer, 'obj', fileName, onReady); this.ImportFile (importer, 'obj', fileName, onReady);
}, },
ImportStlFile : function (fileName, onReady) ImportStlFile : function (fileName, onReady)
{ {
var importer = new OV.ImporterStl (); var importer = new OV.ImporterStl ();
this.ImportFile (importer, 'stl', fileName, onReady); this.ImportFile (importer, 'stl', fileName, onReady);
}, },
ImportOffFile : function (fileName, onReady) ImportOffFile : function (fileName, onReady)
{ {
var importer = new OV.ImporterOff (); var importer = new OV.ImporterOff ();
this.ImportFile (importer, 'off', fileName, onReady); this.ImportFile (importer, 'off', fileName, onReady);
}, },
ImportPlyFile : function (fileName, onReady) ImportPlyFile : function (fileName, onReady)
{ {
var importer = new OV.ImporterPly (); var importer = new OV.ImporterPly ();
this.ImportFile (importer, 'ply', fileName, onReady); this.ImportFile (importer, 'ply', fileName, onReady);
}, },
Import3dsFile : function (fileName, onReady) Import3dsFile : function (fileName, onReady)
{ {
var importer = new OV.Importer3ds (); var importer = new OV.Importer3ds ();
this.ImportFile (importer, '3ds', fileName, onReady); this.ImportFile (importer, '3ds', fileName, onReady);
}, },
ImportGltfFile : function (folderName, fileName, onReady) ImportGltfFile : function (folderName, fileName, onReady)
{ {
var importer = new OV.ImporterGltf (); var importer = new OV.ImporterGltf ();
this.ImportFile (importer, 'gltf/' + folderName, fileName, onReady); this.ImportFile (importer, 'gltf/' + folderName, fileName, onReady);
}, },
ImportO3dvFile : function (fileName, onReady) ImportO3dvFile : function (fileName, onReady)
{ {
var importer = new OV.ImporterO3dv (); var importer = new OV.ImporterO3dv ();
this.ImportFile (importer, 'o3dv', fileName, onReady); this.ImportFile (importer, 'o3dv', fileName, onReady);
}, },
@ -48,7 +48,7 @@ module.exports =
{ {
let content = testUtils.GetArrayBufferFileContent (folder, fileName); let content = testUtils.GetArrayBufferFileContent (folder, fileName);
var extension = OV.GetFileExtension (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); let fileContent = testUtils.GetArrayBufferFileContent (folder, filePath);
return fileContent; return fileContent;
}); });
@ -58,10 +58,10 @@ module.exports =
return material; return material;
}, },
getFileBuffer : function (filePath) { getFileBuffer : function (filePath) {
return buffers.GetFileBuffer (filePath); return fileAccessor.GetFileBuffer (filePath);
}, },
getTextureBuffer : function (filePath) { getTextureBuffer : function (filePath) {
return buffers.GetTextureBuffer (filePath); return fileAccessor.GetTextureBuffer (filePath);
}, },
onSuccess : function () { onSuccess : function () {
let model = importer.GetModel (); let model = importer.GetModel ();
@ -71,7 +71,7 @@ module.exports =
onReady (model); onReady (model);
}, },
onComplete : function () { onComplete : function () {
} }
}); });
} }