Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report empty tile children arrays as a warning #288

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions specs/TilesetValidationSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ describe("Tileset validation", function () {
expect(result.get(0).type).toEqual("REQUIRED_VALUE_NOT_FOUND");
});

it("detects issues in tileChildrenEmptyArray", async function () {
const result = await Validators.validateTilesetFile(
"specs/data/tilesets/tileChildrenEmptyArray.json"
);
expect(result.length).toEqual(1);
expect(result.get(0).type).toEqual("ARRAY_LENGTH_UNEXPECTED");
});

it("detects issues in tileContentBoundingVolumeInvalidType", async function () {
const result = await Validators.validateTilesetFile(
"specs/data/tilesets/tileContentBoundingVolumeInvalidType.json"
Expand Down
13 changes: 13 additions & 0 deletions specs/data/tilesets/tileChildrenEmptyArray.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"asset" : {
"version" : "1.1"
},
"geometricError" : 2.0,
"root" : {
"boundingVolume" : {
"box" : [ 0.5, 0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5 ]
},
"geometricError" : 1.0,
"children": []
}
}
15 changes: 15 additions & 0 deletions src/issues/JsonValidationIssues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ export class JsonValidationIssues {
return issue;
}

/**
* A warning that indicates that an array SHOULD have had a
* certain length, but had a different length.
*
* @param path - The path for the `ValidationIssue`
* @param message - The message for the `ValidationIssue`
* @returns The `ValidationIssue`
*/
static ARRAY_LENGTH_UNEXPECTED(path: string, message: string) {
const type = "ARRAY_LENGTH_UNEXPECTED";
const severity = ValidationIssueSeverity.WARNING;
const issue = new ValidationIssue(type, path, message, severity);
return issue;
}

/**
* Indicates that the length of a string does not match the length
* that is specified via the JSON schema, using the `minLength`
Expand Down
18 changes: 16 additions & 2 deletions src/validation/TileValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,19 +347,33 @@ export class TileValidator {
const children = tile.children;
const childrenPath = tilePath + "/children";
if (defined(children)) {
// The children MUST be an array of objects with at least 1 element
// The children MUST be an array of objects
if (
!BasicValidator.validateArray(
childrenPath,
"children",
children,
1,
0,
undefined,
"object",
context
)
) {
result = false;
} else {
// The children are an array of objects.
// The case that the array has a length of 0 will cause a warning,
// due to https://github.com/CesiumGS/3d-tiles/issues/752
if (children.length === 0) {
const message =
`The 'children' array should contain at least 1 element, ` +
`but had a length of 0`;
const issue = JsonValidationIssues.ARRAY_LENGTH_UNEXPECTED(
childrenPath,
message
);
context.addIssue(issue);
}
}
}
return result;
Expand Down
Loading