Creating a particle system but computed value is NaN?

Hi guys I have a particle system I made, it’s just particles in the shape of a texture and they are randomly generated inside of an imaginary square.

And everything works perfectly fine! these particles are doing EXACTLY what I want them to do. but I keep getting the error message:

THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The “position” attribute is likely to have NaN values.

what have I done wrong in the code? Thanks

THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The “position” attribute is likely to have NaN values.

const textureeeee = new THREE.TextureLoader().load( 'Untitled00000000 Small.png' );

const ParticlesGeometryyy = new THREE.BufferGeometry();
const ParticlesCnttt = 50000;
const verticesss = [];

verticesss.push();


const posArrayyy = new Float32Array(ParticlesCnttt);
for(let i = 0; i < ParticlesCntt; i++){
    posArrayyy[i] = (Math.random()-0.5)*60
}

ParticlesGeometryyy.setAttribute('position', new THREE.BufferAttribute(posArrayyy, 3, 3));
const materialForParticlesss = new THREE.PointsMaterial({
    size: 0.15,
    map: textureeeee,
    transparent: true,
    depthWrite: false,
})

const ParticlesMeshhh = new THREE.Points(ParticlesGeometryyy, materialForParticlesss)
//scene.add(ParticlesMeshhh)
ParticlesMeshhh.translateX(500)
ParticlesMeshhh.translateY(1.25)
ParticlesMeshhh.translateZ(12.5)

Hi!

When you do this, your array for that buffer attribute contains data for anything else, but not for 50K vertices.
As each vertex has 3 values, your attribute now is for 50000 / 3 = 16666.666.

Thus, this part:

const posArrayyy = new Float32Array(ParticlesCnttt);
for(let i = 0; i < ParticlesCntt; i++){
    posArrayyy[i] = (Math.random()-0.5)*60
}

needs a minor change:

const posArrayyy = new Float32Array(ParticlesCnttt * 3); // triple the count
for(let i = 0; i < ParticlesCntt * 3; i++){ // also triple the count
    posArrayyy[i] = (Math.random()-0.5)*60
}

PS I haven’t tested, it’s just a thought :slight_smile:

1 Like

Yep! worked perfectly! thank you!

1 Like