<? include_once 'auth.php'; ?>
<html>
  <head>
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=no" />
    
  </head>
  <body style="margin: 0 auto; ">
      
    <div id="MyViewerDiv" style = "height:100%; width=100%; position:relative;"></div>
    

    <!-- The Viewer JS -->
    <link rel="stylesheet" href="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/style.min.css" type="text/css">
    <script src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.min.js"></script>

    <!-- Developer JS -->
    <script>
    window.scrollTo(0,1);
      var viewer;
      var options = {
        env: 'AutodeskProduction',
        accessToken: <? echo "'". json_decode($data,true)[access_token] . "'" ?>
      };

      var documentId = 'urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ajdrYTltZG4wb3JxbnVmemY3YTJ1cGs3aXZqam0zaWRfdHV0b3JpYWxfYnVja2V0L1RJVEFOJTIwVjIuMC5ud2M=';
      Autodesk.Viewing.Initializer(options, onInitialized);

      function onInitialized() {
          var htmlElement = document.getElementById('MyViewerDiv');
        viewer = new Autodesk.Viewing.GuiViewer3D(htmlElement);	
        
        Autodesk.Viewing.Document.load(documentId, onDocumentLoaded);
        
      }


function onDocumentLoaded(doc) {
var geometries = doc.getRoot().search({'type':'geometry'});
var initGeom = geometries[0];
var svfUrl = doc.getViewablePath(initGeom);

viewer.start(svfUrl, {ids:[2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 ,81 ,82,83]}, onLoadModelSuccess, onLoadModelError);

}


function onLoadModelSuccess(model) {
    //console.log('loaded');
    viewer.loadSpinner.style.display = "none"
    
    viewer.addEventListener(Autodesk.Viewing.EXTENSION_LOADED_EVENT, function( event ) {
        // remove toolbar
        viewer.toolbar.setVisible(false);
        if(event.extensionId == "Autodesk.BimWalk"){
            
    
    //apply bim walk 
    
    
    //full secren 
    //viewer.loadExtension('Autodesk.FullScreen');
    //viewer.getExtension('Autodesk.FullScreen').activate();
    
    //set view
    //viewer.setViewFromArray([32.88218720911618, 55.742152427803816, 4.057462146799779, 24.617119873608203, 56.74246493363141, 3.8003855858942828, 0, 0, 1, 1.5962059620596205, 1.3089969389957472, 1, 0]);
    //viewer.setLightPreset(15);
    // viewer.impl.toggleEnvMapBackground(true);
    
    
    //change profile 
    viewer.profile.settings.ambientShadows = false;
    viewer.profile.settings.lightPreset = 11;
    viewer.profile.settings.bimWalkToolPopup = false;
    viewer.setProfile(viewer.profile);
    viewer.setGhosting(false);
   //viewer.getExtension('Autodesk.BimWalk').activate();
    
        }
        //set fov to 75 
     //viewer.setFOV(75);
    }
    
        );
 
 
 viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function( event ) {
    
        viewer.hide(80);
    });

    
        
        
        

    
}

function onLoadModelError(viewerErrorCode) {
            console.error('onLoadModelError() - errorCode:' + viewerErrorCode);
        }

    </script>

  </body>
</html>