Babylon viewer customized template?

i was trying to customoize the viewer template when use @babylonjs/viewer, I’m trying to do it with js instead Html arrtrubutes, however, not work, any pros helps me,plz!~
here is my code:

import * as BabylonViewer from "@babylonjs/viewer";


const template = document.createElement("template");
template.innerHTML = `
  <div id='main'>

  </div>
 `;
class MxmThreeViewer extends HTMLElement {
  element: HTMLElement | null;
  slotNode;
  viewer;
  static get observedAttributes() {
    return ["url", "config"];
  }

  constructor() {
    super();
    const shadowRoot = this.attachShadow({ mode: "closed" });

    shadowRoot.appendChild(template.content.cloneNode(true));
    this.element = shadowRoot.querySelector("#main");
    if (this.element) {
      this.viewer = new BabylonViewer.DefaultViewer(this.element, {
        scene: {
          debug: false,
        },

        camera: {
          behaviors: {
            autoRotate: 0,
            framing:true
          },
          framing: {
            type: 2,
            zoomOnBoundingInfo: true,
            zoomStopsAnimation: false,
          },
          bouncing: {
            type: 1,
          },
        },
        model: {
          url: this.url,
        },
        templates:{
          main:{
            html:`<div>
              <viewer></viewer>
            </div>`
          },
          viewer: {
            html:`<canvas></canvas>`
          }
        }
      });
      console.log(this.viewer.templateManager.getTemplate("mxm-view"));
      
    }

    const slot = this.element?.querySelector("slot");
    if (slot) {
      this.slotNode = slot?.querySelector("div");
      slot?.addEventListener("slotchange", () => {
        const node = slot.assignedNodes()[0];
        if (node) {
          (this.slotNode as any) = node;
          this.render();
        }
      });
    }
  }

 
  get url() {
    
    const url = this.getAttribute("url");
    return url ? url : "";
  }

  set url(value: string) {

    this.setAttribute("url", value);
  }

  connectedCallback() {
    if (!this.url) {
      this.url = "http://192.168.21.133:8276/rebuild.glb";
    }
    this.render();
  }
  attributeChangedCallback(name: any, oldVal: any, newVal: any) {
    if (oldVal !== newVal) {
      switch(name) {
          case 'url':
              this.url = newVal;
              break;
     }
   }
  }
  render() {
    console.log("render", this.url);
  }
}

window.customElements.define("mxm-three-viewer", MxmThreeViewer);

here is the error:
Screen Shot 2022-03-29 at 4.37.57 PM

Hello!
Some kind of online reproduction with codepen or jsfiddle would be helpful for us to understand your problem better. :slight_smile:

cc @RaananW

If you could share the project (github maybe?) it would be wonderful. This way I will be able to check with you what went wrong there.
It seems like the viewer is trying to find the overlay template, though it doesn’t exist and should not exist, as you haven’t defined it.

2 Likes

Thanks Raanan, I was busy on something else before. I just update all my questions and code to github, my questions in the Readme file, see if you are free to help me.

https://github.com/mxm-web-develop/workspace/tree/babylonQuestion/src

Thanks Carolhmj, I was busy on something else before. I just update all my questions and code to github, my questions in the Readme file, see if you are free to help me.

Hey there, I tried to access it but it’s giving a 404 error

If the repo is private, that might explain why.

1 Like

yeah it was private , now its fixed,

yeah, now its opened

I am still getting 404. are you sure the URL is correct?

let’s move it all to one thread. We’ll continue there - Camera position set after loading new model