can't render .obj mesh
Hi, I want to load an object with the three_d_asset load utility and display it in my 3d environment. I'm loading the object as a mesh so I can translate and rotate it before adding it to a Gm, and all of this works, but when I call frame_input().screen().render() on it, I get the error
thread 'main' panicked at 'the uniform normalMatrix is sent to the shader but not defined or never used'
I haven't found a way around this order yet, and an not sure what it means. For reference, the version of three_d and three_d_asset I am using is
three-d = "0.15.0"
three-d-asset = {version="0.5.0", features=["obj"]}
Would greatly appreciate any pointers here!
Thanks for reporting 🙏 can you try to update to version 0.16 and see if it's still a problem? I guess the mesh you are loading doesn't contain normals?
Thanks for the tip! My project currently uses 0.15.0, and it looks like I can't update three-d to 0.16.1 for my project, as that breaks too many things in my project. For the mesh, I'm loading from a .obj and .mtl that I export out of Blender. This is the code I'm using to load an obj mesh:
let mut bot_model_mesh: CpuMesh = raw_assets.deserialize("smallbot.obj").unwrap();
let mat4_from_pose: Matrix4<f32> = isometry_to_matrix(pose);
bot_model_mesh.transform(&mat4_from_pose).unwrap();
Rc::new(Gm::new(
Mesh::new(context, &bot_model_mesh),
PhysicalMaterial::default(),
))
and the error occurs on the frame_input render call,
frame_input.screen().render(camera, vec![bot_model], &[]);
It's not a great error message, but the problem is probably that your mesh doesn't contain any normals, at least please check that! The PhysicalMaterial requires normals, so you need to have them on the mesh. You can compute them by bot_model_mesh.compute_normals().
three-d = "0.16.3"
Btw, this problem is reproducible with the shapes example by removing the lights on
https://github.com/asny/three-d/blob/master/examples/shapes/src/main.rs#L115 (playground)
Or by changing one light to AmbientLight and removing the other light (playground)
Having both lights as AmbientLight triggers a different error
@rcywongaa I don't get that error when removing the lights on the shapes example, my guess is that you are on Linux or Chrome OS? The shader compilers are different depending on the OS.
I've tried fixing this particular error in https://github.com/asny/three-d/commit/17b1f13c317b8bed145c4d597a0eaa97e1ff2282 but since I can't reproduce, it's difficult to know if I solved both of your problems (they might be different problems). At least it should work on Linux/Chrome OS now.