Morgan Wilde
Morgan Wilde

Reputation: 17303

SceneKit material being filled with random patterns, why?

I have a simple touch detection method that should change the color of the node being touched.

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
        }
    }
}

My node hierarchy contains one node made using a custom SCNGeometry and 8 nodes with a regular SCNBox geometry.

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)

Here's a couple screenshots of how the color changes after I touch a box. The pattern flickers and change on every rotation.

enter image description here enter image description here

What is the cause of this strange color pattern? I just want it to stay a solid color.

Upvotes: 0

Views: 169

Answers (1)

ABakerSmith
ABakerSmith

Reputation: 22939

It looks to me like you've got two nodes inside each other - the number of boxes doesn't add up with the number you specified in your question.

Upvotes: 1

Related Questions