Material Picker on which extension?

I can get the material picked using

viewer.onSceneReadyToDisplay(function() {
var setMaterialForMeshOriginal = viewer.setMaterialForMesh;
viewer.setMaterialForMesh = function(material, mesh) {
  setMaterialForMeshOriginal.apply(this, [material, mesh]);
}

However, because the same materials are used on multiple extensions, 7 different extensions in my case, I don’t know which extension the user changed the material. I’ve tried looking at the mesh.name, but that is empty. I do not want to create multiple, identical materials just to know it was “Maple Door” instead of “Maple baseboard”. How can I identify the extension name the material picker used.

With setMaterialForMesh replacing trick you rather won’t be able to determine which extension triggered the replacement. Could you explain what would you like to achieve, perhaps there is some other approach that will work?

When a material is selected, I want to capture [extension name, material name] to send to another process with the selected materials list. Is there a way to capture the extension name when the picker is first displayed?

We have recently added a new, not yet documented call that allows for this:

viewer.onApiUserStateChanged(function(key, value) {
});

For state changes triggered by the material picker, the key in the callback is MaterialPicker:EXTENSION_NAME, and value is the name of the selected material. Let us know if this works.

That is exactly what I needed. Works like a champ. Thank you.