Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCNNode opacity and visibility

I have one node that is inside of another node. Both are loaded from .obj files. The outer node has an opacity of 0.01. The inner node has an opacity of 0.99. The inner node is not visible at all unless I change its opacity to 1 or the opacity of the outer node to 0. When I rotate the scene with the invisible node slightly, the node appears. When I rotate it back it disappears.

Any thoughts on how I can maintain visibility of the inner node?

like image 579
leo Avatar asked Nov 27 '25 11:11

leo


1 Answers

You can easily control a visibility of an inner sphere using .renderingOrder instance property:

var renderingOrder: Int { get set }       /*  By default it equals to zero  */

Here's how it looks like in a code:

// NESTED OBJECT
let innerNode = SCNNode()
innerNode.geometry = SCNSphere(radius: 0.5)
innerNode.geometry?.firstMaterial?.diffuse.contents = UIColor(white: 0.0, 
                                                              alpha: 0.99)
scene.rootNode.addChildNode(innerNode)
    
// OUTER OBJECT
let outerSphere = scene.rootNode.childNode(withName: "ball", recursively: true)
outerSphere?.geometry?.firstMaterial?.diffuse.contents = UIColor(white: 1.0, 
                                                                 alpha: 0.3)
outerSphere?.renderingOrder = 1

enter image description here

like image 174
Andy Jazz Avatar answered Nov 29 '25 08:11

Andy Jazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!