vislite 0.8.1-alpha.1 → 0.8.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 (196) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +220 -214
  3. package/LICENSE +20 -20
  4. package/README.md +136 -136
  5. package/lib/Buffer/index.umd.js +36 -36
  6. package/lib/Buffer/index.umd.min.js +2 -2
  7. package/lib/Canvas/index.umd.js +694 -691
  8. package/lib/Canvas/index.umd.min.js +3 -3
  9. package/lib/Cardinal/index.umd.js +91 -91
  10. package/lib/Cardinal/index.umd.min.js +2 -2
  11. package/lib/Eoap/index.umd.js +34 -34
  12. package/lib/Eoap/index.umd.min.js +2 -2
  13. package/lib/Geometry/index.umd.js +286 -286
  14. package/lib/Geometry/index.umd.min.js +2 -2
  15. package/lib/Hermite/index.umd.js +36 -36
  16. package/lib/Hermite/index.umd.min.js +2 -2
  17. package/lib/Matrix4/index.umd.js +125 -125
  18. package/lib/Matrix4/index.umd.min.js +2 -2
  19. package/lib/Mercator/index.umd.js +20 -20
  20. package/lib/Mercator/index.umd.min.js +2 -2
  21. package/lib/OralCanvas/index.es.js +637 -634
  22. package/lib/OralCanvas/index.es.min.js +3 -3
  23. package/lib/OralWebGL/index.es.js +560 -560
  24. package/lib/OralWebGL/index.es.min.js +3 -3
  25. package/lib/SVG/index.umd.js +471 -471
  26. package/lib/SVG/index.umd.min.js +2 -2
  27. package/lib/Shader/index.umd.js +69 -69
  28. package/lib/Shader/index.umd.min.js +3 -3
  29. package/lib/Texture/index.umd.js +54 -54
  30. package/lib/Texture/index.umd.min.js +2 -2
  31. package/lib/TreeLayout/index.umd.js +368 -368
  32. package/lib/TreeLayout/index.umd.min.js +2 -2
  33. package/lib/WebGL/index.umd.js +607 -607
  34. package/lib/WebGL/index.umd.min.js +3 -3
  35. package/lib/animation/index.umd.js +73 -73
  36. package/lib/animation/index.umd.min.js +2 -2
  37. package/lib/formatColor/index.umd.js +40 -40
  38. package/lib/formatColor/index.umd.min.js +2 -2
  39. package/lib/getLoopColors/index.umd.js +36 -36
  40. package/lib/getLoopColors/index.umd.min.js +2 -2
  41. package/lib/getWebGLContext/index.umd.js +63 -63
  42. package/lib/getWebGLContext/index.umd.min.js +2 -2
  43. package/lib/index.umd.js +2974 -2971
  44. package/lib/index.umd.min.js +3 -3
  45. package/lib/move/index.umd.js +8 -8
  46. package/lib/move/index.umd.min.js +2 -2
  47. package/lib/resizeObserver/index.umd.js +30 -30
  48. package/lib/resizeObserver/index.umd.min.js +2 -2
  49. package/lib/rotate/index.umd.js +8 -8
  50. package/lib/rotate/index.umd.min.js +2 -2
  51. package/lib/ruler/index.umd.js +138 -138
  52. package/lib/ruler/index.umd.min.js +2 -2
  53. package/lib/scale/index.umd.js +7 -7
  54. package/lib/scale/index.umd.min.js +2 -2
  55. package/lib/throttle/index.umd.js +49 -49
  56. package/lib/throttle/index.umd.min.js +2 -2
  57. package/lib/viewHandler/index.umd.js +120 -120
  58. package/lib/viewHandler/index.umd.min.js +2 -2
  59. package/miniprogram/ui-canvas/drawImage.js +6 -4
  60. package/miniprogram/ui-canvas/index.js +122 -122
  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 +40 -40
  83. package/package/index.ts +76 -76
  84. package/package/move/index.ts +2 -2
  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 +2 -2
  89. package/package/throttle/index.ts +2 -2
  90. package/package/viewHandler/index.ts +2 -2
  91. package/package.json +70 -70
  92. package/src/Canvas.ts +72 -72
  93. package/src/Eoap.ts +66 -66
  94. package/src/Geometry.ts +210 -210
  95. package/src/Matrix4/index.ts +84 -84
  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/WebGL.ts +66 -66
  103. package/src/animation.ts +98 -98
  104. package/src/common/assemble.ts +22 -22
  105. package/src/common/canvas/arc.ts +51 -51
  106. package/src/common/canvas/config.ts +158 -158
  107. package/src/common/canvas/gradient.ts +29 -29
  108. package/src/common/canvas/index.ts +183 -183
  109. package/src/common/canvas/painter.ts +453 -446
  110. package/src/common/canvas/texts.ts +18 -18
  111. package/src/common/geometry/prism-horizontal.ts +50 -50
  112. package/src/common/geometry/prism-vertical.ts +55 -55
  113. package/src/common/geometry/sphere-fragment.ts +40 -40
  114. package/src/common/geometry/tool/circle.ts +17 -17
  115. package/src/common/geometry/tool/rotateLine.ts +48 -48
  116. package/src/common/geometry/tool/triangles.ts +23 -23
  117. package/src/common/mergeOption.ts +6 -6
  118. package/src/common/setStyle.ts +5 -5
  119. package/src/common/svg/config.ts +190 -190
  120. package/src/common/svg/gradient.ts +63 -63
  121. package/src/common/svg/index.ts +356 -356
  122. package/src/common/svg/tool.ts +44 -44
  123. package/src/common/tree/index.ts +25 -25
  124. package/src/common/tree/toInnerTree.ts +59 -59
  125. package/src/common/tree/toPlainTree.ts +132 -132
  126. package/src/common/webgl/buffer.ts +79 -79
  127. package/src/common/webgl/doDraw.ts +108 -108
  128. package/src/common/webgl/getColorFactory.ts +26 -26
  129. package/src/common/webgl/getShader.ts +48 -48
  130. package/src/common/webgl/getTexture.ts +11 -11
  131. package/src/common/webgl/getWebGLContext.ts +45 -45
  132. package/src/common/webgl/index.ts +227 -227
  133. package/src/common/webgl/shader.ts +75 -75
  134. package/src/common/webgl/texture.ts +97 -97
  135. package/src/formatColor.ts +44 -44
  136. package/src/getLoopColors.ts +42 -42
  137. package/src/interpolation/Cardinal.ts +110 -110
  138. package/src/interpolation/Hermite.ts +65 -65
  139. package/src/layout/TreeLayout.ts +188 -188
  140. package/src/move.ts +7 -7
  141. package/src/resizeObserver.ts +37 -37
  142. package/src/rotate.ts +7 -7
  143. package/src/ruler.ts +209 -209
  144. package/src/scale.ts +6 -6
  145. package/src/shader/fsColor.c +7 -7
  146. package/src/shader/fsColors.c +7 -7
  147. package/src/shader/fsCube.c +8 -8
  148. package/src/shader/fsImage.c +8 -8
  149. package/src/shader/vsColor.c +17 -17
  150. package/src/shader/vsColors.c +13 -13
  151. package/src/shader/vsCube.c +13 -13
  152. package/src/shader/vsImage.c +13 -13
  153. package/src/throttle.ts +52 -52
  154. package/src/viewHandler.ts +160 -160
  155. package/types/Buffer.d.ts +23 -23
  156. package/types/Canvas.d.ts +318 -318
  157. package/types/CanvasConfig.d.ts +106 -106
  158. package/types/CanvasOption.d.ts +8 -8
  159. package/types/CanvasOpts.d.ts +9 -9
  160. package/types/Cardinal.d.ts +13 -13
  161. package/types/Geometry.d.ts +132 -132
  162. package/types/GeometryOption.d.ts +11 -11
  163. package/types/GeometryResult.d.ts +18 -18
  164. package/types/Gradient.d.ts +14 -14
  165. package/types/Hermite.d.ts +18 -18
  166. package/types/Map.d.ts +9 -9
  167. package/types/Matrix4.d.ts +47 -47
  168. package/types/Object3D.d.ts +114 -114
  169. package/types/SVG.d.ts +238 -238
  170. package/types/SVGConfig.d.ts +79 -79
  171. package/types/Scene3D.d.ts +6 -6
  172. package/types/Shader.d.ts +23 -23
  173. package/types/Texture.d.ts +16 -16
  174. package/types/Tree.d.ts +69 -69
  175. package/types/TreeConfig.d.ts +36 -36
  176. package/types/TreeLayout.d.ts +54 -54
  177. package/types/TreeOption.d.ts +48 -48
  178. package/types/WebGL.d.ts +38 -38
  179. package/types/WebGLOption.d.ts +14 -14
  180. package/types/animation.d.ts +6 -6
  181. package/types/formatColor.d.ts +2 -2
  182. package/types/getLoopColors.d.ts +2 -2
  183. package/types/getWebGLContext.d.ts +4 -4
  184. package/types/index.d.ts +175 -175
  185. package/types/move.d.ts +2 -2
  186. package/types/painterConfig.d.ts +2 -2
  187. package/types/resizeObserver.d.ts +2 -2
  188. package/types/rotate.d.ts +2 -2
  189. package/types/ruler.d.ts +7 -7
  190. package/types/scale.d.ts +2 -2
  191. package/types/throttle.d.ts +4 -4
  192. package/types/throttleOption.d.ts +21 -21
  193. package/types/ui-canvas.d.ts +4 -4
  194. package/types/viewHandler.d.ts +13 -13
  195. package/uni-app/drawImage.js +19 -17
  196. package/uni-app/ui-canvas.vue +290 -290
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.8.1-alpha.1
2
+ * VISLite JavaScript Library v0.8.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: Wed Apr 03 2024 10:29:52 GMT+0800 (China Standard Time)
9
+ * Publish Date: Wed Apr 10 2024 20:35:52 GMT+0800 (中国标准时间)
10
10
  */
11
11
  /******************************************************************************
12
12
  Copyright (c) Microsoft Corporation.
@@ -40,600 +40,600 @@ 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, mode) {
44
- if (opts === void 0) { opts = {}; }
45
- if (mode === void 0) { mode = "scaleToFill"; }
46
- var names = ["experimental-webgl", "webkit-3d", "moz-webgl"];
47
- var painter = canvas.getContext("webgl", opts);
48
- for (var i = 0; i < names.length; i++) {
49
- try {
50
- painter = canvas.getContext(names[i], opts);
51
- }
52
- catch (e) { }
53
- if (painter)
54
- break;
55
- }
56
- if (!painter)
57
- throw new Error('Non canvas or browser does not support webgl.');
58
- var width = painter.canvas.width, height = painter.canvas.height;
59
- var scaleX = scale, scaleY = scale;
60
- if (mode == "aspectFit") {
61
- if (width > height) {
62
- scaleX *= height / width;
63
- }
64
- else if (height > width) {
65
- scaleY *= width / height;
66
- }
67
- }
68
- else if (mode == "aspectFill") {
69
- if (width > height) {
70
- scaleY *= width / height;
71
- }
72
- else if (height > width) {
73
- scaleX *= height / width;
74
- }
75
- }
76
- var viewWidth = width * scaleX;
77
- var viewHeight = height * scaleY;
78
- painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
79
- painter.depthFunc(painter.LEQUAL);
80
- painter.enable(painter.DEPTH_TEST);
81
- return painter;
43
+ function getWebGLContext (canvas, scale, opts, mode) {
44
+ if (opts === void 0) { opts = {}; }
45
+ if (mode === void 0) { mode = "scaleToFill"; }
46
+ var names = ["experimental-webgl", "webkit-3d", "moz-webgl"];
47
+ var painter = canvas.getContext("webgl", opts);
48
+ for (var i = 0; i < names.length; i++) {
49
+ try {
50
+ painter = canvas.getContext(names[i], opts);
51
+ }
52
+ catch (e) { }
53
+ if (painter)
54
+ break;
55
+ }
56
+ if (!painter)
57
+ throw new Error('Non canvas or browser does not support webgl.');
58
+ var width = painter.canvas.width, height = painter.canvas.height;
59
+ var scaleX = scale, scaleY = scale;
60
+ if (mode == "aspectFit") {
61
+ if (width > height) {
62
+ scaleX *= height / width;
63
+ }
64
+ else if (height > width) {
65
+ scaleY *= width / height;
66
+ }
67
+ }
68
+ else if (mode == "aspectFill") {
69
+ if (width > height) {
70
+ scaleY *= width / height;
71
+ }
72
+ else if (height > width) {
73
+ scaleX *= height / width;
74
+ }
75
+ }
76
+ var viewWidth = width * scaleX;
77
+ var viewHeight = height * scaleY;
78
+ painter.viewport((width - viewWidth) * 0.5, (height - viewHeight) * 0.5, viewWidth, viewHeight);
79
+ painter.depthFunc(painter.LEQUAL);
80
+ painter.enable(painter.DEPTH_TEST);
81
+ return painter;
82
82
  }
83
83
 
84
- function getColorFactory (painter) {
85
- var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
86
- var pixels = new Uint8Array(4 * width * height);
87
- painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
88
- return function (x, y) {
89
- y = height - y;
90
- var pixelR = pixels[4 * (y * width + x)];
91
- var pixelG = pixels[4 * (y * width + x) + 1];
92
- var pixelB = pixels[4 * (y * width + x) + 2];
93
- var pixelA = pixels[4 * (y * width + x) + 3];
94
- return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
95
- };
84
+ function getColorFactory (painter) {
85
+ var width = painter.drawingBufferWidth, height = painter.drawingBufferHeight;
86
+ var pixels = new Uint8Array(4 * width * height);
87
+ painter.readPixels(0, 0, width, height, painter.RGBA, painter.UNSIGNED_BYTE, pixels);
88
+ return function (x, y) {
89
+ y = height - y;
90
+ var pixelR = pixels[4 * (y * width + x)];
91
+ var pixelG = pixels[4 * (y * width + x) + 1];
92
+ var pixelB = pixels[4 * (y * width + x) + 2];
93
+ var pixelA = pixels[4 * (y * width + x) + 3];
94
+ return "rgba(" + pixelR + "," + pixelG + "," + pixelB + "," + pixelA + ")";
95
+ };
96
96
  }
97
97
 
98
- function _move (d, a, b, c) {
99
- if (c === void 0) { c = 0; }
100
- var sqrt = Math.sqrt(a * a + b * b + c * c);
101
- return [
102
- 1, 0, 0, 0,
103
- 0, 1, 0, 0,
104
- 0, 0, 1, 0,
105
- a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
106
- ];
98
+ function _move (d, a, b, c) {
99
+ if (c === void 0) { c = 0; }
100
+ var sqrt = Math.sqrt(a * a + b * b + c * c);
101
+ return [
102
+ 1, 0, 0, 0,
103
+ 0, 1, 0, 0,
104
+ 0, 0, 1, 0,
105
+ a * d / sqrt, b * d / sqrt, c * d / sqrt, 1
106
+ ];
107
107
  }
108
108
 
109
- function _rotate (deg) {
110
- var sin = Math.sin(deg), cos = Math.cos(deg);
111
- return [
112
- cos, sin, 0, 0,
113
- -sin, cos, 0, 0,
114
- 0, 0, 1, 0,
115
- 0, 0, 0, 1
116
- ];
109
+ function _rotate (deg) {
110
+ var sin = Math.sin(deg), cos = Math.cos(deg);
111
+ return [
112
+ cos, sin, 0, 0,
113
+ -sin, cos, 0, 0,
114
+ 0, 0, 1, 0,
115
+ 0, 0, 0, 1
116
+ ];
117
117
  }
118
118
 
119
- function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
120
- if (cx === void 0) { cx = 0; }
121
- if (cy === void 0) { cy = 0; }
122
- if (cz === void 0) { cz = 0; }
123
- return [
124
- xTimes, 0, 0, 0,
125
- 0, yTimes, 0, 0,
126
- 0, 0, zTimes, 0,
127
- cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
128
- ];
119
+ function _scale (xTimes, yTimes, zTimes, cx, cy, cz) {
120
+ if (cx === void 0) { cx = 0; }
121
+ if (cy === void 0) { cy = 0; }
122
+ if (cz === void 0) { cz = 0; }
123
+ return [
124
+ xTimes, 0, 0, 0,
125
+ 0, yTimes, 0, 0,
126
+ 0, 0, zTimes, 0,
127
+ cx - cx * xTimes, cy - cy * yTimes, cz - cz * zTimes, 1
128
+ ];
129
129
  }
130
130
 
131
- function _transform (a1, b1, c1, a2, b2, c2) {
132
- if (typeof a1 === 'number' && typeof b1 === 'number') {
133
- if (typeof c1 !== 'number') {
134
- c1 = 0;
135
- a2 = a1;
136
- b2 = b1;
137
- c2 = 1;
138
- }
139
- else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
140
- a2 = a1;
141
- b2 = b1;
142
- c2 = c1;
143
- a1 = 0;
144
- b1 = 0;
145
- c1 = 0;
146
- }
147
- if (a1 == a2 && b1 == b2 && c1 == c2)
148
- throw new Error('It\'s not a legitimate ray!');
149
- var sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)), cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1, sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0, b = (a2 - a1) * sin1 + (b2 - b1) * cos1, c = c2 - c1, sqrt2 = Math.sqrt(b * b + c * c), cos2 = sqrt2 != 0 ? c / sqrt2 : 1, sin2 = sqrt2 != 0 ? b / sqrt2 : 0;
150
- return [
151
- [
152
- cos1, cos2 * sin1, sin1 * sin2, 0,
153
- -sin1, cos1 * cos2, cos1 * sin2, 0,
154
- 0, -sin2, cos2, 0,
155
- b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
156
- ],
157
- [
158
- cos1, -sin1, 0, 0,
159
- cos2 * sin1, cos2 * cos1, -sin2, 0,
160
- sin1 * sin2, cos1 * sin2, cos2, 0,
161
- a1, b1, c1, 1
162
- ]
163
- ];
164
- }
165
- else {
166
- throw new Error('a1 and b1 is required!');
167
- }
131
+ function _transform (a1, b1, c1, a2, b2, c2) {
132
+ if (typeof a1 === 'number' && typeof b1 === 'number') {
133
+ if (typeof c1 !== 'number') {
134
+ c1 = 0;
135
+ a2 = a1;
136
+ b2 = b1;
137
+ c2 = 1;
138
+ }
139
+ else if (typeof a2 !== 'number' || typeof b2 !== 'number' || typeof c2 !== 'number') {
140
+ a2 = a1;
141
+ b2 = b1;
142
+ c2 = c1;
143
+ a1 = 0;
144
+ b1 = 0;
145
+ c1 = 0;
146
+ }
147
+ if (a1 == a2 && b1 == b2 && c1 == c2)
148
+ throw new Error('It\'s not a legitimate ray!');
149
+ var sqrt1 = Math.sqrt((a2 - a1) * (a2 - a1) + (b2 - b1) * (b2 - b1)), cos1 = sqrt1 != 0 ? (b2 - b1) / sqrt1 : 1, sin1 = sqrt1 != 0 ? (a2 - a1) / sqrt1 : 0, b = (a2 - a1) * sin1 + (b2 - b1) * cos1, c = c2 - c1, sqrt2 = Math.sqrt(b * b + c * c), cos2 = sqrt2 != 0 ? c / sqrt2 : 1, sin2 = sqrt2 != 0 ? b / sqrt2 : 0;
150
+ return [
151
+ [
152
+ cos1, cos2 * sin1, sin1 * sin2, 0,
153
+ -sin1, cos1 * cos2, cos1 * sin2, 0,
154
+ 0, -sin2, cos2, 0,
155
+ b1 * sin1 - a1 * cos1, c1 * sin2 - a1 * sin1 * cos2 - b1 * cos1 * cos2, -a1 * sin1 * sin2 - b1 * cos1 * sin2 - c1 * cos2, 1
156
+ ],
157
+ [
158
+ cos1, -sin1, 0, 0,
159
+ cos2 * sin1, cos2 * cos1, -sin2, 0,
160
+ sin1 * sin2, cos1 * sin2, cos2, 0,
161
+ a1, b1, c1, 1
162
+ ]
163
+ ];
164
+ }
165
+ else {
166
+ throw new Error('a1 and b1 is required!');
167
+ }
168
168
  }
169
169
 
170
- var _multiply = function (matrix4, param) {
171
- var newParam = [];
172
- for (var i = 0; i < 4; i++)
173
- for (var j = 0; j < param.length / 4; j++)
174
- newParam[j * 4 + i] =
175
- matrix4[i] * param[j * 4] +
176
- matrix4[i + 4] * param[j * 4 + 1] +
177
- matrix4[i + 8] * param[j * 4 + 2] +
178
- matrix4[i + 12] * param[j * 4 + 3];
179
- return newParam;
180
- };
181
- var __initMatrix4 = [
182
- 1, 0, 0, 0,
183
- 0, 1, 0, 0,
184
- 0, 0, 1, 0,
185
- 0, 0, 0, 1
186
- ];
187
- var Matrix4 = (function () {
188
- function Matrix4(initMatrix4) {
189
- if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
190
- this.name = 'Matrix4';
191
- this.__matrix4 = initMatrix4;
192
- }
193
- Matrix4.prototype.setValue = function (initMatrix4) {
194
- if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
195
- this.__matrix4 = initMatrix4;
196
- return this;
197
- };
198
- Matrix4.prototype.move = function (dis, a, b, c) {
199
- if (c === void 0) { c = 0; }
200
- this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4);
201
- return this;
202
- };
203
- Matrix4.prototype.rotate = function (deg, a1, b1, c1, a2, b2, c2) {
204
- var matrix4s = _transform(a1, b1, c1, a2, b2, c2);
205
- this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4);
206
- return this;
207
- };
208
- Matrix4.prototype.scale = function (xTimes, yTimes, zTimes, cx, cy, cz) {
209
- if (cx === void 0) { cx = 0; }
210
- if (cy === void 0) { cy = 0; }
211
- if (cz === void 0) { cz = 0; }
212
- this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4);
213
- return this;
214
- };
215
- Matrix4.prototype.multiply = function (newMatrix4, flag) {
216
- if (flag === void 0) { flag = false; }
217
- this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4);
218
- return this;
219
- };
220
- Matrix4.prototype.use = function (x, y, z, w) {
221
- if (z === void 0) { z = 0; }
222
- if (w === void 0) { w = 1; }
223
- return _multiply(this.__matrix4, [x, y, z, w]);
224
- };
225
- Matrix4.prototype.value = function () {
226
- return this.__matrix4;
227
- };
228
- return Matrix4;
170
+ var _multiply = function (matrix4, param) {
171
+ var newParam = [];
172
+ for (var i = 0; i < 4; i++)
173
+ for (var j = 0; j < param.length / 4; j++)
174
+ newParam[j * 4 + i] =
175
+ matrix4[i] * param[j * 4] +
176
+ matrix4[i + 4] * param[j * 4 + 1] +
177
+ matrix4[i + 8] * param[j * 4 + 2] +
178
+ matrix4[i + 12] * param[j * 4 + 3];
179
+ return newParam;
180
+ };
181
+ var __initMatrix4 = [
182
+ 1, 0, 0, 0,
183
+ 0, 1, 0, 0,
184
+ 0, 0, 1, 0,
185
+ 0, 0, 0, 1
186
+ ];
187
+ var Matrix4 = (function () {
188
+ function Matrix4(initMatrix4) {
189
+ if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
190
+ this.name = 'Matrix4';
191
+ this.__matrix4 = initMatrix4;
192
+ }
193
+ Matrix4.prototype.setValue = function (initMatrix4) {
194
+ if (initMatrix4 === void 0) { initMatrix4 = __initMatrix4; }
195
+ this.__matrix4 = initMatrix4;
196
+ return this;
197
+ };
198
+ Matrix4.prototype.move = function (dis, a, b, c) {
199
+ if (c === void 0) { c = 0; }
200
+ this.__matrix4 = _multiply(_move(dis, a, b, c), this.__matrix4);
201
+ return this;
202
+ };
203
+ Matrix4.prototype.rotate = function (deg, a1, b1, c1, a2, b2, c2) {
204
+ var matrix4s = _transform(a1, b1, c1, a2, b2, c2);
205
+ this.__matrix4 = _multiply(_multiply(_multiply(matrix4s[1], _rotate(deg)), matrix4s[0]), this.__matrix4);
206
+ return this;
207
+ };
208
+ Matrix4.prototype.scale = function (xTimes, yTimes, zTimes, cx, cy, cz) {
209
+ if (cx === void 0) { cx = 0; }
210
+ if (cy === void 0) { cy = 0; }
211
+ if (cz === void 0) { cz = 0; }
212
+ this.__matrix4 = _multiply(_scale(xTimes, yTimes, zTimes, cx, cy, cz), this.__matrix4);
213
+ return this;
214
+ };
215
+ Matrix4.prototype.multiply = function (newMatrix4, flag) {
216
+ if (flag === void 0) { flag = false; }
217
+ this.__matrix4 = flag ? _multiply(this.__matrix4, newMatrix4) : _multiply(newMatrix4, this.__matrix4);
218
+ return this;
219
+ };
220
+ Matrix4.prototype.use = function (x, y, z, w) {
221
+ if (z === void 0) { z = 0; }
222
+ if (w === void 0) { w = 1; }
223
+ return _multiply(this.__matrix4, [x, y, z, w]);
224
+ };
225
+ Matrix4.prototype.value = function () {
226
+ return this.__matrix4;
227
+ };
228
+ return Matrix4;
229
229
  }());
230
230
 
231
- var newBuffer = function (painter) {
232
- return painter.createBuffer();
233
- };
234
- var writeBuffer = function (painter, data, isElement, usage) {
235
- var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
236
- painter.bufferData(TYPE, data, usage);
237
- };
238
- var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
239
- painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
240
- painter.enableVertexAttribArray(location);
241
- };
242
- var BufferObject = (function () {
243
- function BufferObject(painter, isElement) {
244
- if (isElement === void 0) { isElement = false; }
245
- this.__painter = painter;
246
- this.__isElement = isElement;
247
- this.__buffer = newBuffer(painter);
248
- this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
249
- }
250
- BufferObject.prototype.use = function () {
251
- this.__painter.bindBuffer(this.__type, this.__buffer);
252
- return this;
253
- };
254
- BufferObject.prototype.write = function (data) {
255
- writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
256
- this.__fsize = data.BYTES_PER_ELEMENT;
257
- return this;
258
- };
259
- BufferObject.prototype.divide = function (location, size, stride, offset) {
260
- if (offset === void 0) { offset = 0; }
261
- useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
262
- return this;
263
- };
264
- return BufferObject;
231
+ var newBuffer = function (painter) {
232
+ return painter.createBuffer();
233
+ };
234
+ var writeBuffer = function (painter, data, isElement, usage) {
235
+ var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
236
+ painter.bufferData(TYPE, data, usage);
237
+ };
238
+ var useBuffer = function (painter, location, size, type, stride, offset, normalized) {
239
+ painter.vertexAttribPointer(location, size, type, normalized, stride, offset);
240
+ painter.enableVertexAttribArray(location);
241
+ };
242
+ var BufferObject = (function () {
243
+ function BufferObject(painter, isElement) {
244
+ if (isElement === void 0) { isElement = false; }
245
+ this.__painter = painter;
246
+ this.__isElement = isElement;
247
+ this.__buffer = newBuffer(painter);
248
+ this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER;
249
+ }
250
+ BufferObject.prototype.use = function () {
251
+ this.__painter.bindBuffer(this.__type, this.__buffer);
252
+ return this;
253
+ };
254
+ BufferObject.prototype.write = function (data) {
255
+ writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW);
256
+ this.__fsize = data.BYTES_PER_ELEMENT;
257
+ return this;
258
+ };
259
+ BufferObject.prototype.divide = function (location, size, stride, offset) {
260
+ if (offset === void 0) { offset = 0; }
261
+ useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false);
262
+ return this;
263
+ };
264
+ return BufferObject;
265
265
  }());
266
266
 
267
- var initTexture = function (painter, type, unit) {
268
- var texture = painter.createTexture();
269
- painter.activeTexture(painter['TEXTURE' + unit]);
270
- painter.bindTexture(type, texture);
271
- return texture;
272
- };
273
- var linkImage = function (painter, type, level, format, textureType, image) {
274
- painter.texImage2D(type, level, format, format, textureType, image);
275
- };
276
- var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
277
- var types = [
278
- painter.TEXTURE_CUBE_MAP_POSITIVE_X,
279
- painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
280
- painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
281
- painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
282
- painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
283
- painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
284
- ];
285
- var target;
286
- for (var i = 0; i < types.length; i++) {
287
- if (images[i]) {
288
- target = types[i];
289
- painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
290
- painter.bindTexture(type, texture);
291
- painter.texImage2D(target, level, format, format, textureType, images[i]);
292
- }
293
- }
294
- painter.generateMipmap(type);
295
- };
296
- var TextureObject = (function () {
297
- function TextureObject(painter, type, unit) {
298
- if (unit === void 0) { unit = 0; }
299
- this.__painter = painter;
300
- this.__type = {
301
- "2d": painter.TEXTURE_2D,
302
- "cube": painter.TEXTURE_CUBE_MAP
303
- }[type];
304
- this.__texture = initTexture(painter, this.__type, unit);
305
- painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
306
- painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
307
- painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
308
- painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
309
- }
310
- TextureObject.prototype.useImage = function (image) {
311
- linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
312
- return this;
313
- };
314
- TextureObject.prototype.useCube = function (images, width, height) {
315
- linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
316
- return this;
317
- };
318
- return TextureObject;
267
+ var initTexture = function (painter, type, unit) {
268
+ var texture = painter.createTexture();
269
+ painter.activeTexture(painter['TEXTURE' + unit]);
270
+ painter.bindTexture(type, texture);
271
+ return texture;
272
+ };
273
+ var linkImage = function (painter, type, level, format, textureType, image) {
274
+ painter.texImage2D(type, level, format, format, textureType, image);
275
+ };
276
+ var linkCube = function (painter, type, level, format, textureType, images, width, height, texture) {
277
+ var types = [
278
+ painter.TEXTURE_CUBE_MAP_POSITIVE_X,
279
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_X,
280
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Y,
281
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Y,
282
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Z,
283
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Z
284
+ ];
285
+ var target;
286
+ for (var i = 0; i < types.length; i++) {
287
+ if (images[i]) {
288
+ target = types[i];
289
+ painter.texImage2D(target, level, format, width, height, 0, format, textureType, null);
290
+ painter.bindTexture(type, texture);
291
+ painter.texImage2D(target, level, format, format, textureType, images[i]);
292
+ }
293
+ }
294
+ painter.generateMipmap(type);
295
+ };
296
+ var TextureObject = (function () {
297
+ function TextureObject(painter, type, unit) {
298
+ if (unit === void 0) { unit = 0; }
299
+ this.__painter = painter;
300
+ this.__type = {
301
+ "2d": painter.TEXTURE_2D,
302
+ "cube": painter.TEXTURE_CUBE_MAP
303
+ }[type];
304
+ this.__texture = initTexture(painter, this.__type, unit);
305
+ painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
306
+ painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
307
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
308
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
309
+ }
310
+ TextureObject.prototype.useImage = function (image) {
311
+ linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image);
312
+ return this;
313
+ };
314
+ TextureObject.prototype.useCube = function (images, width, height) {
315
+ linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture);
316
+ return this;
317
+ };
318
+ return TextureObject;
319
319
  }());
320
320
 
321
- var textures = {};
322
- function getTexture (type, painter, kind) {
323
- var uniqueName = type + "-" + kind;
324
- if (!textures[uniqueName]) {
325
- textures[uniqueName] = new TextureObject(painter, kind);
326
- }
327
- return textures[uniqueName];
321
+ var textures = {};
322
+ function getTexture (type, painter, kind) {
323
+ var uniqueName = type + "-" + kind;
324
+ if (!textures[uniqueName]) {
325
+ textures[uniqueName] = new TextureObject(painter, kind);
326
+ }
327
+ return textures[uniqueName];
328
328
  }
329
329
 
330
- var loadShader = function (painter, type, source) {
331
- var shader = painter.createShader(type);
332
- if (shader == null)
333
- throw new Error('Unable to create shader!');
334
- painter.shaderSource(shader, source);
335
- painter.compileShader(shader);
336
- if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
337
- throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
338
- return shader;
339
- };
340
- var useShader = function (painter, vshaderSource, fshaderSource) {
341
- var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
342
- var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
343
- var glProgram = painter.createProgram();
344
- painter.attachShader(glProgram, vertexShader);
345
- painter.attachShader(glProgram, fragmentShader);
346
- painter.linkProgram(glProgram);
347
- if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
348
- throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
349
- return glProgram;
350
- };
351
- var ShaderObject = (function () {
352
- function ShaderObject(painter) {
353
- this.__painter = painter;
354
- }
355
- ShaderObject.prototype.use = function () {
356
- this.__painter.useProgram(this.program);
357
- return this;
358
- };
359
- ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
360
- this.program = useShader(this.__painter, vshaderSource, fshaderSource);
361
- return this;
362
- };
363
- return ShaderObject;
330
+ var loadShader = function (painter, type, source) {
331
+ var shader = painter.createShader(type);
332
+ if (shader == null)
333
+ throw new Error('Unable to create shader!');
334
+ painter.shaderSource(shader, source);
335
+ painter.compileShader(shader);
336
+ if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
337
+ throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader));
338
+ return shader;
339
+ };
340
+ var useShader = function (painter, vshaderSource, fshaderSource) {
341
+ var vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource);
342
+ var fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource);
343
+ var glProgram = painter.createProgram();
344
+ painter.attachShader(glProgram, vertexShader);
345
+ painter.attachShader(glProgram, fragmentShader);
346
+ painter.linkProgram(glProgram);
347
+ if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
348
+ throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram));
349
+ return glProgram;
350
+ };
351
+ var ShaderObject = (function () {
352
+ function ShaderObject(painter) {
353
+ this.__painter = painter;
354
+ }
355
+ ShaderObject.prototype.use = function () {
356
+ this.__painter.useProgram(this.program);
357
+ return this;
358
+ };
359
+ ShaderObject.prototype.compile = function (vshaderSource, fshaderSource) {
360
+ this.program = useShader(this.__painter, vshaderSource, fshaderSource);
361
+ return this;
362
+ };
363
+ return ShaderObject;
364
364
  }());
365
365
 
366
- 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}";
366
+ 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}";
367
367
 
368
- 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}";
368
+ 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}";
369
369
 
370
- 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}";
370
+ 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}";
371
371
 
372
- 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}";
372
+ 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}";
373
373
 
374
- var fsColor = "precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}";
374
+ 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}";
375
375
 
376
- var fsColors = "precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}";
376
+ 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}";
377
377
 
378
- 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}";
378
+ 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}";
379
379
 
380
- 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}";
380
+ 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}";
381
381
 
382
- var shaders = {};
383
- function getShader (type, painter, mesh) {
384
- var _a, _b;
385
- var uniqueName = type +
386
- (mesh.material.color ? "1" : "0") +
387
- (mesh.material.colors ? "1" : "0") +
388
- (mesh.material.image ? "1" : "0") +
389
- (mesh.material.cube ? "1" : "0");
390
- if (shaders[uniqueName])
391
- return shaders[uniqueName].use();
392
- var vertexShader = (_a = {},
393
- _a[type + "1000"] = vsColor,
394
- _a[type + "0100"] = vsColors,
395
- _a[type + "0010"] = vsImage,
396
- _a[type + "0001"] = vsCube,
397
- _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");
398
- var fragmentShader = (_b = {},
399
- _b[type + "1000"] = fsColor,
400
- _b[type + "0100"] = fsColors,
401
- _b[type + "0010"] = fsImage,
402
- _b[type + "0001"] = fsCube,
403
- _b)[uniqueName];
404
- var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
405
- shaders[uniqueName] = shader;
406
- return shader;
382
+ var shaders = {};
383
+ function getShader (type, painter, mesh) {
384
+ var _a, _b;
385
+ var uniqueName = type +
386
+ (mesh.material.color ? "1" : "0") +
387
+ (mesh.material.colors ? "1" : "0") +
388
+ (mesh.material.image ? "1" : "0") +
389
+ (mesh.material.cube ? "1" : "0");
390
+ if (shaders[uniqueName])
391
+ return shaders[uniqueName].use();
392
+ var vertexShader = (_a = {},
393
+ _a[type + "1000"] = vsColor,
394
+ _a[type + "0100"] = vsColors,
395
+ _a[type + "0010"] = vsImage,
396
+ _a[type + "0001"] = vsCube,
397
+ _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");
398
+ var fragmentShader = (_b = {},
399
+ _b[type + "1000"] = fsColor,
400
+ _b[type + "0100"] = fsColors,
401
+ _b[type + "0010"] = fsImage,
402
+ _b[type + "0001"] = fsCube,
403
+ _b)[uniqueName];
404
+ var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
405
+ shaders[uniqueName] = shader;
406
+ return shader;
407
407
  }
408
408
 
409
- function doDraw (type, painter, mesh, meshWorld, globalWorld) {
410
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
411
- var shader = getShader(type, painter, mesh);
412
- new BufferObject(painter).use()
413
- .write(mesh.geometry.attributes.position.array)
414
- .divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
415
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
416
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
417
- painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
418
- if (mesh.geometry.attributes.normal) {
419
- new BufferObject(painter).use()
420
- .write(mesh.geometry.attributes.normal.array)
421
- .divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
422
- }
423
- if ("color" in mesh.material) {
424
- painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), (_a = mesh.material.color) === null || _a === void 0 ? void 0 : _a.r, (_b = mesh.material.color) === null || _b === void 0 ? void 0 : _b.g, (_c = mesh.material.color) === null || _c === void 0 ? void 0 : _c.b, (_d = mesh.material.color) === null || _d === void 0 ? void 0 : _d.alpha);
425
- }
426
- if ("colors" in mesh.material) {
427
- new BufferObject(painter).use()
428
- .write((_e = mesh.material.colors) === null || _e === void 0 ? void 0 : _e.array)
429
- .divide(painter.getAttribLocation(shader.program, "a_color"), (_f = mesh.material.colors) === null || _f === void 0 ? void 0 : _f.itemSize, (_g = mesh.material.colors) === null || _g === void 0 ? void 0 : _g.itemSize, 0);
430
- }
431
- else if ("cube" in mesh.material) {
432
- var size = ((_j = (_h = mesh.material.cube) === null || _h === void 0 ? void 0 : _h.right) === null || _j === void 0 ? void 0 : _j.image.value).width;
433
- painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
434
- getTexture(type, painter, 'cube').useCube([
435
- (_l = (_k = mesh.material.cube) === null || _k === void 0 ? void 0 : _k.right) === null || _l === void 0 ? void 0 : _l.image.value,
436
- (_o = (_m = mesh.material.cube) === null || _m === void 0 ? void 0 : _m.left) === null || _o === void 0 ? void 0 : _o.image.value,
437
- (_q = (_p = mesh.material.cube) === null || _p === void 0 ? void 0 : _p.top) === null || _q === void 0 ? void 0 : _q.image.value,
438
- (_s = (_r = mesh.material.cube) === null || _r === void 0 ? void 0 : _r.bottom) === null || _s === void 0 ? void 0 : _s.image.value,
439
- (_u = (_t = mesh.material.cube) === null || _t === void 0 ? void 0 : _t.far) === null || _u === void 0 ? void 0 : _u.image.value,
440
- (_w = (_v = mesh.material.cube) === null || _v === void 0 ? void 0 : _v.near) === null || _w === void 0 ? void 0 : _w.image.value
441
- ], size, size);
442
- }
443
- else if ("image" in mesh.material) {
444
- painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
445
- new BufferObject(painter).use()
446
- .write((_x = mesh.geometry.attributes.uv) === null || _x === void 0 ? void 0 : _x.array)
447
- .divide(painter.getAttribLocation(shader.program, "a_textcoord"), (_y = mesh.geometry.attributes.uv) === null || _y === void 0 ? void 0 : _y.itemSize, 2, 0);
448
- getTexture(type, painter, '2d').useImage((_z = mesh.material.image) === null || _z === void 0 ? void 0 : _z.value);
449
- }
450
- if (mesh.geometry.index) {
451
- new BufferObject(painter, true).use()
452
- .write(mesh.geometry.index.array);
453
- painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
454
- }
455
- else {
456
- painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
457
- }
409
+ function doDraw (type, painter, mesh, meshWorld, globalWorld) {
410
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
411
+ var shader = getShader(type, painter, mesh);
412
+ new BufferObject(painter).use()
413
+ .write(mesh.geometry.attributes.position.array)
414
+ .divide(painter.getAttribLocation(shader.program, "a_position"), mesh.geometry.attributes.position.itemSize, mesh.geometry.attributes.position.itemSize, 0);
415
+ painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_world"), false, globalWorld.matrix);
416
+ painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_proporion"), false, globalWorld.proporion);
417
+ painter.uniformMatrix4fv(painter.getUniformLocation(shader.program, "u_matrix_mesh"), false, meshWorld.matrix);
418
+ if (mesh.geometry.attributes.normal) {
419
+ new BufferObject(painter).use()
420
+ .write(mesh.geometry.attributes.normal.array)
421
+ .divide(painter.getAttribLocation(shader.program, "a_normal"), mesh.geometry.attributes.normal.itemSize, mesh.geometry.attributes.normal.itemSize, 0);
422
+ }
423
+ if ("color" in mesh.material) {
424
+ painter.uniform4f(painter.getUniformLocation(shader.program, "u_color"), (_a = mesh.material.color) === null || _a === void 0 ? void 0 : _a.r, (_b = mesh.material.color) === null || _b === void 0 ? void 0 : _b.g, (_c = mesh.material.color) === null || _c === void 0 ? void 0 : _c.b, (_d = mesh.material.color) === null || _d === void 0 ? void 0 : _d.alpha);
425
+ }
426
+ if ("colors" in mesh.material) {
427
+ new BufferObject(painter).use()
428
+ .write((_e = mesh.material.colors) === null || _e === void 0 ? void 0 : _e.array)
429
+ .divide(painter.getAttribLocation(shader.program, "a_color"), (_f = mesh.material.colors) === null || _f === void 0 ? void 0 : _f.itemSize, (_g = mesh.material.colors) === null || _g === void 0 ? void 0 : _g.itemSize, 0);
430
+ }
431
+ else if ("cube" in mesh.material) {
432
+ var size = ((_j = (_h = mesh.material.cube) === null || _h === void 0 ? void 0 : _h.right) === null || _j === void 0 ? void 0 : _j.image.value).width;
433
+ painter.uniform1i(painter.getUniformLocation(shader.program, "u_texture"), 0);
434
+ getTexture(type, painter, 'cube').useCube([
435
+ (_l = (_k = mesh.material.cube) === null || _k === void 0 ? void 0 : _k.right) === null || _l === void 0 ? void 0 : _l.image.value,
436
+ (_o = (_m = mesh.material.cube) === null || _m === void 0 ? void 0 : _m.left) === null || _o === void 0 ? void 0 : _o.image.value,
437
+ (_q = (_p = mesh.material.cube) === null || _p === void 0 ? void 0 : _p.top) === null || _q === void 0 ? void 0 : _q.image.value,
438
+ (_s = (_r = mesh.material.cube) === null || _r === void 0 ? void 0 : _r.bottom) === null || _s === void 0 ? void 0 : _s.image.value,
439
+ (_u = (_t = mesh.material.cube) === null || _t === void 0 ? void 0 : _t.far) === null || _u === void 0 ? void 0 : _u.image.value,
440
+ (_w = (_v = mesh.material.cube) === null || _v === void 0 ? void 0 : _v.near) === null || _w === void 0 ? void 0 : _w.image.value
441
+ ], size, size);
442
+ }
443
+ else if ("image" in mesh.material) {
444
+ painter.uniform1i(painter.getUniformLocation(shader.program, "u_sampler"), 0);
445
+ new BufferObject(painter).use()
446
+ .write((_x = mesh.geometry.attributes.uv) === null || _x === void 0 ? void 0 : _x.array)
447
+ .divide(painter.getAttribLocation(shader.program, "a_textcoord"), (_y = mesh.geometry.attributes.uv) === null || _y === void 0 ? void 0 : _y.itemSize, 2, 0);
448
+ getTexture(type, painter, '2d').useImage((_z = mesh.material.image) === null || _z === void 0 ? void 0 : _z.value);
449
+ }
450
+ if (mesh.geometry.index) {
451
+ new BufferObject(painter, true).use()
452
+ .write(mesh.geometry.index.array);
453
+ painter.drawElements(painter[mesh.geometry.type], mesh.geometry.index.count, painter.UNSIGNED_BYTE, 0);
454
+ }
455
+ else {
456
+ painter.drawArrays(painter[mesh.geometry.type], 0, mesh.geometry.attributes.position.count);
457
+ }
458
458
  }
459
459
 
460
- function assemble (begin, end, step, count) {
461
- var val = [];
462
- for (var index = 0; index < count; index++)
463
- val[index] = begin;
464
- return function () {
465
- for (var i = 0; i < count; i++) {
466
- if (val[i] + step < end) {
467
- val[i] = +(val[i] + step).toFixed(7);
468
- break;
469
- }
470
- else if (i < count - 1) {
471
- val[i] = begin;
472
- }
473
- }
474
- return val;
475
- };
460
+ function assemble (begin, end, step, count) {
461
+ var val = [];
462
+ for (var index = 0; index < count; index++)
463
+ val[index] = begin;
464
+ return function () {
465
+ for (var i = 0; i < count; i++) {
466
+ if (val[i] + step < end) {
467
+ val[i] = +(val[i] + step).toFixed(7);
468
+ break;
469
+ }
470
+ else if (i < count - 1) {
471
+ val[i] = begin;
472
+ }
473
+ }
474
+ return val;
475
+ };
476
476
  }
477
477
 
478
- var needUpdate = false;
479
- var scale = 10;
480
- var WebGL = (function () {
481
- function WebGL(ViewCanvas, RegionCanvas, mode) {
482
- this.name = "WebGL";
483
- this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
484
- this.__regionList = {};
485
- this.__regionAssemble = assemble(0, 1, 0.2, 3);
486
- this.__regionName = "";
487
- this.__regionColor = [0, 0, 0, 1];
488
- this.__scene = {
489
- children: [],
490
- matrix: new Matrix4([
491
- 1, 0, 0, 0,
492
- 0, 1, 0, 0,
493
- 0, 0, 1, 0,
494
- 0, 0, 0, scale
495
- ])
496
- };
497
- this.__unique = new Date().valueOf();
498
- this.painter = getWebGLContext(ViewCanvas, scale, {}, mode);
499
- if (RegionCanvas) {
500
- this.__regionPainter = getWebGLContext(RegionCanvas, scale, {}, mode);
501
- }
502
- var proportion = this.painter.canvas.width / this.painter.canvas.height;
503
- var xProportion = 1;
504
- var yProportion = 1;
505
- if (proportion > 1) {
506
- xProportion = 1 / proportion;
507
- }
508
- else {
509
- yProportion = proportion;
510
- }
511
- var zProportion = Math.min(xProportion, yProportion);
512
- this.__proporion = [
513
- xProportion, 0, 0, 0,
514
- 0, yProportion, 0, 0,
515
- 0, 0, zProportion, 0,
516
- 0, 0, 0, 1
517
- ];
518
- }
519
- WebGL.prototype.matrix = function (initMatrix4) {
520
- return new Matrix4(initMatrix4);
521
- };
522
- WebGL.prototype.getMatrix = function () {
523
- return this.__scene.matrix;
524
- };
525
- WebGL.prototype.getObject3D = function () {
526
- return this.__scene.children;
527
- };
528
- WebGL.prototype.review = function (isUpdateRegion) {
529
- if (isUpdateRegion === void 0) { isUpdateRegion = false; }
530
- if (isUpdateRegion) {
531
- if (this.__regionPainter) {
532
- this.__regionPainter.clearColor(1, 1, 1, 1);
533
- this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
534
- }
535
- }
536
- else {
537
- this.painter.clearColor(1, 1, 1, 1);
538
- this.painter.clear(this.painter.COLOR_BUFFER_BIT);
539
- }
540
- for (var index = 0; index < this.__scene.children.length; index++) {
541
- this.draw(this.__scene.children[index], isUpdateRegion);
542
- }
543
- return this;
544
- };
545
- WebGL.prototype.draw = function (object3D, isUpdateRegion) {
546
- var _a;
547
- if (isUpdateRegion === void 0) { isUpdateRegion = false; }
548
- if (!isUpdateRegion)
549
- needUpdate = true;
550
- var meshWorld = {
551
- matrix: (_a = object3D.matrix) === null || _a === void 0 ? void 0 : _a.value()
552
- };
553
- var globalWorld = {
554
- matrix: this.__scene.matrix.value(),
555
- proporion: this.__proporion
556
- };
557
- this.setRegion(object3D.region);
558
- for (var index = 0; index < object3D.mesh.length; index++) {
559
- if (isUpdateRegion) {
560
- if (this.__regionPainter) {
561
- doDraw("painter" + this.__unique, this.__regionPainter, {
562
- geometry: object3D.mesh[index].geometry,
563
- material: {
564
- color: {
565
- r: this.__regionColor[0],
566
- g: this.__regionColor[1],
567
- b: this.__regionColor[2],
568
- alpha: this.__regionColor[3]
569
- }
570
- }
571
- }, meshWorld, globalWorld);
572
- this.__getColor = getColorFactory(this.__regionPainter);
573
- }
574
- }
575
- else {
576
- doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
577
- }
578
- }
579
- };
580
- WebGL.prototype.render = function (object3D) {
581
- if (!('matrix' in object3D))
582
- object3D.matrix = new Matrix4();
583
- if (!('region' in object3D))
584
- object3D.region = "";
585
- for (var index = 0; index < object3D.mesh.length; index++) {
586
- var mesh = object3D.mesh[index];
587
- if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
588
- mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
589
- }
590
- if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
591
- mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
592
- }
593
- if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
594
- mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
595
- }
596
- if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
597
- mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
598
- }
599
- if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
600
- mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
601
- }
602
- }
603
- this.__scene.children.push(object3D);
604
- this.draw(object3D);
605
- };
606
- WebGL.prototype.setRegion = function (regionName) {
607
- this.__regionName = regionName + "";
608
- if (regionName) {
609
- if (this.__regionList[regionName] == void 0) {
610
- this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
611
- }
612
- this.__regionColor = this.__regionList[regionName];
613
- }
614
- else {
615
- this.__regionColor = [0, 0, 0, 1];
616
- }
617
- return this;
618
- };
619
- WebGL.prototype.getRegion = function (x, y) {
620
- var _this = this;
621
- if (needUpdate)
622
- this.review(true);
623
- needUpdate = false;
624
- return new Promise(function (resolve) {
625
- var rgba = _this.__getColor(x, y);
626
- for (var key in _this.__regionList) {
627
- var currentRGBA = _this.__regionList[key];
628
- if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
629
- resolve(key);
630
- break;
631
- }
632
- }
633
- resolve("");
634
- });
635
- };
636
- return WebGL;
478
+ var needUpdate = false;
479
+ var scale = 10;
480
+ var WebGL = (function () {
481
+ function WebGL(ViewCanvas, RegionCanvas, mode) {
482
+ this.name = "WebGL";
483
+ this.__getColor = function (x, y) { return "rgba(0,0,0,1)"; };
484
+ this.__regionList = {};
485
+ this.__regionAssemble = assemble(0, 1, 0.2, 3);
486
+ this.__regionName = "";
487
+ this.__regionColor = [0, 0, 0, 1];
488
+ this.__scene = {
489
+ children: [],
490
+ matrix: new Matrix4([
491
+ 1, 0, 0, 0,
492
+ 0, 1, 0, 0,
493
+ 0, 0, 1, 0,
494
+ 0, 0, 0, scale
495
+ ])
496
+ };
497
+ this.__unique = new Date().valueOf();
498
+ this.painter = getWebGLContext(ViewCanvas, scale, {}, mode);
499
+ if (RegionCanvas) {
500
+ this.__regionPainter = getWebGLContext(RegionCanvas, scale, {}, mode);
501
+ }
502
+ var proportion = this.painter.canvas.width / this.painter.canvas.height;
503
+ var xProportion = 1;
504
+ var yProportion = 1;
505
+ if (proportion > 1) {
506
+ xProportion = 1 / proportion;
507
+ }
508
+ else {
509
+ yProportion = proportion;
510
+ }
511
+ var zProportion = Math.min(xProportion, yProportion);
512
+ this.__proporion = [
513
+ xProportion, 0, 0, 0,
514
+ 0, yProportion, 0, 0,
515
+ 0, 0, zProportion, 0,
516
+ 0, 0, 0, 1
517
+ ];
518
+ }
519
+ WebGL.prototype.matrix = function (initMatrix4) {
520
+ return new Matrix4(initMatrix4);
521
+ };
522
+ WebGL.prototype.getMatrix = function () {
523
+ return this.__scene.matrix;
524
+ };
525
+ WebGL.prototype.getObject3D = function () {
526
+ return this.__scene.children;
527
+ };
528
+ WebGL.prototype.review = function (isUpdateRegion) {
529
+ if (isUpdateRegion === void 0) { isUpdateRegion = false; }
530
+ if (isUpdateRegion) {
531
+ if (this.__regionPainter) {
532
+ this.__regionPainter.clearColor(1, 1, 1, 1);
533
+ this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT);
534
+ }
535
+ }
536
+ else {
537
+ this.painter.clearColor(1, 1, 1, 1);
538
+ this.painter.clear(this.painter.COLOR_BUFFER_BIT);
539
+ }
540
+ for (var index = 0; index < this.__scene.children.length; index++) {
541
+ this.draw(this.__scene.children[index], isUpdateRegion);
542
+ }
543
+ return this;
544
+ };
545
+ WebGL.prototype.draw = function (object3D, isUpdateRegion) {
546
+ var _a;
547
+ if (isUpdateRegion === void 0) { isUpdateRegion = false; }
548
+ if (!isUpdateRegion)
549
+ needUpdate = true;
550
+ var meshWorld = {
551
+ matrix: (_a = object3D.matrix) === null || _a === void 0 ? void 0 : _a.value()
552
+ };
553
+ var globalWorld = {
554
+ matrix: this.__scene.matrix.value(),
555
+ proporion: this.__proporion
556
+ };
557
+ this.setRegion(object3D.region);
558
+ for (var index = 0; index < object3D.mesh.length; index++) {
559
+ if (isUpdateRegion) {
560
+ if (this.__regionPainter) {
561
+ doDraw("painter" + this.__unique, this.__regionPainter, {
562
+ geometry: object3D.mesh[index].geometry,
563
+ material: {
564
+ color: {
565
+ r: this.__regionColor[0],
566
+ g: this.__regionColor[1],
567
+ b: this.__regionColor[2],
568
+ alpha: this.__regionColor[3]
569
+ }
570
+ }
571
+ }, meshWorld, globalWorld);
572
+ this.__getColor = getColorFactory(this.__regionPainter);
573
+ }
574
+ }
575
+ else {
576
+ doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
577
+ }
578
+ }
579
+ };
580
+ WebGL.prototype.render = function (object3D) {
581
+ if (!('matrix' in object3D))
582
+ object3D.matrix = new Matrix4();
583
+ if (!('region' in object3D))
584
+ object3D.region = "";
585
+ for (var index = 0; index < object3D.mesh.length; index++) {
586
+ var mesh = object3D.mesh[index];
587
+ if (mesh.geometry.attributes.normal && Array.isArray(mesh.geometry.attributes.normal.array)) {
588
+ mesh.geometry.attributes.normal.array = new Float32Array(mesh.geometry.attributes.normal.array);
589
+ }
590
+ if (mesh.geometry.attributes.position && Array.isArray(mesh.geometry.attributes.position.array)) {
591
+ mesh.geometry.attributes.position.array = new Float32Array(mesh.geometry.attributes.position.array);
592
+ }
593
+ if (mesh.geometry.attributes.uv && Array.isArray(mesh.geometry.attributes.uv.array)) {
594
+ mesh.geometry.attributes.uv.array = new Float32Array(mesh.geometry.attributes.uv.array);
595
+ }
596
+ if (mesh.geometry.index && Array.isArray(mesh.geometry.index.array)) {
597
+ mesh.geometry.index.array = new Uint8Array(mesh.geometry.index.array);
598
+ }
599
+ if (mesh.material.colors && Array.isArray(mesh.material.colors.array)) {
600
+ mesh.material.colors.array = new Float32Array(mesh.material.colors.array);
601
+ }
602
+ }
603
+ this.__scene.children.push(object3D);
604
+ this.draw(object3D);
605
+ };
606
+ WebGL.prototype.setRegion = function (regionName) {
607
+ this.__regionName = regionName + "";
608
+ if (regionName) {
609
+ if (this.__regionList[regionName] == void 0) {
610
+ this.__regionList[regionName] = __spreadArray(__spreadArray([], this.__regionAssemble(), true), [1], false);
611
+ }
612
+ this.__regionColor = this.__regionList[regionName];
613
+ }
614
+ else {
615
+ this.__regionColor = [0, 0, 0, 1];
616
+ }
617
+ return this;
618
+ };
619
+ WebGL.prototype.getRegion = function (x, y) {
620
+ var _this = this;
621
+ if (needUpdate)
622
+ this.review(true);
623
+ needUpdate = false;
624
+ return new Promise(function (resolve) {
625
+ var rgba = _this.__getColor(x, y);
626
+ for (var key in _this.__regionList) {
627
+ var currentRGBA = _this.__regionList[key];
628
+ if ("rgba(" + currentRGBA[0] * 255 + "," + currentRGBA[1] * 255 + "," + currentRGBA[2] * 255 + "," + currentRGBA[3] * 255 + ")" == rgba) {
629
+ resolve(key);
630
+ break;
631
+ }
632
+ }
633
+ resolve("");
634
+ });
635
+ };
636
+ return WebGL;
637
637
  }());
638
638
 
639
639
  export { WebGL as default };