0
votes

am exporting my models using ObjectExporter, my code is follows

exporter = new THREE.ObjectExporter;
    var obj = exporter.parse(globalObject);
    var json = JSON.stringify(obj);
    console.log(json);

i can get the json exported data successfully, but after load it using ObjectLoader the Geometry only loading materials are not loading, am loading my saved model by following code

 var loader = new THREE.ObjectLoader();
loader.load("savedjson.json",function ( obj ) {
  scene.add( obj );
  console.log(obj);
}); 

any clue to get materials work with the ObjectExporter?

1

1 Answers

1
votes

I had the same problem. I have a first attempt at a workaround(but it needs to be improved for sure). What I do is, after loading the object, I traverse the model

    loader.load("savedjson.json", function (obj){

        obj.traverse(function(child){ initChild(child); });

        scene.add(obj);
    }

In initChild(child) I do this:

    initChild(child)
    {
        if(child.material != null)
        {
           var childMaterialName = child.material.name;
           child.material = new THREE.MeshPhongMaterial();
           child.material.name = childMaterialName ;
           AssignMap(child.material);
        }
    }

In AssignMap(material) I first load the textures, then assign them based on the material name:

    AssignMap(material)
    {
        var texture_metal = new THREE.ImageUtils.loadTexture("media/texture_metal.jpg");
        var texture_glass = new THREE.ImageUtils.loadTexture("media/texture_glass.jpg");

        if(material.name == "metal texture")
        {
            material.map = texture_metal;
        }

        if(material.name == "glass texture")
        {
           material.map = texture_glass;
        }
    }