vislite 0.2.0-alpha.7 → 0.2.0-alpha.8

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 (41) hide show
  1. package/CHANGELOG +1 -0
  2. package/lib/Canvas/index.umd.js +1 -1
  3. package/lib/Canvas/index.umd.min.js +1 -1
  4. package/lib/Cardinal/index.umd.js +1 -1
  5. package/lib/Cardinal/index.umd.min.js +1 -1
  6. package/lib/Eoap/index.umd.js +1 -1
  7. package/lib/Eoap/index.umd.min.js +1 -1
  8. package/lib/Hermite/index.umd.js +1 -1
  9. package/lib/Hermite/index.umd.min.js +1 -1
  10. package/lib/Matrix4/index.umd.js +1 -1
  11. package/lib/Matrix4/index.umd.min.js +1 -1
  12. package/lib/Mercator/index.umd.js +1 -1
  13. package/lib/Mercator/index.umd.min.js +1 -1
  14. package/lib/OralCanvas/index.es.js +1 -1
  15. package/lib/OralCanvas/index.es.min.js +1 -1
  16. package/lib/OralWebGL/index.es.js +5 -4
  17. package/lib/OralWebGL/index.es.min.js +2 -2
  18. package/lib/SVG/index.umd.js +1 -1
  19. package/lib/SVG/index.umd.min.js +1 -1
  20. package/lib/WebGL/index.umd.js +5 -4
  21. package/lib/WebGL/index.umd.min.js +2 -2
  22. package/lib/animation/index.umd.js +1 -1
  23. package/lib/animation/index.umd.min.js +1 -1
  24. package/lib/getLoopColors/index.umd.js +1 -1
  25. package/lib/getLoopColors/index.umd.min.js +1 -1
  26. package/lib/index.umd.js +7 -6
  27. package/lib/index.umd.min.js +2 -2
  28. package/lib/rotate/index.umd.js +1 -1
  29. package/lib/rotate/index.umd.min.js +1 -1
  30. package/lib/ruler/index.umd.js +1 -1
  31. package/lib/ruler/index.umd.min.js +1 -1
  32. package/lib/viewHandler/index.umd.js +3 -3
  33. package/lib/viewHandler/index.umd.min.js +2 -2
  34. package/package.json +1 -1
  35. package/src/common/webgl/getShader.ts +9 -1
  36. package/src/common/webgl/index.ts +4 -3
  37. package/src/common/webgl/texture.ts +1 -0
  38. package/src/viewHandler.ts +2 -2
  39. package/types/Object3D.d.ts +3 -2
  40. package/types/WebGL.d.ts +10 -0
  41. package/uni-app/ui-canvas.vue +55 -31
package/CHANGELOG CHANGED
@@ -26,6 +26,7 @@ v0.2.0:
26
26
  1、为解决this问题,同时优化参数内容,修改了uni-app和微信小程序组件ui-canvas事件语法
27
27
  (对旧语法进行了向下兼容)
28
28
  2、校对types中定义的类型信息
29
+ 3、修复uni-app组件ui-canvas在支付宝小程序区域计算相关错误
29
30
  - 优化改造
30
31
  1、针对Canvas和SVG的画笔配置config的属性名,统一使用小驼峰
31
32
  (对旧语法进行了向下兼容)
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -276,6 +276,7 @@ var TextureObject = (function () {
276
276
  }[type];
277
277
  this.__texture = initTexture(painter, this.__type, unit);
278
278
  painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
279
+ painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
279
280
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
280
281
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
281
282
  }
@@ -344,7 +345,7 @@ function getShader (type, painter, mesh) {
344
345
  (mesh.material.cube ? "1" : "0");
345
346
  if (shaders[uniqueName])
346
347
  return shaders[uniqueName].use();
347
- var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : '', "\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n void main(){\n vec4 temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\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 ").concat(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n }\n ");
348
+ var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : '', "\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n void main(){\n vec4 temp = a_position;\n\n // \u5E94\u7528\u53D8\u6362\u77E9\u9635\uFF1A\u5C4F\u5E55\u6BD4\u8C03\u5E73\u77E9\u9635\u3001\u4E16\u754C\u77E9\u9635\u3001\u7269\u4F53\u77E9\u9635\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\n\n // \u628A\u539F\u751F\u7684WebGL\u4F7F\u7528\u7684\u5DE6\u624B\u5750\u6807\u7CFB\u53D8\u6210\u4E86\u53F3\u624B\u5750\u6807\u7CFB\n temp.z = -1.0 * temp.z;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\n // \u4E3A\u4FDD\u8BC1\u7EB9\u7406\u548C\u76F8\u5BF9\u4F4D\u7F6E\u6B63\u786E\n // x\u3001y\u3001z\u7684\u6539\u53D8\u6EE1\u8DB3\u7EBF\u6027\u53D8\u6362\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 ").concat(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n }\n ");
348
349
  var fragmentShader = "\n precision mediump float;\n\n ".concat(mesh.geometry.attributes.normal ? 'varying vec3 v_normal;' : '', "\n ").concat(mesh.material.color ? 'uniform vec4 u_color;' : '', "\n ").concat(mesh.material.cube ? 'uniform samplerCube u_texture;' : '', "\n ").concat(mesh.material.image ? 'uniform sampler2D u_sampler;varying vec2 v_textcoord;' : '', "\n\n void main(){\n ").concat(mesh.material.color ? 'gl_FragColor = u_color;' : '', "\n ").concat(mesh.material.cube ? 'gl_FragColor = textureCube(u_texture,normalize(v_normal));' : '', "\n ").concat(mesh.material.image ? 'gl_FragColor = texture2D(u_sampler,v_textcoord);' : '', "\n }\n ");
349
350
  var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
350
351
  shaders[uniqueName] = shader;
@@ -428,7 +429,7 @@ var WebGL = (function () {
428
429
  matrix: new Matrix4([
429
430
  1, 0, 0, 0,
430
431
  0, 1, 0, 0,
431
- 0, 0, -1, 0,
432
+ 0, 0, 1, 0,
432
433
  0, 0, 0, scale
433
434
  ])
434
435
  };
@@ -501,12 +502,12 @@ var WebGL = (function () {
501
502
  }
502
503
  }
503
504
  }, meshWorld, globalWorld);
505
+ this.__getColor = getColorFactory(this.__regionPainter);
504
506
  }
505
507
  else {
506
508
  doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
507
509
  }
508
510
  }
509
- this.__getColor = getColorFactory(this.__regionPainter);
510
511
  };
511
512
  WebGL.prototype.render = function (object3D) {
512
513
  if (!('matrix' in object3D))
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -12,4 +12,4 @@
12
12
  * alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
13
13
  * beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
14
14
  */
15
- function t(t,r,e){if(e||2===arguments.length)for(var i,o=0,a=r.length;o<a;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,a=0;a<i.length;a++){try{o=t.getContext(i[a],e)}catch(t){}if(o)break}if(!o)throw new Error("Non canvas or browser does not support webgl.");var n=o.canvas.width,_=o.canvas.height,u=n*r,s=_*r;return o.viewport(.5*(n-u),.5*(_-s),u,s),o.depthFunc(o.LEQUAL),o.enable(o.DEPTH_TEST),o}var e=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},i=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,i,o){return void 0===o&&(o=0),this.__matrix4=e(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,i,o),this.__matrix4),this},t.prototype.rotate=function(t,r,i,o,a,n,_){var u=function(t,r,e,i,o,a){if("number"==typeof t&&"number"==typeof r){if("number"!=typeof e?(e=0,i=t,o=r,a=1):"number"==typeof i&&"number"==typeof o&&"number"==typeof a||(i=t,o=r,a=e,t=0,r=0,e=0),t==i&&r==o&&e==a)throw new Error("It's not a legitimate ray!");var n=Math.sqrt((i-t)*(i-t)+(o-r)*(o-r)),_=0!=n?(o-r)/n:1,u=0!=n?(i-t)/n:0,s=(i-t)*u+(o-r)*_,m=a-e,c=Math.sqrt(s*s+m*m),h=0!=c?m/c:1,l=0!=c?s/c:0;return[[_,h*u,u*l,0,-u,_*h,_*l,0,0,-l,h,0,r*u-t*_,e*l-t*u*h-r*_*h,-t*u*l-r*_*l-e*h,1],[_,-u,0,0,h*u,h*_,-l,0,u*l,_*l,h,0,t,r,e,1]]}throw new Error("a1 and b1 is required!")}(r,i,o,a,n,_);return this.__matrix4=e(e(e(u[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)),u[0]),this.__matrix4),this},t.prototype.scale=function(t,r,i,o,a,n){return void 0===o&&(o=0),void 0===a&&(a=0),void 0===n&&(n=0),this.__matrix4=e(function(t,r,e,i,o,a){return void 0===i&&(i=0),void 0===o&&(o=0),void 0===a&&(a=0),[t,0,0,0,0,r,0,0,0,0,e,0,i-i*t,o-o*r,a-a*e,1]}(t,r,i,o,a,n),this.__matrix4),this},t.prototype.multiply=function(t,r){return void 0===r&&(r=!1),this.__matrix4=r?e(this.__matrix4,t):e(t,this.__matrix4),this},t.prototype.use=function(t,r,i,o){return void 0===i&&(i=0),void 0===o&&(o=1),e(this.__matrix4,[t,r,i,o])},t.prototype.value=function(){return this.__matrix4},t}(),o=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,a,n){t.vertexAttribPointer(r,e,i,n,o,a),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 r==t.TEXTURE_2D&&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_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,a){t.texImage2D(r,e,i,i,o,a)}(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,a,n,_,u){for(var s,m=[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],c=0;c<m.length;c++)a[c]&&(s=m[c],t.texImage2D(s,e,i,n,_,0,i,o,null),t.bindTexture(r,u),t.texImage2D(s,e,i,i,o,a[c]));t.generateMipmap(r)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,r,e,this.__texture),this},t}(),n={};function _(t,r,e){var i=t+"-"+e;return n[i]||(n[i]=new a(r,e)),n[i]}var u=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},s=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=u(t,t.VERTEX_SHADER,r),o=u(t,t.FRAGMENT_SHADER,e),a=t.createProgram();if(t.attachShader(a,i),t.attachShader(a,o),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(a));return a}(this.__painter,t,r),this},t}(),m={};function c(t,r,e,i,a){var n=function(t,r,e){var i=t+(e.geometry.attributes.normal?"1":"0")+(e.material.image?"1":"0")+(e.material.color?"1":"0")+(e.material.cube?"1":"0");if(m[i])return m[i].use();var o="\n attribute vec4 a_position;\n\n ".concat(e.geometry.attributes.normal?"attribute vec4 a_normal;varying vec3 v_normal;":"","\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(e.material.image?"attribute vec2 a_textcoord;varying vec2 v_textcoord;":"","\n\n void main(){\n vec4 temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position;\n\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\n float dist = 4.0;\n\n // 使用投影直接计算\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 ").concat(e.geometry.attributes.normal?"v_normal = normalize(vec3(a_normal));":"","\n ").concat(e.material.image?"v_textcoord = a_textcoord;":"","\n }\n "),a="\n precision mediump float;\n\n ".concat(e.geometry.attributes.normal?"varying vec3 v_normal;":"","\n ").concat(e.material.color?"uniform vec4 u_color;":"","\n ").concat(e.material.cube?"uniform samplerCube u_texture;":"","\n ").concat(e.material.image?"uniform sampler2D u_sampler;varying vec2 v_textcoord;":"","\n\n void main(){\n ").concat(e.material.color?"gl_FragColor = u_color;":"","\n ").concat(e.material.cube?"gl_FragColor = textureCube(u_texture,normalize(v_normal));":"","\n ").concat(e.material.image?"gl_FragColor = texture2D(u_sampler,v_textcoord);":"","\n }\n "),n=new s(r).compile(o,a).use();return m[i]=n,n}(t,r,e);if(new o(r).use().write(e.geometry.attributes.position.array).divide(r.getAttribLocation(n.program,"a_position"),e.geometry.attributes.position.itemSize,3,0),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_world"),!1,a.matrix),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_proporion"),!1,a.proporion),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new o(r).use().write(e.geometry.attributes.normal.array).divide(r.getAttribLocation(n.program,"a_normal"),e.geometry.attributes.normal.itemSize,3,0),"color"in e.material)r.uniform4f(r.getUniformLocation(n.program,"u_color"),e.material.color.r,e.material.color.g,e.material.color.b,e.material.color.alpha);else if("cube"in e.material){var u=e.material.cube.right.image.value.width;_(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],u,u)}else"image"in e.material&&(r.uniform1i(r.getUniformLocation(n.program,"u_sampler"),0),new o(r).use().write(e.geometry.attributes.uv.array).divide(r.getAttribLocation(n.program,"a_textcoord"),e.geometry.attributes.uv.itemSize,2,0),_(t,r,"2d").useImage(e.material.image.value));e.geometry.index?(new o(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 h=!1,l=function(){function e(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=[],a=0;a<i;a++)o[a]=t;return function(){for(var a=0;a<i;a++){if(o[a]<r){o[a]=+(o[a]+e).toFixed(7);break}a<i-1&&(o[a]=t)}return o}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new i([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),this.__regionPainter=r(e,10,{});var o=this.painter.canvas.width/this.painter.canvas.height,a=1,n=1;o>1?a=1/o:n=o;var _=Math.min(a,n);this.__proporion=[a,0,0,0,0,n,0,0,0,0,_,0,0,0,0,1]}return e.prototype.matrix=function(t){return new i(t)},e.prototype.getMatrix=function(){return this.__scene.matrix},e.prototype.getObject3D=function(){return this.__scene.children},e.prototype.review=function(t){void 0===t&&(t=!1),t?(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},e.prototype.draw=function(t,r){void 0===r&&(r=!1),r||(h=!0);var e,i,o,a,n={matrix:t.matrix.value()},_={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var u=0;u<t.mesh.length;u++)r?c("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[u].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},n,_):c("region"+this.__unique,this.painter,t.mesh[u],n,_);this.__getColor=(e=this.__regionPainter,i=e.drawingBufferWidth,o=e.drawingBufferHeight,a=new Uint8Array(4*i*o),e.readPixels(0,0,i,o,e.RGBA,e.UNSIGNED_BYTE,a),function(t,r){return"rgba("+a[4*((r=o-r)*i+t)]+","+a[4*(r*i+t)+1]+","+a[4*(r*i+t)+2]+","+a[4*(r*i+t)+3]+")"})},e.prototype.render=function(t){"matrix"in t||(t.matrix=new i),"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))}this.__scene.children.push(t),this.draw(t)},e.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},e.prototype.getRegion=function(t,r){var e=this;return h&&this.review(!0),h=!1,new Promise((function(i,o){var a=e.__getColor(t,r);for(var n in e.__regionList){var _=e.__regionList[n];if("rgba("+255*_[0]+","+255*_[1]+","+255*_[2]+","+255*_[3]+")"==a){i(n);break}}i("")}))},e}();export{l as default};
15
+ function t(t,r,e){if(e||2===arguments.length)for(var i,a=0,o=r.length;a<o;a++)!i&&a in r||(i||(i=Array.prototype.slice.call(r,0,a)),i[a]=r[a]);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"],a=null,o=0;o<i.length;o++){try{a=t.getContext(i[o],e)}catch(t){}if(a)break}if(!a)throw new Error("Non canvas or browser does not support webgl.");var n=a.canvas.width,_=a.canvas.height,u=n*r,s=_*r;return a.viewport(.5*(n-u),.5*(_-s),u,s),a.depthFunc(a.LEQUAL),a.enable(a.DEPTH_TEST),a}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,a){return"rgba("+i[4*((a=e-a)*r+t)]+","+i[4*(a*r+t)+1]+","+i[4*(a*r+t)+2]+","+i[4*(a*r+t)+3]+")"}}var i=function(t,r){for(var e=[],i=0;i<4;i++)for(var a=0;a<r.length/4;a++)e[4*a+i]=t[i]*r[4*a]+t[i+4]*r[4*a+1]+t[i+8]*r[4*a+2]+t[i+12]*r[4*a+3];return e},a=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,a){return void 0===a&&(a=0),this.__matrix4=i(function(t,r,e,i){void 0===i&&(i=0);var a=Math.sqrt(r*r+e*e+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,r*t/a,e*t/a,i*t/a,1]}(t,r,e,a),this.__matrix4),this},t.prototype.rotate=function(t,r,e,a,o,n,_){var u=function(t,r,e,i,a,o){if("number"==typeof t&&"number"==typeof r){if("number"!=typeof e?(e=0,i=t,a=r,o=1):"number"==typeof i&&"number"==typeof a&&"number"==typeof o||(i=t,a=r,o=e,t=0,r=0,e=0),t==i&&r==a&&e==o)throw new Error("It's not a legitimate ray!");var n=Math.sqrt((i-t)*(i-t)+(a-r)*(a-r)),_=0!=n?(a-r)/n:1,u=0!=n?(i-t)/n:0,s=(i-t)*u+(a-r)*_,m=o-e,c=Math.sqrt(s*s+m*m),h=0!=c?m/c:1,l=0!=c?s/c:0;return[[_,h*u,u*l,0,-u,_*h,_*l,0,0,-l,h,0,r*u-t*_,e*l-t*u*h-r*_*h,-t*u*l-r*_*l-e*h,1],[_,-u,0,0,h*u,h*_,-l,0,u*l,_*l,h,0,t,r,e,1]]}throw new Error("a1 and b1 is required!")}(r,e,a,o,n,_);return this.__matrix4=i(i(i(u[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)),u[0]),this.__matrix4),this},t.prototype.scale=function(t,r,e,a,o,n){return void 0===a&&(a=0),void 0===o&&(o=0),void 0===n&&(n=0),this.__matrix4=i(function(t,r,e,i,a,o){return void 0===i&&(i=0),void 0===a&&(a=0),void 0===o&&(o=0),[t,0,0,0,0,r,0,0,0,0,e,0,i-i*t,a-a*r,o-o*e,1]}(t,r,e,a,o,n),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,a){return void 0===e&&(e=0),void 0===a&&(a=1),i(this.__matrix4,[t,r,e,a])},t.prototype.value=function(){return this.__matrix4},t}(),o=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 a=e?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(a,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,a,o,n){t.vertexAttribPointer(r,e,i,n,a,o),t.enableVertexAttribArray(r)}(this.__painter,t,r,this.__painter.FLOAT,e*this.__fsize,i*this.__fsize,!1),this},t}(),n=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 r==t.TEXTURE_2D&&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,a,o){t.texImage2D(r,e,i,i,a,o)}(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,a,o,n,_,u){for(var s,m=[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],c=0;c<m.length;c++)o[c]&&(s=m[c],t.texImage2D(s,e,i,n,_,0,i,a,null),t.bindTexture(r,u),t.texImage2D(s,e,i,i,a,o[c]));t.generateMipmap(r)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,r,e,this.__texture),this},t}(),_={};function u(t,r,e){var i=t+"-"+e;return _[i]||(_[i]=new n(r,e)),_[i]}var s=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},m=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=s(t,t.VERTEX_SHADER,r),a=s(t,t.FRAGMENT_SHADER,e),o=t.createProgram();if(t.attachShader(o,i),t.attachShader(o,a),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(o));return o}(this.__painter,t,r),this},t}(),c={};function h(t,r,e,i,a){var n=function(t,r,e){var i=t+(e.geometry.attributes.normal?"1":"0")+(e.material.image?"1":"0")+(e.material.color?"1":"0")+(e.material.cube?"1":"0");if(c[i])return c[i].use();var a="\n attribute vec4 a_position;\n\n ".concat(e.geometry.attributes.normal?"attribute vec4 a_normal;varying vec3 v_normal;":"","\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(e.material.image?"attribute vec2 a_textcoord;varying vec2 v_textcoord;":"","\n\n void main(){\n vec4 temp = a_position;\n\n // 应用变换矩阵:屏幕比调平矩阵、世界矩阵、物体矩阵\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\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\n ").concat(e.geometry.attributes.normal?"v_normal = normalize(vec3(a_normal));":"","\n ").concat(e.material.image?"v_textcoord = a_textcoord;":"","\n }\n "),o="\n precision mediump float;\n\n ".concat(e.geometry.attributes.normal?"varying vec3 v_normal;":"","\n ").concat(e.material.color?"uniform vec4 u_color;":"","\n ").concat(e.material.cube?"uniform samplerCube u_texture;":"","\n ").concat(e.material.image?"uniform sampler2D u_sampler;varying vec2 v_textcoord;":"","\n\n void main(){\n ").concat(e.material.color?"gl_FragColor = u_color;":"","\n ").concat(e.material.cube?"gl_FragColor = textureCube(u_texture,normalize(v_normal));":"","\n ").concat(e.material.image?"gl_FragColor = texture2D(u_sampler,v_textcoord);":"","\n }\n "),n=new m(r).compile(a,o).use();return c[i]=n,n}(t,r,e);if(new o(r).use().write(e.geometry.attributes.position.array).divide(r.getAttribLocation(n.program,"a_position"),e.geometry.attributes.position.itemSize,3,0),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_world"),!1,a.matrix),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_proporion"),!1,a.proporion),r.uniformMatrix4fv(r.getUniformLocation(n.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new o(r).use().write(e.geometry.attributes.normal.array).divide(r.getAttribLocation(n.program,"a_normal"),e.geometry.attributes.normal.itemSize,3,0),"color"in e.material)r.uniform4f(r.getUniformLocation(n.program,"u_color"),e.material.color.r,e.material.color.g,e.material.color.b,e.material.color.alpha);else if("cube"in e.material){var _=e.material.cube.right.image.value.width;u(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(n.program,"u_sampler"),0),new o(r).use().write(e.geometry.attributes.uv.array).divide(r.getAttribLocation(n.program,"a_textcoord"),e.geometry.attributes.uv.itemSize,2,0),u(t,r,"2d").useImage(e.material.image.value));e.geometry.index?(new o(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 l=!1,g=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 a=[],o=0;o<i;o++)a[o]=t;return function(){for(var o=0;o<i;o++){if(a[o]<r){a[o]=+(a[o]+e).toFixed(7);break}o<i-1&&(a[o]=t)}return a}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new a([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),this.__regionPainter=r(e,10,{});var i=this.painter.canvas.width/this.painter.canvas.height,o=1,n=1;i>1?o=1/i:n=i;var _=Math.min(o,n);this.__proporion=[o,0,0,0,0,n,0,0,0,0,_,0,0,0,0,1]}return i.prototype.matrix=function(t){return new a(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.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||(l=!0);var i={matrix:t.matrix.value()},a={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var o=0;o<t.mesh.length;o++)r?(h("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[o].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},i,a),this.__getColor=e(this.__regionPainter)):h("region"+this.__unique,this.painter,t.mesh[o],i,a)},i.prototype.render=function(t){"matrix"in t||(t.matrix=new a),"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))}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 l&&this.review(!0),l=!1,new Promise((function(i,a){var o=e.__getColor(t,r);for(var n in e.__regionList){var _=e.__regionList[n];if("rgba("+255*_[0]+","+255*_[1]+","+255*_[2]+","+255*_[3]+")"==o){i(n);break}}i("")}))},i}();export{g as default};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -298,6 +298,7 @@
298
298
  }[type];
299
299
  this.__texture = initTexture(painter, this.__type, unit);
300
300
  painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
301
+ painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
301
302
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
302
303
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
303
304
  }
@@ -366,7 +367,7 @@
366
367
  (mesh.material.cube ? "1" : "0");
367
368
  if (shaders[uniqueName])
368
369
  return shaders[uniqueName].use();
369
- var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : '', "\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n void main(){\n vec4 temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\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 ").concat(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n }\n ");
370
+ var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : '', "\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n void main(){\n vec4 temp = a_position;\n\n // \u5E94\u7528\u53D8\u6362\u77E9\u9635\uFF1A\u5C4F\u5E55\u6BD4\u8C03\u5E73\u77E9\u9635\u3001\u4E16\u754C\u77E9\u9635\u3001\u7269\u4F53\u77E9\u9635\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\n\n // \u628A\u539F\u751F\u7684WebGL\u4F7F\u7528\u7684\u5DE6\u624B\u5750\u6807\u7CFB\u53D8\u6210\u4E86\u53F3\u624B\u5750\u6807\u7CFB\n temp.z = -1.0 * temp.z;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\n // \u4E3A\u4FDD\u8BC1\u7EB9\u7406\u548C\u76F8\u5BF9\u4F4D\u7F6E\u6B63\u786E\n // x\u3001y\u3001z\u7684\u6539\u53D8\u6EE1\u8DB3\u7EBF\u6027\u53D8\u6362\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 ").concat(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n }\n ");
370
371
  var fragmentShader = "\n precision mediump float;\n\n ".concat(mesh.geometry.attributes.normal ? 'varying vec3 v_normal;' : '', "\n ").concat(mesh.material.color ? 'uniform vec4 u_color;' : '', "\n ").concat(mesh.material.cube ? 'uniform samplerCube u_texture;' : '', "\n ").concat(mesh.material.image ? 'uniform sampler2D u_sampler;varying vec2 v_textcoord;' : '', "\n\n void main(){\n ").concat(mesh.material.color ? 'gl_FragColor = u_color;' : '', "\n ").concat(mesh.material.cube ? 'gl_FragColor = textureCube(u_texture,normalize(v_normal));' : '', "\n ").concat(mesh.material.image ? 'gl_FragColor = texture2D(u_sampler,v_textcoord);' : '', "\n }\n ");
371
372
  var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
372
373
  shaders[uniqueName] = shader;
@@ -450,7 +451,7 @@
450
451
  matrix: new Matrix4([
451
452
  1, 0, 0, 0,
452
453
  0, 1, 0, 0,
453
- 0, 0, -1, 0,
454
+ 0, 0, 1, 0,
454
455
  0, 0, 0, scale
455
456
  ])
456
457
  };
@@ -523,12 +524,12 @@
523
524
  }
524
525
  }
525
526
  }, meshWorld, globalWorld);
527
+ this.__getColor = getColorFactory(this.__regionPainter);
526
528
  }
527
529
  else {
528
530
  doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
529
531
  }
530
532
  }
531
- this.__getColor = getColorFactory(this.__regionPainter);
532
533
  };
533
534
  WebGL.prototype.render = function (object3D) {
534
535
  if (!('matrix' in object3D))
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -12,4 +12,4 @@
12
12
  * alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
13
13
  * beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
14
14
  */
15
- var t,r;t=this,r=function(){"use strict";var t=function(r,e){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])},t(r,e)};function r(t,r,e){if(e||2===arguments.length)for(var i,n=0,o=r.length;n<o;n++)!i&&n in r||(i||(i=Array.prototype.slice.call(r,0,n)),i[n]=r[n]);return t.concat(i||Array.prototype.slice.call(r))}function e(t,r,e){void 0===e&&(e={});for(var i=["webgl","experimental-webgl","webkit-3d","moz-webgl"],n=null,o=0;o<i.length;o++){try{n=t.getContext(i[o],e)}catch(t){}if(n)break}if(!n)throw new Error("Non canvas or browser does not support webgl.");var a=n.canvas.width,_=n.canvas.height,s=a*r,u=_*r;return n.viewport(.5*(a-s),.5*(_-u),s,u),n.depthFunc(n.LEQUAL),n.enable(n.DEPTH_TEST),n}var i=function(t,r){for(var e=[],i=0;i<4;i++)for(var n=0;n<r.length/4;n++)e[4*n+i]=t[i]*r[4*n]+t[i+4]*r[4*n+1]+t[i+8]*r[4*n+2]+t[i+12]*r[4*n+3];return e},n=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,n){return void 0===n&&(n=0),this.__matrix4=i(function(t,r,e,i){void 0===i&&(i=0);var n=Math.sqrt(r*r+e*e+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,r*t/n,e*t/n,i*t/n,1]}(t,r,e,n),this.__matrix4),this},t.prototype.rotate=function(t,r,e,n,o,a,_){var s=function(t,r,e,i,n,o){if("number"==typeof t&&"number"==typeof r){if("number"!=typeof e?(e=0,i=t,n=r,o=1):"number"==typeof i&&"number"==typeof n&&"number"==typeof o||(i=t,n=r,o=e,t=0,r=0,e=0),t==i&&r==n&&e==o)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((i-t)*(i-t)+(n-r)*(n-r)),_=0!=a?(n-r)/a:1,s=0!=a?(i-t)/a:0,u=(i-t)*s+(n-r)*_,m=o-e,c=Math.sqrt(u*u+m*m),l=0!=c?m/c:1,h=0!=c?u/c:0;return[[_,l*s,s*h,0,-s,_*l,_*h,0,0,-h,l,0,r*s-t*_,e*h-t*s*l-r*_*l,-t*s*h-r*_*h-e*l,1],[_,-s,0,0,l*s,l*_,-h,0,s*h,_*h,l,0,t,r,e,1]]}throw new Error("a1 and b1 is required!")}(r,e,n,o,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,n,o,a){return void 0===n&&(n=0),void 0===o&&(o=0),void 0===a&&(a=0),this.__matrix4=i(function(t,r,e,i,n,o){return void 0===i&&(i=0),void 0===n&&(n=0),void 0===o&&(o=0),[t,0,0,0,0,r,0,0,0,0,e,0,i-i*t,n-n*r,o-o*e,1]}(t,r,e,n,o,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,n){return void 0===e&&(e=0),void 0===n&&(n=1),i(this.__matrix4,[t,r,e,n])},t.prototype.value=function(){return this.__matrix4},t}(),o=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 n=e?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(n,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,n,o,a){t.vertexAttribPointer(r,e,i,a,n,o),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 r==t.TEXTURE_2D&&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_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,n,o){t.texImage2D(r,e,i,i,n,o)}(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,n,o,a,_,s){for(var u,m=[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],c=0;c<m.length;c++)o[c]&&(u=m[c],t.texImage2D(u,e,i,a,_,0,i,n,null),t.bindTexture(r,s),t.texImage2D(u,e,i,i,n,o[c]));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 u=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},m=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=u(t,t.VERTEX_SHADER,r),n=u(t,t.FRAGMENT_SHADER,e),o=t.createProgram();if(t.attachShader(o,i),t.attachShader(o,n),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(o));return o}(this.__painter,t,r),this},t}(),c={};function l(t,r,e,i,n){var a=function(t,r,e){var i=t+(e.geometry.attributes.normal?"1":"0")+(e.material.image?"1":"0")+(e.material.color?"1":"0")+(e.material.cube?"1":"0");if(c[i])return c[i].use();var n="\n attribute vec4 a_position;\n\n ".concat(e.geometry.attributes.normal?"attribute vec4 a_normal;varying vec3 v_normal;":"","\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(e.material.image?"attribute vec2 a_textcoord;varying vec2 v_textcoord;":"","\n\n void main(){\n vec4 temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position;\n\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\n float dist = 4.0;\n\n // 使用投影直接计算\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 ").concat(e.geometry.attributes.normal?"v_normal = normalize(vec3(a_normal));":"","\n ").concat(e.material.image?"v_textcoord = a_textcoord;":"","\n }\n "),o="\n precision mediump float;\n\n ".concat(e.geometry.attributes.normal?"varying vec3 v_normal;":"","\n ").concat(e.material.color?"uniform vec4 u_color;":"","\n ").concat(e.material.cube?"uniform samplerCube u_texture;":"","\n ").concat(e.material.image?"uniform sampler2D u_sampler;varying vec2 v_textcoord;":"","\n\n void main(){\n ").concat(e.material.color?"gl_FragColor = u_color;":"","\n ").concat(e.material.cube?"gl_FragColor = textureCube(u_texture,normalize(v_normal));":"","\n ").concat(e.material.image?"gl_FragColor = texture2D(u_sampler,v_textcoord);":"","\n }\n "),a=new m(r).compile(n,o).use();return c[i]=a,a}(t,r,e);if(new o(r).use().write(e.geometry.attributes.position.array).divide(r.getAttribLocation(a.program,"a_position"),e.geometry.attributes.position.itemSize,3,0),r.uniformMatrix4fv(r.getUniformLocation(a.program,"u_matrix_world"),!1,n.matrix),r.uniformMatrix4fv(r.getUniformLocation(a.program,"u_matrix_proporion"),!1,n.proporion),r.uniformMatrix4fv(r.getUniformLocation(a.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new o(r).use().write(e.geometry.attributes.normal.array).divide(r.getAttribLocation(a.program,"a_normal"),e.geometry.attributes.normal.itemSize,3,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);else if("cube"in e.material){var _=e.material.cube.right.image.value.width;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 o(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 o(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 h=!1,p=function(){function t(t,r){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 n=[],o=0;o<i;o++)n[o]=t;return function(){for(var o=0;o<i;o++){if(n[o]<r){n[o]=+(n[o]+e).toFixed(7);break}o<i-1&&(n[o]=t)}return n}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new n([1,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,10])},this.__unique=(new Date).valueOf(),this.painter=e(t,10),this.__regionPainter=e(r,10,{});var i=this.painter.canvas.width/this.painter.canvas.height,o=1,a=1;i>1?o=1/i:a=i;var _=Math.min(o,a);this.__proporion=[o,0,0,0,0,a,0,0,0,0,_,0,0,0,0,1]}return t.prototype.matrix=function(t){return new n(t)},t.prototype.getMatrix=function(){return this.__scene.matrix},t.prototype.getObject3D=function(){return this.__scene.children},t.prototype.review=function(t){void 0===t&&(t=!1),t?(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},t.prototype.draw=function(t,r){void 0===r&&(r=!1),r||(h=!0);var e,i,n,o,a={matrix:t.matrix.value()},_={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var s=0;s<t.mesh.length;s++)r?l("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[s].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},a,_):l("region"+this.__unique,this.painter,t.mesh[s],a,_);this.__getColor=(e=this.__regionPainter,i=e.drawingBufferWidth,n=e.drawingBufferHeight,o=new Uint8Array(4*i*n),e.readPixels(0,0,i,n,e.RGBA,e.UNSIGNED_BYTE,o),function(t,r){return"rgba("+o[4*((r=n-r)*i+t)]+","+o[4*(r*i+t)+1]+","+o[4*(r*i+t)+2]+","+o[4*(r*i+t)+3]+")"})},t.prototype.render=function(t){"matrix"in t||(t.matrix=new n),"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))}this.__scene.children.push(t),this.draw(t)},t.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},t.prototype.getRegion=function(t,r){var e=this;return h&&this.review(!0),h=!1,new Promise((function(i,n){var o=e.__getColor(t,r);for(var a in e.__regionList){var _=e.__regionList[a];if("rgba("+255*_[0]+","+255*_[1]+","+255*_[2]+","+255*_[3]+")"==o){i(a);break}}i("")}))},t}();return function(r){function e(t){if(!t)throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");var e,i,n=t.clientWidth,o=t.clientHeight,a=t;a._vislite_canvas_?(e=a._vislite_canvas_[0],i=a._vislite_canvas_[1]):(i=document.createElement("canvas"),t.appendChild(i),i.style.position="absolute",i.style.zIndex="-1",e=document.createElement("canvas"),t.appendChild(e),a._vislite_canvas_=[e,i],t.setAttribute("vislite","WebGL"));for(var _=0,s=[e,i];_<s.length;_++){var u=s[_];u.style.width=n+"px",u.setAttribute("width",n+""),u.style.height=o+"px",u.setAttribute("height",o+"")}return r.call(this,e,i)||this}return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}(e,r),e}(p)},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t="undefined"!=typeof globalThis?globalThis:t||self).VISLite_WebGL=r();
15
+ var t,e;t=this,e=function(){"use strict";var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};function e(t,e,r){if(r||2===arguments.length)for(var i,n=0,o=e.length;n<o;n++)!i&&n in e||(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))}function r(t,e,r){void 0===r&&(r={});for(var i=["webgl","experimental-webgl","webkit-3d","moz-webgl"],n=null,o=0;o<i.length;o++){try{n=t.getContext(i[o],r)}catch(t){}if(n)break}if(!n)throw new Error("Non canvas or browser does not support webgl.");var a=n.canvas.width,_=n.canvas.height,u=a*e,s=_*e;return n.viewport(.5*(a-u),.5*(_-s),u,s),n.depthFunc(n.LEQUAL),n.enable(n.DEPTH_TEST),n}function i(t){var e=t.drawingBufferWidth,r=t.drawingBufferHeight,i=new Uint8Array(4*e*r);return t.readPixels(0,0,e,r,t.RGBA,t.UNSIGNED_BYTE,i),function(t,n){return"rgba("+i[4*((n=r-n)*e+t)]+","+i[4*(n*e+t)+1]+","+i[4*(n*e+t)+2]+","+i[4*(n*e+t)+3]+")"}}var n=function(t,e){for(var r=[],i=0;i<4;i++)for(var n=0;n<e.length/4;n++)r[4*n+i]=t[i]*e[4*n]+t[i+4]*e[4*n+1]+t[i+8]*e[4*n+2]+t[i+12]*e[4*n+3];return r},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,e,r,i){return void 0===i&&(i=0),this.__matrix4=n(function(t,e,r,i){void 0===i&&(i=0);var n=Math.sqrt(e*e+r*r+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,e*t/n,r*t/n,i*t/n,1]}(t,e,r,i),this.__matrix4),this},t.prototype.rotate=function(t,e,r,i,o,a,_){var u=function(t,e,r,i,n,o){if("number"==typeof t&&"number"==typeof e){if("number"!=typeof r?(r=0,i=t,n=e,o=1):"number"==typeof i&&"number"==typeof n&&"number"==typeof o||(i=t,n=e,o=r,t=0,e=0,r=0),t==i&&e==n&&r==o)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((i-t)*(i-t)+(n-e)*(n-e)),_=0!=a?(n-e)/a:1,u=0!=a?(i-t)/a:0,s=(i-t)*u+(n-e)*_,m=o-r,c=Math.sqrt(s*s+m*m),l=0!=c?m/c:1,h=0!=c?s/c:0;return[[_,l*u,u*h,0,-u,_*l,_*h,0,0,-h,l,0,e*u-t*_,r*h-t*u*l-e*_*l,-t*u*h-e*_*h-r*l,1],[_,-u,0,0,l*u,l*_,-h,0,u*h,_*h,l,0,t,e,r,1]]}throw new Error("a1 and b1 is required!")}(e,r,i,o,a,_);return this.__matrix4=n(n(n(u[1],function(t){var e=Math.sin(t),r=Math.cos(t);return[r,e,0,0,-e,r,0,0,0,0,1,0,0,0,0,1]}(t)),u[0]),this.__matrix4),this},t.prototype.scale=function(t,e,r,i,o,a){return void 0===i&&(i=0),void 0===o&&(o=0),void 0===a&&(a=0),this.__matrix4=n(function(t,e,r,i,n,o){return void 0===i&&(i=0),void 0===n&&(n=0),void 0===o&&(o=0),[t,0,0,0,0,e,0,0,0,0,r,0,i-i*t,n-n*e,o-o*r,1]}(t,e,r,i,o,a),this.__matrix4),this},t.prototype.multiply=function(t,e){return void 0===e&&(e=!1),this.__matrix4=e?n(this.__matrix4,t):n(t,this.__matrix4),this},t.prototype.use=function(t,e,r,i){return void 0===r&&(r=0),void 0===i&&(i=1),n(this.__matrix4,[t,e,r,i])},t.prototype.value=function(){return this.__matrix4},t}(),a=function(){function t(t,e){void 0===e&&(e=!1),this.__painter=t,this.__isElement=e,this.__buffer=function(t){return t.createBuffer()}(t),this.__type=e?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,e,r,i){var n=r?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(n,e,i)}(this.__painter,t,this.__isElement,this.__painter.STATIC_DRAW),this.__fsize=t.BYTES_PER_ELEMENT,this},t.prototype.divide=function(t,e,r,i){return void 0===i&&(i=0),function(t,e,r,i,n,o,a){t.vertexAttribPointer(e,r,i,a,n,o),t.enableVertexAttribArray(e)}(this.__painter,t,e,this.__painter.FLOAT,r*this.__fsize,i*this.__fsize,!1),this},t}(),_=function(){function t(t,e,r){void 0===r&&(r=0),this.__painter=t,this.__type={"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP}[e],this.__texture=function(t,e,r){var i=t.createTexture();return e==t.TEXTURE_2D&&t.activeTexture(t["TEXTURE"+r]),t.bindTexture(e,i),i}(t,this.__type,r),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,e,r,i,n,o){t.texImage2D(e,r,i,i,n,o)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t),this},t.prototype.useCube=function(t,e,r){return function(t,e,r,i,n,o,a,_,u){for(var s,m=[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],c=0;c<m.length;c++)o[c]&&(s=m[c],t.texImage2D(s,r,i,a,_,0,i,n,null),t.bindTexture(e,u),t.texImage2D(s,r,i,i,n,o[c]));t.generateMipmap(e)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,e,r,this.__texture),this},t}(),u={};function s(t,e,r){var i=t+"-"+r;return u[i]||(u[i]=new _(e,r)),u[i]}var m=function(t,e,r){var i=t.createShader(e);if(null==i)throw new Error("Unable to create shader!");if(t.shaderSource(i,r),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS))throw new Error("Failed to compile shader:"+t.getShaderInfoLog(i));return i},c=function(){function t(t){this.__painter=t}return t.prototype.use=function(){return this.__painter.useProgram(this.program),this},t.prototype.compile=function(t,e){return this.program=function(t,e,r){var i=m(t,t.VERTEX_SHADER,e),n=m(t,t.FRAGMENT_SHADER,r),o=t.createProgram();if(t.attachShader(o,i),t.attachShader(o,n),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(o));return o}(this.__painter,t,e),this},t}(),l={};function h(t,e,r,i,n){var o=function(t,e,r){var i=t+(r.geometry.attributes.normal?"1":"0")+(r.material.image?"1":"0")+(r.material.color?"1":"0")+(r.material.cube?"1":"0");if(l[i])return l[i].use();var n="\n attribute vec4 a_position;\n\n ".concat(r.geometry.attributes.normal?"attribute vec4 a_normal;varying vec3 v_normal;":"","\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(r.material.image?"attribute vec2 a_textcoord;varying vec2 v_textcoord;":"","\n\n void main(){\n vec4 temp = a_position;\n\n // 应用变换矩阵:屏幕比调平矩阵、世界矩阵、物体矩阵\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\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\n ").concat(r.geometry.attributes.normal?"v_normal = normalize(vec3(a_normal));":"","\n ").concat(r.material.image?"v_textcoord = a_textcoord;":"","\n }\n "),o="\n precision mediump float;\n\n ".concat(r.geometry.attributes.normal?"varying vec3 v_normal;":"","\n ").concat(r.material.color?"uniform vec4 u_color;":"","\n ").concat(r.material.cube?"uniform samplerCube u_texture;":"","\n ").concat(r.material.image?"uniform sampler2D u_sampler;varying vec2 v_textcoord;":"","\n\n void main(){\n ").concat(r.material.color?"gl_FragColor = u_color;":"","\n ").concat(r.material.cube?"gl_FragColor = textureCube(u_texture,normalize(v_normal));":"","\n ").concat(r.material.image?"gl_FragColor = texture2D(u_sampler,v_textcoord);":"","\n }\n "),a=new c(e).compile(n,o).use();return l[i]=a,a}(t,e,r);if(new a(e).use().write(r.geometry.attributes.position.array).divide(e.getAttribLocation(o.program,"a_position"),r.geometry.attributes.position.itemSize,3,0),e.uniformMatrix4fv(e.getUniformLocation(o.program,"u_matrix_world"),!1,n.matrix),e.uniformMatrix4fv(e.getUniformLocation(o.program,"u_matrix_proporion"),!1,n.proporion),e.uniformMatrix4fv(e.getUniformLocation(o.program,"u_matrix_mesh"),!1,i.matrix),r.geometry.attributes.normal&&new a(e).use().write(r.geometry.attributes.normal.array).divide(e.getAttribLocation(o.program,"a_normal"),r.geometry.attributes.normal.itemSize,3,0),"color"in r.material)e.uniform4f(e.getUniformLocation(o.program,"u_color"),r.material.color.r,r.material.color.g,r.material.color.b,r.material.color.alpha);else if("cube"in r.material){var _=r.material.cube.right.image.value.width;s(t,e,"cube").useCube([r.material.cube.right.image.value,r.material.cube.left.image.value,r.material.cube.top.image.value,r.material.cube.bottom.image.value,r.material.cube.far.image.value,r.material.cube.near.image.value],_,_)}else"image"in r.material&&(e.uniform1i(e.getUniformLocation(o.program,"u_sampler"),0),new a(e).use().write(r.geometry.attributes.uv.array).divide(e.getAttribLocation(o.program,"a_textcoord"),r.geometry.attributes.uv.itemSize,2,0),s(t,e,"2d").useImage(r.material.image.value));r.geometry.index?(new a(e,!0).use().write(r.geometry.index.array),e.drawElements(e[r.geometry.type],r.geometry.index.count,e.UNSIGNED_BYTE,0)):e.drawArrays(e[r.geometry.type],0,r.geometry.attributes.position.count)}var p=!1,g=function(){function t(t,e){this.name="WebGL",this.__getColor=function(t,e){return"rgba(0,0,0,1)"},this.__regionList={},this.__regionAssemble=function(t,e,r,i){for(var n=[],o=0;o<i;o++)n[o]=t;return function(){for(var o=0;o<i;o++){if(n[o]<e){n[o]=+(n[o]+r).toFixed(7);break}o<i-1&&(n[o]=t)}return n}}(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),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 t.prototype.matrix=function(t){return new o(t)},t.prototype.getMatrix=function(){return this.__scene.matrix},t.prototype.getObject3D=function(){return this.__scene.children},t.prototype.review=function(t){void 0===t&&(t=!1),t?(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 e=0;e<this.__scene.children.length;e++)this.draw(this.__scene.children[e],t);return this},t.prototype.draw=function(t,e){void 0===e&&(e=!1),e||(p=!0);var r={matrix:t.matrix.value()},n={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var o=0;o<t.mesh.length;o++)e?(h("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[o].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},r,n),this.__getColor=i(this.__regionPainter)):h("region"+this.__unique,this.painter,t.mesh[o],r,n)},t.prototype.render=function(t){"matrix"in t||(t.matrix=new o),"region"in t||(t.region="");for(var e=0;e<t.mesh.length;e++){var r=t.mesh[e];r.geometry.attributes.normal&&Array.isArray(r.geometry.attributes.normal.array)&&(r.geometry.attributes.normal.array=new Float32Array(r.geometry.attributes.normal.array)),r.geometry.attributes.position&&Array.isArray(r.geometry.attributes.position.array)&&(r.geometry.attributes.position.array=new Float32Array(r.geometry.attributes.position.array)),r.geometry.attributes.uv&&Array.isArray(r.geometry.attributes.uv.array)&&(r.geometry.attributes.uv.array=new Float32Array(r.geometry.attributes.uv.array)),r.geometry.index&&Array.isArray(r.geometry.index.array)&&(r.geometry.index.array=new Uint8Array(r.geometry.index.array))}this.__scene.children.push(t),this.draw(t)},t.prototype.setRegion=function(t){return this.__regionName=t+"",t?(null==this.__regionList[t]&&(this.__regionList[t]=e(e([],this.__regionAssemble(),!0),[1],!1)),this.__regionColor=this.__regionList[t]):this.__regionColor=[0,0,0,1],this},t.prototype.getRegion=function(t,e){var r=this;return p&&this.review(!0),p=!1,new Promise((function(i,n){var o=r.__getColor(t,e);for(var a in r.__regionList){var _=r.__regionList[a];if("rgba("+255*_[0]+","+255*_[1]+","+255*_[2]+","+255*_[3]+")"==o){i(a);break}}i("")}))},t}();return function(e){function r(t){if(!t)throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");var r,i,n=t.clientWidth,o=t.clientHeight,a=t;a._vislite_canvas_?(r=a._vislite_canvas_[0],i=a._vislite_canvas_[1]):(i=document.createElement("canvas"),t.appendChild(i),i.style.position="absolute",i.style.zIndex="-1",r=document.createElement("canvas"),t.appendChild(r),a._vislite_canvas_=[r,i],t.setAttribute("vislite","WebGL"));for(var _=0,u=[r,i];_<u.length;_++){var s=u[_];s.style.width=n+"px",s.setAttribute("width",n+""),s.style.height=o+"px",s.setAttribute("height",o+"")}return e.call(this,r,i)||this}return function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function i(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}(r,e),r}(g)},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).VISLite_WebGL=e();
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
package/lib/index.umd.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1415,6 +1415,7 @@
1415
1415
  }[type];
1416
1416
  this.__texture = initTexture(painter, this.__type, unit);
1417
1417
  painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST);
1418
+ painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST);
1418
1419
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE);
1419
1420
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE);
1420
1421
  }
@@ -1483,7 +1484,7 @@
1483
1484
  (mesh.material.cube ? "1" : "0");
1484
1485
  if (shaders[uniqueName])
1485
1486
  return shaders[uniqueName].use();
1486
- var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : '', "\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n void main(){\n vec4 temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\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 ").concat(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n }\n ");
1487
+ var vertexShader = "\n attribute vec4 a_position;\n\n ".concat(mesh.geometry.attributes.normal ? 'attribute vec4 a_normal;varying vec3 v_normal;' : '', "\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : '', "\n\n void main(){\n vec4 temp = a_position;\n\n // \u5E94\u7528\u53D8\u6362\u77E9\u9635\uFF1A\u5C4F\u5E55\u6BD4\u8C03\u5E73\u77E9\u9635\u3001\u4E16\u754C\u77E9\u9635\u3001\u7269\u4F53\u77E9\u9635\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\n\n // \u628A\u539F\u751F\u7684WebGL\u4F7F\u7528\u7684\u5DE6\u624B\u5750\u6807\u7CFB\u53D8\u6210\u4E86\u53F3\u624B\u5750\u6807\u7CFB\n temp.z = -1.0 * temp.z;\n\n // \u8868\u793A\u773C\u775B\u8DDD\u79BBvec4(0.0,0.0,1.0)\u7684\u8DDD\u79BB\n float dist = 4.0;\n\n // \u4F7F\u7528\u6295\u5F71\u76F4\u63A5\u8BA1\u7B97\n // \u4E3A\u4FDD\u8BC1\u7EB9\u7406\u548C\u76F8\u5BF9\u4F4D\u7F6E\u6B63\u786E\n // x\u3001y\u3001z\u7684\u6539\u53D8\u6EE1\u8DB3\u7EBF\u6027\u53D8\u6362\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 ").concat(mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : '', "\n ").concat(mesh.material.image ? 'v_textcoord = a_textcoord;' : '', "\n }\n ");
1487
1488
  var fragmentShader = "\n precision mediump float;\n\n ".concat(mesh.geometry.attributes.normal ? 'varying vec3 v_normal;' : '', "\n ").concat(mesh.material.color ? 'uniform vec4 u_color;' : '', "\n ").concat(mesh.material.cube ? 'uniform samplerCube u_texture;' : '', "\n ").concat(mesh.material.image ? 'uniform sampler2D u_sampler;varying vec2 v_textcoord;' : '', "\n\n void main(){\n ").concat(mesh.material.color ? 'gl_FragColor = u_color;' : '', "\n ").concat(mesh.material.cube ? 'gl_FragColor = textureCube(u_texture,normalize(v_normal));' : '', "\n ").concat(mesh.material.image ? 'gl_FragColor = texture2D(u_sampler,v_textcoord);' : '', "\n }\n ");
1488
1489
  var shader = new ShaderObject(painter).compile(vertexShader, fragmentShader).use();
1489
1490
  shaders[uniqueName] = shader;
@@ -1549,7 +1550,7 @@
1549
1550
  matrix: new Matrix4([
1550
1551
  1, 0, 0, 0,
1551
1552
  0, 1, 0, 0,
1552
- 0, 0, -1, 0,
1553
+ 0, 0, 1, 0,
1553
1554
  0, 0, 0, scale
1554
1555
  ])
1555
1556
  };
@@ -1622,12 +1623,12 @@
1622
1623
  }
1623
1624
  }
1624
1625
  }, meshWorld, globalWorld);
1626
+ this.__getColor = getColorFactory(this.__regionPainter);
1625
1627
  }
1626
1628
  else {
1627
1629
  doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld);
1628
1630
  }
1629
1631
  }
1630
- this.__getColor = getColorFactory(this.__regionPainter);
1631
1632
  };
1632
1633
  WebGL.prototype.render = function (object3D) {
1633
1634
  if (!('matrix' in object3D))
@@ -1826,10 +1827,10 @@
1826
1827
  if (mouseP == null)
1827
1828
  return;
1828
1829
  var tempMouseP = mousePosition(el, event);
1829
- var normal = [tempMouseP.x - mouseP.x, mouseP.y - tempMouseP.y];
1830
+ var normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y];
1830
1831
  var rotateNormal = [
1831
1832
  normal[1],
1832
- normal[0] * -1,
1833
+ normal[0],
1833
1834
  0
1834
1835
  ];
1835
1836
  if (rotateNormal[0] == 0 && rotateNormal[1] == 0)
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -12,4 +12,4 @@
12
12
  * alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
13
13
  * beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
14
14
  */
15
- var t,e;t=this,e=function(){"use strict";var t=function(){function t(t){void 0===t&&(t=.5),this.name="Hermite",this.__u=t}return t.prototype.setP=function(t,e,i,r,n,o){if(!(t<i))throw new Error("The point x-position should be increamented!");this.__a=t,this.__b=i;var a=this.__u*n,s=this.__u*o;return e/=i-t,r/=i-t,this.__MR=[2*e-2*r+a+s,3*r-3*e-2*a-s,a,e],this},t.prototype.use=function(t){if(this.__MR){var e=(t-this.__a)/(this.__b-this.__a),i=e*e;return(e*i*this.__MR[0]+i*this.__MR[1]+e*this.__MR[2]+this.__MR[3])*(this.__b-this.__a)}throw new Error("You shoud first set the position!")},t}(),e=function(){function e(t){void 0===t&&(t=0),this.name="Cardinal",this.__t=t}return e.prototype.setP=function(e){this.__HS={x:[],h:[]};var i,r,n=(e[1][1]-e[0][1])/(e[1][0]-e[0][0]);for(this.__HS.x[0]=e[0][0],i=1;i<e.length;i++){if(e[i][0]<=e[i-1][0])throw new Error("The point position should be increamented!");this.__HS.x[i]=e[i][0],r=i<e.length-1?(e[i+1][1]-e[i-1][1])/(e[i+1][0]-e[i-1][0]):(e[i][1]-e[i-1][1])/(e[i][0]-e[i-1][0]),this.__HS.h[i-1]=new t(.5*(1-this.__t)).setP(e[i-1][0],e[i-1][1],e[i][0],e[i][1],n,r),n=r}return this},e.prototype.use=function(t){if(this.__HS){for(this.__i=-1;this.__i+1<this.__HS.x.length&&(t>this.__HS.x[this.__i+1]||-1==this.__i&&t>=this.__HS.x[this.__i+1]);)this.__i+=1;return this.__i<0?this.__HS.h[0].use(this.__HS.x[0]):this.__i>=this.__HS.h.length?this.__HS.h[this.__HS.h.length-1].use(this.__HS.x[this.__HS.x.length-1]):this.__HS.h[this.__i].use(t)}throw new Error("You shoud first set the position!")},e}(),i=function(t,e){for(var i=[],r=0;r<4;r++)for(var n=0;n<e.length/4;n++)i[4*n+r]=t[r]*e[4*n]+t[r+4]*e[4*n+1]+t[r+8]*e[4*n+2]+t[r+12]*e[4*n+3];return i},r=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,e,r,n){return void 0===n&&(n=0),this.__matrix4=i(function(t,e,i,r){void 0===r&&(r=0);var n=Math.sqrt(e*e+i*i+r*r);return[1,0,0,0,0,1,0,0,0,0,1,0,e*t/n,i*t/n,r*t/n,1]}(t,e,r,n),this.__matrix4),this},t.prototype.rotate=function(t,e,r,n,o,a,s){var _=function(t,e,i,r,n,o){if("number"==typeof t&&"number"==typeof e){if("number"!=typeof i?(i=0,r=t,n=e,o=1):"number"==typeof r&&"number"==typeof n&&"number"==typeof o||(r=t,n=e,o=i,t=0,e=0,i=0),t==r&&e==n&&i==o)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((r-t)*(r-t)+(n-e)*(n-e)),s=0!=a?(n-e)/a:1,_=0!=a?(r-t)/a:0,h=(r-t)*_+(n-e)*s,u=o-i,l=Math.sqrt(h*h+u*u),c=0!=l?u/l:1,f=0!=l?h/l:0;return[[s,c*_,_*f,0,-_,s*c,s*f,0,0,-f,c,0,e*_-t*s,i*f-t*_*c-e*s*c,-t*_*f-e*s*f-i*c,1],[s,-_,0,0,c*_,c*s,-f,0,_*f,s*f,c,0,t,e,i,1]]}throw new Error("a1 and b1 is required!")}(e,r,n,o,a,s);return this.__matrix4=i(i(i(_[1],function(t){var e=Math.sin(t),i=Math.cos(t);return[i,e,0,0,-e,i,0,0,0,0,1,0,0,0,0,1]}(t)),_[0]),this.__matrix4),this},t.prototype.scale=function(t,e,r,n,o,a){return void 0===n&&(n=0),void 0===o&&(o=0),void 0===a&&(a=0),this.__matrix4=i(function(t,e,i,r,n,o){return void 0===r&&(r=0),void 0===n&&(n=0),void 0===o&&(o=0),[t,0,0,0,0,e,0,0,0,0,i,0,r-r*t,n-n*e,o-o*i,1]}(t,e,r,n,o,a),this.__matrix4),this},t.prototype.multiply=function(t,e){return void 0===e&&(e=!1),this.__matrix4=e?i(this.__matrix4,t):i(t,this.__matrix4),this},t.prototype.use=function(t,e,r,n){return void 0===r&&(r=0),void 0===n&&(n=1),i(this.__matrix4,[t,e,r,n])},t.prototype.value=function(){return this.__matrix4},t}();function n(t,e,i,r,n){var o=Math.cos(i),a=Math.sin(i);return[(r-t)*o-(n-e)*a+t,(r-t)*a+(n-e)*o+e]}var o,a=[],s=function(t,e){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},s(t,e)};function _(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}function h(t,e,i){if(i||2===arguments.length)for(var r,n=0,o=e.length;n<o;n++)!r&&n in e||(r||(r=Array.prototype.slice.call(e,0,n)),r[n]=e[n]);return t.concat(r||Array.prototype.slice.call(e))}var u=["href","title","show","type","role","actuate"],l=function(t,e,i){u.indexOf(e)>-1?t.setAttributeNS("http://www.w3.org/1999/xlink","xlink:"+e,i+""):t.setAttribute(e,i+"")},c=l;function f(t,e){l(t,"stroke",e.strokeStyle),l(t,"fill",e.fillStyle),l(t,"stroke-dasharray",e.lineDash.join(","))}function p(t,e){l(t,"fill",e.fillStyle)}function g(t,e){l(t,"stroke",e.strokeStyle),l(t,"fill","none"),l(t,"stroke-dasharray",e.lineDash.join(","))}var m=function(t,e,i,r,n){var o=Math.cos(i),a=Math.sin(i);return[+((r-t)*o-(n-e)*a+t).toFixed(7),+((r-t)*a+(n-e)*o+e).toFixed(7)]};function v(t,e,i,r,n,o,a){e<0&&(t+=e,e*=-1);var s,_=[];s=m(0,0,t,n,0),_[0]=s[0],_[1]=s[1],s=m(0,0,e,s[0],s[1]),_[2]=s[0],_[3]=s[1],s=m(0,0,t,o,0),_[4]=s[0],_[5]=s[1],s=m(0,0,e,s[0],s[1]),_[6]=s[0],_[7]=s[1],a(t,t+e,_[0]+i,_[1]+r,_[4]+i,_[5]+r,_[2]+i,_[3]+r,_[6]+i,_[7]+r,.5*(o-n))}var d=function(t,e,i,r,n){if("text"!==t.nodeName.toLowerCase())throw new Error("Need a <text> !");c(t,"dy",{top:.5*e["font-size"],middle:0,bottom:.5*-e["font-size"]}[e.textBaseline]),function(t,e){for(var i in e)t.style[i]=e[i]}(t,{"text-anchor":{left:"start",right:"end",center:"middle"}[e.textAlign],"dominant-baseline":"central","font-size":e["font-size"]+"px","font-family":e["font-family"]}),c(t,"x",i),c(t,"y",r),"number"==typeof n&&c(t,"transform","rotate("+(n%=360)+","+i+","+r+")")},y=function(t,e,i,r){if("circle"!==t.nodeName.toLowerCase())throw new Error("Need a <circle> !");c(t,"cx",e),c(t,"cy",i),c(t,"r",r)},E=function(t,e){if("path"!==t.nodeName.toLowerCase())throw new Error("Need a <path> !");c(t,"d",e)},b=function(t,e,i,r,n){if("rect"!==t.nodeName.toLowerCase())throw new Error("Need a <rect> !");n<0&&(i-=n*=-1),r<0&&(e-=r*=-1),c(t,"x",e),c(t,"y",i),c(t,"width",r),c(t,"height",n)},x=function(t,e,i,r,n,o,a,s){if("path"!==t.nodeName.toLowerCase())throw new Error("Need a <path> !");if(a%=2*Math.PI,n>o){var _=n;n=o,o=_}s>=1.999999*Math.PI||s<=1.999999*-Math.PI?s=1.999999*Math.PI:s%=2*Math.PI,v(a,s,i,r,n,o,(function(i,r,a,s,_,h,u,l,f,p,g){var m=r-i>Math.PI?1:0,v="M"+a+" "+s;g<0&&(g=-g),v+="A"+n+" "+n+" 0 "+m+" 1 "+u+" "+l,"round"==e["arc-end-cap"]?v+="A"+g+" "+g+" 0 1 0 "+f+" "+p:"-round"==e["arc-end-cap"]?v+="A"+g+" "+g+" 0 1 1 "+f+" "+p:v+="L"+f+" "+p,v+="A"+o+" "+o+" 0 "+m+" 0 "+_+" "+h,"round"==e["arc-start-cap"]?v+="A"+g+" "+g+" 0 1 0 "+a+" "+s:"-round"==e["arc-start-cap"]?v+="A"+g+" "+g+" 0 1 1 "+a+" "+s:v+="L"+a+" "+s,"butt"==e["arc-start-cap"]&&(v+="Z"),c(t,"d",v)}))},w={"font-size":"fontSize","font-family":"fontFamily","arc-start-cap":"arcStartCap","arc-end-cap":"arcEndCap"},T=function(){function t(t){this.name="SVG",this.__config={fillStyle:"#000",strokeStyle:"#000",lineWidth:1,textAlign:"left",textBaseline:"middle","font-size":16,"font-family":"sans-serif","arc-start-cap":"butt","arc-end-cap":"butt",lineDash:[]},this.__path="",this.__currentPosition=[],this.__svg=t}return t.prototype.config=function(t){if("object"!=typeof t)return this.__config[w[t]||t];for(var e in t){var i=w[e]||e;this.__config[i]=t[e]}return this},t.prototype.useEl=function(t){return this.__useEl=t,this},t.prototype.getEl=function(){return this.__useEl},t.prototype.appendEl=function(t,e){var i;return e=e||this.__svg,"string"==typeof t&&(i=t,t=document.createElementNS("http://www.w3.org/2000/svg",i)),e.appendChild(t),this.__useEl=t,this},t.prototype.appendBoard=function(t,e){var i=t;if("string"==typeof t&&(i={text:"text",path:"path",arc:"path",circle:"circle",rect:"rect"}[t]||""),""==i)throw new Error("Unsupported drawing method:"+t);return this.appendEl(i,e)},t.prototype.remove=function(){if(!this.__useEl)throw new Error("Currently, no node can be deleted.");return this.__useEl.parentNode.removeChild(this.__useEl),this},t.prototype.attr=function(t){if(!this.__useEl)throw new Error("Currently, no node can be modified or viewed.");if("object"!=typeof t)return function(t,e){return u.indexOf(e)>-1&&(e="xlink:"+e),t.getAttribute(e)}(this.__useEl,t);for(var e in t)c(this.__useEl,e,t[e]);return this},t.prototype.fillText=function(t,e,i,r){return void 0===r&&(r=0),d(this.__useEl,this.__config,e,i,r),this.__useEl.textContent=t,p(this.__useEl,this.__config),this},t.prototype.strokeText=function(t,e,i,r){return void 0===r&&(r=0),d(this.__useEl,this.__config,e,i,r),this.__useEl.textContent=t,g(this.__useEl,this.__config),this},t.prototype.fullText=function(t,e,i,r){return void 0===r&&(r=0),d(this.__useEl,this.__config,e,i,r),this.__useEl.textContent=t,f(this.__useEl,this.__config),this},t.prototype.fillArc=function(t,e,i,r,n,o){return x(this.__useEl,this.__config,t,e,i,r,n,o),p(this.__useEl,this.__config),this},t.prototype.strokeArc=function(t,e,i,r,n,o){return x(this.__useEl,this.__config,t,e,i,r,n,o),g(this.__useEl,this.__config),this},t.prototype.fullArc=function(t,e,i,r,n,o){return x(this.__useEl,this.__config,t,e,i,r,n,o),f(this.__useEl,this.__config),this},t.prototype.fillCircle=function(t,e,i){return y(this.__useEl,t,e,i),p(this.__useEl,this.__config),this},t.prototype.strokeCircle=function(t,e,i){return y(this.__useEl,t,e,i),g(this.__useEl,this.__config),this},t.prototype.fullCircle=function(t,e,i){return y(this.__useEl,t,e,i),f(this.__useEl,this.__config),this},t.prototype.fillRect=function(t,e,i,r){return b(this.__useEl,t,e,i,r),p(this.__useEl,this.__config),this},t.prototype.strokeRect=function(t,e,i,r){return b(this.__useEl,t,e,i,r),g(this.__useEl,this.__config),this},t.prototype.fullRect=function(t,e,i,r){return b(this.__useEl,t,e,i,r),f(this.__useEl,this.__config),this},t.prototype.beginPath=function(){return this.__currentPosition=[],this.__path="",this},t.prototype.closePath=function(){return this.__path+="Z",this},t.prototype.moveTo=function(t,e){return this.__currentPosition=[t,e],this.__path+="M"+t+" "+e,this},t.prototype.lineTo=function(t,e){return this.__currentPosition=[t,e],this.__path+=(""==this.__path?"M":"L")+t+" "+e,this},t.prototype.fill=function(){return E(this.__useEl,this.__path),p(this.__useEl,this.__config),this},t.prototype.stroke=function(){return E(this.__useEl,this.__path),g(this.__useEl,this.__config),this},t.prototype.full=function(){return E(this.__useEl,this.__path),f(this.__useEl,this.__config),this},t.prototype.arc=function(t,e,i,r,o){var a=n(t,e,r,t+i,e),s=n(t,e,r+o,t+i,e);return r=r/Math.PI*180,o=o/Math.PI*180,""==this.__path?this.__path+="M"+a[0]+","+a[1]:a[0]==this.__currentPosition[0]&&a[1]==this.__currentPosition[1]||(this.__path+="L"+a[0]+","+a[1]),this.__path+="A"+i+","+i+" 0 "+(o>180||o<-180?1:0)+","+(o>0?1:0)+" "+s[0]+","+s[1],this},t.prototype.quadraticCurveTo=function(t,e,i,r){return this.__path+="Q"+t+" "+e+","+i+" "+r,this},t.prototype.bezierCurveTo=function(t,e,i,r,n,o){return this.__path+="C"+t+" "+e+","+i+" "+r+","+n+" "+o,this},t}(),C=function(t){function e(e){if(!e)throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.");var i=e.clientWidth,r=e.clientHeight,n=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.appendChild(n),n.setAttribute("width",i+""),n.setAttribute("height",r+""),n.setAttribute("viewBox","0 0 "+i+" "+r),t.call(this,n)||this}return _(e,t),e}(T),A=function(t,e,i,r,n){return t.beginPath(),t.translate(i,r),t.rotate(n),t.font=e.fontStyle+" "+e.fontWeight+" "+e.fontSize+"px "+e.fontFamily,t},M=function(t,e,i,r,n,o,a,s){if(n>o){var _=n;n=o,o=_}return a%=2*Math.PI,s>=1.999999*Math.PI||s<=1.999999*-Math.PI?s=2*Math.PI:s%=2*Math.PI,v(a,s,i,r,n,o,(function(a,s,_,h,u,l,c,f,p,g,m){m<0&&(m=-m),t.beginPath(),t.moveTo(_,h),t.arc(i,r,n,a,s,!1),"round"!=e.arcEndCap?t.lineTo(p,g):t.arc(.5*(c+p),.5*(f+g),m,s-Math.PI,s,!0),t.arc(i,r,o,s,a,!0),"round"!=e.arcStartCap?t.lineTo(_,h):t.arc(.5*(_+u),.5*(h+l),m,a,a-Math.PI,!0)})),"butt"==e.arcStartCap&&t.closePath(),t},S=function(t,e,i,r){return t.beginPath(),t.moveTo(e+r,i),t.arc(e,i,r,0,2*Math.PI),t},P=function(t,e,i,r,n){return t.beginPath(),t.rect(e,i,r,n),t};function L(t,e,i,r,n){for(var o=0,a="",s=0;s<e.length;s++)t.measureText(a+e[s]).width>i?(n(a,((o+=1)-.5)*r),a=e[s]):s==e.length-1?(o+=1,n(a+e[s],(o-.5)*r)):a+=e[s];return o*r}var R=function(){function t(t,e,i){void 0===e&&(e={}),this.__region=null,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",e),this.__region=i,this.painter.textBaseline="middle",this.painter.textAlign="left"}return t.prototype.useConfig=function(t,e){if(this.__region&&["fillStyle","strokeStyle","shadowBlur","shadowColor"].indexOf(t)<0&&this.__region.useConfig(t,e),"lineDash"==t)this.painter.setLineDash&&this.painter.setLineDash(e);else if(t in this.__specialConfig)this.__specialConfig[t]=e;else{if(!(t in this.__initConfig))throw new Error("Illegal configuration item of painter : "+t+" !");this.painter[t]=e}return this},t.prototype.fillText=function(t,e,i,r){return void 0===r&&(r=0),this.__region&&this.__region.fillText(t,e,i,r),this.painter.save(),A(this.painter,this.__specialConfig,e,i,r).fillText(t,0,0),this.painter.restore(),this},t.prototype.strokeText=function(t,e,i,r){return void 0===r&&(r=0),this.__region&&this.__region.strokeText(t,e,i,r),this.painter.save(),A(this.painter,this.__specialConfig,e,i,r).strokeText(t,0,0),this.painter.restore(),this},t.prototype.fullText=function(t,e,i,r){return void 0===r&&(r=0),this.__region&&this.__region.fullText(t,e,i,r),this.painter.save(),A(this.painter,this.__specialConfig,e,i,r),this.painter.fillText(t,0,0),this.painter.strokeText(t,0,0),this.painter.restore(),this},t.prototype.fillTexts=function(t,e,i,r,n,o){var a=this;void 0===n&&(n=1.2),void 0===o&&(o=0),this.__region&&this.__region.fillTexts(t,e,i,r,n),this.painter.save(),A(this.painter,this.__specialConfig,e,i,o);var s=L(this.painter,t,r,this.__specialConfig.fontSize*n,(function(t,e){a.painter.fillText(t,0,e)}));return this.painter.restore(),s},t.prototype.strokeTexts=function(t,e,i,r,n,o){var a=this;void 0===n&&(n=1.2),void 0===o&&(o=0),this.__region&&this.__region.fillTexts(t,e,i,r,n),this.painter.save(),A(this.painter,this.__specialConfig,e,i,o);var s=L(this.painter,t,r,this.__specialConfig.fontSize*n,(function(t,e){a.painter.strokeText(t,0,e)}));return this.painter.restore(),s},t.prototype.fullTexts=function(t,e,i,r,n,o){var a=this;void 0===n&&(n=1.2),void 0===o&&(o=0),this.__region&&this.__region.fillTexts(t,e,i,r,n),this.painter.save(),A(this.painter,this.__specialConfig,e,i,o);var s=L(this.painter,t,r,this.__specialConfig.fontSize*n,(function(t,e){a.painter.fillText(t,0,e),a.painter.strokeText(t,0,e)}));return this.painter.restore(),s},t.prototype.beginPath=function(){return this.__region&&this.__region.beginPath(),this.painter.beginPath(),this},t.prototype.closePath=function(){return this.__region&&this.__region.closePath(),this.painter.closePath(),this},t.prototype.moveTo=function(t,e){return this.__region&&this.__region.moveTo(t,e),this.painter.moveTo(Math.round(t)+.5,Math.round(e)+.5),this},t.prototype.lineTo=function(t,e){return this.__region&&this.__region.lineTo(t,e),this.painter.lineTo(Math.round(t)+.5,Math.round(e)+.5),this},t.prototype.arc=function(t,e,i,r,n){return this.__region&&this.__region.arc(t,e,i,r,n),this.painter.arc(t,e,i,r,r+n,n<0),this},t.prototype.fill=function(){return this.__region&&this.__region.fill(),this.painter.fill(),this},t.prototype.stroke=function(){return this.__region&&this.__region.stroke(),this.painter.stroke(),this},t.prototype.full=function(){return this.__region&&this.__region.full(),this.painter.fill(),this.painter.stroke(),this},t.prototype.save=function(){return this.__region&&this.__region.save(),this.painter.save(),this},t.prototype.restore=function(){return this.__region&&this.__region.restore(),this.painter.restore(),this},t.prototype.quadraticCurveTo=function(t,e,i,r){return this.__region&&this.__region.quadraticCurveTo(t,e,i,r),this.painter.quadraticCurveTo(t,e,i,r),this},t.prototype.bezierCurveTo=function(t,e,i,r,n,o){return this.__region&&this.__region.bezierCurveTo(t,e,i,r,n,o),this.painter.bezierCurveTo(t,e,i,r,n,o),this},t.prototype.clearRect=function(t,e,i,r){return this.__region&&this.__region.clearRect(t,e,i,r),this.painter.clearRect(t,e,i,r),this},t.prototype.fillArc=function(t,e,i,r,n,o){return this.__region&&this.__region.fillArc(t,e,i,r,n,o),M(this.painter,this.__specialConfig,t,e,i,r,n,o).fill(),this},t.prototype.strokeArc=function(t,e,i,r,n,o){return this.__region&&this.__region.strokeArc(t,e,i,r,n,o),M(this.painter,this.__specialConfig,t,e,i,r,n,o).stroke(),this},t.prototype.fullArc=function(t,e,i,r,n,o){return this.__region&&this.__region.fullArc(t,e,i,r,n,o),M(this.painter,this.__specialConfig,t,e,i,r,n,o),this.painter.fill(),this.painter.stroke(),this},t.prototype.fillCircle=function(t,e,i){return this.__region&&this.__region.fillCircle(t,e,i),S(this.painter,t,e,i).fill(),this},t.prototype.strokeCircle=function(t,e,i){return this.__region&&this.__region.strokeCircle(t,e,i),S(this.painter,t,e,i).stroke(),this},t.prototype.fullCircle=function(t,e,i){return this.__region&&this.__region.fullCircle(t,e,i),S(this.painter,t,e,i),this.painter.fill(),this.painter.stroke(),this},t.prototype.fillRect=function(t,e,i,r){return this.__region&&this.__region.fillRect(t,e,i,r),P(this.painter,t,e,i,r).fill(),this},t.prototype.strokeRect=function(t,e,i,r){return this.__region&&this.__region.strokeRect(t,e,i,r),P(this.painter,t,e,i,r).stroke(),this},t.prototype.fullRect=function(t,e,i,r){return this.__region&&this.__region.fullRect(t,e,i,r),P(this.painter,t,e,i,r),this.painter.fill(),this.painter.stroke(),this},t}();function k(t,e,i,r){for(var n=[],o=0;o<r;o++)n[o]=t;return function(){for(var o=0;o<r;o++){if(n[o]<e){n[o]=+(n[o]+i).toFixed(7);break}o<r-1&&(n[o]=t)}return n}}var I={"font-size":"fontSize","font-family":"fontFamily","font-weight":"fontWeight","font-style":"fontStyle","arc-start-cap":"arcStartCap","arc-end-cap":"arcEndCap"},U=function(t){function e(e,i){var r=t.call(this,e,{},new R(i,{willReadFrequently:!0}))||this;return r.name="Canvas",r.__regionList={},r.__regionAssemble=k(0,255,1,3),r.setRegion(""),r}return _(e,t),e.prototype.config=function(t){for(var e in t){var i=I[e]||e;this.useConfig(i,t[e])}return this},e.prototype.setRegion=function(t){if(t){if(null==this.__regionList[t]){var e=this.__regionAssemble();this.__regionList[t]="rgb("+e[0]+","+e[1]+","+e[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},e.prototype.getRegion=function(t,e){var i=this;return new Promise((function(r,n){var o=i.__region.painter.getImageData(t-.5,e-.5,1,1),a=o.data,s=function(){for(var t in i.__regionList)if("rgb("+a[0]+","+a[1]+","+a[2]+")"==i.__regionList[t]){r(t);break}r("")};a?s():o.then((function(t){a=t,s()}))}))},e.prototype.getContext=function(t){return void 0===t&&(t=!1),t?this.__region.painter:this.painter},e}(R),B=function(t){function e(e){var i=this;if(!e)throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");var r,n,o=e.clientWidth,a=e.clientHeight,s=e;s._vislite_canvas_?(r=s._vislite_canvas_[0],n=s._vislite_canvas_[1]):(r=document.createElement("canvas"),e.appendChild(r),n=document.createElement("canvas"),s._vislite_canvas_=[r,n],e.setAttribute("vislite","Canvas"));for(var _=0,h=[r,n];_<h.length;_++){var u=h[_];u.style.width=o+"px",u.setAttribute("width",o+""),u.style.height=a+"px",u.setAttribute("height",a+"")}return(i=t.call(this,r,n)||this).__canvas=r,i}return _(e,t),e.prototype.toDataURL=function(){var t=this;return new Promise((function(e){e(t.__canvas.toDataURL())}))},e}(U);function D(t,e,i){void 0===i&&(i={});for(var r=["webgl","experimental-webgl","webkit-3d","moz-webgl"],n=null,o=0;o<r.length;o++){try{n=t.getContext(r[o],i)}catch(t){}if(n)break}if(!n)throw new Error("Non canvas or browser does not support webgl.");var a=n.canvas.width,s=n.canvas.height,_=a*e,h=s*e;return n.viewport(.5*(a-_),.5*(s-h),_,h),n.depthFunc(n.LEQUAL),n.enable(n.DEPTH_TEST),n}var N=function(){function t(t,e){void 0===e&&(e=!1),this.__painter=t,this.__isElement=e,this.__buffer=function(t){return t.createBuffer()}(t),this.__type=e?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,e,i,r){var n=i?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(n,e,r)}(this.__painter,t,this.__isElement,this.__painter.STATIC_DRAW),this.__fsize=t.BYTES_PER_ELEMENT,this},t.prototype.divide=function(t,e,i,r){return void 0===r&&(r=0),function(t,e,i,r,n,o,a){t.vertexAttribPointer(e,i,r,a,n,o),t.enableVertexAttribArray(e)}(this.__painter,t,e,this.__painter.FLOAT,i*this.__fsize,r*this.__fsize,!1),this},t}(),F=function(){function t(t,e,i){void 0===i&&(i=0),this.__painter=t,this.__type={"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP}[e],this.__texture=function(t,e,i){var r=t.createTexture();return e==t.TEXTURE_2D&&t.activeTexture(t["TEXTURE"+i]),t.bindTexture(e,r),r}(t,this.__type,i),t.texParameteri(this.__type,t.TEXTURE_MIN_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,e,i,r,n,o){t.texImage2D(e,i,r,r,n,o)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t),this},t.prototype.useCube=function(t,e,i){return function(t,e,i,r,n,o,a,s,_){for(var h,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],l=0;l<u.length;l++)o[l]&&(h=u[l],t.texImage2D(h,i,r,a,s,0,r,n,null),t.bindTexture(e,_),t.texImage2D(h,i,r,r,n,o[l]));t.generateMipmap(e)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,e,i,this.__texture),this},t}(),z={};function H(t,e,i){var r=t+"-"+i;return z[r]||(z[r]=new F(e,i)),z[r]}var O=function(t,e,i){var r=t.createShader(e);if(null==r)throw new Error("Unable to create shader!");if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error("Failed to compile shader:"+t.getShaderInfoLog(r));return r},G=function(){function t(t){this.__painter=t}return t.prototype.use=function(){return this.__painter.useProgram(this.program),this},t.prototype.compile=function(t,e){return this.program=function(t,e,i){var r=O(t,t.VERTEX_SHADER,e),n=O(t,t.FRAGMENT_SHADER,i),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,n),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(o));return o}(this.__painter,t,e),this},t}(),X={};function q(t,e,i,r,n){var o=function(t,e,i){var r=t+(i.geometry.attributes.normal?"1":"0")+(i.material.image?"1":"0")+(i.material.color?"1":"0")+(i.material.cube?"1":"0");if(X[r])return X[r].use();var n="\n attribute vec4 a_position;\n\n ".concat(i.geometry.attributes.normal?"attribute vec4 a_normal;varying vec3 v_normal;":"","\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(i.material.image?"attribute vec2 a_textcoord;varying vec2 v_textcoord;":"","\n\n void main(){\n vec4 temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position;\n\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\n float dist = 4.0;\n\n // 使用投影直接计算\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 ").concat(i.geometry.attributes.normal?"v_normal = normalize(vec3(a_normal));":"","\n ").concat(i.material.image?"v_textcoord = a_textcoord;":"","\n }\n "),o="\n precision mediump float;\n\n ".concat(i.geometry.attributes.normal?"varying vec3 v_normal;":"","\n ").concat(i.material.color?"uniform vec4 u_color;":"","\n ").concat(i.material.cube?"uniform samplerCube u_texture;":"","\n ").concat(i.material.image?"uniform sampler2D u_sampler;varying vec2 v_textcoord;":"","\n\n void main(){\n ").concat(i.material.color?"gl_FragColor = u_color;":"","\n ").concat(i.material.cube?"gl_FragColor = textureCube(u_texture,normalize(v_normal));":"","\n ").concat(i.material.image?"gl_FragColor = texture2D(u_sampler,v_textcoord);":"","\n }\n "),a=new G(e).compile(n,o).use();return X[r]=a,a}(t,e,i);if(new N(e).use().write(i.geometry.attributes.position.array).divide(e.getAttribLocation(o.program,"a_position"),i.geometry.attributes.position.itemSize,3,0),e.uniformMatrix4fv(e.getUniformLocation(o.program,"u_matrix_world"),!1,n.matrix),e.uniformMatrix4fv(e.getUniformLocation(o.program,"u_matrix_proporion"),!1,n.proporion),e.uniformMatrix4fv(e.getUniformLocation(o.program,"u_matrix_mesh"),!1,r.matrix),i.geometry.attributes.normal&&new N(e).use().write(i.geometry.attributes.normal.array).divide(e.getAttribLocation(o.program,"a_normal"),i.geometry.attributes.normal.itemSize,3,0),"color"in i.material)e.uniform4f(e.getUniformLocation(o.program,"u_color"),i.material.color.r,i.material.color.g,i.material.color.b,i.material.color.alpha);else if("cube"in i.material){var a=i.material.cube.right.image.value.width;H(t,e,"cube").useCube([i.material.cube.right.image.value,i.material.cube.left.image.value,i.material.cube.top.image.value,i.material.cube.bottom.image.value,i.material.cube.far.image.value,i.material.cube.near.image.value],a,a)}else"image"in i.material&&(e.uniform1i(e.getUniformLocation(o.program,"u_sampler"),0),new N(e).use().write(i.geometry.attributes.uv.array).divide(e.getAttribLocation(o.program,"a_textcoord"),i.geometry.attributes.uv.itemSize,2,0),H(t,e,"2d").useImage(i.material.image.value));i.geometry.index?(new N(e,!0).use().write(i.geometry.index.array),e.drawElements(e[i.geometry.type],i.geometry.index.count,e.UNSIGNED_BYTE,0)):e.drawArrays(e[i.geometry.type],0,i.geometry.attributes.position.count)}var W=!1,V=function(){function t(t,e){this.name="WebGL",this.__getColor=function(t,e){return"rgba(0,0,0,1)"},this.__regionList={},this.__regionAssemble=k(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new r([1,0,0,0,0,1,0,0,0,0,-1,0,0,0,0,10])},this.__unique=(new Date).valueOf(),this.painter=D(t,10),this.__regionPainter=D(e,10,{});var i=this.painter.canvas.width/this.painter.canvas.height,n=1,o=1;i>1?n=1/i:o=i;var a=Math.min(n,o);this.__proporion=[n,0,0,0,0,o,0,0,0,0,a,0,0,0,0,1]}return t.prototype.matrix=function(t){return new r(t)},t.prototype.getMatrix=function(){return this.__scene.matrix},t.prototype.getObject3D=function(){return this.__scene.children},t.prototype.review=function(t){void 0===t&&(t=!1),t?(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 e=0;e<this.__scene.children.length;e++)this.draw(this.__scene.children[e],t);return this},t.prototype.draw=function(t,e){void 0===e&&(e=!1),e||(W=!0);var i,r,n,o,a={matrix:t.matrix.value()},s={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var _=0;_<t.mesh.length;_++)e?q("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[_].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},a,s):q("region"+this.__unique,this.painter,t.mesh[_],a,s);this.__getColor=(i=this.__regionPainter,r=i.drawingBufferWidth,n=i.drawingBufferHeight,o=new Uint8Array(4*r*n),i.readPixels(0,0,r,n,i.RGBA,i.UNSIGNED_BYTE,o),function(t,e){return"rgba("+o[4*((e=n-e)*r+t)]+","+o[4*(e*r+t)+1]+","+o[4*(e*r+t)+2]+","+o[4*(e*r+t)+3]+")"})},t.prototype.render=function(t){"matrix"in t||(t.matrix=new r),"region"in t||(t.region="");for(var e=0;e<t.mesh.length;e++){var i=t.mesh[e];i.geometry.attributes.normal&&Array.isArray(i.geometry.attributes.normal.array)&&(i.geometry.attributes.normal.array=new Float32Array(i.geometry.attributes.normal.array)),i.geometry.attributes.position&&Array.isArray(i.geometry.attributes.position.array)&&(i.geometry.attributes.position.array=new Float32Array(i.geometry.attributes.position.array)),i.geometry.attributes.uv&&Array.isArray(i.geometry.attributes.uv.array)&&(i.geometry.attributes.uv.array=new Float32Array(i.geometry.attributes.uv.array)),i.geometry.index&&Array.isArray(i.geometry.index.array)&&(i.geometry.index.array=new Uint8Array(i.geometry.index.array))}this.__scene.children.push(t),this.draw(t)},t.prototype.setRegion=function(t){return this.__regionName=t+"",t?(null==this.__regionList[t]&&(this.__regionList[t]=h(h([],this.__regionAssemble(),!0),[1],!1)),this.__regionColor=this.__regionList[t]):this.__regionColor=[0,0,0,1],this},t.prototype.getRegion=function(t,e){var i=this;return W&&this.review(!0),W=!1,new Promise((function(r,n){var o=i.__getColor(t,e);for(var a in i.__regionList){var s=i.__regionList[a];if("rgba("+255*s[0]+","+255*s[1]+","+255*s[2]+","+255*s[3]+")"==o){r(a);break}}r("")}))},t}(),Y=function(t){function e(e){if(!e)throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");var i,r,n=e.clientWidth,o=e.clientHeight,a=e;a._vislite_canvas_?(i=a._vislite_canvas_[0],r=a._vislite_canvas_[1]):(r=document.createElement("canvas"),e.appendChild(r),r.style.position="absolute",r.style.zIndex="-1",i=document.createElement("canvas"),e.appendChild(i),a._vislite_canvas_=[i,r],e.setAttribute("vislite","WebGL"));for(var s=0,_=[i,r];s<_.length;s++){var h=_[s];h.style.width=n+"px",h.setAttribute("width",n+""),h.style.height=o+"px",h.setAttribute("height",o+"")}return t.call(this,i,r)||this}return _(e,t),e}(V),j=function(t,e,i,r){var n=Math.cos(t),o=Math.sin(t);return[e*n-i*o,e*o+i*n,r]},Z=function(){function t(t,e){void 0===t&&(t=7),void 0===e&&(e=[107,36]),this.name="Eoap",this.__scale=t,this.__center=e}return t.prototype.use=function(t,e){var i,r,n,o,a,s,_=(i=(360-e)/180*Math.PI,r=100*this.__scale,n=0,o=0,a=Math.cos(i),s=Math.sin(i),[o*s+r*a,n,o*a-r*s]);return _=j(t/180*Math.PI,_[0],_[1],_[2]),_=j((90-this.__center[0])/180*Math.PI,_[0],_[1],_[2]),_=function(t,e,i,r){var n=Math.cos(t),o=Math.sin(t);return[e,i*n-r*o,i*o+r*n]}((90-this.__center[1])/180*Math.PI,_[0],_[1],_[2]),[-_[0],_[1],_[2]]},t}(),Q=function(t,e){void 0===t&&(t=7),void 0===e&&(e=[107,36]),this.name="Mercator";var i=100*t*Math.PI/180,r=i*e[0],n=-1*i*e[1];this.use=function(t,e){return[.8*(i*t-r),-1*i*e-n]}},K=function(t,e){var i=t.getBoundingClientRect();return{x:e.clientX-i.left,y:e.clientY-i.top}};return{Cardinal:e,Hermite:t,Matrix4:r,rotate:n,getLoopColors:function(t,e){void 0===e&&(e=1);var i=["rgba(84,112,198,"+e+")","rgba(145,204,117,"+e+")","rgba(250,200,88,"+e+")","rgba(238,102,102,"+e+")","rgba(115,192,222,"+e+")","rgba(59,162,114,"+e+")","rgba(252,132,82,"+e+")","rgba(154,96,180,"+e+")","rgba(234,124,204,"+e+")"],r=[];if(t<=i.length)return i;if(t%i.length==0)for(var n=0;n<t/i.length;n++)r=r.concat(i);else{for(var o=1;o<t/i.length;o++)r=r.concat(i);if(t%i.length==1)r=r.concat(i[4]);else for(var a=0;a<t%i.length;a++)r=r.concat(i[a])}return r},animation:function(t,e,i){void 0===e&&(e=400),void 0===i&&(i=function(){});var r={timer:function(t,e,i){if(!t)throw new Error("Tick is required!");var n=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return a.push({id:n,createTime:new Date,tick:t,duration:e,callback:i}),r.start(),n},start:function(){o||(o=setInterval(r.tick,13))},tick:function(){var t,e,i,n,o,s,_,h=a;for((a=[]).length=0,e=0;e<h.length;e++)t=(o=h[e]).createTime,i=o.tick,s=o.duration,n=o.callback,i(_=(_=(+(new Date).valueOf()-t.valueOf())/s)>1?1:_),_<1&&o.id?a.push(o):n(_);a.length<=0&&r.stop()},stop:function(){o&&(clearInterval(o),o=null)}},n=r.timer((function(e){t(e)}),e,i);return function(){var t;for(t in a)if(a[t].id==n)return void(a[t].id=void 0)}},ruler:function(t,e,i){if(t<e){var r=e;e=t,t=r}else if(t==e)return[t];var n=function(t){for(var e=t<100&&t>-100?10:.1,i=-1,r=t;10==e?r>=-100&&r<=100:r<=-100||r>=100;)i+=1,r*=e;if(10==e)return Math.pow(10,i);for(var n="0.",o=1;o<i;o++)n+="0";return+(n+"1")}(t-e),o=Math.ceil((t-e)*n/i),a=(o={3:2,4:5,6:5,7:5,8:10,9:10,11:10,12:10,13:15,14:15,16:15,17:15,18:20,19:20,21:20,22:20,23:25,24:25,26:25,27:25}[o]||o)/n,s=Math.floor(e/a)*a,_=[];_.push(s);for(var h=1;_[_.length-1]<t;h++)_.push(s+a*h);return _},SVG:C,Canvas:B,WebGL:Y,Eoap:Z,Mercator:Q,viewHandler:function(t){var e=document.getElementsByTagName("body")[0];e.addEventListener("keydown",(function(e){var i=function(t){return{37:"left",38:"up",39:"right",40:"down"}[t.keyCode||t.which]}(e);"up"==i?t({type:"lookUp",normal:[],value:.1}):"down"==i?t({type:"lookDown",normal:[],value:.1}):"left"==i?t({type:"lookLeft",normal:[],value:.1}):"right"==i&&t({type:"lookRight",normal:[],value:.1})}));var i=null,r=function(r){if(null!=i){var n=K(e,r),o=[n.x-i.x,i.y-n.y],a=[o[1],-1*o[0],0];0==a[0]&&0==a[1]||(t({type:"rotate",normal:a,value:.01*(Math.abs(n.x-i.x)+Math.abs(n.y-i.y))}),i=n)}};e.addEventListener("mousedown",(function(t){i=K(e,t)})),e.addEventListener("mouseup",(function(t){i=null})),e.addEventListener("mousemove",(function(t){r(t)})),e.addEventListener("touchend",(function(t){i=null})),e.addEventListener("touchstart",(function(t){i=K(e,t)})),e.addEventListener("touchmove",(function(t){r(t.touches[0])}));var n=function(e){0!=e&&t({type:"scale",value:e<0?.899:1.101,normal:[]})};e.addEventListener("mousewheel",(function(t){n(t.wheelDelta)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(t){n(-1*t.detail)}),!1)}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).VISLite=e();
15
+ var t,e;t=this,e=function(){"use strict";var t=function(){function t(t){void 0===t&&(t=.5),this.name="Hermite",this.__u=t}return t.prototype.setP=function(t,e,i,r,n,o){if(!(t<i))throw new Error("The point x-position should be increamented!");this.__a=t,this.__b=i;var a=this.__u*n,s=this.__u*o;return e/=i-t,r/=i-t,this.__MR=[2*e-2*r+a+s,3*r-3*e-2*a-s,a,e],this},t.prototype.use=function(t){if(this.__MR){var e=(t-this.__a)/(this.__b-this.__a),i=e*e;return(e*i*this.__MR[0]+i*this.__MR[1]+e*this.__MR[2]+this.__MR[3])*(this.__b-this.__a)}throw new Error("You shoud first set the position!")},t}(),e=function(){function e(t){void 0===t&&(t=0),this.name="Cardinal",this.__t=t}return e.prototype.setP=function(e){this.__HS={x:[],h:[]};var i,r,n=(e[1][1]-e[0][1])/(e[1][0]-e[0][0]);for(this.__HS.x[0]=e[0][0],i=1;i<e.length;i++){if(e[i][0]<=e[i-1][0])throw new Error("The point position should be increamented!");this.__HS.x[i]=e[i][0],r=i<e.length-1?(e[i+1][1]-e[i-1][1])/(e[i+1][0]-e[i-1][0]):(e[i][1]-e[i-1][1])/(e[i][0]-e[i-1][0]),this.__HS.h[i-1]=new t(.5*(1-this.__t)).setP(e[i-1][0],e[i-1][1],e[i][0],e[i][1],n,r),n=r}return this},e.prototype.use=function(t){if(this.__HS){for(this.__i=-1;this.__i+1<this.__HS.x.length&&(t>this.__HS.x[this.__i+1]||-1==this.__i&&t>=this.__HS.x[this.__i+1]);)this.__i+=1;return this.__i<0?this.__HS.h[0].use(this.__HS.x[0]):this.__i>=this.__HS.h.length?this.__HS.h[this.__HS.h.length-1].use(this.__HS.x[this.__HS.x.length-1]):this.__HS.h[this.__i].use(t)}throw new Error("You shoud first set the position!")},e}(),i=function(t,e){for(var i=[],r=0;r<4;r++)for(var n=0;n<e.length/4;n++)i[4*n+r]=t[r]*e[4*n]+t[r+4]*e[4*n+1]+t[r+8]*e[4*n+2]+t[r+12]*e[4*n+3];return i},r=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,e,r,n){return void 0===n&&(n=0),this.__matrix4=i(function(t,e,i,r){void 0===r&&(r=0);var n=Math.sqrt(e*e+i*i+r*r);return[1,0,0,0,0,1,0,0,0,0,1,0,e*t/n,i*t/n,r*t/n,1]}(t,e,r,n),this.__matrix4),this},t.prototype.rotate=function(t,e,r,n,o,a,s){var _=function(t,e,i,r,n,o){if("number"==typeof t&&"number"==typeof e){if("number"!=typeof i?(i=0,r=t,n=e,o=1):"number"==typeof r&&"number"==typeof n&&"number"==typeof o||(r=t,n=e,o=i,t=0,e=0,i=0),t==r&&e==n&&i==o)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((r-t)*(r-t)+(n-e)*(n-e)),s=0!=a?(n-e)/a:1,_=0!=a?(r-t)/a:0,h=(r-t)*_+(n-e)*s,u=o-i,l=Math.sqrt(h*h+u*u),c=0!=l?u/l:1,f=0!=l?h/l:0;return[[s,c*_,_*f,0,-_,s*c,s*f,0,0,-f,c,0,e*_-t*s,i*f-t*_*c-e*s*c,-t*_*f-e*s*f-i*c,1],[s,-_,0,0,c*_,c*s,-f,0,_*f,s*f,c,0,t,e,i,1]]}throw new Error("a1 and b1 is required!")}(e,r,n,o,a,s);return this.__matrix4=i(i(i(_[1],function(t){var e=Math.sin(t),i=Math.cos(t);return[i,e,0,0,-e,i,0,0,0,0,1,0,0,0,0,1]}(t)),_[0]),this.__matrix4),this},t.prototype.scale=function(t,e,r,n,o,a){return void 0===n&&(n=0),void 0===o&&(o=0),void 0===a&&(a=0),this.__matrix4=i(function(t,e,i,r,n,o){return void 0===r&&(r=0),void 0===n&&(n=0),void 0===o&&(o=0),[t,0,0,0,0,e,0,0,0,0,i,0,r-r*t,n-n*e,o-o*i,1]}(t,e,r,n,o,a),this.__matrix4),this},t.prototype.multiply=function(t,e){return void 0===e&&(e=!1),this.__matrix4=e?i(this.__matrix4,t):i(t,this.__matrix4),this},t.prototype.use=function(t,e,r,n){return void 0===r&&(r=0),void 0===n&&(n=1),i(this.__matrix4,[t,e,r,n])},t.prototype.value=function(){return this.__matrix4},t}();function n(t,e,i,r,n){var o=Math.cos(i),a=Math.sin(i);return[(r-t)*o-(n-e)*a+t,(r-t)*a+(n-e)*o+e]}var o,a=[],s=function(t,e){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},s(t,e)};function _(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}function h(t,e,i){if(i||2===arguments.length)for(var r,n=0,o=e.length;n<o;n++)!r&&n in e||(r||(r=Array.prototype.slice.call(e,0,n)),r[n]=e[n]);return t.concat(r||Array.prototype.slice.call(e))}var u=["href","title","show","type","role","actuate"],l=function(t,e,i){u.indexOf(e)>-1?t.setAttributeNS("http://www.w3.org/1999/xlink","xlink:"+e,i+""):t.setAttribute(e,i+"")},c=l;function f(t,e){l(t,"stroke",e.strokeStyle),l(t,"fill",e.fillStyle),l(t,"stroke-dasharray",e.lineDash.join(","))}function p(t,e){l(t,"fill",e.fillStyle)}function g(t,e){l(t,"stroke",e.strokeStyle),l(t,"fill","none"),l(t,"stroke-dasharray",e.lineDash.join(","))}var m=function(t,e,i,r,n){var o=Math.cos(i),a=Math.sin(i);return[+((r-t)*o-(n-e)*a+t).toFixed(7),+((r-t)*a+(n-e)*o+e).toFixed(7)]};function v(t,e,i,r,n,o,a){e<0&&(t+=e,e*=-1);var s,_=[];s=m(0,0,t,n,0),_[0]=s[0],_[1]=s[1],s=m(0,0,e,s[0],s[1]),_[2]=s[0],_[3]=s[1],s=m(0,0,t,o,0),_[4]=s[0],_[5]=s[1],s=m(0,0,e,s[0],s[1]),_[6]=s[0],_[7]=s[1],a(t,t+e,_[0]+i,_[1]+r,_[4]+i,_[5]+r,_[2]+i,_[3]+r,_[6]+i,_[7]+r,.5*(o-n))}var d=function(t,e,i,r,n){if("text"!==t.nodeName.toLowerCase())throw new Error("Need a <text> !");c(t,"dy",{top:.5*e["font-size"],middle:0,bottom:.5*-e["font-size"]}[e.textBaseline]),function(t,e){for(var i in e)t.style[i]=e[i]}(t,{"text-anchor":{left:"start",right:"end",center:"middle"}[e.textAlign],"dominant-baseline":"central","font-size":e["font-size"]+"px","font-family":e["font-family"]}),c(t,"x",i),c(t,"y",r),"number"==typeof n&&c(t,"transform","rotate("+(n%=360)+","+i+","+r+")")},y=function(t,e,i,r){if("circle"!==t.nodeName.toLowerCase())throw new Error("Need a <circle> !");c(t,"cx",e),c(t,"cy",i),c(t,"r",r)},E=function(t,e){if("path"!==t.nodeName.toLowerCase())throw new Error("Need a <path> !");c(t,"d",e)},b=function(t,e,i,r,n){if("rect"!==t.nodeName.toLowerCase())throw new Error("Need a <rect> !");n<0&&(i-=n*=-1),r<0&&(e-=r*=-1),c(t,"x",e),c(t,"y",i),c(t,"width",r),c(t,"height",n)},x=function(t,e,i,r,n,o,a,s){if("path"!==t.nodeName.toLowerCase())throw new Error("Need a <path> !");if(a%=2*Math.PI,n>o){var _=n;n=o,o=_}s>=1.999999*Math.PI||s<=1.999999*-Math.PI?s=1.999999*Math.PI:s%=2*Math.PI,v(a,s,i,r,n,o,(function(i,r,a,s,_,h,u,l,f,p,g){var m=r-i>Math.PI?1:0,v="M"+a+" "+s;g<0&&(g=-g),v+="A"+n+" "+n+" 0 "+m+" 1 "+u+" "+l,"round"==e["arc-end-cap"]?v+="A"+g+" "+g+" 0 1 0 "+f+" "+p:"-round"==e["arc-end-cap"]?v+="A"+g+" "+g+" 0 1 1 "+f+" "+p:v+="L"+f+" "+p,v+="A"+o+" "+o+" 0 "+m+" 0 "+_+" "+h,"round"==e["arc-start-cap"]?v+="A"+g+" "+g+" 0 1 0 "+a+" "+s:"-round"==e["arc-start-cap"]?v+="A"+g+" "+g+" 0 1 1 "+a+" "+s:v+="L"+a+" "+s,"butt"==e["arc-start-cap"]&&(v+="Z"),c(t,"d",v)}))},w={"font-size":"fontSize","font-family":"fontFamily","arc-start-cap":"arcStartCap","arc-end-cap":"arcEndCap"},T=function(){function t(t){this.name="SVG",this.__config={fillStyle:"#000",strokeStyle:"#000",lineWidth:1,textAlign:"left",textBaseline:"middle","font-size":16,"font-family":"sans-serif","arc-start-cap":"butt","arc-end-cap":"butt",lineDash:[]},this.__path="",this.__currentPosition=[],this.__svg=t}return t.prototype.config=function(t){if("object"!=typeof t)return this.__config[w[t]||t];for(var e in t){var i=w[e]||e;this.__config[i]=t[e]}return this},t.prototype.useEl=function(t){return this.__useEl=t,this},t.prototype.getEl=function(){return this.__useEl},t.prototype.appendEl=function(t,e){var i;return e=e||this.__svg,"string"==typeof t&&(i=t,t=document.createElementNS("http://www.w3.org/2000/svg",i)),e.appendChild(t),this.__useEl=t,this},t.prototype.appendBoard=function(t,e){var i=t;if("string"==typeof t&&(i={text:"text",path:"path",arc:"path",circle:"circle",rect:"rect"}[t]||""),""==i)throw new Error("Unsupported drawing method:"+t);return this.appendEl(i,e)},t.prototype.remove=function(){if(!this.__useEl)throw new Error("Currently, no node can be deleted.");return this.__useEl.parentNode.removeChild(this.__useEl),this},t.prototype.attr=function(t){if(!this.__useEl)throw new Error("Currently, no node can be modified or viewed.");if("object"!=typeof t)return function(t,e){return u.indexOf(e)>-1&&(e="xlink:"+e),t.getAttribute(e)}(this.__useEl,t);for(var e in t)c(this.__useEl,e,t[e]);return this},t.prototype.fillText=function(t,e,i,r){return void 0===r&&(r=0),d(this.__useEl,this.__config,e,i,r),this.__useEl.textContent=t,p(this.__useEl,this.__config),this},t.prototype.strokeText=function(t,e,i,r){return void 0===r&&(r=0),d(this.__useEl,this.__config,e,i,r),this.__useEl.textContent=t,g(this.__useEl,this.__config),this},t.prototype.fullText=function(t,e,i,r){return void 0===r&&(r=0),d(this.__useEl,this.__config,e,i,r),this.__useEl.textContent=t,f(this.__useEl,this.__config),this},t.prototype.fillArc=function(t,e,i,r,n,o){return x(this.__useEl,this.__config,t,e,i,r,n,o),p(this.__useEl,this.__config),this},t.prototype.strokeArc=function(t,e,i,r,n,o){return x(this.__useEl,this.__config,t,e,i,r,n,o),g(this.__useEl,this.__config),this},t.prototype.fullArc=function(t,e,i,r,n,o){return x(this.__useEl,this.__config,t,e,i,r,n,o),f(this.__useEl,this.__config),this},t.prototype.fillCircle=function(t,e,i){return y(this.__useEl,t,e,i),p(this.__useEl,this.__config),this},t.prototype.strokeCircle=function(t,e,i){return y(this.__useEl,t,e,i),g(this.__useEl,this.__config),this},t.prototype.fullCircle=function(t,e,i){return y(this.__useEl,t,e,i),f(this.__useEl,this.__config),this},t.prototype.fillRect=function(t,e,i,r){return b(this.__useEl,t,e,i,r),p(this.__useEl,this.__config),this},t.prototype.strokeRect=function(t,e,i,r){return b(this.__useEl,t,e,i,r),g(this.__useEl,this.__config),this},t.prototype.fullRect=function(t,e,i,r){return b(this.__useEl,t,e,i,r),f(this.__useEl,this.__config),this},t.prototype.beginPath=function(){return this.__currentPosition=[],this.__path="",this},t.prototype.closePath=function(){return this.__path+="Z",this},t.prototype.moveTo=function(t,e){return this.__currentPosition=[t,e],this.__path+="M"+t+" "+e,this},t.prototype.lineTo=function(t,e){return this.__currentPosition=[t,e],this.__path+=(""==this.__path?"M":"L")+t+" "+e,this},t.prototype.fill=function(){return E(this.__useEl,this.__path),p(this.__useEl,this.__config),this},t.prototype.stroke=function(){return E(this.__useEl,this.__path),g(this.__useEl,this.__config),this},t.prototype.full=function(){return E(this.__useEl,this.__path),f(this.__useEl,this.__config),this},t.prototype.arc=function(t,e,i,r,o){var a=n(t,e,r,t+i,e),s=n(t,e,r+o,t+i,e);return r=r/Math.PI*180,o=o/Math.PI*180,""==this.__path?this.__path+="M"+a[0]+","+a[1]:a[0]==this.__currentPosition[0]&&a[1]==this.__currentPosition[1]||(this.__path+="L"+a[0]+","+a[1]),this.__path+="A"+i+","+i+" 0 "+(o>180||o<-180?1:0)+","+(o>0?1:0)+" "+s[0]+","+s[1],this},t.prototype.quadraticCurveTo=function(t,e,i,r){return this.__path+="Q"+t+" "+e+","+i+" "+r,this},t.prototype.bezierCurveTo=function(t,e,i,r,n,o){return this.__path+="C"+t+" "+e+","+i+" "+r+","+n+" "+o,this},t}(),C=function(t){function e(e){if(!e)throw new Error("VISLite SVG:The mount point requires an HTMLElement type but encountered null.");var i=e.clientWidth,r=e.clientHeight,n=document.createElementNS("http://www.w3.org/2000/svg","svg");return e.appendChild(n),n.setAttribute("width",i+""),n.setAttribute("height",r+""),n.setAttribute("viewBox","0 0 "+i+" "+r),t.call(this,n)||this}return _(e,t),e}(T),A=function(t,e,i,r,n){return t.beginPath(),t.translate(i,r),t.rotate(n),t.font=e.fontStyle+" "+e.fontWeight+" "+e.fontSize+"px "+e.fontFamily,t},M=function(t,e,i,r,n,o,a,s){if(n>o){var _=n;n=o,o=_}return a%=2*Math.PI,s>=1.999999*Math.PI||s<=1.999999*-Math.PI?s=2*Math.PI:s%=2*Math.PI,v(a,s,i,r,n,o,(function(a,s,_,h,u,l,c,f,p,g,m){m<0&&(m=-m),t.beginPath(),t.moveTo(_,h),t.arc(i,r,n,a,s,!1),"round"!=e.arcEndCap?t.lineTo(p,g):t.arc(.5*(c+p),.5*(f+g),m,s-Math.PI,s,!0),t.arc(i,r,o,s,a,!0),"round"!=e.arcStartCap?t.lineTo(_,h):t.arc(.5*(_+u),.5*(h+l),m,a,a-Math.PI,!0)})),"butt"==e.arcStartCap&&t.closePath(),t},S=function(t,e,i,r){return t.beginPath(),t.moveTo(e+r,i),t.arc(e,i,r,0,2*Math.PI),t},P=function(t,e,i,r,n){return t.beginPath(),t.rect(e,i,r,n),t};function L(t,e,i,r,n){for(var o=0,a="",s=0;s<e.length;s++)t.measureText(a+e[s]).width>i?(n(a,((o+=1)-.5)*r),a=e[s]):s==e.length-1?(o+=1,n(a+e[s],(o-.5)*r)):a+=e[s];return o*r}var R=function(){function t(t,e,i){void 0===e&&(e={}),this.__region=null,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",e),this.__region=i,this.painter.textBaseline="middle",this.painter.textAlign="left"}return t.prototype.useConfig=function(t,e){if(this.__region&&["fillStyle","strokeStyle","shadowBlur","shadowColor"].indexOf(t)<0&&this.__region.useConfig(t,e),"lineDash"==t)this.painter.setLineDash&&this.painter.setLineDash(e);else if(t in this.__specialConfig)this.__specialConfig[t]=e;else{if(!(t in this.__initConfig))throw new Error("Illegal configuration item of painter : "+t+" !");this.painter[t]=e}return this},t.prototype.fillText=function(t,e,i,r){return void 0===r&&(r=0),this.__region&&this.__region.fillText(t,e,i,r),this.painter.save(),A(this.painter,this.__specialConfig,e,i,r).fillText(t,0,0),this.painter.restore(),this},t.prototype.strokeText=function(t,e,i,r){return void 0===r&&(r=0),this.__region&&this.__region.strokeText(t,e,i,r),this.painter.save(),A(this.painter,this.__specialConfig,e,i,r).strokeText(t,0,0),this.painter.restore(),this},t.prototype.fullText=function(t,e,i,r){return void 0===r&&(r=0),this.__region&&this.__region.fullText(t,e,i,r),this.painter.save(),A(this.painter,this.__specialConfig,e,i,r),this.painter.fillText(t,0,0),this.painter.strokeText(t,0,0),this.painter.restore(),this},t.prototype.fillTexts=function(t,e,i,r,n,o){var a=this;void 0===n&&(n=1.2),void 0===o&&(o=0),this.__region&&this.__region.fillTexts(t,e,i,r,n),this.painter.save(),A(this.painter,this.__specialConfig,e,i,o);var s=L(this.painter,t,r,this.__specialConfig.fontSize*n,(function(t,e){a.painter.fillText(t,0,e)}));return this.painter.restore(),s},t.prototype.strokeTexts=function(t,e,i,r,n,o){var a=this;void 0===n&&(n=1.2),void 0===o&&(o=0),this.__region&&this.__region.fillTexts(t,e,i,r,n),this.painter.save(),A(this.painter,this.__specialConfig,e,i,o);var s=L(this.painter,t,r,this.__specialConfig.fontSize*n,(function(t,e){a.painter.strokeText(t,0,e)}));return this.painter.restore(),s},t.prototype.fullTexts=function(t,e,i,r,n,o){var a=this;void 0===n&&(n=1.2),void 0===o&&(o=0),this.__region&&this.__region.fillTexts(t,e,i,r,n),this.painter.save(),A(this.painter,this.__specialConfig,e,i,o);var s=L(this.painter,t,r,this.__specialConfig.fontSize*n,(function(t,e){a.painter.fillText(t,0,e),a.painter.strokeText(t,0,e)}));return this.painter.restore(),s},t.prototype.beginPath=function(){return this.__region&&this.__region.beginPath(),this.painter.beginPath(),this},t.prototype.closePath=function(){return this.__region&&this.__region.closePath(),this.painter.closePath(),this},t.prototype.moveTo=function(t,e){return this.__region&&this.__region.moveTo(t,e),this.painter.moveTo(Math.round(t)+.5,Math.round(e)+.5),this},t.prototype.lineTo=function(t,e){return this.__region&&this.__region.lineTo(t,e),this.painter.lineTo(Math.round(t)+.5,Math.round(e)+.5),this},t.prototype.arc=function(t,e,i,r,n){return this.__region&&this.__region.arc(t,e,i,r,n),this.painter.arc(t,e,i,r,r+n,n<0),this},t.prototype.fill=function(){return this.__region&&this.__region.fill(),this.painter.fill(),this},t.prototype.stroke=function(){return this.__region&&this.__region.stroke(),this.painter.stroke(),this},t.prototype.full=function(){return this.__region&&this.__region.full(),this.painter.fill(),this.painter.stroke(),this},t.prototype.save=function(){return this.__region&&this.__region.save(),this.painter.save(),this},t.prototype.restore=function(){return this.__region&&this.__region.restore(),this.painter.restore(),this},t.prototype.quadraticCurveTo=function(t,e,i,r){return this.__region&&this.__region.quadraticCurveTo(t,e,i,r),this.painter.quadraticCurveTo(t,e,i,r),this},t.prototype.bezierCurveTo=function(t,e,i,r,n,o){return this.__region&&this.__region.bezierCurveTo(t,e,i,r,n,o),this.painter.bezierCurveTo(t,e,i,r,n,o),this},t.prototype.clearRect=function(t,e,i,r){return this.__region&&this.__region.clearRect(t,e,i,r),this.painter.clearRect(t,e,i,r),this},t.prototype.fillArc=function(t,e,i,r,n,o){return this.__region&&this.__region.fillArc(t,e,i,r,n,o),M(this.painter,this.__specialConfig,t,e,i,r,n,o).fill(),this},t.prototype.strokeArc=function(t,e,i,r,n,o){return this.__region&&this.__region.strokeArc(t,e,i,r,n,o),M(this.painter,this.__specialConfig,t,e,i,r,n,o).stroke(),this},t.prototype.fullArc=function(t,e,i,r,n,o){return this.__region&&this.__region.fullArc(t,e,i,r,n,o),M(this.painter,this.__specialConfig,t,e,i,r,n,o),this.painter.fill(),this.painter.stroke(),this},t.prototype.fillCircle=function(t,e,i){return this.__region&&this.__region.fillCircle(t,e,i),S(this.painter,t,e,i).fill(),this},t.prototype.strokeCircle=function(t,e,i){return this.__region&&this.__region.strokeCircle(t,e,i),S(this.painter,t,e,i).stroke(),this},t.prototype.fullCircle=function(t,e,i){return this.__region&&this.__region.fullCircle(t,e,i),S(this.painter,t,e,i),this.painter.fill(),this.painter.stroke(),this},t.prototype.fillRect=function(t,e,i,r){return this.__region&&this.__region.fillRect(t,e,i,r),P(this.painter,t,e,i,r).fill(),this},t.prototype.strokeRect=function(t,e,i,r){return this.__region&&this.__region.strokeRect(t,e,i,r),P(this.painter,t,e,i,r).stroke(),this},t.prototype.fullRect=function(t,e,i,r){return this.__region&&this.__region.fullRect(t,e,i,r),P(this.painter,t,e,i,r),this.painter.fill(),this.painter.stroke(),this},t}();function k(t,e,i,r){for(var n=[],o=0;o<r;o++)n[o]=t;return function(){for(var o=0;o<r;o++){if(n[o]<e){n[o]=+(n[o]+i).toFixed(7);break}o<r-1&&(n[o]=t)}return n}}var I={"font-size":"fontSize","font-family":"fontFamily","font-weight":"fontWeight","font-style":"fontStyle","arc-start-cap":"arcStartCap","arc-end-cap":"arcEndCap"},U=function(t){function e(e,i){var r=t.call(this,e,{},new R(i,{willReadFrequently:!0}))||this;return r.name="Canvas",r.__regionList={},r.__regionAssemble=k(0,255,1,3),r.setRegion(""),r}return _(e,t),e.prototype.config=function(t){for(var e in t){var i=I[e]||e;this.useConfig(i,t[e])}return this},e.prototype.setRegion=function(t){if(t){if(null==this.__regionList[t]){var e=this.__regionAssemble();this.__regionList[t]="rgb("+e[0]+","+e[1]+","+e[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},e.prototype.getRegion=function(t,e){var i=this;return new Promise((function(r,n){var o=i.__region.painter.getImageData(t-.5,e-.5,1,1),a=o.data,s=function(){for(var t in i.__regionList)if("rgb("+a[0]+","+a[1]+","+a[2]+")"==i.__regionList[t]){r(t);break}r("")};a?s():o.then((function(t){a=t,s()}))}))},e.prototype.getContext=function(t){return void 0===t&&(t=!1),t?this.__region.painter:this.painter},e}(R),B=function(t){function e(e){var i=this;if(!e)throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.");var r,n,o=e.clientWidth,a=e.clientHeight,s=e;s._vislite_canvas_?(r=s._vislite_canvas_[0],n=s._vislite_canvas_[1]):(r=document.createElement("canvas"),e.appendChild(r),n=document.createElement("canvas"),s._vislite_canvas_=[r,n],e.setAttribute("vislite","Canvas"));for(var _=0,h=[r,n];_<h.length;_++){var u=h[_];u.style.width=o+"px",u.setAttribute("width",o+""),u.style.height=a+"px",u.setAttribute("height",a+"")}return(i=t.call(this,r,n)||this).__canvas=r,i}return _(e,t),e.prototype.toDataURL=function(){var t=this;return new Promise((function(e){e(t.__canvas.toDataURL())}))},e}(U);function N(t,e,i){void 0===i&&(i={});for(var r=["webgl","experimental-webgl","webkit-3d","moz-webgl"],n=null,o=0;o<r.length;o++){try{n=t.getContext(r[o],i)}catch(t){}if(n)break}if(!n)throw new Error("Non canvas or browser does not support webgl.");var a=n.canvas.width,s=n.canvas.height,_=a*e,h=s*e;return n.viewport(.5*(a-_),.5*(s-h),_,h),n.depthFunc(n.LEQUAL),n.enable(n.DEPTH_TEST),n}function D(t){var e=t.drawingBufferWidth,i=t.drawingBufferHeight,r=new Uint8Array(4*e*i);return t.readPixels(0,0,e,i,t.RGBA,t.UNSIGNED_BYTE,r),function(t,n){return"rgba("+r[4*((n=i-n)*e+t)]+","+r[4*(n*e+t)+1]+","+r[4*(n*e+t)+2]+","+r[4*(n*e+t)+3]+")"}}var F=function(){function t(t,e){void 0===e&&(e=!1),this.__painter=t,this.__isElement=e,this.__buffer=function(t){return t.createBuffer()}(t),this.__type=e?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,e,i,r){var n=i?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(n,e,r)}(this.__painter,t,this.__isElement,this.__painter.STATIC_DRAW),this.__fsize=t.BYTES_PER_ELEMENT,this},t.prototype.divide=function(t,e,i,r){return void 0===r&&(r=0),function(t,e,i,r,n,o,a){t.vertexAttribPointer(e,i,r,a,n,o),t.enableVertexAttribArray(e)}(this.__painter,t,e,this.__painter.FLOAT,i*this.__fsize,r*this.__fsize,!1),this},t}(),z=function(){function t(t,e,i){void 0===i&&(i=0),this.__painter=t,this.__type={"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP}[e],this.__texture=function(t,e,i){var r=t.createTexture();return e==t.TEXTURE_2D&&t.activeTexture(t["TEXTURE"+i]),t.bindTexture(e,r),r}(t,this.__type,i),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,e,i,r,n,o){t.texImage2D(e,i,r,r,n,o)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t),this},t.prototype.useCube=function(t,e,i){return function(t,e,i,r,n,o,a,s,_){for(var h,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],l=0;l<u.length;l++)o[l]&&(h=u[l],t.texImage2D(h,i,r,a,s,0,r,n,null),t.bindTexture(e,_),t.texImage2D(h,i,r,r,n,o[l]));t.generateMipmap(e)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,e,i,this.__texture),this},t}(),H={};function O(t,e,i){var r=t+"-"+i;return H[r]||(H[r]=new z(e,i)),H[r]}var G=function(t,e,i){var r=t.createShader(e);if(null==r)throw new Error("Unable to create shader!");if(t.shaderSource(r,i),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error("Failed to compile shader:"+t.getShaderInfoLog(r));return r},X=function(){function t(t){this.__painter=t}return t.prototype.use=function(){return this.__painter.useProgram(this.program),this},t.prototype.compile=function(t,e){return this.program=function(t,e,i){var r=G(t,t.VERTEX_SHADER,e),n=G(t,t.FRAGMENT_SHADER,i),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,n),t.linkProgram(o),!t.getProgramParameter(o,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(o));return o}(this.__painter,t,e),this},t}(),W={};function q(t,e,i,r,n){var o=function(t,e,i){var r=t+(i.geometry.attributes.normal?"1":"0")+(i.material.image?"1":"0")+(i.material.color?"1":"0")+(i.material.cube?"1":"0");if(W[r])return W[r].use();var n="\n attribute vec4 a_position;\n\n ".concat(i.geometry.attributes.normal?"attribute vec4 a_normal;varying vec3 v_normal;":"","\n\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;\n\n ").concat(i.material.image?"attribute vec2 a_textcoord;varying vec2 v_textcoord;":"","\n\n void main(){\n vec4 temp = a_position;\n\n // 应用变换矩阵:屏幕比调平矩阵、世界矩阵、物体矩阵\n temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;\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\n ").concat(i.geometry.attributes.normal?"v_normal = normalize(vec3(a_normal));":"","\n ").concat(i.material.image?"v_textcoord = a_textcoord;":"","\n }\n "),o="\n precision mediump float;\n\n ".concat(i.geometry.attributes.normal?"varying vec3 v_normal;":"","\n ").concat(i.material.color?"uniform vec4 u_color;":"","\n ").concat(i.material.cube?"uniform samplerCube u_texture;":"","\n ").concat(i.material.image?"uniform sampler2D u_sampler;varying vec2 v_textcoord;":"","\n\n void main(){\n ").concat(i.material.color?"gl_FragColor = u_color;":"","\n ").concat(i.material.cube?"gl_FragColor = textureCube(u_texture,normalize(v_normal));":"","\n ").concat(i.material.image?"gl_FragColor = texture2D(u_sampler,v_textcoord);":"","\n }\n "),a=new X(e).compile(n,o).use();return W[r]=a,a}(t,e,i);if(new F(e).use().write(i.geometry.attributes.position.array).divide(e.getAttribLocation(o.program,"a_position"),i.geometry.attributes.position.itemSize,3,0),e.uniformMatrix4fv(e.getUniformLocation(o.program,"u_matrix_world"),!1,n.matrix),e.uniformMatrix4fv(e.getUniformLocation(o.program,"u_matrix_proporion"),!1,n.proporion),e.uniformMatrix4fv(e.getUniformLocation(o.program,"u_matrix_mesh"),!1,r.matrix),i.geometry.attributes.normal&&new F(e).use().write(i.geometry.attributes.normal.array).divide(e.getAttribLocation(o.program,"a_normal"),i.geometry.attributes.normal.itemSize,3,0),"color"in i.material)e.uniform4f(e.getUniformLocation(o.program,"u_color"),i.material.color.r,i.material.color.g,i.material.color.b,i.material.color.alpha);else if("cube"in i.material){var a=i.material.cube.right.image.value.width;O(t,e,"cube").useCube([i.material.cube.right.image.value,i.material.cube.left.image.value,i.material.cube.top.image.value,i.material.cube.bottom.image.value,i.material.cube.far.image.value,i.material.cube.near.image.value],a,a)}else"image"in i.material&&(e.uniform1i(e.getUniformLocation(o.program,"u_sampler"),0),new F(e).use().write(i.geometry.attributes.uv.array).divide(e.getAttribLocation(o.program,"a_textcoord"),i.geometry.attributes.uv.itemSize,2,0),O(t,e,"2d").useImage(i.material.image.value));i.geometry.index?(new F(e,!0).use().write(i.geometry.index.array),e.drawElements(e[i.geometry.type],i.geometry.index.count,e.UNSIGNED_BYTE,0)):e.drawArrays(e[i.geometry.type],0,i.geometry.attributes.position.count)}var V=!1,Y=function(){function t(t,e){this.name="WebGL",this.__getColor=function(t,e){return"rgba(0,0,0,1)"},this.__regionList={},this.__regionAssemble=k(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new r([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,10])},this.__unique=(new Date).valueOf(),this.painter=N(t,10),this.__regionPainter=N(e,10,{});var i=this.painter.canvas.width/this.painter.canvas.height,n=1,o=1;i>1?n=1/i:o=i;var a=Math.min(n,o);this.__proporion=[n,0,0,0,0,o,0,0,0,0,a,0,0,0,0,1]}return t.prototype.matrix=function(t){return new r(t)},t.prototype.getMatrix=function(){return this.__scene.matrix},t.prototype.getObject3D=function(){return this.__scene.children},t.prototype.review=function(t){void 0===t&&(t=!1),t?(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 e=0;e<this.__scene.children.length;e++)this.draw(this.__scene.children[e],t);return this},t.prototype.draw=function(t,e){void 0===e&&(e=!1),e||(V=!0);var i={matrix:t.matrix.value()},r={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var n=0;n<t.mesh.length;n++)e?(q("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,r),this.__getColor=D(this.__regionPainter)):q("region"+this.__unique,this.painter,t.mesh[n],i,r)},t.prototype.render=function(t){"matrix"in t||(t.matrix=new r),"region"in t||(t.region="");for(var e=0;e<t.mesh.length;e++){var i=t.mesh[e];i.geometry.attributes.normal&&Array.isArray(i.geometry.attributes.normal.array)&&(i.geometry.attributes.normal.array=new Float32Array(i.geometry.attributes.normal.array)),i.geometry.attributes.position&&Array.isArray(i.geometry.attributes.position.array)&&(i.geometry.attributes.position.array=new Float32Array(i.geometry.attributes.position.array)),i.geometry.attributes.uv&&Array.isArray(i.geometry.attributes.uv.array)&&(i.geometry.attributes.uv.array=new Float32Array(i.geometry.attributes.uv.array)),i.geometry.index&&Array.isArray(i.geometry.index.array)&&(i.geometry.index.array=new Uint8Array(i.geometry.index.array))}this.__scene.children.push(t),this.draw(t)},t.prototype.setRegion=function(t){return this.__regionName=t+"",t?(null==this.__regionList[t]&&(this.__regionList[t]=h(h([],this.__regionAssemble(),!0),[1],!1)),this.__regionColor=this.__regionList[t]):this.__regionColor=[0,0,0,1],this},t.prototype.getRegion=function(t,e){var i=this;return V&&this.review(!0),V=!1,new Promise((function(r,n){var o=i.__getColor(t,e);for(var a in i.__regionList){var s=i.__regionList[a];if("rgba("+255*s[0]+","+255*s[1]+","+255*s[2]+","+255*s[3]+")"==o){r(a);break}}r("")}))},t}(),j=function(t){function e(e){if(!e)throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");var i,r,n=e.clientWidth,o=e.clientHeight,a=e;a._vislite_canvas_?(i=a._vislite_canvas_[0],r=a._vislite_canvas_[1]):(r=document.createElement("canvas"),e.appendChild(r),r.style.position="absolute",r.style.zIndex="-1",i=document.createElement("canvas"),e.appendChild(i),a._vislite_canvas_=[i,r],e.setAttribute("vislite","WebGL"));for(var s=0,_=[i,r];s<_.length;s++){var h=_[s];h.style.width=n+"px",h.setAttribute("width",n+""),h.style.height=o+"px",h.setAttribute("height",o+"")}return t.call(this,i,r)||this}return _(e,t),e}(Y),Z=function(t,e,i,r){var n=Math.cos(t),o=Math.sin(t);return[e*n-i*o,e*o+i*n,r]},Q=function(){function t(t,e){void 0===t&&(t=7),void 0===e&&(e=[107,36]),this.name="Eoap",this.__scale=t,this.__center=e}return t.prototype.use=function(t,e){var i,r,n,o,a,s,_=(i=(360-e)/180*Math.PI,r=100*this.__scale,n=0,o=0,a=Math.cos(i),s=Math.sin(i),[o*s+r*a,n,o*a-r*s]);return _=Z(t/180*Math.PI,_[0],_[1],_[2]),_=Z((90-this.__center[0])/180*Math.PI,_[0],_[1],_[2]),_=function(t,e,i,r){var n=Math.cos(t),o=Math.sin(t);return[e,i*n-r*o,i*o+r*n]}((90-this.__center[1])/180*Math.PI,_[0],_[1],_[2]),[-_[0],_[1],_[2]]},t}(),K=function(t,e){void 0===t&&(t=7),void 0===e&&(e=[107,36]),this.name="Mercator";var i=100*t*Math.PI/180,r=i*e[0],n=-1*i*e[1];this.use=function(t,e){return[.8*(i*t-r),-1*i*e-n]}},J=function(t,e){var i=t.getBoundingClientRect();return{x:e.clientX-i.left,y:e.clientY-i.top}};return{Cardinal:e,Hermite:t,Matrix4:r,rotate:n,getLoopColors:function(t,e){void 0===e&&(e=1);var i=["rgba(84,112,198,"+e+")","rgba(145,204,117,"+e+")","rgba(250,200,88,"+e+")","rgba(238,102,102,"+e+")","rgba(115,192,222,"+e+")","rgba(59,162,114,"+e+")","rgba(252,132,82,"+e+")","rgba(154,96,180,"+e+")","rgba(234,124,204,"+e+")"],r=[];if(t<=i.length)return i;if(t%i.length==0)for(var n=0;n<t/i.length;n++)r=r.concat(i);else{for(var o=1;o<t/i.length;o++)r=r.concat(i);if(t%i.length==1)r=r.concat(i[4]);else for(var a=0;a<t%i.length;a++)r=r.concat(i[a])}return r},animation:function(t,e,i){void 0===e&&(e=400),void 0===i&&(i=function(){});var r={timer:function(t,e,i){if(!t)throw new Error("Tick is required!");var n=(new Date).valueOf()+"_"+(1e3*Math.random()).toFixed(0);return a.push({id:n,createTime:new Date,tick:t,duration:e,callback:i}),r.start(),n},start:function(){o||(o=setInterval(r.tick,13))},tick:function(){var t,e,i,n,o,s,_,h=a;for((a=[]).length=0,e=0;e<h.length;e++)t=(o=h[e]).createTime,i=o.tick,s=o.duration,n=o.callback,i(_=(_=(+(new Date).valueOf()-t.valueOf())/s)>1?1:_),_<1&&o.id?a.push(o):n(_);a.length<=0&&r.stop()},stop:function(){o&&(clearInterval(o),o=null)}},n=r.timer((function(e){t(e)}),e,i);return function(){var t;for(t in a)if(a[t].id==n)return void(a[t].id=void 0)}},ruler:function(t,e,i){if(t<e){var r=e;e=t,t=r}else if(t==e)return[t];var n=function(t){for(var e=t<100&&t>-100?10:.1,i=-1,r=t;10==e?r>=-100&&r<=100:r<=-100||r>=100;)i+=1,r*=e;if(10==e)return Math.pow(10,i);for(var n="0.",o=1;o<i;o++)n+="0";return+(n+"1")}(t-e),o=Math.ceil((t-e)*n/i),a=(o={3:2,4:5,6:5,7:5,8:10,9:10,11:10,12:10,13:15,14:15,16:15,17:15,18:20,19:20,21:20,22:20,23:25,24:25,26:25,27:25}[o]||o)/n,s=Math.floor(e/a)*a,_=[];_.push(s);for(var h=1;_[_.length-1]<t;h++)_.push(s+a*h);return _},SVG:C,Canvas:B,WebGL:j,Eoap:Q,Mercator:K,viewHandler:function(t){var e=document.getElementsByTagName("body")[0];e.addEventListener("keydown",(function(e){var i=function(t){return{37:"left",38:"up",39:"right",40:"down"}[t.keyCode||t.which]}(e);"up"==i?t({type:"lookUp",normal:[],value:.1}):"down"==i?t({type:"lookDown",normal:[],value:.1}):"left"==i?t({type:"lookLeft",normal:[],value:.1}):"right"==i&&t({type:"lookRight",normal:[],value:.1})}));var i=null,r=function(r){if(null!=i){var n=J(e,r),o=[n.x-i.x,n.y-i.y],a=[o[1],o[0],0];0==a[0]&&0==a[1]||(t({type:"rotate",normal:a,value:.01*(Math.abs(n.x-i.x)+Math.abs(n.y-i.y))}),i=n)}};e.addEventListener("mousedown",(function(t){i=J(e,t)})),e.addEventListener("mouseup",(function(t){i=null})),e.addEventListener("mousemove",(function(t){r(t)})),e.addEventListener("touchend",(function(t){i=null})),e.addEventListener("touchstart",(function(t){i=J(e,t)})),e.addEventListener("touchmove",(function(t){r(t.touches[0])}));var n=function(e){0!=e&&t({type:"scale",value:e<0?.899:1.101,normal:[]})};e.addEventListener("mousewheel",(function(t){n(t.wheelDelta)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(t){n(-1*t.detail)}),!1)}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).VISLite=e();
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -71,10 +71,10 @@
71
71
  if (mouseP == null)
72
72
  return;
73
73
  var tempMouseP = mousePosition(el, event);
74
- var normal = [tempMouseP.x - mouseP.x, mouseP.y - tempMouseP.y];
74
+ var normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y];
75
75
  var rotateNormal = [
76
76
  normal[1],
77
- normal[0] * -1,
77
+ normal[0],
78
78
  0
79
79
  ];
80
80
  if (rotateNormal[0] == 0 && rotateNormal[1] == 0)
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0-alpha.8
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
@@ -12,4 +12,4 @@
12
12
  * alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
13
13
  * beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
14
14
  */
15
- var e,n;e=this,n=function(){"use strict";var e=function(e,n){var t=e.getBoundingClientRect();return{x:n.clientX-t.left,y:n.clientY-t.top}};return function(n){var t=document.getElementsByTagName("body")[0];t.addEventListener("keydown",(function(e){var t=function(e){return{37:"left",38:"up",39:"right",40:"down"}[e.keyCode||e.which]}(e);"up"==t?n({type:"lookUp",normal:[],value:.1}):"down"==t?n({type:"lookDown",normal:[],value:.1}):"left"==t?n({type:"lookLeft",normal:[],value:.1}):"right"==t&&n({type:"lookRight",normal:[],value:.1})}));var o=null,i=function(i){if(null!=o){var u=e(t,i),l=[u.x-o.x,o.y-u.y],a=[l[1],-1*l[0],0];0==a[0]&&0==a[1]||(n({type:"rotate",normal:a,value:.01*(Math.abs(u.x-o.x)+Math.abs(u.y-o.y))}),o=u)}};t.addEventListener("mousedown",(function(n){o=e(t,n)})),t.addEventListener("mouseup",(function(e){o=null})),t.addEventListener("mousemove",(function(e){i(e)})),t.addEventListener("touchend",(function(e){o=null})),t.addEventListener("touchstart",(function(n){o=e(t,n)})),t.addEventListener("touchmove",(function(e){i(e.touches[0])}));var u=function(e){0!=e&&n({type:"scale",value:e<0?.899:1.101,normal:[]})};t.addEventListener("mousewheel",(function(e){u(e.wheelDelta)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(e){u(-1*e.detail)}),!1)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_viewHandler=n();
15
+ var e,n;e=this,n=function(){"use strict";var e=function(e,n){var t=e.getBoundingClientRect();return{x:n.clientX-t.left,y:n.clientY-t.top}};return function(n){var t=document.getElementsByTagName("body")[0];t.addEventListener("keydown",(function(e){var t=function(e){return{37:"left",38:"up",39:"right",40:"down"}[e.keyCode||e.which]}(e);"up"==t?n({type:"lookUp",normal:[],value:.1}):"down"==t?n({type:"lookDown",normal:[],value:.1}):"left"==t?n({type:"lookLeft",normal:[],value:.1}):"right"==t&&n({type:"lookRight",normal:[],value:.1})}));var o=null,i=function(i){if(null!=o){var u=e(t,i),l=[u.x-o.x,u.y-o.y],a=[l[1],l[0],0];0==a[0]&&0==a[1]||(n({type:"rotate",normal:a,value:.01*(Math.abs(u.x-o.x)+Math.abs(u.y-o.y))}),o=u)}};t.addEventListener("mousedown",(function(n){o=e(t,n)})),t.addEventListener("mouseup",(function(e){o=null})),t.addEventListener("mousemove",(function(e){i(e)})),t.addEventListener("touchend",(function(e){o=null})),t.addEventListener("touchstart",(function(n){o=e(t,n)})),t.addEventListener("touchmove",(function(e){i(e.touches[0])}));var u=function(e){0!=e&&n({type:"scale",value:e<0?.899:1.101,normal:[]})};t.addEventListener("mousewheel",(function(e){u(e.wheelDelta)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(e){u(-1*e.detail)}),!1)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_viewHandler=n();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vislite",
3
- "version": "0.2.0-alpha.7",
3
+ "version": "0.2.0-alpha.8",
4
4
  "description": "灵活、快速、简单的数据可视化交互式跨端前端库",
5
5
  "main": "./lib/index.umd.min.js",
6
6
  "typings": "./types/index.d.ts",
@@ -25,12 +25,20 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
25
25
  ${mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : ''}
26
26
 
27
27
  void main(){
28
- vec4 temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position;
28
+ vec4 temp = a_position;
29
+
30
+ // 应用变换矩阵:屏幕比调平矩阵、世界矩阵、物体矩阵
31
+ temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;
32
+
33
+ // 把原生的WebGL使用的左手坐标系变成了右手坐标系
34
+ temp.z = -1.0 * temp.z;
29
35
 
30
36
  // 表示眼睛距离vec4(0.0,0.0,1.0)的距离
31
37
  float dist = 4.0;
32
38
 
33
39
  // 使用投影直接计算
40
+ // 为保证纹理和相对位置正确
41
+ // x、y、z的改变满足线性变换
34
42
  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));
35
43
 
36
44
  ${mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : ''}
@@ -2,7 +2,7 @@ import getWebGLContext from './getWebGLContext'
2
2
  import Object3DType from '../../../types/Object3D'
3
3
  import Scene3DType from '../../../types/Scene3D'
4
4
  import getColorFactory from './getColorFactory'
5
- import Matrix4 from '../../Matrix4/index'
5
+ import Matrix4 from '..//../Matrix4/index'
6
6
  import doDraw from './doDraw'
7
7
  import assemble from '../assemble'
8
8
 
@@ -32,7 +32,7 @@ class WebGL {
32
32
  matrix: new Matrix4([
33
33
  1, 0, 0, 0,
34
34
  0, 1, 0, 0,
35
- 0, 0, -1, 0,
35
+ 0, 0, 1, 0,
36
36
  0, 0, 0, scale
37
37
  ])
38
38
  }
@@ -131,13 +131,14 @@ class WebGL {
131
131
  }
132
132
  }
133
133
  }, meshWorld, globalWorld)
134
+
135
+ this.__getColor = getColorFactory(this.__regionPainter)
134
136
  } else {
135
137
  // 画布上
136
138
  doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld)
137
139
  }
138
140
  }
139
141
 
140
- this.__getColor = getColorFactory(this.__regionPainter)
141
142
  }
142
143
 
143
144
  render(object3D: Object3DType) {
@@ -78,6 +78,7 @@ class TextureObject {
78
78
 
79
79
  // 配置纹理
80
80
  painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST)
81
+ painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST)
81
82
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE)
82
83
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE)
83
84
  }
@@ -71,12 +71,12 @@ export default function (callback: callbackFun) {
71
71
  let tempMouseP = mousePosition(el, event)
72
72
 
73
73
  // 先求解出轨迹向量
74
- let normal = [tempMouseP.x - mouseP.x, mouseP.y - tempMouseP.y]
74
+ let normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
75
75
 
76
76
  // 方向向量旋转90deg得到旋转向量
77
77
  let rotateNormal = [
78
78
  normal[1],
79
- normal[0] * -1,
79
+ normal[0],
80
80
  0
81
81
  ]
82
82
 
@@ -37,7 +37,8 @@ export interface meshType {
37
37
  }
38
38
 
39
39
  // 点、线、还是三角形
40
- type: string // "POINTS" | "LINES" | "INE_STRIP" | "LINE_LOOP" | "TRIANGLES" | "TRIANGLE_STRIP" | "TRIANGLE_FAN"
40
+ // "POINTS" | "LINES" | "INE_STRIP" | "LINE_LOOP" | "TRIANGLES" | "TRIANGLE_STRIP" | "TRIANGLE_FAN"
41
+ type: string
41
42
  }
42
43
 
43
44
  // 材质
@@ -95,7 +96,7 @@ export interface meshType {
95
96
 
96
97
  export default interface Object3D {
97
98
 
98
- // 区域名称,如果设置为空字符串,表示此区域无需记录
99
+ // 区域名称,不设置或设置为空字符串,表示此区域无需记录
99
100
  region?: string
100
101
 
101
102
  // 变换矩阵
package/types/WebGL.d.ts CHANGED
@@ -26,4 +26,14 @@ export default interface WebGLType {
26
26
  */
27
27
  getObject3D(): Object3DType[]
28
28
 
29
+ /**
30
+ * 设置区域
31
+ */
32
+ setRegion(regionName: string | number): this
33
+
34
+ /**
35
+ * 获取区域
36
+ */
37
+ getRegion(x: number, y: number): Promise<string>
38
+
29
39
  }
@@ -57,10 +57,10 @@ export default {
57
57
  help: {},
58
58
  viewImg: "",
59
59
  // #ifdef H5
60
- isH5: true
60
+ isH5: true,
61
61
  // #endif
62
62
  // #ifndef H5
63
- isH5: false
63
+ isH5: false,
64
64
  // #endif
65
65
  };
66
66
  },
@@ -75,26 +75,27 @@ export default {
75
75
  },
76
76
  touchstart: {
77
77
  type: Function,
78
- default: () => { },
78
+ default: () => {},
79
79
  },
80
80
  cover: {
81
81
  type: Boolean,
82
- default: true
83
- }
82
+ default: true,
83
+ },
84
84
  },
85
85
  methods: {
86
86
  fetch() {
87
+ let painter, region, painterid, regionid;
87
88
  // #ifdef MP-WEIXIN
88
- let painter = uni.createCanvasContext("painter", this);
89
- let region = uni.createCanvasContext("region", this);
90
- let painterid = "painter";
91
- let regionid = "region";
89
+ painter = uni.createCanvasContext("painter", this);
90
+ region = uni.createCanvasContext("region", this);
91
+ painterid = "painter";
92
+ regionid = "region";
92
93
  // #endif
93
94
  // #ifndef MP-WEIXIN
94
- let painter = uni.createCanvasContext("painter-" + this.uniqueid, this);
95
- let region = uni.createCanvasContext("region-" + this.uniqueid, this);
96
- let painterid = "painter-" + this.uniqueid;
97
- let regionid = "region-" + this.uniqueid;
95
+ painter = uni.createCanvasContext("painter-" + this.uniqueid, this);
96
+ region = uni.createCanvasContext("region-" + this.uniqueid, this);
97
+ painterid = "painter-" + this.uniqueid;
98
+ regionid = "region-" + this.uniqueid;
98
99
  // #endif
99
100
 
100
101
  let _this = this;
@@ -106,6 +107,9 @@ export default {
106
107
  },
107
108
  {
108
109
  getContext() {
110
+ // #ifdef MP-ALIPAY
111
+ let getImageData = region.getImageData;
112
+ // #endif
109
113
  region.getImageData = (x, y, width, height) => {
110
114
  return new Promise((resolve, reject) => {
111
115
  let options = {
@@ -123,7 +127,7 @@ export default {
123
127
  };
124
128
 
125
129
  // #ifdef MP-ALIPAY
126
- region.getImageData(options, _this);
130
+ getImageData(options, _this);
127
131
  // #endif
128
132
  // #ifndef MP-ALIPAY
129
133
  uni.canvasGetImageData(options, _this);
@@ -140,14 +144,16 @@ export default {
140
144
 
141
145
  // 如果不使用原生渲染
142
146
  if (!this.cover && !this.isH5) {
143
- uni.canvasToTempFilePath({
144
- canvasId: painterid,
145
- success: (e) => {
146
- this.viewImg = e.tempFilePath;
147
- }
148
- }, this);
147
+ uni.canvasToTempFilePath(
148
+ {
149
+ canvasId: painterid,
150
+ success: (e) => {
151
+ this.viewImg = e.tempFilePath;
152
+ },
153
+ },
154
+ this
155
+ );
149
156
  }
150
-
151
157
  };
152
158
  return new Promise((resolve, reject) => {
153
159
  this.help.instance.toDataURL = () => {
@@ -171,7 +177,7 @@ export default {
171
177
  let doRun = (x, y) => {
172
178
  this.help.instance.getRegion(x, y).then((regionName) => {
173
179
  // 兼容旧语法
174
- if (doback) doback(regionName);
180
+ if (typeof doback == "function") doback(regionName);
175
181
 
176
182
  this.$emit("dotouchstart", {
177
183
  name: regionName,
@@ -182,15 +188,22 @@ export default {
182
188
  };
183
189
 
184
190
  if (this.cover || this.isH5) {
185
-
186
191
  // #ifdef MP-ALIPAY
187
192
  uni
188
193
  .createSelectorQuery()
189
194
  .selectViewport()
190
195
  .scrollOffset()
191
196
  .exec((ret) => {
192
- let x = event.touches[0].x + ret[0].scrollLeft;
193
- let y = event.touches[0].y + ret[0].scrollTop;
197
+ let x, y;
198
+ // #ifdef MP-ALIPAY
199
+ x = event.touches[0].x;
200
+ y = event.touches[0].y;
201
+ // #endif
202
+ // #ifndef MP-ALIPAY
203
+ x = event.touches[0].x + ret[0].scrollLeft;
204
+ y = event.touches[0].y + ret[0].scrollTop;
205
+ // #endif
206
+
194
207
  doRun(x, y);
195
208
  });
196
209
  // #endif
@@ -199,13 +212,24 @@ export default {
199
212
  let y = event.touches[0].y;
200
213
  doRun(x, y);
201
214
  // #endif
202
-
203
215
  } else {
204
-
205
- uni.createSelectorQuery().in(this).select('.view-' + this.uniqueid).boundingClientRect(data => {
206
- doRun(event.touches[0].pageX - data.left, event.touches[0].pageY - data.top);
207
- }).exec()
208
-
216
+ uni
217
+ .createSelectorQuery()
218
+ .selectViewport()
219
+ .scrollOffset()
220
+ .exec((ret) => {
221
+ uni
222
+ .createSelectorQuery()
223
+ .in(this)
224
+ .select(".view-" + this.uniqueid)
225
+ .boundingClientRect((data) => {
226
+ doRun(
227
+ event.touches[0].pageX - data.left - ret[0].scrollLeft,
228
+ event.touches[0].pageY - data.top - ret[0].scrollTop
229
+ );
230
+ })
231
+ .exec();
232
+ });
209
233
  }
210
234
  },
211
235
  doitstart(event) {