Recently, a customer tried our 3D platform. When importing the model, the model appeared completely black and invisible. This article talks about the situation in total darkness.
After testing, it was found that there may be the following situations.
obj model has no normal vector
If the normal vector is not exported when the obj model is exported, the model will not be able to receive light, and the exported model will be completely black. In this case, there is no specular reflection.
As for the solution, one is to let the modeler re-export the model, and check the export normal vector when exporting.
In addition, it can be compatible with the program to determine whether the model has a normal vector. If not, the program calculates the normal vector by itself.
Take threejs as an example, call computeVertexNormals to calculate the normal vector code as follows:
if(child.geometry && !child.geometry.hasAttribute('normal')) {
child.geometry.computeVertexNormals();
}
PS: How to judge whether the model has a normal vector, just open the *.obj file with a text editor and check whether there is a "vn" mark
Set the model color to black in the mtl file
When some modelers export the mtl file, the parameter Kd is 0 0 0, and the Kd parameter will be parsed into the color attribute of the model material, which is the color.
In this case, although the model is completely black, the color of the highlights is there, that is, the highlights can be seen at a specific angle:
So the solution is to remove all the settings of Kd 0 0 0, or the modeler can re-export the model file so that Kd becomes a non-zero value.
mtl is also a text file, which can be opened and viewed directly with a text editor:
In PS mtl, Kd represents the color of diffuse reflection, and Ks represents the color of specular reflection.
The texture in the mtl file refers to the local path
Sometimes when a modeler exports an mtl file, the texture path inside is a local absolute path, as shown in the following figure:
At this time, the imported model became black because it couldn't find the texture. In this case, although the model is completely black, the color of the highlights is there, that is, the highlights can be seen at a specific angle, ibid.
The solution is to change the absolute path to a relative path, as shown below:
You can manually edit the mtl file to modify it, or you can set it when the modeler exports it.
The imported scene has no lights set
In another case, there is no problem with the model, but because the scene is not set with any lights, the model cannot be seen. In this case, you need to add lights to the program.
Concluding remarks
The last modified rendering
If you are interested in visualization, you can communicate with me on WeChat 541002349. Pay attention to the public account "ITMan Biaoshu" to receive more valuable articles in time.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。