From 0f02be43dd93f549b618153554941616afadb162 Mon Sep 17 00:00:00 2001 From: kovacsv Date: Fri, 6 Aug 2021 22:18:02 +0200 Subject: [PATCH] Add utility functions for extension detection. --- source/import/importergltf.js | 14 +------------- source/io/bufferutils.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/source/import/importergltf.js b/source/import/importergltf.js index 30db05e..022a377 100644 --- a/source/import/importergltf.js +++ b/source/import/importergltf.js @@ -776,18 +776,6 @@ OV.ImporterGltf = class extends OV.ImporterBase ImportTexture (gltf, gltfTextureRef) { - function GetTextureFileExtension (mimeType) - { - if (mimeType === undefined || mimeType === null) { - return ''; - } - let mimeParts = mimeType.split ('/'); - if (mimeParts.length === 0) { - return ''; - } - return '.' + mimeParts[mimeParts.length - 1]; - } - if (gltfTextureRef === undefined || gltfTextureRef === null) { return null; } @@ -808,7 +796,7 @@ OV.ImporterGltf = class extends OV.ImporterBase if (gltfImage.uri !== undefined) { let base64Buffer = OV.Base64DataURIToArrayBuffer (gltfImage.uri); if (base64Buffer !== null) { - textureParams.name = 'Embedded_' + textureIndexString + GetTextureFileExtension (base64Buffer.mimeType); + textureParams.name = 'Embedded_' + textureIndexString + '.' + OV.GetFileExtensionFromMimeType (base64Buffer.mimeType); textureParams.url = OV.CreateObjectUrlWithMimeType (base64Buffer.buffer, base64Buffer.mimeType); textureParams.buffer = base64Buffer.buffer; } else { diff --git a/source/io/bufferutils.js b/source/io/bufferutils.js index d8690c9..2b4e71a 100644 --- a/source/io/bufferutils.js +++ b/source/io/bufferutils.js @@ -61,6 +61,18 @@ OV.Base64DataURIToArrayBuffer = function (uri) }; }; +OV.GetFileExtensionFromMimeType = function (mimeType) +{ + if (mimeType === undefined || mimeType === null) { + return ''; + } + let mimeParts = mimeType.split ('/'); + if (mimeParts.length === 0) { + return ''; + } + return mimeParts[mimeParts.length - 1]; +}; + OV.CreateObjectUrl = function (content) { let blob = new Blob ([content]);