소스 검색

Change extrudegeometry to buffergeometry

gero3 8 년 전
부모
커밋
c720cc8c0b
1개의 변경된 파일325개의 추가작업 그리고 200개의 파일을 삭제
  1. 325 200
      src/geometries/ExtrudeGeometry.js

+ 325 - 200
src/geometries/ExtrudeGeometry.js

@@ -1,4 +1,6 @@
-import { Geometry } from '../core/Geometry';
+//import { Geometry } from '../core/Geometry';
+import { BufferGeometry } from '../core/BufferGeometry';
+import { Float32BufferAttribute } from '../core/BufferAttribute';
 import { Vector2 } from '../math/Vector2';
 import { Face3 } from '../core/Face3';
 import { Vector3 } from '../math/Vector3';
@@ -30,20 +32,20 @@ import { ShapeUtils } from '../extras/ShapeUtils';
 
 function ExtrudeGeometry( shapes, options ) {
 
-	if ( typeof( shapes ) === "undefined" ) {
+	if ( typeof(shapes) === "undefined") {
 
 		shapes = [];
 		return;
 
 	}
 
-	Geometry.call( this );
+	BufferGeometry.call(this);
 
 	this.type = 'ExtrudeGeometry';
 
-	shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
+	shapes = Array.isArray(shapes) ? shapes : [shapes];
 
-	this.addShapeList( shapes, options );
+	this.addShapeList(shapes, options);
 
 	this.computeFaceNormals();
 
@@ -57,23 +59,83 @@ function ExtrudeGeometry( shapes, options ) {
 
 }
 
-ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
+ExtrudeGeometry.prototype = Object.create(BufferGeometry.prototype);
 ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
 
-ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
+ExtrudeGeometry.prototype.getArrays = function() {
+
+	var verticesArray;
+	var positionAttribute = this.getAttribute("position");
+	if (positionAttribute) {
+		
+		verticesArray = Array.prototype.slice.call(positionAttribute.array);
+		
+	} else {
+		
+		verticesArray = [];
+		
+	}
+	
+	var uvArray;
+	var uvAttribute = this.getAttribute("uv");
+	if (positionAttribute) {
+		
+		uvArray = Array.prototype.slice.call(uvAttribute.array);
+		
+	} else {
+		
+		uvArray = [];
+		
+	}
+
+	var indicesArray;
+	var IndexAttribute = this.index;
+	
+	if (IndexAttribute) {
+		
+		indicesArray = Array.prototype.slice.call(IndexAttribute.array);
+		
+	} else {
+		
+		indicesArray = [];
+		
+	}
+
+	return {
+		position: verticesArray,
+		uv:uvArray,
+		index: indicesArray
+	};
+
+};
+
+ExtrudeGeometry.prototype.addShapeList = function(shapes, options) {
 
 	var sl = shapes.length;
+	options.arrays = this.getArrays()
 
-	for ( var s = 0; s < sl; s ++ ) {
+	for (var s = 0; s < sl; s++) {
 
-		var shape = shapes[ s ];
-		this.addShape( shape, options );
+		var shape = shapes[s];
+		this.addShape(shape, options);
 
 	}
+	
+	this.setIndex(options.arrays.index);
+	this.addAttribute('position', new Float32BufferAttribute(options.arrays.position, 3));
+	this.addAttribute('uv', new Float32BufferAttribute(options.arrays.uv, 2));
 
 };
 
-ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
+ExtrudeGeometry.prototype.addShape = function(shape, options) {
+
+	var arrays = options.arrays ? options.arrays : this.getArrays();
+	var verticesArray = arrays.position;
+	var indicesArray = arrays.index;
+	var uvArray = arrays.uv;
+	
+	var placeholder = []; 
+
 
 	var amount = options.amount !== undefined ? options.amount : 100;
 
@@ -94,9 +156,9 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 	var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : ExtrudeGeometry.WorldUVGenerator;
 
 	var splineTube, binormal, normal, position2;
-	if ( extrudePath ) {
+	if (extrudePath) {
 
-		extrudePts = extrudePath.getSpacedPoints( steps );
+		extrudePts = extrudePath.getSpacedPoints(steps);
 
 		extrudeByPath = true;
 		bevelEnabled = false; // bevels not supported for path extrusion
@@ -105,7 +167,7 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 		// TODO1 - have a .isClosed in spline?
 
-		splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames( steps, false );
+		splineTube = options.frames !== undefined ? options.frames : extrudePath.computeFrenetFrames(steps, false);
 
 		// console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
 
@@ -117,7 +179,7 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 	// Safeguards if bevels are not enabled
 
-	if ( ! bevelEnabled ) {
+	if (!bevelEnabled) {
 
 		bevelSegments = 0;
 		bevelThickness = 0;
@@ -130,28 +192,28 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 	var ahole, h, hl; // looping of holes
 	var scope = this;
 
-	var shapesOffset = this.vertices.length;
+	var shapesOffset = verticesArray.length / 3;
 
-	var shapePoints = shape.extractPoints( curveSegments );
+	var shapePoints = shape.extractPoints(curveSegments);
 
 	var vertices = shapePoints.shape;
 	var holes = shapePoints.holes;
 
-	var reverse = ! ShapeUtils.isClockWise( vertices );
+	var reverse = !ShapeUtils.isClockWise(vertices);
 
-	if ( reverse ) {
+	if (reverse) {
 
 		vertices = vertices.reverse();
 
 		// Maybe we should also check if holes are in the opposite direction, just to be safe ...
 
-		for ( h = 0, hl = holes.length; h < hl; h ++ ) {
+		for (h = 0, hl = holes.length; h < hl; h++) {
 
-			ahole = holes[ h ];
+			ahole = holes[h];
 
-			if ( ShapeUtils.isClockWise( ahole ) ) {
+			if (ShapeUtils.isClockWise(ahole)) {
 
-				holes[ h ] = ahole.reverse();
+				holes[h] = ahole.reverse();
 
 			}
 
@@ -162,26 +224,26 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 	}
 
 
-	var faces = ShapeUtils.triangulateShape( vertices, holes );
+	var faces = ShapeUtils.triangulateShape(vertices, holes);
 
 	/* Vertices */
 
 	var contour = vertices; // vertices has all points but contour has only points of circumference
 
-	for ( h = 0, hl = holes.length; h < hl; h ++ ) {
+	for (h = 0, hl = holes.length; h < hl; h++) {
 
-		ahole = holes[ h ];
+		ahole = holes[h];
 
-		vertices = vertices.concat( ahole );
+		vertices = vertices.concat(ahole);
 
 	}
 
 
-	function scalePt2( pt, vec, size ) {
+	function scalePt2(pt, vec, size) {
 
-		if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
+		if (!vec) console.error("THREE.ExtrudeGeometry: vec does not exist");
 
-		return vec.clone().multiplyScalar( size ).add( pt );
+		return vec.clone().multiplyScalar(size).add(pt);
 
 	}
 
@@ -193,7 +255,7 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 	// Find directions for point movement
 
 
-	function getBevelVec( inPt, inPrev, inNext ) {
+	function getBevelVec(inPt, inPrev, inNext) {
 
 		// computes for inPt the corresponding point inPt' on a new contour
 		//   shifted by 1 unit (length of normalized vector) to the left
@@ -202,86 +264,92 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 		// inPt' is the intersection of the two lines parallel to the two
 		//  adjacent edges of inPt at a distance of 1 unit on the left side.
 
-		var v_trans_x, v_trans_y, shrink_by = 1;		// resulting translation vector for inPt
+		var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
 
 		// good reading for geometry algorithms (here: line-line intersection)
 		// http://geomalgorithms.com/a05-_intersect-1.html
 
-		var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
-		var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
+		var v_prev_x = inPt.x - inPrev.x,
+			v_prev_y = inPt.y - inPrev.y;
+		var v_next_x = inNext.x - inPt.x,
+			v_next_y = inNext.y - inPt.y;
 
-		var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
+		var v_prev_lensq = (v_prev_x * v_prev_x + v_prev_y * v_prev_y);
 
 		// check for collinear edges
-		var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
+		var collinear0 = (v_prev_x * v_next_y - v_prev_y * v_next_x);
 
-		if ( Math.abs( collinear0 ) > Number.EPSILON ) {
+		if (Math.abs(collinear0) > Number.EPSILON) {
 
 			// not collinear
 
 			// length of vectors for normalizing
 
-			var v_prev_len = Math.sqrt( v_prev_lensq );
-			var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
+			var v_prev_len = Math.sqrt(v_prev_lensq);
+			var v_next_len = Math.sqrt(v_next_x * v_next_x + v_next_y * v_next_y);
 
 			// shift adjacent points by unit vectors to the left
 
-			var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
-			var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
+			var ptPrevShift_x = (inPrev.x - v_prev_y / v_prev_len);
+			var ptPrevShift_y = (inPrev.y + v_prev_x / v_prev_len);
 
-			var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
-			var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
+			var ptNextShift_x = (inNext.x - v_next_y / v_next_len);
+			var ptNextShift_y = (inNext.y + v_next_x / v_next_len);
 
 			// scaling factor for v_prev to intersection point
 
-			var sf = (  ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
-						( ptNextShift_y - ptPrevShift_y ) * v_next_x    ) /
-					  ( v_prev_x * v_next_y - v_prev_y * v_next_x );
+			var sf = ((ptNextShift_x - ptPrevShift_x) * v_next_y -
+					(ptNextShift_y - ptPrevShift_y) * v_next_x) /
+				(v_prev_x * v_next_y - v_prev_y * v_next_x);
 
 			// vector from inPt to intersection point
 
-			v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
-			v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
+			v_trans_x = (ptPrevShift_x + v_prev_x * sf - inPt.x);
+			v_trans_y = (ptPrevShift_y + v_prev_y * sf - inPt.y);
 
 			// Don't normalize!, otherwise sharp corners become ugly
 			//  but prevent crazy spikes
-			var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
-			if ( v_trans_lensq <= 2 ) {
+			var v_trans_lensq = (v_trans_x * v_trans_x + v_trans_y * v_trans_y);
+			if (v_trans_lensq <= 2) {
 
-				return	new Vector2( v_trans_x, v_trans_y );
+				return new Vector2(v_trans_x, v_trans_y);
 
-			} else {
+			}
+			else {
 
-				shrink_by = Math.sqrt( v_trans_lensq / 2 );
+				shrink_by = Math.sqrt(v_trans_lensq / 2);
 
 			}
 
-		} else {
+		}
+		else {
 
 			// handle special case of collinear edges
 
-			var direction_eq = false;		// assumes: opposite
-			if ( v_prev_x > Number.EPSILON ) {
+			var direction_eq = false; // assumes: opposite
+			if (v_prev_x > Number.EPSILON) {
 
-				if ( v_next_x > Number.EPSILON ) {
+				if (v_next_x > Number.EPSILON) {
 
 					direction_eq = true;
 
 				}
 
-			} else {
+			}
+			else {
 
-				if ( v_prev_x < - Number.EPSILON ) {
+				if (v_prev_x < -Number.EPSILON) {
 
-					if ( v_next_x < - Number.EPSILON ) {
+					if (v_next_x < -Number.EPSILON) {
 
 						direction_eq = true;
 
 					}
 
-				} else {
+				}
+				else {
 
-					if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
+					if (Math.sign(v_prev_y) === Math.sign(v_next_y)) {
 
 						direction_eq = true;
 
@@ -291,99 +359,101 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 			}
 
-			if ( direction_eq ) {
+			if (direction_eq) {
 
 				// console.log("Warning: lines are a straight sequence");
-				v_trans_x = - v_prev_y;
-				v_trans_y =  v_prev_x;
-				shrink_by = Math.sqrt( v_prev_lensq );
+				v_trans_x = -v_prev_y;
+				v_trans_y = v_prev_x;
+				shrink_by = Math.sqrt(v_prev_lensq);
 
-			} else {
+			}
+			else {
 
 				// console.log("Warning: lines are a straight spike");
 				v_trans_x = v_prev_x;
 				v_trans_y = v_prev_y;
-				shrink_by = Math.sqrt( v_prev_lensq / 2 );
+				shrink_by = Math.sqrt(v_prev_lensq / 2);
 
 			}
 
 		}
 
-		return	new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
+		return new Vector2(v_trans_x / shrink_by, v_trans_y / shrink_by);
 
 	}
 
 
 	var contourMovements = [];
 
-	for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
+	for (var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i++, j++, k++) {
 
-		if ( j === il ) j = 0;
-		if ( k === il ) k = 0;
+		if (j === il) j = 0;
+		if (k === il) k = 0;
 
 		//  (j)---(i)---(k)
 		// console.log('i,j,k', i, j , k)
 
-		contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
+		contourMovements[i] = getBevelVec(contour[i], contour[j], contour[k]);
 
 	}
 
-	var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
+	var holesMovements = [],
+		oneHoleMovements, verticesMovements = contourMovements.concat();
 
-	for ( h = 0, hl = holes.length; h < hl; h ++ ) {
+	for (h = 0, hl = holes.length; h < hl; h++) {
 
-		ahole = holes[ h ];
+		ahole = holes[h];
 
 		oneHoleMovements = [];
 
-		for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
+		for (i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i++, j++, k++) {
 
-			if ( j === il ) j = 0;
-			if ( k === il ) k = 0;
+			if (j === il) j = 0;
+			if (k === il) k = 0;
 
 			//  (j)---(i)---(k)
-			oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
+			oneHoleMovements[i] = getBevelVec(ahole[i], ahole[j], ahole[k]);
 
 		}
 
-		holesMovements.push( oneHoleMovements );
-		verticesMovements = verticesMovements.concat( oneHoleMovements );
+		holesMovements.push(oneHoleMovements);
+		verticesMovements = verticesMovements.concat(oneHoleMovements);
 
 	}
 
 
 	// Loop bevelSegments, 1 for the front, 1 for the back
 
-	for ( b = 0; b < bevelSegments; b ++ ) {
+	for (b = 0; b < bevelSegments; b++) {
 
 		//for ( b = bevelSegments; b > 0; b -- ) {
 
 		t = b / bevelSegments;
-		z = bevelThickness * Math.cos( t * Math.PI / 2 );
-		bs = bevelSize * Math.sin( t * Math.PI / 2 );
+		z = bevelThickness * Math.cos(t * Math.PI / 2);
+		bs = bevelSize * Math.sin(t * Math.PI / 2);
 
 		// contract shape
 
-		for ( i = 0, il = contour.length; i < il; i ++ ) {
+		for (i = 0, il = contour.length; i < il; i++) {
 
-			vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
+			vert = scalePt2(contour[i], contourMovements[i], bs);
 
-			v( vert.x, vert.y,  - z );
+			v(vert.x, vert.y, -z);
 
 		}
 
 		// expand holes
 
-		for ( h = 0, hl = holes.length; h < hl; h ++ ) {
+		for (h = 0, hl = holes.length; h < hl; h++) {
 
-			ahole = holes[ h ];
-			oneHoleMovements = holesMovements[ h ];
+			ahole = holes[h];
+			oneHoleMovements = holesMovements[h];
 
-			for ( i = 0, il = ahole.length; i < il; i ++ ) {
+			for (i = 0, il = ahole.length; i < il; i++) {
 
-				vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
+				vert = scalePt2(ahole[i], oneHoleMovements[i], bs);
 
-				v( vert.x, vert.y,  - z );
+				v(vert.x, vert.y, -z);
 
 			}
 
@@ -395,24 +465,25 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 	// Back facing vertices
 
-	for ( i = 0; i < vlen; i ++ ) {
+	for (i = 0; i < vlen; i++) {
 
-		vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
+		vert = bevelEnabled ? scalePt2(vertices[i], verticesMovements[i], bs) : vertices[i];
 
-		if ( ! extrudeByPath ) {
+		if (!extrudeByPath) {
 
-			v( vert.x, vert.y, 0 );
+			v(vert.x, vert.y, 0);
 
-		} else {
+		}
+		else {
 
 			// v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
 
-			normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
-			binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
+			normal.copy(splineTube.normals[0]).multiplyScalar(vert.x);
+			binormal.copy(splineTube.binormals[0]).multiplyScalar(vert.y);
 
-			position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
+			position2.copy(extrudePts[0]).add(normal).add(binormal);
 
-			v( position2.x, position2.y, position2.z );
+			v(position2.x, position2.y, position2.z);
 
 		}
 
@@ -423,26 +494,27 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 	var s;
 
-	for ( s = 1; s <= steps; s ++ ) {
+	for (s = 1; s <= steps; s++) {
 
-		for ( i = 0; i < vlen; i ++ ) {
+		for (i = 0; i < vlen; i++) {
 
-			vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
+			vert = bevelEnabled ? scalePt2(vertices[i], verticesMovements[i], bs) : vertices[i];
 
-			if ( ! extrudeByPath ) {
+			if (!extrudeByPath) {
 
-				v( vert.x, vert.y, amount / steps * s );
+				v(vert.x, vert.y, amount / steps * s);
 
-			} else {
+			}
+			else {
 
 				// v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
 
-				normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
-				binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
+				normal.copy(splineTube.normals[s]).multiplyScalar(vert.x);
+				binormal.copy(splineTube.binormals[s]).multiplyScalar(vert.y);
 
-				position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
+				position2.copy(extrudePts[s]).add(normal).add(binormal);
 
-				v( position2.x, position2.y, position2.z );
+				v(position2.x, position2.y, position2.z);
 
 			}
 
@@ -454,39 +526,40 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 	// Add bevel segments planes
 
 	//for ( b = 1; b <= bevelSegments; b ++ ) {
-	for ( b = bevelSegments - 1; b >= 0; b -- ) {
+	for (b = bevelSegments - 1; b >= 0; b--) {
 
 		t = b / bevelSegments;
-		z = bevelThickness * Math.cos ( t * Math.PI / 2 );
-		bs = bevelSize * Math.sin( t * Math.PI / 2 );
+		z = bevelThickness * Math.cos(t * Math.PI / 2);
+		bs = bevelSize * Math.sin(t * Math.PI / 2);
 
 		// contract shape
 
-		for ( i = 0, il = contour.length; i < il; i ++ ) {
+		for (i = 0, il = contour.length; i < il; i++) {
 
-			vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
-			v( vert.x, vert.y,  amount + z );
+			vert = scalePt2(contour[i], contourMovements[i], bs);
+			v(vert.x, vert.y, amount + z);
 
 		}
 
 		// expand holes
 
-		for ( h = 0, hl = holes.length; h < hl; h ++ ) {
+		for (h = 0, hl = holes.length; h < hl; h++) {
 
-			ahole = holes[ h ];
-			oneHoleMovements = holesMovements[ h ];
+			ahole = holes[h];
+			oneHoleMovements = holesMovements[h];
 
-			for ( i = 0, il = ahole.length; i < il; i ++ ) {
+			for (i = 0, il = ahole.length; i < il; i++) {
 
-				vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
+				vert = scalePt2(ahole[i], oneHoleMovements[i], bs);
 
-				if ( ! extrudeByPath ) {
+				if (!extrudeByPath) {
 
-					v( vert.x, vert.y,  amount + z );
+					v(vert.x, vert.y, amount + z);
 
-				} else {
+				}
+				else {
 
-					v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
+					v(vert.x, vert.y + extrudePts[steps - 1].y, extrudePts[steps - 1].x + z);
 
 				}
 
@@ -511,17 +584,17 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 	function buildLidFaces() {
 
-		if ( bevelEnabled ) {
+		if (bevelEnabled) {
 
 			var layer = 0; // steps + 1
 			var offset = vlen * layer;
 
 			// Bottom faces
 
-			for ( i = 0; i < flen; i ++ ) {
+			for (i = 0; i < flen; i++) {
 
-				face = faces[ i ];
-				f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
+				face = faces[i];
+				f3(face[2] + offset, face[1] + offset, face[0] + offset);
 
 			}
 
@@ -530,30 +603,31 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 			// Top faces
 
-			for ( i = 0; i < flen; i ++ ) {
+			for (i = 0; i < flen; i++) {
 
-				face = faces[ i ];
-				f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
+				face = faces[i];
+				f3(face[0] + offset, face[1] + offset, face[2] + offset);
 
 			}
 
-		} else {
+		}
+		else {
 
 			// Bottom faces
 
-			for ( i = 0; i < flen; i ++ ) {
+			for (i = 0; i < flen; i++) {
 
-				face = faces[ i ];
-				f3( face[ 2 ], face[ 1 ], face[ 0 ] );
+				face = faces[i];
+				f3(face[2], face[1], face[0]);
 
 			}
 
 			// Top faces
 
-			for ( i = 0; i < flen; i ++ ) {
+			for (i = 0; i < flen; i++) {
 
-				face = faces[ i ];
-				f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
+				face = faces[i];
+				f3(face[0] + vlen * steps, face[1] + vlen * steps, face[2] + vlen * steps);
 
 			}
 
@@ -566,13 +640,13 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 	function buildSideFaces() {
 
 		var layeroffset = 0;
-		sidewalls( contour, layeroffset );
+		sidewalls(contour, layeroffset);
 		layeroffset += contour.length;
 
-		for ( h = 0, hl = holes.length; h < hl; h ++ ) {
+		for (h = 0, hl = holes.length; h < hl; h++) {
 
-			ahole = holes[ h ];
-			sidewalls( ahole, layeroffset );
+			ahole = holes[h];
+			sidewalls(ahole, layeroffset);
 
 			//, true
 			layeroffset += ahole.length;
@@ -581,74 +655,111 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 	}
 
-	function sidewalls( contour, layeroffset ) {
+	function sidewalls(contour, layeroffset) {
 
 		var j, k;
 		i = contour.length;
 
-		while ( -- i >= 0 ) {
+		while (--i >= 0) {
 
 			j = i;
 			k = i - 1;
-			if ( k < 0 ) k = contour.length - 1;
+			if (k < 0) k = contour.length - 1;
 
 			//console.log('b', i,j, i-1, k,vertices.length);
 
-			var s = 0, sl = steps  + bevelSegments * 2;
+			var s = 0,
+				sl = steps + bevelSegments * 2;
 
-			for ( s = 0; s < sl; s ++ ) {
+			for (s = 0; s < sl; s++) {
 
 				var slen1 = vlen * s;
-				var slen2 = vlen * ( s + 1 );
+				var slen2 = vlen * (s + 1);
 
 				var a = layeroffset + j + slen1,
 					b = layeroffset + k + slen1,
 					c = layeroffset + k + slen2,
 					d = layeroffset + j + slen2;
 
-				f4( a, b, c, d, contour, s, sl, j, k );
+				f4(a, b, c, d, contour, s, sl, j, k);
 
 			}
 
 		}
 
 	}
-
-
-	function v( x, y, z ) {
-
-		scope.vertices.push( new Vector3( x, y, z ) );
+	function v(x, y, z) {
+		
+		placeholder.push(x);
+		placeholder.push(y);
+		placeholder.push(z);
 
 	}
 
-	function f3( a, b, c ) {
 
-		a += shapesOffset;
-		b += shapesOffset;
-		c += shapesOffset;
+	function f3(a, b, c) {
 
-		scope.faces.push( new Face3( a, b, c, null, null, 0 ) );
+		addVertex(a);
+		addVertex(b);
+		addVertex(c);
 
-		var uvs = uvgen.generateTopUV( scope, a, b, c );
+		var nextIndex = verticesArray.length/3;
+		var uvs = uvgen.generateTopUV( scope, verticesArray , nextIndex - 3, nextIndex - 2, nextIndex - 1 );
 
-		scope.faceVertexUvs[ 0 ].push( uvs );
+		uvArray.push(uvs[0].x);
+		uvArray.push(uvs[0].y);
+		uvArray.push(uvs[1].x);
+		uvArray.push(uvs[1].y);
+		uvArray.push(uvs[2].x);
+		uvArray.push(uvs[2].y);
+		//scope.faceVertexUvs[ 0 ].push( uvs );
 
 	}
 
-	function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
+	function f4(a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2) {
 
-		a += shapesOffset;
-		b += shapesOffset;
-		c += shapesOffset;
-		d += shapesOffset;
+		addVertex(a);
+		addVertex(b);
+		addVertex(d);
 
-		scope.faces.push( new Face3( a, b, d, null, null, 1 ) );
-		scope.faces.push( new Face3( b, c, d, null, null, 1 ) );
+		addVertex(b);
+		addVertex(c);
+		addVertex(d);
 
 		var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
+		uvArray.push(uvs[0].x);
+		uvArray.push(uvs[0].y);
+		uvArray.push(uvs[1].x);
+		uvArray.push(uvs[1].y);
+		uvArray.push(uvs[3].x);
+		uvArray.push(uvs[3].y);
+		
+		uvArray.push(uvs[1].x);
+		uvArray.push(uvs[1].y);
+		uvArray.push(uvs[2].x);
+		uvArray.push(uvs[2].y);
+		uvArray.push(uvs[3].x);
+		uvArray.push(uvs[3].y);
+
+		//scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
+		//scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
 
-		scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
-		scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
+	}
+	
+	function addVertex(index){
+		
+		indicesArray.push(verticesArray.length/3);
+		verticesArray.push(placeholder[index * 3 + 0]);
+		verticesArray.push(placeholder[index * 3 + 1]);
+		verticesArray.push(placeholder[index * 3 + 2]);
+		
+	}
+
+	if (!options.arrays) {
+
+		this.setIndex(indicesArray);
+		this.addAttribute('position', new Float32BufferAttribute(verticesArray, 3));
+		this.addAttribute('uv', new Float32BufferAttribute(options.arrays.uv, 2));
 
 	}
 
@@ -656,47 +767,59 @@ ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
 
 ExtrudeGeometry.WorldUVGenerator = {
 
-	generateTopUV: function ( geometry, indexA, indexB, indexC ) {
-
-		var vertices = geometry.vertices;
+	generateTopUV: function(geometry, vertices , indexA, indexB, indexC) {
 
-		var a = vertices[ indexA ];
-		var b = vertices[ indexB ];
-		var c = vertices[ indexC ];
+		var a_x = vertices[indexA * 3];
+		var a_y = vertices[indexA * 3 + 1];
+		var b_x = vertices[indexB * 3];
+		var b_y = vertices[indexB * 3 + 1];
+		var c_x = vertices[indexC * 3];
+		var c_y = vertices[indexC * 3 + 1];
 
 		return [
-			new Vector2( a.x, a.y ),
-			new Vector2( b.x, b.y ),
-			new Vector2( c.x, c.y )
+			new Vector2(a_x, a_y),
+			new Vector2(b_x, b_y),
+			new Vector2(c_x, c_y)
 		];
 
 	},
 
-	generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
+	generateSideWallUV: function(geometry, vertices,  indexA, indexB, indexC, indexD) {
 
-		var vertices = geometry.vertices;
 
-		var a = vertices[ indexA ];
-		var b = vertices[ indexB ];
-		var c = vertices[ indexC ];
-		var d = vertices[ indexD ];
 
-		if ( Math.abs( a.y - b.y ) < 0.01 ) {
+		var a = vertices[indexA];
+		
+		var a_x = vertices[indexA * 3];
+		var a_y = vertices[indexA * 3 + 1];
+		var a_z = vertices[indexA * 3 + 2];
+		var b_x = vertices[indexB * 3];
+		var b_y = vertices[indexB * 3 + 1];
+		var b_z = vertices[indexB * 3 + 2];
+		var c_x = vertices[indexC * 3];
+		var c_y = vertices[indexC * 3 + 1];
+		var c_z = vertices[indexC * 3 + 2];
+		var d_x = vertices[indexD * 3];
+		var d_y = vertices[indexD * 3 + 1];
+		var d_z = vertices[indexD * 3 + 2];
+
+		if (Math.abs(a_y - b_y) < 0.01) {
 
 			return [
-				new Vector2( a.x, 1 - a.z ),
-				new Vector2( b.x, 1 - b.z ),
-				new Vector2( c.x, 1 - c.z ),
-				new Vector2( d.x, 1 - d.z )
+				new Vector2(a_x, 1 - a_z),
+				new Vector2(b_x, 1 - b_z),
+				new Vector2(c_x, 1 - c_z),
+				new Vector2(d_x, 1 - d_z)
 			];
 
-		} else {
+		}
+		else {
 
 			return [
-				new Vector2( a.y, 1 - a.z ),
-				new Vector2( b.y, 1 - b.z ),
-				new Vector2( c.y, 1 - c.z ),
-				new Vector2( d.y, 1 - d.z )
+				new Vector2(a_y, 1 - a_z),
+				new Vector2(b_y, 1 - b_z),
+				new Vector2(c_y, 1 - c_z),
+				new Vector2(d_y, 1 - d_z)
 			];
 
 		}
@@ -705,4 +828,6 @@ ExtrudeGeometry.WorldUVGenerator = {
 };
 
 
-export { ExtrudeGeometry };
+export {
+	ExtrudeGeometry
+};