gpt4 book ai didi

swift - RealityKit – 如何编辑或添加光照?

转载 作者:行者123 更新时间:2023-12-05 02:09:31 26 4
gpt4 key购买 nike

我正在尝试在我的 RealityKit AR 场景中添加光照。我在 Reality Composer 中找不到光照选项。如果有办法添加 Directional Light 或对其进行编辑,请告诉我。我已经尝试过 Apple 文档,但无法理解如何添加它们。

enter image description here

最佳答案

目前您无法在 Reality Composer 中执行此操作,您需要使用 RealityKit。因此,您需要创建一个继承自 Entity 类并符合 HasPointLight 协议(protocol)的自定义类。在 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
}
}

enter image description here

The same way you can add a Directional Light to the scene. But remember: a position of Directional Light does not important, but an orientation does! By default it's oriented to north (-Z).

class Lighting: Entity, HasDirectionalLight {

required init() {
super.init()

self.light = DirectionalLightComponent(color: .red,
intensity: 100000,
isRealWorldProxy: true)
}
}

enter image description here

也可以阅读我的STORY关于 Medium 上的灯。

关于swift - RealityKit – 如何编辑或添加光照?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59747147/

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