Hello everyone!
I’m a web developer with limited experience in 3D Asset making. I was designing a 3D Asset Library and I am using BabylonJs to do so. It’s an amazing library. But I ran into many problems, and finally into this one that I need the community’s help with.
I am using BabylonJs Viewer:
<script src="https://cdn.babylonjs.com/viewer/babylon.viewer.js"></script>
I am fetching a .gltf file from a backend nodejs server to then display the file in the viewer on the client’s browser.
In frontend, on HTML side. I’m doing:
<babylon id="babylon-viewer">
<model id="gltf-model" url="${gltf}"></model>
</babylon>
But I’m doing this dynamically through Javascript:
// Disable auto init
BabylonViewer.disableInit = true;
// Fetch file from URL
fetch(url)
.then(response => {
// Convert Json file to String
gltf = "data:" + JSON.stringify(response.data);
}).then( () => {
// init now
BabylonViewer.InitTags('babylon');
})
But the Viewer on HTML side is showing an error saying “Error loading the model”.
And in developer console it’s showing the error:
I tested the file with glTF-Validator, and it shows me that the file is valid with no errors:
{
"uri": "[File Name].gltf",
"mimeType": "model/gltf+json",
"validatorVersion": "2.0.0-dev.3.4",
"validatedAt": "2021-12-10T19:20:49.493Z",
"issues": {
"numErrors": 0,
"numWarnings": 0,
"numInfos": 2,
"numHints": 0,
"messages": [
{
"code": "NODE_EMPTY",
"message": "Empty node encountered.",
"severity": 2,
"pointer": "/nodes/1"
},
{
"code": "NODE_EMPTY",
"message": "Empty node encountered.",
"severity": 2,
"pointer": "/nodes/3"
}
],
"truncated": false
},
"info": {
"version": "2.0",
"generator": "VoxEdit Beta e2de1723",
{
"pointer": "/buffers/0",
"mimeType": "application/gltf-buffer",
"storage": "data-uri",
"byteLength": 1296
},
...
After doing research on gltf, I understand that my file is a gltf (embedded) file. I converted my files using CesiumGS/gltf-pipeline to convert my embedded gltf file to glb and Draco gltf but I was still getting “Unable to import meshes from data:” error.
However if I send the gltf files as a folder to the client when they visit the website, and then do this instead:
<babylon id="babylon-viewer">
<model id="gltf-model" url="assets/model.gltf"></model>
</babylon>
Then the same gltf file generates the scene correctly. But I can’t do this as there are going to be 1000’s of gltf files in the library.
Could someone point me in the right direction where to go from here? I’m unable to solve this issue as the file seems correct, I don’t know which step I am missing. This is a bit new for me.
Thank you for any replies, I appreciate the time any of you took to help me!