Test: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 62: | Line 62: | ||
<script> | <script> | ||
// | const modelViewer = document.getElementById('bearModel'); | ||
const loadingStatus = document.getElementById('loadingStatus'); | |||
const controlsInfo = document.getElementById('controlsInfo'); | |||
// Define texture URLs | |||
const textures = { | |||
brown: 'https://survivalcraft.wiki/content/Textures/Creatures/Bear_Brown.png', | brown: 'https://survivalcraft.wiki/content/Textures/Creatures/Bear_Brown.png', | ||
black: 'https://survivalcraft.wiki/content/Textures/Creatures/Bear_Black.png' | black: 'https://survivalcraft.wiki/content/Textures/Creatures/Bear_Black.png' | ||
}; | }; | ||
// Track loading state | |||
modelViewer.addEventListener('load', () => { | |||
console.log('Model loaded successfully'); | |||
loadingStatus.textContent = 'Model loaded successfully!'; | |||
controlsInfo.style.display = 'block'; | |||
// Apply initial texture | |||
setTimeout(() => { | |||
changeBearTexture(); | |||
}, 100); | |||
}); | |||
modelViewer.addEventListener('error', (event) => { | |||
console.error('Model loading error:', event); | |||
loadingStatus.textContent = 'Error loading model. Check browser console.'; | |||
loadingStatus.style.color = '#d63031'; | |||
}); | |||
modelViewer.addEventListener('progress', (event) => { | |||
const progress = event.detail.totalProgress; | |||
loadingStatus.textContent = `Loading model... ${Math.round(progress * 100)}%`; | |||
}); | |||
function changeBearTexture() { | |||
const selector = document.getElementById('bearTexture'); | const selector = document.getElementById('bearTexture'); | ||
const selectedTexture = selector.value; | const selectedTexture = selector.value; | ||
console.log('Attempting to change texture to:', selectedTexture); | console.log('Attempting to change texture to:', selectedTexture); | ||
// Wait for model to be fully loaded | // Wait for model to be fully loaded | ||
if ( | if (modelViewer.loaded) { | ||
try { | try { | ||
// Try to access the model's materials | // Try to access the model's materials | ||
Line 104: | Line 129: | ||
}; | }; | ||
img.onerror = () => { | img.onerror = () => { | ||
console.error('Failed to load texture:', | console.error('Failed to load texture:', textures[selectedTexture]); | ||
}; | }; | ||
img.src = | img.src = textures[selectedTexture]; | ||
} | } | ||
}); | }); | ||
Line 116: | Line 141: | ||
console.log('Model not yet loaded, will apply texture after load'); | console.log('Model not yet loaded, will apply texture after load'); | ||
} | } | ||
} | } | ||
// Debug: Log when everything is ready | |||
document.addEventListener('DOMContentLoaded', () => { | |||
console.log('DOM loaded, model-viewer should initialize'); | |||
console.log(' | |||
// Check if model-viewer is defined | // Check if model-viewer is defined | ||
if (typeof customElements.get('model-viewer') === 'undefined') { | if (typeof customElements.get('model-viewer') === 'undefined') { | ||
console.error('model-viewer component not loaded'); | console.error('model-viewer component not loaded'); | ||
loadingStatus.textContent = 'Error: model-viewer component failed to load'; | |||
loadingStatus.style.color = '#d63031'; | |||
} | } | ||
} | }); | ||
</script> | </script> | ||
</html> | </html> |