You can use simple planes if you want but you have to account for the fact that the anchor is not necessarily the center of the plane.
You will still get a "bounding box" style representation and there may be some over/under lap but it should be much closer to what you were expecting.
Something like the following should work for you on both vertical and horizontal planes.
The relevant line is the setTransformationMatrix
entity.setTransformMatrix(
anchor.originFromAnchorTransform * anchor.geometry.extent.anchorFromExtentTransform,
relativeTo: nil)
if generateSimplifiedPlanes {
let mesh: MeshResource = try! await MeshResource.generatePlane(
width: anchor.geometry.extent.width,
height: anchor.geometry.extent.height)
modelEntity.model?.mesh = mesh
modelEntity.collision?.shapes = [try! await ShapeResource.generateStaticMesh(from: mesh)]
entity.setTransformMatrix(
anchor.originFromAnchorTransform * anchor.geometry.extent.anchorFromExtentTransform,
relativeTo: nil)
}
else {
let shape: ShapeResource = try! await ShapeResource.generateStaticMesh(
positions: anchor.geometry.meshVertices.asSIMD3(ofType: Float.self),
faceIndices: anchor.geometry.meshFaces.asUInt16Array())
modelEntity.collision?.shapes = [shape]
modelEntity.model?.mesh = planeAnchorToMeshResource(anchor)
entity.transform = Transform(matrix: anchor.originFromAnchorTransform)
}
Notes:
It appears that the extent is always defined on a vertical plane so if you apply anchorFromExtentTransform you always want to use a vertical plane.
This is rough code from a while ago and I haven't checked to see if there are newer/easier ways to do this.
Topic:
Spatial Computing
SubTopic:
ARKit