我的目标是创建一个粒子系统,其中涉及为每个粒子(顶点)程序生成的纹理,但我发现很难创建一个在 Canvas 和 WebGL 渲染器下使用 three.js 的粒子系统的原型
我要达到的标准:
- 独立于渲染器(ParticleCanvasMaterial 不适用于 WebGL)
- 圆形纹理(ParticleBasicMaterial 不喜欢画布纹理;无法使其输出圆形)
- 程序生成这些纹理(不能只使用带有准备好的圆形纹理的 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);