Browse Source

Clean up.

Mr.doob 13 years ago
parent
commit
61605499c1

+ 404 - 0
examples/canvas_geometry_shapes.html

@@ -0,0 +1,404 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<title>three.js canvas - geometry - shapes</title>
+		<meta charset="utf-8">
+		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
+		<style>
+			body {
+				font-family: Monospace;
+				background-color: #f0f0f0;
+				margin: 0px;
+				overflow: hidden;
+			}
+		</style>
+	</head>
+	<body>
+		<canvas id="debug" style="position:absolute; left:100px"></canvas>
+
+		<script src="../build/three.min.js"></script>
+
+		<script src="js/Stats.js"></script>
+
+
+		<script>
+
+			var container, stats;
+
+			var camera, scene, renderer;
+
+			var text, plane;
+
+			var targetRotation = 0;
+			var targetRotationOnMouseDown = 0;
+
+			var mouseX = 0;
+			var mouseXOnMouseDown = 0;
+
+			var windowHalfX = window.innerWidth / 2;
+			var windowHalfY = window.innerHeight / 2;
+
+			init();
+			animate();
+
+			function init() {
+
+				container = document.createElement( 'div' );
+				document.body.appendChild( container );
+
+				camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
+				camera.position.set( 0, 150, 500 );
+
+				scene = new THREE.Scene();
+
+				var light = new THREE.DirectionalLight( 0xffffff );
+				light.position.set( 0, 0, 1 );
+				scene.add( light );
+
+				parent = new THREE.Object3D();
+				parent.position.y = 50;
+				scene.add( parent );
+
+				function addShape( shape, color, x, y, z, rx, ry, rz, s ) {
+
+					// flat shape
+
+					var geometry = new THREE.ShapeGeometry( shape );
+
+					var mesh = new THREE.Mesh( geometry, new THREE.MeshLambertMaterial( { color: color, overdraw: true } ) );
+					mesh.position.set( x, y, z );
+					mesh.rotation.set( rx, ry, rz );
+					mesh.scale.set( s, s, s );
+					parent.add( mesh );
+
+					// line
+
+					var geometry = shape.createPointsGeometry();
+					var material = new THREE.LineBasicMaterial( { linewidth: 10, color: 0x333333, transparent: true } );
+
+					var line = new THREE.Line( geometry, material );
+					line.position.set( x, y, z );
+					line.rotation.set( rx, ry, rz );
+					line.scale.set( s, s, s );
+					parent.add( line );
+
+				}
+
+
+				// California
+
+				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 ) );
+
+				var californiaShape = new THREE.Shape( californiaPts );
+
+
+				// Triangle
+
+				var triangleShape = new THREE.Shape();
+				triangleShape.moveTo(  80, 20 );
+				triangleShape.lineTo(  40, 80 );
+				triangleShape.lineTo( 120, 80 );
+				triangleShape.lineTo(  80, 20 ); // close path
+
+
+				// Heart
+
+				var x = 0, y = 0;
+
+				var heartShape = new THREE.Shape(); // From http://blog.burlock.org/html5/130-paths
+
+				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 + 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 );
+				heartShape.bezierCurveTo( x + 35, y, x + 25, y + 25, x + 25, y + 25 );
+
+
+				// Square
+
+				var sqLength = 80;
+
+				var squareShape = new THREE.Shape();
+				squareShape.moveTo( 0,0 );
+				squareShape.lineTo( 0, sqLength );
+				squareShape.lineTo( sqLength, sqLength );
+				squareShape.lineTo( sqLength, 0 );
+				squareShape.lineTo( 0, 0 );
+
+
+				// Rectangle
+
+				var rectLength = 120, rectWidth = 40;
+
+				var rectShape = new THREE.Shape();
+				rectShape.moveTo( 0,0 );
+				rectShape.lineTo( 0, rectWidth );
+				rectShape.lineTo( rectLength, rectWidth );
+				rectShape.lineTo( rectLength, 0 );
+				rectShape.lineTo( 0, 0 );
+
+
+				// Rounded rectangle
+
+				var roundedRectShape = new THREE.Shape();
+
+				( 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.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 );
+					ctx.lineTo( x + radius, y );
+					ctx.quadraticCurveTo( x, y, x, y + radius );
+
+				} )( roundedRectShape, 0, 0, 50, 50, 20 );
+
+
+				// Circle
+
+				var circleRadius = 40;
+				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 );
+
+
+				// Fish
+
+				x = y = 0;
+
+				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);
+
+
+				// Arc circle
+
+				var arcShape = new THREE.Shape();
+				arcShape.moveTo( 50, 10 );
+				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 );
+				arcShape.holes.push( holePath );
+
+
+				// Smiley
+
+				var smileyShape = new THREE.Shape();
+				smileyShape.moveTo( 80, 40 );
+				smileyShape.absarc( 40, 40, 40, 0, Math.PI*2, false );
+
+				var smileyEye1Path = new THREE.Path();
+				smileyEye1Path.moveTo( 35, 20 );
+				// smileyEye1Path.absarc( 25, 20, 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 );
+				smileyShape.holes.push( smileyEye2Path );
+
+				var smileyMouthPath = new THREE.Path();
+				// ugly box mouth
+				// smileyMouthPath.moveTo( 20, 40 );
+				// smileyMouthPath.lineTo( 60, 40 );
+				// smileyMouthPath.lineTo( 60, 60 );
+				// smileyMouthPath.lineTo( 20, 60 );
+				// smileyMouthPath.lineTo( 20, 40 );
+
+				smileyMouthPath.moveTo( 20, 40 );
+				smileyMouthPath.quadraticCurveTo( 40, 60, 60, 40 );
+				smileyMouthPath.bezierCurveTo( 70, 45, 70, 50, 60, 60 );
+				smileyMouthPath.quadraticCurveTo( 40, 80, 20, 60 );
+				smileyMouthPath.quadraticCurveTo( 5, 50, 20, 40 );
+
+				smileyShape.holes.push( smileyMouthPath );
+
+
+				// Spline shape + path extrusion
+
+				var splinepts = [];
+				splinepts.push( new THREE.Vector2 ( 350, 100 ) );
+				splinepts.push( new THREE.Vector2 ( 400, 450 ) );
+				splinepts.push( new THREE.Vector2 ( -140, 350 ) );
+				splinepts.push( new THREE.Vector2 ( 0, 0 ) );
+
+				var splineShape = new THREE.Shape(  );
+				splineShape.moveTo( 0, 0 );
+				splineShape.splineThru( splinepts );
+
+
+				// addShape( shape, color, x, y, z, rx, ry,rz, s );
+
+				addShape( californiaShape, 0xffaa00, -300, -100, 0, 0, 0, 0, 0.25 );
+				addShape( triangleShape, 0xffee00, -180, 0, 0, 0, 0, 0, 1 );
+				addShape( roundedRectShape, 0x005500, -150, 150, 0, 0, 0, 0, 1 );
+				addShape( squareShape, 0x0055ff, 150, 100, 0, 0, 0, 0, 1 );
+				addShape( heartShape, 0xff1100, 0, 100, 0, Math.PI, 0, 0, 1 );
+				addShape( circleShape, 0x00ff11, 120, 250, 0, 0, 0, 0, 1 );
+				addShape( fishShape, 0x222222, -60, 200, 0, 0, 0, 0, 1 );
+				addShape( smileyShape, 0xee00ff, -270, 250, 0, Math.PI, 0, 0, 1 );
+				addShape( arcShape, 0xbb4422, 150, 0, 0, 0, 0, 0, 1 );
+				addShape( splineShape, 0x888888, -50, -100, 0, 0, 0, 0, 0.2 );
+
+				//
+
+				renderer = new THREE.CanvasRenderer( { antialias: true } );
+				renderer.setSize( window.innerWidth, window.innerHeight );
+				renderer.sortObjects = false;
+				renderer.sortElements = false;
+				container.appendChild( renderer.domElement );
+
+				stats = new Stats();
+				stats.domElement.style.position = 'absolute';
+				stats.domElement.style.top = '0px';
+				container.appendChild( stats.domElement );
+
+				document.addEventListener( 'mousedown', onDocumentMouseDown, false );
+				document.addEventListener( 'touchstart', onDocumentTouchStart, false );
+				document.addEventListener( 'touchmove', onDocumentTouchMove, false );
+
+				//
+
+				window.addEventListener( 'resize', onWindowResize, false );
+
+			}
+
+			function onWindowResize() {
+
+				windowHalfX = window.innerWidth / 2;
+				windowHalfY = window.innerHeight / 2;
+
+				camera.aspect = window.innerWidth / window.innerHeight;
+				camera.updateProjectionMatrix();
+
+				renderer.setSize( window.innerWidth, window.innerHeight );
+
+			}
+
+			//
+
+			function onDocumentMouseDown( event ) {
+
+				event.preventDefault();
+
+				document.addEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.addEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.addEventListener( 'mouseout', onDocumentMouseOut, false );
+
+				mouseXOnMouseDown = event.clientX - windowHalfX;
+				targetRotationOnMouseDown = targetRotation;
+
+			}
+
+			function onDocumentMouseMove( event ) {
+
+				mouseX = event.clientX - windowHalfX;
+
+				targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.02;
+
+			}
+
+			function onDocumentMouseUp( event ) {
+
+				document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
+
+			}
+
+			function onDocumentMouseOut( event ) {
+
+				document.removeEventListener( 'mousemove', onDocumentMouseMove, false );
+				document.removeEventListener( 'mouseup', onDocumentMouseUp, false );
+				document.removeEventListener( 'mouseout', onDocumentMouseOut, false );
+
+			}
+
+			function onDocumentTouchStart( event ) {
+
+				if ( event.touches.length == 1 ) {
+
+					event.preventDefault();
+
+					mouseXOnMouseDown = event.touches[ 0 ].pageX - windowHalfX;
+					targetRotationOnMouseDown = targetRotation;
+
+				}
+
+			}
+
+			function onDocumentTouchMove( event ) {
+
+				if ( event.touches.length == 1 ) {
+
+					event.preventDefault();
+
+					mouseX = event.touches[ 0 ].pageX - windowHalfX;
+					targetRotation = targetRotationOnMouseDown + ( mouseX - mouseXOnMouseDown ) * 0.05;
+
+				}
+
+			}
+
+			//
+
+			function animate() {
+
+				requestAnimationFrame( animate );
+
+				render();
+				stats.update();
+
+			}
+
+			function render() {
+
+				parent.rotation.y += ( targetRotation - parent.rotation.y ) * 0.05;
+				renderer.render( scene, camera );
+
+			}
+
+		</script>
+
+	</body>
+</html>

+ 0 - 147
examples/canvas_geometry_shapes_2d.html

@@ -1,147 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <title>three.js webgl - geometry - shape 2d</title>
-    <meta charset="utf-8">
-    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
-
-    <style>
-      * {
-        margin: 0;
-        padding: 0;
-      }
-      body {
-        overflow: hidden;
-        color: #808080;
-        font-family: Monospace;
-        font-size: 13px;
-      }
-      #debug {
-        display: block;
-        position: relative;
-        margin: 50px auto;
-      }
-      #info {
-        position: absolute;
-        top: 0px; width: 100%;
-        padding: 5px;
-        text-align: center;
-      }
-    </style>
-  </head>
-
-  <body>
-    <div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> webgl - 2d geometry in 3d space</div>
-    <canvas id="debug" width="800" height="600"></canvas>
-
-    <script src="../build/three.min.js"></script>
-    <script src="js/Stats.js"></script>
-
-    <script>
-
-      var width = 800;
-      var height = 600;
-
-      var stats = new Stats();
-      stats.domElement.style.position = 'absolute';
-      stats.domElement.style.top = '0px';
-      document.body.appendChild( stats.domElement );
-
-      var renderer = new THREE.CanvasRenderer({
-        canvas: document.getElementById( 'debug' )
-      });
-      renderer.sortElements = false;
-      var camera = new THREE.OrthographicCamera(0, width, 0, height, -10000);
-      var scene = new THREE.Scene();
-
-      var a = width / 4;
-      var b = height / 4;
-      var c = width / 4 + width / 2;
-      var d = height / 4 + height / 2;
-
-      renderer.setSize( width, height );
-
-      var points = [], radius = width / 4, ox = width / 2, oy = height / 2;
-
-      for ( var i = 0, l = 33; i < l; i++ ) {
-
-        var pct = ( i ) / 32;
-        var angle = pct * Math.PI + Math.PI;
-        var x = radius * Math.cos( angle );
-        var y = radius * Math.sin( angle );
-
-        points.push( new THREE.Vector2( x, y ) );
-
-      }
-
-      points.push( new THREE.Vector2(
-        radius * Math.cos( Math.PI * 1.5 + Math.PI ),
-        radius * Math.sin( Math.PI * 1.5 + Math.PI )
-      ) );
-
-      var shape = new THREE.Shape(points);
-      var geometry = shape.makeGeometry();
-
-      // Make the fill.
-
-      var material = new THREE.MeshBasicMaterial({
-        color: 0xFF7d72,
-        overdraw: true,
-        transparent: true
-      });
-      material.side = THREE.DoubleSide;
-
-      var mesh = new THREE.Mesh( geometry, material );
-      mesh.position.x = ox;
-      mesh.position.y = oy;
-
-      scene.add( camera );
-      scene.add( mesh );
-
-      // Make the outline.
-
-      geometry = new THREE.ShapeGeometry( shape );
-      material = new THREE.LineBasicMaterial({
-        linewidth: 25,
-        color: 0x333333,
-        overdraw: true,
-        transparent: true
-      });
-
-      // Close the line
-      geometry.vertices.push(geometry.vertices[0].clone());
-
-      mesh = new THREE.Line( geometry, material );
-      mesh.position.x = ox;
-      mesh.position.y = oy;
-
-      scene.add( mesh );
-
-      loop();
-
-      function loop() {
-
-        rotate();
-
-        renderer.render( scene, camera );
-        stats.update();
-
-        requestAnimationFrame( loop );
-
-      }
-
-      function rotate() {
-
-        for ( var i = 0, l = scene.__objects.length; i < l; i++ ) {
-
-          var mesh = scene.__objects[ i ];
-          mesh.rotation.y += 0.05;
-
-        }
-
-      }
-
-    </script>
-
-</body>
-</html>

+ 44 - 60
examples/webgl_geometry_shapes.html

@@ -67,10 +67,25 @@
 				parent.position.y = 50;
 				scene.add( parent );
 
-				function addGeometry( geometry, points, spacedPoints, color, x, y, z, rx, ry, rz, s ) {
+				function addShape( shape, extrudeSettings, color, x, y, z, rx, ry, rz, s ) {
+
+					var points = shape.createPointsGeometry();
+					var spacedPoints = shape.createSpacedPointsGeometry( 100 );
+
+					// flat shape
+
+					var geometry = new THREE.ShapeGeometry( shape );
+
+					var mesh = THREE.SceneUtils.createMultiMaterialObject( geometry, [ new THREE.MeshLambertMaterial( { color: color } ), new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true, transparent: true } ) ] );
+					mesh.position.set( x, y, z - 125 );
+					mesh.rotation.set( rx, ry, rz );
+					mesh.scale.set( s, s, s );
+					parent.add( mesh );
 
 					// 3d shape
 
+					var geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
+
 					var mesh = THREE.SceneUtils.createMultiMaterialObject( geometry, [ new THREE.MeshLambertMaterial( { color: color } ), new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true, transparent: true } ) ] );
 					mesh.position.set( x, y, z - 75 );
 					mesh.rotation.set( rx, ry, rz );
@@ -105,7 +120,7 @@
 					// transparent line from equidistance sampled points
 
 					var line = new THREE.Line( spacedPoints, new THREE.LineBasicMaterial( { color: color, opacity: 0.2 } ) );
-					line.position.set( x, y, z + 100 );
+					line.position.set( x, y, z + 125 );
 					line.rotation.set( rx, ry, rz );
 					line.scale.set( s, s, s );
 					parent.add( line );
@@ -114,14 +129,13 @@
 
 					var pgeo = THREE.GeometryUtils.clone( spacedPoints );
 					var particles2 = new THREE.ParticleSystem( pgeo, new THREE.ParticleBasicMaterial( { color: color, size: 2, opacity: 0.5 } ) );
-					particles2.position.set( x, y, z + 100 );
+					particles2.position.set( x, y, z + 125 );
 					particles2.rotation.set( rx, ry, rz );
 					particles2.scale.set( s, s, s );
 					parent.add( particles2 );
 
 				}
 
-				var extrudeSettings = {	amount: 20,  bevelEnabled: true, bevelSegments: 2, steps: 2 }; // bevelSegments: 2, steps: 2 , bevelSegments: 5, bevelSize: 8, bevelThickness:5,
 
 				// California
 
@@ -152,9 +166,6 @@
 
 				var californiaShape = new THREE.Shape( californiaPts );
 
-				var california3d = new THREE.ExtrudeGeometry( californiaShape, { amount: 20	} );
-				var californiaPoints = californiaShape.createPointsGeometry();
-				var californiaSpacedPoints = californiaShape.createSpacedPointsGeometry( 100 );
 
 				// Triangle
 
@@ -164,10 +175,6 @@
 				triangleShape.lineTo( 120, 80 );
 				triangleShape.lineTo(  80, 20 ); // close path
 
-				var triangle3d = triangleShape.extrude( extrudeSettings );
-				var trianglePoints = triangleShape.createPointsGeometry();
-				var triangleSpacedPoints = triangleShape.createSpacedPointsGeometry();
-
 
 				// Heart
 
@@ -183,11 +190,6 @@
 				heartShape.bezierCurveTo( x + 80, y + 35, x + 80, y, x + 50, y );
 				heartShape.bezierCurveTo( x + 35, y, x + 25, y + 25, x + 25, y + 25 );
 
-				var heart3d = heartShape.extrude( extrudeSettings );
-				var heartPoints = heartShape.createPointsGeometry();
-				var heartSpacedPoints = heartShape.createSpacedPointsGeometry();
-
-				//heartShape.debug( document.getElementById("debug") );
 
 				// Square
 
@@ -200,9 +202,6 @@
 				squareShape.lineTo( sqLength, 0 );
 				squareShape.lineTo( 0, 0 );
 
-				var square3d = squareShape.extrude( extrudeSettings );
-				var squarePoints = squareShape.createPointsGeometry();
-				var squareSpacedPoints = squareShape.createSpacedPointsGeometry();
 
 				// Rectangle
 
@@ -215,20 +214,12 @@
 				rectShape.lineTo( rectLength, 0 );
 				rectShape.lineTo( 0, 0 );
 
-				var rect3d = rectShape.extrude( extrudeSettings );
-				var rectPoints = rectShape.createPointsGeometry();
-				var rectSpacedPoints = rectShape.createSpacedPointsGeometry();
 
 				// Rounded rectangle
 
 				var roundedRectShape = new THREE.Shape();
-				roundedRect( roundedRectShape, 0, 0, 50, 50, 20 );
-
-				var roundedRect3d = roundedRectShape.extrude( extrudeSettings );
-				var roundedRectPoints = roundedRectShape.createPointsGeometry();
-				var roundedRectSpacedPoints = roundedRectShape.createSpacedPointsGeometry();
 
-				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 );
@@ -240,7 +231,8 @@
 					ctx.lineTo( x + radius, y );
 					ctx.quadraticCurveTo( x, y, x, y + radius );
 
-				}
+				} )( roundedRectShape, 0, 0, 50, 50, 20 );
+
 
 				// Circle
 
@@ -252,9 +244,6 @@
 				circleShape.quadraticCurveTo( -circleRadius, -circleRadius, -circleRadius, 0 );
 				circleShape.quadraticCurveTo( -circleRadius, circleRadius, 0, circleRadius );
 
-				var circle3d = circleShape.extrude( extrudeSettings );
-				var circlePoints = circleShape.createPointsGeometry();
-				var circleSpacedPoints = circleShape.createSpacedPointsGeometry();
 
 				// Fish
 
@@ -269,9 +258,6 @@
 				fishShape.quadraticCurveTo(x + 100, y + 10, x + 90, y + 10);
 				fishShape.quadraticCurveTo(x + 50, y + 80, x, y);
 
-				var fish3d = fishShape.extrude( extrudeSettings );
-				var fishPoints = fishShape.createPointsGeometry();
-				var fishSpacedPoints = fishShape.createSpacedPointsGeometry();
 
 				// Arc circle
 
@@ -284,10 +270,6 @@
 				holePath.absarc( 10, 10, 10, 0, Math.PI*2, true );
 				arcShape.holes.push( holePath );
 
-				var arc3d = arcShape.extrude( extrudeSettings );
-				var arcPoints = arcShape.createPointsGeometry();
-				var arcSpacedPoints = arcShape.createSpacedPointsGeometry();
-
 
 				// Smiley
 
@@ -299,7 +281,7 @@
 				smileyEye1Path.moveTo( 35, 20 );
 				// smileyEye1Path.absarc( 25, 20, 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();
@@ -324,10 +306,6 @@
 				smileyShape.holes.push( smileyMouthPath );
 
 
-				var smiley3d = smileyShape.extrude( extrudeSettings );
-				var smileyPoints = smileyShape.createPointsGeometry();
-				var smileySpacedPoints = smileyShape.createSpacedPointsGeometry();
-
 				// Spline shape + path extrusion
 
 				var splinepts = [];
@@ -340,7 +318,7 @@
 				splineShape.moveTo( 0, 0 );
 				splineShape.splineThru( splinepts );
 
-				//splineShape.debug( document.getElementById("debug") );
+				// splineShape.debug( document.getElementById("debug") );
 
 				// TODO 3d path?
 
@@ -350,25 +328,31 @@
 				apath.points.push(new THREE.Vector3(40, 220, 50));
 				apath.points.push(new THREE.Vector3(200, 290, 100));
 
+
+				var extrudeSettings = { amount: 20 }; // bevelSegments: 2, steps: 2 , bevelSegments: 5, bevelSize: 8, bevelThickness:5
+
+				// addShape( shape, color, x, y, z, rx, ry,rz, s );
+
+				addShape( californiaShape, extrudeSettings, 0xffaa00, -300, -100, 0, 0, 0, 0, 0.25 );
+
+				extrudeSettings.bevelEnabled = true;
+				extrudeSettings.bevelSegments = 2;
+				extrudeSettings.steps = 2;
+
+				addShape( triangleShape, extrudeSettings, 0xffee00, -180, 0, 0, 0, 0, 0, 1 );
+				addShape( roundedRectShape, extrudeSettings, 0x005500, -150, 150, 0, 0, 0, 0, 1 );
+				addShape( squareShape, extrudeSettings, 0x0055ff, 150, 100, 0, 0, 0, 0, 1 );
+				addShape( heartShape, extrudeSettings, 0xff1100, 0, 100, 0, Math.PI, 0, 0, 1 );
+				addShape( circleShape, extrudeSettings, 0x00ff11, 120, 250, 0, 0, 0, 0, 1 );
+				addShape( fishShape, extrudeSettings, 0x222222, -60, 200, 0, 0, 0, 0, 1 );
+				addShape( smileyShape, extrudeSettings, 0xee00ff, -270, 250, 0, Math.PI, 0, 0, 1 );
+				addShape( arcShape, extrudeSettings, 0xbb4422, 150, 0, 0, 0, 0, 0, 1 );
+
 				extrudeSettings.extrudePath = apath;
 				extrudeSettings.bevelEnabled = false;
 				extrudeSettings.steps = 20;
 
-				var splineShape3d = splineShape.extrude( extrudeSettings );
-				var splinePoints = splineShape.createPointsGeometry( );
-				var splineSpacedPoints = splineShape.createSpacedPointsGeometry( );
-
-				addGeometry( california3d, californiaPoints, californiaSpacedPoints,	0xffaa00, -300, -100, 0,     0, 0, 0, 0.25 );
-				addGeometry( triangle3d, trianglePoints, triangleSpacedPoints, 			0xffee00, -180,    0, 0,     0, 0, 0, 1 );
-				addGeometry( roundedRect3d, roundedRectPoints, roundedRectSpacedPoints,	0x005500, -150,  150, 0,     0, 0, 0, 1 );
-				addGeometry( square3d, squarePoints, squareSpacedPoints,				0x0055ff,  150,  100, 0,     0, 0, 0, 1 );
-				addGeometry( heart3d, heartPoints, heartSpacedPoints,					0xff1100,    0,  100, 0, 	 Math.PI, 0, 0, 1 );
-				addGeometry( circle3d, circlePoints, circleSpacedPoints,				0x00ff11,  120,  250, 0,     0, 0, 0, 1 );
-				addGeometry( fish3d, fishPoints, fishSpacedPoints,						0x222222,  -60,  200, 0,     0, 0, 0, 1 );
-				addGeometry( splineShape3d, splinePoints, splineSpacedPoints,			0x888888,  -50,  -100, -50,  0, 0, 0, 0.2 );
-				addGeometry( arc3d, arcPoints, arcSpacedPoints,							0xbb4422,  150,    0, 0,     0, 0, 0, 1 );
-				addGeometry( smiley3d, smileyPoints, smileySpacedPoints,				0xee00ff,  -270,    250, 0,  Math.PI, 0, 0, 1 );
-
+				addShape( splineShape, extrudeSettings, 0x888888, -50, -100, -50, 0, 0, 0, 0.2 );
 
 				//
 

+ 0 - 147
examples/webgl_geometry_shapes_2d.html

@@ -1,147 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
-  <head>
-    <title>three.js webgl - geometry - shape 2d</title>
-    <meta charset="utf-8">
-    <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
-
-    <style>
-      * {
-        margin: 0;
-        padding: 0;
-      }
-      body {
-        overflow: hidden;
-        color: #808080;
-        font-family: Monospace;
-        font-size: 13px;
-      }
-      #debug {
-        display: block;
-        position: relative;
-        margin: 50px auto;
-      }
-      #info {
-        position: absolute;
-        top: 0px; width: 100%;
-        padding: 5px;
-        text-align: center;
-      }
-    </style>
-  </head>
-
-  <body>
-    <div id="info"><a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> webgl - 2d geometry in 3d space</div>
-    <canvas id="debug" width="800" height="600"></canvas>
-
-    <script src="../build/three.min.js"></script>
-    <script src="js/Stats.js"></script>
-
-    <script>
-
-      var width = 800;
-      var height = 600;
-
-      var stats = new Stats();
-      stats.domElement.style.position = 'absolute';
-      stats.domElement.style.top = '0px';
-      document.body.appendChild( stats.domElement );
-
-      var renderer = new THREE.WebGLRenderer({
-        canvas: document.getElementById( 'debug' )
-      });
-      renderer.sortElements = false;
-      var camera = new THREE.OrthographicCamera(0, width, 0, height, -10000);
-      var scene = new THREE.Scene();
-
-      var a = width / 4;
-      var b = height / 4;
-      var c = width / 4 + width / 2;
-      var d = height / 4 + height / 2;
-
-      renderer.setSize( width, height );
-
-      var points = [], radius = width / 4, ox = width / 2, oy = height / 2;
-
-      for ( var i = 0, l = 33; i < l; i++ ) {
-
-        var pct = ( i ) / 32;
-        var angle = pct * Math.PI + Math.PI;
-        var x = radius * Math.cos( angle );
-        var y = radius * Math.sin( angle );
-
-        points.push( new THREE.Vector2( x, y ) );
-
-      }
-
-      points.push( new THREE.Vector2(
-        radius * Math.cos( Math.PI * 1.5 + Math.PI ),
-        radius * Math.sin( Math.PI * 1.5 + Math.PI )
-      ) );
-
-      var shape = new THREE.Shape(points);
-      var geometry = shape.makeGeometry();
-
-      // Make the fill.
-
-      var material = new THREE.MeshBasicMaterial({
-        color: 0xFF7d72,
-        overdraw: true,
-        transparent: true
-      });
-      material.side = THREE.DoubleSide;
-
-      var mesh = new THREE.Mesh( geometry, material );
-      mesh.position.x = ox;
-      mesh.position.y = oy;
-
-      scene.add( camera );
-      scene.add( mesh );
-
-      // Make the outline.
-
-      geometry = new THREE.ShapeGeometry( shape );
-      material = new THREE.LineBasicMaterial({
-        linewidth: 25,
-        color: 0x333333,
-        overdraw: true,
-        transparent: true
-      });
-
-      // Close the line
-      geometry.vertices.push(geometry.vertices[0].clone());
-
-      mesh = new THREE.Line( geometry, material );
-      mesh.position.x = ox;
-      mesh.position.y = oy;
-
-      scene.add( mesh );
-
-      loop();
-
-      function loop() {
-
-        rotate();
-
-        renderer.render( scene, camera );
-        stats.update();
-
-        requestAnimationFrame( loop );
-
-      }
-
-      function rotate() {
-
-        for ( var i = 0, l = scene.__objects.length; i < l; i++ ) {
-
-          var mesh = scene.__objects[ i ];
-          mesh.rotation.y += 0.05;
-
-        }
-
-      }
-
-    </script>
-
-</body>
-</html>

+ 86 - 109
src/extras/geometries/ShapeGeometry.js

@@ -6,177 +6,154 @@
  *
  * parameters = {
  *
- *  curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
+ *	curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  *
- *  material: <int> // material index for front and back faces
- *  uvGenerator: <Object> // object that provides UV generator functions
+ *	material: <int> // material index for front and back faces
+ *	uvGenerator: <Object> // object that provides UV generator functions
  *
  * }
  **/
 
-(function() {
+THREE.ShapeGeometry = function ( shapes, options ) {
 
-  THREE.ShapeGeometry = function( _shapes, options ) {
+	THREE.Geometry.call( this );
 
-    THREE.Geometry.call( this );
+	if ( shapes instanceof Array === false ) shapes = [ shapes ];
 
-    var shapes = _shapes instanceof Array ? _shapes : [ _shapes ];
+	this.shapebb = shapes[ shapes.length - 1 ].getBoundingBox();
 
-    this.shapebb = shapes[ shapes.length - 1 ].getBoundingBox();
+	this.addShapeList( shapes, options );
 
-    this.addShapeList( shapes, options );
+	this.computeCentroids();
+	this.computeFaceNormals();
 
-    this.computeCentroids();
-    this.computeFaceNormals();
+};
 
-  };
+THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
 
-  /**
-   * Extends THREE.Geometry
-   */
-  THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
-
-  /**
-   * Add an array of shapes to THREE.ShapeGeometry.
-   */
-  THREE.ShapeGeometry.prototype.addShapeList = function( shapes, options ) {
-
-    for ( var i = 0, l = shapes.length; i < l; i++ ) {
-
-      var shape = shapes[ i ];
-      this.addShape( shape, options );
-
-    }
-
-    return this;
-
-  };
+/**
+ * Add an array of shapes to THREE.ShapeGeometry.
+ */
+THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
 
-  /**
-   * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
-   */
-  THREE.ShapeGeometry.prototype.addShape = function( shape, _options ) {
+	for ( var i = 0, l = shapes.length; i < l; i++ ) {
 
-    var options = isUndefined( _options ) ? {} : _options;
+		var shape = shapes[ i ];
+		this.addShape( shape, options );
 
-    // TODO: This exists in THREE.ExtrudeGeometry, but not really used.
-    // var curveSegments = isNumber( options.curveSegments ) ? options.curveSegments : 12;
+	}
 
-    var material = options.material;
-    var uvgen = isUndefined( options.UVGenerator ) ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
+	return this;
 
-    var shapebb = this.shapebb;
+};
 
-    // Variable initialization
+/**
+ * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
+ */
+THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
 
-    var scope = this,
-      i, l, hole, s; // Iterable variables
+	if ( options === undefined ) options = {};
 
-    var shapesOffset = this.vertices.length;
-    var shapePoints = shape.extractPoints();
+	var material = options.material;
+	var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
 
-    var vertices = shapePoints.shape;
-    var holes = shapePoints.holes;
+	var shapebb = this.shapebb;
 
-    var reverse = !THREE.Shape.Utils.isClockWise( vertices );
+	// Variable initialization
 
-    if ( reverse ) {
+	var scope = this, i, l, hole, s; // Iterable variables
 
-      vertices = vertices.reverse();
+	var shapesOffset = this.vertices.length;
+	var shapePoints = shape.extractPoints();
 
-      // Maybe we should also check if holes are in the opposite direction, just to be safe...
+	var vertices = shapePoints.shape;
+	var holes = shapePoints.holes;
 
-      for ( i = 0, l = holes.length; i < l; i++ ) {
+	var reverse = !THREE.Shape.Utils.isClockWise( vertices );
 
-        hole = holes[ i ];
+	if ( reverse ) {
 
-        if ( THREE.Shape.Utils.isClockWise( hole ) ) {
+		vertices = vertices.reverse();
 
-          holes[ i ] = hole.reverse();
+		// Maybe we should also check if holes are in the opposite direction, just to be safe...
 
-        }
+		for ( i = 0, l = holes.length; i < l; i++ ) {
 
-      }
+			hole = holes[ i ];
 
-      reverse = false;
+			if ( THREE.Shape.Utils.isClockWise( hole ) ) {
 
-    }
+				holes[ i ] = hole.reverse();
 
-    var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
+			}
 
-    // Vertices
+		}
 
-    var contour = vertices;
+		reverse = false;
 
-    for ( i = 0, l = holes.length; i < l; i++ ) {
+	}
 
-      hole = holes[ i ];
-      vertices = vertices.concat( hole );
+	var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
 
-    }
+	// Vertices
 
-    // Variable initialization round 2
+	var contour = vertices;
 
-    var vert, vlen = vertices.length,
-        face, flen = faces.length,
-        cont, clen = contour.length;
+	for ( i = 0, l = holes.length; i < l; i++ ) {
 
-    /* Vertices */
+		hole = holes[ i ];
+		vertices = vertices.concat( hole );
 
-    // Make sure there is a z-depth, usually not the case
-    // when converting from THREE.Shape
+	}
 
-    for ( i = 0; i < vlen; i++ ) {
+	// Variable initialization round 2
 
-      vert = vertices[ i ];
-      v( vert.x, vert.y, 0 );
+	var vert, vlen = vertices.length;
+	var face, flen = faces.length;
+	var cont, clen = contour.length;
 
-    }
+	/* Vertices */
 
-    /* Faces */
+	// Make sure there is a z-depth, usually not the case
+	// when converting from THREE.Shape
 
-    for ( i = 0; i < flen; i++ ) {
+	for ( i = 0; i < vlen; i++ ) {
 
-      face = faces[ i ];
-      f3( face[ 2 ], face[ 1 ], face[ 0 ] );
+		vert = vertices[ i ];
+		v( vert.x, vert.y, 0 );
 
-    }
+	}
 
-    /**
-     * Utility functions for addShape method
-     */
+	/* Faces */
 
-    function v( x, y, z ) {
+	for ( i = 0; i < flen; i++ ) {
 
-      scope.vertices.push( new THREE.Vector3( x, y, z ) );
+		face = faces[ i ];
+		f3( face[ 2 ], face[ 1 ], face[ 0 ] );
 
-    }
+	}
 
-    function f3( a, b, c ) {
+	/**
+	 * Utility functions for addShape method
+	 */
 
-      a += shapesOffset;
-      b += shapesOffset;
-      c += shapesOffset;
+	function v( x, y, z ) {
 
-      scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
-      var uvs = uvgen.generateBottomUV( scope, shape, options, a, b, c );
+		scope.vertices.push( new THREE.Vector3( x, y, z ) );
 
-      scope.faceVertexUvs[ 0 ].push( uvs );
+	}
 
-    }
+	function f3( a, b, c ) {
 
-  };
+		a += shapesOffset;
+		b += shapesOffset;
+		c += shapesOffset;
 
-  /**
-   * A few utility functions.
-   */
+		scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
+		var uvs = uvgen.generateBottomUV( scope, shape, options, a, b, c );
 
-  function isNumber(o) {
-    return toString.call(o) == '[object Number]';
-  }
+		scope.faceVertexUvs[ 0 ].push( uvs );
 
-  function isUndefined(o) {
-    return o === void 0;
-  }
+	}
 
-})();
+};