vislite 0.5.0 → 0.5.2-alpha.1

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 (76) hide show
  1. package/CHANGELOG +137 -132
  2. package/lib/Buffer/index.umd.js +36 -36
  3. package/lib/Buffer/index.umd.min.js +2 -2
  4. package/lib/Canvas/index.umd.js +650 -650
  5. package/lib/Canvas/index.umd.min.js +2 -2
  6. package/lib/Cardinal/index.umd.js +91 -91
  7. package/lib/Cardinal/index.umd.min.js +2 -2
  8. package/lib/Eoap/index.umd.js +34 -34
  9. package/lib/Eoap/index.umd.min.js +2 -2
  10. package/lib/Geometry/index.umd.js +142 -142
  11. package/lib/Geometry/index.umd.min.js +2 -2
  12. package/lib/Hermite/index.umd.js +36 -36
  13. package/lib/Hermite/index.umd.min.js +2 -2
  14. package/lib/Matrix4/index.umd.js +119 -119
  15. package/lib/Matrix4/index.umd.min.js +2 -2
  16. package/lib/Mercator/index.umd.js +20 -20
  17. package/lib/Mercator/index.umd.min.js +2 -2
  18. package/lib/OralCanvas/index.es.js +598 -598
  19. package/lib/OralCanvas/index.es.min.js +2 -2
  20. package/lib/OralWebGL/index.es.js +524 -524
  21. package/lib/OralWebGL/index.es.min.js +2 -2
  22. package/lib/SVG/index.umd.js +406 -406
  23. package/lib/SVG/index.umd.min.js +2 -2
  24. package/lib/Shader/index.umd.js +61 -61
  25. package/lib/Shader/index.umd.min.js +2 -2
  26. package/lib/Texture/index.umd.js +53 -53
  27. package/lib/Texture/index.umd.min.js +2 -2
  28. package/lib/TreeLayout/index.umd.js +363 -363
  29. package/lib/TreeLayout/index.umd.min.js +2 -2
  30. package/lib/WebGL/index.umd.js +571 -571
  31. package/lib/WebGL/index.umd.min.js +2 -2
  32. package/lib/animation/index.umd.js +72 -72
  33. package/lib/animation/index.umd.min.js +2 -2
  34. package/lib/formatColor/index.umd.js +40 -40
  35. package/lib/formatColor/index.umd.min.js +2 -2
  36. package/lib/getLoopColors/index.umd.js +36 -36
  37. package/lib/getLoopColors/index.umd.min.js +2 -2
  38. package/lib/getWebGLContext/index.umd.js +44 -44
  39. package/lib/getWebGLContext/index.umd.min.js +2 -2
  40. package/lib/index.umd.js +2647 -2647
  41. package/lib/index.umd.min.js +2 -2
  42. package/lib/resizeObserver/index.umd.js +29 -29
  43. package/lib/resizeObserver/index.umd.min.js +2 -2
  44. package/lib/rotate/index.umd.js +8 -8
  45. package/lib/rotate/index.umd.min.js +2 -2
  46. package/lib/ruler/index.umd.js +126 -126
  47. package/lib/ruler/index.umd.min.js +2 -2
  48. package/lib/throttle/index.umd.js +49 -49
  49. package/lib/throttle/index.umd.min.js +2 -2
  50. package/lib/viewHandler/index.umd.js +120 -120
  51. package/lib/viewHandler/index.umd.min.js +2 -2
  52. package/package/Geometry/index.ts +2 -2
  53. package/package/index.ts +72 -72
  54. package/package.json +66 -66
  55. package/src/Eoap.ts +66 -66
  56. package/src/Geometry.ts +82 -82
  57. package/src/Matrix4/index.ts +76 -76
  58. package/src/Mercator.ts +27 -27
  59. package/src/TreeLayout/index.ts +186 -186
  60. package/src/common/geometry/prism-horizontal.ts +33 -33
  61. package/src/common/geometry/prism-vertical.ts +40 -40
  62. package/src/common/geometry/sphere-fragment.ts +39 -39
  63. package/src/common/geometry/tool/circle.ts +11 -11
  64. package/src/common/svg/index.ts +344 -344
  65. package/src/rotate.ts +7 -7
  66. package/types/CanvasConfig.d.ts +106 -106
  67. package/types/Geometry.d.ts +40 -40
  68. package/types/GeometryOption.d.ts +11 -11
  69. package/types/GeometryResult.d.ts +18 -18
  70. package/types/Map.d.ts +9 -9
  71. package/types/Matrix4.d.ts +42 -42
  72. package/types/SVG.d.ts +215 -215
  73. package/types/TreeLayout.d.ts +54 -54
  74. package/types/index.d.ts +169 -169
  75. package/types/rotate.d.ts +2 -2
  76. package/uni-app/ui-canvas.vue +206 -202
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.5.0
2
+ * VISLite JavaScript Library v0.5.2-alpha.1
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 Sep 30 2023 19:14:04 GMT+0800 (中国标准时间)
9
+ * Publish Date: Thu Oct 12 2023 15:44:35 GMT+0800 (China Standard Time)
10
10
  */
11
11
  /******************************************************************************
12
12
  Copyright (c) Microsoft Corporation.
@@ -40,301 +40,301 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
40
40
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
41
41
  };
42
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;
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
63
  }
64
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
- };
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
77
  }
78
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
- ];
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
88
  }
89
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
- ];
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
98
  }
99
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
- ];
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
110
  }
111
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
- }
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
149
  }
150
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;
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
204
  }());
205
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;
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
240
  }());
241
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;
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
293
  }());
294
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];
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
302
  }
303
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;
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
338
  }());
339
339
 
340
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}";
@@ -353,259 +353,259 @@ var fsImage = "precision mediump float;\n\nuniform sampler2D u_sampler;\nvarying
353
353
 
354
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
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;
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
381
  }
382
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
- }
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
431
  }
432
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
- };
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
449
  }
450
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;
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
609
  }());
610
610
 
611
611
  export { WebGL as default };