Преглед изворни кода

Tests: Add test for USDZExporter (#31435)

Michael Blix пре 5 месеци
родитељ
комит
57decfe0bd
2 измењених фајлова са 98 додато и 0 уклоњено
  1. 97 0
      test/unit/addons/exporters/USDZExporter.tests.js
  2. 1 0
      test/unit/three.addons.unit.js

+ 97 - 0
test/unit/addons/exporters/USDZExporter.tests.js

@@ -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 - 0
test/unit/three.addons.unit.js

@@ -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';

粤ICP备19079148号