Jump to content

Test: Difference between revisions

From Survivalcraft Wiki
No edit summary
No edit summary
Line 69: Line 69:


modelViewer.addEventListener('load', async () => {
modelViewer.addEventListener('load', async () => {
  // Get all materials
   const materials = modelViewer.model.materials;
   const materials = modelViewer.model.materials;


   // For demonstration, apply to the first material
   console.log('Found materials:', materials.map(m => m.name)); // debug
  const material = materials[0];


   // Create Image object
  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/Creatures/Bear_Brown.png';
   texture.src = 'https://survivalcraft.wiki/content/Textures/Bear_diffuse.png';
   await texture.decode(); // wait until loaded
   await texture.decode();


   // Assign as baseColorTexture
   // Use the setTexture method:
   material.pbrMetallicRoughness.setBaseColorTexture(texture);
  // 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>

Revision as of 17:34, 28 July 2025


Cell 1 Cell 2
Cell 3 Cell 4