|
|
@@ -0,0 +1,97 @@
|
|
|
+/* global QUnit */
|
|
|
+
|
|
|
+import { USDZExporter } from '../../../../examples/jsm/exporters/USDZExporter.js';
|
|
|
+import {
|
|
|
+ unzipSync,
|
|
|
+ strFromU8,
|
|
|
+} from '../../../../examples/jsm/libs/fflate.module.js';
|
|
|
+import {
|
|
|
+ Scene,
|
|
|
+ Mesh,
|
|
|
+ MeshStandardMaterial,
|
|
|
+ BoxGeometry,
|
|
|
+} from '../../../../src/Three.js';
|
|
|
+
|
|
|
+function isValidUSDA( usda ) {
|
|
|
+
|
|
|
+ const header = usda.split( '\n' )[ 0 ];
|
|
|
+ if ( header !== '#usda 1.0' ) return false;
|
|
|
+
|
|
|
+ return true;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+export default QUnit.module( 'Addons', () => {
|
|
|
+
|
|
|
+ QUnit.module( 'Exporters', () => {
|
|
|
+
|
|
|
+ QUnit.module( 'USDZExporter', () => {
|
|
|
+
|
|
|
+ QUnit.test( 'methods', ( assert ) => {
|
|
|
+
|
|
|
+ const exporter = new USDZExporter();
|
|
|
+ assert.ok(
|
|
|
+ exporter instanceof USDZExporter,
|
|
|
+ 'USDZExporter can be instantiated'
|
|
|
+ );
|
|
|
+ assert.ok(
|
|
|
+ typeof exporter.parseAsync === 'function',
|
|
|
+ 'parseAsync method exists'
|
|
|
+ );
|
|
|
+ assert.ok( typeof exporter.parse === 'function', 'parse method exists' );
|
|
|
+ assert.ok(
|
|
|
+ typeof exporter.setTextureUtils === 'function',
|
|
|
+ 'setTextureUtils method exists'
|
|
|
+ );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ QUnit.test( 'export basic scene', async ( assert ) => {
|
|
|
+
|
|
|
+ const exporter = new USDZExporter();
|
|
|
+
|
|
|
+ const scene = new Scene();
|
|
|
+ const geometry = new BoxGeometry( 1, 1, 1 );
|
|
|
+ const material = new MeshStandardMaterial( {
|
|
|
+ color: 0x00ff00,
|
|
|
+ roughness: 0.5,
|
|
|
+ metalness: 0.8,
|
|
|
+ } );
|
|
|
+ const mesh = new Mesh( geometry, material );
|
|
|
+ mesh.name = 'box';
|
|
|
+ scene.add( mesh );
|
|
|
+
|
|
|
+ const result = await exporter.parseAsync( scene );
|
|
|
+
|
|
|
+ assert.ok(
|
|
|
+ result.buffer instanceof ArrayBuffer,
|
|
|
+ 'Export returns a ArrayBuffer'
|
|
|
+ );
|
|
|
+ assert.ok(
|
|
|
+ result.buffer.byteLength > 0,
|
|
|
+ 'ArrayBuffer has non-zero length'
|
|
|
+ );
|
|
|
+
|
|
|
+ const unzipped = unzipSync( result );
|
|
|
+ const fileNames = Object.keys( unzipped );
|
|
|
+
|
|
|
+ const modelFileName = 'model.usda';
|
|
|
+
|
|
|
+ assert.ok( fileNames.length > 0, 'ZIP contains at least one file' );
|
|
|
+ assert.equal(
|
|
|
+ fileNames[ 0 ],
|
|
|
+ modelFileName,
|
|
|
+ `First file is ${modelFileName}`
|
|
|
+ );
|
|
|
+ assert.ok(
|
|
|
+ isValidUSDA( strFromU8( unzipped[ modelFileName ] ) ),
|
|
|
+ `${modelFileName} has content`
|
|
|
+ );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+ } );
|
|
|
+
|
|
|
+} );
|