RealityKit 不会显示多个 DirectionalLight
RealityKit won't show more than one DirectionalLight
我正在尝试在 RealityKit 中创建一个简单的 3D 场景,其中有两盏灯从相反的两侧照亮网格。一切似乎都在工作,但两个灯不会同时工作。如果我注释掉 light01,则 light02 会正常显示。
显然,从项目类型来看,您可以看出我在这方面还很陌生。我错过了什么?
func makeUIView(context: Context) -> ARView {
//Configure ARView
let arView = ARView(frame: .zero, cameraMode: .nonAR,
automaticallyConfigureSession: true)
//Set background color
arView.environment.background = .color(.black)
let light01 = DirectionalLight()
light01.light.color = .red
light01.light.intensity = 30000
light01.light.isRealWorldProxy = true
light01.shadow?.maximumDistance = 10.0
light01.shadow?.depthBias = 5.0
light01.orientation = simd_quatf(angle: -.pi/1.5, axis: [0,1,0])
let light01Anchor = AnchorEntity(world: [0, 20, 0])
light01Anchor.addChild(light01)
arView.scene.addAnchor(light01Anchor)
//NOT WORKING
let light02 = DirectionalLight()
light02.light.color = .green
light02.light.intensity = 20000
light02.light.isRealWorldProxy = true
light02.shadow?.maximumDistance = 10.0
light02.shadow?.depthBias = 5.0
light02.orientation = simd_quatf(angle: .pi/1.5, axis: [0,1,0])
let light02Anchor = AnchorEntity(world: [0, 40, 0])
light02Anchor.addChild(light02)
arView.scene.addAnchor(light02Anchor)
//Create plane for floor
let floorMesh = MeshResource.generatePlane(width: 10, depth: 10)
let floorMaterial = SimpleMaterial(color: .white, isMetallic: false)
let floorEntity = ModelEntity(mesh: floorMesh,
materials: [floorMaterial])
let floorAnchor = AnchorEntity(world: [0, 0, 0])
floorAnchor.addChild(floorEntity)
arView.scene.addAnchor(floorAnchor)
let sphereMesh = MeshResource.generateSphere(radius: 1.5)
let sphereMaterial = SimpleMaterial(color: .white,
roughness: 0.9,
isMetallic: false)
let sphereEntity = ModelEntity(mesh: sphereMesh,
materials: [sphereMaterial])
let sphereAnchor = AnchorEntity(world: [0, 1.5, -4])
sphereAnchor.addChild(sphereEntity)
arView.scene.addAnchor(sphereAnchor)
//Camera
let camera = PerspectiveCamera()
let cameraAnchor = AnchorEntity(world: [0, 1, 1])
cameraAnchor.addChild(camera)
arView.scene.addAnchor(cameraAnchor)
return arView
}
关于 RealityKit 2.0 中的 DirectionalLight
RealityKit 场景最多可以包含 nine lights。其中八个可能是不同类型的动态光——PointLights、SpotLights 和 DirectionalLight,其中一个是 image-based 光 (IBL)。但是,RealityKit 仅支持每个场景 ONE
DirectionalLight(a.k.a。虚拟太阳)。
除上述之外,需要注意的是DirectionalLight在RealityKit场景中的位置无关紧要 DirectionalLight 有 .isRealWorldProxy
个实例 属性,如果设置为 true
,它会在虚拟内容上投射阴影而不照亮场景中的任何东西。您可以使用它在接受动态照明的遮挡材料上创建阴影。
我正在尝试在 RealityKit 中创建一个简单的 3D 场景,其中有两盏灯从相反的两侧照亮网格。一切似乎都在工作,但两个灯不会同时工作。如果我注释掉 light01,则 light02 会正常显示。 显然,从项目类型来看,您可以看出我在这方面还很陌生。我错过了什么?
func makeUIView(context: Context) -> ARView {
//Configure ARView
let arView = ARView(frame: .zero, cameraMode: .nonAR,
automaticallyConfigureSession: true)
//Set background color
arView.environment.background = .color(.black)
let light01 = DirectionalLight()
light01.light.color = .red
light01.light.intensity = 30000
light01.light.isRealWorldProxy = true
light01.shadow?.maximumDistance = 10.0
light01.shadow?.depthBias = 5.0
light01.orientation = simd_quatf(angle: -.pi/1.5, axis: [0,1,0])
let light01Anchor = AnchorEntity(world: [0, 20, 0])
light01Anchor.addChild(light01)
arView.scene.addAnchor(light01Anchor)
//NOT WORKING
let light02 = DirectionalLight()
light02.light.color = .green
light02.light.intensity = 20000
light02.light.isRealWorldProxy = true
light02.shadow?.maximumDistance = 10.0
light02.shadow?.depthBias = 5.0
light02.orientation = simd_quatf(angle: .pi/1.5, axis: [0,1,0])
let light02Anchor = AnchorEntity(world: [0, 40, 0])
light02Anchor.addChild(light02)
arView.scene.addAnchor(light02Anchor)
//Create plane for floor
let floorMesh = MeshResource.generatePlane(width: 10, depth: 10)
let floorMaterial = SimpleMaterial(color: .white, isMetallic: false)
let floorEntity = ModelEntity(mesh: floorMesh,
materials: [floorMaterial])
let floorAnchor = AnchorEntity(world: [0, 0, 0])
floorAnchor.addChild(floorEntity)
arView.scene.addAnchor(floorAnchor)
let sphereMesh = MeshResource.generateSphere(radius: 1.5)
let sphereMaterial = SimpleMaterial(color: .white,
roughness: 0.9,
isMetallic: false)
let sphereEntity = ModelEntity(mesh: sphereMesh,
materials: [sphereMaterial])
let sphereAnchor = AnchorEntity(world: [0, 1.5, -4])
sphereAnchor.addChild(sphereEntity)
arView.scene.addAnchor(sphereAnchor)
//Camera
let camera = PerspectiveCamera()
let cameraAnchor = AnchorEntity(world: [0, 1, 1])
cameraAnchor.addChild(camera)
arView.scene.addAnchor(cameraAnchor)
return arView
}
关于 RealityKit 2.0 中的 DirectionalLight
RealityKit 场景最多可以包含 nine lights。其中八个可能是不同类型的动态光——PointLights、SpotLights 和 DirectionalLight,其中一个是 image-based 光 (IBL)。但是,RealityKit 仅支持每个场景 ONE
DirectionalLight(a.k.a。虚拟太阳)。
除上述之外,需要注意的是DirectionalLight在RealityKit场景中的位置无关紧要 DirectionalLight 有 .isRealWorldProxy
个实例 属性,如果设置为 true
,它会在虚拟内容上投射阴影而不照亮场景中的任何东西。您可以使用它在接受动态照明的遮挡材料上创建阴影。