使用three.js对Particle进行程序生成的纹理

bit*_*inn 0 javascript procedural-generation three.js

我的目标是创建一个粒子系统,其中涉及每个粒子(顶点)的程序生成纹理,但我发现很难创建这样的粒子系统的原型,它在Canvas和WebGL渲染器下都可以使用three.js

我想要实现的标准:

  1. 渲染器独立(ParticleCanvasMaterial不能与WebGL一起使用)
  2. 圆形纹理(ParticleBasicMaterial不喜欢画布纹理;无法使其输出圆形)
  3. 程序生成那些纹理(不能只使用带有准备的圆纹理的loadTexture)

目前这是否可以使用three.js?我错过了一些功能吗?

//create a texture generation function
function simpleTexture() {

    // generate canvas
    var canvas = document.createElement('canvas');
    canvas.width = 100;
    canvas.height = 100;

    // get context
    var context = canvas.getContext('2d');

    // circle texture
    context.beginPath();
    context.arc(50, 50, 50, 0, Math.PI*2, true); 
    context.closePath();
    context.fillStyle = "red";
    context.fill();

    // get texture
    texture = new THREE.Texture(
        canvas
    );

    texture.needsUpdate = true;
    return texture;

}

    //then use it like following...

    var material = new THREE.ParticleBasicMaterial({
        color: 0xffffff,
        size: 1,
        map: simpleTexture,
        blending: THREE.AdditiveBlending,
        transparent: true
    });

    var system = new THREE.ParticleSystem(particles, material);
Run Code Online (Sandbox Code Playgroud)

Wes*_*ley 5

对于问题1你无能为力.ParticleCanvasMaterial用于CanvasRenderer.

关于2和3,你可以使用ParticleBasicMaterial和生成程序生成的纹理WebGLRenderer.这是一个圆形纹理和随机顶点颜色:http://jsfiddle.net/7yDGy/1/