vislite 0.5.2-alpha.1 → 0.5.2

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 (191) hide show
  1. package/.editorconfig +18 -18
  2. package/AUTHORS.txt +6 -6
  3. package/CHANGELOG +143 -137
  4. package/LICENSE +20 -20
  5. package/README.md +69 -69
  6. package/lib/Buffer/index.umd.js +36 -36
  7. package/lib/Buffer/index.umd.min.js +2 -2
  8. package/lib/Canvas/index.umd.js +650 -650
  9. package/lib/Canvas/index.umd.min.js +2 -2
  10. package/lib/Cardinal/index.umd.js +91 -91
  11. package/lib/Cardinal/index.umd.min.js +2 -2
  12. package/lib/Eoap/index.umd.js +34 -34
  13. package/lib/Eoap/index.umd.min.js +2 -2
  14. package/lib/Geometry/index.umd.js +142 -142
  15. package/lib/Geometry/index.umd.min.js +2 -2
  16. package/lib/Hermite/index.umd.js +36 -36
  17. package/lib/Hermite/index.umd.min.js +2 -2
  18. package/lib/Matrix4/index.umd.js +119 -119
  19. package/lib/Matrix4/index.umd.min.js +2 -2
  20. package/lib/Mercator/index.umd.js +20 -20
  21. package/lib/Mercator/index.umd.min.js +2 -2
  22. package/lib/OralCanvas/index.es.js +598 -598
  23. package/lib/OralCanvas/index.es.min.js +2 -2
  24. package/lib/OralWebGL/index.es.js +532 -532
  25. package/lib/OralWebGL/index.es.min.js +3 -3
  26. package/lib/SVG/index.umd.js +470 -405
  27. package/lib/SVG/index.umd.min.js +3 -3
  28. package/lib/Shader/index.umd.js +69 -69
  29. package/lib/Shader/index.umd.min.js +3 -3
  30. package/lib/Texture/index.umd.js +53 -53
  31. package/lib/Texture/index.umd.min.js +2 -2
  32. package/lib/TreeLayout/index.umd.js +363 -363
  33. package/lib/TreeLayout/index.umd.min.js +2 -2
  34. package/lib/WebGL/index.umd.js +579 -579
  35. package/lib/WebGL/index.umd.min.js +3 -3
  36. package/lib/animation/index.umd.js +72 -72
  37. package/lib/animation/index.umd.min.js +2 -2
  38. package/lib/formatColor/index.umd.js +40 -40
  39. package/lib/formatColor/index.umd.min.js +2 -2
  40. package/lib/getLoopColors/index.umd.js +36 -36
  41. package/lib/getLoopColors/index.umd.min.js +2 -2
  42. package/lib/getWebGLContext/index.umd.js +44 -44
  43. package/lib/getWebGLContext/index.umd.min.js +2 -2
  44. package/lib/index.umd.js +2744 -2662
  45. package/lib/index.umd.min.js +3 -3
  46. package/lib/move/index.umd.js +27 -0
  47. package/lib/move/index.umd.min.js +11 -0
  48. package/lib/resizeObserver/index.umd.js +29 -29
  49. package/lib/resizeObserver/index.umd.min.js +2 -2
  50. package/lib/rotate/index.umd.js +8 -8
  51. package/lib/rotate/index.umd.min.js +2 -2
  52. package/lib/ruler/index.umd.js +126 -126
  53. package/lib/ruler/index.umd.min.js +2 -2
  54. package/lib/scale/index.umd.js +26 -0
  55. package/lib/scale/index.umd.min.js +11 -0
  56. package/lib/throttle/index.umd.js +49 -49
  57. package/lib/throttle/index.umd.min.js +2 -2
  58. package/lib/viewHandler/index.umd.js +120 -120
  59. package/lib/viewHandler/index.umd.min.js +2 -2
  60. package/miniprogram/ui-canvas/index.js +107 -107
  61. package/miniprogram/ui-canvas/index.json +4 -4
  62. package/miniprogram/ui-canvas/index.wxml +4 -4
  63. package/miniprogram/ui-canvas/index.wxss +5 -5
  64. package/package/Buffer/index.ts +2 -2
  65. package/package/Canvas/index.ts +2 -2
  66. package/package/Cardinal/index.ts +2 -2
  67. package/package/Eoap/index.ts +2 -2
  68. package/package/Geometry/index.ts +2 -2
  69. package/package/Hermite/index.ts +2 -2
  70. package/package/Matrix4/index.ts +2 -2
  71. package/package/Mercator/index.ts +2 -2
  72. package/package/OralCanvas/index.ts +2 -2
  73. package/package/OralWebGL/index.ts +2 -2
  74. package/package/SVG/index.ts +2 -2
  75. package/package/Shader/index.ts +39 -39
  76. package/package/Texture/index.ts +2 -2
  77. package/package/TreeLayout/index.ts +2 -2
  78. package/package/WebGL/index.ts +2 -2
  79. package/package/animation/index.ts +2 -2
  80. package/package/formatColor/index.ts +2 -2
  81. package/package/getLoopColors/index.ts +2 -2
  82. package/package/getWebGLContext/index.ts +39 -39
  83. package/package/index.ts +76 -72
  84. package/package/move/index.ts +3 -0
  85. package/package/resizeObserver/index.ts +2 -2
  86. package/package/rotate/index.ts +2 -2
  87. package/package/ruler/index.ts +2 -2
  88. package/package/scale/index.ts +3 -0
  89. package/package/throttle/index.ts +2 -2
  90. package/package/viewHandler/index.ts +2 -2
  91. package/package.json +66 -66
  92. package/src/Canvas.ts +67 -67
  93. package/src/Eoap.ts +66 -66
  94. package/src/Geometry.ts +82 -82
  95. package/src/Matrix4/index.ts +76 -76
  96. package/src/Matrix4/move.ts +12 -12
  97. package/src/Matrix4/rotate.ts +15 -15
  98. package/src/Matrix4/scale.ts +11 -11
  99. package/src/Matrix4/transform.ts +64 -64
  100. package/src/Mercator.ts +27 -27
  101. package/src/SVG.ts +24 -24
  102. package/src/TreeLayout/index.ts +186 -186
  103. package/src/WebGL.ts +66 -66
  104. package/src/animation.ts +98 -98
  105. package/src/common/assemble.ts +22 -22
  106. package/src/common/canvas/arc.ts +50 -50
  107. package/src/common/canvas/config.ts +158 -158
  108. package/src/common/canvas/gradient.ts +29 -29
  109. package/src/common/canvas/index.ts +168 -168
  110. package/src/common/canvas/painter.ts +426 -426
  111. package/src/common/canvas/texts.ts +18 -18
  112. package/src/common/geometry/prism-horizontal.ts +33 -33
  113. package/src/common/geometry/prism-vertical.ts +40 -40
  114. package/src/common/geometry/sphere-fragment.ts +39 -39
  115. package/src/common/geometry/tool/circle.ts +11 -11
  116. package/src/common/mergeOption.ts +6 -6
  117. package/src/common/setStyle.ts +5 -5
  118. package/src/common/svg/config.ts +186 -174
  119. package/src/common/svg/gradient.ts +63 -0
  120. package/src/common/svg/index.ts +356 -344
  121. package/src/common/svg/tool.ts +44 -44
  122. package/src/common/tree/index.ts +25 -25
  123. package/src/common/tree/toInnerTree.ts +56 -56
  124. package/src/common/tree/toPlainTree.ts +131 -131
  125. package/src/common/webgl/buffer.ts +79 -79
  126. package/src/common/webgl/doDraw.ts +108 -108
  127. package/src/common/webgl/getColorFactory.ts +26 -26
  128. package/src/common/webgl/getShader.ts +48 -48
  129. package/src/common/webgl/getTexture.ts +11 -11
  130. package/src/common/webgl/getWebGLContext.ts +27 -27
  131. package/src/common/webgl/index.ts +223 -223
  132. package/src/common/webgl/shader.ts +75 -75
  133. package/src/common/webgl/texture.ts +96 -96
  134. package/src/formatColor.ts +44 -44
  135. package/src/getLoopColors.ts +42 -42
  136. package/src/interpolation/Cardinal.ts +110 -110
  137. package/src/interpolation/Hermite.ts +65 -65
  138. package/src/move.ts +8 -0
  139. package/src/resizeObserver.ts +36 -36
  140. package/src/rotate.ts +7 -7
  141. package/src/ruler.ts +188 -188
  142. package/src/scale.ts +7 -0
  143. package/src/shader/fsColor.c +7 -7
  144. package/src/shader/fsColors.c +7 -7
  145. package/src/shader/fsCube.c +8 -8
  146. package/src/shader/fsImage.c +8 -8
  147. package/src/shader/vsColor.c +17 -17
  148. package/src/shader/vsColors.c +13 -13
  149. package/src/shader/vsCube.c +13 -13
  150. package/src/shader/vsImage.c +13 -13
  151. package/src/throttle.ts +51 -51
  152. package/src/viewHandler.ts +158 -158
  153. package/types/Buffer.d.ts +23 -23
  154. package/types/Canvas.d.ts +300 -300
  155. package/types/CanvasConfig.d.ts +106 -106
  156. package/types/CanvasOption.d.ts +7 -7
  157. package/types/Cardinal.d.ts +13 -13
  158. package/types/Geometry.d.ts +40 -40
  159. package/types/GeometryOption.d.ts +11 -11
  160. package/types/GeometryResult.d.ts +18 -18
  161. package/types/Gradient.d.ts +14 -14
  162. package/types/Hermite.d.ts +18 -18
  163. package/types/Map.d.ts +9 -9
  164. package/types/Matrix4.d.ts +42 -42
  165. package/types/Object3D.d.ts +114 -114
  166. package/types/SVG.d.ts +238 -215
  167. package/types/SVGConfig.d.ts +76 -76
  168. package/types/Scene3D.d.ts +6 -6
  169. package/types/Shader.d.ts +21 -21
  170. package/types/Texture.d.ts +16 -16
  171. package/types/Tree.d.ts +69 -69
  172. package/types/TreeConfig.d.ts +24 -24
  173. package/types/TreeLayout.d.ts +54 -54
  174. package/types/TreeOption.d.ts +48 -48
  175. package/types/WebGL.d.ts +38 -38
  176. package/types/WebGLOption.d.ts +7 -7
  177. package/types/animation.d.ts +6 -6
  178. package/types/formatColor.d.ts +2 -2
  179. package/types/getLoopColors.d.ts +2 -2
  180. package/types/getWebGLContext.d.ts +2 -2
  181. package/types/index.d.ts +175 -169
  182. package/types/move.d.ts +3 -0
  183. package/types/painterConfig.d.ts +2 -2
  184. package/types/resizeObserver.d.ts +2 -2
  185. package/types/rotate.d.ts +2 -2
  186. package/types/ruler.d.ts +7 -7
  187. package/types/scale.d.ts +3 -0
  188. package/types/throttle.d.ts +4 -4
  189. package/types/throttleOption.d.ts +21 -21
  190. package/types/viewHandler.d.ts +13 -13
  191. package/uni-app/ui-canvas.vue +226 -226
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.5.2-alpha.1
2
+ * VISLite JavaScript Library v0.5.2
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: Thu Oct 12 2023 15:44:35 GMT+0800 (China Standard Time)
9
+ * Publish Date: Sat Nov 04 2023 09:25:44 GMT+0800 (中国标准时间)
10
10
  */
11
11
  /******************************************************************************
12
12
  Copyright (c) Microsoft Corporation.
@@ -40,572 +40,572 @@ 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
- 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}";
340
+ var vsColor = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n\r\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\r\n temp.z = -1.0 * temp.z;\r\n\r\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\r\n float dist = 4.0;\r\n\r\n // 使用投影直接计算\r\n // 为保证纹理和相对位置正确\r\n // x、y、z的改变满足线性变换\r\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));\r\n}";
341
341
 
342
- var vsColors = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_color = a_color;\n}";
342
+ var vsColors = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec4 a_color;\r\nvarying vec4 v_color;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\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));\r\n\r\n v_color = a_color;\r\n}";
343
343
 
344
- var vsImage = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec2 a_textcoord;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_textcoord = a_textcoord;\n}";
344
+ var vsImage = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec2 a_textcoord;\r\nvarying vec2 v_textcoord;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\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));\r\n\r\n v_textcoord = a_textcoord;\r\n}";
345
345
 
346
- var vsCube = "attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_normal;\nvarying vec3 v_normal;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_normal = normalize(vec3(a_normal));\n}";
346
+ var vsCube = "attribute vec4 a_position;\r\nuniform mat4 u_matrix;\r\nattribute vec4 a_normal;\r\nvarying vec3 v_normal;\r\n\r\nvoid main()\r\n{\r\n vec4 temp = u_matrix * a_position;\r\n temp.z = -1.0 * temp.z;\r\n float dist = 4.0;\r\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));\r\n\r\n v_normal = normalize(vec3(a_normal));\r\n}";
347
347
 
348
- var fsColor = "precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}";
348
+ var fsColor = "precision mediump float;\r\n\r\nuniform vec4 u_color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = u_color;\r\n}";
349
349
 
350
- var fsColors = "precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}";
350
+ var fsColors = "precision mediump float;\r\n\r\nvarying vec4 v_color;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = v_color;\r\n}";
351
351
 
352
- var fsImage = "precision mediump float;\n\nuniform sampler2D u_sampler;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n gl_FragColor = texture2D(u_sampler, v_textcoord);\n}";
352
+ var fsImage = "precision mediump float;\r\n\r\nuniform sampler2D u_sampler;\r\nvarying vec2 v_textcoord;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = texture2D(u_sampler, v_textcoord);\r\n}";
353
353
 
354
- var fsCube = "precision mediump float;\n\nvarying vec3 v_normal;\nuniform samplerCube u_texture;\n\nvoid main()\n{\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\n}";
354
+ var fsCube = "precision mediump float;\r\n\r\nvarying vec3 v_normal;\r\nuniform samplerCube u_texture;\r\n\r\nvoid main()\r\n{\r\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\r\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 };