Sfoglia il codice sorgente

BufferGeometry: Added merge. Only non-indexed geometry.

Mr.doob 10 anni fa
parent
commit
d4334724b0
1 ha cambiato i file con 34 aggiunte e 2 eliminazioni
  1. 34 2
      src/core/BufferGeometry.js

+ 34 - 2
src/core/BufferGeometry.js

@@ -757,11 +757,43 @@ THREE.BufferGeometry.prototype = {
 		*/
 
 		return offsets;
+
 	},
 
-	merge: function () {
+	merge: function ( geometry, offset ) {
+
+		if ( geometry instanceof THREE.BufferGeometry === false ) {
+
+			console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
+			return;
+
+		}
+
+		if ( offset === undefined ) offset = 0;
+
+		var attributes = this.attributes;
+
+		for ( var key in attributes ) {
+
+			if ( geometry.attributes[ key ] === undefined ) continue;
+
+			var attribute1 = attributes[ key ];
+			var attributeArray1 = attribute1.array;
+
+			var attribute2 = geometry.attributes[ key ];
+			var attributeArray2 = attribute2.array;
+
+			var attributeSize = attribute2.itemSize;
+
+			for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
+
+				attributeArray1[ j ] = attributeArray2[ i ];
 
-		console.log( 'BufferGeometry.merge(): TODO' );
+			}
+
+		}
+
+		return this;
 
 	},