SceneKit_大神03_navigationbar上的3D文字
让学习成为一种习惯
先认识一个方法,这个方法在SCNView 里面
public func hitTest(_ point: CGPoint, options: [SCNHitTestOption : Any]? = nil) -> [SCNHitTestResult]
当我们手点击屏幕时,要知道我们都点到了那些节点,我们应该怎么处理呢?
首先我们添加一个手势到视图中去
let tap = UITapGestureRecognizer(target: self, action: #selector(tapHandle(gesture:)))
scnView.addGestureRecognizer(tap)
然后,我们获取点击到的第一个节点
func tapHandle(gesture:UITapGestureRecognizer){
let results:[SCNHitTestResult] = (self.scnView?.hitTest(gesture.location(ofTouch: 0, in: self.scnView), options: nil))!
guard let firstNode = results.first else{
return
}
// 点击到的节点
print(firstNode.node)
}
open class SCNHitTestResult : NSObject {
/// 击中的几点
open var node: SCNNode { get }
/// 击中的几何体索引
open var geometryIndex: Int { get }
/// 击中的面的索引
open var faceIndex: Int { get }
/// 击中的本地坐标系统
open var localCoordinates: SCNVector3 { get }
/// 击中的世界坐标系统
open var worldCoordinates: SCNVector3 { get }
/// 击中节点的本地法线坐标
open var localNormal: SCNVector3 { get }
/// 击中的世界坐标系统的法线坐标
open var worldNormal: SCNVector3 { get }
/*! World transform of the node intersected. */
open var modelTransform: SCNMatrix4 { get }
/*! The bone node hit. Only available if the node hit has a SCNSkinner attached. */
@available(iOS 10.0, *)
open var boneNode: SCNNode { get }
/*!
@method textureCoordinatesWithMappingChannel:
@abstract Returns the texture coordinates at the point of intersection, for a given mapping channel.
@param channel The texture coordinates source index of the geometry to use. The channel must exists on the geometry otherwise {0,0} will be returned.
*/
open func textureCoordinates(withMappingChannel channel: Int) -> CGPoint
}
我们看出来,通过这个方法可以获取的信息还是蛮多的,gei'qu