Browse Source

Merge pull request #12406 from Mugen87/curve2

CurvePath: Remove factory methods
Mr.doob 7 years ago
parent
commit
e42806c75c

+ 3 - 0
docs/api/core/BufferGeometry.html

@@ -316,6 +316,9 @@
 		<h3>[method:BufferGeometry setFromObject] ( [page:Object3D object] )</h3>
 		<h3>[method:BufferGeometry setFromObject] ( [page:Object3D object] )</h3>
 		<div>Sets the attributes for this BufferGeometry from an [page:Object3D].</div>
 		<div>Sets the attributes for this BufferGeometry from an [page:Object3D].</div>
 
 
+		<h3>[method:BufferGeometry setFromPoints] ( [page:Array points] )</h3>
+		<div>Sets the attributes for this BufferGeometry from an array of points.</div>
+
 		<h3>[method:Object toJSON]()</h3>
 		<h3>[method:Object toJSON]()</h3>
 		<div>Returns a JSON object representation of the BufferGeometry.</div>
 		<div>Returns a JSON object representation of the BufferGeometry.</div>
 
 

+ 3 - 0
docs/api/core/Geometry.html

@@ -315,6 +315,9 @@
 	        Use [page:Object3D.rotation] for typical real-time mesh rotation.
 	        Use [page:Object3D.rotation] for typical real-time mesh rotation.
 		</div>
 		</div>
 
 
+		<h3>[method:Geometry setFromPoints] ( [page:Array points] )</h3>
+		<div>Sets the vertices for this Geometry from an array of points.</div>
+
 		<h3>[method:null sortFacesByMaterialIndex] (  )</h3>
 		<h3>[method:null sortFacesByMaterialIndex] (  )</h3>
 		<div>
 		<div>
 		Sorts the faces array according to material index. For complex geometries with several materials,
 		Sorts the faces array according to material index. For complex geometries with several materials,

+ 0 - 23
docs/api/extras/core/CurvePath.html

@@ -49,29 +49,6 @@
 		<h3>[method:null closePath]()</h3>
 		<h3>[method:null closePath]()</h3>
 		<div>Adds a [page:LineCurve lineCurve] to close the path.</div>
 		<div>Adds a [page:LineCurve lineCurve] to close the path.</div>
 
 
-		<h3>[method:Geometry createGeometry]( [page:Vector3 points] )</h3>
-		<div>
-		points -- An array of [page:Vector3 Vector3s]<br /><br />
-
-		Creates a geometry from points
-		</div>
-
-		<h3>[method:Geometry createPointsGeometry]( [page:Integer divisions] )</h3>
-		<div>
-		divisions -- How many segments to create. Defaults to *12*.<br /><br />
-
-		Creates a [page:Geometry] object comprised of [page:Vector3 Vector3s], for example
-		to be used with [page:Line] or [page:Points]. Uses [page:Curve.getPoints]() for the division.
-		</div>
-
-		<h3>[method:Geometry createSpacedPointsGeometry]( [page:Integer divisions] )</h3>
-		<div>
-		divisions -- How many segments to create. Defaults to *12*.<br /><br />
-
-		Creates a [page:Geometry] object comprised of [page:Vector3]s that are equidistant, for example
-		to be used with [page:Line] or [page:Points].	Uses [page:Curve.getSpacedPoints]() for the division.
-		</div>
-
 		<h3>[method:Float getCurveLengths]()</h3>
 		<h3>[method:Float getCurveLengths]()</h3>
 		<div>Adds together the lengths of the curves in the [page:.curves] array.</div>
 		<div>Adds together the lengths of the curves in the [page:.curves] array.</div>
 
 

+ 2 - 2
docs/api/extras/curves/CatmullRomCurve3.html

@@ -27,8 +27,8 @@ var curve = new THREE.CatmullRomCurve3( [
 	new THREE.Vector3( 10, 0, 10 )
 	new THREE.Vector3( 10, 0, 10 )
 ] );
 ] );
 
 
-var geometry = new THREE.Geometry();
-geometry.vertices = curve.getPoints( 50 );
+var points = curve.getPoints( 50 );
+var geometry = new THREE.BufferGeometry().setFromPoints( points );
 
 
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 
 

+ 2 - 2
docs/api/extras/curves/CubicBezierCurve.html

@@ -28,9 +28,9 @@ var curve = new THREE.CubicBezierCurve(
 	new THREE.Vector2( 10, 0 )
 	new THREE.Vector2( 10, 0 )
 );
 );
 
 
-var path = new THREE.Path( curve.getPoints( 50 ) );
+var points = curve.getPoints( 50 );
+var geometry = new THREE.BufferGeometry().setFromPoints( points );
 
 
-var geometry = path.createPointsGeometry( 50 );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 
 
 // Create the final object to add to the scene
 // Create the final object to add to the scene

+ 2 - 2
docs/api/extras/curves/CubicBezierCurve3.html

@@ -28,8 +28,8 @@ var curve = new THREE.CubicBezierCurve3(
 	new THREE.Vector3( 10, 0, 0 )
 	new THREE.Vector3( 10, 0, 0 )
 );
 );
 
 
-var geometry = new THREE.Geometry();
-geometry.vertices = curve.getPoints( 50 );
+var points = curve.getPoints( 50 );
+var geometry = new THREE.BufferGeometry().setFromPoints( points );
 
 
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 
 

+ 3 - 2
docs/api/extras/curves/EllipseCurve.html

@@ -28,8 +28,9 @@ var curve = new THREE.EllipseCurve(
 	0                 // aRotation
 	0                 // aRotation
 );
 );
 
 
-var path = new THREE.Path( curve.getPoints( 50 ) );
-var geometry = path.createPointsGeometry( 50 );
+var points = curve.getPoints( 50 );
+var geometry = new THREE.BufferGeometry().setFromPoints( points );
+
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 
 
 // Create the final object to add to the scene
 // Create the final object to add to the scene

+ 2 - 2
docs/api/extras/curves/QuadraticBezierCurve.html

@@ -27,9 +27,9 @@ var curve = new THREE.QuadraticBezierCurve(
 	new THREE.Vector2( 10, 0 )
 	new THREE.Vector2( 10, 0 )
 );
 );
 
 
-var path = new THREE.Path( curve.getPoints( 50 ) );
+var points = curve.getPoints( 50 );
+var geometry = new THREE.BufferGeometry().setFromPoints( points );
 
 
-var geometry = path.createPointsGeometry( 50 );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 
 
 //Create the final object to add to the scene
 //Create the final object to add to the scene

+ 2 - 2
docs/api/extras/curves/QuadraticBezierCurve3.html

@@ -27,8 +27,8 @@ var curve = new THREE.QuadraticBezierCurve3(
 	new THREE.Vector3( 10, 0, 0 )
 	new THREE.Vector3( 10, 0, 0 )
 );
 );
 
 
-var geometry = new THREE.Geometry();
-geometry.vertices = curve.getPoints( 50 );
+var points = curve.getPoints( 50 );
+var geometry = new THREE.BufferGeometry().setFromPoints( points );
 
 
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 
 

+ 2 - 2
docs/api/extras/curves/SplineCurve.html

@@ -29,9 +29,9 @@ var curve = new THREE.SplineCurve( [
 	new THREE.Vector2( 10, 0 )
 	new THREE.Vector2( 10, 0 )
 ] );
 ] );
 
 
-var path = new THREE.Path( curve.getPoints( 50 ) );
+var points = curve.getPoints( 50 );
+var geometry = new THREE.BufferGeometry().setFromPoints( points );
 
 
-var geometry = path.createPointsGeometry( 50 );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
 
 
 // Create the final object to add to the scene
 // Create the final object to add to the scene

+ 0 - 32
editor/js/libs/tern-threejs/threejs.js

@@ -924,34 +924,10 @@
           "!type": "boolean",
           "!type": "boolean",
           "!doc": "todo"
           "!doc": "todo"
         },
         },
-        "getWrapPoints": {
-          "!type": "fn(oldPts: todo, path: todo) -> todo",
-          "!doc": "todo"
-        },
-        "createPointsGeometry": {
-          "!type": "fn(divisions: todo) -> todo",
-          "!doc": "todo"
-        },
-        "addWrapPath": {
-          "!type": "fn(bendpath: todo) -> todo",
-          "!doc": "todo"
-        },
-        "createGeometry": {
-          "!type": "fn(points: todo) -> todo",
-          "!doc": "todo"
-        },
         "add": {
         "add": {
           "!type": "fn(curve: todo) -> todo",
           "!type": "fn(curve: todo) -> todo",
           "!doc": "todo"
           "!doc": "todo"
         },
         },
-        "getTransformedSpacedPoints": {
-          "!type": "fn(segments: todo, bends: todo) -> todo",
-          "!doc": "todo"
-        },
-        "createSpacedPointsGeometry": {
-          "!type": "fn(divisions: todo) -> todo",
-          "!doc": "todo"
-        },
         "closePath": {
         "closePath": {
           "!type": "fn() -> todo",
           "!type": "fn() -> todo",
           "!doc": "todo"
           "!doc": "todo"
@@ -963,14 +939,6 @@
         "getCurveLengths": {
         "getCurveLengths": {
           "!type": "fn() -> todo",
           "!type": "fn() -> todo",
           "!doc": "todo"
           "!doc": "todo"
-        },
-        "getTransformedPoints": {
-          "!type": "fn(segments: todo, bends: todo) -> todo",
-          "!doc": "todo"
-        },
-        "checkConnection": {
-          "!type": "fn() -> todo",
-          "!doc": "todo"
         }
         }
       },
       },
       "!doc": "todo",
       "!doc": "todo",

+ 2 - 2
examples/canvas_geometry_shapes.html

@@ -82,8 +82,8 @@
 
 
 					// line
 					// line
 
 
-					var geometry = shape.createPointsGeometry();
-					geometry.vertices.push( geometry.vertices[ 0 ].clone() );
+					var points = shape.getPoints();
+					var geometry = new THREE.Geometry().setFromPoints( points );
 
 
 					var material = new THREE.LineBasicMaterial( { linewidth: 10, color: 0x333333, transparent: true } );
 					var material = new THREE.LineBasicMaterial( { linewidth: 10, color: 0x333333, transparent: true } );
 
 

+ 10 - 6
examples/webgl_geometry_shapes.html

@@ -114,12 +114,16 @@
 					// lines
 					// lines
 
 
 					shape.autoClose = true;
 					shape.autoClose = true;
-					var points = shape.createPointsGeometry();
-					var spacedPoints = shape.createSpacedPointsGeometry( 50 );
+
+					var points = shape.getPoints();
+					var spacedPoints = shape.getSpacedPoints( 50 );
+
+					var geometryPoints = new THREE.BufferGeometry().setFromPoints( points );
+					var geometrySpacedPoints = new THREE.BufferGeometry().setFromPoints( spacedPoints );
 
 
 					// solid line
 					// solid line
 
 
-					var line = new THREE.Line( points, new THREE.LineBasicMaterial( { color: color, linewidth: 3 } ) );
+					var line = new THREE.Line( geometryPoints, new THREE.LineBasicMaterial( { color: color, linewidth: 3 } ) );
 					line.position.set( x, y, z - 25 );
 					line.position.set( x, y, z - 25 );
 					line.rotation.set( rx, ry, rz );
 					line.rotation.set( rx, ry, rz );
 					line.scale.set( s, s, s );
 					line.scale.set( s, s, s );
@@ -127,7 +131,7 @@
 
 
 					// line from equidistance sampled points
 					// line from equidistance sampled points
 
 
-					var line = new THREE.Line( spacedPoints, new THREE.LineBasicMaterial( { color: color, linewidth: 3 } ) );
+					var line = new THREE.Line( geometrySpacedPoints, new THREE.LineBasicMaterial( { color: color, linewidth: 3 } ) );
 					line.position.set( x, y, z + 25 );
 					line.position.set( x, y, z + 25 );
 					line.rotation.set( rx, ry, rz );
 					line.rotation.set( rx, ry, rz );
 					line.scale.set( s, s, s );
 					line.scale.set( s, s, s );
@@ -135,7 +139,7 @@
 
 
 					// vertices from real points
 					// vertices from real points
 
 
-					var particles = new THREE.Points( points, new THREE.PointsMaterial( { color: color, size: 4 } ) );
+					var particles = new THREE.Points( geometryPoints, new THREE.PointsMaterial( { color: color, size: 4 } ) );
 					particles.position.set( x, y, z + 75 );
 					particles.position.set( x, y, z + 75 );
 					particles.rotation.set( rx, ry, rz );
 					particles.rotation.set( rx, ry, rz );
 					particles.scale.set( s, s, s );
 					particles.scale.set( s, s, s );
@@ -143,7 +147,7 @@
 
 
 					// equidistance sampled points
 					// equidistance sampled points
 
 
-					var particles = new THREE.Points( spacedPoints, new THREE.PointsMaterial( { color: color, size: 4 } ) );
+					var particles = new THREE.Points( geometrySpacedPoints, new THREE.PointsMaterial( { color: color, size: 4 } ) );
 					particles.position.set( x, y, z + 125 );
 					particles.position.set( x, y, z + 125 );
 					particles.rotation.set( rx, ry, rz );
 					particles.rotation.set( rx, ry, rz );
 					particles.scale.set( s, s, s );
 					particles.scale.set( s, s, s );

+ 5 - 4
examples/webgl_geometry_text_shapes.html

@@ -116,11 +116,12 @@
 
 
 						var shape = shapes[ i ];
 						var shape = shapes[ i ];
 
 
-						var lineGeometry = shape.createPointsGeometry();
+						var points = shape.getPoints();
+						var geometry = new THREE.BufferGeometry().setFromPoints( points );
+						
+						geometry.translate( xMid, 0, 0 );
 
 
-						lineGeometry.translate( xMid, 0, 0 );
-
-						var lineMesh = new THREE.Line( lineGeometry, matDark );
+						var lineMesh = new THREE.Line( geometry, matDark );
 						lineText.add( lineMesh );
 						lineText.add( lineMesh );
 
 
 					}
 					}

+ 46 - 0
src/Three.Legacy.js

@@ -24,6 +24,7 @@ import { Geometry } from './core/Geometry.js';
 import { Object3D } from './core/Object3D.js';
 import { Object3D } from './core/Object3D.js';
 import { Uniform } from './core/Uniform.js';
 import { Uniform } from './core/Uniform.js';
 import { Curve } from './extras/core/Curve.js';
 import { Curve } from './extras/core/Curve.js';
+import { CurvePath } from './extras/core/CurvePath.js';
 import { CatmullRomCurve3 } from './extras/curves/CatmullRomCurve3.js';
 import { CatmullRomCurve3 } from './extras/curves/CatmullRomCurve3.js';
 import { AxesHelper } from './helpers/AxesHelper.js';
 import { AxesHelper } from './helpers/AxesHelper.js';
 import { BoxHelper } from './helpers/BoxHelper.js';
 import { BoxHelper } from './helpers/BoxHelper.js';
@@ -242,6 +243,51 @@ Curve.create = function ( construct, getPoint ) {
 
 
 //
 //
 
 
+Object.assign( CurvePath.prototype, {
+
+	createPointsGeometry: function ( divisions ) {
+
+		console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
+
+		// generate geometry from path points (for Line or Points objects)
+
+		var pts = this.getPoints( divisions );
+		return this.createGeometry( pts );
+
+	},
+
+	createSpacedPointsGeometry: function ( divisions ) {
+
+		console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
+
+		// generate geometry from equidistant sampling along the path
+
+		var pts = this.getSpacedPoints( divisions );
+		return this.createGeometry( pts );
+
+	},
+
+	createGeometry: function ( points ) {
+
+		console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
+
+		var geometry = new Geometry();
+
+		for ( var i = 0, l = points.length; i < l; i ++ ) {
+
+			var point = points[ i ];
+			geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
+
+		}
+
+		return geometry;
+
+	}
+
+} );
+
+//
+
 export function ClosedSplineCurve3( points ) {
 export function ClosedSplineCurve3( points ) {
 
 
 	console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
 	console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );

+ 17 - 0
src/core/BufferGeometry.js

@@ -334,6 +334,23 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, {
 
 
 	},
 	},
 
 
+	setFromPoints: function ( points ) {
+
+		var position = [];
+
+		for ( var i = 0, l = points.length; i < l; i ++ ) {
+
+			var point = points[ i ];
+			position.push( point.x, point.y, point.z || 0 );
+
+		}
+
+		this.addAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
+
+		return this;
+
+	},
+
 	updateFromObject: function ( object ) {
 	updateFromObject: function ( object ) {
 
 
 		var geometry = object.geometry;
 		var geometry = object.geometry;

+ 15 - 0
src/core/Geometry.js

@@ -921,6 +921,21 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, {
 
 
 	},
 	},
 
 
+	setFromPoints: function ( points ) {
+
+		this.vertices = [];
+
+		for ( var i = 0, l = points.length; i < l; i ++ ) {
+
+			var point = points[ i ];
+			this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
+
+		}
+
+		return this;
+
+	},
+
 	sortFacesByMaterialIndex: function () {
 	sortFacesByMaterialIndex: function () {
 
 
 		var faces = this.faces;
 		var faces = this.faces;

+ 0 - 39
src/extras/core/CurvePath.js

@@ -1,6 +1,4 @@
 import { Curve } from './Curve.js';
 import { Curve } from './Curve.js';
-import { Vector3 } from '../../math/Vector3.js';
-import { Geometry } from '../../core/Geometry.js';
 import { LineCurve } from '../curves/LineCurve.js';
 import { LineCurve } from '../curves/LineCurve.js';
 
 
 /**
 /**
@@ -198,43 +196,6 @@ CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
 
 
 		return points;
 		return points;
 
 
-	},
-
-	/**************************************************************
-	 *	Create Geometries Helpers
-	 **************************************************************/
-
-	/// Generate geometry from path points (for Line or Points objects)
-
-	createPointsGeometry: function ( divisions ) {
-
-		var pts = this.getPoints( divisions );
-		return this.createGeometry( pts );
-
-	},
-
-	// Generate geometry from equidistant sampling along the path
-
-	createSpacedPointsGeometry: function ( divisions ) {
-
-		var pts = this.getSpacedPoints( divisions );
-		return this.createGeometry( pts );
-
-	},
-
-	createGeometry: function ( points ) {
-
-		var geometry = new Geometry();
-
-		for ( var i = 0, l = points.length; i < l; i ++ ) {
-
-			var point = points[ i ];
-			geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
-
-		}
-
-		return geometry;
-
 	}
 	}
 
 
 } );
 } );