ios - SceneKit Material 中充满了随机图案,为什么?

标签 ios swift 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 制作的节点和 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)

下面是我触摸一个框后颜色如何变化的几个屏幕截图。图案在每次旋转时闪烁和变化。

enter image description here enter image description here

这种奇怪的颜色模式的原因是什么?我只希望它保持纯色。

最佳答案

在我看来你有两个节点在彼此内部 - 框的数量与你在问题中指定的数量不相加。

关于ios - SceneKit Material 中充满了随机图案,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29943324/

相关文章:

ios - 我可以检测到导致 "applicationWillResignActive"调用的原因吗?

ios - 如何将 SDWebImage 图像推送到详细 View

swift - UITextView swift 中字符串的粗体部分

ios - SceneKit 在多个透明平面上延迟阴影

ios - Swift UIView 自定义 View 在 ViewController 操作后不会更新

ios - loadNibNamed 与 initWithFrame 两难设置框架的高度和宽度

ios - 转换为 URLError,然后访问 'code' 属性会导致崩溃

swift - Swift 中数据模型的动态属性(getters/setters)

ios - 在创建游戏的范围之外,如何在 iOS 中创建程序生成的可视化效果?

ios - 场景Kit/ARKit : map screen shape into 3D object