()
| 156 | } |
| 157 | |
| 158 | function completeCurrentTransition() { |
| 159 | if (!isTransitioning || !particles || !particles.geometry || !particles.userData.toPositions || !particles.userData.toColors) { |
| 160 | // Clear transition state if data is missing or geometry invalid |
| 161 | isTransitioning = false; |
| 162 | transitionProgress = 0; |
| 163 | if (particles && particles.userData) { |
| 164 | delete particles.userData.fromPositions; |
| 165 | delete particles.userData.toPositions; |
| 166 | delete particles.userData.fromColors; |
| 167 | delete particles.userData.toColors; |
| 168 | delete particles.userData.targetPattern; |
| 169 | } |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | const positions = particles.geometry.attributes.position.array; |
| 174 | const colors = particles.geometry.attributes.color.array; |
| 175 | |
| 176 | // Ensure arrays are valid before setting |
| 177 | if (positions && colors && |
| 178 | particles.userData.toPositions && particles.userData.toColors && |
| 179 | positions.length === particles.userData.toPositions.length && |
| 180 | colors.length === particles.userData.toColors.length) { |
| 181 | positions.set(particles.userData.toPositions); |
| 182 | colors.set(particles.userData.toColors); |
| 183 | particles.geometry.userData.currentColors = new Float32Array(particles.userData.toColors); // Update stored colors |
| 184 | particles.geometry.attributes.position.needsUpdate = true; |
| 185 | particles.geometry.attributes.color.needsUpdate = true; |
| 186 | currentPattern = particles.userData.targetPattern; // Update current pattern index |
| 187 | } else { |
| 188 | console.error("Transition data length mismatch or invalid data on completion!"); |
| 189 | } |
| 190 | |
| 191 | // Clean up transition data |
| 192 | delete particles.userData.fromPositions; |
| 193 | delete particles.userData.toPositions; |
| 194 | delete particles.userData.fromColors; |
| 195 | delete particles.userData.toColors; |
| 196 | delete particles.userData.targetPattern; |
| 197 | isTransitioning = false; |
| 198 | transitionProgress = 0; |
| 199 | } |
| 200 | |
| 201 | function transitionToPattern(newPattern) { |
| 202 | if (!particles || !particles.geometry || !particles.geometry.attributes.position) return; |
no outgoing calls
no test coverage detected