Hello!
I’m trying various ways to get tags from a downloaded GLTF file, but I’ve never been able to access them in BabylonJS.
I created a simple GLTF file in Blender, in the file I see the tags (test, lod) in the meshes section:
"meshes" : [
{
"extras" : {
"tags" : "test lod",
"prop" : 1
},
"name" : "Cube",
"primitives" : [
{
"attributes" : {
"POSITION" : 0,
"NORMAL" : 1,
"TEXCOORD_0" : 2
},
"indices" : 3,
"material" : 0
}
]
}
],
The last thing I tried was to create an extension for ImportMeshAsync. The extension is successfully registered and has access to resources:
import { IGLTFLoaderExtension } from '@babylonjs/loaders/glTF'
import { GLTFLoader } from '@babylonjs/loaders/glTF/2.0'
import { Tags, TransformNode } from '@babylonjs/core'
class TagsExtension implements IGLTFLoaderExtension {
public readonly name = 'MyTagsExtension'
public enabled = true
constructor(private _loader: GLTFLoader) {}
public loadNodeAsync(context: string, node: any, assign: (babylonMesh: any) => void): Promise<TransformNode> {
return this._loader.loadNodeAsync(context, node, function (babylonMesh) {
if (babylonMesh.id == 'BTLMN_Prop_RoadSign_A') {
console.log(babylonMesh, node)
}
if (node.extras && node.extras.tags) {
Tags.AddTagsTo(babylonMesh, node.extras.tags);
}
assign(babylonMesh);
});
}
public dispose(): void {
// Add code to dispose any resources used by the extension
}
}
export default function RegisterTagsExtension () {
GLTFLoader.RegisterExtension("MyTagsExtension", (loader: GLTFLoader) => {
return new TagsExtension(loader)
})
}
But babylonMesh.metadata and node.extras remain empty.
Tags are imported well and work with files .babylon, without additional extensions, but we need GLTF.
I’m looking for any working way to get tags from GLTF. Perhaps there is an example that I could not find? I will be glad of any help. Thanks!