javascript - Three.js 添加纹理到 JSON 对象

标签 javascript json html 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 加载器:

                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

最佳答案

这可能对您有帮助吗?

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

关于javascript - Three.js 添加纹理到 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47555225/

相关文章:

html - 当正文很长时,页脚不会停留在屏幕底部

javascript - 如何在 JavaScript 中用 "/"替换字符串中所有出现的 "_"?

javascript - 匹配来自单个正则表达式的文件名和文件扩展名

java - 如何在谷歌云存储构建器中设置项目 ID?

java - JSON解析数组

html - 展开 float 元素后的空白

javascript - Joomla 3.6 自定义 html 模块中的与我聊天链接

javascript - 异步 Redis 和 Promise

java - 在 Rest Assured 中发布多部分文件和 JSON

javascript - 在其他两个 DIV 之间显示 HTML DIV