Skip to content

Commit 8f92075

Browse files
committed
first commit
0 parents  commit 8f92075

26 files changed

+2159
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
_book
3+
node_modules

GITBOOK.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
> Gitbook setup: https://github.com/GitbookIO/gitbook/blob/master/docs/setup.md
2+
3+
## Install
4+
5+
```bash
6+
$ npm install gitbook-cli -g
7+
```
8+
9+
## Develop
10+
11+
```bash
12+
$ gitbook serve
13+
```
14+
15+
- Add Link:
16+
17+
```
18+
// api
19+
[CuboidGeometry]({{book.api}}classes/core.cuboidgeometry.html)
20+
21+
// docs
22+
[资源加载]({{book.docs}}structure/resource-manager.html)
23+
```
24+
25+
## Build
26+
```bash
27+
$ npm run build
28+
```

README.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# 关于 Oasis Engine
2+
3+
**Oasis Engine** 是一套移动优先的 JS 引擎运行时,使用 Typescript 编写。为了保证引擎的体积最小化,我们将引擎的包分为:
4+
5+
![packages](https://gw.alipayobjects.com/mdn/rms_d27172/afts/img/A*3rlVQ6CTpJAAAAAAAAAAAAAAARQnAQ)
6+
7+
## 主包
8+
9+
引擎核心架构逻辑和核心功能([oasis-engine](https://www.npmjs.com/package/oasis-engine)),包含以下子包:
10+
11+
|主包|解释|API|
12+
|:--|:--|--|
13+
|[@oasis-engine/design](https://www.npmjs.com/package/@oasis-engine/design)| 引擎基础设计规范,如克隆规范、销毁规范、RHI规范 |[API]({{book.api}}modules/design.html)|
14+
|[@oasis-engine/math](https://www.npmjs.com/package/@oasis-engine/math)| 数学库 |[API]({{book.api}}modules/modules/math.html)|
15+
|[@oasis-engine/loader](https://www.npmjs.com/package/@oasis-engine/loader)| 资源加载 |[API]({{book.api}}modules/loader.html)|
16+
|[@oasis-engine/rhi-webgl](https://www.npmjs.com/package/@oasis-engine/rhi-webgl)| WebGL 渲染硬件接口(Rendering Hardware Interface)|[API]({{baok.api}}modules/rhi_webgl.html)|
17+
|[@oasis-engine/core](https://www.npmjs.com/package/@oasis-engine/core)| 引擎核心,如组件系统 |[API]({{book.api}}modules/core.html)|
18+
19+
20+
## 扩展包
21+
22+
非核心功能和偏业务逻辑定制,Oasis Engine 官方提供的扩展包有:
23+
24+
|扩张包|解释|API|
25+
|:--|:--|:--|
26+
|[@oasis-engine/draco](https://www.npmjs.com/package/@oasis-engine/draco)| Draco 模型压缩 |[API]({{book.api}}modules/draco.html)|
27+
|[@oasis-engine/stats](https://www.npmjs.com/package/@oasis-engine/stats)| 引擎状态显示器 |[API]({{book.api}}modules/stats.html)|
28+
|[@oasis-engine/framebuffer-picker](https://www.npmjs.com/package/@oasis-engine/framebuffer-picker)| 帧缓冲拾取 |[API]({{book.api}}modules/framebuffer_picker.html)|
29+
|[@oasis-engine/controls](https://www.npmjs.com/package/@oasis-engine/controls)| 控制器 |[API]({{book.api}}modules/controls.html)|
30+
|[@oasis-engine/tween](https://www.npmjs.com/package/@oasis-engine/tween)| 补间动画 |[API]({{baok.api}}modules/tween.html)|
31+
32+
33+
# 附录
34+
35+
- API 文档:[https://oasis-engine.github.io/api/0.1/globals.html](https://oasis-engine.github.io/api/0.1/globals.html)

SUMMARY.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Summary
2+
3+
* [Introduction](README.md)
4+
* 新手上路
5+
* [绘制一个立方体](abc/cube.md)
6+
* [绘制一个 3D 模型](abc/model.md)
7+
* 基础结构
8+
* [引擎](structure/engine.md)
9+
* [场景](structure/scene.md)
10+
* [实体](structure/entity.md)
11+
* [脚本组件](structure/script.md)
12+
* [资源管理与加载](structure/resource-manager.md)
13+
* 资源系统
14+
* [纹理资源](resource-system/texture.md)
15+
* 渲染系统
16+
* [相机](render-system/camera.md)
17+
* [灯光](render-system/light.md)
18+
* [几何体渲染器](render-system/geometry-renderer.md)
19+
* [常用几何体](render-system/basic-geometry.md)
20+
* 变换系统
21+
* [变换系统](transform-system/transform.md)
22+
* 动画系统
23+
* [骨骼动画](animation-system/skeletal-animation.md)
24+
* [粒子动画](animation-system/particle-system.md)
25+
* 工具库
26+
* [数学库](tools/math.md)
27+
* 碰撞系统
28+
* [射线投射](collision-system/ray.md)
29+
* [碰撞检测](collision-system/collision.md)
30+
* 交互系统
31+
* [控制器](interaction-system/controls.md)
32+
* [帧缓冲拾取](interaction-system/framebuffer-picker.md)

abc/cube.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# 绘制一个立方体
2+
3+
这个教程将带你开发一个“旋转的方块”示例。
4+
5+
6+
1.安装引擎:
7+
8+
```bash
9+
npm install --save oasis-engine
10+
11+
## 阿里内部可以用 tnpm
12+
tnpm install --save oasis-engine
13+
```
14+
15+
2.输入以下代码:
16+
17+
```typescript
18+
// 引入模块
19+
import {
20+
Engine,
21+
Camera,
22+
Entity,
23+
WebCanvas,
24+
WebGLRenderer,
25+
GeometryRenderer,
26+
CuboidGeometry,
27+
BlinnPhongMaterial,
28+
DirectLight,
29+
Vector3,
30+
Vector4,
31+
Script,
32+
} from 'oasis-engine';
33+
34+
// 创建画布
35+
const canvas = document.getElementById('canvas');
36+
const webcanvas = new WebCanvas(canvas);
37+
webcanvas.width = window.innerWidth;
38+
webcanvas.height = window.innerHeight;
39+
40+
// 创建引擎
41+
let engine = new Engine(webcanvas, new WebGLRenderer());
42+
43+
// 获取场景根实体
44+
const scene = engine.sceneManager.activeScene;
45+
const rootEntity = scene.createRootEntity('root');
46+
47+
// 创建一个相机实体
48+
let cameraEntity = rootEntity.createChild('camera_entity');
49+
cameraEntity.transform.position = new Vector3(0, 10, 50);
50+
cameraEntity.transform.lookAt(new Vector3(0, 0, 0));
51+
let camera = cameraEntity.addComponent(Camera);
52+
camera.backgroundColor = new Vector4(1,1,1,1)
53+
54+
55+
// 创建一个实体用来挂载方向光
56+
let lightEntity = rootEntity.createChild('light');
57+
58+
// 创建一个方向光组件
59+
let directLight = lightEntity.addComponent(DirectLight)
60+
directLight.color = new Vector3( 1.0, 1.0, 1.0 );
61+
directLight.intensity = 0.5;
62+
63+
// 通过灯光实体的旋转角度控制光线方向
64+
lightEntity.transform.rotation = new Vector3(45, 45, 45);
65+
66+
// 创建立方体实体
67+
let cubeEntity = rootEntity.createChild('cube');
68+
let cube = cubeEntity.addComponent(GeometryRenderer)
69+
cube.geometry = new CuboidGeometry(4, 4, 4);
70+
cube.material = new BlinnPhongMaterial('blinn');
71+
72+
// 旋转脚本组件
73+
class Rotate extends Script {
74+
private _tempVector = new Vector3(0, 1, 0);
75+
onUpdate() {
76+
this.entity.transform.rotate(this._tempVector);
77+
}
78+
}
79+
80+
// 添加旋转脚本组件
81+
cubeEntity.addComponent(Rotate);
82+
83+
// 启动引擎
84+
engine.run();
85+
```

abc/model.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# 绘制一个 3D 模型
2+
3+
```typescript
4+
import {
5+
AmbientLight,
6+
WebGLEngine,
7+
Script,
8+
Camera,
9+
Vector3
10+
} from 'oasis-engine';
11+
12+
class ResourceScript extends Script {
13+
async onAwake() {
14+
const gltf = await this.engine.resourceManager.load(
15+
'https://gw.alipayobjects.com/os/OasisHub/c11f06c1-12b4-447f-a7c4-c75ba7f692f4/86/0.46107136414206873.gltf',
16+
);
17+
gltf.defaultSceneRoot.transform.setPosition(0, -10, 0)
18+
this.entity.addChild(gltf.defaultSceneRoot);
19+
}
20+
}
21+
22+
const engine = new WebGLEngine('canvas');
23+
engine.canvas.resizeByClientSize();
24+
25+
const rootEntity = engine.sceneManager.activeScene.createRootEntity();
26+
27+
const cameraEntity = rootEntity.createChild('camera');
28+
cameraEntity.addComponent(Camera);
29+
const pos = cameraEntity.transform.position;
30+
pos.setValue(0, -5, 20);
31+
cameraEntity.transform.position = pos;
32+
cameraEntity.transform.lookAt(new Vector3(0, -5, 0));
33+
34+
rootEntity.addComponent(ResourceScript);
35+
let ambientLight = rootEntity.addComponent(AmbientLight)
36+
ambientLight.intensity = 1.2;
37+
38+
engine.run();
39+
```

animation-system/particle-system.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# 粒子动画
2+
3+
Oasis 3D 的 **GPU 粒子系统** [GPUParticleSystem]({{book.api}}classes/core.gpuparticlesystem.html) 内部将会根据配置参数,自动生成几何体和材质,不需要手动创建和添加。所以,使用粒子系统,我们唯一需要关注的是配置参数。
4+
5+
```typescript
6+
let particleComp = obj.addComponent(GPUParticleSystem);
7+
8+
// 初始化
9+
particleComp.initialize({
10+
maxCount: 1000,
11+
spawnCount: 100,
12+
once: true,
13+
options: {
14+
velocity: [0.2, 0.2, 0.2],
15+
acceleration: [0, -0.02, 0],
16+
color: 0x125570,
17+
lifetime: 5,
18+
size:20,
19+
}
20+
});
21+
22+
// 发射粒子
23+
particleComp.start();
24+
25+
// 停止发射
26+
particleComp.stop();
27+
28+
// 发射过程中调整发射参数
29+
particleComp.setOptions({
30+
velocity: [0, 0, 0],
31+
lifetime: 10,
32+
});
33+
```
34+
35+
36+
## 参数
37+
38+
39+
粒子参数需要在初始化([GPUParticleSystem.initialize]({{book.api}}classes/core.gpuparticlesystem.html#initialize))时配置,不同粒子参数生成的粒子效果有千百种,在使用时,需要分析想要实现的特效的物理特性,例如:初始位置、初速度、加速度和这些参数的随机范围等。。初始化参数很多,但是都有默认值,在查看之前,你最好对每个参数的含义都有简单的认识:
40+
41+
42+
- [`maxCount`]({{book.api}}classes/core.gpuparticlesystem.html#maxcount) :最大粒子数,决定所占内存的大小,需要合理分配。
43+
- [`once`]({{book.api}}classes/core.gpuparticlesystem.html#once) :是否只发射一次,默认 `false` (循环发射)。
44+
- [`blendFunc`]({{book.api}}classes/core.gpuparticlesystem.html#blendfunc) : 支持传入 webgl 混合因子,下图左为透明度混合,下图右为柔和相加混合,默认透明度混合 `[gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA]` 。
45+
46+
    ![](https://gw.alipayobjects.com/zos/rmsportal/NTAMmVCYSrXYsRvgjBYw.png#align=left&display=inline&height=190&margin=%5Bobject%20Object%5D&originHeight=200&originWidth=422&status=done&style=none&width=400)
47+
48+
- [`particleTex`]({{book.api}}classes/core.gpuparticlesystem.html#particletex) : 粒子形状贴图。
49+
- [`maskTexture`]({{book.api}}classes/core.gpuparticlesystem.html#particlemasktex) :粒子遮罩贴图,遮罩用于在粒子上叠加特定透明度的发光效果,使用遮罩前后对比:
50+
51+
    ![image.png](https://intranetproxy.alipay.com/skylark/lark/0/2019/png/161276/1566567166055-23ed9fc8-907e-4855-ba83-24703d7c2cc0.png#align=left&display=inline&height=217&margin=%5Bobject%20Object%5D&name=image.png&originHeight=433&originWidth=890&size=345326&status=done&style=none&width=445)
52+
53+
54+
- [`useOriginColor`]({{book.api}}classes/core.gpuparticlesystem.html#useorigincolor) :是否使用图片原色,为 `true`  时使用图片原色,为 `false`  时,图片原色混合用户配置的颜色,可以在原图的基础上混合出任意的颜色:
55+
56+
    ![image.png](https://intranetproxy.alipay.com/skylark/lark/0/2019/png/161276/1566567187067-d4067842-c5b3-43f8-a936-395c628ce97c.png#align=left&display=inline&height=250&margin=%5Bobject%20Object%5D&name=image.png&originHeight=499&originWidth=1009&size=506372&status=done&style=none&width=504.5)
57+
58+
59+
- [`rotateToVelocity`]({{book.api}}classes/core.gpuparticlesystem.html#rotatetovelocity) :是否跟随粒子运动速度的方向,默认 `false`,为 `true`  时,将粒子贴图的单位向量旋转至粒子运动速度的方向,例如烟花:
60+
61+
    ![xi.gif](https://intranetproxy.alipay.com/skylark/lark/0/2019/gif/161276/1566567277218-594ec692-7608-4b5a-8aff-05e6cea2b62f.gif#align=left&display=inline&height=385&margin=%5Bobject%20Object%5D&name=xi.gif&originHeight=489&originWidth=494&size=345464&status=done&style=none&width=389)
62+
63+
64+
`false` 时,无旋转,适用于方向一致的场景,例如孔明灯:
65+
66+
    ![xx.gif](https://intranetproxy.alipay.com/skylark/lark/0/2019/gif/161276/1566567330802-a71c903d-5f3c-4daa-a058-d076df2372ed.gif#align=left&display=inline&height=389&margin=%5Bobject%20Object%5D&name=xx.gif&originHeight=489&originWidth=494&size=1532055&status=done&style=none&width=393)
67+
68+
69+
- [`isScaleByLifetime`]({{book.api}}classes/core.gpuparticlesystem.html#isscalebylifetime) :是否随生命周期缩小至消失。为 `true` 时粒子会越来越小,为 `false` 时粒子大小保持不变,只有透明度会降低,可用于制作淡出消失的效果:
70+
71+
    ![](https://gw.alipayobjects.com/zos/rmsportal/ZtxLeEHDUbWvGliQmWMu.gif#align=left&display=inline&height=534&margin=%5Bobject%20Object%5D&originHeight=638&originWidth=478&status=done&style=none&width=400) |
72+
73+
74+
- [`fadeIn`]({{book.api}}classes/core.gpuparticlesystem.html#fadein) :是否添加淡入效果,可用于制作烟雾效果:
75+
76+
    ![](https://gw.alipayobjects.com/zos/rmsportal/xwSEmEOkXGJMAWfNbyRR.gif#align=left&display=inline&height=363&margin=%5Bobject%20Object%5D&originHeight=630&originWidth=694&status=done&style=none&width=400) |
77+
78+
79+
- [`getOptions`]({{book.api}}classes/core.gpuparticlesystem.html#getoptions) : 获取更新参数的回调函数,常用于按照曲线公式更新粒子初始位置,效果为粒子按照曲线的轨迹运动,用法示例如下:
80+
81+
```typescript
82+
const getPosition = (tick) => {
83+
let r = Math.acos(Math.sin(tick));
84+
let x = r * Math.cos(tick);
85+
let y = r * Math.sin(tick);
86+
return [x, y, 0];
87+
}
88+
89+
const options = {
90+
velocityRandomness: [0.2, 0.2, 0.2],
91+
acceleration: [0, -0.02, 0],
92+
color: 0x125570,
93+
colorRandomness: 0.5,
94+
lifetime: 5,
95+
size:30,
96+
};
97+
98+
particleComp.init({
99+
maxCount: 10000,
100+
spawnCount: 20,
101+
once: false,
102+
useOriginColor:false,
103+
getOptions: function(time) { // time 为累计运行时间,单位秒
104+
var position = getPosition(time);
105+
if(position) {
106+
options.position = position;
107+
}
108+
return options;
109+
}
110+
});
111+
```
112+
113+
- [`options`]({{book.api}}classes/core.gpuparticlesystem.html#options) : 粒子属性控制参数集,包含粒子发射位置、速度、加速度、旋转角度、颜色、大小、初始旋转角度、自转角速率、生命周期长度和相应随机因子的配置。随机因子用于控制参数生成的随机范围。
114+
115+
116+
- **大小随机因子**,取值在 0~1 之间,例如:大小为 50,随机因子为 0,则生成的粒子大小均为 50,随机因子为 0.5,则生成的粒子大小范围在 25~75 之间随机,随机因子为 1,则生成粒子大小范围在 0~100 之间随机:
117+
118+
```typescript
119+
size = size + (Math.random() - 0.5* 2 * sizeRandomness * size
120+
```
121+
122+
123+
- **颜色随机因子**,取值在0~1之间,颜色的 R、G、B通道的色值会分别在随机因子范围内取一个随机值,然后截取在 0~1 范围内:
124+
125+
```typescript
126+
color[i] = color[i] + (Math.random() - 0.5) * colorRandomness
127+
```
128+
129+
- **初始旋转角度随机因子**,取值在 0~1 之间,例如:rotate 为 0,随机因子为 0,则生成的粒子角度均为 0,随机因子为 1,则生成的角度在 -PI~PI 之间随机:
130+
131+
```typescript
132+
startAngle = startAngle + (Math.random() - 0.5) * Math.PI * startAngleRandomness * 2
133+
```

0 commit comments

Comments
 (0)