lythreeframe 1.2.62 → 1.2.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +160 -1
- package/dist/bundle.cjs.js +193 -188
- package/dist/bundle.esm.js +193 -188
- package/dist/index.d.ts +1 -0
- package/dist/lythreeframe/Frame/Controller.d.ts +42 -20
- package/dist/lythreeframe/Object/Actor.d.ts +13 -20
- package/dist/lythreeframe/Object/Components/SceneComponent.d.ts +9 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,162 @@
|
|
|
1
1
|
# lythreeframe
|
|
2
2
|
|
|
3
|
-
Three.js
|
|
3
|
+
一个基于 Three.js 的 WebGPU/WebGL 3D 应用框架,提供类似游戏引擎的架构设计,简化 3D 场景的开发流程。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🎮 类 Unreal Engine 的 Actor-Component 架构
|
|
8
|
+
- 🖥️ 支持 WebGPU 和 WebGL 双渲染后端
|
|
9
|
+
- 📦 完善的资源管理系统(几何体、材质、纹理)
|
|
10
|
+
- 🎬 内置后处理效果(Bloom、DOF、GTAO、SSR、Outline 等)
|
|
11
|
+
- 🎯 射线检测与交互事件系统
|
|
12
|
+
- 🎥 灵活的相机控制(轨道控制、第一人称)
|
|
13
|
+
- 📐 支持透视/正交相机切换
|
|
14
|
+
|
|
15
|
+
## 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install lythreeframe
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 依赖
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"three": "^0.180.0",
|
|
26
|
+
"@types/three": "^0.181.0",
|
|
27
|
+
"gsap": "^3.12.2"
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 快速开始
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { ThreeJsApp, BoxActor, DirectionalLightActor, AmbientLightActor } from 'lythreeframe';
|
|
35
|
+
|
|
36
|
+
// 创建应用
|
|
37
|
+
const app = new ThreeJsApp({
|
|
38
|
+
viewportParam: {
|
|
39
|
+
elementId: 'canvas-container'
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// 添加光源
|
|
44
|
+
const dirLight = new DirectionalLightActor(app);
|
|
45
|
+
dirLight.setPosition(5, 10, 5);
|
|
46
|
+
app.world.addActor(dirLight);
|
|
47
|
+
|
|
48
|
+
const ambLight = new AmbientLightActor(app);
|
|
49
|
+
app.world.addActor(ambLight);
|
|
50
|
+
|
|
51
|
+
// 添加物体
|
|
52
|
+
const box = new BoxActor(app);
|
|
53
|
+
box.setPosition(0, 1, 0);
|
|
54
|
+
app.world.addActor(box);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## 核心架构
|
|
58
|
+
|
|
59
|
+
### ThreeJsApp
|
|
60
|
+
应用入口,管理整个 3D 应用的生命周期。
|
|
61
|
+
|
|
62
|
+
### World
|
|
63
|
+
场景管理器,负责 Actor 的添加、移除和 Tick 更新。
|
|
64
|
+
|
|
65
|
+
### Viewport
|
|
66
|
+
视口管理,处理渲染器创建、窗口缩放和后处理管线。
|
|
67
|
+
|
|
68
|
+
### Controller
|
|
69
|
+
输入控制器,处理鼠标交互、射线检测和相机控制。
|
|
70
|
+
|
|
71
|
+
### Actor / Component
|
|
72
|
+
- `Actor`: 场景中的实体对象,包含一个或多个 Component
|
|
73
|
+
- `SceneComponent`: 具有 3D 变换的组件基类
|
|
74
|
+
- `MeshComponent`: 网格渲染组件
|
|
75
|
+
|
|
76
|
+
## 内置 Actor
|
|
77
|
+
|
|
78
|
+
| Actor | 说明 |
|
|
79
|
+
|-------|------|
|
|
80
|
+
| `BoxActor` | 立方体 |
|
|
81
|
+
| `PlaneActor` | 平面 |
|
|
82
|
+
| `DirectionalLightActor` | 平行光 |
|
|
83
|
+
| `AmbientLightActor` | 环境光 |
|
|
84
|
+
| `SkyActor` | 天空盒 |
|
|
85
|
+
| `LevelActor` | 关卡容器 |
|
|
86
|
+
|
|
87
|
+
## 后处理效果
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { ThreeJsApp, PostProcessStepType } from 'lythreeframe';
|
|
91
|
+
|
|
92
|
+
const app = new ThreeJsApp({
|
|
93
|
+
viewportParam: { elementId: 'container' },
|
|
94
|
+
postProcessParam: {
|
|
95
|
+
steps: [
|
|
96
|
+
{ type: PostProcessStepType.Bloom, enabled: true, param: { threshold: 0.8, strength: 0.5, radius: 0.5 } },
|
|
97
|
+
{ type: PostProcessStepType.FXAA, enabled: true }
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
支持的后处理效果:
|
|
104
|
+
- Bloom(泛光)
|
|
105
|
+
- DOF(景深)
|
|
106
|
+
- GTAO(环境光遮蔽)
|
|
107
|
+
- SSR(屏幕空间反射)
|
|
108
|
+
- Outline(轮廓描边)
|
|
109
|
+
- FXAA / SMAA(抗锯齿)
|
|
110
|
+
|
|
111
|
+
## 交互事件
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// 组件级别事件
|
|
115
|
+
component.onClickDelegate.add(() => console.log('clicked'));
|
|
116
|
+
component.onHoverBeginDelegate.add(() => console.log('hover begin'));
|
|
117
|
+
|
|
118
|
+
// Actor 级别事件
|
|
119
|
+
actor.onClickDelegate.add((component) => console.log('actor clicked'));
|
|
120
|
+
|
|
121
|
+
// 控制器级别事件
|
|
122
|
+
app.controller.onComponentClickDelegate.add((event) => {
|
|
123
|
+
console.log('component:', event.component);
|
|
124
|
+
event.handled = true; // 阻止默认行为
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## 相机控制
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// 切换相机类型
|
|
132
|
+
app.updateCamera({
|
|
133
|
+
type: 'perspective',
|
|
134
|
+
fov: 60,
|
|
135
|
+
near: 0.1,
|
|
136
|
+
far: 1000
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// 聚焦到目标
|
|
140
|
+
app.controller.focusTo(targetPosition, targetQuaternion, distance, duration);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 资源管理
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
// 加载 GLTF 模型
|
|
147
|
+
const gltf = await app.assetManager.loadGltfFromPathAsync('/models/scene.glb');
|
|
148
|
+
|
|
149
|
+
// 资源会自动进行引用计数管理
|
|
150
|
+
app.assetManager.addAsset(geometry);
|
|
151
|
+
app.assetManager.releaseAsset(geometry);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## 销毁
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
app.destroy();
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## License
|
|
161
|
+
|
|
162
|
+
MIT
|