我有一个swatch.scn文件,我正在尝试将它的几何图形添加到我的scene中。我必须抓取swatch.childNodes.first来获得正确的几何图形,然后我添加它,但在我的scene中什么也没有显示。我很想知道如何解决这个问题。谢谢!
extension SCNNode {
convenience init(named name: String) {
self.init()
guard let scene = SCNScene(named: name) else { return }
for childNode in scene.rootNode.childNodes {
addChildNode(childNode)
}
}
}
// in viewDidLoad
// Create a new scene
let scene = SCNScene(named: "art.scnassets/ship.scn")!
let swatch = SCNNode(named: "art.scnassets/swatch.scn")
let n = swatch.childNodes.first!
let geo = n.geometry!
print(n.geometry!) // <SCNGeometry: 0x281cb3b60 'bigger_swatch'>
n.position = SCNVector3(0, 0, -1)
n.scale = SCNVector3(3, 3, 3)
scene.rootNode.addChildNode(n)发布于 2019-08-09 15:54:29
尝尝这个
let swatch = SCNNode(named: "art.scnassets/swatch.scn")
swatch.position = SCNVector3(0, 0, -1)
swatch.scale = SCNVector3(3, 3, 3)
scene.rootNode.addChildNode(swatch)
// Note: your swatch-node holds the entire geometries from your file.
// You can do something like this:
print(swatch.childnodes.count)https://stackoverflow.com/questions/57420020
复制相似问题