2

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

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

有没有人有什么建议?

4

1 回答 1

3

这取决于您正在处理的“粒子”的含义。使用 a您将指WebGLRenderer的是 a 中的顶点ParticleSystem,但使用 aCanvasRenderer您的意思是Particle(仅适用于 Canvas)。就粒子系统而言,用于构造它的材料具有大小,就像在通常的示例中一样: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
于 2012-07-19T23:11:47.063 回答