# 🔧 Troubleshooting Guide

Common issues and their solutions.

Last Updated: October 24, 2025

---

## 📋 Table of Contents
- [Controls Not Visible](#controls-not-visible)
- [Models Not Loading](#models-not-loading)
- [Performance Issues](#performance-issues)
- [Mobile-Specific Problems](#mobile-specific-problems)
- [Fullscreen Issues](#fullscreen-issues)
- [Material/Texture Issues](#materialtexture-issues)
- [Gallery Switching Issues](#gallery-switching-issues)

---

## 🎮 Controls Not Visible

### Issue: Model controls not showing at bottom
**Symptoms**: Bottom control bar is missing or hidden

**Possible Causes & Solutions:**

#### 1. Wrong Gallery Active
**Check**: Are you in model gallery mode?
```javascript
// In console:
document.querySelector('#model-gallery').classList.contains('active')
// Should return: true
```
**Solution**: Click the 3D model button (cube icon) in header

#### 2. CSS Display Override
**Check**: Inspect element in DevTools
```css
/* Should see: */
.threejs-controls {
    display: flex !important;
}
```
**Solution**: Check for conflicting CSS rules hiding controls

#### 3. Z-Index Issue
**Check**: Controls might be behind canvas
```javascript
// In console:
const controls = document.querySelector('.threejs-controls');
console.log(window.getComputedStyle(controls).zIndex);
// Should be: 10000 or higher
```
**Solution**: Verify z-index hierarchy in style.css

#### 4. Fullscreen Mode
**Check**: Are you in fullscreen?
**Solution**: Controls should be visible in fullscreen. If not, check:
```css
.dynamic-showcase:fullscreen .threejs-controls,
.dynamic-showcase.mobile-fullscreen .threejs-controls {
    display: flex !important;
    visibility: visible !important;
}
```

### Issue: SSR Master Control Panel not showing
**Symptoms**: Top-right panel is missing

**Solutions:**

#### 1. Check Model Gallery Active
Panel only shows in model gallery mode
```javascript
// Should be true:
document.querySelector('#model-gallery').classList.contains('active')
```

#### 2. Check Panel State
```javascript
// In console:
const panel = document.querySelector('.master-control-panel');
console.log(window.getComputedStyle(panel).opacity);
// Should be: 1
console.log(window.getComputedStyle(panel).transform);
// Should be: none or matrix(1, 0, 0, 1, 0, 0)
```

#### 3. Expand Panel
Panel might be collapsed. Click the header to expand.

### Issue: Virtual joystick not visible on mobile
**Symptoms**: Joystick missing in mobile fullscreen

**Solutions:**

#### 1. Check Mobile Fullscreen Active
```javascript
// Should be true:
document.querySelector('.dynamic-showcase').classList.contains('mobile-fullscreen')
```

#### 2. Check Positioning
```javascript
const joystick = document.querySelector('#mobile-joystick');
console.log(window.getComputedStyle(joystick).bottom);
// Should be: 250px
console.log(window.getComputedStyle(joystick).display);
// Should be: flex
```

#### 3. Check Z-Index
```javascript
console.log(window.getComputedStyle(joystick).zIndex);
// Should be: 10001 or higher
```

---

## 📦 Models Not Loading

### Issue: Model shows "Loading..." but never appears
**Symptoms**: Loading message stays, no model visible

**Solutions:**

#### 1. Check Console for Errors
Open browser console (F12) and look for:
```
❌ Failed to load model: [path]
❌ 404 Not Found
❌ CORS error
```

#### 2. Verify File Path
```javascript
// Check if file exists:
fetch('assets/models/your-model.glb')
    .then(r => console.log('File exists:', r.ok))
    .catch(e => console.error('File not found:', e))
```

#### 3. Check File Format
Supported formats:
- `.glb` (recommended)
- `.gltf`
- `.drc` (DRACO compressed)

**Not supported**: `.obj`, `.fbx`, `.blend`

#### 4. DRACO Models
If model uses DRACO compression:
```javascript
// Check DRACO loader initialized:
console.log('DRACO loader:', viewer.dracoLoader);
// Should not be undefined
```

### Issue: Model loads but is invisible
**Symptoms**: Loading completes, but nothing visible

**Solutions:**

#### 1. Check Model Position
```javascript
// In console:
console.log('Model position:', viewer.currentModel.position);
// Should be near: {x: 0, y: -0.86, z: 0}
```

#### 2. Check Camera Position
```javascript
console.log('Camera position:', viewer.camera.position);
// Should be looking at model, not away from it
```

#### 3. Frame Camera to Model
Press **F** key or click **📷 Fit** button

#### 4. Check Model Scale
```javascript
console.log('Model scale:', viewer.currentModel.scale);
// Should be: {x: 1, y: 1, z: 1} or similar
```

### Issue: Model appears black/dark
**Symptoms**: Model loads but is completely black

**Solutions:**

#### 1. Check Lighting
```javascript
// Count lights in scene:
const lights = viewer.scene.children.filter(c => c.isLight);
console.log('Lights:', lights.length);
// Should be: 2 or more
```

#### 2. Enable HDRI
Click **HDRI** button to enable environment lighting

#### 3. Check Material
```javascript
// Check if model has materials:
viewer.currentModel.traverse(child => {
    if (child.isMesh) {
        console.log('Material:', child.material);
    }
});
```

---

## ⚡ Performance Issues

### Issue: Low FPS / Choppy animation
**Symptoms**: Stuttering, slow response, low frame rate

**Solutions:**

#### 1. Check Current FPS
```javascript
// Add FPS counter:
let lastTime = performance.now();
let frames = 0;
setInterval(() => {
    const now = performance.now();
    const fps = Math.round((frames * 1000) / (now - lastTime));
    console.log('FPS:', fps);
    frames = 0;
    lastTime = now;
}, 1000);
// Then in animate loop:
frames++;
```

#### 2. Disable Heavy Effects
```javascript
// Disable SSR:
viewer.toggleSSRReflections(false);

// Disable Bloom:
viewer.toggleBloom(false);

// Disable SSAO:
viewer.toggleSSAO(false);
```

#### 3. Reduce Pixel Ratio
```javascript
viewer.renderer.setPixelRatio(1.0); // Lower quality, better performance
```

#### 4. Check for Memory Leaks
```javascript
// Check memory usage (Chrome only):
if (performance.memory) {
    console.log('Memory:', {
        used: Math.round(performance.memory.usedJSHeapSize / 1048576) + 'MB',
        total: Math.round(performance.memory.totalJSHeapSize / 1048576) + 'MB'
    });
}
```

### Issue: Memory usage keeps growing
**Symptoms**: Memory increases with each model load, eventual crash

**Solutions:**

#### 1. Check Model Disposal
Models should be disposed when switching:
```javascript
// Should see in console when switching models:
console.log('🧹 Disposing old model');
```

#### 2. Manual Cleanup
```javascript
// Force cleanup:
if (viewer.currentModel) {
    viewer.disposeModel();
}
```

#### 3. Reload Page
If memory is already high, reload the page to reset

---

## 📱 Mobile-Specific Problems

### Issue: Controls freeze after tapping
**Symptoms**: Can't rotate/pan/zoom after interaction

**Solutions:**

#### 1. Check Touch Events
```javascript
// Should see in console:
console.log('Touch start');
console.log('Touch move');
```

#### 2. Check Controls Enabled
```javascript
console.log('Controls enabled:', viewer.controls.enabled);
// Should be: true
```

#### 3. Disable Problematic Code
If `resetUIZoom()` is being called, it might cause issues:
```javascript
// This should be disabled:
// this.resetUIZoom(); // DISABLED
```

### Issue: Buttons too small to tap
**Symptoms**: Hard to press buttons on mobile

**Solutions:**

#### 1. Check Button Height
```javascript
const btn = document.querySelector('.control-btn');
console.log('Button height:', window.getComputedStyle(btn).height);
// Should be: 32px on mobile
```

#### 2. Enter Fullscreen
Mobile fullscreen mode has larger buttons

### Issue: Joystick not responding
**Symptoms**: Joystick visible but doesn't move camera

**Solutions:**

#### 1. Check Joystick Enabled
```javascript
console.log('Joystick enabled:', viewer.joystickEnabled);
// Should be: true in mobile fullscreen
```

#### 2. Check Touch Events
```javascript
// Should see when touching joystick:
console.log('Joystick touch');
```

### Issue: Page crashes after 7-8 models
**Symptoms**: Mobile browser crashes or reloads

**Solutions:**

#### 1. Memory Disposal
Ensure models are being disposed:
```javascript
// Should see when switching models:
console.log('🧹 Disposing old model');
console.log('Disposed geometries, materials, textures');
```

#### 2. Reduce Quality
Lower pixel ratio and disable effects:
```javascript
viewer.renderer.setPixelRatio(0.75);
viewer.toggleSSRReflections(false);
viewer.toggleBloom(false);
```

---

## 🖥️ Fullscreen Issues

### Issue: Fullscreen button doesn't work
**Symptoms**: Clicking maximize does nothing

**Solutions:**

#### 1. Check Browser Support
```javascript
console.log('Fullscreen supported:', document.fullscreenEnabled);
// Should be: true
```

#### 2. User Gesture Required
Fullscreen must be triggered by user action (click, tap)

#### 3. Check for Errors
```javascript
// Look for:
console.error('Fullscreen request failed');
```

### Issue: Controls disappear in fullscreen
**Symptoms**: Entering fullscreen hides controls

**Solutions:**

#### 1. Check Fullscreen Class
```javascript
// Should be true in fullscreen:
document.querySelector('.dynamic-showcase').matches(':fullscreen')
```

#### 2. Check CSS Rules
```css
/* Should exist: */
.dynamic-showcase:fullscreen .threejs-controls {
    display: flex !important;
}
```

### Issue: Exit fullscreen button not visible
**Symptoms**: Can't exit fullscreen

**Solutions:**

#### 1. Press ESC Key
ESC always exits fullscreen

#### 2. Check Button Visibility
```javascript
const exitBtn = document.querySelector('#mobile-exit-btn');
console.log('Exit button display:', window.getComputedStyle(exitBtn).display);
// Should be: block or flex
```

---

## 🎨 Material/Texture Issues

### Issue: Materials look wrong after loading
**Symptoms**: Model looks plastic, not metallic

**Solutions:**

#### 1. Check Material Preservation
Materials should preserve GLTF values:
```javascript
viewer.currentModel.traverse(child => {
    if (child.isMesh) {
        console.log('Metalness:', child.material.metalness);
        console.log('Roughness:', child.material.roughness);
    }
});
```

#### 2. Reset Material
Click **🎨 Reset** button to restore original material

### Issue: Textures not loading
**Symptoms**: Model is solid color, no textures

**Solutions:**

#### 1. Check Texture Paths
Textures must be in same folder as model or use absolute paths

#### 2. Check Console
```
❌ Failed to load texture: [path]
```

#### 3. Check CORS
Textures from external domains need CORS headers

### Issue: Floor too bright/dark
**Symptoms**: Floor doesn't match expected appearance

**Solutions:**

#### 1. Adjust Floor Opacity
Use Floor slider in SSR panel (if visible)

#### 2. Check Lighting
```javascript
// Adjust hemisphere light:
viewer.hemiLight.intensity = 1.0; // Adjust as needed
```

---

## 🔄 Gallery Switching Issues

### Issue: Crash when switching to model gallery
**Symptoms**: Page reloads or freezes when clicking model button

**Solutions:**

#### 1. Check Rendering Pause
Rendering should pause when leaving model gallery:
```javascript
// Should see in console:
console.log('🛑 Pausing Three.js rendering');
```

#### 2. Check Resume
Rendering should resume when entering model gallery:
```javascript
// Should see in console:
console.log('▶️ Resuming Three.js rendering');
```

#### 3. Clear Animation Frames
```javascript
// Should happen automatically:
if (viewer.animationFrameId) {
    cancelAnimationFrame(viewer.animationFrameId);
}
```

### Issue: Video doesn't play after switching
**Symptoms**: Video gallery shows thumbnail but won't play

**Solutions:**

#### 1. Check YouTube API
```javascript
console.log('YouTube API loaded:', typeof YT !== 'undefined');
// Should be: true
```

#### 2. Click Play Button
Some browsers require user interaction to play video

---

## 🔍 Debugging Tools

### Browser Console
**Open**: Press F12 or Ctrl+Shift+I (Cmd+Option+I on Mac)

**Useful Commands:**
```javascript
// Check viewer state:
console.log('Viewer:', viewer);

// Check current model:
console.log('Model:', viewer.currentModel);

// Check controls:
console.log('Controls:', viewer.controls);

// Check scene:
console.log('Scene children:', viewer.scene.children);

// Force render:
viewer.forceRender();

// Check FPS:
console.log('Renderer info:', viewer.renderer.info);
```

### Performance Monitor
```javascript
// Enable stats:
const stats = new Stats();
document.body.appendChild(stats.dom);

// In animate loop:
stats.update();
```

### Memory Monitor
```javascript
// Check memory (Chrome only):
setInterval(() => {
    if (performance.memory) {
        console.log('Memory:', 
            Math.round(performance.memory.usedJSHeapSize / 1048576) + 'MB'
        );
    }
}, 5000);
```

---

## 🆘 Still Having Issues?

### Check Documentation
- [CONTROLS.md](CONTROLS.md) - Controls reference
- [UI_COMPONENTS.md](UI_COMPONENTS.md) - UI components
- [PERFORMANCE.md](PERFORMANCE.md) - Performance tips
- [MOBILE_UI_FIXES_SESSION.md](MOBILE_UI_FIXES_SESSION.md) - Mobile fixes

### Check Console
Always check browser console (F12) for error messages

### Clear Cache
Try hard refresh: Ctrl+F5 (Cmd+Shift+R on Mac)

### Test in Different Browser
Try Chrome, Firefox, or Edge to isolate browser-specific issues

### Check Network
Slow network can cause loading issues. Check DevTools Network tab.

---

<p align="center">
  <strong>Most Issues Have Simple Solutions</strong><br>
  <sub>Check console first, then docs</sub>
</p>
