SCNVertexSemanticTangent is not defined in the vertex descriptor

Hello,


I'm using SceneKit with metal and when i want to access the tangent vector, i get the following error:

Vertex attribute 2 is not defined in the vertex descriptor


The documentation says that the tangent vector is infered from the normal and texture coordinates (i have both)

Am i missing something or is this simply a bug of iOS9?


Sincerely

Replies

You can get round this by using ModelIO to create your geometry, and using its methods to compute tangents. This seems to work:


import SceneKit
import ModelIO
import SceneKit.ModelIO // not sure why this is needed

let mesh = MDLMesh(sphereWithExtent: float3(repeating: 1), segments: uint2(32, 16), inwardNormals: false, geometryType: .triangles, allocator: nil)
  mesh.addTangentBasis(forTextureCoordinateAttributeNamed: MDLVertexAttributeTextureCoordinate, normalAttributeNamed: MDLVertexAttributeNormal, tangentAttributeNamed: MDLVertexAttributeTangent)
  let sphere = SCNGeometry(mdlMesh: mesh)