Ios 如何从TouchsMoved方法获得在sceneview上绘制UIBezierpath的精确CGpoint?
UIBezierpath在现实世界中的其他地方显示 从下面的代码中收集CGPointIos 如何从TouchsMoved方法获得在sceneview上绘制UIBezierpath的精确CGpoint?,ios,scenekit,arkit,uibezierpath,swift4.2,Ios,Scenekit,Arkit,Uibezierpath,Swift4.2,UIBezierpath在现实世界中的其他地方显示 从下面的代码中收集CGPoint override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { guard let location = touches.first?.location(in: self.sceneView) else { return } arrayCG
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let location = touches.first?.location(in: self.sceneView) else {
return
}
arrayCGPoints.append(location)
}
func updateBazierPath(){
if arrayCGPoints.count > 0 {
let bezierPath = UIBezierPath()
var i : Int = 0
for varPoint in arrayCGPoints{
if i == 0 {
bezierPath.move(to: varPoint)
}
else{
bezierPath.addLine(to: varPoint)
}
i += 1
}
bezierPath.close()
}
// Add shape
let shape = SCNShape(path: bezierPath, extrusionDepth: 0.2)
let shapeNode = SCNNode(geometry: shape)
self.sceneView.scene.rootNode.addChildNode(shapeNode)
shapeNode.geometry?.firstMaterial?.isDoubleSided = true
shapeNode.geometry!.firstMaterial?.diffuse.contents = UIColor.blue
shapeNode.position.z = -0.2
shapeNode.eulerAngles.x = -.pi / 2
}
还尝试将点转换为米
arrayCGPoints.append(CGPoint(x: location.x/100, y: location.y/100))
仍然不工作这将在@0,0,0处绘制一个节点,勾勒出该人从中拖动的内容,将屏幕坐标转换为世界坐标。我创建了一个单独的SCInvector3数组,它们是3d空间中的坐标(您可以在屏幕上的这些点上放置一些节点来证明位置)。还要注意,追加是x,z,z(不是scenepoint.y)。我的相机从0,15,0.1看0,0,0。这至少会让你看到z发生了什么,希望能回答你提出的问题 如果您希望生成的形状与用户触摸的确切位置保持一致,这里没有解决这个问题
var shapeNode = SCNNode()
func updateBazierPath()
{
for vPoints in arrayCGPoints
{
let projectedPoint = gameScene.projectPoint(SCNVector3(0, 0, 0))
let scenePoint = gameScene.unprojectPoint(SCNVector3(vPoints.x, vPoints.y, CGFloat(projectedPoint.z)))
scenePoints.append(SCNVector3(scenePoint.x, scenePoint.z, scenePoint.z))
}
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: CGFloat(scenePoints[0].x), y: CGFloat(scenePoints[0].y)))
for vCount in 1...scenePoints.count - 1
{
bezierPath.addLine(to: CGPoint(x: CGFloat(scenePoints[vCount].x), y: CGFloat(scenePoints[vCount].y)))
}
bezierPath.close()
shapeNode.removeFromParentNode()
let shape = SCNShape(path: bezierPath, extrusionDepth: 0.5)
shapeNode = SCNNode(geometry: shape)
shapeNode.geometry?.firstMaterial?.isDoubleSided = true
shapeNode.geometry!.firstMaterial?.diffuse.contents = UIColor.yellow
//let action = SCNAction.repeatForever(SCNAction.rotate(by: .pi, around: SCNVector3(1, 0, 0), duration: 5))
//shapeNode.runAction(action)
shapeNode.position = SCNVector3(0, 0, 0)
shapeNode.eulerAngles.x = -.pi / 2
gNodes.gameNodes.addChildNode(shapeNode)
}
我尝试了您的解决方案,但线条显示出现问题,例如,我的z位置出现错误,对pathIs sceneview渲染的影响不正确