Created
August 22, 2022 08:49
-
-
Save elkraneo/ee849960853d4808c49e2b9a9a7bf0c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Mesh { | |
func insideProjectedPosition(in arView: ARView) -> Self { | |
guard !vertices.isEmpty, !faces.isEmpty else { return self } | |
var filteredFaces: [Mesh.Face] = [] | |
var filteredVertices: [SIMD3<Float>] = [] | |
for face in faces { | |
var verticesInsideBounds: [SIMD3<Float>] = [] | |
for vertexIndex in face.triangle { | |
let vertex = vertices[vertexIndex] | |
if let vertexPosition = arView.project(vertex) { | |
if arView.bounds | |
.inset(by: .init(top: 100, left: 100, bottom: 100, right: 100)) | |
.contains(vertexPosition) | |
{ | |
verticesInsideBounds.append(vertex) | |
} | |
} | |
} | |
if verticesInsideBounds.count == 3 { | |
filteredFaces.append(face) | |
filteredVertices.append(contentsOf: verticesInsideBounds) | |
} | |
} | |
return Mesh( | |
vertices: filteredVertices, | |
faces: filteredFaces | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment