gpt4 book ai didi

ios - 如何将 ScnNode 用作 ScnLight?

转载 作者:搜寻专家 更新时间:2023-11-01 05:43:44 26 4
gpt4 key购买 nike

 var sun = SCNNode(geometry: SCNSphere(radius:0.35))

sun.geometry?.firstMaterial?.diffuse.contents=#imageLiteral(resourceName: "Sun")

sun.position=SCNVector3(0,0,-1)

我想使用太阳 SCNSphere 作为全向光源。

 let OmniLight = SCNLight()      
OmniLight.type = SCNLight.LightType.omni
OmniLight.color = UIColor.white

但是如果我运行这段代码,太阳是全黑的。

最佳答案

将其添加到场景中:

scene.rootNode.addChildNode(sun)

这是 Playground 代码示例:

import UIKit
import SceneKit
import PlaygroundSupport


// create a scene view with an empty scene
var sceneView = SCNView(frame: CGRect(x: 0, y: 0, width: 640, height: 480))
var scene = SCNScene()
sceneView.scene = scene
PlaygroundPage.current.liveView = sceneView

// default lighting
sceneView.autoenablesDefaultLighting = false

// a camera
var cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 3)
scene.rootNode.addChildNode(cameraNode)

// your code (minus the image)
var sun = SCNNode(geometry: SCNSphere(radius:0.35))
sun.geometry?.firstMaterial?.diffuse.contents = UIColor.orange
sun.position=SCNVector3(0,0,-1)
let OmniLight = SCNLight()
OmniLight.type = SCNLight.LightType.omni
OmniLight.color = UIColor.white

// add to scene
scene.rootNode.addChildNode(sun)

关于ios - 如何将 ScnNode 用作 ScnLight?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47055935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com