Revoking urls is now the responsibility of the main importer object.
This commit is contained in:
parent
2450cb8feb
commit
0c03fb3bca
@ -179,21 +179,6 @@ OV.FileList = class
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
OV.RevokeModelUrls = function (model)
|
|
||||||
{
|
|
||||||
if (model === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (let i = 0; i < model.MaterialCount (); i++) {
|
|
||||||
let material = model.GetMaterial (i);
|
|
||||||
material.EnumerateTextureMaps (function (texture) {
|
|
||||||
if (texture.url !== null) {
|
|
||||||
OV.RevokeObjectUrl (texture.url);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
OV.ImportErrorCode =
|
OV.ImportErrorCode =
|
||||||
{
|
{
|
||||||
NoImportableFile : 1,
|
NoImportableFile : 1,
|
||||||
@ -217,8 +202,8 @@ OV.ImportResult = class
|
|||||||
this.model = null;
|
this.model = null;
|
||||||
this.mainFile = null;
|
this.mainFile = null;
|
||||||
this.upVector = null;
|
this.upVector = null;
|
||||||
this.usedFiles = [];
|
this.usedFiles = null;
|
||||||
this.missingFiles = [];
|
this.missingFiles = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -275,6 +260,8 @@ OV.Importer = class
|
|||||||
new OV.ImporterGltf ()
|
new OV.ImporterGltf ()
|
||||||
];
|
];
|
||||||
this.fileList = new OV.FileList (this.importers);
|
this.fileList = new OV.FileList (this.importers);
|
||||||
|
this.model = null;
|
||||||
|
this.usedFiles = [];
|
||||||
this.missingFiles = [];
|
this.missingFiles = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,9 +283,14 @@ OV.Importer = class
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.RevokeModelUrls ();
|
||||||
|
this.model = null;
|
||||||
|
this.usedFiles = [];
|
||||||
|
this.missingFiles = [];
|
||||||
|
this.usedFiles.push (mainFile.file.name);
|
||||||
|
|
||||||
let result = new OV.ImportResult ();
|
let result = new OV.ImportResult ();
|
||||||
result.mainFile = mainFile.file.name;
|
result.mainFile = mainFile.file.name;
|
||||||
result.usedFiles.push (mainFile.file.name);
|
|
||||||
|
|
||||||
let obj = this;
|
let obj = this;
|
||||||
let importer = mainFile.importer;
|
let importer = mainFile.importer;
|
||||||
@ -307,11 +299,10 @@ OV.Importer = class
|
|||||||
let file = obj.fileList.FindFileByPath (fileName);
|
let file = obj.fileList.FindFileByPath (fileName);
|
||||||
if (file === null || file.content === null) {
|
if (file === null || file.content === null) {
|
||||||
obj.missingFiles.push (fileName);
|
obj.missingFiles.push (fileName);
|
||||||
result.missingFiles.push (fileName);
|
|
||||||
fileBuffer = null;
|
fileBuffer = null;
|
||||||
} else {
|
} else {
|
||||||
fileBuffer = file.content;
|
fileBuffer = file.content;
|
||||||
result.usedFiles.push (fileName);
|
obj.usedFiles.push (fileName);
|
||||||
}
|
}
|
||||||
return fileBuffer;
|
return fileBuffer;
|
||||||
});
|
});
|
||||||
@ -336,8 +327,12 @@ OV.Importer = class
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.model = importer.GetModel ();
|
this.model = importer.GetModel ();
|
||||||
result.model.SetName (mainFile.file.name);
|
this.model.SetName (mainFile.file.name);
|
||||||
|
|
||||||
|
result.model = this.model;
|
||||||
|
result.usedFiles = this.usedFiles;
|
||||||
|
result.missingFiles = this.missingFiles;
|
||||||
result.upVector = importer.GetUpDirection ();
|
result.upVector = importer.GetUpDirection ();
|
||||||
callbacks.success (result);
|
callbacks.success (result);
|
||||||
}
|
}
|
||||||
@ -372,7 +367,6 @@ OV.Importer = class
|
|||||||
if (reset) {
|
if (reset) {
|
||||||
this.fileList = newFileList;
|
this.fileList = newFileList;
|
||||||
}
|
}
|
||||||
this.missingFiles = [];
|
|
||||||
this.fileList.GetContent (function () {
|
this.fileList.GetContent (function () {
|
||||||
onReady ();
|
onReady ();
|
||||||
});
|
});
|
||||||
@ -387,4 +381,19 @@ OV.Importer = class
|
|||||||
{
|
{
|
||||||
return this.fileList.IsOnlySource (source);
|
return this.fileList.IsOnlySource (source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RevokeModelUrls ()
|
||||||
|
{
|
||||||
|
if (this.model === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < this.model.MaterialCount (); i++) {
|
||||||
|
let material = this.model.GetMaterial (i);
|
||||||
|
material.EnumerateTextureMaps (function (texture) {
|
||||||
|
if (texture.url !== null) {
|
||||||
|
OV.RevokeObjectUrl (texture.url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -92,6 +92,26 @@ describe ('Importer Test', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it ('Multiple files', function () {
|
||||||
|
let files = [
|
||||||
|
new FileObject ('obj', 'cube_with_materials.obj'),
|
||||||
|
new FileObject ('obj', 'cube_with_materials.mtl'),
|
||||||
|
new FileObject ('obj', 'cube_texture.png')
|
||||||
|
]
|
||||||
|
|
||||||
|
let theImporter = new OV.Importer ();
|
||||||
|
ImportFilesWithImporter (theImporter, 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 files', function () {
|
it ('Missing files', function () {
|
||||||
let files = [];
|
let files = [];
|
||||||
files.push (new FileObject ('obj', 'cube_with_materials.obj'));
|
files.push (new FileObject ('obj', 'cube_with_materials.obj'));
|
||||||
@ -178,5 +198,39 @@ describe ('Importer Test', function () {
|
|||||||
assert.fail ();
|
assert.fail ();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it ('Reuse importer', function () {
|
||||||
|
let files1 = [
|
||||||
|
new FileObject ('obj', 'cube_with_materials.obj'),
|
||||||
|
new FileObject ('obj', 'cube_with_materials.mtl'),
|
||||||
|
new FileObject ('obj', 'cube_texture.png')
|
||||||
|
]
|
||||||
|
let files2 = [
|
||||||
|
new FileObject ('obj', 'single_triangle.obj')
|
||||||
|
];
|
||||||
|
|
||||||
|
let theImporter = new OV.Importer ();
|
||||||
|
ImportFilesWithImporter (theImporter, files1, {
|
||||||
|
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, []);
|
||||||
|
|
||||||
|
ImportFilesWithImporter (theImporter, files2, {
|
||||||
|
success : function (importer, importResult) {
|
||||||
|
assert (!OV.IsModelEmpty (importResult.model));
|
||||||
|
assert.deepStrictEqual (importResult.usedFiles, ['single_triangle.obj']);
|
||||||
|
assert.deepStrictEqual (importResult.missingFiles, []);
|
||||||
|
},
|
||||||
|
error : function (importer, importError) {
|
||||||
|
assert.fail ();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error : function (importer, importError) {
|
||||||
|
assert.fail ();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -14,7 +14,10 @@ global.URL = {
|
|||||||
createObjectURL : function () {
|
createObjectURL : function () {
|
||||||
objectUrlCounter += 1;
|
objectUrlCounter += 1;
|
||||||
return 'ObjectUrl:' + objectUrlCounter.toString ();
|
return 'ObjectUrl:' + objectUrlCounter.toString ();
|
||||||
}
|
},
|
||||||
|
revokeObjectURL : function () {
|
||||||
|
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
global.FileObject = function (folderName, fileName)
|
global.FileObject = function (folderName, fileName)
|
||||||
|
|||||||
@ -71,9 +71,6 @@ OV.Website = class
|
|||||||
this.dialog.Hide ();
|
this.dialog.Hide ();
|
||||||
this.dialog = null;
|
this.dialog = null;
|
||||||
}
|
}
|
||||||
if (this.model !== null) {
|
|
||||||
OV.RevokeModelUrls (this.model);
|
|
||||||
}
|
|
||||||
this.model = null;
|
this.model = null;
|
||||||
this.parameters.introDiv.hide ();
|
this.parameters.introDiv.hide ();
|
||||||
this.ShowViewer (false);
|
this.ShowViewer (false);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user