Просмотр исходного кода

Reworked DynamicBufferAttribute. Related #5969.
Sorry @benaadams but the automatic updateRange code was troublesome. Better to let the user deal with it I think.

Mr.doob 10 лет назад
Родитель
Сommit
67686409e9

+ 26 - 17
examples/webgl_buffergeometry_drawcalls.html

@@ -102,21 +102,28 @@
 
 				scene = new THREE.Scene();
 
-				geometry = new THREE.BufferGeometry();
-				var material = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors });
+
+				group = new THREE.Group();
+				scene.add( group );
+
+				var helper = new THREE.BoxHelper( new THREE.Mesh( new THREE.BoxGeometry( r, r, r ) ) );
+				helper.material.color.setHex( 0x080808 );
+				helper.material.blending = THREE.AdditiveBlending;
+				helper.material.transparent = true;
+				group.add( helper );
 
 				var segments = maxParticleCount * maxParticleCount;
 
 				positions = new Float32Array( segments * 3 );
 				colors = new Float32Array( segments * 3 );
 
-				var pMaterial = new THREE.PointCloudMaterial({
+				var pMaterial = new THREE.PointCloudMaterial( {
 					color: 0xFFFFFF,
 					size: 3,
 					blending: THREE.AdditiveBlending,
 					transparent: true,
 					sizeAttenuation: false
-				});
+				} );
 
 				particles = new THREE.BufferGeometry();
 				particlePositions = new Float32Array( maxParticleCount * 3 );
@@ -132,10 +139,10 @@
 					particlePositions[ i * 3 + 2 ] = z;
 
 					// add it to the geometry
-					particlesData.push({
+					particlesData.push( {
 						velocity: new THREE.Vector3( -1 + Math.random() * 2, -1 + Math.random() * 2,  -1 + Math.random() * 2 ),
 						numConnections: 0
-					});
+					} );
 
 				}
 
@@ -145,18 +152,16 @@
 					index: 0
 				} );
 
-				particles.addAttribute( 'position', new THREE.BufferAttribute( particlePositions, 3 ) );
+				particles.addAttribute( 'position', new THREE.DynamicBufferAttribute( particlePositions, 3 ) );
 
 				// create the particle system
 				pointCloud = new THREE.PointCloud( particles, pMaterial );
-
-				group = new THREE.Object3D();
-
-				// add it to the scene
 				group.add( pointCloud );
 
-				geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
-				geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
+				var geometry = new THREE.BufferGeometry();
+
+				geometry.addAttribute( 'position', new THREE.DynamicBufferAttribute( positions, 3 ) );
+				geometry.addAttribute( 'color', new THREE.DynamicBufferAttribute( colors, 3 ) );
 
 				geometry.computeBoundingSphere();
 
@@ -166,15 +171,19 @@
 					index: 0
 				} );
 
+				var material = new THREE.LineBasicMaterial( {
+					vertexColors: THREE.VertexColors,
+					blending: THREE.AdditiveBlending,
+					transparent: true
+				} );
+
 				linesMesh = new THREE.Line( geometry, material, THREE.LinePieces );
 				group.add( linesMesh );
 
-				scene.add( group );
-
 				//
 
 				renderer = new THREE.WebGLRenderer( { antialias: true } );
-				renderer.setPixelRatio( window.devicePixelRatio )
+				renderer.setPixelRatio( window.devicePixelRatio );
 				renderer.setSize( window.innerWidth, window.innerHeight );
 
 				renderer.gammaInput = true;
@@ -249,7 +258,7 @@
 							particleData.numConnections++;
 							particleDataB.numConnections++;
 
-							var alpha = 1.0 - dist / effectController.minDistance + 0.2;
+							var alpha = 1.0 - dist / effectController.minDistance;
 
 							positions[ vertexpos++ ] = particlePositions[ i * 3     ];
 							positions[ vertexpos++ ] = particlePositions[ i * 3 + 1 ];

+ 2 - 0
src/core/BufferAttribute.js

@@ -32,6 +32,8 @@ THREE.BufferAttribute.prototype = {
 
 		}
 
+		return this;
+
 	},
 
 	set: function ( value, offset ) {

+ 5 - 139
src/core/DynamicBufferAttribute.js

@@ -1,5 +1,6 @@
 /**
  * @author benaadams / https://twitter.com/ben_a_adams
+ * @author mrdoob / http://mrdoob.com/
  */
 
 THREE.DynamicBufferAttribute = function ( array, itemSize ) {
@@ -10,146 +11,11 @@ THREE.DynamicBufferAttribute = function ( array, itemSize ) {
 
 };
 
-THREE.DynamicBufferAttribute.prototype = {
+THREE.DynamicBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
+THREE.DynamicBufferAttribute.prototype.constructor = THREE.DynamicBufferAttribute;
 
-	constructor: THREE.DynamicBufferAttribute,
+THREE.DynamicBufferAttribute.prototype.clone = function () {
 
-	get length() {
-
-		return this.array.length;
-
-	},
-
-	copyAt: function ( index1, attribute, index2 ) {
-
-		index1 *= this.itemSize;
-		index2 *= attribute.itemSize;
-
-		for ( var i = 0, l = this.itemSize; i < l; i++ ) {
-
-			this.array[index1 + i] = attribute.array[index2 + i];
-
-		}
-
-		this.markForUpdate( index1, this.itemSize );
-
-	},
-
-	set: function ( value, offset ) {
-
-		if ( offset === undefined ) offset = 0;
-
-		this.array.set( value, offset );
-
-		this.markForUpdate( offset, value.length );
-
-		return this;
-
-	},
-
-	setX: function ( index, x ) {
-
-		index *= this.itemSize;
-
-		this.array[index] = x;
-
-		this.markForUpdate( index, 1 );
-
-		return this;
-
-	},
-
-	setY: function ( index, y ) {
-
-		index = index * this.itemSize + 1;
-
-		this.array[index * this.itemSize + 1] = y;
-
-		this.markForUpdate( index, 1 );
-
-		return this;
-
-	},
-
-	setZ: function ( index, z ) {
-
-		index = index * this.itemSize + 2;
-
-		this.array[index * this.itemSize + 2] = z;
-
-		this.markForUpdate( index, 1 );
-
-		return this;
-
-	},
-
-	setXY: function ( index, x, y ) {
-
-		index *= this.itemSize;
-
-		this.array[index] = x;
-		this.array[index + 1] = y;
-
-		this.markForUpdate( index, 2 );
-
-		return this;
-
-	},
-
-	setXYZ: function ( index, x, y, z ) {
-
-		index *= this.itemSize;
-
-		this.array[index] = x;
-		this.array[index + 1] = y;
-		this.array[index + 2] = z;
-
-		this.markForUpdate( index, 3 );
-
-		return this;
-
-	},
-
-	setXYZW: function ( index, x, y, z, w ) {
-
-		index *= this.itemSize;
-
-		this.array[index] = x;
-		this.array[index + 1] = y;
-		this.array[index + 2] = z;
-		this.array[index + 3] = w;
-
-		this.markForUpdate( index, 4 );
-
-		return this;
-
-	},
-
-	markForUpdate: function ( offset, count ) {
-
-		if ( this.updateRange.count <= 0 ) {
-
-			this.updateRange.offset = offset;
-			this.updateRange.count = count;
-
-		} else {
-
-			var end0 = offset + count;
-			var end1 = this.updateRange.offset + this.updateRange.count;
-
-			this.updateRange.offset = ( offset <= this.updateRange.offset ) ? offset : this.updateRange.offset;
-			this.updateRange.count = ( ( end0 >= end1 ) ? end0 : end1 ) - this.updateRange.offset;
-
-		}
-
-		return this;
-
-	},
-
-	clone: function () {
-
-		return new THREE.DynamicBufferAttribute( new this.array.constructor( this.array ), this.itemSize );
-
-	}
+	return new THREE.DynamicBufferAttribute( new this.array.constructor( this.array ), this.itemSize );
 
 };