RealityKit - 在ARView中放置模型时出现运行时警告

12

当我点击ARView中的模型进行加载时,运行时出现以下警告:警告(次要线程):在sdf/path.cpp的第859行的AppendProperty中--只能将属性“preliminary:anchoring:type”附加到prim路径(/) 警告(次要线程):在sdf/path.cpp的第859行的AppendProperty中--只能将属性“triggers”附加到prim路径(/)

有人知道为什么会出现这个警告吗?所有逻辑都在我的ViewController中:

import UIKit
import ARKit
import RealityKit
import SwiftUI
import Combine

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate  {

private var modelArray: [String] = []
var selectedModel = ""

@IBOutlet weak var arView: ARView!

@IBOutlet weak var modelCollectionView: UICollectionView!

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    
    loadModelName()
    arView.session.delegate = self
    setupARView()
    //modelArray = getModelNames()
    self.modelCollectionView.dataSource = self
    self.modelCollectionView.delegate = self
    arView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTap(recognizer:))))
    
}
 // Dynamically load available files from directory
func loadModelName() {
    
    let fm = FileManager.default
    let path = Bundle.main.resourcePath!

    do {
        let items = try fm.contentsOfDirectory(atPath: path)

        for item in items where item.hasSuffix("usdz"){
            let modelName = item.replacingOccurrences(of: ".usdz", with: "")
            print("Found \(item)")
            modelArray.append(modelName)
        }
    } catch {
        // failed to read directory – bad permissions, perhaps?
    }
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return modelArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "item", for: indexPath) as! itemCell
        cell.itemImage.image = UIImage(named: self.modelArray[indexPath.row])
        return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let cell = collectionView.cellForItem(at: indexPath)
    cell?.backgroundColor = UIColor.lightGray
    selectedModel = self.modelArray[indexPath.row] + ".usdz"
}
func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
    let cell = collectionView.cellForItem(at: indexPath)
    cell?.backgroundColor = UIColor.white
}



 func setupARView() {
        arView.automaticallyConfigureSession = false
        let configuration  = ARWorldTrackingConfiguration()
        configuration.planeDetection = [.horizontal, .vertical]
        configuration.environmentTexturing = .automatic
        if ARWorldTrackingConfiguration.supportsSceneReconstruction(.mesh) {
            print("scene reconstruction supported")
            configuration.sceneReconstruction = .mesh
            configuration.sceneReconstruction = .meshWithClassification
            arView.debugOptions.insert(.showSceneUnderstanding)
        }
        arView.session.run(configuration)
        print("plane detection")
    }



 @objc
    func handleTap(recognizer: UITapGestureRecognizer) {
        //gets the location in the arView
        let location = recognizer.location(in: arView)
        //grab the results of the tap -location: the location of the tap -allowing: tye type of surface to calculate the location -alignment: the type of surface
        let reults = arView.raycast(from: location, allowing: .estimatedPlane, alignment: .any)
        
    //check to see if the raycast returned a result, did it actually hit a horizontal surface
    if let firstResult = reults.first {
        //returns an array of all the things it finds so grab the first
        //in order to add objects into a scene, we have to add objects to anchors, firstResult.worldTransform - add anchor at the orientation and position
        print("tap gesture recognized")
        print("DEBUG: the model is \(selectedModel)")
        let anchor = ARAnchor(name: selectedModel, transform: firstResult.worldTransform)
        arView.session.add(anchor: anchor)
    } else {
        print("object placement failed, couldn't find surface")
    } 
}

func placeObject(named entityName: String, for anchor: ARAnchor) {
let entity = try! ModelEntity.loadModel(named: entityName)

    //add collision to have physiscs for manipulations
    entity.generateCollisionShapes(recursive: true)
    arView.installGestures([.rotation, .translation], for: entity)

    //create an anchor entity
    let anchorEntity = AnchorEntity(anchor: anchor)
    // add the entity to anchor
    anchorEntity.addChild(entity.clone(recursive: true))
    //add the anchor with the entity to the scene
    arView.scene.addAnchor(anchorEntity)
}
}

extension ViewController: ARSessionDelegate {
    func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
        for anchor in anchors {
            if let anchorName = anchor.name, anchorName == selectedModel {
                placeObject(named: anchorName, for: anchor)
            }
        }
    }
}

您正在添加的模型是一个有效的usdz文件吗? - Kevin Oswaldo
1
是的,它们是来自苹果的usdz模型。 - Myoung
1
嗨 @AndyJazz,不,我还没有试过,因为我正在处理其他项目,但我会在有机会的时候尝试一下,请谢谢你的帮助! - Myoung
1
@AndyJazz 啊!是的,这是个问题.. :( 但还是谢谢你回复我! - Myoung
1
@AndyJazz 我刚刚升级到最新的iOS系统,问题得到了解决!我猜只要不断更新,直到他们修复所有错误就可以了.. :) - Myoung
显示剩余3条评论
1个回答

2

关于警告

我会简要说明,答案是这样的:如果您为USDZ模型设置了初步锚定,则Xcode将不会打印此类警告。这些警告来自于USD C++库。

现在让我们更详细地讨论一下。正如您之前所说,在调试模式下运行AR应用程序时,Xcode的控制台会出现两个警告:

// Warning: in AppendProperty at line 859 of sdf/path.cpp - Can only append a 
// property 'preliminary:anchoring:type' to a prim path (/)

// Warning: in AppendProperty at line 859 of sdf/path.cpp - Can only append a
// property 'triggers' to a prim path (/)

您可以轻松地在Pixar/Apple的path.cpp文件中找到生成这些警告的C++语句(只需在Spotlight搜索字符串中键入该文件的名称)。以下是它:
SdfPath::AppendProperty(TfToken const &propName) const {
    if (ARCH_UNLIKELY(_propPart)) {
        TF_WARN("Can only append a property '%s' to a prim path (%s)",
                propName.GetText(), GetText());
        return EmptyPath();
    }
}

所以,重点是什么呢?让我引用苹果的文档:

初步定位API将锚点的中心指定为prim的原点,将锚点的顶部指定为其法向量指向。运行时需要资产提供此属性的值。


你可以在USDZ模式的故事中了解更多关于preliminary:anchoring:type的内容。
换句话说,如果您在场景中使用预先生成的锚点文件,无论是在Reality Composer中分配的锚点还是为 .usdz 场景定义的锚点,都不会收到此类消息。

Reality Composer也使用这些模式描述其USDZ导出中的AR功能...

关闭警告

如果这些消息真的很烦人,只需将它们关闭。

进入Xcode菜单Product - Scheme - Edit Scheme并添加您的环境变量。

OS_ACTIVITY_MODE = disable

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接