Treize Cinq
Treize Cinq

Reputation: 425

Three.js | Generate dynamically a BezierCurve

I don't find the right syntax to generate dynamically a BezierCurve from an array, I've tried to make a push, but it don't work.

var x = [0,10,100,220,100, etc,...];
var y = [10,0,100,200,200, etc,...];
var z = [100,220,10,0,100, etc,...];

var points = [];

for(i=0; i < x.length; i++){ 
   points.push( new THREE.Vector3( x[i], y[i], z[i] ) );
   } 

var curve = new THREE.CubicBezierCurve3( points );

var geometry = new THREE.Geometry();
var curveObject = new THREE.Line( geometry, material );
scene.add(curveObject);

An idea ?

Upvotes: 1

Views: 620

Answers (1)

Derte Trdelnik
Derte Trdelnik

Reputation: 2706

you can use

var curve = new (Function.bind.apply(THREE.CubicBezierCurve3, [null].concat(points)));

or if you target only ES6 compatible browsers spread operator

var curve = new THREE.CubicBezierCurve3(...points);

Upvotes: 1

Related Questions