2016-05-09 10 views
1

私はThree.jsで卵メッシュを作成しようとしています。私はLatheGeometryを使って以下のコードを書いたが、正しい方程式がない。誰も助けることができますか?Three.jsで卵メッシュを作成するには?

var r0 = 40 
var r1 = r0/4; 
var inc = Math.PI/r0; 
points = []; 
points.push(new THREE.Vector2(0.0001, -r0/2)); 
for (var i = 0; i <= r0; i ++) { 
    var def = i<r0/2 ? 0 : r1*Math.sin((i-r0/2)*inc); 
    points.push(new THREE.Vector2(Math.sqrt(r0*i-i*i), i+def-r0/2)); 
} 
points.push(new THREE.Vector2(0.0001, -r0/2)); 
var geometry = new THREE.LatheGeometry(points, 30); 
var material = new THREE.MeshPhongMaterial({ color: 0xFFFF20 }); 
Ovo = new THREE.Mesh(geometry, material); 
Ovo.position.set(0, 20.1, 0); 
scene.add(Ovo); 

答えて

8

あなたはそうのように "卵" ジオメトリを作成することができます

// points - (x, y) pairs are rotated around the y-axis 
var points = []; 
for (var deg = 0; deg <= 180; deg += 6) { 

    var rad = Math.PI * deg/180; 
    var point = new THREE.Vector2((0.72 + .08 * Math.cos(rad)) * Math.sin(rad), - Math.cos(rad)); // the "egg equation" 
    //console.log(point); // x-coord should be greater than zero to avoid degenerate triangles; it is not in this formula. 
    points.push(point); 

} 

geometry = new THREE.LatheBufferGeometry(points, 32); 

enter image description here

three.js r.76

関連する問題