我知道如何在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 ]谢谢
发布于 2017-02-21 04:04:07
首先,让我们创建相机和灯光
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)注意相机和灯光的位置。因为我们将使“世界”球体的半径更大。然后创建一个名为"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)
}这应该就行了。只需在did加载函数中调用camAndLights()和world()即可。享受吧!
https://stackoverflow.com/questions/30657930
复制相似问题