ivstas
ivstas

Reputation: 1233

Is three.js ObjectLoader capable of loading textures?

three.js version 0.0.70, blender version 2.73a

I have a scene exported from blender to three.js json format using new io_three (not io_three_mesh) exporter.

I'm able to import the scene into three.js using ObjectLoader:

var objectLoader = new THREE.ObjectLoader();
objectLoader.load('assets/models/exportedScene.json', function(imported) {
    scene.add(imported);
});

Unfortunatelly, no texture is applied to an object, only the material. As I see from exportedScene.json file, there is an info about texture in file:

"images": [{
    "url": "blue.jpg",
    "uuid": "DFE5BBBF-601B-48EA-9C05-B9CB9C07D92E",
    "type": "Geometry",
    "name": "blue.jpg"
}],
"materials": [{
    "color": 200962,
    "specular": 5066061,
    "shininess": 8,
    "ambient": 200962,
    "depthTest": true,
    "depthWrite": true,
    "name": "partitionMat",
    "emissive": 0,
    "uuid": "A705A33F-68C1-489C-A702-89A0140247AB",
    "blending": "NormalBlending",
    "vertexColors": false,
    "map": "73277351-6CCF-4E84-A9F0-D275A101D842",
    "type": "MeshPhongMaterial"
}],
"textures": [{
    "minFilter": "LinearMipMapLinearFilter",
    "wrap": ["RepeatWrapping","RepeatWrapping"],
    "magFilter": "LinearFilter",
    "mapping": "UVMapping",
    "image": "DFE5BBBF-601B-48EA-9C05-B9CB9C07D92E",
    "repeat": [1,1],
    "name": "carpetTexture",
    "anisotropy": 1.0,
    "uuid": "73277351-6CCF-4E84-A9F0-D275A101D842",
    "type": "Geometry"
}],

But as I said before, no texture is applied. I tried placing texture file near the html with js script, but it didn't work.

Maybe my initial approach is incorrect and I should import textures similar to http://threejs.org/examples/webgl_loader_obj.html? However, this one is about using ObjLoader (not ObjectLoader), and I'm not sure if it's correct.

Upvotes: 0

Views: 1456

Answers (2)

Evalds Urtans
Evalds Urtans

Reputation: 6694

Latest format support it like following:

"images":[
    {
        "uuid": "A430CF4-AD77-11E3-914E-00248C62C323",          
        "url": "../models/1024_tornis.png"          
    },
    {
        "uuid": "eka_tv_2_i",
        "url": "../models/eka_tv_2.jpg"         
    },
    {           
        "uuid": "sala_model_0709_map_i",
        "url": "../models/sala_model_0709_map.png"          
    }
],

"textures":[
    {
        "uuid": "1024_tornis",          
        "image": "A430CF4-AD77-11E3-914E-00248C62C323"          
    },
    {
        "uuid": "eka_tv_2",
        "image": "eka_tv_2_i"           
    },
    {           
        "uuid": "sala_model_0709_map",
        "image": "sala_model_0709_map_i"            
    }
],
"materials": [
    {
        "uuid": "3C5CA6AA-055B-417B-97E0-706BA446140B",
        "type": "MeshLambertMaterial",
        "name": "Material.001",
        "color": 16777215,
        "emissive": 0,
        "map": "1024_tornis"
    }]

Upvotes: 1

repsac
repsac

Reputation: 161

Check out the dev branch. There have been recent commits for texture support for the upcoming r71 release.

Upvotes: 1

Related Questions