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