-
-
Save sturdysturge/9f20228850630c1a62334b184f70f14c to your computer and use it in GitHub Desktop.
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
import SwiftUI | |
import RealityKit | |
struct ARViewContainer: UIViewRepresentable { | |
func createPreview(boxAnchor: Experience.Box, arView: ARView) -> ARView { | |
guard let steelBox = boxAnchor.steelBox else { return arView } | |
let cameraAnchor = AnchorEntity(.camera) | |
arView.scene.anchors.append(cameraAnchor) | |
cameraAnchor.addChild(steelBox) | |
var transform = steelBox.transform | |
transform.translation = SIMD3<Float>(0,0,1.86) | |
steelBox.move(to: transform, relativeTo: nil) | |
return arView | |
} | |
func makeUIView(context: Context) -> ARView { | |
let arView = ARView(frame: .zero) | |
guard let boxAnchor = try? Experience.loadBox() else { return arView } | |
#if targetEnvironment(simulator) | |
return createPreview(boxAnchor: boxAnchor, arView: arView) | |
#else | |
arView.scene.anchors.append(boxAnchor) | |
return arView | |
#endif | |
} | |
func updateUIView(_ uiView: ARView, context: Context) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment