Browse Source

InterleavedBufferAttribute: Add support for clone().

Mugen87 5 years ago
parent
commit
5aae4a3092
2 changed files with 28 additions and 1 deletions
  1. 2 0
      src/core/InterleavedBufferAttribute.d.ts
  2. 26 1
      src/core/InterleavedBufferAttribute.js

+ 2 - 0
src/core/InterleavedBufferAttribute.d.ts

@@ -1,3 +1,4 @@
+import { BufferAttribute } from './BufferAttribute';
 import { InterleavedBuffer } from './InterleavedBuffer';
 import { InterleavedBuffer } from './InterleavedBuffer';
 import { Matrix4 } from './../math/Matrix4';
 import { Matrix4 } from './../math/Matrix4';
 /**
 /**
@@ -24,6 +25,7 @@ export class InterleavedBufferAttribute {
 	readonly isInterleavedBufferAttribute: true;
 	readonly isInterleavedBufferAttribute: true;
 
 
 	applyMatrix4( m: Matrix4 ): this;
 	applyMatrix4( m: Matrix4 ): this;
+	clone(): BufferAttribute;
 	getX( index: number ): number;
 	getX( index: number ): number;
 	setX( index: number, x: number ): InterleavedBufferAttribute;
 	setX( index: number, x: number ): InterleavedBufferAttribute;
 	getY( index: number ): number;
 	getY( index: number ): number;

+ 26 - 1
src/core/InterleavedBufferAttribute.js

@@ -1,4 +1,5 @@
 import { Vector3 } from '../math/Vector3.js';
 import { Vector3 } from '../math/Vector3.js';
+import { BufferAttribute } from './BufferAttribute.js';
 
 
 /**
 /**
  * @author benaadams / https://twitter.com/ben_a_adams
  * @author benaadams / https://twitter.com/ben_a_adams
@@ -156,9 +157,31 @@ Object.assign( InterleavedBufferAttribute.prototype, {
 
 
 	},
 	},
 
 
+	clone: function () {
+
+		console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.' );
+
+		var array = [];
+
+		for ( var i = 0; i < this.count; i ++ ) {
+
+			var index = i * this.data.stride + this.offset;
+
+			for ( var j = 0; j < this.itemSize; j ++ ) {
+
+				array.push( this.data.array[ index + j ] );
+
+			}
+
+		}
+
+		return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
+
+	},
+
 	toJSON: function () {
 	toJSON: function () {
 
 
-		// deinterleave data and save it as an ordinary buffer attribute for now
+		console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.' );
 
 
 		var array = [];
 		var array = [];
 
 
@@ -174,6 +197,8 @@ Object.assign( InterleavedBufferAttribute.prototype, {
 
 
 		}
 		}
 
 
+		// deinterleave data and save it as an ordinary buffer attribute for now
+
 		return {
 		return {
 			itemSize: this.itemSize,
 			itemSize: this.itemSize,
 			type: this.array.constructor.name,
 			type: this.array.constructor.name,