From 9829e16a3f55c71ce94fbce4ece864ff6c4aa7b2 Mon Sep 17 00:00:00 2001 From: Will Eastcott Date: Tue, 15 Oct 2024 10:56:19 +0100 Subject: [PATCH] Fix text encoding in glTF exporter (#7034) --- src/extras/exporters/gltf-exporter.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/extras/exporters/gltf-exporter.js b/src/extras/exporters/gltf-exporter.js index e3a88dba980..837d8db318c 100644 --- a/src/extras/exporters/gltf-exporter.js +++ b/src/extras/exporters/gltf-exporter.js @@ -769,13 +769,13 @@ class GltfExporter extends CoreExporter { const resources = this.collectResources(entity); return this.buildJson(resources, options).then((json) => { - - const jsonText = JSON.stringify(json); + const encoder = new TextEncoder(); + const jsonData = encoder.encode(JSON.stringify(json)); const headerLength = 12; const jsonHeaderLength = 8; - const jsonDataLength = jsonText.length; + const jsonDataLength = jsonData.length; const jsonPaddingLength = (4 - (jsonDataLength & 3)) & 3; const binaryHeaderLength = 8; @@ -804,9 +804,7 @@ class GltfExporter extends CoreExporter { let offset = headerLength + jsonHeaderLength; // JSON data - for (let i = 0; i < jsonDataLength; i++) { - glbView.setUint8(offset + i, jsonText.charCodeAt(i)); - } + new Uint8Array(glbBuffer, offset, jsonDataLength).set(jsonData); offset += jsonDataLength;