Home > Blockchain >  RealityKit – Face Anchor not putting model in AR
RealityKit – Face Anchor not putting model in AR

Time:06-20

I am using RealityKit face anchors. I downloaded a model from SketchFab but I am trying to put the model on the face it does not work and does not display anything.

struct ARViewContainer: UIViewRepresentable {
    
    func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
        
        let configuration = ARFaceTrackingConfiguration()
        arView.session.run(configuration)
        
        let anchor = AnchorEntity(.face)
        let model = try! Entity.loadModel(named: "squid-game")
        
        anchor.addChild(model)
        arView.scene.addAnchor(anchor)           
        return arView
    }       
    func updateUIView(_ uiView: ARView, context: Context) { }
}

CodePudding user response:

  1. One of the most common problems that AR developers can deal with is model size. In RealityKit, ARKit, RoomPlan & SceneKit, the working units are meters. Quite often models created in 3dsMax or Blender are imported into Xcode in centimeter scale. Therefore, they are 100 times bigger than they should be. You cannot see your model because you may be inside it and its inner surface of shader is not rendered in RealityKit. So, all you need is to scale the size of the model.

     anchor.scale /= 100
    
  2. The second common problem is a pivot point's location. In 99% of cases, the pivot should be inside the model. Model's pivot is like a "dart", and .face anchor is like "10 points". Unfortunately, RealityKit 2.0 does not have the ability to control the pivot. SceneKit does.

  3. There are also hardware constraints. Run the following simple check:

     if !ARFaceTrackingConfiguration.isSupported {
         print("Your device isn't supported")
     } else {
         let config = ARFaceTrackingConfiguration()
         arView.session.run(config)
     }
    
  4. I also recommend you open your .usdz model in Reality Composer app to make sure it can be successfully loaded and is not 100% transparent.

CodePudding user response:

  1. try to check your model
  2. is there any error when you run the demo
  3. you can use a .reality file to test, and you can also download sample in apple developer site
  • Related