I'm trying to use RealityKit and SwiftUI to place an object of a specified size in AR. However, the object is displayed a little smaller than the size specified in the code. How can I get the object to display at the correct size?
Here is the current code:
func addObject() {
let mesh = MeshResource.generateBox(width: Float(1.0),
height: Float(1.0),
depth: Float(1.0))
let material = SimpleMaterial(color: .gray,
roughness: 0.5,
isMetallic: true)
let modelEntity = ModelEntity(mesh: mesh,
materials: [material])
let anchorEntity = AnchorEntity(plane: .horizontal)
modelEntity.generateCollisionShapes(recursive: true)
self.installGestures([.rotation, .translation] ,for: modelEntity)
anchorEntity.name = "BoxAnchor"
anchorEntity.addChild(modelEntity)
self.scene.addAnchor(anchorEntity)
}
I have confirmed that I am able to detect the plane correctly using ARCoachingOverlayView and FocusEntity.
Any advices are helpful. Thanks.