123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- /**
- * @author mrdoob / http://mrdoob.com/
- */
- THREE.BufferAttribute = function ( array, itemSize ) {
- this.uuid = THREE.Math.generateUUID();
- this.array = array;
- this.itemSize = itemSize;
- this.dynamic = false;
- this.updateRange = { offset: 0, count: - 1 };
- this.version = 0;
- };
- THREE.BufferAttribute.prototype = {
- constructor: THREE.BufferAttribute,
- get length() {
- console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
- return this.array.length;
- },
- get count() {
- return this.array.length / this.itemSize;
- },
- set needsUpdate( value ) {
- if ( value === true ) this.version ++;
- },
- setDynamic: function ( value ) {
- this.dynamic = value;
- return this;
- },
- copy: function ( source ) {
- this.array = new source.array.constructor( source.array );
- this.itemSize = source.itemSize;
- this.dynamic = source.dynamic;
- return this;
- },
- 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 ];
- }
- return this;
- },
- copyArray: function ( array ) {
- this.array.set( array );
- return this;
- },
- copyColorsArray: function ( colors ) {
- var array = this.array, offset = 0;
- for ( var i = 0, l = colors.length; i < l; i ++ ) {
- var color = colors[ i ];
- if ( color === undefined ) {
- console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
- color = new THREE.Color();
- }
- array[ offset ++ ] = color.r;
- array[ offset ++ ] = color.g;
- array[ offset ++ ] = color.b;
- }
- return this;
- },
- copyIndicesArray: function ( indices ) {
- var array = this.array, offset = 0;
- for ( var i = 0, l = indices.length; i < l; i ++ ) {
- var index = indices[ i ];
- array[ offset ++ ] = index.a;
- array[ offset ++ ] = index.b;
- array[ offset ++ ] = index.c;
- }
- return this;
- },
- copyVector2sArray: function ( vectors ) {
- var array = this.array, offset = 0;
- for ( var i = 0, l = vectors.length; i < l; i ++ ) {
- var vector = vectors[ i ];
- if ( vector === undefined ) {
- console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
- vector = new THREE.Vector2();
- }
- array[ offset ++ ] = vector.x;
- array[ offset ++ ] = vector.y;
- }
- return this;
- },
- copyVector3sArray: function ( vectors ) {
- var array = this.array, offset = 0;
- for ( var i = 0, l = vectors.length; i < l; i ++ ) {
- var vector = vectors[ i ];
- if ( vector === undefined ) {
- console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
- vector = new THREE.Vector3();
- }
- array[ offset ++ ] = vector.x;
- array[ offset ++ ] = vector.y;
- array[ offset ++ ] = vector.z;
- }
- return this;
- },
- copyVector4sArray: function ( vectors ) {
- var array = this.array, offset = 0;
- for ( var i = 0, l = vectors.length; i < l; i ++ ) {
- var vector = vectors[ i ];
- if ( vector === undefined ) {
- console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
- vector = new THREE.Vector4();
- }
- array[ offset ++ ] = vector.x;
- array[ offset ++ ] = vector.y;
- array[ offset ++ ] = vector.z;
- array[ offset ++ ] = vector.w;
- }
- return this;
- },
- set: function ( value, offset ) {
- if ( offset === undefined ) offset = 0;
- this.array.set( value, offset );
- return this;
- },
- getX: function ( index ) {
- return this.array[ index * this.itemSize ];
- },
- setX: function ( index, x ) {
- this.array[ index * this.itemSize ] = x;
- return this;
- },
- getY: function ( index ) {
- return this.array[ index * this.itemSize + 1 ];
- },
- setY: function ( index, y ) {
- this.array[ index * this.itemSize + 1 ] = y;
- return this;
- },
- getZ: function ( index ) {
- return this.array[ index * this.itemSize + 2 ];
- },
- setZ: function ( index, z ) {
- this.array[ index * this.itemSize + 2 ] = z;
- return this;
- },
- getW: function ( index ) {
- return this.array[ index * this.itemSize + 3 ];
- },
- setW: function ( index, w ) {
- this.array[ index * this.itemSize + 3 ] = w;
- return this;
- },
- setXY: function ( index, x, y ) {
- index *= this.itemSize;
- this.array[ index + 0 ] = x;
- this.array[ index + 1 ] = y;
- return this;
- },
- setXYZ: function ( index, x, y, z ) {
- index *= this.itemSize;
- this.array[ index + 0 ] = x;
- this.array[ index + 1 ] = y;
- this.array[ index + 2 ] = z;
- return this;
- },
- setXYZW: function ( index, x, y, z, w ) {
- index *= this.itemSize;
- this.array[ index + 0 ] = x;
- this.array[ index + 1 ] = y;
- this.array[ index + 2 ] = z;
- this.array[ index + 3 ] = w;
- return this;
- },
- clone: function () {
- return new this.constructor().copy( this );
- }
- };
- //
- THREE.Int8Attribute = function ( array, itemSize ) {
- return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
- };
- THREE.Uint8Attribute = function ( array, itemSize ) {
- return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
- };
- THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
- return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
- };
- THREE.Int16Attribute = function ( array, itemSize ) {
- return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
- };
- THREE.Uint16Attribute = function ( array, itemSize ) {
- return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
- };
- THREE.Int32Attribute = function ( array, itemSize ) {
- return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
- };
- THREE.Uint32Attribute = function ( array, itemSize ) {
- return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
- };
- THREE.Float32Attribute = function ( array, itemSize ) {
- return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
- };
- THREE.Float64Attribute = function ( array, itemSize ) {
- return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
- };
- // Deprecated
- THREE.DynamicBufferAttribute = function ( array, itemSize ) {
- console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
- return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
- };
|