I am working with MeshAnchors, and I am having troubles getting to the classification of the triangles/faces.
This post references the MeshAnchor.Geometry, and that struct does have a property named "classifications", but it is of type GeometrySource. I cannot find any classification information in GeometrySource. Am I missing something there?
I think I am looking for something of type MeshAnchor.MeshClassification, but I cannot find any structs with this as a property.
You are on the right track. Here are two extensions which should get you the mesh classification of a single face in the mesh (I haven't tested it!):
extension GeometrySource {
subscript(_ index: Int32) -> CUnsignedChar {
precondition(format == .uchar, "This subscript operator can only be used on GeometrySource instances with format .uchar")
return buffer.contents().advanced(by: offset + (stride * Int(index))).assumingMemoryBound(to: CUnsignedChar.self).pointee
}
}
extension MeshAnchor {
public func classificationOf(face index: Int32) -> MeshAnchor.MeshClassification? {
guard let classifications = self.geometry.classifications else { return nil }
let classification = classifications[index]
return MeshAnchor.MeshClassification(rawValue: Int(classification)) ?? nil
}
}