我正在尝试使用ThreeJS编写一个非常简单的脚本,它可以在您单击的位置生成一个点。
这是添加该点的函数:
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 );
}
但它只添加了第一个创建的点。有趣的是,在同一函数中,我放置了生成随机点的原始示例,它不仅添加了所有生成的顶点,而且每次单击都能正常工作。
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 );
}
我在生活中做错了什么,才会遭受这种不合逻辑的工作?
谢谢!