Normally, when a three.js model is exported as JSON it includes all materials and textures. I would like this data to be loaded from external urls. So my exported JSON would include all 3D data, but just URLs where to load the materials. I’m thinking of a clean way to do this. One way I’m thinking of is to store some extra information in the userData for the meshes, so the userData would look something like this:
userData: {
extMaterial: {
url: "http://somewhere/material",
// maybe more information, like texture scale and rotation
}
}
And then have a class ExtMaterialLoader
that loads the materials and creates real three.js materials from the data. Loading a model would be something like:
let model=...; // First load the model normally using e.g. ObjectLoader
let extMaterialLoader=new ExtMaterialLoader();
await extMaterialLoader.loadMaterialsForObject(model);
Would like to ask for your opinion on this way of doing things. Is there already another established pattern for referencing and loading external materials?