Bladeren bron

Split shapes func. to shapes / lines; added holes

Paul Booker 8 jaren geleden
bovenliggende
commit
8570748186
1 gewijzigde bestanden met toevoegingen van 64 en 54 verwijderingen
  1. 64 54
      examples/webgl_geometry_shapes.html

+ 64 - 54
examples/webgl_geometry_shapes.html

@@ -33,7 +33,6 @@
 			var mouseXOnMouseDown = 0;
 
 			var windowHalfX = window.innerWidth / 2;
-			var windowHalfY = window.innerHeight / 2;
 
 			init();
 			animate();
@@ -105,6 +104,12 @@
 					mesh.scale.set( s, s, s );
 					group.add( mesh );
 
+					addLineShape( shape, extrudeSettings, color, x, y, z, rx, ry, rz, s );
+
+				}
+
+				function addLineShape( shape, extrudeSettings, color, x, y, z, rx, ry, rz, s ) {
+
 					// lines
 
 					shape.autoClose = true;
@@ -150,28 +155,28 @@
 
 				var californiaPts = [];
 
-				californiaPts.push( new THREE.Vector2 ( 610, 320 ) );
-				californiaPts.push( new THREE.Vector2 ( 450, 300 ) );
-				californiaPts.push( new THREE.Vector2 ( 392, 392 ) );
-				californiaPts.push( new THREE.Vector2 ( 266, 438 ) );
-				californiaPts.push( new THREE.Vector2 ( 190, 570 ) );
-				californiaPts.push( new THREE.Vector2 ( 190, 600 ) );
-				californiaPts.push( new THREE.Vector2 ( 160, 620 ) );
-				californiaPts.push( new THREE.Vector2 ( 160, 650 ) );
-				californiaPts.push( new THREE.Vector2 ( 180, 640 ) );
-				californiaPts.push( new THREE.Vector2 ( 165, 680 ) );
-				californiaPts.push( new THREE.Vector2 ( 150, 670 ) );
-				californiaPts.push( new THREE.Vector2 (  90, 737 ) );
-				californiaPts.push( new THREE.Vector2 (  80, 795 ) );
-				californiaPts.push( new THREE.Vector2 (  50, 835 ) );
-				californiaPts.push( new THREE.Vector2 (  64, 870 ) );
-				californiaPts.push( new THREE.Vector2 (  60, 945 ) );
-				californiaPts.push( new THREE.Vector2 ( 300, 945 ) );
-				californiaPts.push( new THREE.Vector2 ( 300, 743 ) );
-				californiaPts.push( new THREE.Vector2 ( 600, 473 ) );
-				californiaPts.push( new THREE.Vector2 ( 626, 425 ) );
-				californiaPts.push( new THREE.Vector2 ( 600, 370 ) );
-				californiaPts.push( new THREE.Vector2 ( 610, 320 ) );
+				californiaPts.push( new THREE.Vector2( 610, 320 ) );
+				californiaPts.push( new THREE.Vector2( 450, 300 ) );
+				californiaPts.push( new THREE.Vector2( 392, 392 ) );
+				californiaPts.push( new THREE.Vector2( 266, 438 ) );
+				californiaPts.push( new THREE.Vector2( 190, 570 ) );
+				californiaPts.push( new THREE.Vector2( 190, 600 ) );
+				californiaPts.push( new THREE.Vector2( 160, 620 ) );
+				californiaPts.push( new THREE.Vector2( 160, 650 ) );
+				californiaPts.push( new THREE.Vector2( 180, 640 ) );
+				californiaPts.push( new THREE.Vector2( 165, 680 ) );
+				californiaPts.push( new THREE.Vector2( 150, 670 ) );
+				californiaPts.push( new THREE.Vector2(  90, 737 ) );
+				californiaPts.push( new THREE.Vector2(  80, 795 ) );
+				californiaPts.push( new THREE.Vector2(  50, 835 ) );
+				californiaPts.push( new THREE.Vector2(  64, 870 ) );
+				californiaPts.push( new THREE.Vector2(  60, 945 ) );
+				californiaPts.push( new THREE.Vector2( 300, 945 ) );
+				californiaPts.push( new THREE.Vector2( 300, 743 ) );
+				californiaPts.push( new THREE.Vector2( 600, 473 ) );
+				californiaPts.push( new THREE.Vector2( 626, 425 ) );
+				californiaPts.push( new THREE.Vector2( 600, 370 ) );
+				californiaPts.push( new THREE.Vector2( 610, 320 ) );
 
 				for( var i = 0; i < californiaPts.length; i ++ ) californiaPts[ i ].multiplyScalar( 0.25 );
 
@@ -181,10 +186,10 @@
 				// Triangle
 
 				var triangleShape = new THREE.Shape();
-				triangleShape.moveTo(  80, 20 );
-				triangleShape.lineTo(  40, 80 );
+				triangleShape.moveTo( 80, 20 );
+				triangleShape.lineTo( 40, 80 );
 				triangleShape.lineTo( 120, 80 );
-				triangleShape.lineTo(  80, 20 ); // close path
+				triangleShape.lineTo( 80, 20 ); // close path
 
 
 				// Heart
@@ -195,7 +200,7 @@
 
 				heartShape.moveTo( x + 25, y + 25 );
 				heartShape.bezierCurveTo( x + 25, y + 25, x + 20, y, x, y );
-				heartShape.bezierCurveTo( x - 30, y, x - 30, y + 35,x - 30,y + 35 );
+				heartShape.bezierCurveTo( x - 30, y, x - 30, y + 35, x - 30, y + 35 );
 				heartShape.bezierCurveTo( x - 30, y + 55, x - 10, y + 77, x + 25, y + 95 );
 				heartShape.bezierCurveTo( x + 60, y + 77, x + 80, y + 55, x + 80, y + 35 );
 				heartShape.bezierCurveTo( x + 80, y + 35, x + 80, y, x + 50, y );
@@ -207,7 +212,7 @@
 				var sqLength = 80;
 
 				var squareShape = new THREE.Shape();
-				squareShape.moveTo( 0,0 );
+				squareShape.moveTo( 0, 0 );
 				squareShape.lineTo( 0, sqLength );
 				squareShape.lineTo( sqLength, sqLength );
 				squareShape.lineTo( sqLength, 0 );
@@ -219,7 +224,7 @@
 				var rectLength = 120, rectWidth = 40;
 
 				var rectShape = new THREE.Shape();
-				rectShape.moveTo( 0,0 );
+				rectShape.moveTo( 0, 0 );
 				rectShape.lineTo( 0, rectWidth );
 				rectShape.lineTo( rectLength, rectWidth );
 				rectShape.lineTo( rectLength, 0 );
@@ -230,12 +235,12 @@
 
 				var roundedRectShape = new THREE.Shape();
 
-				( function roundedRect( ctx, x, y, width, height, radius ){
+				( function roundedRect( ctx, x, y, width, height, radius ) {
 
 					ctx.moveTo( x, y + radius );
 					ctx.lineTo( x, y + height - radius );
 					ctx.quadraticCurveTo( x, y + height, x + radius, y + height );
-					ctx.lineTo( x + width - radius, y + height) ;
+					ctx.lineTo( x + width - radius, y + height );
 					ctx.quadraticCurveTo( x + width, y + height, x + width, y + height - radius );
 					ctx.lineTo( x + width, y + radius );
 					ctx.quadraticCurveTo( x + width, y, x + width - radius, y );
@@ -262,9 +267,9 @@
 				var circleShape = new THREE.Shape();
 				circleShape.moveTo( 0, circleRadius );
 				circleShape.quadraticCurveTo( circleRadius, circleRadius, circleRadius, 0 );
-				circleShape.quadraticCurveTo( circleRadius, -circleRadius, 0, -circleRadius );
-				circleShape.quadraticCurveTo( -circleRadius, -circleRadius, -circleRadius, 0 );
-				circleShape.quadraticCurveTo( -circleRadius, circleRadius, 0, circleRadius );
+				circleShape.quadraticCurveTo( circleRadius, - circleRadius, 0, - circleRadius );
+				circleShape.quadraticCurveTo( - circleRadius, - circleRadius, - circleRadius, 0 );
+				circleShape.quadraticCurveTo( - circleRadius, circleRadius, 0, circleRadius );
 
 
 				// Fish
@@ -273,23 +278,23 @@
 
 				var fishShape = new THREE.Shape();
 
-				fishShape.moveTo(x,y);
-				fishShape.quadraticCurveTo(x + 50, y - 80, x + 90, y - 10);
-				fishShape.quadraticCurveTo(x + 100, y - 10, x + 115, y - 40);
-				fishShape.quadraticCurveTo(x + 115, y, x + 115, y + 40);
-				fishShape.quadraticCurveTo(x + 100, y + 10, x + 90, y + 10);
-				fishShape.quadraticCurveTo(x + 50, y + 80, x, y);
+				fishShape.moveTo( x, y );
+				fishShape.quadraticCurveTo( x + 50, y - 80, x + 90, y - 10 );
+				fishShape.quadraticCurveTo( x + 100, y - 10, x + 115, y - 40 );
+				fishShape.quadraticCurveTo( x + 115, y, x + 115, y + 40 );
+				fishShape.quadraticCurveTo( x + 100, y + 10, x + 90, y + 10 );
+				fishShape.quadraticCurveTo( x + 50, y + 80, x, y );
 
 
 				// Arc circle
 
 				var arcShape = new THREE.Shape();
 				arcShape.moveTo( 50, 10 );
-				arcShape.absarc( 10, 10, 40, 0, Math.PI*2, false );
+				arcShape.absarc( 10, 10, 40, 0, Math.PI * 2, false );
 
 				var holePath = new THREE.Path();
 				holePath.moveTo( 20, 10 );
-				holePath.absarc( 10, 10, 10, 0, Math.PI*2, true );
+				holePath.absarc( 10, 10, 10, 0, Math.PI * 2, true );
 				arcShape.holes.push( holePath );
 
 
@@ -297,17 +302,17 @@
 
 				var smileyShape = new THREE.Shape();
 				smileyShape.moveTo( 80, 40 );
-				smileyShape.absarc( 40, 40, 40, 0, Math.PI*2, false );
+				smileyShape.absarc( 40, 40, 40, 0, Math.PI * 2, false );
 
 				var smileyEye1Path = new THREE.Path();
 				smileyEye1Path.moveTo( 35, 20 );
-				smileyEye1Path.absellipse( 25, 20, 10, 10, 0, Math.PI*2, true );
+				smileyEye1Path.absellipse( 25, 20, 10, 10, 0, Math.PI * 2, true );
 
 				smileyShape.holes.push( smileyEye1Path );
 
 				var smileyEye2Path = new THREE.Path();
 				smileyEye2Path.moveTo( 65, 20 );
-				smileyEye2Path.absarc( 55, 20, 10, 0, Math.PI*2, true );
+				smileyEye2Path.absarc( 55, 20, 10, 0, Math.PI * 2, true );
 				smileyShape.holes.push( smileyEye2Path );
 
 				var smileyMouthPath = new THREE.Path();
@@ -323,10 +328,10 @@
 				// Spline shape
 
 				var splinepts = [];
-				splinepts.push( new THREE.Vector2 ( 70, 20 ) );
-				splinepts.push( new THREE.Vector2 ( 80, 90 ) );
-				splinepts.push( new THREE.Vector2 ( -30, 70 ) );
-				splinepts.push( new THREE.Vector2 ( 0, 0 ) );
+				splinepts.push( new THREE.Vector2( 70, 20 ) );
+				splinepts.push( new THREE.Vector2( 80, 90 ) );
+				splinepts.push( new THREE.Vector2( - 30, 70 ) );
+				splinepts.push( new THREE.Vector2( 0, 0 ) );
 
 				var splineShape = new THREE.Shape();
 				splineShape.moveTo( 0, 0 );
@@ -343,10 +348,18 @@
 				addShape( squareShape,      extrudeSettings, 0x0040f0,  150,  100, 0, 0, 0, 0, 1 );
 				addShape( heartShape,       extrudeSettings, 0xf00000,   60,  100, 0, 0, 0, Math.PI, 1 );
 				addShape( circleShape,      extrudeSettings, 0x00f000,  120,  250, 0, 0, 0, 0, 1 );
-				addShape( fishShape,        extrudeSettings, 0x404040,  -60,  200, 0, 0, 0, 0, 1 );
+				addShape( fishShape,        extrudeSettings, 0x404040, - 60,  200, 0, 0, 0, 0, 1 );
 				addShape( smileyShape,      extrudeSettings, 0xf000f0, -200,  250, 0, 0, 0, Math.PI, 1 );
 				addShape( arcShape,         extrudeSettings, 0x804000,  150,    0, 0, 0, 0, 0, 1 );
-				addShape( splineShape,      extrudeSettings, 0x808080,  -50, -100, 0, 0, 0, 0, 1 );
+				addShape( splineShape,      extrudeSettings, 0x808080, - 50, -100, 0, 0, 0, 0, 1 );
+
+				addLineShape( arcShape.holes[ 0 ], extrudeSettings, 0x804000, 150, 0, 0, 0, 0, 0, 1 );
+
+				for ( var i = 0; i < smileyShape.holes.length; i += 1 ) {
+
+					addLineShape( smileyShape.holes[ i ], extrudeSettings, 0xf000f0, - 200, 250, 0, 0, 0, Math.PI, 1 );
+
+				}
 
 				//
 
@@ -371,9 +384,6 @@
 
 			function onWindowResize() {
 
-				windowHalfX = window.innerWidth / 2;
-				windowHalfY = window.innerHeight / 2;
-
 				camera.aspect = window.innerWidth / window.innerHeight;
 				camera.updateProjectionMatrix();