diff --git a/examples/webgl_buffergeometry_drawcalls.html b/examples/webgl_buffergeometry_drawcalls.html index 299dec0e0f5d62be8e113c189810023a684acb33..6154ca71e7c49e6296e01e843142f4fe31be6de1 100644 --- a/examples/webgl_buffergeometry_drawcalls.html +++ b/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 ]; diff --git a/src/core/BufferAttribute.js b/src/core/BufferAttribute.js index de1c11cabe7c2311799feb5fd5c19b4b3c924ff8..5808eca92172eb4b397b3a024f702e7e21701226 100644 --- a/src/core/BufferAttribute.js +++ b/src/core/BufferAttribute.js @@ -32,6 +32,8 @@ THREE.BufferAttribute.prototype = { } + return this; + }, set: function ( value, offset ) { diff --git a/src/core/DynamicBufferAttribute.js b/src/core/DynamicBufferAttribute.js index c3484735f2e6fac66150231ba9ad14ae88b34900..17610aa25bb76a94c85798afc1b6e3a563585a79 100644 --- a/src/core/DynamicBufferAttribute.js +++ b/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 ); };