bit*_*inn 0 javascript procedural-generation three.js
我的目标是创建一个粒子系统,其中涉及每个粒子(顶点)的程序生成纹理,但我发现很难创建这样的粒子系统的原型,它在Canvas和WebGL渲染器下都可以使用three.js
我想要实现的标准:
目前这是否可以使用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)
对于问题1你无能为力.ParticleCanvasMaterial用于CanvasRenderer.
关于2和3,你可以使用ParticleBasicMaterial和生成程序生成的纹理WebGLRenderer.这是一个圆形纹理和随机顶点颜色:http://jsfiddle.net/7yDGy/1/