Browse Source

BufferAttribute.length not compatible with r71

The definition of `BufferAttribute.length` has changed since r71 (see
#6473).

![r71](https://github.com/mrdoob/three.js/blob/master/src/core/BufferAttribute.js#L18-L22)

![r72dev](https://github.com/mrdoob/three.js/blob/dev/src/core/BufferAttribute.js#L18-L31)

Backward compatibility with r71 should be kept, otherwise, the method
should just be removed!

Implementation should be

```
get length () {

console.warn( 'THREE.BufferAttribute: .length has been deprecated.
Please use .count.' );
return this.array.length;

}
```
dubejf 10 years ago
parent
commit
cbf1cd2803

+ 1 - 1
examples/js/loaders/gltf/glTFLoader.js

@@ -84,7 +84,7 @@ THREE.glTFLoader.prototype.load = function( url, callback ) {
 
 	var ClassicGeometry = function() {
 
-		this.geometry = new THREE.BufferGeometry;
+		this.geometry = new THREE.BufferGeometry();
 
 		this.totalAttributes = 0;
 		this.loadedAttributes = 0;

+ 4 - 4
examples/webgl_buffergeometry_instancing.html

@@ -145,7 +145,7 @@
 
             var offsets = new THREE.InstancedBufferAttribute( new Float32Array( instances * 3 ), 3, 1, false );
 
-            for ( var i = 0, ul = offsets.length; i < ul; i++ ) {
+            for ( var i = 0, ul = offsets.count; i < ul; i++ ) {
 
                 offsets.setXYZ( i, Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 );
 
@@ -155,7 +155,7 @@
 
             var colors = new THREE.InstancedBufferAttribute( new Float32Array( instances * 4 ), 4, 1, false );
 
-            for ( var i = 0, ul = colors.length; i < ul; i++ ) {
+            for ( var i = 0, ul = colors.count; i < ul; i++ ) {
 
                 colors.setXYZW( i, Math.random(), Math.random(), Math.random(), Math.random() );
 
@@ -167,7 +167,7 @@
 
             var orientationsStart = new THREE.InstancedBufferAttribute( new Float32Array( instances * 4 ), 4, 1, false );
 
-            for ( var i = 0, ul = orientationsStart.length; i < ul; i++ ) {
+            for ( var i = 0, ul = orientationsStart.count; i < ul; i++ ) {
 
                 vector.set( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
                 vector.normalize();
@@ -180,7 +180,7 @@
 
             var orientationsEnd = new THREE.InstancedBufferAttribute( new Float32Array( instances * 4 ), 4, 1, false );
 
-            for ( var i = 0, ul = orientationsEnd.length; i < ul; i++ ) {
+            for ( var i = 0, ul = orientationsEnd.count; i < ul; i++ ) {
 
                 vector.set( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
                 vector.normalize();

+ 3 - 3
examples/webgl_buffergeometry_instancing_dynamic.html

@@ -213,7 +213,7 @@
             var offsets = new THREE.InstancedBufferAttribute( new Float32Array( instances * 3 ), 3, 1, false );
 
             var vector = new THREE.Vector4();
-            for ( var i = 0, ul = offsets.length; i < ul; i++ ) {
+            for ( var i = 0, ul = offsets.count; i < ul; i++ ) {
                 var x = Math.random() * 100 - 50;
                 var y = Math.random() * 100 - 50;
                 var z = Math.random() * 100 - 50;
@@ -228,7 +228,7 @@
 
             orientations = new THREE.InstancedBufferAttribute( new Float32Array( instances * 4 ), 4, 1, true );
 
-            for ( var i = 0, ul = orientations.length; i < ul; i++ ) {
+            for ( var i = 0, ul = orientations.count; i < ul; i++ ) {
 
                 vector.set( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
                 vector.normalize();
@@ -318,7 +318,7 @@
             var delta = ( time - lastTime ) / 5000;
             tmpQ.set( moveQ.x * delta, moveQ.y * delta, moveQ.z * delta, 1 ).normalize();
 
-            for ( var i = 0, ul = orientations.length; i < ul; i++ ) {
+            for ( var i = 0, ul = orientations.count; i < ul; i++ ) {
                 var index = i * 4;
                 currentQ.set( orientations.array[index], orientations.array[index + 1], orientations.array[index + 2], orientations.array[index + 3] );
                 currentQ.multiply( tmpQ );

+ 3 - 3
examples/webgl_buffergeometry_instancing_interleaved_dynamic.html

@@ -185,7 +185,7 @@
         var offsets = new THREE.InterleavedBufferAttribute( instanceBuffer, 3, 0 );
 
         var vector = new THREE.Vector4();
-        for ( var i = 0, ul = offsets.length; i < ul; i++ ) {
+        for ( var i = 0, ul = offsets.count; i < ul; i++ ) {
             var x = Math.random() * 100 - 50;
             var y = Math.random() * 100 - 50;
             var z = Math.random() * 100 - 50;
@@ -199,7 +199,7 @@
 
         orientations = new THREE.InterleavedBufferAttribute( instanceBuffer, 4, 4 );
 
-        for ( var i = 0, ul = orientations.length; i < ul; i++ ) {
+        for ( var i = 0, ul = orientations.count; i < ul; i++ ) {
 
             vector.set( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
             vector.normalize();
@@ -290,7 +290,7 @@
         var delta = ( time - lastTime ) / 5000;
         tmpQ.set( moveQ.x * delta, moveQ.y * delta, moveQ.z * delta, 1 ).normalize();
 
-        for ( var i = 0, ul = orientations.length; i < ul; i++ ) {
+        for ( var i = 0, ul = orientations.count; i < ul; i++ ) {
             var index = i * instanceBuffer.stride + orientations.offset;
             currentQ.set( instanceBuffer.array[index], instanceBuffer.array[index + 1], instanceBuffer.array[index + 2], instanceBuffer.array[index + 3] );
             currentQ.multiply( tmpQ );

+ 2 - 2
src/core/BufferAttribute.js

@@ -19,8 +19,8 @@ THREE.BufferAttribute.prototype = {
 
 	get length () {
 
-		console.warn( 'THREE.BufferAttribute: .length has been renamed to .count.' );
-		return this.count;
+		console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
+		return this.array.length;
 
 	},
 

+ 2 - 2
src/core/BufferGeometry.js

@@ -1067,7 +1067,7 @@ THREE.BufferGeometry.prototype = {
 				itemSize: attribute.itemSize,
 				type: attribute.array.constructor.name,
 				array: array
-			}
+			};
 
 		}
 
@@ -1082,7 +1082,7 @@ THREE.BufferGeometry.prototype = {
 			data.data.boundingSphere = {
 				center: boundingSphere.center.toArray(),
 				radius: boundingSphere.radius
-			}
+			};
 
 		}
 

+ 1 - 1
src/extras/geometries/EdgesGeometry.js

@@ -11,7 +11,7 @@ THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
 	var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
 
 	var edge = [ 0, 0 ], hash = {};
-	var sortFunction = function ( a, b ) { return a - b };
+	var sortFunction = function ( a, b ) { return a - b; };
 
 	var keys = [ 'a', 'b', 'c' ];
 

+ 7 - 5
test/unit/geometry/EdgesGeometry.js

@@ -96,7 +96,7 @@ function testEdges ( vertList, idxList, numAfter ) {
 		var numBefore = idxList.length;
 		equal( countEdges (geom), numBefore, "Edges before!" );
 
-		var egeom = new THREE.EdgesGeometry ( geom );;
+		var egeom = new THREE.EdgesGeometry( geom );
 
 		equal( countEdges (egeom), numAfter, "Edges after!" );
 		output( geom, egeom );
@@ -163,7 +163,7 @@ function createIndexedBufferGeometry ( vertList, idxList ) {
 
 function addDrawCalls ( geometry ) {
 
-	var numTris = geometry.getAttribute( 'index' ).length / 3;
+	var numTris = geometry.getAttribute( 'index' ).count / 3;
 
 	var offset = 0;
 	for ( var i = 0 ; i < numTris; i ++ ) {
@@ -183,7 +183,7 @@ function countEdges ( geom ) {
 
 	if ( geom instanceof THREE.EdgesGeometry ) {
 
-		return geom.getAttribute( 'position' ).length / 2;
+		return geom.getAttribute( 'position' ).count / 2;
 
 	}
 
@@ -196,11 +196,11 @@ function countEdges ( geom ) {
 	var indices = geom.getAttribute( 'index' );
 	if ( indices !== undefined ) {
 
-		return indices.length;
+		return indices.count;
 
 	}
 
-	return geom.getAttribute( 'position' ).length;
+	return geom.getAttribute( 'position' ).count;
 
 }
 
@@ -228,7 +228,9 @@ function output ( geom, egeom ) {
 	scene.add(edges);
 
 	if (scene.children.length % 8 === 0) {
+
 		xoffset += 2;
+
 	}
 
 }