我有一个简单的触摸检测方法,该方法应该更改被触摸节点的颜色。
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
let touch = touches.first as! UITouch
let point = touch.locationInView(view)
let options: [NSObject : AnyObject] = [
SCNHitTestFirstFoundOnlyKey: NSNumber(bool: true),
SCNHitTestSortResultsKey: NSNumber(bool: true)
]
if let results = sceneView.hitTest(point, options: options) as? [SCNHitTestResult] {
if let result = results.first {
// Red color material
let material = SCNMaterial()
material.diffuse.contents = UIColor.redColor()
// Assign it to the node
result.node.geometry?.firstMaterial = material
}
}
}
我的节点层次结构包含一个使用自定义
SCNGeometry
制成的节点和8个具有常规SCNBox
几何形状的节点。let boxGeometry = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)
let boxNode = SCNNode(geometry: boxGeometry)
boxNode.position = SCNVector3(x: vector.x, y: vector.y, z: vector.z)
这是几个触摸屏幕框后颜色变化的屏幕截图。图案闪烁并在每次旋转时改变。
这种奇怪的颜色模式是什么原因造成的?我只希望它保持纯色。
最佳答案
在我看来,您彼此之间有两个节点-盒子的数量并不等于您在问题中指定的数量。