1

我使用以下代码在 AR 中显示 USDZ 模型:

class ViewController: UIViewController {

@IBOutlet var sceneView: ARSCNView!

override func viewDidLoad() {
    super.viewDidLoad()

    sceneView.autoenablesDefaultLighting = true
    sceneView.scene = SCNScene(named: "art.scnassets/model.usdz")!
    sceneView.session.run(ARWorldTrackingConfiguration())
}

但是模型太大了。我该如何扩展它?

4

1 回答 1

0

尝试这个:

override func viewDidLoad() {
    super.viewDidLoad()
    
    let sceneView = self.view as! SCNView

    let scene = SCNScene()
    sceneView.scene = scene
    sceneView.backgroundColor = .darkGray
    sceneView.allowsCameraControl = true
    sceneView.autoenablesDefaultLighting = true
    
    // Fighter
    let fighterScene = SCNScene(named: "art.scnassets/ship.scn")!
    
    let fighterNode = fighterScene.rootNode.childNode(withName: "fighter", 
                                                   recursively: true)
    
    fighterNode?.scale = SCNVector3(0.3, 0.3, 0.3)
    
    scene.rootNode.addChildNode(fighterNode!)

    // ...
}

在此处输入图像描述

在此处输入图像描述

于 2021-06-18T01:45:28.540 回答