Pass original file name and extension to importers.
This commit is contained in:
parent
5bd71dd50c
commit
fb3cdbe83c
@ -139,7 +139,7 @@ OV.Importer = class
|
|||||||
return fileBuffer;
|
return fileBuffer;
|
||||||
});
|
});
|
||||||
|
|
||||||
importer.Import (mainFile.file.content, mainFile.file.extension, {
|
importer.Import (mainFile.file.name, mainFile.file.extension, mainFile.file.content, {
|
||||||
getDefaultMaterial : () => {
|
getDefaultMaterial : () => {
|
||||||
let material = new OV.Material (OV.MaterialType.Phong);
|
let material = new OV.Material (OV.MaterialType.Phong);
|
||||||
material.color = settings.defaultColor;
|
material.color = settings.defaultColor;
|
||||||
@ -152,12 +152,9 @@ OV.Importer = class
|
|||||||
return buffers.GetTextureBuffer (filePath);
|
return buffers.GetTextureBuffer (filePath);
|
||||||
},
|
},
|
||||||
onSuccess : () => {
|
onSuccess : () => {
|
||||||
this.model = importer.GetModel ();
|
|
||||||
this.model.SetName (mainFile.file.name);
|
|
||||||
|
|
||||||
let result = new OV.ImportResult ();
|
let result = new OV.ImportResult ();
|
||||||
result.mainFile = mainFile.file.name;
|
result.mainFile = mainFile.file.name;
|
||||||
result.model = this.model;
|
result.model = importer.GetModel ();
|
||||||
result.usedFiles = this.usedFiles;
|
result.usedFiles = this.usedFiles;
|
||||||
result.missingFiles = this.missingFiles;
|
result.missingFiles = this.missingFiles;
|
||||||
result.upVector = importer.GetUpDirection ();
|
result.upVector = importer.GetUpDirection ();
|
||||||
|
|||||||
@ -5,10 +5,11 @@ OV.ImporterBase = class
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Import (content, extension, callbacks)
|
Import (name, extension, content, callbacks)
|
||||||
{
|
{
|
||||||
this.Clear ();
|
this.Clear ();
|
||||||
|
|
||||||
|
this.name = name;
|
||||||
this.extension = extension;
|
this.extension = extension;
|
||||||
this.callbacks = callbacks;
|
this.callbacks = callbacks;
|
||||||
this.model = new OV.Model ();
|
this.model = new OV.Model ();
|
||||||
@ -22,6 +23,7 @@ OV.ImporterBase = class
|
|||||||
|
|
||||||
Clear ()
|
Clear ()
|
||||||
{
|
{
|
||||||
|
this.name = null;
|
||||||
this.extension = null;
|
this.extension = null;
|
||||||
this.callbacks = null;
|
this.callbacks = null;
|
||||||
this.model = null;
|
this.model = null;
|
||||||
@ -46,6 +48,7 @@ OV.ImporterBase = class
|
|||||||
}
|
}
|
||||||
|
|
||||||
OV.FinalizeModel (this.model, this.callbacks.getDefaultMaterial);
|
OV.FinalizeModel (this.model, this.callbacks.getDefaultMaterial);
|
||||||
|
|
||||||
callbacks.onSuccess ();
|
callbacks.onSuccess ();
|
||||||
callbacks.onComplete ();
|
callbacks.onComplete ();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -212,7 +212,7 @@ describe ('Exporter', function () {
|
|||||||
|
|
||||||
let contentBuffer = stlFile.GetBufferContent ();
|
let contentBuffer = stlFile.GetBufferContent ();
|
||||||
let importer = new OV.ImporterStl ();
|
let importer = new OV.ImporterStl ();
|
||||||
importer.Import (contentBuffer, 'stl', {
|
importer.Import (stlFile.GetName (), 'stl', contentBuffer, {
|
||||||
getDefaultMaterial () {
|
getDefaultMaterial () {
|
||||||
return new OV.Material (OV.MaterialType.Phong);
|
return new OV.Material (OV.MaterialType.Phong);
|
||||||
},
|
},
|
||||||
@ -306,7 +306,7 @@ describe ('Exporter', function () {
|
|||||||
|
|
||||||
let contentBuffer = plyFile.GetBufferContent ();
|
let contentBuffer = plyFile.GetBufferContent ();
|
||||||
let importer = new OV.ImporterPly ();
|
let importer = new OV.ImporterPly ();
|
||||||
importer.Import (contentBuffer, 'ply', {
|
importer.Import (plyFile.GetName (), 'ply', contentBuffer, {
|
||||||
getDefaultMaterial () {
|
getDefaultMaterial () {
|
||||||
return new OV.Material (OV.MaterialType.Phong);
|
return new OV.Material (OV.MaterialType.Phong);
|
||||||
},
|
},
|
||||||
@ -336,7 +336,7 @@ describe ('Exporter', function () {
|
|||||||
|
|
||||||
let contentBuffer = gltfFile.GetBufferContent ();
|
let contentBuffer = gltfFile.GetBufferContent ();
|
||||||
let importer = new OV.ImporterGltf ();
|
let importer = new OV.ImporterGltf ();
|
||||||
importer.Import (contentBuffer, 'gltf', {
|
importer.Import (gltfFile.GetName (), 'gltf', contentBuffer, {
|
||||||
getDefaultMaterial () {
|
getDefaultMaterial () {
|
||||||
return new OV.Material (OV.MaterialType.Phong);
|
return new OV.Material (OV.MaterialType.Phong);
|
||||||
},
|
},
|
||||||
@ -374,7 +374,7 @@ describe ('Exporter', function () {
|
|||||||
|
|
||||||
let contentBuffer = glbFile.GetBufferContent ();
|
let contentBuffer = glbFile.GetBufferContent ();
|
||||||
let importer = new OV.ImporterGltf ();
|
let importer = new OV.ImporterGltf ();
|
||||||
importer.Import (contentBuffer, 'glb', {
|
importer.Import (glbFile.GetName (), 'glb', contentBuffer, {
|
||||||
getDefaultMaterial () {
|
getDefaultMaterial () {
|
||||||
return new OV.Material (OV.MaterialType.Phong);
|
return new OV.Material (OV.MaterialType.Phong);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -312,7 +312,6 @@ describe ('Importer Test', function () {
|
|||||||
ImportFiles (files, {
|
ImportFiles (files, {
|
||||||
success : function (importer, importResult) {
|
success : function (importer, importResult) {
|
||||||
assert (!OV.IsModelEmpty (importResult.model));
|
assert (!OV.IsModelEmpty (importResult.model));
|
||||||
console.log (importResult.usedFiles);
|
|
||||||
assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']);
|
assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']);
|
||||||
assert.deepStrictEqual (importResult.missingFiles, []);
|
assert.deepStrictEqual (importResult.missingFiles, []);
|
||||||
done ();
|
done ();
|
||||||
|
|||||||
@ -52,7 +52,7 @@ module.exports =
|
|||||||
let fileContent = testUtils.GetArrayBufferFileContent (folder, filePath);
|
let fileContent = testUtils.GetArrayBufferFileContent (folder, filePath);
|
||||||
return fileContent;
|
return fileContent;
|
||||||
});
|
});
|
||||||
importer.Import (content, extension, {
|
importer.Import (fileName, extension, content, {
|
||||||
getDefaultMaterial : function () {
|
getDefaultMaterial : function () {
|
||||||
var material = new OV.Material (OV.MaterialType.Phong);
|
var material = new OV.Material (OV.MaterialType.Phong);
|
||||||
return material;
|
return material;
|
||||||
|
|||||||
@ -141,11 +141,12 @@ OV.Navigator = class
|
|||||||
|
|
||||||
FillTree (importResult)
|
FillTree (importResult)
|
||||||
{
|
{
|
||||||
this.titleDiv.html (importResult.mainFile).attr ('title', importResult.mainFile);
|
const model = importResult.model;
|
||||||
|
const mainFile = importResult.mainFile;
|
||||||
|
const usedFiles = importResult.usedFiles;
|
||||||
|
const missingFiles = importResult.missingFiles;
|
||||||
|
|
||||||
let model = importResult.model;
|
this.titleDiv.html (mainFile).attr ('title', mainFile);
|
||||||
let usedFiles = importResult.usedFiles;
|
|
||||||
let missingFiles = importResult.missingFiles;
|
|
||||||
|
|
||||||
let filesItem = new OV.TreeViewGroupItem ('Files', 'files');
|
let filesItem = new OV.TreeViewGroupItem ('Files', 'files');
|
||||||
this.treeView.AddItem (filesItem);
|
this.treeView.AddItem (filesItem);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user