2

I want to create a CurvePath for example

var spline = new THREE.SplineCurve3([
    new THREE.Vector3(0, 0, 0),
    new THREE.Vector3(1, 0, 0),
    new THREE.Vector3(1, 1, 0),
]);

and I will send a particle along with path using (javascript psuedocode)

var t = 0;

function update(){
    t = t + 0.05;
    particle.position = spline.getPointAt(t)
}

However I want the splinecurve not to create soft bends at the edges of the shape, so for the shape above the particle will turn at a right angle at the point (1, 0, 0).

I know this should be implemented in LineCurve3 or something, but for all the other curves except for SplineCurve3, getPoint() is not implemented.

Im using THREE r59.

4

1 回答 1

3

编辑:THREE.Curve.create()已被弃用。请参阅此答案以了解要遵循的新模式。


要创建自己的曲线类,即 的子类THREE.Curve,请遵循以下模式:

MyCurve = THREE.Curve.create(

    // define the constructor (args optional)
    function( points, s ) {

        this.points = points;
        this.myProperty = s; // add a property if you want

    },

    // define the getPoint() function
    function( t ) {

        return new THREE.Vector3( x, y, z ); // flesh this out

    }

);

在您的情况下,您可以复制SplineCurve3- 您只需要更改getPoint()功能。为此,您可以替换它:

    v.x = THREE.Curve.Utils.interpolate(pt0.x, pt1.x, pt2.x, pt3.x, weight);
    v.y = THREE.Curve.Utils.interpolate(pt0.y, pt1.y, pt2.y, pt3.y, weight);
    v.z = THREE.Curve.Utils.interpolate(pt0.z, pt1.z, pt2.z, pt3.z, weight);

使用简单的线性插值:

    v.copy( pt1 ).lerp( pt2, weight );

三.js r.60

于 2013-09-02T21:13:51.490 回答