Three.js materialLoader doesn't load embedded texture image

Viewed 369

I'm exporting a three.js material using material.toJSON() provided method, this is the result:

{
"metadata":{"version":4.5,"type":"Material","generator":"Material.toJSON"},
"uuid":"8E6F9A32-1952-4E12-A099-632637DBD732",
"type":"MeshStandardMaterial",
"color":11141120,
"roughness":1,
"metalness":0.5,
"emissive":0,
"map":"876D3309-43AD-4EEE-946F-A8AE8BA53C9E",
"transparent":true,"depthFunc":3,"depthTest":true,"depthWrite":true,

"textures":[
    {
        "uuid":"876D3309-43AD-4EEE-946F-A8AE8BA53C9E",
        "name":"",
        "mapping":300,
        "repeat":[1,1],
        "offset":[0,0],
        "center":[0,0],
        "rotation":0,
        "wrap":[1001,1001],
        "minFilter":1008,
        "magFilter":1006,
        "anisotropy":1,
        "flipY":true,
        "image":"C6B4FEDA-8E7E-490A-A1AD-866ECE36E952"}],

"images":[
{
    "uuid":"C6B4FEDA-8E7E-490A-A1AD-866ECE36E952",
    "url":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAEACAYAAADFkM5nAAAg[...]"
}]}

I try to use MaterialLoader as the example suggest

https://threejs.org/docs/#api/loaders/MaterialLoader

but at parsing time I always get this error

THREE.MaterialLoader: Undefined texture 876D3309-43AD-4EEE-946F-A8AE8BA53C9E

I'm I wrong if I expect from the MaterialLoader to use the embedded resources? I'm doing it wrong or missing something? How can I also load the images in the json file into the related texture?

Thanks!

here a fiddle: http://jsfiddle.net/akmcv7Lh/211/

1 Answers

Notice that MaterialLoader is not able to load textures. It expects that textures are set via MaterialLoader.setTextures() before loading a JSON file like ObjectLoader does:

const loader = new MaterialLoader();
loader.setTextures( textures );

So MaterialLoader can only be used as a standalone loader if the respective materials have no textures. Otherwise you have to prepare the textures on app level similar how ObjectLoader does.

Related