Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created January 9, 2021 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturdysturge/9f20228850630c1a62334b184f70f14c to your computer and use it in GitHub Desktop.
Save sturdysturge/9f20228850630c1a62334b184f70f14c to your computer and use it in GitHub Desktop.
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