{"record":{"id":"4792e406ea0a02a8","repo":"bevyengine/bevy","slug":"cannot-generate-tangents-for-0","errorCode":null,"errorMessage":"cannot generate tangents for {0:?}","messagePattern":"cannot generate tangents for (.+?)","errorType":"exception","errorClass":"GenerateTangentsError","httpStatus":null,"severity":"error","filePath":"crates/bevy_mesh/src/mikktspace.rs","lineNumber":65,"sourceCode":"    fn tex_coord(&self, face: usize, vert: usize) -> [f32; 2] {\n        self.uvs[self.index(face, vert)]\n    }\n\n    fn set_tangent(\n        &mut self,\n        tangent_space: Option<bevy_mikktspace::TangentSpace>,\n        face: usize,\n        vert: usize,\n    ) {\n        let idx = self.index(face, vert);\n        self.tangents[idx] = tangent_space.unwrap_or_default().tangent_encoded();\n    }\n}\n\n#[derive(Error, Debug)]\n/// Failed to generate tangents for the mesh.\npub enum GenerateTangentsError {\n    #[error(\"cannot generate tangents for {0:?}\")]\n    UnsupportedTopology(PrimitiveTopology),\n    #[error(\"missing indices\")]\n    MissingIndices,\n    #[error(\"missing vertex attributes '{0}'\")]\n    MissingVertexAttribute(&'static str),\n    #[error(\"the '{0}' vertex attribute should have {1:?} format\")]\n    InvalidVertexAttributeFormat(&'static str, VertexFormat),\n    #[error(\"mesh not suitable for tangent generation\")]\n    MikktspaceError(#[from] bevy_mikktspace::GenerateTangentSpaceError),\n    #[error(\"Mesh access error: {0}\")]\n    MeshAccessError(#[from] MeshAccessError),\n}\n\npub(crate) fn generate_tangents_for_mesh(\n    mesh: &Mesh,\n) -> Result<Vec<[f32; 4]>, GenerateTangentsError> {\n    match mesh.primitive_topology() {\n        PrimitiveTopology::TriangleList => {}","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_mesh/src/mikktspace.rs#L47-L83","documentation":"GenerateTangentsError::UnsupportedTopology (crates/bevy_mesh/src/mikktspace.rs:65), returned by Mesh::compute_tangents / generate_tangents_for_mesh. The mikktspace tangent-generation algorithm walks triangles by index triplets, so the mesh must use PrimitiveTopology::TriangleList; any other topology is rejected with the offending variant embedded in the error.","triggerScenarios":"Calling mesh.compute_tangents() on a mesh created with PrimitiveTopology::TriangleStrip, PointList, LineList or LineStrip. The match at mikktspace.rs:83 sends every non-TriangleList topology into this error before any attribute is read.","commonSituations":"Normal-mapping a strip-optimized custom mesh to save index memory; accidentally reusing a 2D/line mesh constructor for a 3D shaded asset; importers that emit strips for legacy data.","solutions":["Build the mesh with PrimitiveTopology::TriangleList before compute_tangents()","Convert strip indices to triangle-list indices (expand each consecutive triple) and re-insert via insert_indices","Skip tangent generation for non-triangle meshes (tangents are meaningless for lines/points)"],"exampleFix":"// before\nlet mut mesh = Mesh::new(PrimitiveTopology::TriangleStrip, RenderAssetUsages::default());\n// ...positions, normals, uvs, indices...\nmesh.compute_tangents(); // Err(UnsupportedTopology(TriangleStrip))\n\n// after\nlet mut mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::default());\n// ...same attributes...\nmesh.compute_tangents().unwrap();","handlingStrategy":"validation","validationCode":"if mesh.primitive_topology() == PrimitiveTopology::TriangleList {\n    mesh.compute_tangents()?;\n} else {\n    // convert to triangle list or skip tangents\n}","typeGuard":"fn is_triangle_list(mesh: &Mesh) -> bool {\n    matches!(mesh.primitive_topology(), PrimitiveTopology::TriangleList)\n}","tryCatchPattern":"if let Err(GenerateTangentsError::UnsupportedTopology(topo)) = mesh.compute_tangents() {\n    bevy::log::error!(\"compute_tangents needs TriangleList, got {topo:?}\");\n}","preventionTips":["Use PrimitiveTopology::TriangleList for any mesh that will be normal-mapped","Expand strip indices to triangle lists at import time","Remember points/lines cannot have meaningful tangents at all"],"tags":["bevy","mesh","tangents","mikktspace","primitive-topology","mismatch"],"backgroundTag":"primitive-topology-mismatch","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}