iosscenekitscnnodescnmaterial

How can I wrap image around SCNTube in circular manner?


I want to make a Saturn ring wrapped by an image in circular manner, so it looks real. The Sphere is completely fine, the only issue is with ring node.

What I want:

enter image description here

What I have tried:

let saturnRingNode = scene?.rootNode.childNode(withName: "saturn_ring", recursively: true)
let ring = UIImage(named: "saturn_ring")
saturnRingNode?.geometry?.firstMaterial?.diffuse.contents = ring

Here is my saturn_ring image:

enter image description here

How does it look:

enter image description here

I also tried to rotate materials as following code. But I thing it is not rendering in circular manner. It is just changing the direction of the lines.

if let material = saturnRingNode?.geometry?.firstMaterial {
    material.diffuse.contentsTransform = SCNMatrix4MakeRotation(Float.pi / 2, 0, 0, 1) 
}

I have tried AI tools, Apple developer community but couldn't find anything.


Solution

  • I replaced a tube with a torus and rotated the texture image 90 degrees. XCode did the mapping itself.

    let saturnRingNode = scene?.rootNode.childNode(withName: "saturn_ring", recursively: true)
    let ring = UIImage(named: "saturn_ring")
    saturnRingNode?.geometry?.firstMaterial?.diffuse.contents = ring
    

    How to control the height of this torus?

    1. Select the ring node
    2. Node inspectorTransforms → Set the Y scale to 0

    How does it look?

    enter image description here