mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 14:01:00 +00:00
fix(artifacts): treat GLB data URI images as embedded (#15654)
This commit is contained in:
1 parent
abada9bc76
commit
ebf4efaabd
2 files changed
+39
-6
No files matched your search
@@ -150,6 +150,35 @@ describe("GLB image bufferView and buffer resolution", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not count data URI images or data URI buffers as external", async () => {
|
||||
const layout = await readGlb(
|
||||
glbWithJson(
|
||||
JSON.stringify({
|
||||
asset: { version: "2.0" },
|
||||
buffers: [
|
||||
{
|
||||
uri: `data:application/octet-stream;base64,${GLB_IMAGE.toString("base64")}`,
|
||||
byteLength: GLB_IMAGE.length,
|
||||
},
|
||||
],
|
||||
bufferViews: [{ buffer: 0, byteLength: GLB_IMAGE.length }],
|
||||
images: [
|
||||
{
|
||||
uri: `data:image/png;base64,${GLB_IMAGE.toString("base64")}`,
|
||||
},
|
||||
{ bufferView: 0, mimeType: "image/png" },
|
||||
{ uri: "cesium.png" },
|
||||
],
|
||||
}),
|
||||
Buffer.alloc(0),
|
||||
),
|
||||
);
|
||||
expect(layout.regionsExamined).toBe("complete");
|
||||
expect(layout.limitations).toEqual([]);
|
||||
expect(layout.metadata.external_images).toBe(1);
|
||||
expect(layout.regions.map(({ path }) => path)).toEqual(["chunks/0.json"]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
"a non-object image element before a valid sibling",
|
||||
|
||||
@@ -311,6 +311,8 @@ const indexOf = (value: unknown): number | undefined =>
|
||||
Number.isSafeInteger(value) && (value as number) >= 0
|
||||
? (value as number)
|
||||
: undefined;
|
||||
const isDataUri = (value: unknown): boolean =>
|
||||
typeof value === "string" && /^data:/iu.test(value);
|
||||
|
||||
const readGlbJsonChunk = async (
|
||||
read: AssetRead,
|
||||
@@ -454,11 +456,12 @@ export const glbLayout = async (
|
||||
unresolvedImages++;
|
||||
return;
|
||||
}
|
||||
// An image named by URI is outside the GLB, not one of its regions.
|
||||
// A data URI carries the image in the JSON chunk; any other URI names
|
||||
// a companion file outside the GLB, not one of its regions.
|
||||
if (imageRecord["bufferView"] === undefined) {
|
||||
// Only a URI string establishes an external source.
|
||||
if (typeof imageRecord["uri"] === "string") externalImages++;
|
||||
else unresolvedImages++;
|
||||
if (typeof imageRecord["uri"] === "string") {
|
||||
if (!isDataUri(imageRecord["uri"])) externalImages++;
|
||||
} else unresolvedImages++;
|
||||
return;
|
||||
}
|
||||
const viewIndex = indexOf(imageRecord["bufferView"]);
|
||||
@@ -472,9 +475,10 @@ export const glbLayout = async (
|
||||
const buffer =
|
||||
bufferIndex === undefined ? undefined : asRecord(buffers[bufferIndex]);
|
||||
// glTF 2.0 GLB: only buffers[0] without a uri is the BIN chunk. A buffer
|
||||
// with a uri is external, so its images are not GLB regions either.
|
||||
// with a data URI is embedded in the JSON chunk; any other uri is
|
||||
// external, so its images are not GLB regions either.
|
||||
if (buffer !== undefined && typeof buffer["uri"] === "string") {
|
||||
externalImages++;
|
||||
if (!isDataUri(buffer["uri"])) externalImages++;
|
||||
return;
|
||||
}
|
||||
const start =
|
||||
|
||||
Reference in new issue
Block a user