-
-
Notifications
You must be signed in to change notification settings - Fork 36k
Description
Description of the problem
Today I've been struggling with exporting a model from Blender to Three.js using the JSON exporter. I don't think the normals are getting exported correctly.
This error seems to happen with any Blender export to .json, but I've included a very simple .blend file containing only a sphere.
I'm using a simple glow shader from ShaderFrog. If you click "edit" you can see the source. Here's how it looks applied to a vanilla Three.SphereGeometry
:
The shader correctly applied to a vanilla Three sphere
And here's how it looks when applied to the sphere exported from Blender to JSON:
The shader incorrectly applied to a vanilla sphere exported from Blender
You can see that the shader only appears correct from one angle, but distorted from other angles. The shader is not correctly "sticking" to the edge of the object, as it should based on the normal calculation in the shader source code.
If, in Three.js, if I call mesh.geometry.computeVertexNormals()
, which clobbers the normals exported from Blender, then the shader is correct again:
The same Blender exported sphere with normals recalculated by Three
Since normals are corrected and the shader works after calling computeVertexNormals()
, I suspect there's a bug in the Blender exporter.
Issue #3221, "Blender Scene Exporter normals wrong" was opened 3 years ago by @willy-vvu. In the issue, he shows an older version(?) of the exporter that includes a "Flip YZ" option:
Not only is this option not available in the current Blender to Three python script (found here), but I can't find any history of the text "Flip YZ" in the git history for the folder containing those scripts. I'm not sure what happened here.
When exporting using Blender's native .obj exporter, and loaded into Three.js the normals are *fine.* Exporting to .obj and importing using the ObjLoader shows correct behavior with the above shader. Exporting the same object using the JSON exporter causes the normal error. Also note that Blender's default .obj exporter gives you an option for "forward" and "up" vectors:
I'm not sure if these are the reason that the .obj export works correctly, but it seems suspicious that flipping vectors was mentioned in an older ticket.
I do not currently have a live running version of the json export using the shader, but I can provide one if it's required for debugging.
Three.js version
- ✅ Dev
- ✅ r75
Browser
- ✅ All of them
OS
- ✅ All of them