Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions test/unit/addons/exporters/USDZExporter.tests.js
Original file line number Diff line number Diff line change
@@ -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`
);

} );

} );

} );

} );
1 change: 1 addition & 0 deletions test/unit/three.addons.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
import './addons/utils/BufferGeometryUtils.tests.js';
import './addons/math/ColorSpaces.tests.js';
import './addons/curves/NURBSCurve.tests.js';
import './addons/exporters/USDZExporter.tests.js';