@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react';
22import PropTypes from 'prop-types' ;
33import * as THREE from 'three' ;
44
5- const Starfield = ( { onSkyboxLoaded = ( ) => { } , uiVisible = false } ) => {
5+ const Starfield = ( { onSkyboxLoaded = ( ) => { } , uiVisible = false , disableScrollMotion = false } ) => {
66 // Three.js scene references
77 const mountRef = useRef ( null ) ;
88 const sceneRef = useRef ( null ) ;
@@ -318,7 +318,9 @@ const Starfield = ({ onSkyboxLoaded = () => { }, uiVisible = false }) => {
318318
319319 // Add event listeners
320320 window . addEventListener ( 'resize' , handleResize ) ;
321- window . addEventListener ( 'scroll' , handleScroll , { passive : true } ) ;
321+ if ( ! disableScrollMotion ) {
322+ window . addEventListener ( 'scroll' , handleScroll , { passive : true } ) ;
323+ }
322324 document . addEventListener ( 'visibilitychange' , handleVisibilityChange ) ;
323325
324326 // Initialize scroll tracking
@@ -332,7 +334,9 @@ const Starfield = ({ onSkyboxLoaded = () => { }, uiVisible = false }) => {
332334 // Cleanup function
333335 return ( ) => {
334336 window . removeEventListener ( 'resize' , handleResize ) ;
335- window . removeEventListener ( 'scroll' , handleScroll ) ;
337+ if ( ! disableScrollMotion ) {
338+ window . removeEventListener ( 'scroll' , handleScroll ) ;
339+ }
336340 document . removeEventListener ( 'visibilitychange' , handleVisibilityChange ) ;
337341 cancelAnimationFrame ( animationFrameRef . current ) ;
338342
@@ -382,8 +386,13 @@ const Starfield = ({ onSkyboxLoaded = () => { }, uiVisible = false }) => {
382386 scrollVelocityRef . current *= ANIMATION_CONFIG . velocityDecay ;
383387
384388 // Convert scroll velocity to speed multiplier (restore original values)
385- const velocityFactor = Math . min ( scrollVelocityRef . current / ANIMATION_CONFIG . maxVelocity , 1.0 ) ;
386- const scrollAmplification = 2.5 + velocityFactor * 40 ;
389+ let velocityFactor = 0 ;
390+ let scrollAmplification = 2.5 ;
391+
392+ if ( ! disableScrollMotion ) {
393+ velocityFactor = Math . min ( scrollVelocityRef . current / ANIMATION_CONFIG . maxVelocity , 1.0 ) ;
394+ scrollAmplification = 2.5 + velocityFactor * 40 ;
395+ }
387396
388397 starLayersRef . current . forEach ( ( starLayer ) => {
389398 if ( starLayer && starLayer . userData ) {
@@ -398,7 +407,7 @@ const Starfield = ({ onSkyboxLoaded = () => { }, uiVisible = false }) => {
398407 // Only animate star movement if animation is enabled
399408 if ( starsAnimatingRef . current && starLayer . material . opacity > 0 ) {
400409 // Flying through space motion - stars move toward camera (restore original speed)
401- const baseFlightSpeed = 0.5 ;
410+ const baseFlightSpeed = 0.7 ;
402411 const flightSpeed = baseFlightSpeed * scrollAmplification ;
403412
404413 // Update star positions
@@ -455,7 +464,7 @@ const Starfield = ({ onSkyboxLoaded = () => { }, uiVisible = false }) => {
455464
456465 // Return cleanup function
457466 return cleanup ;
458- } , [ ] ) ; // Empty dependency array - only run once
467+ } , [ disableScrollMotion ] ) ; // Include disableScrollMotion dependency
459468
460469 return (
461470 < div
@@ -476,7 +485,8 @@ const Starfield = ({ onSkyboxLoaded = () => { }, uiVisible = false }) => {
476485// PropTypes validation
477486Starfield . propTypes = {
478487 onSkyboxLoaded : PropTypes . func ,
479- uiVisible : PropTypes . bool
488+ uiVisible : PropTypes . bool ,
489+ disableScrollMotion : PropTypes . bool
480490} ;
481491
482492export default Starfield ;
0 commit comments