three-base 0.0.1 → 1.0.2
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 +1 -2
- package/lib/ApngTexture.ts +91 -0
- package/lib/ApngTextureManage.ts +130 -0
- package/lib/EventMesh.ts +79 -0
- package/lib/ExtrudeMesh.ts +569 -0
- package/lib/FPScontrol.ts +209 -0
- package/lib/PointLight.ts +78 -0
- package/lib/ThreeBasic.ts +399 -0
- package/lib/ThreeMouse.ts +464 -0
- package/lib/Transition.ts +256 -0
- package/lib/draco/README.md +32 -0
- package/lib/draco/draco_decoder.js +52 -0
- package/lib/draco/draco_decoder.wasm +0 -0
- package/lib/draco/draco_encoder.js +33 -0
- package/lib/draco/draco_wasm_wrapper.js +104 -0
- package/lib/keyContorls.ts +127 -0
- package/lib/shaders.ts +264 -0
- package/lib/text/Text2D.ts +63 -0
- package/lib/text/Text3D.ts +20 -0
- package/lib/threeLoader.ts +119 -0
- package/lib/threeUtils.ts +84 -0
- package/lib/type.ts +11 -0
- package/package.json +45 -27
- package/.gitattributes +0 -2
- package/.github/workflows/npm-publish.yml +0 -22
- package/LICENSE +0 -21
- package/example/index.html +0 -27
- package/example/index.js +0 -0
- package/lib/index.ts +0 -112
- package/tsconfig.json +0 -11
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: xiaosihan
|
|
3
|
+
* @Date: 2021-04-10 02:44:01
|
|
4
|
+
* @Last Modified by: xiaosihan
|
|
5
|
+
* @Last Modified time: 2022-06-22 19:44:23
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import threeUtils from "./threeUtils";
|
|
9
|
+
|
|
10
|
+
function bezier(arr: [number, number, number, number], t: number) {
|
|
11
|
+
const ut = 1 - t;
|
|
12
|
+
const a1 = arr[1] * ut + arr[2] * t;
|
|
13
|
+
const result = ((arr[0] * ut + arr[1] * t) * ut + a1 * t) * ut + (a1 * ut + (arr[2] * ut + arr[3] * t) * t) * t;
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface TParam { [key: string]: number }
|
|
18
|
+
|
|
19
|
+
// 过渡动画插件
|
|
20
|
+
export default class Transition {
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*Creates an instance of transition.
|
|
24
|
+
* @param {{ [key: string]: number }} // 初始值
|
|
25
|
+
* @param {[0.8, 0, 0.2, 1]} // 贝塞尔曲线
|
|
26
|
+
* @param {number} [duration=1000] // 过渡时间
|
|
27
|
+
* @memberof transition
|
|
28
|
+
*/
|
|
29
|
+
constructor(
|
|
30
|
+
param: TParam = {},
|
|
31
|
+
bezier: [number, number, number, number] = [0.8, 0, 0.2, 1],
|
|
32
|
+
duration = 500
|
|
33
|
+
) {
|
|
34
|
+
|
|
35
|
+
this.setDuration(duration);
|
|
36
|
+
|
|
37
|
+
this.setBezier(bezier);
|
|
38
|
+
|
|
39
|
+
this.set(param);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 所有的 key 的枚举
|
|
43
|
+
_keys: Array<string> = [];
|
|
44
|
+
|
|
45
|
+
// 贝塞尔曲线
|
|
46
|
+
_bezier: [number, number, number, number] = [0.8, 0, 0.2, 1];
|
|
47
|
+
|
|
48
|
+
// x轴贝塞尔
|
|
49
|
+
_Xbezier: [number, number, number, number] = [0, 0.8, 0.2, 1];
|
|
50
|
+
|
|
51
|
+
// y轴贝塞尔
|
|
52
|
+
_Ybezier: [number, number, number, number] = [0, 0, 1, 1];
|
|
53
|
+
|
|
54
|
+
setBezier(bezier: [number, number, number, number] = [0.8, 0, 0.2, 1]): this {
|
|
55
|
+
this._bezier = [...bezier];
|
|
56
|
+
this._Xbezier = [0, bezier[0], bezier[2], 1];
|
|
57
|
+
this._Ybezier = [0, bezier[1], bezier[3], 1];
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 当前时间戳
|
|
62
|
+
timeTemp = performance.now();
|
|
63
|
+
|
|
64
|
+
// 过渡时间
|
|
65
|
+
_duration = 0;
|
|
66
|
+
|
|
67
|
+
//延时
|
|
68
|
+
_delay = 0;
|
|
69
|
+
|
|
70
|
+
// 设置过渡时间
|
|
71
|
+
setDuration(duration = 500): this {
|
|
72
|
+
this._duration = duration;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 设置延时
|
|
77
|
+
setDelay(delay = 0) {
|
|
78
|
+
this._delay = delay;
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 存储 每个参数的 起始位置 起始时间 终止位置 终止时间
|
|
83
|
+
_: { [key: string]: number } = {};
|
|
84
|
+
|
|
85
|
+
onChangeCall?: (josn: { [key: string]: number }) => void;
|
|
86
|
+
|
|
87
|
+
// 执行过度动画
|
|
88
|
+
run({ timeTemp }: any) {
|
|
89
|
+
this.timeTemp = timeTemp;
|
|
90
|
+
if (!this.onChangeCall || this.isDone()) {
|
|
91
|
+
threeUtils.removeEventListener("requestAnimationFrame", this.runbindThis);
|
|
92
|
+
} else {
|
|
93
|
+
this.onChangeCall(this.getJson());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
runbindThis = this.run.bind(this);
|
|
98
|
+
|
|
99
|
+
// 设置动画对象的回调事件
|
|
100
|
+
onChange(onChangeCall: (josn: { [key: string]: number }) => void): this {
|
|
101
|
+
this.onChangeCall = onChangeCall;
|
|
102
|
+
threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 计算当前 key 的值
|
|
107
|
+
get(key: string | number): number {
|
|
108
|
+
|
|
109
|
+
key = String(key);
|
|
110
|
+
|
|
111
|
+
if (this._keys.includes(key) && this.timeTemp < (this._[key + "_startTime"] + this._duration)) {
|
|
112
|
+
|
|
113
|
+
let start = this._[key + "_start"];
|
|
114
|
+
|
|
115
|
+
let end = this._[key + "_end"];
|
|
116
|
+
|
|
117
|
+
let timeProgress = Math.min(1, Math.max(0, (this.timeTemp - this._[key + "_startTime"]) / this._duration));
|
|
118
|
+
|
|
119
|
+
// 斜率
|
|
120
|
+
let t = 0;
|
|
121
|
+
|
|
122
|
+
// 微分法 求斜率t
|
|
123
|
+
while (bezier(this._Xbezier, t + 0.1) < timeProgress) {
|
|
124
|
+
t += 0.1;
|
|
125
|
+
}
|
|
126
|
+
while (bezier(this._Xbezier, t + 0.01) < timeProgress) {
|
|
127
|
+
t += 0.01;
|
|
128
|
+
}
|
|
129
|
+
while (bezier(this._Xbezier, t + 0.001) < timeProgress) {
|
|
130
|
+
t += 0.001;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
t = Math.min(1, Math.max(0, t)) // 斜率最大为1
|
|
134
|
+
|
|
135
|
+
// 通过斜率求y值
|
|
136
|
+
return (bezier(this._Ybezier, t) * (end - start)) + start;
|
|
137
|
+
|
|
138
|
+
} else if (this._keys.includes(key) && this.timeTemp >= (this._[key + "_startTime"] + this._duration)) {
|
|
139
|
+
|
|
140
|
+
return this._[key + "_end"];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// `没有 ${key} 的值`;
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
set(param: TParam): this {
|
|
148
|
+
|
|
149
|
+
let timetemp = performance.now() + this._delay;;
|
|
150
|
+
|
|
151
|
+
for (let key in param) {
|
|
152
|
+
|
|
153
|
+
// 有就赋值
|
|
154
|
+
if (this._keys.includes(key) && Math.abs(param[key] - this._[key + "_end"]) > 0.001) {
|
|
155
|
+
|
|
156
|
+
this._[key + "_start"] = this.get(key);
|
|
157
|
+
|
|
158
|
+
this._[key + "_end"] = param[key];
|
|
159
|
+
// 起始时间
|
|
160
|
+
this._[key + "_startTime"] = timetemp;
|
|
161
|
+
|
|
162
|
+
// 执行状态未完成
|
|
163
|
+
this._isDone = false;
|
|
164
|
+
|
|
165
|
+
// 没有就添加一个
|
|
166
|
+
} else if (!this._keys.includes(key)) {
|
|
167
|
+
|
|
168
|
+
this._[key + "_start"] = param[key];
|
|
169
|
+
|
|
170
|
+
this._[key + "_end"] = param[key];
|
|
171
|
+
// 起始时间
|
|
172
|
+
this._[key + "_startTime"] = timetemp - this._duration;
|
|
173
|
+
|
|
174
|
+
// 执行状态未完成
|
|
175
|
+
this._isDone = false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!this._keys.includes(key)) {
|
|
179
|
+
this._keys.push(key);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 执行状态未完成
|
|
183
|
+
this._isDone = false;
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
threeUtils.addEventListener("requestAnimationFrame", this.runbindThis);
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
// 重置起始和终止位置
|
|
190
|
+
reset(param: TParam): this {
|
|
191
|
+
|
|
192
|
+
for (let key in param) {
|
|
193
|
+
this._[key + "_start"] = param[key];
|
|
194
|
+
this._[key + "_end"] = param[key];
|
|
195
|
+
this._[key + "_startTime"] = -this._duration;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (this.onChangeCall) {
|
|
199
|
+
this.onChangeCall(this.getJson());
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
this._isDone = true;
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 获取过渡对象上面的key
|
|
207
|
+
getKeys(): string[] {
|
|
208
|
+
return [...this._keys];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// 判断是否有这个参数
|
|
212
|
+
hasKey(key: string): boolean {
|
|
213
|
+
return this._keys.includes(key);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// 获取全部参数
|
|
217
|
+
getJson(): { [key: string]: number } {
|
|
218
|
+
let keys = this.getKeys();
|
|
219
|
+
|
|
220
|
+
let json: { [key: string]: number } = {};
|
|
221
|
+
|
|
222
|
+
keys.map(key => {
|
|
223
|
+
json[key] = this.get(key);
|
|
224
|
+
});
|
|
225
|
+
return json;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
_isDone = false;
|
|
229
|
+
|
|
230
|
+
// 是否执行完成了
|
|
231
|
+
isDone(): boolean {
|
|
232
|
+
|
|
233
|
+
if (this._isDone) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
let isisDone = false;
|
|
238
|
+
|
|
239
|
+
for (let i in this._keys) {
|
|
240
|
+
|
|
241
|
+
isisDone = this._[this._keys[i] + "_startTime"] + this._duration < this.timeTemp;
|
|
242
|
+
|
|
243
|
+
// 只要有一个没有完成 都算没有完成 过渡
|
|
244
|
+
if (!isisDone) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!this._isDone) {
|
|
250
|
+
this._isDone = true;
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Draco 3D Data Compression
|
|
2
|
+
|
|
3
|
+
Draco is an open-source library for compressing and decompressing 3D geometric meshes and point clouds. It is intended to improve the storage and transmission of 3D graphics.
|
|
4
|
+
|
|
5
|
+
[Website](https://google.github.io/draco/) | [GitHub](https://github.com/google/draco)
|
|
6
|
+
|
|
7
|
+
## Contents
|
|
8
|
+
|
|
9
|
+
This folder contains three utilities:
|
|
10
|
+
|
|
11
|
+
* `draco_decoder.js` — Emscripten-compiled decoder, compatible with any modern browser.
|
|
12
|
+
* `draco_decoder.wasm` — WebAssembly decoder, compatible with newer browsers and devices.
|
|
13
|
+
* `draco_wasm_wrapper.js` — JavaScript wrapper for the WASM decoder.
|
|
14
|
+
|
|
15
|
+
Each file is provided in two variations:
|
|
16
|
+
|
|
17
|
+
* **Default:** Latest stable builds, tracking the project's [master branch](https://github.com/google/draco).
|
|
18
|
+
* **glTF:** Builds targeted by the [glTF mesh compression extension](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression), tracking the [corresponding Draco branch](https://github.com/google/draco/tree/gltf_2.0_draco_extension).
|
|
19
|
+
|
|
20
|
+
Either variation may be used with `THREE.DRACOLoader`:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
var dracoLoader = new THREE.DRACOLoader();
|
|
24
|
+
dracoLoader.setDecoderPath('path/to/decoders/');
|
|
25
|
+
dracoLoader.setDecoderConfig({type: 'js'}); // (Optional) Override detection of WASM support.
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Further [documentation on GitHub](https://github.com/google/draco/tree/master/javascript/example#static-loading-javascript-decoder).
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
[Apache License 2.0](https://github.com/google/draco/blob/master/LICENSE)
|