目前我正在研究具有复制 AR 对象功能的基于 AR 的项目,我遇到的问题是当我使用 .clone() 方法克隆 SCNNode ...它创建相同的实例并且当我更改重复的 SCNNode 的名称时,它更改所有节点的名称.. 我如何克隆具有不同名称、模型名称等属性的 SCNNode?
基本上我想要每个克隆的虚拟对象的特定属性来删除对象..
放置对象的代码
func placeVirtualObject(_ virtualObject: VirtualObject) {
guard let cameraTransform = session.currentFrame?.camera.transform,
let focusSquarePosition = focusSquare.lastPosition else {
statusViewController.showMessage("CANNOT PLACE OBJECT\nTry moving left or right.")
return
}
Api.Params.selectedModel = virtualObject
virtualObject.name = String(Api.Params.inputPreviewId)
virtualObject.scale = SCNVector3Make(0.01, 0.01, 0.01)
virtualObject.setPosition(focusSquarePosition, relativeTo: cameraTransform, smoothMovement: false)
updateQueue.async {
self.sceneView.scene.rootNode.addChildNode(virtualObject)
}
}
用于复制节点
func placeDuplicateVirtualObject(_ virtualObject: VirtualObject) {
guard let cameraTransform = session.currentFrame?.camera.transform,
let focusSquarePosition = focusSquare.lastPosition else {
statusViewController.showMessage("CANNOT PLACE OBJECT\nTry moving left or right.")
return
}
Api.Params.selectedModel = virtualObject
let duplicate = virtualObject.clone()
duplicate.name = String(Api.Params.inputPreviewId)
duplicate.scale = SCNVector3Make(0.01, 0.01, 0.01)
duplicate.setPosition(focusSquarePosition, relativeTo: cameraTransform, smoothMovement: false)
updateQueue.async {
self.sceneView.scene.rootNode.addChildNode(duplicate)
}
}