threejs 实现一个球形点阵图
import * as THREE from "three";
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
300
);
camera.position.set(0, 0, 28);
scene.add(camera);
const sphereGeometry = new THREE.SphereGeometry(15, 32, 32);
const pointsMaterial = new THREE.PointsMaterial();
pointsMaterial.size = 0.01;
pointsMaterial.color.set(0xfff000);
pointsMaterial.sizeAttenuation = true;
const points = new THREE.Points(sphereGeometry, pointsMaterial);
scene.add(points);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
let angle = 0;
function animate() {
requestAnimationFrame(animate);
points.rotation.y = angle * Math.PI / 180;
points.rotation.x = angle * Math.PI / 180;
renderer.render(scene, camera);
angle += 1;
if (angle >= 360) {
angle = 0;
}
renderer.render(scene, camera);
}
animate();
最终效果:
