Explorar o código

Merge pull request #15298 from Mugen87/dev11

Tests: Clean up
Mr.doob %!s(int64=6) %!d(string=hai) anos
pai
achega
a3321589d8

BIN=BIN
examples/models/skinned/simple/simple.blend


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 53
examples/models/skinned/simple/simple.js


+ 64 - 105
test/unit/src/core/BufferGeometry.tests.js

@@ -5,22 +5,20 @@
 /* global QUnit */
 
 import { BufferGeometry } from '../../../../src/core/BufferGeometry';
-import { JSONLoader } from '../../../../src/loaders/JSONLoader';
-import { DirectGeometry } from '../../../../src/core/DirectGeometry';
 import {
 	BufferAttribute,
 	Uint16BufferAttribute,
-	Uint32BufferAttribute,
-	Float32BufferAttribute
+	Uint32BufferAttribute
 } from '../../../../src/core/BufferAttribute';
+import { Color } from '../../../../src/math/Color';
+import { Vector2 } from '../../../../src/math/Vector2';
 import { Vector3 } from '../../../../src/math/Vector3';
+import { Vector4 } from '../../../../src/math/Vector4';
 import { Matrix4 } from '../../../../src/math/Matrix4';
 import { Sphere } from '../../../../src/math/Sphere';
-import { Vector2 } from '../../../../src/math/Vector2';
 import { Geometry } from '../../../../src/core/Geometry';
 import { Face3 } from '../../../../src/core/Face3';
 import { Mesh } from '../../../../src/objects/Mesh';
-import { Color } from '../../../../src/math/Color';
 import { Line } from '../../../../src/objects/Line.js';
 import {
 	x,
@@ -547,128 +545,89 @@ export default QUnit.module( 'Core', () => {
 
 		QUnit.test( "fromGeometry/fromDirectGeometry", ( assert ) => {
 
-			if ( typeof XMLHttpRequest === 'undefined' ) {
-
-				assert.expect( 0 );
-				return;
-
-			}
-
-			assert.timeout( 1000 );
-
-			var a = new BufferGeometry();
-			// BoxGeometry is a bit too simple but works fine in a pinch
-			// var b = new BoxGeometry( 1, 1, 1 );
-			// b.mergeVertices();
-			// b.computeVertexNormals();
-			// b.computeBoundingBox();
-			// b.computeBoundingSphere();
-			var asyncDone = assert.async(); // tell QUnit we're done with asserts
-
-			var loader = new JSONLoader();
-			loader.load( "../../examples/models/skinned/simple/simple.js", function ( modelGeometry ) {
+			// geometry definition
 
-				a.fromGeometry( modelGeometry );
+			var geometry = new Geometry();
 
-				var attr;
-				var geometry = new DirectGeometry().fromGeometry( modelGeometry );
+			// vertices
 
-				var positions = new Float32Array( geometry.vertices.length * 3 );
-				attr = new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices );
-				assert.ok( bufferAttributeEquals( a.attributes.position, attr ), "Vertices are identical" );
+			var v1 = new Vector3( 1, - 1, 0 );
+			var v2 = new Vector3( 1, 1, 0 );
+			var v3 = new Vector3( - 1, 1, 0 );
+			var v4 = new Vector3( - 1, - 1, 0 );
 
-				if ( geometry.normals.length > 0 ) {
+			// faces, normals and colors
 
-					var normals = new Float32Array( geometry.normals.length * 3 );
-					attr = new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals );
-					assert.ok( bufferAttributeEquals( a.attributes.normal, attr ), "Normals are identical" );
+			geometry.vertices.push( v1, v2, v3, v4 );
 
-				}
-
-				if ( geometry.colors.length > 0 ) {
-
-					var colors = new Float32Array( geometry.colors.length * 3 );
-					attr = new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors );
-					assert.ok( bufferAttributeEquals( a.attributes.color, attr ), "Colors are identical" );
-
-				}
-
-				if ( geometry.uvs.length > 0 ) {
+			var f1 = new Face3( 0, 1, 2 );
+			f1.normal.set( 0, 0, 1 );
+			f1.color.set( 0xff0000 );
+			var f2 = new Face3( 2, 3, 0 );
+			f2.normal.set( 0, 0, 1 );
+			f2.color.set( 0xff0000 );
 
-					var uvs = new Float32Array( geometry.uvs.length * 2 );
-					attr = new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs );
-					assert.ok( bufferAttributeEquals( a.attributes.uv, attr ), "UVs are identical" );
+			geometry.faces.push( f1, f2 );
 
-				}
-
-				if ( geometry.uvs2.length > 0 ) {
-
-					var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
-					attr = new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 );
-					assert.ok( bufferAttributeEquals( a.attributes.uv2, attr ), "UV2s are identical" );
-
-				}
+			// uvs
 
-				// groups
-				assert.deepEqual( a.groups, geometry.groups, "Groups are identical" );
+			var uvs = geometry.faceVertexUvs[ 0 ];
+			uvs.length = 0;
 
-				// morphs
-				if ( geometry.morphTargets !== undefined ) {
-
-					for ( var name in geometry.morphTargets ) {
-
-						var morphTargets = geometry.morphTargets[ name ];
-
-						for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
-
-							var morphTarget = morphTargets[ i ];
-
-							attr = new Float32BufferAttribute( morphTarget.length * 3, 3 );
-							attr.copyVector3sArray( morphTarget );
-
-							assert.ok(
-								bufferAttributeEquals( a.morphAttributes[ name ][ i ], attr ),
-								"MorphTargets #" + i + " are identical"
-							);
-
-						}
-
-					}
-
-				}
-
-				// skinning
-				if ( geometry.skinIndices.length > 0 ) {
+			uvs.push( [
+				new Vector2( 1, 0 ),
+			  new Vector2( 1, 1 ),
+			  new Vector2( 0, 1 )
+			] );
 
-					attr = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
-					attr.copyVector4sArray( geometry.skinIndices );
-					assert.ok( bufferAttributeEquals( a.attributes.skinIndex, attr ), "SkinIndices are identical" );
+			uvs.push( [
+				new Vector2( 0, 1 ),
+			  new Vector2( 0, 0 ),
+			  new Vector2( 1, 0 )
+			] );
 
-				}
+			// skin weights
 
-				if ( geometry.skinWeights.length > 0 ) {
+			var sw1 = new Vector4( 0.8, 0.2, 0, 0 );
+			var sw2 = new Vector4( 0.7, 0.2, 0.1, 0 );
+			var sw3 = new Vector4( 0.8, 0.1, 0.1, 0 );
+			var sw4 = new Vector4( 1, 0, 0, 0 );
 
-					attr = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
-					attr.copyVector4sArray( geometry.skinWeights );
-					assert.ok( bufferAttributeEquals( a.attributes.skinWeight, attr ), "SkinWeights are identical" );
+			geometry.skinWeights.push( sw1, sw2, sw3, sw4 );
 
-				}
+			 // skin indices
 
-				if ( geometry.boundingSphere !== null ) {
+			var si1 = new Vector4( 0, 1, 2, 3 );
+			var si2 = new Vector4( 2, 3, 4, 5 );
+			var si3 = new Vector4( 4, 5, 6, 7 );
+			var si4 = new Vector4( 6, 7, 8, 9 );
 
-					assert.ok( a.boundingSphere.equals( geometry.boundingSphere ), "BoundingSphere is identical" );
+			geometry.skinIndices.push( si1, si2, si3, si4 );
 
-				}
+			// create BufferGeometry
 
-				if ( geometry.boundingBox !== null ) {
+			var bufferGeometry = new BufferGeometry().fromGeometry( geometry );
 
-					assert.ok( a.boundingBox.equals( geometry.boundingBox ), "BoundingBox is identical" );
+			// expected values
 
-				}
+			var vertices = new Float32Array( [ 1, - 1, 0, 1, 1, 0, - 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ] );
+			var normals = new Float32Array( [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 ] );
+			var colors = new Float32Array( [ 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 ] );
+			var uvs = new Float32Array( [ 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0 ] );
+			var skinIndices = new Float32Array( [ 0, 1, 2, 3, 2, 3, 4, 5, 4, 5, 6, 7, 4, 5, 6, 7, 6, 7, 8, 9, 0, 1, 2, 3 ] );
+			var skindWeights = new Float32Array( [
+				0.8, 0.2, 0, 0, 0.7, 0.2, 0.1, 0, 0.8, 0.1, 0.1, 0,
+				0.8, 0.1, 0.1, 0, 1, 0, 0, 0, 0.8, 0.2, 0, 0
+			] );
 
-				asyncDone();
+			var attributes = bufferGeometry.attributes;
 
-			} );
+			assert.deepEqual( attributes.position.array, vertices, "Vertices are as expected" );
+			assert.deepEqual( attributes.normal.array, normals, "Normals are as expected" );
+			assert.deepEqual( attributes.color.array, colors, "Colors are as expected" );
+			assert.deepEqual( attributes.uv.array, uvs, "Texture coordinates are as expected" );
+			assert.deepEqual( attributes.skinIndex.array, skinIndices, "Skin indices are as expected" );
+			assert.deepEqual( attributes.skinWeight.array, skindWeights, "Skin weights are as expected" );
 
 		} );
 

+ 113 - 182
test/unit/src/core/DirectGeometry.tests.js

@@ -5,8 +5,10 @@
 /* global QUnit */
 
 import { DirectGeometry } from '../../../../src/core/DirectGeometry';
-import { JSONLoader } from '../../../../src/loaders/JSONLoader';
 import { Vector2 } from '../../../../src/math/Vector2';
+import { Vector3 } from '../../../../src/math/Vector3';
+import { Vector4 } from '../../../../src/math/Vector4';
+import { Color } from '../../../../src/math/Color';
 import { Face3 } from '../../../../src/core/Face3';
 import { Geometry } from '../../../../src/core/Geometry';
 
@@ -48,214 +50,143 @@ export default QUnit.module( 'Core', () => {
 
 		QUnit.test( "fromGeometry", ( assert ) => {
 
-			if ( typeof XMLHttpRequest === 'undefined' ) {
+			// geometry definition
 
-				assert.expect( 0 );
-				return;
+			var geometry = new Geometry();
 
-			}
+			// vertices
 
-			assert.timeout( 1000 );
+			var v1 = new Vector3( 1, - 1, 0 );
+			var v2 = new Vector3( 1, 1, 0 );
+			var v3 = new Vector3( - 1, 1, 0 );
+			var v4 = new Vector3( - 1, - 1, 0 );
 
-			var a = new DirectGeometry();
-
-			var asyncDone = assert.async(); // tell QUnit when we're done with async stuff
-
-			var loader = new JSONLoader();
-			loader.load( "../../examples/models/skinned/simple/simple.js", function ( geometry ) {
-
-				a.fromGeometry( geometry );
-
-				var tmp = new DirectGeometry();
-				tmp.computeGroups( geometry );
-				assert.deepEqual( a.groups, tmp.groups, "Check groups" );
-
-				var morphTargets = geometry.morphTargets;
-				var morphTargetsLength = morphTargets.length;
-
-				var morphTargetsPosition;
-
-				if ( morphTargetsLength > 0 ) {
-
-					morphTargetsPosition = [];
-
-					for ( var i = 0; i < morphTargetsLength; i ++ ) {
-
-						morphTargetsPosition[ i ] = [];
-
-					}
-
-					morphTargets.position = morphTargetsPosition;
-
-				}
-
-				var morphNormals = geometry.morphNormals;
-				var morphNormalsLength = morphNormals.length;
-
-				var morphTargetsNormal;
-
-				if ( morphNormalsLength > 0 ) {
-
-					morphTargetsNormal = [];
-
-					for ( var i = 0; i < morphNormalsLength; i ++ ) {
-
-						morphTargetsNormal[ i ] = [];
-
-					}
-
-					morphTargets.normal = morphTargetsNormal;
-
-				}
-
-				var vertices = [];
-				var normals = [];
-				var colors = [];
-				var uvs = [];
-				var uvs2 = [];
-				var skinIndices = [];
-				var skinWeights = [];
-
-				var hasFaceVertexUv = geometry.faceVertexUvs[ 0 ] && geometry.faceVertexUvs[ 0 ].length > 0;
-				var hasFaceVertexUv2 = geometry.faceVertexUvs[ 1 ] && geometry.faceVertexUvs[ 1 ].length > 0;
-
-				var hasSkinIndices = geometry.skinIndices.length === geometry.vertices.length;
-				var hasSkinWeights = geometry.skinWeights.length === geometry.vertices.length;
-
-				for ( var i = 0; i < geometry.faces.length; i ++ ) {
-
-					var face = geometry.faces[ i ];
-
-					vertices.push(
-						geometry.vertices[ face.a ],
-						geometry.vertices[ face.b ],
-						geometry.vertices[ face.c ]
-					);
-
-					var vertexNormals = face.vertexNormals;
-
-					if ( vertexNormals.length === 3 ) {
-
-						normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
+			// faces, normals and colors
 
-					} else {
+			geometry.vertices.push( v1, v2, v3, v4 );
 
-						normals.push( face.normal, face.normal, face.normal );
+			var f1 = new Face3( 0, 1, 2 );
+			f1.normal.set( 0, 0, 1 );
+			f1.color.set( 0xff0000 );
+			var f2 = new Face3( 2, 3, 0 );
+			f2.normal.set( 0, 0, 1 );
+			f2.color.set( 0xff0000 );
 
-					}
+			geometry.faces.push( f1, f2 );
 
-					var vertexColors = face.vertexColors;
+			// uvs
 
-					if ( vertexColors.length === 3 ) {
+			var uvs = geometry.faceVertexUvs[ 0 ];
+			uvs.length = 0;
 
-						colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
+			uvs.push( [
+				new Vector2( 1, 0 ),
+				new Vector2( 1, 1 ),
+				new Vector2( 0, 1 )
+			] );
 
-					} else {
+			uvs.push( [
+				new Vector2( 0, 1 ),
+				new Vector2( 0, 0 ),
+				new Vector2( 1, 0 )
+			] );
 
-						colors.push( face.color, face.color, face.color );
+			// skin weights
 
-					}
+			var sw1 = new Vector4( 0.8, 0.2, 0, 0 );
+			var sw2 = new Vector4( 0.7, 0.2, 0.1, 0 );
+			var sw3 = new Vector4( 0.8, 0.1, 0.1, 0 );
+			var sw4 = new Vector4( 1, 0, 0, 0 );
 
-					if ( hasFaceVertexUv === true ) {
+			geometry.skinWeights.push( sw1, sw2, sw3, sw4 );
 
-						var vertexUvs = geometry.faceVertexUvs[ 0 ][ i ];
+			// skin indices
 
-						if ( vertexUvs !== undefined ) {
+			var si1 = new Vector4( 0, 1, 2, 3 );
+			var si2 = new Vector4( 2, 3, 4, 5 );
+			var si3 = new Vector4( 4, 5, 6, 7 );
+			var si4 = new Vector4( 6, 7, 8, 9 );
 
-							uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
+			geometry.skinIndices.push( si1, si2, si3, si4 );
 
-						} else {
+			// create DirectGeometry
 
-							uvs.push( new Vector2(), new Vector2(), new Vector2() );
+			var directGeometry = new DirectGeometry().fromGeometry( geometry );
 
-						}
+			// expected values
 
-					}
-
-					if ( hasFaceVertexUv2 === true ) {
-
-						var vertexUvs = geometry.faceVertexUvs[ 1 ][ i ];
-
-						if ( vertexUvs !== undefined ) {
-
-							uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
-
-						} else {
-
-							uvs2.push( new Vector2(), new Vector2(), new Vector2() );
-
-						}
-
-					}
-
-					// morphs
-
-					for ( var j = 0; j < morphTargetsLength; j ++ ) {
-
-						var morphTarget = morphTargets[ j ].vertices;
-
-						morphTargetsPosition[ j ].push(
-							morphTarget[ face.a ],
-							morphTarget[ face.b ],
-							morphTarget[ face.c ]
-						);
-
-					}
-
-					for ( var j = 0; j < morphNormalsLength; j ++ ) {
-
-						var morphNormal = morphNormals[ j ].vertexNormals[ i ];
-
-						morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
-
-					}
-
-					// skins
-
-					if ( hasSkinIndices ) {
-
-						skinIndices.push(
-							geometry.skinIndices[ face.a ],
-							geometry.skinIndices[ face.b ],
-							geometry.skinIndices[ face.c ]
-						);
-
-					}
-
-					if ( hasSkinWeights ) {
-
-						skinWeights.push(
-							geometry.skinWeights[ face.a ],
-							geometry.skinWeights[ face.b ],
-							geometry.skinWeights[ face.c ]
-						);
-
-					}
-
-				}
-
-				assert.deepEqual( a.vertices, vertices, "Vertices are identical" );
-				assert.deepEqual( a.normals, normals, "Normals are identical" );
-				assert.deepEqual( a.colors, colors, "Colors are identical" );
-				assert.deepEqual( a.uvs, uvs, "UV coordinates are identical" );
-				assert.deepEqual( a.uvs2, uvs2, "UV(2) coordinates are identical" );
-				assert.deepEqual( a.skinIndices, skinIndices, "SkinIndices are identical" );
-				assert.deepEqual( a.skinWeights, skinWeights, "SkinWeights are identical" );
-				assert.deepEqual( a.morphTargetsPosition, morphTargetsPosition, "MorphTargets (Position) are identical" );
-				assert.deepEqual( a.morphTargetsNormal, morphTargetsNormal, "MorphTargets (Normals) are identical" );
+			var vertices = [
+				// first face
+				new Vector3( 1, - 1, 0 ),
+				new Vector3( 1, 1, 0 ),
+				new Vector3( - 1, 1, 0 ),
+				// second face
+				new Vector3( - 1, 1, 0 ),
+				new Vector3( - 1, - 1, 0 ),
+				new Vector3( 1, - 1, 0 )
+			];
 
-				asyncDone();
+			var normals = [
+				// first face
+				new Vector3( 0, 0, 1 ),
+				new Vector3( 0, 0, 1 ),
+				new Vector3( 0, 0, 1 ),
+				// second face
+				new Vector3( 0, 0, 1 ),
+				new Vector3( 0, 0, 1 ),
+				new Vector3( 0, 0, 1 )
+			];
 
-			}, onProgress, onError );
+			var colors = [
+				// first face
+				new Color( 1, 0, 0 ),
+				new Color( 1, 0, 0 ),
+				new Color( 1, 0, 0 ),
+				// second face
+				new Color( 1, 0, 0 ),
+				new Color( 1, 0, 0 ),
+				new Color( 1, 0, 0 )
+			];
 
-			function onProgress() {}
+			var uvs = [
+				// first face
+				new Vector2( 1, 0 ),
+				new Vector2( 1, 1 ),
+				new Vector2( 0, 1 ),
+				// second face
+				new Vector2( 0, 1 ),
+				new Vector2( 0, 0 ),
+				new Vector2( 1, 0 )
+			];
 
-			function onError( error ) {
+			var skinIndices = [
+				// first face
+				new Vector4( 0, 1, 2, 3 ),
+				new Vector4( 2, 3, 4, 5 ),
+				new Vector4( 4, 5, 6, 7 ),
+				// second face
+				new Vector4( 4, 5, 6, 7 ),
+				new Vector4( 6, 7, 8, 9 ),
+				new Vector4( 0, 1, 2, 3 )
+			];
 
-				console.error( error );
-				asyncDone();
+			var skinWeights = [
+				// first face
+				new Vector4( 0.8, 0.2, 0, 0 ),
+				new Vector4( 0.7, 0.2, 0.1, 0 ),
+				new Vector4( 0.8, 0.1, 0.1, 0 ),
+				// second face
+				new Vector4( 0.8, 0.1, 0.1, 0 ),
+				new Vector4( 1, 0, 0, 0 ),
+				new Vector4( 0.8, 0.2, 0, 0 )
+			];
 
-			}
+			assert.deepEqual( directGeometry.vertices, vertices, "Vertices are as expected" );
+			assert.deepEqual( directGeometry.normals, normals, "Normals are as expected" );
+			assert.deepEqual( directGeometry.colors, colors, "Colors are as expected" );
+			assert.deepEqual( directGeometry.uvs, uvs, "Texture coordinates are as expected" );
+			assert.deepEqual( directGeometry.skinIndices, skinIndices, "Skin indices are as expected" );
+			assert.deepEqual( directGeometry.skinWeights, skinWeights, "Skin weights are as expected" );
 
 		} );
 

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio