RealityKit – 如何编辑或添加照明? [英] RealityKit – How to edit or add a Lighting?

查看:32
本文介绍了RealityKit – 如何编辑或添加照明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to add lighting in my RealityKit AR Scene. And I can't find the Lighting option in Reality Composer. If there's a way to add Directional Light or edit it then please tell me. I've tried Apple Documentation but can't understand how to add them.

推荐答案

目前在 Reality Composer 中无法做到,需要使用 RealityKit.因此,您需要创建一个继承自Entity 类并符合HasPointLight 协议的自定义类.在 macOS 项目中运行此代码以了解 PointLight 设置的工作原理:

At the moment you can't do it in Reality Composer, you need to use a RealityKit. So, you need to create a custom class that inherits from Entity class and conforms to HasPointLight protocol. Run this code in macOS project to find out how a PointLight setup works:

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).

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)
    }
}

也可以阅读我的故事关于灯光中.

Also can read my STORY about lights on Medium.

这篇关于RealityKit – 如何编辑或添加照明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆