Files
XCEngine/docs/api/components/light-component/light-component.md
ssdfasd f5a34f8adc docs: 重构 API 文档 - components 和 scene 模块
- components: 修复英文标题为中文,添加缺失组件文档
  - 新增 camera-component, light-component, audio-source-component, audio-listener-component 类总览
  - 修复 get-position.md 格式
  - 更新 components.md 模块总览
- scene: 修复方法文档格式,新增缺失方法
  - 修复 find.md, create-game-object.md 英文标题
  - 新增 FindByID, SerializeToString, DeserializeFromString 方法文档
  - 更新 scene.md 类总览方法列表
2026-03-26 01:50:27 +08:00

91 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LightComponent
**命名空间**: `XCEngine::Components`
**类型**: `class`
**头文件**: `XCEngine/Components/LightComponent.h`
**描述**: 光源组件,支持方向光、点光、聚光灯三种类型,可设置颜色、强度和阴影。
## 概述
LightComponent 是 XCEngine ECS 系统中的光源组件支持三种光源类型方向光Directional、点光Point和聚光灯Spot。方向光从无穷远处照射模拟太阳光点光从一个点向所有方向照射聚光灯沿一个锥形方向照射。光源组件可以设置颜色、强度、作用范围和是否投射阴影。
## 枚举
### LightType
| 枚举值 | 描述 |
|--------|------|
| `Directional` | 方向光,从无穷远处照射 |
| `Point` | 点光,从一个点向所有方向照射 |
| `Spot` | 聚光灯,沿锥形方向照射 |
## 公共方法
### 光源类型
| 方法 | 描述 |
|------|------|
| [`GetLightType`](get-light-type.md) | 获取光源类型 |
| [`SetLightType`](set-light-type.md) | 设置光源类型 |
### 光源属性
| 方法 | 描述 |
|------|------|
| [`GetColor`](get-color.md) | 获取光源颜色 |
| [`SetColor`](set-color.md) | 设置光源颜色 |
| [`GetIntensity`](get-intensity.md) | 获取光源强度 |
| [`SetIntensity`](set-intensity.md) | 设置光源强度 |
| [`GetRange`](get-range.md) | 获取作用范围(点光/聚光灯) |
| [`SetRange`](set-range.md) | 设置作用范围 |
### 聚光灯属性
| 方法 | 描述 |
|------|------|
| [`GetSpotAngle`](get-spot-angle.md) | 获取聚光灯角度 |
| [`SetSpotAngle`](set-spot-angle.md) | 设置聚光灯角度 |
### 阴影
| 方法 | 描述 |
|------|------|
| [`GetCastsShadows`](get-casts-shadows.md) | 检查是否投射阴影 |
| [`SetCastsShadows`](set-casts-shadows.md) | 设置是否投射阴影 |
## 使用示例
```cpp
#include <XCEngine/Components/LightComponent.h>
#include <XCEngine/Components/GameObject.h>
using namespace XCEngine::Components;
void SetupLighting(GameObject* lightObject) {
auto light = lightObject->AddComponent<LightComponent>();
light->SetLightType(LightType::Directional);
light->SetColor(Math::Color::White());
light->SetIntensity(1.0f);
light->SetCastsShadows(true);
}
void SetupPointLight(GameObject* pointLightObject) {
auto pointLight = pointLightObject->AddComponent<LightComponent>();
pointLight->SetLightType(LightType::Point);
pointLight->SetColor(Math::Color(1.0f, 0.8f, 0.6f, 1.0f));
pointLight->SetIntensity(2.0f);
pointLight->SetRange(10.0f);
}
```
## 相关文档
- [Components 模块总览](../components.md) - Components 模块总览
- [Component](../component/component.md) - 组件基类
- [TransformComponent](../transform-component/transform-component.md) - 变换组件