Recently, a customer tried out our 3D platform. When importing the model, the model was completely black and invisible. This article describes the situation of all black.
After the test, it is found that there are several possible cases.
The OBJ model has no normal vector
If the obJ model is exported without the normal vector, it will cause the model cannot receive light and the exported model will be completely black. In this case, there is no specular reflection.
One solution is to have the modeler re-export the model with the export normal vector checked.
In addition, the program can also be compatible, judge whether the model has a normal vector, if not, the program to calculate the normal vector. Taking Threejs as an example, call computeVertexNormals to calculate the normal vector code as follows:
if(child.geometry && ! child.geometry.hasAttribute('normal')) { child.geometry.computeVertexNormals(); }Copy the code
PS: How to determine 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
Some modelers export MTL files with the parameter Kd 0 0 0, which is parsed to the color property of the model material. In this case, although the model is completely black, the highlight color is present, that is, the highlight can be seen at a specific Angle:
So the solution is to remove Kd 0, 0, 0 altogether, or the modeler can re-export the model file to make Kd a value that is not all 0.
MTL is also a text file, which can be opened directly with a text editor:
In PS MTL, Kd represents the color of diffuse reflection and Ks represents the color of specular reflection.
Maps in MTL files refer to local paths
Sometimes when modelers export MTL files, the mapping path inside is the local absolute path, as shown below:
The imported model turned black because it could not find a map. In this case, although the model is completely black, the color of the highlights is present, that is, the highlights can be seen at a specific Angle, ditto.
The solution is to change the absolute path to the relative path, as shown below:
You can modify the MTL file manually or set it when the modeler exports it.
The imported scene is not lit
There is also a case where the model is fine, but the model cannot be seen because the scene is not lit. In this case, lights need to be added programmatically.
# epilogue
The last modified renderings
If you are interested in visualization, you can communicate with me on wechat 541002349. Follow the public account “ITMan Biao Shu” to receive more valuable articles in time.