In the RealityKit code below I expect the box to be positioned lower given the world translation I've applied to y. I think I'm misunderstanding what setWorldOrigin does. I want to redefine the coordinate mapping so that zero is in a different location. What am I doing/expecting incorrectly? Thanks.
let arView = ARView(frame: .zero, cameraMode: .nonAR)
arView.environment.background = .color(.white)
var relativeTransform = matrix_identity_float4x4
relativeTransform.columns.3.y = -1
arView.session.setWorldOrigin(relativeTransform: relativeTransform)
let material = SimpleMaterial(color: .gray, isMetallic: false)
let entity = ModelEntity(mesh: .generateBox(size: 0.3), materials: [material])
let anchor = AnchorEntity(world: .zero)
anchor.addChild(entity)
arView.scene.addAnchor(anchor)
Read this post for details.
ARSession is an AR object, so all session's properties and methods are working only when session is running. ARSession is meaningless in .nonAR
mode (i.e. VR mode), on macOS app, and in the Xcode Simulator. In your case, I suggest using the following scenario.
import UIKit
import RealityKit
class Camera: Entity, HasPerspectiveCamera, HasAnchoring {
required init() {
super.init()
self.camera = PerspectiveCameraComponent(near: 0.01,
far: 200.00,
fieldOfViewInDegrees: 50.0)
self.transform.translation.y = 0.5
self.transform.translation.z = 2.0
}
}
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
arView.environment.background = .color(.black)
let camera = Camera()
arView.scene.addAnchor(camera)
let entity = ModelEntity(mesh: .generateBox(size: 0.1))
let anchor = AnchorEntity(world: .zero)
anchor.addChild(entity)
arView.scene.addAnchor(anchor)
}
}
In RealityKit 2.0 using .ar
mode, you can't change far clipping plane
value.