(newPattern)
| 199 | } |
| 200 | |
| 201 | function transitionToPattern(newPattern) { |
| 202 | if (!particles || !particles.geometry || !particles.geometry.attributes.position) return; |
| 203 | |
| 204 | isTransitioning = true; |
| 205 | const posAttr = particles.geometry.attributes.position; |
| 206 | const colAttr = particles.geometry.attributes.color; |
| 207 | |
| 208 | // Ensure current colors are stored correctly before starting |
| 209 | if (!particles.geometry.userData.currentColors || particles.geometry.userData.currentColors.length !== colAttr.array.length) { |
| 210 | particles.geometry.userData.currentColors = new Float32Array(colAttr.array); |
| 211 | } |
| 212 | |
| 213 | const curPos = new Float32Array(posAttr.array); |
| 214 | const curCol = new Float32Array(particles.geometry.userData.currentColors); // Use stored colors as 'from' |
| 215 | |
| 216 | const newPos = new Float32Array(curPos.length); |
| 217 | const patternFn = patterns[newPattern]; |
| 218 | const count = params.particleCount; |
| 219 | |
| 220 | // Generate new positions |
| 221 | for (let i = 0; i < count; i++) { |
| 222 | const p = patternFn(i, count); |
| 223 | newPos[i * 3] = p.x; |
| 224 | newPos[i * 3 + 1] = p.y; |
| 225 | newPos[i * 3 + 2] = p.z; |
| 226 | } |
| 227 | |
| 228 | // Generate new colors |
| 229 | const newCol = new Float32Array(curCol.length); |
| 230 | const palette = colorPalettes[newPattern%colorPalettes.length]; |
| 231 | for (let i = 0; i < count; i++) { |
| 232 | const base = palette[0]; |
| 233 | const variation = 1.0; // Keep color variation consistent |
| 234 | newCol[i * 3] = base.r * variation; |
| 235 | newCol[i * 3 + 1] = base.g * variation; |
| 236 | newCol[i * 3 + 2] = base.b * variation; |
| 237 | } |
| 238 | |
| 239 | // Store transition data |
| 240 | particles.userData.fromPositions = curPos; |
| 241 | particles.userData.toPositions = newPos; |
| 242 | particles.userData.fromColors = curCol; |
| 243 | particles.userData.toColors = newCol; |
| 244 | particles.userData.targetPattern = newPattern; // Store the target pattern index |
| 245 | transitionProgress = 0; // Reset progress |
| 246 | } |
| 247 | |
| 248 | |
| 249 | // --- Helper function to map a value from one range to another --- |
no outgoing calls
no test coverage detected