VIM Viewer - Custom request

by simon_vimaec

HTML

<script src="https://unpkg.com/vim-webgl-viewer@2.0.2"></script>

CSS

/* Makes full screen and remove scrollbars */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  touch-action: none; /* This prevents touches from being eaten up by the browser. */
}

JavaScript

async function runDemo() {

	// Create a viewer.
  const viewer = new VIM.Viewer()

// Make a standard hmlhttp request
  const xhr = new XMLHttpRequest()
  // Specify response type ArrayBuffer
  xhr.responseType = 'arraybuffer'
  xhr.open('GET', 'https://vim02.azureedge.net/samples/residence.v1.2.75.vim')
  xhr.send()
	xhr.onprogress = (e) => console.log(`Downloading Vim (${(e.loaded / 1000).toFixed(0)} kb)`)
	
  xhr.onload = async () => {
		// Load vim from ArrayBuffer 
		const vim = await VIM.open(xhr.response, {
      rotation: new VIM.THREE.Vector3(270, 0, 0)
    })

		// Load all geometry from the vim.
    vim.loadAll()
    
    // Add vim to the viewer
    viewer.add(vim)

		// Frame Immediately.
		viewer.camera.snap().frame(vim)
  }
}

runDemo()