Importing raw .OBJ string data with ImportMesh

So it seems to have imported the mesh into the scene successfully, but I can’t see the mesh in the scene for some reason. This is using the method you provided, and I did in fact use the blob() method on the fetched data beforehand.

@brianzinn I have not base64 encoded it although the Babylon ImportMesh loader is telling me the import was successful.

Use the Inspector - or look at scene meshes directly - they may be out of scale?
The Inspector | Babylon.js Documentation (babylonjs.com)

Change your log to: console.log('success', newAssetMeshes) to see what was imported.

If you open the babylonjs inspector, is the mesh listed under nodes? If so, could it just be positioned off screen somewhere, or scaled too small, behind something else etc? Basically as @brianzinn suggested above.

@brianzinn @sable I was trying to scale the assets manually. From the console.log I am in fact getting information from the mesh being imported, but it’s nowhere to be found and I’m not too sure about the scale of the object as well.

I’m going to take a break on this now but I think the import problem has been solved for now. I really appreciate all of the help, so thank ya all!

2 Likes

The inspector will help you find the object. You can see (and edit) the position/scale of the mesh. Very helpful for debugging.

For some reason my project won’t allow the debugger to open lol I think it’s missing an DOM element to map too

@brianzinn @sable

Hey guys, hope y’all had a good weekend!
I made use of the debugger! Here’s the code and a screen shot of the imported asset in the debugger:

    this.assetsService.getAssetQuixelEntirety(assetId)
      .then((info) => {
        info.blob().then((b) => {
          const url = URL.createObjectURL(b);
          console.log(url);
          BAB.SceneLoader.ImportMesh('', url, '', this.scene,
            (newAssetMeshes, _, __, animationGroup) => {
              console.log('success');
            }, null, null, '.obj');
        });
      });

It seems to be importing a Node of some sort but not the actual mesh, I’m not sure what this means but I’m definitely doing something wrong.

Do you get the same result with any obj?

It’s an obj blob from Quixel, it’s the same for each one

It does look like a node instead of a mesh, because otherwise you would see faces/vertices listed.

I worked a bit on the .obj loader some time ago, but I have never seen createObjectURL used that way and the only way I know is base64 encoding. Having said that, I don’t think you should be sending or receiving the obj model in a binary format - I don’t see that as being necessary. So, I think it should be:

info.text().then(text => {
   SceneLoader.ImportMesh('', `data:${text}`, '', this.scene,
        (newAssetMeshes, _, __, animationGroup) => {
          console.log('success');
        }, null, null, '.obj');
    });
});

@brianzinn
That method works fine, as shown in the pg further up (https://playground.babylonjs.com/#V98D08#2), so I think something else is going on here, though your method works too.
@FullSiliconAlchemist Does the obj load fine if imported normally (i.e. just loading it directly from a server, or drag and drop into the sandbox)?

edit:
Using the text version seems massively slower however (though can’t think why that should be) https://playground.babylonjs.com/#V98D08#3

1 Like

@brianzinn @sable I’ve just noticed that the file I’m importing does not resemble the format from the .obj bunny in the examples as seen here:

Image 1 (Quixel)
image

Image 2 (Babylon bunny)
image

I’m going to review Quixel’s API to see what the format is, although I’m certain they mentioned it was OBJ.

1 Like

The obj file importer will validate vertex lines with a regex. It looks like your “v” is at the end, while it needs to be v followed by the 3 points (maybe you are doing your own newline parsing?):
Babylon.js/solidParser.ts at master · BabylonJS/Babylon.js (github.com)

Also, that may explain why your model has zero vertices…