2016-09-14 3 views
1

Ces derniers jours, je me bats un peu avec SceneKit. J'essaye de tracer un SCNSphere clair/transparent, avec un projecteur rouge. Il semble que mon projecteur rouge devienne également transparent si je mets mon SCNSphere en couleur transparente/claire. Est-il possible de dissocier le noeud SCNLight du noeud SCNSphereNode, de sorte que la couleur rouge vif du spot reste si le SCNSphere est transparent? Les images des deux sphères sont en dessous du code.Est-il possible de dessiner un SCNSphere clair avec un SCNSpotlight rouge vif?

Mon code:

func setupView() { 
    scene = SCNScene() 
    caliView.scene = scene 
    caliView.allowsCameraControl = true 
    caliView.backgroundColor = UIColor.clearColor() 
    let clearMaterial = SCNMaterial() 
    clearMaterial.diffuse.contents = UIColor(white: 0.9, alpha: 0.5) 
    clearMaterial.locksAmbientWithDiffuse = true 


    let shape = SCNSphere(radius: 5) 
    shape.materials = [clearMaterial] 
    let shapeNode = SCNNode(geometry: shape) 

    let spotLight = SCNLight() 
    spotLight.type = SCNLightTypeSpot 
    spotLight.color = UIColor.init(colorLiteralRed: 180, green: 0, blue: 0, alpha: 0.0) 
    let lightNode = SCNNode() 
    lightNode.light = spotLight 

    lightNode.position = SCNVector3(x: 0.0, y:0.0, z:15.0) 
    lightNode.orientation = SCNQuaternion(x: 0.0, y:0, z:30, w:0.0) 


    let ambientLight = SCNLight() 
    ambientLight.type = SCNLightTypeAmbient 
    ambientLight.color = UIColor(white: 0.8, alpha: 0.2) 
    let ambientNode = SCNNode() 
    ambientNode.light = ambientLight 

    shapeNode.position = SCNVector3(x: 0.0, y: 0.0, z: 0.0) 

    scene.rootNode.addChildNode(ambientNode) 
    scene.rootNode.addChildNode(shapeNode) 
    shapeNode.addChildNode(lightNode) 


    } 

sphère Darker avec projecteur rouge vif:

Darker sphere with bright red spotlight

sphère Plus transparent avec projecteur rouge doux:

More transparent sphere with soft red spotlight

Répondre

1

Dans cette ligne ... shapeNode.addChildNode (lightNode) ... vous avez ajouté le noeud lumineux au noeud de la sphère. Si vous souhaitez les dissocier tout en les déplaçant, vous pouvez créer un SCNNode vide et y ajouter les deux autres instances SCNNode en tant qu'enfants (celui de la lumière et celui de la sphère):

func setupView() { 
scene = SCNScene() 
caliView.scene = scene 
caliView.allowsCameraControl = true 
caliView.backgroundColor = UIColor.clearColor() 
let clearMaterial = SCNMaterial() 
clearMaterial.diffuse.contents = UIColor(white: 0.9, alpha: 0.5) 
clearMaterial.locksAmbientWithDiffuse = true 

let emptyNode = SCNNode() 

let shape = SCNSphere(radius: 5) 
shape.materials = [clearMaterial] 
let shapeNode = SCNNode(geometry: shape) 

let spotLight = SCNLight() 
spotLight.type = SCNLightTypeSpot 
spotLight.color = UIColor.init(colorLiteralRed: 180, green: 0, blue: 0, alpha: 0.0) 
let lightNode = SCNNode() 
lightNode.light = spotLight 

lightNode.position = SCNVector3(x: 0.0, y:0.0, z:15.0) 
lightNode.orientation = SCNQuaternion(x: 0.0, y:0, z:30, w:0.0) 

let ambientLight = SCNLight() 
ambientLight.type = SCNLightTypeAmbient 
ambientLight.color = UIColor(white: 0.8, alpha: 0.2) 
let ambientNode = SCNNode() 
ambientNode.light = ambientLight 

shapeNode.position = SCNVector3(x: 0.0, y: 0.0, z: 0.0) 

emptyNode.addChild(shapeNode) 
emptyNode.addChild(lightNode) 
scene.rootNode.addChildNode(emptyNode) 
scene.rootNode.addChildNode(ambientNode) 

}

+0

Merci pour votre réponse! Je ai essayé d'implémenter ce code .. mais cela ne fonctionnerait malheureusement pas :-(même problème: si j'essaie de rendre la sphère plus transparente, la lumière rouge fait la même chose – Rosa90

+0

Je pense que vous pouvez résoudre le problème avec [categorybitmask] (https: //developer.apple.com/reference/scenekit/scnlight/1523669-categorybitmask) –

+0

Je pense que nous prenons le problème du mauvais côté: ne nous attendons pas à ce que la couleur/transparence du spot soit confondue avec celle du –