@miaoshangzuan/catsjs 0.1.27 → 0.1.29
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/build/ARGBtoColor.js +55 -0
- package/build/Functions.js +112 -0
- package/build/camera/Camera2D.js +40 -0
- package/build/cats2d.js +57 -0
- package/build/cats2d.module.min.js +19 -0
- package/build/math/PerlinNoise.js +199 -0
- package/build/math/matrix.js +637 -0
- package/build/math/utils.js +62 -0
- package/build/matrix.module.min.js +18 -0
- package/build/model/Geometry.js +24 -0
- package/build/model/Material.js +133 -0
- package/build/model/Mesh.js +168 -0
- package/build/model/Object2D.js +376 -0
- package/build/model/SkinnedMesh.js +153 -0
- package/build/plugins/animation.js +331 -0
- package/build/plugins/loaders/Canvas.js +4 -0
- package/build/plugins/loaders/FileLoader.js +41 -0
- package/build/plugins/loaders/StringLoader.js +254 -0
- package/build/plugins/loaders/TextLoader.js +30 -0
- package/build/plugins/loaders/TextureLoader.js +45 -0
- package/build/plugins/moreObject2D.js +608 -0
- package/build/renderer/GLRenderer.js +178 -0
- package/build/renderer/SpriteGenerator.js +226 -0
- package/build/renderer/WebGLRenderer.js +577 -0
- package/build/scene/Scene.js +45 -0
- package/build/sort.js +51 -0
- package/package.json +31 -4
- package/cats2d.module.min.js +0 -19
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 颜色处理
|
|
3
|
+
* 当前版本 0.1.3
|
|
4
|
+
* 于2025年4月2日开始开发
|
|
5
|
+
* @author MiaoShangZuan <3268208143@qq.com>
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 颜色处理
|
|
12
|
+
* @param {number|string} value 颜色参数
|
|
13
|
+
* @returns 返回颜色分量
|
|
14
|
+
*/
|
|
15
|
+
function ARGBtoColor( value='#000000' ) {
|
|
16
|
+
let a, r, g, b;
|
|
17
|
+
if(typeof value == 'number') {
|
|
18
|
+
a = 0xFF;
|
|
19
|
+
r = (value >> 16) & 0xFF;
|
|
20
|
+
g = (value >> 8) & 0xFF;
|
|
21
|
+
b = value & 0xFF;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const hex = value.replace(/^#/, '');
|
|
25
|
+
if(hex.length === 6) {
|
|
26
|
+
a = 'FF';
|
|
27
|
+
r = hex.slice(0, 2);
|
|
28
|
+
g = hex.slice(2, 4);
|
|
29
|
+
b = hex.slice(4, 6);
|
|
30
|
+
}
|
|
31
|
+
else if(hex.length === 8) {
|
|
32
|
+
a = hex.slice(0, 2);
|
|
33
|
+
r = hex.slice(2, 4);
|
|
34
|
+
g = hex.slice(4, 6);
|
|
35
|
+
b = hex.slice(6, 8);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
a = 'FF';
|
|
39
|
+
r = g = b = '00';
|
|
40
|
+
}
|
|
41
|
+
a = parseInt(a, 16);
|
|
42
|
+
r = parseInt(r, 16);
|
|
43
|
+
g = parseInt(g, 16);
|
|
44
|
+
b = parseInt(b, 16);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
r: r / 255,
|
|
48
|
+
g: g / 255,
|
|
49
|
+
b: b / 255,
|
|
50
|
+
a: a / 255,
|
|
51
|
+
value
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default ARGBtoColor;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一些辅助函数
|
|
3
|
+
* 于2025年5月1日开始开发
|
|
4
|
+
* @author MiaoShangZuan <3268208143@qq.com>
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 本人于2024年9月8日拉了一坨代码,如下。
|
|
11
|
+
* 望后期的我来修复。(暂时先用旧版代码吧--调皮脸)
|
|
12
|
+
* @param {object} data 输入Object2D参数
|
|
13
|
+
* @param {object} Object2D 默认Object2D参数
|
|
14
|
+
* @param {object} stipulate 替换规则
|
|
15
|
+
*/
|
|
16
|
+
function extract( data, Object2D, stipulate=[] ) {
|
|
17
|
+
if( data != undefined ) {
|
|
18
|
+
for( let key in Object2D ) {
|
|
19
|
+
if( data[key] != undefined ) {
|
|
20
|
+
// 判断子属性是否为对象或数组
|
|
21
|
+
// 且是否一个一个遍历
|
|
22
|
+
if( typeof Object2D[key] == 'object' && stipulate == undefined || typeof Object2D[key] == 'object' && stipulate.indexOf(key) == -1 ) {
|
|
23
|
+
if( ! Array.isArray(Object2D[key]) ) {
|
|
24
|
+
// 此属性是对象
|
|
25
|
+
for( let key2 in Object2D[key] ) {
|
|
26
|
+
if( data[key][key2] != undefined ) Object2D[key][key2] = data[key][key2];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// 此属性是数组
|
|
31
|
+
for( let i = 0; i < Object2D[key].length; i++ ) {
|
|
32
|
+
if( data[key][i] != undefined ) Object2D[key][i] = data[key][i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// 正常替换
|
|
38
|
+
Object2D[key] = data[key];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function concatFloat32Arrays( arrays ) {
|
|
46
|
+
const result = [];
|
|
47
|
+
|
|
48
|
+
let arr;
|
|
49
|
+
for(let i=0; i<arrays.length; i++) {
|
|
50
|
+
arr = arrays[i];
|
|
51
|
+
for(let j=0; j<arr.length; j++) {
|
|
52
|
+
result.push(arr[j]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return new Float32Array(result);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function cross( x1, y1, x2, y2 ) {
|
|
60
|
+
return x1 * y2 - x2 * y1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function containTriangle( x0, y0, x1, y1, x2, y2, x3, y3 ) {
|
|
64
|
+
let state = false;
|
|
65
|
+
|
|
66
|
+
const AB = { x: x2-x1, y: y2-y1 },
|
|
67
|
+
BC = { x: x3-x2, y: y3-y2 },
|
|
68
|
+
CA = { x: x1-x3, y: y1-y3 },
|
|
69
|
+
AP = { x: x0-x1, y: y0-y1 },
|
|
70
|
+
BP = { x: x0-x2, y: y0-y2 },
|
|
71
|
+
CP = { x: x0-x3, y: y0-y3 },
|
|
72
|
+
CAP = cross(AB.x, AB.y, AP.x, AP.y),
|
|
73
|
+
CBP = cross(BC.x, BC.y, BP.x, BP.y),
|
|
74
|
+
CCP = cross(CA.x, CA.y, CP.x, CP.y);
|
|
75
|
+
|
|
76
|
+
if( CAP>0&&CBP>0&&CCP>0 || !CAP&&CBP*CCP!=0 || !CBP&&CAP*CCP!=0 || !CCP&&CAP*CBP!=0 || !CAP&&!CBP || !CBP&&!CCP || !CCP&&!CAP ) {
|
|
77
|
+
state = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return state;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function polygonArea2( pathVertices ) {
|
|
84
|
+
const points = [...pathVertices], count = pathVertices.length; // 复制数组
|
|
85
|
+
points.push( pathVertices[0], pathVertices[1] ); // 添加起点
|
|
86
|
+
let area = 0;
|
|
87
|
+
for(let i=0; i<count; i+=2) {
|
|
88
|
+
area += cross(points[i], points[i+1], points[i+2], points[i+3]);
|
|
89
|
+
}
|
|
90
|
+
area *= 0.5;
|
|
91
|
+
return area;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function arrDel( arr, start, num ) {
|
|
95
|
+
const count = arr.length;
|
|
96
|
+
if(start >= count) start %= count;
|
|
97
|
+
|
|
98
|
+
if(start+num <= count) {
|
|
99
|
+
arr.splice(start, num);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const num2 = count-start;
|
|
103
|
+
arr.splice(start, num2);
|
|
104
|
+
arr.splice(0, num-num2);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//function arrayAsyncForEach( element, func, index=0 ) {
|
|
109
|
+
// func(element[index]);
|
|
110
|
+
//}
|
|
111
|
+
|
|
112
|
+
export { extract, concatFloat32Arrays, cross, containTriangle, polygonArea2, arrDel };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Vector3, Matrix4 } from '../math/matrix.js';
|
|
2
|
+
|
|
3
|
+
const { sin, cos } = Math;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CatsJS-2D相机
|
|
7
|
+
* 当前版本 0.3
|
|
8
|
+
* 于2025年3月16日开始开发
|
|
9
|
+
* @author MiaoShangZuan <3268208143@qq.com>
|
|
10
|
+
*/
|
|
11
|
+
class Camera2D {
|
|
12
|
+
constructor( near=0.1, far=20 ) {
|
|
13
|
+
this.type = 'Camera';
|
|
14
|
+
this.rotate = 0;
|
|
15
|
+
this.position = new Vector3( 0, 0, 10 );
|
|
16
|
+
this.near = near;
|
|
17
|
+
this.far = far;
|
|
18
|
+
this.unitX = 70;
|
|
19
|
+
this.unitY = 70;
|
|
20
|
+
this.model = undefined;
|
|
21
|
+
}
|
|
22
|
+
matrix() {
|
|
23
|
+
const _m = 1 / (this.near-this.far),
|
|
24
|
+
sinz = sin(this.rotate), cosz = cos(this.rotate);
|
|
25
|
+
let zoom = 1;
|
|
26
|
+
if(this.position.z > 0) zoom = 10/this.position.z;
|
|
27
|
+
if(this.model) {
|
|
28
|
+
this.position.x = this.model.position.x;
|
|
29
|
+
this.position.y = this.model.position.y;
|
|
30
|
+
}
|
|
31
|
+
return new Matrix4([
|
|
32
|
+
zoom*cosz, -zoom*sinz, 0, -this.position.x*zoom,
|
|
33
|
+
zoom*sinz, zoom*cosz, 0, -this.position.y*zoom,
|
|
34
|
+
0, 0, 2*_m, (this.near+this.far-2*this.position.z)*_m,
|
|
35
|
+
0, 0, 0, 1
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default Camera2D;
|
package/build/cats2d.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { MatrixNxM, Matrix2, Matrix3, Matrix4, VectorN, Vector2, Vector3, Vector4 } from './math/matrix.js';
|
|
2
|
+
import WebGLRenderer from './renderer/WebGLRenderer.js';
|
|
3
|
+
import Scene from './scene/Scene.js';
|
|
4
|
+
import Camera2D from './camera/Camera2D.js';
|
|
5
|
+
import {
|
|
6
|
+
Mesh, BufferGeometry, BasicMaterial, VertexMaterial, ArrayMaterial, RawTexture,
|
|
7
|
+
Bone, Skeleton, SkinnedMesh,
|
|
8
|
+
RectGeometry, CircleGeometry, MergeGeometry,
|
|
9
|
+
Group, MeshHelper, GridHelper, BezierHelper, RectHelper, CircleHelper, SkeletonHelper
|
|
10
|
+
} from './model/Object2D.js';
|
|
11
|
+
import {
|
|
12
|
+
BezierToCure, CureToShape, Extrusion,
|
|
13
|
+
EllipseGeometry, IsoscelesGeometry, StarGeometry, HeartGeometry,
|
|
14
|
+
MeshHelperX, EllipseHelper, StarHelper, HeartHelper
|
|
15
|
+
} from './plugins/moreObject2D.js';
|
|
16
|
+
import { AnBezier, AnFunc, AnLerp, AnCureController, Animation, AnGetBezierFunc } from './plugins/animation.js';
|
|
17
|
+
import * as MathUtils from './math/utils.js';
|
|
18
|
+
import PerlinNoise from './math/PerlinNoise.js';
|
|
19
|
+
import FileLoader from './plugins/loaders/FileLoader.js';
|
|
20
|
+
import TextLoader from './plugins/loaders/TextLoader.js';
|
|
21
|
+
import TextureLoader from './plugins/loaders/TextureLoader.js';
|
|
22
|
+
import StringLoader from './plugins/loaders/StringLoader.js';
|
|
23
|
+
// import ChainConstraint from './plugins/controllers/ChainConstraint.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* CatsJS
|
|
27
|
+
* beta_0.1.29
|
|
28
|
+
* 于2023年1月25日开始开发
|
|
29
|
+
* 于2023年4月9日发布第一个版本(下载地址已失效)
|
|
30
|
+
* @author MiaoShangZuan <3268208143@qq.com>
|
|
31
|
+
*
|
|
32
|
+
*
|
|
33
|
+
* /\_/\
|
|
34
|
+
* ( o.o )
|
|
35
|
+
* > ^ <
|
|
36
|
+
* / /\
|
|
37
|
+
* // 真 的 猫 //
|
|
38
|
+
* // 保 佑 代 码 //
|
|
39
|
+
* // 永 无 BUG //
|
|
40
|
+
*/
|
|
41
|
+
const Version = 'beta 0.1.29';
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
Version,
|
|
45
|
+
MatrixNxM, Matrix2, Matrix3, Matrix4, VectorN, Vector2, Vector3, Vector4,
|
|
46
|
+
WebGLRenderer, Scene, Camera2D, Mesh,
|
|
47
|
+
BufferGeometry, BasicMaterial, VertexMaterial, ArrayMaterial, RawTexture,
|
|
48
|
+
Bone, Skeleton, SkinnedMesh,
|
|
49
|
+
RectGeometry, CircleGeometry, MergeGeometry,
|
|
50
|
+
Group, MeshHelper, GridHelper, BezierHelper, RectHelper, CircleHelper, SkeletonHelper,
|
|
51
|
+
BezierToCure, CureToShape, Extrusion,
|
|
52
|
+
EllipseGeometry, IsoscelesGeometry, StarGeometry, HeartGeometry,
|
|
53
|
+
MeshHelperX, EllipseHelper, StarHelper, HeartHelper,
|
|
54
|
+
AnBezier, AnFunc, AnLerp, AnCureController, Animation, AnGetBezierFunc,
|
|
55
|
+
MathUtils, PerlinNoise,
|
|
56
|
+
FileLoader, TextLoader, TextureLoader, StringLoader
|
|
57
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* CatsJS
|
|
4
|
+
* beta_0.1.29
|
|
5
|
+
* 于2023年1月25日开始开发
|
|
6
|
+
* 于2023年4月9日发布第一个版本(下载地址已失效)
|
|
7
|
+
* @author MiaoShangZuan <3268208143@qq.com>
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* /\_/\
|
|
11
|
+
* ( o.o )
|
|
12
|
+
* > ^ <
|
|
13
|
+
* / /\
|
|
14
|
+
* // 真 的 猫 //
|
|
15
|
+
* // 保 佑 代 码 //
|
|
16
|
+
* // 永 无 BUG //
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const t=Math.abs,e=Math.sqrt;function s(t,e,s){if(t.line==e.line&&t.column==e.column){const i=[],n=t.line*t.column;let r;for(let o=0;o<n;o++)r=t.element[o]+s*e.element[o],i.push(r);return i}}function i(t,e){const s=[];let i;if("number"==typeof e)t.element.forEach(t=>{i=t*e,s.push(i)});else if(t.column==e.line)for(let n=0;n<t.line;n++)for(let r=0;r<e.column;r++){i=0;for(let s=0;s<t.column;s++)i+=t.element[n*t.column+s]*e.element[s*e.column+r];s.push(i)}return s}function n(t,e){let s=0;if(1==e)s=t[0];else if(2==e)s=t[0]*t[3]-t[1]*t[2];else if(3==e){const e=t[0],i=t[1],n=t[2],r=t[3],o=t[4],a=t[5],h=t[6],l=t[7],c=t[8];s=e*o*c-e*a*l+n*r*l-i*r*c+i*a*h-n*o*h}else if(4==e){const e=t[0],i=t[1],n=t[2],r=t[3],o=t[4],a=t[5],h=t[6],l=t[7],c=t[8],u=t[9],_=t[10],m=t[11];t[12];const p=t[13],f=t[14],d=t[15];s=e*a*_*d-e*a*m*f-e*h*u*d+e*l*u*f+e*h*m*p-e*l*_*p-i*o*_*d+i*o*m*f+n*o*u*d-r*o*u*f-n*o*m*p+r*o*_*p+i*h*c*d-i*l*c*f-n*a*c*d+r*a*c*f}else{let i;for(let n=0;n<e;n++)i=t[n]*r(t,e,0,n),s+=i}return s}function r(t,e,s,i){const r=[];let o;for(let n=0;n<e;n++)if(n!=s)for(let s=0;s<e;s++)s!=i&&(o=s+e*n,r.push(t[o]));return n(r,e-1)*function(t=0){return t%2==0?1:-1}(s+i)}function o(t){if(t.line==t.column&&t.line>1&&t.column>1){const e=[];let s;for(let i=0;i<t.line;i++)for(let n=0;n<t.column;n++)s=r(t.element,t.line,i,n),e.push(s);return e}}function a(t,e){let s,i=0;if(t.line==e.line&&1==t.column&&1==e.column)for(let n=0;n<t.element.length;n++)s=t.element[n]*e.element[n],i+=s;return i}function h(t){if(t.line>0&&1==t.column){let s=0;return t.element.forEach(t=>{s+=t*t}),e(s)}}function l(t,e=1){if(t.line>0&&1==t.column){const s=1/h(t),i=[];let n;return t.element.forEach(t=>{n=t*s*e,i.push(n)}),i}}class c{constructor(t=2,e=2,s=[1,0,0,1]){this.type="Matrix",this.line=t,this.column=e;const i=t*e;if(s.length==i)this.element=s;else{this.element=[];for(let t=0;t<i;t++)this.element.push(0)}}step(t=2,e=2){const s=t*e;if(this.line=t,this.column=e,this.element.length!=s){this.element=[];for(let t=0;t<s;t++)this.element.push(0)}}set(t=[1,0,0,1]){const e=this.line*this.column;t.length==e?this.element=t:console.error("参数错误!")}copy(t){if(this.line==t.line&&this.column==t.column){const e=[];t.element.forEach(t=>{e.push(t)}),this.element=e}}addition(t){this.line==t.line&&this.column==t.column?this.element=s(this,t,1):console.error("参数错误!")}subtract(t){this.line==t.line&&this.column==t.column?this.element=s(this,t,-1):console.error("参数错误!")}multiply(t){"number"==typeof t?this.element=i(this,t):this.column==t.line?(this.element=i(this,t),this.column=t.column):console.error("参数错误!")}premultiply(t){"number"==typeof t?this.element=i(this,t):t.column==this.line?(this.element=i(t,this),this.line=t.line):console.error("参数错误!")}det(){if(this.line==this.column&&this.line>1)return n(this.element,this.line);console.error("参数错误!")}cofactor(t=1,e=1){if(this.line==this.column&&this.line>1)return r(this.element,this.line,t-1,e-1);console.error("参数错误!")}adjoint(){if(this.line==this.column&&this.line>1)return new c(this.line,this.column,o(this));console.error("参数错误!")}inverse(){if(this.line==this.column&&this.line>1)return new c(this.line,this.column,function(e){if(e.line==e.column){let s=n(e.element,e.line);if(t(s)>1e-9){s=1/s;const t=[];let i;return o(e).forEach(e=>{i=e*s,t.push(i)}),t}console.error("此矩阵无逆矩阵")}}(this));console.error("参数错误!")}reduction(){this.line>1&&1==this.column?(this.element=function(t){if(t.line>1&&1==t.column){const e=[],s=t.line-1;let i;for(let n=0;n<s;n++)i=t.element[n]/t.element[s],e.push(i);return e}}(this),this.line-=1):console.error("参数错误!")}reverse(){const t=this.line,e=this.column;this.element=function(t){const e=[];let s;for(let i=0;i<t.column;i++)for(let n=0;n<t.line;n++)s=t.element[n*t.column+i],e.push(s);return e}(this),this.line=e,this.column=t}}class u extends c{constructor(t=[1,0,0,1]){super(2,2,t)}}class _ extends c{constructor(t=[1,0,0,0,1,0,0,0,1]){super(3,3,t)}}class m extends c{constructor(t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]){super(4,4,t)}}class p{constructor(t=[0,0]){this.type="Vector",this.line=t.length,this.column=1,this.element=t}set(t=[0,0]){this.line=t.length,this.element=t}copy(t){if(this.line==t.line)for(let e=0;e<this.line;e++)this.element[e]=t.element[e];else console.error("参数错误!")}addition(t){this.line==t.line&&1==t.column?this.element=s(this,t,1):console.error("参数错误!")}subtract(t){this.line==t.line&&1==t.column?this.element=s(this,t,-1):console.error("参数错误!")}multiply(t){if("number"==typeof t)this.element=i(this,t);else{if(this.line==t.line&&1==t.column)return a(this,t);console.error("参数错误!")}}transform(t){"Matrix"==t.type&&t.column==this.line?this.element=i(t,this):console.error("参数错误!")}angle(t){if(this.line==t.line&&1==t.column)return function(t,e){if(t.line==e.line&&1==t.column&&1==e.column)return a(t,e)/(h(t)*h(e))}(this,t);console.error("参数错误!")}projection(t){if(this.line==t.line&&1==t.column)return function(t,e){if(t.line==e.line&&1==t.column&&1==e.column){const s=l(e,1);let i=0;for(let e=0;e<s.length;e++)i+=t.element[e]*s[e];return i}}(t,this);console.error("参数错误!")}norm(){return h(this)}scale(t=1){this.element=l(this,t)}unit(){const t=l(this,1);return new p(t)}reverse(){const t=this.line,e=this.column;this.line=e,this.column=t}}class f extends p{constructor(t=0,e=0){super([t,e])}get x(){return this.element[0]}set x(t=0){this.element[0]=t}get y(){return this.element[1]}set y(t=0){this.element[1]=t}set(t=0,e=0){this.element[0]=t,this.element[1]=e}unit(){const t=l(this,1);return new f(t[0],t[1])}}class d extends p{constructor(t=0,e=0,s=0){super([t,e,s])}get x(){return this.element[0]}set x(t=0){this.element[0]=t}get y(){return this.element[1]}set y(t=0){this.element[1]=t}get z(){return this.element[2]}set z(t=0){this.element[2]=t}set(t=0,e=0,s=0){this.element[0]=t,this.element[1]=e,this.element[2]=s}unit(){const t=l(this,1);return new d(t[0],t[1],t[2])}}class T extends p{constructor(t=0,e=0,s=0,i=0){super([t,e,s,i])}get x(){return this.element[0]}set x(t=0){this.element[0]=t}get y(){return this.element[1]}set y(t=0){this.element[1]=t}get z(){return this.element[2]}set z(t=0){this.element[2]=t}get w(){return this.element[3]}set w(t=0){this.element[3]=t}set(t=0,e=0,s=0,i=0){this.element[0]=t,this.element[1]=e,this.element[2]=s,this.element[3]=i}unit(){const t=l(this,1);return new T(t[0],t[1],t[2],t[3])}}class x{constructor(){this.width=300,this.height=300,this.naturalWidth=300,this.naturalHeight=300,this.domElement=document.createElement("canvas"),this.domElement.width=300,this.domElement.height=300,this.domElement.style.width="300px",this.domElement.style.height="300px",this.gl=this.domElement.getContext("webgl2"),this.TEXTURE_UNIT_BUFFER={},this.PROGRAMS=[]}setSize(t=300,e=300){this.width=t,this.height=e,this.naturalWidth=t,this.naturalHeight=e,this.domElement.width=t,this.domElement.height=e,this.domElement.style.width=`${t}px`,this.domElement.style.height=`${e}px`,this.gl.viewport(0,0,t,e)}setPixelRatio(t){const e=this.width*t,s=this.height*t;this.naturalWidth=e,this.naturalHeight=s,this.domElement.width=e,this.domElement.height=s,this.gl.viewport(0,0,e,s)}createShader(t,e){const s=this.gl,i=s.createShader(t);return s.shaderSource(i,e),s.compileShader(i),i}createProgram(t,e){const s=this.gl,i=this.createShader(s.VERTEX_SHADER,t),n=this.createShader(s.FRAGMENT_SHADER,e),r=s.createProgram();return s.attachShader(r,i),s.attachShader(r,n),s.linkProgram(r),s.deleteShader(i),s.deleteShader(n),r}deleteBuffer(t){this.gl.deleteBuffer(t)}getTextureUnits(){return this.gl.getParameter(this.gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS)}getPassCount(){return this.PROGRAMS.length}inBlankTextureUnit(t,e,s=0,i={}){const n=this.gl,r=n.createTexture(),o=i.filterMin||n.NEAREST,a=i.filterMag||n.NEAREST,h=i.wrapS||n.CLAMP_TO_EDGE,l=i.wrapT||n.CLAMP_TO_EDGE,c=i.internalformat||n.RGBA8,u=i.format||n.RGBA,_=i.type||n.UNSIGNED_BYTE;n.activeTexture(n.TEXTURE0+s),n.bindTexture(n.TEXTURE_2D,r),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!0),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,o),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,a),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,h),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,l),n.texImage2D(n.TEXTURE_2D,0,c,t,e,0,u,_,null),this.TEXTURE_UNIT_BUFFER[`unit_${s}`]=r}inTextureUnit(t,e=0,s={}){const i=this.gl,n=i.createTexture(),r=s.filterMin||i.NEAREST,o=s.filterMag||i.NEAREST,a=s.wrapS||i.CLAMP_TO_EDGE,h=s.wrapT||i.CLAMP_TO_EDGE;i.activeTexture(i.TEXTURE0+e),i.bindTexture(i.TEXTURE_2D,n),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,!0),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,r),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,o),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,a),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,h),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),r!==i.LINEAR_MIPMAP_LINEAR&&r!==i.LINEAR_MIPMAP_NEAREST&&r!==i.NEAREST_MIPMAP_LINEAR&&r!==i.NEAREST_MIPMAP_NEAREST||i.generateMipmap(i.TEXTURE_2D),n.media=t,this.TEXTURE_UNIT_BUFFER[`unit_${e}`]=n}updateTextureUnit(t=0){const e=this.gl,s=this.TEXTURE_UNIT_BUFFER[`unit_${t}`];s&&(e.bindTexture(e.TEXTURE_2D,s),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,s.media))}getTextureUnit(t=0){return this.TEXTURE_UNIT_BUFFER[`unit_${t}`]}existsTextureUnit(t=0){return!!this.TEXTURE_UNIT_BUFFER[`unit_${t}`]}deleteTextureUnit(t=0){const e=this.TEXTURE_UNIT_BUFFER[`unit_${t}`];e&&(this.gl.deleteTexture(e),this.TEXTURE_UNIT_BUFFER[`unit_${t}`]=void 0)}getUniformLocation(t,e){return this.PROGRAMS[t.sequence].uniformLocation[e]}addPass(t){let e;t.program?(e=t.program,e.sequence=this.PROGRAMS.length):t.vertexSource&&t.fragmentSource&&(e=this.createProgram(t.vertexSource,t.fragmentSource),e.sequence=this.PROGRAMS.length);const s={program:e,uniformLocation:{},drawFunc:t.drawFunc,drawStartFunc:t.drawStartFunc,drawEndFunc:t.drawEndFunc};if(e&&t.uniformarr)for(let i of t.uniformarr)s.uniformLocation[i]=this.gl.getUniformLocation(e,i);this.PROGRAMS.push(s)}renderPicture(){for(let t of this.PROGRAMS)t.drawFunc(this.gl,t.program,t.drawStartFunc,t.drawEndFunc)}outputAsync(){return new Promise(t=>{const e=new Image;e.src=this.domElement.toDataURL("image/png"),e.onload=()=>{t(e)}})}}const{trunc:E,pow:g}=Math;class R{constructor(){this._texture_pixel_unit_=450,this._texture_size_max_=9,this._texture_canvas_=document.createElement("canvas"),this._texture_canvas_.width=this._texture_canvas_.height=this._texture_pixel_unit_,this._texture_ctx_=this._texture_canvas_.getContext("2d")}setTexturePixelUnit(t){this._texture_pixel_unit_=t}getMaps(t){const e=[],s=[];let i,n=0;for(let r of t)i=r.getSizeValue(this._texture_pixel_unit_),"video"==r.mediaType?(r.mapUnit=n+16,n++,s.push(r)):i<=this._texture_size_max_&&(e[i-1]?-1==e[i-1].indexOf(r)&&e[i-1].push(r):e[i-1]=[r]);for(let t=0;t<e.length;t++)e[t]||(e[t]=[]);return{maps:e,videos:s}}processingMaps(t,e=0,s=0){if(s+1<this._texture_size_max_){const i=t[e];if(i.length>0){const n=E(.25*i[s].length);if(n>0){let t;for(let e=0;e<n;e++){t={pixel_unit:s+2,element:[]};for(let e=0;e<4;e++)t.element.push(i[s][0]),i[s].splice(0,1);i[s+1]?i[s+1].push(t):i[s+1]=[t]}}i[++s]&&this.processingMaps(t,e,s)}}else{const i=t[e],n=i[s].length;let r=4;for(let t=0;t<=s;t++)if(i[t].length>0){r=3;break}if(n>r){const o=[];for(let t=0;t<=s;t++)o.push([]);for(let t=r;t<n;t++)o[s].push(i[s][t]);i[s].splice(r,n-r),t.push(o),e++,this.processingMaps(t,e,s)}}}setSpriteSize(t){const e=t.length,s=t[e-1].length,i=g(2,e-1);let n=this._texture_pixel_unit_,r=this._texture_pixel_unit_,o=!1,a=0;for(;a<e-1;)t[a].length>0&&(o=!0,a=e),a++;o?s<3?(n*=(s+1)*i,r*=i):(n*=2*i,r*=2*i):s<4?(n*=s*i,r*=i):(n*=2*i,r*=2*i),this._texture_canvas_.width=n,this._texture_canvas_.height=r,this._texture_ctx_.imageSmoothingEnabled=!1}drawMap(t,e,s,i){if(e.pixel_unit){const n=g(2,e.pixel_unit-2)*this._texture_pixel_unit_;let r,o;for(let a=0;a<4;a++)r=s+a%2*n,o=i+E(a/2)*n,this.drawMap(t,e.element[a],r,o)}else{const n=this._texture_canvas_.width,r=this._texture_canvas_.height,o=this._texture_pixel_unit_*g(2,e.getSizeValue(this._texture_pixel_unit_)-1),a=o/n,h=o/r,l=s/n,c=(r-i)/r;this._texture_ctx_.beginPath(),this._texture_ctx_.drawImage(e.media,s,i,o,o),this._texture_ctx_.closePath(),e.activate=!0,e.mapUnit=t+10,e.uvmat.set([a,0,l,0,h,c-h,0,0,1])}}drawingMaps(t,e,s,i,n){if(s>0){const r=e[s-1].length,o=g(2,s-1)*this._texture_pixel_unit_;if(r>0){let a,h;for(let l=0;l<r;l++)a=i+l%2*o,h=n+E(l/2)*o,this.drawMap(t,e[s-1][l],a,h);i+=r%2*o,n+=E(r/2)*o}this.drawingMaps(t,e,s-1,i,n)}}render(t,e){this.setSpriteSize(e),this._texture_ctx_.clearRect(0,0,this._texture_canvas_.width,this._texture_canvas_.height);const s=e.length,i=e[s-1].length,n=g(2,s-1)*this._texture_pixel_unit_;let r,o;if(this._texture_canvas_.width==this._texture_canvas_.height)for(let a=0;a<i;a++)r=a%2*n,o=E(a/2)*n,this.drawMap(t,e[s-1][a],r,o);else for(let a=0;a<i;a++)r=a*n,o=0,this.drawMap(t,e[s-1][a],r,o);return r+=n,this.drawingMaps(t,e,s-1,r,o),new Promise(t=>{const e=new Image;e.src=this._texture_canvas_.toDataURL("image/png"),e.onload=()=>{t(e)}})}createSprite(t){const e=this.getMaps(t),s=[e.maps];this.processingMaps(s);const i=[];for(let t=0;t<s.length;t++)s[t].length>0&&i.push(this.render(t,s[t]));return new Promise(t=>{(async function(t){const e=[];for await(let s of t)e.push(s);return e})(i).then(s=>t({images:s,videos:e.videos}))})}}function y(t,e,s=1){const i=new Array,n=new Object,r=new Array;let o,a=0;return t.forEach(t=>{a=function(t,e){const s=JSON.parse('["'+e.replace(/\./g,'","')+'"]');let i=t;for(let t=0;t<s.length;t++)i=i[s[t]];return i}(t,e),i.push(a),null==n["key_"+a]?n["key_"+a]=[t]:n["key_"+a].push(t)}),i.sort((t,e)=>s*(t-e)).forEach(t=>{t!=o&&(n["key_"+t].forEach(t=>{r.push(t)}),o=t)}),r}const{min:A,max:U}=Math,v="#version 300 es\nvoid main() {\n float x = mod(floor(float(gl_VertexID+1) / 3.0), 2.0) * 2.0 - 1.0;\n float y = mod(floor(float(gl_VertexID+5) / 3.0), 2.0) * 2.0 - 1.0;\n gl_Position = vec4(x, y, 0.999999, 1.0);\n}",S="\n/*\n * bcol 背景色\n * fcol 前景色\n */\nvec4 colorBlend(vec4 bcol, vec4 fcol) {\n\tfloat a = bcol.a * (1. - fcol.a),\n alpha = fcol.a + a,\n alphasve = alpha > 1e-3 ? 1.0/alpha : 0.0;\n\treturn vec4(\n \t(bcol.r * a + fcol.r * fcol.a) * alphasve,\n (bcol.g * a + fcol.g * fcol.a) * alphasve,\n (bcol.b * a + fcol.b * fcol.a) * alphasve,\n alpha\n );\n}";class M extends x{constructor(){super(),this.type="Renderer",this.SpriteGenerator=new R,this._sprite_state_=!1,this._multi_pass_state_=!1,this.DRAW_ATTRIBUTES={scene:void 0,camera:void 0,vs_mat:void 0,INIT_TEXTUREUNITS_STATE:!1,INIT_TEXTUREUNITS_ONLOAD:void 0,INIT_TEXTUREUNITS_ONLOAD2:void 0,INIT_TEXTUREUNITS_ONLOAD_STATE:!1},this.MAIN_VERTEX_SHADER_SOURCE="\nvoid main() {\n gl_Position = vertTransform();\n}\n",this.MAIN_FRAGMENT_SHADER_SOURCE="\nvoid main() {\n o_texture = fragOutput();\n o_depthtex = gl_FragCoord.z;\n //colorShade(o_texture, o_depthtex);\n}\n",this.FRAG_1_SHADER_SOURCE=void 0,this.FRAG_2_SHADER_SOURCE=void 0,this.FRAG_3_SHADER_SOURCE=void 0,this.POST_FX_SOURCE="\nvoid PostFX(out vec4 fragColor, in vec2 fragCoord) {\n // 芝士后处理函数~\n // 在这里写后处理代码\n}\n",this.MAIN_PASS_DRAW_START=void 0,this.MAIN_PASS_DRAW_END=void 0,this.FRAG_1_PASS_DRAW_START=void 0,this.FRAG_1_PASS_DRAW_END=void 0,this.FRAG_2_PASS_DRAW_START=void 0,this.FRAG_2_PASS_DRAW_END=void 0,this.FRAG_3_PASS_DRAW_START=void 0,this.FRAG_3_PASS_DRAW_END=void 0,this.FINAL_PASS_DRAW_START=void 0,this.FINAL_PASS_DRAW_END=void 0,this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA={index:-1,mapUnit:0,mapUnit1:-1,mapUnit2:-1,mapUnit3:-1},this.FRAMEBUFFER0=void 0,this.FRAMEBUFFER2=void 0,this.FRAMEBUFFER3=void 0,this.FRAMEBUFFER4=void 0,this.TEXTURE_UNIT_0_MIPMAP=!1,this.TEXTURE_UNIT_4_MIPMAP=!1,this.TEXTURE_UNIT_5_MIPMAP=!1,this.TEXTURE_UNIT_6_MIPMAP=!1,this.TEXTURE_UNIT_7_MIPMAP=!1,this.TEXTURE_UNIT_8_MIPMAP=!1,this.TEXTURE_UNIT_9_MIPMAP=!1,this.fragmentShaderExtension=!1,this.updateDrawFunc=(t,e,s)=>{const i=this.DRAW_ATTRIBUTES.scene;if(t){const t=A(6,e.length);for(let s=0;s<t;s++){const t=s+10;this.existsTextureUnit(t)&&this.deleteTextureUnit(t),this.inTextureUnit(e[s],t),i.setSpriteTexture(e[s])}const n=A(6,s.length);for(let t=0;t<n;t++){const e=t+16;this.existsTextureUnit(e)&&this.deleteTextureUnit(e),this.inTextureUnit(s[t].media,e)}for(let t of i.element)if(t.material&&t.material.maps&&t.material.maps.length>0)for(let e of t.material.maps)e.glTexture=this.getTextureUnit(e.mapUnit)}this.DRAW_ATTRIBUTES.INIT_TEXTUREUNITS_ONLOAD?.(),this.DRAW_ATTRIBUTES.INIT_TEXTUREUNITS_STATE||(this.DRAW_ATTRIBUTES.INIT_TEXTUREUNITS_STATE=!0,this.DRAW_ATTRIBUTES.INIT_TEXTUREUNITS_ONLOAD2?.())}}getFragsShaderSource(t=1){let e=this[`FRAG_${t}_SHADER_SOURCE`];if(!e){const s=1==t?"u_texture":`u_colortex${this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA["mapUnit"+(t-1)]}`;e=`\nuniform sampler2D ${s};\nuniform vec2 u_resolution;\nout vec4 fragColor;\nvoid main() {\n vec2 texcoord = gl_FragCoord.xy / u_resolution;\n fragColor = texture(${s}, texcoord);\n}`}return e}setMainDrawStart(t){this.MAIN_PASS_DRAW_START=t}setMainDrawEnd(t){this.MAIN_PASS_DRAW_END=t}setFragsDrawStart(t=1,e){this[`FRAG_${t}_PASS_DRAW_START`]=e}setFragsDrawEnd(t=1,e){this[`FRAG_${t}_PASS_DRAW_END`]=e}setFinalDrawStart(t){this.FINAL_PASS_DRAW_START=t}setFinalDrawEnd(t){this.FINAL_PASS_DRAW_END=t}setVertSource(t){this.MAIN_VERTEX_SHADER_SOURCE=t}setFragSource(t){this.MAIN_FRAGMENT_SHADER_SOURCE=t}setFragsSource(t=1,e){this[`FRAG_${t}_SHADER_SOURCE`]=e}setPostFXSource(t){this.POST_FX_SOURCE=t}setTextureUnitMipmap(t=0,e=!1){if(this[`TEXTURE_UNIT_${t}_MIPMAP`]=e,!e){const e=this.gl;e.bindTexture(e.TEXTURE_2D,this.getTextureUnit(t)),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.bindTexture(e.TEXTURE_2D,null)}}activateFragShader(t=4){if(t<4||this.existsTextureUnit(t))console.error(`第${t}号纹理单元已被占用!`);else if(this.fragmentShaderExtension){const e=this.gl,s=U(1,this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA.index+1);this.inBlankTextureUnit(this.naturalWidth,this.naturalHeight,t,{filterMin:e.LINEAR,filterMag:e.LINEAR});const i=this.getTextureUnit(t),n=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,n),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.bindFramebuffer(e.FRAMEBUFFER,null),this[`FRAMEBUFFER${s+1}`]=n,this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA[`mapUnit${s}`]=t,this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA.index=s,this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA.mapUnit=t}}setAssetPreloading(t,e,s){this.DRAW_ATTRIBUTES.scene=t,this.DRAW_ATTRIBUTES.camera=e,this.DRAW_ATTRIBUTES.INIT_TEXTUREUNITS_ONLOAD2=s}assetPreloading(){this.updateMaps(this.DRAW_ATTRIBUTES.scene.element,this.updateDrawFunc)}initMultiPass(){if(!this._multi_pass_state_){if(this.addPass({vertexSource:`#version 300 es\nlayout(location = 0) in vec3 a_position;\nlayout(location = 1) in vec4 a_color;\nlayout(location = 2) in vec3 a_uv;\n\nuniform mat4 u_mvsmat;\nuniform int u_id;\n\nout vec4 v_color;\nout vec3 v_uv;\n\nvec4 vertTransform() {\n v_color = a_color;\n v_uv = a_uv;\n return u_mvsmat * vec4( a_position, 1.0 );\n}\n\n${this.MAIN_VERTEX_SHADER_SOURCE}`,fragmentSource:`#version 300 es\nprecision highp float;\nprecision highp int;\n\nlayout(location = 0) out vec4 o_texture;\nlayout(location = 1) out float o_depthtex;\n\nuniform sampler2D u_imagetex;\nuniform vec2 u_resolution;\nuniform mat3 u_uvmat;\nuniform int u_id;\n\nin vec4 v_color;\nin vec3 v_uv;\n\n${S}\n\nvec4 fragOutput() {\n vec4 color = v_color;\n if( v_uv.p > 0.0 ) {\n vec3 uv = u_uvmat * v_uv;\n vec4 pixel = texture( u_imagetex, uv.st );\n color.rgb = pixel.rgb;\n color.a *= pixel.a;\n }\n return color;\n}\n\n${this.MAIN_FRAGMENT_SHADER_SOURCE}`,drawFunc:(t,e)=>{t.useProgram(e),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA);const s=this.DRAW_ATTRIBUTES.camera;t.uniform1i(t.getUniformLocation(e,"u_imagetex"),10);const i=new m([s.unitX/this.width*2,0,0,0,0,s.unitY/this.height*2,0,0,0,0,1,0,0,0,0,1]);i.multiply(s.matrix()),this.DRAW_ATTRIBUTES.vs_mat=i,this.MAIN_PASS_DRAW_START?.(t,e),this.DRAW_ATTRIBUTES.INIT_TEXTUREUNITS_ONLOAD_STATE||(this.DRAW_ATTRIBUTES.INIT_TEXTUREUNITS_ONLOAD=()=>{const s=y(this.DRAW_ATTRIBUTES.scene.element,"position.z"),i=this.getTextureUnit(0);if(this.TEXTURE_UNIT_0_MIPMAP&&(t.bindTexture(t.TEXTURE_2D,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.bindTexture(t.TEXTURE_2D,null)),t.bindFramebuffer(t.FRAMEBUFFER,this.FRAMEBUFFER0),t.clearBufferfv(t.COLOR,0,[0,0,0,0]),t.clearBufferfv(t.COLOR,1,[0,0,0,0]),s.forEach(s=>s.draw(t,e,this.DRAW_ATTRIBUTES.vs_mat)),t.bindFramebuffer(t.FRAMEBUFFER,null),this.TEXTURE_UNIT_0_MIPMAP&&(t.bindTexture(t.TEXTURE_2D,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR),t.generateMipmap(t.TEXTURE_2D),t.bindTexture(t.TEXTURE_2D,null)),this.MAIN_PASS_DRAW_END?.(t,e),this.fragmentShaderExtension)for(let e=2;e<this.PROGRAMS.length;e++){const s=this.PROGRAMS[e];s.drawFunc(t,s.program)}const n=this.PROGRAMS[1];n.drawFunc(t,n.program)},this.DRAW_ATTRIBUTES.INIT_TEXTUREUNITS_ONLOAD_STATE=!0),this.assetPreloading()}}),this.addPass({vertexSource:v,fragmentSource:`#version 300 es\nprecision highp float;\nprecision highp int;\n\nout vec4 fragColor;\n\nuniform sampler2D u_texture;\nuniform sampler2D u_depthtex;\nuniform vec2 u_resolution;\nuniform vec4 u_background;\n\n${S}\n\n${this.POST_FX_SOURCE}\n\nvoid main() {\n vec2 uv = gl_FragCoord.xy / u_resolution;\n vec4 color = u_background;\n vec4 map = texture(u_texture, uv);\n //map.rgb /= map.a;\n\n if(map.a > 1e-4) color = colorBlend(color, map);\n \n fragColor = color;\n PostFX(fragColor, gl_FragCoord.xy);\n}`,drawFunc:(t,e)=>{t.useProgram(e),t.blendFunc(t.ONE,t.ZERO);const s=this.DRAW_ATTRIBUTES.scene;t.uniform4f(t.getUniformLocation(e,"u_background"),s.color.r,s.color.g,s.color.b,s.color.a),this.FINAL_PASS_DRAW_START?.(t,e),t.drawArrays(t.TRIANGLES,0,6),this.FINAL_PASS_DRAW_END?.(t,e)}}),this.fragmentShaderExtension)for(let t=1;t<=this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA.index;t++)this.addPass({vertexSource:v,fragmentSource:`#version 300 es\nprecision highp float;\nprecision highp int;\n\n${S}\n\n${this.getFragsShaderSource(t)}`,drawFunc:(e,s)=>{e.useProgram(s),1==t&&e.blendFunc(e.ONE,e.ZERO),this[`FRAG_${t}_PASS_DRAW_START`]?.(e,s),e.bindFramebuffer(e.FRAMEBUFFER,this[`FRAMEBUFFER${t+1}`]),e.clearBufferfv(e.COLOR,0,[0,0,0,0]),e.drawArrays(e.TRIANGLES,0,6),e.bindFramebuffer(e.FRAMEBUFFER,null);const i=this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA[`mapUnit${t}`];this[`TEXTURE_UNIT_${i}_MIPMAP`]&&(e.bindTexture(e.TEXTURE_2D,this.getTextureUnit(i)),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.generateMipmap(e.TEXTURE_2D),e.bindTexture(e.TEXTURE_2D,null)),this[`FRAG_${t}_PASS_DRAW_END`]?.(e,s)}});const t=this.gl;t.enable(t.DEPTH_TEST),t.depthFunc(t.LEQUAL),t.enable(t.BLEND),t.depthMask(!1),this.inBlankTextureUnit(this.naturalWidth,this.naturalHeight,0,{filterMin:t.LINEAR,filterMag:t.LINEAR}),this.inBlankTextureUnit(this.naturalWidth,this.naturalHeight,1,{internalformat:t.R8,format:t.RED});const e=this.getTextureUnit(0),s=this.getTextureUnit(1),i=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,i),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT1,t.TEXTURE_2D,s,0),t.drawBuffers([t.COLOR_ATTACHMENT0,t.COLOR_ATTACHMENT1]),t.bindFramebuffer(t.FRAMEBUFFER,null),this.FRAMEBUFFER0=i;const n=this.PROGRAMS[0].program;t.useProgram(n),t.uniform2f(t.getUniformLocation(n,"u_resolution"),this.naturalWidth,this.naturalHeight);const r=this.PROGRAMS[1].program;if(t.useProgram(r),t.uniform1i(t.getUniformLocation(r,"u_texture"),this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA.mapUnit),t.uniform1i(t.getUniformLocation(r,"u_depthtex"),1),t.uniform2f(t.getUniformLocation(r,"u_resolution"),this.naturalWidth,this.naturalHeight),this.fragmentShaderExtension)for(let e=2;e<this.PROGRAMS.length;e++){const s=this.PROGRAMS[e].program;t.useProgram(s),t.uniform1i(t.getUniformLocation(s,"u_texture"),0),t.uniform1i(t.getUniformLocation(s,"u_depthtex"),1),t.uniform2f(t.getUniformLocation(s,"u_resolution"),this.naturalWidth,this.naturalHeight);for(let i=1;i<e;i++){const e=this.FRAGS_TEXTURE_UNIT_OUTPUT_DATA[`mapUnit${i}`];t.uniform1i(t.getUniformLocation(s,`u_colortex${e}`),e)}}this._multi_pass_state_=!0}}updateMaps(t,e){if(this._sprite_state_)e(!1);else{this._sprite_state_=!0;let s=!1;const i=[];for(let e of t)e.preprocess(t=>{if("Group"!=t.type||t.typeAddModelEvent||t.setAddModelEvent(()=>{this._sprite_state_=!1}),t.material&&t.material.maps)for(let e of t.material.maps)-1==i.indexOf(e)&&i.push(e)});for(let t of i)if(!t.activate){s=!0,this.SpriteGenerator.createSprite(i).then(t=>{e(!0,t.images,t.videos)});break}s||e(!1)}}render(t,e){this.DRAW_ATTRIBUTES.scene=t,this.DRAW_ATTRIBUTES.camera=e,this._multi_pass_state_||(this.initMultiPass(),t.setAddModelEvent(()=>{this._sprite_state_=!1}),console.log("webgl渲染上下文已启用"));const s=this.gl,i=this.PROGRAMS[0];i.drawFunc(s,i.program);const n=s.getError();0!=n&&console.error("来自gl.getError:",n)}}function F(t="#000000"){let e,s,i,n;if("number"==typeof t)e=255,s=t>>16&255,i=t>>8&255,n=255&t;else{const r=t.replace(/^#/,"");6===r.length?(e="FF",s=r.slice(0,2),i=r.slice(2,4),n=r.slice(4,6)):8===r.length?(e=r.slice(0,2),s=r.slice(2,4),i=r.slice(4,6),n=r.slice(6,8)):(e="FF",s=i=n="00"),e=parseInt(e,16),s=parseInt(s,16),i=parseInt(i,16),n=parseInt(n,16)}return{r:s/255,g:i/255,b:n/255,a:e/255,value:t}}class b{constructor(t="#000000"){this.type="Scene",this.color=F(t),this.element=[],this.ADD_MODEL_FUNC=void 0,this.SPRITE_TEXTURE_ARRAY=[],this.typeAddModelEvent=!1,this.SPRITE_TEXTURE_LOAD_FUNC=void 0}setColor(t="#000000"){this.color=F(t)}setAddModelEvent(t){this.ADD_MODEL_FUNC=t,this.typeAddModelEvent=!0}setSpriteTexture(t){this.SPRITE_TEXTURE_ARRAY.push(t),this.SPRITE_TEXTURE_LOAD_FUNC?.(t)}getSpriteTexture(t){this.SPRITE_TEXTURE_LOAD_FUNC=t}add(t){-1==this.element.indexOf(t)&&(this.element.push(t),this.ADD_MODEL_FUNC?.())}remove(t){const e=this.element.indexOf(t);-1!=e&&this.element.splice(e,1)}}const{sin:I,cos:w}=Math;class D{constructor(t=.1,e=20){this.type="Camera",this.rotate=0,this.position=new d(0,0,10),this.near=t,this.far=e,this.unitX=70,this.unitY=70,this.model=void 0}matrix(){const t=1/(this.near-this.far),e=I(this.rotate),s=w(this.rotate);let i=1;return this.position.z>0&&(i=10/this.position.z),this.model&&(this.position.x=this.model.position.x,this.position.y=this.model.position.y),new m([i*s,-i*e,0,-this.position.x*i,i*e,i*s,0,-this.position.y*i,0,0,2*t,(this.near+this.far-2*this.position.z)*t,0,0,0,1])}}const N=Math.sin,P=Math.cos,$=Math.trunc,O=1/3;let L=1;class X{constructor(t,e){this.type="Mesh",this.geometry=t,this.material=e,this.scale=new d(1,1,1),this.rotation=new d,this.position=new d,this.id=L,L++}getFaceTexture(t=0){let e;if(this.material&&this.material.maps&&this.material.maps.length>0){const s=this.geometry.uvs[9*t+2];s>=0&&(e=this.material.maps[s])}return e}matrix(){const t=N(this.rotation.z),e=P(this.rotation.z),s=P(this.rotation.x),i=P(this.rotation.y);return new m([i*e*this.scale.x*this.scale.z,s*t*this.scale.y*this.scale.z,0,this.position.x,-i*t*this.scale.x*this.scale.z,s*e*this.scale.y*this.scale.z,0,this.position.y,0,0,1,this.position.z,0,0,0,1])}vertices(){const t=[],e=this.geometry.vertices.length;let s,i=0,n=0;3==this.geometry.connect&&this.material.maps&&this.material.maps.length>0&&(i=1);for(let r=0;r<e;r+=3)s=this.material.getColor(n,this.geometry.connect),t.push(this.geometry.vertices[r],this.geometry.vertices[r+1],this.geometry.vertices[r+2],s.r,s.g,s.b,s.a,this.geometry.uvs[r],this.geometry.uvs[r+1],i),n++;return new Float32Array(t)}draw(t,e,s){const i=this.vertices(),n=i.BYTES_PER_ELEMENT,r=t.createVertexArray();t.bindVertexArray(r);const o=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,o),t.bufferData(t.ARRAY_BUFFER,i,t.STATIC_DRAW);t.vertexAttribPointer(0,3,t.FLOAT,!1,10*n,0),t.enableVertexAttribArray(0);t.vertexAttribPointer(1,4,t.FLOAT,!1,10*n,3*n),t.enableVertexAttribArray(1);t.vertexAttribPointer(2,3,t.FLOAT,!1,10*n,7*n),t.enableVertexAttribArray(2);const a=i.length/10,h=this.matrix();if(h.premultiply(s),h.reverse(),t.uniformMatrix4fv(t.getUniformLocation(e,"u_mvsmat"),!1,h.element),t.uniform1i(t.getUniformLocation(e,"u_id"),this.id),3==this.geometry.connect){let s,i=0;for(let n=0;n<a;n+=3){const r=this.getFaceTexture($(n*O));r&&(s&&s.id==r.id?"video"==s.mediaType&&!s.media.paused&&!s.media.ended&&s.media.currentTime-i>1e-4&&(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s.glTexture.media),i=s.media.currentTime):(s=r,t.bindTexture(t.TEXTURE_2D,s.glTexture),"video"!=s.mediaType||s.media.paused||s.media.ended||(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s.glTexture.media),i=s.media.currentTime),t.uniform1i(t.getUniformLocation(e,"u_imagetex"),s.mapUnit),t.uniformMatrix3fv(t.getUniformLocation(e,"u_uvmat"),!1,[s.uvmat.element[0],s.uvmat.element[3],s.uvmat.element[6],s.uvmat.element[1],s.uvmat.element[4],s.uvmat.element[7],s.uvmat.element[2],s.uvmat.element[5],s.uvmat.element[8]]))),t.drawArrays(t.TRIANGLES,n,3)}}else 2==this.geometry.connect&&t.drawArrays(t.LINES,0,a);t.bindVertexArray(null),t.bindBuffer(t.ARRAY_BUFFER,null),t.deleteVertexArray(r),t.deleteBuffer(o)}preprocess(t){t(this)}}class C{constructor(t,e,s=3){let i=[],n=[];5==arguments.length&&(i=arguments[2],n=arguments[3],s=arguments[4]),this.type="Geometry",this.connect=s,this.vertices=t,this.uvs=e,this.skinIndices=i,this.skinWeights=n}}const B=Math.round,G=Math.trunc,k=Math.sqrt,W=Math.log,z=Math.max,H=1/W(4);let V=1;class Y{constructor(t){this.media=t,this.mediaType=t instanceof HTMLImageElement?"image":t instanceof HTMLVideoElement?"video":"null",this.ratio=t.height/t.width,this.activate=!1,this.mapUnit=0,this.uvmat=new _,this._kh=k(t.width/t.height),this._kw=1/this._kh,this.glTexture=void 0,this.id=V,V++}uvRatio(t=0,e=0,s=1,i=1){return this.ratio*(i-e)/(s-t)}getSizeValue(t){const e=this.media.width*this.media.height/(t*t),s=W(e)*H+1;return B(z(s,1))}}class q{constructor(t={opacity:1,color:"#7b68ee",maps:void 0}){null==t.opacity&&(t.opacity=1),null==t.color&&(t.color="#7b68ee"),this.type="Material",this.opacity=t.opacity,this.color=F(t.color),this.maps=t.maps}getColor(){return{r:this.color.r,g:this.color.g,b:this.color.b,a:this.color.a*this.opacity,value:this.color.value}}}class j{constructor(t=1,e=["#7b68ee","#7b68ee","#7b68ee"]){this.type="Material",this.opacity=t,this.color=[],e.forEach(t=>{this.color.push(F(t))})}getColor(t=0,e=3){t%=e;const s=this.color[t];return{r:s.r,g:s.g,b:s.b,a:s.a*this.opacity,value:s.value}}}class J{constructor(t=1,e=[]){this.type="Material",this.opacity=t,this.content=e}add(t){-1==this.content.indexOf(t)&&this.content.push(t)}remove(t){const e=this.content.indexOf(t);-1!=e&&this.content.splice(e,1)}getColor(t=0,e=3){const s=G(t/e)%this.content.length;t%=e;const i=this.content[s].getColor(t,e);return{r:i.r,g:i.g,b:i.b,a:i.a*this.opacity,value:i.value}}}const K=Math.sin,Z=Math.cos;class Q{constructor(){this.type="Bone",this.element=[],this.position=new f,this.bind=void 0,this._frotate_=0,this._rotate_=0}set rotate(t){this._rotate_=t,this.element.forEach(t=>{t._frotate_=this._frotate_+this._rotate_,t.update()})}get rotate(){return this._rotate_}update(){this.element.forEach(t=>{t._frotate_=this._frotate_+this._rotate_,t.update()})}add(t){-1==this.element.indexOf(t)&&(this.element.push(t),t.bind=this,t._frotate_=this._frotate_+this._rotate_,t.update())}remove(t){const e=this.element.indexOf(t);-1!=e&&(this.element.splice(e,1),t.bind=void 0,t._frotate_=0,t.update())}trotate(){return this._frotate_+this._rotate_}tcoord(){const t={x:this.position.x,y:this.position.y};if(null!=this.bind){const e=this.bind.tcoord(),s=K(this._frotate_),i=Z(this._frotate_),n=t.x,r=t.y;t.x=n*i+r*s+e.x,t.y=r*i-n*s+e.y}return t}coord(){let t=this.position.x,e=this.position.y;if(null!=this.bind){const s=this.bind.coord();t+=s.x,e+=s.y}return{x:t,y:e}}matrix(t=1){const e=this._frotate_+t*this._rotate_,s=this.coord(),i=this.tcoord(),n=K(e),r=Z(e);return new m([r,n,0,i.x-s.x*r-s.y*n,-n,r,0,i.y+s.x*n-s.y*r,0,0,1,0,0,0,0,1])}}class tt{constructor(t,e){this.type="Skeleton",this.mainBone=e,this.bones=t,this.vector=new T}vertices(t){const e=[],s=t.vertices.length/3;let i,n,r,o;for(let a=0;a<s;a++){this.vector.set(t.vertices[3*a],t.vertices[3*a+1],t.vertices[3*a+2],1),n=this.bones[t.skinIndices[a][0]],r=t.skinWeights[a][0],o=n.matrix(r),i=t.skinIndices[a].length;for(let e=1;e<i;e++)n=this.bones[t.skinIndices[a][e]],r=t.skinWeights[a][e],o.multiply(n.matrix(r));this.vector.transform(o),e.push(this.vector.x,this.vector.y,this.vector.z)}return e}}class et extends X{constructor(t,e){super(t,e),this.skeleton=void 0}bind(t){this.skeleton=t}vertices(){const t=[],e=this.skeleton.vertices(this.geometry),s=e.length;let i,n=0,r=0;3==this.geometry.connect&&null!=this.material.maps&&(n=1);for(let o=0;o<s;o+=3)i=this.material.getColor(r,this.geometry.connect),t.push(e[o],e[o+1],e[o+2],i.r,i.g,i.b,i.a,this.geometry.uvs[o],this.geometry.uvs[o+1],n),r++;return new Float32Array(t)}}function st(t,e,s=[]){if(null!=t)for(let i in e)if(null!=t[i])if("object"==typeof e[i]&&null==s||"object"==typeof e[i]&&-1==s.indexOf(i))if(Array.isArray(e[i]))for(let s=0;s<e[i].length;s++)null!=t[i][s]&&(e[i][s]=t[i][s]);else for(let s in e[i])null!=t[i][s]&&(e[i][s]=t[i][s]);else e[i]=t[i]}function it(t,e,s,i){return t*i-s*e}function nt(t,e,s,i,n,r,o,a){let h=!1;const l={x:n-s,y:r-i},c={x:o-n,y:a-r},u={x:s-o,y:i-a},_={x:t-s,y:e-i},m={x:t-n,y:e-r},p={x:t-o,y:e-a},f=it(l.x,l.y,_.x,_.y),d=it(c.x,c.y,m.x,m.y),T=it(u.x,u.y,p.x,p.y);return(f>0&&d>0&&T>0||!f&&d*T!=0||!d&&f*T!=0||!T&&f*d!=0||!f&&!d||!d&&!T||!T&&!f)&&(h=!0),h}function rt(t,e,s){const i=t.length;if(e>=i&&(e%=i),e+s<=i)t.splice(e,s);else{const n=i-e;t.splice(e,n),t.splice(0,s-n)}}const ot=Math.PI,at=Math.sin,ht=Math.cos,lt=Math.round;class ct extends X{constructor(){super(),this.type="Group",this.element=[],this.ADD_MODEL_FUNC=void 0,this.typeAddModelEvent=!1}setAddModelEvent(t){this.ADD_MODEL_FUNC=t,this.typeAddModelEvent=!0}add(t){-1==this.element.indexOf(t)&&(this.element.push(t),this.ADD_MODEL_FUNC?.())}remove(t){const e=this.element.indexOf(t);-1!=e&&this.element.splice(e,1)}draw(t,e,s,i){null==i&&(i=new m);const n=this.matrix();n.multiply(i);const r=new m;r.copy(s),r.multiply(n),this.element.forEach(i=>{"Mesh"==i.type?i.draw(t,e,r):"Group"==i.type&&i.draw(t,e,s,n)})}preprocess(t){t(this),this.element.forEach(e=>{e.preprocess(t)})}}class ut extends C{constructor(t=1,e=1){const s=.5*t,i=.5*e;super([-s,i,0,-s,-i,0,s,-i,0,-s,i,0,s,-i,0,s,i,0],[0,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,0],3)}}class _t extends C{constructor(t=.5,e=64){const s=[],i=[],n=2*ot/e;let r,o,a,h;for(let l=0;l<e;l++)r=at(l*n),o=ht(l*n),a=at((l+1)*n),h=ht((l+1)*n),s.push(0,0,0,t*r,t*o,0,t*a,t*h,0),i.push(.5,.5,0,.5*(r+1),.5*(o+1),0,.5*(a+1),.5*(h+1),0);super(s,i,3)}}class mt extends C{constructor(t,e){super([...t.vertices,...e.vertices],new Array(t.vertices.length+e.vertices.length).fill(0),t.connect)}}class pt extends X{constructor(t,e="#ffffff"){"Mesh"==t.type&&3==t.geometry.connect&&(t=t.geometry);const s=[],i=[],n=t.vertices.length;for(let e=0;e<n;e+=9)s.push(t.vertices[e],t.vertices[e+1],t.vertices[e+2],t.vertices[e+3],t.vertices[e+4],t.vertices[e+5],t.vertices[e+3],t.vertices[e+4],t.vertices[e+5],t.vertices[e+6],t.vertices[e+7],t.vertices[e+8],t.vertices[e+6],t.vertices[e+7],t.vertices[e+8],t.vertices[e],t.vertices[e+1],t.vertices[e+2]),i.push(0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1);super(new C(s,i,2),new q({color:e}))}}class ft extends X{constructor(t=10,e=10,s="#ffffff"){const i=.5*(t=lt(t)),n=.5*(e=lt(e)),r=[],o=new Array(6*(t+e+2)).fill(-1);for(let t=-n;t<=n;t++)r.push(-i,t,0,i,t,0);for(let t=-i;t<=i;t++)r.push(t,n,0,t,-n,0);super(new C(r,o,2),new q({color:s}))}}class dt extends X{constructor(t){const e={points:[new f(-2,0),new f(2,0),new f(-2,2),new f(2,2)],sub:40,color:"#7b68ee",opacity:1};st(t,e,["points"]);super(new C([],[],2),new q({opacity:e.opacity,color:e.color})),this.points=e.points,this.sub=e.sub}vertices(){const t=[],e=this.points.length;if(2==e){const e=this.material.getColor(0,2),s=this.material.getColor(1,2);t.push(this.points[0].x,this.points[0].y,0,e.r,e.g,e.b,e.a,0,0,-1,this.points[1].x,this.points[1].y,0,s.r,s.g,s.b,s.a,0,0,-1)}else if(3==e){const e={x:this.points[2].x-this.points[0].x,y:this.points[2].y-this.points[0].y},s={x:this.points[1].x-this.points[2].x,y:this.points[1].y-this.points[2].y},i={x:0,y:0},n={x:0,y:0},r={x:0,y:0};let o,a,h;for(let l=0;l<this.sub;l++)for(let c=0;c<2;c++)a=l+c,o=a/this.sub,h=this.material.getColor(a,2),i.x=this.points[0].x+e.x*o,i.y=this.points[0].y+e.y*o,n.x=this.points[2].x+s.x*o,n.y=this.points[2].y+s.y*o,r.x=i.x+(n.x-i.x)*o,r.y=i.y+(n.y-i.y)*o,t.push(r.x,r.y,0,h.r,h.g,h.b,h.a,0,0,-1)}else if(4==e){const e={x:this.points[2].x-this.points[0].x,y:this.points[2].y-this.points[0].y},s={x:this.points[3].x-this.points[2].x,y:this.points[3].y-this.points[2].y},i={x:this.points[1].x-this.points[3].x,y:this.points[1].y-this.points[3].y},n={x:0,y:0},r={x:0,y:0},o={x:0,y:0},a={x:0,y:0},h={x:0,y:0},l={x:0,y:0},c={x:0,y:0},u={x:0,y:0};let _,m,p;for(let f=0;f<this.sub;f++)for(let d=0;d<2;d++)m=f+d,_=m/this.sub,p=this.material.getColor(m,2),n.x=this.points[0].x+e.x*_,n.y=this.points[0].y+e.y*_,r.x=this.points[2].x+s.x*_,r.y=this.points[2].y+s.y*_,o.x=this.points[3].x+i.x*_,o.y=this.points[3].y+i.y*_,a.x=r.x-n.x,a.y=r.y-n.y,h.x=o.x-r.x,h.y=o.y-r.y,l.x=n.x+a.x*_,l.y=n.y+a.y*_,c.x=r.x+h.x*_,c.y=r.y+h.y*_,u.x=l.x+(c.x-l.x)*_,u.y=l.y+(c.y-l.y)*_,t.push(u.x,u.y,0,p.r,p.g,p.b,p.a,0,0,-1)}return new Float32Array(t)}getPoints(){const t=[];return this.points.forEach(e=>t.push(e.x,e.y)),t}}class Tt extends X{constructor(t=1,e=1,s="#7b68ee"){const i=.5*t,n=.5*e,r=[-i,n,0,-i,-n,0,-i,-n,0,i,-n,0,i,-n,0,i,n,0,i,n,0,-i,n,0],o=new Array(18).fill(-1);super(new C(r,o,2),new q({color:s}))}}class xt extends X{constructor(t=.5,e="#7b68ee",s=64){const i=[],n=[],r=2*ot/s;let o,a,h,l;for(let e=0;e<s;e++)o=at(e*r),a=ht(e*r),h=at((e+1)*r),l=ht((e+1)*r),i.push(t*o,t*a,0,t*h,t*l,0),n.push(0,0,-1,0,0,-1);super(new C(i,n,2),new q({color:e}))}}class Et extends X{constructor(t,e="#1e3a8a",s="#00ced1"){"Mesh"==t.type&&(t=t.skeleton);super(new C([],[],2),new j(1,[e,s])),this.skeleton=t}loadVertices(t,e,s){let i;t.element.forEach(t=>{i=t.tcoord(),s.push(e.x,e.y,0,i.x,i.y,0),this.loadVertices(t,i,s)})}vertices(){const t=[];this.loadVertices(this.skeleton.mainBone,this.skeleton.mainBone.tcoord(),t);const e=[],s=t.length;let i,n=0;for(let r=0;r<s;r+=3)i=this.material.getColor(n,this.geometry.connect),e.push(t[r],t[r+1],t[r+2],i.r,i.g,i.b,i.a,0,0,-1),n++;return new Float32Array(e)}}const gt=Math.PI,Rt=Math.sin,yt=Math.cos,At=Math.sqrt;function Ut(t){const e=[],s=t.vertices(),i=s.length;for(let t=0;t<i;t+=10)e.push(s[t],s[t+1],s[t+2]);return e}function vt(t,e=0){const s=t.x,i=t.y,n=Rt(e),r=yt(e);return{x:s*r-i*n,y:i*r+s*n}}function St(t){return At(t.x*t.x+t.y*t.y)}function Mt(t,e){const s=.5*t.length;return e>=s&&(e%=s),{x:t[2*e],y:t[2*e+1],index:e}}function Ft(t){const e=[];for(let s=0;s<t.length;s++)e.push(...t[s]);return e}function bt(t){const e=Rt(t),s=1/17;return{x:16*e*e*e*s,y:(13*yt(t)-5*yt(2*t)-2*yt(3*t)-yt(4*t))*s}}class It extends X{constructor(t,e="#7b68ee"){let s;if("Group"==t.type){const e=[];let i,n;for(let s=0;s<t.element.length;s++)i=t.element[s],2==i.geometry.connect&&(n=i.geometry.vertices,0==n.length&&(n=Ut(i)),e.push(n));s=Ft(e)}else 2==t.geometry.connect&&(s=t.geometry.vertices,0==s.length&&(s=Ut(t)));const i=new Array(s.length).fill(-1);super(new C(s,i,2),new q({color:e}))}}class wt extends X{constructor(t,e=.4,s="#7b68ee",i=8){let n;if("Group"==t.type){const e=[];let s,i;for(let n=0;n<t.element.length;n++)s=t.element[n],2==s.geometry.connect&&(i=s.geometry.vertices,0==i.length&&(i=Ut(s)),e.push(i));n=Ft(e)}else 2==t.geometry.connect&&(n=t.geometry.vertices,0==n.length&&(n=Ut(t)));const r=[],o=[],a={x:0,y:0},h={x:0,y:0},l={x:0,y:0};let c,u,_,m,p,f,d,T;for(let t=0;t<n.length;t+=6){a.x=n[t],a.y=n[t+1],h.x=n[t+3],h.y=n[t+4],l.x=h.x-a.x,l.y=h.y-a.y,c=At(l.x*l.x+l.y*l.y),c>0&&(u=.5*e/c,l.x*=u,l.y*=u),_=vt(l,.5*gt),m=vt(l,.5*-gt),r.push(a.x+_.x,a.y+_.y,0,a.x+m.x,a.y+m.y,0,h.x+m.x,h.y+m.y,0,a.x+_.x,a.y+_.y,0,h.x+m.x,h.y+m.y,0,h.x+_.x,h.y+_.y,0),o.push(0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1);for(let t=0;t<i;t++)d=gt*(t+1)/i,T=gt*t/i,p=vt(_,d),f=vt(_,T),r.push(a.x+p.x,a.y+p.y,0,a.x,a.y,0,a.x+f.x,a.y+f.y,0);for(let t=0;t<i;t++)d=gt*(t+1)/i,T=gt*t/i,p=vt(m,d),f=vt(m,T),r.push(h.x+p.x,h.y+p.y,0,h.x,h.y,0,h.x+f.x,h.y+f.y,0)}super(new C(r,o,3),new q({color:s}))}}class Dt extends X{constructor(t,e="#7b68ee"){let s;if("Group"==t.type){const e=[];let i;for(let s=0;s<t.element.length;s++)i=t.element[s].geometry.vertices,0==i.length&&(i=Ut(t.element[s])),e.push(i);s=Ft(e)}else 2==t.geometry.connect&&(s=t.geometry.vertices,0==s.length&&(s=Ut(t)));let i=function(t){const e=[t[0],t[1]],s=t.length;let i,n,r,o=t[0],a=t[1];for(let h=3;h<s;h+=3)n=t[h],r=t[h+1],i=St({x:n-o,y:r-a}),i>.001&&e.push(n,r),o=n,a=r;return i=St({x:o-t[0],y:a-t[1]}),i<.001&&e.splice(s-2,2),e}(s);if(function(t){const e=[...t],s=t.length;e.push(t[0],t[1]);let i=0;for(let t=0;t<s;t+=2)i+=it(e[t],e[t+1],e[t+2],e[t+3]);return i*=.5,i}(i)<0){const t=[];for(let e=i.length-1;e>0;e-=2)t.push(i[e-1],i[e]);i=t}s=[];let n,r,o,a,h,l=.5*i.length,c=0,u=!1;for(;l>3;)if(o=Mt(i,c),a=Mt(i,c+1),h=Mt(i,c+2),n=it(a.x-o.x,a.y-o.y,a.x-h.x,a.y-h.y),n<0){r=[...i],rt(r,2*c,6);for(let t=0;t<r.length;t+=2)if(u=nt(r[t],r[t+1],o.x,o.y,a.x,a.y,h.x,h.y),u){c++;break}u||(s.push(o.x,o.y,0,a.x,a.y,0,h.x,h.y,0),rt(i,2*c+2,2),l--)}else c++;s.push(i[0],i[1],0,i[2],i[3],0,i[4],i[5],0);const _=new Array(s.length).fill(-1);super(new C(s,_,3),new q({color:e}))}}class Nt extends C{constructor(t){const e={a:1,b:.5,thickness:1,start:0,end:360,sub:64};st(t,e);const s=[],i=[],n=e.start/180*gt,r=(e.end/180*gt-n)/e.sub,o=1-e.thickness;let a,h,l,c,u,_;for(let t=0;t<e.sub;t++)u=n+t*r,_=n+(t+1)*r,a=Rt(u),h=yt(u),l=Rt(_),c=yt(_),e.thickness>0?(s.push(e.a*a,e.b*h,0,o*e.a*a,o*e.b*h,0,o*e.a*l,o*e.b*c,0,e.a*a,e.b*h,0,o*e.a*l,o*e.b*c,0,e.a*l,e.b*c,0),i.push(.5*a+.5,.5*h+.5,0,.5*o*a+.5,.5*o*h+.5,0,.5*o*l+.5,.5*o*c+.5,0,.5*a+.5,.5*h+.5,0,.5*o*l+.5,.5*o*c+.5,0,.5*l+.5,.5*c+.5,0)):(s.push(e.a*a,e.b*h,0,0,0,0,e.a*l,e.b*c,0),i.push(.5*a+.5,.5*h+.5,0,.5*o*l+.5,.5*o*c+.5,0,.5*l+.5,.5*c+.5,0));super(s,i,3)}}class Pt extends C{constructor(t=1,e=1,s=1,i=0){const n=[],r=[],o=.5*t,a=.5*e,h=.5*s,l=o-a,c=-s,u=a-o,_=i+1,m=1/_;let p,f,d,T,x,E,g,R,y,A,U,v,S,M,F,b;for(let t=0;t<_;t++)F=t*m,b=(t+1)*m,y=l*F,A=c*F,U=l*b,v=c*b,S=u*F,M=u*b,p=y-o,f=A+h,d=U-o,T=v+h,x=M+o,g=S+o,n.push(p,f,0,d,T,0,x,T,0,p,f,0,x,T,0,g,f,0),E=1-F,R=1-b,r.push(0,E,0,0,R,0,1,R,0,0,E,0,1,R,0,1,E,0);super(n,r,3)}}class $t extends C{constructor(t=1,e=.38196601125,s=5){const i=[],n=[],r=.5*e/t,o=2*s,a=2*gt/o;let h,l,c,u,_,m,p,f,d;for(let s=0;s<o;s+=2)p=s*a,f=(s+1)*a,d=(s+2)*a,h=Rt(p),l=yt(p),c=Rt(f),u=yt(f),_=Rt(d),m=yt(d),i.push(t*h,t*l,0,0,0,0,e*c,e*u,0,e*c,e*u,0,0,0,0,t*_,t*m,0),n.push(.5*h+.5,.5*l+.5,0,.5,.5,0,r*c+.5,r*u+.5,0,r*c+.5,r*u+.5,0,.5,.5,0,.5*_+.5,.5*m+.5,0);super(i,n,3)}}class Ot extends C{constructor(t=1,e=64){const s=[],i=[],n=2*gt/e;let r,o,a,h;for(let l=0;l<e;l++)a=l*n,h=(l+1)*n,r=bt(a),o=bt(h),s.push(t*r.x,t*r.y,0,0,0,0,t*o.x,t*o.y,0),i.push(.5*r.x+.5,.5*r.y+.5,0,.5,.5,0,.5*o.x+.5,.5*o.y+.5,0);super(s,i,3)}}class Lt extends X{constructor(t,e="#ffffff"){super(new C([],[],2),new q({color:e})),this.bind=t}vertices(){const t=[],e=this.bind.vertices(),s=e.length;let i,n,r,o,a,h,l=0;for(let c=0;c<s;c+=30)i=this.material.getColor(l,this.geometry.connect),n=this.material.getColor(l+1,this.geometry.connect),r=this.material.getColor(l+2,this.geometry.connect),o=this.material.getColor(l+3,this.geometry.connect),a=this.material.getColor(l+4,this.geometry.connect),h=this.material.getColor(l+5,this.geometry.connect),t.push(e[c],e[c+1],e[c+2],i.r,i.g,i.b,i.a,0,0,-1,e[c+10],e[c+11],e[c+12],n.r,n.g,n.b,n.a,0,0,-1,e[c+10],e[c+11],e[c+12],r.r,r.g,r.b,r.a,0,0,-1,e[c+20],e[c+21],e[c+22],o.r,o.g,o.b,o.a,0,0,-1,e[c+20],e[c+21],e[c+22],a.r,a.g,a.b,a.a,0,0,-1,e[c],e[c+1],e[c+2],h.r,h.g,h.b,h.a,0,0,-1),l+=6;return new Float32Array(t)}}class Xt extends X{constructor(t=1,e=.5,s="#7b68ee",i=64){const n=[],r=[],o=2*gt/i;let a,h,l,c,u,_;for(let s=0;s<i;s++)u=s*o,_=(s+1)*o,a=t*Rt(u),h=e*yt(u),l=t*Rt(_),c=e*yt(_),n.push(a,h,0,l,c,0),r.push(0,0,-1,0,0,-1);super(new C(n,r,2),new q({color:s}))}}class Ct extends X{constructor(t=1,e=.38196601125,s=5,i="#ffff00"){const n=[],r=[],o=2*s,a=2*gt/o;let h,l,c,u,_,m,p,f,d;for(let s=0;s<o;s+=2)p=s*a,f=(s+1)*a,d=(s+2)*a,h=t*Rt(p),l=t*yt(p),c=e*Rt(f),u=e*yt(f),_=t*Rt(d),m=t*yt(d),n.push(h,l,0,c,u,0,c,u,0,_,m,0),r.push(0,0,-1,0,0,-1,0,0,-1,0,0,-1);super(new C(n,r,2),new q({color:i}))}}class Bt extends X{constructor(t=1,e="#ff0000",s=64){const i=[],n=[],r=2*gt/s;let o,a,h,l;for(let e=0;e<s;e++)h=e*r,l=(e+1)*r,o=bt(h),a=bt(l),i.push(t*o.x,t*o.y,0,t*a.x,t*a.y,0),n.push(0,0,-1,0,0,-1);super(new C(i,n,2),new q({color:e}))}}const Gt=Math.sqrt,kt=Math.acos,Wt=Math.cos,zt=Math.sign,Ht=Math.pow,Vt=Math.abs,Yt=Math.PI,qt=1/3,jt=1/27,Jt=2*Yt*qt,Kt=2*Jt;function Zt(t,e,s,i){const n=e/t,r=s/t,o=function(t,e){const s=e*e*.25+t*t*t*jt;if(s>0){const t=Gt(s);return[Ht(.5*-e+t,qt)+Ht(.5*-e-t,qt)]}if(0==s){if(0==t&&0==e)return[0];if(0!=t&&0!=e){const t=Ht(.5*-e,qt);return[2*t,-t]}}else if(s<0){const s=Vt(t)*qt*Gt(-t*qt),i=qt*kt(-e/s*.5),n=2*Ht(s,qt);return[n*Wt(i),n*Wt(i+Jt),n*Wt(i+Kt)]}}(r-n*n*qt,2*n*n*n*jt-n*r*qt+i/t),a=[];let h;return o.forEach(t=>{h=t-n*qt,a.push(h)}),a}function Qt(t,e,s){const i=e+s,n=[t[4]-t[0],t[5]-t[1]],r=[t[6]-t[4],t[7]-t[5]],o=[t[2]-t[6],t[3]-t[7]],a=o[0]-2*r[0]+n[0],h=3*(r[0]-n[0]),l=3*n[0],c=o[1]-2*r[1]+n[1],u=3*(r[1]-n[1]),_=3*n[1];return[new ee(e,i,e=>a*(e/=s)*e*e+h*e*e+l*e+t[0]),new ee(e,i,e=>c*(e/=s)*e*e+u*e*e+_*e+t[1]),new ee(e,i,t=>{const e=3*c*(t/=s)*t+2*u*t+_,i=3*a*t*t+2*h*t+l,n=e/Gt(i*i+e*e);return function(t){if(0!=t)return zt(t)}(i)*kt(n)})]}class te{constructor(t=[]){this.type="BezierCure",8==t.length?this.points=t:this.points=[0,0,8,0,3,4,6,6]}value(t){const e=this.points[2]+3*(this.points[4]-this.points[6])-this.points[0],s=3*(this.points[6]-2*this.points[4]+this.points[0]),i=3*(this.points[4]-this.points[0]),n=this.points[0]-t;let r=[];if(0!=e&&0!=s&&0!=i?r=Zt(e,s,i,n):0!=s&&0!=i?r=function(t,e,s){const i=e*e-4*t*s,n=[];if(i>=0){const s=1/t*.5;if(i>0){const t=Gt(i),r=(-e+t)*s,o=(-e-t)*s;n.push(r),n.push(o)}else 0==i&&n.push(-e*s)}return n}(s,i,n):0!=i&&(r=function(t,e){return[-e/t]}(i,n)),r.length>0){const t=r.sort((t,e)=>t-e)[0];return(this.points[3]+3*(this.points[5]-this.points[7])-this.points[1])*t*t*t+3*(this.points[7]-2*this.points[5]+this.points[1])*t*t+3*(this.points[5]-this.points[1])*t+this.points[1]}return 0}}class ee{constructor(t=0,e=1,s=t=>t){this.type="FuncCure",this.__func=s,this.__start_x=t,this.__end_x=e}value(t){return this.__func(t)}}class se{constructor(t=0,e=1,s=0,i=1){this.type="LerpCure",this.__start_x=t,this.__end_x=e,this.__a=s,this.__b=i,this.__c=e-t}value(t){return this.__a+function(t=0){return 6*t*t*t*t*t-15*t*t*t*t+10*t*t*t}(t/this.__c)*(this.__b-this.__a)}}class ie{constructor(){this.type="Controller",this.content=[]}add(t){-1==this.content.indexOf(t)&&this.content.push(t)}remove(t){const e=this.content.indexOf(t);-1!=e&&this.content.splice(e,1)}value(t=0){let e=t;return this.content.forEach(s=>{"BezierCure"==s.type?t>s.points[0]&&t<s.points[2]?e=s.value(t):t==s.points[0]?e=s.points[1]:t==s.points[2]&&(e=s.points[3]):"FuncCure"==s.type&&t>=s.__start_x&&t<=s.__end_x?e=s.value(t-s.__start_x):"LerpCure"==s.type&&(t>s.__start_x&&t<s.__end_x?e=s.value(t-s.__start_x):t==s.__start_x?e=s.__a:t==s.__end_x&&(e=s.__b))}),e}}class ne{constructor(t={}){this.type="Animation",this.keys=[],this.fps=25,this.time=2e3,this.t=0,this.state="end",this.cycle=!1,this.__binding=void 0,this.__attributes={},this.__controller={},Object.keys(t).forEach(e=>{"Controller"==t[e].type&&(this.__attributes[e]=t[e].value(0),this.__controller[e]=t[e],this.keys.push(e))}),this.__update=t=>{if("play"==t.state)if(t.t+=1e3/t.fps,t.t>t.time&&t.cycle&&(t.t=0),t.t<=t.time){const e=.001*t.t;t.keys.forEach(s=>{t.__attributes[s]=t.__controller[s].value(e)}),t.__binding?.(t.__attributes),setTimeout(()=>{t.__update(t)},1e3/t.fps)}else t.state="end"}}play(){if("play"!=this.state){"end"==this.state&&(this.t=0),this.state="play";const t=.001*this.t;this.keys.forEach(e=>{this.__attributes[e]=this.__controller[e].value(t)}),this.__binding?.(this.__attributes),setTimeout(()=>{this.__update(this)},1e3/this.fps)}}pause(){"play"==this.state&&(this.state="pause")}stop(){this.state="end"}binding(t){this.__binding=t}}var re=Object.freeze({__proto__:null,clipFrames:function(t=1,e=1,s=[]){const i=[],n=1/t,r=1/e;for(let t of s){const e=[],s=t.length;let o,a,h;for(let i=0;i<s;i+=2)o=i+1,a=t[i]*n,h=t[o]*r,e.push([a,h+r,a,h,a+n,h,a,h+r,a+n,h,a+n,h+r]);i.push(e)}return i},degToRad:function(t){return.017453292519943295*t},hexToRGB:function(t){"string"==typeof t&&(t=parseInt(t.replace("#",""),16));let e=t>>16,s=(65280&t)>>8,i=255&t;return e/=255,s/=255,i/=255,{r:e,g:s,b:i}},radToDeg:function(t){return 57.29577951308232*t}});const oe=Math.PI,ae=Math.sin,he=Math.cos,le=Math.floor,ce=Math.ceil,ue=Math.trunc,_e=Math.random,me=1/1.414214,pe=1/1.7321;class fe{constructor(t=()=>_e()){this.data=[{},{},{}],this.argument=0,this.structure=t}fade(t){return 6*t*t*t*t*t-15*t*t*t*t+10*t*t*t}lerp(t,e,s){return t+this.fade(s)*(e-t)}get1d(t=0){const e=le(t),s=ce(t);null==this.data[0][`s${e}`]&&(this.data[0][`s${e}`]=this.structure(this.argument),this.argument++),null==this.data[0][`s${s}`]&&(this.data[0][`s${s}`]=this.structure(this.argument),this.argument++);const i=this.data[0][`s${e}`],n=this.data[0][`s${s}`],r=t-ue(t);return this.lerp(i,n,r)}get2d(t=0,e=0){const s=le(t),i=ce(t),n=le(e),r=ce(e);if(null==this.data[1][`s${s}_${n}`]){const t=2*this.structure(this.argument)*oe;this.data[1][`s${s}_${n}`]={x:he(t),y:ae(t)},this.argument++}if(null==this.data[1][`s${s}_${r}`]){const t=2*this.structure(this.argument)*oe;this.data[1][`s${s}_${r}`]={x:he(t),y:ae(t)},this.argument++}if(null==this.data[1][`s${i}_${r}`]){const t=2*this.structure(this.argument)*oe;this.data[1][`s${i}_${r}`]={x:he(t),y:ae(t)},this.argument++}if(null==this.data[1][`s${i}_${n}`]){const t=2*this.structure(this.argument)*oe;this.data[1][`s${i}_${n}`]={x:he(t),y:ae(t)},this.argument++}const o=this.data[1][`s${s}_${n}`],a=this.data[1][`s${s}_${r}`],h=this.data[1][`s${i}_${r}`],l=this.data[1][`s${i}_${n}`],c=n-e,u=s-t,_=r-e,m=i-t,p=r-e,f=i-t,d=n-e,T=(s-t)*o.x+c*o.y,x=u*a.x+_*a.y,E=m*h.x+p*h.y,g=f*l.x+d*l.y,R=.5*(T*me+1),y=.5*(x*me+1),A=.5*(E*me+1),U=.5*(g*me+1),v=t-ue(t),S=e-ue(e),M=this.lerp(R,U,v),F=this.lerp(y,A,v);return this.lerp(M,F,S)}get3d(t=0,e=0,s=0){const i=le(t),n=ce(t),r=le(e),o=ce(e),a=le(s),h=ce(s);if(null==this.data[2][`s${i}_${r}_${a}`]){const t=2*this.structure(this.argument)*oe,e=2*this.structure(this.argument+1)*oe,s=ae(t);this.data[2][`s${i}_${r}_${a}`]={x:s*he(e),y:s*ae(e),z:he(t)},this.argument+=2}if(null==this.data[2][`s${i}_${o}_${a}`]){const t=2*this.structure(this.argument)*oe,e=2*this.structure(this.argument+1)*oe,s=ae(t);this.data[2][`s${i}_${o}_${a}`]={x:s*he(e),y:s*ae(e),z:he(t)},this.argument+=2}if(null==this.data[2][`s${n}_${o}_${a}`]){const t=2*this.structure(this.argument)*oe,e=2*this.structure(this.argument+1)*oe,s=ae(t);this.data[2][`s${n}_${o}_${a}`]={x:s*he(e),y:s*ae(e),z:he(t)},this.argument+=2}if(null==this.data[2][`s${n}_${r}_${a}`]){const t=2*this.structure(this.argument)*oe,e=2*this.structure(this.argument+1)*oe,s=ae(t);this.data[2][`s${n}_${r}_${a}`]={x:s*he(e),y:s*ae(e),z:he(t)},this.argument+=2}if(null==this.data[2][`s${i}_${r}_${h}`]){const t=2*this.structure(this.argument)*oe,e=2*this.structure(this.argument+1)*oe,s=ae(t);this.data[2][`s${i}_${r}_${h}`]={x:s*he(e),y:s*ae(e),z:he(t)},this.argument+=2}if(null==this.data[2][`s${i}_${o}_${h}`]){const t=2*this.structure(this.argument)*oe,e=2*this.structure(this.argument+1)*oe,s=ae(t);this.data[2][`s${i}_${o}_${h}`]={x:s*he(e),y:s*ae(e),z:he(t)},this.argument+=2}if(null==this.data[2][`s${n}_${o}_${h}`]){const t=2*this.structure(this.argument)*oe,e=2*this.structure(this.argument+1)*oe,s=ae(t);this.data[2][`s${n}_${o}_${h}`]={x:s*he(e),y:s*ae(e),z:he(t)},this.argument+=2}if(null==this.data[2][`s${n}_${r}_${h}`]){const t=2*this.structure(this.argument)*oe,e=2*this.structure(this.argument+1)*oe,s=ae(t);this.data[2][`s${n}_${r}_${h}`]={x:s*he(e),y:s*ae(e),z:he(t)},this.argument+=2}const l=this.data[2][`s${i}_${r}_${a}`],c=this.data[2][`s${i}_${o}_${a}`],u=this.data[2][`s${n}_${o}_${a}`],_=this.data[2][`s${n}_${r}_${a}`],m=this.data[2][`s${i}_${r}_${h}`],p=this.data[2][`s${i}_${o}_${h}`],f=this.data[2][`s${n}_${o}_${h}`],d=this.data[2][`s${n}_${r}_${h}`],T=r-e,x=a-s,E=i-t,g=o-e,R=a-s,y=n-t,A=o-e,U=a-s,v=n-t,S=r-e,M=a-s,F=i-t,b=r-e,I=h-s,w=i-t,D=o-e,N=h-s,P=n-t,$=o-e,O=h-s,L=n-t,X=r-e,C=h-s,B=(i-t)*l.x+T*l.y+x*l.z,G=E*c.x+g*c.y+R*c.z,k=y*u.x+A*u.y+U*u.z,W=v*_.x+S*_.y+M*_.z,z=F*m.x+b*m.y+I*m.z,H=w*p.x+D*p.y+N*p.z,V=P*f.x+$*f.y+O*f.z,Y=L*d.x+X*d.y+C*d.z,q=.5*(B*pe+1),j=.5*(G*pe+1),J=.5*(k*pe+1),K=.5*(W*pe+1),Z=.5*(z*pe+1),Q=.5*(H*pe+1),tt=.5*(V*pe+1),et=.5*(Y*pe+1),st=t-ue(t),it=e-ue(e),nt=s-ue(s),rt=this.lerp(q,K,st),ot=this.lerp(j,J,st),at=this.lerp(Z,et,st),ht=this.lerp(Q,tt,st),lt=this.lerp(rt,ot,it),ct=this.lerp(at,ht,it);return this.lerp(lt,ct,nt)}}class de{constructor(){this.type="FileLoader"}loadFile(t,e){const s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="arraybuffer",s.onload=()=>{if(200===s.status){const t=s.response;e(t)}},s.send()}loadFileAsync(t){return new Promise(e=>{const s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="arraybuffer",s.onload=()=>{if(200===s.status){const t=s.response;e(t)}},s.send()})}}class Te extends de{constructor(){super(),this.type="TextLoader",this.textDecoder=new TextDecoder("utf-8")}loadAsync(t){return new Promise(e=>{this.loadFile(t,t=>{const s=new Uint8Array(t);e(this.textDecoder.decode(s))})})}}class xe{constructor(){this.type="TextureLoader"}loadAsync(t){const e=JSON.parse(`["${t.replace(/\./g,'","')}"]`),s=e[e.length-1].toLowerCase();return new Promise(e=>{if("jpeg"==s||"jpg"==s||"png"==s||"gif"==s||"webp"==s||"bmp"==s){const s=new Image;s.crossOrigin="anonymous",s.src=t,s.onload=()=>e(new Y(s))}else if("mp4"==s||"m4v"==s||"webm"==s){const s=document.createElement("video");s.crossOrigin="anonymous",s.muted=!0,s.src=t,s.onloadeddata=()=>{s.width=s.videoWidth,s.height=s.videoHeight,e(new Y(s))}}})}}const Ee=document.createElement("canvas"),ge=Ee.getContext("2d",{willReadFrequently:!0}),Re=Math.round;class ye{constructor(){this.type="StringLoader",this.fonts=["sans-serif","Arial","Helvetica","Verdana","Tahoma","Trebuchet MS","serif","Times New Roman","Georgia","Palatino","monospace","Courier New","Lucida Console","Monaco","Consolas","cursive","Comic Sans MS","Brush Script MT","fantasy","Impact","Papyrus","FangSong","仿宋","Microsoft YaHei","微软雅黑"]}getFont(t){const e=t.toLowerCase();let s;for(let t of this.fonts)if(t.toLowerCase()==e){switch(t){case"Airal":s="Airal, sans-serif";break;case"Helvetica":s="Helvetica, sans-serif";break;case"Verdana":s="Verdana, sans-serif";break;case"Tahoma":s="Tahoma, sans-serif";break;case"Trebuchet MS":s='"Trebuchet MS", sans-serif';break;case"Times New Roman":s='"Times New Roman", serif';break;case"Georgia":s="Georgia, serif";break;case"Palatino":s="Palatino, serif";break;case"Courier New":s='"Courier New", monospace';break;case"Lucida Console":s='"Lucida Console", monospace';break;case"Monaco":s="Monaco, monospace";break;case"Consolas":s="Consolas, monospace";break;case"Comic Sans MS":s='"Comic Sans MS", cursive';break;case"Brush Script MT":s='"Brush Script MT", cursive';break;case"Impact":s="Impact, fantasy";break;case"Papyrus":s="Papyrus, fantasy";break;case"FangSong":s='"FangSong"';break;case"仿宋":s='"仿宋"';break;case"Microsoft YaHei":s='"Microsoft YaHei"';break;case"微软雅黑":s='"微软雅黑"';break;default:s=t}break}return s}queryFont(t){const e=t.toLowerCase();let s=!1;for(let t of this.fonts)if(t.toLowerCase()==e){s=!0;break}return s}addFont(t,e){if(!this.queryFont(t)){new FontFace(t,`url(${e})`).load().then(e=>{document.fonts.add(e),this.fonts.push(t)}).catch(t=>console.error("字体加载失败:",t))}}fontReady(t){document.fonts.ready.then(()=>{t?.()})}createAsync(t){const e={text:"Hello LiaoJS!",size:40,style:"normal",weight:"normal",variant:"normal",font:"sans-serif",color:"#7b68ee",paddingW:0,paddingH:0,shadow:!1,shadowColor:"rgba(0,0,0,0.8)",shadowOffsetX:6,shadowOffsetY:6,shadowBlur:8,outline:!1,outlines:[]};st(t,e,["outlines"]),this.queryFont(e.font)?e.font=this.getFont(e.font):e.font="sans-serif",ge.font=`${e.variant} ${e.style} ${e.weight} ${e.size}px ${e.font}`;const s=ge.measureText(e.text),i=Re(s.actualBoundingBoxRight-s.actualBoundingBoxLeft)+2*e.paddingW,n=Re(s.actualBoundingBoxAscent+s.actualBoundingBoxDescent)+2*e.paddingH;Ee.width=i,Ee.height=n,ge.clearRect(0,0,i,n),ge.textAlign="start",ge.textBaseline="top",ge.font=`${e.variant} ${e.style} ${e.weight} ${e.size}px ${e.font}`,e.shadow&&(ge.shadowColor=e.shadowColor,ge.shadowOffsetX=e.shadowOffsetX,ge.shadowOffsetY=e.shadowOffsetY,ge.shadowBlur=e.shadowBlur);const r=e.paddingW,o=e.paddingH;ge.fillStyle=e.color,ge.fillText(e.text,r,o),e.outline&&e.outlines.forEach(t=>{const s=[2,2],i=1,n="#868686";null==t.spacing&&(t.spacing=s),null==t.width&&(t.width=i),null==t.color&&(t.color=n),ge.setLineDash(t.spacing),ge.strokeStyle=t.color,ge.lineWidth=t.width,ge.strokeText(e.text,r,o),ge.setLineDash([])});const a=Ee.toDataURL("image/png");return new Promise(t=>{const e=new Image;e.src=a,e.onload=()=>t(new Y(e))})}}const Ae="beta 0.1.29";export{te as AnBezier,ie as AnCureController,ee as AnFunc,Qt as AnGetBezierFunc,se as AnLerp,ne as Animation,J as ArrayMaterial,q as BasicMaterial,dt as BezierHelper,It as BezierToCure,Q as Bone,C as BufferGeometry,D as Camera2D,_t as CircleGeometry,xt as CircleHelper,wt as CureToShape,Nt as EllipseGeometry,Xt as EllipseHelper,Dt as Extrusion,de as FileLoader,ft as GridHelper,ct as Group,Ot as HeartGeometry,Bt as HeartHelper,Pt as IsoscelesGeometry,re as MathUtils,u as Matrix2,_ as Matrix3,m as Matrix4,c as MatrixNxM,mt as MergeGeometry,X as Mesh,pt as MeshHelper,Lt as MeshHelperX,fe as PerlinNoise,Y as RawTexture,ut as RectGeometry,Tt as RectHelper,b as Scene,tt as Skeleton,Et as SkeletonHelper,et as SkinnedMesh,$t as StarGeometry,Ct as StarHelper,ye as StringLoader,Te as TextLoader,xe as TextureLoader,f as Vector2,d as Vector3,T as Vector4,p as VectorN,Ae as Version,j as VertexMaterial,M as WebGLRenderer};
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 柏林噪声
|
|
3
|
+
* 当前版本 0.2
|
|
4
|
+
* 于2024年7月7日开始开发
|
|
5
|
+
* @author MiaoShangZuan <3268208143@qq.com>
|
|
6
|
+
*/
|
|
7
|
+
const PI = Math.PI;
|
|
8
|
+
const sin = Math.sin;
|
|
9
|
+
const cos = Math.cos;
|
|
10
|
+
const floor = Math.floor;
|
|
11
|
+
const ceil = Math.ceil;
|
|
12
|
+
const trunc = Math.trunc;
|
|
13
|
+
const random = Math.random;
|
|
14
|
+
const _J2 = 1 / 1.414214;
|
|
15
|
+
const _J3 = 1 / 1.7321;
|
|
16
|
+
|
|
17
|
+
class PerlinNoise {
|
|
18
|
+
constructor( structure=()=>{return random()} ) {
|
|
19
|
+
this.data = [{}, {}, {}];
|
|
20
|
+
this.argument = 0;
|
|
21
|
+
this.structure = structure;
|
|
22
|
+
}
|
|
23
|
+
fade( t ) {
|
|
24
|
+
return 6 * t * t * t * t * t - 15 * t * t * t * t + 10 * t * t * t;
|
|
25
|
+
}
|
|
26
|
+
lerp( a, b, x ) {
|
|
27
|
+
return a + this.fade(x) * (b - a);
|
|
28
|
+
}
|
|
29
|
+
get1d( x=0 ) {
|
|
30
|
+
const x1 = floor(x), x2 = ceil(x);
|
|
31
|
+
|
|
32
|
+
if(this.data[0][`s${x1}`] == undefined) {
|
|
33
|
+
this.data[0][`s${x1}`] = this.structure(this.argument);
|
|
34
|
+
this.argument++;
|
|
35
|
+
}
|
|
36
|
+
if(this.data[0][`s${x2}`] == undefined) {
|
|
37
|
+
this.data[0][`s${x2}`] = this.structure(this.argument);
|
|
38
|
+
this.argument++;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const y1 = this.data[0][`s${x1}`], y2 = this.data[0][`s${x2}`],
|
|
42
|
+
t = x - trunc(x);
|
|
43
|
+
|
|
44
|
+
return this.lerp( y1, y2, t );
|
|
45
|
+
}
|
|
46
|
+
get2d( x=0, y=0 ) {
|
|
47
|
+
const x1 = floor(x), x2 = ceil(x),
|
|
48
|
+
y1 = floor(y), y2 = ceil(y);
|
|
49
|
+
|
|
50
|
+
if(this.data[1][`s${x1}_${y1}`] == undefined) {
|
|
51
|
+
const rad = this.structure(this.argument) * 2 * PI;
|
|
52
|
+
this.data[1][`s${x1}_${y1}`] = { x: cos(rad), y: sin(rad) };
|
|
53
|
+
this.argument++;
|
|
54
|
+
}
|
|
55
|
+
if(this.data[1][`s${x1}_${y2}`] == undefined) {
|
|
56
|
+
const rad = this.structure(this.argument) * 2 * PI;
|
|
57
|
+
this.data[1][`s${x1}_${y2}`] = { x: cos(rad), y: sin(rad) };
|
|
58
|
+
this.argument++;
|
|
59
|
+
}
|
|
60
|
+
if(this.data[1][`s${x2}_${y2}`] == undefined) {
|
|
61
|
+
const rad = this.structure(this.argument) * 2 * PI;
|
|
62
|
+
this.data[1][`s${x2}_${y2}`] = { x: cos(rad), y: sin(rad) };
|
|
63
|
+
this.argument++;
|
|
64
|
+
}
|
|
65
|
+
if(this.data[1][`s${x2}_${y1}`] == undefined) {
|
|
66
|
+
const rad = this.structure(this.argument) * 2 * PI;
|
|
67
|
+
this.data[1][`s${x2}_${y1}`] = { x: cos(rad), y: sin(rad) };
|
|
68
|
+
this.argument++;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* dot1 -- upper left
|
|
73
|
+
* dot2 -- lower left
|
|
74
|
+
* dot3 -- lower right
|
|
75
|
+
* dot4 -- upper right
|
|
76
|
+
*/
|
|
77
|
+
const p1 = this.data[1][`s${x1}_${y1}`],
|
|
78
|
+
p2 = this.data[1][`s${x1}_${y2}`],
|
|
79
|
+
p3 = this.data[1][`s${x2}_${y2}`],
|
|
80
|
+
p4 = this.data[1][`s${x2}_${y1}`],
|
|
81
|
+
v1 = { x: x1-x, y: y1-y },
|
|
82
|
+
v2 = { x: x1-x, y: y2-y },
|
|
83
|
+
v3 = { x: x2-x, y: y2-y },
|
|
84
|
+
v4 = { x: x2-x, y: y1-y },
|
|
85
|
+
dot1 = v1.x * p1.x + v1.y * p1.y,
|
|
86
|
+
dot2 = v2.x * p2.x + v2.y * p2.y,
|
|
87
|
+
dot3 = v3.x * p3.x + v3.y * p3.y,
|
|
88
|
+
dot4 = v4.x * p4.x + v4.y * p4.y,
|
|
89
|
+
g1 = (dot1 * _J2 + 1) * 0.5,
|
|
90
|
+
g2 = (dot2 * _J2 + 1) * 0.5,
|
|
91
|
+
g3 = (dot3 * _J2 + 1) * 0.5,
|
|
92
|
+
g4 = (dot4 * _J2 + 1) * 0.5,
|
|
93
|
+
u = x - trunc(x), v = y - trunc(y),
|
|
94
|
+
lerp1 = this.lerp( g1, g4, u ),
|
|
95
|
+
lerp2 = this.lerp( g2, g3, u );
|
|
96
|
+
|
|
97
|
+
return this.lerp( lerp1, lerp2, v );
|
|
98
|
+
}
|
|
99
|
+
get3d( x=0, y=0, z=0 ) {
|
|
100
|
+
const x1 = floor(x), x2 = ceil(x),
|
|
101
|
+
y1 = floor(y), y2 = ceil(y),
|
|
102
|
+
z1 = floor(z), z2 = ceil(z);
|
|
103
|
+
|
|
104
|
+
if(this.data[2][`s${x1}_${y1}_${z1}`] == undefined) {
|
|
105
|
+
const u = this.structure(this.argument) * 2 * PI, v = this.structure(this.argument+1) * 2 * PI,
|
|
106
|
+
sinu = sin(u);
|
|
107
|
+
this.data[2][`s${x1}_${y1}_${z1}`] = { x: sinu*cos(v), y: sinu*sin(v), z: cos(u) };
|
|
108
|
+
this.argument+=2;
|
|
109
|
+
}
|
|
110
|
+
if(this.data[2][`s${x1}_${y2}_${z1}`] == undefined) {
|
|
111
|
+
const u = this.structure(this.argument) * 2 * PI, v = this.structure(this.argument+1) * 2 * PI,
|
|
112
|
+
sinu = sin(u);
|
|
113
|
+
this.data[2][`s${x1}_${y2}_${z1}`] = { x: sinu*cos(v), y: sinu*sin(v), z: cos(u) };
|
|
114
|
+
this.argument+=2;
|
|
115
|
+
}
|
|
116
|
+
if(this.data[2][`s${x2}_${y2}_${z1}`] == undefined) {
|
|
117
|
+
const u = this.structure(this.argument) * 2 * PI, v = this.structure(this.argument+1) * 2 * PI,
|
|
118
|
+
sinu = sin(u);
|
|
119
|
+
this.data[2][`s${x2}_${y2}_${z1}`] = { x: sinu*cos(v), y: sinu*sin(v), z: cos(u) };
|
|
120
|
+
this.argument+=2;
|
|
121
|
+
}
|
|
122
|
+
if(this.data[2][`s${x2}_${y1}_${z1}`] == undefined) {
|
|
123
|
+
const u = this.structure(this.argument) * 2 * PI, v = this.structure(this.argument+1) * 2 * PI,
|
|
124
|
+
sinu = sin(u);
|
|
125
|
+
this.data[2][`s${x2}_${y1}_${z1}`] = { x: sinu*cos(v), y: sinu*sin(v), z: cos(u) };
|
|
126
|
+
this.argument+=2;
|
|
127
|
+
}
|
|
128
|
+
if(this.data[2][`s${x1}_${y1}_${z2}`] == undefined) {
|
|
129
|
+
const u = this.structure(this.argument) * 2 * PI, v = this.structure(this.argument+1) * 2 * PI,
|
|
130
|
+
sinu = sin(u);
|
|
131
|
+
this.data[2][`s${x1}_${y1}_${z2}`] = { x: sinu*cos(v), y: sinu*sin(v), z: cos(u) };
|
|
132
|
+
this.argument+=2;
|
|
133
|
+
}
|
|
134
|
+
if(this.data[2][`s${x1}_${y2}_${z2}`] == undefined) {
|
|
135
|
+
const u = this.structure(this.argument) * 2 * PI, v = this.structure(this.argument+1) * 2 * PI,
|
|
136
|
+
sinu = sin(u);
|
|
137
|
+
this.data[2][`s${x1}_${y2}_${z2}`] = { x: sinu*cos(v), y: sinu*sin(v), z: cos(u) };
|
|
138
|
+
this.argument+=2;
|
|
139
|
+
}
|
|
140
|
+
if(this.data[2][`s${x2}_${y2}_${z2}`] == undefined) {
|
|
141
|
+
const u = this.structure(this.argument) * 2 * PI, v = this.structure(this.argument+1) * 2 * PI,
|
|
142
|
+
sinu = sin(u);
|
|
143
|
+
this.data[2][`s${x2}_${y2}_${z2}`] = { x: sinu*cos(v), y: sinu*sin(v), z: cos(u) };
|
|
144
|
+
this.argument+=2;
|
|
145
|
+
}
|
|
146
|
+
if(this.data[2][`s${x2}_${y1}_${z2}`] == undefined) {
|
|
147
|
+
const u = this.structure(this.argument) * 2 * PI, v = this.structure(this.argument+1) * 2 * PI,
|
|
148
|
+
sinu = sin(u);
|
|
149
|
+
this.data[2][`s${x2}_${y1}_${z2}`] = { x: sinu*cos(v), y: sinu*sin(v), z: cos(u) };
|
|
150
|
+
this.argument+=2;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const p1 = this.data[2][`s${x1}_${y1}_${z1}`],
|
|
154
|
+
p2 = this.data[2][`s${x1}_${y2}_${z1}`],
|
|
155
|
+
p3 = this.data[2][`s${x2}_${y2}_${z1}`],
|
|
156
|
+
p4 = this.data[2][`s${x2}_${y1}_${z1}`],
|
|
157
|
+
p5 = this.data[2][`s${x1}_${y1}_${z2}`],
|
|
158
|
+
p6 = this.data[2][`s${x1}_${y2}_${z2}`],
|
|
159
|
+
p7 = this.data[2][`s${x2}_${y2}_${z2}`],
|
|
160
|
+
p8 = this.data[2][`s${x2}_${y1}_${z2}`],
|
|
161
|
+
v1 = { x: x1-x, y: y1-y, z: z1-z },
|
|
162
|
+
v2 = { x: x1-x, y: y2-y, z: z1-z },
|
|
163
|
+
v3 = { x: x2-x, y: y2-y, z: z1-z },
|
|
164
|
+
v4 = { x: x2-x, y: y1-y, z: z1-z },
|
|
165
|
+
v5 = { x: x1-x, y: y1-y, z: z2-z },
|
|
166
|
+
v6 = { x: x1-x, y: y2-y, z: z2-z },
|
|
167
|
+
v7 = { x: x2-x, y: y2-y, z: z2-z },
|
|
168
|
+
v8 = { x: x2-x, y: y1-y, z: z2-z },
|
|
169
|
+
dot1 = v1.x * p1.x + v1.y * p1.y + v1.z * p1.z,
|
|
170
|
+
dot2 = v2.x * p2.x + v2.y * p2.y + v2.z * p2.z,
|
|
171
|
+
dot3 = v3.x * p3.x + v3.y * p3.y + v3.z * p3.z,
|
|
172
|
+
dot4 = v4.x * p4.x + v4.y * p4.y + v4.z * p4.z,
|
|
173
|
+
dot5 = v5.x * p5.x + v5.y * p5.y + v5.z * p5.z,
|
|
174
|
+
dot6 = v6.x * p6.x + v6.y * p6.y + v6.z * p6.z,
|
|
175
|
+
dot7 = v7.x * p7.x + v7.y * p7.y + v7.z * p7.z,
|
|
176
|
+
dot8 = v8.x * p8.x + v8.y * p8.y + v8.z * p8.z,
|
|
177
|
+
g1 = (dot1 * _J3 + 1) * 0.5,
|
|
178
|
+
g2 = (dot2 * _J3 + 1) * 0.5,
|
|
179
|
+
g3 = (dot3 * _J3 + 1) * 0.5,
|
|
180
|
+
g4 = (dot4 * _J3 + 1) * 0.5,
|
|
181
|
+
g5 = (dot5 * _J3 + 1) * 0.5,
|
|
182
|
+
g6 = (dot6 * _J3 + 1) * 0.5,
|
|
183
|
+
g7 = (dot7 * _J3 + 1) * 0.5,
|
|
184
|
+
g8 = (dot8 * _J3 + 1) * 0.5,
|
|
185
|
+
r = x - trunc(x),
|
|
186
|
+
g = y - trunc(y),
|
|
187
|
+
b = z - trunc(z),
|
|
188
|
+
lerp1 = this.lerp( g1, g4, r ),
|
|
189
|
+
lerp2 = this.lerp( g2, g3, r ),
|
|
190
|
+
lerp3 = this.lerp( g5, g8, r ),
|
|
191
|
+
lerp4 = this.lerp( g6, g7, r ),
|
|
192
|
+
lerp5 = this.lerp( lerp1, lerp2, g ),
|
|
193
|
+
lerp6 = this.lerp( lerp3, lerp4, g );
|
|
194
|
+
|
|
195
|
+
return this.lerp( lerp5, lerp6, b );
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export default PerlinNoise;
|