Issue with HtmlMesh in Babylon.js - HTML Content Not Displaying Properly

Hello Babylon.js Community!

I’m working on a project where I would like to render HTML content inside my 3D scene using the HtmlMesh addon, but I’m running into some issues that I can’t seem to understand the root of. Here’s what I’ve implemented so far:

import * as BABYLON from 'babylonjs'
import {
  HtmlMeshRenderer, HtmlMesh
} from "@babylonjs/addons/htmlMesh";

// ... other code ...

const htmlMeshRenderer = new HtmlMeshRenderer(scene);
const htmlMeshDiv = new HtmlMesh(scene, "div");

const div = document.createElement('div');
div.innerHTML = `
      <h1>Yo yo yo!!!</h1>
      <p>This is a sample HTML mesh.</p>
      <button>Click me</button>
`

div.style.backgroundColor = "purple";
div.style.width = '100%';
div.style.height = '100%';
div.style.textAlign = 'center';
div.style.fontSize = '100px';

htmlMeshDiv.setContent(div, 4, 4);

htmlMeshDiv.position.x = 0;
htmlMeshDiv.position.y = 2;

My Issues:

  1. The HTML content (purple div) doesn’t seem to be rendering properly in my scene
  2. I’m not seeing any errors in the console, but the HTML content is not visible
  3. I’ve confirmed the rest of my scene is rendering correctly (ground, camera, lights)

Questions:

  1. Is there something obvious I’m missing in my HtmlMesh implementation?
  2. Do I have to add text content to the div for it to be visible?
  3. Are there any specific requirements for the HtmlMeshRenderer that I might have overlooked?
  4. Should I be using a different approach to render HTML content in my Babylon.js scene?
  5. Are there any known issues with HtmlMesh in the current version of Babylon.js?

Environment:

  • Using Babylon.js with TypeScript
  • Importing HtmlMesh from “@babylonjs/addons/htmlMesh”

Any help or guidance would be greatly appreciated! I’ve attached the github link to my current implementation above for reference.

Thank you for the future help! :slight_smile:

So, my first suspect would be the babylon context. You are using the UMD package (babylonjs) with the es6 version of the HtmlMesh. Can you try using the @babylonjs/core package instead of the UMD package?
And let’s take it from there :slight_smile:

1 Like

Hi RaananW,

Thank you for your suggestion! I’ve implemented your recommendation by switching from the UMD package to @babylonjs/core, but I’m still experiencing the same issue with the HTML content not rendering in my scene.

Here’s what I’ve updated in my code:

// Changed from
// import * as BABYLON from 'babylonjs'
// to
import * as BABYLON from '@babylonjs/core'
import {
  HtmlMeshRenderer, HtmlMesh
} from "@babylonjs/addons/htmlMesh";

I’ve pushed these changes to my GitHub repository, but the HTML mesh, though it is in the scene does not render any of the test html I defined. I’ve verified that:

  1. The scene itself renders correctly (ground, vertical plane for html, camera, lights)
  2. No errors appear in the console related to the html Mesh
  3. The HtmlMeshRenderer and HtmlMesh are being instantiated without errors

I’m wondering if:

  1. There are specific initialization steps for HtmlMeshRenderer that I’m missing
  2. The HTML content needs special handling to be visible in the scene
  3. There might be a version compatibility issue between @babylonjs/core and @babylonjs/addons

I am at a loss here; any further guidance would be greatly appreciated!

Hi ZedroPappa! I just pulled your repo (commit 3c2d6cc) and executed following steps:

  1. npm install
  2. npm run dev / npm run preview

Both development and production builds work on Chrome and Safari.

Sometimes browsers cache a previous build. You can try launching your app on a different port, for example, with the command: npm run dev -- --port 5001.

2 Likes

It works indeed! Thank you for the helpfull feedback!

I was opening the app on Chrome and it didn’t render the HTML inside the plane properly. Once I read your message, I tried with Firefox and to my surprise, it worked just like your screenshot.

I wonder what could be causing this incompatibility with Chrome. Any clues?

Try to clear Chrome cache