Three.js Sparks.js - “断言失败,游泳池耗尽”

时间:2013-04-26 08:21:42

标签: three.js

我有以下简单的函数,它应该产生一个简单的火焰效果,我从这里构建代码的实际显示部分:

http://jeromeetienne.github.io/sparkseditor/

每当我运行该功能时,它似乎耗尽了池(最大粒子)然后死亡,屏幕上没有可见的痕迹。我正在使用r53,而许多(如果不是全部)sparks.js示例都使用r47,不确定这是否相关。

您可以在此处找到产生错误的实际文件:

http://jeromeetienne.github.io/threex/docs/threex.sparks.html

我的火焰代码如下:

  var position = data.status.position;
  var group = new Object3D();

  scene.add(group);

  var sparks = new THREEx.Sparks({
     maxParticles : 10,
     counter : new SPARKS.SteadyCounter(300)
  });

  var emitter   = sparks.emitter();

  var color = function() {
     this.initialize = function(emitter, particle) {
        particle.target.color().setHSV(0.4, 0.8, 0.4);
        particle.target.size(100);
     };
  };

  emitter.addInitializer(new color());
  emitter.addInitializer(new SPARKS.Position(new SPARKS.PointZone(new THREE.Vector3(

     position.x, position.y, position.z

  ))));
  emitter.addInitializer(new SPARKS.Lifetime(0, 0.8));
  emitter.addInitializer(new SPARKS.Velocity(new SPARKS.PointZone(new THREE.Vector3(

     position.x, position.y-100, position.z

  ))));
  emitter.addAction(new SPARKS.Age());
  emitter.addAction(new SPARKS.Move());
  emitter.addAction(new SPARKS.RandomDrift(1000,0,1000));
  emitter.addAction(new SPARKS.Accelerate(0,-200,0));

  emitter.addCallback('created', function(particle) {
     group.add(particle);
  });
  emitter.addCallback('dead', function(particle) {
     particle.target.visible = false;
     group.remove(particle);
  });

  emitter.start();

在此先感谢,非常感谢任何帮助:)

1 个答案:

答案 0 :(得分:0)

我最近编写了一个能够产生特殊效果的粒子引擎,包括火焰效果,目前适用于Three.js v.56:

http://stemkoski.github.io/Three.js/Particle-Engine.html

http://stemkoski.blogspot.com/2013/06/creating-particle-effects-engine-in.html附带的博文包含相关详细信息。也许这段代码可以根据您的需求进行调整?

希望这有帮助!