vislite 0.5.0 → 0.5.2-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.
Files changed (157) hide show
  1. package/.editorconfig +18 -18
  2. package/AUTHORS.txt +6 -6
  3. package/CHANGELOG +5 -0
  4. package/LICENSE +20 -20
  5. package/README.md +69 -69
  6. package/miniprogram/ui-canvas/index.js +107 -107
  7. package/miniprogram/ui-canvas/index.json +4 -4
  8. package/miniprogram/ui-canvas/index.wxml +4 -4
  9. package/miniprogram/ui-canvas/index.wxss +5 -5
  10. package/package/Buffer/index.ts +2 -2
  11. package/package/Canvas/index.ts +2 -2
  12. package/package/Cardinal/index.ts +2 -2
  13. package/package/Eoap/index.ts +2 -2
  14. package/package/Hermite/index.ts +2 -2
  15. package/package/Matrix4/index.ts +2 -2
  16. package/package/Mercator/index.ts +2 -2
  17. package/package/OralCanvas/index.ts +2 -2
  18. package/package/OralWebGL/index.ts +2 -2
  19. package/package/SVG/index.ts +2 -2
  20. package/package/Shader/index.ts +39 -39
  21. package/package/Texture/index.ts +2 -2
  22. package/package/TreeLayout/index.ts +2 -2
  23. package/package/WebGL/index.ts +2 -2
  24. package/package/animation/index.ts +2 -2
  25. package/package/formatColor/index.ts +2 -2
  26. package/package/getLoopColors/index.ts +2 -2
  27. package/package/getWebGLContext/index.ts +39 -39
  28. package/package/resizeObserver/index.ts +2 -2
  29. package/package/rotate/index.ts +2 -2
  30. package/package/ruler/index.ts +2 -2
  31. package/package/throttle/index.ts +2 -2
  32. package/package/viewHandler/index.ts +2 -2
  33. package/package.json +1 -1
  34. package/src/Canvas.ts +67 -67
  35. package/src/Matrix4/move.ts +12 -12
  36. package/src/Matrix4/rotate.ts +15 -15
  37. package/src/Matrix4/scale.ts +11 -11
  38. package/src/Matrix4/transform.ts +64 -64
  39. package/src/SVG.ts +24 -24
  40. package/src/WebGL.ts +66 -66
  41. package/src/animation.ts +98 -98
  42. package/src/common/assemble.ts +22 -22
  43. package/src/common/canvas/arc.ts +50 -50
  44. package/src/common/canvas/config.ts +158 -158
  45. package/src/common/canvas/gradient.ts +29 -29
  46. package/src/common/canvas/index.ts +168 -168
  47. package/src/common/canvas/painter.ts +426 -426
  48. package/src/common/canvas/texts.ts +18 -18
  49. package/src/common/mergeOption.ts +6 -6
  50. package/src/common/setStyle.ts +5 -5
  51. package/src/common/svg/config.ts +174 -174
  52. package/src/common/svg/tool.ts +44 -44
  53. package/src/common/tree/index.ts +25 -25
  54. package/src/common/tree/toInnerTree.ts +56 -56
  55. package/src/common/tree/toPlainTree.ts +131 -131
  56. package/src/common/webgl/buffer.ts +79 -79
  57. package/src/common/webgl/doDraw.ts +108 -108
  58. package/src/common/webgl/getColorFactory.ts +26 -26
  59. package/src/common/webgl/getShader.ts +48 -48
  60. package/src/common/webgl/getTexture.ts +11 -11
  61. package/src/common/webgl/getWebGLContext.ts +27 -27
  62. package/src/common/webgl/index.ts +223 -223
  63. package/src/common/webgl/shader.ts +75 -75
  64. package/src/common/webgl/texture.ts +96 -96
  65. package/src/formatColor.ts +44 -44
  66. package/src/getLoopColors.ts +42 -42
  67. package/src/interpolation/Cardinal.ts +110 -110
  68. package/src/interpolation/Hermite.ts +65 -65
  69. package/src/resizeObserver.ts +36 -36
  70. package/src/ruler.ts +188 -188
  71. package/src/shader/fsColor.c +7 -7
  72. package/src/shader/fsColors.c +7 -7
  73. package/src/shader/fsCube.c +8 -8
  74. package/src/shader/fsImage.c +8 -8
  75. package/src/shader/vsColor.c +17 -17
  76. package/src/shader/vsColors.c +13 -13
  77. package/src/shader/vsCube.c +13 -13
  78. package/src/shader/vsImage.c +13 -13
  79. package/src/throttle.ts +51 -51
  80. package/src/viewHandler.ts +158 -158
  81. package/types/Buffer.d.ts +23 -23
  82. package/types/Canvas.d.ts +300 -300
  83. package/types/CanvasOption.d.ts +7 -7
  84. package/types/Cardinal.d.ts +13 -13
  85. package/types/Gradient.d.ts +14 -14
  86. package/types/Hermite.d.ts +18 -18
  87. package/types/Object3D.d.ts +114 -114
  88. package/types/SVGConfig.d.ts +76 -76
  89. package/types/Scene3D.d.ts +6 -6
  90. package/types/Shader.d.ts +21 -21
  91. package/types/Texture.d.ts +16 -16
  92. package/types/Tree.d.ts +69 -69
  93. package/types/TreeConfig.d.ts +24 -24
  94. package/types/TreeOption.d.ts +48 -48
  95. package/types/WebGL.d.ts +38 -38
  96. package/types/WebGLOption.d.ts +7 -7
  97. package/types/animation.d.ts +6 -6
  98. package/types/formatColor.d.ts +2 -2
  99. package/types/getLoopColors.d.ts +2 -2
  100. package/types/getWebGLContext.d.ts +2 -2
  101. package/types/painterConfig.d.ts +2 -2
  102. package/types/resizeObserver.d.ts +2 -2
  103. package/types/ruler.d.ts +7 -7
  104. package/types/throttle.d.ts +4 -4
  105. package/types/throttleOption.d.ts +21 -21
  106. package/types/viewHandler.d.ts +13 -13
  107. package/uni-app/ui-canvas.vue +226 -222
  108. package/lib/Buffer/index.umd.js +0 -55
  109. package/lib/Buffer/index.umd.min.js +0 -11
  110. package/lib/Canvas/index.umd.js +0 -721
  111. package/lib/Canvas/index.umd.min.js +0 -11
  112. package/lib/Cardinal/index.umd.js +0 -112
  113. package/lib/Cardinal/index.umd.min.js +0 -11
  114. package/lib/Eoap/index.umd.js +0 -53
  115. package/lib/Eoap/index.umd.min.js +0 -11
  116. package/lib/Geometry/index.umd.js +0 -205
  117. package/lib/Geometry/index.umd.min.js +0 -11
  118. package/lib/Hermite/index.umd.js +0 -55
  119. package/lib/Hermite/index.umd.min.js +0 -11
  120. package/lib/Matrix4/index.umd.js +0 -146
  121. package/lib/Matrix4/index.umd.min.js +0 -11
  122. package/lib/Mercator/index.umd.js +0 -39
  123. package/lib/Mercator/index.umd.min.js +0 -11
  124. package/lib/OralCanvas/index.es.js +0 -657
  125. package/lib/OralCanvas/index.es.min.js +0 -11
  126. package/lib/OralWebGL/index.es.js +0 -611
  127. package/lib/OralWebGL/index.es.min.js +0 -11
  128. package/lib/SVG/index.umd.js +0 -475
  129. package/lib/SVG/index.umd.min.js +0 -11
  130. package/lib/Shader/index.umd.js +0 -134
  131. package/lib/Shader/index.umd.min.js +0 -11
  132. package/lib/Texture/index.umd.js +0 -72
  133. package/lib/Texture/index.umd.min.js +0 -11
  134. package/lib/TreeLayout/index.umd.js +0 -430
  135. package/lib/TreeLayout/index.umd.min.js +0 -11
  136. package/lib/WebGL/index.umd.js +0 -684
  137. package/lib/WebGL/index.umd.min.js +0 -11
  138. package/lib/animation/index.umd.js +0 -91
  139. package/lib/animation/index.umd.min.js +0 -11
  140. package/lib/formatColor/index.umd.js +0 -59
  141. package/lib/formatColor/index.umd.min.js +0 -11
  142. package/lib/getLoopColors/index.umd.js +0 -55
  143. package/lib/getLoopColors/index.umd.min.js +0 -11
  144. package/lib/getWebGLContext/index.umd.js +0 -65
  145. package/lib/getWebGLContext/index.umd.min.js +0 -11
  146. package/lib/index.umd.js +0 -2834
  147. package/lib/index.umd.min.js +0 -11
  148. package/lib/resizeObserver/index.umd.js +0 -48
  149. package/lib/resizeObserver/index.umd.min.js +0 -11
  150. package/lib/rotate/index.umd.js +0 -27
  151. package/lib/rotate/index.umd.min.js +0 -11
  152. package/lib/ruler/index.umd.js +0 -145
  153. package/lib/ruler/index.umd.min.js +0 -11
  154. package/lib/throttle/index.umd.js +0 -70
  155. package/lib/throttle/index.umd.min.js +0 -11
  156. package/lib/viewHandler/index.umd.js +0 -139
  157. package/lib/viewHandler/index.umd.min.js +0 -11
@@ -1,611 +0,0 @@
1
- /*!
2
- * VISLite JavaScript Library v0.5.0
3
- * git+https://github.com/oi-contrib/VISLite.git
4
- *
5
- * Copyright zxl20070701
6
- * Released under the MIT license
7
- * https://zxl20070701.github.io/notebook/home.html
8
- *
9
- * Publish Date: Sat Sep 30 2023 19:14:04 GMT+0800 (中国标准时间)
10
- */
11
- /******************************************************************************
12
- Copyright (c) Microsoft Corporation.
13
-
14
- Permission to use, copy, modify, and/or distribute this software for any
15
- purpose with or without fee is hereby granted.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
- PERFORMANCE OF THIS SOFTWARE.
24
- ***************************************************************************** */
25
- /* global Reflect, Promise, SuppressedError, Symbol */
26
-
27
-
28
- function __spreadArray(to, from, pack) {
29
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
- if (ar || !(i in from)) {
31
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
- ar[i] = from[i];
33
- }
34
- }
35
- return to.concat(ar || Array.prototype.slice.call(from));
36
- }
37
-
38
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
39
- var e = new Error(message);
40
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
41
- };
42
-
43
- function getWebGLContext (canvas, scale, opts) {
44
- if (opts === void 0) { opts = {}; }
45
- var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"], painter = null;
46
- for (var i = 0; i < names.length; i++) {
47
- try {
48
- painter = canvas.getContext(names[i], opts);
49
- }
50
- catch (e) { }
51
- if (painter)
52
- break;
53
- }
54
- if (!painter)
55
- throw new Error('Non canvas or browser does not support webgl.');
56
- var width = painter.canvas.width, height = painter.canvas.height;
57
- var viewWidth = width * scale;
58
- var viewHeight = height * scale;
59
- painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
60
- painter.depthFunc(painter.LEQUAL);
61
- painter.enable(painter.DEPTH_TEST);
62
- return painter;
63
- }
64
-
65
- function getColorFactory (painter) {
66
- var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
67
- var pixels = new Uint8Array(4 * width * height);
68
- painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
69
- return function (x, y) {
70
- y = height - y;
71
- var pixelR = pixels[4 * (y * width + x)];
72
- var pixelG = pixels[4 * (y * width + x) + 1];
73
- var pixelB = pixels[4 * (y * width + x) + 2];
74
- var pixelA = pixels[4 * (y * width + x) + 3];
75
- return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
76
- };
77
- }
78
-
79
- function _move (d, a, b, c) {
80
- if (c === void 0) { c = 0; }
81
- var sqrt = Math.sqrt(a * a + b * b + c * c);
82
- return [
83
- 1, 0, 0, 0,
84
- 0, 1, 0, 0,
85
- 0, 0, 1, 0,
86
- a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
87
- ];
88
- }
89
-
90
- function _rotate (deg) {
91
- var sin = Math.sin(deg), cos = Math.cos(deg);
92
- return [
93
- cos, sin, 0, 0,
94
- -sin, cos, 0, 0,
95
- 0, 0, 1, 0,
96
- 0, 0, 0, 1
97
- ];
98
- }
99
-
100
- function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
101
- if (cx === void 0) { cx = 0; }
102
- if (cy === void 0) { cy = 0; }
103
- if (cz === void 0) { cz = 0; }
104
- return [
105
- xTimes, 0, 0, 0,
106
- 0, yTimes, 0, 0,
107
- 0, 0, zTimes, 0,
108
- cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
109
- ];
110
- }
111
-
112
- function _transform (a1, b1, c1, a2, b2, c2) {
113
- if (typeof a1 === 'number' && typeof b1 === 'number') {
114
- if (typeof c1 !== 'number') {
115
- c1 = 0;
116
- a2 = a1;
117
- b2 = b1;
118
- c2 = 1;
119
- }
120
- else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
121
- a2 = a1;
122
- b2 = b1;
123
- c2 = c1;
124
- a1 = 0;
125
- b1 = 0;
126
- c1 = 0;
127
- }
128
- if (a1 == a2 && b1 == b2 && c1 == c2)
129
- throw new Error('It\'s not a legitimate ray!');
130
- var sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)), cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1, sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0, b = (a2 - a1) * sin1 + (b2 - b1) * cos1, c = c2 - c1, sqrt2 = Math.sqrt(b * b + c * c), cos2 = sqrt2 != 0 ? c / sqrt2 : 1, sin2 = sqrt2 != 0 ? b / sqrt2 : 0;
131
- return [
132
- [
133
- cos1, cos2 * sin1, sin1 * sin2, 0,
134
- -sin1, cos1 * cos2, cos1 * sin2, 0,
135
- 0, -sin2, cos2, 0,
136
- b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
137
- ],
138
- [
139
- cos1, -sin1, 0, 0,
140
- cos2 * sin1, cos2 * cos1, -sin2, 0,
141
- sin1 * sin2, cos1 * sin2, cos2, 0,
142
- a1, b1, c1, 1
143
- ]
144
- ];
145
- }
146
- else {
147
- throw new Error('a1 and b1 is required!');
148
- }
149
- }
150
-
151
- var _multiply = function (matrix4, param) {
152
- var newParam = [];
153
- for (var i = 0; i < 4; i++)
154
- for (var j = 0; j < param.length / 4; j++)
155
- newParam[j * 4 + i] =
156
- matrix4[i] * param[j * 4] +
157
- matrix4[i + 4] * param[j * 4 + 1] +
158
- matrix4[i + 8] * param[j * 4 + 2] +
159
- matrix4[i + 12] * param[j * 4 + 3];
160
- return newParam;
161
- };
162
- var Matrix4 = (function () {
163
- function Matrix4(initMatrix4) {
164
- if (initMatrix4 === void 0) { initMatrix4 = [
165
- 1, 0, 0, 0,
166
- 0, 1, 0, 0,
167
- 0, 0, 1, 0,
168
- 0, 0, 0, 1
169
- ]; }
170
- this.name = 'Matrix4';
171
- this.__matrix4 = initMatrix4;
172
- }
173
- Matrix4.prototype.move = function (dis, a, b, c) {
174
- if (c === void 0) { c = 0; }
175
- this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4);
176
- return this;
177
- };
178
- Matrix4.prototype.rotate = function (deg, a1, b1, c1, a2, b2, c2) {
179
- var matrix4s = _transform(a1, b1, c1, a2, b2, c2);
180
- this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4);
181
- return this;
182
- };
183
- Matrix4.prototype.scale = function (xTimes, yTimes, zTimes, cx, cy, cz) {
184
- if (cx === void 0) { cx = 0; }
185
- if (cy === void 0) { cy = 0; }
186
- if (cz === void 0) { cz = 0; }
187
- this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4);
188
- return this;
189
- };
190
- Matrix4.prototype.multiply = function (newMatrix4, flag) {
191
- if (flag === void 0) { flag = false; }
192
- this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4);
193
- return this;
194
- };
195
- Matrix4.prototype.use = function (x, y, z, w) {
196
- if (z === void 0) { z = 0; }
197
- if (w === void 0) { w = 1; }
198
- return _multiply(this.__matrix4, [x, y, z, w]);
199
- };
200
- Matrix4.prototype.value = function () {
201
- return this.__matrix4;
202
- };
203
- return Matrix4;
204
- }());
205
-
206
- var newBuffer = function (painter) {
207
- return painter.createBuffer();
208
- };
209
- var writeBuffer = function (painter, data, isElement, usage) {
210
- var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
211
- painter.bufferData(TYPE, data, usage);
212
- };
213
- var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
214
- painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
215
- painter.enableVertexAttribArray(location);
216
- };
217
- var BufferObject = (function () {
218
- function BufferObject(painter, isElement) {
219
- if (isElement === void 0) { isElement = false; }
220
- this.__painter = painter;
221
- this.__isElement = isElement;
222
- this.__buffer = newBuffer(painter);
223
- this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
224
- }
225
- BufferObject.prototype.use = function () {
226
- this.__painter.bindBuffer(this.__type, this.__buffer);
227
- return this;
228
- };
229
- BufferObject.prototype.write = function (data) {
230
- writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
231
- this.__fsize = data.BYTES_PER_ELEMENT;
232
- return this;
233
- };
234
- BufferObject.prototype.divide = function (location, size, stride, offset) {
235
- if (offset === void 0) { offset = 0; }
236
- useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
237
- return this;
238
- };
239
- return BufferObject;
240
- }());
241
-
242
- var initTexture = function (painter, type, unit) {
243
- var texture = painter.createTexture();
244
- painter.activeTexture(painter['TEXTURE' + unit]);
245
- painter.bindTexture(type, texture);
246
- return texture;
247
- };
248
- var linkImage = function (painter, type, level, format, textureType, image) {
249
- painter.texImage2D(type, level, format, format, textureType, image);
250
- };
251
- var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
252
- var types = [
253
- painter.TEXTURE_CUBE_MAP_POSITIVE_X,
254
- painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
255
- painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
256
- painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
257
- painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
258
- painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
259
- ], target;
260
- for (var i = 0; i < types.length; i++) {
261
- if (images[i]) {
262
- target = types[i];
263
- painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
264
- painter.bindTexture(type, texture);
265
- painter.texImage2D(target, level, format, format, textureType, images[i]);
266
- }
267
- }
268
- painter.generateMipmap(type);
269
- };
270
- var TextureObject = (function () {
271
- function TextureObject(painter, type, unit) {
272
- if (unit === void 0) { unit = 0; }
273
- this.__painter = painter;
274
- this.__type = {
275
- "2d": painter.TEXTURE_2D,
276
- "cube": painter.TEXTURE_CUBE_MAP
277
- }[type];
278
- this.__texture = initTexture(painter, this.__type, unit);
279
- painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
280
- painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
281
- painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
282
- painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
283
- }
284
- TextureObject.prototype.useImage = function (image) {
285
- linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
286
- return this;
287
- };
288
- TextureObject.prototype.useCube = function (images, width, height) {
289
- linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
290
- return this;
291
- };
292
- return TextureObject;
293
- }());
294
-
295
- var textures = {};
296
- function getTexture (type, painter, kind) {
297
- var uniqueName = type + "-" + kind;
298
- if (!textures[uniqueName]) {
299
- textures[uniqueName] = new TextureObject(painter, kind);
300
- }
301
- return textures[uniqueName];
302
- }
303
-
304
- var loadShader = function (painter, type, source) {
305
- var shader = painter.createShader(type);
306
- if (shader == null)
307
- throw new Error('Unable to create shader!');
308
- painter.shaderSource(shader, source);
309
- painter.compileShader(shader);
310
- if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
311
- throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
312
- return shader;
313
- };
314
- var useShader = function (painter, vshaderSource, fshaderSource) {
315
- var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
316
- var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
317
- var glProgram = painter.createProgram();
318
- painter.attachShader(glProgram, vertexShader);
319
- painter.attachShader(glProgram, fragmentShader);
320
- painter.linkProgram(glProgram);
321
- if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
322
- throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
323
- return glProgram;
324
- };
325
- var ShaderObject = (function () {
326
- function ShaderObject(painter) {
327
- this.__painter = painter;
328
- }
329
- ShaderObject.prototype.use = function () {
330
- this.__painter.useProgram(this.program);
331
- return this;
332
- };
333
- ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
334
- this.program = useShader(this.__painter, vshaderSource, fshaderSource);
335
- return this;
336
- };
337
- return ShaderObject;
338
- }());
339
-
340
- var vsColor = "attribute vec4 a_position;\nuniform mat4 u_matrix;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\n temp.z = -1.0 * temp.z;\n\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\n float dist = 4.0;\n\n // 使用投影直接计算\n // 为保证纹理和相对位置正确\n // x、y、z的改变满足线性变换\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n}";
341
-
342
- var vsColors = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_color = a_color;\n}";
343
-
344
- var vsImage = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec2 a_textcoord;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_textcoord = a_textcoord;\n}";
345
-
346
- var vsCube = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_normal;\nvarying vec3 v_normal;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_normal = normalize(vec3(a_normal));\n}";
347
-
348
- var fsColor = "precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}";
349
-
350
- var fsColors = "precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}";
351
-
352
- var fsImage = "precision mediump float;\n\nuniform sampler2D u_sampler;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n gl_FragColor = texture2D(u_sampler, v_textcoord);\n}";
353
-
354
- var fsCube = "precision mediump float;\n\nvarying vec3 v_normal;\nuniform samplerCube u_texture;\n\nvoid main()\n{\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\n}";
355
-
356
- var shaders = {};
357
- function getShader (type, painter, mesh) {
358
- var _a, _b;
359
- var uniqueName = type +
360
- (mesh.material.color ? "1" : "0") +
361
- (mesh.material.colors ? "1" : "0") +
362
- (mesh.material.image ? "1" : "0") +
363
- (mesh.material.cube ? "1" : "0");
364
- if (shaders[uniqueName])
365
- return shaders[uniqueName].use();
366
- var vertexShader = (_a = {},
367
- _a[type + "1000"] = vsColor,
368
- _a[type + "0100"] = vsColors,
369
- _a[type + "0010"] = vsImage,
370
- _a[type + "0001"] = vsCube,
371
- _a)[uniqueName].replace(/uniform +mat4 +u_matrix;/, "\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;").replace(/u_matrix +\* +a_position/, "u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position");
372
- var fragmentShader = (_b = {},
373
- _b[type + "1000"] = fsColor,
374
- _b[type + "0100"] = fsColors,
375
- _b[type + "0010"] = fsImage,
376
- _b[type + "0001"] = fsCube,
377
- _b)[uniqueName];
378
- var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
379
- shaders[uniqueName] = shader;
380
- return shader;
381
- }
382
-
383
- function doDraw (type, painter, mesh, meshWorld, globalWorld) {
384
- var shader = getShader(type, painter, mesh);
385
- new BufferObject(painter).use()
386
- .write(mesh.geometry.attributes.position.array)
387
- .divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
388
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
389
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
390
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
391
- if (mesh.geometry.attributes.normal) {
392
- new BufferObject(painter).use()
393
- .write(mesh.geometry.attributes.normal.array)
394
- .divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
395
- }
396
- if ("color" in mesh.material) {
397
- painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), mesh.material.color.r, mesh.material.color.g, mesh.material.color.b, mesh.material.color.alpha);
398
- }
399
- if ("colors" in mesh.material) {
400
- new BufferObject(painter).use()
401
- .write(mesh.material.colors.array)
402
- .divide(painter.getAttribLocation(shader.program, "a_color"), mesh.material.colors.itemSize, mesh.material.colors.itemSize, 0);
403
- }
404
- else if ("cube" in mesh.material) {
405
- var size = mesh.material.cube.right.image.value.width;
406
- painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
407
- getTexture(type, painter, 'cube').useCube([
408
- mesh.material.cube.right.image.value,
409
- mesh.material.cube.left.image.value,
410
- mesh.material.cube.top.image.value,
411
- mesh.material.cube.bottom.image.value,
412
- mesh.material.cube.far.image.value,
413
- mesh.material.cube.near.image.value
414
- ], size, size);
415
- }
416
- else if ("image" in mesh.material) {
417
- painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
418
- new BufferObject(painter).use()
419
- .write(mesh.geometry.attributes.uv.array)
420
- .divide(painter.getAttribLocation(shader.program, "a_textcoord"), mesh.geometry.attributes.uv.itemSize, 2, 0);
421
- getTexture(type, painter, '2d').useImage(mesh.material.image.value);
422
- }
423
- if (mesh.geometry.index) {
424
- new BufferObject(painter, true).use()
425
- .write(mesh.geometry.index.array);
426
- painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
427
- }
428
- else {
429
- painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
430
- }
431
- }
432
-
433
- function assemble (begin, end, step, count) {
434
- var val = [];
435
- for (var index = 0; index < count; index++)
436
- val[index] = begin;
437
- return function () {
438
- for (var i = 0; i < count; i++) {
439
- if (val[i] + step < end) {
440
- val[i] = +(val[i] + step).toFixed(7);
441
- break;
442
- }
443
- else if (i < count - 1) {
444
- val[i] = begin;
445
- }
446
- }
447
- return val;
448
- };
449
- }
450
-
451
- var needUpdate = false;
452
- var scale = 10;
453
- var WebGL = (function () {
454
- function WebGL(ViewCanvas, RegionCanvas) {
455
- this.name = "WebGL";
456
- this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
457
- this.__regionList = {};
458
- this.__regionAssemble = assemble(0, 1, 0.2, 3);
459
- this.__regionName = "";
460
- this.__regionColor = [0, 0, 0, 1];
461
- this.__scene = {
462
- children: [],
463
- matrix: new Matrix4([
464
- 1, 0, 0, 0,
465
- 0, 1, 0, 0,
466
- 0, 0, 1, 0,
467
- 0, 0, 0, scale
468
- ])
469
- };
470
- this.__unique = new Date().valueOf();
471
- this.painter = getWebGLContext(ViewCanvas, scale);
472
- if (RegionCanvas) {
473
- this.__regionPainter = getWebGLContext(RegionCanvas, scale, {});
474
- }
475
- var proportion = this.painter.canvas.width / this.painter.canvas.height;
476
- var xProportion = 1;
477
- var yProportion = 1;
478
- if (proportion > 1) {
479
- xProportion = 1 / proportion;
480
- }
481
- else {
482
- yProportion = proportion;
483
- }
484
- var zProportion = Math.min(xProportion, yProportion);
485
- this.__proporion = [
486
- xProportion, 0, 0, 0,
487
- 0, yProportion, 0, 0,
488
- 0, 0, zProportion, 0,
489
- 0, 0, 0, 1
490
- ];
491
- }
492
- WebGL.prototype.matrix = function (initMatrix4) {
493
- return new Matrix4(initMatrix4);
494
- };
495
- WebGL.prototype.getMatrix = function () {
496
- return this.__scene.matrix;
497
- };
498
- WebGL.prototype.getObject3D = function () {
499
- return this.__scene.children;
500
- };
501
- WebGL.prototype.review = function (isUpdateRegion) {
502
- if (isUpdateRegion === void 0) { isUpdateRegion = false; }
503
- if (isUpdateRegion) {
504
- if (this.__regionPainter) {
505
- this.__regionPainter.clearColor(1, 1, 1, 1);
506
- this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
507
- }
508
- }
509
- else {
510
- this.painter.clearColor(1, 1, 1, 1);
511
- this.painter.clear(this.painter.COLOR_BUFFER_BIT);
512
- }
513
- for (var index = 0; index < this.__scene.children.length; index++) {
514
- this.draw(this.__scene.children[index], isUpdateRegion);
515
- }
516
- return this;
517
- };
518
- WebGL.prototype.draw = function (object3D, isUpdateRegion) {
519
- if (isUpdateRegion === void 0) { isUpdateRegion = false; }
520
- if (!isUpdateRegion)
521
- needUpdate = true;
522
- var meshWorld = {
523
- matrix: object3D.matrix.value()
524
- };
525
- var globalWorld = {
526
- matrix: this.__scene.matrix.value(),
527
- proporion: this.__proporion
528
- };
529
- this.setRegion(object3D.region);
530
- for (var index = 0; index < object3D.mesh.length; index++) {
531
- if (isUpdateRegion) {
532
- if (this.__regionPainter) {
533
- doDraw("painter" + this.__unique, this.__regionPainter, {
534
- geometry: object3D.mesh[index].geometry,
535
- material: {
536
- color: {
537
- r: this.__regionColor[0],
538
- g: this.__regionColor[1],
539
- b: this.__regionColor[2],
540
- alpha: this.__regionColor[3]
541
- }
542
- }
543
- }, meshWorld, globalWorld);
544
- this.__getColor = getColorFactory(this.__regionPainter);
545
- }
546
- }
547
- else {
548
- doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
549
- }
550
- }
551
- };
552
- WebGL.prototype.render = function (object3D) {
553
- if (!('matrix' in object3D))
554
- object3D.matrix = new Matrix4();
555
- if (!('region' in object3D))
556
- object3D.region = "";
557
- for (var index = 0; index < object3D.mesh.length; index++) {
558
- var mesh = object3D.mesh[index];
559
- if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
560
- mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
561
- }
562
- if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
563
- mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
564
- }
565
- if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
566
- mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
567
- }
568
- if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
569
- mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
570
- }
571
- if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
572
- mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
573
- }
574
- }
575
- this.__scene.children.push(object3D);
576
- this.draw(object3D);
577
- };
578
- WebGL.prototype.setRegion = function (regionName) {
579
- this.__regionName = regionName + "";
580
- if (regionName) {
581
- if (this.__regionList[regionName] == void 0) {
582
- this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
583
- }
584
- this.__regionColor = this.__regionList[regionName];
585
- }
586
- else {
587
- this.__regionColor = [0, 0, 0, 1];
588
- }
589
- return this;
590
- };
591
- WebGL.prototype.getRegion = function (x, y) {
592
- var _this = this;
593
- if (needUpdate)
594
- this.review(true);
595
- needUpdate = false;
596
- return new Promise(function (resolve, reject) {
597
- var rgba = _this.__getColor(x, y);
598
- for (var key in _this.__regionList) {
599
- var currentRGBA = _this.__regionList[key];
600
- if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
601
- resolve(key);
602
- break;
603
- }
604
- }
605
- resolve("");
606
- });
607
- };
608
- return WebGL;
609
- }());
610
-
611
- export { WebGL as default };
@@ -1,11 +0,0 @@
1
- /*!
2
- * VISLite JavaScript Library v0.5.0
3
- * git+https://github.com/oi-contrib/VISLite.git
4
- *
5
- * Copyright zxl20070701
6
- * Released under the MIT license
7
- * https://zxl20070701.github.io/notebook/home.html
8
- *
9
- * Publish Date: Sat Sep 30 2023 19:14:04 GMT+0800 (中国标准时间)
10
- */
11
- function t(t,r,e){if(e||2===arguments.length)for(var i,o=0,n=r.length;o<n;o++)!i&&o in r||(i||(i=Array.prototype.slice.call(r,0,o)),i[o]=r[o]);return t.concat(i||Array.prototype.slice.call(r))}function r(t,r,e){void 0===e&&(e={});for(var i=["webgl","experimental-webgl","webkit-3d","moz-webgl"],o=null,n=0;n<i.length;n++){try{o=t.getContext(i[n],e)}catch(t){}if(o)break}if(!o)throw new Error("Non canvas or browser does not support webgl.");var a=o.canvas.width,_=o.canvas.height,s=a*r,m=_*r;return o.viewport(.5*(a-s),.5*(_-m),s,m),o.depthFunc(o.LEQUAL),o.enable(o.DEPTH_TEST),o}function e(t){var r=t.drawingBufferWidth,e=t.drawingBufferHeight,i=new Uint8Array(4*r*e);return t.readPixels(0,0,r,e,t.RGBA,t.UNSIGNED_BYTE,i),function(t,o){return"rgba("+i[4*((o=e-o)*r+t)]+","+i[4*(o*r+t)+1]+","+i[4*(o*r+t)+2]+","+i[4*(o*r+t)+3]+")"}}"function"==typeof SuppressedError&&SuppressedError;var i=function(t,r){for(var e=[],i=0;i<4;i++)for(var o=0;o<r.length/4;o++)e[4*o+i]=t[i]*r[4*o]+t[i+4]*r[4*o+1]+t[i+8]*r[4*o+2]+t[i+12]*r[4*o+3];return e},o=function(){function t(t){void 0===t&&(t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this.name="Matrix4",this.__matrix4=t}return t.prototype.move=function(t,r,e,o){return void 0===o&&(o=0),this.__matrix4=i(function(t,r,e,i){void 0===i&&(i=0);var o=Math.sqrt(r*r+e*e+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,r*t/o,e*t/o,i*t/o,1]}(t,r,e,o),this.__matrix4),this},t.prototype.rotate=function(t,r,e,o,n,a,_){var s=function(t,r,e,i,o,n){if("number"==typeof t&&"number"==typeof r){if("number"!=typeof e?(e=0,i=t,o=r,n=1):"number"==typeof i&&"number"==typeof o&&"number"==typeof n||(i=t,o=r,n=e,t=0,r=0,e=0),t==i&&r==o&&e==n)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((i-t)*(i-t)+(o-r)*(o-r)),_=0!=a?(o-r)/a:1,s=0!=a?(i-t)/a:0,m=(i-t)*s+(o-r)*_,u=n-e,p=Math.sqrt(m*m+u*u),l=0!=p?u/p:1,c=0!=p?m/p:0;return[[_,l*s,s*c,0,-s,_*l,_*c,0,0,-c,l,0,r*s-t*_,e*c-t*s*l-r*_*l,-t*s*c-r*_*c-e*l,1],[_,-s,0,0,l*s,l*_,-c,0,s*c,_*c,l,0,t,r,e,1]]}throw new Error("a1 and b1 is required!")}(r,e,o,n,a,_);return this.__matrix4=i(i(i(s[1],function(t){var r=Math.sin(t),e=Math.cos(t);return[e,r,0,0,-r,e,0,0,0,0,1,0,0,0,0,1]}(t)),s[0]),this.__matrix4),this},t.prototype.scale=function(t,r,e,o,n,a){return void 0===o&&(o=0),void 0===n&&(n=0),void 0===a&&(a=0),this.__matrix4=i(function(t,r,e,i,o,n){return void 0===i&&(i=0),void 0===o&&(o=0),void 0===n&&(n=0),[t,0,0,0,0,r,0,0,0,0,e,0,i-i*t,o-o*r,n-n*e,1]}(t,r,e,o,n,a),this.__matrix4),this},t.prototype.multiply=function(t,r){return void 0===r&&(r=!1),this.__matrix4=r?i(this.__matrix4,t):i(t,this.__matrix4),this},t.prototype.use=function(t,r,e,o){return void 0===e&&(e=0),void 0===o&&(o=1),i(this.__matrix4,[t,r,e,o])},t.prototype.value=function(){return this.__matrix4},t}(),n=function(){function t(t,r){void 0===r&&(r=!1),this.__painter=t,this.__isElement=r,this.__buffer=function(t){return t.createBuffer()}(t),this.__type=r?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER}return t.prototype.use=function(){return this.__painter.bindBuffer(this.__type,this.__buffer),this},t.prototype.write=function(t){return function(t,r,e,i){var o=e?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(o,r,i)}(this.__painter,t,this.__isElement,this.__painter.STATIC_DRAW),this.__fsize=t.BYTES_PER_ELEMENT,this},t.prototype.divide=function(t,r,e,i){return void 0===i&&(i=0),function(t,r,e,i,o,n,a){t.vertexAttribPointer(r,e,i,a,o,n),t.enableVertexAttribArray(r)}(this.__painter,t,r,this.__painter.FLOAT,e*this.__fsize,i*this.__fsize,!1),this},t}(),a=function(){function t(t,r,e){void 0===e&&(e=0),this.__painter=t,this.__type={"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP}[r],this.__texture=function(t,r,e){var i=t.createTexture();return t.activeTexture(t["TEXTURE"+e]),t.bindTexture(r,i),i}(t,this.__type,e),t.texParameteri(this.__type,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(this.__type,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(this.__type,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(this.__type,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}return t.prototype.useImage=function(t){return function(t,r,e,i,o,n){t.texImage2D(r,e,i,i,o,n)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t),this},t.prototype.useCube=function(t,r,e){return function(t,r,e,i,o,n,a,_,s){for(var m,u=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],p=0;p<u.length;p++)n[p]&&(m=u[p],t.texImage2D(m,e,i,a,_,0,i,o,null),t.bindTexture(r,s),t.texImage2D(m,e,i,i,o,n[p]));t.generateMipmap(r)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,r,e,this.__texture),this},t}(),_={};function s(t,r,e){var i=t+"-"+e;return _[i]||(_[i]=new a(r,e)),_[i]}var m=function(t,r,e){var i=t.createShader(r);if(null==i)throw new Error("Unable to create shader!");if(t.shaderSource(i,e),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS))throw new Error("Failed to compile shader:"+t.getShaderInfoLog(i));return i},u=function(){function t(t){this.__painter=t}return t.prototype.use=function(){return this.__painter.useProgram(this.program),this},t.prototype.compile=function(t,r){return this.program=function(t,r,e){var i=m(t,t.VERTEX_SHADER,r),o=m(t,t.FRAGMENT_SHADER,e),n=t.createProgram();if(t.attachShader(n,i),t.attachShader(n,o),t.linkProgram(n),!t.getProgramParameter(n,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(n));return n}(this.__painter,t,r),this},t}(),p="attribute vec4 a_position;\nuniform mat4 u_matrix;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\n temp.z = -1.0 * temp.z;\n\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\n float dist = 4.0;\n\n // 使用投影直接计算\n // 为保证纹理和相对位置正确\n // x、y、z的改变满足线性变换\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n}",l="attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_color = a_color;\n}",c="attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec2 a_textcoord;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_textcoord = a_textcoord;\n}",h="attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_normal;\nvarying vec3 v_normal;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_normal = normalize(vec3(a_normal));\n}",g="precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}",f="precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}",v="precision mediump float;\n\nuniform sampler2D u_sampler;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n gl_FragColor = texture2D(u_sampler, v_textcoord);\n}",d="precision mediump float;\n\nvarying vec3 v_normal;\nuniform samplerCube u_texture;\n\nvoid main()\n{\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\n}",y={};function E(t,r,e,i,o){var a=function(t,r,e){var i,o,n=t+(e.material.color?"1":"0")+(e.material.colors?"1":"0")+(e.material.image?"1":"0")+(e.material.cube?"1":"0");if(y[n])return y[n].use();var a=(i={},i[t+"1000"]=p,i[t+"0100"]=l,i[t+"0010"]=c,i[t+"0001"]=h,i)[n].replace(/uniform +mat4 +u_matrix;/,"\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;").replace(/u_matrix +\* +a_position/,"u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position"),_=(o={},o[t+"1000"]=g,o[t+"0100"]=f,o[t+"0010"]=v,o[t+"0001"]=d,o)[n],s=new u(r).compile(a,_).use();return y[n]=s,s}(t,r,e);if(new n(r).use().write(e.geometry.attributes.position.array).divide(r.getAttribLocation(a.program,"a_position"),e.geometry.attributes.position.itemSize,e.geometry.attributes.position.itemSize,0),r.uniformMatrix4fv(r.getUniformLocation(a.program,"u_matrix_world"),!1,o.matrix),r.uniformMatrix4fv(r.getUniformLocation(a.program,"u_matrix_proporion"),!1,o.proporion),r.uniformMatrix4fv(r.getUniformLocation(a.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new n(r).use().write(e.geometry.attributes.normal.array).divide(r.getAttribLocation(a.program,"a_normal"),e.geometry.attributes.normal.itemSize,e.geometry.attributes.normal.itemSize,0),"color"in e.material&&r.uniform4f(r.getUniformLocation(a.program,"u_color"),e.material.color.r,e.material.color.g,e.material.color.b,e.material.color.alpha),"colors"in e.material)new n(r).use().write(e.material.colors.array).divide(r.getAttribLocation(a.program,"a_color"),e.material.colors.itemSize,e.material.colors.itemSize,0);else if("cube"in e.material){var _=e.material.cube.right.image.value.width;r.uniform1i(r.getUniformLocation(a.program,"u_texture"),0),s(t,r,"cube").useCube([e.material.cube.right.image.value,e.material.cube.left.image.value,e.material.cube.top.image.value,e.material.cube.bottom.image.value,e.material.cube.far.image.value,e.material.cube.near.image.value],_,_)}else"image"in e.material&&(r.uniform1i(r.getUniformLocation(a.program,"u_sampler"),0),new n(r).use().write(e.geometry.attributes.uv.array).divide(r.getAttribLocation(a.program,"a_textcoord"),e.geometry.attributes.uv.itemSize,2,0),s(t,r,"2d").useImage(e.material.image.value));e.geometry.index?(new n(r,!0).use().write(e.geometry.index.array),r.drawElements(r[e.geometry.type],e.geometry.index.count,r.UNSIGNED_BYTE,0)):r.drawArrays(r[e.geometry.type],0,e.geometry.attributes.position.count)}var x=!1,b=function(){function i(t,e){this.name="WebGL",this.__getColor=function(t,r){return"rgba(0,0,0,1)"},this.__regionList={},this.__regionAssemble=function(t,r,e,i){for(var o=[],n=0;n<i;n++)o[n]=t;return function(){for(var n=0;n<i;n++){if(o[n]+e<r){o[n]=+(o[n]+e).toFixed(7);break}n<i-1&&(o[n]=t)}return o}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new o([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,10])},this.__unique=(new Date).valueOf(),this.painter=r(t,10),e&&(this.__regionPainter=r(e,10,{}));var i=this.painter.canvas.width/this.painter.canvas.height,n=1,a=1;i>1?n=1/i:a=i;var _=Math.min(n,a);this.__proporion=[n,0,0,0,0,a,0,0,0,0,_,0,0,0,0,1]}return i.prototype.matrix=function(t){return new o(t)},i.prototype.getMatrix=function(){return this.__scene.matrix},i.prototype.getObject3D=function(){return this.__scene.children},i.prototype.review=function(t){void 0===t&&(t=!1),t?this.__regionPainter&&(this.__regionPainter.clearColor(1,1,1,1),this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT)):(this.painter.clearColor(1,1,1,1),this.painter.clear(this.painter.COLOR_BUFFER_BIT));for(var r=0;r<this.__scene.children.length;r++)this.draw(this.__scene.children[r],t);return this},i.prototype.draw=function(t,r){void 0===r&&(r=!1),r||(x=!0);var i={matrix:t.matrix.value()},o={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var n=0;n<t.mesh.length;n++)r?this.__regionPainter&&(E("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[n].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},i,o),this.__getColor=e(this.__regionPainter)):E("region"+this.__unique,this.painter,t.mesh[n],i,o)},i.prototype.render=function(t){"matrix"in t||(t.matrix=new o),"region"in t||(t.region="");for(var r=0;r<t.mesh.length;r++){var e=t.mesh[r];e.geometry.attributes.normal&&Array.isArray(e.geometry.attributes.normal.array)&&(e.geometry.attributes.normal.array=new Float32Array(e.geometry.attributes.normal.array)),e.geometry.attributes.position&&Array.isArray(e.geometry.attributes.position.array)&&(e.geometry.attributes.position.array=new Float32Array(e.geometry.attributes.position.array)),e.geometry.attributes.uv&&Array.isArray(e.geometry.attributes.uv.array)&&(e.geometry.attributes.uv.array=new Float32Array(e.geometry.attributes.uv.array)),e.geometry.index&&Array.isArray(e.geometry.index.array)&&(e.geometry.index.array=new Uint8Array(e.geometry.index.array)),e.material.colors&&Array.isArray(e.material.colors.array)&&(e.material.colors.array=new Float32Array(e.material.colors.array))}this.__scene.children.push(t),this.draw(t)},i.prototype.setRegion=function(r){return this.__regionName=r+"",r?(null==this.__regionList[r]&&(this.__regionList[r]=t(t([],this.__regionAssemble(),!0),[1],!1)),this.__regionColor=this.__regionList[r]):this.__regionColor=[0,0,0,1],this},i.prototype.getRegion=function(t,r){var e=this;return x&&this.review(!0),x=!1,new Promise((function(i,o){var n=e.__getColor(t,r);for(var a in e.__regionList){var _=e.__regionList[a];if("rgba("+255*_[0]+","+255*_[1]+","+255*_[2]+","+255*_[3]+")"==n){i(a);break}}i("")}))},i}();export{b as default};