【问题标题】:creating a spherical particle basic material for webgl renderer in threejs在threejs中为webgl渲染器创建球形粒子基础材质
【发布时间】:2013-06-07 09:31:33
【问题描述】:

我有一个工作的threejs示例,其中粒子通过画布使用程序函数渲染到球形对象上,如下所示:

var material = new THREE.ParticleCanvasMaterial( {

      color: 0xffffff,
      program: function ( context ) {

        context.beginPath();
        context.arc( 0, 0, 1, 0, PI2, true );
        context.closePath();
        context.fill();

      }

    } );

    for ( var i = 0; i < 1000; i ++ ) {

      particle = new THREE.Particle( material );
      particle.position.x = Math.random() * 2 - 1;
      particle.position.y = Math.random() * 2 - 1;
      particle.position.z = Math.random() * 2 - 1;
      particle.position.normalize();
      particle.position.multiplyScalar( Math.random() * 10 + 600 );

      initParticle( particle, i * 10 );

      scene.add( particle );

    }

但是,我想切换到 webGL 渲染器以使事情运行得更快一点,但它没有程序选项。似乎我可能需要使用地图,但我不确定如何。任何人都对如何调整此代码以使用 webGL 渲染器完成相同的事情有任何想法。

【问题讨论】:

标签: javascript three.js webgl


【解决方案1】:

这是一个示例,展示了如何使用 WebGLRenderer 以程序方式为您的粒子创建纹理:http://jsfiddle.net/y18ag3dq/

但是,如果您想使用自己的纹理,只需将所需的任何纹理加载到 map 字段中:

var texture = THREE.ImageUtils.loadTexture('/images/my_texture.png');
// Do NOT set this flag. Explanation provided by WestLangley in the comments
// texture.needsUpdate=true;

var material = new THREE.ParticleBasicMaterial({
  // ...
  map: texture,
  // add all relevant fields as described in the link above
});

// geometry should contain your particle vertices
var particle = new THREE.ParticleSystem(geometry, material);
scene.add(particle);

【讨论】:

  • 不要用ImageUtils.loadTexture() 设置needsUpdate 标志。它会在纹理加载后为您设置。在纹理完成加载之前设置它会导致渲染错误。
  • 我错过了那个,我的错。编辑了我的答案。
猜你喜欢
  • 2015-07-28
  • 1970-01-01
  • 2012-09-04
  • 1970-01-01
  • 2017-01-09
  • 2017-04-14
  • 2017-01-08
  • 1970-01-01
  • 2017-01-20
相关资源
最近更新 更多