0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[RealityKit] Lightに関して

Posted at

PointLight

  • 点光源のことを指す。点座標に向けて光を当てる光源で全方向に光を与えるエンティティのことを指す。
    他にもライトの色や強度を設定することができる

  • HasPointLightプロトコルに準拠している

  • 持っているコンポーネント
    Transformコンポーネント
    Synchronizationコンポーネント
    PointLightコンポーネント

サンプルコード

let lightEntity = PointLight()
let anchorEntity = AnchorEntity(plane: .horizontal)
// .light で PointLightが持っているPointLightコンポーネントのプロパティにアクセスできる。
lightEntity.light.color = .red  
lightEntity.light.intensity = 1500 強度
lightEntity.light.attenuationRadius = 0.5 // ライトが影響する距離
lightEntity.look(at: [0,0,0], from: [0,0,0.1], relativeTo: anchorEntity) // ライトをどこから(from)どこに(relativeTo)に向けるか
anchorEntity.addChild(lightEntity)
arView.scene.anchors.append(anchorEntity)

SpotLight

* 円錐状の光をある方向から与えるエンティティ
* HasSpotLightを準拠している
*持っているコンポーネント
Transformコンポーネント
Synchronizationコンポーネント
SpotLightコンポーネント
コード

let lightEntity = SpotLight()
lightEntity.light.color = .red //色
lightEntity.light.intensity = 2000 // 強さ
lightEntity.look(at: [0,0,0], from: [0,0.03,0.1], relativeTo: lightAnchor) // 方向を決める
// ここら辺でどのような円錐の形で光を与えるのかを決めるっぽいがあんまりわかってない。
lightEntity.light.innerAngleInDegrees = 40 // 光を与える円錐の内角
lightEntity.light.outerAngleInDegrees = 60 // 光を与える円錐の外角
lightEntity.light.attenuationRadius = 15 // 光の量がゼロになる円錐の半径

let lightAnchor = AnchorEntity(plane: .horizontal)
lightAnchor.addChild(lightEntity)
arView.scene.anchors.append(lightAnchor)

DirectionalLight

特定の方向から一直線に光を与えるエンティティのことを指す。

  • HasDirectionalLightコンポーネントを持つ
  • 持っているコンポーネント
    Transformコンポーネント
    DirectionalLightコンポーネント
    Synchronizationコンポーネント
let lightEntity = DirectionalLight()
lightEntity.light.color = .red // 色
lightEntity.light.intensity = 1500 // 強さ
lightEntity.shadow?.maximumDistance = 5 // 影の最大の距離
lightEntity.shadow?.depthBias = 5 // 影の深度

let lightAnchor = AnchorEntity(plane: .horizontal)
lightAnchor.addChild(lightEntity)
arView.scene.anchors.append(lightAnchor)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?