Skip to content

Instantly share code, notes, and snippets.

@wrr wrr/body-end.html
Created Jul 4, 2019

Embed
What would you like to do?
Detect which material was selected by the user and show the material name.
<style>
#banner {
position: absolute;
top: 30px;
text-align: center;
font-size: 3em;
width: 100%;
z-index: 10;
visibility: hidden
}
</style>
<div id="banner"></div>
<script>
(function() {
var messageId = 0;
function hideBanner(bannerElement, messageIdArg) {
return function() {
// Hide the message only if it wasn't replaced with a new one.
if (messageId === messageIdArg) {
bannerElement.style.visibility = 'hidden';
}
}
}
function showMessage(message) {
var bannerElement = document.getElementById('banner');
bannerElement.textContent = message;
bannerElement.style.visibility = 'visible';
messageId += 1;
setTimeout(hideBanner(bannerElement, messageId), 4000);
}
var viewer = WALK.getViewer();
viewer.onSceneReadyToDisplay(function() {
var setMaterialForNodeOriginal = viewer.setMaterialForNode;
viewer.setMaterialForNode = function(material, node) {
setMaterialForNodeOriginal.apply(this, [material, node]);
showMessage('material: ' + material.name);
}
});
}());
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.