Test: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 69: | Line 69: | ||
modelViewer.addEventListener('load', async () => { | modelViewer.addEventListener('load', async () => { | ||
const materials = modelViewer.model.materials; | const materials = modelViewer.model.materials; | ||
console.log('Found materials:', materials.map(m => m.name)); // debug | |||
// Create | const material = materials[0]; // or find by name if you know it | ||
// Create an HTMLImageElement | |||
const texture = new Image(); | const texture = new Image(); | ||
texture.src = 'https://survivalcraft.wiki/content/Textures/ | texture.src = 'https://survivalcraft.wiki/content/Textures/Bear_diffuse.png'; | ||
await texture.decode(); | await texture.decode(); | ||
// | // Use the setTexture method: | ||
material. | // first argument: name of texture slot (e.g., 'baseColorTexture') | ||
// second argument: Image or HTMLCanvasElement | |||
await material.setTexture('baseColorTexture', texture); | |||
}); | }); | ||
</script> | </script> | ||
</body> | </body> | ||
</html> | </html> |