import * as THREE from 'three';

export class DustEffect {
    constructor(scene) {
        this.dust = null;
        this._create(scene);
    }

    _create(scene) {
        const particleCount = 3000;
        const particlesGeometry = new THREE.BufferGeometry();
        const positions = [];

        for (let i = 0; i < particleCount; i++) {
            positions.push(
                (Math.random() - 0.5) * 15,
                Math.random() * 8,
                (Math.random() - 0.5) * 45
            );
        }
        particlesGeometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));

        const particleMaterial = new THREE.PointsMaterial({
            color: 0xaaaaaa,
            size: 0.015,
            transparent: true,
            opacity: 0.08,
            blending: THREE.AdditiveBlending
        });

        this.dust = new THREE.Points(particlesGeometry, particleMaterial);
        scene.add(this.dust);
    }

    update(deltaTime) {
        if (deltaTime && this.dust) {
            const positions = this.dust.geometry.attributes.position.array;
            for (let i = 1; i < positions.length; i += 3) {
                positions[i] -= deltaTime * 0.006;
                if (positions[i] < -2) {
                    positions[i] = 8;
                }
            }
            this.dust.geometry.attributes.position.needsUpdate = true;
        }
    }
}