Advertisement
Guest User

Untitled

a guest
Jul 11th, 2022
1,456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.14 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <meta name="viewport" content="width=device=width, initial-scale=1.0">
  6.   <title>Founder Series</title>
  7.   <script type="module" src="https://unpkg.com/@google/[email protected]/dist/model-viewer.min.js"></script><!---->
  8.  
  9.   <style>
  10.     model-viewer{
  11.       width: 90%;
  12.       height: 512px;
  13.       margin: 0 auto;
  14.       padding: 10;
  15.     }
  16.   </style>
  17. </head>
  18. <body>
  19.   <select class="controls" ,="" id="color-controls" onchange="updateCol();" >
  20.     <option value="https://01000001khan.github.io/AR-Speakers/assets/textures/founder/blackWalnut.jpg">Black Walnut</option>
  21.     <option value="https://01000001khan.github.io/AR-Speakers/assets/textures/founder/darkCherry.jpg">Dark Cherry</option>
  22.     <option value="https://01000001khan.github.io/AR-Speakers/assets/textures/founder/walnut.jpg" selected="selected">Walnut</option>
  23.     <option value="https://01000001khan.github.io/AR-Speakers/assets/textures/founder/pianoBlack.jpg">Piano Black</option>
  24.     <option value="https://01000001khan.github.io/AR-Speakers/assets/textures/UV.jpg">Non-existent Testing Material</option>
  25.   </select>
  26.  
  27.  
  28.   <p>Founder 120H</p>
  29.   <model-viewer id="speaker" ar ar-modes="webxr scene-viewer quick-look" camera-controls auto-rotate src="https://01000001khan.github.io/AR-Speakers/assets/models/founder/founder120h.glb" onload="updateCol();">
  30.     <button slot="ar-button" style="background-color: white; border-radius: 4px; border: none; position: absolute; bottom: 16px; right: 16px; ">View in AR</button>
  31.   </model-viewer>
  32.   <br>
  33.    
  34.  
  35.  
  36.   <script>
  37.  
  38.     //called on change in colour selection list
  39.     function updateCol(){
  40.      
  41.       let speakers = document.querySelectorAll("#speaker")
  42.  
  43.       speakers.forEach(function(speaker){
  44.         const material = speaker.model.materials[0];
  45.  
  46.        
  47.         //Get current text value (name) of selected option
  48.         var e = document.getElementById("color-controls");
  49.         var finishName = e.options[e.selectedIndex].text;
  50.        
  51.         material.pbrMetallicRoughness['baseColorTexture'].texture.source.setURI(e.value);
  52.  
  53.         if (finishName === "Black Walnut"){
  54.           material.pbrMetallicRoughness.setRoughnessFactor(0.8);
  55.           material.pbrMetallicRoughness.setMetallicFactor(1.0);
  56.         }
  57.         else if (finishName === "Dark Cherry"){
  58.           material.pbrMetallicRoughness.setRoughnessFactor(0.0);
  59.           material.pbrMetallicRoughness.setMetallicFactor(0.0);
  60.         }
  61.         else if (finishName === "Walnut")
  62.         {
  63.           material.pbrMetallicRoughness.setRoughnessFactor(0.8);
  64.           material.pbrMetallicRoughness.setMetallicFactor(0.1);
  65.         }
  66.         else if (finishName === "Piano Black")
  67.         {
  68.           material.pbrMetallicRoughness.setRoughnessFactor(0.0);
  69.           material.pbrMetallicRoughness.setMetallicFactor(1.0);
  70.         }
  71.         else if (finishName === "Non-existent Testing Material")
  72.         {
  73.           material.pbrMetallicRoughness.setRoughnessFactor(0.5);
  74.           material.pbrMetallicRoughness.setMetallicFactor(1.0);
  75.         }      
  76.       });
  77.     }
  78.  
  79.   </script>
  80.  
  81. </body>
  82. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement