使用 JSONLoader 的多种材料? [英] Multiple materials with JSONLoader?

查看:22
本文介绍了使用 JSONLoader 的多种材料?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将两种材质分配给一个使用 JSONLoader 加载的网格?

Is it possible to assign two materials to one mesh which has been loaded with JSONLoader?

我在 Blender 中制作了一个简单的角色并将其导出为 Three.js 格式,其中包含变形目标和 UV.

I've made a simple character in blender and exported it to three.js format, which contains morph targets and UVs.

我试图为身体分配纯色材质,为角色的头部分配一张图片(http://touhou.ru/dev/webgl-test-stackoverflow/kourindouhime.jpg),但在加载网格和材料后,我得到一个灰色的网格.

I was trying to assign solid color material to the body and a picture to my character's head (http://touhou.ru/dev/webgl-test-stackoverflow/kourindouhime.jpg), but after loading mesh and materials I get a gray-colored mesh.

这是我项目的生产版本(使用 wasd 移动,当您看到您要控制的灰色玩家网格时,这正是我要说的):http://touhou.ru/dev/webgl-test-stackoverflow/

Here's production version of my project (use wasd to move and when you see a gray player mesh which you'd be controlling, that's exactly the thing I'm talking about): http://touhou.ru/dev/webgl-test-stackoverflow/

这是我使用 JSONLoader 加载网格和材料的方式:

And here's the way I'm loading mesh and materials with JSONLoader:

  var player_loader = new THREE.JSONLoader();

  player_loader.load( "running_babe.js", function(geo, material) {
    material[0].morphTargets = true;
    material[1].morphTargets = true;
    var materials = new THREE.MeshFaceMaterial(material);
    player = new THREE.Mesh( geo, materials );
    scene.add(player);
  });

我做错了什么吗?

更新:问题出在我的导出中.现在第二个材料看起来像这样:

UPDATE: the problem was in my export. Now the second material looks that way:

    {
            "DbgColor" : 15597568,
            "DbgIndex" : 1,
            "DbgName" : "Material.001",
            "blending" : "NormalBlending",
            "colorAmbient" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
            "colorDiffuse" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
            "colorSpecular" : [0.5, 0.5, 0.5],
            "depthTest" : true,
            "depthWrite" : true,
            "mapDiffuse" : "kourindouhime.jpg",
            "mapDiffuseWrap" : ["repeat", "repeat"],
            "shading" : "Lambert",
            "specularCoef" : 50,
            "transparency" : 1.0,
            "transparent" : false,
            "vertexColors" : false
    }

而且效果很好.谢谢各位.

and it works very nice. Thank you guys.

推荐答案

如果我没看错你的代码,running_babe.js 就是你所说的网格.看其来源,材料如下:

If I looked your code correctly, running_babe.js is the mesh you are talking about. Looking at its source, the materials are as follows:

"materials" : [ {
    "DbgColor" : 15658734,
    "DbgIndex" : 0,
    "DbgName" : "Material",
    "blending" : "NormalBlending",
    "colorAmbient" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
    "colorDiffuse" : [0.6400000190734865, 0.6400000190734865, 0.6400000190734865],
    "colorSpecular" : [0.5, 0.5, 0.5],
    "depthTest" : true,
    "depthWrite" : true,
    "shading" : "Lambert",
    "specularCoef" : 50,
    "transparency" : 1.0,
    "transparent" : false,
    "vertexColors" : false
},

{
    "DbgColor" : 15658734,
    "DbgIndex" : 0,
    "DbgName" : "default",
    "vertexColors" : false
}],

可以清楚地看到没有纹理,第二个没有任何纹理,第一个具有灰色阴影的所有颜色.似乎材料没有正确导出.这并不奇怪,因为导出材料很困难,因为 3d 建模器概念和three.js 材料参数之间可能没有明确的映射.我只是通过在该文件中手动指定材料参数来修复它.

It can be clearly seen that there are no textures, the second one doesn't have really anything and the first one has all colors as a shade of gray. Seems like the materials aren't exported correctly. That is not a big surprise as exporting materials is hard, as there might not be a clear mapping between 3d modeler concepts and three.js material params. I'd just fix it by manually specifying the material params into that file.

这篇关于使用 JSONLoader 的多种材料?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆