|
202 | 202 | } |
203 | 203 |
|
204 | 204 | /** |
205 | | - * Creates a new ball mesh with an attached face. |
| 205 | + * Creates a glowing outline mesh for a given object. |
| 206 | + * @param {THREE.Mesh} targetMesh The mesh to create the glow for. |
| 207 | + * @param {string} glowColor The hex color for the glow. |
| 208 | + * @returns {THREE.Mesh} The glowing mesh. |
| 209 | + */ |
| 210 | + function createGlowMesh(targetMesh, glowColor) { |
| 211 | + // Create a duplicate of the ball's geometry |
| 212 | + const glowGeometry = targetMesh.geometry.clone(); |
| 213 | + |
| 214 | + // Create a glowing material |
| 215 | + const glowMaterial = new THREE.MeshBasicMaterial({ |
| 216 | + color: new THREE.Color(glowColor), |
| 217 | + side: THREE.BackSide, |
| 218 | + blending: THREE.AdditiveBlending, |
| 219 | + transparent: true, |
| 220 | + opacity: 0.8 |
| 221 | + }); |
| 222 | + |
| 223 | + // Create the glowing mesh |
| 224 | + const glowMesh = new THREE.Mesh(glowGeometry, glowMaterial); |
| 225 | + |
| 226 | + // Scale it up slightly to create the outline effect |
| 227 | + const scale = 1.1; // 10% larger than the original mesh |
| 228 | + glowMesh.scale.set(scale, scale, scale); |
| 229 | + |
| 230 | + // We need to add this to the scene separately so it is rendered after the player's main mesh |
| 231 | + scene.add(glowMesh); |
| 232 | + |
| 233 | + return glowMesh; |
| 234 | + } |
| 235 | + |
| 236 | + /** |
| 237 | + * Creates a new ball mesh with an attached face and a glowing outline. |
206 | 238 | * @param {number} radius The radius of the ball. |
207 | 239 | * @param {string} color The hex color for the ball material. |
208 | 240 | * @returns {THREE.Mesh} The new mesh object. |
|
237 | 269 | // Add the face to the ball mesh as a child |
238 | 270 | ballMesh.add(facePlane); |
239 | 271 |
|
| 272 | + // Add a glowing outline to the ball mesh |
| 273 | + const glowMesh = createGlowMesh(ballMesh, color); |
| 274 | + ballMesh.add(glowMesh); |
| 275 | + |
240 | 276 | return ballMesh; |
241 | 277 | } |
242 | 278 |
|
|
0 commit comments