将一个圆形几何体指向一个三角形.js

时间:2016-07-09 20:19:54

标签: javascript 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 个答案:

答案 0 :(得分:0)

如果您想将这两个对象视为一个,请使用THREE.Object3D()并操纵它。