Created
January 23, 2022 05:47
-
-
Save ynagatomo/44a1cdcd63fee9db00bbb69b1122f200 to your computer and use it in GitHub Desktop.
A minimal AR view.
This file contains 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
// 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