How to embed external meshes in code (es. .stl)

Hi there,
my application is a little bit atipical. I’m developing a 3D scene embedded in Chromium browser inside our application. So, we can’t (we/they don’t want :slight_smile: ) use an http server to serve the 3D scene and all the resources are accessed only from file system: CORS violation! :rage:
So i use all images for textures and even for environment as base64 strings hardcoded in my js files.
All work fine, CORS is respected and the application can run as aspected.

The question is: if i need in future (and i think i really need) to import some external meshes (i.e. .stl file or .obj) can i use a similar technique? Is there a way to embed this meshes directly inside my .js file and then use them like i did with base64 images?

Thanks :wink:

That should work, see this thread: Loading base64 data

Basically, you can convert your base64 to blob then create a url from it with URL.createObjectURL that you can use to load the asset.

2 Likes

Thank you, i’ll give a try :wink:

It works! i was struggling with async/await for base64 to blob conversion, but in the end all works like a charm! thank you :wink:

This is my PG: https://playground.babylonjs.com/#HBRF92#8

2 Likes