0
我有一个简单的触摸检测方法,应该改变被触摸节点的颜色。SceneKit素材被填充随机模式,为什么?
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
并用常规SCNBox
几何8个节点做出一个节点。
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)
下面是我触摸一个盒子后颜色变化情况的截图。图案在每次旋转时闪烁并改变。
这是什么奇怪的彩色图案的原因是什么?我只想让它保持纯色。
它看起来像你可能有一个盒子里面另一个... – ABakerSmith
哦,男孩......你绝对正确@ABakerSmith!请在下面发布答案,以便我可以接受。 –
干杯,很高兴分类你的问题! – ABakerSmith