2012-06-20 36 views
2

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

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

有没有人有任何建议?

回答

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