vislite 0.1.0 → 0.2.0-alpha.7

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