简体   繁体   English

Collada model 黑色装

[英]Collada model loaded in Black

I have copied the example given in the official three.js repo of how to load the DAE Collada model, modified it to remove the animations, and loaded my own Collada model.我复制了官方 three.js repo 中给出的如何加载 DAE Collada model 的示例,修改它以删除动画,并加载我自己的 Collada model。

The problem is that the model loads in black as you can see in this codesandbox , and I wasn't able to change the material color?问题是 model 加载为黑色,如您在此codesandbox中所见,我无法更改材质颜色? You can see that the same model file(after I converted it from Collada to GLTF) is parsed with blue color.您可以看到相同的 model 文件(在我将其从 Collada 转换为 GLTF 之后)被解析为蓝色。 Can you please tell me how can I load the color correctly?你能告诉我如何正确加载颜色吗? thanks in advance.提前致谢。

I looked at your geometry with console.log(child.geometry) and noticed that it doesn't have any normals data.我用console.log(child.geometry)查看了你的几何图形,发现它没有任何normals数据。 It only has position, uv, & uv2 , but you need normals to calculate the behavior of light reflecting from your faces.它只有position, uv, & uv2 ,但你需要法线来计算从你的脸上反射的光的行为。

There are 3 things you can do to solve this:你可以做三件事来解决这个问题:

1 Add your own normals: 1 添加自己的法线:

Re-export your Collada file with normals data from your 3D editor software.从 3D 编辑器软件中重新导出带有法线数据的 Collada 文件。

2 Flat shading: 2 平面着色:

Use flat-shading so every face is flat, without smooth or rounded edges.使用平面阴影,使每个面都是平坦的,没有光滑或圆形的边缘。 You don't need normals data for this because the shader just assumes every triangle's normal is pointing perpendicular to its surface.您不需要法线数据,因为着色器只是假设每个三角形的法线都垂直于其表面。

avatar.traverse(function (child) {
  if (child.isMesh) {
    child.material.flatShading = true;
  }
});

3 Calculate normals: 3 计算法线:

You could ask Three.js to calculate the normals for you .您可以要求 Three.js 为您计算法线 Just be aware that it does this by averaging connected vertices, so faces might accidentally look too smooth or too hard in places you don't expect.请注意,它通过对连接的顶点进行平均来实现这一点,因此在您意想不到的地方,面可能会意外地看起来太光滑或太硬。

avatar.traverse(function (child) {
  if (child.isMesh) {
    child.geometry.computeVertexNormals();
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM