vislite 0.8.0 → 1.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS.txt +6 -6
- package/CHANGELOG +17 -2
- package/LICENSE +20 -20
- package/README.md +2 -36
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +9 -24
- package/lib/Canvas/index.umd.min.js +3 -3
- package/lib/Cardinal/index.umd.js +2 -2
- package/lib/Cardinal/index.umd.min.js +2 -2
- package/lib/Eoap/index.umd.js +2 -2
- package/lib/Eoap/index.umd.min.js +2 -2
- package/lib/Hermite/index.umd.js +2 -2
- package/lib/Hermite/index.umd.min.js +2 -2
- package/lib/Matrix4/index.umd.js +2 -2
- package/lib/Matrix4/index.umd.min.js +2 -2
- package/lib/Mercator/index.umd.js +2 -2
- package/lib/Mercator/index.umd.min.js +2 -2
- package/lib/SVG/index.umd.js +19 -35
- package/lib/SVG/index.umd.min.js +3 -3
- package/lib/Shader/index.umd.js +3 -82
- package/lib/Shader/index.umd.min.js +3 -3
- package/lib/Texture/index.umd.js +2 -2
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +2 -2
- package/lib/TreeLayout/index.umd.min.js +2 -2
- package/lib/animation/index.umd.js +2 -2
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/getLoopColors/index.umd.js +2 -2
- package/lib/getLoopColors/index.umd.min.js +2 -2
- package/lib/getWebGLContext/index.umd.js +2 -2
- package/lib/getWebGLContext/index.umd.min.js +2 -2
- package/lib/index.umd.js +104 -944
- package/lib/index.umd.min.js +3 -3
- package/lib/move/index.umd.js +2 -2
- package/lib/move/index.umd.min.js +2 -2
- package/lib/resizeObserver/index.umd.js +2 -2
- package/lib/resizeObserver/index.umd.min.js +2 -2
- package/lib/rotate/index.umd.js +2 -2
- package/lib/rotate/index.umd.min.js +2 -2
- package/lib/ruler/index.umd.js +2 -2
- package/lib/ruler/index.umd.min.js +2 -2
- package/lib/scale/index.umd.js +2 -2
- package/lib/scale/index.umd.min.js +2 -2
- package/lib/throttle/index.umd.js +2 -2
- package/lib/throttle/index.umd.min.js +2 -2
- package/miniprogram/ui-canvas/index.js +100 -107
- package/miniprogram/ui-canvas/index.json +4 -4
- package/miniprogram/ui-canvas/index.wxml +4 -4
- package/miniprogram/ui-canvas/index.wxss +5 -5
- package/package/Buffer/index.ts +2 -2
- package/package/Canvas/index.ts +2 -2
- package/package/Cardinal/index.ts +2 -2
- package/package/Eoap/index.ts +2 -2
- package/package/Hermite/index.ts +2 -2
- package/package/Matrix4/index.ts +2 -2
- package/package/Mercator/index.ts +2 -2
- package/package/SVG/index.ts +2 -2
- package/package/Shader/index.ts +2 -39
- package/package/Texture/index.ts +2 -2
- package/package/TreeLayout/index.ts +2 -2
- package/package/animation/index.ts +2 -2
- package/package/getLoopColors/index.ts +2 -2
- package/package/index.ts +67 -76
- package/package/move/index.ts +2 -2
- package/package/resizeObserver/index.ts +2 -2
- package/package/rotate/index.ts +2 -2
- package/package/ruler/index.ts +2 -2
- package/package/scale/index.ts +2 -2
- package/package/throttle/index.ts +2 -2
- package/package.json +1 -1
- package/src/Eoap.ts +66 -66
- package/src/Matrix4/index.ts +84 -84
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/scale.ts +11 -11
- package/src/Matrix4/transform.ts +64 -64
- package/src/Mercator.ts +27 -27
- package/src/SVG.ts +24 -24
- package/src/animation.ts +98 -98
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/arc.ts +51 -51
- package/src/common/canvas/config.ts +158 -158
- package/src/common/canvas/gradient.ts +24 -29
- package/src/common/canvas/index.ts +1 -12
- package/src/common/canvas/texts.ts +18 -18
- package/src/common/mergeOption.ts +6 -6
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +190 -190
- package/src/common/svg/gradient.ts +53 -63
- package/src/common/svg/index.ts +347 -356
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/index.ts +25 -25
- package/src/common/tree/toInnerTree.ts +59 -59
- package/src/common/tree/toPlainTree.ts +132 -132
- package/src/common/webgl/buffer.ts +79 -79
- package/src/common/webgl/getWebGLContext.ts +1 -1
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +97 -97
- package/src/formatColor.ts +44 -44
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +110 -110
- package/src/interpolation/Hermite.ts +65 -65
- package/src/layout/TreeLayout.ts +188 -188
- package/src/move.ts +7 -7
- package/src/resizeObserver.ts +37 -37
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +209 -209
- package/src/scale.ts +6 -6
- package/src/throttle.ts +52 -52
- package/types/Buffer.d.ts +23 -23
- package/types/CanvasConfig.d.ts +106 -106
- package/types/CanvasOption.d.ts +8 -8
- package/types/CanvasOpts.d.ts +9 -9
- package/types/Cardinal.d.ts +13 -13
- package/types/Gradient.d.ts +14 -14
- package/types/Hermite.d.ts +18 -18
- package/types/Map.d.ts +9 -9
- package/types/Matrix4.d.ts +47 -47
- package/types/SVG.d.ts +238 -238
- package/types/SVGConfig.d.ts +79 -79
- package/types/Shader.d.ts +16 -23
- package/types/Texture.d.ts +16 -16
- package/types/Tree.d.ts +69 -69
- package/types/TreeConfig.d.ts +36 -36
- package/types/TreeLayout.d.ts +54 -54
- package/types/TreeOption.d.ts +48 -48
- package/types/animation.d.ts +9 -6
- package/types/getLoopColors.d.ts +5 -2
- package/types/getWebGLContext.d.ts +3 -0
- package/types/index.d.ts +149 -176
- package/types/move.d.ts +5 -2
- package/types/painterConfig.d.ts +2 -2
- package/types/resizeObserver.d.ts +5 -2
- package/types/rotate.d.ts +5 -2
- package/types/ruler.d.ts +10 -7
- package/types/scale.d.ts +5 -2
- package/types/throttle.d.ts +7 -4
- package/types/throttleOption.d.ts +21 -21
- package/uni-app/ui-canvas.vue +4 -11
- package/lib/Geometry/index.umd.d.ts +0 -3
- package/lib/Geometry/index.umd.js +0 -353
- package/lib/Geometry/index.umd.min.d.ts +0 -3
- package/lib/Geometry/index.umd.min.js +0 -11
- package/lib/OralCanvas/index.es.d.ts +0 -3
- package/lib/OralCanvas/index.es.js +0 -693
- package/lib/OralCanvas/index.es.min.d.ts +0 -3
- package/lib/OralCanvas/index.es.min.js +0 -11
- package/lib/OralWebGL/index.es.d.ts +0 -3
- package/lib/OralWebGL/index.es.js +0 -639
- package/lib/OralWebGL/index.es.min.d.ts +0 -3
- package/lib/OralWebGL/index.es.min.js +0 -11
- package/lib/WebGL/index.umd.d.ts +0 -3
- package/lib/WebGL/index.umd.js +0 -712
- package/lib/WebGL/index.umd.min.d.ts +0 -3
- package/lib/WebGL/index.umd.min.js +0 -11
- package/lib/formatColor/index.umd.d.ts +0 -3
- package/lib/formatColor/index.umd.js +0 -59
- package/lib/formatColor/index.umd.min.d.ts +0 -3
- package/lib/formatColor/index.umd.min.js +0 -11
- package/lib/viewHandler/index.umd.d.ts +0 -3
- package/lib/viewHandler/index.umd.js +0 -139
- package/lib/viewHandler/index.umd.min.d.ts +0 -3
- package/lib/viewHandler/index.umd.min.js +0 -11
- package/package/Geometry/index.ts +0 -3
- package/package/OralCanvas/index.ts +0 -3
- package/package/OralWebGL/index.ts +0 -3
- package/package/WebGL/index.ts +0 -3
- package/package/formatColor/index.ts +0 -3
- package/package/viewHandler/index.ts +0 -3
- package/src/Geometry.ts +0 -211
- package/src/WebGL.ts +0 -67
- package/src/common/geometry/prism-horizontal.ts +0 -50
- package/src/common/geometry/prism-vertical.ts +0 -55
- package/src/common/geometry/sphere-fragment.ts +0 -40
- package/src/common/geometry/tool/circle.ts +0 -18
- package/src/common/geometry/tool/rotateLine.ts +0 -49
- package/src/common/geometry/tool/triangles.ts +0 -24
- package/src/common/webgl/doDraw.ts +0 -109
- package/src/common/webgl/getColorFactory.ts +0 -27
- package/src/common/webgl/getShader.ts +0 -49
- package/src/common/webgl/getTexture.ts +0 -12
- package/src/common/webgl/index.ts +0 -228
- package/src/shader/fsColor.c +0 -8
- package/src/shader/fsColors.c +0 -8
- package/src/shader/fsCube.c +0 -9
- package/src/shader/fsImage.c +0 -9
- package/src/shader/vsColor.c +0 -18
- package/src/shader/vsColors.c +0 -14
- package/src/shader/vsCube.c +0 -14
- package/src/shader/vsImage.c +0 -14
- package/src/viewHandler.ts +0 -161
- package/types/Geometry.d.ts +0 -133
- package/types/GeometryOption.d.ts +0 -12
- package/types/GeometryResult.d.ts +0 -19
- package/types/Object3D.d.ts +0 -115
- package/types/Scene3D.d.ts +0 -7
- package/types/WebGL.d.ts +0 -39
- package/types/WebGLOption.d.ts +0 -15
- package/types/formatColor.d.ts +0 -3
- package/types/viewHandler.d.ts +0 -14
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.8.0
|
|
3
|
-
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
|
-
*
|
|
5
|
-
* Copyright zxl20070701
|
|
6
|
-
* Released under the MIT license
|
|
7
|
-
* https://zxl20070701.github.io/notebook/home.html
|
|
8
|
-
*
|
|
9
|
-
* Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
|
|
10
|
-
*/
|
|
11
|
-
var t,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,o=0,n=r.length;o<n;o++)!i&&o in r||(i||(i=Array.prototype.slice.call(r,0,o)),i[o]=r[o]);return t.concat(i||Array.prototype.slice.call(r))}function e(t,r,e,i){void 0===e&&(e={}),void 0===i&&(i="scaleToFill");for(var o=["experimental-webgl","webkit-3d","moz-webgl"],n=t.getContext("webgl",e),a=0;a<o.length;a++){try{n=t.getContext(o[a],e)}catch(t){}if(n)break}if(!n)throw new Error("Non canvas or browser does not support webgl.");var s=n.canvas.width,u=n.canvas.height,_=r,m=r;"aspectFit"==i?s>u?_*=u/s:u>s&&(m*=s/u):"aspectFill"==i&&(s>u?m*=s/u:u>s&&(_*=u/s));var l=s*_,p=u*m;return n.viewport(.5*(s-l),.5*(u-p),l,p),n.depthFunc(n.LEQUAL),n.enable(n.DEPTH_TEST),n}function i(t){var r=t.drawingBufferWidth,e=t.drawingBufferHeight,i=new Uint8Array(4*r*e);return t.readPixels(0,0,r,e,t.RGBA,t.UNSIGNED_BYTE,i),function(t,o){return"rgba("+i[4*((o=e-o)*r+t)]+","+i[4*(o*r+t)+1]+","+i[4*(o*r+t)+2]+","+i[4*(o*r+t)+3]+")"}}"function"==typeof SuppressedError&&SuppressedError;var o=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},n=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],a=function(){function t(t){void 0===t&&(t=n),this.name="Matrix4",this.__matrix4=t}return t.prototype.setValue=function(t){return void 0===t&&(t=n),this.__matrix4=t,this},t.prototype.move=function(t,r,e,i){return void 0===i&&(i=0),this.__matrix4=o(function(t,r,e,i){void 0===i&&(i=0);var o=Math.sqrt(r*r+e*e+i*i);return[1,0,0,0,0,1,0,0,0,0,1,0,r*t/o,e*t/o,i*t/o,1]}(t,r,e,i),this.__matrix4),this},t.prototype.rotate=function(t,r,e,i,n,a,s){var u=function(t,r,e,i,o,n){if("number"==typeof t&&"number"==typeof r){if("number"!=typeof e?(e=0,i=t,o=r,n=1):"number"==typeof i&&"number"==typeof o&&"number"==typeof n||(i=t,o=r,n=e,t=0,r=0,e=0),t==i&&r==o&&e==n)throw new Error("It's not a legitimate ray!");var a=Math.sqrt((i-t)*(i-t)+(o-r)*(o-r)),s=0!=a?(o-r)/a:1,u=0!=a?(i-t)/a:0,_=(i-t)*u+(o-r)*s,m=n-e,l=Math.sqrt(_*_+m*m),p=0!=l?m/l:1,c=0!=l?_/l:0;return[[s,p*u,u*c,0,-u,s*p,s*c,0,0,-c,p,0,r*u-t*s,e*c-t*u*p-r*s*p,-t*u*c-r*s*c-e*p,1],[s,-u,0,0,p*u,p*s,-c,0,u*c,s*c,p,0,t,r,e,1]]}throw new Error("a1 and b1 is required!")}(r,e,i,n,a,s);return this.__matrix4=o(o(o(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,i,n,a){return void 0===i&&(i=0),void 0===n&&(n=0),void 0===a&&(a=0),this.__matrix4=o(function(t,r,e,i,o,n){return void 0===i&&(i=0),void 0===o&&(o=0),void 0===n&&(n=0),[t,0,0,0,0,r,0,0,0,0,e,0,i-i*t,o-o*r,n-n*e,1]}(t,r,e,i,n,a),this.__matrix4),this},t.prototype.multiply=function(t,r){return void 0===r&&(r=!1),this.__matrix4=r?o(this.__matrix4,t):o(t,this.__matrix4),this},t.prototype.use=function(t,r,e,i){return void 0===e&&(e=0),void 0===i&&(i=1),o(this.__matrix4,[t,r,e,i])},t.prototype.value=function(){return this.__matrix4},t}(),s=function(){function t(t,r){void 0===r&&(r=!1),this.__painter=t,this.__isElement=r,this.__buffer=function(t){return t.createBuffer()}(t),this.__type=r?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER}return t.prototype.use=function(){return this.__painter.bindBuffer(this.__type,this.__buffer),this},t.prototype.write=function(t){return function(t,r,e,i){var o=e?t.ELEMENT_ARRAY_BUFFER:t.ARRAY_BUFFER;t.bufferData(o,r,i)}(this.__painter,t,this.__isElement,this.__painter.STATIC_DRAW),this.__fsize=t.BYTES_PER_ELEMENT,this},t.prototype.divide=function(t,r,e,i){return void 0===i&&(i=0),function(t,r,e,i,o,n,a){t.vertexAttribPointer(r,e,i,a,o,n),t.enableVertexAttribArray(r)}(this.__painter,t,r,this.__painter.FLOAT,e*this.__fsize,i*this.__fsize,!1),this},t}(),u=function(){function t(t,r,e){void 0===e&&(e=0),this.__painter=t,this.__type={"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP}[r],this.__texture=function(t,r,e){var i=t.createTexture();return t.activeTexture(t["TEXTURE"+e]),t.bindTexture(r,i),i}(t,this.__type,e),t.texParameteri(this.__type,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(this.__type,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(this.__type,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(this.__type,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)}return t.prototype.useImage=function(t){return function(t,r,e,i,o,n){t.texImage2D(r,e,i,i,o,n)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t),this},t.prototype.useCube=function(t,r,e){return function(t,r,e,i,o,n,a,s,u){for(var _,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],l=0;l<m.length;l++)n[l]&&(_=m[l],t.texImage2D(_,e,i,a,s,0,i,o,null),t.bindTexture(r,u),t.texImage2D(_,e,i,i,o,n[l]));t.generateMipmap(r)}(this.__painter,this.__type,0,this.__painter.RGBA,this.__painter.UNSIGNED_BYTE,t,r,e,this.__texture),this},t}(),_={};function m(t,r,e){var i=t+"-"+e;return _[i]||(_[i]=new u(r,e)),_[i]}var l=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},p=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=l(t,t.VERTEX_SHADER,r),o=l(t,t.FRAGMENT_SHADER,e),n=t.createProgram();if(t.attachShader(n,i),t.attachShader(n,o),t.linkProgram(n),!t.getProgramParameter(n,t.LINK_STATUS))throw new Error("Failed to link program: "+t.getProgramInfoLog(n));return n}(this.__painter,t,r),this},t}(),c="attribute vec4 a_position;\nuniform mat4 u_matrix;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n\n // 把原生的WebGL使用的左手坐标系变成了右手坐标系\n temp.z = -1.0 * temp.z;\n\n // 表示眼睛距离vec4(0.0,0.0,1.0)的距离\n float dist = 4.0;\n\n // 使用投影直接计算\n // 为保证纹理和相对位置正确\n // x、y、z的改变满足线性变换\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n}",v="attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_color;\nvarying vec4 v_color;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_color = a_color;\n}",d="attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec2 a_textcoord;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_textcoord = a_textcoord;\n}",h="attribute vec4 a_position;\nuniform mat4 u_matrix;\nattribute vec4 a_normal;\nvarying vec3 v_normal;\n\nvoid main()\n{\n vec4 temp = u_matrix * a_position;\n temp.z = -1.0 * temp.z;\n float dist = 4.0;\n gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));\n\n v_normal = normalize(vec3(a_normal));\n}",g="precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main()\n{\n gl_FragColor = u_color;\n}",f="precision mediump float;\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_FragColor = v_color;\n}",y="precision mediump float;\n\nuniform sampler2D u_sampler;\nvarying vec2 v_textcoord;\n\nvoid main()\n{\n gl_FragColor = texture2D(u_sampler, v_textcoord);\n}",E="precision mediump float;\n\nvarying vec3 v_normal;\nuniform samplerCube u_texture;\n\nvoid main()\n{\n gl_FragColor = textureCube(u_texture, normalize(v_normal));\n}",b={};function x(t,r,e,i,o){var n,a,u,_,l,x,T,w,A,R,P,U,L,C,S,I,z,F,M,B,N,D,G,O,X=function(t,r,e){var i,o,n=t+(e.material.color?"1":"0")+(e.material.colors?"1":"0")+(e.material.image?"1":"0")+(e.material.cube?"1":"0");if(b[n])return b[n].use();var a=(i={},i[t+"1000"]=c,i[t+"0100"]=v,i[t+"0010"]=d,i[t+"0001"]=h,i)[n].replace(/uniform +mat4 +u_matrix;/,"\n uniform mat4 u_matrix_world;\n uniform mat4 u_matrix_mesh;\n uniform mat4 u_matrix_proporion;").replace(/u_matrix +\* +a_position/,"u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position"),s=(o={},o[t+"1000"]=g,o[t+"0100"]=f,o[t+"0010"]=y,o[t+"0001"]=E,o)[n],u=new p(r).compile(a,s).use();return b[n]=u,u}(t,r,e);if(new s(r).use().write(e.geometry.attributes.position.array).divide(r.getAttribLocation(X.program,"a_position"),e.geometry.attributes.position.itemSize,e.geometry.attributes.position.itemSize,0),r.uniformMatrix4fv(r.getUniformLocation(X.program,"u_matrix_world"),!1,o.matrix),r.uniformMatrix4fv(r.getUniformLocation(X.program,"u_matrix_proporion"),!1,o.proporion),r.uniformMatrix4fv(r.getUniformLocation(X.program,"u_matrix_mesh"),!1,i.matrix),e.geometry.attributes.normal&&new s(r).use().write(e.geometry.attributes.normal.array).divide(r.getAttribLocation(X.program,"a_normal"),e.geometry.attributes.normal.itemSize,e.geometry.attributes.normal.itemSize,0),"color"in e.material&&r.uniform4f(r.getUniformLocation(X.program,"u_color"),null===(n=e.material.color)||void 0===n?void 0:n.r,null===(a=e.material.color)||void 0===a?void 0:a.g,null===(u=e.material.color)||void 0===u?void 0:u.b,null===(_=e.material.color)||void 0===_?void 0:_.alpha),"colors"in e.material)new s(r).use().write(null===(l=e.material.colors)||void 0===l?void 0:l.array).divide(r.getAttribLocation(X.program,"a_color"),null===(x=e.material.colors)||void 0===x?void 0:x.itemSize,null===(T=e.material.colors)||void 0===T?void 0:T.itemSize,0);else if("cube"in e.material){var V=(null===(A=null===(w=e.material.cube)||void 0===w?void 0:w.right)||void 0===A?void 0:A.image.value).width;r.uniform1i(r.getUniformLocation(X.program,"u_texture"),0),m(t,r,"cube").useCube([null===(P=null===(R=e.material.cube)||void 0===R?void 0:R.right)||void 0===P?void 0:P.image.value,null===(L=null===(U=e.material.cube)||void 0===U?void 0:U.left)||void 0===L?void 0:L.image.value,null===(S=null===(C=e.material.cube)||void 0===C?void 0:C.top)||void 0===S?void 0:S.image.value,null===(z=null===(I=e.material.cube)||void 0===I?void 0:I.bottom)||void 0===z?void 0:z.image.value,null===(M=null===(F=e.material.cube)||void 0===F?void 0:F.far)||void 0===M?void 0:M.image.value,null===(N=null===(B=e.material.cube)||void 0===B?void 0:B.near)||void 0===N?void 0:N.image.value],V,V)}else"image"in e.material&&(r.uniform1i(r.getUniformLocation(X.program,"u_sampler"),0),new s(r).use().write(null===(D=e.geometry.attributes.uv)||void 0===D?void 0:D.array).divide(r.getAttribLocation(X.program,"a_textcoord"),null===(G=e.geometry.attributes.uv)||void 0===G?void 0:G.itemSize,2,0),m(t,r,"2d").useImage(null===(O=e.material.image)||void 0===O?void 0:O.value));e.geometry.index?(new s(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 T=!1,w=function(){function t(t,r,i){this.name="WebGL",this.__getColor=function(t,r){return"rgba(0,0,0,1)"},this.__regionList={},this.__regionAssemble=function(t,r,e,i){for(var o=[],n=0;n<i;n++)o[n]=t;return function(){for(var n=0;n<i;n++){if(o[n]+e<r){o[n]=+(o[n]+e).toFixed(7);break}n<i-1&&(o[n]=t)}return o}}(0,1,.2,3),this.__regionName="",this.__regionColor=[0,0,0,1],this.__scene={children:[],matrix:new a([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,{},i),r&&(this.__regionPainter=e(r,10,{},i));var o=this.painter.canvas.width/this.painter.canvas.height,n=1,s=1;o>1?n=1/o:s=o;var u=Math.min(n,s);this.__proporion=[n,0,0,0,0,s,0,0,0,0,u,0,0,0,0,1]}return t.prototype.matrix=function(t){return new a(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&&(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){var e;void 0===r&&(r=!1),r||(T=!0);var o={matrix:null===(e=t.matrix)||void 0===e?void 0:e.value()},n={matrix:this.__scene.matrix.value(),proporion:this.__proporion};this.setRegion(t.region);for(var a=0;a<t.mesh.length;a++)r?this.__regionPainter&&(x("painter"+this.__unique,this.__regionPainter,{geometry:t.mesh[a].geometry,material:{color:{r:this.__regionColor[0],g:this.__regionColor[1],b:this.__regionColor[2],alpha:this.__regionColor[3]}}},o,n),this.__getColor=i(this.__regionPainter)):x("region"+this.__unique,this.painter,t.mesh[a],o,n)},t.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)),e.material.colors&&Array.isArray(e.material.colors.array)&&(e.material.colors.array=new Float32Array(e.material.colors.array))}this.__scene.children.push(t),this.draw(t)},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 T&&this.review(!0),T=!1,new Promise((function(i){var o=e.__getColor(t,r);for(var n in e.__regionList){var a=e.__regionList[n];if("rgba("+255*a[0]+","+255*a[1]+","+255*a[2]+","+255*a[3]+")"==o){i(n);break}}i("")}))},t}();return function(r){function e(t,e){if(void 0===e&&(e={}),!t)throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.");e=function(t,r){for(var e in t)r[e]=t[e];return r}(e,{region:!0});var i,o=t.clientWidth,n=t.clientHeight,a=null,s=t;s._vislite_canvas_?(i=s._vislite_canvas_[0],a=s._vislite_canvas_[1]):(e.region&&(a=document.createElement("canvas"),t.appendChild(a),a.style.position="absolute",a.style.zIndex="-1",a.style.opacity="0"),i=document.createElement("canvas"),t.appendChild(i),s._vislite_canvas_=[i,a],t.setAttribute("vislite","WebGL"));for(var u=0,_=[i,a];u<_.length;u++){var m=_[u];m&&(m.style.width=o+"px",m.setAttribute("width",o+""),m.style.height=n+"px",m.setAttribute("height",n+""))}return r.call(this,i,a,e.mode)||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}(w)},"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();
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.8.0
|
|
3
|
-
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
|
-
*
|
|
5
|
-
* Copyright zxl20070701
|
|
6
|
-
* Released under the MIT license
|
|
7
|
-
* https://zxl20070701.github.io/notebook/home.html
|
|
8
|
-
*
|
|
9
|
-
* Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
|
|
10
|
-
*/
|
|
11
|
-
(function (global, factory) {
|
|
12
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
13
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
14
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VISLite_formatColor = factory());
|
|
15
|
-
})(this, (function () { 'use strict';
|
|
16
|
-
|
|
17
|
-
var toHex = function (value) {
|
|
18
|
-
var hex = value.toString(16);
|
|
19
|
-
return hex.length == 1 ? ("0" + hex) : hex;
|
|
20
|
-
};
|
|
21
|
-
function formatColor (color, format) {
|
|
22
|
-
var colorNode = document.getElementsByTagName('head')[0];
|
|
23
|
-
colorNode.style['color'] = color;
|
|
24
|
-
var allStyle = document.defaultView && document.defaultView.getComputedStyle ?
|
|
25
|
-
document.defaultView.getComputedStyle(colorNode, null) :
|
|
26
|
-
colorNode.currentStyle;
|
|
27
|
-
var oralFormat = allStyle.getPropertyValue('color').replace(/rgba?\(/, '').replace(")", "").split(',');
|
|
28
|
-
for (var index = 0; index < oralFormat.length; index++) {
|
|
29
|
-
oralFormat[index] = +oralFormat[index];
|
|
30
|
-
}
|
|
31
|
-
oralFormat.push(1);
|
|
32
|
-
switch (format) {
|
|
33
|
-
case "3d": {
|
|
34
|
-
return [
|
|
35
|
-
oralFormat[0] / 255,
|
|
36
|
-
oralFormat[1] / 255,
|
|
37
|
-
oralFormat[2] / 255,
|
|
38
|
-
oralFormat[3]
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
case "rgba": {
|
|
42
|
-
return "rgba(".concat(oralFormat[0], ", ").concat(oralFormat[1], ", ").concat(oralFormat[2], ", ").concat(oralFormat[3], ")");
|
|
43
|
-
}
|
|
44
|
-
case "rgb": {
|
|
45
|
-
return "rgb(".concat(oralFormat[0], ", ").concat(oralFormat[1], ", ").concat(oralFormat[2], ")");
|
|
46
|
-
}
|
|
47
|
-
case "hexAlpha": {
|
|
48
|
-
return "#".concat(toHex(oralFormat[0])).concat(toHex(oralFormat[1])).concat(toHex(oralFormat[2])).concat(toHex(+(oralFormat[3] * 255).toFixed(0)));
|
|
49
|
-
}
|
|
50
|
-
case "hex": {
|
|
51
|
-
return "#".concat(toHex(oralFormat[0])).concat(toHex(oralFormat[1])).concat(toHex(oralFormat[2]));
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
throw new Error("Unsupported color format: " + format);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return formatColor;
|
|
58
|
-
|
|
59
|
-
}));
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.8.0
|
|
3
|
-
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
|
-
*
|
|
5
|
-
* Copyright zxl20070701
|
|
6
|
-
* Released under the MIT license
|
|
7
|
-
* https://zxl20070701.github.io/notebook/home.html
|
|
8
|
-
*
|
|
9
|
-
* Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
|
|
10
|
-
*/
|
|
11
|
-
var e,t;e=this,t=function(){"use strict";var e=function(e){var t=e.toString(16);return 1==t.length?"0"+t:t};return function(t,o){var c=document.getElementsByTagName("head")[0];c.style.color=t;for(var n=(document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(c,null):c.currentStyle).getPropertyValue("color").replace(/rgba?\(/,"").replace(")","").split(","),r=0;r<n.length;r++)n[r]=+n[r];switch(n.push(1),o){case"3d":return[n[0]/255,n[1]/255,n[2]/255,n[3]];case"rgba":return"rgba(".concat(n[0],", ").concat(n[1],", ").concat(n[2],", ").concat(n[3],")");case"rgb":return"rgb(".concat(n[0],", ").concat(n[1],", ").concat(n[2],")");case"hexAlpha":return"#".concat(e(n[0])).concat(e(n[1])).concat(e(n[2])).concat(e(+(255*n[3]).toFixed(0)));case"hex":return"#".concat(e(n[0])).concat(e(n[1])).concat(e(n[2]))}throw new Error("Unsupported color format: "+o)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_formatColor=t();
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.8.0
|
|
3
|
-
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
|
-
*
|
|
5
|
-
* Copyright zxl20070701
|
|
6
|
-
* Released under the MIT license
|
|
7
|
-
* https://zxl20070701.github.io/notebook/home.html
|
|
8
|
-
*
|
|
9
|
-
* Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
|
|
10
|
-
*/
|
|
11
|
-
(function (global, factory) {
|
|
12
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
13
|
-
typeof define === 'function' && define.amd ? define(factory) :
|
|
14
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VISLite_viewHandler = factory());
|
|
15
|
-
})(this, (function () { 'use strict';
|
|
16
|
-
|
|
17
|
-
var mousePosition = function (el, event) {
|
|
18
|
-
var bounding = el.getBoundingClientRect();
|
|
19
|
-
return {
|
|
20
|
-
"x": event.clientX - bounding.left,
|
|
21
|
-
"y": event.clientY - bounding.top
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
var getKeyString = function (event) {
|
|
25
|
-
return {
|
|
26
|
-
37: "left",
|
|
27
|
-
38: "up",
|
|
28
|
-
39: "right",
|
|
29
|
-
40: "down",
|
|
30
|
-
}[event.keyCode || event.which];
|
|
31
|
-
};
|
|
32
|
-
function viewHandler (callback) {
|
|
33
|
-
var el = document.getElementsByTagName('body')[0];
|
|
34
|
-
el.addEventListener("keydown", function (event) {
|
|
35
|
-
var keyCode = getKeyString(event);
|
|
36
|
-
if (keyCode == 'up') {
|
|
37
|
-
callback({
|
|
38
|
-
type: "lookUp",
|
|
39
|
-
normal: [],
|
|
40
|
-
value: 0.1,
|
|
41
|
-
event: event
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
else if (keyCode == 'down') {
|
|
45
|
-
callback({
|
|
46
|
-
type: "lookDown",
|
|
47
|
-
normal: [],
|
|
48
|
-
value: 0.1,
|
|
49
|
-
event: event
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
else if (keyCode == 'left') {
|
|
53
|
-
callback({
|
|
54
|
-
type: "lookLeft",
|
|
55
|
-
normal: [],
|
|
56
|
-
value: 0.1,
|
|
57
|
-
event: event
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
else if (keyCode == 'right') {
|
|
61
|
-
callback({
|
|
62
|
-
type: "lookRight",
|
|
63
|
-
normal: [],
|
|
64
|
-
value: 0.1,
|
|
65
|
-
event: event
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
var mouseP = null;
|
|
70
|
-
var doMove = function (event) {
|
|
71
|
-
if (mouseP == null) {
|
|
72
|
-
callback({
|
|
73
|
-
type: "hover",
|
|
74
|
-
normal: [],
|
|
75
|
-
value: 0,
|
|
76
|
-
event: event
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
var tempMouseP = mousePosition(el, event);
|
|
81
|
-
var normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y];
|
|
82
|
-
var rotateNormal = [
|
|
83
|
-
normal[1],
|
|
84
|
-
normal[0],
|
|
85
|
-
0
|
|
86
|
-
];
|
|
87
|
-
if (rotateNormal[0] == 0 && rotateNormal[1] == 0)
|
|
88
|
-
return;
|
|
89
|
-
callback({
|
|
90
|
-
type: "rotate",
|
|
91
|
-
normal: rotateNormal,
|
|
92
|
-
value: (Math.abs(tempMouseP.x - mouseP.x) + Math.abs(tempMouseP.y - mouseP.y)) * 0.01,
|
|
93
|
-
event: event
|
|
94
|
-
});
|
|
95
|
-
mouseP = tempMouseP;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
el.addEventListener("mousedown", function (event) {
|
|
99
|
-
mouseP = mousePosition(el, event);
|
|
100
|
-
});
|
|
101
|
-
el.addEventListener("mouseup", function () {
|
|
102
|
-
mouseP = null;
|
|
103
|
-
});
|
|
104
|
-
el.addEventListener("mousemove", function (event) {
|
|
105
|
-
doMove(event);
|
|
106
|
-
});
|
|
107
|
-
el.addEventListener("touchend", function () {
|
|
108
|
-
mouseP = null;
|
|
109
|
-
});
|
|
110
|
-
el.addEventListener("touchstart", function (event) {
|
|
111
|
-
mouseP = mousePosition(el, event);
|
|
112
|
-
});
|
|
113
|
-
el.addEventListener("touchmove", function (event) {
|
|
114
|
-
doMove(event.touches[0]);
|
|
115
|
-
});
|
|
116
|
-
var doScale = function (value, event) {
|
|
117
|
-
if (value == 0)
|
|
118
|
-
return;
|
|
119
|
-
var baseTimes = 0.899;
|
|
120
|
-
callback({
|
|
121
|
-
type: "scale",
|
|
122
|
-
value: value < 0 ? baseTimes : 2 - baseTimes,
|
|
123
|
-
normal: [],
|
|
124
|
-
event: event
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
el.addEventListener("mousewheel", function (event) {
|
|
128
|
-
doScale(event.wheelDelta, event);
|
|
129
|
-
});
|
|
130
|
-
if (window.addEventListener) {
|
|
131
|
-
window.addEventListener('DOMMouseScroll', function (event) {
|
|
132
|
-
doScale(-1 * event.detail, event);
|
|
133
|
-
}, false);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return viewHandler;
|
|
138
|
-
|
|
139
|
-
}));
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.8.0
|
|
3
|
-
* git+https://github.com/oi-contrib/VISLite.git
|
|
4
|
-
*
|
|
5
|
-
* Copyright zxl20070701
|
|
6
|
-
* Released under the MIT license
|
|
7
|
-
* https://zxl20070701.github.io/notebook/home.html
|
|
8
|
-
*
|
|
9
|
-
* Publish Date: Sat Mar 02 2024 12:41:38 GMT+0800 (中国标准时间)
|
|
10
|
-
*/
|
|
11
|
-
var 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,event:e}):"down"==t?n({type:"lookDown",normal:[],value:.1,event:e}):"left"==t?n({type:"lookLeft",normal:[],value:.1,event:e}):"right"==t&&n({type:"lookRight",normal:[],value:.1,event:e})}));var o=null,i=function(i){if(null==o)n({type:"hover",normal:[],value:0,event:i});else{var u=e(t,i),l=[u.x-o.x,u.y-o.y],a=[l[1],l[0],0];if(0==a[0]&&0==a[1])return;n({type:"rotate",normal:a,value:.01*(Math.abs(u.x-o.x)+Math.abs(u.y-o.y)),event:i}),o=u}};t.addEventListener("mousedown",(function(n){o=e(t,n)})),t.addEventListener("mouseup",(function(){o=null})),t.addEventListener("mousemove",(function(e){i(e)})),t.addEventListener("touchend",(function(){o=null})),t.addEventListener("touchstart",(function(n){o=e(t,n)})),t.addEventListener("touchmove",(function(e){i(e.touches[0])}));var u=function(e,t){0!=e&&n({type:"scale",value:e<0?.899:1.101,normal:[],event:t})};t.addEventListener("mousewheel",(function(e){u(e.wheelDelta,e)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(e){u(-1*e.detail,e)}),!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/WebGL/index.ts
DELETED
package/src/Geometry.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import type GeometryType from "../types/Geometry"
|
|
2
|
-
import type GeometryOptionType from "../types/GeometryOption"
|
|
3
|
-
import type GeometryResultType from "../types/GeometryResult"
|
|
4
|
-
|
|
5
|
-
type rotateLineType = (x0: number, y0: number, z0: number, isNormal: boolean) => Array<number>
|
|
6
|
-
|
|
7
|
-
import { splitNum } from './common/geometry/tool/circle'
|
|
8
|
-
import prismHorizontal from './common/geometry/prism-horizontal'
|
|
9
|
-
import prismVertical from './common/geometry/prism-vertical'
|
|
10
|
-
import sphereFragment from './common/geometry/sphere-fragment'
|
|
11
|
-
import mergeOption from './common/mergeOption'
|
|
12
|
-
import rotateLineFactory from "./common/geometry/tool/rotateLine"
|
|
13
|
-
import triangles from "./common/geometry/tool/triangles"
|
|
14
|
-
import rotate from "./rotate"
|
|
15
|
-
|
|
16
|
-
class Geometry implements GeometryType {
|
|
17
|
-
readonly name: string = 'Geometry'
|
|
18
|
-
|
|
19
|
-
private __option: GeometryOptionType
|
|
20
|
-
|
|
21
|
-
constructor(option: GeometryOptionType = {}) {
|
|
22
|
-
this.__option = mergeOption(option, {
|
|
23
|
-
precision: 0.1, // 精度
|
|
24
|
-
normal: false, // 是否需要法向量
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
config(option: GeometryOptionType) {
|
|
29
|
-
for (const key in option) {
|
|
30
|
-
this.__option[key] = option[key]
|
|
31
|
-
}
|
|
32
|
-
return this
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 【1】辅助方法
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
// 计算切割份数
|
|
40
|
-
splitNum(radius: number, deg?: number) {
|
|
41
|
-
return splitNum(this.__option.precision as number, radius, deg)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 物体方向转换
|
|
45
|
-
rotateLine(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number) {
|
|
46
|
-
const rotateLine = rotateLineFactory(x1, y1, z1, x2, y2, z2)
|
|
47
|
-
return (x: number, y: number, z: number) => rotateLine(x, y, z, this.__option.normal as boolean)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 【2】立方片段
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
// 棱柱水平部分
|
|
55
|
-
prismHorizontal(x: number, y: number, z: number, radius: number, num: number, d: number, beginDeg?: number, deg?: number) {
|
|
56
|
-
return prismHorizontal(this.__option.normal as boolean, x, y, z, radius, num, d, beginDeg, deg)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 棱柱垂直部分
|
|
60
|
-
prismVertical(x: number, y: number, z: number, radius: number, height: number, num: number, beginDeg?: number, deg?: number) {
|
|
61
|
-
return prismVertical(this.__option.normal as boolean, x, y, z, radius, height, num, beginDeg, deg)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 球体中的一瓣子
|
|
65
|
-
sphereFragment(cx: number, cy: number, cz: number, radius: number, num: number, index: number) {
|
|
66
|
-
return sphereFragment(this.__option.normal as boolean, cx, cy, cz, radius, num, index)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 【3】立方体
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
// 饼柱体
|
|
74
|
-
pie(x: number, y: number, z: number, radius: number, height: number, beginDeg: number, deg: number): Array<GeometryResultType> {
|
|
75
|
-
|
|
76
|
-
// 求解出需要切割多少份比较合理
|
|
77
|
-
const num = splitNum(this.__option.precision as number, radius, deg)
|
|
78
|
-
|
|
79
|
-
const beginXZ = rotate(x, z, beginDeg, x + radius, z)
|
|
80
|
-
const endXZ = rotate(x, z, beginDeg + deg, x + radius, z)
|
|
81
|
-
|
|
82
|
-
const result = [{
|
|
83
|
-
name: "bottom",
|
|
84
|
-
points: prismHorizontal(this.__option.normal as boolean, x, y, z, radius, num as number, height > 0 ? -1 : 1, beginDeg, deg),
|
|
85
|
-
length: 3 * num,
|
|
86
|
-
method: "TRIANGLES" as const
|
|
87
|
-
}, {
|
|
88
|
-
name: "top",
|
|
89
|
-
points: prismHorizontal(this.__option.normal as boolean, x, y + height, z, radius, num as number, height > 0 ? 1 : -1, beginDeg, deg),
|
|
90
|
-
length: 3 * num,
|
|
91
|
-
method: "TRIANGLES" as const
|
|
92
|
-
}, {
|
|
93
|
-
name: "side",
|
|
94
|
-
points: prismVertical(this.__option.normal as boolean, x, y, z, radius, height, num as number, beginDeg, deg),
|
|
95
|
-
length: 6 * num,
|
|
96
|
-
method: "TRIANGLES" as const
|
|
97
|
-
}, {
|
|
98
|
-
name: "begin",
|
|
99
|
-
points: triangles(this.__option.normal as boolean, [
|
|
100
|
-
x, y, z, x, y + height, z, beginXZ[0], y, beginXZ[1],
|
|
101
|
-
beginXZ[0], y + height, beginXZ[1], beginXZ[0], y, beginXZ[1], x, y + height, z
|
|
102
|
-
]),
|
|
103
|
-
length: 6,
|
|
104
|
-
method: "TRIANGLES" as const
|
|
105
|
-
}, {
|
|
106
|
-
name: "end",
|
|
107
|
-
points: triangles(this.__option.normal as boolean, [
|
|
108
|
-
x, y, z, endXZ[0], y, endXZ[1], x, y + height, z,
|
|
109
|
-
endXZ[0], y + height, endXZ[1], x, y + height, z, endXZ[0], y, endXZ[1]
|
|
110
|
-
]),
|
|
111
|
-
length: 6,
|
|
112
|
-
method: "TRIANGLES" as const
|
|
113
|
-
}]
|
|
114
|
-
|
|
115
|
-
return result
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 圆柱体
|
|
119
|
-
cylinder(x: number, y: number, z: number, radius: number, x2: number, y2?: number, z2?: number): Array<GeometryResultType> {
|
|
120
|
-
|
|
121
|
-
// 求解出需要切割多少份比较合理
|
|
122
|
-
const num = splitNum(this.__option.precision as number, radius)
|
|
123
|
-
|
|
124
|
-
if (arguments.length == 5) {
|
|
125
|
-
return this.prism(x, y, z, radius, x2, num)
|
|
126
|
-
} else {
|
|
127
|
-
return this.prism(x, y, z, radius, x2, y2 as number, z2, num)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// 棱柱体
|
|
132
|
-
prism(x: number, y: number, z: number, radius: number, x2: number, y2: number, z2?: number, num?: number): Array<GeometryResultType> {
|
|
133
|
-
|
|
134
|
-
let height: number, rotateLine: rotateLineType | null = null
|
|
135
|
-
|
|
136
|
-
if (arguments.length == 6) {
|
|
137
|
-
height = x2
|
|
138
|
-
num = y2
|
|
139
|
-
} else {
|
|
140
|
-
height = (y > y2 ? -1 : 1) * Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y) + (z2 as number - z) * (z2 as number - z))
|
|
141
|
-
rotateLine = rotateLineFactory(x, y, z, x2, y2, z2 as number)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const result = [{
|
|
145
|
-
name: "bottom",
|
|
146
|
-
points: [],
|
|
147
|
-
length: 0,
|
|
148
|
-
method: "TRIANGLES" as const
|
|
149
|
-
}, {
|
|
150
|
-
name: "top",
|
|
151
|
-
points: [],
|
|
152
|
-
length: 0,
|
|
153
|
-
method: "TRIANGLES" as const
|
|
154
|
-
}, {
|
|
155
|
-
name: "side",
|
|
156
|
-
points: [],
|
|
157
|
-
length: 0,
|
|
158
|
-
method: "TRIANGLES" as const
|
|
159
|
-
}]
|
|
160
|
-
|
|
161
|
-
// 绘制底部的盖子
|
|
162
|
-
; (result[0].points as Array<number>).push(...prismHorizontal(this.__option.normal as boolean, x, y, z, radius, num as number, height > 0 ? -1 : 1))
|
|
163
|
-
|
|
164
|
-
// 绘制顶部的盖子
|
|
165
|
-
; (result[1].points as Array<number>).push(...prismHorizontal(this.__option.normal as boolean, x, y + height, z, radius, num as number, height > 0 ? 1 : -1))
|
|
166
|
-
|
|
167
|
-
// 绘制侧边部分
|
|
168
|
-
; (result[2].points as Array<number>).push(...prismVertical(this.__option.normal as boolean, x, y, z, radius, height, num as number))
|
|
169
|
-
|
|
170
|
-
for (let i = 0; i < result.length; i++) {
|
|
171
|
-
if (rotateLine) {
|
|
172
|
-
|
|
173
|
-
const points = []
|
|
174
|
-
let isNormal = false
|
|
175
|
-
for (let index = 0; index < result[i].points.length; index += 3) {
|
|
176
|
-
points.push(...rotateLine(result[i].points[index], result[i].points[index + 1], result[i].points[index + 2], (this.__option.normal as boolean) && isNormal))
|
|
177
|
-
isNormal = !isNormal
|
|
178
|
-
}
|
|
179
|
-
(result[i].points as Array<number>) = points
|
|
180
|
-
}
|
|
181
|
-
result[i].length = result[i].points.length / (this.__option.normal ? 6 : 3)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return result
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// 球体
|
|
188
|
-
sphere(cx: number, cy: number, cz: number, radius: number): Array<GeometryResultType> {
|
|
189
|
-
|
|
190
|
-
// 求解出需要切割多少份比较合理
|
|
191
|
-
const num = splitNum(this.__option.precision as number, radius)
|
|
192
|
-
|
|
193
|
-
// 然后一瓣瓣的绘制
|
|
194
|
-
const result = [{
|
|
195
|
-
name: "surface",
|
|
196
|
-
points: [],
|
|
197
|
-
length: 0,
|
|
198
|
-
method: "TRIANGLES" as const
|
|
199
|
-
}]
|
|
200
|
-
for (let i = 0; i < num; i++) {
|
|
201
|
-
; (result[0].points as Array<number>).push(...sphereFragment(this.__option.normal as boolean, cx, cy, cz, radius, num, i))
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
result[0].length = result[0].points.length / (this.__option.normal ? 6 : 3)
|
|
205
|
-
|
|
206
|
-
return result
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export default Geometry
|
package/src/WebGL.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type WebGLOptionType from '../types/WebGLOption'
|
|
2
|
-
import type WebGLType from '../types/WebGL'
|
|
3
|
-
|
|
4
|
-
import OralWebGL from './common/webgl/index'
|
|
5
|
-
import mergeOption from './common/mergeOption'
|
|
6
|
-
|
|
7
|
-
class WebGL extends OralWebGL implements WebGLType {
|
|
8
|
-
constructor(el: HTMLElement | null, option: WebGLOptionType = {}) {
|
|
9
|
-
if (!el) {
|
|
10
|
-
throw new Error("VISLite WebGL:The mount point requires an HTMLElement type but encountered null.")
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
option = mergeOption(option, {
|
|
14
|
-
region: true
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
const width = el.clientWidth, height = el.clientHeight
|
|
18
|
-
|
|
19
|
-
let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null = null
|
|
20
|
-
|
|
21
|
-
const _el = el as any
|
|
22
|
-
|
|
23
|
-
// 如果已经初始化过了
|
|
24
|
-
if (_el._vislite_canvas_) {
|
|
25
|
-
ViewCanvas = _el._vislite_canvas_[0]
|
|
26
|
-
RegionCanvas = _el._vislite_canvas_[1]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// 否则就初始化
|
|
30
|
-
else {
|
|
31
|
-
|
|
32
|
-
if (option.region) {
|
|
33
|
-
|
|
34
|
-
RegionCanvas = document.createElement('canvas')
|
|
35
|
-
el.appendChild(RegionCanvas)
|
|
36
|
-
|
|
37
|
-
RegionCanvas.style.position = 'absolute'
|
|
38
|
-
RegionCanvas.style.zIndex = "-1"
|
|
39
|
-
RegionCanvas.style.opacity = "0"
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
ViewCanvas = document.createElement('canvas')
|
|
44
|
-
el.appendChild(ViewCanvas)
|
|
45
|
-
|
|
46
|
-
_el._vislite_canvas_ = [ViewCanvas, RegionCanvas]
|
|
47
|
-
|
|
48
|
-
el.setAttribute('vislite', 'WebGL')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 设置画布大小
|
|
52
|
-
for (const canvas of [ViewCanvas, RegionCanvas]) {
|
|
53
|
-
|
|
54
|
-
if (canvas) {
|
|
55
|
-
canvas.style.width = width + "px"
|
|
56
|
-
canvas.setAttribute('width', width + "")
|
|
57
|
-
|
|
58
|
-
canvas.style.height = height + "px"
|
|
59
|
-
canvas.setAttribute('height', height + "")
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
super(ViewCanvas, RegionCanvas, option.mode)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default WebGL
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import rotate from '../../rotate'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 棱柱水平部分
|
|
5
|
-
* @param normal 是否需要法向量
|
|
6
|
-
* @param x 中心
|
|
7
|
-
* @param y
|
|
8
|
-
* @param z
|
|
9
|
-
* @param radius 半径
|
|
10
|
-
* @param num 份数
|
|
11
|
-
* @param d 方向(用于 表示是底还是顶,方便计算法向量)
|
|
12
|
-
* @param beginDeg 开始弧度,默认0
|
|
13
|
-
* @param deg 跨越弧度,默认2pi
|
|
14
|
-
* @returns 点数组
|
|
15
|
-
*/
|
|
16
|
-
export default function (normal: boolean, x: number, y: number, z: number, radius: number, num: number, d: number, beginDeg: number = 0, deg: number = Math.PI * 2) {
|
|
17
|
-
|
|
18
|
-
let beginX: number, beginZ: number
|
|
19
|
-
if (num == 4) {
|
|
20
|
-
const temp = radius / 1.414
|
|
21
|
-
beginX = x + temp
|
|
22
|
-
beginZ = z + temp
|
|
23
|
-
|
|
24
|
-
} else {
|
|
25
|
-
beginX = x + radius
|
|
26
|
-
beginZ = z
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let point = [beginX, beginZ]
|
|
30
|
-
if (beginDeg != 0) {
|
|
31
|
-
point = rotate(x, z, beginDeg, beginX, beginZ)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const points = []
|
|
35
|
-
const perDeg = deg / num
|
|
36
|
-
for (let i = 0; i < num; i++) {
|
|
37
|
-
|
|
38
|
-
points.push(x, y, z)
|
|
39
|
-
if (normal) points.push(0, d, 0)
|
|
40
|
-
|
|
41
|
-
points.push(point[0], y, point[1])
|
|
42
|
-
if (normal) points.push(0, d, 0)
|
|
43
|
-
|
|
44
|
-
point = rotate(x, z, perDeg * (i + 1), beginX, beginZ)
|
|
45
|
-
points.push(point[0], y, point[1])
|
|
46
|
-
if (normal) points.push(0, d, 0)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return points
|
|
50
|
-
}
|