Issues when merging different meshes before exporting to babylon from blender

when i export meshes from blender 2.8 using the 2.8 exporter of babylon to babylon format, it works really great, all perfect.

It also works perfect when I combine say a few meshes that use the same material, all perfect.

Where I am finding a challenge is in the following case:

  • say I have a mesh, but then I also have 4 text objects and a couple of cubes. I convert all of them to meshes, and then I merge them all using the join function of blender, so they all become one mesh.

  • When I now export this one single mesh, something weird happens with the material unfortunately. It just bakes the material wrong and it all appears black in babylon.

  • I have tried to just assign the same material to all of them, but mmm still the problem happens anyway. It seems to be something about those extra text meshes, when I get rid of them it all works well.

  • If I combine a number of similar meshes I have no problems, Interestingly once in the past I did this text meshes thing and I didnt have the problem, not sure whats the issue in this specific case

if you have any tip about this issue let me know

thank you :slight_smile:

pinging @PirateJC

1 Like

@javismiles do you have the same result when exporting to a .gltf file?

What about if you use the built in exporter in Blender to .gltf. Same result?

1 Like

@PirateJC thank you, so far i have only exported to babylon format, never tried the .gltf, are there any drawbacks to doing it with .gltf? the code is the same?

Post your export log file

Good question! Yes there are differences for sure, but for the scenario you’re describing it would be a very simple and easy troubleshooting case.

The only thing I can think about is if you have multi-materials in Blender. If for some reason when you combine all of the meshes, you end up with more than 1 material, things MAY break in the export.

Try this:

  1. Try using the same exporter you’re already using, but export to .gltf instead
  2. If that’s the same result, try using the built in exporter to .gltf in the Blender exporter menu.
  3. Check that your combined mesh only does have 1 single material applied to it.

Those would be some quick next steps to troubleshoot a little further.

@PirateJC @JCPalmer
thank you very much for trying to help, so:

  • yes at the beginning i could see multiple materials but then i got rid of them and made sure that there was only 1 single material (I even assigned on purpose the very same PBR material to everything and fused joined everything and made sure there was 1 mesh and 1 material) and the problem was still happening
  • i will try gltf and report back, i gather that the loading code in babylon.js remains the same?
  • i will also post here shortly the log of the exported process that fails

@PirateJC @JCPalmer
I attach below the log of the export that produces the issues, that one is with blender 2.82 but i have also tested the same with 2.80 and same issue. The “will trigger baking” lines are for sure not the issue, as those appear always in every case and the export always works perfectly, the material is baked and voila no issues at all, so the problem must be somewhere else.

I will soon try next the export to gltf to compare.

Exporter version: 6.4.6, Blender version: 2.82 (sub 7)
========= Conversion from Blender to Babylon.js =========
Scene settings used :
Inline textures : false
Material Type : PBR
Positions Precision : 4
Normals Precision : 3
UVs Precision : 3
Vert Color Precision: 3
Mat Weight Precision: 2
Keep Z-up r-handed : no
Texture directory : C:\MEDIA\sendbabylon
Python World class constructor completed
processing begun of mesh: test-hr
processing begun of material: Material
WARNING: unsupported node type(ShaderNodeSeparateXYZ) will trigger baking
WARNING: unsupported node type(ShaderNodeMath) will trigger baking
WARNING: unsupported node type(ShaderNodeValToRGB) will trigger baking
Baking texture, type: DIFFUSE, mapped using: UVMap
processing texture test_hr_baked_DIFFUSE
texture type: diffuseTexture, mapped using: “UVMap”
bake time: 0 min, 0.7314 secs
num positions : 349874
num normals : 349874
num tangents : 0
num uvs : 699748
num uvs2 : 0
num colors : 0
num triangles : 117563
processing begun of camera (UniversalCamera): Camera
animation processing begun
processing action CameraAction.001: in[0 - 533], out[0 - 533]
processing begun of light (POINT): Light
processing begun of light (POINT): Light.001
processing begun of light (POINT): Light.002
processing begun of light (POINT): Light.003
processing begun of light (POINT): Light.004
========= Writing of JSON file started =========
writing mesh: test-hr
========= Writing of JSON file completed =========
========= end of processing =========
elapsed time: 0 min, 15.0985 secs

@PirateJC @JCPalmer I have exported the integrated model to gltf 2.0 in .glb format directly from blender, by the way it occupies less space, 11 megabytes instead of 18, thats very interesting is it because its a more compressed format?

in any case I am trying to load it with the same code I had, just changing obviously the extension to .glb, but I get error “SyntaxError: Unexpected token g in JSON at position 0”

the function Im using to load is this one:
SceneLoader.AppendAsync(lrmodel, “”, scene, function (evt) {}).then(
(scene) => {… etc, etc

and then oops I see this warning in console:
logger.ts:71 BJS - [21:57:58]: Unable to find a plugin to load .glb files. Trying to use .babylon default plugin. To load from a specific filetype (eg. gltf) see:

so it seems I need to do something special to load .glb files

my app is a react app, I tried to add now the on the index.html but I get same error

so then I noticed that I am already importing babylonjs-loaders in my react project

import {
} from “@babylonjs/core”;

import “babylonjs-loaders”;

but it looks like it still doesnt find the .glb plugin mmm

and I have confirmed that I have babylonjs-loaders installed in node-modules folder and it is loading it as well

drwxr-xr-x 2 root root 4096 Feb 6 16:01 .
drwxr-xr-x 1094 root root 36864 Feb 6 16:01 …
-rw-r–r-- 1 root root 526229 Oct 26 1985 babylonjs.loaders.js
-rw-r–r-- 1 root root 761603 Oct 26 1985
-rw-r–r-- 1 root root 156977 Oct 26 1985 babylonjs.loaders.min.js
-rw-r–r-- 1 root root 233049 Oct 26 1985 babylonjs.loaders.module.d.ts
-rw-r–r-- 1 root root 1883 Feb 6 16:01 package.json
-rw-r–r-- 1 root root 960 Oct 26 1985
[root@ babylonjs-loaders]#

First you might want to look at the file test_hr_baked_DIFFUSE.jpg that was generated. It might be black. The materials are pretty hostile to BJS. Those nodes have no meaning in either StandardMaterial nor PBRMaterial, so an Albedo texture is baked.


Baking is really up to Blender to do. While it might be easier for Blender to bake these materials one at a time, if you can get the equivalent effect without them, you will be much better off. That is a pretty big mesh, 118k triangles (probably majority flat shaded, since verts are 350k). The UV’s would un-neccessary if baking were not required, unless there is also a texture involved.

a .babylon format is a text based JSON file with the extension changed. A GLB is a binary file. Their transmission sizes are not directly comparable, since a text file can be gzipped, while a binary cannot. You need to register the .babylon to the webserver, however. I would recommend just changing the extension of the file to .json.

I also see 533 frames of camera animation. The GLB format may or may not have that.

@JCPalmer thank you very much, so:

  • I always look at the DIFFUSE jpg, it is never black, but sometimes it looks different to the normal stuff, but never fully black

  • the amount of triangles is needed for my project and its not an issue, its working really well

  • about materials, the thing is that I apply a material that sets different colors for different heights of the model, if I could maybe replicate that with babylon, but not sure how to do it. So image there is some shape, and the lower part of the shape has a certain color, the middle part another color and the top part another color and smooth transitions between them (ramp node in blender), so yes potentially I could get rid of the blender materials and replace them with babylon materials if I knew how to recreate something like that in babylon I guess; in blender I have to tie the vertical coordinate of the model to the ramp etc etc

  • changing the extension to .json? of what? of the .glb file? but thats a binary file

  • the animation is not relevant, I dont use it for anything, its there because blender puts it there but it doesnt help or hurt

If you think the baked image is in the ballpark, then being black usually has to be the lighting. For PBR, it is either the lights, or environment texture. You have 4 point lights, but I do not know of any other reason. If the texture was not loading, it would show as that red-black checker board.

The triangles, animation and file extension stuff was all for the size difference. You would change the .babylon file to .json.

@JCPalmer thank you, thats what I don’t get, if a .babylon file is already a text file, why change the extension to json? oh maybe so that its picked for being gzipped, I get that, in fact I think I already added in my server to have the .babylon files gzipped as well, so thats ok but thank you for the suggestion

well my main issue now is that I wanted to try if .glb would load things well to then compare, but as you can see in my previous examples I cannot load .glb, I get errors that I dont have the plugin to load .glb, but i do have installed the babylon loaders library which is what I don’t understand, (I have a message above about that)

Hi @javismiles :slight_smile: I took a look at your babylon export issues with regards to the material and geometry issues. Unfortunately, it would be nice to have your blend file, but I don’t, so this is from my own made up data.

So I created something (Blender 2.90) and exported it with @JCPalmer 's exporter. Basically, I created two cubes and three text objects that I converted to meshes, gave a different material to each object then merged all the meshes and exported to .babylon. In image 1 below you can see the result : 1 mesh, and 5 materials and one multi-material (from the 5 materials). Works fine.

Each individual material is simple - a Principled BSDF shader(Image 2 left) that does not require and baking. I have also used text objects with simple shaders here:

The Detective’s Office

The neon signs use a simple emissive shader (Image 2 right).

I suspect that your merged mesh is using more complex shaders as the Blender babylon exporter is having to “bake out” images. This requires a UV map. In image 3 you see the UV map generated by Blender for a text object. All the faces are selected (on right) and the vertices (on left) are all in a single line - not a very good map! So for more complicated shaders that require baking, I suspect this will create quite a mess.

No idea how Blender’s GLB exporter would handle this, that UV map is going to create all kinds of problems.

Post your .blend file if you can.

Stay Safe, gryff :slight_smile:

@gryff this is great help thank you very much,
you are right the difference is that I am not using just a plain material, I am using a material with nodes built to change the color depending on the area on the y axis of the model,
will see if i can post some blend example soon, thank you again for your help

@gryff @JCPalmer I finally solved this by doing the following:

  • instead of exporting the .babylon file with just 1 mesh, I finally exported two meshes, one the main mesh, and another a mesh with all the texts integrated; each with a different material, and yeah it works perfect, zero problems

Exporting all in 1 single mesh worked for you and also for me in a previous case in the past, but it would just never work in this specific case, probably because of UV issues caused by the positions of these specific texts etc

but at the end of the day the easiest solution is to export two meshes, the main thing and the text bits separately and just show and hide both when needed and yeah this works well and gives me better control as i can put different materials to each part without worrying about issues

thank you again for the help :slight_smile: