Jump to content

Test: Difference between revisions

From Survivalcraft Wiki
No edit summary
No edit summary
 
(50 intermediate revisions by 2 users not shown)
Line 4: Line 4:




<table>
{{#widget:ModelViewer
<tr>
|src=https://survivalcraft.wiki/content/Models/Moose.glb
<td>Cell 1</td>
|alt=Brown Bear
<td> Cell 2</td>
|width=270px
</tr>
|height=200px
|interactionPrompt=false
|backgroundColor=transparent
|cameraControls=true
|disableZoom=true
|cameraOrbit=220deg 75deg 4m
|ar=true
|arModes=scene-viewer quick-look webxr
|poster=https://survivalcraft.wiki/content/Models/Bear_Brown.webp}}


<tr>
{{#widget:ModelViewer
<td>Cell 3</td>
|src=https://survivalcraft.wiki/content/Models/Boat.glb
<td> Cell 4</td>
|alt=Donkey
</tr>
|width=270px
|height=200px
|interactionPrompt=false
|backgroundColor=transparent
|cameraControls=true
|disableZoom=true
|cameraOrbit=220deg 75deg 4m
|ar=true
|arModes=scene-viewer quick-look webxr
|poster=https://survivalcraft.wiki/content/Models/Bear_Brown.webp
}}


 
{{#widget:ModelViewer
 
|src=https://survivalcraft.wiki/content/Models/SoundGenerator.glb
<html>
|alt=Donkey
<head>
|width=270px
  <script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
|height=200px
  <style>
|interactionPrompt=false
    model-viewer {
|backgroundColor=transparent
      width: 100%;
|cameraControls=true
      height: 500px;
|disableZoom=true
      background-color: #eee;
|cameraOrbit=220deg 75deg 4m
    }
|ar=true
  </style>
|arModes=scene-viewer quick-look webxr
</head>
|poster=https://survivalcraft.wiki/content/Models/SoundGenerator.webp
<body>
}}
<model-viewer id="bearModel"
  src="https://survivalcraft.wiki/content/Models/Bear.glb"
  ar shadow-intensity="1" camera-controls touch-action="pan-y"
  environment-image="neutral"
  auto-rotate>
</model-viewer>
 
<script type="module">
const modelViewer = document.querySelector('#bearModel');
 
modelViewer.addEventListener('load', async () => {
  try {
    console.log('Model loaded, attempting to change texture...');
   
    // Method 1: Try to access Three.js scene directly
    const scene = modelViewer.model.scene || modelViewer.model;
   
    if (scene) {
      scene.traverse((child) => {
        if (child.isMesh && child.material) {
          console.log('Found mesh with material:', child.name);
         
          // Create a new texture loader
          const loader = new Image();
          loader.crossOrigin = 'anonymous';
          loader.onload = () => {
            // Create canvas to convert image to texture
            const canvas = document.createElement('canvas');
            const ctx = canvas.getContext('2d');
            canvas.width = loader.width;
            canvas.height = loader.height;
            ctx.drawImage(loader, 0, 0);
           
            // Apply to material
            if (Array.isArray(child.material)) {
              child.material.forEach(mat => {
                if (mat.map) {
                  mat.map.image = canvas;
                  mat.map.needsUpdate = true;
                }
                mat.needsUpdate = true;
              });
            } else {
              if (child.material.map) {
                child.material.map.image = canvas;
                child.material.map.needsUpdate = true;
              }
              child.material.needsUpdate = true;
            }
           
            modelViewer.requestUpdate();
            console.log('Texture updated successfully');
          };
          loader.src = 'https://survivalcraft.wiki/content/Textures/Creatures/Bear_Brown.png';
        }
      });
    }
   
    // Method 2: Try model-viewer's material system
    const materials = modelViewer.model.materials;
    console.log('Found materials:', materials ? materials.map(m => m.name) : 'none');
   
  } catch (error) {
    console.error('Error updating texture:', error);
  }
});
 
</script>
</body>
</html>

Latest revision as of 18:47, 31 July 2025