Jump to content

Load glb model into scene directly from content string.


yatao-wf
 Share

Recommended Posts

I'm pretty new for babylon framework and I'm trying to load glb model without a public url for security reason. So I tried to load it directly from content string, but it didn't work for some reason and I have no idea why unfortunately.

I've shared my playground here:

https://playground.babylonjs.com/#7F6S08

I tried  both `raw_content`  and `base64_model_content`  and none if it worked.

 

Would appreciate anyone can help here.

2ftx4ft.glb

Link to comment
Share on other sites

  • 3 weeks later...

This is a case that the code doesn't handle. I've filed an issue: https://github.com/BabylonJS/Babylon.js/issues/5579

In the meantime, you can do this a bit indirectly by using a blob with an object url.

https://playground.babylonjs.com/#7F6S08#2

Note that your base64 encoded string was incorrect compared to the file you attached. I had to re-encoded the data.

Link to comment
Share on other sites

  • 1 year later...
  • 2 months later...

@bghgary thank you very much for this solution! 

@Vorpal To convert the model, read it as a generic attachment and convert it to base64. You can use Buffer class method to convert it from and to base64 format:

// converts from Blob (of File) class to base 64
Buffer.from(content).toString('base64')

// converts from base64 string to Buffer (you can use it as argument of Blob constructor)
Buffer.from(base64, 'base64')

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...