在 ARKit 中加载 3D 对象需要多少文件?

How many files are required to load 3D object in ARKit?

我正在我的应用程序中加载 3D 模型(3D 模型是从下载的示例应用程序中复制的),但是示例应用程序正在运行,当我尝试更改模型文件时,模型不显示。

在 Apple 示例 AR 应用程序和许多其他示例代码中,我们看到有用于加载任何 3D 模型的 .scn 或 .dae 文件。

我的问题是除了 .scn 或 .dae 文件之外,还需要哪些文件来加载对象?我是否遗漏了一些要包含在我的演示应用程序中的文件?

这是我加载 3D 对象文件的解决方案。

@IBOutlet weak var sceneView: ARSCNView!
private var modelNode: SCNNode!


@objc func addObjectToSceneView(withGestureRecognizer recognizer: UIGestureRecognizer) {

    let tapLocation = recognizer.location(in: sceneView)

    let hitTestResults = sceneView.hitTest(tapLocation, types: .existingPlaneUsingExtent)

    guard let hitTestResult = hitTestResults.first else { return }
    let translation = hitTestResult.worldTransform.translation
    let x = translation.x
    let y = translation.y
    let z = translation.z

    // For load .scn file 
    let tempScene = SCNScene(named:"art.scnassets/cat/cat.scn”)
    modelNode = tempScene.rootNode
    modelNode.position = SCNVector3(x,y,z)
    sceneView.scene.rootNode.addChildNode(modelNode)

    //For load .dae file
    let tempScene = SCNScene(named: "art.scnassets/Petroleum_Lamp/Petroleum_Lamp.dae")
    modelNode = tempScene.rootNode.childNode(withName: "Lamp", recursively: true)!
    modelNode.position = SCNVector3(x,y,z)
    sceneView.scene.rootNode.addChildNode(modelNode)   
  }

您可以从这里将 .dae/.obj 转换为 .scn.. enter image description here