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,11 +1,11 @@
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
- function t(t,r,e){if(e||2===arguments.length)for(var i,o=0,n=r.length;o<n;o++)!i&&o in r||(i||(i=Array.prototype.slice.call(r,0,o)),i[o]=r[o]);return t.concat(i||Array.prototype.slice.call(r))}function r(t,r,e){void 0===e&&(e={});for(var i=["webgl","experimental-webgl","webkit-3d","moz-webgl"],o=null,n=0;n<i.length;n++){try{o=t.getContext(i[n],e)}catch(t){}if(o)break}if(!o)throw new Error("Non canvas or browser does not support webgl.");var a=o.canvas.width,_=o.canvas.height,s=a*r,m=_*r;return o.viewport(.5*(a-s),.5*(_-m),s,m),o.depthFunc(o.LEQUAL),o.enable(o.DEPTH_TEST),o}function e(t){var r=t.drawingBufferWidth,e=t.drawingBufferHeight,i=new Uint8Array(4*r*e);return t.readPixels(0,0,r,e,t.RGBA,t.UNSIGNED_BYTE,i),function(t,o){return"rgba("+i[4*((o=e-o)*r+t)]+","+i[4*(o*r+t)+1]+","+i[4*(o*r+t)+2]+","+i[4*(o*r+t)+3]+")"}}"function"==typeof SuppressedError&&SuppressedError;var i=function(t,r){for(var e=[],i=0;i<4;i++)for(var o=0;o<r.length/4;o++)e[4*o+i]=t[i]*r[4*o]+t[i+4]*r[4*o+1]+t[i+8]*r[4*o+2]+t[i+12]*r[4*o+3];return e},o=function(){function t(t){void 0===t&&(t=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this.name="Matrix4",this.__matrix4=t}return t.prototype.move=function(t,r,e,o){return void 0===o&&(o=0),this.__matrix4=i(function(t,r,e,i){void 0===i&&(i=0);var o=Math.sqrt(r*r+e*e+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,r*t/o,e*t/o,i*t/o,1]}(t,r,e,o),this.__matrix4),this},t.prototype.rotate=function(t,r,e,o,n,a,_){var s=function(t,r,e,i,o,n){if("number"==typeof t&&"number"==typeof r){if("number"!=typeof e?(e=0,i=t,o=r,n=1):"number"==typeof i&&"number"==typeof o&&"number"==typeof n||(i=t,o=r,n=e,t=0,r=0,e=0),t==i&&r==o&&e==n)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((i-t)*(i-t)+(o-r)*(o-r)),_=0!=a?(o-r)/a:1,s=0!=a?(i-t)/a:0,m=(i-t)*s+(o-r)*_,u=n-e,p=Math.sqrt(m*m+u*u),l=0!=p?u/p:1,c=0!=p?m/p:0;return[[_,l*s,s*c,0,-s,_*l,_*c,0,0,-c,l,0,r*s-t*_,e*c-t*s*l-r*_*l,-t*s*c-r*_*c-e*l,1],[_,-s,0,0,l*s,l*_,-c,0,s*c,_*c,l,0,t,r,e,1]]}throw new Error("a1 and b1 is required!")}(r,e,o,n,a,_);return this.__matrix4=i(i(i(s[1],function(t){var r=Math.sin(t),e=Math.cos(t);return[e,r,0,0,-r,e,0,0,0,0,1,0,0,0,0,1]}(t)),s[0]),this.__matrix4),this},t.prototype.scale=function(t,r,e,o,n,a){return void 0===o&&(o=0),void 0===n&&(n=0),void 0===a&&(a=0),this.__matrix4=i(function(t,r,e,i,o,n){return void 0===i&&(i=0),void 0===o&&(o=0),void 0===n&&(n=0),[t,0,0,0,0,r,0,0,0,0,e,0,i-i*t,o-o*r,n-n*e,1]}(t,r,e,o,n,a),this.__matrix4),this},t.prototype.multiply=function(t,r){return void 0===r&&(r=!1),this.__matrix4=r?i(this.__matrix4,t):i(t,this.__matrix4),this},t.prototype.use=function(t,r,e,o){return void 0===e&&(e=0),void 0===o&&(o=1),i(this.__matrix4,[t,r,e,o])},t.prototype.value=function(){return this.__matrix4},t}(),n=function(){function t(t,r){void 0===r&&(r=!1),this.__painter=t,this.__isElement=r,this.__buffer=function(t){return t.createBuffer()}(t),this.__type=r?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER}return t.prototype.use=function(){return this.__painter.bindBuffer(this.__type,this.__buffer),this},t.prototype.write=function(t){return function(t,r,e,i){var o=e?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(o,r,i)}(this.__painter,t,this.__isElement,this.__painter.STATIC_DRAW),this.__fsize=t.BYTES_PER_ELEMENT,this},t.prototype.divide=function(t,r,e,i){return void 0===i&&(i=0),function(t,r,e,i,o,n,a){t.vertexAttribPointer(r,e,i,a,o,n),t.enableVertexAttribArray(r)}(this.__painter,t,r,this.__painter.FLOAT,e*this.__fsize,i*this.__fsize,!1),this},t}(),a=function(){function t(t,r,e){void 0===e&&(e=0),this.__painter=t,this.__type={"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP}[r],this.__texture=function(t,r,e){var i=t.createTexture();return t.activeTexture(t["TEXTURE"+e]),t.bindTexture(r,i),i}(t,this.__type,e),t.texParameteri(this.__type,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(this.__type,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(this.__type,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(this.__type,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}return t.prototype.useImage=function(t){return function(t,r,e,i,o,n){t.texImage2D(r,e,i,i,o,n)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t),this},t.prototype.useCube=function(t,r,e){return function(t,r,e,i,o,n,a,_,s){for(var m,u=[t.TEXTURE_CUBE_MAP_POSITIVE_X,t.TEXTURE_CUBE_MAP_NEGATIVE_X,t.TEXTURE_CUBE_MAP_POSITIVE_Y,t.TEXTURE_CUBE_MAP_NEGATIVE_Y,t.TEXTURE_CUBE_MAP_POSITIVE_Z,t.TEXTURE_CUBE_MAP_NEGATIVE_Z],p=0;p<u.length;p++)n[p]&&(m=u[p],t.texImage2D(m,e,i,a,_,0,i,o,null),t.bindTexture(r,s),t.texImage2D(m,e,i,i,o,n[p]));t.generateMipmap(r)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,r,e,this.__texture),this},t}(),_={};function s(t,r,e){var i=t+"-"+e;return _[i]||(_[i]=new a(r,e)),_[i]}var m=function(t,r,e){var i=t.createShader(r);if(null==i)throw new Error("Unable to create shader!");if(t.shaderSource(i,e),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS))throw new Error("Failed to compile shader:"+t.getShaderInfoLog(i));return i},u=function(){function t(t){this.__painter=t}return t.prototype.use=function(){return this.__painter.useProgram(this.program),this},t.prototype.compile=function(t,r){return this.program=function(t,r,e){var i=m(t,t.VERTEX_SHADER,r),o=m(t,t.FRAGMENT_SHADER,e),n=t.createProgram();if(t.attachShader(n,i),t.attachShader(n,o),t.linkProgram(n),!t.getProgramParameter(n,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(n));return n}(this.__painter,t,r),this},t}(),p="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}",l="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}",c="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}",h="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}",g="precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}",f="precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}",v="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}",d="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}",y={};function E(t,r,e,i,o){var a=function(t,r,e){var i,o,n=t+(e.material.color?"1":"0")+(e.material.colors?"1":"0")+(e.material.image?"1":"0")+(e.material.cube?"1":"0");if(y[n])return y[n].use();var a=(i={},i[t+"1000"]=p,i[t+"0100"]=l,i[t+"0010"]=c,i[t+"0001"]=h,i)[n].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"),_=(o={},o[t+"1000"]=g,o[t+"0100"]=f,o[t+"0010"]=v,o[t+"0001"]=d,o)[n],s=new u(r).compile(a,_).use();return y[n]=s,s}(t,r,e);if(new n(r).use().write(e.geometry.attributes.position.array).divide(r.getAttribLocation(a.program,"a_position"),e.geometry.attributes.position.itemSize,e.geometry.attributes.position.itemSize,0),r.uniformMatrix4fv(r.getUniformLocation(a.program,"u_matrix_world"),!1,o.matrix),r.uniformMatrix4fv(r.getUniformLocation(a.program,"u_matrix_proporion"),!1,o.proporion),r.uniformMatrix4fv(r.getUniformLocation(a.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new n(r).use().write(e.geometry.attributes.normal.array).divide(r.getAttribLocation(a.program,"a_normal"),e.geometry.attributes.normal.itemSize,e.geometry.attributes.normal.itemSize,0),"color"in e.material&&r.uniform4f(r.getUniformLocation(a.program,"u_color"),e.material.color.r,e.material.color.g,e.material.color.b,e.material.color.alpha),"colors"in e.material)new n(r).use().write(e.material.colors.array).divide(r.getAttribLocation(a.program,"a_color"),e.material.colors.itemSize,e.material.colors.itemSize,0);else if("cube"in e.material){var _=e.material.cube.right.image.value.width;r.uniform1i(r.getUniformLocation(a.program,"u_texture"),0),s(t,r,"cube").useCube([e.material.cube.right.image.value,e.material.cube.left.image.value,e.material.cube.top.image.value,e.material.cube.bottom.image.value,e.material.cube.far.image.value,e.material.cube.near.image.value],_,_)}else"image"in e.material&&(r.uniform1i(r.getUniformLocation(a.program,"u_sampler"),0),new n(r).use().write(e.geometry.attributes.uv.array).divide(r.getAttribLocation(a.program,"a_textcoord"),e.geometry.attributes.uv.itemSize,2,0),s(t,r,"2d").useImage(e.material.image.value));e.geometry.index?(new n(r,!0).use().write(e.geometry.index.array),r.drawElements(r[e.geometry.type],e.geometry.index.count,r.UNSIGNED_BYTE,0)):r.drawArrays(r[e.geometry.type],0,e.geometry.attributes.position.count)}var x=!1,b=function(){function i(t,e){this.name="WebGL",this.__getColor=function(t,r){return"rgba(0,0,0,1)"},this.__regionList={},this.__regionAssemble=function(t,r,e,i){for(var o=[],n=0;n<i;n++)o[n]=t;return function(){for(var n=0;n<i;n++){if(o[n]+e<r){o[n]=+(o[n]+e).toFixed(7);break}n<i-1&&(o[n]=t)}return o}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new o([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,10])},this.__unique=(new Date).valueOf(),this.painter=r(t,10),e&&(this.__regionPainter=r(e,10,{}));var i=this.painter.canvas.width/this.painter.canvas.height,n=1,a=1;i>1?n=1/i:a=i;var _=Math.min(n,a);this.__proporion=[n,0,0,0,0,a,0,0,0,0,_,0,0,0,0,1]}return i.prototype.matrix=function(t){return new o(t)},i.prototype.getMatrix=function(){return this.__scene.matrix},i.prototype.getObject3D=function(){return this.__scene.children},i.prototype.review=function(t){void 0===t&&(t=!1),t?this.__regionPainter&&(this.__regionPainter.clearColor(1,1,1,1),this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT)):(this.painter.clearColor(1,1,1,1),this.painter.clear(this.painter.COLOR_BUFFER_BIT));for(var r=0;r<this.__scene.children.length;r++)this.draw(this.__scene.children[r],t);return this},i.prototype.draw=function(t,r){void 0===r&&(r=!1),r||(x=!0);var i={matrix:t.matrix.value()},o={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var n=0;n<t.mesh.length;n++)r?this.__regionPainter&&(E("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[n].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},i,o),this.__getColor=e(this.__regionPainter)):E("region"+this.__unique,this.painter,t.mesh[n],i,o)},i.prototype.render=function(t){"matrix"in t||(t.matrix=new o),"region"in t||(t.region="");for(var r=0;r<t.mesh.length;r++){var e=t.mesh[r];e.geometry.attributes.normal&&Array.isArray(e.geometry.attributes.normal.array)&&(e.geometry.attributes.normal.array=new Float32Array(e.geometry.attributes.normal.array)),e.geometry.attributes.position&&Array.isArray(e.geometry.attributes.position.array)&&(e.geometry.attributes.position.array=new Float32Array(e.geometry.attributes.position.array)),e.geometry.attributes.uv&&Array.isArray(e.geometry.attributes.uv.array)&&(e.geometry.attributes.uv.array=new Float32Array(e.geometry.attributes.uv.array)),e.geometry.index&&Array.isArray(e.geometry.index.array)&&(e.geometry.index.array=new Uint8Array(e.geometry.index.array)),e.material.colors&&Array.isArray(e.material.colors.array)&&(e.material.colors.array=new Float32Array(e.material.colors.array))}this.__scene.children.push(t),this.draw(t)},i.prototype.setRegion=function(r){return this.__regionName=r+"",r?(null==this.__regionList[r]&&(this.__regionList[r]=t(t([],this.__regionAssemble(),!0),[1],!1)),this.__regionColor=this.__regionList[r]):this.__regionColor=[0,0,0,1],this},i.prototype.getRegion=function(t,r){var e=this;return x&&this.review(!0),x=!1,new Promise((function(i,o){var n=e.__getColor(t,r);for(var a in e.__regionList){var _=e.__regionList[a];if("rgba("+255*_[0]+","+255*_[1]+","+255*_[2]+","+255*_[3]+")"==n){i(a);break}}i("")}))},i}();export{b as default};
11
+ function r(r,t,e){if(e||2===arguments.length)for(var i,o=0,n=t.length;o<n;o++)!i&&o in t||(i||(i=Array.prototype.slice.call(t,0,o)),i[o]=t[o]);return r.concat(i||Array.prototype.slice.call(t))}function t(r,t,e){void 0===e&&(e={});for(var i=["webgl","experimental-webgl","webkit-3d","moz-webgl"],o=null,n=0;n<i.length;n++){try{o=r.getContext(i[n],e)}catch(r){}if(o)break}if(!o)throw new Error("Non canvas or browser does not support webgl.");var a=o.canvas.width,_=o.canvas.height,s=a*t,m=_*t;return o.viewport(.5*(a-s),.5*(_-m),s,m),o.depthFunc(o.LEQUAL),o.enable(o.DEPTH_TEST),o}function e(r){var t=r.drawingBufferWidth,e=r.drawingBufferHeight,i=new Uint8Array(4*t*e);return r.readPixels(0,0,t,e,r.RGBA,r.UNSIGNED_BYTE,i),function(r,o){return"rgba("+i[4*((o=e-o)*t+r)]+","+i[4*(o*t+r)+1]+","+i[4*(o*t+r)+2]+","+i[4*(o*t+r)+3]+")"}}"function"==typeof SuppressedError&&SuppressedError;var i=function(r,t){for(var e=[],i=0;i<4;i++)for(var o=0;o<t.length/4;o++)e[4*o+i]=r[i]*t[4*o]+r[i+4]*t[4*o+1]+r[i+8]*t[4*o+2]+r[i+12]*t[4*o+3];return e},o=function(){function r(r){void 0===r&&(r=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this.name="Matrix4",this.__matrix4=r}return r.prototype.move=function(r,t,e,o){return void 0===o&&(o=0),this.__matrix4=i(function(r,t,e,i){void 0===i&&(i=0);var o=Math.sqrt(t*t+e*e+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,t*r/o,e*r/o,i*r/o,1]}(r,t,e,o),this.__matrix4),this},r.prototype.rotate=function(r,t,e,o,n,a,_){var s=function(r,t,e,i,o,n){if("number"==typeof r&&"number"==typeof t){if("number"!=typeof e?(e=0,i=r,o=t,n=1):"number"==typeof i&&"number"==typeof o&&"number"==typeof n||(i=r,o=t,n=e,r=0,t=0,e=0),r==i&&t==o&&e==n)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((i-r)*(i-r)+(o-t)*(o-t)),_=0!=a?(o-t)/a:1,s=0!=a?(i-r)/a:0,m=(i-r)*s+(o-t)*_,u=n-e,p=Math.sqrt(m*m+u*u),l=0!=p?u/p:1,c=0!=p?m/p:0;return[[_,l*s,s*c,0,-s,_*l,_*c,0,0,-c,l,0,t*s-r*_,e*c-r*s*l-t*_*l,-r*s*c-t*_*c-e*l,1],[_,-s,0,0,l*s,l*_,-c,0,s*c,_*c,l,0,r,t,e,1]]}throw new Error("a1 and b1 is required!")}(t,e,o,n,a,_);return this.__matrix4=i(i(i(s[1],function(r){var t=Math.sin(r),e=Math.cos(r);return[e,t,0,0,-t,e,0,0,0,0,1,0,0,0,0,1]}(r)),s[0]),this.__matrix4),this},r.prototype.scale=function(r,t,e,o,n,a){return void 0===o&&(o=0),void 0===n&&(n=0),void 0===a&&(a=0),this.__matrix4=i(function(r,t,e,i,o,n){return void 0===i&&(i=0),void 0===o&&(o=0),void 0===n&&(n=0),[r,0,0,0,0,t,0,0,0,0,e,0,i-i*r,o-o*t,n-n*e,1]}(r,t,e,o,n,a),this.__matrix4),this},r.prototype.multiply=function(r,t){return void 0===t&&(t=!1),this.__matrix4=t?i(this.__matrix4,r):i(r,this.__matrix4),this},r.prototype.use=function(r,t,e,o){return void 0===e&&(e=0),void 0===o&&(o=1),i(this.__matrix4,[r,t,e,o])},r.prototype.value=function(){return this.__matrix4},r}(),n=function(){function r(r,t){void 0===t&&(t=!1),this.__painter=r,this.__isElement=t,this.__buffer=function(r){return r.createBuffer()}(r),this.__type=t?r.ELEMENT_ARRAY_BUFFER:r.ARRAY_BUFFER}return r.prototype.use=function(){return this.__painter.bindBuffer(this.__type,this.__buffer),this},r.prototype.write=function(r){return function(r,t,e,i){var o=e?r.ELEMENT_ARRAY_BUFFER:r.ARRAY_BUFFER;r.bufferData(o,t,i)}(this.__painter,r,this.__isElement,this.__painter.STATIC_DRAW),this.__fsize=r.BYTES_PER_ELEMENT,this},r.prototype.divide=function(r,t,e,i){return void 0===i&&(i=0),function(r,t,e,i,o,n,a){r.vertexAttribPointer(t,e,i,a,o,n),r.enableVertexAttribArray(t)}(this.__painter,r,t,this.__painter.FLOAT,e*this.__fsize,i*this.__fsize,!1),this},r}(),a=function(){function r(r,t,e){void 0===e&&(e=0),this.__painter=r,this.__type={"2d":r.TEXTURE_2D,cube:r.TEXTURE_CUBE_MAP}[t],this.__texture=function(r,t,e){var i=r.createTexture();return r.activeTexture(r["TEXTURE"+e]),r.bindTexture(t,i),i}(r,this.__type,e),r.texParameteri(this.__type,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(this.__type,r.TEXTURE_MAG_FILTER,r.NEAREST),r.texParameteri(this.__type,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(this.__type,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE)}return r.prototype.useImage=function(r){return function(r,t,e,i,o,n){r.texImage2D(t,e,i,i,o,n)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,r),this},r.prototype.useCube=function(r,t,e){return function(r,t,e,i,o,n,a,_,s){for(var m,u=[r.TEXTURE_CUBE_MAP_POSITIVE_X,r.TEXTURE_CUBE_MAP_NEGATIVE_X,r.TEXTURE_CUBE_MAP_POSITIVE_Y,r.TEXTURE_CUBE_MAP_NEGATIVE_Y,r.TEXTURE_CUBE_MAP_POSITIVE_Z,r.TEXTURE_CUBE_MAP_NEGATIVE_Z],p=0;p<u.length;p++)n[p]&&(m=u[p],r.texImage2D(m,e,i,a,_,0,i,o,null),r.bindTexture(t,s),r.texImage2D(m,e,i,i,o,n[p]));r.generateMipmap(t)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,r,t,e,this.__texture),this},r}(),_={};function s(r,t,e){var i=r+"-"+e;return _[i]||(_[i]=new a(t,e)),_[i]}var m=function(r,t,e){var i=r.createShader(t);if(null==i)throw new Error("Unable to create shader!");if(r.shaderSource(i,e),r.compileShader(i),!r.getShaderParameter(i,r.COMPILE_STATUS))throw new Error("Failed to compile shader:"+r.getShaderInfoLog(i));return i},u=function(){function r(r){this.__painter=r}return r.prototype.use=function(){return this.__painter.useProgram(this.program),this},r.prototype.compile=function(r,t){return this.program=function(r,t,e){var i=m(r,r.VERTEX_SHADER,t),o=m(r,r.FRAGMENT_SHADER,e),n=r.createProgram();if(r.attachShader(n,i),r.attachShader(n,o),r.linkProgram(n),!r.getProgramParameter(n,r.LINK_STATUS))throw new Error("Failed to link program: "+r.getProgramInfoLog(n));return n}(this.__painter,r,t),this},r}(),p="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}",l="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}",c="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}",h="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}",g="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}",f="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}",v="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}",d="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}",y={};function E(r,t,e,i,o){var a=function(r,t,e){var i,o,n=r+(e.material.color?"1":"0")+(e.material.colors?"1":"0")+(e.material.image?"1":"0")+(e.material.cube?"1":"0");if(y[n])return y[n].use();var a=(i={},i[r+"1000"]=p,i[r+"0100"]=l,i[r+"0010"]=c,i[r+"0001"]=h,i)[n].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"),_=(o={},o[r+"1000"]=g,o[r+"0100"]=f,o[r+"0010"]=v,o[r+"0001"]=d,o)[n],s=new u(t).compile(a,_).use();return y[n]=s,s}(r,t,e);if(new n(t).use().write(e.geometry.attributes.position.array).divide(t.getAttribLocation(a.program,"a_position"),e.geometry.attributes.position.itemSize,e.geometry.attributes.position.itemSize,0),t.uniformMatrix4fv(t.getUniformLocation(a.program,"u_matrix_world"),!1,o.matrix),t.uniformMatrix4fv(t.getUniformLocation(a.program,"u_matrix_proporion"),!1,o.proporion),t.uniformMatrix4fv(t.getUniformLocation(a.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new n(t).use().write(e.geometry.attributes.normal.array).divide(t.getAttribLocation(a.program,"a_normal"),e.geometry.attributes.normal.itemSize,e.geometry.attributes.normal.itemSize,0),"color"in e.material&&t.uniform4f(t.getUniformLocation(a.program,"u_color"),e.material.color.r,e.material.color.g,e.material.color.b,e.material.color.alpha),"colors"in e.material)new n(t).use().write(e.material.colors.array).divide(t.getAttribLocation(a.program,"a_color"),e.material.colors.itemSize,e.material.colors.itemSize,0);else if("cube"in e.material){var _=e.material.cube.right.image.value.width;t.uniform1i(t.getUniformLocation(a.program,"u_texture"),0),s(r,t,"cube").useCube([e.material.cube.right.image.value,e.material.cube.left.image.value,e.material.cube.top.image.value,e.material.cube.bottom.image.value,e.material.cube.far.image.value,e.material.cube.near.image.value],_,_)}else"image"in e.material&&(t.uniform1i(t.getUniformLocation(a.program,"u_sampler"),0),new n(t).use().write(e.geometry.attributes.uv.array).divide(t.getAttribLocation(a.program,"a_textcoord"),e.geometry.attributes.uv.itemSize,2,0),s(r,t,"2d").useImage(e.material.image.value));e.geometry.index?(new n(t,!0).use().write(e.geometry.index.array),t.drawElements(t[e.geometry.type],e.geometry.index.count,t.UNSIGNED_BYTE,0)):t.drawArrays(t[e.geometry.type],0,e.geometry.attributes.position.count)}var x=!1,b=function(){function i(r,e){this.name="WebGL",this.__getColor=function(r,t){return"rgba(0,0,0,1)"},this.__regionList={},this.__regionAssemble=function(r,t,e,i){for(var o=[],n=0;n<i;n++)o[n]=r;return function(){for(var n=0;n<i;n++){if(o[n]+e<t){o[n]=+(o[n]+e).toFixed(7);break}n<i-1&&(o[n]=r)}return o}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new o([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,10])},this.__unique=(new Date).valueOf(),this.painter=t(r,10),e&&(this.__regionPainter=t(e,10,{}));var i=this.painter.canvas.width/this.painter.canvas.height,n=1,a=1;i>1?n=1/i:a=i;var _=Math.min(n,a);this.__proporion=[n,0,0,0,0,a,0,0,0,0,_,0,0,0,0,1]}return i.prototype.matrix=function(r){return new o(r)},i.prototype.getMatrix=function(){return this.__scene.matrix},i.prototype.getObject3D=function(){return this.__scene.children},i.prototype.review=function(r){void 0===r&&(r=!1),r?this.__regionPainter&&(this.__regionPainter.clearColor(1,1,1,1),this.__regionPainter.clear(this.__regionPainter.COLOR_BUFFER_BIT)):(this.painter.clearColor(1,1,1,1),this.painter.clear(this.painter.COLOR_BUFFER_BIT));for(var t=0;t<this.__scene.children.length;t++)this.draw(this.__scene.children[t],r);return this},i.prototype.draw=function(r,t){void 0===t&&(t=!1),t||(x=!0);var i={matrix:r.matrix.value()},o={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(r.region);for(var n=0;n<r.mesh.length;n++)t?this.__regionPainter&&(E("painter"+this.__unique,this.__regionPainter,{geometry:r.mesh[n].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},i,o),this.__getColor=e(this.__regionPainter)):E("region"+this.__unique,this.painter,r.mesh[n],i,o)},i.prototype.render=function(r){"matrix"in r||(r.matrix=new o),"region"in r||(r.region="");for(var t=0;t<r.mesh.length;t++){var e=r.mesh[t];e.geometry.attributes.normal&&Array.isArray(e.geometry.attributes.normal.array)&&(e.geometry.attributes.normal.array=new Float32Array(e.geometry.attributes.normal.array)),e.geometry.attributes.position&&Array.isArray(e.geometry.attributes.position.array)&&(e.geometry.attributes.position.array=new Float32Array(e.geometry.attributes.position.array)),e.geometry.attributes.uv&&Array.isArray(e.geometry.attributes.uv.array)&&(e.geometry.attributes.uv.array=new Float32Array(e.geometry.attributes.uv.array)),e.geometry.index&&Array.isArray(e.geometry.index.array)&&(e.geometry.index.array=new Uint8Array(e.geometry.index.array)),e.material.colors&&Array.isArray(e.material.colors.array)&&(e.material.colors.array=new Float32Array(e.material.colors.array))}this.__scene.children.push(r),this.draw(r)},i.prototype.setRegion=function(t){return this.__regionName=t+"",t?(null==this.__regionList[t]&&(this.__regionList[t]=r(r([],this.__regionAssemble(),!0),[1],!1)),this.__regionColor=this.__regionList[t]):this.__regionColor=[0,0,0,1],this},i.prototype.getRegion=function(r,t){var e=this;return x&&this.review(!0),x=!1,new Promise((function(i,o){var n=e.__getColor(r,t);for(var a in e.__regionList){var _=e.__regionList[a];if("rgba("+255*_[0]+","+255*_[1]+","+255*_[2]+","+255*_[3]+")"==n){i(a);break}}i("")}))},i}();export{b as default};