我有一个简单的触摸检测方法,可以改变被触摸节点的颜色。
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)
下面是我触摸一个框后颜色如何变化的几个屏幕截图。图案在每次旋转时闪烁和变化。
这种奇怪的颜色模式的原因是什么?我只希望它保持纯色。
最佳答案
在我看来你有两个节点在彼此内部 - 框的数量与你在问题中指定的数量不相加。
关于ios - SceneKit Material 中充满了随机图案,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29943324/