@galacean/effects-threejs 0.0.1-alpha.0

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 ADDED
@@ -0,0 +1,77 @@
1
+ # Galacean Effects 的 THREE.JS 插件
2
+
3
+ 使用此插件,可以在 THREE.JS 环境下加载并渲染 Galacean Effects 动效。
4
+
5
+ ## 版本说明
6
+
7
+ - Three.js ![](https://img.shields.io/badge/npm-0.149.0-green.svg?style=flat-square)
8
+
9
+ ## 使用步骤
10
+
11
+ ### 1、THREE.JS 场景初始化
12
+
13
+ 在 THREE.JS 中实现 Galacean Effects 首先要创建一个 THREE.JS 场景:
14
+
15
+ ``` ts
16
+ import * as THREE from 'three';
17
+
18
+ // 创建一个 renderer
19
+ const renderer = new THREE.WebGLRenderer({
20
+ alpha: true,
21
+ stencil: true,
22
+ antialias: true,
23
+ depth: true,
24
+ premultipliedAlpha: true,
25
+ });
26
+ // 创建一个场景
27
+ const scene = new THREE.Scene();
28
+ const container = document.getElementById('J-container');
29
+ const { width, height } = container.getBoundingClientRect();
30
+ // 创建一个相机
31
+ const camera = new THREE.PerspectiveCamera(80, width / height, 0.1, 1000);
32
+
33
+ camera.position.set(0, 0, 8);
34
+ camera.lookAt(0, 0, 0);
35
+ scene.add(camera);
36
+ renderer.setPixelRatio(window.devicePixelRatio);
37
+ renderer.setSize(width, height);
38
+
39
+ container.appendChild(renderer.domElement);
40
+ ```
41
+
42
+ ### 2、ThreeDisplayObject 实例化和资源加载
43
+
44
+ ``` ts
45
+ import { ThreeDisplayObject } from '@galacean/effects-threejs';
46
+
47
+ const displayObject = new ThreeDisplayObject(renderer.getContext(), { width, height });
48
+ // 加载 Galacean Effects 产物
49
+ await displayObject.loadScene('./xxx.json');
50
+ // 将绘制对象添加到 THREE 的 scene 中
51
+ scene.add(displayObject);
52
+ ```
53
+
54
+ ### 3、执行 THREE.JS 渲染
55
+
56
+ ``` ts
57
+ const { currentComposition } = displayObject;
58
+ let lastTime = performance.now();
59
+
60
+ function render () {
61
+ // 判断当前合成是否被销毁
62
+ if (!currentComposition.isDestroyed) {
63
+ displayObject.update(performance.now() - lastTime);
64
+ }
65
+
66
+ lastTime = performance.now();
67
+ renderer.render(scene, camera);
68
+
69
+ requestAnimationFrame(render);
70
+ }
71
+
72
+ render();
73
+ ```
74
+
75
+ ## API 文档
76
+
77
+ TODO
@@ -0,0 +1,6 @@
1
+ export * from '@galacean/effects-core';
2
+ export * from './three-display-object';
3
+ export * from './three-texture';
4
+ export * from './material';
5
+ export * from './three-composition';
6
+ export declare const version: string;