Skip to content

Commit f20755b

Browse files
mariofarandaclaude
andcommitted
Mobile texture optimization: load lower-res textures on mobile devices
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b57850d commit f20755b

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

public/earth-texture-mobile.png

1.69 MB
Loading

public/ocean-mask-mobile.png

240 KB
Loading

src/App.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ function App() {
8383
const [isClosing, setIsClosing] = useState(false)
8484

8585
// Mobile Detection
86-
const [isMobile, setIsMobile] = useState(false)
86+
// Compute initial mobile state synchronously so the scene effect can use it
87+
const isMobileInitial = typeof window !== 'undefined' && (
88+
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ||
89+
(('ontouchstart' in window || navigator.maxTouchPoints > 0) && window.innerWidth <= 768)
90+
)
91+
const [isMobile, setIsMobile] = useState(isMobileInitial)
8792
const [showMobileMenu, setShowMobileMenu] = useState(false)
8893
const [isMobileMenuClosing, setIsMobileMenuClosing] = useState(false)
8994
const [isMobileMenuAnimating, setIsMobileMenuAnimating] = useState(false) // Guards hamburger button against re-trigger during close animation
@@ -532,7 +537,7 @@ function App() {
532537

533538
// Load simplified Earth texture
534539
const earthTexture = new THREE.TextureLoader().load(
535-
'/earth-texture.png',
540+
isMobile ? '/earth-texture-mobile.png' : '/earth-texture.png',
536541
() => {
537542
earthTexture.anisotropy = renderer.capabilities.getMaxAnisotropy()
538543
checkAllLoaded()
@@ -541,12 +546,12 @@ function App() {
541546
(error) => console.error('Error loading texture:', error)
542547
)
543548

544-
const oceanMaskTexture = new THREE.TextureLoader().load('/ocean-mask.png', () => {
549+
const oceanMaskTexture = new THREE.TextureLoader().load(isMobile ? '/ocean-mask-mobile.png' : '/ocean-mask.png', () => {
545550
oceanMaskTexture.anisotropy = renderer.capabilities.getMaxAnisotropy()
546551
oceanMaskTextureRef.current = oceanMaskTexture
547552
})
548553

549-
const bumpTexture = new THREE.TextureLoader().load('/earth-bump.jpg', () => {
554+
const bumpTexture = new THREE.TextureLoader().load(isMobile ? '/earth-bump-mobile.jpg' : '/earth-bump.jpg', () => {
550555
bumpTexture.anisotropy = renderer.capabilities.getMaxAnisotropy()
551556
})
552557

0 commit comments

Comments
 (0)