loaders.gl: Test reorganization (#699)

This commit is contained in:
Ib Green 2018-08-30 11:13:05 -07:00 committed by GitHub
parent d4aa1b3803
commit aecee72db4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 6455 additions and 43 deletions

1664
1 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,26 +1,37 @@
/* global console, process */
/* eslint-disable no-console */
const {GLBParser} = require('../src/glb-loader');
const {toArrayBuffer} = require('../src/common/loader-utils');
const {GLBParser, GLTFParser, toArrayBuffer} = require('../src');
const fs = require('fs');
const [,, ...args] = process.argv;
if (args.length === 0) {
console.log('glbdump: no glb files specifed...');
function printHelp() {
console.log('glbdump: no glb files specified...');
console.log('glbdump --json Pretty prints the JSON chunk...');
console.log('glbdump --gltf Parses as glTF and pretty prints all scenes...');
process.exit(0); // eslint-disable-line
}
const options = parseOptions();
let options;
for (const filename of args) {
if (filename.indexOf('--') !== 0) {
dumpFile(filename);
function main() {
const [,, ...args] = process.argv;
if (args.length === 0) {
printHelp();
}
options = parseOptions(args);
for (const filename of args) {
if (filename.indexOf('--') !== 0) {
dumpFile(filename);
}
}
}
main();
function dumpFile(filename) {
console.log(`\nGLB dump of ${filename}:`);
@ -32,6 +43,20 @@ function dumpFile(filename) {
const data = new GLBParser(arrayBuffer).parseWithMetadata({ignoreMagic: true});
if (options.dumpGLTF) {
dumpGLTFScenes(data);
} else {
dumpGLBSegments(data);
}
if (options.dumpJSON) {
console.log(JSON.stringify(data, null, 2));
}
}
// GLB SEGMENTS
function dumpGLBSegments(data) {
for (const key in data) {
const array = data[key];
if (Array.isArray(array)) {
@ -40,10 +65,6 @@ function dumpFile(filename) {
logObject(key, array);
}
}
if (options.dumpJSON) {
console.log(JSON.stringify(data, null, 2));
}
}
function logArray(key, array) {
@ -58,7 +79,23 @@ function logObject(field, object) {
);
}
function parseOptions() {
// GLTF
function dumpGLTFScenes(data) {
const gltfParser = new GLTFParser(data);
const gltf = gltfParser.resolve();
if (gltf.asset) {
console.log(JSON.stringify(gltf.asset, null, 2));
}
const scenes = gltf.scenes || [];
for (const scene of scenes) {
console.log(JSON.stringify(scene, null, 2));
}
}
// OPTIONS
function parseOptions(args) {
const opts = {
dumpJSON: false
};
@ -69,6 +106,12 @@ function parseOptions() {
case '--json':
opts.dumpJSON = true;
break;
case '--gltf':
opts.dumpGLTF = true;
break;
case '--help':
printHelp();
break;
default:
console.warn(`Unknown option ${arg}`);
}

View File

@ -32,6 +32,10 @@ class TextDecoderPolyfill {
throw new TypeError('stream option must be boolean');
}
if (view instanceof ArrayBuffer) {
view = new Uint8Array(view);
}
if (!ArrayBuffer.isView(view)) {
throw new TypeError('passed argument must be an array buffer view');
} else {
@ -40,7 +44,12 @@ class TextDecoderPolyfill {
arr.forEach((charcode, i) => {
charArr[i] = String.fromCharCode(charcode);
});
return decodeURIComponent(escape(charArr.join('')));
const text = charArr.join('');
try {
return decodeURIComponent(escape(text));
} catch (error) {
return text;
}
}
}
}

View File

@ -1,5 +0,0 @@
// Public methods
export {default as default, parseGLB} from './glb-loader';
// Experimental exports, exposes internals
export {default as GLBParser} from './glb-parser';

View File

@ -1,4 +0,0 @@
// Public methods
export {default as default} from './glb-writer';
export {default as GLBBuilder} from './glb-builder';
export {default as _packBinaryJson} from './pack-binary-json';

View File

@ -3,9 +3,24 @@ export {loadFile} from './common/loader';
export {loadUri} from './common/loader-utils/load-uri.js';
export {smartFetch, smartParse} from './common/smart-fetch';
// GLB/GLTF LOADERS & WRITERS
export {default as GLBLoader, GLBParser} from './glb-loader';
export {default as GLBWriter, GLBBuilder} from './glb-writer';
// UTILS
// Get MIME type and size from binary image data
export {getImageSize} from './common/loader-utils/get-image-size';
// Convert between Buffers and ArrayBuffers
export {toArrayBuffer, toBuffer} from './common/loader-utils/binary-utils';
// TextEncoder/Decoder polyfills for Node.js
export {default as TextDecoder} from './common/loader-utils/text-decoder';
export {default as TextEncoder} from './common/loader-utils/text-encoder';
// LOADERS
// GLB LOADER & WRITER
export {default as GLBLoader} from './glb-loader/glb-loader';
export {default as GLBParser} from './glb-loader/glb-parser';
export {default as GLBWriter} from './glb-writer/glb-writer';
export {default as GLBBuilder} from './glb-writer/glb-builder';
// MODEL LOADERS
export {default as OBJLoader} from './obj-loader/obj-loader';

View File

@ -14,7 +14,7 @@ function loadTestFiles() {
const fs = module.require && module.require('fs');
if (!testFiles && fs) {
testFiles = new Map(['png', 'jpeg', 'gif', 'bmp', 'tiff'].map(type => {
const imagePath = path.resolve(__dirname, `../../data/img1-preview.${type}`);
const imagePath = path.resolve(__dirname, `../../data/images/img1-preview.${type}`);
const image = fs.readFileSync(imagePath);
return [type, image];
}));

View File

@ -2,7 +2,7 @@
import test from 'tape-catch';
import {OBJLoader, KMLLoader, smartParse} from 'loaders.gl';
import KML from '../kml-loader/KML_Samples.kml';
import KML from '../data/kml/KML_Samples.kml';
const LOADERS = [
OBJLoader, KMLLoader

View File

@ -1,4 +1,21 @@
# Attributions
# Attributions for Sample Files
Test data (image1-preview.*) from binary-gltf-utils
under MIT license: Copyright (c) 2016-17 Karl Cheng
## Images
* `image1-preview.*` - copied from `binary-gltf-utils` under MIT license: Copyright (c) 2016-17 Karl Cheng
## gltf-2.0
* `2CylinderEngine.glb` - From [Khronos glTF-Sample-Models](https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/2CylinderEngine/glTF-Binary/2CylinderEngine.glb)
## PCD
* The sample PCD files were copied from THREE.js `examples/models/pcd` under MIT license
## KML
Standard Google KML sample file.

File diff suppressed because it is too large Load Diff

View File

Before

Width:  |  Height:  |  Size: 450 KiB

After

Width:  |  Height:  |  Size: 450 KiB

View File

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 118 KiB

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

Before

Width:  |  Height:  |  Size: 164 KiB

After

Width:  |  Height:  |  Size: 164 KiB

View File

@ -3,7 +3,7 @@ import test from 'tape-catch';
import {toLowPrecision} from 'loaders.gl/common/loader-utils';
import {GLBLoader, GLBBuilder} from 'loaders.gl';
import {_packBinaryJson as packBinaryJson} from 'loaders.gl/glb-writer';
import packBinaryJson from 'loaders.gl/glb-writer/pack-binary-json';
const TEST_CASES = {
flat: {
@ -38,7 +38,7 @@ const TEST_CASES = {
]
},
full: require('./test-data.json')
full: require('../data/glb/test-data.json')
};
test('GLB#encode-and-parse', t => {

View File

@ -4,7 +4,7 @@ import test from 'tape-catch';
import {GLBBuilder, GLBParser} from 'loaders.gl';
import unpackGLBBuffers from 'loaders.gl/glb-loader/unpack-glb-buffers';
import TEST_JSON from './test-data.json';
import TEST_JSON from '../data/glb/test-data.json';
const BUFFERS = [
new Int8Array([3, 2, 3]),

View File

@ -3,7 +3,7 @@ import test from 'tape-catch';
import {GLBBuilder} from 'loaders.gl';
import {_packBinaryJson as packBinaryJson} from 'loaders.gl/glb-writer';
import packBinaryJson from 'loaders.gl/glb-writer/pack-binary-json';
const inputJSONTypedArraysMixed = {
slices: [

View File

@ -1,4 +1,4 @@
import './common';
import './glb-loader';
import './kml-loader/kml-loader.spec.js';
import './pcd-loader/pcd-loader.spec.js';
import './kml-loader/kml-loader.spec';
import './pcd-loader/pcd-loader.spec';

View File

@ -2,7 +2,7 @@
import test from 'tape-catch';
import {KMLLoader} from 'loaders.gl';
import KML from './KML_Samples.kml';
import KML from '../data/kml/KML_Samples.kml';
const INVALID_KML = `\
<?xml version="1.0" encoding="UTF-8"?>

View File

@ -1 +0,0 @@
Attribution: Sample PCD files copied from THREE.js examples/models/pcd

View File

@ -1,9 +1,9 @@
/* eslint-disable max-len */
import test from 'tape-catch';
import {PCDLoader} from 'loaders.gl';
import {TextEncoder} from 'loaders.gl/common/loader-utils';
import {TextEncoder, toArrayBuffer} from 'loaders.gl/common/loader-utils';
import PCD from './simple-ascii.pcd';
import PCD from '../data/pcd/simple-ascii.pcd';
test('PCDLoader#parseText', t => {
const binaryPCD = new TextEncoder().encode(PCD);
@ -16,3 +16,22 @@ test('PCDLoader#parseText', t => {
t.end();
});
test('PCDLoader#parseBinary', t => {
const path = require('path');
const fs = module.require && module.require('fs');
if (!fs) {
t.comment('binary data tests only available under Node.js');
t.end();
}
const file = fs.readFileSync(path.resolve(__dirname, '../data/pcd/Zaghetto.pcd'));
const binaryPCD = toArrayBuffer(file);
const data = PCDLoader.parseBinary(binaryPCD);
t.ok(data.header, 'Documents were found');
t.equal(data.attributes.position.length, 179250, 'position attribute was found');
t.end();
});