loaders.gl: Test reorganization (#699)
@ -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}`);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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';
|
||||
@ -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';
|
||||
@ -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';
|
||||
|
||||
@ -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];
|
||||
}));
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
BIN
test/modules/loaders.gl/data/gltf-2.0/2CylinderEngine-Draco.bin
Normal file
BIN
test/modules/loaders.gl/data/gltf-2.0/2CylinderEngine.glb
Normal file
|
Before Width: | Height: | Size: 450 KiB After Width: | Height: | Size: 450 KiB |
|
Before Width: | Height: | Size: 118 KiB After Width: | Height: | Size: 118 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 164 KiB After Width: | Height: | Size: 164 KiB |
@ -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 => {
|
||||
|
||||
@ -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]),
|
||||
|
||||
@ -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: [
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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"?>
|
||||
|
||||
@ -1 +0,0 @@
|
||||
Attribution: Sample PCD files copied from THREE.js examples/models/pcd
|
||||
@ -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();
|
||||
});
|
||||
|
||||