I'm trying a very simple script using ThreeJS that generate a point where you click.
This is the function that adds the point:
function addPoint(coord){
var geometry = new THREE.BufferGeometry();
var vertices = [];
const sprite = new THREE.TextureLoader().load( 'textures/disc.png' );
vertices.push( coord.x, coord.y, coord.z );
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
var material = new THREE.PointsMaterial( { size: 1, sizeAttenuation: true, map: sprite, alphaTest: 0.5, transparent: true } );
material.color.setHSL( 1.0, 0.3, 0.7 );
const particles = new THREE.Points( geometry, material );
//scene.add( particles );
group.add( particles );
}
But it adds to the scene just the first point created. The curious thing is that in the same function i put the original example that generates random points, it doesn't just adds all the generated vertices, but it works every time you click
for ( let i = 0; i < 10000; i ++ ) {
const x = 2000 * Math.random() - 1000;
const y = 2000 * Math.random() - 1000;
const z = 2000 * Math.random() - 1000;
vertices.push( x, y, z );
}
What I did wrong in my life to deserve this illogical working?
Thank you!