How to create a custom gltf plugin

I generate GLTF files with a custom extension. Now i want to create a simple viewer, load a gltf file and react to that extension. The extension contains some coloring data and an additional mask texture that i want to use to tint the model.

I already managed to do it with BabylonJS as they have a plugin mechanism that i can hook into, read metadata, attach it to the material and then use it in a plugin material to modify the PBR shader.

Is there anything similar in playcanvas? Any documentation that i might be missing?

1 Like

Found out that there is no way to register a plugin or something that can hande a custom GLTF extension. Had to copy this function here

to add custom extension handler here

would be great if the glb parser would actually expose the createMaterial function and some of the utility function. I might create an issue for that on github.

Now the last bit i need to know is how to add shader chunks into the standard material

When you load the glb asset, you can specify a processing functions that get called when the glb is parsed - at that point you can get data from your extensions.

1 Like

yes, but that is too late though, because at that point the textures have already been consumed to create the material and unused textures are basically “lost”. My custom extension needs to grab one of those textures otherwise it is not assigned anywhere.

@slimbuck understands this the best.
But I’m pretty sure we have some internal test project where a custom texture is referenced by the material plugin, so it should be doable using this callbacks.

1 Like

Hi @Ginie,

Please do create an issue and describe accurately what you’re trying to achieve.

If you need the equivalent of a material extension, then you probably can just implement a material.postprocess handler. This handler is given the standard material instance and the gltf material object (see here). Although I see it is not sent the list of textures. That’s perhaps something you’d need to get the job done?


That is exactly the point. The postprocess does not receive textures.

Sorry for not making that clear in the opening post. Yet at that point i had no understanding of playcanvas internals and was not able to find any documentation about “how to create a plugin and add to the gltf asset pipeline”. So that what i asked for. After reading the source code i then found those preprocess, process and postprocess hooks.

What i want to achieve with the custom extension:

  1. grab an additional texture and additional metadata from any gltf material node

  2. add custom shader to “tint” the model based on that texture (being a mask) and metadata (some coloring info)

Point 1. is solved, yet not to my satisfaction, as i need to use the process hook to access the texture and therefore have to replicate the createMaterial function from glb-parser.

Here is the current extension code

Point 2. is an open question to me. I have to learn how to add custom shader bits to an existing material. Any link to an example or documentation would be awesome.

This is how i solved it for babylon

1 Like

@slimbuck i have opened a github issue based on this thread access textures inside a gltf material content handler · Issue #5606 · playcanvas/engine · GitHub

Also i managed to solve the custom shader chunk part and all the custom behavior i wanted. Full source code is here

With that all questions for this topic are answered.