【问题标题】:SceneKit material being filled with random patterns, why?SceneKit 材质被随机图案填充,为什么?
【发布时间】:2015-04-29 20:49:57
【问题描述】:

我有一个简单的触摸检测方法,可以改变被触摸节点的颜色。

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)

这里有几个屏幕截图,说明我触摸一个框后颜色如何变化。每次旋转时,图案都会闪烁并发生变化。

这种奇怪的颜色图案是什么原因造成的?我只是希望它保持纯色。

【问题讨论】:

  • 看起来你可能有一个盒子在另一个盒子里......
  • 哦,男孩......你是绝对正确的@ABakerSmith!请在下面发布答案,以便我接受。
  • 干杯,很高兴解决了您的问题!

标签: ios swift scenekit


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2019-08-25
    • 2020-11-07
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    • 1970-01-01
    • 2019-02-19
    • 2017-07-31
    相关资源
    最近更新 更多