|
@@ -7,6 +7,7 @@ import { BufferGeometryUtils } from '../../../../examples/jsm/utils/BufferGeomet
|
|
|
|
|
|
import { BufferAttribute } from '../../../../src/core/BufferAttribute';
|
|
import { BufferAttribute } from '../../../../src/core/BufferAttribute';
|
|
import { BufferGeometry } from '../../../../src/core/BufferGeometry';
|
|
import { BufferGeometry } from '../../../../src/core/BufferGeometry';
|
|
|
|
+import { TriangleStripDrawMode, TriangleFanDrawMode } from '../../../../src/constants';
|
|
|
|
|
|
export default QUnit.module( 'BufferGeometryUtils', () => {
|
|
export default QUnit.module( 'BufferGeometryUtils', () => {
|
|
|
|
|
|
@@ -129,4 +130,44 @@ export default QUnit.module( 'BufferGeometryUtils', () => {
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
+ QUnit.test( 'convertToTriangles()', ( assert ) => {
|
|
|
|
+
|
|
|
|
+ // TRIANGLE_STRIP
|
|
|
|
+
|
|
|
|
+ const vertices1 = [];
|
|
|
|
+
|
|
|
|
+ vertices1.push( 0, 0, 0 ); // v0
|
|
|
|
+ vertices1.push( 1, 0, 0 ); // v1
|
|
|
|
+ vertices1.push( 0, 1, 0 ); // v2
|
|
|
|
+ vertices1.push( 2, 0, 0 ); // v3
|
|
|
|
+ vertices1.push( 2, 1, 0 ); // v4
|
|
|
|
+ vertices1.push( 3, 0, 0 ); // v5
|
|
|
|
+
|
|
|
|
+ var geometry1 = new BufferGeometry();
|
|
|
|
+
|
|
|
|
+ geometry1.setAttribute( 'position', new BufferAttribute( new Float32Array( vertices1 ), 3 ) );
|
|
|
|
+ geometry1 = BufferGeometryUtils.convertToTriangles( geometry1, TriangleStripDrawMode );
|
|
|
|
+
|
|
|
|
+ assert.deepEqual( geometry1.index.array, new Uint16Array( [ 0, 1, 2, 3, 2, 1, 2, 3, 4, 5, 4, 3 ] ), 'correct triangle indices from triangle strip' );
|
|
|
|
+
|
|
|
|
+ // TRIANGLE_FAN
|
|
|
|
+
|
|
|
|
+ const vertices2 = [];
|
|
|
|
+
|
|
|
|
+ vertices2.push( 0, 0, 0 ); // v0
|
|
|
|
+ vertices2.push( 1, 0, 0 ); // v1
|
|
|
|
+ vertices2.push( 1, 1, 0 ); // v2
|
|
|
|
+ vertices2.push( 0, 1, 0 ); // v3
|
|
|
|
+ vertices2.push( - 1, 1, 0 ); // v4
|
|
|
|
+ vertices2.push( - 1, 0, 0 ); // v5
|
|
|
|
+
|
|
|
|
+ var geometry2 = new BufferGeometry();
|
|
|
|
+
|
|
|
|
+ geometry2.setAttribute( 'position', new BufferAttribute( new Float32Array( vertices2 ), 3 ) );
|
|
|
|
+ geometry2 = BufferGeometryUtils.convertToTriangles( geometry2, TriangleFanDrawMode );
|
|
|
|
+
|
|
|
|
+ assert.deepEqual( geometry2.index.array, new Uint16Array( [ 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5 ] ), 'correct triangle indices from triangle fan' );
|
|
|
|
+
|
|
|
|
+ } );
|
|
|
|
+
|
|
} );
|
|
} );
|