Always use texture buffer instead of url in case of export.

This commit is contained in:
Viktor Kovacs 2021-04-09 08:25:00 +02:00
parent efbd5a08a2
commit 3607ab3649
6 changed files with 11 additions and 30 deletions

View File

@ -3,7 +3,6 @@ OV.ExportedFile = class
constructor (name) constructor (name)
{ {
this.name = name; this.name = name;
this.url = null;
this.content = null; this.content = null;
} }
@ -17,16 +16,6 @@ OV.ExportedFile = class
this.name = name; this.name = name;
} }
GetUrl ()
{
return this.url;
}
SetUrl (url)
{
this.url = url;
}
GetContent () GetContent ()
{ {
return this.content; return this.content;

View File

@ -50,7 +50,7 @@ OV.ExporterGltf = class extends OV.ExporterBase
let textureIndex = fileNameToIndex[fileName]; let textureIndex = fileNameToIndex[fileName];
if (textureIndex === undefined) { if (textureIndex === undefined) {
let textureFile = new OV.ExportedFile (fileName); let textureFile = new OV.ExportedFile (fileName);
textureFile.SetUrl (texture.url); textureFile.SetContent (texture.buffer);
files.push (textureFile); files.push (textureFile);
textureIndex = mainJson.textures.length; textureIndex = mainJson.textures.length;

View File

@ -25,7 +25,7 @@ OV.ExporterObj = class extends OV.ExporterBase
}); });
if (fileIndex === -1) { if (fileIndex === -1) {
let textureFile = new OV.ExportedFile (fileName); let textureFile = new OV.ExportedFile (fileName);
textureFile.SetUrl (texture.url); textureFile.SetContent (texture.buffer);
files.push (textureFile); files.push (textureFile);
} }
} }

View File

@ -387,7 +387,7 @@ OV.Viewer = class
this.ResizeRenderer (width, height); this.ResizeRenderer (width, height);
} }
this.Render (); this.Render ();
let url = this.renderer.domElement.toDataURL(); let url = this.renderer.domElement.toDataURL ();
if (originalSize !== null) { if (originalSize !== null) {
this.ResizeRenderer ( this.ResizeRenderer (
parseInt (originalSize.x, 10), parseInt (originalSize.x, 10),

View File

@ -12,15 +12,15 @@ function CreateTestModel ()
material1.diffuseMap = new OV.TextureMap (); material1.diffuseMap = new OV.TextureMap ();
material1.diffuseMap.name = 'textures/texture1.png'; material1.diffuseMap.name = 'textures/texture1.png';
material1.diffuseMap.url = 'texture1_url'; material1.diffuseMap.url = 'texture1_url';
material1.diffuseMap.buffer = new ArrayBuffer (4); material1.diffuseMap.buffer = new ArrayBuffer (1);
material1.specularMap = new OV.TextureMap (); material1.specularMap = new OV.TextureMap ();
material1.specularMap.name = 'textures/texture2.png'; material1.specularMap.name = 'textures/texture2.png';
material1.specularMap.url = 'texture2_url'; material1.specularMap.url = 'texture2_url';
material1.specularMap.buffer = new ArrayBuffer (4); material1.specularMap.buffer = new ArrayBuffer (2);
material1.bumpMap = new OV.TextureMap (); material1.bumpMap = new OV.TextureMap ();
material1.bumpMap.name = 'textures/texture3.png'; material1.bumpMap.name = 'textures/texture3.png';
material1.bumpMap.url = 'texture3_url'; material1.bumpMap.url = 'texture3_url';
material1.bumpMap.buffer = new ArrayBuffer (4); material1.bumpMap.buffer = new ArrayBuffer (3);
model.AddMaterial (material1); model.AddMaterial (material1);
let material2 = new OV.Material (); let material2 = new OV.Material ();
@ -121,18 +121,15 @@ describe ('Exporter', function () {
let textureFile1 = result[2]; let textureFile1 = result[2];
assert.strictEqual (textureFile1.GetName (), 'texture1.png'); assert.strictEqual (textureFile1.GetName (), 'texture1.png');
assert.strictEqual (textureFile1.GetUrl (), 'texture1_url'); assert.strictEqual (textureFile1.GetContent ().byteLength, 1);
assert.strictEqual (textureFile1.GetContent (), null);
let textureFile2 = result[3]; let textureFile2 = result[3];
assert.strictEqual (textureFile2.GetName (), 'texture2.png'); assert.strictEqual (textureFile2.GetName (), 'texture2.png');
assert.strictEqual (textureFile2.GetUrl (), 'texture2_url'); assert.strictEqual (textureFile2.GetContent ().byteLength, 2);
assert.strictEqual (textureFile2.GetContent (), null);
let textureFile3 = result[4]; let textureFile3 = result[4];
assert.strictEqual (textureFile3.GetName (), 'texture3.png'); assert.strictEqual (textureFile3.GetName (), 'texture3.png');
assert.strictEqual (textureFile3.GetUrl (), 'texture3_url'); assert.strictEqual (textureFile3.GetContent ().byteLength, 3);
assert.strictEqual (textureFile3.GetContent (), null);
}); });
it ('Stl Export', function () { it ('Stl Export', function () {
@ -305,8 +302,7 @@ describe ('Exporter', function () {
assert.strictEqual (binFile.GetName (), 'model.bin'); assert.strictEqual (binFile.GetName (), 'model.bin');
assert.strictEqual (textureFile.GetName (), 'texture1.png'); assert.strictEqual (textureFile.GetName (), 'texture1.png');
assert.strictEqual (textureFile.GetUrl (), 'texture1_url'); assert.strictEqual (textureFile.GetContent ().byteLength, 1);
assert.strictEqual (textureFile.GetContent (), null);
let contentBuffer = gltfFile.GetContent (); let contentBuffer = gltfFile.GetContent ();
let importer = new OV.ImporterGltf (); let importer = new OV.ImporterGltf ();

View File

@ -133,11 +133,7 @@ OV.ShowExportDialog = function (model)
fileList.empty (); fileList.empty ();
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
let file = files[i]; let file = files[i];
let url = file.GetUrl (); let url = OV.CreateObjectUrl (file.GetContent ());
if (url === null) {
url = OV.CreateObjectUrl (file.GetContent ());
createdUrls.push (url);
}
let fileLink = $('<a>').addClass ('ov_dialog_file_link').appendTo (fileList); let fileLink = $('<a>').addClass ('ov_dialog_file_link').appendTo (fileList);
fileLink.attr ('href', url); fileLink.attr ('href', url);
fileLink.attr ('download', file.GetName ()); fileLink.attr ('download', file.GetName ());