2016-07-09 8 views
0

以下は私のスニペットですが、今は球面上に単一のパーティクルを配置したいと思います。 ParticalとSphereのジオメトリをどのように組み合わせることができますか?これが達成されると私はあなたが1のTHREE.Object3D()を使用して、それを操作するように2つのオブジェクトを扱いたい場合は、動的にthree.jsの球体ジオメトリをポイント

 init(); 
     animate(); 

     function init() { 
     camera = new THREE.PerspectiveCamera(60, window.innerWidth/window.innerHeight, 1, 2000); 
     camera.position.z = 500; 

     renderer = new THREE.WebGLRenderer(); 
     renderer.setClearColor(0x000000); 
     renderer.setPixelRatio(window.devicePixelRatio); 
     renderer.setSize(window.innerWidth, window.innerHeight); 

     document.body.appendChild(renderer.domElement); 

     scene = new THREE.Scene(); 

     loader = new THREE.TextureLoader(); 
     loader.load('<%= image_path('earthmap1k.jpg') %>', function (texture) { 
      geometry = new THREE.SphereGeometry(200, 20, 20); 
      material = new THREE.MeshBasicMaterial({ map: texture, overdraw: 0.5, wireframe: true }); 
      mesh = new THREE.Mesh(geometry, material); 
      scene.add(mesh); 
     }); 

    function addPartical() { 
    var distance = 200; 
    ggeometry = new THREE.Geometry(); 
    vertex  = new THREE.Vector3(); 
    theta  = THREE.Math.randFloatSpread(360); 
    phi  = THREE.Math.randFloatSpread(360); 

    vertex.x = distance * Math.sin(theta) * Math.cos(phi); 
    vertex.y = distance * Math.sin(theta) * Math.sin(phi); 
    vertex.z = distance * Math.cos(theta); 

    ggeometry.vertices.push(vertex); 

    particles = new THREE.Points(ggeometry, new THREE.PointsMaterial({color: 0xffffff})); 
    particles.boundingSphere = 50; 
    scene.add(particles); 
    }; 

     } 



     function animate() { 
     requestAnimationFrame(animate); 
     addParticle(); 
     render(); 
     } 

     function render() { 
     renderer.render(scene, camera); 
     } 
+1

ここで球を描いています。パーティクルのコードはどこにありますか? – gaitat

+0

@gaitatパーティクルを追加するために私の答えを編集しました。しかし、この場合、これらは2つの異なるジオメトリであるため、世界地図とパーティクルは互いに結ばれません。私は球に粒子をマッピングしたい。球が回転しても、それに粒子が付く。 –

+0

あなたは、あなたの 'distance'変数に等しい半径の球で粒子を描いている。同じ半径の球も描画しています。だからあなたの粒子は球に落ちるはずです。 – gaitat

答えて

0

球の上に粒子をレンダリングします。

+0

私は実際には 'THREE.Group();'を使って問題を解決しました...シーンの代わりに '球形ジオメトリ'と 'パーティクル'を追加しましたが、 'Object3D'はこの場合にどのように使うことができるかを確認してください –

+0

nice件名に関する議論:https://github.com/mrdoob/three.js/issues/8711 – gaitat

関連する問題