2016-05-02 82 views
1

我沒有找到正確的語法來從數組中動態生成一個BezierCurve,我試圖做一個推動,但它不工作。Three.js |動態生成一個BezierCurve

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); 

一個想法?

+2

['THREE.CubicBezierCurve3'](http://threejs.org/docs/#Reference /Extras.Curves/CubicBezierCurve3)不需要數組,它需要四(4)['THREE.Vector3'](http://threejs.org/docs/#Reference/Math/Vector3)。 –

+0

RightAndré,THREE.CubicBezierCurve3採取4 Three.Vector3 MAXIMUM。 –

回答

1

可以使用

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

,或者如果你的目標只是ES6兼容的瀏覽器蔓延運營商

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

超級!!!它的工作完美! –