vislite 0.8.0 → 1.0.0-next.0

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 (201) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +17 -2
  3. package/LICENSE +20 -20
  4. package/README.md +2 -36
  5. package/lib/Buffer/index.umd.js +2 -2
  6. package/lib/Buffer/index.umd.min.js +2 -2
  7. package/lib/Canvas/index.umd.js +9 -24
  8. package/lib/Canvas/index.umd.min.js +3 -3
  9. package/lib/Cardinal/index.umd.js +2 -2
  10. package/lib/Cardinal/index.umd.min.js +2 -2
  11. package/lib/Eoap/index.umd.js +2 -2
  12. package/lib/Eoap/index.umd.min.js +2 -2
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/SVG/index.umd.js +19 -35
  20. package/lib/SVG/index.umd.min.js +3 -3
  21. package/lib/Shader/index.umd.js +3 -82
  22. package/lib/Shader/index.umd.min.js +3 -3
  23. package/lib/Texture/index.umd.js +2 -2
  24. package/lib/Texture/index.umd.min.js +2 -2
  25. package/lib/TreeLayout/index.umd.js +2 -2
  26. package/lib/TreeLayout/index.umd.min.js +2 -2
  27. package/lib/animation/index.umd.js +2 -2
  28. package/lib/animation/index.umd.min.js +2 -2
  29. package/lib/getLoopColors/index.umd.js +2 -2
  30. package/lib/getLoopColors/index.umd.min.js +2 -2
  31. package/lib/getWebGLContext/index.umd.js +2 -2
  32. package/lib/getWebGLContext/index.umd.min.js +2 -2
  33. package/lib/index.umd.js +104 -944
  34. package/lib/index.umd.min.js +3 -3
  35. package/lib/move/index.umd.js +2 -2
  36. package/lib/move/index.umd.min.js +2 -2
  37. package/lib/resizeObserver/index.umd.js +2 -2
  38. package/lib/resizeObserver/index.umd.min.js +2 -2
  39. package/lib/rotate/index.umd.js +2 -2
  40. package/lib/rotate/index.umd.min.js +2 -2
  41. package/lib/ruler/index.umd.js +2 -2
  42. package/lib/ruler/index.umd.min.js +2 -2
  43. package/lib/scale/index.umd.js +2 -2
  44. package/lib/scale/index.umd.min.js +2 -2
  45. package/lib/throttle/index.umd.js +2 -2
  46. package/lib/throttle/index.umd.min.js +2 -2
  47. package/miniprogram/ui-canvas/index.js +100 -107
  48. package/miniprogram/ui-canvas/index.json +4 -4
  49. package/miniprogram/ui-canvas/index.wxml +4 -4
  50. package/miniprogram/ui-canvas/index.wxss +5 -5
  51. package/package/Buffer/index.ts +2 -2
  52. package/package/Canvas/index.ts +2 -2
  53. package/package/Cardinal/index.ts +2 -2
  54. package/package/Eoap/index.ts +2 -2
  55. package/package/Hermite/index.ts +2 -2
  56. package/package/Matrix4/index.ts +2 -2
  57. package/package/Mercator/index.ts +2 -2
  58. package/package/SVG/index.ts +2 -2
  59. package/package/Shader/index.ts +2 -39
  60. package/package/Texture/index.ts +2 -2
  61. package/package/TreeLayout/index.ts +2 -2
  62. package/package/animation/index.ts +2 -2
  63. package/package/getLoopColors/index.ts +2 -2
  64. package/package/index.ts +67 -76
  65. package/package/move/index.ts +2 -2
  66. package/package/resizeObserver/index.ts +2 -2
  67. package/package/rotate/index.ts +2 -2
  68. package/package/ruler/index.ts +2 -2
  69. package/package/scale/index.ts +2 -2
  70. package/package/throttle/index.ts +2 -2
  71. package/package.json +1 -1
  72. package/src/Eoap.ts +66 -66
  73. package/src/Matrix4/index.ts +84 -84
  74. package/src/Matrix4/move.ts +12 -12
  75. package/src/Matrix4/rotate.ts +15 -15
  76. package/src/Matrix4/scale.ts +11 -11
  77. package/src/Matrix4/transform.ts +64 -64
  78. package/src/Mercator.ts +27 -27
  79. package/src/SVG.ts +24 -24
  80. package/src/animation.ts +98 -98
  81. package/src/common/assemble.ts +22 -22
  82. package/src/common/canvas/arc.ts +51 -51
  83. package/src/common/canvas/config.ts +158 -158
  84. package/src/common/canvas/gradient.ts +24 -29
  85. package/src/common/canvas/index.ts +1 -12
  86. package/src/common/canvas/texts.ts +18 -18
  87. package/src/common/mergeOption.ts +6 -6
  88. package/src/common/setStyle.ts +5 -5
  89. package/src/common/svg/config.ts +190 -190
  90. package/src/common/svg/gradient.ts +53 -63
  91. package/src/common/svg/index.ts +347 -356
  92. package/src/common/svg/tool.ts +44 -44
  93. package/src/common/tree/index.ts +25 -25
  94. package/src/common/tree/toInnerTree.ts +59 -59
  95. package/src/common/tree/toPlainTree.ts +132 -132
  96. package/src/common/webgl/buffer.ts +79 -79
  97. package/src/common/webgl/getWebGLContext.ts +1 -1
  98. package/src/common/webgl/shader.ts +75 -75
  99. package/src/common/webgl/texture.ts +97 -97
  100. package/src/formatColor.ts +44 -44
  101. package/src/getLoopColors.ts +42 -42
  102. package/src/interpolation/Cardinal.ts +110 -110
  103. package/src/interpolation/Hermite.ts +65 -65
  104. package/src/layout/TreeLayout.ts +188 -188
  105. package/src/move.ts +7 -7
  106. package/src/resizeObserver.ts +37 -37
  107. package/src/rotate.ts +7 -7
  108. package/src/ruler.ts +209 -209
  109. package/src/scale.ts +6 -6
  110. package/src/throttle.ts +52 -52
  111. package/types/Buffer.d.ts +23 -23
  112. package/types/CanvasConfig.d.ts +106 -106
  113. package/types/CanvasOption.d.ts +8 -8
  114. package/types/CanvasOpts.d.ts +9 -9
  115. package/types/Cardinal.d.ts +13 -13
  116. package/types/Gradient.d.ts +14 -14
  117. package/types/Hermite.d.ts +18 -18
  118. package/types/Map.d.ts +9 -9
  119. package/types/Matrix4.d.ts +47 -47
  120. package/types/SVG.d.ts +238 -238
  121. package/types/SVGConfig.d.ts +79 -79
  122. package/types/Shader.d.ts +16 -23
  123. package/types/Texture.d.ts +16 -16
  124. package/types/Tree.d.ts +69 -69
  125. package/types/TreeConfig.d.ts +36 -36
  126. package/types/TreeLayout.d.ts +54 -54
  127. package/types/TreeOption.d.ts +48 -48
  128. package/types/animation.d.ts +9 -6
  129. package/types/getLoopColors.d.ts +5 -2
  130. package/types/getWebGLContext.d.ts +3 -0
  131. package/types/index.d.ts +149 -176
  132. package/types/move.d.ts +5 -2
  133. package/types/painterConfig.d.ts +2 -2
  134. package/types/resizeObserver.d.ts +5 -2
  135. package/types/rotate.d.ts +5 -2
  136. package/types/ruler.d.ts +10 -7
  137. package/types/scale.d.ts +5 -2
  138. package/types/throttle.d.ts +7 -4
  139. package/types/throttleOption.d.ts +21 -21
  140. package/uni-app/ui-canvas.vue +4 -11
  141. package/lib/Geometry/index.umd.d.ts +0 -3
  142. package/lib/Geometry/index.umd.js +0 -353
  143. package/lib/Geometry/index.umd.min.d.ts +0 -3
  144. package/lib/Geometry/index.umd.min.js +0 -11
  145. package/lib/OralCanvas/index.es.d.ts +0 -3
  146. package/lib/OralCanvas/index.es.js +0 -693
  147. package/lib/OralCanvas/index.es.min.d.ts +0 -3
  148. package/lib/OralCanvas/index.es.min.js +0 -11
  149. package/lib/OralWebGL/index.es.d.ts +0 -3
  150. package/lib/OralWebGL/index.es.js +0 -639
  151. package/lib/OralWebGL/index.es.min.d.ts +0 -3
  152. package/lib/OralWebGL/index.es.min.js +0 -11
  153. package/lib/WebGL/index.umd.d.ts +0 -3
  154. package/lib/WebGL/index.umd.js +0 -712
  155. package/lib/WebGL/index.umd.min.d.ts +0 -3
  156. package/lib/WebGL/index.umd.min.js +0 -11
  157. package/lib/formatColor/index.umd.d.ts +0 -3
  158. package/lib/formatColor/index.umd.js +0 -59
  159. package/lib/formatColor/index.umd.min.d.ts +0 -3
  160. package/lib/formatColor/index.umd.min.js +0 -11
  161. package/lib/viewHandler/index.umd.d.ts +0 -3
  162. package/lib/viewHandler/index.umd.js +0 -139
  163. package/lib/viewHandler/index.umd.min.d.ts +0 -3
  164. package/lib/viewHandler/index.umd.min.js +0 -11
  165. package/package/Geometry/index.ts +0 -3
  166. package/package/OralCanvas/index.ts +0 -3
  167. package/package/OralWebGL/index.ts +0 -3
  168. package/package/WebGL/index.ts +0 -3
  169. package/package/formatColor/index.ts +0 -3
  170. package/package/viewHandler/index.ts +0 -3
  171. package/src/Geometry.ts +0 -211
  172. package/src/WebGL.ts +0 -67
  173. package/src/common/geometry/prism-horizontal.ts +0 -50
  174. package/src/common/geometry/prism-vertical.ts +0 -55
  175. package/src/common/geometry/sphere-fragment.ts +0 -40
  176. package/src/common/geometry/tool/circle.ts +0 -18
  177. package/src/common/geometry/tool/rotateLine.ts +0 -49
  178. package/src/common/geometry/tool/triangles.ts +0 -24
  179. package/src/common/webgl/doDraw.ts +0 -109
  180. package/src/common/webgl/getColorFactory.ts +0 -27
  181. package/src/common/webgl/getShader.ts +0 -49
  182. package/src/common/webgl/getTexture.ts +0 -12
  183. package/src/common/webgl/index.ts +0 -228
  184. package/src/shader/fsColor.c +0 -8
  185. package/src/shader/fsColors.c +0 -8
  186. package/src/shader/fsCube.c +0 -9
  187. package/src/shader/fsImage.c +0 -9
  188. package/src/shader/vsColor.c +0 -18
  189. package/src/shader/vsColors.c +0 -14
  190. package/src/shader/vsCube.c +0 -14
  191. package/src/shader/vsImage.c +0 -14
  192. package/src/viewHandler.ts +0 -161
  193. package/types/Geometry.d.ts +0 -133
  194. package/types/GeometryOption.d.ts +0 -12
  195. package/types/GeometryResult.d.ts +0 -19
  196. package/types/Object3D.d.ts +0 -115
  197. package/types/Scene3D.d.ts +0 -7
  198. package/types/WebGL.d.ts +0 -39
  199. package/types/WebGLOption.d.ts +0 -15
  200. package/types/formatColor.d.ts +0 -3
  201. package/types/viewHandler.d.ts +0 -14
@@ -1,11 +0,0 @@
1
- /*!
2
- * VISLite JavaScript Library v0.8.0
3
- * git+https://github.com/oi-contrib/VISLite.git
4
- *
5
- * Copyright zxl20070701
6
- * Released under the MIT license
7
- * https://zxl20070701.github.io/notebook/home.html
8
- *
9
- * Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
10
- */
11
- var t=function(i,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])},t(i,e)};"function"==typeof SuppressedError&&SuppressedError;var i=function(t,i,e,n,r){var o=Math.cos(e),s=Math.sin(e);return[+((n-t)*o-(r-i)*s+t).toFixed(7),+((n-t)*s+(r-i)*o+i).toFixed(7)]};var e=function(t,i,e,n,r){return t.beginPath(),t.translate(e,n),t.rotate(r),t.font=i.fontStyle+" "+i.fontWeight+" "+i.fontSize+"px "+i.fontFamily,t},n=function(t,e,n,r,o,s,_,a){if(o>s){var h=o;o=s,s=h}return _%=2*Math.PI,a>=1.999999*Math.PI||a<=1.999999*-Math.PI?a=2*Math.PI:a%=2*Math.PI,function(t,e,n,r,o,s,_){e<0&&(t+=e,e*=-1);var a,h=[];a=i(0,0,t,o,0),h[0]=a[0],h[1]=a[1],a=i(0,0,e,a[0],a[1]),h[2]=a[0],h[3]=a[1],a=i(0,0,t,s,0),h[4]=a[0],h[5]=a[1],a=i(0,0,e,a[0],a[1]),h[6]=a[0],h[7]=a[1],_(t,t+e,h[0]+n,h[1]+r,h[4]+n,h[5]+r,h[2]+n,h[3]+r,h[6]+n,h[7]+r,.5*(s-o))}(_,a,n,r,o,s,(function(i,_,a,h,l,p,f,u,g,c,y){y<0&&(y=-y),t.beginPath(),t.moveTo(a,h),t.arc(n,r,o,i,_,!1),"round"==e.arcEndCap?t.arc(.5*(f+g),.5*(u+c),y,_-Math.PI,_,!0):"-round"==e.arcEndCap?t.arc(.5*(f+g),.5*(u+c),y,_-Math.PI,_,!1):t.lineTo(g,c),t.arc(n,r,s,_,i,!0),"round"==e.arcStartCap?t.arc(.5*(a+l),.5*(h+p),y,i,i-Math.PI,!0):"-round"==e.arcStartCap?t.arc(.5*(a+l),.5*(h+p),y,i,i-Math.PI,!1):t.lineTo(a,h)})),"butt"==e.arcStartCap&&t.closePath(),t},r=function(t,i,e,n){return t.beginPath(),t.moveTo(i+n,e),t.arc(i,e,n,0,2*Math.PI),t},o=function(t,i,e,n,r){return t.beginPath(),t.rect(i,e,n,r),t};function s(t,i,e,n,r){for(var o=0,s="",_=0;_<i.length;_++)t.measureText(s+i[_]).width>e||/\n$/.test(s)?(r(s,((o+=1)-.5)*n),s=i[_]):_==i.length-1?(o+=1,r(s+i[_],(o-.5)*n)):s+=i[_];return o*n}var _=function(){function t(t,i,e,n,r){void 0===i&&(i={}),void 0===n&&(n=!1),this.__region=null,this.__onlyRegion=!1,this.__specialConfig={fontSize:16,fontFamily:"sans-serif",fontWeight:400,fontStyle:"normal",arcStartCap:"butt",arcEndCap:"butt"},this.__initConfig={fillStyle:"black",strokeStyle:"black",lineWidth:1,textAlign:"left",textBaseline:"middle",lineDash:[],shadowBlur:0,shadowColor:"black"},this.painter=t.getContext("2d",i),this.__region=e,this.__isPainter=n,this.painter.textBaseline="middle",this.painter.textAlign="left"}return t.prototype.useConfig=function(t,i){if(this.__region&&["fillStyle","strokeStyle","shadowBlur","shadowColor"].indexOf(t)<0&&this.__region.useConfig(t,i),this.__isPainter&&this.__onlyRegion)return this;if("lineDash"==t)this.painter.setLineDash&&this.painter.setLineDash(i);else if(t in this.__specialConfig)"fontSize"==t&&(i=Math.round(i)),this.__specialConfig[t]=i;else{if(!(t in this.__initConfig))throw new Error("Illegal configuration item of painter : "+t+" !");this.painter[t]=i}return this},t.prototype.fillText=function(t,i,n,r){return void 0===r&&(r=0),this.__region&&this.__region.fillText(t,i,n,r),this.__isPainter&&this.__onlyRegion||(this.painter.save(),e(this.painter,this.__specialConfig,i,n,r).fillText(t,0,0),this.painter.restore()),this},t.prototype.strokeText=function(t,i,n,r){return void 0===r&&(r=0),this.__region&&this.__region.strokeText(t,i,n,r),this.__isPainter&&this.__onlyRegion||(this.painter.save(),e(this.painter,this.__specialConfig,i,n,r).strokeText(t,0,0),this.painter.restore()),this},t.prototype.fullText=function(t,i,n,r){return void 0===r&&(r=0),this.__region&&this.__region.fullText(t,i,n,r),this.__isPainter&&this.__onlyRegion||(this.painter.save(),e(this.painter,this.__specialConfig,i,n,r),this.painter.fillText(t,0,0),this.painter.strokeText(t,0,0),this.painter.restore()),this},t.prototype.fillTexts=function(t,i,n,r,o,_){var a=this;void 0===o&&(o=1.2),void 0===_&&(_=0);var h=0;if(this.__region&&(h=this.__region.fillTexts(t,i,n,r,o)),this.__isPainter&&this.__onlyRegion)return h;this.painter.save(),e(this.painter,this.__specialConfig,i,n,_);var l=s(this.painter,t,r,this.__specialConfig.fontSize*o,(function(t,i){a.painter.fillText(t,0,i)}));return this.painter.restore(),l},t.prototype.strokeTexts=function(t,i,n,r,o,_){var a=this;void 0===o&&(o=1.2),void 0===_&&(_=0);var h=0;if(this.__region&&(h=this.__region.fillTexts(t,i,n,r,o)),this.__isPainter&&this.__onlyRegion)return h;this.painter.save(),e(this.painter,this.__specialConfig,i,n,_);var l=s(this.painter,t,r,this.__specialConfig.fontSize*o,(function(t,i){a.painter.strokeText(t,0,i)}));return this.painter.restore(),l},t.prototype.fullTexts=function(t,i,n,r,o,_){var a=this;void 0===o&&(o=1.2),void 0===_&&(_=0);var h=0;if(this.__region&&(h=this.__region.fillTexts(t,i,n,r,o)),this.__isPainter&&this.__onlyRegion)return h;this.painter.save(),e(this.painter,this.__specialConfig,i,n,_);var l=s(this.painter,t,r,this.__specialConfig.fontSize*o,(function(t,i){a.painter.fillText(t,0,i),a.painter.strokeText(t,0,i)}));return this.painter.restore(),l},t.prototype.beginPath=function(){return this.__region&&this.__region.beginPath(),this.__isPainter&&this.__onlyRegion||this.painter.beginPath(),this},t.prototype.closePath=function(){return this.__region&&this.__region.closePath(),this.__isPainter&&this.__onlyRegion||this.painter.closePath(),this},t.prototype.moveTo=function(t,i){return this.__region&&this.__region.moveTo(t,i),this.__isPainter&&this.__onlyRegion||this.painter.moveTo(Math.round(t)+.5,Math.round(i)+.5),this},t.prototype.lineTo=function(t,i){return this.__region&&this.__region.lineTo(t,i),this.__isPainter&&this.__onlyRegion||this.painter.lineTo(Math.round(t)+.5,Math.round(i)+.5),this},t.prototype.arc=function(t,i,e,n,r){return this.__region&&this.__region.arc(t,i,e,n,r),this.__isPainter&&this.__onlyRegion||this.painter.arc(t,i,e,n,n+r,r<0),this},t.prototype.fill=function(){return this.__region&&this.__region.fill(),this.__isPainter&&this.__onlyRegion||this.painter.fill(),this},t.prototype.stroke=function(){return this.__region&&this.__region.stroke(),this.__isPainter&&this.__onlyRegion||this.painter.stroke(),this},t.prototype.full=function(){return this.__region&&this.__region.full(),this.__isPainter&&this.__onlyRegion||(this.painter.fill(),this.painter.stroke()),this},t.prototype.save=function(){return this.__region&&this.__region.save(),this.__isPainter&&this.__onlyRegion||this.painter.save(),this},t.prototype.restore=function(){return this.__region&&this.__region.restore(),this.__isPainter&&this.__onlyRegion||this.painter.restore(),this},t.prototype.clip=function(){return this.__region&&this.__region.clip(),this.__isPainter&&this.__onlyRegion||this.painter.clip(),this},t.prototype.quadraticCurveTo=function(t,i,e,n){return this.__region&&this.__region.quadraticCurveTo(t,i,e,n),this.__isPainter&&this.__onlyRegion||this.painter.quadraticCurveTo(t,i,e,n),this},t.prototype.bezierCurveTo=function(t,i,e,n,r,o){return this.__region&&this.__region.bezierCurveTo(t,i,e,n,r,o),this.__isPainter&&this.__onlyRegion||this.painter.bezierCurveTo(t,i,e,n,r,o),this},t.prototype.clearRect=function(t,i,e,n){return this.__region&&this.__region.clearRect(t,i,e,n),this.__isPainter&&this.__onlyRegion||this.painter.clearRect(t,i,e,n),this},t.prototype.fillArc=function(t,i,e,r,o,s){return this.__region&&this.__region.fillArc(t,i,e,r,o,s),this.__isPainter&&this.__onlyRegion||n(this.painter,this.__specialConfig,t,i,e,r,o,s).fill(),this},t.prototype.strokeArc=function(t,i,e,r,o,s){return this.__region&&this.__region.strokeArc(t,i,e,r,o,s),this.__isPainter&&this.__onlyRegion||n(this.painter,this.__specialConfig,t,i,e,r,o,s).stroke(),this},t.prototype.fullArc=function(t,i,e,r,o,s){return this.__region&&this.__region.fullArc(t,i,e,r,o,s),this.__isPainter&&this.__onlyRegion||(n(this.painter,this.__specialConfig,t,i,e,r,o,s),this.painter.fill(),this.painter.stroke()),this},t.prototype.fillCircle=function(t,i,e){return this.__region&&this.__region.fillCircle(t,i,e),this.__isPainter&&this.__onlyRegion||r(this.painter,t,i,e).fill(),this},t.prototype.strokeCircle=function(t,i,e){return this.__region&&this.__region.strokeCircle(t,i,e),this.__isPainter&&this.__onlyRegion||r(this.painter,t,i,e).stroke(),this},t.prototype.fullCircle=function(t,i,e){return this.__region&&this.__region.fullCircle(t,i,e),this.__isPainter&&this.__onlyRegion||(r(this.painter,t,i,e),this.painter.fill(),this.painter.stroke()),this},t.prototype.fillRect=function(t,i,e,n){return this.__region&&this.__region.fillRect(t,i,e,n),this.__isPainter&&this.__onlyRegion||o(this.painter,t,i,e,n).fill(),this},t.prototype.strokeRect=function(t,i,e,n){return this.__region&&this.__region.strokeRect(t,i,e,n),this.__isPainter&&this.__onlyRegion||o(this.painter,t,i,e,n).stroke(),this},t.prototype.fullRect=function(t,i,e,n){return this.__region&&this.__region.fullRect(t,i,e,n),this.__isPainter&&this.__onlyRegion||(o(this.painter,t,i,e,n),this.painter.fill(),this.painter.stroke()),this},t.prototype.draw=function(){},t.prototype.drawImage=function(t,i,e,n,r,o){var s=this;return void 0===o&&(o=!1),new Promise((function(_){if(s.__region&&(s.__region.fillRect(i,e,n,r),_({})),s.__isPainter&&s.__onlyRegion)return s;if("string"!=typeof t||o)s.painter.drawImage(t,i,e,n,r),_({});else{var a=new Image;a.onload=function(){s.painter.drawImage(a,i,e,n,r),_({})},a.src=t}}))},t}();var a={"font-size":"fontSize","font-family":"fontFamily","font-weight":"fontWeight","font-style":"fontStyle","arc-start-cap":"arcStartCap","arc-end-cap":"arcEndCap"},h=function(i){function n(t,e,n,r){void 0===n&&(n={}),void 0===r&&(r=1);var o=i.call(this,t,n,e?new _(e,{willReadFrequently:!0}):void 0,!0,r)||this;return o.name="Canvas",o.__regionList={},o.__regionAssemble=function(t,i,e,n){for(var r=[],o=0;o<n;o++)r[o]=t;return function(){for(var o=0;o<n;o++){if(r[o]+e<i){r[o]=+(r[o]+e).toFixed(7);break}o<n-1&&(r[o]=t)}return r}}(0,255,10,3),o.__scaleSize=r,o.setRegion(""),o}return function(i,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(n,i),n.prototype.config=function(t){for(var i in t){var e=a[i]||i;this.useConfig(e,t[i])}return this},n.prototype.onlyRegion=function(t){return this.__onlyRegion=t,this},n.prototype.setRegion=function(t){if(this.__region)if(t){if(null==this.__regionList[t]){var i=this.__regionAssemble();this.__regionList[t]="rgb("+i[0]+","+i[1]+","+i[2]+")"}this.__region.useConfig("fillStyle",this.__regionList[t])&&this.__region.useConfig("strokeStyle",this.__regionList[t])}else this.__region.useConfig("fillStyle","#000000")&&this.__region.useConfig("strokeStyle","#000000");return this},n.prototype.getRegion=function(t,i){var e=this;return new Promise((function(n){var r=e.__region?e.__region.painter.getImageData(t-.5,i-.5,1,1):{data:[0,0,0,0]},o=r.data,s=function(){if(e.__region)for(var t in e.__regionList)if("rgb("+o[0]+","+o[1]+","+o[2]+")"==e.__regionList[t]){n(t);break}n("")};o?s():r.then((function(t){o=t,s()}))}))},n.prototype.textWidth=function(t){this.painter.save(),e(this.painter,this.__specialConfig,0,0,0);var i=this.painter.measureText(t+"").width;return this.painter.restore(),i},n.prototype.getContext=function(t){return void 0===t&&(t=!1),t?this.__region?this.__region.painter:null:this.painter},n.prototype.getInfo=function(){return{width:this.painter.canvas.width/this.__scaleSize,height:this.painter.canvas.height/this.__scaleSize}},n.prototype.createLinearGradient=function(t,i,e,n){return function(t,i,e,n,r){var o=t.createLinearGradient(i,e,n,r),s={value:function(){return o},setColor:function(t,i){return o.addColorStop(t,i),s}};return s}(this.painter,t,i,e,n)},n.prototype.createRadialGradient=function(t,i,e){return function(t,i,e,n){var r=t.createRadialGradient(i,e,0,i,e,n),o={value:function(){return r},setColor:function(t,i){return r.addColorStop(t,i),o}};return o}(this.painter,t,i,e)},n.prototype.getColor=function(t,i){t*=this.__scaleSize,i*=this.__scaleSize;var e=this.painter.getImageData(t-.5,i-.5,1,1).data;return"rgba("+e[0]+","+e[1]+","+e[2]+","+e[3]+")"},n}(_);export{h as default};
@@ -1,3 +0,0 @@
1
- import { OralWebGL } from "../../types/index"
2
-
3
- export default OralWebGL
@@ -1,639 +0,0 @@
1
- /*!
2
- * VISLite JavaScript Library v0.8.0
3
- * git+https://github.com/oi-contrib/VISLite.git
4
- *
5
- * Copyright zxl20070701
6
- * Released under the MIT license
7
- * https://zxl20070701.github.io/notebook/home.html
8
- *
9
- * Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
10
- */
11
- /******************************************************************************
12
- Copyright (c) Microsoft Corporation.
13
-
14
- Permission to use, copy, modify, and/or distribute this software for any
15
- purpose with or without fee is hereby granted.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
18
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
19
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
20
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
21
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
- PERFORMANCE OF THIS SOFTWARE.
24
- ***************************************************************************** */
25
- /* global Reflect, Promise, SuppressedError, Symbol */
26
-
27
-
28
- function __spreadArray(to, from, pack) {
29
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
- if (ar || !(i in from)) {
31
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
- ar[i] = from[i];
33
- }
34
- }
35
- return to.concat(ar || Array.prototype.slice.call(from));
36
- }
37
-
38
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
39
- var e = new Error(message);
40
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
41
- };
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;
82
- }
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
- };
96
- }
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
- ];
107
- }
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
- ];
117
- }
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
- ];
129
- }
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
- }
168
- }
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;
229
- }());
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;
265
- }());
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;
319
- }());
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];
328
- }
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;
364
- }());
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}";
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}";
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}";
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}";
373
-
374
- var fsColor = "precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}";
375
-
376
- var fsColors = "precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}";
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}";
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}";
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;
407
- }
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
- }
458
- }
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
- };
476
- }
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;
637
- }());
638
-
639
- export { WebGL as default };