【问题标题】:SceneKit how to add a texture inner SCNSphereSceneKit 如何在 SCNSphere 内部添加纹理
【发布时间】:2017-02-21 04:04:07
【问题描述】:

我知道如何在 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 ]

谢谢

【问题讨论】:

  • 表面内部是否有照明?材料是双面的吗?
  • 双面他的意思是你的材料的doubleSided属性是YES(默认是NO
  • @mnuages 是的,你是对的!

标签: textures scenekit


【解决方案1】:

首先让我们创建相机和灯光

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)

注意相机和灯光位置。z cus 我们将扩大“世界”球体的半径。 然后让我们创建一个名为“world”的函数来创建我们的球体。 将球体的第一个材质设置为 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()。 享受吧!

【讨论】:

    猜你喜欢
    • 2020-04-01
    • 1970-01-01
    • 2016-09-05
    • 2016-07-04
    • 2018-02-08
    • 2019-12-24
    • 2016-02-20
    • 2018-07-31
    • 1970-01-01
    相关资源
    最近更新 更多