提交 e42806c7 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #12406 from Mugen87/curve2

CurvePath: Remove factory methods
...@@ -316,6 +316,9 @@ ...@@ -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>
......
...@@ -315,6 +315,9 @@ ...@@ -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,
......
...@@ -49,29 +49,6 @@ ...@@ -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>
......
...@@ -27,8 +27,8 @@ var curve = new THREE.CatmullRomCurve3( [ ...@@ -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(); var points = curve.getPoints( 50 );
geometry.vertices = curve.getPoints( 50 ); var geometry = new THREE.BufferGeometry().setFromPoints( points );
var material = new THREE.LineBasicMaterial( { color : 0xff0000 } ); var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
......
...@@ -28,9 +28,9 @@ var curve = new THREE.CubicBezierCurve( ...@@ -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
......
...@@ -28,8 +28,8 @@ var curve = new THREE.CubicBezierCurve3( ...@@ -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(); var points = curve.getPoints( 50 );
geometry.vertices = curve.getPoints( 50 ); var geometry = new THREE.BufferGeometry().setFromPoints( points );
var material = new THREE.LineBasicMaterial( { color : 0xff0000 } ); var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
......
...@@ -28,8 +28,9 @@ var curve = new THREE.EllipseCurve( ...@@ -28,8 +28,9 @@ var curve = new THREE.EllipseCurve(
0 // aRotation 0 // aRotation
); );
var path = new THREE.Path( curve.getPoints( 50 ) ); var points = curve.getPoints( 50 );
var geometry = path.createPointsGeometry( 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
......
...@@ -27,9 +27,9 @@ var curve = new THREE.QuadraticBezierCurve( ...@@ -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
......
...@@ -27,8 +27,8 @@ var curve = new THREE.QuadraticBezierCurve3( ...@@ -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(); var points = curve.getPoints( 50 );
geometry.vertices = curve.getPoints( 50 ); var geometry = new THREE.BufferGeometry().setFromPoints( points );
var material = new THREE.LineBasicMaterial( { color : 0xff0000 } ); var material = new THREE.LineBasicMaterial( { color : 0xff0000 } );
......
...@@ -29,9 +29,9 @@ var curve = new THREE.SplineCurve( [ ...@@ -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
......
...@@ -924,34 +924,10 @@ ...@@ -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 @@ ...@@ -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",
......
...@@ -82,8 +82,8 @@ ...@@ -82,8 +82,8 @@
// line // line
var geometry = shape.createPointsGeometry(); var points = shape.getPoints();
geometry.vertices.push( geometry.vertices[ 0 ].clone() ); 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 } );
......
...@@ -114,12 +114,16 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 );
......
...@@ -116,11 +116,12 @@ ...@@ -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( geometry, matDark );
var lineMesh = new THREE.Line( lineGeometry, matDark );
lineText.add( lineMesh ); lineText.add( lineMesh );
} }
......
...@@ -24,6 +24,7 @@ import { Geometry } from './core/Geometry.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 ) { ...@@ -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.' );
......
...@@ -334,6 +334,23 @@ Object.assign( BufferGeometry.prototype, EventDispatcher.prototype, { ...@@ -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;
......
...@@ -921,6 +921,21 @@ Object.assign( Geometry.prototype, EventDispatcher.prototype, { ...@@ -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;
......
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 ), { ...@@ -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;
} }
} ); } );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册