访问THREE.js粒子系统中的单个粒子

时间:2013-07-14 20:53:39

标签: three.js system particles

我真的尝试过每一个例子,在网上搜索了几个小时,但我似乎无法让它正常工作!

所以我只是尝试实现一个模拟落雪的小粒子系统,就像这样:http://www.aerotwist.com/tutorials/creating-particles-with-three-js/

但我只能整体访问它。意思是我可以这样旋转它,但是一旦我尝试迭代它的顶点,整个动画就会出现打嗝!我真的很感激这里的一些帮助!

-

以下是关键部分:

- >设置粒子系统:

var partikelGeo = new THREE.Geometry();
    var partikelMaterial = new THREE.ParticleBasicMaterial({
        color:0xffffff,
        size: 10,
        map: THREE.ImageUtils.loadTexture('snowflake2.png'),
        blending: THREE.AdditiveBlending,
        transparent:true
        });

        var partikelAnzahl = 3500;


        for (var p = 0; p < partikelAnzahl; p++) {

            var pX = Math.random() * 1000 -500;
            var pY = Math.random() * 1000 -500;
            var pZ = Math.random() * 1000 -500;

            var partikel = new THREE.Vertex(new THREE.Vector3(pX,pY,pZ));

            partikel.velocity = new THREE.Vector3(0,-Math.random(),0);

            partikelGeo.vertices.push(partikel);



        }   



    var partikelSystem = new THREE.ParticleSystem(partikelGeo, partikelMaterial);
    partikelSystem.sortParticles = true;
    scene.add(partikelSystem);

- &GT;渲染&amp;鼠标点击动画

var frame = 0;

        function animate(){

        // request new frame
        requestAnimationFrame(function(){
            animate();
        });

        // render
        render();
  }

animate();


        var check = 0;

        onmousedown = function(){

            if (check) {
                check = 0;
            }else{
                check = 1;
            }

        }

        function render() {

              if (check) {
                clickDo();
              }


            camera.lookAt(new THREE.Vector3(0,0,0));

             renderer.render(scene,camera);

        }




        function clickDo() {
            frame++;

    partikelSystem.rotation.y += 0.01;


    var pCount = partikelAnzahl;
        while(pCount--) {

          // get the particle
          var particle =
        partikelGeo.vertices[pCount];

          // check if we need to reset
          if(particle.position.y < -200) {
        particle.position.y = 200;
        particle.velocity.y = 0;
          }

          // update the velocity with
          // a splat of randomniz
          particle.velocity.y -=
        Math.random() * .1;

          // and the position
          particle.position.addSelf(
        particle.velocity);
        }

        // flag to the particle system
        // that we've changed its vertices.
        partikelSystem.
          geometry.
          __dirtyVertices = true;       




        }

拉​​赫

1 个答案:

答案 0 :(得分:0)

您的代码对我来说很好。我建议在使用添加剂混合时尝试不对粒子进行排序:

partikelSystem.sortParticles = false;