Skip to content

Instantly share code, notes, and snippets.

@ynagatomo
Created January 23, 2022 05:47
Show Gist options
  • Save ynagatomo/44a1cdcd63fee9db00bbb69b1122f200 to your computer and use it in GitHub Desktop.
Save ynagatomo/44a1cdcd63fee9db00bbb69b1122f200 to your computer and use it in GitHub Desktop.
A minimal AR view.
// ARSpaceView.swift
import SwiftUI
import RealityKit
import ARKit
struct ARSpaceView: UIViewRepresentable {
let modelName = "InsideISS.usdz"
let modelPosition = SIMD3<Float>([0, 0, 0]) // [meters]
func makeUIView(context: Context) -> some UIView {
let arView = ARView(frame: .zero)
let anchorEntity = AnchorEntity(world: modelPosition)
arView.scene.addAnchor(anchorEntity)
do {
let modelEntity = try Entity.load(named: modelName)
anchorEntity.addChild(modelEntity)
} catch {
assertionFailure("could not load assets.")
}
let config = ARWorldTrackingConfiguration()
arView.session.run(config)
return arView
}
func updateUIView(_ uiView: UIViewType, context: Context) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment