Skip to content

Commit

Permalink
Merge pull request #230 from javagl/extensions-validation
Browse files Browse the repository at this point in the history
Drafts for extensions validation
  • Loading branch information
lilleyse authored Oct 14, 2022
2 parents 2c89c2c + 29f2dda commit dbfbcee
Show file tree
Hide file tree
Showing 48 changed files with 1,684 additions and 497 deletions.
13 changes: 9 additions & 4 deletions specs/TilesetValidationSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Validators } from "../src/validation/Validators";
import { ContentDataValidators } from "../src/validation/ContentDataValidators";

ContentDataValidators.registerDefaults();

describe("Tileset validation", function () {
it("detects issues in assetTilesetVersionInvalidType", async function () {
Expand Down Expand Up @@ -729,8 +732,9 @@ describe("Tileset validation", function () {
const result = await Validators.validateTilesetFile(
"specs/data/tilesets/extensionFoundButNotUsed.json"
);
expect(result.length).toEqual(1);
expect(result.get(0).type).toEqual("EXTENSION_FOUND_BUT_NOT_USED");
expect(result.length).toEqual(2);
expect(result.get(0).type).toEqual("EXTENSION_NOT_SUPPORTED");
expect(result.get(1).type).toEqual("EXTENSION_FOUND_BUT_NOT_USED");
});

it("detects issues in extensionRequiredButNotUsed", async function () {
Expand Down Expand Up @@ -810,8 +814,9 @@ describe("Tileset validation", function () {
const result = await Validators.validateTilesetFile(
"specs/data/tilesets/extensionUsedButNotFound.json"
);
expect(result.length).toEqual(1);
expect(result.get(0).type).toEqual("EXTENSION_USED_BUT_NOT_FOUND");
expect(result.length).toEqual(2);
expect(result.get(0).type).toEqual("EXTENSION_NOT_SUPPORTED");
expect(result.get(1).type).toEqual("EXTENSION_USED_BUT_NOT_FOUND");
});

it("detects issues in extrasUnexpectedType", async function () {
Expand Down
25 changes: 25 additions & 0 deletions specs/data/tilesets/boundingVolumeS2/s2AndInvalidBox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"asset": {
"version": "1.1"
},
"extensionsUsed": [
"3DTILES_bounding_volume_S2"
],
"extensionsRequired": [
"3DTILES_bounding_volume_S2"
],
"geometricError": 2.0,
"root": {
"geometricError": 1.0,
"boundingVolume": {
"box": [ 1, 2, 3],
"extensions": {
"3DTILES_bounding_volume_S2": {
"token": "1",
"minimumHeight": 0,
"maximumHeight": 10000
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"asset": {
"version": "1.1"
},
"extensionsUsed": [
"3DTILES_bounding_volume_S2"
],
"extensionsRequired": [
"3DTILES_bounding_volume_S2"
],
"geometricError": 2.0,
"root": {
"geometricError": 1.0,
"boundingVolume": {
"extensions": {
"3DTILES_bounding_volume_S2": {
"token": "1",
"minimumHeight": 0,
"maximumHeight": "NOT_A_NUMBER"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"asset": {
"version": "1.1"
},
"extensionsUsed": [
"3DTILES_bounding_volume_S2"
],
"extensionsRequired": [
"3DTILES_bounding_volume_S2"
],
"geometricError": 2.0,
"root": {
"geometricError": 1.0,
"boundingVolume": {
"extensions": {
"3DTILES_bounding_volume_S2": {
"token": "1",
"minimumHeight": 100,
"maximumHeight": 99
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"asset": {
"version": "1.1"
},
"extensionsUsed": [
"3DTILES_bounding_volume_S2"
],
"extensionsRequired": [
"3DTILES_bounding_volume_S2"
],
"geometricError": 2.0,
"root": {
"geometricError": 1.0,
"boundingVolume": {
"extensions": {
"3DTILES_bounding_volume_S2": {
"token": "1",
"minimumHeight": "NOT_A_NUMBER",
"maximumHeight": 10000
}
}
}
}
}
24 changes: 24 additions & 0 deletions specs/data/tilesets/boundingVolumeS2/s2TokenInvalidType.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"asset": {
"version": "1.1"
},
"extensionsUsed": [
"3DTILES_bounding_volume_S2"
],
"extensionsRequired": [
"3DTILES_bounding_volume_S2"
],
"geometricError": 2.0,
"root": {
"geometricError": 1.0,
"boundingVolume": {
"extensions": {
"3DTILES_bounding_volume_S2": {
"token": 12345,
"minimumHeight": 0,
"maximumHeight": 10000
}
}
}
}
}
24 changes: 24 additions & 0 deletions specs/data/tilesets/boundingVolumeS2/s2TokenInvalidValue.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"asset": {
"version": "1.1"
},
"extensionsUsed": [
"3DTILES_bounding_volume_S2"
],
"extensionsRequired": [
"3DTILES_bounding_volume_S2"
],
"geometricError": 2.0,
"root": {
"geometricError": 1.0,
"boundingVolume": {
"extensions": {
"3DTILES_bounding_volume_S2": {
"token": "NOT_A_VALID_TOKEN",
"minimumHeight": 0,
"maximumHeight": 10000
}
}
}
}
}
23 changes: 23 additions & 0 deletions specs/data/tilesets/boundingVolumeS2/s2TokenMissing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"asset": {
"version": "1.1"
},
"extensionsUsed": [
"3DTILES_bounding_volume_S2"
],
"extensionsRequired": [
"3DTILES_bounding_volume_S2"
],
"geometricError": 2.0,
"root": {
"geometricError": 1.0,
"boundingVolume": {
"extensions": {
"3DTILES_bounding_volume_S2": {
"minimumHeight": 0,
"maximumHeight": 10000
}
}
}
}
}
24 changes: 24 additions & 0 deletions specs/data/tilesets/boundingVolumeS2/validTilesetWithS2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"asset": {
"version": "1.1"
},
"extensionsUsed": [
"3DTILES_bounding_volume_S2"
],
"extensionsRequired": [
"3DTILES_bounding_volume_S2"
],
"geometricError": 2.0,
"root": {
"geometricError": 1.0,
"boundingVolume": {
"extensions": {
"3DTILES_bounding_volume_S2": {
"token": "1",
"minimumHeight": 0,
"maximumHeight": 10000
}
}
}
}
}
15 changes: 15 additions & 0 deletions specs/data/tilesets/extensionNotDeclared_1_0_glTF.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"asset" : {
"version" : "1.0"
},
"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 ]
},
"content": {
"uri": "tiles/glTF/Triangle/Triangle.gltf"
},
"geometricError" : 1.0
}
}
15 changes: 15 additions & 0 deletions specs/data/tilesets/extensionNotNecessary_1_1_glTF.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"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 ]
},
"content": {
"uri": "tiles/glTF/Triangle/Triangle.gltf"
},
"geometricError" : 1.0
}
}
47 changes: 43 additions & 4 deletions src/ValidatorMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import { writeUnchecked } from "./base/writeUnchecked";

import { ValidationState } from "./validation/ValidationState";
import { Validators } from "./validation/Validators";
import { ExtendedObjectsValidators } from "./validation/ExtendedObjectsValidators";

import { BoundingVolumeS2Validator } from "./validation/extensions/BoundingVolumeS2Validator";

import { TileImplicitTiling } from "./structure/TileImplicitTiling";
import { Schema } from "./structure/Metadata/Schema";
import { ValidationResult } from "./validation/ValidationResult";

/**
* A class summarizing the command-line functions of the validator.
Expand All @@ -27,7 +31,7 @@ export class ValidatorMain {
static async validateTilesetFile(
fileName: string,
reportFileName: string | undefined
): Promise<void> {
): Promise<ValidationResult> {
console.log("Validating tileset " + fileName);
const validationResult = await Validators.validateTilesetFile(fileName);
if (defined(reportFileName)) {
Expand All @@ -36,6 +40,7 @@ export class ValidatorMain {
console.log("Validation result:");
console.log(validationResult.serialize());
}
return validationResult;
}

static async validateTilesetsDirectory(
Expand All @@ -50,19 +55,35 @@ export class ValidatorMain {
const ignoreCase = true;
const matcher = globMatcher(globPattern, ignoreCase);
const tilesetFiles = filterIterable(allFiles, matcher);
let numFiles = 0;
let numFilesWithErrors = 0;
let numFilesWithWarnings = 0;
for (const tilesetFile of tilesetFiles) {
let reportFileName = undefined;
if (writeReports) {
reportFileName = ValidatorMain.deriveReportFileName(tilesetFile);
}
await ValidatorMain.validateTilesetFile(tilesetFile, reportFileName);
const validationResult = await ValidatorMain.validateTilesetFile(
tilesetFile,
reportFileName
);
numFiles++;
if (validationResult.numErrors > 0) {
numFilesWithErrors++;
}
if (validationResult.numWarnings > 0) {
numFilesWithWarnings++;
}
}
console.log("Validated " + numFiles + " files");
console.log(" " + numFilesWithErrors + " files with errors");
console.log(" " + numFilesWithWarnings + " files with warnings");
}

static async validateSchemaFile(
fileName: string,
reportFileName: string | undefined
): Promise<void> {
): Promise<ValidationResult> {
console.log("Validating schema " + fileName);
const validationResult = await Validators.validateSchemaFile(fileName);
if (defined(reportFileName)) {
Expand All @@ -71,14 +92,15 @@ export class ValidatorMain {
console.log("Validation result:");
console.log(validationResult.serialize());
}
return validationResult;
}

static async validateSubtreeFile(
fileName: string,
validationState: ValidationState,
implicitTiling: TileImplicitTiling | undefined,
reportFileName: string | undefined
): Promise<void> {
): Promise<ValidationResult> {
console.log("Validating subtree " + fileName);
const validationResult = await Validators.validateSubtreeFile(
fileName,
Expand All @@ -91,6 +113,7 @@ export class ValidatorMain {
console.log("Validation result:");
console.log(validationResult.serialize());
}
return validationResult;
}

static async validateAllTilesetSpecFiles(
Expand Down Expand Up @@ -191,6 +214,22 @@ export class ValidatorMain {
);
}

/**
* Register the validators for known extensions
*/
static registerExtensionValidators() {
// Register the validator for 3DTILES_bounding_volume_S2
{
const s2Validator = new BoundingVolumeS2Validator();
const override = true;
ExtendedObjectsValidators.register(
"3DTILES_bounding_volume_S2",
s2Validator,
override
);
}
}

/**
* Derives a file name for a report from the given input file name.
* The resulting file name will be a file in the same directory as
Expand Down
Loading

0 comments on commit dbfbcee

Please sign in to comment.