【发布时间】:2020-04-13 18:20:26
【问题描述】:
我想使用 iOS SceneKit 加载对象。
我如何卸载加载的对象并重新加载另一个对象?
参考代码below,我成功加载了对象。
func sceneSetup() {
if let filePath = Bundle.main.path(forResource: "Smiley", ofType: "scn") {
let referenceURL = URL(fileURLWithPath: filePath)
self.contentNode = SCNReferenceNode(url: referenceURL)
self.contentNode?.load()
self.head.morpher?.unifiesNormals = true // ensures the normals are not morphed but are recomputed after morphing the vertex instead. Otherwise the node has a low poly look.
self.scene.rootNode.addChildNode(self.contentNode!)
}
self.faceView.autoenablesDefaultLighting = true
// set the scene to the view
self.faceView.scene = self.scene
// allows the user to manipulate the camera
self.faceView.allowsCameraControl = false
// configure the view
self.faceView.backgroundColor = .clear
}
但我不知道如何加载和切换多个对象。
我在项目中添加了testScene.scn并添加了如下代码,但是只加载了第一个指定的对象。
var charaSelect = "Smiley"
//tapEvent(ViewDidLoad)
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(FaceGeoViewController.tapped(_:)))
tapGesture.delegate = self
self.view.addGestureRecognizer(tapGesture)
//tap
@objc func tapped(_ sender: UITapGestureRecognizer)
{
self.charaSelect = "testScene"
}
func sceneSetup() {
if let filePath = Bundle.main.path(forResource: self.charaSelect, ofType: "scn") {
let referenceURL = URL(fileURLWithPath: filePath)
self.contentNode = SCNReferenceNode(url: referenceURL)
self.contentNode?.load()
self.head.morpher?.unifiesNormals = true // ensures the normals are not morphed but are recomputed after morphing the vertex instead. Otherwise the node has a low poly look.
self.scene.rootNode.addChildNode(self.contentNode!)
}
self.faceView.autoenablesDefaultLighting = true
// set the scene to the view
self.faceView.scene = self.scene
// allows the user to manipulate the camera
self.faceView.allowsCameraControl = false
// configure the view
self.faceView.backgroundColor = .clear
}
我该怎么办?
【问题讨论】:
-
您好,我想澄清一下,您想放置几个对象并同时删除其中一些吗?谢谢