RealityKit–面部锚不在AR中放置模型

发布于 2025-02-08 23:13:43 字数 663 浏览 2 评论 0原文

我正在使用RealityKit面部锚。我从Sketchfab下载了一个模型,但我试图将模型放在脸上不起作用,并且没有显示任何内容。

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) { }
}

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) { }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

衣神在巴黎 2025-02-15 23:13:43
  1. AR开发人员可以处理的最常见问题之一是模型大小。在RealityKit,Arkit,Roomplan& Scenekit,工作单元是米。经常以3DSMAX或搅拌机创建的模型以厘米级将XCode导入到Xcode中。因此,它们比应有的大100倍。您看不到模型,因为您可能在其中,并且其内部着色器的内表面没有在RealityKit中呈现。因此,您只需要扩展模型的大小。

     锚点 /= 100
     
  2. 第二个常见问题是枢轴点的位置。在99%的情况下,枢轴应在模型内部。 Model的枢轴就像“飞镖”,.face锚点就像“ 10分”。不幸的是,RealityKit 2.0无法控制枢轴。 Scenekit做。

  3. 也有硬件约束。运行以下简单检查:

      if!arfacetrackingConfiguration.issupported {
         打印(“不支持您的设备”)
     } 别的 {
         令config = arfacetrackingConfiguration()
         arview.session.run(config)
     }
     
  4. 我还建议您在COMPOSER应用中打开.usdz模型,以确保它可以成功加载并且不是100%透明的。

  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.

话少情深 2025-02-15 23:13:43
  1. 检查您的模型。
  2. 运行演示时,是否有任何错误
  3. 您可以使用.reality文件进行测试,还可以从Apple开发人员网站下载示例。
  1. 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 a sample from the Apple Developer site.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文