2015-06-05 49 views
0

我知道如何在SCNSphere表面添加紋理,但是當我將相機移動到球體很暗時,所以我想知道如何將紋理添加到內部表面,以下是我現在使用:SceneKit如何添加紋理內部SCNSphere

let boingBall = SCNSphere(radius: 4.0) 
     let boingBallNode = SCNNode(geometry: boingBall) 
     boingBallNode.position = SCNVector3(x: 0, y: 3, z: -10) 
     scene.rootNode.addChildNode(boingBallNode) 

     let material = SCNMaterial() 
     material.diffuse.contents = UIImage(named: "texture.png") 
     material.specular.contents = UIColor.whiteColor() 
     material.shininess = 1.0 
     boingBall.materials = [ material ] 

感謝

+0

表面內部是否有任何照明?材料是雙面的嗎? –

+0

和雙面他意味着你材料的'doubleSided'屬性是'YES'(默認是'NO') – mnuages

+0

@mnuages是的,你是對的! – user1058113

回答

0

首先,讓我們創建相機和燈光

func camAndLights(){ 
    let cameranode = SCNNode() 
    cameranode.camera = SCNCamera() 

    cameranode.position = SCNVector3(x: 0, y: 70, z: 200) 
    cameranode.camera?.zFar = 1000.0 



    let lightbrnl = SCNNode() 
    lightbrnl.light = SCNLight() 
    lightbrnl.light?.type = SCNLight.LightType.directional 
    lightbrnl.position = SCNVector3(x: 0, y: 200, z: 0) 
    lightbrnl.light?.zFar = 1000.0 
    lightbrnl.light?.color = UIColor.cyan 

    scene.rootNode.addChildNode(lightbrnl) 
    scene.rootNode.addChildNode(cameranode) 

注意攝像機和光position.z CUS,我們將讓我們的「世界」的半徑球大。 然後讓我們創建一個名爲「世界」的函數來創建我們的球體。 球體的第一材料設置爲 isdouble = true 和中心在(0,0,0)

func world(){ 
    let world = SCNSphere(radius: 700) 

    world.firstMaterial?.diffuse.contents = UIImage(named: "sky") 

    world.firstMaterial?.isDoubleSided = true 
    let worldnode = SCNNode(geometry: world) 

    worldnode.position = SCNVector3(x: 0, y: 0, z: 0) 
    scene.rootNode.addChildNode(worldnode) 

} 

中間的世界節點,應該這樣做。只需在您的加載函數中調用camAndLights()world()即可。 享受!