| 2838 | } |
| 2839 | |
| 2840 | applyConnectionColors(group, sourceValues) { |
| 2841 | const contributions = new Float32Array(group.connections.length); |
| 2842 | let maxContribution = 0; |
| 2843 | group.connections.forEach((connection, index) => { |
| 2844 | const activation = sourceValues[connection.sourceIndex] ?? 0; |
| 2845 | const contribution = activation * connection.weight; |
| 2846 | contributions[index] = contribution; |
| 2847 | const magnitude = Math.abs(contribution); |
| 2848 | if (magnitude > maxContribution) maxContribution = magnitude; |
| 2849 | }); |
| 2850 | const scale = maxContribution > 1e-6 ? maxContribution : group.maxAbsWeight || 1; |
| 2851 | group.connections.forEach((connection, index) => { |
| 2852 | const normalized = clamp(contributions[index] / scale, -1, 1); |
| 2853 | const magnitude = Math.abs(normalized); |
| 2854 | if (magnitude < 1e-3) { |
| 2855 | this.tempColor.setRGB(0, 0, 0); |
| 2856 | } else if (normalized >= 0) { |
| 2857 | this.tempColor.setRGB(0, magnitude, 0); |
| 2858 | } else { |
| 2859 | this.tempColor.setRGB(magnitude, 0, 0); |
| 2860 | } |
| 2861 | group.mesh.setColorAt(index, this.tempColor); |
| 2862 | }); |
| 2863 | group.mesh.instanceColor.needsUpdate = true; |
| 2864 | } |
| 2865 | |
| 2866 | handleResize() { |
| 2867 | const width = window.innerWidth; |