gpt4 book ai didi

Swift 错误 - 尝试将父节点添加为子节点

转载 作者:可可西里 更新时间:2023-11-01 00:54:32 25 4
gpt4 key购买 nike

我正在尝试获取我拥有的 .dae 文件,并在它识别出我在照片中拥有的第一个图像文件后显示它。不幸的是,我收到一个错误,指出父节点被添加为子节点,但我不明白这是在哪里发生的。

有什么想法吗?

import UIKit
import SceneKit
import ARKit

class PlaneTrackingViewController: UIViewController, ARSCNViewDelegate {

@IBOutlet weak var ARPlaneView: ARSCNView!

override func viewDidLoad() {
super.viewDidLoad()

ARPlaneView.delegate = self

let scene = SCNScene(named: "Art.scnassets/LoadScene.scn")!

ARPlaneView.scene = scene
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

let configuration = ARImageTrackingConfiguration()

guard let trackedImages = ARReferenceImage.referenceImages(inGroupNamed: "Photos", bundle: Bundle.main) else {print ("No Images Available")
return
}

configuration.trackingImages = trackedImages
configuration.maximumNumberOfTrackedImages = 1
ARPlaneView.session.run(configuration)
}

override func viewWillDisappear(_ animated: Bool) {
ARPlaneView.session.pause()
}

func renderer(_ renderer:SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()

if let imageAnchor = anchor as? ARImageAnchor {
let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)

plane.firstMaterial?.diffuse.contents = UIColor(white: 1, alpha: 0.6)

let planeNode = SCNNode(geometry: plane)
planeNode.eulerAngles.x = -.pi / 2

let motorScene = SCNScene(named: "Art.scnassets/ACMotor/ACMotor.dae")!
let motorNode = motorScene.rootNode.childNodes.first!

motorNode.position = SCNVector3Zero
motorNode.position.z = 0.3

motorNode.addChildNode(motorNode)
node.addChildNode(planeNode)
}
return node
}
}

最佳答案

It should be written this way: scene.rootNode.addChildNode(node)

或者在你的情况下:

motorScene.rootNode.addChildNode(motorNode)

关于Swift 错误 - 尝试将父节点添加为子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52653791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com