Skip to content

Commit

Permalink
Fix text encoding in glTF exporter (#7034)
Browse files Browse the repository at this point in the history
  • Loading branch information
willeastcott authored and Martin Valigursky committed Oct 15, 2024
1 parent 79800b4 commit 9829e16
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/extras/exporters/gltf-exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 9829e16

Please sign in to comment.