47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
import * as THREE from 'three';
|
|
|
|
export class DustEffect {
|
|
constructor(scene) {
|
|
this.dust = null;
|
|
this._create(scene);
|
|
}
|
|
|
|
_create(scene) {
|
|
const particleCount = 2000;
|
|
const particlesGeometry = new THREE.BufferGeometry();
|
|
const positions = [];
|
|
|
|
for (let i = 0; i < particleCount; i++) {
|
|
positions.push(
|
|
(Math.random() - 0.5) * 15,
|
|
Math.random() * 10,
|
|
(Math.random() - 0.5) * 15
|
|
);
|
|
}
|
|
particlesGeometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
|
|
|
|
const particleMaterial = new THREE.PointsMaterial({
|
|
color: 0xffffff,
|
|
size: 0.015,
|
|
transparent: true,
|
|
opacity: 0.08,
|
|
blending: THREE.AdditiveBlending
|
|
});
|
|
|
|
this.dust = new THREE.Points(particlesGeometry, particleMaterial);
|
|
scene.add(this.dust);
|
|
}
|
|
|
|
update() {
|
|
if (this.dust) {
|
|
const positions = this.dust.geometry.attributes.position.array;
|
|
for (let i = 1; i < positions.length; i += 3) {
|
|
positions[i] -= 0.001;
|
|
if (positions[i] < -2) {
|
|
positions[i] = 8;
|
|
}
|
|
}
|
|
this.dust.geometry.attributes.position.needsUpdate = true;
|
|
}
|
|
}
|
|
} |