javascriptthree.jsblenderuv-mapping

Loading more than one Blender-exported object/mesh+material in Three.js


I've modelled two objects in Blender, with different materials and different textures UV-mapped to them. I'm rendering it with the CanvasRenderer

If I export it, there is more than one material but just one mesh in the resulting JSON file.

This is the (simplified) code I use to load a model with Three.js:

var loader = new THREE.JSONLoader();
loader.load(myModelPath, function {

    var material = geometry.materials[0];
    material.morphTargets = true;
    material.overdraw = true;

    var mesh = new THREE.Mesh(geometry, material);

    mesh.scale.set(50, 50, 50);
    mesh.position.set(0, 0, 0);

    scene.add(mesh);

});

As you can see, I'm only using the [0] material. The result is that the second object uses the first object's material (if I use the [1] material, the opposite happens).

But I do not know how to create a mesh that uses more than one material!

Is it even possible? Or, is there a way to export more than one JSON file from Blender (one per object)?


Solution

  • They have probably made improvements to the json exporter since this question was asked, but it is possible now. In the export options near the bottom under settings, there is a checkbox for all meshes. Uncheck that and only the selected mesh will be exported.