VIM Viewer - Outlines
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 the vim
await vim.loadAll()
// Add loaded vim to a viewer
viewer.add(vim)
viewer.camera.snap().frame(vim)
// get all bim objects with geometry
const all = [...vim.getObjects()].filter((o) => o.hasMesh)
for (let i = 0; i < all.length; i++) {
// get bim family name for object element.
const element = await all[i].getBimElement()
const name = element.familyName
// add outline to all windows.
// note that selection also uses the outline api.
if (typeof name === 'string' && name.includes('Window')) {
all[i].outline = true
}
}
}
runDemo()