AlexB
September 21, 2023, 12:42pm
1
Hey there,
Looking at the documentation for the GLTF loader extension, there is a callback for when a material is imported:
But seems like there is no callback for when a mesh is imported.
I would have expected to see something like:
loadMeshPropertiesAsync(
context: string,
node: BABYLON.GLTF2.Loader.INode,
mesh: BABYLON.GLTF2.Loader.IMesh,
primitive: BABYLON.GLTF2.Loader.IMeshPrimitive,
babylonMesh: Mesh
): Nullable<Promise>
Am I missing something?
Thanks!
@bghgary
bghgary
September 21, 2023, 3:22pm
2
Welcome to the forums!
There are two undocumented ones that I haven’t exposed because I’m not confident of their function signature. They can still change. Use at your own risk.
/**
* @internal
* Define this method to modify the default behavior when loading vertex data for mesh primitives.
* @param context The context when loading the asset
* @param primitive The glTF mesh primitive property
* @returns A promise that resolves with the loaded geometry when the load is complete or null if not handled
*/
_loadVertexDataAsync?(context: string, primitive: IMeshPrimitive, babylonMesh: Mesh): Nullable<Promise<Geometry>>;
/**
* @internal
* Define this method to modify the default behavior when loading data for mesh primitives.
* @param context The context when loading the asset
* @param name The mesh name when loading the asset
* @param node The glTF node when loading the asset
* @param mesh The glTF mesh when loading the asset
* @param primitive The glTF mesh primitive property
* @param assign A function called synchronously after parsing the glTF properties
* @returns A promise that resolves with the loaded mesh when the load is complete or null if not handled
*/
_loadMeshPrimitiveAsync?(
context: string,
name: string,
node: INode,
mesh: IMesh,
primitive: IMeshPrimitive,
assign: (babylonMesh: AbstractMesh) => void
): Nullable<Promise<AbstractMesh>>;
2 Likes
AlexB
September 21, 2023, 6:59pm
3
@bghgary Thanks for your quick answer!
Looks like _loadMeshPrimitiveAsync
is a good fit.
Do you have any example/playground showing its usage?
Thanks!
bghgary
September 21, 2023, 8:06pm
5
This is the only usage within the code base.
const extensions = this._loader.gltf.extensions;
if (extensions && extensions[this.name]) {
const extension = extensions[this.name] as IKHRMaterialVariants_Variants;
this._variants = extension.variants;
}
}
/**
* @internal
*/
public _loadMeshPrimitiveAsync(
context: string,
name: string,
node: INode,
mesh: IMesh,
primitive: IMeshPrimitive,
assign: (babylonMesh: AbstractMesh) => void
): Nullable<Promise<AbstractMesh>> {
return GLTFLoader.LoadExtensionAsync<IKHRMaterialVariants_Mapping, AbstractMesh>(context, primitive, this.name, (extensionContext, extension) => {
const promises = new Array<Promise<any>>();
promises.push(
3 Likes