Skip to content

Commit

Permalink
Merge pull request #277 from CesiumGS/handle-spaces-in-i3dm-uri
Browse files Browse the repository at this point in the history
Handle URI with spaces in I3DM
  • Loading branch information
lilleyse committed Jun 12, 2023
2 parents 068f8bc + 5c5d2af commit 0e4c443
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

Version ?.?.? - 2023-mm-dd

- When an I3DM refers to an external glTF asset with a URI, then the URI has to be padded with `0x20` (space) bytes if necessary to satisfy the alignment requirements. The validator only accepted `0x00` (zero) bytes as padding bytes. Now the validator properly handles trailing spaces, and reports the presence of zero-bytes with a validation warning ([#276](https://github.com/CesiumGS/3d-tiles-validator/issues/276))

Version 0.4.1 - 2023-05-02

- Moved most of the internal implementation into the `3d-tiles-tools`, and replaced it with a dependency to `3d-tiles-tools`
Expand Down
8 changes: 8 additions & 0 deletions specs/TilesetValidationSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,4 +951,12 @@ describe("Tileset validation", function () {
);
expect(result.length).toEqual(0);
});

it("detects no issues in tilesets/tiles/i3dm/i3dmWithUri/tileset.json", async function () {
const result = await Validators.validateTilesetFile(
"specs/data/tilesets/tiles/i3dm/i3dmWithUri/tileset.json"
);
expect(result.length).toEqual(1);
expect(result.get(0).type).toEqual("CONTENT_VALIDATION_WARNING");
});
});
Binary file not shown.
17 changes: 17 additions & 0 deletions specs/data/tilesets/tiles/i3dm/i3dmWithUri/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


A tileset that refers to a single I3DM file, which in turn refers to a
single glTF file (the `Box` glTF sample model).

The I3DM refers to the GLB using a URI, in contrast to embedding the
GLB inside the GLB.

The URI is `"Box.glb "`: It includes spaces, as a regression test
for https://github.com/CesiumGS/3d-tiles-validator/issues/276 .

The string (including spaces) consists of 11 characters.

In order to achieve the alignment requirement, the payload data is
padded with _additional_ `0x00` bytes to achieve a payload length
of 16 bytes. This is not allowed by the specification, and should
cause a WARNING during the validation.
Binary file not shown.
19 changes: 19 additions & 0 deletions specs/data/tilesets/tiles/i3dm/i3dmWithUri/tileset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"asset" : {
"version" : "1.1"
},
"geometricError" : 2.0,
"root" : {
"boundingVolume" : {
"box" : [
0.0, 0.0, 0.0,
0.5, 0.0, 0.0,
0.0, 0.5, 0.0,
0.0, 0.0, 0.5 ]
},
"geometricError" : 1.0,
"content": {
"uri": "i3dmWithUri.i3dm"
}
}
}
19 changes: 16 additions & 3 deletions src/tileFormats/I3dmValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,22 @@ export class I3dmValidator implements Validator<Buffer> {
result = false;
}
} else {
// The GLB data was a URI. Create the URI from the buffer, and remove
// any zero-bytes from the string that may be introduced by padding
const glbUri = glbData.toString().replace(/\0/g, "");
// The GLB data was a URI, as indicated by `gltfFormat === 0`.
// The padding bytes in this case should be 0x20 (space) bytes,
// so issue a warning if the buffer contais 0x00 (zero) bytes.
if (glbData.includes("\0")) {
const message =
`The field containing the URI of the glTF asset contained ` +
`0x00 (zero)-bytes, but should only be padded with 0x20 (space) bytes`;
const issue = ContentValidationIssues.CONTENT_VALIDATION_WARNING(
uri,
message
);
context.addIssue(issue);
}
// Create the URI from the buffer, and remove any bytes (zeros
// or trailing) that may be introduced by padding.
const glbUri = glbData.toString().replace(/\0/g, "").trim();
const resourceResolver = context.getResourceResolver();
const resolvedGlbData = await resourceResolver.resolveData(glbUri);
if (!defined(resolvedGlbData)) {
Expand Down

0 comments on commit 0e4c443

Please sign in to comment.