阅读(3191) (0)

three.js Path

2022-12-26 13:53:22 更新

该类定义了二维路径,提供了一些类似2D Canvas API的方法来创建或者构造二维路径。

代码示例

const path = new THREE.Path();

path.lineTo( 0, 0.8 );
path.quadraticCurveTo( 0, 1, 0.2, 1 );
path.lineTo( 1, 1 );

const points = path.getPoints();

const geometry = new THREE.BufferGeometry().setFromPoints( points );
const material = new THREE.LineBasicMaterial( { color: 0xffffff } );

const line = new THREE.Line( geometry, material );
scene.add( line );

构造函数

Path( points : Array )

points -- (可选)Vector2s数组。

从传入的点中创建一条Path。第一个点定义了偏移量, 接下来的点作为LineCurves被添加到curves数组中。

倘若没有点被指定,一条空路径将会被创建,.currentPoint将被设置为原点。

属性

共有属性请参见其基类CurvePath。

.currentPoint : Vector2

路径当前的偏移量,任何新被加入的Curve将会从这里开始。

方法

共有方法请参见其基类CurvePath。

.absarc ( x : Float, y : Float, radius : Float, startAngle : Float, endAngle : Float, clockwise : Boolean ) : this

x, y -- 弧线的绝对中心。
radius -- 弧线的半径。
startAngle -- 起始角,以弧度来表示。
endAngle -- 终止角,以弧度来表示。
clockwise -- 以顺时针方向创建(扫过)弧线。默认值为false

添加一条绝对定位的EllipseCurve到路径中。

.absellipse ( x : Float, y : Float, xRadius : Float, yRadius : Float, startAngle : Float, endAngle : Float, clockwise : Boolean, rotation : Float ) : this

x, y -- 椭圆的绝对中心。
xRadius -- 椭圆x轴方向的半径。
yRadius -- 椭圆y轴方向的半径。
startAngle -- 起始角,以弧度来表示。
endAngle -- 终止角,以弧度来表示。
clockwise -- 以顺时针方向创建(扫过)椭圆。默认值为false
rotation -- 椭圆从X轴正方向逆时针的旋转角度(可选),以弧度表示,默认值为0

添加一条绝对定位的EllipseCurve到路径中。

.arc ( x : Float, y : Float, radius : Float, startAngle : Float, endAngle : Float, clockwise : Boolean ) : this

x, y -- 弧线的中心来自上次调用后的偏移量。
radius -- 弧线的半径。
startAngle -- 起始角,以弧度来表示。
endAngle -- 终止角,以弧度来表示。
clockwise -- 以顺时针方向创建(扫过)弧线。默认值为false

添加一条EllipseCurve到路径中,位置相对于.currentPoint。

.bezierCurveTo ( cp1X : Float, cp1Y : Float, cp2X : Float, cp2Y : Float, x : Float, y : Float ) : this

从.currentPoint创建一条贝塞尔曲线,以(cp1X, cp1Y)和(cp2X, cp2Y)作为控制点,并将.currentPoint更新到x,y。

.ellipse ( x : Float, y : Float, xRadius : Float, yRadius : Float, startAngle : Float, endAngle : Float, clockwise : Boolean, rotation : Float ) : this

x, y -- 椭圆的中心来自上次调用后的偏移量。The center of the ellipse offset from the last call.
xRadius -- 椭圆x轴方向的半径。
yRadius -- 椭圆y轴方向的半径。
startAngle -- 起始角,以弧度来表示。
endAngle -- 终止角,以弧度来表示。
clockwise -- 以顺时针方向创建(扫过)椭圆。默认值为false
rotation -- 椭圆从X轴正方向逆时针的旋转角度(可选),以弧度表示,默认值为0

添加一条EllipseCurve到路径中,位置相对于.currentPoint。

.lineTo ( x : Float, y : Float ) : this

在当前路径上,从.currentPoint连接一条直线到x,y。

.moveTo ( x : Float, y : Float ) : this

将.currentPoint移动到x, y。

.quadraticCurveTo ( cpX : Float, cpY : Float, x : Float, y : Float ) : this

从.currentPoint创建一条二次曲线,以(cpX,cpY)作为控制点,并将.currentPoint更新到x,y。

.setFromPoints ( vector2s : Array ) : this

points -- Vector2数组。点将被作为LineCurves加入到curves数组中。

.splineThru ( points : Array ) : this

points -Vector2数组。连接一条新的SplineCurve到路径上。

源代码

src/extras/core/Path.js