'How retrieve the normal for a given face of ARMeshGeometry?
given a ARMeshAnchor 'meshAnchor', i can retrieve its geometry and faces :
let geometry = meshAnchor.geometry
let faces = geometry.faces
var i = Int(0)
while i < faces.count
{
//??? get the normal of faces[i]
i = i+1
}
how can I retrieve the normal in world coordinates of faces[i] ?
Is there 1 normal per face ? per vertex of each triangle ? or per each vertex of the mesh ?
According to Apple : https://developer.apple.com/documentation/arkit/armeshgeometry/3516923-normals
var normals: ARGeometrySource { get }
= Rays that define which direction is outside for each face
Solution 1:[1]
This was my solution. I used the int32 from the mesh anchor of the face geometry. This solution should run without an error. I was able to get a correct solution. Like I tested it by using the mesh surface created with scene understanding then getting a mesh face that was on the floor and it returned 0,1,0 (y is up direction) which is right! btw I used .first because there are 3 faces stored in the array due to the 3 verticies of a triangle. and their normals are all the same since its a plane.
for index in 0..<anchor.geometry.faces.count {
let x = anchor.geometry.normals[anchor.geometry.faces[index].first!].0
let y = anchor.geometry.normals[anchor.geometry.faces[index].first!].1
let z = anchor.geometry.normals[anchor.geometry.faces[index].first!].2
let normal = SIMD3(x, y, z)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bhavin p |