How to import Gltf mantaining meshes's names

Hi
New of Babylonjs.
I’m developing a web tool for a research project, importing geometry from gltf format.
In order to link meshes to a database containing data of corresponding objects, I’m trying to use the mesh name assigning them a unique id.
Unfortunately when I import the geometry, the name of meshes seems to be converted in a Nodexxx format.
Is there some way to mantain in babylonjs scene, the name assigned in gltf file?

Thank you very much

Berardo

Hi @bernat and welcome to the forum. I think there must be a misunderstanding somewhere. Names are preserved see the console of https://www.babylonjs-playground.com/#8IMNBM#72

2 Likes

Thank you JohnK for the welcome and your answer.
Your example works fine.
Something different happens with my .glb files (I implement them by using SharpGltf libraries).
BTW importing them in online editors (i.e. https://www.gltfeditor.com/) names are correctly managed while in babylonjs sandbox or using my file in your example they are substituted with a nodexxx++ rule.
Unfortunately I cannot share a file here, because of my new member status.
Is there a way to share a .glb file for futher investigation?

Hi bernat… welcome. I can verify your issue (I agree - I see name problems). BUT… maybe ONLY for .glb

JohnK showed a .gltf playground. Names looked fine. BUT… go here…

https://doc.babylonjs.com/resources/meshes_to_load

Choose “seagulf.glb” PLAYGROUND. https://www.babylonjs-playground.com/#8LFTCH#2

Chose inspector from options (gear) menu, then expand NODES branch, then under-scored root branch, then next root branch, and discover (and click-on) a mesh named mesh_id26. (The same “renaming” format/problem as @bernat is stating. He is correct… and likely .glb only.)

So, I Wingnut, verify and validate his issue. I see it. Feel free to load OTHER .glb playgrounds from the demo’s list - test those. Same problems… mesh being renamed, like bernat states.

ONLY for .glb, and NOT gltf… (it seems). @bernat, stay tuned… experts are nearby… we see what you see. Let’s ping BJS superstar and all-around nice person @sebavan. He’ll know stuff for sure. :slight_smile:

Off-topic aside: Did ya’ll see @sebavan working “daily Q&A duty” lately? He’s an excellent Q&A forum custodian, eh? SO nice, and SO smart. (Hugs to sebavan… AND JohnK… and DK… and a bunch of others. Ya’ll rock.


Personal note to friends: I'll be back to help eventually, I hope. I think I need to *change residence*... a 2nd time... in < 3 months. OUCH! Trailer home I bought... maybe NOT FIT to live-in. It might be out-gassing formaldehyde and making me sick (I can't sleep, 3-7 nightmares/lucid-dreams per night cuz... no deep sleep. Trying EVERYTHING.) SO... I'm arranging an (emergency) move to $$apartment$$... in an area of Wisconsin that has few/none available. Expensive, and I might need to re-sell/destroy house trailer. MY problem cuz... I bought "as is". OMG! STRESS HELL! Will I die of poisoning... before new apartment is available? Let's watch and see. :/

End of self-whining. PM me at will, friends. Wingy in deep crap. Got rescue ideas? :slight_smile:


Ok, let’s get back to bernat’s stuff… see what we can learn. BabylonJS Gltf-loader code is at… Babylon.js/babylon.glTF2FileLoader.js at master · BabylonJS/Babylon.js · GitHub

That might not be the correct GLB loader though. For .glb… BJS might use Draco hanging on a webworker!)

(What the heck did Wingy say? Sounded like Swahilli.) :slight_smile:

Stay tuned, bernat!

1 Like

Hi Wingy What a nightmare! - hope you get sorted out soon and find somewhere safe to live.

Ooops! Still the same for the .glb file https://www.babylonjs-playground.com/#8IMNBM#75

An you can use the names to load just one mesh https://www.babylonjs-playground.com/#8IMNBM#74

and you can use this name to load this mesh directly https://www.babylonjs-playground.com/#8LFTCH#284, implying this is the name in the file.

Also if you open the seagulf.glb file in a text editor you find at the start (before all the binary stuff)

[{"name":"mesh_id26","primitives":[{"attributes":{"NORMAL":2,"POSITION":1,"TEXCOORD_0":3},"indices":0,"material":0,"mode":4}]}],"nodes":[{"matrix":[217.4147186279297,0.0,0.0,0.0,0.0,217.4147186279297,0.0,0.0,0.0,0.0,217.4147186279297,0.0,0.00005183570829103701,-511.98663330078127,512.0,1.0],"mesh":0,"name":"mesh_id26","extensions":{}},{"children":[0],"name":"root","extensions":{}}],"samplers":[{"minFilter":9985}],"scenes":[{"nodes":[1]}],"scene":0,"textures":[{"name":"texture3","sampler":0,"source":0},{"name":"texture5","sampler":0,"source":1},{"name":"texture_3_2048x2048_bc","sampler":0,"source":2},{"name":"texture_5_2048x2048_mr","sampler":0,"source":3}],"extensionsUsed":["KHR_materials_pbrSpecularGlossiness","MSFT_lod"]}

containing the name mesh_id26

and in gltfeditor image

So it seems that this is the name in the file.

Also if Babylon.js was doing the renaming it would be consistent across all files, yet alien.glb uses individual names, seagulf.glb uses mesh_id26.

Could the renaming be happening elsewhere? Perhaps SharpGltf libraries?

We might need a copy of one of your files.

1 Like

Hi Wingnut, sorry for your home issues, (formaldehyde is not a good night friend and even carcinogenic but it is easily measurable with a cheap instrument, may be u can investigate a little).
Yes, the strange behavior in name parsing is limited to binary glb format. Unfortunately it is the only way to link objects between applications without disturbing extras.
JohnK, I verified the file is parsed correctly in threejs. I can send u my .glb by email because I’m not able to share it here.

In which case the solution is outside my skill set. You probably need to wait for @sebavan or others.

Hello @bernat,

Could you please share with @bghgary your file so that he could investigate the issue quickly ?

@Wingnut so sorry about your home issues :frowning: and as you would say… HUG… :wink: Hope you ll get all of it sorted soon

What you can do is making a dummy PG and put the url to your file as a comment in this PG. Quite ugly but you can at least share links this way!

ok. I added a very light .glb sample on github.
I obtained it by parsing the very knotty IFC STEP/Express format used for Building Information Modeling.

It seems the GLTF loader does not use the property name of the mesh when creating the mesh but uses the name property of the node containing the mesh instead.

As in your file the nodes don’t have names, meshes end up with default names.

What we could do, maybe, is to use IMesh.name (the name of the mesh in the gltf file) as the name of the mesh (if provided - if not, we would still use the name of the node), and put the name of the node in the id property of the babylon mesh.

That would be a breaking change, however. To avoid a breaking change, we could put IMesh.name in the mesh.id property.

Thoughts @bghgary, @sebavan, @Deltakosh?

I ll definitely leave this one to @bghgary as he is our GLTF grand master :wink:

What we could do, maybe, is to use IMesh.name (the name of the mesh in the gltf file) as the name of the mesh (if provided - if not, we would still use the name of the node), and put the name of the node in the id property of the babylon mesh.

The glTF loader used to do this in an early version. The issue with this is that it’s inconsistent. Sometimes glTF meshes will have names and sometimes it won’t. Since the mapping between glTF and Babylon are not 1:1 (e.g. glTF node/mesh/primitives becomes Babylon transform node + child meshes), I don’t see a clean solution to this. We can maybe store the mesh names in metadata?

I think the best solution maybe to add a loader extension that will assign the names in a specific way for this particular scenario?

@bghgary you’r completely right.
I investigated and also noticed that meshes with multiple primitives have no name (though the primitives are named).
I updated my naming policy and now everything works fine.
For the sake of clarity I added an updated version of the .glb file in the same github.
Anyway, to me an extension of the gltf importer naming policy could be adopted here (i.e. using the automatic naming only for meshes with empty value).
BTW thank you all for the quick response and investigation. I’m glad to be a member of a such reactive community.

Berardo

Gee Wingy that is the last thing you need given the virus state south of the border. Take care mate - this forum needs you.

Stay Safe All, gryff :slight_smile:

1 Like