瀏覽代碼

InterleavedBufferAttribute: Added toJSON().

Mugen87 5 年之前
父節點
當前提交
9b89f1d248

+ 5 - 0
docs/api/en/core/InterleavedBufferAttribute.html

@@ -45,6 +45,11 @@
 			How many values make up each item.
 		</p>
 
+		<h3>[property:String name]</h3>
+		<p>
+		Optional name for this attribute instance. Default is an empty string.
+		</p>
+
 		<h3>[property:Integer offset]</h3>
 		<p>
 			The offset in the underlying array buffer where an item starts.

+ 5 - 0
docs/api/zh/core/InterleavedBufferAttribute.html

@@ -44,6 +44,11 @@
 			队列中每个矢量有多少个元素构成。
 		</p>
 
+		<h3>[property:String name]</h3>
+		<p>
+		Optional name for this attribute instance. Default is an empty string.
+		</p>
+
 		<h3>[property:Integer offset]</h3>
 		<p>
 			缓存队列中每个元素的起始位置的偏移量。

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

@@ -12,6 +12,7 @@ export class InterleavedBufferAttribute {
 		normalized?: boolean
 	);
 
+	name: string;
 	data: InterleavedBuffer;
 	itemSize: number;
 	offset: number;
@@ -45,5 +46,11 @@ export class InterleavedBufferAttribute {
 		z: number,
 		w: number
 	): InterleavedBufferAttribute;
+	toJSON(): {
+		itemSize: number,
+		type: string,
+		array: number[],
+		normalized: boolean
+	};
 
 }

+ 29 - 0
src/core/InterleavedBufferAttribute.js

@@ -8,6 +8,8 @@ var _vector = new Vector3();
 
 function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
 
+	this.name = '';
+
 	this.data = interleavedBuffer;
 	this.itemSize = itemSize;
 	this.offset = offset;
@@ -152,6 +154,33 @@ Object.assign( InterleavedBufferAttribute.prototype, {
 
 		return this;
 
+	},
+
+	toJSON: function () {
+
+		// deinterleave data and save it as an ordinary buffer attribute for now
+
+		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 {
+			itemSize: this.itemSize,
+			type: this.array.constructor.name,
+			array: array,
+			normalized: this.normalized
+		};
+
 	}
 
 } );