VIM Viewer - Visibility

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 new viewer 
  const viewer = new VIM.Viewer()

	// Open the vim file
  const vim = await VIM.open(
    "https://vim02.azureedge.net/samples/residence.v1.2.75.vim",
    {
        rotation: new VIM.THREE.Vector3(270, 0, 0),
    },
		(p) => console.log(`Downloading Vim (${(p.loaded / 1000).toFixed(0)} kb)`)
	)
  
	// Load all geometry from vim
	await vim.loadAll()

	// Add vim to viewer
  viewer.add(vim)

	// Immediately frame camera on vim
	viewer.camera.snap().frame(vim)

  // get all bim objects with geometry
  const all = [...vim.getObjects()].filter((o) => o.hasMesh)
  
  // get radius from each object bounding box
  const radius = all.map(
    (o) => o.getBoundingBox().getBoundingSphere(new VIM.THREE.Sphere()).radius
  )
  
  // hide all small objects 
  for (let i = 0; i < all.length; i++) {
    all[i].visible = radius[i] > 15
  }	
}

runDemo()