three.js将纹理添加到JSON对象

时间:2017-11-29 14:33:17

标签: javascript json html5 three.js

我在Blender中创建了一个3D模型。比我用Three.js导出器导出它并在JavaScript中加载它。一切正常,但纹理没有显示。我在Blender中添加了纹理作为图片。

JSON文件:

{
"normals":[0,-1,0,...]
"vertices":[-0.0101738,1.5,6.55678,-0.0101738,1.5,...]
"materials":[{
    "DbgIndex":0,
    "blending":1,
    "colorSpecular":[1,1,1],
    "opacity":1,
    "colorDiffuse":[0.8,0.554325,0.316799],
    "mapDiffuseWrap":["repeat","repeat"],
    "transparent":false,
    "wireframe":false,
    "DbgColor":15658734,
    "depthWrite":true,
    "specularCoef":50,
    "mapDiffuse":"parket.jpg",
    "mapDiffuseRepeat":[1,1],
    "visible":true,
    "mapDiffuseAnisotropy":1,
    "shading":"phong",
    "depthTest":true,
    "doubleSided":false,
    "colorEmissive":[0,0,0],
    "DbgName":"Les"
},{
    "DbgIndex":1,
    "blending":1,
    "colorSpecular":[1,1,1],
    "opacity":1,
    "colorDiffuse":[0.287043,0.0523764,0.0102247],
    "transparent":false,
    "wireframe":false,
    "DbgColor":15597568,
    "depthWrite":true,
    "specularCoef":50,
    "visible":true,
    "shading":"phong",
    "depthTest":true,
    "doubleSided":false,
    "colorEmissive":[0,0,0],
    "DbgName":"\u010crna"
},{
    "DbgIndex":2,
    "blending":1,
    "colorSpecular":[1,1,1],
    "opacity":1,
    "colorDiffuse":[0.8,0.136903,0.018619],
    "transparent":false,
    "wireframe":false,
    "DbgColor":60928,
    "depthWrite":true,
    "specularCoef":50,
    "visible":true,
    "shading":"phong",
    "depthTest":true,
    "doubleSided":false,
    "colorEmissive":[0,0,0],
    "DbgName":"Rjava"
}],
"metadata":{
    "materials":3,
    "uvs":0,
    "generator":"io_three",
    "type":"Geometry",
    "vertices":276,
    "normals":109,
    "faces":241,
    "version":3
},
"faces":[35,22,0,1,2,0,0...]
"uvs":[]

}

JSON Loader:

                var loader = new THREE.JSONLoader();
                loader.load( 'samosteza.json', function ( geometry, material ) {
                    mesh = new THREE.Mesh( geometry, material);
                    mesh.scale.x = mesh.scale.y = mesh.scale.z = 30;
                    mesh.translation = THREE.GeometryUtils.center(geometry);
                    mesh.translateY(-150);
                    scene.add( mesh )
                }, 'parket.jpg');

任何人都知道如何显示纹理?我的纹理(' parket.jpg')与index.html文件位于同一文件夹中。

修改

我刚刚发现纹理已经显示,但没有正确显示。我有木质纹理,所有我看到的是棕色。我尝试用不同的纹理改变纹理,但我总是在对象上得到一种颜色,而不是完整的纹理。

enter image description here

纹理:

enter image description here

1 个答案:

答案 0 :(得分:0)

可能这对你有帮助吗?

mesh.material.map = THREE.ImageUtils.loadTexture( src );
mesh.material.needsUpdate = true;