How to use gltf-validator - 6 common examples

To help you get started, we’ve selected a few gltf-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TimvanScherpenzeel / gltf-to-usdz-research / lib / index.js View on Github external
.then((gltf) => {
    const parsedGltf = JSON.parse(gltf);

    gltfValidator
      .validateBytes(new Uint8Array(Buffer.from(JSON.stringify(parsedGltf))))
      .catch((error) => {
        console.warn('Validation failed: ', error);

        process.exit(1);
      });

    return converter(parsedGltf);
  })
  .then((data) => {
github TimvanScherpenzeel / gltf-to-usdz-research / lib / index.js View on Github external
.then((gltf) => {
				const parsedGltf = JSON.parse(gltf);

				gltfValidator
					.validateBytes(new Uint8Array(Buffer.from(JSON.stringify(parsedGltf))))
					.catch((error) => {
						console.warn('Validation failed: ', error);
					});

				const convertedFile = converter(parsedGltf);

				convertedFile.then((data) => {
					fs.writeFile(output, data, (error) => {
						if (!error) {
							console.log(`Written file to ${output}`);
						} else {
							console.error(error);
						}
					});
				});
github KhronosGroup / glTF-Asset-Generator / Tools / validate.js View on Github external
async function validateModel(glTFAsset) {
    const asset = fs.readFileSync(glTFAsset.modelFilepath);

    return validator.validateBytes(new Uint8Array(asset), {
        uri: glTFAsset.modelName,
        writeTimestamp: false,
        externalResourceFunction: (uri) =>
            new Promise((resolve, reject) => {
                uri = path.resolve(path.dirname(glTFAsset.modelFilepath), decodeURIComponent(uri));
                fs.readFile(uri, (error, data) => {
                    if (error) {
                        console.error(error.toString());
                        reject(error.toString());
                        return;
                    }
                    resolve(data);
                });
            })
    }).then((report) => {
        glTFAsset.report = report;
github donmccurdy / glTF-Transform / scripts / validate.js View on Github external
const validateURI = (uri) => {
    const asset = fs.readFileSync(uri);
    const dir = path.dirname(uri);
    const promise = validator.validateBytes(new Uint8Array(asset), {
        uri,
        externalResourceFunction: (uri) =>
        new Promise((resolve) => {
            uri = path.resolve(dir, decodeURIComponent(uri));
            const buffer = fs.readFileSync(uri)
            resolve(new Uint8Array(buffer));
        })
    })
        .then((report) => {
            messages.numAssets++;
            messages.numErrors += report.issues.numErrors;
            messages.numWarnings += report.issues.numWarnings;
            messages.numInfos += report.issues.numInfos;
            messages.numHints += report.issues.numHints;
            if (verbose) {
                messages.reports.push(report);
github AnalyticalGraphicsInc / gltf-vscode / src / validationProvider.ts View on Github external
export async function validate(sourceFilename: string) {
    if (typeof sourceFilename === 'undefined') {
        return;
    }
    if (!fs.existsSync(sourceFilename)) {
        throw new Error('File not found.');
    }

    const currentSettings: ValidatorSettings = vscode.workspace.getConfiguration('glTF').get('Validation');

    const gltfData = fs.readFileSync(sourceFilename);
    const baseName = path.basename(sourceFilename);
    const folderName = path.resolve(sourceFilename, '..');

    const result = await gltfValidator.validateBytes(new Uint8Array(gltfData), {
        uri: baseName,
        maxIssues: currentSettings.maxIssues,
        ignoredIssues: currentSettings.ignoredIssues,
        severityOverrides: currentSettings.severityOverrides,
        externalResourceFunction: (uri : string) =>
            new Promise((resolve, reject) => {
                uri = path.resolve(folderName, decodeURIComponent(uri));
                fs.readFile(uri, (err, data) => {
                    if (err) {
                        reject(err.toString());
                        return;
                    }
                    resolve(data);
                });
            }),
    });
github donmccurdy / three-gltf-viewer / src / validation-controller.js View on Github external
      .then((buffer) => validateBytes(new Uint8Array(buffer), {
        externalResourceFunction: (uri) =>
          this.resolveExternalResource(uri, rootFile, rootPath, assetMap)
      }))
      .then((report) => this.setReport(report, response))

gltf-validator

Library for validating glTF 2.0 assets, compiled from Dart to JS.

Apache-2.0
Latest version published 2 years ago

Package Health Score

57 / 100
Full package analysis

Popular gltf-validator functions