Skip to content

Commit

Permalink
(fix) updating Voyager parsing/validation of scenes to support modern (
Browse files Browse the repository at this point in the history
…#569)

Updated Voyager parser and validation to support modern features and properties.
  • Loading branch information
EMaslowskiQ authored Jan 25, 2024
1 parent 24e610b commit 684df40
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 31 deletions.
32 changes: 16 additions & 16 deletions server/types/voyager/DocumentValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/brace-style */
/**
* 3D Foundation Project
* Copyright 2019 Smithsonian Institution
Expand All @@ -16,13 +15,13 @@
* limitations under the License.
*/

import ajv from 'ajv';
import AjvCore from 'ajv';

import * as documentSchema from './json/document.schema.json';
import * as commonSchema from './json/common.schema.json';
import * as metaSchema from './json/meta.schema.json';
import * as modelSchema from './json/model.schema.json';
import * as setupSchema from './json/setup.schema.json';
import documentSchema from './json/document.schema.json';
import commonSchema from './json/common.schema.json';
import metaSchema from './json/meta.schema.json';
import modelSchema from './json/model.schema.json';
import setupSchema from './json/setup.schema.json';

import { IDocument } from './document';

Expand All @@ -31,14 +30,12 @@ import * as H from '../../utils/helpers';

////////////////////////////////////////////////////////////////////////////////

export class DocumentValidator
{
private _schemaValidator: ajv.Ajv;
private _validateDocument: ajv.ValidateFunction;
export class DocumentValidator {
private _schemaValidator;
private _validateDocument;

constructor()
{
this._schemaValidator = new ajv({
constructor() {
this._schemaValidator = new AjvCore({
schemas: [
documentSchema,
commonSchema,
Expand All @@ -54,14 +51,17 @@ export class DocumentValidator
);
}

validate(document: IDocument): H.IOResults
{
validate(document: IDocument): H.IOResults {
if (!this._validateDocument(document)) {
const error: string = this._schemaValidator.errorsText(this._validateDocument.errors, { separator: ', ', dataVar: 'document' });
LOG.error(error, LOG.LS.eSYS);
return { success: false, error };
}

// if (ENV_DEVELOPMENT) {
// console.log('JSONValidator.validateDocument - OK');
// }

return { success: true };
}
}
9 changes: 5 additions & 4 deletions server/types/voyager/common.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable quotes, @typescript-eslint/brace-style */
/**
* NOTE: this file is part of the definition of a Voyager scene, found in a .svx.json file.
* This was imported from Voyager's source/client/schema on 1/27/2023. It was then modified,
* This was imported from Voyager's source/client/schema on 1/24/2024. It was then modified,
* minimally, to allow for use by Packrat. Ideally, in the future, we will extract out the
* definition of this shared file format for use by both projects.
*/

/**
* 3D Foundation Project
* Copyright 2019 Smithsonian Institution
Expand Down Expand Up @@ -33,13 +32,15 @@ export type Quaternion = Vector4;
export type ColorRGB = Vector3;
export type ColorRGBA = Vector4;

export type TLanguageType = "EN" | "ES" | "DE" | "NL" | "JA";
export enum ELanguageType { EN, ES, DE, NL, JA }
export type TLanguageType = "EN" | "ES" | "DE" | "NL" | "JA" | "FR" | "HAW";
export enum ELanguageType { EN, ES, DE, NL, JA, FR, HAW }
export enum ELanguageStringType {
EN = 'English',
ES = 'Spanish (Español)',
DE = 'German (Deutsche)',
NL = 'Dutch (Nederlands)',
JA = 'Japanese (日本語)',
FR = 'French (Français)',
HAW = 'Hawaiian (ʻŌlelo Hawaiʻi)',
}
export const DEFAULT_LANGUAGE = "EN";
3 changes: 1 addition & 2 deletions server/types/voyager/document.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable quotes, @typescript-eslint/brace-style */
/**
* NOTE: this file is part of the definition of a Voyager scene, found in a .svx.json file.
* This was imported from Voyager's source/client/schema on 1/27/2023. It was then modified,
* This was imported from Voyager's source/client/schema on 1/24/2024. It was then modified,
* minimally, to allow for use by Packrat. Ideally, in the future, we will extract out the
* definition of this shared file format for use by both projects.
*/

/**
* 3D Foundation Project
* Copyright 2019 Smithsonian Institution
Expand Down
13 changes: 13 additions & 0 deletions server/types/voyager/json/model.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@
"type": "string",
"minLength": 1
},
"imageCredit": {
"description": "Credit line image in this annotation with language key.",
"type": "object"
},
"imageAltText": {
"description": "Alt text for image in this annotation with language key",
"type": "object"
},
"audioId": {
"description": "Id of an audio resource for this annotation.",
"type": "string",
"minLength": 1
},
"style": {
"type": "string"
},
Expand Down
7 changes: 4 additions & 3 deletions server/types/voyager/meta.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable quotes, @typescript-eslint/brace-style, @typescript-eslint/no-explicit-any */
/* eslint-disable quotes, @typescript-eslint/brace-style */
/**
* NOTE: this file is part of the definition of a Voyager scene, found in a .svx.json file.
* This was imported from Voyager's source/client/schema on 1/27/2023. It was then modified,
* This was imported from Voyager's source/client/schema on 1/24/2024. It was then modified,
* minimally, to allow for use by Packrat. Ideally, in the future, we will extract out the
* definition of this shared file format for use by both projects.
*/

/**
* 3D Foundation Project
* Copyright 2019 Smithsonian Institution
Expand Down Expand Up @@ -92,4 +91,6 @@ export interface IAudioClip
id: string;
name: string;
uris: Dictionary<string>;
captionUris: Dictionary<string>;
durations: Dictionary<string>;
}
6 changes: 4 additions & 2 deletions server/types/voyager/model.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable quotes, @typescript-eslint/brace-style */
/**
* NOTE: this file is part of the definition of a Voyager scene, found in a .svx.json file.
* This was imported from Voyager's source/client/schema on 1/27/2023. It was then modified,
* This was imported from Voyager's source/client/schema on 1/24/2024. It was then modified,
* minimally, to allow for use by Packrat. Ideally, in the future, we will extract out the
* definition of this shared file format for use by both projects.
*/

/**
* 3D Foundation Project
* Copyright 2019 Smithsonian Institution
Expand Down Expand Up @@ -84,6 +83,9 @@ export interface IAnnotation
taglist?: Dictionary<string[]>;
articleId?: string;
imageUri?: string;
imageCredit?: Dictionary<string>;
imageAltText?: Dictionary<string>;
audioId?: string;

style?: string;
visible?: boolean;
Expand Down
10 changes: 6 additions & 4 deletions server/types/voyager/setup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/* eslint-disable quotes, @typescript-eslint/brace-style, @typescript-eslint/no-explicit-any */
/* eslint-disable quotes, @typescript-eslint/brace-style */
/**
* NOTE: this file is part of the definition of a Voyager scene, found in a .svx.json file.
* This was imported from Voyager's source/client/schema on 1/27/2023. It was then modified,
* This was imported from Voyager's source/client/schema on 1/24/2024. It was then modified,
* minimally, to allow for use by Packrat. Ideally, in the future, we will extract out the
* definition of this shared file format for use by both projects.
*/

// import { Dictionary } from "@ff/core/types";
//import { Dictionary } from "@ff/core/types";
type Dictionary<T> = Record<string, T>;
import { ELanguageType, TLanguageType } from "./common";

Expand Down Expand Up @@ -74,6 +73,8 @@ export interface IViewer
exposure: number;
toneMapping: boolean;
gamma: number;
isWallMountAR: boolean;
arScale: number;
annotationsVisible?: boolean;
activeTags?: string;
sortedTags?: string;
Expand Down Expand Up @@ -169,6 +170,7 @@ export interface ISlicer
axis: TSliceAxis;
inverted: boolean;
position: number;
color: number[];
}

export type ITours = ITour[];
Expand Down

0 comments on commit 684df40

Please sign in to comment.