我正在尝试将 SCNNode 拖动到拖动位置的当前场景中。
var currentBlock: SCNNode?
@objc func handlePan (gesture: UIPanGestureRecognizer) {
// Location of Pan
var location = gesture.location(in: self.sceneView)
switch gesture.state {
case .began:
// Add Node Reference, add Node to Scene
if redBlockUI?.frame.contains(location) == true {
currentBlock = createBlock(color: .red, location: location)
}
case .changed:
// Drag Node Here
currentBlock?.position = SCNVector3(location.x, location.y, -1)
case .ended:
// Remove Node Reference (Don't delete from Scene)
currentBlock = nil
default: break
}
}
func createBlock (color: UIColor, location: CGPoint) -> SCNNode {
// Make Geometry
let block: SCNGeometry = SCNBox(width: 10.0, height: 10.0, length: 10.0, chamferRadius: 1.0)
block.materials.first?.diffuse.contents = color
// Attach Geometry to SCNNode
let blockNode = SCNNode(geometry: block)
blockNode.position = SCNVector3(location.x, location.y, -1)
// Add to scene
sceneView.scene.rootNode.addChildNode(blockNode)
return blockNode
}
但是,该对象不是在此位置创建的。我需要进行某种点转换吗?谢谢!