瀏覽代碼

New PolyhedronBufferGeometry (#9757)

* PolyhedronBufferGeometry: Initial commit

* PolyhedronBufferGeometry: Update docs
Michael Herzog 8 年之前
父節點
當前提交
4e59e79c34

+ 54 - 0
docs/api/geometries/DodecahedronBufferGeometry.html

@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<base href="../../" />
+		<script src="list.js"></script>
+		<script src="page.js"></script>
+		<link type="text/css" rel="stylesheet" href="page.css" />
+	</head>
+	<body>
+		[page:PolyhedronBufferGeometry] &rarr;
+
+		<h1>[name]</h1>
+
+		<div class="desc">A class for generating a dodecahedron geometries.</div>
+
+		<iframe id="scene" src="scenes/geometry-browser.html#DodecahedronBufferGeometry"></iframe>
+
+		<script>
+
+		// iOS iframe auto-resize workaround
+
+		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
+
+			var scene = document.getElementById( 'scene' );
+
+			scene.style.width = getComputedStyle( scene ).width;
+			scene.style.height = getComputedStyle( scene ).height;
+			scene.setAttribute( 'scrolling', 'no' );
+
+		}
+
+		</script>
+
+		<h2>Constructor</h2>
+
+		<h3>[name]([page:Float radius], [page:Integer detail])</h3>
+		<div>
+		radius — Radius of the dodecahedron. Default is 1.<br />
+		detail — Default is 0. Setting this to a value greater than 0 adds vertices making it no longer a dodecahedron.
+		</div>
+
+		<h2>Properties</h2>
+
+		<h3>[property:Object parameters]</h3>
+		<div>
+		An object with all of the parameters that were used to generate the geometry.
+		</div>
+
+		<h2>Source</h2>
+
+		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+	</body>
+</html>

+ 1 - 1
docs/api/geometries/DodecahedronGeometry.html

@@ -8,7 +8,7 @@
 		<link type="text/css" rel="stylesheet" href="page.css" />
 	</head>
 	<body>
-		[page:PolyhedronGeometry] &rarr;
+		[page:Geometry] &rarr;
 
 		<h1>[name]</h1>
 

+ 53 - 0
docs/api/geometries/IcosahedronBufferGeometry.html

@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<base href="../../" />
+		<script src="list.js"></script>
+		<script src="page.js"></script>
+		<link type="text/css" rel="stylesheet" href="page.css" />
+	</head>
+	<body>
+		[page:PolyhedronBufferGeometry] &rarr;
+		<h1>[name]</h1>
+
+		<div class="desc">A class for generating an icosahedron geometry.</div>
+
+		<iframe id="scene" src="scenes/geometry-browser.html#IcosahedronBufferGeometry"></iframe>
+
+		<script>
+
+		// iOS iframe auto-resize workaround
+
+		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
+
+			var scene = document.getElementById( 'scene' );
+
+			scene.style.width = getComputedStyle( scene ).width;
+			scene.style.height = getComputedStyle( scene ).height;
+			scene.setAttribute( 'scrolling', 'no' );
+
+		}
+
+		</script>
+
+		<h2>Constructor</h2>
+
+		<h3>[name]([page:Float radius], [page:Integer detail])</h3>
+		<div>
+		radius — Default is 1. <br />
+		detail — Default is 0.  Setting this to a value greater than 0 adds more vertices making it no longer an icosahedron.  When detail is greater than 1, it's effectively a sphere.
+		</div>
+
+		<h2>Properties</h2>
+
+		<h3>[property:Object parameters]</h3>
+		<div>
+		An object with all of the parameters that were used to generate the geometry.
+		</div>
+
+		<h2>Source</h2>
+
+		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+	</body>
+</html>

+ 2 - 1
docs/api/geometries/IcosahedronGeometry.html

@@ -8,7 +8,8 @@
 		<link type="text/css" rel="stylesheet" href="page.css" />
 	</head>
 	<body>
-		[page:PolyhedronGeometry] &rarr;
+		[page:Geometry] &rarr;
+		
 		<h1>[name]</h1>
 
 		<div class="desc">A class for generating an icosahedron geometry.</div>

+ 53 - 0
docs/api/geometries/OctahedronBufferGeometry.html

@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<base href="../../" />
+		<script src="list.js"></script>
+		<script src="page.js"></script>
+		<link type="text/css" rel="stylesheet" href="page.css" />
+	</head>
+	<body>
+		[page:PolyhedronBufferGeometry] &rarr;
+		<h1>[name]</h1>
+
+		<div class="desc">A class for generating an octahedron geometry.</div>
+
+		<iframe id="scene" src="scenes/geometry-browser.html#OctahedronBufferGeometry"></iframe>
+
+		<script>
+
+		// iOS iframe auto-resize workaround
+
+		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
+
+			var scene = document.getElementById( 'scene' );
+
+			scene.style.width = getComputedStyle( scene ).width;
+			scene.style.height = getComputedStyle( scene ).height;
+			scene.setAttribute( 'scrolling', 'no' );
+
+		}
+
+		</script>
+
+		<h2>Constructor</h2>
+
+		<h3>[name]([page:Float radius], [page:Integer detail])</h3>
+		<div>
+		radius — Radius of the octahedron. Default is 1.<br />
+		detail — Default is 0.  Setting this to a value greater than zero add vertices making it no longer an octahedron.
+		</div>
+
+		<h2>Properties</h2>
+
+		<h3>[property:Object parameters]</h3>
+		<div>
+		An object with all of the parameters that were used to generate the geometry.
+		</div>
+
+		<h2>Source</h2>
+
+		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+	</body>
+</html>

+ 2 - 1
docs/api/geometries/OctahedronGeometry.html

@@ -8,7 +8,8 @@
 		<link type="text/css" rel="stylesheet" href="page.css" />
 	</head>
 	<body>
-		[page:PolyhedronGeometry] &rarr;
+		[page:Geometry] &rarr;
+		
 		<h1>[name]</h1>
 
 		<div class="desc">A class for generating an octahedron geometry.</div>

+ 64 - 0
docs/api/geometries/PolyhedronBufferGeometry.html

@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<base href="../../" />
+		<script src="list.js"></script>
+		<script src="page.js"></script>
+		<link type="text/css" rel="stylesheet" href="page.css" />
+	</head>
+	<body>
+		[page:BufferGeometry] &rarr;
+
+		<h1>[name]</h1>
+
+		<div class="desc">
+			A polyhedron is a solid in three dimensions with flat faces. This class will take an array of vertices,
+			project them onto a sphere, and then divide them up to the desired level of detail. This class is used
+			by [page:DodecahedronBufferGeometry], [page:IcosahedronBufferGeometry], [page:OctahedronBufferGeometry],
+			and [page:TetrahedronBufferGeometry] to generate their respective geometries.
+		</div>
+
+		<h2>Example</h2>
+<code>
+var verticesOfCube = [
+    -1,-1,-1,    1,-1,-1,    1, 1,-1,    -1, 1,-1,
+    -1,-1, 1,    1,-1, 1,    1, 1, 1,    -1, 1, 1,
+];
+
+var indicesOfFaces = [
+    2,1,0,    0,3,2,
+    0,4,7,    7,3,0,
+    0,1,5,    5,4,0,
+    1,2,6,    6,5,1,
+    2,3,7,    7,6,2,
+    4,5,6,    6,7,4
+];
+
+var geometry = new THREE.PolyhedronBufferGeometry( verticesOfCube, indicesOfFaces, 6, 2 );
+</code>
+
+		<h2>Constructor</h2>
+
+
+		<h3>[name]([page:Array vertices], [page:Array faces], [page:Float radius], [page:Integer detail])</h3>
+		<div>
+		vertices — [page:Array] of points of the form [1,1,1, -1,-1,-1, ... ] <br />
+		faces — [page:Array] of indices that make up the faces of the form [0,1,2, 2,3,0, ... ] <br />
+		radius — [page:Float] - The radius of the final shape <br />
+		detail — [page:Integer] - How many levels to subdivide the geometry. The more detail, the smoother the shape.
+		</div>
+
+		<h2>Properties</h2>
+
+		<h3>[property:Object parameters]</h3>
+		<div>
+		An object with all of the parameters that were used to generate the geometry.
+		</div>
+
+
+		<h2>Source</h2>
+
+		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+	</body>
+</html>

+ 1 - 3
docs/api/geometries/PolyhedronGeometry.html

@@ -14,9 +14,7 @@
 
 		<div class="desc">
 			A polyhedron is a solid in three dimensions with flat faces. This class will take an array of vertices,
-			project them onto a sphere, and then divide them up to the desired level of detail. This class is used
-			by [page:DodecahedronGeometry], [page:IcosahedronGeometry], [page:OctahedronGeometry],
-			and [page:TetrahedronGeometry] to generate their respective geometries.
+			project them onto a sphere, and then divide them up to the desired level of detail.
 		</div>
 
 		<h2>Example</h2>

+ 54 - 0
docs/api/geometries/TetrahedronBufferGeometry.html

@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<base href="../../" />
+		<script src="list.js"></script>
+		<script src="page.js"></script>
+		<link type="text/css" rel="stylesheet" href="page.css" />
+	</head>
+	<body>
+		[page:PolyhedronBufferGeometry] &rarr;
+
+		<h1>[name]</h1>
+
+		<div class="desc">A class for generating a tetrahedron geometries.</div>
+
+		<iframe id="scene" src="scenes/geometry-browser.html#TetrahedronBufferGeometry"></iframe>
+
+		<script>
+
+		// iOS iframe auto-resize workaround
+
+		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
+
+			var scene = document.getElementById( 'scene' );
+
+			scene.style.width = getComputedStyle( scene ).width;
+			scene.style.height = getComputedStyle( scene ).height;
+			scene.setAttribute( 'scrolling', 'no' );
+
+		}
+
+		</script>
+
+		<h2>Constructor</h2>
+
+		<h3>[name]([page:Float radius], [page:Integer detail])</h3>
+		<div>
+		radius — Radius of the tetrahedron. Default is 1.<br />
+		detail — Default is 0. Setting this to a value greater than 0 adds vertices making it no longer a tetrahedron.
+		</div>
+
+		<h2>Properties</h2>
+
+		<h3>[property:Object parameters]</h3>
+		<div>
+		An object with all of the parameters that were used to generate the geometry.
+		</div>
+
+		<h2>Source</h2>
+
+		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+	</body>
+</html>

+ 1 - 1
docs/api/geometries/TetrahedronGeometry.html

@@ -8,7 +8,7 @@
 		<link type="text/css" rel="stylesheet" href="page.css" />
 	</head>
 	<body>
-		[page:PolyhedronGeometry] &rarr;
+		[page:Geometry] &rarr;
 
 		<h1>[name]</h1>
 

+ 5 - 0
docs/list.js

@@ -44,21 +44,26 @@ var list = {
 			[ "ConeGeometry", "api/geometries/ConeGeometry" ],
 			[ "CylinderBufferGeometry", "api/geometries/CylinderBufferGeometry" ],
 			[ "CylinderGeometry", "api/geometries/CylinderGeometry" ],
+			[ "DodecahedronBufferGeometry", "api/geometries/DodecahedronBufferGeometry" ],
 			[ "DodecahedronGeometry", "api/geometries/DodecahedronGeometry" ],
 			[ "ExtrudeGeometry", "api/geometries/ExtrudeGeometry" ],
+			[ "IcosahedronBufferGeometry", "api/geometries/IcosahedronBufferGeometry" ],
 			[ "IcosahedronGeometry", "api/geometries/IcosahedronGeometry" ],
 			[ "LatheBufferGeometry", "api/geometries/LatheBufferGeometry" ],
 			[ "LatheGeometry", "api/geometries/LatheGeometry" ],
+			[ "OctahedronBufferGeometry", "api/geometries/OctahedronBufferGeometry" ],
 			[ "OctahedronGeometry", "api/geometries/OctahedronGeometry" ],
 			[ "ParametricGeometry", "api/geometries/ParametricGeometry" ],
 			[ "PlaneBufferGeometry", "api/geometries/PlaneBufferGeometry" ],
 			[ "PlaneGeometry", "api/geometries/PlaneGeometry" ],
+			[ "PolyhedronBufferGeometry", "api/geometries/PolyhedronBufferGeometry" ],
 			[ "PolyhedronGeometry", "api/geometries/PolyhedronGeometry" ],
 			[ "RingBufferGeometry", "api/geometries/RingBufferGeometry" ],
 			[ "RingGeometry", "api/geometries/RingGeometry" ],
 			[ "ShapeGeometry", "api/geometries/ShapeGeometry" ],
 			[ "SphereBufferGeometry", "api/geometries/SphereBufferGeometry" ],
 			[ "SphereGeometry", "api/geometries/SphereGeometry" ],
+			[ "TetrahedronBufferGeometry", "api/geometries/TetrahedronBufferGeometry" ],
 			[ "TetrahedronGeometry", "api/geometries/TetrahedronGeometry" ],
 			[ "TextGeometry", "api/geometries/TextGeometry" ],
 			[ "TorusBufferGeometry", "api/geometries/TorusBufferGeometry" ],

+ 104 - 0
docs/scenes/js/geometry.js

@@ -426,6 +426,32 @@ var guis = {
 
 	},
 
+	DodecahedronBufferGeometry : function() {
+
+		var data = {
+			radius : 10,
+			detail : 0,
+		};
+
+		function generateGeometry() {
+
+			updateGroupGeometry( mesh,
+				new THREE.DodecahedronBufferGeometry(
+					data.radius, data.detail
+				)
+			);
+
+		}
+
+		var folder = gui.addFolder( 'THREE.DodecahedronBufferGeometry' );
+
+		folder.add( data, 'radius', 1, 20 ).onChange( generateGeometry );
+		folder.add( data, 'detail', 0, 5 ).step( 1 ).onChange( generateGeometry );
+
+		generateGeometry();
+
+	},
+
 	IcosahedronGeometry : function() {
 
 		var data = {
@@ -452,6 +478,32 @@ var guis = {
 
 	},
 
+	IcosahedronBufferGeometry : function() {
+
+		var data = {
+			radius : 10,
+			detail : 0,
+		};
+
+		function generateGeometry() {
+
+			updateGroupGeometry( mesh,
+				new THREE.IcosahedronBufferGeometry(
+					data.radius, data.detail
+				)
+			);
+
+		}
+
+		var folder = gui.addFolder( 'THREE.IcosahedronBufferGeometry' );
+
+		folder.add( data, 'radius', 1, 20 ).onChange( generateGeometry );
+		folder.add( data, 'detail', 0, 5 ).step( 1 ).onChange( generateGeometry );
+
+		generateGeometry();
+
+	},
+
 	LatheBufferGeometry : function() {
 
 		var points = [];
@@ -550,6 +602,32 @@ var guis = {
 
 	},
 
+	OctahedronBufferGeometry : function() {
+
+		var data = {
+			radius : 10,
+			detail : 0,
+		};
+
+		function generateGeometry() {
+
+			updateGroupGeometry( mesh,
+				new THREE.OctahedronBufferGeometry(
+					data.radius, data.detail
+				)
+			);
+
+		}
+
+		var folder = gui.addFolder( 'THREE.OctahedronBufferGeometry' );
+
+		folder.add( data, 'radius', 1, 20 ).onChange( generateGeometry );
+		folder.add( data, 'detail', 0, 5 ).step( 1 ).onChange( generateGeometry );
+
+		generateGeometry();
+
+	},
+
 	PlaneBufferGeometry : function( mesh ) {
 
 		var data = {
@@ -776,6 +854,32 @@ var guis = {
 
 	},
 
+	TetrahedronBufferGeometry : function() {
+
+		var data = {
+			radius : 10,
+			detail : 0,
+		};
+
+		function generateGeometry() {
+
+			updateGroupGeometry( mesh,
+				new THREE.TetrahedronBufferGeometry(
+					data.radius, data.detail
+				)
+			);
+
+		}
+
+		var folder = gui.addFolder( 'THREE.TetrahedronBufferGeometry' );
+
+		folder.add( data, 'radius', 1, 20 ).onChange( generateGeometry );
+		folder.add( data, 'detail', 0, 5 ).step( 1 ).onChange( generateGeometry );
+
+		generateGeometry();
+
+	},
+
 	TextGeometry : function( mesh ) {
 
 		var data = {

+ 63 - 0
src/geometries/DodecahedronBufferGeometry.js

@@ -0,0 +1,63 @@
+import { PolyhedronBufferGeometry } from './PolyhedronBufferGeometry';
+
+/**
+ * @author Mugen87 / https://github.com/Mugen87
+ */
+
+function DodecahedronBufferGeometry( radius, detail ) {
+
+	var t = ( 1 + Math.sqrt( 5 ) ) / 2;
+	var r = 1 / t;
+
+	var vertices = [
+
+		// (±1, ±1, ±1)
+		- 1, - 1, - 1,    - 1, - 1,  1,
+		- 1,  1, - 1,    - 1,  1,  1,
+		 1, - 1, - 1,     1, - 1,  1,
+		 1,  1, - 1,     1,  1,  1,
+
+		// (0, ±1/φ, ±φ)
+		 0, - r, - t,     0, - r,  t,
+		 0,  r, - t,     0,  r,  t,
+
+		// (±1/φ, ±φ, 0)
+		- r, - t,  0,    - r,  t,  0,
+		 r, - t,  0,     r,  t,  0,
+
+		// (±φ, 0, ±1/φ)
+		- t,  0, - r,     t,  0, - r,
+		- t,  0,  r,     t,  0,  r
+	];
+
+	var indices = [
+		 3, 11,  7,      3,  7, 15,      3, 15, 13,
+		 7, 19, 17,      7, 17,  6,      7,  6, 15,
+		17,  4,  8,     17,  8, 10,     17, 10,  6,
+		 8,  0, 16,      8, 16,  2,      8,  2, 10,
+		 0, 12,  1,      0,  1, 18,      0, 18, 16,
+		 6, 10,  2,      6,  2, 13,      6, 13, 15,
+		 2, 16, 18,      2, 18,  3,      2,  3, 13,
+		18,  1,  9,     18,  9, 11,     18, 11,  3,
+		 4, 14, 12,      4, 12,  0,      4,  0,  8,
+		11,  9,  5,     11,  5, 19,     11, 19,  7,
+		19,  5, 14,     19, 14,  4,     19,  4, 17,
+		 1, 12, 14,      1, 14,  5,      1,  5,  9
+	];
+
+	PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
+
+	this.type = 'DodecahedronBufferGeometry';
+
+	this.parameters = {
+		radius: radius,
+		detail: detail
+	};
+
+}
+
+DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
+DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry;
+
+
+export { DodecahedronBufferGeometry };

+ 7 - 42
src/geometries/DodecahedronGeometry.js

@@ -1,4 +1,5 @@
-import { PolyhedronGeometry } from './PolyhedronGeometry';
+import { Geometry } from '../core/Geometry';
+import { DodecahedronBufferGeometry } from './DodecahedronBufferGeometry';
 
 /**
  * @author Abe Pazos / https://hamoid.com
@@ -6,46 +7,7 @@ import { PolyhedronGeometry } from './PolyhedronGeometry';
 
 function DodecahedronGeometry( radius, detail ) {
 
-	var t = ( 1 + Math.sqrt( 5 ) ) / 2;
-	var r = 1 / t;
-
-	var vertices = [
-
-		// (±1, ±1, ±1)
-		- 1, - 1, - 1,    - 1, - 1,  1,
-		- 1,  1, - 1,    - 1,  1,  1,
-		 1, - 1, - 1,     1, - 1,  1,
-		 1,  1, - 1,     1,  1,  1,
-
-		// (0, ±1/φ, ±φ)
-		 0, - r, - t,     0, - r,  t,
-		 0,  r, - t,     0,  r,  t,
-
-		// (±1/φ, ±φ, 0)
-		- r, - t,  0,    - r,  t,  0,
-		 r, - t,  0,     r,  t,  0,
-
-		// (±φ, 0, ±1/φ)
-		- t,  0, - r,     t,  0, - r,
-		- t,  0,  r,     t,  0,  r
-	];
-
-	var indices = [
-		 3, 11,  7,      3,  7, 15,      3, 15, 13,
-		 7, 19, 17,      7, 17,  6,      7,  6, 15,
-		17,  4,  8,     17,  8, 10,     17, 10,  6,
-		 8,  0, 16,      8, 16,  2,      8,  2, 10,
-		 0, 12,  1,      0,  1, 18,      0, 18, 16,
-		 6, 10,  2,      6,  2, 13,      6, 13, 15,
-		 2, 16, 18,      2, 18,  3,      2,  3, 13,
-		18,  1,  9,     18,  9, 11,     18, 11,  3,
-		 4, 14, 12,      4, 12,  0,      4,  0,  8,
-		11,  9,  5,     11,  5, 19,     11, 19,  7,
-		19,  5, 14,     19, 14,  4,     19,  4, 17,
-		 1, 12, 14,      1, 14,  5,      1,  5,  9
-	];
-
-	PolyhedronGeometry.call( this, vertices, indices, radius, detail );
+	Geometry.call( this );
 
 	this.type = 'DodecahedronGeometry';
 
@@ -54,9 +16,12 @@ function DodecahedronGeometry( radius, detail ) {
 		detail: detail
 	};
 
+	this.fromBufferGeometry( new THREE.DodecahedronBufferGeometry( radius, detail ) );
+	this.mergeVertices();
+
 }
 
-DodecahedronGeometry.prototype = Object.create( PolyhedronGeometry.prototype );
+DodecahedronGeometry.prototype = Object.create( Geometry.prototype );
 DodecahedronGeometry.prototype.constructor = DodecahedronGeometry;
 
 

+ 5 - 1
src/geometries/Geometries.js

@@ -1,11 +1,15 @@
 export { WireframeGeometry } from './WireframeGeometry.js';
 export { ParametricGeometry } from './ParametricGeometry.js';
-export { ParametricBufferGeometry } from './ParametricBufferGeometry.js';
 export { TetrahedronGeometry } from './TetrahedronGeometry.js';
+export { TetrahedronBufferGeometry } from './TetrahedronBufferGeometry.js';
 export { OctahedronGeometry } from './OctahedronGeometry.js';
+export { OctahedronBufferGeometry } from './OctahedronBufferGeometry.js';
 export { IcosahedronGeometry } from './IcosahedronGeometry.js';
+export { IcosahedronBufferGeometry } from './IcosahedronBufferGeometry.js';
 export { DodecahedronGeometry } from './DodecahedronGeometry.js';
+export { DodecahedronBufferGeometry } from './DodecahedronBufferGeometry.js';
 export { PolyhedronGeometry } from './PolyhedronGeometry.js';
+export { PolyhedronBufferGeometry } from './PolyhedronBufferGeometry.js';
 export { TubeGeometry } from './TubeGeometry.js';
 export { TorusKnotGeometry } from './TorusKnotGeometry.js';
 export { TorusKnotBufferGeometry } from './TorusKnotBufferGeometry.js';

+ 39 - 0
src/geometries/IcosahedronBufferGeometry.js

@@ -0,0 +1,39 @@
+import { PolyhedronBufferGeometry } from './PolyhedronBufferGeometry';
+
+/**
+ * @author Mugen87 / https://github.com/Mugen87
+ */
+
+function IcosahedronBufferGeometry( radius, detail ) {
+
+	var t = ( 1 + Math.sqrt( 5 ) ) / 2;
+
+	var vertices = [
+		- 1,  t,  0,    1,  t,  0,   - 1, - t,  0,    1, - t,  0,
+		 0, - 1,  t,    0,  1,  t,    0, - 1, - t,    0,  1, - t,
+		 t,  0, - 1,    t,  0,  1,   - t,  0, - 1,   - t,  0,  1
+	];
+
+	var indices = [
+		 0, 11,  5,    0,  5,  1,    0,  1,  7,    0,  7, 10,    0, 10, 11,
+		 1,  5,  9,    5, 11,  4,   11, 10,  2,   10,  7,  6,    7,  1,  8,
+		 3,  9,  4,    3,  4,  2,    3,  2,  6,    3,  6,  8,    3,  8,  9,
+		 4,  9,  5,    2,  4, 11,    6,  2, 10,    8,  6,  7,    9,  8,  1
+	];
+
+	PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
+
+	this.type = 'IcosahedronBufferGeometry';
+
+	this.parameters = {
+		radius: radius,
+		detail: detail
+	};
+
+}
+
+IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
+IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry;
+
+
+export { IcosahedronBufferGeometry };

+ 7 - 18
src/geometries/IcosahedronGeometry.js

@@ -1,4 +1,5 @@
-import { PolyhedronGeometry } from './PolyhedronGeometry';
+import { Geometry } from '../core/Geometry';
+import { IcosahedronBufferGeometry } from './IcosahedronBufferGeometry';
 
 /**
  * @author timothypratley / https://github.com/timothypratley
@@ -6,22 +7,7 @@ import { PolyhedronGeometry } from './PolyhedronGeometry';
 
 function IcosahedronGeometry( radius, detail ) {
 
-	var t = ( 1 + Math.sqrt( 5 ) ) / 2;
-
-	var vertices = [
-		- 1,  t,  0,    1,  t,  0,   - 1, - t,  0,    1, - t,  0,
-		 0, - 1,  t,    0,  1,  t,    0, - 1, - t,    0,  1, - t,
-		 t,  0, - 1,    t,  0,  1,   - t,  0, - 1,   - t,  0,  1
-	];
-
-	var indices = [
-		 0, 11,  5,    0,  5,  1,    0,  1,  7,    0,  7, 10,    0, 10, 11,
-		 1,  5,  9,    5, 11,  4,   11, 10,  2,   10,  7,  6,    7,  1,  8,
-		 3,  9,  4,    3,  4,  2,    3,  2,  6,    3,  6,  8,    3,  8,  9,
-		 4,  9,  5,    2,  4, 11,    6,  2, 10,    8,  6,  7,    9,  8,  1
-	];
-
-	PolyhedronGeometry.call( this, vertices, indices, radius, detail );
+ 	Geometry.call( this );
 
 	this.type = 'IcosahedronGeometry';
 
@@ -30,9 +16,12 @@ function IcosahedronGeometry( radius, detail ) {
 		detail: detail
 	};
 
+	this.fromBufferGeometry( new THREE.IcosahedronBufferGeometry( radius, detail ) );
+	this.mergeVertices();
+
 }
 
-IcosahedronGeometry.prototype = Object.create( PolyhedronGeometry.prototype );
+IcosahedronGeometry.prototype = Object.create( Geometry.prototype );
 IcosahedronGeometry.prototype.constructor = IcosahedronGeometry;
 
 

+ 32 - 0
src/geometries/OctahedronBufferGeometry.js

@@ -0,0 +1,32 @@
+import { PolyhedronBufferGeometry } from './PolyhedronBufferGeometry';
+
+/**
+ * @author Mugen87 / https://github.com/Mugen87
+ */
+
+function OctahedronBufferGeometry( radius,detail ) {
+
+	var vertices = [
+		1, 0, 0,   - 1, 0, 0,    0, 1, 0,    0, - 1, 0,    0, 0, 1,    0, 0, - 1
+	];
+
+	var indices = [
+		0, 2, 4,    0, 4, 3,    0, 3, 5,    0, 5, 2,    1, 2, 5,    1, 5, 3,    1, 3, 4,    1, 4, 2
+	];
+
+	PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
+
+	this.type = 'OctahedronBufferGeometry';
+
+	this.parameters = {
+		radius: radius,
+		detail: detail
+	};
+
+}
+
+OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
+OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
+
+
+export { OctahedronBufferGeometry };

+ 7 - 11
src/geometries/OctahedronGeometry.js

@@ -1,4 +1,5 @@
-import { PolyhedronGeometry } from './PolyhedronGeometry';
+import { Geometry } from '../core/Geometry';
+import { OctahedronBufferGeometry } from './OctahedronBufferGeometry';
 
 /**
  * @author timothypratley / https://github.com/timothypratley
@@ -6,15 +7,7 @@ import { PolyhedronGeometry } from './PolyhedronGeometry';
 
 function OctahedronGeometry( radius, detail ) {
 
-	var vertices = [
-		1, 0, 0,   - 1, 0, 0,    0, 1, 0,    0, - 1, 0,    0, 0, 1,    0, 0, - 1
-	];
-
-	var indices = [
-		0, 2, 4,    0, 4, 3,    0, 3, 5,    0, 5, 2,    1, 2, 5,    1, 5, 3,    1, 3, 4,    1, 4, 2
-	];
-
-	PolyhedronGeometry.call( this, vertices, indices, radius, detail );
+	Geometry.call( this );
 
 	this.type = 'OctahedronGeometry';
 
@@ -23,9 +16,12 @@ function OctahedronGeometry( radius, detail ) {
 		detail: detail
 	};
 
+	this.fromBufferGeometry( new THREE.OctahedronBufferGeometry( radius, detail ) );
+	this.mergeVertices();
+
 }
 
-OctahedronGeometry.prototype = Object.create( PolyhedronGeometry.prototype );
+OctahedronGeometry.prototype = Object.create( Geometry.prototype );
 OctahedronGeometry.prototype.constructor = OctahedronGeometry;
 
 

+ 306 - 0
src/geometries/PolyhedronBufferGeometry.js

@@ -0,0 +1,306 @@
+import { BufferGeometry } from '../core/BufferGeometry';
+import { Uint16Attribute, Uint32Attribute, Float32Attribute } from '../core/BufferAttribute';
+import { Vector3 } from '../math/Vector3';
+import { Vector2 } from '../math/Vector2';
+import { Sphere } from '../math/Sphere';
+
+/**
+ * @author Mugen87 / https://github.com/Mugen87
+ */
+
+function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
+
+	BufferGeometry.call( this );
+
+	this.type = 'PolyhedronBufferGeometry';
+
+	this.parameters = {
+		vertices: vertices,
+		indices: indices,
+		radius: radius,
+		detail: detail
+	};
+
+	radius = radius || 1;
+	detail = detail || 0;
+
+	// default buffer data
+
+	var vertexBuffer = [];
+	var uvBuffer = [];
+
+	// the subdivision creates the vertex buffer data
+
+	subdivide( detail );
+
+	// all vertices should lie on a conceptual sphere with a given radius
+
+	appplyRadius( radius );
+
+	// finally, create the uv data
+
+	generateUVs();
+
+	// build non-indexed geometry
+
+	this.addAttribute( 'position', Float32Attribute( vertexBuffer, 3 ) );
+	this.addAttribute( 'normal', Float32Attribute( vertexBuffer.slice(), 3 ) );
+	this.addAttribute( 'uv', Float32Attribute( uvBuffer, 2 ) );
+	this.normalizeNormals();
+
+	this.boundingSphere = new Sphere( new Vector3(), radius );
+
+	// helper functions
+
+	function subdivide( detail ) {
+
+		var a = new Vector3();
+		var b = new Vector3();
+		var c = new Vector3();
+
+		// iterate over all faces and apply a subdivison with the given detail value
+
+		for ( var i = 0; i < indices.length; i += 3 ) {
+
+			// get the vertices of the face
+
+			getVertexByIndex( indices[ i + 0 ], a );
+			getVertexByIndex( indices[ i + 1 ], b );
+			getVertexByIndex( indices[ i + 2 ], c );
+
+			// perform subdivision
+
+			subdivideFace( a, b, c, detail );
+
+		}
+
+	}
+
+	function subdivideFace( a, b, c, detail ) {
+
+		var cols = Math.pow( 2, detail );
+
+		// we use this multidimensional array as a data structure for creating the subdivision
+
+		var v = [];
+
+		var i, j;
+
+		// construct all of the vertices for this subdivision
+
+		for ( i = 0 ; i <= cols; i ++ ) {
+
+			v[ i ] = [];
+
+			var aj = a.clone().lerp( c, i / cols );
+			var bj = b.clone().lerp( c, i / cols );
+
+			var rows = cols - i;
+
+			for ( j = 0; j <= rows; j ++ ) {
+
+				if ( j === 0 && i === cols ) {
+
+					v[ i ][ j ] = aj;
+
+				} else {
+
+					v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
+
+				}
+
+			}
+
+		}
+
+		// construct all of the faces
+
+		for ( i = 0; i < cols ; i ++ ) {
+
+			for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
+
+				var k = Math.floor( j / 2 );
+
+				if ( j % 2 === 0 ) {
+
+					pushVertex( v[ i ][ k + 1 ] );
+					pushVertex( v[ i + 1 ][ k ] );
+					pushVertex( v[ i ][ k ] );
+
+				} else {
+
+					pushVertex( v[ i ][ k + 1 ] );
+					pushVertex( v[ i + 1 ][ k + 1 ] );
+					pushVertex( v[ i + 1 ][ k ] );
+
+				}
+
+			}
+
+		}
+
+	}
+
+	function appplyRadius( radius ) {
+
+		var vertex = new Vector3();
+
+		// iterate over the entire buffer and apply the radius to each vertex
+
+		for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
+
+			vertex.x = vertexBuffer[ i + 0 ];
+			vertex.y = vertexBuffer[ i + 1 ];
+			vertex.z = vertexBuffer[ i + 2 ];
+
+			vertex.normalize().multiplyScalar( radius );
+
+			vertexBuffer[ i + 0 ] = vertex.x;
+			vertexBuffer[ i + 1 ] = vertex.y;
+			vertexBuffer[ i + 2 ] = vertex.z;
+
+		}
+
+	}
+
+	function generateUVs() {
+
+		var vertex = new Vector3();
+
+		for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
+
+			vertex.x = vertexBuffer[ i + 0 ];
+			vertex.y = vertexBuffer[ i + 1 ];
+			vertex.z = vertexBuffer[ i + 2 ];
+
+			var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
+			var v = inclination( vertex ) / Math.PI + 0.5;
+			uvBuffer.push( u, 1 - v );
+
+		}
+
+		correctUVs();
+
+		correctSeam();
+
+	}
+
+	function correctSeam() {
+
+		// handle case when face straddles the seam, see #3269
+
+		for ( var i = 0; i < uvBuffer.length; i += 6 ) {
+
+			// uv data of a single face
+
+			var x0 = uvBuffer[ i + 0 ];
+			var x1 = uvBuffer[ i + 2 ];
+			var x2 = uvBuffer[ i + 4 ];
+
+			var max = Math.max( x0, x1, x2 );
+			var min = Math.min( x0, x1, x2 );
+
+			// 0.9 is somewhat arbitrary
+
+			if ( max > 0.9 && min < 0.1 ) {
+
+				if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
+				if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
+				if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
+
+			}
+
+		}
+
+	}
+
+	function pushVertex( vertex ) {
+
+		vertexBuffer.push( vertex.x, vertex.y, vertex.z );
+
+	}
+
+	function getVertexByIndex( index, vertex ) {
+
+		var stride = index * 3;
+
+		vertex.x = vertices[ stride + 0 ];
+		vertex.y = vertices[ stride + 1 ];
+		vertex.z = vertices[ stride + 2 ];
+
+	}
+
+	function correctUVs() {
+
+		var a = new Vector3();
+		var b = new Vector3();
+		var c = new Vector3();
+
+		var centroid = new Vector3();
+
+		var uvA = new Vector2();
+		var uvB = new Vector2();
+		var uvC = new Vector2();
+
+		for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
+
+			a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
+			b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
+			c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
+
+			uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
+			uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
+			uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
+
+			centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
+
+			var azi = azimuth( centroid );
+
+			correctUV( uvA, j + 0, a, azi );
+			correctUV( uvB, j + 2, b, azi );
+			correctUV( uvC, j + 4, c, azi );
+
+		}
+
+	}
+
+	function correctUV( uv, stride, vector, azimuth  ) {
+
+		if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
+
+			uvBuffer[ stride ] =  uv.x - 1;
+
+		}
+
+		if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
+
+			uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
+
+		}
+
+	}
+
+	// Angle around the Y axis, counter-clockwise when looking from above.
+
+	function azimuth( vector ) {
+
+		return Math.atan2( vector.z, - vector.x );
+
+	}
+
+
+	// Angle above the XZ plane.
+
+	function inclination( vector ) {
+
+		return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
+
+	}
+
+}
+
+PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
+PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
+
+
+export { PolyhedronBufferGeometry };

+ 2 - 215
src/geometries/PolyhedronGeometry.js

@@ -1,8 +1,5 @@
 import { Geometry } from '../core/Geometry';
-import { Vector2 } from '../math/Vector2';
-import { Face3 } from '../core/Face3';
-import { Vector3 } from '../math/Vector3';
-import { Sphere } from '../math/Sphere';
+import { PolyhedronBufferGeometry } from './PolyhedronBufferGeometry';
 
 /**
  * @author clockworkgeek / https://github.com/clockworkgeek
@@ -23,219 +20,9 @@ function PolyhedronGeometry( vertices, indices, radius, detail ) {
 		detail: detail
 	};
 
-	radius = radius || 1;
-	detail = detail || 0;
-
-	var that = this;
-
-	for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
-
-		prepare( new Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
-
-	}
-
-	var p = this.vertices;
-
-	var faces = [];
-
-	for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
-
-		var v1 = p[ indices[ i ] ];
-		var v2 = p[ indices[ i + 1 ] ];
-		var v3 = p[ indices[ i + 2 ] ];
-
-		faces[ j ] = new Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
-
-	}
-
-	var centroid = new Vector3();
-
-	for ( var i = 0, l = faces.length; i < l; i ++ ) {
-
-		subdivide( faces[ i ], detail );
-
-	}
-
-
-	// Handle case when face straddles the seam
-
-	for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
-
-		var uvs = this.faceVertexUvs[ 0 ][ i ];
-
-		var x0 = uvs[ 0 ].x;
-		var x1 = uvs[ 1 ].x;
-		var x2 = uvs[ 2 ].x;
-
-		var max = Math.max( x0, x1, x2 );
-		var min = Math.min( x0, x1, x2 );
-
-		if ( max > 0.9 && min < 0.1 ) {
-
-			// 0.9 is somewhat arbitrary
-
-			if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
-			if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
-			if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
-
-		}
-
-	}
-
-
-	// Apply radius
-
-	for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
-
-		this.vertices[ i ].multiplyScalar( radius );
-
-	}
-
-
-	// Merge vertices
-
+	this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
 	this.mergeVertices();
 
-	this.computeFaceNormals();
-
-	this.boundingSphere = new Sphere( new Vector3(), radius );
-
-
-	// Project vector onto sphere's surface
-
-	function prepare( vector ) {
-
-		var vertex = vector.normalize().clone();
-		vertex.index = that.vertices.push( vertex ) - 1;
-
-		// Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
-
-		var u = azimuth( vector ) / 2 / Math.PI + 0.5;
-		var v = inclination( vector ) / Math.PI + 0.5;
-		vertex.uv = new Vector2( u, 1 - v );
-
-		return vertex;
-
-	}
-
-
-	// Approximate a curved face with recursively sub-divided triangles.
-
-	function make( v1, v2, v3 ) {
-
-		var face = new Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
-		that.faces.push( face );
-
-		centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
-
-		var azi = azimuth( centroid );
-
-		that.faceVertexUvs[ 0 ].push( [
-			correctUV( v1.uv, v1, azi ),
-			correctUV( v2.uv, v2, azi ),
-			correctUV( v3.uv, v3, azi )
-		] );
-
-	}
-
-
-	// Analytically subdivide a face to the required detail level.
-
-	function subdivide( face, detail ) {
-
-		var cols = Math.pow( 2, detail );
-		var a = prepare( that.vertices[ face.a ] );
-		var b = prepare( that.vertices[ face.b ] );
-		var c = prepare( that.vertices[ face.c ] );
-		var v = [];
-
-		// Construct all of the vertices for this subdivision.
-
-		for ( var i = 0 ; i <= cols; i ++ ) {
-
-			v[ i ] = [];
-
-			var aj = prepare( a.clone().lerp( c, i / cols ) );
-			var bj = prepare( b.clone().lerp( c, i / cols ) );
-			var rows = cols - i;
-
-			for ( var j = 0; j <= rows; j ++ ) {
-
-				if ( j === 0 && i === cols ) {
-
-					v[ i ][ j ] = aj;
-
-				} else {
-
-					v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
-
-				}
-
-			}
-
-		}
-
-		// Construct all of the faces.
-
-		for ( var i = 0; i < cols ; i ++ ) {
-
-			for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
-
-				var k = Math.floor( j / 2 );
-
-				if ( j % 2 === 0 ) {
-
-					make(
-						v[ i ][ k + 1 ],
-						v[ i + 1 ][ k ],
-						v[ i ][ k ]
-					);
-
-				} else {
-
-					make(
-						v[ i ][ k + 1 ],
-						v[ i + 1 ][ k + 1 ],
-						v[ i + 1 ][ k ]
-					);
-
-				}
-
-			}
-
-		}
-
-	}
-
-
-	// Angle around the Y axis, counter-clockwise when looking from above.
-
-	function azimuth( vector ) {
-
-		return Math.atan2( vector.z, - vector.x );
-
-	}
-
-
-	// Angle above the XZ plane.
-
-	function inclination( vector ) {
-
-		return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
-
-	}
-
-
-	// Texture fixing helper. Spheres have some odd behaviours.
-
-	function correctUV( uv, vector, azimuth ) {
-
-		if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new Vector2( uv.x - 1, uv.y );
-		if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
-		return uv.clone();
-
-	}
-
 }
 
 PolyhedronGeometry.prototype = Object.create( Geometry.prototype );

+ 32 - 0
src/geometries/TetrahedronBufferGeometry.js

@@ -0,0 +1,32 @@
+import { PolyhedronBufferGeometry } from './PolyhedronBufferGeometry';
+
+/**
+ * @author Mugen87 / https://github.com/Mugen87
+ */
+
+function TetrahedronBufferGeometry( radius, detail ) {
+
+	var vertices = [
+		1,  1,  1,   - 1, - 1,  1,   - 1,  1, - 1,    1, - 1, - 1
+	];
+
+	var indices = [
+		2,  1,  0,    0,  3,  2,    1,  3,  0,    2,  3,  1
+	];
+
+	PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
+
+	this.type = 'TetrahedronBufferGeometry';
+
+	this.parameters = {
+		radius: radius,
+		detail: detail
+	};
+
+}
+
+TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
+TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry;
+
+
+export { TetrahedronBufferGeometry };

+ 7 - 11
src/geometries/TetrahedronGeometry.js

@@ -1,4 +1,5 @@
-import { PolyhedronGeometry } from './PolyhedronGeometry';
+import { Geometry } from '../core/Geometry';
+import { TetrahedronBufferGeometry } from './TetrahedronBufferGeometry';
 
 /**
  * @author timothypratley / https://github.com/timothypratley
@@ -6,15 +7,7 @@ import { PolyhedronGeometry } from './PolyhedronGeometry';
 
 function TetrahedronGeometry( radius, detail ) {
 
-	var vertices = [
-		 1,  1,  1,   - 1, - 1,  1,   - 1,  1, - 1,    1, - 1, - 1
-	];
-
-	var indices = [
-		 2,  1,  0,    0,  3,  2,    1,  3,  0,    2,  3,  1
-	];
-
-	PolyhedronGeometry.call( this, vertices, indices, radius, detail );
+	Geometry.call( this );
 
 	this.type = 'TetrahedronGeometry';
 
@@ -23,9 +16,12 @@ function TetrahedronGeometry( radius, detail ) {
 		detail: detail
 	};
 
+	this.fromBufferGeometry( new THREE.TetrahedronBufferGeometry( radius, detail ) );
+	this.mergeVertices();
+
 }
 
-TetrahedronGeometry.prototype = Object.create( PolyhedronGeometry.prototype );
+TetrahedronGeometry.prototype = Object.create( Geometry.prototype );
 TetrahedronGeometry.prototype.constructor = TetrahedronGeometry;