你如何在Three.js中找到粒子的大小?

时间:2012-06-20 15:37:07

标签: three.js

如何在Three.js中找到粒子的大小?

使用geometrys,您可以使用边界框/球体以三个单位计算其大小。但是一个粒子没有边界框,无论如何我都看不到它的大小。

有人有任何建议吗?

1 个答案:

答案 0 :(得分:3)

这取决于你正在处理的'粒子'的含义。使用WebGLRenderer,您将引用ParticleSystem中的顶点,但使用CanvasRenderer表示Particle(仅限Canvas)。就ParticleSystem而言,用于构造它的材料有一个大小,就像通常的例子一样:     geometry = new THREE.Geometry();

for ( i = 0; i < 10000; i ++ ) {
  var vertex = new THREE.Vector3(); // and set its location
  geometry.vertices.push( vertex );
}

material = new THREE.ParticleBasicMaterial( { 
  size: 35,  // This might be the size you are thinking of?
  sizeAttenuation: false, 
  map: // Some THREE.Texture
});

particles = new THREE.ParticleSystem( geometry, material );

然后您可以访问该尺寸,并使用

进行修改
particles.material.size = newSize;

如果要为画布创建Particle,那么它非常相似:

// Construct the particle with a material
var material = new THREE.ParticleBasicMaterial( { 
  map: new THREE.Texture(  canvas ), 
  blending: THREE.AdditiveBlending 
}); 
particle = new THREE.Particle( textMaterial );
// Just need to access the material to get the 'size'
var size = particle.material.size