Hi All,
I am trying to put the babylon viewer inside a custom html element. I can’t seem to get it working. Here is my attempt: https://codepen.io/brianteheng/pen/BaWxXxJ
Any insight would be helpful!
Thank you,
-Brian
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Shadow Element</title>
<script src="js/shadow_babylon.js" defer></script>
</head>
<body>
<h1>Shadow Component</h1>
<div>
<my-comp></my-comp>
</div>
</body>
</html>
````Preformatted text`
shadow_babylon.js:
class CustomElement extends HTMLElement {
constructor() {
super();
// Create a shadow root
const shadow = this.attachShadow({ mode: 'open' });
const script = document.createElement('script');
script.src = "https://cdn.babylonjs.com/viewer/babylon.viewer.js";
script.onload = function () {
console.log("Script loaded and ready");
};
shadow.appendChild(script);
const babylon = document.createElement('babylon');
babylon.setAttribute('model', "https://models.babylonjs.com/boombox.glb");
babylon.setAttribute("id", "babylon-viewer");
shadow.appendChild(babylon);
}
}
customElements.define('my-comp', CustomElement);