定义THREE.Vector3的随机坐标

时间:2014-08-08 15:06:09

标签: javascript three.js

我在Three JS中挤出一个样条曲线,我希望z轴是随机的。

目前我正在使用Math.random()*(10 + 10) - 10来获取Z的值

但是我有很多这些线,它汲取了大量资源。

是否有诀窍使这段代码更好?

谢谢!

var Spline6 =  new THREE.SplineCurve3( [

    new THREE.Vector3(225.8,42.3,Math.random() * (10 + 10) - 10 ),
    new THREE.Vector3(68.4,42.3,Math.random() * (10 + 10) - 10 ),
    new THREE.Vector3(62.1,42.9,Math.random() * (10 + 10) - 10 ),
    new THREE.Vector3(52.9,45.1,Math.random() * (10 + 10) - 10 ),
    new THREE.Vector3(41.9,49.8,Math.random() * (10 + 10) - 10 ),

] );


var pts = [], numPts = 32;

for ( var i = 0; i < numPts * 6; i ++ ) {

var l = 4

var a = i / numPts * Math.PI;

pts.push( new THREE.Vector2 ( Math.cos( a ) * l *2, Math.sin( a ) * l ) ); 

}

var shape = new THREE.Shape( pts );

var geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );

var material3 = new THREE.MeshLambertMaterial( { color: 0x717171, wireframe: false } );



var mesh = new THREE.Mesh( geometry, material3 );

scene.add( mesh );

0 个答案:

没有答案