1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| export class CloudsPlus { constructor( height = 20, num = 100, size = 400, scale = 100, autoRotate = true ) { this.height = height; this.num = num; this.size = size; this.scale = scale; this.autoRotate = autoRotate; let textureLoader = new THREE.TextureLoader(); const map1 = textureLoader.load("./textures/cloud/cloud1.jfif"); const map2 = textureLoader.load("./textures/cloud/cloud2.jfif"); const map3 = textureLoader.load("./textures/cloud/cloud3.jpg");
let materials = [];
let material1 = new THREE.PointsMaterial({ map: map1, color: 0xffffff, alphaMap: map2, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, depthTest: false, size: 0.2 * size, }); let material2 = new THREE.PointsMaterial({ map: map2, color: 0xffffff, alphaMap: map3, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, depthTest: false, size: 0.5 * size, }); let material3 = new THREE.PointsMaterial({ map: map3, color: 0xffffff, alphaMap: map1, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, depthTest: false, size: 0.8 * size, }); let material4 = new THREE.PointsMaterial({ map: map2, color: 0xffffff, alphaMap: map1, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, depthTest: false, size: 1 * size, }); materials.push(material1, material2, material3, material4); this.mesh = new THREE.Group();
for (let i = 0; i < materials.length; i++) { let material = materials[i]; let geometry = this.generateGeometry(this.num); let points = new THREE.Points(geometry, material);
this.mesh.add(points); } if (autoRotate) { this.animate(); } } generateGeometry(num = 300) { const vertices = []; for (let i = 0; i < num; i++) { let randomX = (Math.random() - 0.5) * 2 * this.scale; let randomY = Math.random() * (this.height / 2) + this.height; let randomZ = (Math.random() - 0.5) * 2 * this.scale; vertices.push(randomX, randomY, randomZ); } const geometry = new THREE.BufferGeometry(); geometry.setAttribute( "position", new THREE.Float32BufferAttribute(vertices, 3) ); return geometry; } animate() { let i = 1; this.mesh.traverse((item) => { let speed = 40 * i;
if (item instanceof THREE.Points) { gsap.to(item.rotation, { duration: speed, repeat: -1, y: Math.PI * 2, }); } i++; }); } }
|