Add febric to GLB Model from png

Officially three.js is a library for the web, and using it in Node.js will require workarounds. People do that (search for “headless rendering” in the forums for examples) but it is definitely more complicated than using the library on the web. In Node.js, the APIs we use to render (WebGL) and load resources (HTMLCanvas, HTMLImage) do not exist, and have to be replaced in one way or another.

If you have the option of running a headless browser — rather than just executing a node.js script — that will certainly make things easier, but at higher cost if this is a high-traffic API. I’d start with a thread like this perhaps:

As for replacing the texture, whatever you get from THREE.GLTFLoader is just a THREE.Group. You can iterate it and modify materials using all of the normal three.js material APIs.

loader.load('model.glb', ({scene}) => {
  scene.traverse((object) => {
    if (object.material && object.name === 'MyObject') {
     object.material.map = myTexture;
    }
  });
});