我正在尝试在 RealityKit AR 场景中添加照明。我在 Reality Composer 中找不到灯光选项。如果有办法添加Directional Light
或编辑它然后请告诉我。我尝试过 Apple 文档,但不明白如何添加它们。
目前您无法在 Reality Composer 中执行此操作,您需要使用 RealityKit。因此,您需要创建一个继承自的自定义类Entity
类并符合HasPointLight
协议。在 macOS 项目中运行此代码以了解 PointLight 设置的工作原理:
import AppKit
import RealityKit
class Lighting: Entity, HasPointLight {
required init() {
super.init()
self.light = PointLightComponent(color: .red,
intensity: 100000,
attenuationRadius: 20)
}
}
class GameViewController: NSViewController {
@IBOutlet var arView: ARView!
override func awakeFromNib() {
arView.environment.background = .color(.black)
let pointLight = Lighting().light
let boxAnchor = try! Experience.loadBox()
boxAnchor.components.set(pointLight)
arView.scene.anchors.append(boxAnchor)
boxAnchor.steelBox!.scale = [9,9,9]
boxAnchor.steelBox!.position.z = -0.5
}
}
您可以使用相同的方式向场景添加定向光。但请记住:定向光的位置并不重要,重要的是方向!默认情况下,它面向北 (-Z)。
class Lighting: Entity, HasDirectionalLight {
required init() {
super.init()
self.light = DirectionalLightComponent(color: .red,
intensity: 100000,
isRealWorldProxy: true)
}
}
也可以阅读我的STORY https://medium.com/@arkit/realitykit-911-lighting-and-shadows-66f99bcd5219关于Medium上的灯光。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)